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

add(metrics): Track mempool actions and size bucketed by weight (copy of #6972, credit @str4d) #7019

Merged
merged 8 commits into from
Jul 18, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
metrics: Track mempool actions and size bucketed by weight
  • Loading branch information
str4d committed Jun 15, 2023
commit 4c6bfbfb98b686786333c7b2e26a5903799c3390
9 changes: 9 additions & 0 deletions zebra-chain/src/transaction/unmined.rs
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,13 @@ pub struct VerifiedUnminedTx {
/// transparent inputs and outputs.
pub legacy_sigop_count: u64,

/// The number of conventional actions for `transaction`, as defined by [ZIP-317].
///
/// The number of actions is limited by [`MAX_BLOCK_BYTES`], so it fits in a u32.
///
/// [ZIP-317]: https://zips.z.cash/zip-0317#block-production
pub conventional_actions: u32,

/// The number of unpaid actions for `transaction`,
/// as defined by [ZIP-317] for block production.
///
Expand Down Expand Up @@ -381,6 +388,7 @@ impl VerifiedUnminedTx {
legacy_sigop_count: u64,
) -> Result<Self, zip317::Error> {
let fee_weight_ratio = zip317::conventional_fee_weight_ratio(&transaction, miner_fee);
let conventional_actions = zip317::conventional_actions(&transaction.transaction);
let unpaid_actions = zip317::unpaid_actions(&transaction, miner_fee);

zip317::mempool_checks(unpaid_actions, miner_fee, transaction.size)?;
Expand All @@ -390,6 +398,7 @@ impl VerifiedUnminedTx {
miner_fee,
legacy_sigop_count,
fee_weight_ratio,
conventional_actions,
unpaid_actions,
})
}
Expand Down
2 changes: 1 addition & 1 deletion zebra-chain/src/transaction/unmined/zip317.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ pub fn conventional_fee_weight_ratio(
/// as defined by [ZIP-317].
///
/// [ZIP-317]: https://zips.z.cash/zip-0317#fee-calculation
fn conventional_actions(transaction: &Transaction) -> u32 {
pub fn conventional_actions(transaction: &Transaction) -> u32 {
let tx_in_total_size: usize = transaction
.inputs()
.iter()
Expand Down
100 changes: 100 additions & 0 deletions zebrad/src/components/mempool/storage/verified_set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -286,10 +286,110 @@ impl VerifiedSet {
}

fn update_metrics(&mut self) {
// Track the sum of unpaid actions within each transaction (as they are subject to the
// unpaid action limit). Transactions that have weight >= 1 have no unpaid actions by
// definition.
let mut unpaid_actions_with_weight_lt20pct = 0;
let mut unpaid_actions_with_weight_lt40pct = 0;
let mut unpaid_actions_with_weight_lt60pct = 0;
let mut unpaid_actions_with_weight_lt80pct = 0;
let mut unpaid_actions_with_weight_lt1 = 0;

// Track the total number of paid actions across all transactions in the mempool. This
// added to the bucketed unpaid actions above is equal to the total number of conventional
// actions in the mempool.
let mut paid_actions = 0;
teor2345 marked this conversation as resolved.
Show resolved Hide resolved

// Track the sum of transaction sizes (the metric by which they are mainly limited) across
// several buckets.
let mut size_with_weight_lt1 = 0;
let mut size_with_weight_eq1 = 0;
let mut size_with_weight_gt1 = 0;
let mut size_with_weight_gt2 = 0;
let mut size_with_weight_gt3 = 0;

for entry in self.full_transactions() {
paid_actions += entry.conventional_actions - entry.unpaid_actions;
teor2345 marked this conversation as resolved.
Show resolved Hide resolved

if entry.fee_weight_ratio > 3.0 {
size_with_weight_gt3 += entry.transaction.size;
} else if entry.fee_weight_ratio > 2.0 {
size_with_weight_gt2 += entry.transaction.size;
} else if entry.fee_weight_ratio > 1.0 {
size_with_weight_gt1 += entry.transaction.size;
} else if entry.fee_weight_ratio == 1.0 {
size_with_weight_eq1 += entry.transaction.size;
} else {
size_with_weight_lt1 += entry.transaction.size;
if entry.fee_weight_ratio < 0.2 {
unpaid_actions_with_weight_lt20pct += entry.unpaid_actions;
} else if entry.fee_weight_ratio < 0.4 {
unpaid_actions_with_weight_lt40pct += entry.unpaid_actions;
} else if entry.fee_weight_ratio < 0.6 {
unpaid_actions_with_weight_lt60pct += entry.unpaid_actions;
} else if entry.fee_weight_ratio < 0.8 {
unpaid_actions_with_weight_lt80pct += entry.unpaid_actions;
} else {
unpaid_actions_with_weight_lt1 += entry.unpaid_actions;
}
}
}

metrics::gauge!(
"zcash.mempool.actions.unpaid",
unpaid_actions_with_weight_lt20pct as f64,
"bk" => "< 0.2",
);
metrics::gauge!(
"zcash.mempool.actions.unpaid",
unpaid_actions_with_weight_lt40pct as f64,
"bk" => "< 0.4",
);
metrics::gauge!(
"zcash.mempool.actions.unpaid",
unpaid_actions_with_weight_lt60pct as f64,
"bk" => "< 0.6",
);
metrics::gauge!(
"zcash.mempool.actions.unpaid",
unpaid_actions_with_weight_lt80pct as f64,
"bk" => "< 0.8",
);
metrics::gauge!(
"zcash.mempool.actions.unpaid",
unpaid_actions_with_weight_lt1 as f64,
"bk" => "< 1",
);
metrics::gauge!("zcash.mempool.actions.paid", paid_actions as f64);
metrics::gauge!(
"zcash.mempool.size.transactions",
self.transaction_count() as f64,
);
metrics::gauge!(
"zcash.mempool.size.weighted",
size_with_weight_lt1 as f64,
"bk" => "< 1",
);
metrics::gauge!(
"zcash.mempool.size.weighted",
size_with_weight_eq1 as f64,
"bk" => "1",
);
metrics::gauge!(
"zcash.mempool.size.weighted",
size_with_weight_gt1 as f64,
"bk" => "> 1",
);
metrics::gauge!(
"zcash.mempool.size.weighted",
size_with_weight_gt2 as f64,
"bk" => "> 2",
);
metrics::gauge!(
"zcash.mempool.size.weighted",
size_with_weight_gt3 as f64,
"bk" => "> 3",
);
metrics::gauge!(
"zcash.mempool.size.bytes",
self.transactions_serialized_size as f64,
Expand Down