Skip to content

Commit

Permalink
Preliminary add_epoch_root implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
tbro committed Jan 6, 2025
1 parent bfb3d08 commit 87e80a6
Showing 1 changed file with 25 additions and 4 deletions.
29 changes: 25 additions & 4 deletions types/src/v0/impls/stake_table.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
use super::{
v0_3::{DAMembers, StakeTable, StakeTables},
L1Client, NodeState, PubKey, SeqTypes,
Header, L1Client, NodeState, PubKey, SeqTypes,
};

use async_trait::async_trait;
use contract_bindings::permissioned_stake_table::StakersUpdatedFilter;
use ethers::types::U256;
use ethers::types::{Address, U256};
use futures::FutureExt;
use hotshot::types::SignatureKey as _;
use hotshot_contract_adapter::stake_table::NodeInfoJf;
use hotshot_types::{
Expand All @@ -18,13 +20,11 @@ use hotshot_types::{
PeerConfig,
};
use itertools::Itertools;
use std::sync::RwLock;
use std::{
cmp::max,
collections::{BTreeMap, BTreeSet, HashMap},
num::NonZeroU64,
str::FromStr,
sync::Arc,
};
use thiserror::Error;

Expand Down Expand Up @@ -248,6 +248,7 @@ impl EpochCommittees {
#[error("Could not lookup leader")] // TODO error variants? message?
pub struct LeaderLookupError;

#[async_trait]
impl Membership<SeqTypes> for EpochCommittees {
type Error = LeaderLookupError;

Expand Down Expand Up @@ -462,6 +463,26 @@ impl Membership<SeqTypes> for EpochCommittees {
))
.unwrap()
}

#[allow(clippy::type_complexity)]
async fn add_epoch_root(
&self,
epoch: Epoch,
block_header: Header,
) -> Option<Box<dyn FnOnce(&mut Self) + Send>> {
if let Ok(stake_table) = self
.l1_client
// TODO add contract address to `EpochCommittee`.
.get_stake_table(Address::default(), block_header.height())
.await
{
Some(Box::new(move |c| {
let _ = c.update_stake_table(epoch, stake_table);
}))
} else {
None
}
}
}

#[cfg(test)]
Expand Down

0 comments on commit 87e80a6

Please sign in to comment.