Skip to content

Conversation

@gzliudan
Copy link
Collaborator

@gzliudan gzliudan commented Jan 7, 2026

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 apply

  • Bugfix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation Update (if none of the other choices apply)
  • Regular KTLO or any of the maintaince work. e.g code style
  • CICD Improvement

Impacted Components

Which part of the codebase this PR will touch base on,

Put an in the boxes that apply

  • Consensus
  • Account
  • Network
  • Geth
  • Smart Contract
  • External components
  • Not sure (Please specify below)

Checklist

Put an in the boxes once you have confirmed below actions (or provide reasons on not doing so) that

  • This PR has sufficient test coverage (unit/integration test) OR I have provided reason in the PR description for not having test coverage
  • Provide an end-to-end test plan in the PR description on how to manually test it on the devnet/testnet.
  • Tested the backwards compatibility.
  • Tested with XDC nodes running this version co-exist with those running the previous version.
  • Relevant documentation has been updated as part of this PR
  • N/A

@coderabbitai
Copy link

coderabbitai bot commented Jan 7, 2026

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.


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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

Copilot AI left a 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/types package to miner package with support for LazyTransaction wrapper
  • 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.
Copy link

Copilot AI Jan 7, 2026

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".

Suggested change
// if after providing it to the constructor.
// it after providing it to the constructor.

Copilot uses AI. Check for mistakes.
// 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
Copy link

Copilot AI Jan 7, 2026

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".

Suggested change
// authorizations (EIP7702). This helps minimize number of transactions that can be
// authorizations (EIP7702). This helps minimize the number of transactions that can be

Copilot uses AI. Check for mistakes.
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
Copy link

Copilot AI Jan 7, 2026

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".

Suggested change
// overflow the number of permitted transactions from a single accoun
// overflow the number of permitted transactions from a single account

Copilot uses AI. Check for mistakes.
Comment on lines +68 to +84
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)
Copy link

Copilot AI Jan 7, 2026

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.

Suggested change
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)

Copilot uses AI. Check for mistakes.
Comment on lines +121 to +122
// Note, the input map is reowned so the caller should not interact any more with
// if after providing it to the constructor.
Copy link

Copilot AI Jan 7, 2026

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.

Suggested change
// 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.

Copilot uses AI. Check for mistakes.
// 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.
Copy link

Copilot AI Jan 7, 2026

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).

Suggested change
// of the account being sweeped by an unrelated account.
// of the account being swept by an unrelated account.

Copilot uses AI. Check for mistakes.
// 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
Copy link

Copilot AI Jan 7, 2026

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".

Suggested change
// 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

Copilot uses AI. Check for mistakes.
Comment on lines +1084 to +1088
warped := lazyTx.Resolve()
if warped == nil || warped.Tx == nil {
break
}
tx := warped.Tx
Copy link

Copilot AI Jan 7, 2026

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.

Copilot uses AI. Check for mistakes.
Comment on lines +133 to +137
if tx := lazyTx.Resolve(); tx.Tx.IsSpecialTransaction() {
specialTxs = append(specialTxs, tx.Tx)
} else {
normalTxs = append(normalTxs, lazyTx)
}
Copy link

Copilot AI Jan 7, 2026

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.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant