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

Try to include more tx in the bundle and skip including tx that already included in previous bundle #2454

Merged
merged 5 commits into from
Feb 1, 2024

Conversation

NingLin-P
Copy link
Member

This PR contains 2 improvements on bundle construction:

  • Try to include more tx in the bundle to increase bundle utilization
  • Skip including tx that was already included in the previous bundle to reduce duplicated tx, this can reduce duplicated tx significantly in some scenarios, it is originally from a discussion with @nazar-pc.

More detail on the second one:

Suppose in a domain there is an operator with a large share of stake and is expected to produce multiple bundles for a domain block, when the operator constructs a bundle it iterates over its tx pool, and tx is returned according to its tip and the time it arrived, if the operator gonna produce 5 bundles, most likely all the tx inside these bundle will be the same, thus a lot of duplicate tx.

With this PR, when the operator produces the second bundle it will skip tx already included in the first bundle, if there is no more tx, it simply stops producing an empty bundle, and once the consensus chain tip changed (no matter if there is new domain block or not) the operator will not skip and retry to include these tx in the next bundle.

One scenario that is different from the main is when a user sends 2 tx with nonce N and N+1, if tx N is included in a bundle while tx N+1 is not, tx N+1 has to wait until the next consensus chain block before included in the bundle again, I have spent quite some time to support this scenario to make it just like main, but it is much much more complicate and I believe this edge case doesn't worth it.

Code contributor checklist:

@@ -1,32 +1,222 @@
//! Shared domain worker functions.
// Copyright 2020 Parity Technologies (UK) Ltd.
Copy link
Contributor

@ParthDesai ParthDesai Jan 31, 2024

Choose a reason for hiding this comment

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

Is this refactoring necessary for this PR? If not, would it be better into its own PR?

I am talking about this commit: 71935c7

Copy link
Member Author

Choose a reason for hiding this comment

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

Not really necessary for this PR, will do that next time 👍

Copy link
Member

@vedhavyas vedhavyas left a comment

Choose a reason for hiding this comment

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

Makes sense

Left some questions

@@ -204,6 +255,9 @@ where
estimated_bundle_weight = next_estimated_bundle_weight;
bundle_size = next_bundle_size;
extrinsics.push(pending_tx_data.clone());

self.previous_bundled_tx
Copy link
Member

Choose a reason for hiding this comment

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

We seem to just add the bundle after submission but there is always a possiblity that bundle never made it into Consensus node TX pool.
I would suggest checking the Consensus node TX pool if this bundle is included without any failures and then only proceed to index this here

Copy link
Member Author

Choose a reason for hiding this comment

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

but there is always a possiblity that bundle never made it into Consensus node TX pool.

Do you mean the local consensus node's tx pool? bundle should always be able to submit to the local consensus node tx pool, if it is failed then most likely there is a bug.

Copy link
Member Author

Choose a reason for hiding this comment

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

The bundled tx hashes are cleared whenever the consensus chain tip is changed, which is because the bundle may not be included by the next consensus block due to:

  • the bundle is dropped silently during propagation due to network issue
  • the bundle can't fit into the next consensus block or didn't arrive at the block author's tx pool in time, and becomes invalid as the head ER is changed
  • etc

We can't predict these situations locally thus we clear the bundled tx hashes whenever the consensus chain tip is changed to have more retry.

Copy link
Contributor

@ParthDesai ParthDesai Feb 1, 2024

Choose a reason for hiding this comment

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

While it is possible to monitor consensus tx pool and based on that make decision on whether to clear the cache or not. The implementation IIUC would be similar to how substrate transaction pool monitors block import/finalization, which can be very involved and in my opinion, not worth the effort.

@NingLin-P NingLin-P added this pull request to the merge queue Feb 1, 2024
Merged via the queue into main with commit e8ed377 Feb 1, 2024
9 checks passed
@NingLin-P NingLin-P deleted the construct-bundle branch February 1, 2024 12:50
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.

4 participants