Skip to content

Commit

Permalink
Implement block header generation with signing
Browse files Browse the repository at this point in the history
  • Loading branch information
zbuc committed Aug 20, 2024
1 parent dd76baa commit 197154c
Show file tree
Hide file tree
Showing 13 changed files with 511 additions and 97 deletions.
6 changes: 6 additions & 0 deletions Cargo.lock

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

Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ async fn app_tracks_uptime_for_genesis_validator_missing_blocks() -> anyhow::Res
let height = 4;
for i in 1..=height {
node.block()
.with_signatures(vec![])
.without_signatures()
.execute()
.tap(|_| trace!(%i, "executing block with no signatures"))
.instrument(error_span!("executing block with no signatures", %i))
Expand Down
16 changes: 13 additions & 3 deletions crates/core/app/tests/common/test_node_builder_ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,21 @@ pub trait BuilderExt: Sized {

impl BuilderExt for Builder {
type Error = anyhow::Error;
fn with_penumbra_auto_app_state(self, app_state: AppState) -> Result<Self, Self::Error> {
fn with_penumbra_auto_app_state(mut self, app_state: AppState) -> Result<Self, Self::Error> {
let Self { keyring, .. } = &self;
let mut content = match app_state {
AppState::Content(c) => c,
AppState::Checkpoint(_) => anyhow::bail!("checkpointed state is not supported"),
};

for (consensus_vk, _) in keyring {
// Let the seed for the penumbra validator be derived from the verification key,
// that way tests can operate with no rng.
let seed = Some(SpendKeyBytes(consensus_vk.to_bytes()));

// Generate a penumbra validator with this consensus key, and a corresponding
// allocation of delegation tokens.
let (validator, allocation) = generate_penumbra_validator(consensus_vk);
let (validator, allocation) = generate_penumbra_validator(consensus_vk, seed);

// Add the validator to the staking component's genesis content.
trace!(?validator, "adding validator to staking genesis content");
Expand All @@ -50,6 +54,11 @@ impl BuilderExt for Builder {
content.shielded_pool_content.allocations.push(allocation);
}

// Set the chain ID from the content
if !content.chain_id.is_empty() {
self.chain_id = Some(content.chain_id.clone());
}

// Serialize the app state into bytes, and add it to the builder.
let app_state = AppState::Content(content);
serde_json::to_vec(&app_state)
Expand All @@ -61,8 +70,9 @@ impl BuilderExt for Builder {
/// Generates a [`Validator`][PenumbraValidator] given a consensus verification key.
fn generate_penumbra_validator(
consensus_key: &ed25519_consensus::VerificationKey,
seed: Option<SpendKeyBytes>,
) -> (PenumbraValidator, Allocation) {
let seed = SpendKeyBytes(OsRng.gen());
let seed = seed.unwrap_or(SpendKeyBytes(OsRng.gen()));
let spend_key = SpendKey::from(seed.clone());
let validator_id_sk = spend_key.spend_auth_key();
let validator_id_vk = VerificationKey::from(validator_id_sk);
Expand Down
10 changes: 10 additions & 0 deletions crates/test/mock-client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,16 @@ impl MockClient {
Ok(self)
}

pub async fn with_sync_to_inner_storage(
mut self,
storage: cnidarium::Storage,
) -> anyhow::Result<Self> {
let latest = storage.latest_snapshot();
self.sync_to_latest(latest).await?;

Ok(self)
}

pub async fn sync_to_latest<R: StateRead>(&mut self, state: R) -> anyhow::Result<()> {
let height = state.get_block_height().await?;
self.sync_to(height, state).await?;
Expand Down
5 changes: 5 additions & 0 deletions crates/test/mock-consensus/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,14 @@ license.workspace = true
anyhow = { workspace = true }
bytes = { workspace = true }
ed25519-consensus = { workspace = true }
hex = { workspace = true }
prost = { workspace = true }
rand_core = { workspace = true }
serde = { workspace = true }
serde_json = { workspace = true }
sha2 = { workspace = true }
tap = { workspace = true }
tendermint = { workspace = true, default-features = true }
tendermint-proto = { workspace = true }
tower = { workspace = true, features = ["full"] }
tracing = { workspace = true }
1 change: 1 addition & 0 deletions crates/test/mock-consensus/src/abci.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ where
retain_height,
} = &response;
trace!(?data, ?retain_height, "received Commit response");

Ok(response)
}
response => {
Expand Down
Loading

0 comments on commit 197154c

Please sign in to comment.