From 48553af6c37b56450231e4396d99f85e5d6477f8 Mon Sep 17 00:00:00 2001 From: Conor Schaefer Date: Wed, 21 Aug 2024 13:55:13 -0700 Subject: [PATCH] feat(pd): dynamic addresses in devnet allocations In an effort to improve the developer experience, adding a CLI arg for `pd network generate` so that that local devents networks can be created with arbitrary Penumbra wallet address included in the genesis allocations. This allows a new developer to get started quickly, without making their own CSV file to pass in. Refs #3811. --- crates/bin/pd/src/cli.rs | 8 ++++++- crates/bin/pd/src/main.rs | 2 ++ crates/bin/pd/src/network/generate.rs | 30 +++++++++++++++++++++++++++ 3 files changed, 39 insertions(+), 1 deletion(-) diff --git a/crates/bin/pd/src/cli.rs b/crates/bin/pd/src/cli.rs index 9ca4226eed..6583a5fccd 100644 --- a/crates/bin/pd/src/cli.rs +++ b/crates/bin/pd/src/cli.rs @@ -167,8 +167,14 @@ pub enum NetworkCommand { /// Path to CSV file containing initial allocations [default: latest testnet]. #[clap(long, parse(from_os_str))] allocations_input_file: Option, - /// Path to JSON file containing initial validator configs [default: latest testnet]. + /// Penumbra wallet address to include in genesis allocations. + /// Intended to make dev experience nicer on first run: + /// generate a wallet, view its address, then generate a devnet + /// with that address included in the base allocations. + #[clap(long)] + allocation_address: Option, #[clap(long, parse(from_os_str))] + /// Path to JSON file containing initial validator configs [default: latest testnet]. validators_input_file: Option, /// Testnet name [default: latest testnet]. #[clap(long)] diff --git a/crates/bin/pd/src/main.rs b/crates/bin/pd/src/main.rs index a203d8f175..4c2f003ae4 100644 --- a/crates/bin/pd/src/main.rs +++ b/crates/bin/pd/src/main.rs @@ -319,6 +319,7 @@ async fn main() -> anyhow::Result<()> { unbonding_delay, active_validator_limit, allocations_input_file, + allocation_address, validators_input_file, chain_id, gas_price_simple, @@ -377,6 +378,7 @@ async fn main() -> anyhow::Result<()> { peer_address_template, Some(external_addresses), allocations_input_file, + allocation_address, validators_input_file, timeout_commit, active_validator_limit, diff --git a/crates/bin/pd/src/network/generate.rs b/crates/bin/pd/src/network/generate.rs index 113e3b5bb2..9208c20920 100644 --- a/crates/bin/pd/src/network/generate.rs +++ b/crates/bin/pd/src/network/generate.rs @@ -68,6 +68,7 @@ impl NetworkConfig { peer_address_template: Option, external_addresses: Option>, allocations_input_file: Option, + allocation_address: Option
, validators_input_file: Option, tendermint_timeout_commit: Option, active_validator_limit: Option, @@ -90,6 +91,11 @@ impl NetworkConfig { allocations.push(v.delegation_allocation()?); } + // Add an extra allocation for a dynamic wallet address. + if let Some(address) = allocation_address { + tracing::info!(%address, "adding dynamic allocation to genesis"); + allocations.extend(NetworkAllocation::simple(address)); + } // Convert to domain type, for use with other Penumbra interfaces. // We do this conversion once and store it in the struct for convenience. let validators: anyhow::Result> = @@ -390,6 +396,7 @@ pub fn network_generate( external_addresses: Vec, validators_input_file: Option, allocations_input_file: Option, + allocation_address: Option
, proposal_voting_blocks: Option, gas_price_simple: Option, ) -> anyhow::Result<()> { @@ -400,6 +407,7 @@ pub fn network_generate( peer_address_template, Some(external_addresses), allocations_input_file, + allocation_address, validators_input_file, tendermint_timeout_commit, active_validator_limit, @@ -456,6 +464,26 @@ impl NetworkAllocation { Ok(res) } + /// Creates a basic set of genesis [Allocation]s for the provided [Address]. + /// Returns multiple Allocations, so that it's immediately possible to use the DEX, + /// for basic interactive testing of swap behavior. + /// For more control over precise allocation amounts, use [from_csv]. + pub fn simple(address: Address) -> Vec { + vec![ + Allocation { + address: address.clone(), + raw_denom: "upenumbra".into(), + // The `upenumbra` base denom is millionths, so `10^6 * n` + // results in `n` `penumbra` tokens. + raw_amount: (100_000 * 10u128.pow(6)).into(), + }, + Allocation { + address: address.clone(), + raw_denom: "test_usd".into(), + raw_amount: (1_000 as u128).into(), + }, + ] + } } /// Represents a funding stream within a testnet configuration file. @@ -729,6 +757,7 @@ mod tests { None, None, None, + None, )?; assert_eq!(testnet_config.name, "test-chain-1234"); assert_eq!(testnet_config.genesis.validators.len(), 0); @@ -752,6 +781,7 @@ mod tests { Some(String::from("validator.local")), None, None, + None, Some(ci_validators_filepath), None, None,