Skip to content

Commit

Permalink
boilerplate
Browse files Browse the repository at this point in the history
Branched from #2325. Adds most everything from #2237. Main blocker now is to iron out
`ChainConfig` versions. Then we can get into the actual stake table
retrieval logic.
  • Loading branch information
tbro committed Dec 5, 2024
1 parent 4982a2f commit f10f8c9
Show file tree
Hide file tree
Showing 9 changed files with 571 additions and 15 deletions.
1 change: 0 additions & 1 deletion sequencer/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ use futures::{
stream::{Stream, StreamExt},
};
use hotshot::{
traits::election::static_committee::StaticCommittee,
types::{Event, EventType, SystemContextHandle},
MarketplaceConfig, SystemContext,
};
Expand Down
15 changes: 8 additions & 7 deletions sequencer/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ use espresso_types::{
};
use futures::FutureExt;
use genesis::L1Finalized;
use hotshot::traits::election::static_committee::StaticCommittee;
use hotshot_types::traits::election::Membership;
use std::sync::Arc;
// Should move `STAKE_TABLE_CAPACITY` in the sequencer repo when we have variate stake table support
Expand Down Expand Up @@ -386,12 +385,6 @@ pub async fn init_node<P: SequencerPersistence, V: Versions>(
topics
};

// Create the HotShot membership
let membership = StaticCommittee::new(
network_config.config.known_nodes_with_stake.clone(),
network_config.config.known_nodes_with_stake.clone(),
);

// Initialize the push CDN network (and perform the initial connection)
let cdn_network = PushCdnNetwork::new(
network_params.cdn_endpoint,
Expand Down Expand Up @@ -517,6 +510,13 @@ pub async fn init_node<P: SequencerPersistence, V: Versions>(
current_version: V::Base::VERSION,
};

// Create the HotShot membership
let membership = StaticCommittee::new_stake(
network_config.config.known_nodes_with_stake.clone(),
network_config.config.known_nodes_with_stake.clone(),
&instance_state,
);

let mut ctx = SequencerContext::init(
network_config,
validator_config,
Expand Down Expand Up @@ -954,6 +954,7 @@ pub mod testing {
.with_upgrades(upgrades);

// Create the HotShot membership
// TODO use our own implementation and pull from contract
let membership = StaticCommittee::new(
config.known_nodes_with_stake.clone(),
config.known_nodes_with_stake.clone(),
Expand Down
6 changes: 3 additions & 3 deletions types/src/v0/impls/instance_state.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::v0::{
traits::StateCatchup, v0_99::ChainConfig, GenesisHeader, L1BlockInfo, L1Client, PubKey,
traits::StateCatchup, v0_3::ChainConfig, GenesisHeader, L1BlockInfo, L1Client, PubKey,
Timestamp, Upgrade, UpgradeMode,
};
use hotshot_types::traits::states::InstanceState;
Expand All @@ -17,7 +17,7 @@ use super::state::ValidatedState;
#[derive(derive_more::Debug, Clone)]
pub struct NodeState {
pub node_id: u64,
pub chain_config: crate::v0_99::ChainConfig,
pub chain_config: crate::v0_3::ChainConfig,
pub l1_client: L1Client,
#[debug("{}", peers.name())]
pub peers: Arc<dyn StateCatchup>,
Expand Down Expand Up @@ -46,7 +46,7 @@ pub struct NodeState {
impl NodeState {
pub fn new(
node_id: u64,
chain_config: ChainConfig,
chain_config: crate::v0_3::ChainConfig,
l1_client: L1Client,
catchup: impl StateCatchup + 'static,
current_version: Version,
Expand Down
52 changes: 51 additions & 1 deletion types/src/v0/impls/l1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@ use futures::{
future::Future,
stream::{self, StreamExt},
};
use hotshot_types::traits::metrics::Metrics;
use hotshot::types::SignatureKey;
use hotshot_types::{
stake_table::StakeTableEntry,
traits::{metrics::Metrics, node_implementation::NodeType},
};
use lru::LruCache;
use serde::{de::DeserializeOwned, Serialize};
use tokio::{
Expand Down Expand Up @@ -779,6 +783,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 may need to be passed in as well
unimplemented!();
}
}

impl L1State {
Expand Down Expand Up @@ -1246,4 +1261,39 @@ mod test {
};
tracing::info!(?final_state, "state updated");
}

#[tokio::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::permissioned_stake_table::PermissionedStakeTable::deploy(
client.clone(),
(),
)
.unwrap()
.send()
.await?;

Ok(())
}
}
8 changes: 6 additions & 2 deletions types/src/v0/impls/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,18 @@ mod header;
mod instance_state;
mod l1;
mod solver;
mod stake_table;
mod state;
mod transaction;

pub use auction::SolverAuctionResultsProvider;
pub use fee_info::{retain_accounts, FeeError};
pub use instance_state::NodeState;
pub use state::ProposalValidationError;
pub use state::{get_l1_deposits, BuilderValidationError, StateValidationError, ValidatedState};
pub use stake_table::StaticCommittee;
pub use state::{
get_l1_deposits, BuilderValidationError, ProposalValidationError, StateValidationError,
ValidatedState,
};

#[cfg(any(test, feature = "testing"))]
pub use instance_state::mock;
Loading

0 comments on commit f10f8c9

Please sign in to comment.