Skip to content

Commit

Permalink
add back l1 impl
Browse files Browse the repository at this point in the history
  • Loading branch information
tbro committed Nov 4, 2024
1 parent b31b51c commit 6ce37b5
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 2 deletions.
49 changes: 49 additions & 0 deletions types/src/v0/impls/l1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ use futures::{
future::Future,
stream::{self, StreamExt},
};
use hotshot::types::SignatureKey;
use hotshot_types::{stake_table::StakeTableEntry, traits::node_implementation::NodeType};
use lru::LruCache;
use serde::{de::DeserializeOwned, Serialize};
use tracing::Instrument;
Expand Down Expand Up @@ -588,6 +590,17 @@ impl L1Client {
});
events.flatten().map(FeeInfo::from).collect().await
}

/// Get `StakeTable` at block height.
pub async fn get_stake_table<TYPES: NodeType>(
&self,
_block: u64,
_address: Address,
) -> Vec<<TYPES::SignatureKey as SignatureKey>::StakeTableEntry> {
// TODO we either need address from configuration or contract-bindings.
// TODO epoch size will probably need to be passed in as well
unimplemented!();
}
}

impl L1State {
Expand Down Expand Up @@ -942,4 +955,40 @@ mod test {
async fn test_wait_for_block_http() {
test_wait_for_block_helper(false).await
}

#[async_std::test]
async fn test_get_stake_table() -> anyhow::Result<()> {
setup_test();

// how many deposits will we make
let deposits = 5;
let deploy_txn_count = 2;

let anvil = Anvil::new().spawn();
let wallet_address = anvil.addresses().first().cloned().unwrap();
let l1_client = L1Client::new(anvil.endpoint().parse().unwrap());
let wallet: LocalWallet = anvil.keys()[0].clone().into();

// In order to deposit we need a provider that can sign.
let provider =
Provider::<Http>::try_from(anvil.endpoint())?.interval(Duration::from_millis(10u64));
let client =
SignerMiddleware::new(provider.clone(), wallet.with_chain_id(anvil.chain_id()));
let client = Arc::new(client);

// Initialize a contract with some deposits

// deploy the fee contract
let stake_table_contract =
contract_bindings::stake_table::StakeTable::deploy(client.clone(), ())
.unwrap()
.send()
.await?;
// contract_bindings::fee_contract::FeeContract::deploy(Arc::new(client.clone()), ())
// .unwrap()
// .send()
// .await?;

Ok(())
}
}
8 changes: 6 additions & 2 deletions types/src/v0/impls/stake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,15 @@ impl<TYPES: NodeType> StakeCommittee<TYPES> {
/// to be called before calling `self.stake()` so that
/// `Self.stake_table` only needs to be updated once in a given
/// life-cycle but may be read from many times.
// TODO we could just subscribe to L1 updates w/ recent `l1Client`
// changes, but current structure of `Membership` isn't ideal (we
// would have a subscription per field).
async fn update_stake_table(&mut self, l1_block_height: u64) {
let table: Vec<<<TYPES as NodeType>::SignatureKey as SignatureKey>::StakeTableEntry> = self
.provider
.get_stake_table::<TYPES>(l1_block_height, self.contract_address.unwrap())
.await;
.await
.clone();
self.stake_table = table;
}
// We need a constructor to match our concrete type.
Expand Down Expand Up @@ -143,7 +147,7 @@ impl<TYPES: NodeType> Membership<TYPES> for StakeCommittee<TYPES> {
stake_table: members,
indexed_stake_table,
epoch_size: 12, // TODO get the real number from config (I think)
provider: L1Client::new(Url::from_str("http:://ab.b").unwrap(), 0),
provider: L1Client::http(Url::from_str("http:://ab.b").unwrap()),
contract_address: None,
committee_topic,
}
Expand Down

0 comments on commit 6ce37b5

Please sign in to comment.