From a3b8a8c05c723d138c3a89282e2416a5e3b6ab02 Mon Sep 17 00:00:00 2001 From: PJColombo Date: Fri, 14 Feb 2025 00:17:54 +0100 Subject: [PATCH 1/3] feat: track latest synced block in Blobscan by updating block root and slot after slot processing --- src/clients/blobscan/types.rs | 14 ++++++++++ .../event_handlers/finalized_checkpoint.rs | 4 ++- src/synchronizer/mod.rs | 26 ++++++++++++------- 3 files changed, 33 insertions(+), 11 deletions(-) diff --git a/src/clients/blobscan/types.rs b/src/clients/blobscan/types.rs index a5f9cef..6c29257 100644 --- a/src/clients/blobscan/types.rs +++ b/src/clients/blobscan/types.rs @@ -68,6 +68,10 @@ pub struct BlockchainSyncStateRequest { pub last_upper_synced_slot: Option, #[serde(default, skip_serializing_if = "Option::is_none")] pub last_finalized_block: Option, + #[serde(default, skip_serializing_if = "Option::is_none")] + pub last_upper_synced_block_root: Option, + #[serde(default, skip_serializing_if = "Option::is_none")] + pub last_upper_synced_block_slot: Option, } #[derive(Deserialize, Debug)] @@ -77,6 +81,10 @@ pub struct BlockchainSyncStateResponse { pub last_lower_synced_slot: Option, #[serde(default, skip_serializing_if = "Option::is_none")] pub last_upper_synced_slot: Option, + #[serde(default, skip_serializing_if = "Option::is_none")] + pub last_upper_synced_block_root: Option, + #[serde(default, skip_serializing_if = "Option::is_none")] + pub last_upper_synced_block_slot: Option, } #[derive(Debug, PartialEq)] @@ -84,6 +92,8 @@ pub struct BlockchainSyncState { pub last_finalized_block: Option, pub last_lower_synced_slot: Option, pub last_upper_synced_slot: Option, + pub last_upper_synced_block_root: Option, + pub last_upper_synced_block_slot: Option, } #[derive(Serialize, Debug)] @@ -253,6 +263,8 @@ impl From for BlockchainSyncState { last_finalized_block: None, last_lower_synced_slot: response.last_lower_synced_slot, last_upper_synced_slot: response.last_upper_synced_slot, + last_upper_synced_block_root: response.last_upper_synced_block_root, + last_upper_synced_block_slot: response.last_upper_synced_block_slot, } } } @@ -263,6 +275,8 @@ impl From for BlockchainSyncStateRequest { last_lower_synced_slot: sync_state.last_lower_synced_slot, last_upper_synced_slot: sync_state.last_upper_synced_slot, last_finalized_block: sync_state.last_finalized_block, + last_upper_synced_block_root: sync_state.last_upper_synced_block_root, + last_upper_synced_block_slot: sync_state.last_upper_synced_block_slot, } } } diff --git a/src/indexer/event_handlers/finalized_checkpoint.rs b/src/indexer/event_handlers/finalized_checkpoint.rs index c443b89..df99098 100644 --- a/src/indexer/event_handlers/finalized_checkpoint.rs +++ b/src/indexer/event_handlers/finalized_checkpoint.rs @@ -71,9 +71,11 @@ where self.context .blobscan_client() .update_sync_state(BlockchainSyncState { + last_finalized_block: Some(last_finalized_block_number), last_lower_synced_slot: None, last_upper_synced_slot: None, - last_finalized_block: Some(last_finalized_block_number), + last_upper_synced_block_root: None, + last_upper_synced_block_slot: None, }) .await .map_err(FinalizedCheckpointEventHandlerError::BlobscanFinalizedBlockUpdateFailure)?; diff --git a/src/synchronizer/mod.rs b/src/synchronizer/mod.rs index d20ef36..6f912b0 100644 --- a/src/synchronizer/mod.rs +++ b/src/synchronizer/mod.rs @@ -262,16 +262,20 @@ impl Synchronizer { }); if self.checkpoint_type != CheckpointType::Disabled { - let last_lower_synced_slot = if self.checkpoint_type == CheckpointType::Lower { - last_slot - } else { - None - }; - let last_upper_synced_slot = if self.checkpoint_type == CheckpointType::Upper { - last_slot - } else { - None - }; + let mut last_lower_synced_slot = None; + let mut last_upper_synced_slot = None; + let mut last_upper_synced_block_root = None; + let mut last_upper_synced_block_slot = None; + + if self.checkpoint_type == CheckpointType::Lower { + last_lower_synced_slot = last_slot; + } else if self.checkpoint_type == CheckpointType::Upper { + last_upper_synced_slot = last_slot; + last_upper_synced_block_root = + self.last_synced_block.as_ref().map(|block| block.root); + last_upper_synced_block_slot = + self.last_synced_block.as_ref().map(|block| block.slot); + } if let Err(error) = self .context @@ -280,6 +284,8 @@ impl Synchronizer { last_finalized_block: None, last_lower_synced_slot, last_upper_synced_slot, + last_upper_synced_block_root, + last_upper_synced_block_slot, }) .await { From 7cbb123d189ac0e5acda8f12b29df8236fc6b68d Mon Sep 17 00:00:00 2001 From: PJColombo Date: Fri, 14 Feb 2025 00:46:20 +0100 Subject: [PATCH 2/3] feat: pass last synced block root and slot to synchronizer when starting indexer --- src/indexer/mod.rs | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/indexer/mod.rs b/src/indexer/mod.rs index eb8bbf3..c592743 100644 --- a/src/indexer/mod.rs +++ b/src/indexer/mod.rs @@ -112,13 +112,17 @@ impl Indexer { }; let last_synced_block = sync_state.and_then(|state| { - state - .last_upper_synced_slot - .map(|last_upper_synced_slot| BlockHeader { - slot: last_upper_synced_slot, - root: B256::ZERO, + match ( + state.last_upper_synced_block_root, + state.last_upper_synced_slot, + ) { + (Some(root), Some(slot)) => Some(BlockHeader { parent_root: B256::ZERO, - }) + root, + slot, + }), + _ => None, + } }); let upper_indexed_block_id = match &last_synced_block { From 699eac30ed5102dfc33b1bfe4d7af119b17a5fad Mon Sep 17 00:00:00 2001 From: PJColombo Date: Fri, 14 Feb 2025 08:32:27 +0100 Subject: [PATCH 3/3] chore: display last upper synced block slot and root in log --- src/indexer/mod.rs | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/src/indexer/mod.rs b/src/indexer/mod.rs index c592743..9fad045 100644 --- a/src/indexer/mod.rs +++ b/src/indexer/mod.rs @@ -111,7 +111,7 @@ impl Indexer { }, }; - let last_synced_block = sync_state.and_then(|state| { + let last_synced_block = sync_state.as_ref().and_then(|state| { match ( state.last_upper_synced_block_root, state.last_upper_synced_slot, @@ -125,14 +125,10 @@ impl Indexer { } }); - let upper_indexed_block_id = match &last_synced_block { - Some(block) => block.slot.into(), - None => BlockId::Head, - }; - info!( - lower_indexed_block_id = current_lower_block_id.to_string(), - upper_indexed_block_id = upper_indexed_block_id.to_string(), + last_lowest_synced_slot = ?current_lower_block_id, + last_upper_synced_block_slot = ?last_synced_block.as_ref().map(|block| block.slot), + last_upper_synced_block_root = ?last_synced_block.as_ref().map(|block| block.root), "Starting indexer…", );