Skip to content

Commit

Permalink
add e2e test, saving progress
Browse files Browse the repository at this point in the history
  • Loading branch information
alecps committed Aug 5, 2024
1 parent 41ebaec commit 21e324f
Show file tree
Hide file tree
Showing 13 changed files with 112 additions and 37 deletions.
22 changes: 22 additions & 0 deletions cmd/geth/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,28 @@ func startNode(ctx *cli.Context, stack *node.Node, backend ethapi.Backend) {
}
}()

// if ctx.GlobalIsSet(utils.L2ForkFlag.Name) {
// go func() {
// sub := stack.EventMux().Subscribe(ethCore.ChainHeadEvent{})
// defer sub.Unsubscribe()
// for {
// event := <-sub.Chan()
// if event == nil {
// continue
// }
// var latest *types.Header
// if done, ok := event.Data.(ethCore.ChainHeadEvent); ok {
// latest = done.Block.Header()
// }

// if ctx.GlobalUint64(utils.L2ForkFlag.Name) >= latest.Number.Uint64() {
// log.Info("L2 Migration Block Reached", "latest", latest.Number.Uint64(), "latesthash", latest.Hash())
// stack.Close()
// }
// }
// }()
// }

// Spawn a standalone goroutine for status synchronization monitoring,
// close the node when synchronization is complete if user required.
if ctx.GlobalBool(utils.ExitWhenSyncedFlag.Name) {
Expand Down
10 changes: 6 additions & 4 deletions consensus/istanbul/backend/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -554,9 +554,11 @@ func (sb *Backend) Commit(proposal istanbul.Proposal, aggregatedSeal types.Istan
}
}
sb.onNewConsensusBlock(block, result.Receipts, result.Logs, result.State)

if sb.chain.Config().IsL2(block.Number()) {
sb.logger.Info("L2 hard fork reached, stopping the backend")
sb.StopValidating()
sb.Close()
//sb.core.Stop()
}
return nil
}
Expand All @@ -576,9 +578,9 @@ func (sb *Backend) Verify(proposal istanbul.Proposal) (*istanbulCore.StateProces
}

// Don't verify blocks after the L2 hard fork
if sb.chain.Config().IsL2(block.Number()) {
return nil, 0, core.ErrPostL2BlockNumber
}
// if sb.chain.Config().IsL2(block.Number()) {
// return nil, 0, core.ErrPostL2BlockNumber
// }

