Skip to content

Commit

Permalink
staking: promote get_consensus_set to ConsensusIndexRead
Browse files Browse the repository at this point in the history
  • Loading branch information
cratelyn committed Mar 18, 2024
1 parent 9f569c4 commit 733b9a1
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 12 deletions.
17 changes: 5 additions & 12 deletions crates/core/app/tests/mock_consensus_staking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,18 +89,11 @@ async fn mock_consensus_can_delegate_to_a_validator() -> anyhow::Result<()> {
assert_eq!(end, Some(State::Active));
}

async fn get_consensus_set(
snapshot: &cnidarium::Snapshot,
) -> anyhow::Result<Vec<penumbra_stake::IdentityKey>> {
use futures::TryStreamExt;
use penumbra_stake::component::ConsensusIndexRead;
snapshot.consensus_set_stream()?.try_collect().await
}

// Show that the validator was, and still is, in the consensus set.
{
let start = get_consensus_set(&snapshot_start).await?;
let end = get_consensus_set(&snapshot_end).await?;
use penumbra_stake::component::ConsensusIndexRead;
let start = snapshot_start.get_consensus_set().await?;
let end = snapshot_end.get_consensus_set().await?;
let expected = [existing_validator_id];
assert_eq!(
start, expected,
Expand Down Expand Up @@ -172,7 +165,7 @@ async fn mock_consensus_can_delegate_to_a_validator() -> anyhow::Result<()> {

// Show that the set of validators looks correct.
{
use penumbra_stake::validator::State;
use penumbra_stake::{component::ConsensusIndexRead, validator::State};
let snapshot = post_tx_snapshot;
// The original validator should still be active.
assert_eq!(
Expand All @@ -189,7 +182,7 @@ async fn mock_consensus_can_delegate_to_a_validator() -> anyhow::Result<()> {
);
// The original validator should still be the only validator in the consensus set.
assert_eq!(
get_consensus_set(&snapshot_start).await?.len(),
snapshot_start.get_consensus_set().await?.len(),
1,
"the new validator should not be part of the consensus set yet"
);
Expand Down
6 changes: 6 additions & 0 deletions crates/core/component/stake/src/component/stake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -530,6 +530,12 @@ pub trait ConsensusIndexRead: StateRead {
.boxed())
}

/// Returns the [`IdentityKey`]s of validators that are currently in the consensus set.
async fn get_consensus_set(&self) -> anyhow::Result<Vec<IdentityKey>> {
use futures::TryStreamExt;
self.consensus_set_stream()?.try_collect().await
}

/// Returns whether a validator should be indexed in the consensus set.
/// Here, "consensus set" refers to the set of active validators as well as
/// the "inactive" validators which could be promoted during a view change.
Expand Down

0 comments on commit 733b9a1

Please sign in to comment.