-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Prepare for asynchronous transaction validation in tx pool #3650
Conversation
@@ -953,6 +953,14 @@ impl<B: BlockT, S: NetworkSpecialization<B>, H: ExHashT> Protocol<B, S, H> { | |||
who: PeerId, | |||
extrinsics: message::Transactions<B::Extrinsic> | |||
) { | |||
// sending extrinsic to light node is considered a bad behavior | |||
if !self.config.roles.is_full() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ahhh, forgot about this change - could create a separate PR for it, if required. Extrinsics from other nodes are ignored by light tx pool anyway => this change only decreases traffic on light client.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not super happy about how sync and async code operates here. I really think we should avoid locking inside the event pool.
Can we maybe keep the pool synchronous and just decouple validation? Alternatively we could have the (sync) pool running in it's own thread and the asynchronous code would just send messages (like AddTx(raw, TransactionValidity)
via mpsc
channel.
let import_results = validation_results | ||
.into_iter() | ||
.map(|validation_result| { | ||
let imported = self_clone.0.pool.write().import(validation_result?)?; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is locking inside the event loop :/ I think it might have very bad performance consequences.
The separate-thread approach won't work for light-in-browser, I believe :/ By decoupling you mean passing pre-validated transactions to Also - could you please elaborate on "avoid locking inside the event pool" - not sure I got it :/ Did you mean locks like |
Yeah, that's exactly what I mean. I don't think it's healthy to do that.
I still think it might be a bit cleaner to do so. |
OK, thanks :) I still not sure - what's wrong with locking in this PR - there are exactly same locks as before, locking exactly same (tokio) threads (at different moments, though) :) And after fix, they still be there. But decoupling, probably, makes sense. |
Co-Authored-By: Tomasz Drwięga <tomusdrw@users.noreply.github.com>
Co-Authored-By: Tomasz Drwięga <tomusdrw@users.noreply.github.com>
So the I've also found that in my first commit I've missed one |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fair enough. Somehow I though that sync RPC are executed differently than async (in a separate thread pool), but that's obviously not the case.
The decoupling looks good, I think that in the future it may still make sense to dedicate a separate thread for transaction pool alterations / locking and avoid locks in async code completely.
Alternatively we could try to rewrite the pool to avoid locks - that would mean that the ready iterator API would need to be async most likely.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great!
This is required to restore txpool && txpool-related RPCs on light client after #3538 (light-related changes will be added in follow-up PRs). The main change in this PR is that
ChainApi::validate_transaction
now returnsFuture<>
instead ofResult<>
. This affectsPool::{submit_at, submit_one, submit_and_watch, prune, prune_tags}
methods. All other changes are simply fixes to support that change.Planned light-related changes: (1) separate
ChainApi
implementation that will useFetcher
to validate transaction on remote node (that has been removed in #3538) and (2) separatemaintain_transaction_pool()
implementation that will (presumably) fetch proof-of-tx-inclusion from remote node and remove transactions that are included in the block.