Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fetch stake table #2237

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions contract-bindings/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ pub mod light_client_state_update_vk_mock;
pub mod plonk_verifier;
pub mod plonk_verifier_2;
pub mod shared_types;
pub mod stake_table;
2,743 changes: 2,743 additions & 0 deletions contract-bindings/src/stake_table.rs

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion justfile
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ build-docker-images:
scripts/build-docker-images-native

# generate rust bindings for contracts
REGEXP := "^LightClient$|^LightClientStateUpdateVK$|^FeeContract$|PlonkVerifier$|^ERC1967Proxy$|^LightClientMock$|^LightClientStateUpdateVKMock$|^PlonkVerifier2$"
REGEXP := "^LightClient$|^LightClientStateUpdateVK$|^FeeContract$|^StakeTable$|PlonkVerifier$|^ERC1967Proxy$|^LightClientMock$|^LightClientStateUpdateVKMock$|^PlonkVerifier2$"
gen-bindings:
forge bind --contracts ./contracts/src/ --crate-name contract-bindings --bindings-path contract-bindings --select "{{REGEXP}}" --overwrite --force

Expand Down
18 changes: 9 additions & 9 deletions sequencer/src/context.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
use std::fmt::Display;

use anyhow::Context;
use async_compatibility_layer::art::async_timeout;
use async_std::{
Expand All @@ -10,27 +8,24 @@ use committable::{Commitment, Committable};
use derivative::Derivative;
use espresso_types::{
v0::traits::{EventConsumer as PersistenceEventConsumer, SequencerPersistence},
NodeState, PubKey, Transaction, ValidatedState,
NodeState, PubKey, StakeCommittee, Transaction, ValidatedState,
};
use futures::{
future::{join_all, Future},
stream::{Stream, StreamExt},
};
use hotshot::{
traits::election::static_committee::StaticCommittee,
types::{Event, EventType, SystemContextHandle},
MarketplaceConfig, Memberships, SystemContext,
};
use hotshot_events_service::events_source::{EventConsumer, EventsStreamer};

use hotshot_orchestrator::client::OrchestratorClient;
use hotshot_query_service::Leaf;
use hotshot_types::{
consensus::ConsensusMetricsValue,
data::{EpochNumber, ViewNumber},
network::NetworkConfig,
traits::{
election::Membership,
metrics::Metrics,
network::{ConnectedNetwork, Topic},
node_implementation::{ConsensusTime, Versions},
Expand All @@ -39,6 +34,7 @@ use hotshot_types::{
utils::{View, ViewInner},
PeerConfig,
};
use std::fmt::Display;
use std::time::Duration;
use url::Url;

Expand Down Expand Up @@ -112,20 +108,24 @@ impl<N: ConnectedNetwork<PubKey>, P: SequencerPersistence, V: Versions> Sequence
.load_consensus_state::<V>(instance_state.clone())
.await?;

let committee_membership = StaticCommittee::new(
let committee_membership = StakeCommittee::new_stake(
config.known_nodes_with_stake.clone(),
config.known_nodes_with_stake.clone(),
Topic::Global,
&instance_state,
config.epoch_height,
);

let da_membership = StaticCommittee::new(
let da_membership = StakeCommittee::new_stake(
config.known_nodes_with_stake.clone(),
config.known_da_nodes.clone(),
Topic::Da,
&instance_state,
config.epoch_height,
);

let memberships = Memberships {
quorum_membership: committee_membership.clone(),
quorum_membership: committee_membership,
da_membership,
};

Expand Down
4 changes: 3 additions & 1 deletion sequencer/src/genesis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,8 @@ mod test {
base_fee: 1.into(),
fee_recipient: FeeAccount::default(),
fee_contract: Some(Address::default()),
bid_recipient: None
bid_recipient: None,
stake_table_contract: None
}
);
assert_eq!(
Expand Down Expand Up @@ -481,6 +482,7 @@ mod test {
fee_recipient: FeeAccount::default(),
bid_recipient: None,
fee_contract: None,
stake_table_contract: None
}
);
assert_eq!(
Expand Down
4 changes: 2 additions & 2 deletions sequencer/src/message_compat_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,13 @@ use vbs::{

#[cfg(feature = "testing")]
async fn test_message_compat<Ver: StaticVersionType>(_ver: Ver) {
use espresso_types::{Payload, SeqTypes, Transaction};
use espresso_types::{Payload, SeqTypes, StakeCommittee, Transaction};
use hotshot_example_types::node_types::TestVersions;
use hotshot_types::{traits::network::Topic, PeerConfig};

let (sender, priv_key) = PubKey::generated_from_seed_indexed(Default::default(), 0);
let signature = PubKey::sign(&priv_key, &[]).unwrap();
let membership = StaticCommittee::new(
let membership = StakeCommittee::new(
vec![], /* no elligible leaders */
vec![PeerConfig::default()], /* one committee member, necessary to generate a VID share */
Topic::Global,
Expand Down
1 change: 1 addition & 0 deletions types/src/reference_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ fn reference_chain_config() -> crate::v0_3::ChainConfig {
fee_contract: Some(Default::default()),
fee_recipient: Default::default(),
bid_recipient: Some(Default::default()),
stake_table_contract: Some(Default::default()),
}
}

Expand Down
51 changes: 51 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> {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

link

// 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,42 @@ 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();

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 stake TODO

// deploy the stake_table contract
let stake_table_contract = contract_bindings::stake_table::StakeTable::deploy(
client.clone(),
(Address::default(), Address::default(), 64u64),
)
.unwrap()
.send()
.await?;

let epoch = stake_table_contract.current_epoch().call().await?;
assert_eq!(0, epoch);

let stake = stake_table_contract.total_stake().call().await?;
dbg!(&stake);

// let nodes = stake_table_contract.nodes.call().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,11 +8,15 @@ mod header;
mod instance_state;
mod l1;
mod solver;
mod stake;
mod state;
mod transaction;

pub use auction::SolverAuctionResultsProvider;
pub use fee_info::{retain_accounts, FeeError};
pub use instance_state::{mock, NodeState};
pub use state::ProposalValidationError;
pub use state::{get_l1_deposits, BuilderValidationError, StateValidationError, ValidatedState};
pub use stake::StakeCommittee;
pub use state::{
get_l1_deposits, BuilderValidationError, ProposalValidationError, StateValidationError,
ValidatedState,
};
Loading
Loading