Skip to content

Commit

Permalink
Improve logging and metrics for block publication (sigp#5699)
Browse files Browse the repository at this point in the history
* Improve logging and metrics for block publication

* Add better buckets

* Bump SQL connection timeout for tests.
  • Loading branch information
michaelsproul authored May 3, 2024
1 parent ee974db commit d3d429f
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 4 deletions.
8 changes: 7 additions & 1 deletion beacon_node/http_api/src/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,13 @@ lazy_static::lazy_static! {
);
pub static ref HTTP_API_BLOCK_BROADCAST_DELAY_TIMES: Result<HistogramVec> = try_create_histogram_vec(
"http_api_block_broadcast_delay_times",
"Time between start of the slot and when the block was broadcast",
"Time between start of the slot and when the block completed broadcast and processing",
&["provenance"]
);
pub static ref HTTP_API_BLOCK_GOSSIP_TIMES: Result<HistogramVec> = try_create_histogram_vec_with_buckets(
"http_api_block_gossip_times",
"Time between receiving the block on HTTP and publishing it on gossip",
decimal_buckets(-2, 2),
&["provenance"]
);
pub static ref HTTP_API_BLOCK_PUBLISHED_LATE_TOTAL: Result<IntCounter> = try_create_int_counter(
Expand Down
18 changes: 17 additions & 1 deletion beacon_node/http_api/src/publish_blocks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@ pub async fn publish_block<T: BeaconChainTypes, B: IntoGossipVerifiedBlockConten
ProvenancedBlock::Local(block_contents, _) => (block_contents, true),
ProvenancedBlock::Builder(block_contents, _) => (block_contents, false),
};
let provenance = if is_locally_built_block {
"local"
} else {
"builder"
};
let block = block_contents.inner_block().clone();
let delay = get_block_delay_ms(seen_timestamp, block.message(), &chain.slot_clock);
debug!(log, "Signed block received in HTTP API"; "slot" => block.slot());
Expand All @@ -75,7 +80,18 @@ pub async fn publish_block<T: BeaconChainTypes, B: IntoGossipVerifiedBlockConten
.checked_sub(seen_timestamp)
.unwrap_or_else(|| Duration::from_secs(0));

info!(log, "Signed block published to network via HTTP API"; "slot" => block.slot(), "publish_delay" => ?publish_delay);
metrics::observe_timer_vec(
&metrics::HTTP_API_BLOCK_GOSSIP_TIMES,
&[provenance],
publish_delay,
);

info!(
log,
"Signed block published to network via HTTP API";
"slot" => block.slot(),
"publish_delay_ms" => publish_delay.as_millis()
);

match block.as_ref() {
SignedBeaconBlock::Base(_)
Expand Down
2 changes: 1 addition & 1 deletion beacon_node/network/src/sync/block_lookups/parent_chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ pub(crate) fn compute_parent_chains(nodes: &[Node]) -> Vec<NodeChain> {
// Iterate blocks with no children
for tip in nodes {
let mut block_root = tip.block_root;
if parent_to_child.get(&block_root).is_none() {
if !parent_to_child.contains_key(&block_root) {
let mut chain = vec![];

// Resolve chain of blocks
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ pub const POOL_SIZE: u32 = 1;
#[cfg(not(test))]
pub const CONNECTION_TIMEOUT: Duration = Duration::from_secs(5);
#[cfg(test)]
pub const CONNECTION_TIMEOUT: Duration = Duration::from_millis(500);
pub const CONNECTION_TIMEOUT: Duration = Duration::from_secs(1);

/// Supported version of the interchange format.
pub const SUPPORTED_INTERCHANGE_FORMAT_VERSION: u64 = 5;
Expand Down

0 comments on commit d3d429f

Please sign in to comment.