Skip to content

Conversation

@gzliudan
Copy link
Collaborator

@gzliudan gzliudan commented Jan 6, 2026

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

Copilot AI review requested due to automatic review settings January 6, 2026 11:15
@coderabbitai
Copy link

coderabbitai bot commented Jan 6, 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 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/types to miner package 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
Copy link

Copilot AI Jan 6, 2026

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.

Suggested change
break
log.Warn("Skipping unresolved or invalid lazy transaction")
txs.Pop()
continue

Copilot uses AI. Check for mistakes.
Comment on lines +362 to +368
txs[acc] = append(txs[acc], &txpool.LazyTransaction{
Hash: tx.Hash(),
Tx: &txpool.Transaction{Tx: tx},
Time: tx.Time(),
GasFeeCap: tx.GasFeeCap(),
GasTipCap: tx.GasTipCap(),
})
Copy link

Copilot AI Jan 6, 2026

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.

Copilot uses AI. Check for mistakes.
Comment on lines +2115 to +2131
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
}
}
Copy link

Copilot AI Jan 6, 2026

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.

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

Copilot AI Jan 6, 2026

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.

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

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 6, 2026

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

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