Skip to content

Commit

Permalink
fix(sidecar): double allocation when doing sanity check for receipts
Browse files Browse the repository at this point in the history
  • Loading branch information
thedevbirb committed Nov 5, 2024
1 parent db13a6b commit 90891bf
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions bolt-sidecar/src/state/execution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -467,29 +467,30 @@ impl<C: StateFetcher> ExecutionState<C> {
if let Some(template) = self.remove_block_template(slot) {
debug!(%slot, "Removed block template for slot");
let hashes = template.transaction_hashes();
let receipts =
self.client.get_receipts(&hashes).await?.into_iter().flatten().collect::<Vec<_>>();
let receipts = self.client.get_receipts(&hashes).await?;

for receipt in receipts.iter() {
let mut receipts_len = 0;
for receipt in receipts.iter().flatten() {
// Calculate the total tip revenue for this transaction: (effective_gas_price - basefee) * gas_used
let tip_per_gas = receipt.effective_gas_price - self.basefee;
let total_tip = tip_per_gas * receipt.gas_used;

trace!(hash = %receipt.transaction_hash, total_tip, "Receipt found");

ApiMetrics::increment_gross_tip_revenue(total_tip);
receipts_len += 1;
}

// Sanity check with additional logs if there are any discrepancies
if hashes.len() != receipts.len() {
if hashes.len() != receipts_len {
warn!(
%slot,
template_hashes = hashes.len(),
receipts_found = receipts.len(),
receipts_found = receipts_len,
"mismatch between template transaction hashes and receipts found from client"
);
hashes.iter().for_each(|hash| {
if !receipts.iter().any(|receipt| receipt.transaction_hash == *hash) {
if !receipts.iter().flatten().any(|receipt| receipt.transaction_hash == *hash) {
warn!(%hash, "missing receipt for transaction");
}
});
Expand Down

0 comments on commit 90891bf

Please sign in to comment.