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

[NIT-2479] - pathdb support for full nodes #2324

Merged
merged 43 commits into from
Jul 23, 2024
Merged
Show file tree
Hide file tree
Changes from 39 commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
ffe3a59
add pathdb related notes
magicxyyz May 8, 2024
3249cbb
adds --execution.caching.state-scheme command line flag
diegoximenes May 16, 2024
16ef283
use pathdb or hashdb according with command line flag
diegoximenes May 17, 2024
07eb983
use pathdb on memory backed state db
diegoximenes May 17, 2024
2d0e08c
StateHistory caching option
diegoximenes May 17, 2024
ab10d4c
define pathdb as the default state scheme to be used in tests
diegoximenes May 17, 2024
e8956ed
pathdb support in InitializeArbosInDatabase
diegoximenes May 20, 2024
e8c1b30
general improvements when testing state-scheme args
diegoximenes May 20, 2024
5364d39
recreate missing states fails if is executed with path scheme
diegoximenes May 20, 2024
1a15b72
add comment on why HashScheme is being used in setupProgramTest
diegoximenes May 20, 2024
a2bf331
gracefully fails if provided state scheme is incompatible with stored…
diegoximenes May 20, 2024
7c50868
fix challenger tests, some of them require hashdb by now
diegoximenes May 21, 2024
d30e66c
Closes stateDatabase.TrieDB() after finishing using it
diegoximenes May 23, 2024
3426e47
Removes DefaultTestCachingConfig
diegoximenes May 24, 2024
7477572
Only calls TrieDB.Commit once for PathScheme in InitializeArbosInData…
diegoximenes May 24, 2024
924fbef
Test for openInitializeChainDb
diegoximenes May 24, 2024
b1a6952
fix state-scheme flag usage
diegoximenes May 27, 2024
588d993
Fix tests.
diegoximenes Jun 17, 2024
cbf3656
use pebble instead of leveldb in CreateStackConfigForTest
diegoximenes Jun 13, 2024
54fc056
Gets state scheme to use in tests through an env var
diegoximenes Jun 14, 2024
6832aca
Runs tests with hash and path states scheme in github ci
diegoximenes Jun 14, 2024
cfb5947
Default Caching.StateHistory based on DefaultSequencerConfig.MaxBlock…
diegoximenes Jun 14, 2024
f6c9ca5
Adds copyright to init_test.go
diegoximenes Jun 14, 2024
3b1cd93
Adds comments regarding why using HashScheme for Archive tests
diegoximenes Jun 14, 2024
d9d3ffc
Adds missing word in comment
diegoximenes Jun 14, 2024
39e313d
Uses env var to define trie in NewMemoryBackedStateDB and NewArbosMem…
diegoximenes Jun 17, 2024
6cfde26
Do not create new error variables
diegoximenes Jul 8, 2024
ffda7a7
Runs race tests with hash and path schemes
diegoximenes Jul 8, 2024
875d815
Removes unncessary path logic when initializing arbos in database
diegoximenes Jul 12, 2024
e3a0460
By now -> For now
diegoximenes Jul 18, 2024
82c5ec7
Moves GetTestStateScheme to util/testhelpers/env
diegoximenes Jul 18, 2024
6256b5b
Do not WriteOrTestGenBlock when blockchain is not empty and using pat…
diegoximenes Jul 19, 2024
3379ab6
Fixes TrieDB().Close() error handling in InitializeArbosInDatabase
diegoximenes Jul 19, 2024
18575a7
Fixex github defaults test for hash scheme
diegoximenes Jul 19, 2024
2425295
Moves test configs from gethexec to system_tests
diegoximenes Jul 18, 2024
5993bc8
Fixes triedb import from geth
diegoximenes Jul 20, 2024
5736c56
Fixes ci, runs gotestsum package by package
diegoximenes Jul 22, 2024
fc900cc
Updates go-ethereum
diegoximenes Jul 22, 2024
6f04d12
Uses TriedbConfig from geth
diegoximenes Jul 22, 2024
97b5bda
Merge remote-tracking branch 'origin/master' into pathdb_fullnode
tsahee Jul 23, 2024
44a15ea
Merge branch 'master' into pathdb_fullnode
diegoximenes Jul 23, 2024
af590c3
Merge branch 'master' into pathdb_fullnode
diegoximenes Jul 23, 2024
3af4343
Merge branch 'master' into pathdb_fullnode
diegoximenes Jul 23, 2024
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
35 changes: 32 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,10 @@ jobs:
echo "GOMEMLIMIT=6GiB" >> "$GITHUB_ENV"
echo "GOGC=80" >> "$GITHUB_ENV"

