From 1c47fda8fe1d25698476066fdf74bad3153f88f0 Mon Sep 17 00:00:00 2001 From: tbro Date: Thu, 19 Dec 2024 18:17:38 -0300 Subject: [PATCH] fix compile errors for the `Memberships` trait update --- sequencer/src/api.rs | 13 +++++++++---- sequencer/src/context.rs | 2 +- sequencer/src/lib.rs | 2 +- types/src/v0/impls/stake_table.rs | 24 +++++------------------- 4 files changed, 16 insertions(+), 25 deletions(-) diff --git a/sequencer/src/api.rs b/sequencer/src/api.rs index bcc3a7a9c..586623269 100644 --- a/sequencer/src/api.rs +++ b/sequencer/src/api.rs @@ -186,10 +186,15 @@ impl, V: Versions, P: SequencerPersistence> } else { self.consensus().await.read().await.cur_epoch().await }; - ::Membership::stake_table( - &self.consensus().await.read().await.memberships, - epoch, - ) + + self.consensus() + .await + .read() + .await + .memberships + .read() + .await + .stake_table(epoch) } } diff --git a/sequencer/src/context.rs b/sequencer/src/context.rs index 1149f4ba4..b56c0b6eb 100644 --- a/sequencer/src/context.rs +++ b/sequencer/src/context.rs @@ -130,7 +130,7 @@ impl, P: SequencerPersistence, V: Versions> Sequence validator_config.private_key.clone(), instance_state.node_id, config.clone(), - membership, + Arc::new(async_lock::RwLock::new(membership)), network.clone(), initializer, ConsensusMetricsValue::new(metrics), diff --git a/sequencer/src/lib.rs b/sequencer/src/lib.rs index 07359392b..e3f7141b8 100644 --- a/sequencer/src/lib.rs +++ b/sequencer/src/lib.rs @@ -490,7 +490,7 @@ pub async fn init_node( let network = { let p2p_network = Libp2pNetwork::from_config( network_config.clone(), - Arc::new(RwLock::new(membership.clone())), + Arc::new(async_lock::RwLock::new(membership.clone())), gossip_config, request_response_config, libp2p_bind_address, diff --git a/types/src/v0/impls/stake_table.rs b/types/src/v0/impls/stake_table.rs index 9c36a20e6..31d456534 100644 --- a/types/src/v0/impls/stake_table.rs +++ b/types/src/v0/impls/stake_table.rs @@ -148,7 +148,7 @@ impl EpochCommittees { /// 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. - fn update_stake_table(&self, epoch: EpochNumber, st: StakeTables) -> Committee { + fn update_stake_table(&mut self, epoch: EpochNumber, st: StakeTables) -> Committee { // This works because `get_stake_table` is fetching *all* // update events and building the table for us. We will need // more subtlety when start fetching only the events since last update. @@ -310,16 +310,11 @@ impl Membership for EpochCommittees { } /// Get the stake table for the current view - // TODO awaiting addition of `add_epoch_root` to Memberships trait - // which we need to avoid `&mut self`. fn stake_table(&self, epoch: Epoch) -> Vec> { if let Some(st) = self.state.get(&epoch) { st.indexed_stake_table.clone().into_values().collect() } else { - self.update_stake_table(epoch, self.l1_client.stake_table(&epoch)) - .indexed_stake_table - .into_values() - .collect() + vec![] } } /// Get the stake table for the current view @@ -327,10 +322,7 @@ impl Membership for EpochCommittees { if let Some(sc) = self.state.get(&epoch) { sc.indexed_da_members.clone().into_values().collect() } else { - self.update_stake_table(epoch, self.l1_client.stake_table(&epoch)) - .indexed_da_members - .into_values() - .collect() + vec![] } } @@ -343,10 +335,7 @@ impl Membership for EpochCommittees { if let Some(sc) = self.state.get(&epoch) { sc.indexed_stake_table.clone().into_keys().collect() } else { - self.update_stake_table(epoch, self.l1_client.stake_table(&epoch)) - .indexed_stake_table - .into_keys() - .collect() + BTreeSet::new() } } @@ -359,10 +348,7 @@ impl Membership for EpochCommittees { if let Some(sc) = self.state.get(&epoch) { sc.indexed_da_members.clone().into_keys().collect() } else { - self.update_stake_table(epoch, self.l1_client.stake_table(&epoch)) - .indexed_da_members - .into_keys() - .collect() + BTreeSet::new() } }