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 Permissioned Stake Table from L1 #2361

Open
wants to merge 65 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
65 commits
Select commit Hold shift + click to select a range
0e76651
Initial draft for minimal L1 stake table
sveitser Nov 25, 2024
0bb1514
Add Schnorr verifying key
sveitser Nov 25, 2024
0c4df9a
fix solhint error: named mapping keys and values
sveitser Nov 25, 2024
fdec50c
WIP: contract stake table types to rust types
sveitser Nov 27, 2024
4cfd276
rename: SimpleStakeTable -> PermissionedStakeTable
sveitser Nov 27, 2024
10d3d13
PermissionedStakeTable contract: add DA flag
sveitser Nov 27, 2024
beed539
Allow setting an initial stake table on deployment
sveitser Nov 27, 2024
c919dd1
deploy: load initial stake table from toml file
sveitser Nov 27, 2024
6b8d822
Use serde instead of unsafe rust
sveitser Nov 27, 2024
80dc00e
Update utils/src/deployer.rs
sveitser Dec 4, 2024
f1741e3
WIP: load initial stake table from file
sveitser Dec 4, 2024
99d7186
Merge remote-tracking branch 'origin/main' into ma/simple-stake-table
sveitser Dec 5, 2024
f926e84
Move solidity <-> jf code to contract adapter
sveitser Dec 5, 2024
0862ca7
Load initial stake table from file
sveitser Dec 5, 2024
1b2ccd5
remove unused imports
sveitser Dec 5, 2024
b2d5236
remove unused module
sveitser Dec 5, 2024
b642d06
dev-node: fix arguments to deploy function
sveitser Dec 5, 2024
2827cfa
fix clippy
sveitser Dec 5, 2024
0219c4a
Merge remote-tracking branch 'origin/main' into ma/simple-stake-table
sveitser Dec 5, 2024
e15c2b3
fix Cargo.toml for bindings generation
sveitser Dec 5, 2024
4982a2f
Merge remote-tracking branch 'origin/hotshot/0.5.82' into ma/simple-s…
tbro Dec 5, 2024
1120c7b
combine adding and removing into single event
sveitser Dec 6, 2024
927fef5
boilerplate
tbro Dec 5, 2024
271bd0e
add TODO
tbro Dec 5, 2024
27a8e7c
use `HashSet`
tbro Dec 5, 2024
4500763
some cleanup
tbro Dec 6, 2024
44cbe87
Avoid re-exporting v1 chain config
tbro Dec 6, 2024
b108074
add stake_table_address to v0_99 `ChainConfig`
tbro Dec 6, 2024
dbaca7c
export local `StaticCommittee`
tbro Dec 6, 2024
10cfe43
change instantiation order
tbro Dec 6, 2024
0adfa82
successfully deploy stake_table contract for test
tbro Dec 6, 2024
8533978
cleanup
tbro Dec 6, 2024
b1179bf
update comment to match implementation (#2282)
alysiahuggins Dec 6, 2024
53274f2
update query-service
imabdulbasit Dec 5, 2024
6f68c0b
db max connections = 25 for dev node tests
imabdulbasit Dec 5, 2024
3be3606
update query-service
imabdulbasit Dec 5, 2024
66d1590
Fix no-storage decides
QuentinI Dec 6, 2024
4a2cd03
Branches -> tags
QuentinI Dec 6, 2024
53810bd
2368 stake table registration with fixed stake (#2365)
alysiahuggins Dec 6, 2024
36b319e
update comment to match implementation (#2282)
alysiahuggins Dec 6, 2024
fb71704
update query-service
imabdulbasit Dec 5, 2024
b8fdaf8
db max connections = 25 for dev node tests
imabdulbasit Dec 5, 2024
ac54297
update query-service
imabdulbasit Dec 5, 2024
97ff37f
Fix no-storage decides
QuentinI Dec 6, 2024
266027a
Branches -> tags
QuentinI Dec 6, 2024
f68aed0
2368 stake table registration with fixed stake (#2365)
alysiahuggins Dec 6, 2024
624f5ca
add TODO
tbro Dec 6, 2024
a6afc75
fetch events from l1
tbro Dec 6, 2024
27bf006
Merge branch 'main' into ma/simple-stake-table
imabdulbasit Dec 9, 2024
94a07a4
fix env var for permissioned_stake_table
imabdulbasit Dec 9, 2024
a55cfd6
Add test for jf / contract types conversions
sveitser Dec 9, 2024
e19186a
cleanup: pass rng
sveitser Dec 9, 2024
ef90df4
remove generics from `Memberships` implementation
tbro Dec 9, 2024
ffe9c54
disambiguate Membership
tbro Dec 9, 2024
77ff146
load stake table from toml file (#2377)
imabdulbasit Dec 10, 2024
f1b2799
remove generic from stake table (#2383)
imabdulbasit Dec 10, 2024
59f1cb8
Merge branch 'ma/simple-stake-table' into tb/pos/fetch-stake-table2
sveitser Dec 10, 2024
1297b51
Add method to compute stake table from L1 events
sveitser Dec 10, 2024
683215d
Add test to update DA status of staker
sveitser Dec 10, 2024
2a22320
Merge remote-tracking branch 'origin/tb/pos/fetch-stake-table2' into …
tbro Dec 10, 2024
7d5e92d
fix up stake_table fetching
tbro Dec 10, 2024
4a58471
cleanup
tbro Dec 10, 2024
89bded5
Merge remote-tracking branch 'origin/main' into tb/pos/fetch-stake-ta…
tbro Dec 10, 2024
f5c4b87
fix merge resolution error
tbro Dec 10, 2024
9057464
fix lint error
tbro Dec 10, 2024
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 Cargo.lock

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

3 changes: 3 additions & 0 deletions contracts/rust/adapter/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ num-bigint = { version = "0.4", default-features = false }
num-traits = { version = "0.2", default-features = false }
serde = { workspace = true }

[dev-dependencies]
rand = { workspace = true }

[[bin]]
name = "eval-domain"
path = "src/bin/eval_domain.rs"
52 changes: 33 additions & 19 deletions contracts/rust/adapter/src/stake_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,21 @@ use ark_ec::{
use ark_ed_on_bn254::EdwardsConfig;
use ark_ff::{BigInteger, PrimeField};
use ark_serialize::{CanonicalDeserialize, CanonicalSerialize};
use ark_std::rand::{Rng, RngCore};
use contract_bindings::permissioned_stake_table::{self, EdOnBN254Point, NodeInfo};
use diff_test_bn254::ParsedG2Point;
use ethers::{
abi::AbiDecode,
prelude::{AbiError, EthAbiCodec, EthAbiType},
types::U256,
};
use hotshot_types::{light_client::StateVerKey, network::PeerConfigKeys, signature_key::BLSPubKey};
use hotshot_types::{
light_client::{StateKeyPair, StateVerKey},
network::PeerConfigKeys,
signature_key::BLSPubKey,
stake_table::StakeTableEntry,
traits::signature_key::SignatureKey as _,
};
use serde::{Deserialize, Serialize};
use std::str::FromStr;

Expand Down Expand Up @@ -113,6 +120,21 @@ pub struct NodeInfoJf {
pub da: bool,
}

impl NodeInfoJf {
pub fn random(rng: &mut impl RngCore) -> Self {
let mut seed = [0u8; 32];
rng.fill_bytes(&mut seed);

let (stake_table_key, _) = BLSPubKey::generated_from_seed_indexed(seed, 0);
let state_key_pair = StateKeyPair::generate_from_seed_indexed(seed, 0);
Self {
stake_table_key,
state_ver_key: state_key_pair.ver_key(),
da: rng.gen(),
}
}
}

impl From<NodeInfoJf> for NodeInfo {
fn from(value: NodeInfoJf) -> Self {
let NodeInfoJf {
Expand All @@ -135,6 +157,15 @@ impl From<NodeInfoJf> for NodeInfo {
}
}

impl From<NodeInfoJf> for StakeTableEntry<BLSPubKey> {
fn from(value: NodeInfoJf) -> Self {
StakeTableEntry {
stake_key: value.stake_table_key,
stake_amount: U256::from(1), // dummy stake amount
}
}
}

impl From<NodeInfo> for NodeInfoJf {
fn from(value: NodeInfo) -> Self {
let NodeInfo {
Expand Down Expand Up @@ -193,27 +224,10 @@ impl From<PeerConfigKeys<BLSPubKey>> for NodeInfoJf {
#[cfg(test)]
mod test {
use super::*;
use ark_std::rand::{Rng, RngCore};
use hotshot_types::{light_client::StateKeyPair, traits::signature_key::BuilderSignatureKey};

impl NodeInfoJf {
fn random(rng: &mut impl RngCore) -> Self {
let mut seed = [0u8; 32];
rng.fill_bytes(&mut seed);

let (stake_table_key, _) = BLSPubKey::generated_from_seed_indexed(seed, 0);
let state_key_pair = StateKeyPair::generate_from_seed_indexed(seed, 0);
Self {
stake_table_key,
state_ver_key: state_key_pair.ver_key(),
da: rng.gen(),
}
}
}

#[test]
fn test_node_info_round_trip() {
let mut rng = ark_std::rand::thread_rng();
let mut rng = rand::thread_rng();
for _ in 0..20 {
let jf = NodeInfoJf::random(&mut rng);
let sol: NodeInfo = jf.clone().into();
Expand Down
Binary file modified data/v99/chain_config.bin
Binary file not shown.
3 changes: 2 additions & 1 deletion data/v99/chain_config.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@
"chain_id": "35353",
"fee_contract": "0x0000000000000000000000000000000000000000",
"fee_recipient": "0x0000000000000000000000000000000000000000",
"max_block_size": "10240"
"max_block_size": "10240",
"stake_table_contract": "0x0000000000000000000000000000000000000000"
}
Binary file modified data/v99/header.bin
Binary file not shown.
3 changes: 2 additions & 1 deletion data/v99/header.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
"chain_id": "35353",
"fee_contract": "0x0000000000000000000000000000000000000000",
"fee_recipient": "0x0000000000000000000000000000000000000000",
"max_block_size": "10240"
"max_block_size": "10240",
"stake_table_contract": "0x0000000000000000000000000000000000000000"
}
}
},
Expand Down
17 changes: 7 additions & 10 deletions sequencer/src/api.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
use std::pin::Pin;

use anyhow::{bail, Context};
use async_lock::RwLock;
use async_once_cell::Lazy;
Expand All @@ -9,8 +7,8 @@ use data_source::{CatchupDataSource, StakeTableDataSource, SubmitDataSource};
use derivative::Derivative;
use espresso_types::{
retain_accounts, v0::traits::SequencerPersistence, v0_99::ChainConfig, AccountQueryData,
BlockMerkleTree, FeeAccount, FeeAccountProof, FeeMerkleTree, NodeState, PubKey, Transaction,
ValidatedState,
BlockMerkleTree, FeeAccount, FeeAccountProof, FeeMerkleTree, NodeState, PubKey,
StaticCommittee, Transaction, ValidatedState,
};
use futures::{
future::{BoxFuture, Future, FutureExt},
Expand All @@ -34,6 +32,7 @@ use hotshot_types::{
};
use hotshot_types::{stake_table::StakeTableEntry, traits::election::Membership};
use jf_merkle_tree::MerkleTreeScheme;
use std::pin::Pin;
use std::sync::Arc;

use self::data_source::{
Expand Down Expand Up @@ -188,12 +187,10 @@ impl<N: ConnectedNetwork<PubKey>, V: Versions, P: SequencerPersistence>
self.consensus().await.read().await.cur_epoch().await
};

self.consensus()
.await
.read()
.await
.memberships
.stake_table(epoch)
<StaticCommittee as Membership<SeqTypes>>::stake_table(
&self.consensus().await.read().await.memberships,
epoch,
)
}
}

Expand Down
13 changes: 5 additions & 8 deletions sequencer/src/context.rs
Original file line number Diff line number Diff line change
@@ -1,25 +1,19 @@
use std::{fmt::Display, sync::Arc};

use anyhow::Context;
use async_lock::RwLock;
use derivative::Derivative;
use espresso_types::{
v0::traits::{EventConsumer as PersistenceEventConsumer, SequencerPersistence},
NodeState, PubKey, Transaction, ValidatedState,
NodeState, PubKey, StaticCommittee, Transaction, ValidatedState,
};
use futures::{
future::{join_all, Future},
stream::{Stream, StreamExt},
};
use hotshot::{
traits::election::static_committee::StaticCommittee,
types::{Event, EventType, SystemContextHandle},
MarketplaceConfig, SystemContext,
};
use hotshot_events_service::events_source::{EventConsumer, EventsStreamer};
use parking_lot::Mutex;
use tokio::{spawn, task::JoinHandle};

use hotshot_orchestrator::client::OrchestratorClient;
use hotshot_types::{
consensus::ConsensusMetricsValue,
Expand All @@ -32,7 +26,10 @@ use hotshot_types::{
},
PeerConfig, ValidatorConfig,
};
use parking_lot::Mutex;
use std::fmt::Debug;
use std::{fmt::Display, sync::Arc};
use tokio::{spawn, task::JoinHandle};
use tracing::{Instrument, Level};
use url::Url;

Expand Down Expand Up @@ -83,7 +80,7 @@ impl<N: ConnectedNetwork<PubKey>, P: SequencerPersistence, V: Versions> Sequence
pub async fn init(
network_config: NetworkConfig<PubKey>,
validator_config: ValidatorConfig<<SeqTypes as NodeType>::SignatureKey>,
membership: StaticCommittee<SeqTypes>,
membership: StaticCommittee,
instance_state: NodeState,
persistence: P,
network: Arc<N>,
Expand Down
4 changes: 3 additions & 1 deletion sequencer/src/genesis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,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: Some(Address::default())
}
);
assert_eq!(
Expand Down Expand Up @@ -489,6 +490,7 @@ mod test {
fee_recipient: FeeAccount::default(),
bid_recipient: None,
fee_contract: None,
stake_table_contract: None,
}
);
assert_eq!(
Expand Down
105 changes: 54 additions & 51 deletions sequencer/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ mod message_compat_tests;
use anyhow::Context;
use catchup::StatePeers;
use context::SequencerContext;
use espresso_types::StaticCommittee;
use espresso_types::{
traits::EventConsumer, BackoffParams, L1ClientOptions, NodeState, PubKey, SeqTypes,
SolverAuctionResultsProvider, ValidatedState,
};
use genesis::L1Finalized;
use hotshot::traits::election::static_committee::StaticCommittee;
use hotshot_types::traits::election::Membership;
use proposal_fetcher::ProposalFetcherConfig;
use std::sync::Arc;
Expand Down Expand Up @@ -391,12 +391,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 @@ -439,6 +433,59 @@ pub async fn init_node<P: SequencerPersistence, V: Versions>(
response_size_maximum: network_params.libp2p_max_direct_transmit_size,
};

let l1_client = l1_params
.options
.with_metrics(metrics)
.connect(l1_params.url)
.await?;
l1_client.spawn_tasks().await;
let l1_genesis = match genesis.l1_finalized {
L1Finalized::Block(b) => b,
L1Finalized::Number { number } => l1_client.wait_for_finalized_block(number).await,
L1Finalized::Timestamp { timestamp } => {
l1_client
.wait_for_finalized_block_with_timestamp(timestamp.unix_timestamp().into())
.await
}
};

let mut genesis_state = ValidatedState {
chain_config: genesis.chain_config.into(),
..Default::default()
};
for (address, amount) in genesis.accounts {
tracing::info!(%address, %amount, "Prefunding account for demo");
genesis_state.prefund_account(address, amount);
}

let instance_state = NodeState {
chain_config: genesis.chain_config,
l1_client,
genesis_header: genesis.header,
genesis_state,
l1_genesis: Some(l1_genesis),
peers: catchup::local_and_remote(
persistence.clone(),
StatePeers::<SequencerApiVersion>::from_urls(
network_params.state_peers,
network_params.catchup_backoff,
metrics,
),
)
.await,
node_id: node_index,
upgrades: genesis.upgrades,
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,
Default::default(),
);

// Initialize the Libp2p network
let network = {
let p2p_network = Libp2pNetwork::from_config(
Expand Down Expand Up @@ -479,50 +526,6 @@ pub async fn init_node<P: SequencerPersistence, V: Versions>(
))
};

let mut genesis_state = ValidatedState {
chain_config: genesis.chain_config.into(),
..Default::default()
};
for (address, amount) in genesis.accounts {
tracing::info!(%address, %amount, "Prefunding account for demo");
genesis_state.prefund_account(address, amount);
}

let l1_client = l1_params
.options
.with_metrics(metrics)
.connect(l1_params.url)
.await?;
l1_client.spawn_tasks().await;
let l1_genesis = match genesis.l1_finalized {
L1Finalized::Block(b) => b,
L1Finalized::Number { number } => l1_client.wait_for_finalized_block(number).await,
L1Finalized::Timestamp { timestamp } => {
l1_client
.wait_for_finalized_block_with_timestamp(timestamp.unix_timestamp().into())
.await
}
};
let instance_state = NodeState {
chain_config: genesis.chain_config,
l1_client,
genesis_header: genesis.header,
genesis_state,
l1_genesis: Some(l1_genesis),
peers: catchup::local_and_remote(
persistence.clone(),
StatePeers::<SequencerApiVersion>::from_urls(
network_params.state_peers,
network_params.catchup_backoff,
metrics,
),
)
.await,
node_id: node_index,
upgrades: genesis.upgrades,
current_version: V::Base::VERSION,
};

let mut ctx = SequencerContext::init(
network_config,
validator_config,
Expand Down
3 changes: 1 addition & 2 deletions sequencer/src/message_compat_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ use std::path::Path;

use committable::Committable;
use espresso_types::{NodeState, PubKey, ValidatedState};
use hotshot::traits::election::static_committee::StaticCommittee;
use hotshot_types::{
data::{
DaProposal, EpochNumber, QuorumProposal, UpgradeProposal, VidDisperse, VidDisperseShare,
Expand Down Expand Up @@ -53,7 +52,7 @@ use vbs::{

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

Expand Down
Loading
Loading