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

chore(sidecar): warn in case of inconsistent gross revenue calculations #353

Merged
merged 1 commit into from
Nov 5, 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
2 changes: 1 addition & 1 deletion bolt-sidecar/src/builder/template.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! Package `template` contains the functionality for building local block templates that can
//! be used as a fallback. It's also used to keep any intermediary state that is needed to simulate
//! new commitment requests.
use std::collections::HashMap;
use std::collections::{HashMap, HashSet};

use alloy::primitives::{Address, U256};
use ethereum_consensus::{
Expand Down
29 changes: 24 additions & 5 deletions bolt-sidecar/src/state/execution.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
use alloy::{
eips::eip4844::MAX_BLOBS_PER_BLOCK,
primitives::{Address, U256},
primitives::{Address, B256, U256},
transports::TransportError,
};
use reth_primitives::{
revm_primitives::EnvKzgSettings, BlobTransactionValidationError, PooledTransactionsElement,
};
use std::{collections::HashMap, ops::Deref};
use std::{
collections::{HashMap, HashSet},
ops::Deref,
};
use thiserror::Error;
use tracing::{debug, trace};
use tracing::{debug, trace, warn};

use crate::{
builder::BlockTemplate,
Expand Down Expand Up @@ -464,9 +467,10 @@ 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?;
let receipts =
self.client.get_receipts(&hashes).await?.into_iter().flatten().collect::<Vec<_>>();
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this will allocate twice instead of once like previouy

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 catch, fixed with 90891bf


for receipt in receipts.into_iter().flatten() {
for receipt in receipts.iter() {
// 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;
Expand All @@ -475,6 +479,21 @@ impl<C: StateFetcher> ExecutionState<C> {

ApiMetrics::increment_gross_tip_revenue(total_tip);
}

// Sanity check with additional logs if there are any discrepancies
if hashes.len() != receipts.len() {
warn!(
%slot,
template_hashes = hashes.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) {
warn!(%hash, "missing receipt for transaction");
}
});
}
}

Ok(())
Expand Down
Loading