diff --git a/Cargo.lock b/Cargo.lock index 74467ef7a..e98bd7a01 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -712,7 +712,7 @@ dependencies = [ [[package]] name = "c-kzg" version = "0.1.0" -source = "git+https://github.com/pawanjay176/c-kzg-4844?rev=cb3745d26b728ee526dc41912e3e1bc6f17a5eeb#cb3745d26b728ee526dc41912e3e1bc6f17a5eeb" +source = "git+https://github.com/pawanjay176/c-kzg-4844?rev=669a13800a8a0d094c5387db58e06936ef194a25#669a13800a8a0d094c5387db58e06936ef194a25" dependencies = [ "hex", "libc", diff --git a/beacon_node/beacon_chain/src/beacon_chain.rs b/beacon_node/beacon_chain/src/beacon_chain.rs index 04a628a6e..1e9cc055c 100644 --- a/beacon_node/beacon_chain/src/beacon_chain.rs +++ b/beacon_node/beacon_chain/src/beacon_chain.rs @@ -399,6 +399,7 @@ pub struct BeaconChain { /// Provides monitoring of a set of explicitly defined validators. pub validator_monitor: RwLock>, pub blob_cache: BlobCache, + pub kzg: Option>, } type BeaconBlockAndState = (BeaconBlock, BeaconState); diff --git a/beacon_node/beacon_chain/src/builder.rs b/beacon_node/beacon_chain/src/builder.rs index 887ddf773..54ae834f9 100644 --- a/beacon_node/beacon_chain/src/builder.rs +++ b/beacon_node/beacon_chain/src/builder.rs @@ -21,12 +21,14 @@ use eth1::Config as Eth1Config; use execution_layer::ExecutionLayer; use fork_choice::{ForkChoice, ResetPayloadStatuses}; use futures::channel::mpsc::Sender; +use kzg::Kzg; use operation_pool::{OperationPool, PersistedOperationPool}; use parking_lot::RwLock; use slasher::Slasher; use slog::{crit, error, info, Logger}; use slot_clock::{SlotClock, TestingSlotClock}; use std::marker::PhantomData; +use std::path::PathBuf; use std::sync::Arc; use std::time::Duration; use store::{Error as StoreError, HotColdDB, ItemStore, KeyValueStoreOp}; @@ -94,6 +96,7 @@ pub struct BeaconChainBuilder { // Pending I/O batch that is constructed during building and should be executed atomically // alongside `PersistedBeaconChain` storage when `BeaconChainBuilder::build` is called. pending_io_batch: Vec, + trusted_setup_path: Option, task_executor: Option, } @@ -133,6 +136,7 @@ where slasher: None, validator_monitor: None, pending_io_batch: vec![], + trusted_setup_path: None, task_executor: None, } } @@ -572,6 +576,11 @@ where self } + pub fn trusted_setup(mut self, trusted_setup_file_path: PathBuf) -> Self { + self.trusted_setup_path = Some(trusted_setup_file_path); + self + } + /// Consumes `self`, returning a `BeaconChain` if all required parameters have been supplied. /// /// An error will be returned at runtime if all required parameters have not been configured. @@ -613,6 +622,14 @@ where slot_clock.now().ok_or("Unable to read slot")? }; + let kzg = if let Some(trusted_setup_file) = self.trusted_setup_path { + let kzg = Kzg::new_from_file(trusted_setup_file) + .map_err(|e| format!("Failed to load trusted setup: {:?}", e))?; + Some(Arc::new(kzg)) + } else { + None + }; + let initial_head_block_root = fork_choice .get_head(current_slot, &self.spec) .map_err(|e| format!("Unable to get fork choice head: {:?}", e))?; @@ -814,6 +831,7 @@ where slasher: self.slasher.clone(), validator_monitor: RwLock::new(validator_monitor), blob_cache: BlobCache::default(), + kzg, }; let head = beacon_chain.head_snapshot(); diff --git a/beacon_node/client/src/builder.rs b/beacon_node/client/src/builder.rs index 36d6491a5..150afeacb 100644 --- a/beacon_node/client/src/builder.rs +++ b/beacon_node/client/src/builder.rs @@ -188,6 +188,12 @@ where builder }; + let builder = if let Some(trusted_setup_file) = config.trusted_setup_file { + builder.trusted_setup(trusted_setup_file) + } else { + builder + }; + let chain_exists = builder.store_contains_beacon_chain().unwrap_or(false); // If the client is expect to resume but there's no beacon chain in the database, diff --git a/beacon_node/client/src/config.rs b/beacon_node/client/src/config.rs index 5e43c1eaa..3a8b2db3e 100644 --- a/beacon_node/client/src/config.rs +++ b/beacon_node/client/src/config.rs @@ -68,6 +68,7 @@ pub struct Config { pub chain: beacon_chain::ChainConfig, pub eth1: eth1::Config, pub execution_layer: Option, + pub trusted_setup_file: Option, pub http_api: http_api::Config, pub http_metrics: http_metrics::Config, pub monitoring_api: Option, @@ -90,6 +91,7 @@ impl Default for Config { sync_eth1_chain: false, eth1: <_>::default(), execution_layer: None, + trusted_setup_file: None, graffiti: Graffiti::default(), http_api: <_>::default(), http_metrics: <_>::default(), diff --git a/beacon_node/src/cli.rs b/beacon_node/src/cli.rs index 81a7c6bbe..24bc06c7b 100644 --- a/beacon_node/src/cli.rs +++ b/beacon_node/src/cli.rs @@ -511,6 +511,17 @@ pub fn cli_app<'a, 'b>() -> App<'a, 'b> { .default_value("1") .takes_value(true) ) + /* 4844 settings */ + .arg( + Arg::with_name("trusted-setup-file") + .long("trusted-setup-file") + .value_name("FILE") + .help("File containing the trusted setup parameters. \ + NOTE: This is only for the devnet, the trusted setup params \ + must be embedded into the ethspec once parameter loading \ + is supported in the ckzg library") + .takes_value(true) + ) /* * Database purging and compaction. */ diff --git a/beacon_node/src/config.rs b/beacon_node/src/config.rs index 3b94c3129..af33fdf28 100644 --- a/beacon_node/src/config.rs +++ b/beacon_node/src/config.rs @@ -360,6 +360,11 @@ pub fn get_config( client_config.execution_layer = Some(el_config); } + // 4844 params + if let Some(trusted_setup_file) = cli_args.value_of("trusted-setup-file") { + client_config.trusted_setup_file = Some(PathBuf::from(trusted_setup_file)); + } + if let Some(freezer_dir) = cli_args.value_of("freezer-dir") { client_config.freezer_db_path = Some(PathBuf::from(freezer_dir)); } diff --git a/crypto/kzg/Cargo.toml b/crypto/kzg/Cargo.toml index fb1351f4a..d61745e14 100644 --- a/crypto/kzg/Cargo.toml +++ b/crypto/kzg/Cargo.toml @@ -18,4 +18,5 @@ eth2_serde_utils = "0.1.1" hex = "0.4.2" eth2_hashing = "0.3.0" ethereum-types = "0.12.1" -c-kzg = {git = "https://github.com/pawanjay176/c-kzg-4844", rev = "cb3745d26b728ee526dc41912e3e1bc6f17a5eeb" } +c-kzg = {git = "https://github.com/pawanjay176/c-kzg-4844", rev = "669a13800a8a0d094c5387db58e06936ef194a25" } +