Skip to content
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

Feature/immediately handle subintent nullification #1016

Merged
merged 4 commits into from
Nov 11, 2024

Conversation

dhedey
Copy link
Contributor

@dhedey dhedey commented Nov 7, 2024

Summary

The main intention was to ensure subintent handling is fixed/immediate in the pending result cache and the mempool.

As part of this ticket, I worked through a few refactors:

  • Encapsulated mempool related systems directly under the MempoolManager where it can (A) safely handle atomicity of operations and avoid deadlocks, and (B) enable us to eventually safely refactor and possibly merge the cache and mempool. That was the intended direction ~18 months ago, I'm not quite sure why it ended up not being finished - but I've pushed through with the merger anyway. I think it works nicely.
  • Improved the scope of our locks to be smaller. In one particular case in add_if_committable_internal I expect this to have a non-trivial impact on throughput.
  • Improved the pending rejection "is permanent" checks to require passing an AtState so we can't use the wrong thing by mistake; and commonise the code.

Testing

Might add some more unit tests tomorrow.

@dhedey dhedey changed the base branch from main to tests/improve-core-api-test-abstractions November 7, 2024 04:02
Copy link

github-actions bot commented Nov 7, 2024

Phylum Report Link

Copy link

github-actions bot commented Nov 7, 2024

Docker tags
docker.io/radixdlt/private-babylon-node:pr-1016
docker.io/radixdlt/private-babylon-node:35688e4d64
docker.io/radixdlt/private-babylon-node:sha-35688e4

Base automatically changed from tests/improve-core-api-test-abstractions to develop November 7, 2024 11:47
@codecov-commenter
Copy link

codecov-commenter commented Nov 7, 2024

Codecov Report

Attention: Patch coverage is 39.06250% with 351 lines in your changes missing coverage. Please review.

Project coverage is 42.7%. Comparing base (befe08d) to head (851b910).
Report is 2 commits behind head on develop.

Files with missing lines Patch % Lines
...er/src/mempool/pending_transaction_result_cache.rs 56.5% 116 Missing ⚠️
...-rust/state-manager/src/mempool/mempool_manager.rs 24.0% 98 Missing ⚠️
...e-rust/state-manager/src/transaction/validation.rs 5.6% 67 Missing ⚠️
...rust/state-manager/src/mempool/priority_mempool.rs 18.1% 36 Missing ⚠️
core-rust/state-manager/src/mempool/mod.rs 0.0% 5 Missing ⚠️
...er/src/core_api/handlers/lts/transaction_status.rs 0.0% 4 Missing ⚠️
...erver/src/core_api/handlers/mempool_transaction.rs 0.0% 4 Missing ⚠️
...server/src/core_api/handlers/transaction_status.rs 0.0% 4 Missing ⚠️
core-rust/state-manager/src/committer.rs 60.0% 4 Missing ⚠️
core-rust/state-manager/src/jni/mempool.rs 0.0% 4 Missing ⚠️
... and 6 more
Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff             @@
##             develop   #1016     +/-   ##
===========================================
- Coverage       42.8%   42.7%   -0.2%     
- Complexity      4621    4623      +2     
===========================================
  Files           1759    1759             
  Lines          54252   54468    +216     
  Branches        1524    1524             
===========================================
+ Hits           23266   23302     +36     
- Misses         30505   30686    +181     
+ Partials         481     480      -1     
Flag Coverage Δ
rust 42.7% <39.0%> (-0.2%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
...er/src/core_api/handlers/lts/transaction_submit.rs 0.0% <ø> (ø)
...e-api-server/src/core_api/handlers/mempool_list.rs 0.0% <ø> (ø)
core-rust/p2p/src/address_book_components.rs 22.2% <ø> (ø)
core-rust/p2p/src/migration.rs 100.0% <ø> (ø)
core-rust/p2p/src/safety_store_components.rs 5.5% <ø> (ø)
...ust/state-manager/src/jni/node_rust_environment.rs 0.0% <ø> (ø)
core-rust/state-manager/src/store/traits.rs 37.0% <ø> (ø)
core-rust/state-manager/src/types.rs 50.5% <ø> (ø)
...-server/src/core_api/handlers/transaction_parse.rs 0.0% <0.0%> (ø)
core-rust/state-manager/src/state_manager.rs 86.6% <94.1%> (-0.1%) ⬇️
... and 14 more

... and 2 files with indirect coverage changes

Copy link

sonarqubecloud bot commented Nov 7, 2024

MempoolRejectionReason::TransactionIntentAlreadyCommitted(_) => false,
MempoolRejectionReason::SubintentAlreadyFinalized(_) => false,
MempoolRejectionReason::FromExecution(_) => true,
MempoolRejectionReason::ValidationError(_) => false,
Copy link
Member

Choose a reason for hiding this comment

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

Per cuttlefish update, transaction validation is stateful. Is the permanent rejection logic below still correct?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not quite - if a Cuttlefish-only transaction is evaluated against Bottlenose it will be permanently rejected at validation time, but then become acceptable in Cuttlefish.

I think this is unlikely to cause any critical issues -- and have some ideas for tweaking this in future, as discussed in the task list document -- but it's quite a hard subject to resolve satisfactorily without a lot of work. Happy to discuss later in the week.

Vec<SubintentHash>,
),
>,
// INVARIANT: The `intent_lookup` and `subintent_lookup` are kept exactly in sync with
Copy link
Member

Choose a reason for hiding this comment

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

Is mempool transaction adding single-threaded? The "sync" logic doesn't look thread-safe - there is a race condition where the reverse lookup goes out-of-sync with pending transaction records.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Inside the pending_transaction_result_cache.rs, we have a &mut self so know we have locally exclusive access - the locking and co-ordination is controlled in the mempool_manager.rs parent -- but please do verify it for correctness :)

Copy link
Member

Choose a reason for hiding this comment

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

You're right. The &mut references are obtained from write() on the RW Lock, not some unsafe transmutation, which prevents unsynchronized modification to the cache data structure.

@dhedey dhedey merged commit afed42a into develop Nov 11, 2024
22 checks passed
@dhedey dhedey deleted the feature/immediately-handle-subintent-nullification branch November 11, 2024 15:29
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.

3 participants