From 7f79c7f21fe0bf590f72bec6b24b9113fa1c24c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=96mer=20Faruk=20Irmak?= Date: Mon, 16 Sep 2024 11:04:25 +0300 Subject: [PATCH 1/2] refactor: eliminate double re-execution in AsyncChecker (#1036) --- params/version.go | 2 +- rollup/ccc/async_checker.go | 35 ++++------------------------------- 2 files changed, 5 insertions(+), 32 deletions(-) diff --git a/params/version.go b/params/version.go index eae9a56a9e26..3916379abda9 100644 --- a/params/version.go +++ b/params/version.go @@ -24,7 +24,7 @@ import ( const ( VersionMajor = 5 // Major version component of the current release VersionMinor = 7 // Minor version component of the current release - VersionPatch = 13 // Patch version component of the current release + VersionPatch = 14 // Patch version component of the current release VersionMeta = "mainnet" // Version metadata to append to the version string ) diff --git a/rollup/ccc/async_checker.go b/rollup/ccc/async_checker.go index 1b1d2a09df59..1cb9b7d78768 100644 --- a/rollup/ccc/async_checker.go +++ b/rollup/ccc/async_checker.go @@ -173,8 +173,6 @@ func (c *AsyncChecker) checkerTask(block *types.Block, ccc *Checker, forkCtx con } header := block.Header() - header.GasUsed = 0 - gasPool := new(core.GasPool).AddGas(header.GasLimit) ccc.Reset() accRc := new(types.RowConsumption) @@ -184,7 +182,7 @@ func (c *AsyncChecker) checkerTask(block *types.Block, ccc *Checker, forkCtx con } var curRc *types.RowConsumption - curRc, err = c.checkTxAndApply(parent, header, statedb, gasPool, tx, ccc) + curRc, err = c.checkTx(parent, header, statedb, tx, ccc) if err != nil { err = &ErrorWithTxnIdx{ TxIdx: uint(txIdx), @@ -208,39 +206,14 @@ func (c *AsyncChecker) checkerTask(block *types.Block, ccc *Checker, forkCtx con } } -func (c *AsyncChecker) checkTxAndApply(parent *types.Block, header *types.Header, state *state.StateDB, gasPool *core.GasPool, tx *types.Transaction, ccc *Checker) (*types.RowConsumption, error) { - // don't commit the state during tracing for circuit capacity checker, otherwise we cannot revert. - // and even if we don't commit the state, the `refund` value will still be correct, as explained in `CommitTransaction` - commitStateAfterApply := false - snap := state.Snapshot() - - // 1. we have to check circuit capacity before `core.ApplyTransaction`, - // because if the tx can be successfully executed but circuit capacity overflows, it will be inconvenient to revert. - // 2. even if we don't commit to the state during the tracing (which means `clearJournalAndRefund` is not called during the tracing), - // the `refund` value will still be correct, because: - // 2.1 when starting handling the first tx, `state.refund` is 0 by default, - // 2.2 after tracing, the state is either committed in `core.ApplyTransaction`, or reverted, so the `state.refund` can be cleared, - // 2.3 when starting handling the following txs, `state.refund` comes as 0 +func (c *AsyncChecker) checkTx(parent *types.Block, header *types.Header, state *state.StateDB, tx *types.Transaction, ccc *Checker) (*types.RowConsumption, error) { trace, err := tracing.NewTracerWrapper().CreateTraceEnvAndGetBlockTrace(c.bc.Config(), c.bc, c.bc.Engine(), c.bc.Database(), - state, parent, types.NewBlockWithHeader(header).WithBody([]*types.Transaction{tx}, nil), commitStateAfterApply) - // `w.current.traceEnv.State` & `w.current.state` share a same pointer to the state, so only need to revert `w.current.state` - // revert to snapshot for calling `core.ApplyMessage` again, (both `traceEnv.GetBlockTrace` & `core.ApplyTransaction` will call `core.ApplyMessage`) - state.RevertToSnapshot(snap) + state, parent, types.NewBlockWithHeader(header).WithBody([]*types.Transaction{tx}, nil), true) if err != nil { return nil, err } - rc, err := ccc.ApplyTransaction(trace) - if err != nil { - return rc, err - } - - _, err = core.ApplyTransaction(c.bc.Config(), c.bc, nil /* coinbase will default to chainConfig.Scroll.FeeVaultAddress */, gasPool, - state, header, tx, &header.GasUsed, *c.bc.GetVMConfig()) - if err != nil { - return nil, err - } - return rc, nil + return ccc.ApplyTransaction(trace) } // ScheduleError forces a block to error on a given transaction index From 521a074f60986d6e503521cdee704f31f6c145ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=96mer=20Faruk=20Irmak?= Date: Mon, 16 Sep 2024 13:56:11 +0300 Subject: [PATCH 2/2] feat: allow removing txns from pool via CLI/RPC (#1041) --- eth/api_backend.go | 4 ++++ internal/ethapi/api.go | 5 +++++ internal/ethapi/backend.go | 1 + internal/web3ext/web3ext.go | 5 +++++ params/version.go | 2 +- 5 files changed, 16 insertions(+), 1 deletion(-) diff --git a/eth/api_backend.go b/eth/api_backend.go index cae5e28efb79..5aee374c3c66 100644 --- a/eth/api_backend.go +++ b/eth/api_backend.go @@ -266,6 +266,10 @@ func (b *EthAPIBackend) SendTx(ctx context.Context, signedTx *types.Transaction) return b.eth.txPool.AddLocal(signedTx) } +func (b *EthAPIBackend) RemoveTx(txHash common.Hash) { + b.eth.txPool.RemoveTx(txHash, true) +} + func (b *EthAPIBackend) GetPoolTransactions() (types.Transactions, error) { pending := b.eth.txPool.Pending(false) var txs types.Transactions diff --git a/internal/ethapi/api.go b/internal/ethapi/api.go index 67bf83af6bfc..b57bc67195f7 100644 --- a/internal/ethapi/api.go +++ b/internal/ethapi/api.go @@ -227,6 +227,11 @@ func (s *PublicTxPoolAPI) Status() map[string]hexutil.Uint { } } +// RemoveTransactionByHash evicts a transaction from the pool. +func (s *PublicTxPoolAPI) RemoveTransactionByHash(ctx context.Context, hash common.Hash) { + s.b.RemoveTx(hash) +} + // Inspect retrieves the content of the transaction pool and flattens it into an // easily inspectable list. func (s *PublicTxPoolAPI) Inspect() map[string]map[string]map[string]string { diff --git a/internal/ethapi/backend.go b/internal/ethapi/backend.go index b2be3ae41a0a..45d595edd51c 100644 --- a/internal/ethapi/backend.go +++ b/internal/ethapi/backend.go @@ -75,6 +75,7 @@ type Backend interface { // Transaction pool API SendTx(ctx context.Context, signedTx *types.Transaction) error + RemoveTx(txHash common.Hash) GetTransaction(ctx context.Context, txHash common.Hash) (*types.Transaction, common.Hash, uint64, uint64, error) GetPoolTransactions() (types.Transactions, error) GetPoolTransaction(txHash common.Hash) *types.Transaction diff --git a/internal/web3ext/web3ext.go b/internal/web3ext/web3ext.go index 023c13687144..2967a849b1a1 100644 --- a/internal/web3ext/web3ext.go +++ b/internal/web3ext/web3ext.go @@ -772,6 +772,11 @@ web3._extend({ call: 'txpool_contentFrom', params: 1, }), + new web3._extend.Method({ + name: 'removeTransactionByHash', + call: 'txpool_removeTransactionByHash', + params: 1 + }), ] }); ` diff --git a/params/version.go b/params/version.go index 3916379abda9..7f4b7c582248 100644 --- a/params/version.go +++ b/params/version.go @@ -24,7 +24,7 @@ import ( const ( VersionMajor = 5 // Major version component of the current release VersionMinor = 7 // Minor version component of the current release - VersionPatch = 14 // Patch version component of the current release + VersionPatch = 15 // Patch version component of the current release VersionMeta = "mainnet" // Version metadata to append to the version string )