Skip to content

Commit

Permalink
feat(portal-bridge(beacon)): generate and gossip `HistoricalSummaries…
Browse files Browse the repository at this point in the history
…WithProof` content
  • Loading branch information
ogenev committed Aug 21, 2024
1 parent b4a81e3 commit 5e75579
Show file tree
Hide file tree
Showing 9 changed files with 201 additions and 89 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions ethportal-api/src/types/consensus/beacon_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ pub struct BeaconState {
#[superstruct(getter(copy))]
pub genesis_validators_root: B256,
#[superstruct(getter(copy))]
#[serde(deserialize_with = "as_u64")]
pub slot: u64,
#[superstruct(getter(copy))]
pub fork: Fork,
Expand All @@ -84,12 +85,14 @@ pub struct BeaconState {

// Registry
pub validators: VariableList<Validator, ValidatorRegistryLimit>,
#[serde(deserialize_with = "ssz_types::serde_utils::quoted_u64_var_list::deserialize")]
pub balances: VariableList<u64, ValidatorRegistryLimit>,

// Randomness
pub randao_mixes: FixedVector<B256, EpochsPerHistoricalVector>,

// Slashings
#[serde(deserialize_with = "ssz_types::serde_utils::quoted_u64_fixed_vec::deserialize")]
pub slashings: FixedVector<u64, EpochsPerSlashingsVector>,

// Participation (Altair and later)
Expand All @@ -109,6 +112,7 @@ pub struct BeaconState {

// Inactivity
#[superstruct(only(Bellatrix, Capella, Deneb))]
#[serde(deserialize_with = "ssz_types::serde_utils::quoted_u64_var_list::deserialize")]
pub inactivity_scores: VariableList<u64, ValidatorRegistryLimit>,

// Light-client sync committees
Expand Down
1 change: 1 addition & 0 deletions ethportal-api/src/types/consensus/body.rs
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@ pub struct VoluntaryExit {
#[derive(Debug, PartialEq, Clone, Default, Deserialize, Serialize, Decode, Encode, TreeHash)]
pub struct Eth1Data {
pub deposit_root: B256,
#[serde(deserialize_with = "as_u64")]
pub deposit_count: u64,
pub block_hash: B256,
}
Expand Down
1 change: 1 addition & 0 deletions ethportal-api/src/types/consensus/participation_flags.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use tree_hash::{Hash256, PackedEncoding, TreeHash, TreeHashType};
#[derive(Debug, Default, Clone, Copy, PartialEq, Deserialize, Serialize)]
#[serde(transparent)]
pub struct ParticipationFlags {
#[serde(deserialize_with = "serde_utils::quoted_u8::deserialize")]
bits: u8,
}

Expand Down
1 change: 1 addition & 0 deletions portal-bridge/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ trin-metrics = { path = "../trin-metrics" }
trin-utils = { path = "../trin-utils" }
trin-validation = { path = "../trin-validation" }
url = "2.3.1"
log = "0.4.22"

[dev-dependencies]
env_logger = "0.9.0"
Expand Down
11 changes: 11 additions & 0 deletions portal-bridge/src/api/consensus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,17 @@ impl ConsensusApi {
Ok(Self { primary, fallback })
}

/// Requests the `BeaconState` structure corresponding to the current head of the beacon chain.
pub async fn get_beacon_state(&self) -> anyhow::Result<String> {
let endpoint = "/eth/v2/debug/beacon/states/finalized".to_string();
self.request(endpoint).await
}

pub async fn get_beacon_state_finalized_root(&self) -> anyhow::Result<String> {
let endpoint = "/eth/v1/beacon/states/finalized/root".to_string();
self.request(endpoint).await
}

/// Requests the `LightClientBootstrap` structure corresponding to a given post-Altair beacon
/// block root.
pub async fn get_lc_bootstrap<S: AsRef<str> + Display>(
Expand Down
Loading

0 comments on commit 5e75579

Please sign in to comment.