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 5f0b44b
Show file tree
Hide file tree
Showing 16 changed files with 862 additions and 101 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
2 changes: 1 addition & 1 deletion crates/core/app/tests/common/test_node_ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ where
.tap(|start| tracing::info!(?start, "fast forwarding to next epoch"));

loop {
self.block().execute().await?;
self.block().without_signatures().execute().await?;
let current = get_epoch().await?;
if current != start {
tracing::debug!(end = ?current, ?start, "reached next epoch");
Expand Down
Loading

0 comments on commit 5f0b44b

Please sign in to comment.