// check bad block
if sb.hasBadProposal(block.Hash()) {
Expand Down
2 changes: 1 addition & 1 deletion consensus/istanbul/backend/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -1058,7 +1058,7 @@ func (sb *Backend) SetStartValidatingBlock(blockNumber *big.Int) error {
}

// SetStopValidatingBlock sets the block that the validator will stop just before (exclusive range)
func (sb *Backend) SetStopValidatingBlock(blockNumber *big.Int) error { // TODO(Alec) code pointer
func (sb *Backend) SetStopValidatingBlock(blockNumber *big.Int) error {
if sb.replicaState == nil {
return errNotAValidator
}
Expand Down
6 changes: 6 additions & 0 deletions core/blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -811,6 +811,12 @@ func (bc *BlockChain) ExportN(w io.Writer, first uint64, last uint64) error {
//
// Note, this function assumes that the `mu` mutex is held!
func (bc *BlockChain) writeHeadBlock(block *types.Block) {
if bc.Config().IsL2(block.Number()) {
log.Info("L2 hard fork reached, stopping the blockchain")
bc.StopInsert()
// bc.Stop()
bc.Engine().Close()
}
// If the block is on a side chain or an unknown one, force other heads onto it too
updateHeads := rawdb.ReadCanonicalHash(bc.db, block.NumberU64()) != block.Hash()

Expand Down
6 changes: 3 additions & 3 deletions core/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,9 +207,9 @@ func SetupGenesisBlockWithOverride(db ethdb.Database, genesis *Genesis, override
if overrideHFork != nil {
newcfg.HForkBlock = overrideHFork
}
if l2Fork != nil {
newcfg.L2Block = l2Fork
}
// if l2Fork != nil {
// newcfg.L2Block = l2Fork
// }
if err := newcfg.CheckConfigForkOrder(); err != nil {
return newcfg, common.Hash{}, err
}
Expand Down
4 changes: 2 additions & 2 deletions e2e_test/e2e_bench_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func BenchmarkNet100EmptyBlocks(b *testing.B) {
for i := 0; i < b.N; i++ {
ac := test.AccountConfig(n, 0)
gingerbreadBlock := common.Big0
gc, ec, err := test.BuildConfig(ac, gingerbreadBlock)
gc, ec, err := test.BuildConfig(ac, gingerbreadBlock, nil)
require.NoError(b, err)
network, shutdown, err := test.NewNetwork(ac, gc, ec)
require.NoError(b, err)
Expand All @@ -45,7 +45,7 @@ func BenchmarkNet1000Txs(b *testing.B) {

ac := test.AccountConfig(n, n)
gingerbreadBlock := common.Big0
gc, ec, err := test.BuildConfig(ac, gingerbreadBlock)
gc, ec, err := test.BuildConfig(ac, gingerbreadBlock, nil)
require.NoError(b, err)
accounts := test.Accounts(ac.DeveloperAccounts(), gc.ChainConfig())
network, shutdown, err := test.NewNetwork(ac, gc, ec)
Expand Down
80 changes: 60 additions & 20 deletions e2e_test/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func init() {
func TestSendCelo(t *testing.T) {
ac := test.AccountConfig(3, 2)
gingerbreadBlock := common.Big0
gc, ec, err := test.BuildConfig(ac, gingerbreadBlock)
gc, ec, err := test.BuildConfig(ac, gingerbreadBlock, nil)
require.NoError(t, err)
network, shutdown, err := test.NewNetwork(ac, gc, ec)
require.NoError(t, err)
Expand All @@ -71,7 +71,7 @@ func TestSendCelo(t *testing.T) {
func TestTraceSendCeloViaGoldToken(t *testing.T) {
ac := test.AccountConfig(3, 2)
gingerbreadBlock := common.Big0
gc, ec, err := test.BuildConfig(ac, gingerbreadBlock)
gc, ec, err := test.BuildConfig(ac, gingerbreadBlock, nil)
require.NoError(t, err)
network, shutdown, err := test.NewNetwork(ac, gc, ec)
require.NoError(t, err)
Expand Down Expand Up @@ -108,7 +108,7 @@ func TestTraceSendCeloViaGoldToken(t *testing.T) {
func TestCallTraceTransactionNativeTransfer(t *testing.T) {
ac := test.AccountConfig(1, 2)
gingerbreadBlock := common.Big0
gc, ec, err := test.BuildConfig(ac, gingerbreadBlock)
gc, ec, err := test.BuildConfig(ac, gingerbreadBlock, nil)
require.NoError(t, err)
network, shutdown, err := test.NewNetwork(ac, gc, ec)
require.NoError(t, err)
Expand Down Expand Up @@ -146,7 +146,7 @@ func TestCallTraceTransactionNativeTransfer(t *testing.T) {
func TestPrestateTransactionNativeTransfer(t *testing.T) {
ac := test.AccountConfig(1, 2)
gingerbreadBlock := common.Big0
gc, ec, err := test.BuildConfig(ac, gingerbreadBlock)
gc, ec, err := test.BuildConfig(ac, gingerbreadBlock, nil)
require.NoError(t, err)
network, shutdown, err := test.NewNetwork(ac, gc, ec)
require.NoError(t, err)
Expand Down Expand Up @@ -184,7 +184,7 @@ func TestSingleNodeNetworkManyTxs(t *testing.T) {
txsPerIteration := 5
ac := test.AccountConfig(1, 1)
gingerbreadBlock := common.Big0
gc, ec, err := test.BuildConfig(ac, gingerbreadBlock)
gc, ec, err := test.BuildConfig(ac, gingerbreadBlock, nil)
require.NoError(t, err)
gc.Istanbul.Epoch = uint64(iterations) * 50 // avoid the epoch for this test
network, shutdown, err := test.NewNetwork(ac, gc, ec)
Expand All @@ -210,7 +210,7 @@ func TestSingleNodeNetworkManyTxs(t *testing.T) {
func TestEpochBlockMarshaling(t *testing.T) {
accounts := test.AccountConfig(1, 0)
gingerbreadBlock := common.Big0
gc, ec, err := test.BuildConfig(accounts, gingerbreadBlock)
gc, ec, err := test.BuildConfig(accounts, gingerbreadBlock, nil)
require.NoError(t, err)

// Configure the shortest possible epoch, uptimeLookbackWindow minimum is 3
Expand Down Expand Up @@ -240,7 +240,7 @@ func TestEpochBlockMarshaling(t *testing.T) {
func TestStartStopValidators(t *testing.T) {
ac := test.AccountConfig(4, 2)
gingerbreadBlock := common.Big0
gc, ec, err := test.BuildConfig(ac, gingerbreadBlock)
gc, ec, err := test.BuildConfig(ac, gingerbreadBlock, nil)
require.NoError(t, err)
network, _, err := test.NewNetwork(ac, gc, ec)
require.NoError(t, err)
Expand Down Expand Up @@ -369,6 +369,46 @@ func TestStartStopValidators(t *testing.T) {

}

// TODO(Alec)
func TestStopNetworkAtL2Block(t *testing.T) {
ac := test.AccountConfig(3, 2)
gingerbreadBlock := common.Big0
l2Block := big.NewInt(2)
gc, ec, err := test.BuildConfig(ac, gingerbreadBlock, l2Block)
require.NoError(t, err)
network, _, err := test.NewNetwork(ac, gc, ec)
require.NoError(t, err)

// We define our own shutdown function because we don't want to print
// errors about already stopped nodes. Since this test can fail while we
// have stopped nodes.
defer func() {
for _, err := range network.Shutdown() {
if !errors.Is(err, test.ErrTrackerAlreadyStopped) && !errors.Is(err, node.ErrNodeStopped) {
fmt.Println(err.Error())
}
}
}()

ctx, cancel := context.WithTimeout(context.Background(), time.Second*200)
defer cancel()

err = network.AwaitBlock(ctx, l2Block.Uint64())
require.NoError(t, err)

// err = network.AwaitBlock(ctx, l2Block.Uint64())
// require.NoError(t, err)

shortCtx, cancel := context.WithTimeout(context.Background(), time.Second*3)
defer cancel()

err = network.AwaitBlock(shortCtx, l2Block.Uint64()+1)
// Expect DeadlineExceeded error
if !errors.Is(err, context.DeadlineExceeded) {
t.Fatalf("expecting %q, instead got: %v ", context.DeadlineExceeded.Error(), err)
}
}

// This test was created to reproduce the concurrent map access error in
// https://github.com/celo-org/celo-blockchain/issues/1799
//
Expand All @@ -377,7 +417,7 @@ func TestStartStopValidators(t *testing.T) {
func TestBlockTracingConcurrentMapAccess(t *testing.T) {
ac := test.AccountConfig(1, 2)
gingerbreadBlock := common.Big0
gc, ec, err := test.BuildConfig(ac, gingerbreadBlock)
gc, ec, err := test.BuildConfig(ac, gingerbreadBlock, nil)
require.NoError(t, err)
network, shutdown, err := test.NewNetwork(ac, gc, ec)
require.NoError(t, err)
Expand Down Expand Up @@ -428,7 +468,7 @@ func TestBlockTracingConcurrentMapAccess(t *testing.T) {
func TestBlockTracingSequentialAccess(t *testing.T) {
ac := test.AccountConfig(1, 2)
gingerbreadBlock := common.Big0
gc, ec, err := test.BuildConfig(ac, gingerbreadBlock)
gc, ec, err := test.BuildConfig(ac, gingerbreadBlock, nil)
require.NoError(t, err)
network, shutdown, err := test.NewNetwork(ac, gc, ec)
require.NoError(t, err)
Expand Down Expand Up @@ -463,7 +503,7 @@ type rpcCustomTransaction struct {
func TestRPCDynamicTxGasPriceWithBigFeeCap(t *testing.T) {
ac := test.AccountConfig(3, 2)
gingerbreadBlock := common.Big0
gc, ec, err := test.BuildConfig(ac, gingerbreadBlock)
gc, ec, err := test.BuildConfig(ac, gingerbreadBlock, nil)
require.NoError(t, err)
network, shutdown, err := test.NewNetwork(ac, gc, ec)
require.NoError(t, err)
Expand Down Expand Up @@ -504,7 +544,7 @@ func TestRPCDynamicTxGasPriceWithBigFeeCap(t *testing.T) {
func TestRPCDynamicTxGasPriceWithState(t *testing.T) {
ac := test.AccountConfig(3, 2)
gingerbreadBlock := common.Big0
gc, ec, err := test.BuildConfig(ac, gingerbreadBlock)
gc, ec, err := test.BuildConfig(ac, gingerbreadBlock, nil)
require.NoError(t, err)
ec.TxLookupLimit = 0
ec.NoPruning = true
Expand Down Expand Up @@ -582,7 +622,7 @@ func testRPCDynamicTxGasPriceWithoutState(t *testing.T, afterGingerbread, altern
}
cusdAddress := common.HexToAddress("0xd008")
ac := test.AccountConfig(3, 2)
gc, ec, err := test.BuildConfig(ac, gingerbreadBlock)
gc, ec, err := test.BuildConfig(ac, gingerbreadBlock, nil)
ec.TrieDirtyCache = 5
require.NoError(t, err)
network, shutdown, err := test.NewNetwork(ac, gc, ec)
Expand Down Expand Up @@ -656,7 +696,7 @@ func pruneStateOfBlock(ctx context.Context, node *test.Node, blockNumber *big.In
func runMochaTest(t *testing.T, add_args func(*env.AccountsConfig, *genesis.Config, test.Network) []string) {
ac := test.AccountConfig(1, 1)
gingerbreadBlock := common.Big0
gc, ec, err := test.BuildConfig(ac, gingerbreadBlock)
gc, ec, err := test.BuildConfig(ac, gingerbreadBlock, nil)
require.NoError(t, err)
network, shutdown, err := test.NewNetwork(ac, gc, ec)
require.NoError(t, err)
Expand Down Expand Up @@ -702,7 +742,7 @@ func TestEthersJSCompatibility(t *testing.T) {
func TestEthersJSCompatibilityDisableAfterGingerbread(t *testing.T) {
ac := test.AccountConfig(1, 1)
gingerbreadBlock := common.Big0
gc, ec, err := test.BuildConfig(ac, gingerbreadBlock)
gc, ec, err := test.BuildConfig(ac, gingerbreadBlock, nil)
require.NoError(t, err)

// Check fields present (compatibility set by default)
Expand Down Expand Up @@ -750,7 +790,7 @@ func TestEthersJSCompatibilityDisableAfterGingerbread(t *testing.T) {
func TestEthersJSCompatibilityDisableBeforeGingerbread(t *testing.T) {
ac := test.AccountConfig(1, 1)
var gingerbreadBlock *big.Int = nil
gc, ec, err := test.BuildConfig(ac, gingerbreadBlock)
gc, ec, err := test.BuildConfig(ac, gingerbreadBlock, nil)
require.NoError(t, err)

// Check fields present (compatibility set by default)
Expand Down Expand Up @@ -807,7 +847,7 @@ func TestEthCompatibilityFieldsOnGenesisBlock(t *testing.T) {
var gingerbreadBlock *big.Int = nil

// Fist we test without eth compatibility to ensure that the setting has an effect.
gc, ec, err := test.BuildConfig(ac, gingerbreadBlock)
gc, ec, err := test.BuildConfig(ac, gingerbreadBlock, nil)
ec.RPCEthCompatibility = false
require.NoError(t, err)
network, shutdown, err := test.NewNetwork(ac, gc, ec)
Expand All @@ -826,7 +866,7 @@ func TestEthCompatibilityFieldsOnGenesisBlock(t *testing.T) {

// Now we with eth compatility enabled and see that gasLimit and baseFee
// are returned on the block.
gc, ec, err = test.BuildConfig(ac, gingerbreadBlock)
gc, ec, err = test.BuildConfig(ac, gingerbreadBlock, nil)
ec.RPCEthCompatibility = true
require.NoError(t, err)
network, shutdown, err = test.NewNetwork(ac, gc, ec)
Expand All @@ -848,7 +888,7 @@ func TestSettingGingerbreadOnGenesisBlock(t *testing.T) {
// Fist we test without gingerbread to ensure that setting the gingerbread
// actually has an effect.
var gingerbreadBlock *big.Int = nil
gc, ec, err := test.BuildConfig(ac, gingerbreadBlock)
gc, ec, err := test.BuildConfig(ac, gingerbreadBlock, nil)
ec.RPCEthCompatibility = false
require.NoError(t, err)
network, shutdown, err := test.NewNetwork(ac, gc, ec)
Expand All @@ -867,7 +907,7 @@ func TestSettingGingerbreadOnGenesisBlock(t *testing.T) {

// Now we check that setting the gingerbread block at genesis causes gasLimit and baseFee to be set on the block.
gingerbreadBlock = big.NewInt(0)
gc, ec, err = test.BuildConfig(ac, gingerbreadBlock)
gc, ec, err = test.BuildConfig(ac, gingerbreadBlock, nil)
ec.RPCEthCompatibility = false
require.NoError(t, err)
network, shutdown, err = test.NewNetwork(ac, gc, ec)
Expand All @@ -886,7 +926,7 @@ func TestSettingGingerbreadOnGenesisBlock(t *testing.T) {
func TestGetFinalizedBlock(t *testing.T) {
ac := test.AccountConfig(2, 2)
gingerbreadBlock := common.Big0
gc, ec, err := test.BuildConfig(ac, gingerbreadBlock)
gc, ec, err := test.BuildConfig(ac, gingerbreadBlock, nil)
require.NoError(t, err)
network, shutdown, err := test.NewNetwork(ac, gc, ec)
require.NoError(t, err)
Expand Down
4 changes: 2 additions & 2 deletions e2e_test/e2e_transfer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ const (
func TestTransferCELO(t *testing.T) {
ac := test.AccountConfig(1, 3)
gingerbreadBlock := common.Big0
gc, ec, err := test.BuildConfig(ac, gingerbreadBlock)
gc, ec, err := test.BuildConfig(ac, gingerbreadBlock, nil)
require.NoError(t, err)
network, shutdown, err := test.NewNetwork(ac, gc, ec)
require.NoError(t, err)
Expand Down Expand Up @@ -259,7 +259,7 @@ func prepareTransaction(txArgs ethapi.TransactionArgs, senderKey *ecdsa.PrivateK
func TestTransferERC20(t *testing.T) {
ac := test.AccountConfig(1, 3)
gingerbreadBlock := common.Big0
gc, ec, err := test.BuildConfig(ac, gingerbreadBlock)
gc, ec, err := test.BuildConfig(ac, gingerbreadBlock, nil)
require.NoError(t, err)
network, shutdown, err := test.NewNetwork(ac, gc, ec)
require.NoError(t, err)
Expand Down
4 changes: 4 additions & 0 deletions eth/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,10 @@ func New(stack *node.Node, config *ethconfig.Config) (*Ethereum, error) {
log.Info("Initialised chain configuration", "config", chainConfig)
chainConfig.FullHeaderChainAvailable = config.SyncMode.SyncFullHeaderChain()

if config.L2Fork != nil {
chainConfig.L2Block = config.L2Fork
}

if err := pruner.RecoverPruning(stack.ResolvePath(""), chainDb, stack.ResolvePath(config.TrieCleanCacheJournal)); err != nil {
log.Error("Failed to recover state", "error", err)
}
Expand Down
2 changes: 1 addition & 1 deletion eth/ethconfig/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ type Config struct {
// HFork block override (TODO: remove after the fork)
OverrideHFork *big.Int `toml:",omitempty"`

// l2 fork block override
// l2 fork block
L2Fork *big.Int `toml:",omitempty"`

// The minimum required peers in order for syncing to be initiated, if left
Expand Down
2 changes: 1 addition & 1 deletion les/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ func New(stack *node.Node, config *ethconfig.Config) (*LightEthereum, error) {
return nil, err
}
chainConfig, genesisHash, genesisErr := core.SetupGenesisBlockWithOverride(chainDb, config.Genesis,
config.OverrideHFork)
config.OverrideHFork, config.L2Fork)
if _, isCompat := genesisErr.(*params.ConfigCompatError); genesisErr != nil && !isCompat {
return nil, genesisErr
}
Expand Down
4 changes: 2 additions & 2 deletions params/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -516,7 +516,7 @@ func (c *ChainConfig) CheckConfigForkOrder() error {
{name: "gingerbreadBlock", block: c.GingerbreadBlock},
{name: "gingerbreadP2Block", block: c.GingerbreadP2Block},
{name: "hforkBlock", block: c.HForkBlock},
{name: "l2Block", block: c.L2Block},
// {name: "l2Block", block: c.L2Block},
} {
if lastFork.name != "" {
// Next one must be higher number
Expand Down Expand Up @@ -721,7 +721,7 @@ func (c *ChainConfig) DisableGingerbread() *ChainConfig {
c.GingerbreadP2Block = nil
// Since gingerbread is disabled disable following forks as well
c.HForkBlock = nil
c.L2Block = nil
// c.L2Block = nil
return c
}

Expand Down
Loading

0 comments on commit 21e324f

Please sign in to comment.