- name: run tests without race detection
- name: run tests without race detection and path state scheme
if: matrix.test-mode == 'defaults'
env:
TEST_STATE_SCHEME: path
run: |
packages=`go list ./...`
for package in $packages; do
Expand All @@ -152,8 +154,23 @@ jobs:
fi
done

- name: run tests with race detection
- name: run tests without race detection and hash state scheme
diegoximenes marked this conversation as resolved.
Show resolved Hide resolved
if: matrix.test-mode == 'defaults'
env:
TEST_STATE_SCHEME: hash
run: |
packages=`go list ./...`
for package in $packages; do
echo running tests for $package
if ! stdbuf -oL gotestsum --format short-verbose --packages="$package" --rerun-fails=1 --no-color=false -- -timeout 20m -tags=cionly; then
exit 1
fi
done

- name: run tests with race detection and path state scheme
if: matrix.test-mode == 'race'
env:
TEST_STATE_SCHEME: path
run: |
packages=`go list ./...`
for package in $packages; do
Expand All @@ -163,6 +180,19 @@ jobs:
fi
done

- name: run tests with race detection and hash state scheme
if: matrix.test-mode == 'race'
env:
TEST_STATE_SCHEME: hash
run: |
packages=`go list ./...`
for package in $packages; do
echo running tests for $package
if ! stdbuf -oL gotestsum --format short-verbose --packages="$package" --rerun-fails=1 --no-color=false -- -race -timeout 30m; then
exit 1
fi
done

- name: run redis tests
if: matrix.test-mode == 'defaults'
run: TEST_REDIS=redis://localhost:6379/0 gotestsum --format short-verbose -- -p 1 -run TestRedis ./arbnode/... ./system_tests/... -coverprofile=coverage-redis.txt -covermode=atomic -coverpkg=./...
Expand Down Expand Up @@ -214,4 +244,3 @@ jobs:
files: ./coverage.txt,./coverage-redis.txt
verbose: false
token: ${{ secrets.CODECOV_TOKEN }}

