Skip to content

Commit

Permalink
Rename newHashToBlock to newHashToBlockMap
Browse files Browse the repository at this point in the history
  • Loading branch information
qdm12 committed Feb 15, 2022
1 parent 17dec16 commit 960c70f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
6 changes: 3 additions & 3 deletions dot/state/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}
Expand All @@ -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),
Expand Down Expand Up @@ -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),
Expand Down
12 changes: 6 additions & 6 deletions dot/state/hashtoblock.go
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down

0 comments on commit 960c70f

Please sign in to comment.