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

Txpool v2 features for futures connections with other modules #2216

Merged
merged 183 commits into from
Oct 7, 2024

Conversation

AurelienFT
Copy link
Contributor

@AurelienFT AurelienFT commented Sep 18, 2024

REVIEWER NOTE: Review #2193 first for context

Linked Issues/PRs

Closes #2187

Description

(2k of additions is the tests from TxPool v1 which has been instantiated again)

This PR adds all the logic for the service and shared state of the TxPool to be able to be used by all the others modules and to make all the auxiliary mechanisms working.

The PR changes the way the SharedState interact with the pool and the service. Now the SharedState only sends commands to the service that will answer him whenever he is time to do depending on the priority of the request (managed through a tokio select biaised). This makes all methods to return async even find which I'm not a big fan of but didn't found any better solution.
EDIT: I have made some tests especially tries to run execute_suite tests and it seems that blocking can cause "double blocking forever" and so I'm up for an alternative

Here is a list of all interactions made by the different modules and their new name/behavior/reason :

Block producer

Existing New
select_transactions(max_gas) select_transactions(max_gas)

PoA

Existing New
total_consumable_gas() Nothing (unused)
transaction_status_events() Replaced by new_txs_notifier reason
pending_number() Not used anymore after transaction_status_events() change
remove_txs() broadcast_txs_skipped_reason()

Block Importer

Existing New
Stream with blockEvents Stream with block events

P2P

Existing New
gossiped_tx_stream tx_from_p2p_stream
new_tx_gossip_subscription new_peers_subscribed_stream
broadcast_transaction broadcast_transaction
get_tx_ids get_tx_ids
get_txs get_txs
notify_gossip_transaction_validity notify_gossip_transaction_validity

GraphQL API

Existing New
transaction transaction
tx_update_subscribe tx_update_subscribe

Others changes

  • The PR also changes the error type to help separate subdomains of errors and try to be more clear about the moment errors can happens.
  • The TTL management of the transactions is also in place as the less priority task for the service.
  • A new thread pool has been added to manage P2P sync that could take a long time (same behavior as txpool v1)
  • The transactions are now stored as Arc because they need to be shareable with others modules (API, P2P)
  • All the tests from the previous pool has been instantiated and pass.
  • The TxPool don't have anymore unused authorization and match the correct linting requirements.

Checklist

  • Breaking changes are clearly marked as such in the PR description and changelog
  • New behavior is reflected in tests
  • The specification matches the implemented behavior (link update PR if changes are needed)

Before requesting review

  • I have reviewed the code myself
  • I have created follow-up issues caused by this PR and linked them here

AurelienFT and others added 30 commits September 5, 2024 00:20
@@ -0,0 +1,272 @@
//! Test module for update_sender
Copy link
Collaborator

Choose a reason for hiding this comment

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

File identical to the old one that we had=) skipping

@@ -0,0 +1,129 @@
use std::{
Copy link
Collaborator

Choose a reason for hiding this comment

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

The file is identical to V1, skipping=)

@@ -0,0 +1,135 @@
use fuel_core_types::{
Copy link
Collaborator

Choose a reason for hiding this comment

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

The file is identical to V1, skipping=)

