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

[SIP-45] Metrics and protocol config changes #20738

Merged
merged 7 commits into from
Dec 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 29 additions & 7 deletions crates/sui-core/src/consensus_adapter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ pub struct ConsensusAdapterMetrics {
pub sequencing_certificate_positions_moved: Histogram,
pub sequencing_certificate_preceding_disconnected: Histogram,
pub sequencing_certificate_processed: IntCounterVec,
pub sequencing_certificate_amplification_factor: Histogram,
pub sequencing_in_flight_semaphore_wait: IntGauge,
pub sequencing_in_flight_submissions: IntGauge,
pub sequencing_estimated_latency: IntGauge,
Expand Down Expand Up @@ -185,6 +186,12 @@ impl ConsensusAdapterMetrics {
registry,
)
.unwrap(),
sequencing_certificate_amplification_factor: register_histogram_with_registry!(
"sequencing_certificate_amplification_factor",
"The amplification factor used by consensus adapter to submit to consensus.",
SEQUENCING_CERTIFICATE_POSITION_BUCKETS.to_vec(),
registry,
).unwrap(),
}
}

Expand Down Expand Up @@ -354,11 +361,11 @@ impl ConsensusAdapter {
&self,
epoch_store: &Arc<AuthorityPerEpochStore>,
transactions: &[ConsensusTransaction],
) -> (impl Future<Output = ()>, usize, usize, usize) {
) -> (impl Future<Output = ()>, usize, usize, usize, usize) {
if transactions.iter().any(|tx| tx.is_user_transaction()) {
// UserTransactions are generally sent to just one validator and should
// be submitted to consensus without delay.
return (tokio::time::sleep(Duration::ZERO), 0, 0, 0);
return (tokio::time::sleep(Duration::ZERO), 0, 0, 0, 0);
}

// Use the minimum digest to compute submit delay.
Expand All @@ -375,14 +382,18 @@ impl ConsensusAdapter {
_ => None,
})
.min();
let mut amplification_factor = 0;

let (duration, position, positions_moved, preceding_disconnected) =
match min_digest_and_gas_price {
Some((digest, gas_price)) => {
// TODO: Make this configurable.
let k = 5;
let multipler = gas_price / epoch_store.reference_gas_price();
let amplification_factor = if multipler >= k { multipler } else { 0 };
let k = epoch_store
.protocol_config()
.sip_45_consensus_amplification_threshold_as_option()
.unwrap_or(u64::MAX);
let multiplier =
gas_price / std::cmp::max(epoch_store.reference_gas_price(), 1);
amplification_factor = if multiplier >= k { multiplier } else { 0 };
self.await_submit_delay_user_transaction(
epoch_store.committee(),
digest,
Expand All @@ -396,6 +407,7 @@ impl ConsensusAdapter {
position,
positions_moved,
preceding_disconnected,
amplification_factor as usize,
)
}

Expand Down Expand Up @@ -703,7 +715,7 @@ impl ConsensusAdapter {
let mut guard = InflightDropGuard::acquire(&self, tx_type);

// Create the waiter until the node's turn comes to submit to consensus
let (await_submit, position, positions_moved, preceding_disconnected) =
let (await_submit, position, positions_moved, preceding_disconnected, amplification_factor) =
self.await_submit_delay(epoch_store, &transactions[..]);

// Create the waiter until the transaction is processed by consensus or via checkpoint
Expand Down Expand Up @@ -763,6 +775,7 @@ impl ConsensusAdapter {
guard.position = Some(position);
guard.positions_moved = Some(positions_moved);
guard.preceding_disconnected = Some(preceding_disconnected);
guard.amplification_factor = Some(amplification_factor);

let _permit: SemaphorePermit = self
.submit_semaphore
Expand Down Expand Up @@ -1154,6 +1167,7 @@ struct InflightDropGuard<'a> {
position: Option<usize>,
positions_moved: Option<usize>,
preceding_disconnected: Option<usize>,
amplification_factor: Option<usize>,
tx_type: &'static str,
processed_method: ProcessedMethod,
}
Expand Down Expand Up @@ -1185,6 +1199,7 @@ impl<'a> InflightDropGuard<'a> {
position: None,
positions_moved: None,
preceding_disconnected: None,
amplification_factor: None,
tx_type,
processed_method: ProcessedMethod::Consensus,
}
Expand Down Expand Up @@ -1226,6 +1241,13 @@ impl<'a> Drop for InflightDropGuard<'a> {
.observe(preceding_disconnected as f64);
};

if let Some(amplification_factor) = self.amplification_factor {
self.adapter
.metrics
.sequencing_certificate_amplification_factor
.observe(amplification_factor as f64);
};

let latency = self.start.elapsed();
let processed_method = match self.processed_method {
ProcessedMethod::Consensus => "processed_via_consensus",
Expand Down
3 changes: 2 additions & 1 deletion crates/sui-open-rpc/spec/openrpc.json
Original file line number Diff line number Diff line change
Expand Up @@ -1294,7 +1294,7 @@
"name": "Result",
"value": {
"minSupportedProtocolVersion": "1",
"maxSupportedProtocolVersion": "70",
"maxSupportedProtocolVersion": "71",
"protocolVersion": "6",
"featureFlags": {
"accept_zklogin_in_multisig": false,
Expand Down Expand Up @@ -1903,6 +1903,7 @@
"reward_slashing_rate": {
"u64": "10000"
},
"sip_45_consensus_amplification_threshold": null,
"storage_fund_reinvest_rate": {
"u64": "500"
},
Expand Down
12 changes: 11 additions & 1 deletion crates/sui-protocol-config/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use tracing::{info, warn};

/// The minimum and maximum protocol versions supported by this build.
const MIN_PROTOCOL_VERSION: u64 = 1;
const MAX_PROTOCOL_VERSION: u64 = 70;
const MAX_PROTOCOL_VERSION: u64 = 71;

// Record history of protocol version allocations here:
//
Expand Down Expand Up @@ -203,6 +203,7 @@ const MAX_PROTOCOL_VERSION: u64 = 70;
// Add new gas model version to update charging of native functions.
// Add std::uq64_64 module to Move stdlib.
// Improve gas/wall time efficiency of some Move stdlib vector functions
// Version 71: [SIP-45] Enable consensus amplification.

#[derive(Copy, Clone, Debug, Hash, Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord)]
pub struct ProtocolVersion(u64);
Expand Down Expand Up @@ -1333,6 +1334,10 @@ pub struct ProtocolConfig {
/// Adds an absolute cap on the maximum transaction cost when using TotalGasBudgetWithCap at
/// the given multiple of the per-commit budget.
gas_budget_based_txn_cost_absolute_cap_commit_count: Option<u64>,

/// SIP-45: K in the formula `amplification_factor = max(0, gas_price / reference_gas_price - K)`.
/// This is the threshold for activating consensus amplification.
sip_45_consensus_amplification_threshold: Option<u64>,
}

// feature flags
Expand Down Expand Up @@ -2251,6 +2256,8 @@ impl ProtocolConfig {
gas_budget_based_txn_cost_cap_factor: None,

gas_budget_based_txn_cost_absolute_cap_commit_count: None,

sip_45_consensus_amplification_threshold: None,
// When adding a new constant, set it to None in the earliest version, like this:
// new_constant: None,
};
Expand Down Expand Up @@ -3084,6 +3091,9 @@ impl ProtocolConfig {

cfg.validator_validate_metadata_cost_base = Some(20000);
}
71 => {
cfg.sip_45_consensus_amplification_threshold = Some(5);
}
// Use this template when making changes:
//
// // modify an existing constant.
Expand Down
Loading
Loading