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 Memberships from l1 #2390

Merged
merged 72 commits into from
Jan 8, 2025
Merged
Show file tree
Hide file tree
Changes from 37 commits
Commits
Show all changes
72 commits
Select commit Hold shift + click to select a range
17b4c26
attempt to update stake tables
imabdulbasit Dec 11, 2024
d6304c1
cleanup and make epoch as key
imabdulbasit Dec 11, 2024
816f819
initialize the btree maps
tbro Dec 11, 2024
7f2eec7
remove prev_block_epoch
imabdulbasit Dec 12, 2024
6320f3f
wrap committee state in Arc<RwLock<>>
imabdulbasit Dec 12, 2024
6acf598
cargo sort
imabdulbasit Dec 12, 2024
2d04292
add stake back in l1_client
tbro Dec 12, 2024
5788626
Move `StaticCommittee` state into its own type.
tbro Dec 12, 2024
d74eb67
remove NewEpoch event
imabdulbasit Dec 13, 2024
56f3f73
permissioned_stake_table_contract as env var
imabdulbasit Dec 13, 2024
f3fa640
get contract addr from chain config
imabdulbasit Dec 13, 2024
012368d
make state as Arc<RwLock<HashMap<Epoch, StaticCommittee>>>
imabdulbasit Dec 13, 2024
1e88da2
fix imports for MembershipCommittee
imabdulbasit Dec 13, 2024
1fcbd92
cleanup
imabdulbasit Dec 13, 2024
50bfe89
move write lock
imabdulbasit Dec 13, 2024
d585efa
rename quorum to stake_table and da to da_stake_tables
imabdulbasit Dec 13, 2024
2694371
rename MembershipCommittees to EpochCommittees
imabdulbasit Dec 13, 2024
a14d2b4
remove some TODOs
tbro Dec 13, 2024
351bc27
da stakle table -> da members
imabdulbasit Dec 13, 2024
70b758d
fix test_fetch_stake_table: await for tx finalization
imabdulbasit Dec 13, 2024
ce740c8
pass in epoch to update fn
imabdulbasit Dec 13, 2024
1c314ba
hashmap to btreemap for indexed stake table
imabdulbasit Dec 13, 2024
f5f7f02
fix test_genesis_from_toml_with_optional_fields
imabdulbasit Dec 13, 2024
e178037
fix comment
tbro Dec 13, 2024
d9175b7
Small cleanup on trait methods
tbro Dec 13, 2024
79c1617
Return `Committee from updater
tbro Dec 13, 2024
475087a
fix
tbro Dec 13, 2024
c6b1b8c
rename `DAStakeTable` to `DaMembers`
tbro Dec 13, 2024
f4da7fd
workaround: insert stake table for epoch 1
sveitser Dec 16, 2024
6482b18
kill test that may hang
sveitser Dec 16, 2024
5c32108
Use sync locks for stake table state (#2404)
sveitser Dec 16, 2024
28dffec
rename DAMembers
tbro Dec 16, 2024
5685090
log when epochs aren't progressing
tbro Dec 16, 2024
0d68518
return empty `StakeTables` when l1 cache is unavailable
tbro Dec 16, 2024
cc3197d
we only need to distinguish betwen `RwLock`s
tbro Dec 16, 2024
a180214
Add `epoch_height` to `NodeState`
tbro Dec 16, 2024
161121e
fix light client proxy address for demos
imabdulbasit Dec 17, 2024
e8abebd
increase MAX_TXNS_NOT_INCREMENTING to 5
imabdulbasit Dec 17, 2024
4fa1984
patch hotshot
tbro Dec 17, 2024
70dbaf0
cargo lock
tbro Dec 17, 2024
a04ace9
add epoch upgrade type
imabdulbasit Dec 18, 2024
9f1d9ed
Revert "patch hotshot"
tbro Dec 18, 2024
53131fb
WIP: hotshot 0.5.83
sveitser Dec 19, 2024
721698a
Update hotshot-query-service
sveitser Dec 19, 2024
87e146b
fix double space
sveitser Dec 19, 2024
1e2fd09
Builder changes
QuentinI Dec 19, 2024
60f1427
cargo: remove patch
sveitser Dec 19, 2024
88aca4f
add `--keep-going` to lint
tbro Dec 19, 2024
6bf3060
Pull in updates from hotshot
tbro Dec 19, 2024
1c47fda
fix compile errors for the `Memberships` trait update
tbro Dec 19, 2024
9d0bf9c
Add rust binary to update permissioned stake table (#2410)
sveitser Dec 20, 2024
0fa1f3f
store next epoch qc
imabdulbasit Dec 20, 2024
5da92ff
Merge branch 'ma/hotshot-0.5.83' into ab/store-next-epoch-qc
imabdulbasit Dec 20, 2024
b9338c2
update query service
imabdulbasit Dec 20, 2024
688aedc
Update hotshot-* dependencies
sveitser Dec 20, 2024
9385491
Fix rust compilation
sveitser Dec 20, 2024
bd74fe5
store next epoch qc in persistence (#2422)
imabdulbasit Dec 20, 2024
6a6be1a
Merge branch 'ab/st' into ma/hotshot-0.5.83
imabdulbasit Dec 20, 2024
4eaf8f6
cargo fmt
sveitser Dec 20, 2024
59b61df
Cargo update and fix
tbro Jan 6, 2025
bfb3d08
drb compile errors
tbro Jan 6, 2025
87e80a6
Preliminary `add_epoch_root` implementation
tbro Jan 6, 2025
e3fba83
cleanup add_epoch_root
tbro Jan 6, 2025
efbedaf
add stake table contract address to EpochCommittee
tbro Jan 7, 2025
e6c1ccf
update sqlite dependencies
tbro Jan 7, 2025
0264600
update hotshot
tbro Jan 7, 2025
ed6c822
remove storage2 methods
tbro Jan 7, 2025
71046bc
update sequencer-sqlite deps
tbro Jan 7, 2025
f9c8799
upstream query-service fix
tbro Jan 8, 2025
dc5069b
update hotshot
tbro Jan 8, 2025
5cfa92d
fix message compat tests
imabdulbasit Jan 8, 2025
2f56726
WIP: hotshot 0.5.83 (#2417)
imabdulbasit Jan 8, 2025
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
11 changes: 7 additions & 4 deletions .config/nextest.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,13 @@ default-filter = 'not (test(slow_) | package(tests))'
retries = 2

[[profile.default.overrides]]
# This test is fast if it works (usually about 150ms) but sometimes hangs,
# especially when running concurrently with other tests. Kill it after a while
# and retry up to 10 times.
filter = 'test(test_process_client_handling_stream_subscribe_node_identity)'
# These tests are fast if they work (usually about 150ms) but sometimes they
# hang, especially when running Concurrently with other tests. Kill after a
# while and retry up to 10 times to avoid failing the test suite.
filter = """
test(test_process_client_handling_stream_subscribe_node_identity) |
test(test_process_client_handling_stream_subscribe_voters)
"""
slow-timeout = { period = "2s", terminate-after = 1 }
retries = 10

Expand Down
4 changes: 2 additions & 2 deletions .env
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,10 @@ ESPRESSO_BUILDER_ETH_ACCOUNT_INDEX=8
ESPRESSO_DEPLOYER_ACCOUNT_INDEX=9

# Contracts
ESPRESSO_SEQUENCER_LIGHT_CLIENT_PROXY_ADDRESS=0xf7cd8fa9b94db2aa972023b379c7f72c65e4de9d
ESPRESSO_SEQUENCER_LIGHT_CLIENT_PROXY_ADDRESS=0xed1db453c3156ff3155a97ad217b3087d5dc5f6e
tbro marked this conversation as resolved.
Show resolved Hide resolved
ESPRESSO_SEQUENCER_LIGHTCLIENT_ADDRESS=$ESPRESSO_SEQUENCER_LIGHT_CLIENT_PROXY_ADDRESS
ESPRESSO_SEQUENCER_PERMISSIONED_PROVER=0x14dc79964da2c08b23698b3d3cc7ca32193d9955
SPRESSO_SEQUENCER_PERMISSIONED_STAKE_TABLE_ADDRESS=0x8ce361602b935680e8dec218b820ff5056beb7af
ESPRESSO_SEQUENCER_PERMISSIONED_STAKE_TABLE_ADDRESS=0x8ce361602b935680e8dec218b820ff5056beb7af

# Example sequencer demo private keys
ESPRESSO_DEMO_SEQUENCER_STAKING_PRIVATE_KEY_0=BLS_SIGNING_KEY~lNDh4Pn-pTAyzyprOAFdXHwhrKhEwqwtMtkD3CZF4x3o
Expand Down
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.

1 change: 1 addition & 0 deletions sequencer-sqlite/Cargo.lock

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

2 changes: 1 addition & 1 deletion sequencer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ async-lock = { workspace = true }
async-once-cell = { workspace = true }
async-trait = { workspace = true }
bincode = { workspace = true }
todo_by = "0.3"

# CDN imports
cdn-broker = { workspace = true }
Expand Down Expand Up @@ -117,6 +116,7 @@ tagged-base64 = { workspace = true }
tempfile = { workspace = true, optional = true }
tide-disco = { workspace = true }
time = { workspace = true }
todo_by = "0.3"
tokio = { workspace = true }
toml = { workspace = true }
tracing = { workspace = true }
Expand Down
6 changes: 3 additions & 3 deletions sequencer/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,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,
StaticCommittee, Transaction, ValidatedState,
BlockMerkleTree, FeeAccount, FeeAccountProof, FeeMerkleTree, NodeState, PubKey, Transaction,
ValidatedState,
};
use futures::{
future::{BoxFuture, Future, FutureExt},
Expand Down Expand Up @@ -187,7 +187,7 @@ impl<N: ConnectedNetwork<PubKey>, V: Versions, P: SequencerPersistence>
self.consensus().await.read().await.cur_epoch().await
};

<StaticCommittee as Membership<SeqTypes>>::stake_table(
<SeqTypes as NodeType>::Membership::stake_table(
&self.consensus().await.read().await.memberships,
epoch,
)
Expand Down
4 changes: 2 additions & 2 deletions sequencer/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use async_lock::RwLock;
use derivative::Derivative;
use espresso_types::{
v0::traits::{EventConsumer as PersistenceEventConsumer, SequencerPersistence},
NodeState, PubKey, StaticCommittee, Transaction, ValidatedState,
EpochCommittees, NodeState, PubKey, Transaction, ValidatedState,
};
use futures::{
future::{join_all, Future},
Expand Down Expand Up @@ -80,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,
membership: EpochCommittees,
instance_state: NodeState,
persistence: P,
network: Arc<N>,
Expand Down
2 changes: 1 addition & 1 deletion sequencer/src/genesis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,7 @@ mod test {
fee_recipient: FeeAccount::default(),
fee_contract: Some(Address::default()),
bid_recipient: None,
stake_table_contract: Some(Address::default())
stake_table_contract: None
}
);
assert_eq!(
Expand Down
13 changes: 8 additions & 5 deletions sequencer/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,12 @@ mod message_compat_tests;
use anyhow::Context;
use catchup::StatePeers;
use context::SequencerContext;
use espresso_types::StaticCommittee;
use espresso_types::EpochCommittees;
use espresso_types::{
traits::EventConsumer, BackoffParams, L1ClientOptions, NodeState, PubKey, SeqTypes,
SolverAuctionResultsProvider, ValidatedState,
};
use genesis::L1Finalized;
use hotshot_types::traits::election::Membership;
use proposal_fetcher::ProposalFetcherConfig;
use std::sync::Arc;
use tokio::select;
Expand Down Expand Up @@ -476,14 +475,15 @@ pub async fn init_node<P: SequencerPersistence, V: Versions>(
node_id: node_index,
upgrades: genesis.upgrades,
current_version: V::Base::VERSION,
epoch_height: None,
};

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

// Initialize the Libp2p network
Expand Down Expand Up @@ -960,12 +960,15 @@ pub mod testing {
)
.with_current_version(V::Base::version())
.with_genesis(state)
.with_epoch_height(config.epoch_height)
.with_upgrades(upgrades);

// Create the HotShot membership
let membership = StaticCommittee::new(
let membership = EpochCommittees::new_stake(
config.known_nodes_with_stake.clone(),
config.known_nodes_with_stake.clone(),
&node_state,
100,
);

tracing::info!(
Expand Down
8 changes: 4 additions & 4 deletions sequencer/src/message_compat_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@ use hotshot_types::{
ViewSyncFinalizeVote, ViewSyncPreCommitData, ViewSyncPreCommitVote,
},
traits::{
election::Membership, node_implementation::ConsensusTime, signature_key::SignatureKey,
BlockPayload, EncodeBytes,
node_implementation::ConsensusTime, signature_key::SignatureKey, BlockPayload, EncodeBytes,
},
vid::vid_scheme,
};
Expand All @@ -52,14 +51,15 @@ use vbs::{

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

let (sender, priv_key) = PubKey::generated_from_seed_indexed(Default::default(), 0);
let signature = PubKey::sign(&priv_key, &[]).unwrap();
let committee = vec![PeerConfig::default()]; /* one committee member, necessary to generate a VID share */
let membership = StaticCommittee::new(committee.clone(), committee);
let membership =
EpochCommittees::new_stake(committee.clone(), committee, &NodeState::default(), 10);
let upgrade_data = UpgradeProposalData {
old_version: Version { major: 0, minor: 1 },
new_version: Version { major: 1, minor: 0 },
Expand Down
1 change: 1 addition & 0 deletions types/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ testing = []
anyhow = { workspace = true }
ark-serialize = { workspace = true }
async-broadcast = { workspace = true }
async-lock = { workspace = true }
async-trait = { workspace = true }
base64-bytes = { workspace = true }
bincode = { workspace = true }
Expand Down
9 changes: 9 additions & 0 deletions types/src/v0/impls/instance_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ pub struct NodeState {
pub genesis_header: GenesisHeader,
pub genesis_state: ValidatedState,
pub l1_genesis: Option<L1BlockInfo>,
pub epoch_height: Option<u64>,

/// Map containing all planned and executed upgrades.
///
Expand Down Expand Up @@ -64,6 +65,7 @@ impl NodeState {
l1_genesis: None,
upgrades: Default::default(),
current_version,
epoch_height: None,
}
}

Expand Down Expand Up @@ -130,6 +132,13 @@ impl NodeState {
self.current_version = ver;
self
}

// TODO remove following `Memberships` trait update:
// https://github.com/EspressoSystems/HotShot/issues/3966
pub fn with_epoch_height(mut self, epoch_height: u64) -> Self {
self.epoch_height = Some(epoch_height);
self
}
}

// This allows us to turn on `Default` on InstanceState trait
Expand Down
78 changes: 63 additions & 15 deletions types/src/v0/impls/l1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,15 @@ use futures::{
future::Future,
stream::{self, StreamExt},
};
use hotshot_types::traits::metrics::Metrics;
use hotshot_types::{data::EpochNumber, traits::metrics::Metrics};
use lru::LruCache;
use serde::{de::DeserializeOwned, Serialize};
use std::{
cmp::{min, Ordering},
collections::BTreeMap,
fmt::Debug,
num::NonZeroUsize,
sync::Arc,
sync::{self, Arc},
time::Duration,
};
use tokio::{
Expand All @@ -33,8 +34,7 @@ use url::Url;

use super::{L1BlockInfo, L1ClientMetrics, L1State, L1UpdateTask, RpcClient};
use crate::{
v0::impls::stake_table::StakeTables, FeeInfo, L1Client, L1ClientOptions, L1Event,
L1ReconnectTask, L1Snapshot,
v0_3::StakeTables, FeeInfo, L1Client, L1ClientOptions, L1Event, L1ReconnectTask, L1Snapshot,
};

impl PartialOrd for L1BlockInfo {
Expand Down Expand Up @@ -344,6 +344,7 @@ impl L1Client {
provider: Arc::new(provider),
events_max_block_range: opt.l1_events_max_block_range,
state: Arc::new(Mutex::new(L1State::new(opt.l1_blocks_cache_size))),
stake_table_state: Arc::new(sync::RwLock::new(BTreeMap::new())),
sender,
receiver: receiver.deactivate(),
update_task: Default::default(),
Expand Down Expand Up @@ -376,6 +377,39 @@ impl L1Client {
*update_task = Some(spawn(self.update_loop()));
}
}
pub async fn update_membership(
&self,
contract: Address,
l1_block_number: u64,
epoch: EpochNumber,
) {
let retry_delay = self.retry_delay;
let state = self.stake_table_state.clone();

let span = tracing::warn_span!("L1 client memberships update");

async move {
loop {
match self.get_stake_table(contract, l1_block_number).await {
Err(err) => {
tracing::warn!(
?epoch,
?l1_block_number,
"error fetching stake table from l1. err {err}"
);
}
Ok(stake_tables) => {
let mut state = state.write().unwrap();
let _ = state.insert(epoch, stake_tables);
}
}

sleep(retry_delay).await;
}
}
.instrument(span)
.await
}

/// Shut down background tasks associated with this L1 client.
///
Expand Down Expand Up @@ -530,6 +564,16 @@ impl L1Client {
self.state.lock().await.snapshot
}

// TODO remove after `Memberships` trait update on hotshot
// https://github.com/EspressoSystems/HotShot/issues/3966
pub fn stake_table(&self, epoch: &EpochNumber) -> StakeTables {
tbro marked this conversation as resolved.
Show resolved Hide resolved
if let Some(stake_tables) = self.stake_table_state.read().unwrap().get(epoch) {
stake_tables.clone()
} else {
StakeTables::new(vec![].into(), vec![].into())
}
}

/// Wait until the highest L1 block number reaches at least `number`.
///
/// This function does not return any information about the block, since the block is not
Expand Down Expand Up @@ -785,20 +829,23 @@ impl L1Client {
}

/// Get `StakeTable` at block height.
pub async fn get_stake_table(&self, block: u64, address: Address) -> StakeTables {
// TODO epoch size may need to be passed in as well
// TODO here or in memberships check if we have fetched table this epoch
let stake_table_contract = PermissionedStakeTable::new(address, self.provider.clone());
pub async fn get_stake_table(
&self,
contract: Address,
block: u64,
) -> anyhow::Result<StakeTables> {
// TODO stake_table_address needs to be passed in to L1Client
// before update loop starts.
let stake_table_contract = PermissionedStakeTable::new(contract, self.provider.clone());

let events = stake_table_contract
.stakers_updated_filter()
.from_block(0)
.to_block(block)
.query()
.await
.unwrap();
.await?;

StakeTables::from_l1_events(events.clone())
Ok(StakeTables::from_l1_events(events.clone()))
}
}

Expand Down Expand Up @@ -1301,14 +1348,15 @@ mod test {

let new_nodes: Vec<NodeInfo> = vec![node.into()];
let updater = stake_table_contract.update(v, new_nodes);
updater.send().await?;
updater.send().await?.await?;

let block = client.get_block(BlockNumber::Latest).await?.unwrap();
let nodes = l1_client
.get_stake_table(block.number.unwrap().as_u64(), address)
.await;
.get_stake_table(address, block.number.unwrap().as_u64())
.await
.unwrap();

let result = nodes.consensus_stake_table.0[0].clone();
let result = nodes.stake_table.0[0].clone();
assert_eq!(result.stake_amount.as_u64(), 1);
Ok(())
}
Expand Down
2 changes: 1 addition & 1 deletion types/src/v0/impls/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ mod transaction;
pub use auction::SolverAuctionResultsProvider;
pub use fee_info::{retain_accounts, FeeError};
pub use instance_state::NodeState;
pub use stake_table::StaticCommittee;
pub use stake_table::*;
pub use state::{
get_l1_deposits, BuilderValidationError, ProposalValidationError, StateValidationError,
ValidatedState,
Expand Down
Loading
Loading