From 389fcd53caf9cf21fef17a74bec44682cca77cb2 Mon Sep 17 00:00:00 2001 From: Tudor Malene Date: Tue, 13 Feb 2024 15:55:23 +0000 Subject: [PATCH 01/17] validate tx --- go/enclave/enclave.go | 3 ++- go/enclave/nodetype/validator.go | 36 ++++++++++++++++---------------- go/enclave/txpool/txpool.go | 9 ++++++++ 3 files changed, 29 insertions(+), 19 deletions(-) diff --git a/go/enclave/enclave.go b/go/enclave/enclave.go index 9385e2c026..4449072b12 100644 --- a/go/enclave/enclave.go +++ b/go/enclave/enclave.go @@ -84,6 +84,7 @@ type enclaveImpl struct { profiler *profiler.Profiler debugger *debugger.Debugger logger gethlog.Logger + mempool *txpool.TxPool stopControl *stopcontrol.StopControl mainMutex sync.Mutex // serialises all data ingestion or creation to avoid weird races @@ -213,7 +214,7 @@ func NewEnclave( blockchain, ) } else { - service = nodetype.NewValidator(blockProcessor, batchExecutor, registry, rConsumer, chainConfig, config.SequencerID, storage, sigVerifier, logger) + service = nodetype.NewValidator(blockProcessor, batchExecutor, registry, rConsumer, chainConfig, config.SequencerID, storage, sigVerifier, mempool, logger) } chain := l2chain.NewChain( diff --git a/go/enclave/nodetype/validator.go b/go/enclave/nodetype/validator.go index 4997fa3297..ccbd99c126 100644 --- a/go/enclave/nodetype/validator.go +++ b/go/enclave/nodetype/validator.go @@ -5,6 +5,8 @@ import ( "fmt" "math/big" + "github.com/ten-protocol/go-ten/go/enclave/txpool" + "github.com/ethereum/go-ethereum/core/types" "github.com/ten-protocol/go-ten/go/common/errutil" @@ -30,22 +32,12 @@ type obsValidator struct { sequencerID gethcommon.Address storage storage.Storage sigValidator *components.SignatureValidator - logger gethlog.Logger -} - -func NewValidator( - consumer components.L1BlockProcessor, - batchExecutor components.BatchExecutor, - registry components.BatchRegistry, - rollupConsumer components.RollupConsumer, + mempool *txpool.TxPool - chainConfig *params.ChainConfig, + logger gethlog.Logger +} - sequencerID gethcommon.Address, - storage storage.Storage, - sigValidator *components.SignatureValidator, - logger gethlog.Logger, -) ObsValidator { +func NewValidator(consumer components.L1BlockProcessor, batchExecutor components.BatchExecutor, registry components.BatchRegistry, rollupConsumer components.RollupConsumer, chainConfig *params.ChainConfig, sequencerID gethcommon.Address, storage storage.Storage, sigValidator *components.SignatureValidator, mempool *txpool.TxPool, logger gethlog.Logger) ObsValidator { return &obsValidator{ blockProcessor: consumer, batchExecutor: batchExecutor, @@ -55,13 +47,13 @@ func NewValidator( sequencerID: sequencerID, storage: storage, sigValidator: sigValidator, + mempool: mempool, logger: logger, } } -func (val *obsValidator) SubmitTransaction(transaction *common.L2Tx) error { - val.logger.Trace(fmt.Sprintf("Transaction %s submitted to validator but there is nothing to do with it.", transaction.Hash().Hex())) - return nil +func (val *obsValidator) SubmitTransaction(tx *common.L2Tx) error { + return val.mempool.Validate(tx) } func (val *obsValidator) OnL1Fork(_ *common.ChainFork) error { @@ -86,6 +78,14 @@ func (val *obsValidator) ExecuteStoredBatches() error { return err } + // the mempool can only be started when there are a couple of blocks already processed + if !val.mempool.Running() && headBatchSeq != nil && headBatchSeq.Uint64() > common.L2GenesisSeqNo+1 { + err := val.mempool.Start() + if err != nil { + return err + } + } + for _, batch := range batches { if batch.IsGenesis() { if err = val.handleGenesis(batch); err != nil { @@ -155,5 +155,5 @@ func (val *obsValidator) OnL1Block(_ types.Block, _ *components.BlockIngestionTy } func (val *obsValidator) Close() error { - return nil + return val.mempool.Close() } diff --git a/go/enclave/txpool/txpool.go b/go/enclave/txpool/txpool.go index e7ed13f451..c8209e2e19 100644 --- a/go/enclave/txpool/txpool.go +++ b/go/enclave/txpool/txpool.go @@ -4,6 +4,7 @@ import ( "fmt" "math/big" "strings" + _ "unsafe" gethlog "github.com/ethereum/go-ethereum/log" "github.com/ten-protocol/go-ten/go/common/log" @@ -78,6 +79,14 @@ 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 + +// Validate - run the underlying tx pool validation logic +func (t *TxPool) Validate(tx *common.L2Tx) error { + return validateTxBasics(t.legacyPool, tx, false) +} + func (t *TxPool) Running() bool { return t.running } From 4cd8dd5301cad9257364d8010b9299194bf10d9b Mon Sep 17 00:00:00 2001 From: Tudor Malene Date: Tue, 13 Feb 2024 16:11:51 +0000 Subject: [PATCH 02/17] more checks --- go/enclave/nodetype/validator.go | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/go/enclave/nodetype/validator.go b/go/enclave/nodetype/validator.go index ccbd99c126..c9cede2a33 100644 --- a/go/enclave/nodetype/validator.go +++ b/go/enclave/nodetype/validator.go @@ -38,6 +38,15 @@ type obsValidator struct { } func NewValidator(consumer components.L1BlockProcessor, batchExecutor components.BatchExecutor, registry components.BatchRegistry, rollupConsumer components.RollupConsumer, chainConfig *params.ChainConfig, sequencerID gethcommon.Address, storage storage.Storage, sigValidator *components.SignatureValidator, mempool *txpool.TxPool, logger gethlog.Logger) ObsValidator { + // the mempool can only be started when there are a couple of blocks already processed + headBatchSeq := registry.HeadBatchSeq() + if !mempool.Running() && headBatchSeq != nil && headBatchSeq.Uint64() > common.L2GenesisSeqNo+1 { + err := mempool.Start() + if err != nil { + panic(fmt.Errorf("could not start mempool: %w", err)) + } + } + return &obsValidator{ blockProcessor: consumer, batchExecutor: batchExecutor, @@ -53,7 +62,11 @@ func NewValidator(consumer components.L1BlockProcessor, batchExecutor components } func (val *obsValidator) SubmitTransaction(tx *common.L2Tx) error { - return val.mempool.Validate(tx) + headBatch := val.batchRegistry.HeadBatchSeq() + if headBatch != nil && headBatch.Uint64() > common.L2GenesisSeqNo+1 { + return val.mempool.Validate(tx) + } + return fmt.Errorf("not initialised") } func (val *obsValidator) OnL1Fork(_ *common.ChainFork) error { From fdb80975ca46e50babba5e4ddd72499390663c92 Mon Sep 17 00:00:00 2001 From: Tudor Malene Date: Tue, 13 Feb 2024 16:16:32 +0000 Subject: [PATCH 03/17] cleanup --- go/enclave/nodetype/validator.go | 28 +++++++++++++--------------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/go/enclave/nodetype/validator.go b/go/enclave/nodetype/validator.go index c9cede2a33..cf0675b57a 100644 --- a/go/enclave/nodetype/validator.go +++ b/go/enclave/nodetype/validator.go @@ -38,14 +38,7 @@ type obsValidator struct { } func NewValidator(consumer components.L1BlockProcessor, batchExecutor components.BatchExecutor, registry components.BatchRegistry, rollupConsumer components.RollupConsumer, chainConfig *params.ChainConfig, sequencerID gethcommon.Address, storage storage.Storage, sigValidator *components.SignatureValidator, mempool *txpool.TxPool, logger gethlog.Logger) ObsValidator { - // the mempool can only be started when there are a couple of blocks already processed - headBatchSeq := registry.HeadBatchSeq() - if !mempool.Running() && headBatchSeq != nil && headBatchSeq.Uint64() > common.L2GenesisSeqNo+1 { - err := mempool.Start() - if err != nil { - panic(fmt.Errorf("could not start mempool: %w", err)) - } - } + startMempool(registry, mempool) return &obsValidator{ blockProcessor: consumer, @@ -91,13 +84,7 @@ func (val *obsValidator) ExecuteStoredBatches() error { return err } - // the mempool can only be started when there are a couple of blocks already processed - if !val.mempool.Running() && headBatchSeq != nil && headBatchSeq.Uint64() > common.L2GenesisSeqNo+1 { - err := val.mempool.Start() - if err != nil { - return err - } - } + startMempool(val.batchRegistry, val.mempool) for _, batch := range batches { if batch.IsGenesis() { @@ -170,3 +157,14 @@ func (val *obsValidator) OnL1Block(_ types.Block, _ *components.BlockIngestionTy func (val *obsValidator) Close() error { return val.mempool.Close() } + +func startMempool(registry components.BatchRegistry, mempool *txpool.TxPool) { + // the mempool can only be started when there are a couple of blocks already processed + headBatchSeq := registry.HeadBatchSeq() + if !mempool.Running() && headBatchSeq != nil && headBatchSeq.Uint64() > common.L2GenesisSeqNo+1 { + err := mempool.Start() + if err != nil { + panic(fmt.Errorf("could not start mempool: %w", err)) + } + } +} From 9ca6b7d1e58ed70570b052962746cc6a86e159f8 Mon Sep 17 00:00:00 2001 From: Tudor Malene Date: Tue, 13 Feb 2024 16:18:57 +0000 Subject: [PATCH 04/17] cleanup --- go/enclave/enclave.go | 1 - 1 file changed, 1 deletion(-) diff --git a/go/enclave/enclave.go b/go/enclave/enclave.go index 4449072b12..ae3f7c5992 100644 --- a/go/enclave/enclave.go +++ b/go/enclave/enclave.go @@ -84,7 +84,6 @@ type enclaveImpl struct { profiler *profiler.Profiler debugger *debugger.Debugger logger gethlog.Logger - mempool *txpool.TxPool stopControl *stopcontrol.StopControl mainMutex sync.Mutex // serialises all data ingestion or creation to avoid weird races From 7342f61def9868ca0e3011d873ec76ca11ffb486 Mon Sep 17 00:00:00 2001 From: Tudor Malene Date: Tue, 13 Feb 2024 16:20:04 +0000 Subject: [PATCH 05/17] cleanup --- go/enclave/txpool/txpool.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/go/enclave/txpool/txpool.go b/go/enclave/txpool/txpool.go index c8209e2e19..37d3141a95 100644 --- a/go/enclave/txpool/txpool.go +++ b/go/enclave/txpool/txpool.go @@ -4,6 +4,9 @@ import ( "fmt" "math/big" "strings" + + // unsafe package imported in order to link to a private function in go-ethereum. + // This allows us to validate transactions against the tx pool rules. _ "unsafe" gethlog "github.com/ethereum/go-ethereum/log" From 0a1ae98c338efe268d81f0a7688291232d3b589f Mon Sep 17 00:00:00 2001 From: Tudor Malene Date: Wed, 14 Feb 2024 09:30:11 +0000 Subject: [PATCH 06/17] address pr comment --- go/enclave/nodetype/validator.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/go/enclave/nodetype/validator.go b/go/enclave/nodetype/validator.go index cf0675b57a..0035ceb70f 100644 --- a/go/enclave/nodetype/validator.go +++ b/go/enclave/nodetype/validator.go @@ -56,10 +56,10 @@ func NewValidator(consumer components.L1BlockProcessor, batchExecutor components func (val *obsValidator) SubmitTransaction(tx *common.L2Tx) error { headBatch := val.batchRegistry.HeadBatchSeq() - if headBatch != nil && headBatch.Uint64() > common.L2GenesisSeqNo+1 { - return val.mempool.Validate(tx) + if headBatch == nil || headBatch.Uint64() <= common.L2GenesisSeqNo+1 { + return fmt.Errorf("not initialised") } - return fmt.Errorf("not initialised") + return val.mempool.Validate(tx) } func (val *obsValidator) OnL1Fork(_ *common.ChainFork) error { From ec074d93ee689b5ee6ee9733e8ea251fb2f3e85b Mon Sep 17 00:00:00 2001 From: Tudor Malene Date: Wed, 14 Feb 2024 09:56:50 +0000 Subject: [PATCH 07/17] increased timeouts --- integration/eth2network/eth2_network.go | 2 +- integration/eth2network/eth2_network_test.go | 2 +- integration/noderunner/noderunner_test.go | 2 +- integration/simulation/network/geth_utils.go | 2 +- integration/smartcontract/smartcontracts_test.go | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/integration/eth2network/eth2_network.go b/integration/eth2network/eth2_network.go index 19bee3d939..9bfffa7597 100644 --- a/integration/eth2network/eth2_network.go +++ b/integration/eth2network/eth2_network.go @@ -245,7 +245,7 @@ func (n *Impl) Start() error { for i := range n.dataDirs { nodeID := i eg.Go(func() error { - return n.waitForNodeUp(nodeID, 30*time.Second) + return n.waitForNodeUp(nodeID, time.Minute) }) } err = eg.Wait() diff --git a/integration/eth2network/eth2_network_test.go b/integration/eth2network/eth2_network_test.go index 15511060cc..4874b44cb0 100644 --- a/integration/eth2network/eth2_network_test.go +++ b/integration/eth2network/eth2_network_test.go @@ -65,7 +65,7 @@ func TestStartEth2Network(t *testing.T) { 2, 2, randomWalletAddrs, - time.Minute, + 2*time.Minute, ) // wait until the merge has happened assert.Nil(t, network.Start()) diff --git a/integration/noderunner/noderunner_test.go b/integration/noderunner/noderunner_test.go index f0b979bfc6..e2e872b034 100644 --- a/integration/noderunner/noderunner_test.go +++ b/integration/noderunner/noderunner_test.go @@ -58,7 +58,7 @@ func TestCanStartStandaloneObscuroHostAndEnclave(t *testing.T) { 2, 2, []string{hostAddr.String()}, - time.Minute, + 2*time.Minute, ) defer network.Stop() //nolint: errcheck err = network.Start() diff --git a/integration/simulation/network/geth_utils.go b/integration/simulation/network/geth_utils.go index 0af2b329a8..c891c1102c 100644 --- a/integration/simulation/network/geth_utils.go +++ b/integration/simulation/network/geth_utils.go @@ -84,7 +84,7 @@ func StartGethNetwork(wallets *params.SimWallets, startPort int, blockDurationSe 2, 2, walletAddresses, - time.Minute, + 2*time.Minute, ) err = eth2Network.Start() diff --git a/integration/smartcontract/smartcontracts_test.go b/integration/smartcontract/smartcontracts_test.go index f3f8519ff5..151d3691d7 100644 --- a/integration/smartcontract/smartcontracts_test.go +++ b/integration/smartcontract/smartcontracts_test.go @@ -71,7 +71,7 @@ func runGethNetwork(t *testing.T) *netInfo { 2, 2, []string{workerWallet.Address().String()}, - time.Minute, + 2*time.Minute, ) if err = eth2Network.Start(); err != nil { From c8e99325d9c647f3f5c62b8fcebcd51754c72765 Mon Sep 17 00:00:00 2001 From: Tudor Malene Date: Wed, 14 Feb 2024 10:50:53 +0000 Subject: [PATCH 08/17] geth network stopping more robust --- integration/eth2network/eth2_network.go | 3 --- 1 file changed, 3 deletions(-) diff --git a/integration/eth2network/eth2_network.go b/integration/eth2network/eth2_network.go index 9bfffa7597..4713b72cf3 100644 --- a/integration/eth2network/eth2_network.go +++ b/integration/eth2network/eth2_network.go @@ -324,17 +324,14 @@ func (n *Impl) Stop() error { err := n.gethProcesses[i].Process.Kill() if err != nil { fmt.Printf("unable to kill geth node - %s\n", err.Error()) - return err } err = n.prysmBeaconProcesses[i].Process.Kill() if err != nil { fmt.Printf("unable to kill prysm beacon node - %s\n", err.Error()) - return err } err = n.prysmValidatorProcesses[i].Process.Kill() if err != nil { fmt.Printf("unable to kill prysm validator node - %s\n", err.Error()) - return err } } return nil From 61c14d5b655ab41cfdfa16ee6edd9563f8c650be Mon Sep 17 00:00:00 2001 From: Anthony Nixon Date: Wed, 14 Feb 2024 10:55:06 +0000 Subject: [PATCH 09/17] Step to close ports to avoid lingering process bound to ports --- .github/workflows/build-pr.yml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/.github/workflows/build-pr.yml b/.github/workflows/build-pr.yml index db01164a33..110d8c2c10 100644 --- a/.github/workflows/build-pr.yml +++ b/.github/workflows/build-pr.yml @@ -28,6 +28,13 @@ jobs: - name: Download eth2network binaries run: go test ./... -v -count=1 -run TestEnsureBinariesAreAvail + # Close specified ports using lsof before testing / local port list compiled from ./testnet/launcher/docker.go + - name: Close Ports + run: | + for port in 11000 80 81 15000 11010 13010 13011 15010 99 3000 3001 8025 9000; do + kill $(lsof -t -i :$port) || true + done + - name: Test run: go test --failfast -v ./... -count=1 -timeout 5m From 6c870d5b8718b1652a7d9c24004a2ba3ca2665d7 Mon Sep 17 00:00:00 2001 From: Anthony Nixon Date: Wed, 14 Feb 2024 11:04:28 +0000 Subject: [PATCH 10/17] Close all ports in step --- .github/workflows/build-pr.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/build-pr.yml b/.github/workflows/build-pr.yml index 110d8c2c10..12ea52b556 100644 --- a/.github/workflows/build-pr.yml +++ b/.github/workflows/build-pr.yml @@ -28,10 +28,10 @@ jobs: - name: Download eth2network binaries run: go test ./... -v -count=1 -run TestEnsureBinariesAreAvail - # Close specified ports using lsof before testing / local port list compiled from ./testnet/launcher/docker.go - - name: Close Ports + # Close processes on all ports + - name: Close All Ports run: | - for port in 11000 80 81 15000 11010 13010 13011 15010 99 3000 3001 8025 9000; do + for port in $(seq 1 65535); do kill $(lsof -t -i :$port) || true done From 4fc6f2d990730d6e259aa007b0beb2657f03581e Mon Sep 17 00:00:00 2001 From: Anthony Nixon Date: Wed, 14 Feb 2024 11:11:20 +0000 Subject: [PATCH 11/17] Revert "Close all ports in step" This reverts commit 6c870d5b8718b1652a7d9c24004a2ba3ca2665d7. --- .github/workflows/build-pr.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/build-pr.yml b/.github/workflows/build-pr.yml index 12ea52b556..110d8c2c10 100644 --- a/.github/workflows/build-pr.yml +++ b/.github/workflows/build-pr.yml @@ -28,10 +28,10 @@ jobs: - name: Download eth2network binaries run: go test ./... -v -count=1 -run TestEnsureBinariesAreAvail - # Close processes on all ports - - name: Close All Ports + # Close specified ports using lsof before testing / local port list compiled from ./testnet/launcher/docker.go + - name: Close Ports run: | - for port in $(seq 1 65535); do + for port in 11000 80 81 15000 11010 13010 13011 15010 99 3000 3001 8025 9000; do kill $(lsof -t -i :$port) || true done From 28ddf0008d645507272bd7a5668cac564515c962 Mon Sep 17 00:00:00 2001 From: Anthony Nixon Date: Wed, 14 Feb 2024 11:12:18 +0000 Subject: [PATCH 12/17] add port 52300 --- .github/workflows/build-pr.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build-pr.yml b/.github/workflows/build-pr.yml index 110d8c2c10..7ad4b59a66 100644 --- a/.github/workflows/build-pr.yml +++ b/.github/workflows/build-pr.yml @@ -31,7 +31,7 @@ jobs: # Close specified ports using lsof before testing / local port list compiled from ./testnet/launcher/docker.go - name: Close Ports run: | - for port in 11000 80 81 15000 11010 13010 13011 15010 99 3000 3001 8025 9000; do + for port in 11000 80 81 15000 11010 13010 13011 15010 99 3000 3001 8025 9000 52300; do kill $(lsof -t -i :$port) || true done From 9216dfb4b6c220441a1326f4229c8c0aaa161334 Mon Sep 17 00:00:00 2001 From: Anthony Nixon Date: Wed, 14 Feb 2024 11:48:14 +0000 Subject: [PATCH 13/17] Expanded port range --- .github/workflows/build-pr.yml | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/.github/workflows/build-pr.yml b/.github/workflows/build-pr.yml index 7ad4b59a66..1bac441424 100644 --- a/.github/workflows/build-pr.yml +++ b/.github/workflows/build-pr.yml @@ -28,11 +28,16 @@ jobs: - name: Download eth2network binaries run: go test ./... -v -count=1 -run TestEnsureBinariesAreAvail - # Close specified ports using lsof before testing / local port list compiled from ./testnet/launcher/docker.go - - name: Close Ports + # Close specified ports using lsof before testing / local port list compiled from ./integration/constants.go + - name: Close Integration Test Ports run: | - for port in 11000 80 81 15000 11010 13010 13011 15010 99 3000 3001 8025 9000 52300; do - kill $(lsof -t -i :$port) || true + lowest_port=10000 # Lowest starting port + highest_port=58000 # Highest port considering the offset + + # Find processes listening on ports within the range and kill them + for pid in $(lsof -iTCP:$lowest_port-$highest_port -sTCP:LISTEN -t); do + echo "Killing process $pid on one of the ports from $lowest_port to $highest_port" + kill $pid || true done - name: Test From e43a8a371d895cb36313eaefb352a98580dd4f1f Mon Sep 17 00:00:00 2001 From: Anthony Nixon Date: Wed, 14 Feb 2024 12:06:03 +0000 Subject: [PATCH 14/17] additional ports and expand range. --- .github/workflows/build-pr.yml | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/.github/workflows/build-pr.yml b/.github/workflows/build-pr.yml index 1bac441424..cffca9ea3d 100644 --- a/.github/workflows/build-pr.yml +++ b/.github/workflows/build-pr.yml @@ -31,8 +31,9 @@ jobs: # Close specified ports using lsof before testing / local port list compiled from ./integration/constants.go - name: Close Integration Test Ports run: | - lowest_port=10000 # Lowest starting port + lowest_port=8000 # Lowest starting port highest_port=58000 # Highest port considering the offset + additional_ports=(80 81 99) # Additional specific ports # Find processes listening on ports within the range and kill them for pid in $(lsof -iTCP:$lowest_port-$highest_port -sTCP:LISTEN -t); do @@ -40,6 +41,14 @@ jobs: kill $pid || true done + # Close additional specific ports + for port in "${additional_ports[@]}"; do + for pid in $(lsof -ti TCP:$port); do + echo "Killing process $pid on port $port" + kill $pid || true + done + done + - name: Test run: go test --failfast -v ./... -count=1 -timeout 5m From cc981747c1f799c5323fcd82ff4d0a6a25273b8b Mon Sep 17 00:00:00 2001 From: Tudor Malene Date: Wed, 14 Feb 2024 13:25:22 +0000 Subject: [PATCH 15/17] de-flake --- integration/constants.go | 3 ++- integration/contractdeployer/contract_deployer_test.go | 4 ++-- integration/eth2network/eth2_network.go | 2 ++ 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/integration/constants.go b/integration/constants.go index 6191b4f932..37449c6dc5 100644 --- a/integration/constants.go +++ b/integration/constants.go @@ -8,7 +8,8 @@ const ( StartPortSimulationInMem = 22000 StartPortSimulationFullNetwork = 26000 StartPortSmartContractTests = 30000 - StartPortContractDeployerTest = 34000 + StartPortContractDeployerTest1 = 34000 + StartPortContractDeployerTest2 = 35000 StartPortWalletExtensionUnitTest = 38000 StartPortFaucetUnitTest = 42000 StartPortFaucetHTTPUnitTest = 48000 diff --git a/integration/contractdeployer/contract_deployer_test.go b/integration/contractdeployer/contract_deployer_test.go index 7fd64f6fa7..5907f99595 100644 --- a/integration/contractdeployer/contract_deployer_test.go +++ b/integration/contractdeployer/contract_deployer_test.go @@ -45,7 +45,7 @@ func init() { //nolint:gochecknoinits } func TestCanDeployLayer2ERC20Contract(t *testing.T) { - startPort := integration.StartPortContractDeployerTest + startPort := integration.StartPortContractDeployerTest1 hostWSPort := startPort + integration.DefaultHostRPCWSOffset createObscuroNetwork(t, startPort) // This sleep is required to ensure the initial rollup exists, and thus contract deployer can check its balance. @@ -81,7 +81,7 @@ func TestCanDeployLayer2ERC20Contract(t *testing.T) { } func TestFaucetSendsFundsOnlyIfNeeded(t *testing.T) { - startPort := integration.StartPortContractDeployerTest + startPort := integration.StartPortContractDeployerTest2 hostWSPort := startPort + integration.DefaultHostRPCWSOffset createObscuroNetwork(t, startPort) diff --git a/integration/eth2network/eth2_network.go b/integration/eth2network/eth2_network.go index 4713b72cf3..88202901aa 100644 --- a/integration/eth2network/eth2_network.go +++ b/integration/eth2network/eth2_network.go @@ -334,6 +334,8 @@ func (n *Impl) Stop() error { fmt.Printf("unable to kill prysm validator node - %s\n", err.Error()) } } + // wait a second for the kill signal + time.Sleep(time.Second) return nil } From 6c2e43292d616bd82f55fd9e82082ea96955d2cd Mon Sep 17 00:00:00 2001 From: Tudor Malene Date: Wed, 14 Feb 2024 14:11:29 +0000 Subject: [PATCH 16/17] retry the kill --- integration/eth2network/eth2_network.go | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/integration/eth2network/eth2_network.go b/integration/eth2network/eth2_network.go index 88202901aa..33aa0cea89 100644 --- a/integration/eth2network/eth2_network.go +++ b/integration/eth2network/eth2_network.go @@ -3,6 +3,7 @@ package eth2network import ( "context" "encoding/json" + "errors" "fmt" "io" "net/http" @@ -321,15 +322,15 @@ func (n *Impl) Start() error { // Stop stops the network func (n *Impl) Stop() error { for i := 0; i < len(n.dataDirs); i++ { - err := n.gethProcesses[i].Process.Kill() + err := kill(n.gethProcesses[i].Process, 0) if err != nil { fmt.Printf("unable to kill geth node - %s\n", err.Error()) } - err = n.prysmBeaconProcesses[i].Process.Kill() + err = kill(n.prysmBeaconProcesses[i].Process, 0) if err != nil { fmt.Printf("unable to kill prysm beacon node - %s\n", err.Error()) } - err = n.prysmValidatorProcesses[i].Process.Kill() + err = kill(n.prysmValidatorProcesses[i].Process, 0) if err != nil { fmt.Printf("unable to kill prysm validator node - %s\n", err.Error()) } @@ -339,6 +340,21 @@ func (n *Impl) Stop() error { return nil } +const maxTryKill = 5 + +func kill(p *os.Process, cnt int) error { + if killErr := p.Kill(); killErr == nil { + return nil + } else if !errors.Is(killErr, os.ErrProcessDone) { + if cnt >= maxTryKill { + return killErr + } + time.Sleep(time.Second) + return kill(p, cnt+1) + } + return nil +} + // GethGenesis returns the Genesis used in geth to boot up the network func (n *Impl) GethGenesis() []byte { return n.gethGenesisBytes From 52526c9367ed0a16489f5673e24ee21eae3c1c0a Mon Sep 17 00:00:00 2001 From: Tudor Malene Date: Wed, 14 Feb 2024 16:45:46 +0000 Subject: [PATCH 17/17] add check to protect enclave --- go/enclave/enclave.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/go/enclave/enclave.go b/go/enclave/enclave.go index ae3f7c5992..2a48d5b03e 100644 --- a/go/enclave/enclave.go +++ b/go/enclave/enclave.go @@ -473,9 +473,17 @@ func (e *enclaveImpl) SubmitBatch(extBatch *common.ExtBatch) common.SystemError return responses.ToInternalError(fmt.Errorf("requested SubmitBatch with the enclave stopping")) } - core.LogMethodDuration(e.logger, measure.NewStopwatch(), "SubmitBatch call completed.", log.BatchHashKey, extBatch.Hash()) + defer core.LogMethodDuration(e.logger, measure.NewStopwatch(), "SubmitBatch call completed.", log.BatchHashKey, extBatch.Hash()) e.logger.Info("Received new p2p batch", log.BatchHeightKey, extBatch.Header.Number, log.BatchHashKey, extBatch.Hash(), "l1", extBatch.Header.L1Proof) + seqNo := extBatch.Header.SequencerOrderNo.Uint64() + if seqNo > common.L2GenesisSeqNo+1 { + _, err := e.storage.FetchBatchBySeqNo(seqNo - 1) + if err != nil { + return responses.ToInternalError(fmt.Errorf("could not find previous batch with seq: %d", seqNo-1)) + } + } + batch, err := core.ToBatch(extBatch, e.dataEncryptionService, e.dataCompressionService) if err != nil { return responses.ToInternalError(fmt.Errorf("could not convert batch. Cause: %w", err))