Skip to content

TxPool fixes #260

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

Merged
merged 6 commits into from
Jun 12, 2025
Merged

TxPool fixes #260

merged 6 commits into from
Jun 12, 2025

Conversation

lukechampine
Copy link
Member

In the course of writing a test for full txpool behavior, I found a bug in the index handling: all of the transactions were being assigned an index of len(txpool.txns), instead of sequential ones! This was almost certainly the result of copy-pasting the m.txpool.indices[txid] = len(m.txpool.txns) from AddPoolTransactions; it breaks in revalidatePool because we're appending to filtered, not m.txpool.txns directly.

This is probably the root cause of #256. We had been blaming parentMap for that, so I ripped it out. I think it should stay ripped out, though, since benchmarks show that the operation it's optimizing is not particularly slow in the first place.

I also added an important validation step to updateV2TransactionProofs. This should prevent the panic seen in #254.

@Copilot Copilot AI review requested due to automatic review settings June 9, 2025 16:47
@github-project-automation github-project-automation bot moved this to In Progress in Sia Jun 9, 2025
Copy link

@Copilot 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 addresses several transaction pool issues by fixing index assignment, removing an outdated parentMap cache, and strengthening proof validation.

  • Fixes incorrect index assignment in revalidatePool to use the filtered slice length.
  • Removes the parentMap cache and refactors computeParentMap to build a fresh map.
  • Adds a validation step in updateV2TransactionProofs and updates tests to reflect new error handling.

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
chain/pool_test.go Adjust error assertion for AddV2PoolTransactions test
chain/manager_test.go Add TestFullTxPool to validate full pool behavior
chain/manager.go Fix index handling, remove parentMap cache, add proof validation
Comments suppressed due to low confidence (2)

chain/manager_test.go:369

  • This assertion assumes ids has at least one element. If the loop above breaks early, ids may be empty and cause a panic. Add a length check before indexing.
if _, ok := cm.PoolTransaction(ids[0]); !ok {

chain/manager.go:645

  • [nitpick] Recomputing the entire parentMap on each call may degrade performance if this method is invoked frequently. Consider restoring a cache or documenting expected call frequency.
parentMap := make(map[types.Hash256]int)

@lukechampine lukechampine mentioned this pull request Jun 9, 2025
@lukechampine
Copy link
Member Author

[nitpick] Recomputing the entire parentMap on each call may degrade performance if this method is invoked frequently. Consider restoring a cache or documenting expected call frequency.

:omegalol:

@lukechampine
Copy link
Member Author

ok, slight snag here. The RHPv4 code does this in a few places:

- Fund transaction
- Call cm.V2TransactionSet to update the proofs
- Send transaction to host, receive host inputs
- Sign transaction
- Send signed to host

But this fails, because V2TransactionSet now fully validates the transaction, but the transaction is missing inputs and signatures.

I think we could solve this by not updating the proofs renter-side (since the host will update them anyway, after it has all the signatures). But that doesn't address the issue of V2TransactionSet on invalid inputs. So I think we should instead switch to validating only the Merkle proofs in updateV2TransactionProofs, e.g. by adding a ValidateTransactionElements method to consensus.ElementAccumulator.

Copy link
Member

@ChrisSchinnerl ChrisSchinnerl left a comment

Choose a reason for hiding this comment

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

Looking pretty good but broke a few tests it seems.

@n8maninger
Copy link
Member

ok, slight snag here. The RHPv4 code does this in a few places:

- Fund transaction
- Call cm.V2TransactionSet to update the proofs
- Send transaction to host, receive host inputs
- Sign transaction
- Send signed to host

But this fails, because V2TransactionSet now fully validates the transaction, but the transaction is missing inputs and signatures.

I think we could solve this by not updating the proofs renter-side (since the host will update them anyway, after it has all the signatures). But that doesn't address the issue of V2TransactionSet on invalid inputs. So I think we should instead switch to validating only the Merkle proofs in updateV2TransactionProofs, e.g. by adding a ValidateTransactionElements method to consensus.ElementAccumulator.

We'd need to grab the txn parents some other way, but should be fine. I initially thought that might introduce a race with the contract elements, but it appears we rely on the host to fill it in already.

@lukechampine lukechampine merged commit 059d6d9 into master Jun 12, 2025
11 checks passed
@lukechampine lukechampine deleted the parent-map branch June 12, 2025 15:06
@github-project-automation github-project-automation bot moved this from In Progress to Done in Sia Jun 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

4 participants