4 changes: 3 additions & 1 deletion arbnode/inbox_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (

"github.com/offchainlabs/nitro/util/arbmath"
"github.com/offchainlabs/nitro/util/testhelpers"
"github.com/offchainlabs/nitro/util/testhelpers/env"

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core"
Expand Down Expand Up @@ -59,7 +60,8 @@ func NewTransactionStreamerForTest(t *testing.T, ownerAddress common.Address) (*
arbDb := rawdb.NewMemoryDatabase()
initReader := statetransfer.NewMemoryInitDataReader(&initData)

bc, err := gethexec.WriteOrTestBlockChain(chainDb, nil, initReader, chainConfig, arbostypes.TestInitMessage, gethexec.ConfigDefaultTest().TxLookupLimit, 0)
cacheConfig := core.DefaultCacheConfigWithScheme(env.GetTestStateScheme())
bc, err := gethexec.WriteOrTestBlockChain(chainDb, cacheConfig, initReader, chainConfig, arbostypes.TestInitMessage, gethexec.ConfigDefault.TxLookupLimit, 0)

if err != nil {
Fail(t, err)
Expand Down
10 changes: 9 additions & 1 deletion arbos/arbosState/arbosstate.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ import (
"github.com/ethereum/go-ethereum/core/vm"
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/params"
"github.com/ethereum/go-ethereum/triedb"
"github.com/ethereum/go-ethereum/triedb/hashdb"
"github.com/ethereum/go-ethereum/triedb/pathdb"

"github.com/offchainlabs/nitro/arbcompress"
"github.com/offchainlabs/nitro/arbos/addressSet"
Expand All @@ -29,6 +32,7 @@ import (
"github.com/offchainlabs/nitro/arbos/retryables"
"github.com/offchainlabs/nitro/arbos/storage"
"github.com/offchainlabs/nitro/arbos/util"
"github.com/offchainlabs/nitro/util/testhelpers/env"
)

// ArbosState contains ArbOS-related state. It is backed by ArbOS's storage in the persistent stateDB.
Expand Down Expand Up @@ -115,7 +119,11 @@ func OpenSystemArbosStateOrPanic(stateDB vm.StateDB, tracingInfo *util.TracingIn
// NewArbosMemoryBackedArbOSState creates and initializes a memory-backed ArbOS state (for testing only)
func NewArbosMemoryBackedArbOSState() (*ArbosState, *state.StateDB) {
raw := rawdb.NewMemoryDatabase()
db := state.NewDatabase(raw)
trieConfig := &triedb.Config{Preimages: false, PathDB: pathdb.Defaults}
if env.GetTestStateScheme() == rawdb.HashScheme {
trieConfig = &triedb.Config{Preimages: false, HashDB: hashdb.Defaults}
}
db := state.NewDatabaseWithConfig(raw, trieConfig)
statedb, err := state.New(common.Hash{}, db, nil)
if err != nil {
log.Crit("failed to init empty statedb", "error", err)
Expand Down
9 changes: 7 additions & 2 deletions arbos/arbosState/initialization_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,15 @@ import (
"testing"

"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/params"
"github.com/offchainlabs/nitro/arbos/arbostypes"
"github.com/offchainlabs/nitro/arbos/burn"
"github.com/offchainlabs/nitro/statetransfer"
"github.com/offchainlabs/nitro/util/testhelpers"
"github.com/offchainlabs/nitro/util/testhelpers/env"
)

func TestJsonMarshalUnmarshal(t *testing.T) {
Expand Down Expand Up @@ -60,10 +62,13 @@ func tryMarshalUnmarshal(input *statetransfer.ArbosInitializationInfo, t *testin

initReader := statetransfer.NewMemoryInitDataReader(&initData)
chainConfig := params.ArbitrumDevTestChainConfig()
stateroot, err := InitializeArbosInDatabase(raw, initReader, chainConfig, arbostypes.TestInitMessage, 0, 0)

cacheConfig := core.DefaultCacheConfigWithScheme(env.GetTestStateScheme())
stateroot, err := InitializeArbosInDatabase(raw, cacheConfig, initReader, chainConfig, arbostypes.TestInitMessage, 0, 0)
Require(t, err)

stateDb, err := state.New(stateroot, state.NewDatabase(raw), nil)
triedbConfig := cacheConfig.TriedbConfig()
stateDb, err := state.New(stateroot, state.NewDatabaseWithConfig(raw, triedbConfig), nil)
Require(t, err)

arbState, err := OpenArbosState(stateDb, &burn.SystemBurner{})
Expand Down
12 changes: 10 additions & 2 deletions arbos/arbosState/initialize.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"sort"

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core"
"github.com/ethereum/go-ethereum/core/state"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/ethdb"
Expand Down Expand Up @@ -51,13 +52,20 @@ func MakeGenesisBlock(parentHash common.Hash, blockNumber uint64, timestamp uint
return types.NewBlock(head, nil, nil, nil, trie.NewStackTrie(nil))
}

func InitializeArbosInDatabase(db ethdb.Database, initData statetransfer.InitDataReader, chainConfig *params.ChainConfig, initMessage *arbostypes.ParsedInitMessage, timestamp uint64, accountsPerSync uint) (common.Hash, error) {
stateDatabase := state.NewDatabase(db)
func InitializeArbosInDatabase(db ethdb.Database, cacheConfig *core.CacheConfig, initData statetransfer.InitDataReader, chainConfig *params.ChainConfig, initMessage *arbostypes.ParsedInitMessage, timestamp uint64, accountsPerSync uint) (root common.Hash, err error) {
triedbConfig := cacheConfig.TriedbConfig()
triedbConfig.Preimages = false
stateDatabase := state.NewDatabaseWithConfig(db, triedbConfig)
defer func() {
err = errors.Join(err, stateDatabase.TrieDB().Close())
}()
statedb, err := state.New(common.Hash{}, stateDatabase, nil)
if err != nil {
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 {
Expand Down
14 changes: 12 additions & 2 deletions arbos/storage/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,13 @@ import (
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/params"
"github.com/ethereum/go-ethereum/triedb"
"github.com/ethereum/go-ethereum/triedb/hashdb"
"github.com/ethereum/go-ethereum/triedb/pathdb"
"github.com/offchainlabs/nitro/arbos/burn"
"github.com/offchainlabs/nitro/arbos/util"
"github.com/offchainlabs/nitro/util/arbmath"
"github.com/offchainlabs/nitro/util/testhelpers/env"
)

// Storage allows ArbOS to store data persistently in the Ethereum-compatible stateDB. This is represented in
Expand Down Expand Up @@ -73,15 +77,21 @@ func NewGeth(statedb vm.StateDB, burner burn.Burner) *Storage {
}
}

// NewMemoryBacked uses Geth's memory-backed database to create an evm key-value store
// NewMemoryBacked uses Geth's memory-backed database to create an evm key-value store.
// Only used for testing.
func NewMemoryBacked(burner burn.Burner) *Storage {
return NewGeth(NewMemoryBackedStateDB(), burner)
}

// NewMemoryBackedStateDB uses Geth's memory-backed database to create a statedb
// Only used for testing.
func NewMemoryBackedStateDB() vm.StateDB {
diegoximenes marked this conversation as resolved.
Show resolved Hide resolved
raw := rawdb.NewMemoryDatabase()
db := state.NewDatabase(raw)
trieConfig := &triedb.Config{Preimages: false, PathDB: pathdb.Defaults}
if env.GetTestStateScheme() == rawdb.HashScheme {
trieConfig = &triedb.Config{Preimages: false, HashDB: hashdb.Defaults}
}
db := state.NewDatabaseWithConfig(raw, trieConfig)
statedb, err := state.New(common.Hash{}, db, nil)
if err != nil {
panic("failed to init empty statedb")
Expand Down
19 changes: 19 additions & 0 deletions cmd/nitro/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,31 @@ func TestUnsafeStakerConfig(t *testing.T) {
Require(t, err)
}

const validatorArgs = "--persistent.chain /tmp/data --init.dev-init --node.parent-chain-reader.enable=false --parent-chain.id 5 --chain.id 421613 --node.staker.parent-chain-wallet.pathname /l1keystore --node.staker.parent-chain-wallet.password passphrase --http.addr 0.0.0.0 --ws.addr 0.0.0.0 --node.staker.enable --node.staker.strategy MakeNodes --node.staker.staker-interval 10s --execution.forwarding-target null"

func TestValidatorConfig(t *testing.T) {
args := strings.Split("--persistent.chain /tmp/data --init.dev-init --node.parent-chain-reader.enable=false --parent-chain.id 5 --chain.id 421613 --node.staker.parent-chain-wallet.pathname /l1keystore --node.staker.parent-chain-wallet.password passphrase --http.addr 0.0.0.0 --ws.addr 0.0.0.0 --node.staker.enable --node.staker.strategy MakeNodes --node.staker.staker-interval 10s --execution.forwarding-target null", " ")
_, _, err := ParseNode(context.Background(), args)
Require(t, err)
}

func TestInvalidCachingStateSchemeForValidator(t *testing.T) {
validatorArgsWithPathScheme := fmt.Sprintf("%s --execution.caching.state-scheme path", validatorArgs)
args := strings.Split(validatorArgsWithPathScheme, " ")
_, _, err := ParseNode(context.Background(), args)
if !strings.Contains(err.Error(), "path cannot be used as execution.caching.state-scheme when validator is required") {
Fail(t, "failed to detect invalid state scheme for validator")
}
}

func TestInvalidArchiveConfig(t *testing.T) {
args := strings.Split("--execution.caching.archive --execution.caching.state-scheme path --persistent.chain /tmp/data --init.dev-init --node.parent-chain-reader.enable=false --parent-chain.id 5 --chain.id 421613 --node.staker.parent-chain-wallet.pathname /l1keystore --node.staker.parent-chain-wallet.password passphrase --http.addr 0.0.0.0 --ws.addr 0.0.0.0 --node.staker.enable --node.staker.strategy MakeNodes --node.staker.staker-interval 10s --execution.forwarding-target null", " ")
_, _, err := ParseNode(context.Background(), args)
if !strings.Contains(err.Error(), "archive cannot be set when using path as the state-scheme") {
Fail(t, "failed to detect invalid state scheme for archive")
}
}

func TestAggregatorConfig(t *testing.T) {
args := strings.Split("--persistent.chain /tmp/data --init.dev-init --node.parent-chain-reader.enable=false --parent-chain.id 5 --chain.id 421613 --node.batch-poster.parent-chain-wallet.pathname /l1keystore --node.batch-poster.parent-chain-wallet.password passphrase --http.addr 0.0.0.0 --ws.addr 0.0.0.0 --node.sequencer --execution.sequencer.enable --node.feed.output.enable --node.feed.output.port 9642 --node.data-availability.enable --node.data-availability.rpc-aggregator.backends [{\"url\":\"http://localhost:8547\",\"pubkey\":\"abc==\"}]", " ")
_, _, err := ParseNode(context.Background(), args)
Expand Down
12 changes: 12 additions & 0 deletions cmd/nitro/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,10 @@ func openInitializeChainDb(ctx context.Context, stack *node.Node, config *NodeCo
return nil, nil, err
}
chainDb := rawdb.WrapDatabaseWithWasm(chainData, wasmDb, 1)
_, err = rawdb.ParseStateScheme(cacheConfig.StateScheme, chainDb)
if err != nil {
return nil, nil, err
}
err = pruning.PruneChainDb(ctx, chainDb, stack, &config.Init, cacheConfig, persistentConfig, l1Client, rollupAddrs, config.Node.ValidatorRequired())
if err != nil {
return chainDb, nil, fmt.Errorf("error pruning: %w", err)
Expand Down Expand Up @@ -533,6 +537,10 @@ func openInitializeChainDb(ctx context.Context, stack *node.Node, config *NodeCo
return nil, nil, err
}
chainDb := rawdb.WrapDatabaseWithWasm(chainData, wasmDb, 1)
_, err = rawdb.ParseStateScheme(cacheConfig.StateScheme, chainDb)
if err != nil {
return nil, nil, err
}

// Rebuilding wasm store is not required when just starting out
err = gethexec.WriteToKeyValueStore(wasmDb, gethexec.RebuildingPositionKey, gethexec.RebuildingDone)
Expand Down Expand Up @@ -673,6 +681,10 @@ func openInitializeChainDb(ctx context.Context, stack *node.Node, config *NodeCo
log.Warn("Created fake init message as L1Reader is disabled and serialized chain config from init message is not available", "json", string(serializedChainConfig))
}

emptyBlockChain := rawdb.ReadHeadHeader(chainDb) == nil
if !emptyBlockChain && (cacheConfig.StateScheme == rawdb.PathScheme) && config.Init.Force {
return chainDb, nil, errors.New("It is not possible to force init with non-empty blockchain when using path scheme")
}
l2BlockChain, err = gethexec.WriteOrTestBlockChain(chainDb, cacheConfig, initDataReader, chainConfig, parsedInitMessage, config.Execution.TxLookupLimit, config.Init.AccountsPerSync)
if err != nil {
return chainDb, nil, err
Expand Down
77 changes: 76 additions & 1 deletion cmd/nitro/init_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2021-2022, Offchain Labs, Inc.
// Copyright 2021-2024, Offchain Labs, Inc.
// For license information, see https://github.com/nitro/blob/master/LICENSE

package main
Expand All @@ -10,6 +10,7 @@ import (
"encoding/hex"
"errors"
"fmt"
"math/big"
"net"
"net/http"
"os"
Expand All @@ -19,8 +20,13 @@ import (
"testing"
"time"

"github.com/ethereum/go-ethereum/core/rawdb"
"github.com/ethereum/go-ethereum/ethclient"
"github.com/ethereum/go-ethereum/node"
"github.com/offchainlabs/nitro/arbnode"
"github.com/offchainlabs/nitro/cmd/chaininfo"
"github.com/offchainlabs/nitro/cmd/conf"
"github.com/offchainlabs/nitro/execution/gethexec"
"github.com/offchainlabs/nitro/util/testhelpers"
)

Expand Down Expand Up @@ -361,3 +367,72 @@ func TestEmptyDatabaseDir(t *testing.T) {
})
}
}

func TestOpenInitializeChainDbIncompatibleStateScheme(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 = rawdb.PathScheme
nodeConfig.Chain.ID = 42161
nodeConfig.Node = *arbnode.ConfigDefaultL2Test()
nodeConfig.Init.DevInit = true
nodeConfig.Init.DevInitAddress = "0x3f1Eae7D46d88F08fc2F8ed27FCb2AB183EB2d0E"

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

// opening for the first time doesn't error
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)

// opening for the second time doesn't error
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)

// opening with a different state scheme errors
nodeConfig.Execution.Caching.StateScheme = rawdb.HashScheme
_, _, err = openInitializeChainDb(
ctx,
stack,
&nodeConfig,
new(big.Int).SetUint64(nodeConfig.Chain.ID),
gethexec.DefaultCacheConfigFor(stack, &nodeConfig.Execution.Caching),
&nodeConfig.Persistent,
l1Client,
chaininfo.RollupAddresses{},
)
if !strings.Contains(err.Error(), "incompatible state scheme, stored: path, provided: hash") {
t.Fatalf("Failed to detect incompatible state scheme")
}
}
4 changes: 4 additions & 0 deletions cmd/nitro/nitro.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import (
"github.com/ethereum/go-ethereum/accounts/keystore"
"github.com/ethereum/go-ethereum/arbitrum"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/rawdb"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/crypto"
_ "github.com/ethereum/go-ethereum/eth/tracers/js"
Expand Down Expand Up @@ -836,6 +837,9 @@ func (c *NodeConfig) Validate() error {
if err := c.BlocksReExecutor.Validate(); err != nil {
return err
}
if c.Node.ValidatorRequired() && (c.Execution.Caching.StateScheme == rawdb.PathScheme) {
return errors.New("path cannot be used as execution.caching.state-scheme when validator is required")
}
return c.Persistent.Validate()
}

Expand Down
Loading
Loading