@@ -289,7 +289,7 @@ type NodeBuilder struct {
289289 isSequencer bool
290290 takeOwnership bool
291291 withL1 bool
292- defaultDbScheme string
292+ defaultStateScheme string
293293 addresses * chaininfo.RollupAddresses
294294 l3Addresses * chaininfo.RollupAddresses
295295 initMessage * arbostypes.ParsedInitMessage
@@ -377,12 +377,27 @@ func (b *NodeBuilder) DefaultConfig(t *testing.T, withL1 bool) *NodeBuilder {
377377 b .l2StackConfig = testhelpers .CreateStackConfigForTest (b .dataDir )
378378 cp := valnode .TestValidationConfig
379379 b .valnodeConfig = & cp
380- b .defaultDbScheme = rawdb .HashScheme
380+ b .defaultStateScheme = rawdb .HashScheme
381381 if * testflag .StateSchemeFlag == rawdb .PathScheme || * testflag .StateSchemeFlag == rawdb .HashScheme {
382- b .defaultDbScheme = * testflag .StateSchemeFlag
382+ b .defaultStateScheme = * testflag .StateSchemeFlag
383383 }
384- b .execConfig = ExecConfigDefaultTest (t , b .defaultDbScheme )
384+ b .execConfig = ExecConfigDefaultTest (t , b .defaultStateScheme )
385385 b .l3Config = L3NitroConfigDefaultTest (t )
386+
387+ return b
388+ }
389+
390+ // Overrides the database selected with `--test_database_engine` flag
391+ //
392+ // Useful if the test needs a specific database engine to be used
393+ func (b * NodeBuilder ) WithDatabase (database string ) * NodeBuilder {
394+ if database != env .MemoryDB && database != rawdb .DBPebble && database != rawdb .DBLeveldb {
395+ panic ("unknown database engine: " + database )
396+ }
397+
398+ b .l1StackConfig .DBEngine = database
399+ b .l2StackConfig .DBEngine = database
400+ b .l3Config .stackConfig .DBEngine = database
386401 return b
387402}
388403
@@ -435,19 +450,19 @@ func (b *NodeBuilder) RequireScheme(t *testing.T, scheme string) *NodeBuilder {
435450 if testflag .StateSchemeFlag != nil && * testflag .StateSchemeFlag != "" && * testflag .StateSchemeFlag != scheme {
436451 t .Skip ("skipping because db scheme is set and not " , scheme )
437452 }
438- if b .defaultDbScheme != scheme && b .execConfig != nil {
453+ if b .defaultStateScheme != scheme && b .execConfig != nil {
439454 b .execConfig .Caching .StateScheme = scheme
440455 Require (t , b .execConfig .Validate ())
441456 }
442- b .defaultDbScheme = scheme
457+ b .defaultStateScheme = scheme
443458 return b
444459}
445460
446461func (b * NodeBuilder ) ExecConfigDefaultTest (t * testing.T , sequencer bool ) * gethexec.Config {
447462 if sequencer {
448- ExecConfigDefaultTest (t , b .defaultDbScheme )
463+ ExecConfigDefaultTest (t , b .defaultStateScheme )
449464 }
450- return ExecConfigDefaultNonSequencerTest (t , b .defaultDbScheme )
465+ return ExecConfigDefaultNonSequencerTest (t , b .defaultStateScheme )
451466}
452467
453468// WithL1ClientWrapper creates a ClientWrapper for the L1 RPC client before passing it to the L2 node.
@@ -584,8 +599,8 @@ func (b *NodeBuilder) CheckConfig(t *testing.T) {
584599 // validation currently requires hash
585600 b .RequireScheme (t , rawdb .HashScheme )
586601 }
587- if b .defaultDbScheme == "" {
588- b .defaultDbScheme = env .GetTestStateScheme ()
602+ if b .defaultStateScheme == "" {
603+ b .defaultStateScheme = env .GetTestStateScheme ()
589604 }
590605 if b .execConfig == nil {
591606 b .execConfig = b .ExecConfigDefaultTest (t , true )
@@ -615,7 +630,7 @@ func (b *NodeBuilder) BuildL1(t *testing.T) {
615630 t .Fatal (err )
616631 }
617632 b .L1 = NewTestClient (b .ctx )
618- b .L1Info , b .L1 .Client , b .L1 .L1Backend , b .L1 .Stack , b .L1 .ClientWrapper , b .L1 .L1BlobReader = createTestL1BlockChain (t , b .L1Info , b .withL1ClientWrapper )
633+ b .L1Info , b .L1 .Client , b .L1 .L1Backend , b .L1 .Stack , b .L1 .ClientWrapper , b .L1 .L1BlobReader = createTestL1BlockChain (t , b .L1Info , b .withL1ClientWrapper , b . l1StackConfig )
619634 locator , err := server_common .NewMachineLocator (b .valnodeConfig .Wasm .RootPath )
620635 Require (t , err )
621636 b .addresses , b .initMessage = deployOnParentChain (
@@ -1399,7 +1414,7 @@ func createTestValidationNode(t *testing.T, ctx context.Context, config *valnode
13991414 stackConf .WSModules = []string {server_api .Namespace }
14001415 stackConf .P2P .NoDiscovery = true
14011416 stackConf .P2P .ListenAddr = ""
1402- stackConf .DBEngine = "leveldb" // TODO Try pebble again in future once iterator race condition issues are fixed
1417+ stackConf .DBEngine = env . GetTestDatabaseEngine ()
14031418
14041419 valnode .EnsureValidationExposedViaAuthRPC (& stackConf )
14051420
@@ -1484,11 +1499,10 @@ func AddValNode(t *testing.T, ctx context.Context, nodeConfig *arbnode.Config, u
14841499 configByValidationNode (nodeConfig , valStack )
14851500}
14861501
1487- func createTestL1BlockChain (t * testing.T , l1info info , withClientWrapper bool ) (info , * ethclient.Client , * eth.Ethereum , * node.Node , * ClientWrapper , daprovider.BlobReader ) {
1502+ func createTestL1BlockChain (t * testing.T , l1info info , withClientWrapper bool , stackConfig * node. Config ) (info , * ethclient.Client , * eth.Ethereum , * node.Node , * ClientWrapper , daprovider.BlobReader ) {
14881503 if l1info == nil {
14891504 l1info = NewL1TestInfo (t )
14901505 }
1491- stackConfig := testhelpers .CreateStackConfigForTest ("" )
14921506 l1info .GenerateAccount ("Faucet" )
14931507 for _ , acct := range DefaultChainAccounts {
14941508 l1info .GenerateAccount (acct )
@@ -1497,6 +1511,7 @@ func createTestL1BlockChain(t *testing.T, l1info info, withClientWrapper bool) (
14971511 chainConfig := chaininfo .ArbitrumDevTestChainConfig ()
14981512 chainConfig .ArbitrumChainParams = params.ArbitrumChainParams {}
14991513
1514+ stackConfig .DataDir = ""
15001515 stack , err := node .New (stackConfig )
15011516 Require (t , err )
15021517
@@ -1738,15 +1753,23 @@ func createNonL1BlockChainWithStackConfig(
17381753 stack , err := node .New (stackConfig )
17391754 Require (t , err )
17401755
1741- chainData , err := stack .OpenDatabaseWithOptions ("l2chaindata" , node.DatabaseOptions {MetricsNamespace : "l2chaindata/" , PebbleExtraOptions : conf .PersistentConfigDefault .Pebble .ExtraOptions ("l2chaindata" )})
1742- Require (t , err )
1743-
1744- wasmData , err := stack .OpenDatabaseWithOptions ("wasm" , node.DatabaseOptions {MetricsNamespace : "wasm/" , PebbleExtraOptions : conf .PersistentConfigDefault .Pebble .ExtraOptions ("wasm" ), NoFreezer : true })
1745- Require (t , err )
1756+ chainData := rawdb .NewMemoryDatabase ()
1757+ if stack .Config ().DBEngine != env .MemoryDB {
1758+ chainData , err = stack .OpenDatabaseWithOptions ("l2chaindata" , node.DatabaseOptions {MetricsNamespace : "l2chaindata/" , PebbleExtraOptions : conf .PersistentConfigDefault .Pebble .ExtraOptions ("l2chaindata" )})
1759+ Require (t , err )
1760+ }
1761+ wasmData := rawdb .NewMemoryDatabase ()
1762+ if stack .Config ().DBEngine != env .MemoryDB {
1763+ wasmData , err = stack .OpenDatabaseWithOptions ("wasm" , node.DatabaseOptions {MetricsNamespace : "wasm/" , PebbleExtraOptions : conf .PersistentConfigDefault .Pebble .ExtraOptions ("wasm" ), NoFreezer : true })
1764+ Require (t , err )
1765+ }
17461766
17471767 chainDb := rawdb .WrapDatabaseWithWasm (chainData , wasmData )
1748- arbDb , err := stack .OpenDatabaseWithOptions ("arbitrumdata" , node.DatabaseOptions {MetricsNamespace : "arbitrumdata/" , PebbleExtraOptions : conf .PersistentConfigDefault .Pebble .ExtraOptions ("arbitrumdata" ), NoFreezer : true })
1749- Require (t , err )
1768+ arbDb := rawdb .NewMemoryDatabase ()
1769+ if stack .Config ().DBEngine != env .MemoryDB {
1770+ arbDb , err = stack .OpenDatabaseWithOptions ("arbitrumdata" , node.DatabaseOptions {MetricsNamespace : "arbitrumdata/" , PebbleExtraOptions : conf .PersistentConfigDefault .Pebble .ExtraOptions ("arbitrumdata" ), NoFreezer : true })
1771+ Require (t , err )
1772+ }
17501773
17511774 initReader := statetransfer .NewMemoryInitDataReader (& info .ArbInitData )
17521775 if initMessage == nil {
@@ -1836,14 +1859,23 @@ func Create2ndNodeWithConfig(
18361859 chainStack , err := node .New (stackConfig )
18371860 Require (t , err )
18381861
1839- chainData , err := chainStack .OpenDatabaseWithOptions ("l2chaindata" , node.DatabaseOptions {MetricsNamespace : "l2chaindata/" , PebbleExtraOptions : conf .PersistentConfigDefault .Pebble .ExtraOptions ("l2chaindata" )})
1840- Require (t , err )
1841- wasmData , err := chainStack .OpenDatabaseWithOptions ("wasm" , node.DatabaseOptions {MetricsNamespace : "wasm/" , PebbleExtraOptions : conf .PersistentConfigDefault .Pebble .ExtraOptions ("wasm" ), NoFreezer : true })
1842- Require (t , err )
1862+ chainData := rawdb .NewMemoryDatabase ()
1863+ if chainStack .Config ().DBEngine != env .MemoryDB {
1864+ chainData , err = chainStack .OpenDatabaseWithOptions ("l2chaindata" , node.DatabaseOptions {MetricsNamespace : "l2chaindata/" , PebbleExtraOptions : conf .PersistentConfigDefault .Pebble .ExtraOptions ("l2chaindata" )})
1865+ Require (t , err )
1866+ }
1867+ wasmData := rawdb .NewMemoryDatabase ()
1868+ if chainStack .Config ().DBEngine != env .MemoryDB {
1869+ wasmData , err = chainStack .OpenDatabaseWithOptions ("wasm" , node.DatabaseOptions {MetricsNamespace : "wasm/" , PebbleExtraOptions : conf .PersistentConfigDefault .Pebble .ExtraOptions ("wasm" ), NoFreezer : true })
1870+ Require (t , err )
1871+ }
18431872 chainDb := rawdb .WrapDatabaseWithWasm (chainData , wasmData )
18441873
1845- arbDb , err := chainStack .OpenDatabaseWithOptions ("arbitrumdata" , node.DatabaseOptions {MetricsNamespace : "arbitrumdata/" , PebbleExtraOptions : conf .PersistentConfigDefault .Pebble .ExtraOptions ("arbitrumdata" ), NoFreezer : true })
1846- Require (t , err )
1874+ arbDb := rawdb .NewMemoryDatabase ()
1875+ if chainStack .Config ().DBEngine != env .MemoryDB {
1876+ arbDb , err = chainStack .OpenDatabaseWithOptions ("arbitrumdata" , node.DatabaseOptions {MetricsNamespace : "arbitrumdata/" , PebbleExtraOptions : conf .PersistentConfigDefault .Pebble .ExtraOptions ("arbitrumdata" ), NoFreezer : true })
1877+ Require (t , err )
1878+ }
18471879 initReader := statetransfer .NewMemoryInitDataReader (chainInitData )
18481880
18491881 dataSigner := signature .DataSignerFromPrivateKey (parentChainInfo .GetInfoWithPrivKey ("Sequencer" ).PrivateKey )
0 commit comments