Skip to content

Commit

Permalink
gossip: refactor to pass getblock as func param instead of struct/int…
Browse files Browse the repository at this point in the history
…erface
  • Loading branch information
hadv committed Nov 8, 2021
1 parent 475f646 commit cf7fc51
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 13 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# MacOS
.DS_Store

# IDE
.vscode
.idea/
Expand Down Expand Up @@ -48,6 +51,7 @@ lachesis_*
*.graph
*.gv
*.finality
testnet.g

# Backup copies
*~
Expand Down
12 changes: 3 additions & 9 deletions gossip/evmstore/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,11 @@ import (

const nominalSize uint = 1

type ChainReader interface {
GetBlock(n idx.Block) *inter.Block
}

// Store is a node persistent storage working over physical key-value database.
type Store struct {
cfg StoreConfig

mainDB kvdb.Store
chain ChainReader
table struct {
// API-only tables
Receipts kvdb.Store `table:"r"`
Expand Down Expand Up @@ -77,11 +72,10 @@ const (
)

// NewStore creates store over key-value db.
func NewStore(mainDB kvdb.Store, chain ChainReader, cfg StoreConfig) *Store {
func NewStore(mainDB kvdb.Store, cfg StoreConfig) *Store {
s := &Store{
cfg: cfg,
mainDB: mainDB,
chain: chain,
Instance: logger.MakeInstance(),
rlp: rlpstore.Helper{logger.MakeInstance()},
triegc: prque.New(nil),
Expand Down Expand Up @@ -160,7 +154,7 @@ func (s *Store) Commit(block *evmcore.EvmBlock, genesis bool) error {
}
}

func (s *Store) Flush() {
func (s *Store) Flush(getBlock func(n idx.Block) *inter.Block) {
// Ensure that the entirety of the state snapshot is journalled to disk.
var snapBase common.Hash
if s.snaps != nil {
Expand All @@ -179,7 +173,7 @@ func (s *Store) Flush() {

for _, offset := range []uint64{0, 1, TriesInMemory - 1} {
if number := s.CurrentBlock().NumberU64(); number > offset {
recent := s.chain.GetBlock(idx.Block(number - offset))
recent := getBlock(idx.Block(number - offset))
s.Log.Info("Writing cached state to disk", "block", number-offset, "root", recent.Root)
if err := triedb.Commit(common.Hash(recent.Root), true, nil); err != nil {
s.Log.Error("Failed to commit recent state trie", "err", err)
Expand Down
4 changes: 2 additions & 2 deletions gossip/evmstore/store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ import (
func cachedStore() *Store {
cfg := LiteStoreConfig()

return NewStore(memorydb.New(), nil, cfg)
return NewStore(memorydb.New(), cfg)
}

func nonCachedStore() *Store {
cfg := StoreConfig{}

return NewStore(memorydb.New(), nil, cfg)
return NewStore(memorydb.New(), cfg)
}

func withDelay(db kvdb.DropableStore) kvdb.DropableStore {
Expand Down
2 changes: 1 addition & 1 deletion gossip/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@ func (s *Service) Stop() error {

s.blockProcWg.Wait()
close(s.blockProcTasksDone)
s.store.evm.Flush()
s.store.evm.Flush(s.store.GetBlock)
return s.store.Commit()
}

Expand Down
2 changes: 1 addition & 1 deletion gossip/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ func NewStore(dbs kvdb.FlushableDBProducer, cfg StoreConfig) *Store {
table.MigrateTables(&s.table, s.mainDB)

s.initCache()
s.evm = evmstore.NewStore(s.mainDB, s, cfg.EVM)
s.evm = evmstore.NewStore(s.mainDB, cfg.EVM)
s.sfcapi = sfcapi.NewStore(s.table.SfcAPI)

if err := s.migrateData(); err != nil {
Expand Down

0 comments on commit cf7fc51

Please sign in to comment.