Skip to content

Commit

Permalink
feat(pd): dynamic addresses in devnet allocations
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
conorsch committed Aug 22, 2024
1 parent 8ee733c commit 48553af
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 1 deletion.
8 changes: 7 additions & 1 deletion crates/bin/pd/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<PathBuf>,
/// 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<penumbra_keys::Address>,
#[clap(long, parse(from_os_str))]
/// Path to JSON file containing initial validator configs [default: latest testnet].
validators_input_file: Option<PathBuf>,
/// Testnet name [default: latest testnet].
#[clap(long)]
Expand Down
2 changes: 2 additions & 0 deletions crates/bin/pd/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
30 changes: 30 additions & 0 deletions crates/bin/pd/src/network/generate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ impl NetworkConfig {
peer_address_template: Option<String>,
external_addresses: Option<Vec<TendermintAddress>>,
allocations_input_file: Option<PathBuf>,
allocation_address: Option<Address>,
validators_input_file: Option<PathBuf>,
tendermint_timeout_commit: Option<tendermint::Timeout>,
active_validator_limit: Option<u64>,
Expand All @@ -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<Vec<Validator>> =
Expand Down Expand Up @@ -390,6 +396,7 @@ pub fn network_generate(
external_addresses: Vec<TendermintAddress>,
validators_input_file: Option<PathBuf>,
allocations_input_file: Option<PathBuf>,
allocation_address: Option<Address>,
proposal_voting_blocks: Option<u64>,
gas_price_simple: Option<u64>,
) -> anyhow::Result<()> {
Expand All @@ -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,
Expand Down Expand Up @@ -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<Allocation> {
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.
Expand Down Expand Up @@ -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);
Expand All @@ -752,6 +781,7 @@ mod tests {
Some(String::from("validator.local")),
None,
None,
None,
Some(ci_validators_filepath),
None,
None,
Expand Down

0 comments on commit 48553af

Please sign in to comment.