Skip to content
This repository has been archived by the owner on Nov 10, 2023. It is now read-only.

Commit

Permalink
minor fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Wizdave97 committed Sep 12, 2023
1 parent eb31545 commit 30d1212
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 27 deletions.
16 changes: 4 additions & 12 deletions primitives/src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ pub const BLS_SECRET_KEY_BYTES_LEN: usize = 32;
pub const BLS_SIGNATURE_BYTES_LEN: usize = 96;

pub const SYNC_COMMITTEE_SIZE: usize = 512;
pub const EPOCHS_PER_SYNC_COMMITTEE_PERIOD: Epoch = 256;
pub const MAX_WITHDRAWALS_PER_PAYLOAD: usize = 16;
pub const MAX_BLS_TO_EXECUTION_CHANGES: usize = 16;
pub const MAX_VALIDATORS_PER_WITHDRAWALS_SWEEP: usize = 16384;

pub const MAX_VALIDATORS_PER_COMMITTEE: usize = 2048;
pub const EPOCHS_PER_ETH1_VOTING_PERIOD: Epoch = 64;
Expand Down Expand Up @@ -94,10 +98,6 @@ pub mod testnet {
pub const BELLATRIX_FORK_EPOCH: Epoch = 112260;
pub const CAPELLA_FORK_EPOCH: Epoch = u64::MAX;
pub const CAPELLA_FORK_VERSION: Version = [3, 0, 16, 32];
pub const MAX_WITHDRAWALS_PER_PAYLOAD: usize = 16;
pub const MAX_BLS_TO_EXECUTION_CHANGES: usize = 16;
pub const MAX_VALIDATORS_PER_WITHDRAWALS_SWEEP: usize = 16384;
pub const EPOCHS_PER_SYNC_COMMITTEE_PERIOD: Epoch = 256;
}

#[cfg(feature = "mainnet")]
Expand All @@ -113,10 +113,6 @@ pub mod mainnet {
pub const BELLATRIX_FORK_EPOCH: Epoch = 144896;
pub const CAPELLA_FORK_EPOCH: Epoch = u64::MAX;
pub const CAPELLA_FORK_VERSION: Version = [3, 0, 0, 0];
pub const MAX_WITHDRAWALS_PER_PAYLOAD: usize = 16;
pub const MAX_BLS_TO_EXECUTION_CHANGES: usize = 16;
pub const MAX_VALIDATORS_PER_WITHDRAWALS_SWEEP: usize = 16384;
pub const EPOCHS_PER_SYNC_COMMITTEE_PERIOD: Epoch = 256;
}

