fix(core/txpool): allow tx and authority regardless of admission order #31373#2185
fix(core/txpool): allow tx and authority regardless of admission order #31373#2185gzliudan wants to merge 1 commit intoXinFinOrg:dev-upgradefrom
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 ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
📝 Coding Plan
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 |
c259656 to
5deeb41
Compare
There was a problem hiding this comment.
Pull request overview
This PR updates txpool reservation semantics and LegacyPool SetCode authorization validation so a transaction sender and an authority can be accepted regardless of which one is admitted first, removing order-dependence in admission logic.
Changes:
- Refactors
txpool.Reserverinto an interface (with a renamed concreteReservationHandle) and updatesSubPool.Initto accept the interface. - Updates LegacyPool authorization validation to allow at most one in-flight tx for an authority (and to only treat reservations from other subpools as conflicting).
- Expands LegacyPool SetCode transaction tests and introduces a test reserver helper to sanity-check reserve/release behavior.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 5 comments.
| File | Description |
|---|---|
| core/txpool/subpool.go | Updates SubPool.Init to accept a Reserver interface instead of a concrete pointer type. |
| core/txpool/reserver.go | Introduces Reserver interface, renames concrete handle type, and changes Has to mean “reserved by another pool”. |
| core/txpool/legacypool/legacypool.go | Adjusts reservation field/type, authorization conflict checks, and reservation release logic in Clear(). |
| core/txpool/legacypool/legacypool_test.go | Updates/extends SetCode-related tests and adds a test reserver implementation. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| func newReserver() *txpool.Reserver { | ||
| return txpool.NewReservationTracker().NewHandle(42) | ||
| // reserver is a utility struct to sanity check that accounts are | ||
| // properly reserved by the blobpool (no duplicate reserves or unreserves). |
| t.Fatalf("%s: failed to add with remote setcode transaction: %v", name, err) | ||
| } | ||
| // Now send a regular tx from B. | ||
| // B should not be considred as having an in-flight delegation, so |
| }, | ||
| }, | ||
| { | ||
| // This test is analogous to the previous one, but the the replaced |
| name: "remove-hash-from-authority-tracker", | ||
| pending: 10, | ||
| run: func(name string) { | ||
| // Attempt to submit a delegation from an account with a pending tx. | ||
| if err := pool.addRemoteSync(pricedTransaction(0, 100000, minGasPrice, keyC)); err != nil { | ||
| t.Fatalf("%s: failed to add with remote setcode transaction: %v", name, err) | ||
| var keys []*ecdsa.PrivateKey | ||
| for i := 0; i < 30; i++ { | ||
| key, _ := crypto.GenerateKey() | ||
| keys = append(keys, key) | ||
| addr := crypto.PubkeyToAddress(key.PublicKey) | ||
| testAddBalance(pool, addr, big.NewInt(params.Ether)) | ||
| } | ||
| if err, want := pool.addRemoteSync(setCodeTx(0, keyA, []unsignedAuth{{1, keyC}})), ErrAuthorityReserved; !errors.Is(err, want) { | ||
| t.Fatalf("%s: error mismatch: want %v, have %v", name, want, err) | ||
| // Create a transactions with 3 unique auths so the lookup's auth map is | ||
| // filled with addresses. | ||
| for i := 0; i < 30; i += 3 { | ||
| if err := pool.addRemoteSync(pricedSetCodeTx(0, 250000, minGasFee, minGasFee, keys[i], []unsignedAuth{{0, keys[i]}, {0, keys[i+1]}, {0, keys[i+2]}})); err != nil { | ||
| t.Fatalf("%s: failed to add with remote setcode transaction: %v", name, err) | ||
| } | ||
| } | ||
| // Replace one of the transactions with a normal transaction so that the | ||
| // original hash is removed from the tracker. The hash should be | ||
| // associated with 3 different authorities. | ||
| if err := pool.addRemoteSync(pricedTransaction(0, 100000, legacyReplacePrice, keys[0])); err != nil { | ||
| t.Fatalf("%s: failed to replace with remote transaction: %v", name, err) | ||
| } |
| } | ||
| if err, want := pool.addRemoteSync(setCodeTx(0, keyA, []unsignedAuth{{1, keyC}})), ErrAuthorityReserved; !errors.Is(err, want) { | ||
| t.Fatalf("%s: error mismatch: want %v, have %v", name, want, err) | ||
| // Create a transactions with 3 unique auths so the lookup's auth map is |
Proposed changes
Ref: ethereum#31373
Types of changes
What types of changes does your code introduce to XDC network?
Put an
✅in the boxes that applyImpacted Components
Which parts of the codebase does this PR touch?
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