Skip to content

Commit

Permalink
feat(pd): custom voting periods testnet generate
Browse files Browse the repository at this point in the history
During testing of upgrades, it's been handy to reduce the default,
static value of "24h" for voting on a given proposal, so that a proposal
can be made, voted on, and passed, all within e.g. 1h. This setting
greatly accelerates testing on devnets.

Also includes customization var in deploy scripts for `epoch_duration`,
which we're not currently overriding, but now we can if we want to.

Ideally we'd set these customizations by just overriding the
`pd testnet generate` command, but given that the cmd requires
a storage dir arg that's non-standard, it's more straightforward
to stick with the clunky vars-based approach for now.
  • Loading branch information
conorsch committed Nov 30, 2023
1 parent 5b35674 commit 5fb82c1
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 4 deletions.
6 changes: 6 additions & 0 deletions crates/bin/pd/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,10 @@ enum TestnetCommand {
/// Testnet name [default: latest testnet].
#[clap(long)]
chain_id: Option<String>,
/// The duration, in number of blocks, that a governance proposal
/// can be voted on.
#[clap(long)]
proposal_voting_blocks: Option<u64>,
/// Base hostname for a validator's p2p service. If multiple validators
/// exist in the genesis, e.g. via `--validators-input-file`, then
/// numeric suffixes are automatically added, e.g. "-0", "-1", etc.
Expand Down Expand Up @@ -600,6 +604,7 @@ async fn main() -> anyhow::Result<()> {
chain_id,
preserve_chain_id,
external_addresses,
proposal_voting_blocks,
},
testnet_dir,
} => {
Expand Down Expand Up @@ -655,6 +660,7 @@ async fn main() -> anyhow::Result<()> {
active_validator_limit,
epoch_duration,
unbonding_epochs,
proposal_voting_blocks,
)?;
tracing::info!(
n_validators = t.validators.len(),
Expand Down
26 changes: 22 additions & 4 deletions crates/bin/pd/src/testnet/generate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use crate::testnet::config::{get_testnet_dir, TestnetTendermintConfig, Validator
use anyhow::{Context, Result};
use penumbra_app::{genesis, params::AppParameters};
use penumbra_chain::{genesis::Content as ChainContent, params::ChainParameters};
use penumbra_governance::genesis::Content as GovernanceContent;
use penumbra_keys::{keys::SpendKey, Address};
use penumbra_shielded_pool::genesis::{
self as shielded_pool_genesis, Allocation, Content as ShieldedPoolContent,
Expand Down Expand Up @@ -65,6 +66,7 @@ impl TestnetConfig {
active_validator_limit: Option<u64>,
epoch_duration: Option<u64>,
unbonding_epochs: Option<u64>,
proposal_voting_blocks: Option<u64>,
) -> anyhow::Result<TestnetConfig> {
let external_addresses = external_addresses.unwrap_or_default();

Expand Down Expand Up @@ -93,6 +95,7 @@ impl TestnetConfig {
active_validator_limit,
epoch_duration,
unbonding_epochs,
proposal_voting_blocks,
)?;
let genesis = Self::make_genesis(app_state)?;

Expand Down Expand Up @@ -180,20 +183,33 @@ impl TestnetConfig {
active_validator_limit: Option<u64>,
epoch_duration: Option<u64>,
unbonding_epochs: Option<u64>,
proposal_voting_blocks: Option<u64>,
) -> anyhow::Result<genesis::Content> {
let default_gov_params = penumbra_governance::params::GovernanceParameters::default();

let gov_params = penumbra_governance::params::GovernanceParameters {
proposal_voting_blocks: proposal_voting_blocks
.unwrap_or(default_gov_params.proposal_voting_blocks),
..default_gov_params
};

// Look up default app params, so we can fill in defaults.
let default_params = AppParameters::default();
let default_app_params = AppParameters::default();

let app_state = genesis::Content {
stake_content: StakeContent {
validators: validators.into_iter().map(Into::into).collect(),
stake_params: StakeParameters {
active_validator_limit: active_validator_limit
.unwrap_or(default_params.stake_params.active_validator_limit),
.unwrap_or(default_app_params.stake_params.active_validator_limit),
unbonding_epochs: unbonding_epochs
.unwrap_or(default_params.stake_params.unbonding_epochs),
.unwrap_or(default_app_params.stake_params.unbonding_epochs),
..Default::default()
},
},
governance_content: GovernanceContent {
governance_params: gov_params,
},
shielded_pool_content: ShieldedPoolContent {
allocations: allocations.clone(),
},
Expand All @@ -202,7 +218,7 @@ impl TestnetConfig {
chain_id: chain_id.to_string(),
// Fall back to chain param defaults
epoch_duration: epoch_duration
.unwrap_or(default_params.chain_params.epoch_duration),
.unwrap_or(default_app_params.chain_params.epoch_duration),
},
},
..Default::default()
Expand Down Expand Up @@ -332,6 +348,7 @@ pub fn testnet_generate(
external_addresses: Vec<TendermintAddress>,
validators_input_file: Option<PathBuf>,
allocations_input_file: Option<PathBuf>,
proposal_voting_blocks: Option<u64>,
) -> anyhow::Result<()> {
tracing::info!(?chain_id, "Generating network config");
let t = TestnetConfig::generate(
Expand All @@ -345,6 +362,7 @@ pub fn testnet_generate(
active_validator_limit,
epoch_duration,
unbonding_epochs,
proposal_voting_blocks,
)?;
tracing::info!(
n_validators = t.validators.len(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,12 @@ spec:
{{- if .Values.network.preserve_chain_id }}
--preserve-chain-id \
{{- end }}
{{- if .Values.network.epoch_duration }}
--epoch-duration {{ .Values.network.epoch_duration }} \
{{- end }}
{{- if .Values.network.proposal_voting_blocks }}
--proposal-voting-blocks {{ .Values.network.proposal_voting_blocks }} \
{{- end }}
--validators-input-file /penumbra/validators.json \
--external-addresses {{ .Values.network.external_addresses }}
Expand Down
3 changes: 3 additions & 0 deletions deployments/charts/penumbra-network/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ network:
# It'd be grand to have a DNS hostname in here, e.g. `veil.petrichor.guru:31888`.
# external_addresses: veil.petrichor.guru:31888
external_addresses: ""
# Customization of the voting period for governance proposals.
# Dial this down if you want faster voting for testing.
proposal_voting_blocks:

# How many validators are present at genesis. This number must
# match the count in the JSON file used to define the validators.
Expand Down

0 comments on commit 5fb82c1

Please sign in to comment.