Skip to content

Commit

Permalink
refactor(mock-consensus): 🔐 remove Keyring
Browse files Browse the repository at this point in the history
previously, we added a `Keyring` newtype. this was a low-effort, thin
newtype wrapper around a `BTreeMap<VerificationKey, SigningKey>`.

this commit removes it.

NB: this is based on #4001.
  • Loading branch information
cratelyn committed Mar 18, 2024
1 parent 3ca8c46 commit 1987525
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 136 deletions.
17 changes: 12 additions & 5 deletions crates/test/mock-consensus/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@
mod init_chain;

use {
crate::{keyring::Keyring, TestNode},
crate::{Keyring, TestNode},
bytes::Bytes,
std::collections::BTreeMap,
};

/// A buider, used to prepare and instantiate a new [`TestNode`].
Expand Down Expand Up @@ -57,9 +58,15 @@ impl Builder {
);
}

Self {
keyring: Keyring::new_with_size(1),
..self
}
// Generate a consensus key.
let sk = ed25519_consensus::SigningKey::new(rand_core::OsRng);
let vk = sk.verification_key();
tracing::trace!(verification_key = ?vk, "generated consensus key");

// Place it into the keyring.
let mut keyring = BTreeMap::new();
keyring.insert(vk, sk);

Self { keyring, ..self }
}
}
129 changes: 0 additions & 129 deletions crates/test/mock-consensus/src/keyring.rs

This file was deleted.

23 changes: 21 additions & 2 deletions crates/test/mock-consensus/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,13 @@
//
// see penumbra-zone/penumbra#3588.

use {
ed25519_consensus::{SigningKey, VerificationKey},
std::collections::BTreeMap,
};

pub mod block;
pub mod builder;
pub mod keyring;

mod abci;

Expand All @@ -23,9 +27,14 @@ pub struct TestNode<C> {
consensus: C,
last_app_hash: Vec<u8>,
height: tendermint::block::Height,
keyring: self::keyring::Keyring,
keyring: Keyring,
}

/// An ordered map of consensus keys.
///
/// Entries in this keyring consist of a [`VerificationKey`] and a [`SigningKey`].
type Keyring = BTreeMap<VerificationKey, SigningKey>;

impl<C> TestNode<C> {
pub const CHAIN_ID: &'static str = "penumbra-test-chain";

Expand All @@ -40,6 +49,16 @@ impl<C> TestNode<C> {
// - https://doc.rust-lang.org/std/fmt/#formatting-traits
format!("{:02X?}", self.last_app_hash)
}

/// Returns a reference to the test node's set of consensus keys.
pub fn keyring(&self) -> &Keyring {
&self.keyring
}

/// Returns a mutable reference to the test node's set of consensus keys.
pub fn keyring_mut(&mut self) -> &mut Keyring {
&mut self.keyring
}
}

impl<C> TestNode<C>
Expand Down

0 comments on commit 1987525

Please sign in to comment.