hotstuff icon indicating copy to clipboard operation
hotstuff copied to clipboard

refactor: Blockchain to use idiomatic Go

Open meling opened this issue 8 months ago • 0 comments

This method:

func (chain *Blockchain) LocalGet(hash hotstuff.Hash) (*hotstuff.Block, bool) {

Since this already returns a pointer to a block, there is no need to also return a bool. We can simply replace the ok check with a nil check. Thus, the implementation simply becomes:

func (chain *Blockchain) LocalGet(hash hotstuff.Hash) *hotstuff.Block {
	chain.mut.Lock()
	defer chain.mut.Unlock()
	return chain.blocks[hash]
}

Similar adjustments should be made for this method:

func (chain *Blockchain) Get(hash hotstuff.Hash) (block *hotstuff.Block, ok bool) {

meling avatar Jun 17 '25 19:06 meling