Skip to content

Commit

Permalink
fix compile errors for the Memberships trait update
Browse files Browse the repository at this point in the history
  • Loading branch information
tbro committed Dec 19, 2024
1 parent 6bf3060 commit 1c47fda
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 25 deletions.
13 changes: 9 additions & 4 deletions sequencer/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,10 +186,15 @@ impl<N: ConnectedNetwork<PubKey>, V: Versions, P: SequencerPersistence>
} else {
self.consensus().await.read().await.cur_epoch().await
};
<SeqTypes as NodeType>::Membership::stake_table(
&self.consensus().await.read().await.memberships,
epoch,
)

self.consensus()
.await
.read()
.await
.memberships
.read()
.await
.stake_table(epoch)
}
}

Expand Down
2 changes: 1 addition & 1 deletion sequencer/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ impl<N: ConnectedNetwork<PubKey>, 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),
Expand Down
2 changes: 1 addition & 1 deletion sequencer/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,7 @@ pub async fn init_node<P: SequencerPersistence, V: Versions>(
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,
Expand Down
24 changes: 5 additions & 19 deletions types/src/v0/impls/stake_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -310,27 +310,19 @@ impl Membership<SeqTypes> 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<StakeTableEntry<PubKey>> {
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
fn da_stake_table(&self, epoch: Epoch) -> Vec<StakeTableEntry<PubKey>> {
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![]
}
}

Expand All @@ -343,10 +335,7 @@ impl Membership<SeqTypes> 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()
}
}

Expand All @@ -359,10 +348,7 @@ impl Membership<SeqTypes> 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()
}
}

Expand Down

0 comments on commit 1c47fda

Please sign in to comment.