Skip to content

Commit

Permalink
Merge pull request #334 from uprendis/feature/genesis-id-cache
Browse files Browse the repository at this point in the history
Cache for genesis ID
  • Loading branch information
uprendis committed Jun 26, 2022
2 parents d136014 + 38e969f commit ae496f1
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 0 deletions.
1 change: 1 addition & 0 deletions gossip/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ func newService(config Config, store *Store, blockProc BlockProc, engine lachesi
svc.store.GetLastEVs()
svc.store.GetLlrState()
svc.store.GetUpgradeHeights()
svc.store.GetGenesisID()
netVerStore := verwatcher.NewStore(store.table.NetworkVersion)
netVerStore.GetNetworkVersion()
netVerStore.GetMissedVersion()
Expand Down
1 change: 1 addition & 0 deletions gossip/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ type Store struct {
LlrState atomic.Value // store by value
KvdbEvmSnap atomic.Value // store by pointer
UpgradeHeights atomic.Value // store by pointer
Genesis atomic.Value // store by value
}

mutex struct {
Expand Down
6 changes: 6 additions & 0 deletions gossip/store_block.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ import (
)

func (s *Store) GetGenesisID() *hash.Hash {
if v := s.cache.Genesis.Load(); v != nil {
val := v.(hash.Hash)
return &val
}
valBytes, err := s.table.Genesis.Get([]byte("g"))
if err != nil {
s.Log.Crit("Failed to get key-value", "err", err)
Expand All @@ -22,6 +26,7 @@ func (s *Store) GetGenesisID() *hash.Hash {
return nil
}
val := hash.BytesToHash(valBytes)
s.cache.Genesis.Store(val)
return &val
}

Expand All @@ -38,6 +43,7 @@ func (s *Store) SetGenesisID(val hash.Hash) {
if err != nil {
s.Log.Crit("Failed to put key-value", "err", err)
}
s.cache.Genesis.Store(val)
}

// SetBlock stores chain block.
Expand Down

0 comments on commit ae496f1

Please sign in to comment.