Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cache for genesis ID #334

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -13,6 +13,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 @@ -21,6 +25,7 @@ func (s *Store) GetGenesisID() *hash.Hash {
return nil
}
val := hash.BytesToHash(valBytes)
s.cache.Genesis.Store(val)
return &val
}

Expand All @@ -29,6 +34,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