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

Arc definition in TransactionPool #7042

Merged

Conversation

dharjeezy
Copy link
Contributor

closes #5978

/// Get hash of transaction.
fn hash_of(&self, transaction: &B::Extrinsic) -> H;
fn hash_of(&self, transaction: &Arc<B::Extrinsic>) -> H;
Copy link
Contributor

Choose a reason for hiding this comment

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

I think Arc is not needed here.

Copy link
Contributor

Choose a reason for hiding this comment

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

I mean we are already passing reference to the extrinsics data.

Copy link
Member

Choose a reason for hiding this comment

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

Yeah 👍

/// Import a transaction into the pool.
///
/// This will return future.
fn import(&self, transaction: B::Extrinsic) -> TransactionImportFuture;
fn import(&self, transaction: Arc<B::Extrinsic>) -> TransactionImportFuture;
Copy link
Contributor

@michalkucharczyk michalkucharczyk Jan 6, 2025

Choose a reason for hiding this comment

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

This currently does not make sense. We would need to change submit_one/ submit_and_watch API to accept Arc.
Otherwise we create Arc, then dereference it and create new one within transcaction pool implementation.

@michalkucharczyk
Copy link
Contributor

michalkucharczyk commented Jan 6, 2025

For the sake of the simplicity I would only rework transactions function in this PR - it makes sense not to copy/clone extrinsics data to propagate transactions over network.

hash_of IMO does not need Arc - it already takes ref.

When it comes to import - if we really want to change it, we could it in dedicated PR. But I think it is not really needed because submit_one/ submit_and_watch already take an owenership of the extrinsic's data so Arc is not helping here with anything.

@michalkucharczyk
Copy link
Contributor

@dharjeezy are you planning to continue working on this?

@dharjeezy
Copy link
Contributor Author

@dharjeezy are you planning to continue working on this?

yes. i will get it done through the week/weekend.

@@ -471,7 +471,8 @@ where

debug!(target: LOG_TARGET, "Propagating transaction [{:?}]", hash);
if let Some(transaction) = self.transaction_pool.transaction(hash) {
let propagated_to = self.do_propagate_transactions(&[(hash.clone(), transaction)]);
let propagated_to =
self.do_propagate_transactions(&[(hash.clone(), Arc::new(transaction))]);
Copy link
Contributor

@michalkucharczyk michalkucharczyk Jan 25, 2025

Choose a reason for hiding this comment

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

Could we avoid Arc::new here?

I think that this transaction method could also provide an Arc reference, here:

fn transaction(&self, hash: &H) -> Option<B::Extrinsic> {
self.pool.ready_transaction(hash).and_then(
// Only propagable transactions should be resolved for network service.
|tx| if tx.is_propagable() { Some((**tx.data()).clone()) } else { None },
)
}

This is just method of the same trait (sc-network-transactions::config::TransactionPool), so should be easily doable:

fn transaction(&self, hash: &H) -> Option<B::Extrinsic>;

Would you change it too?

title: `networking::TransactionPool` should accept `Arc`
doc:
- audience: Node Dev
description: The TransactionPool trait now accepts an `Arc` for transactions.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
description: The TransactionPool trait now accepts an `Arc` for transactions.
description: The `sc_network_transactions::config::TransactionPool` trait now accepts an `Arc` for transactions.

self.pool.ready_transaction(hash).and_then(
// Only propagable transactions should be resolved for network service.
|tx| if tx.is_propagable() { Some((**tx.data()).clone()) } else { None },
|tx| if tx.is_propagable() { Some(Arc::new((**tx.data()).clone())) } else { None },
Copy link
Contributor

@michalkucharczyk michalkucharczyk Jan 27, 2025

Choose a reason for hiding this comment

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

We don't need new Arc, something like this should work:

Suggested change
|tx| if tx.is_propagable() { Some(Arc::new((**tx.data()).clone())) } else { None },
|tx| tx.is_propagable().then(|| { tx.data().clone() }),

@@ -0,0 +1,9 @@
title: `networking::TransactionPool` should accept `Arc`
Copy link
Contributor

Choose a reason for hiding this comment

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

Name of the file is incorrect. Please rename it to: pr_7042.prdoc

@michalkucharczyk michalkucharczyk added R0-silent Changes should not be mentioned in any release notes T0-node This PR/Issue is related to the topic “node”. labels Jan 27, 2025
title: `networking::TransactionPool` should accept `Arc`
doc:
- audience: Node Dev
description: The `sc_network_transactions::config::TransactionPool` trait now accepts an `Arc` for transactions.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
description: The `sc_network_transactions::config::TransactionPool` trait now accepts an `Arc` for transactions.
description: The `sc_network_transactions::config::TransactionPool` trait now returns an `Arc` for transactions.

@michalkucharczyk
Copy link
Contributor

Looks good, thank you!

@michalkucharczyk
Copy link
Contributor

bot fmt

@command-bot
Copy link

command-bot bot commented Jan 27, 2025

@michalkucharczyk https://gitlab.parity.io/parity/mirrors/polkadot-sdk/-/jobs/8096196 was started for your command "$PIPELINE_SCRIPTS_DIR/commands/fmt/fmt.sh". Check out https://gitlab.parity.io/parity/mirrors/polkadot-sdk/-/pipelines?page=1&scope=all&username=group_605_bot to know what else is being executed currently.

Comment bot cancel 3-652d0981-885a-4723-be4b-575df729f3ea to cancel this command or bot cancel to cancel all commands in this pull request.

Copy link
Contributor

We have migrated the command bot to GHA

Please, see the new usage instructions here or here. Soon the old commands will be disabled.

@command-bot
Copy link

command-bot bot commented Jan 27, 2025

@michalkucharczyk Command "$PIPELINE_SCRIPTS_DIR/commands/fmt/fmt.sh" has finished. Result: https://gitlab.parity.io/parity/mirrors/polkadot-sdk/-/jobs/8096196 has finished. If any artifacts were generated, you can download them from https://gitlab.parity.io/parity/mirrors/polkadot-sdk/-/jobs/8096196/artifacts/download.

@michalkucharczyk michalkucharczyk added this pull request to the merge queue Jan 27, 2025
Merged via the queue into paritytech:master with commit b2004ed Jan 27, 2025
201 of 205 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
R0-silent Changes should not be mentioned in any release notes T0-node This PR/Issue is related to the topic “node”.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

networking::TransactionPool should accept Arc.
5 participants