@@ -0,0 +1,392 @@
use std::{
Copy link
Collaborator

Choose a reason for hiding this comment

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

Content is identical to V1, the difference that 2 types were merged int one file.

@@ -0,0 +1,260 @@
use std::{
Copy link
Collaborator

Choose a reason for hiding this comment

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

Identical to the V1, skipping.

@@ -0,0 +1,87 @@
//! Test module for validating TxUpdateStream state transitions.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Identical to V1, skipping.

xgreenx
xgreenx previously approved these changes Oct 7, 2024
Comment on lines +140 to +141
pool: Shared<TxPool>,
current_height: Arc<RwLock<BlockHeight>>,
Copy link
Contributor

Choose a reason for hiding this comment

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

is there any reason why you use the Shared type alias for pool and not for current_height?
Overall I think Arc<RwLock<_>> is more clear

Copy link
Contributor

@netrome netrome left a comment

Choose a reason for hiding this comment

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

Some opinions on the Shared type, continuing my review...

Comment on lines +84 to +87
// For tests
use crate as fuel_core_services;
#[allow(unused_imports)]
use fuel_core_services as _;
Copy link
Contributor

Choose a reason for hiding this comment

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

What is the purpose of this aliasing dance? We import the crate under a type alias and then alias it to _. This feels weird, but I guess we must achieve something by doing this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Collaborator

Choose a reason for hiding this comment

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

image

It was done to enable feature by default during testing

heavy_async_processor: Arc<HeavyAsyncProcessor>,
utxo_validation: bool,
}
pub type Shared<T> = Arc<RwLock<T>>;
Copy link
Contributor

Choose a reason for hiding this comment

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

While this is a pretty nice type-alias, I don't see any point in making it public. Any other modules that would benefit from the type alias can redefine it, which would be more straight-forward to read and just as concise as importing it without the extra indirection.

Suggested change
pub type Shared<T> = Arc<RwLock<T>>;
type Shared<T> = Arc<RwLock<T>>;

Copy link
Contributor

Choose a reason for hiding this comment

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

Optionally if this is used in a lot of places we should move it out to another module, since the alias has nothing to do with this particular service.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I changed it to pub(crate) because it's used in the tests

},
service::{
memory::MemoryPool,
Shared,
Copy link
Contributor

Choose a reason for hiding this comment

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

For example here I would find it more readable if we instead of importing Shared redefine the alias in this module.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

will let @xgreenx give his advice on this as it's a type he added

Copy link
Collaborator

Choose a reason for hiding this comment

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

Up to @AurelienFT )

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Noted on my note will think about it in the next days to not block the merge.

@AurelienFT AurelienFT enabled auto-merge (squash) October 7, 2024 20:41
@AurelienFT AurelienFT merged commit fdcec1c into master Oct 7, 2024
32 checks passed
@AurelienFT AurelienFT deleted the txpool-v2-block-producer-importer branch October 7, 2024 20:45
Copy link
Contributor

@netrome netrome left a comment

Choose a reason for hiding this comment

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

Another suggestion (not blocking merge)

Comment on lines +188 to +190
should_continue = true;
} else {
should_continue = false;
Copy link
Contributor

Choose a reason for hiding this comment

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

I know the pattern was established before this PR, but it would make more sense to me to just return here instead of declaring and assigning the variable to later return it.

Suggested change
should_continue = true;
} else {
should_continue = false;
return Ok(true);
} else {
return Ok(false);

(and the same for all other branches)

Copy link
Contributor

Choose a reason for hiding this comment

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

Nevermind, I see you already merged! 🎉

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's Ok you can leave comment and I will address in patch in the future. I note this and let this open in the meantime

@xgreenx xgreenx mentioned this pull request Oct 8, 2024
xgreenx added a commit that referenced this pull request Oct 8, 2024
## Version v0.38.0

### Added
- [2309](#2309): Limit number
of concurrent queries to the graphql service.
- [2216](#2216): Add more
function to the state and task of TxPoolV2 to handle the future
interactions with others modules (PoA, BlockProducer, BlockImporter and
P2P).
- [2263](#2263): Use the
Txpool v2 in the whole codebase.

### Removed
- [2306](#2306): Removed hack
for genesis asset contract from the code.

## What's Changed
* Updates to price algorithm by @rafal-ch in
#2292
* Removed hack from the code by @xgreenx in
#2306
* fix(p2p): useless dials to reserved nodes which dont have a location
multiaddress by @rymnc in
#2308
* Txpool v2 features for futures connections with other modules by
@AurelienFT in #2216
* Limit number of concurrent queries to the graphql service by @netrome
in #2309
* Linking TxPoolV2 in place of V1 by @AurelienFT in
#2263


**Full Changelog**:
v0.37.1...v0.38.0

---------

Co-authored-by: AurelienFT <[email protected]>
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.

5 participants