From daa1e3792c10a2e11608fa5e02b18337f1fcf18f Mon Sep 17 00:00:00 2001 From: ckoopmann Date: Thu, 2 Feb 2023 14:55:59 +0800 Subject: [PATCH] Loop over all missing slots since last update --- client/src/node.rs | 41 +++++++++++++++++++++++++++++++++-------- 1 file changed, 33 insertions(+), 8 deletions(-) diff --git a/client/src/node.rs b/client/src/node.rs index 5b1dd3b..b6f923a 100644 --- a/client/src/node.rs +++ b/client/src/node.rs @@ -16,6 +16,7 @@ use execution::evm::Evm; use execution::rpc::http_rpc::HttpRpc; use execution::types::{CallOpts, ExecutionBlock}; use execution::ExecutionClient; +use log::{info, warn}; use crate::errors::NodeError; @@ -25,6 +26,7 @@ pub struct Node { pub config: Arc, payloads: BTreeMap, finalized_payloads: BTreeMap, + current_slot: Option, pub history_size: usize, } @@ -49,6 +51,7 @@ impl Node { config, payloads, finalized_payloads, + current_slot: None, history_size: 64, }) } @@ -90,11 +93,29 @@ impl Node { async fn update_payloads(&mut self) -> Result<(), NodeError> { let latest_header = self.consensus.get_header(); - let latest_payload = self - .consensus - .get_execution_payload(&Some(latest_header.slot)) - .await - .map_err(NodeError::ConsensusPayloadError)?; + let start_slot = self.current_slot.unwrap_or(latest_header.slot); + info!( + "updating payloads payloads_before={:?}", + self.payloads.keys(), + ); + + for slot in start_slot..=latest_header.slot { + let execution_payload = self + .consensus + .get_execution_payload(&Some(slot)) + .await + .map_err(NodeError::ConsensusPayloadError); + match execution_payload { + Ok(payload) => { + self.payloads + .insert(payload.block_number, payload); + info!("Successfully loaded payload for slot: {}", slot); + } + Err(err) => { + warn!("{}", err); + } + } + } let finalized_header = self.consensus.get_finalized_header(); let finalized_payload = self @@ -102,9 +123,6 @@ impl Node { .get_execution_payload(&Some(finalized_header.slot)) .await .map_err(NodeError::ConsensusPayloadError)?; - - self.payloads - .insert(latest_payload.block_number, latest_payload); self.payloads .insert(finalized_payload.block_number, finalized_payload.clone()); self.finalized_payloads @@ -120,6 +138,13 @@ impl Node { self.finalized_payloads.pop_first(); } + info!( + "updated payloads payloads_after={:?}", + self.payloads.keys(), + ); + + self.current_slot = Some(latest_header.slot); + Ok(()) }