From 38e969f1072f5f8d7dff11f4acb6d5af543fc59b Mon Sep 17 00:00:00 2001 From: Egor Lysenko Date: Tue, 21 Jun 2022 17:31:20 +0400 Subject: [PATCH] add cache for genesis ID --- gossip/service.go | 1 + gossip/store.go | 1 + gossip/store_block.go | 6 ++++++ 3 files changed, 8 insertions(+) diff --git a/gossip/service.go b/gossip/service.go index e3129cfb1..267c2b135 100644 --- a/gossip/service.go +++ b/gossip/service.go @@ -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() diff --git a/gossip/store.go b/gossip/store.go index 8c71884ef..1da5fe89f 100644 --- a/gossip/store.go +++ b/gossip/store.go @@ -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 { diff --git a/gossip/store_block.go b/gossip/store_block.go index 16e873c58..7e7840f8d 100644 --- a/gossip/store_block.go +++ b/gossip/store_block.go @@ -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) @@ -21,6 +25,7 @@ func (s *Store) GetGenesisID() *hash.Hash { return nil } val := hash.BytesToHash(valBytes) + s.cache.Genesis.Store(val) return &val } @@ -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.