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

[consensus handler] reorder txns by gas price #12266

Merged
merged 2 commits into from
Jun 12, 2023
Merged

[consensus handler] reorder txns by gas price #12266

merged 2 commits into from
Jun 12, 2023

Conversation

emmazzz
Copy link
Contributor

@emmazzz emmazzz commented May 31, 2023

Description

This PR adds a step in consensus handler to reorder transactions in a Narwhal commit by their gas prices. Right now the reordering is purely based on gas price, which will be later changed to be based on object hotness, etc, as well.

Test Plan

Added a test.


If your changes are not user-facing and not a breaking change, you can skip the following section. Otherwise, please indicate what changed, and then add to the Release Notes section as highlighted during the release process.

Type of Change (Check all that apply)

  • protocol change
  • user-visible impact
  • breaking change for a client SDKs
  • breaking change for FNs (FN binary must upgrade)
  • breaking change for validators or node operators (must upgrade binaries)
  • breaking change for on-chain data layout
  • necessitate either a data wipe or data migration

Release notes

Previously transactions in a Narwhal commit were ordered as the sub-dag is flattened in a depth-first traversal. Now we have added a round of ordering that orders the user transactions in the same commit by gas price, where a transaction with higher gas price will be added for execution in the transaction manager first.

@vercel
Copy link

vercel bot commented May 31, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
offline-signer-helper ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jun 12, 2023 5:03am
sui-kiosk ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jun 12, 2023 5:03am
4 Ignored Deployments
Name Status Preview Comments Updated (UTC)
explorer ⬜️ Ignored (Inspect) Jun 12, 2023 5:03am
explorer-storybook ⬜️ Ignored (Inspect) Jun 12, 2023 5:03am
sui-wallet-kit ⬜️ Ignored (Inspect) Jun 12, 2023 5:03am
wallet-adapter ⬜️ Ignored (Inspect) Jun 12, 2023 5:03am

@emmazzz emmazzz requested review from andll, mwtian and mystenmark May 31, 2023 00:02
@@ -465,6 +466,10 @@ pub struct ProtocolConfig {
/// 3f+1 must vote), while 0bps would indicate that 2f+1 is sufficient.
buffer_stake_for_protocol_upgrade_bps: Option<u64>,

/// What version of reordering algorithm we are using for user transactions included in a Narwhal
/// commit in consensus handler.
consensus_user_transaction_reordering_version: Option<u64>,
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 thought this is similar to gas model in the sense that we will probably iterate a few times so I added it as a version number instead of feature flag.

Copy link
Contributor

Choose a reason for hiding this comment

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

we could still use a feature flag, but make it an enum instead of a bool - i think that will help readability, since the enum variants can be descriptive.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good idea.

Copy link
Contributor

@mwtian mwtian left a comment

Choose a reason for hiding this comment

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

PR looks good. Is there a discussion thread on ordering transactions by gas price?

@@ -357,6 +370,22 @@ impl<T: ParentSync + Send + Sync> ExecutionState for ConsensusHandler<T> {
}
}

fn reorder_by_gas_price(sequenced_transactions: &mut [VerifiedSequencedConsensusTransaction]) {
Copy link
Contributor

Choose a reason for hiding this comment

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

optional: maybe just order_by_gas_price?

@emmazzz
Copy link
Contributor Author

emmazzz commented May 31, 2023

Is there a discussion thread on ordering transactions by gas price?

@mwtian There's a long thread here. This PR is meant to be a starting point for us to experiment with and come up with later steps.

.protocol_config()
.consensus_user_transaction_reordering_version_as_option()
{
reorder_by_gas_price(&mut sequenced_transactions[1..]);
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: Can we add a monitored_scope here?

@@ -465,6 +466,10 @@ pub struct ProtocolConfig {
/// 3f+1 must vote), while 0bps would indicate that 2f+1 is sufficient.
buffer_stake_for_protocol_upgrade_bps: Option<u64>,

/// What version of reordering algorithm we are using for user transactions included in a Narwhal
/// commit in consensus handler.
consensus_user_transaction_reordering_version: Option<u64>,
Copy link
Contributor

Choose a reason for hiding this comment

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

we could still use a feature flag, but make it an enum instead of a bool - i think that will help readability, since the enum variants can be descriptive.

tracking_id: _,
kind: ConsensusTransactionKind::UserTransaction(cert),
}) => cert.gas_price(),
// Non-user transactions are considered to have gas price of zero and are put to the end.
Copy link
Contributor

Choose a reason for hiding this comment

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

i believe this sorts ConsensusCommitPrologue txns to the end, which is definitely not what we want.

Copy link
Contributor Author

@emmazzz emmazzz May 31, 2023

Choose a reason for hiding this comment

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

On line 306, where this function is called, we are sorting only the second transactions onwards so the first txn in the vector which is consensus commit prologue txn should not be affected.

@mwtian
Copy link
Contributor

mwtian commented May 31, 2023

Is there a discussion thread on ordering transactions by gas price?

@mwtian There's a long thread here. This PR is meant to be a starting point for us to experiment with and come up with later steps.

Great, thanks for the pointer. Looking forward to integrating load shedding logic later.

ConsensusTransactionOrdering::ByGasPrice
) {
let _scope = monitored_scope("HandleConsensusOutput::order_by_gas_price");
order_by_gas_price(&mut sequenced_transactions);
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 typical and max size of sequenced_transactions?

Copy link
Contributor

Choose a reason for hiding this comment

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

The size of sequenced_transactions is the number of Sui transactions in a Narwhal commit + 1 (prologue). In 100 node deployments, Narwhal commits happen every 1~2s. Actual size of sequenced_transactions is correlated with TPS. The size limit is much larger based on Narwhal limits.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If we are concerned about added latency due to this additional step, I can run an experiment in private testnet with high TPS and observe what the monitored scope metrics show us.

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think we're going to have any problems caused by sorting - consensus handler is dominated by db reads and writes. Anything that is purely in memory like this should not cause problems

@emmazzz emmazzz force-pushed the emma/order-by-gp branch 3 times, most recently from b9a0201 to 39c5526 Compare June 7, 2023 18:11
@vercel vercel bot temporarily deployed to Preview – offline-signer-helper June 7, 2023 18:21 Inactive
@emmazzz emmazzz force-pushed the emma/order-by-gp branch from d408bb6 to aaee5b9 Compare June 12, 2023 05:02
@emmazzz emmazzz merged commit 1009fed into main Jun 12, 2023
@emmazzz emmazzz deleted the emma/order-by-gp branch June 12, 2023 05:50
ebmifa pushed a commit that referenced this pull request Jun 14, 2023
## Description 

This PR adds a step in consensus handler to reorder transactions in a
Narwhal commit by their gas prices. Right now the reordering is purely
based on gas price, which will be later changed to be based on object
hotness, etc, as well.

## Test Plan 

Added a test.

---
If your changes are not user-facing and not a breaking change, you can
skip the following section. Otherwise, please indicate what changed, and
then add to the Release Notes section as highlighted during the release
process.

### Type of Change (Check all that apply)

- [ ] protocol change
- [x] user-visible impact
- [ ] breaking change for a client SDKs
- [ ] breaking change for FNs (FN binary must upgrade)
- [x] breaking change for validators or node operators (must upgrade
binaries)
- [ ] breaking change for on-chain data layout
- [ ] necessitate either a data wipe or data migration

### Release notes

Previously transactions in a Narwhal commit were ordered as the sub-dag
is flattened in a depth-first traversal. Now we have added a round of
ordering that orders the user transactions in the same commit by gas
price, where a transaction with higher gas price will be added for
execution in the transaction manager first.
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