Skip to content

Commit

Permalink
Only calls TrieDB.Commit once for PathScheme in InitializeArbosInData…
Browse files Browse the repository at this point in the history
…base
  • Loading branch information
diegoximenes committed May 24, 2024
1 parent 0ad8f0b commit abe368b
Showing 1 changed file with 22 additions and 4 deletions.
26 changes: 22 additions & 4 deletions arbos/arbosState/initialize.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,14 +84,21 @@ func InitializeArbosInDatabase(db ethdb.Database, cacheConfig *core.CacheConfig,
log.Crit("failed to init empty statedb", "error", err)
}

// commit avoids keeping the entire state in memory while importing the state.
// At some time it was also used to avoid reprocessing the whole import in case of a crash.
commit := func() (common.Hash, error) {
root, err := statedb.Commit(chainConfig.ArbitrumChainParams.GenesisBlockNum, true)
if err != nil {
return common.Hash{}, err
}
err = stateDatabase.TrieDB().Commit(root, true)
if err != nil {
return common.Hash{}, err
// When using PathScheme TrieDB.Commit should only be called once.
// When using HashScheme it is called multiple times to avoid keeping
// the entire trie in memory.
if cacheConfig.StateScheme == rawdb.HashScheme {
err = stateDatabase.TrieDB().Commit(root, true)
if err != nil {
return common.Hash{}, err
}
}
statedb, err = state.New(root, stateDatabase, nil)
if err != nil {
Expand Down Expand Up @@ -189,7 +196,18 @@ func InitializeArbosInDatabase(db ethdb.Database, cacheConfig *core.CacheConfig,
if err := accountDataReader.Close(); err != nil {
return common.Hash{}, err
}
return commit()

root, err = commit()
if err != nil {
return common.Hash{}, err
}
if cacheConfig.StateScheme == rawdb.PathScheme {
err = stateDatabase.TrieDB().Commit(root, true)
if err != nil {
return common.Hash{}, err
}
}
return root, nil
}

func initializeRetryables(statedb *state.StateDB, rs *retryables.RetryableState, initData statetransfer.RetryableDataReader, currentTimestamp uint64) error {
Expand Down

0 comments on commit abe368b

Please sign in to comment.