#[cfg(all(not(feature = "mainnet"), not(feature = "testnet")))]
Expand All @@ -133,8 +129,4 @@ pub mod devnet {
pub const BELLATRIX_FORK_EPOCH: Epoch = 0;
pub const CAPELLA_FORK_EPOCH: Epoch = 2;
pub const CAPELLA_FORK_VERSION: Version = hex!("52525503");
pub const MAX_WITHDRAWALS_PER_PAYLOAD: usize = 16;
pub const MAX_BLS_TO_EXECUTION_CHANGES: usize = 16;
pub const MAX_VALIDATORS_PER_WITHDRAWALS_SWEEP: usize = 16384;
pub const EPOCHS_PER_SYNC_COMMITTEE_PERIOD: Epoch = 256;
}
5 changes: 4 additions & 1 deletion prover/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -267,11 +267,14 @@ impl SyncCommitteeProver {
let attested_header = self.fetch_header(&attested_block_id).await?;
let mut attested_state =
self.fetch_beacon_state(&get_block_id(attested_header.state_root)).await?;

if attested_state.finalized_checkpoint.root == Node::default() {
return Ok(None)
}
let finalized_block_id = get_block_id(attested_state.finalized_checkpoint.root);
let finalized_header = self.fetch_header(&finalized_block_id).await?;
let mut finalized_state =
self.fetch_beacon_state(&get_block_id(finalized_header.state_root)).await?;

let finality_proof = FinalityProof {
epoch: attested_state.finalized_checkpoint.epoch,
finality_branch: prove_finalized_header(&mut attested_state)?,
Expand Down
28 changes: 14 additions & 14 deletions prover/src/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,17 @@ use tokio_stream::StreamExt;
const CONSENSUS_NODE_URL: &'static str = "http://localhost:3500";
const EL_NODE_URL: &'static str = "http://localhost:8545";

async fn wait_for_el() {
async fn wait_for_el(blocks: usize) {
let provider = Provider::<Http>::connect(EL_NODE_URL).await;
let sub = provider.watch_blocks().await.unwrap();
let _ = sub.take(10).collect::<Vec<_>>();
let _ = sub.take(blocks).collect::<Vec<_>>();
}

#[cfg(test)]
#[allow(non_snake_case)]
#[tokio::test]
async fn fetch_block_header_works() {
wait_for_el().await;
wait_for_el(1).await;
let sync_committee_prover = SyncCommitteeProver::new(CONSENSUS_NODE_URL.to_string());
let block_header = sync_committee_prover.fetch_header("head").await;
assert!(block_header.is_ok());
Expand All @@ -46,7 +46,7 @@ async fn fetch_block_header_works() {
#[allow(non_snake_case)]
#[tokio::test]
async fn fetch_block_works() {
wait_for_el().await;
wait_for_el(1).await;
let sync_committee_prover = SyncCommitteeProver::new(CONSENSUS_NODE_URL.to_string());
let block = sync_committee_prover.fetch_block("head").await;
assert!(block.is_ok());
Expand All @@ -56,7 +56,7 @@ async fn fetch_block_works() {
#[allow(non_snake_case)]
#[tokio::test]
async fn fetch_validator_works() {
wait_for_el().await;
wait_for_el(1).await;
let sync_committee_prover = SyncCommitteeProver::new(CONSENSUS_NODE_URL.to_string());
let validator = sync_committee_prover.fetch_validator("head", "0").await;
assert!(validator.is_ok());
Expand All @@ -67,7 +67,7 @@ async fn fetch_validator_works() {
#[tokio::test]
#[ignore]
async fn fetch_processed_sync_committee_works() {
wait_for_el().await;
wait_for_el(1).await;
let sync_committee_prover = SyncCommitteeProver::new(CONSENSUS_NODE_URL.to_string());
let validator = sync_committee_prover.fetch_processed_sync_committee("head").await;
assert!(validator.is_ok());
Expand Down Expand Up @@ -114,7 +114,7 @@ async fn generate_indexes() {
#[allow(non_snake_case)]
#[tokio::test]
async fn fetch_beacon_state_works() {
wait_for_el().await;
wait_for_el(1).await;
let sync_committee_prover = SyncCommitteeProver::new(CONSENSUS_NODE_URL.to_string());
let beacon_state = sync_committee_prover.fetch_beacon_state("head").await;
assert!(beacon_state.is_ok());
Expand All @@ -124,7 +124,7 @@ async fn fetch_beacon_state_works() {
#[allow(non_snake_case)]
#[tokio::test]
async fn state_root_and_block_header_root_matches() {
wait_for_el().await;
wait_for_el(1).await;
let sync_committee_prover = SyncCommitteeProver::new(CONSENSUS_NODE_URL.to_string());
let mut beacon_state = sync_committee_prover.fetch_beacon_state("head").await.unwrap();

Expand All @@ -141,7 +141,7 @@ async fn state_root_and_block_header_root_matches() {
#[allow(non_snake_case)]
#[tokio::test]
async fn fetch_finality_checkpoints_work() {
wait_for_el().await;
wait_for_el(1).await;
let sync_committee_prover = SyncCommitteeProver::new(CONSENSUS_NODE_URL.to_string());
let finality_checkpoint = sync_committee_prover.fetch_finalized_checkpoint().await;
assert!(finality_checkpoint.is_ok());
Expand All @@ -151,7 +151,7 @@ async fn fetch_finality_checkpoints_work() {
#[allow(non_snake_case)]
#[tokio::test]
async fn test_finalized_header() {
wait_for_el().await;
wait_for_el(1).await;
let sync_committee_prover = SyncCommitteeProver::new(CONSENSUS_NODE_URL.to_string());
let mut state = sync_committee_prover.fetch_beacon_state("head").await.unwrap();

Expand All @@ -178,7 +178,7 @@ async fn test_finalized_header() {
#[allow(non_snake_case)]
#[tokio::test]
async fn test_execution_payload_proof() {
wait_for_el().await;
wait_for_el(10).await;
let sync_committee_prover = SyncCommitteeProver::new(CONSENSUS_NODE_URL.to_string());

let mut finalized_state = sync_committee_prover.fetch_beacon_state("head").await.unwrap();
Expand Down Expand Up @@ -229,7 +229,7 @@ async fn test_execution_payload_proof() {
#[allow(non_snake_case)]
#[tokio::test]
async fn test_sync_committee_update_proof() {
wait_for_el().await;
wait_for_el(1).await;
let sync_committee_prover = SyncCommitteeProver::new(CONSENSUS_NODE_URL.to_string());

let mut finalized_state = sync_committee_prover.fetch_beacon_state("head").await.unwrap();
Expand Down Expand Up @@ -269,7 +269,7 @@ async fn test_prover() {
.filter_module("prover", LevelFilter::Debug)
.format_module_path(false)
.init();
wait_for_el().await;
wait_for_el(1).await;
let node_url = format!("{}/eth/v1/events?topics=finalized_checkpoint", CONSENSUS_NODE_URL);

let sync_committee_prover = SyncCommitteeProver::new(CONSENSUS_NODE_URL.to_string());
Expand Down Expand Up @@ -339,7 +339,7 @@ async fn test_prover() {
#[allow(non_snake_case)]
#[tokio::test]
async fn test_sync_committee_signature_verification() {
wait_for_el().await;
wait_for_el(1).await;
let sync_committee_prover = SyncCommitteeProver::new(CONSENSUS_NODE_URL.to_string());
let block = loop {
let block = sync_committee_prover.fetch_block("head").await.unwrap();
Expand Down

0 comments on commit 30d1212

Please sign in to comment.