-
Notifications
You must be signed in to change notification settings - Fork 69
core/txpool/legacypool: add setCodeTx reorg test #31206 #1924
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
base: dev-upgrade
Are you sure you want to change the base?
Conversation
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
62c7d53 to
5ba0bb3
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR adds support for EIP-7702 SetCode transactions to the XDPoSChain transaction pool and refactors transaction ordering logic from the types package to the miner package. The changes introduce a LazyTransaction wrapper to optimize transaction handling in the miner and improve memory efficiency.
Key changes:
- Add EIP-7702 SetCode transaction support with authority tracking and validation in the legacy transaction pool
- Refactor transaction ordering logic from
core/typestominerpackage with support for LazyTransaction - Implement address reservation mechanism to prevent cross-subpool conflicts for accounts with delegations
Reviewed changes
Copilot reviewed 17 out of 17 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| miner/ordering.go | New transaction ordering implementation moved from types package, with LazyTransaction support |
| miner/ordering_test.go | Comprehensive tests for transaction ordering including EIP-1559 and special transaction handling |
| miner/worker.go | Updated to use LazyTransaction wrapper and new ordering implementation |
| core/txpool/txpool.go | Added address reservation mechanism to ensure exclusive account access per subpool |
| core/txpool/subpool.go | Introduced LazyTransaction type and AddressReserver callback |
| core/txpool/validation.go | Added SetCode transaction validation rules including authority conflict checking |
| core/txpool/legacypool/legacypool.go | Implemented SetCode support with authority tracking and single-tx-per-delegation limits |
| core/txpool/legacypool/legacypool_test.go | Added comprehensive SetCode transaction tests including reorg scenarios |
| core/txpool/errors.go | Added new error types for account limits and authority conflicts |
| core/types/transaction.go | Removed transaction ordering code (moved to miner), added SetCodeAuthorities helper |
| core/types/transaction_test.go | Removed ordering tests (moved to miner package) |
| core/types/tx_setcode.go | Changed SignSetCode parameter order for consistency |
| eth/protocol.go | Updated Pending interface to return LazyTransaction |
| eth/sync.go | Updated to handle LazyTransaction resolution |
| eth/api_backend.go | Updated to handle LazyTransaction resolution |
| eth/helper_test.go | Updated test helper to return LazyTransaction |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
|
||
| warped := lazyTx.Resolve() | ||
| if warped == nil || warped.Tx == nil { | ||
| break |
Copilot
AI
Jan 6, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When Resolve returns nil or the inner Tx is nil, the code breaks out of the loop entirely. This means that if a single lazy transaction fails to resolve, all subsequent transactions in the queue will be skipped. Consider using txs.Pop() or txs.Shift() to skip the problematic transaction and continue processing remaining transactions instead of breaking.
| break | |
| log.Warn("Skipping unresolved or invalid lazy transaction") | |
| txs.Pop() | |
| continue |
| txs[acc] = append(txs[acc], &txpool.LazyTransaction{ | ||
| Hash: tx.Hash(), | ||
| Tx: &txpool.Transaction{Tx: tx}, | ||
| Time: tx.Time(), | ||
| GasFeeCap: tx.GasFeeCap(), | ||
| GasTipCap: tx.GasTipCap(), | ||
| }) |
Copilot
AI
Jan 6, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The LazyTransaction being created is missing the Pool field. If Resolve() is called when Tx is nil, it will attempt to call ltx.Pool.Get(ltx.Hash) with a nil Pool, causing a nil pointer dereference. Since Tx is already being set here, this might not be an immediate issue, but it creates fragile code. Consider either setting the Pool field or ensuring Tx is always non-nil when the Pool is nil.
| func (t *lookup) removeAuthorities(hash common.Hash) { | ||
| for addr := range t.auths { | ||
| list := t.auths[addr] | ||
| // Remove tx from tracker. | ||
| if i := slices.Index(list, hash); i >= 0 { | ||
| list = append(list[:i], list[i+1:]...) | ||
| } else { | ||
| log.Error("Authority with untracked tx", "addr", addr, "hash", hash) | ||
| } | ||
| if len(list) == 0 { | ||
| // If list is newly empty, delete it entirely. | ||
| delete(t.auths, addr) | ||
| continue | ||
| } | ||
| t.auths[addr] = list | ||
| } | ||
| } |
Copilot
AI
Jan 6, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The removeAuthorities function iterates over all addresses in t.auths and attempts to remove the transaction hash from each. However, a transaction's authorities are specific addresses - not all addresses in the map. This implementation is inefficient as it checks every address in the auths map even though the transaction being removed only references a small subset. Additionally, the error log at line 2122 will be triggered for every address that doesn't contain the hash. Consider storing a reverse mapping from transaction hash to its authority addresses, or retrieve the authorities from the transaction before removal.
| if tx := lazyTx.Resolve(); tx.Tx.IsSpecialTransaction() { | ||
| specialTxs = append(specialTxs, tx.Tx) | ||
| } else { |
Copilot
AI
Jan 6, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At line 133, lazyTx.Resolve() is called without checking if it returns nil. If Resolve returns nil, dereferencing tx.Tx will cause a nil pointer panic. Consider adding a nil check before accessing tx.Tx.
| if tx := lazyTx.Resolve(); tx.Tx.IsSpecialTransaction() { | |
| specialTxs = append(specialTxs, tx.Tx) | |
| } else { | |
| if tx := lazyTx.Resolve(); tx != nil && tx.Tx.IsSpecialTransaction() { | |
| specialTxs = append(specialTxs, tx.Tx) | |
| } else if tx != nil { |
| return fmt.Errorf("%w: balance %v, queued cost %v, tx cost %v, overshot %v", core.ErrInsufficientFunds, balance, spent, cost, new(big.Int).Sub(need, newBalance)) | ||
| } | ||
| // Transaction takes a new nonce value out of the pool. Ensure it doesn't | ||
| // overflow the number of permitted transactions from a single accoun |
Copilot
AI
Jan 6, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is a typo in the comment: "accoun" should be "account".
| // overflow the number of permitted transactions from a single accoun | |
| // overflow the number of permitted transactions from a single account |
Proposed changes
Ref: ethereum#31206
Types of changes
What types of changes does your code introduce to XDC network?
Put an
✅in the boxes that applyImpacted Components
Which part of the codebase this PR will touch base on,
Put an
✅in the boxes that applyChecklist
Put an
✅in the boxes once you have confirmed below actions (or provide reasons on not doing so) that