From 259c44664bd596dbb394eb0436f365b6d4036002 Mon Sep 17 00:00:00 2001 From: Tudor Malene Date: Fri, 16 Feb 2024 14:36:51 +0000 Subject: [PATCH 1/8] change mempool validation function --- go/enclave/txpool/txpool.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/go/enclave/txpool/txpool.go b/go/enclave/txpool/txpool.go index 37d3141a95..3ff1461488 100644 --- a/go/enclave/txpool/txpool.go +++ b/go/enclave/txpool/txpool.go @@ -82,12 +82,12 @@ func (t *TxPool) Add(transaction *common.L2Tx) error { return nil } -//go:linkname validateTxBasics github.com/ethereum/go-ethereum/core/txpool/legacypool.(*LegacyPool).validateTxBasics -func validateTxBasics(_ *legacypool.LegacyPool, _ *types.Transaction, _ bool) error +//go:linkname validateTx github.com/ethereum/go-ethereum/core/txpool/legacypool.(*LegacyPool).validateTx +func validateTx(_ *legacypool.LegacyPool, _ *types.Transaction, _ bool) error // Validate - run the underlying tx pool validation logic func (t *TxPool) Validate(tx *common.L2Tx) error { - return validateTxBasics(t.legacyPool, tx, false) + return validateTx(t.legacyPool, tx, false) } func (t *TxPool) Running() bool { From d472ced8475ce3da109dec1e6ac8abdcc0ba9ff3 Mon Sep 17 00:00:00 2001 From: Tudor Malene Date: Fri, 16 Feb 2024 14:50:48 +0000 Subject: [PATCH 2/8] add a delay --- integration/simulation/simulation.go | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/integration/simulation/simulation.go b/integration/simulation/simulation.go index 1e24750bab..678f2e67d3 100644 --- a/integration/simulation/simulation.go +++ b/integration/simulation/simulation.go @@ -61,9 +61,12 @@ func (s *Simulation) Start() { s.bridgeFundingToObscuro() s.trackLogs() // Create log subscriptions, to validate that they're working correctly later. s.prefundObscuroAccounts() // Prefund every L2 wallet - s.deployObscuroERC20s() // Deploy the Obscuro HOC and POC ERC20 contracts - s.prefundL1Accounts() // Prefund every L1 wallet - s.checkHealthStatus() // Checks the nodes health status + + // wait for the validator to become up to date + time.Sleep(1 * time.Second) + s.deployObscuroERC20s() // Deploy the Obscuro HOC and POC ERC20 contracts + s.prefundL1Accounts() // Prefund every L1 wallet + s.checkHealthStatus() // Checks the nodes health status timer := time.Now() fmt.Printf("Starting injection\n") From 9c23300f316d43c52599c34b0f2e38552d266b6b Mon Sep 17 00:00:00 2001 From: Tudor Malene Date: Fri, 16 Feb 2024 15:00:56 +0000 Subject: [PATCH 3/8] add a delay --- integration/simulation/simulation.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/integration/simulation/simulation.go b/integration/simulation/simulation.go index 678f2e67d3..bf7bee89f9 100644 --- a/integration/simulation/simulation.go +++ b/integration/simulation/simulation.go @@ -63,7 +63,7 @@ func (s *Simulation) Start() { s.prefundObscuroAccounts() // Prefund every L2 wallet // wait for the validator to become up to date - time.Sleep(1 * time.Second) + time.Sleep(3 * time.Second) s.deployObscuroERC20s() // Deploy the Obscuro HOC and POC ERC20 contracts s.prefundL1Accounts() // Prefund every L1 wallet s.checkHealthStatus() // Checks the nodes health status From f6f378d886cabe5ef49425174b71855aadfcd0a6 Mon Sep 17 00:00:00 2001 From: Tudor Malene Date: Fri, 16 Feb 2024 16:04:46 +0000 Subject: [PATCH 4/8] update the underlying chain of the mempool --- go/enclave/nodetype/validator.go | 5 +++++ go/enclave/txpool/txpool.go | 6 +++--- integration/common/utils.go | 1 + integration/simulation/simulation.go | 8 +++++--- 4 files changed, 14 insertions(+), 6 deletions(-) diff --git a/go/enclave/nodetype/validator.go b/go/enclave/nodetype/validator.go index 0035ceb70f..00cb69ab96 100644 --- a/go/enclave/nodetype/validator.go +++ b/go/enclave/nodetype/validator.go @@ -109,6 +109,11 @@ func (val *obsValidator) ExecuteStoredBatches() error { return fmt.Errorf("could not store executed batch %s. Cause: %w", batch.Hash(), err) } val.batchRegistry.OnBatchExecuted(batch, receipts) + err = val.mempool.Chain.IngestNewBlock(batch) + if err != nil { + return fmt.Errorf("unable to remove ingest new block into eth blockchain - %w", err) + } + } } return nil diff --git a/go/enclave/txpool/txpool.go b/go/enclave/txpool/txpool.go index 3ff1461488..1715d48abd 100644 --- a/go/enclave/txpool/txpool.go +++ b/go/enclave/txpool/txpool.go @@ -25,7 +25,7 @@ type TxPool struct { txPoolConfig legacypool.Config legacyPool *legacypool.LegacyPool pool *gethtxpool.TxPool - blockchain *ethchainadapter.EthChainAdapter + Chain *ethchainadapter.EthChainAdapter gasTip *big.Int running bool logger gethlog.Logger @@ -37,7 +37,7 @@ func NewTxPool(blockchain *ethchainadapter.EthChainAdapter, gasTip *big.Int, log legacyPool := legacypool.New(txPoolConfig, blockchain) return &TxPool{ - blockchain: blockchain, + Chain: blockchain, txPoolConfig: txPoolConfig, legacyPool: legacyPool, gasTip: gasTip, @@ -52,7 +52,7 @@ func (t *TxPool) Start() error { return fmt.Errorf("tx pool already started") } - memp, err := gethtxpool.New(t.gasTip, t.blockchain, []gethtxpool.SubPool{t.legacyPool}) + memp, err := gethtxpool.New(t.gasTip, t.Chain, []gethtxpool.SubPool{t.legacyPool}) if err != nil { return fmt.Errorf("unable to init geth tx pool - %w", err) } diff --git a/integration/common/utils.go b/integration/common/utils.go index a0a6c43f8c..f0ff1839ad 100644 --- a/integration/common/utils.go +++ b/integration/common/utils.go @@ -99,6 +99,7 @@ func PrefundWallets(ctx context.Context, faucetWallet wallet.Wallet, faucetClien txHashes := make([]gethcommon.Hash, len(wallets)) for idx, w := range wallets { destAddr := w.Address() + fmt.Printf("L2 prefund: %s\n", destAddr.Hex()) txData := &types.LegacyTx{ Nonce: startingNonce + uint64(idx), Value: alloc, diff --git a/integration/simulation/simulation.go b/integration/simulation/simulation.go index bf7bee89f9..6576e94dec 100644 --- a/integration/simulation/simulation.go +++ b/integration/simulation/simulation.go @@ -63,7 +63,7 @@ func (s *Simulation) Start() { s.prefundObscuroAccounts() // Prefund every L2 wallet // wait for the validator to become up to date - time.Sleep(3 * time.Second) + time.Sleep(1 * time.Second) s.deployObscuroERC20s() // Deploy the Obscuro HOC and POC ERC20 contracts s.prefundL1Accounts() // Prefund every L1 wallet s.checkHealthStatus() // Checks the nodes health status @@ -232,6 +232,7 @@ func (s *Simulation) deployObscuroERC20s() { // 0x526c84529b2b8c11f57d93d3f5537aca3aecef9b - this is the address of the L2 contract which is currently hardcoded. contractBytes := erc20contract.L2BytecodeWithDefaultSupply(string(token), gethcommon.HexToAddress("0x526c84529b2b8c11f57d93d3f5537aca3aecef9b")) + fmt.Printf("Deploy contract from: %s\n", owner.Address().Hex()) deployContractTxData := types.DynamicFeeTx{ Nonce: NextNonce(s.ctx, s.RPCHandles, owner), Gas: 5_000_000, @@ -246,12 +247,13 @@ func (s *Simulation) deployObscuroERC20s() { panic(err) } - err = s.RPCHandles.ObscuroWalletRndClient(owner).SendTransaction(s.ctx, signedTx) + rpc := s.RPCHandles.ObscuroWalletClient(owner.Address(), 1) + err = rpc.SendTransaction(s.ctx, signedTx) if err != nil { panic(err) } - err = testcommon.AwaitReceipt(s.ctx, s.RPCHandles.ObscuroWalletRndClient(owner), signedTx.Hash(), s.Params.ReceiptTimeout) + err = testcommon.AwaitReceipt(s.ctx, rpc, signedTx.Hash(), s.Params.ReceiptTimeout) if err != nil { panic(fmt.Sprintf("ERC20 deployment transaction unsuccessful. Cause: %s", err)) } From bf87b02d87bc1ead93f2f985215fca3aee6b4677 Mon Sep 17 00:00:00 2001 From: Tudor Malene Date: Fri, 16 Feb 2024 16:09:43 +0000 Subject: [PATCH 5/8] add another check --- go/enclave/txpool/txpool.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/go/enclave/txpool/txpool.go b/go/enclave/txpool/txpool.go index 1715d48abd..87acf887e3 100644 --- a/go/enclave/txpool/txpool.go +++ b/go/enclave/txpool/txpool.go @@ -82,11 +82,21 @@ func (t *TxPool) Add(transaction *common.L2Tx) error { return nil } +//go:linkname validateTxBasics github.com/ethereum/go-ethereum/core/txpool/legacypool.(*LegacyPool).validateTxBasics +func validateTxBasics(_ *legacypool.LegacyPool, _ *types.Transaction, _ bool) error + //go:linkname validateTx github.com/ethereum/go-ethereum/core/txpool/legacypool.(*LegacyPool).validateTx func validateTx(_ *legacypool.LegacyPool, _ *types.Transaction, _ bool) error // Validate - run the underlying tx pool validation logic func (t *TxPool) Validate(tx *common.L2Tx) error { + // validate against the consensus rules + err := validateTxBasics(t.legacyPool, tx, false) + if err != nil { + return err + } + + // validate against the state. Things like nonce, balance, etc return validateTx(t.legacyPool, tx, false) } From f3929c509e9ecd4263ba2b30b93805d1a2089aec Mon Sep 17 00:00:00 2001 From: Tudor Malene Date: Fri, 16 Feb 2024 16:12:18 +0000 Subject: [PATCH 6/8] lint --- go/enclave/nodetype/validator.go | 1 - 1 file changed, 1 deletion(-) diff --git a/go/enclave/nodetype/validator.go b/go/enclave/nodetype/validator.go index 00cb69ab96..70fb835ff8 100644 --- a/go/enclave/nodetype/validator.go +++ b/go/enclave/nodetype/validator.go @@ -113,7 +113,6 @@ func (val *obsValidator) ExecuteStoredBatches() error { if err != nil { return fmt.Errorf("unable to remove ingest new block into eth blockchain - %w", err) } - } } return nil From fa853d13a4ebeea7672db144dfc9eb4fcf200f4e Mon Sep 17 00:00:00 2001 From: Tudor Malene Date: Fri, 16 Feb 2024 16:28:17 +0000 Subject: [PATCH 7/8] change port --- integration/constants.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/integration/constants.go b/integration/constants.go index fe4ce15bc8..0803d3ac49 100644 --- a/integration/constants.go +++ b/integration/constants.go @@ -13,8 +13,8 @@ const ( StartPortWalletExtensionUnitTest = 38000 StartPortFaucetUnitTest = 42000 StartPortFaucetHTTPUnitTest = 48000 - StartPortTenscanUnitTest = 52000 - StartPortTenGatewayUnitTest = 56000 + StartPortTenscanUnitTest = 12000 + StartPortTenGatewayUnitTest = 16000 DefaultGethWSPortOffset = 100 DefaultGethAUTHPortOffset = 200 From df5cd4c3330d97fd691e8d46ccd0ebab36b718b9 Mon Sep 17 00:00:00 2001 From: Tudor Malene Date: Fri, 16 Feb 2024 17:05:51 +0000 Subject: [PATCH 8/8] address pr comments --- go/enclave/nodetype/sequencer.go | 4 ++-- go/enclave/nodetype/validator.go | 4 ++-- integration/constants.go | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/go/enclave/nodetype/sequencer.go b/go/enclave/nodetype/sequencer.go index 991474f808..f325aa9601 100644 --- a/go/enclave/nodetype/sequencer.go +++ b/go/enclave/nodetype/sequencer.go @@ -141,7 +141,7 @@ func (s *sequencer) createGenesisBatch(block *common.L1Block) error { // this is the actual first block produced in chain err = s.blockchain.IngestNewBlock(batch) if err != nil { - return fmt.Errorf("unable to remove ingest new block into eth blockchain - %w", err) + return fmt.Errorf("failed to feed batch into the virtual eth chain - %w", err) } // the mempool can only be started after at least 1 block is in the blockchain object @@ -282,7 +282,7 @@ func (s *sequencer) produceBatch( // add the batch to the chain so it can remove pending transactions from the pool err = s.blockchain.IngestNewBlock(cb.Batch) if err != nil { - return nil, fmt.Errorf("unable to remove tx from mempool - %w", err) + return nil, fmt.Errorf("failed to feed batch into the virtual eth chain - %w", err) } return cb, nil diff --git a/go/enclave/nodetype/validator.go b/go/enclave/nodetype/validator.go index 70fb835ff8..c788e75527 100644 --- a/go/enclave/nodetype/validator.go +++ b/go/enclave/nodetype/validator.go @@ -108,11 +108,11 @@ func (val *obsValidator) ExecuteStoredBatches() error { if err != nil { return fmt.Errorf("could not store executed batch %s. Cause: %w", batch.Hash(), err) } - val.batchRegistry.OnBatchExecuted(batch, receipts) err = val.mempool.Chain.IngestNewBlock(batch) if err != nil { - return fmt.Errorf("unable to remove ingest new block into eth blockchain - %w", err) + return fmt.Errorf("failed to feed batch into the virtual eth chain- %w", err) } + val.batchRegistry.OnBatchExecuted(batch, receipts) } } return nil diff --git a/integration/constants.go b/integration/constants.go index 0803d3ac49..3d0062700a 100644 --- a/integration/constants.go +++ b/integration/constants.go @@ -3,7 +3,9 @@ package integration // Tracks the start ports handed out to different tests, in a bid to minimise conflicts. const ( StartPortEth2NetworkTests = 10000 + StartPortTenscanUnitTest = 12000 StartPortNodeRunnerTest = 14000 + StartPortTenGatewayUnitTest = 16000 StartPortSimulationGethInMem = 18000 StartPortSimulationInMem = 22000 StartPortSimulationFullNetwork = 26000 @@ -13,8 +15,6 @@ const ( StartPortWalletExtensionUnitTest = 38000 StartPortFaucetUnitTest = 42000 StartPortFaucetHTTPUnitTest = 48000 - StartPortTenscanUnitTest = 12000 - StartPortTenGatewayUnitTest = 16000 DefaultGethWSPortOffset = 100 DefaultGethAUTHPortOffset = 200