Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

change mempool validation function #1800

Merged
merged 8 commits into from
Feb 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions go/enclave/nodetype/sequencer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions go/enclave/nodetype/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,10 @@ func (val *obsValidator) ExecuteStoredBatches() error {
if err != nil {
return fmt.Errorf("could not store executed batch %s. Cause: %w", batch.Hash(), err)
}
err = val.mempool.Chain.IngestNewBlock(batch)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this happen before the OnBatchExecuted call? Just wondering what sort of state things will be in if it did error for some reason. Also the wording on the error message below looks wrong, can remove 'remove' maybe?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good point

if err != nil {
return fmt.Errorf("failed to feed batch into the virtual eth chain- %w", err)
}
val.batchRegistry.OnBatchExecuted(batch, receipts)
}
}
Expand Down
18 changes: 14 additions & 4 deletions go/enclave/txpool/txpool.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand All @@ -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)
}
Expand Down Expand Up @@ -85,9 +85,19 @@ func (t *TxPool) Add(transaction *common.L2Tx) error {
//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)
// 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)
}

func (t *TxPool) Running() bool {
Expand Down
1 change: 1 addition & 0 deletions integration/common/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions integration/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -13,8 +15,6 @@ const (
StartPortWalletExtensionUnitTest = 38000
StartPortFaucetUnitTest = 42000
StartPortFaucetHTTPUnitTest = 48000
StartPortTenscanUnitTest = 52000
StartPortTenGatewayUnitTest = 56000

DefaultGethWSPortOffset = 100
DefaultGethAUTHPortOffset = 200
Expand Down
15 changes: 10 additions & 5 deletions integration/simulation/simulation.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -229,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,
Expand All @@ -243,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))
}
Expand Down
Loading