Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(pd): dynamic addresses in devnet allocations #4827

Merged
merged 1 commit into from
Aug 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading