Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions fork_choice_control/src/checkpoint_sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,28 @@ use types::{
combined::{BeaconState, SignedBeaconBlock},
config::Config,
nonstandard::FinalizedCheckpoint,
phase0::{consts::GENESIS_EPOCH, primitives::H256},
phase0::{
consts::GENESIS_EPOCH,
primitives::{Slot, H256},
},
preset::Preset,
redacting_url::RedactingUrl,
traits::SignedBeaconBlock as _,
};

pub async fn load_finalized_from_remote<P: Preset>(
pub async fn load_from_remote<P: Preset>(
config: &Config,
client: &Client,
url: &RedactingUrl,
checkpoint_slot: Option<Slot>,
) -> Result<FinalizedCheckpoint<P>> {
info!("performing checkpoint sync from {url}…");

let mut block = fetch_block(config, client, url, BlockId::Finalized)
let block_id = checkpoint_slot
.map(BlockId::Slot)
.unwrap_or(BlockId::Finalized);

let mut block = fetch_block(config, client, url, block_id)
.await?
.ok_or(Error::NoFinalizedBlock)?;

Expand Down
31 changes: 20 additions & 11 deletions fork_choice_control/src/storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,12 @@ pub enum StateLoadStrategy<P: Preset> {
Auto {
state_slot: Option<Slot>,
checkpoint_sync_url: Option<RedactingUrl>,
checkpoint_sync_slot: Option<Slot>,
anchor_checkpoint_provider: AnchorCheckpointProvider<P>,
},
Remote {
checkpoint_sync_url: RedactingUrl,
checkpoint_sync_slot: Option<Slot>,
},
Anchor {
block: Arc<SignedBeaconBlock<P>>,
Expand Down Expand Up @@ -108,6 +110,7 @@ impl<P: Preset> Storage<P> {
StateLoadStrategy::Auto {
state_slot,
checkpoint_sync_url,
checkpoint_sync_slot,
anchor_checkpoint_provider,
} => 'block: {
// Attempt to load local state first: either latest or from specified slot.
Expand All @@ -124,9 +127,14 @@ impl<P: Preset> Storage<P> {
info!("anchor checkpoint is already loaded from remote checkpoint sync server");
Ok(checkpoint)
} else {
checkpoint_sync::load_finalized_from_remote(&self.config, client, &url)
.await
.context(Error::CheckpointSyncFailed)
checkpoint_sync::load_from_remote(
&self.config,
client,
&url,
checkpoint_sync_slot,
)
.await
.context(Error::CheckpointSyncFailed)
};

match result {
Expand Down Expand Up @@ -174,15 +182,16 @@ impl<P: Preset> Storage<P> {
}
StateLoadStrategy::Remote {
checkpoint_sync_url,
checkpoint_sync_slot,
} => {
let FinalizedCheckpoint { block, state } =
checkpoint_sync::load_finalized_from_remote(
&self.config,
client,
&checkpoint_sync_url,
)
.await
.context(Error::CheckpointSyncFailed)?;
let FinalizedCheckpoint { block, state } = checkpoint_sync::load_from_remote(
&self.config,
client,
&checkpoint_sync_url,
checkpoint_sync_slot,
)
.await
.context(Error::CheckpointSyncFailed)?;

anchor_block = block;
anchor_state = state;
Expand Down
7 changes: 7 additions & 0 deletions grandine/src/grandine_args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,11 @@ struct BeaconNodeOptions {
#[clap(long)]
checkpoint_sync_url: Option<RedactingUrl>,

/// Load checkpoint state at specified slot instead of recent finalized one. Requires --checkpoint-sync-url
/// [default: None]
#[clap(long, requires = "checkpoint_sync_url")]
checkpoint_sync_slot: Option<Slot>,

/// Force checkpoint sync. Requires --checkpoint-sync-url
/// [default: disabled]
#[clap(long, requires = "checkpoint_sync_url")]
Expand Down Expand Up @@ -913,6 +918,7 @@ impl GrandineArgs {
max_empty_slots,
max_events,
checkpoint_sync_url,
checkpoint_sync_slot,
eth1_rpc_urls,
force_checkpoint_sync,
data_dir,
Expand Down Expand Up @@ -1287,6 +1293,7 @@ impl GrandineArgs {
genesis_state_file,
genesis_state_download_url,
checkpoint_sync_url,
checkpoint_sync_slot,
force_checkpoint_sync,
back_sync_enabled,
eth1_rpc_urls,
Expand Down
1 change: 1 addition & 0 deletions grandine/src/grandine_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ pub struct GrandineConfig {
pub genesis_state_file: Option<PathBuf>,
pub genesis_state_download_url: Option<RedactingUrl>,
pub checkpoint_sync_url: Option<RedactingUrl>,
pub checkpoint_sync_slot: Option<Slot>,
pub force_checkpoint_sync: bool,
pub back_sync_enabled: bool,
pub eth1_rpc_urls: Vec<RedactingUrl>,
Expand Down
6 changes: 6 additions & 0 deletions grandine/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ struct Context {
validator_api_config: Option<ValidatorApiConfig>,
validator_config: Arc<ValidatorConfig>,
checkpoint_sync_url: Option<RedactingUrl>,
checkpoint_sync_slot: Option<Slot>,
force_checkpoint_sync: bool,
back_sync_enabled: bool,
eth1_rpc_urls: Vec<RedactingUrl>,
Expand Down Expand Up @@ -169,6 +170,7 @@ impl Context {
validator_api_config,
validator_config,
checkpoint_sync_url,
checkpoint_sync_slot,
force_checkpoint_sync,
back_sync_enabled,
eth1_rpc_urls,
Expand Down Expand Up @@ -272,11 +274,13 @@ impl Context {
"the requires attribute for force_checkpoint_sync \
ensures checkpoint_sync_url is present",
),
checkpoint_sync_slot,
}
} else {
StateLoadStrategy::Auto {
state_slot,
checkpoint_sync_url,
checkpoint_sync_slot,
anchor_checkpoint_provider: anchor_checkpoint_provider.clone(),
}
};
Expand Down Expand Up @@ -359,6 +363,7 @@ fn try_main() -> Result<()> {
genesis_state_file,
genesis_state_download_url,
checkpoint_sync_url,
checkpoint_sync_slot,
force_checkpoint_sync,
back_sync_enabled,
eth1_rpc_urls,
Expand Down Expand Up @@ -526,6 +531,7 @@ fn try_main() -> Result<()> {
validator_api_config,
validator_config,
checkpoint_sync_url,
checkpoint_sync_slot,
force_checkpoint_sync,
back_sync_enabled,
eth1_rpc_urls,
Expand Down
Loading