-
Notifications
You must be signed in to change notification settings - Fork 464
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
abe368b
commit f06ff8e
Showing
5 changed files
with
120 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
// Copyright 2021-2024, Offchain Labs, Inc. | ||
// For license information, see https://github.com/nitro/blob/master/LICENSE | ||
|
||
package main | ||
|
||
import ( | ||
"context" | ||
"math/big" | ||
"strings" | ||
"testing" | ||
|
||
"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/execution/gethexec" | ||
"github.com/offchainlabs/nitro/util/testhelpers" | ||
) | ||
|
||
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() | ||
// force InitializeArbosInDatabase to be tested | ||
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") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// Copyright 2021-2024, Offchain Labs, Inc. | ||
// For license information, see https://github.com/nitro/blob/master/LICENSE | ||
|
||
package testhelpers | ||
|
||
import "github.com/ethereum/go-ethereum/node" | ||
|
||
func CreateStackConfigForTest(dataDir string) *node.Config { | ||
stackConf := node.DefaultConfig | ||
stackConf.DataDir = dataDir | ||
stackConf.UseLightweightKDF = true | ||
stackConf.WSPort = 0 | ||
stackConf.WSModules = append(stackConf.WSModules, "eth", "debug") | ||
stackConf.HTTPPort = 0 | ||
stackConf.HTTPHost = "" | ||
stackConf.HTTPModules = append(stackConf.HTTPModules, "eth", "debug") | ||
stackConf.P2P.NoDiscovery = true | ||
stackConf.P2P.NoDial = true | ||
stackConf.P2P.ListenAddr = "" | ||
stackConf.P2P.NAT = nil | ||
stackConf.DBEngine = "leveldb" // TODO Try pebble again in future once iterator race condition issues are fixed | ||
return &stackConf | ||
} |