Skip to content

Commit

Permalink
WIP: Split ChainParameters into component-specific parameters (#3086)
Browse files Browse the repository at this point in the history
* Splitting of Rust ChainParameters and genesis content per-component
  • Loading branch information
zbuc authored Sep 28, 2023
1 parent d191582 commit 6e3a497
Show file tree
Hide file tree
Showing 103 changed files with 6,804 additions and 3,866 deletions.
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

60 changes: 33 additions & 27 deletions crates/bin/pcli/src/command/query/chain.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use anyhow::{anyhow, Context, Result};
use comfy_table::{presets, Table};
use futures::TryStreamExt;
use penumbra_chain::params::ChainParameters;
use penumbra_app::params::AppParameters;
use penumbra_proto::{
core::app::v1alpha1::{
query_service_client::QueryServiceClient as AppQueryServiceClient, ChainParametersRequest,
query_service_client::QueryServiceClient as AppQueryServiceClient, AppParametersRequest,
},
core::component::chain::v1alpha1::{
query_service_client::QueryServiceClient as ChainQueryServiceClient, EpochByHeightRequest,
Expand Down Expand Up @@ -46,68 +46,71 @@ pub struct Stats {
}

impl ChainCmd {
pub async fn print_chain_params(&self, app: &mut App) -> Result<()> {
pub async fn print_app_params(&self, app: &mut App) -> Result<()> {
let mut client = AppQueryServiceClient::new(app.pd_channel().await?);
let params: ChainParameters = client
.chain_parameters(tonic::Request::new(ChainParametersRequest {
let params: AppParameters = client
.app_parameters(tonic::Request::new(AppParametersRequest {
chain_id: "".to_string(),
}))
.await?
.into_inner()
.chain_parameters
.ok_or_else(|| anyhow::anyhow!("empty ChainParametersResponse message"))?
.app_parameters
.ok_or_else(|| anyhow::anyhow!("empty AppParametersResponse message"))?
.try_into()?;

println!("Chain Parameters:");
let mut table = Table::new();
table.load_preset(presets::NOTHING);
table
.set_header(vec!["", ""])
.add_row(vec!["Chain ID", &params.chain_id])
.add_row(vec!["Chain ID", &params.chain_params.chain_id])
.add_row(vec![
"Epoch Duration",
&format!("{}", params.epoch_duration),
&format!("{}", params.chain_params.epoch_duration),
])
.add_row(vec![
"Unbonding Epochs",
&format!("{}", params.unbonding_epochs),
&format!("{}", params.stake_params.unbonding_epochs),
])
.add_row(vec![
"Active Validator Limit",
&format!("{}", params.active_validator_limit),
&format!("{}", params.stake_params.active_validator_limit),
])
.add_row(vec![
"Base Reward Rate (bps^2)",
&format!("{}", params.base_reward_rate),
&format!("{}", params.stake_params.base_reward_rate),
])
.add_row(vec![
"Slashing Penalty (Misbehavior) (bps^2)",
&format!("{}", params.slashing_penalty_misbehavior),
&format!("{}", params.stake_params.slashing_penalty_misbehavior),
])
.add_row(vec![
"Slashing Penalty (Downtime) (bps^2)",
&format!("{}", params.slashing_penalty_downtime),
&format!("{}", params.stake_params.slashing_penalty_downtime),
])
.add_row(vec![
"Signed Blocks Window (blocks)",
&format!("{}", params.signed_blocks_window_len),
&format!("{}", params.stake_params.signed_blocks_window_len),
])
.add_row(vec![
"Missed Blocks Max",
&format!("{}", params.missed_blocks_maximum),
&format!("{}", params.stake_params.missed_blocks_maximum),
])
.add_row(vec![
"Proposal Deposit Amount (upenumbra)",
&format!("{}", params.proposal_deposit_amount),
&format!("{}", params.governance_params.proposal_deposit_amount),
])
.add_row(vec![
"IBC Enabled",
&format!("{}", params.ibc_params.ibc_enabled),
])
.add_row(vec!["IBC Enabled", &format!("{}", params.ibc_enabled)])
.add_row(vec![
"Inbound ICS-20 Enabled",
&format!("{}", params.inbound_ics20_transfers_enabled),
&format!("{}", params.ibc_params.inbound_ics20_transfers_enabled),
])
.add_row(vec![
"Outbound ICS-20 Enabled",
&format!("{}", params.outbound_ics20_transfers_enabled),
&format!("{}", params.ibc_params.outbound_ics20_transfers_enabled),
]);

println!("{table}");
Expand Down Expand Up @@ -139,21 +142,24 @@ impl ChainCmd {
.index;

let mut client = AppQueryServiceClient::new(channel.clone());
let chain_params = client
.chain_parameters(tonic::Request::new(ChainParametersRequest {
let app_params = client
.app_parameters(tonic::Request::new(AppParametersRequest {
chain_id: "".to_string(),
}))
.await?
.into_inner()
.chain_parameters
.ok_or_else(|| anyhow::anyhow!("empty ChainParametersResponse message"))?;
.app_parameters
.ok_or_else(|| anyhow::anyhow!("empty AppParametersResponse message"))?;

// Fetch validators.
let mut client = StakeQueryServiceClient::new(channel.clone());
let validators = client
.validator_info(ValidatorInfoRequest {
show_inactive: true,
chain_id: chain_params.chain_id,
chain_id: app_params
.chain_params
.ok_or_else(|| anyhow::anyhow!("missing chain_params in app params"))?
.chain_id,
})
.await?
.into_inner()
Expand Down Expand Up @@ -200,14 +206,14 @@ impl ChainCmd {
pub async fn exec(&self, app: &mut App) -> Result<()> {
match self {
ChainCmd::Params => {
self.print_chain_params(app).await?;
self.print_app_params(app).await?;
}
// TODO: we could implement this as an RPC call using the metrics
// subsystems once #829 is complete
// OR (hdevalence): fold it into pcli q
ChainCmd::Info { verbose } => {
if *verbose {
self.print_chain_params(app).await?;
self.print_app_params(app).await?;
}

let stats = self.get_stats(app).await?;
Expand Down
4 changes: 2 additions & 2 deletions crates/bin/pcli/src/command/query/dex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ impl DexCmd {
) -> Result<()> {
let mut client = ShieldedPoolQueryServiceClient::new(app.pd_channel().await?);

let chain_id = app.view().chain_params().await?.chain_id;
let chain_id = app.view().app_params().await?.chain_params.chain_id;

let outputs = self
.get_batch_outputs(app, chain_id.clone(), height, trading_pair)
Expand Down Expand Up @@ -408,7 +408,7 @@ impl DexCmd {
}
DexCmd::AllPositions { include_closed } => {
let client = DexQueryServiceClient::new(app.pd_channel().await?);
let chain_id = app.view().chain_params().await?.chain_id;
let chain_id = app.view().app_params().await?.chain_params.chain_id;

let positions_stream = self
.get_all_liquidity_positions(client.clone(), *include_closed, Some(chain_id))
Expand Down
20 changes: 10 additions & 10 deletions crates/bin/pcli/src/command/tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,7 @@ impl TxCmd {
.view
.as_mut()
.context("view service must be initialized")?
.chain_params()
.app_params()
.await?;

let account_group_id = app.fvk.account_group_id();
Expand All @@ -437,7 +437,7 @@ impl TxCmd {
swap_plaintext,
position: swap_record.position,
output_data: swap_record.output_data,
epoch_duration: params.epoch_duration,
epoch_duration: params.chain_params.epoch_duration,
proof_blinding_r: Fq::rand(&mut OsRng),
proof_blinding_s: Fq::rand(&mut OsRng),
})
Expand Down Expand Up @@ -549,7 +549,7 @@ impl TxCmd {
.as_mut()
.context("view service must be initialized")?;

let params = view.chain_params().await?;
let params = view.app_params().await?;
let current_height = view.status(account_group_id).await?.sync_height;
let mut client = ChainQueryServiceClient::new(channel.clone());
let current_epoch = client
Expand Down Expand Up @@ -590,7 +590,7 @@ impl TxCmd {
let mut client = StakeQueryServiceClient::new(channel.clone());
let penalty: Penalty = client
.validator_penalty(tonic::Request::new(ValidatorPenaltyRequest {
chain_id: params.chain_id.to_string(),
chain_id: params.chain_params.chain_id.to_string(),
identity_key: Some(validator_identity.into()),
start_epoch_index,
end_epoch_index,
Expand Down Expand Up @@ -781,7 +781,7 @@ impl TxCmd {
start_position,
} = client
.proposal_info(ProposalInfoRequest {
chain_id: app.view().chain_params().await?.chain_id,
chain_id: app.view().app_params().await?.chain_params.chain_id,
proposal_id,
})
.await?
Expand All @@ -790,7 +790,7 @@ impl TxCmd {

let mut rate_data_stream = client
.proposal_rate_data(ProposalRateDataRequest {
chain_id: app.view().chain_params().await?.chain_id,
chain_id: app.view().app_params().await?.chain_params.chain_id,
proposal_id,
})
.await?
Expand Down Expand Up @@ -1013,14 +1013,14 @@ impl TxCmd {
.view
.as_mut()
.context("view service must be initialized")?;
let params = view.chain_params().await?;
let params = view.app_params().await?;
for position_id in owned_position_ids {
// Withdraw the position

// Fetch the information regarding the position from the view service.
let position = client
.liquidity_position_by_id(LiquidityPositionByIdRequest {
chain_id: params.chain_id.to_string(),
chain_id: params.chain_params.chain_id.to_string(),
position_id: Some(position_id.into()),
})
.await?
Expand Down Expand Up @@ -1069,12 +1069,12 @@ impl TxCmd {
.view
.as_mut()
.context("view service must be initialized")?;
let params = view.chain_params().await?;
let params = view.app_params().await?;

// Fetch the information regarding the position from the view service.
let position = client
.liquidity_position_by_id(LiquidityPositionByIdRequest {
chain_id: params.chain_id.to_string(),
chain_id: params.chain_params.chain_id.to_string(),
position_id: Some(PositionId::from(*position_id)),
})
.await?
Expand Down
4 changes: 2 additions & 2 deletions crates/bin/pclientd/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use penumbra_keys::keys::{SeedPhrase, SpendKey};
use penumbra_keys::FullViewingKey;
use penumbra_proto::{
core::app::v1alpha1::{
query_service_client::QueryServiceClient as AppQueryServiceClient, ChainParametersRequest,
query_service_client::QueryServiceClient as AppQueryServiceClient, AppParametersRequest,
},
custody::v1alpha1::custody_protocol_service_server::CustodyProtocolServiceServer,
view::v1alpha1::view_protocol_service_server::ViewProtocolServiceServer,
Expand Down Expand Up @@ -150,7 +150,7 @@ impl Opt {
let mut client = AppQueryServiceClient::connect(grpc_url.to_string()).await?;

let params = client
.chain_parameters(tonic::Request::new(ChainParametersRequest {
.app_parameters(tonic::Request::new(AppParametersRequest {
chain_id: String::new(),
}))
.await?
Expand Down
2 changes: 1 addition & 1 deletion crates/bin/pd/src/consensus.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use anyhow::Result;

use penumbra_chain::genesis;
use penumbra_app::genesis;
use penumbra_storage::Storage;
use tendermint::abci::Event;
use tendermint::v0_34::abci::{
Expand Down
2 changes: 1 addition & 1 deletion crates/bin/pd/src/testnet/config.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use anyhow::Context;
use decaf377_rdsa::{SigningKey, SpendAuth, VerificationKey};
use directories::UserDirs;
use penumbra_chain::genesis::AppState;
use penumbra_app::genesis::AppState;
use penumbra_keys::keys::{SpendKey, SpendKeyBytes};
use penumbra_wallet::KeyStore;
use rand::Rng;
Expand Down
Loading

0 comments on commit 6e3a497

Please sign in to comment.