Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
alecps committed Aug 15, 2024
1 parent 1bec584 commit 356528c
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 10 deletions.
2 changes: 1 addition & 1 deletion core/blockchain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ func TestNoInsertPastL2MigrationBlock(t *testing.T) {
migrationBlock := 2
blockchain.chainConfig.L2MigrationBlock = big.NewInt(int64(migrationBlock))

blocks := makeBlockChain(blockchain.CurrentBlock(), 100, mockEngine.NewFullFaker(), blockchain.db, 0)
blocks := makeBlockChain(blockchain.CurrentBlock(), 100000000, mockEngine.NewFullFaker(), blockchain.db, 0)
failedBlock, err := blockchain.InsertChain(blocks)
require.EqualError(t, err, errInsertionInterrupted.Error())
require.EqualValues(t, migrationBlock-1, failedBlock)
Expand Down
3 changes: 3 additions & 0 deletions core/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ var (
ErrNoGenesis = errors.New("genesis not found in chain")

errSideChainReceipts = errors.New("side blocks can't be accepted as ancient chain data")

// ErrL2Migration is returned when the current block is greater than or equal to the L2 migration block
ErrL2Migration = errors.New("chain has migrated to L2, data exists beyond the configured migration block")
)

// List of evm-call-message pre-checking errors. All state transition messages will
Expand Down
38 changes: 30 additions & 8 deletions e2e_test/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,29 @@ func TestStopNetworkAtl2BlockSimple(t *testing.T) {
testStopNetworkAtL2Block(t, ctx, network, l2BlockOG)
}

/*
Test cases for stopping at L2 migration block:
- [x] (cli/demo) node is syncing, not-validating, hits migration block
- [X] (cli/demo) node restarts with same --l2migrationblock, does not produce new blocks
- [x] (cli/demo) node restarts with --l2migrationblock + 1, produces one new block
- [X] (cli/demo) node restarts with --l2migrationblock - 1, does not produce new blocks, keeps current head at previous migration block, logs error message
- [x] (e2e test) node is synced and following chain, not-validating, hits migration block
- [x] (e2e test) node restarts with same --l2migrationblock, does not produce new blocks
- [x] (e2e test) node restarts with --l2migrationblock + 1, produces one new block
- [x] (e2e test) node restarts with --l2migrationblock - 1, does not produce new blocks, keeps current head at previous migration block, logs error message
- [skip? Is this worth testing?] node is syncing, validating, hits migration block
- [skip?] node restarts with same --l2migrationblock, does not produce new blocks
- [skip?] node restarts with --l2migrationblock + 1, produces one new block
- [skip?] node restarts with --l2migrationblock - 1, does not produce new blocks, keeps current head at previous migration block, logs error message
- [x] (e2e test) node is synced and following chain, validating, hits migration block
- [x] (e2e test) node restarts with same --l2migrationblock, does not produce new blocks
- [x] (e2e test) node restarts with --l2migrationblock + 1, produces one new block
- [x] (e2e test) node restarts with --l2migrationblock - 1, does not produce new blocks, keeps current head at previous migration block, logs error message
- [x] (e2e test) Thresholds - when majority of validators are at migration block, full nodes CANNOT progress even if they have a higher number configured
- [x] (e2e test) Thresholds - when minority of validators are at migration block, full nodes CAN progress if they have a higher number configured
*/

func TestStopNetworkAtL2Block(t *testing.T) {
numValidators := 3
numFullNodes := 2
Expand Down Expand Up @@ -472,17 +495,16 @@ func TestStopNetworkAtL2Block(t *testing.T) {
testStopNetworkAtL2Block(t, ctx, network[:1], l2BlockPlusOne)
testStopNetworkAtL2Block(t, ctx, network[1:], l2BlockPlusTwo)

// TODO(Alec)

// shutdown()
shutdown()

// Restart nodes with --l2-migration-block set to a prev block
// err = network.RestartNetworkWithMigrationBlockOffsets(l2BlockOG, []int64{-1, -1, -1, -1, -1})
// require.NoError(t, err) // TODO(Alec)

// l2BlockMinusOne := new(big.Int).Sub(l2BlockOG, big.NewInt(1))
err = network.RestartNetworkWithMigrationBlockOffsets(l2BlockOG, []int64{-1, -1, -1, -1, -1})
// TODO(Alec) it would actually be nice to return errors here, require.Error(t, err, core.ErrL2Migration.Error())
require.NoError(t, err)

// testStopNetworkAtL2Block(t, ctx, network, l2BlockMinusOne)
// The network should be unchanged
testStopNetworkAtL2Block(t, ctx, network[:1], l2BlockPlusOne)
testStopNetworkAtL2Block(t, ctx, network[1:], l2BlockPlusTwo)
}

// This test was created to reproduce the concurrent map access error in
Expand Down
6 changes: 5 additions & 1 deletion test/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -581,13 +581,17 @@ func (n Network) RestartNetworkWithMigrationBlockOffsets(l2MigrationBlockOG *big
return fmt.Errorf("number of l2BlockMigration offsets must match number of nodes")
}

errors := []error{}
for i, node := range n {
node.EthConfig.L2MigrationBlock = new(big.Int).Add(l2MigrationBlockOG, big.NewInt(offsets[i]))
err := node.Start()
if err != nil {
return err
errors = append(errors, err)
}
}
if len(errors) > 0 {
return fmt.Errorf("failed to restart network: %v", errors)
}

for i, node := range n {
node.AddPeers(n[:i]...)
Expand Down

0 comments on commit 356528c

Please sign in to comment.