Skip to content

Commit

Permalink
Merge pull request #2073 from OffchainLabs/fix-pruning-test
Browse files Browse the repository at this point in the history
Fix starting second node in pruning system test
  • Loading branch information
magicxyyz authored Jan 29, 2024
2 parents 3cb5f77 + 964b3a9 commit b16a3b5
Showing 1 changed file with 64 additions and 34 deletions.
98 changes: 64 additions & 34 deletions system_tests/pruning_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@ package arbtest
import (
"context"
"testing"
"time"

"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/ethdb"
"github.com/ethereum/go-ethereum/node"
"github.com/ethereum/go-ethereum/trie"
"github.com/offchainlabs/nitro/cmd/conf"
"github.com/offchainlabs/nitro/cmd/pruning"
"github.com/offchainlabs/nitro/execution/gethexec"
Expand All @@ -32,35 +34,34 @@ func TestPruning(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()

var dataDir string

func() {
builder := NewNodeBuilder(ctx).DefaultConfig(t, true)
_ = builder.Build(t)
dataDir = builder.dataDir
l2cleanupDone := false
defer func() {
if !l2cleanupDone {
builder.L2.cleanup()
}
builder.L1.cleanup()
}()
builder.L2Info.GenerateAccount("User2")
var txs []*types.Transaction
for i := uint64(0); i < 200; i++ {
tx := builder.L2Info.PrepareTx("Owner", "User2", builder.L2Info.TransferGas, common.Big1, nil)
txs = append(txs, tx)
err := builder.L2.Client.SendTransaction(ctx, tx)
Require(t, err)
}
for _, tx := range txs {
_, err := builder.L2.EnsureTxSucceeded(tx)
Require(t, err)
builder := NewNodeBuilder(ctx).DefaultConfig(t, true)
_ = builder.Build(t)
l2cleanupDone := false
defer func() {
if !l2cleanupDone {
builder.L2.cleanup()
}
l2cleanupDone = true
builder.L2.cleanup()
t.Log("stopped l2 node")
builder.L1.cleanup()
}()
builder.L2Info.GenerateAccount("User2")
var txs []*types.Transaction
for i := uint64(0); i < 200; i++ {
tx := builder.L2Info.PrepareTx("Owner", "User2", builder.L2Info.TransferGas, common.Big1, nil)
txs = append(txs, tx)
err := builder.L2.Client.SendTransaction(ctx, tx)
Require(t, err)
}
for _, tx := range txs {
_, err := builder.L2.EnsureTxSucceeded(tx)
Require(t, err)
}
lastBlock, err := builder.L2.Client.BlockNumber(ctx)
Require(t, err)
l2cleanupDone = true
builder.L2.cleanup()
t.Log("stopped l2 node")

func() {
stack, err := node.New(builder.l2StackConfig)
Require(t, err)
defer stack.Close()
Expand Down Expand Up @@ -105,15 +106,44 @@ func TestPruning(t *testing.T) {
Fatal(t, "The db doesn't have less entries after pruning then before. Before:", chainDbEntriesBeforePruning, "After:", chainDbEntriesAfterPruning)
}
}()
builder := NewNodeBuilder(ctx).DefaultConfig(t, true)
builder.dataDir = dataDir
cancel = builder.Build(t)
defer cancel()

builder.L2Info.GenerateAccount("User2")
testClient, cleanup := builder.Build2ndNode(t, &SecondNodeParams{stackConfig: builder.l2StackConfig})
defer cleanup()

currentBlock := uint64(0)
// wait for the chain to catch up
for currentBlock < lastBlock {
currentBlock, err = testClient.Client.BlockNumber(ctx)
Require(t, err)
time.Sleep(20 * time.Millisecond)
}

currentBlock, err = testClient.Client.BlockNumber(ctx)
Require(t, err)
bc := testClient.ExecNode.Backend.ArbInterface().BlockChain()
triedb := bc.StateCache().TrieDB()
var start uint64
if currentBlock+1 >= builder.execConfig.Caching.BlockCount {
start = currentBlock + 1 - builder.execConfig.Caching.BlockCount
} else {
start = 0
}
for i := start; i <= currentBlock; i++ {
header := bc.GetHeaderByNumber(i)
_, err := bc.StateAt(header.Root)
Require(t, err)
tr, err := trie.New(trie.TrieID(header.Root), triedb)
Require(t, err)
it, err := tr.NodeIterator(nil)
Require(t, err)
for it.Next(true) {
}
Require(t, it.Error())
}

tx := builder.L2Info.PrepareTx("Owner", "User2", builder.L2Info.TransferGas, common.Big1, nil)
err := builder.L2.Client.SendTransaction(ctx, tx)
err = testClient.Client.SendTransaction(ctx, tx)
Require(t, err)
_, err = builder.L2.EnsureTxSucceeded(tx)
_, err = testClient.EnsureTxSucceeded(tx)
Require(t, err)
}

0 comments on commit b16a3b5

Please sign in to comment.