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

Avoid '^triedb layer .+ is disk layer$' error #2588

Merged
merged 1 commit into from
Aug 19, 2024
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
10 changes: 9 additions & 1 deletion arbos/arbosState/initialize.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@ package arbosState
import (
"errors"
"math/big"
"regexp"
"sort"

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core"
"github.com/ethereum/go-ethereum/core/rawdb"
"github.com/ethereum/go-ethereum/core/state"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/ethdb"
Expand Down Expand Up @@ -64,6 +66,8 @@ func InitializeArbosInDatabase(db ethdb.Database, cacheConfig *core.CacheConfig,
log.Crit("failed to init empty statedb", "error", err)
}

noStateTrieChangesToCommitError := regexp.MustCompile("^triedb layer .+ is disk layer$")

// 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) {
Expand All @@ -73,7 +77,11 @@ func InitializeArbosInDatabase(db ethdb.Database, cacheConfig *core.CacheConfig,
}
err = stateDatabase.TrieDB().Commit(root, true)
if err != nil {
return common.Hash{}, err
// pathdb returns an error when there are no state trie changes to commit and we try to commit.
// This checks if the error is the expected one and ignores it.
if (cacheConfig.StateScheme != rawdb.PathScheme) || !noStateTrieChangesToCommitError.MatchString(err.Error()) {
return common.Hash{}, err
}
}
statedb, err = state.New(root, stateDatabase, nil)
if err != nil {
Expand Down
36 changes: 36 additions & 0 deletions cmd/nitro/init_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (
"github.com/offchainlabs/nitro/cmd/conf"
"github.com/offchainlabs/nitro/execution/gethexec"
"github.com/offchainlabs/nitro/util/testhelpers"
"github.com/offchainlabs/nitro/util/testhelpers/env"
)

const (
Expand Down Expand Up @@ -506,3 +507,38 @@ func TestPurgeVersion0WasmStoreEntries(t *testing.T) {
checkKeys(t, db, collidedKeys, true)
checkKeys(t, db, otherKeys, true)
}

func TestOpenInitializeChainDbEmptyInit(t *testing.T) {
t.Parallel()

ctx, cancel := context.WithCancel(context.Background())
defer cancel()

stackConfig := testhelpers.CreateStackConfigForTest(t.TempDir())
stack, err := node.New(stackConfig)
defer stack.Close()
Require(t, err)

nodeConfig := NodeConfigDefault
nodeConfig.Execution.Caching.StateScheme = env.GetTestStateScheme()
nodeConfig.Chain.ID = 42161
nodeConfig.Node = *arbnode.ConfigDefaultL2Test()
nodeConfig.Init.Empty = true

l1Client := ethclient.NewClient(stack.Attach())

chainDb, blockchain, err := openInitializeChainDb(
ctx,
stack,
&nodeConfig,
new(big.Int).SetUint64(nodeConfig.Chain.ID),
gethexec.DefaultCacheConfigFor(stack, &nodeConfig.Execution.Caching),
&nodeConfig.Persistent,
l1Client,
chaininfo.RollupAddresses{},
)
Require(t, err)
blockchain.Stop()
err = chainDb.Close()
Require(t, err)
}
Loading