Loop over all missing slots since last update

This commit is contained in:
ckoopmann 2023-02-02 14:55:59 +08:00
parent 7b7dc708f8
commit daa1e3792c
1 changed files with 33 additions and 8 deletions

View File

@ -16,6 +16,7 @@ use execution::evm::Evm;
use execution::rpc::http_rpc::HttpRpc; use execution::rpc::http_rpc::HttpRpc;
use execution::types::{CallOpts, ExecutionBlock}; use execution::types::{CallOpts, ExecutionBlock};
use execution::ExecutionClient; use execution::ExecutionClient;
use log::{info, warn};
use crate::errors::NodeError; use crate::errors::NodeError;
@ -25,6 +26,7 @@ pub struct Node {
pub config: Arc<Config>, pub config: Arc<Config>,
payloads: BTreeMap<u64, ExecutionPayload>, payloads: BTreeMap<u64, ExecutionPayload>,
finalized_payloads: BTreeMap<u64, ExecutionPayload>, finalized_payloads: BTreeMap<u64, ExecutionPayload>,
current_slot: Option<u64>,
pub history_size: usize, pub history_size: usize,
} }
@ -49,6 +51,7 @@ impl Node {
config, config,
payloads, payloads,
finalized_payloads, finalized_payloads,
current_slot: None,
history_size: 64, history_size: 64,
}) })
} }
@ -90,11 +93,29 @@ impl Node {
async fn update_payloads(&mut self) -> Result<(), NodeError> { async fn update_payloads(&mut self) -> Result<(), NodeError> {
let latest_header = self.consensus.get_header(); let latest_header = self.consensus.get_header();
let latest_payload = self 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 .consensus
.get_execution_payload(&Some(latest_header.slot)) .get_execution_payload(&Some(slot))
.await .await
.map_err(NodeError::ConsensusPayloadError)?; .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_header = self.consensus.get_finalized_header();
let finalized_payload = self let finalized_payload = self
@ -102,9 +123,6 @@ impl Node {
.get_execution_payload(&Some(finalized_header.slot)) .get_execution_payload(&Some(finalized_header.slot))
.await .await
.map_err(NodeError::ConsensusPayloadError)?; .map_err(NodeError::ConsensusPayloadError)?;
self.payloads
.insert(latest_payload.block_number, latest_payload);
self.payloads self.payloads
.insert(finalized_payload.block_number, finalized_payload.clone()); .insert(finalized_payload.block_number, finalized_payload.clone());
self.finalized_payloads self.finalized_payloads
@ -120,6 +138,13 @@ impl Node {
self.finalized_payloads.pop_first(); self.finalized_payloads.pop_first();
} }
info!(
"updated payloads payloads_after={:?}",
self.payloads.keys(),
);
self.current_slot = Some(latest_header.slot);
Ok(()) Ok(())
} }