Skip to content

fix(core/txpool/legacypool): fix flaky test TestAllowedTxSize #30975#2172

Open
gzliudan wants to merge 1 commit intoXinFinOrg:dev-upgradefrom
gzliudan:fix-TestAllowedTxSize
Open

fix(core/txpool/legacypool): fix flaky test TestAllowedTxSize #30975#2172
gzliudan wants to merge 1 commit intoXinFinOrg:dev-upgradefrom
gzliudan:fix-TestAllowedTxSize

Conversation

@gzliudan
Copy link
Collaborator

Proposed changes

Ref: ethereum#30975

Types of changes

What types of changes does your code introduce to XDC network?
Put an in the boxes that apply

  • build: Changes that affect the build system or external dependencies
  • ci: Changes to CI configuration files and scripts
  • chore: Changes that don't change source code or tests
  • docs: Documentation only changes
  • feat: A new feature
  • fix: A bug fix
  • perf: A code change that improves performance
  • refactor: A code change that neither fixes a bug nor adds a feature
  • revert: Revert something
  • style: Changes that do not affect the meaning of the code
  • test: Adding missing tests or correcting existing tests

Impacted Components

Which parts of the codebase does this PR touch?
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
  • Tested on a private network from the genesis block and monitored the chain operating correctly for multiple epochs.
  • 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 March 11, 2026 09:16
@coderabbitai
Copy link

coderabbitai bot commented Mar 11, 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.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: e68b89dd-8f1c-4e4a-b319-5c8a0b7ad8a5

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

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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 targets a flaky unit test in the legacy txpool by making TestAllowedTxSize derive transaction sizes and funding parameters based on the current chain rules, instead of relying on fixed assumptions.

Changes:

  • Funds the sender account based on GetMinGasPrice(head.Number) and head.GasLimit instead of a fixed balance.
  • Computes the maximum allowed transaction data length empirically using actual signed tx sizes, then tests acceptance/rejection around the boundary.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +1365 to 1385
txWithLargeData := pricedDataTransaction(0, pool.currentHead.Load().GasLimit, minGasPrice, key, largeDataLength)
maxTxLengthWithoutData := txWithLargeData.Size() - largeDataLength
maxTxDataLength := txMaxSize - maxTxLengthWithoutData
for tx := pricedDataTransaction(0, pool.currentHead.Load().GasLimit, minGasPrice, key, maxTxDataLength); tx.Size() > txMaxSize; {
maxTxDataLength--
tx = pricedDataTransaction(0, pool.currentHead.Load().GasLimit, minGasPrice, key, maxTxDataLength)
}
minOversizedDataLength := maxTxDataLength + 1
for tx := pricedDataTransaction(0, pool.currentHead.Load().GasLimit, minGasPrice, key, minOversizedDataLength); tx.Size() <= txMaxSize; {
minOversizedDataLength++
tx = pricedDataTransaction(0, pool.currentHead.Load().GasLimit, minGasPrice, key, minOversizedDataLength)
}

// Try adding a transaction with maximal allowed size
tx := pricedDataTransaction(0, pool.currentHead.Load().GasLimit, big.NewInt(300000000), key, dataSize)
tx := pricedDataTransaction(0, pool.currentHead.Load().GasLimit, minGasPrice, key, maxTxDataLength)
if err := pool.addRemoteSync(tx); err != nil {
t.Fatalf("failed to add transaction of size %d, close to maximal: %v", int(tx.Size()), err)
}
// Try adding a transaction with random allowed size
if err := pool.addRemoteSync(pricedDataTransaction(1, pool.currentHead.Load().GasLimit, big.NewInt(300000000), key, uint64(rand.Intn(int(dataSize))))); err != nil {
if err := pool.addRemoteSync(pricedDataTransaction(1, pool.currentHead.Load().GasLimit, minGasPrice, key, uint64(rand.Intn(int(maxTxDataLength+1))))); err != nil {
t.Fatalf("failed to add transaction of random allowed size: %v", err)
Copy link

Copilot AI Mar 11, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maxTxDataLength/minOversizedDataLength are derived using pricedDataTransaction calls that generate fresh random payloads (and thus different signatures) on each iteration. Later you create new transactions again using those lengths (e.g. at the “Try adding…” calls), which can change the RLP-encoded size by a few bytes and reintroduce flakiness around the txMaxSize boundary. To make this deterministic, either (a) build deterministic tx data for this test (fixed byte pattern), or (b) keep/reuse the exact tx instances found by the loops, and for the “random allowed size” case ensure the generated tx is checked/adjusted to be <= txMaxSize before calling addRemoteSync.

Copilot uses AI. Check for mistakes.

// Find the maximum data length for the kind of transaction which will
// be generated in the pool.addRemoteSync calls below.
const largeDataLength = txMaxSize - 200 // enough to have a 5 bytes RLP encoding of the data length number
Copy link

Copilot AI Mar 11, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The inline comment about “enough to have a 5 bytes RLP encoding of the data length number” looks inaccurate for the sizes involved here (txMaxSize is 64KB, so the RLP length-of-length for the data field is much smaller). Consider rewording this to avoid implying a specific RLP encoding size, or explain the actual threshold being targeted by the 200-byte margin.

Suggested change
const largeDataLength = txMaxSize - 200 // enough to have a 5 bytes RLP encoding of the data length number
const largeDataLength = txMaxSize - 200 // leave enough room for RLP overhead and other transaction fields

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.

2 participants