-
Notifications
You must be signed in to change notification settings - Fork 69
core/txpool/legacypool: reject gapped tx from delegated account #31430 #1928
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 |
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 implements EIP-7702 delegation support by adding restrictions on transactions from delegated accounts and introducing a lazy transaction loading mechanism. The main purpose is to prevent transaction churn attacks on delegated accounts by limiting them to one in-flight transaction at a time.
Key changes include:
- Refactored transaction ordering logic from
core/typespackage tominerpackage with support forLazyTransactionwrapper - Added address reservation mechanism in transaction pool to ensure subpool exclusivity
- Implemented delegation and authorization tracking to enforce single-transaction limits on delegated accounts
Reviewed changes
Copilot reviewed 17 out of 17 changed files in this pull request and generated 9 comments.
Show a summary per file
| File | Description |
|---|---|
| miner/ordering.go | New file containing transaction ordering logic moved from core/types, now using LazyTransaction |
| miner/ordering_test.go | New test file with comprehensive tests for transaction ordering, including special transaction separation |
| miner/worker.go | Updated to use new ordering logic with LazyTransaction wrapper and baseFee parameter |
| core/types/transaction.go | Removed TransactionsByPriceAndNonce and related heap structures; added SetCodeAuthorities() and Time() methods |
| core/types/transaction_test.go | Removed ordering tests that were moved to miner package |
| core/types/tx_setcode.go | Fixed SignSetCode parameter order (prv, auth instead of auth, prv) |
| core/txpool/txpool.go | Added address reservation mechanism and LazyTransaction support in Pending() |
| core/txpool/subpool.go | Added LazyTransaction wrapper type and AddressReserver callback; updated SubPool interface |
| core/txpool/validation.go | Enhanced validation with SetCode transaction checks and UsedAndLeftSlots callback |
| core/txpool/errors.go | Moved ErrFutureReplacePending to legacypool; added ErrAccountLimitExceeded |
| core/txpool/legacypool/legacypool.go | Major changes: added delegation limit checking, authority validation, address reservation, and Clear() method |
| core/txpool/legacypool/legacypool_test.go | Added comprehensive tests for SetCode transactions and delegation scenarios; updated all Init() calls |
| core/txpool/legacypool/legacypool2_test.go | Updated Init() calls to include makeAddressReserver() |
| eth/protocol.go | Updated Pending() interface to return LazyTransaction |
| eth/sync.go | Updated to resolve LazyTransaction when syncing |
| eth/api_backend.go | Updated to resolve LazyTransaction when retrieving pool transactions |
| eth/helper_test.go | Updated test helper to return LazyTransaction from Pending() |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| // price sorted transactions in a nonce-honouring way. | ||
| // | ||
| // Note, the input map is reowned so the caller should not interact any more with | ||
| // if after providing it to the constructor. |
Copilot
AI
Jan 7, 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 comment has a typo: "if after" should be "it after".
| // if after providing it to the constructor. | |
| // it after providing it to the constructor. |
| // two states over time as they are received and processed. | ||
| // | ||
| // In addition to tracking transactions, the pool also tracks a set of pending SetCode | ||
| // authorizations (EIP7702). This helps minimize number of transactions that can be |
Copilot
AI
Jan 7, 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 comment has a typo: "minimize number" should be "minimize the number".
| // authorizations (EIP7702). This helps minimize number of transactions that can be | |
| // authorizations (EIP7702). This helps minimize the number of transactions that can be |
| 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 7, 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's 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 |
| i_price := s.txs[i].fees | ||
| if tx := s.txs[i].tx.Resolve(); tx != nil && tx.Tx.To() != nil { | ||
| if _, ok := s.payersSwap[*tx.Tx.To()]; ok { | ||
| i_price = common.TRC21GasPrice | ||
| } | ||
| } | ||
|
|
||
| j_price := s.txs[j].fees | ||
| if tx := s.txs[j].tx.Resolve(); tx != nil && tx.Tx.To() != nil { | ||
| if _, ok := s.payersSwap[*tx.Tx.To()]; ok { | ||
| j_price = common.TRC21GasPrice | ||
| } | ||
| } | ||
|
|
||
| // If the prices are equal, use the time the transaction was first seen for | ||
| // deterministic sorting | ||
| cmp := i_price.Cmp(j_price) |
Copilot
AI
Jan 7, 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 variable name uses underscores which is inconsistent with Go naming conventions. Consider using camelCase: iPrice instead of i_price and jPrice instead of j_price.
| i_price := s.txs[i].fees | |
| if tx := s.txs[i].tx.Resolve(); tx != nil && tx.Tx.To() != nil { | |
| if _, ok := s.payersSwap[*tx.Tx.To()]; ok { | |
| i_price = common.TRC21GasPrice | |
| } | |
| } | |
| j_price := s.txs[j].fees | |
| if tx := s.txs[j].tx.Resolve(); tx != nil && tx.Tx.To() != nil { | |
| if _, ok := s.payersSwap[*tx.Tx.To()]; ok { | |
| j_price = common.TRC21GasPrice | |
| } | |
| } | |
| // If the prices are equal, use the time the transaction was first seen for | |
| // deterministic sorting | |
| cmp := i_price.Cmp(j_price) | |
| iPrice := s.txs[i].fees | |
| if tx := s.txs[i].tx.Resolve(); tx != nil && tx.Tx.To() != nil { | |
| if _, ok := s.payersSwap[*tx.Tx.To()]; ok { | |
| iPrice = common.TRC21GasPrice | |
| } | |
| } | |
| jPrice := s.txs[j].fees | |
| if tx := s.txs[j].tx.Resolve(); tx != nil && tx.Tx.To() != nil { | |
| if _, ok := s.payersSwap[*tx.Tx.To()]; ok { | |
| jPrice = common.TRC21GasPrice | |
| } | |
| } | |
| // If the prices are equal, use the time the transaction was first seen for | |
| // deterministic sorting | |
| cmp := iPrice.Cmp(jPrice) |
| // Note, the input map is reowned so the caller should not interact any more with | ||
| // if after providing it to the constructor. |
Copilot
AI
Jan 7, 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 word "reowned" should be "re-owned" or more likely "reused" based on the context.
| // Note, the input map is reowned so the caller should not interact any more with | |
| // if after providing it to the constructor. | |
| // Note, the input map is reused so the caller should not interact any more with | |
| // it after providing it to the constructor. |
| // trivially churned in the pool. As a standard rule, any account with a deployed | ||
| // delegation or an in-flight authorization to deploy a delegation will only be allowed a | ||
| // single transaction slot instead of the standard number. This is due to the possibility | ||
| // of the account being sweeped by an unrelated account. |
Copilot
AI
Jan 7, 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 phrase "sweeped by" should be "swept by" (past tense of sweep is swept, not sweeped).
| // of the account being sweeped by an unrelated account. | |
| // of the account being swept by an unrelated account. |
| // removeTx removes a single transaction from the queue, moving all subsequent | ||
| // transactions back to the future queue. | ||
| // | ||
| // In unreserve is false, the account will not be relinquished to the main txpool |
Copilot
AI
Jan 7, 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 comment has a typo: "In unreserve" should be "If unreserve".
| // In unreserve is false, the account will not be relinquished to the main txpool | |
| // If unreserve is false, the account will not be relinquished to the main txpool |
| warped := lazyTx.Resolve() | ||
| if warped == nil || warped.Tx == nil { | ||
| break | ||
| } | ||
| tx := warped.Tx |
Copilot
AI
Jan 7, 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's a missing nil check after calling lazyTx.Resolve(). If Resolve() returns a non-nil value but warped.Tx is nil, execution continues to line 1088 which could cause a nil pointer dereference. Consider combining the nil checks or adding a separate check for warped.Tx before the assignment on line 1088.
| if tx := lazyTx.Resolve(); tx.Tx.IsSpecialTransaction() { | ||
| specialTxs = append(specialTxs, tx.Tx) | ||
| } else { | ||
| normalTxs = append(normalTxs, lazyTx) | ||
| } |
Copilot
AI
Jan 7, 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's a missing nil check after calling lazyTx.Resolve() on line 133. If Resolve() returns nil, or if tx.Tx is nil, this will cause a nil pointer dereference when calling tx.Tx.IsSpecialTransaction(). Consider adding a nil check before accessing the transaction.
Proposed changes
Ref: ethereum#31430
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