diff --git a/dot/state/block.go b/dot/state/block.go index 14903473bfc..fd615b0a387 100644 --- a/dot/state/block.go +++ b/dot/state/block.go @@ -59,7 +59,7 @@ type BlockState struct { sync.RWMutex genesisHash common.Hash lastFinalised common.Hash - unfinalisedBlocks *hashToBlock + unfinalisedBlocks *hashToBlockMap // block notifiers imported map[chan *types.Block]struct{} @@ -80,7 +80,7 @@ func NewBlockState(db chaindb.Database, telemetry telemetry.Client) (*BlockState dbPath: db.Path(), baseState: NewBaseState(db), db: chaindb.NewTable(db, blockPrefix), - unfinalisedBlocks: newHashToBlock(), + unfinalisedBlocks: newHashToBlockMap(), imported: make(map[chan *types.Block]struct{}), finalised: make(map[chan *types.FinalisationInfo]struct{}), pruneKeyCh: make(chan *types.Header, pruneKeyBufferSize), @@ -113,7 +113,7 @@ func NewBlockStateFromGenesis(db chaindb.Database, header *types.Header, bt: blocktree.NewBlockTreeFromRoot(header), baseState: NewBaseState(db), db: chaindb.NewTable(db, blockPrefix), - unfinalisedBlocks: newHashToBlock(), + unfinalisedBlocks: newHashToBlockMap(), imported: make(map[chan *types.Block]struct{}), finalised: make(map[chan *types.FinalisationInfo]struct{}), pruneKeyCh: make(chan *types.Header, pruneKeyBufferSize), diff --git a/dot/state/hashtoblock.go b/dot/state/hashtoblock.go index bd3d8aeee5a..cf2bbf172a1 100644 --- a/dot/state/hashtoblock.go +++ b/dot/state/hashtoblock.go @@ -10,30 +10,30 @@ import ( "github.com/ChainSafe/gossamer/lib/common" ) -type hashToBlock struct { +type hashToBlockMap struct { mutex sync.RWMutex mapping map[common.Hash]*types.Block } -func newHashToBlock() *hashToBlock { - return &hashToBlock{ +func newHashToBlockMap() *hashToBlockMap { + return &hashToBlockMap{ mapping: make(map[common.Hash]*types.Block), } } -func (h *hashToBlock) get(hash common.Hash) (block *types.Block) { +func (h *hashToBlockMap) get(hash common.Hash) (block *types.Block) { h.mutex.RLock() defer h.mutex.RUnlock() return h.mapping[hash] } -func (h *hashToBlock) set(hash common.Hash, block *types.Block) { +func (h *hashToBlockMap) set(hash common.Hash, block *types.Block) { h.mutex.Lock() defer h.mutex.Unlock() h.mapping[hash] = block } -func (h *hashToBlock) delete(hash common.Hash) (deletedHeader *types.Header) { +func (h *hashToBlockMap) delete(hash common.Hash) (deletedHeader *types.Header) { h.mutex.Lock() defer h.mutex.Unlock() block := h.mapping[hash]