checkpoint sync without alignment

This commit is contained in:
realbigsean
2023-06-09 12:03:59 -04:00
parent 8da95ac9c6
commit 9fa67ccb88
5 changed files with 22 additions and 50 deletions

View File

@@ -28,6 +28,7 @@ use network::{NetworkConfig, NetworkSenders, NetworkService};
use slasher::Slasher;
use slasher_service::SlasherService;
use slog::{debug, info, warn, Logger};
use state_processing::per_slot_processing;
use std::net::TcpListener;
use std::path::{Path, PathBuf};
use std::sync::Arc;
@@ -347,8 +348,8 @@ where
};
debug!(context.log(), "Downloading finalized block");
// Find a suitable finalized block on an epoch boundary.
let mut block = remote
// Find a suitable finalized block.
let block = remote
.get_beacon_blocks_ssz::<TEthSpec>(BlockId::Finalized, &spec)
.await
.map_err(|e| match e {
@@ -363,42 +364,13 @@ where
debug!(context.log(), "Downloaded finalized block");
let mut block_slot = block.slot();
while block.slot() % slots_per_epoch != 0 {
block_slot = (block_slot / slots_per_epoch - 1) * slots_per_epoch;
debug!(
context.log(),
"Searching for aligned checkpoint block";
"block_slot" => block_slot
);
if let Some(found_block) = remote
.get_beacon_blocks_ssz::<TEthSpec>(BlockId::Slot(block_slot), &spec)
.await
.map_err(|e| {
format!("Error fetching block at slot {}: {:?}", block_slot, e)
})?
{
block = found_block;
}
}
debug!(
context.log(),
"Downloaded aligned finalized block";
"block_root" => ?block.canonical_root(),
"block_slot" => block.slot(),
);
let state_root = block.state_root();
debug!(
context.log(),
"Downloading finalized state";
"state_root" => ?state_root
);
let state = remote
let mut state = remote
.get_debug_beacon_states_ssz::<TEthSpec>(StateId::Root(state_root), &spec)
.await
.map_err(|e| {
@@ -413,13 +385,19 @@ where
debug!(context.log(), "Downloaded finalized state");
while state.slot() % slots_per_epoch != 0 {
per_slot_processing(&mut state, Some(state_root), &spec)
.map_err(|e| format!("Error advancing state: {:?}", e))?;
}
let genesis_state = BeaconState::from_ssz_bytes(&genesis_state_bytes, &spec)
.map_err(|e| format!("Unable to parse genesis state SSZ: {:?}", e))?;
info!(
context.log(),
"Loaded checkpoint block and state";
"slot" => block.slot(),
"block_slot" => block.slot(),
"state_slot" => state.slot(),
"block_root" => ?block.canonical_root(),
"state_root" => ?state_root,
);