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 56cb002 commit b6090a9
Show file tree
Hide file tree
Showing 34 changed files with 749 additions and 164 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 @@ -2,6 +2,7 @@ use {
self::common::{BuilderExt, TestNodeExt, ValidatorDataReadExt},
anyhow::anyhow,
cnidarium::TempStorage,
common::TempStorageExt as _,
decaf377_rdsa::{SigningKey, SpendAuth, VerificationKey},
penumbra_app::{
genesis::{self, AppState},
Expand Down Expand Up @@ -32,7 +33,7 @@ const EPOCH_DURATION: u64 = 8;
async fn app_can_define_and_delegate_to_a_validator() -> anyhow::Result<()> {
// Install a test logger, acquire some temporary storage, and start the test node.
let guard = common::set_tracing_subscriber();
let storage = TempStorage::new().await?;
let storage = TempStorage::new_with_penumbra_prefixes().await?;

// Configure an AppState with slightly shorter epochs than usual.
let app_state = AppState::Content(
Expand Down
3 changes: 2 additions & 1 deletion crates/core/app/tests/app_can_deposit_into_community_pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use {
self::common::BuilderExt,
anyhow::anyhow,
cnidarium::TempStorage,
common::TempStorageExt as _,
penumbra_app::{
genesis::{self, AppState},
server::consensus::Consensus,
Expand All @@ -28,7 +29,7 @@ mod common;
async fn app_can_deposit_into_community_pool() -> anyhow::Result<()> {
// Install a test logger, and acquire some temporary storage.
let guard = common::set_tracing_subscriber();
let storage = TempStorage::new().await?;
let storage = TempStorage::new_with_penumbra_prefixes().await?;

// Define our application state, and start the test node.
let mut test_node = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use {
self::common::ValidatorDataReadExt,
anyhow::anyhow,
cnidarium::TempStorage,
common::TempStorageExt as _,
decaf377_rdsa::VerificationKey,
penumbra_app::{
genesis::{AppState, Content},
Expand Down Expand Up @@ -49,7 +50,7 @@ const PROPOSAL_VOTING_BLOCKS: u64 = 3;
async fn app_can_disable_community_pool_spends() -> anyhow::Result<()> {
// Install a test logger, and acquire some temporary storage.
let guard = common::set_tracing_subscriber();
let storage = TempStorage::new().await?;
let storage = TempStorage::new_with_penumbra_prefixes().await?;

// Define a helper to get the current community pool balance.
let pool_balance = || async { storage.latest_snapshot().community_pool_balance().await };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use {
self::common::ValidatorDataReadExt,
anyhow::anyhow,
cnidarium::TempStorage,
common::TempStorageExt as _,
decaf377_rdsa::VerificationKey,
penumbra_app::{
genesis::{AppState, Content},
Expand Down Expand Up @@ -49,7 +50,7 @@ const PROPOSAL_VOTING_BLOCKS: u64 = 3;
async fn app_can_propose_community_pool_spends() -> anyhow::Result<()> {
// Install a test logger, and acquire some temporary storage.
let guard = common::set_tracing_subscriber();
let storage = TempStorage::new().await?;
let storage = TempStorage::new_with_penumbra_prefixes().await?;

// Define a helper to get the current community pool balance.
let pool_balance = || async { storage.latest_snapshot().community_pool_balance().await };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use {
self::common::BuilderExt,
anyhow::anyhow,
cnidarium::TempStorage,
common::TempStorageExt as _,
penumbra_app::{
genesis::{self, AppState},
server::consensus::Consensus,
Expand All @@ -27,7 +28,7 @@ mod common;
async fn app_can_spend_notes_and_detect_outputs() -> anyhow::Result<()> {
// Install a test logger, acquire some temporary storage, and start the test node.
let guard = common::set_tracing_subscriber();
let storage = TempStorage::new().await?;
let storage = TempStorage::new_with_penumbra_prefixes().await?;
let mut test_node = {
let app_state = AppState::Content(
genesis::Content::default().with_chain_id(TestNode::<()>::CHAIN_ID.to_string()),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use {
anyhow::Context,
cnidarium::TempStorage,
common::TempStorageExt as _,
penumbra_app::{
genesis::{AppState, Content},
server::consensus::Consensus,
Expand Down Expand Up @@ -37,7 +38,7 @@ const COUNT: usize = SWEEP_COUNT + 1;
async fn app_can_sweep_a_collection_of_small_notes() -> anyhow::Result<()> {
// Install a test logger, and acquire some temporary storage.
let guard = common::set_tracing_subscriber_with_env_filter("info".into());
let storage = TempStorage::new().await?;
let storage = TempStorage::new_with_penumbra_prefixes().await?;

// Instantiate a mock tendermint proxy, which we will connect to the test node.
let proxy = penumbra_mock_tendermint_proxy::TestNodeProxy::new::<Consensus>();
Expand Down
3 changes: 2 additions & 1 deletion crates/core/app/tests/app_can_undelegate_from_a_validator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use {
self::common::{BuilderExt, TestNodeExt, ValidatorDataReadExt},
anyhow::anyhow,
cnidarium::TempStorage,
common::TempStorageExt as _,
decaf377_fmd::Precision,
penumbra_app::{
genesis::{self, AppState},
Expand Down Expand Up @@ -37,7 +38,7 @@ const UNBONDING_DELAY: u64 = 4;
async fn app_can_undelegate_from_a_validator() -> anyhow::Result<()> {
// Install a test logger, acquire some temporary storage, and start the test node.
let guard = common::set_tracing_subscriber();
let storage = TempStorage::new().await?;
let storage = TempStorage::new_with_penumbra_prefixes().await?;

// Helper function to get the latest block height.
let get_latest_height = || async {
Expand Down
5 changes: 4 additions & 1 deletion crates/core/app/tests/app_check_dex_vcb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@ use std::{ops::Deref, sync::Arc};
/// This bug was fixed in #4643.
async fn dex_vcb_tracks_multiswap() -> anyhow::Result<()> {
let mut rng = rand_chacha::ChaChaRng::seed_from_u64(1776);
let storage = TempStorage::new().await?.apply_default_genesis().await?;
let storage = TempStorage::new_with_penumbra_prefixes()
.await?
.apply_default_genesis()
.await?;
let mut state = Arc::new(StateDelta::new(storage.latest_snapshot()));

// Create the first swap:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use {
self::common::{BuilderExt, ValidatorDataReadExt},
cnidarium::TempStorage,
common::TempStorageExt as _,
decaf377_rdsa::{SigningKey, SpendAuth, VerificationKey},
penumbra_app::{
genesis::{self, AppState},
Expand All @@ -23,7 +24,7 @@ mod common;
async fn app_rejects_validator_definitions_with_invalid_auth_sigs() -> anyhow::Result<()> {
// Install a test logger, and acquire some temporary storage.
let guard = common::set_tracing_subscriber();
let storage = TempStorage::new().await?;
let storage = TempStorage::new_with_penumbra_prefixes().await?;

// Start the test node.
let mut node = {
Expand Down
5 changes: 3 additions & 2 deletions crates/core/app/tests/app_reproduce_testnet_75_vcb_close.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,19 @@ use {
self::common::BuilderExt,
anyhow::anyhow,
cnidarium::TempStorage,
common::TempStorageExt as _,
penumbra_app::{
genesis::{self, AppState},
server::consensus::Consensus,
},
penumbra_asset::{Value, STAKING_TOKEN_ASSET_ID},
penumbra_auction::StateReadExt as _,
penumbra_auction::{
auction::{
dutch::{ActionDutchAuctionEnd, ActionDutchAuctionSchedule, DutchAuctionDescription},
AuctionNft,
},
component::AuctionStoreRead,
StateReadExt as _,
},
penumbra_keys::test_keys,
penumbra_mock_client::MockClient,
Expand Down Expand Up @@ -65,7 +66,7 @@ async fn app_can_reproduce_tesnet_75_vcb_close() -> anyhow::Result<()> {

common::set_tracing_subscriber_with_env_filter(filter)
};
let storage = TempStorage::new().await?;
let storage = TempStorage::new_with_penumbra_prefixes().await?;
let app_state = AppState::Content(
genesis::Content::default().with_chain_id(TestNode::<()>::CHAIN_ID.to_string()),
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use {
self::common::{BuilderExt, ValidatorDataReadExt},
anyhow::Context,
cnidarium::TempStorage,
common::TempStorageExt as _,
penumbra_app::{
genesis::{self, AppState},
server::consensus::Consensus,
Expand All @@ -18,7 +19,7 @@ mod common;
async fn app_tracks_uptime_for_genesis_validator_missing_blocks() -> anyhow::Result<()> {
// Install a test logger, acquire some temporary storage, and start the test node.
let guard = common::set_tracing_subscriber();
let storage = TempStorage::new().await?;
let storage = TempStorage::new_with_penumbra_prefixes().await?;

// Start the test node.
let mut node = {
Expand Down Expand Up @@ -60,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(Default::default())
.without_signatures()
.execute()
.tap(|_| trace!(%i, "executing block with no signatures"))
.instrument(error_span!("executing block with no signatures", %i))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use {
self::common::{BuilderExt, ValidatorDataReadExt},
anyhow::Context,
cnidarium::TempStorage,
common::TempStorageExt as _,
penumbra_app::{
genesis::{self, AppState},
server::consensus::Consensus,
Expand All @@ -18,7 +19,7 @@ mod common;
async fn app_tracks_uptime_for_genesis_validator_missing_blocks() -> anyhow::Result<()> {
// Install a test logger, acquire some temporary storage, and start the test node.
let guard = common::set_tracing_subscriber();
let storage = TempStorage::new().await?;
let storage = TempStorage::new_with_penumbra_prefixes().await?;

// Start the test node.
let mut node = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use {
self::common::{BuilderExt, TestNodeExt, ValidatorDataReadExt},
cnidarium::TempStorage,
common::TempStorageExt as _,
decaf377_rdsa::{SigningKey, SpendAuth, VerificationKey},
penumbra_app::{
genesis::{self, AppState},
Expand Down Expand Up @@ -32,7 +33,7 @@ async fn app_tracks_uptime_for_validators_only_once_active() -> anyhow::Result<(

// Install a test logger, acquire some temporary storage, and start the test node.
let guard = common::set_tracing_subscriber();
let storage = TempStorage::new().await?;
let storage = TempStorage::new_with_penumbra_prefixes().await?;

// Configure an AppState with slightly shorter epochs than usual.
let app_state = AppState::Content(
Expand Down
3 changes: 3 additions & 0 deletions crates/core/app/tests/common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,6 @@ mod test_node_ext;
/// See [`ValidatorDataRead`][penumbra_stake::component::validator_handler::ValidatorDataRead],
/// and [`ValidatorDataReadExt`].
mod validator_read_ext;

/// Methods for testing IBC functionality.
pub mod ibc_tests;
8 changes: 7 additions & 1 deletion crates/core/app/tests/common/temp_storage_ext.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,24 @@
use {
async_trait::async_trait,
cnidarium::TempStorage,
penumbra_app::{app::App, genesis::AppState},
penumbra_app::{app::App, genesis::AppState, SUBSTORE_PREFIXES},
std::ops::Deref,
};

#[async_trait]
pub trait TempStorageExt: Sized {
async fn apply_genesis(self, genesis: AppState) -> anyhow::Result<Self>;
async fn apply_default_genesis(self) -> anyhow::Result<Self>;
async fn new_with_penumbra_prefixes() -> anyhow::Result<TempStorage>;
}

#[async_trait]
impl TempStorageExt for TempStorage {
// TODO: move this to an Ext trait for Storage instead of TempStorage
async fn new_with_penumbra_prefixes() -> anyhow::Result<TempStorage> {
TempStorage::new_with_prefixes(SUBSTORE_PREFIXES.to_vec()).await
}

async fn apply_genesis(self, genesis: AppState) -> anyhow::Result<Self> {
// Check that we haven't already applied a genesis state:
if self.latest_version() != u64::MAX {
Expand Down
17 changes: 14 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 @@ -11,6 +11,7 @@ use {
penumbra_stake::DelegationToken,
rand::Rng,
rand_core::OsRng,
tendermint::Genesis,
tracing::trace,
};

Expand All @@ -26,17 +27,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 +55,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 +71,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
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use {
self::common::{BuilderExt, ValidatorDataReadExt},
anyhow::anyhow,
cnidarium::TempStorage,
common::TempStorageExt as _,
penumbra_app::{
genesis::{self, AppState},
server::consensus::Consensus,
Expand All @@ -19,7 +20,7 @@ mod common;
async fn mock_consensus_can_define_a_genesis_validator() -> anyhow::Result<()> {
// Install a test logger, acquire some temporary storage, and start the test node.
let guard = common::set_tracing_subscriber();
let storage = TempStorage::new().await?;
let storage = TempStorage::new_with_penumbra_prefixes().await?;
let test_node = {
let app_state = AppState::Content(
genesis::Content::default().with_chain_id(TestNode::<()>::CHAIN_ID.to_string()),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use {
self::common::BuilderExt,
cnidarium::TempStorage,
common::TempStorageExt as _,
penumbra_app::{
genesis::{self, AppState},
server::consensus::Consensus,
Expand All @@ -18,7 +19,7 @@ mod common;
async fn mock_consensus_can_send_a_sequence_of_empty_blocks() -> anyhow::Result<()> {
// Install a test logger, acquire some temporary storage, and start the test node.
let guard = common::set_tracing_subscriber();
let storage = TempStorage::new().await?;
let storage = TempStorage::new_with_penumbra_prefixes().await?;
let mut test_node = {
let app_state = AppState::Content(
genesis::Content::default().with_chain_id(TestNode::<()>::CHAIN_ID.to_string()),
Expand Down
Loading

0 comments on commit b6090a9

Please sign in to comment.