mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-11 18:04:18 +00:00
Weak subjectivity start from genesis (#1675)
This commit was edited by Paul H when rebasing from master to v0.3.0-staging. Solution 2 proposed here: https://github.com/sigp/lighthouse/issues/1435#issuecomment-692317639 - Adds an optional `--wss-checkpoint` flag that takes a string `root:epoch` - Verify that the given checkpoint exists in the chain, or that the the chain syncs through this checkpoint. If not, shutdown and prompt the user to purge state before restarting. Co-authored-by: Paul Hauner <paul@paulhauner.com>
This commit is contained in:
@@ -314,4 +314,14 @@ pub fn cli_app<'a, 'b>() -> App<'a, 'b> {
|
||||
.takes_value(true)
|
||||
.default_value("700")
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name("wss-checkpoint")
|
||||
.long("wss-checkpoint")
|
||||
.help(
|
||||
"Used to input a Weak Subjectivity State Checkpoint in `block_root:epoch_number` format,\
|
||||
where block_root is an '0x' prefixed 32-byte hex string and epoch_number is an integer."
|
||||
)
|
||||
.value_name("WSS_CHECKPOINT")
|
||||
.takes_value(true)
|
||||
)
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@ use std::fs;
|
||||
use std::net::{IpAddr, Ipv4Addr, ToSocketAddrs};
|
||||
use std::net::{TcpListener, UdpSocket};
|
||||
use std::path::PathBuf;
|
||||
use types::{ChainSpec, EthSpec, GRAFFITI_BYTES_LEN};
|
||||
use types::{ChainSpec, Checkpoint, Epoch, EthSpec, Hash256, GRAFFITI_BYTES_LEN};
|
||||
|
||||
/// Gets the fully-initialized global client.
|
||||
///
|
||||
@@ -303,6 +303,41 @@ pub fn get_config<E: EthSpec>(
|
||||
client_config.graffiti.0[..trimmed_graffiti_len]
|
||||
.copy_from_slice(&raw_graffiti[..trimmed_graffiti_len]);
|
||||
|
||||
if let Some(wss_checkpoint) = cli_args.value_of("wss-checkpoint") {
|
||||
let mut split = wss_checkpoint.split(':');
|
||||
let root_str = split
|
||||
.next()
|
||||
.ok_or_else(|| "Improperly formatted weak subjectivity checkpoint".to_string())?;
|
||||
let epoch_str = split
|
||||
.next()
|
||||
.ok_or_else(|| "Improperly formatted weak subjectivity checkpoint".to_string())?;
|
||||
|
||||
if !root_str.starts_with("0x") {
|
||||
return Err(
|
||||
"Unable to parse weak subjectivity checkpoint root, must have 0x prefix"
|
||||
.to_string(),
|
||||
);
|
||||
}
|
||||
|
||||
if !root_str.chars().count() == 66 {
|
||||
return Err(
|
||||
"Unable to parse weak subjectivity checkpoint root, must have 32 bytes".to_string(),
|
||||
);
|
||||
}
|
||||
|
||||
let root =
|
||||
Hash256::from_slice(&hex::decode(&root_str[2..]).map_err(|e| {
|
||||
format!("Unable to parse weak subjectivity checkpoint root: {:?}", e)
|
||||
})?);
|
||||
let epoch = Epoch::new(
|
||||
epoch_str
|
||||
.parse()
|
||||
.map_err(|_| "Invalid weak subjectivity checkpoint epoch".to_string())?,
|
||||
);
|
||||
|
||||
client_config.chain.weak_subjectivity_checkpoint = Some(Checkpoint { epoch, root })
|
||||
}
|
||||
|
||||
if let Some(max_skip_slots) = cli_args.value_of("max-skip-slots") {
|
||||
client_config.chain.import_max_skip_slots = match max_skip_slots {
|
||||
"none" => None,
|
||||
|
||||
Reference in New Issue
Block a user