From 92f6404cd77ab859d63611d6c6c17db7e9f3c568 Mon Sep 17 00:00:00 2001 From: Maciej Kulawik Date: Wed, 11 Oct 2023 16:07:27 +0200 Subject: [PATCH 1/8] add triedb race test --- system_tests/triedb_race_test.go | 83 ++++++++++++++++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 system_tests/triedb_race_test.go diff --git a/system_tests/triedb_race_test.go b/system_tests/triedb_race_test.go new file mode 100644 index 0000000000..468997b181 --- /dev/null +++ b/system_tests/triedb_race_test.go @@ -0,0 +1,83 @@ +package arbtest + +import ( + "context" + "sync" + "testing" + "time" + + "github.com/ethereum/go-ethereum/arbitrum" + "github.com/ethereum/go-ethereum/common" + "github.com/ethereum/go-ethereum/log" + "github.com/ethereum/go-ethereum/rpc" + "github.com/offchainlabs/nitro/arbnode" + "github.com/offchainlabs/nitro/util/testhelpers" +) + +func TestTrieDBCommitRace(t *testing.T) { + _ = testhelpers.InitTestLog(t, log.LvlError) + ctx, cancel := context.WithCancel(context.Background()) + defer cancel() + nodeConfig := arbnode.ConfigDefaultL1Test() + nodeConfig.RPC.MaxRecreateStateDepth = arbitrum.InfiniteMaxRecreateStateDepth + nodeConfig.Sequencer.MaxBlockSpeed = 0 + nodeConfig.Sequencer.MaxTxDataSize = 150 // 1 test tx ~= 110 + nodeConfig.Caching.Archive = true + nodeConfig.Caching.BlockCount = 127 + nodeConfig.Caching.BlockAge = 0 + nodeConfig.Caching.MaxNumberOfBlocksToSkipStateSaving = 127 + nodeConfig.Caching.MaxAmountOfGasToSkipStateSaving = 0 + l2info, node, l2client, _, _, _, l1stack := createTestNodeOnL1WithConfig(t, ctx, true, nodeConfig, nil, nil) + cancel = func() { + defer requireClose(t, l1stack) + defer node.StopAndWait() + } + defer cancel() + l2info.GenerateAccount("User2") + bc := node.Execution.Backend.ArbInterface().BlockChain() + + var wg sync.WaitGroup + quit := make(chan struct{}) + wg.Add(1) + go func() { + defer wg.Done() + for { + select { + default: + TransferBalance(t, "Faucet", "User2", common.Big1, l2info, l2client, ctx) + case <-quit: + return + } + } + }() + api := node.Execution.Backend.APIBackend() + blockNumber := 1 + for i := 0; i < 5; i++ { + var roots []common.Hash + for len(roots) < 1024 { + select { + default: + block, err := api.BlockByNumber(ctx, rpc.BlockNumber(blockNumber)) + if err == nil && block != nil { + root := block.Root() + if statedb, err := bc.StateAt(root); err == nil { + err := statedb.Database().TrieDB().Reference(root, common.Hash{}) + Require(t, err) + roots = append(roots, root) + } + blockNumber += 1 + } + case <-quit: + return + } + } + t.Log("dereferencing...") + for _, root := range roots { + err := bc.TrieDB().Dereference(root) + Require(t, err) + time.Sleep(1) + } + } + close(quit) + wg.Wait() +} From 4800578c7de4da406adcf0dbac99d722284b84dd Mon Sep 17 00:00:00 2001 From: Maciej Kulawik Date: Wed, 11 Oct 2023 16:08:13 +0200 Subject: [PATCH 2/8] improve test configs in recreatestate_rpc_test --- system_tests/recreatestate_rpc_test.go | 28 ++++++++++---------------- 1 file changed, 11 insertions(+), 17 deletions(-) diff --git a/system_tests/recreatestate_rpc_test.go b/system_tests/recreatestate_rpc_test.go index dbf68c8479..33dde05781 100644 --- a/system_tests/recreatestate_rpc_test.go +++ b/system_tests/recreatestate_rpc_test.go @@ -95,9 +95,8 @@ func TestRecreateStateForRPCNoDepthLimit(t *testing.T) { nodeConfig.Sequencer.MaxBlockSpeed = 0 nodeConfig.Sequencer.MaxTxDataSize = 150 // 1 test tx ~= 110 nodeConfig.Caching.Archive = true - // disable caching of states in BlockChain.stateCache + // disable trie/Database.cleans cache, so as states removed from ChainDb won't be cached there nodeConfig.Caching.TrieCleanCache = 0 - nodeConfig.Caching.TrieDirtyCache = 0 nodeConfig.Caching.MaxNumberOfBlocksToSkipStateSaving = 0 nodeConfig.Caching.MaxAmountOfGasToSkipStateSaving = 0 _, execNode, l2client, cancelNode := prepareNodeWithHistory(t, ctx, nodeConfig, 32) @@ -119,7 +118,6 @@ func TestRecreateStateForRPCNoDepthLimit(t *testing.T) { if balance.Cmp(expectedBalance) != 0 { Fatal(t, "unexpected balance result for last block, want: ", expectedBalance, " have: ", balance) } - } func TestRecreateStateForRPCBigEnoughDepthLimit(t *testing.T) { @@ -131,9 +129,8 @@ func TestRecreateStateForRPCBigEnoughDepthLimit(t *testing.T) { nodeConfig.Sequencer.MaxBlockSpeed = 0 nodeConfig.Sequencer.MaxTxDataSize = 150 // 1 test tx ~= 110 nodeConfig.Caching.Archive = true - // disable caching of states in BlockChain.stateCache + // disable trie/Database.cleans cache, so as states removed from ChainDb won't be cached there nodeConfig.Caching.TrieCleanCache = 0 - nodeConfig.Caching.TrieDirtyCache = 0 nodeConfig.Caching.MaxNumberOfBlocksToSkipStateSaving = 0 nodeConfig.Caching.MaxAmountOfGasToSkipStateSaving = 0 _, execNode, l2client, cancelNode := prepareNodeWithHistory(t, ctx, nodeConfig, 32) @@ -166,9 +163,8 @@ func TestRecreateStateForRPCDepthLimitExceeded(t *testing.T) { nodeConfig.Sequencer.MaxBlockSpeed = 0 nodeConfig.Sequencer.MaxTxDataSize = 150 // 1 test tx ~= 110 nodeConfig.Caching.Archive = true - // disable caching of states in BlockChain.stateCache + // disable trie/Database.cleans cache, so as states removed from ChainDb won't be cached there nodeConfig.Caching.TrieCleanCache = 0 - nodeConfig.Caching.TrieDirtyCache = 0 nodeConfig.Caching.MaxNumberOfBlocksToSkipStateSaving = 0 nodeConfig.Caching.MaxAmountOfGasToSkipStateSaving = 0 _, execNode, l2client, cancelNode := prepareNodeWithHistory(t, ctx, nodeConfig, 32) @@ -201,9 +197,8 @@ func TestRecreateStateForRPCMissingBlockParent(t *testing.T) { nodeConfig.Sequencer.MaxBlockSpeed = 0 nodeConfig.Sequencer.MaxTxDataSize = 150 // 1 test tx ~= 110 nodeConfig.Caching.Archive = true - // disable caching of states in BlockChain.stateCache + // disable trie/Database.cleans cache, so as states removed from ChainDb won't be cached there nodeConfig.Caching.TrieCleanCache = 0 - nodeConfig.Caching.TrieDirtyCache = 0 nodeConfig.Caching.MaxNumberOfBlocksToSkipStateSaving = 0 nodeConfig.Caching.MaxAmountOfGasToSkipStateSaving = 0 _, execNode, l2client, cancelNode := prepareNodeWithHistory(t, ctx, nodeConfig, headerCacheLimit+5) @@ -247,9 +242,8 @@ func TestRecreateStateForRPCBeyondGenesis(t *testing.T) { nodeConfig.Sequencer.MaxBlockSpeed = 0 nodeConfig.Sequencer.MaxTxDataSize = 150 // 1 test tx ~= 110 nodeConfig.Caching.Archive = true - // disable caching of states in BlockChain.stateCache + // disable trie/Database.cleans cache, so as states removed from ChainDb won't be cached there nodeConfig.Caching.TrieCleanCache = 0 - nodeConfig.Caching.TrieDirtyCache = 0 nodeConfig.Caching.MaxNumberOfBlocksToSkipStateSaving = 0 nodeConfig.Caching.MaxAmountOfGasToSkipStateSaving = 0 _, execNode, l2client, cancelNode := prepareNodeWithHistory(t, ctx, nodeConfig, 32) @@ -283,9 +277,9 @@ func TestRecreateStateForRPCBlockNotFoundWhileRecreating(t *testing.T) { nodeConfig.Sequencer.MaxBlockSpeed = 0 nodeConfig.Sequencer.MaxTxDataSize = 150 // 1 test tx ~= 110 nodeConfig.Caching.Archive = true - // disable caching of states in BlockChain.stateCache + // disable trie/Database.cleans cache, so as states removed from ChainDb won't be cached there nodeConfig.Caching.TrieCleanCache = 0 - nodeConfig.Caching.TrieDirtyCache = 0 + nodeConfig.Caching.MaxNumberOfBlocksToSkipStateSaving = 0 nodeConfig.Caching.MaxAmountOfGasToSkipStateSaving = 0 _, execNode, l2client, cancelNode := prepareNodeWithHistory(t, ctx, nodeConfig, blockCacheLimit+4) @@ -412,6 +406,9 @@ func testSkippingSavingStateAndRecreatingAfterRestart(t *testing.T, cacheConfig } for i := genesis + 1; i <= genesis+uint64(txCount); i += i % 10 { _, err = client.BalanceAt(ctx, GetTestAddressForAccountName(t, "User2"), new(big.Int).SetUint64(i)) + if err != nil { + t.Log("skipBlocks:", skipBlocks, "skipGas:", skipGas) + } Require(t, err) } @@ -425,10 +422,7 @@ func testSkippingSavingStateAndRecreatingAfterRestart(t *testing.T, cacheConfig func TestSkippingSavingStateAndRecreatingAfterRestart(t *testing.T) { cacheConfig := execution.DefaultCachingConfig cacheConfig.Archive = true - // disable caching of states in BlockChain.stateCache - cacheConfig.TrieCleanCache = 0 - cacheConfig.TrieDirtyCache = 0 - // test defaults + //// test defaults testSkippingSavingStateAndRecreatingAfterRestart(t, &cacheConfig, 512) cacheConfig.MaxNumberOfBlocksToSkipStateSaving = 127 From ebfd141982e5f79867a4c5a398524d0c78ecbebb Mon Sep 17 00:00:00 2001 From: Maciej Kulawik Date: Wed, 11 Oct 2023 16:41:53 +0200 Subject: [PATCH 3/8] fix triedb_race_test --- system_tests/triedb_race_test.go | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/system_tests/triedb_race_test.go b/system_tests/triedb_race_test.go index 468997b181..8174a9b6a2 100644 --- a/system_tests/triedb_race_test.go +++ b/system_tests/triedb_race_test.go @@ -10,7 +10,7 @@ import ( "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/log" "github.com/ethereum/go-ethereum/rpc" - "github.com/offchainlabs/nitro/arbnode" + "github.com/offchainlabs/nitro/execution/gethexec" "github.com/offchainlabs/nitro/util/testhelpers" ) @@ -18,23 +18,24 @@ func TestTrieDBCommitRace(t *testing.T) { _ = testhelpers.InitTestLog(t, log.LvlError) ctx, cancel := context.WithCancel(context.Background()) defer cancel() - nodeConfig := arbnode.ConfigDefaultL1Test() - nodeConfig.RPC.MaxRecreateStateDepth = arbitrum.InfiniteMaxRecreateStateDepth - nodeConfig.Sequencer.MaxBlockSpeed = 0 - nodeConfig.Sequencer.MaxTxDataSize = 150 // 1 test tx ~= 110 - nodeConfig.Caching.Archive = true - nodeConfig.Caching.BlockCount = 127 - nodeConfig.Caching.BlockAge = 0 - nodeConfig.Caching.MaxNumberOfBlocksToSkipStateSaving = 127 - nodeConfig.Caching.MaxAmountOfGasToSkipStateSaving = 0 - l2info, node, l2client, _, _, _, l1stack := createTestNodeOnL1WithConfig(t, ctx, true, nodeConfig, nil, nil) + execConfig := gethexec.ConfigDefaultTest() + execConfig.RPC.MaxRecreateStateDepth = arbitrum.InfiniteMaxRecreateStateDepth + execConfig.Sequencer.MaxBlockSpeed = 0 + execConfig.Sequencer.MaxTxDataSize = 150 // 1 test tx ~= 110 + execConfig.Caching.Archive = true + execConfig.Caching.BlockCount = 127 + execConfig.Caching.BlockAge = 0 + execConfig.Caching.MaxNumberOfBlocksToSkipStateSaving = 127 + execConfig.Caching.MaxAmountOfGasToSkipStateSaving = 0 + l2info, node, l2client, _, _, _, l1stack := createTestNodeOnL1WithConfig(t, ctx, true, nil, execConfig, nil, nil) cancel = func() { defer requireClose(t, l1stack) defer node.StopAndWait() } defer cancel() + execNode := getExecNode(t, node) l2info.GenerateAccount("User2") - bc := node.Execution.Backend.ArbInterface().BlockChain() + bc := execNode.Backend.ArbInterface().BlockChain() var wg sync.WaitGroup quit := make(chan struct{}) @@ -50,7 +51,7 @@ func TestTrieDBCommitRace(t *testing.T) { } } }() - api := node.Execution.Backend.APIBackend() + api := execNode.Backend.APIBackend() blockNumber := 1 for i := 0; i < 5; i++ { var roots []common.Hash From 89a44158d0cff35e2fe692f0a18dbc2fe30e0b39 Mon Sep 17 00:00:00 2001 From: Maciej Kulawik Date: Wed, 11 Oct 2023 16:55:11 +0200 Subject: [PATCH 4/8] set ParentChainReader default config in gethexec.ConfigDefaultTest --- execution/gethexec/node.go | 1 + 1 file changed, 1 insertion(+) diff --git a/execution/gethexec/node.go b/execution/gethexec/node.go index 1068dda967..8b3874729e 100644 --- a/execution/gethexec/node.go +++ b/execution/gethexec/node.go @@ -109,6 +109,7 @@ func ConfigDefaultTest() *Config { config := ConfigDefault config.Sequencer = TestSequencerConfig config.ForwardingTarget = "null" + config.ParentChainReader = headerreader.TestConfig _ = config.Validate() From df6d1dc4816db2c29b3c825db64381a7af075006 Mon Sep 17 00:00:00 2001 From: Maciej Kulawik Date: Wed, 11 Oct 2023 17:03:23 +0200 Subject: [PATCH 5/8] update geth to version with triedb race fix --- go-ethereum | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/go-ethereum b/go-ethereum index b4221631e1..7c1903db73 160000 --- a/go-ethereum +++ b/go-ethereum @@ -1 +1 @@ -Subproject commit b4221631e1e5eac86f01582bd74234e3c0f7f5c7 +Subproject commit 7c1903db73f835fab4cc39f963ceeda6da46d44e From e935a24b545d1573a15d0e6714d19c0062a507a1 Mon Sep 17 00:00:00 2001 From: Maciej Kulawik Date: Wed, 11 Oct 2023 18:58:07 +0200 Subject: [PATCH 6/8] update geth --- go-ethereum | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/go-ethereum b/go-ethereum index 7c1903db73..89540b1440 160000 --- a/go-ethereum +++ b/go-ethereum @@ -1 +1 @@ -Subproject commit 7c1903db73f835fab4cc39f963ceeda6da46d44e +Subproject commit 89540b1440179a851e5e29672a700851c4237d83 From 5e75c666aaee3c10ffbdcbafa372718258824585 Mon Sep 17 00:00:00 2001 From: Maciej Kulawik Date: Wed, 11 Oct 2023 19:09:51 +0200 Subject: [PATCH 7/8] update geth --- go-ethereum | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/go-ethereum b/go-ethereum index 89540b1440..3573250ade 160000 --- a/go-ethereum +++ b/go-ethereum @@ -1 +1 @@ -Subproject commit 89540b1440179a851e5e29672a700851c4237d83 +Subproject commit 3573250adec48511a0bc45647061ed6d25c4ae35 From 36b722ce7db3a2a7b44c78bd47dea912eba24049 Mon Sep 17 00:00:00 2001 From: Maciej Kulawik Date: Thu, 12 Oct 2023 12:47:37 +0200 Subject: [PATCH 8/8] update geth --- go-ethereum | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/go-ethereum b/go-ethereum index 3573250ade..202caf5bf9 160000 --- a/go-ethereum +++ b/go-ethereum @@ -1 +1 @@ -Subproject commit 3573250adec48511a0bc45647061ed6d25c4ae35 +Subproject commit 202caf5bf944835ef78b4d7c4ba8b48bdc54d65d