Skip to content

Commit 51f1f14

Browse files
committed
add fast node to test
1 parent 81e7371 commit 51f1f14

File tree

2 files changed

+37
-19
lines changed

2 files changed

+37
-19
lines changed

e2e_test/e2e_test.go

+16-8
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515
"github.com/celo-org/celo-blockchain/common"
1616
"github.com/celo-org/celo-blockchain/common/hexutil"
1717
"github.com/celo-org/celo-blockchain/core/types"
18+
"github.com/celo-org/celo-blockchain/eth/downloader"
1819
"github.com/celo-org/celo-blockchain/eth/tracers"
1920
"github.com/celo-org/celo-blockchain/log"
2021
"github.com/celo-org/celo-blockchain/mycelo/env"
@@ -392,15 +393,19 @@ func runStopNetworkAtL2BlockTest(ctx context.Context, t *testing.T, network test
392393
func TestStopNetworkAtl2BlockSimple(t *testing.T) {
393394
numValidators := 3
394395
numFullNodes := 2
396+
numFastNodes := 1
395397
ac := test.AccountConfig(numValidators, 2)
396398
gingerbreadBlock := common.Big0
397399
l2BlockOG := big.NewInt(3)
398400
gc, ec, err := test.BuildConfig(ac, gingerbreadBlock, l2BlockOG)
399401
require.NoError(t, err)
400402
network, _, err := test.NewNetwork(ac, gc, ec)
401403
require.NoError(t, err)
402-
network, shutdown, err := test.AddNetworkFullNodes(network, ec, uint64(numFullNodes))
404+
network, _, err = test.AddNonValidatorNodes(network, ec, uint64(numFullNodes), downloader.FullSync)
403405
require.NoError(t, err)
406+
network, shutdown, err := test.AddNonValidatorNodes(network, ec, uint64(numFastNodes), downloader.FastSync)
407+
require.NoError(t, err)
408+
404409
defer shutdown()
405410

406411
ctx, cancel := context.WithTimeout(context.Background(), time.Second*40)
@@ -412,15 +417,19 @@ func TestStopNetworkAtl2BlockSimple(t *testing.T) {
412417
func TestStopNetworkAtL2Block(t *testing.T) {
413418
numValidators := 3
414419
numFullNodes := 2
420+
numFastNodes := 1
415421
ac := test.AccountConfig(numValidators, 2)
416422
gingerbreadBlock := common.Big0
417423
l2BlockOG := big.NewInt(3)
418424
gc, ec, err := test.BuildConfig(ac, gingerbreadBlock, l2BlockOG)
419425
require.NoError(t, err)
420426
network, _, err := test.NewNetwork(ac, gc, ec)
421427
require.NoError(t, err)
422-
network, shutdown, err := test.AddNetworkFullNodes(network, ec, uint64(numFullNodes))
428+
network, _, err = test.AddNonValidatorNodes(network, ec, uint64(numFullNodes), downloader.FullSync)
423429
require.NoError(t, err)
430+
network, shutdown, err := test.AddNonValidatorNodes(network, ec, uint64(numFastNodes), downloader.FastSync)
431+
require.NoError(t, err)
432+
424433
defer shutdown()
425434

426435
ctx, cancel := context.WithTimeout(context.Background(), time.Second*400)
@@ -431,7 +440,7 @@ func TestStopNetworkAtL2Block(t *testing.T) {
431440
shutdown()
432441

433442
// Restart nodes with --l2-migration-block set to the next block
434-
err = network.RestartNetworkWithMigrationBlockOffsets(l2BlockOG, []int64{1, 1, 1, 1, 1})
443+
err = network.RestartNetworkWithMigrationBlockOffsets(l2BlockOG, []int64{1, 1, 1, 1, 1, 1})
435444
require.NoError(t, err)
436445

437446
l2BlockPlusOne := new(big.Int).Add(l2BlockOG, big.NewInt(1))
@@ -441,7 +450,7 @@ func TestStopNetworkAtL2Block(t *testing.T) {
441450
shutdown()
442451

443452
// Restart nodes with --l2-migration-block set to the same block
444-
err = network.RestartNetworkWithMigrationBlockOffsets(l2BlockOG, []int64{1, 1, 1, 1, 1})
453+
err = network.RestartNetworkWithMigrationBlockOffsets(l2BlockOG, []int64{1, 1, 1, 1, 1, 1})
445454
require.NoError(t, err)
446455

447456
runStopNetworkAtL2BlockTest(ctx, t, network, l2BlockPlusOne)
@@ -451,7 +460,7 @@ func TestStopNetworkAtL2Block(t *testing.T) {
451460
// Restart nodes with different --l2-migration-block offsets
452461
// If 2/3 validators (validators are the first 3 nodes in the network array)
453462
// have the same migration block, the network should not be able to add any more blocks
454-
err = network.RestartNetworkWithMigrationBlockOffsets(l2BlockOG, []int64{1, 1, 2, 2, 2})
463+
err = network.RestartNetworkWithMigrationBlockOffsets(l2BlockOG, []int64{1, 1, 2, 2, 2, 2})
455464
require.NoError(t, err)
456465

457466
runStopNetworkAtL2BlockTest(ctx, t, network, l2BlockPlusOne)
@@ -461,7 +470,7 @@ func TestStopNetworkAtL2Block(t *testing.T) {
461470
// Restart nodes with different --l2-migration-block offsets
462471
// If 2/3 validators (validators are the first 3 nodes in the network array)
463472
// have a greater migration block, the rest of the network should be able to add more blocks
464-
err = network.RestartNetworkWithMigrationBlockOffsets(l2BlockOG, []int64{1, 2, 2, 2, 2})
473+
err = network.RestartNetworkWithMigrationBlockOffsets(l2BlockOG, []int64{1, 2, 2, 2, 2, 2})
465474
require.NoError(t, err)
466475

467476
l2BlockPlusTwo := new(big.Int).Add(l2BlockOG, big.NewInt(2))
@@ -472,8 +481,7 @@ func TestStopNetworkAtL2Block(t *testing.T) {
472481
shutdown()
473482

474483
// Restart nodes with --l2-migration-block set to a prev block
475-
err = network.RestartNetworkWithMigrationBlockOffsets(l2BlockOG, []int64{-1, -1, -1, -1, -1})
476-
// TODO(Alec) it would actually be nice to return errors here, require.Error(t, err, core.ErrL2Migration.Error())
484+
err = network.RestartNetworkWithMigrationBlockOffsets(l2BlockOG, []int64{-1, -1, -1, -1, -1, -1})
477485
require.NoError(t, err)
478486

479487
// The network should be unchanged

test/node.go

+21-11
Original file line numberDiff line numberDiff line change
@@ -111,11 +111,12 @@ type Node struct {
111111
SentTxs []*types.Transaction
112112
}
113113

114-
// NewFullNode creates a new running (non-validator) node with the provided config.
115-
func NewFullNode(
114+
// NewNonValidatorNode creates a new running non-validator node with the provided config.
115+
func NewNonValidatorNode(
116116
nc *node.Config,
117117
ec *eth.Config,
118118
genesis *core.Genesis,
119+
syncmode downloader.SyncMode,
119120
) (*Node, error) {
120121

121122
// Copy the node config so we can modify it without damaging the original
@@ -145,6 +146,14 @@ func NewFullNode(
145146
ecCopy.Genesis = genesis
146147
ecCopy.NetworkId = genesis.Config.ChainID.Uint64()
147148
ecCopy.Istanbul.Validator = false
149+
ecCopy.SyncMode = syncmode
150+
151+
// We set these values here to avoid a panic in the eth service when these values are unset during fast sync
152+
if syncmode == downloader.FastSync {
153+
ecCopy.TrieCleanCache = 5
154+
ecCopy.TrieDirtyCache = 5
155+
ecCopy.SnapshotCache = 5
156+
}
148157

149158
node := &Node{
150159
Config: &ncCopy,
@@ -500,25 +509,26 @@ func NewNetwork(accounts *env.AccountsConfig, gc *genesis.Config, ec *eth.Config
500509
return network, shutdown, nil
501510
}
502511

503-
func AddNetworkFullNodes(network Network, ec *eth.Config, numFullNodes uint64) (Network, func(), error) {
504-
var fullNodes Network = make([]*Node, numFullNodes)
512+
// AddNonValidatorNodes Adds non-validator nodes to the network with the specified sync mode.
513+
func AddNonValidatorNodes(network Network, ec *eth.Config, numNodes uint64, syncmode downloader.SyncMode) (Network, func(), error) {
514+
var nodes Network = make([]*Node, numNodes)
505515
genesis := network[0].EthConfig.Genesis
506516

507-
for i := uint64(0); i < numFullNodes; i++ {
508-
n, err := NewFullNode(baseNodeConfig, ec, genesis)
517+
for i := uint64(0); i < numNodes; i++ {
518+
n, err := NewNonValidatorNode(baseNodeConfig, ec, genesis, syncmode)
509519
if err != nil {
510520
return nil, nil, fmt.Errorf("failed to build full node for network: %v", err)
511521
}
512-
fullNodes[i] = n
522+
nodes[i] = n
513523
}
514524

515525
// Connect nodes to each other
516-
for i := range fullNodes {
517-
fullNodes[i].AddPeers(network...)
518-
fullNodes[i].AddPeers(fullNodes[i+1:]...)
526+
for i := range nodes {
527+
nodes[i].AddPeers(network...)
528+
nodes[i].AddPeers(nodes[i+1:]...)
519529
}
520530

521-
network = append(network, fullNodes...)
531+
network = append(network, nodes...)
522532

523533
// Give nodes some time to connect. Also there is a race condition in
524534
// miner.worker its field snapshotBlock is set only when new transactions

0 commit comments

Comments
 (0)