Skip to content
Closed
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
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Exposes some cometbft genesis params in Namada genesis files ([\#2797](https://github.com/anoma/namada/pull/2797))
3 changes: 3 additions & 0 deletions crates/apps/src/lib/config/genesis/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -706,6 +706,7 @@ pub struct FinalizedParameters {
pub gov_params: templates::GovernanceParams,
pub pgf_params: namada::governance::pgf::parameters::PgfParameters,
pub eth_bridge_params: Option<templates::EthBridgeParams>,
pub cometbft_params: templates::CometBftParams,
}

impl FinalizedParameters {
Expand All @@ -716,6 +717,7 @@ impl FinalizedParameters {
gov_params,
pgf_params,
eth_bridge_params,
cometbft_params,
}: templates::Parameters<Validated>,
) -> Self {
use namada::governance::pgf::parameters::PgfParameters;
Expand All @@ -730,6 +732,7 @@ impl FinalizedParameters {
gov_params,
pgf_params: finalized_pgf_params,
eth_bridge_params,
cometbft_params,
}
}
}
Expand Down
90 changes: 90 additions & 0 deletions crates/apps/src/lib/config/genesis/templates.rs
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,8 @@ pub struct Parameters<T: TemplateValidation> {
pub gov_params: GovernanceParams,
pub pgf_params: PgfParams<T>,
pub eth_bridge_params: Option<EthBridgeParams>,
#[serde(default)]
pub cometbft_params: CometBftParams,
}

#[derive(
Expand Down Expand Up @@ -486,6 +488,92 @@ pub struct EthBridgeParams {
pub contracts: Contracts,
}

#[derive(
Clone,
Debug,
Default,
Deserialize,
Serialize,
BorshDeserialize,
BorshSerialize,
PartialEq,
Eq,
)]
pub struct CometBftParams {
/// Block size parameters
pub block: Option<BlockParams>,

/// Validator parameters
pub validator: Option<ValidatorParams>,

/// Version parameters
pub version: Option<VersionParams>,
}

#[derive(
Clone,
Debug,
Deserialize,
Serialize,
BorshDeserialize,
BorshSerialize,
PartialEq,
Eq,
)]
pub struct BlockParams {
/// Maximum number of bytes in a block
pub max_bytes: u64,
/// Maximum amount of gas which can be spent on a block
pub max_gas: i64,
/// This parameter has no value anymore in Tendermint-core
pub time_iota_ms: i64,
}

#[derive(
Clone,
Debug,
Deserialize,
Serialize,
BorshDeserialize,
BorshSerialize,
PartialEq,
Eq,
PartialOrd,
Ord,
)]
pub enum KeyScheme {
Ed22519,
Secp256k1,
}

#[derive(
Clone,
Debug,
Deserialize,
Serialize,
BorshDeserialize,
BorshSerialize,
PartialEq,
Eq,
)]
pub struct ValidatorParams {
pub pub_key_types: Vec<KeyScheme>,
}

#[derive(
Clone,
Debug,
Deserialize,
Serialize,
BorshDeserialize,
BorshSerialize,
PartialEq,
Eq,
)]
pub struct VersionParams {
pub app: u64,
}

impl TokenBalances {
pub fn get(&self, addr: &GenesisAddress) -> Option<token::Amount> {
self.0.get(addr).map(|amt| amt.amount())
Expand Down Expand Up @@ -857,6 +945,7 @@ pub fn validate_parameters(
gov_params,
pgf_params,
eth_bridge_params,
cometbft_params,
} = parameters;
match parameters.denominate(tokens) {
Err(e) => {
Expand All @@ -874,6 +963,7 @@ pub fn validate_parameters(
valid: Default::default(),
},
eth_bridge_params,
cometbft_params,
}),
}
}
Expand Down
41 changes: 39 additions & 2 deletions crates/apps/src/lib/node/ledger/tendermint_node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use std::process::Stdio;
use std::str::FromStr;

use borsh_ext::BorshSerializeExt;
use itertools::Itertools;
use namada::core::chain::ChainId;
use namada::core::key::*;
use namada::core::storage::BlockHeight;
Expand All @@ -19,7 +20,11 @@ use tokio::sync::oneshot::{Receiver, Sender};

use crate::cli::namada_version;
use crate::config;
use crate::config::genesis;
use crate::config::genesis::templates::KeyScheme;
use crate::facade::tendermint::consensus::params;
use crate::facade::tendermint::node::Id as TendermintNodeId;
use crate::facade::tendermint::public_key::Algorithm;
use crate::facade::tendermint::{block, Genesis, Moniker};
use crate::facade::tendermint_config::{
Error as TendermintError, TendermintConfig,
Expand Down Expand Up @@ -116,7 +121,8 @@ async fn initalize_config(
panic!("Tendermint failed to initialize with {:#?}", output);
}

write_tm_genesis(&home_dir, chain_id, genesis_time).await?;
write_tm_genesis(&home_dir, config.shell.base_dir, chain_id, genesis_time)
.await?;

update_tendermint_config(&home_dir, config.cometbft).await?;
Ok((home_dir_string, tendermint_path))
Expand Down Expand Up @@ -429,6 +435,7 @@ async fn update_tendermint_config(

async fn write_tm_genesis(
home_dir: impl AsRef<Path>,
base_dir: impl AsRef<Path>,
chain_id: ChainId,
genesis_time: DateTimeUtc,
) -> Result<()> {
Expand All @@ -439,6 +446,12 @@ async fn write_tm_genesis(
path, err
)
});
let namada_genesis = {
let chain_dir = base_dir.as_ref().join(chain_id.to_string());
genesis::chain::Finalized::read_toml_files(&chain_dir)
.expect("Missing genesis files")
};
let cometbft_genesis_params = namada_genesis.parameters.cometbft_params;
let mut file_contents = vec![];
file.read_to_end(&mut file_contents)
.await
Expand All @@ -464,7 +477,31 @@ async fn write_tm_genesis(
// This parameter has no value anymore in Tendermint-core
time_iota_ms: block::Size::default_time_iota_ms(),
};
genesis.consensus_params.block = size;
genesis.consensus_params.block =
cometbft_genesis_params
.block
.map_or(size, |size| block::Size {
max_bytes: size.max_bytes,
max_gas: size.max_gas,
time_iota_ms: size.time_iota_ms,
});
genesis.consensus_params.validator.pub_key_types = cometbft_genesis_params
.validator
.map(|val| {
val.pub_key_types
.into_iter()
.sorted()
.dedup()
.map(|scheme| match scheme {
KeyScheme::Ed22519 => Algorithm::Ed25519,
KeyScheme::Secp256k1 => Algorithm::Secp256k1,
})
.collect()
})
.unwrap_or_default();
genesis.consensus_params.version = cometbft_genesis_params
.version
.map(|v| params::VersionParams { app: v.app });

let mut file = OpenOptions::new()
.write(true)
Expand Down
12 changes: 11 additions & 1 deletion crates/core/src/key/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,17 @@ pub trait TryFromRef<T: ?Sized>: Sized {
}

/// Type capturing signature scheme IDs
#[derive(PartialEq, Eq, Copy, Clone, Debug)]
#[derive(
PartialEq,
Eq,
Copy,
Clone,
Debug,
Serialize,
Deserialize,
BorshSerialize,
BorshDeserialize,
)]
pub enum SchemeType {
/// Type identifier for Ed25519 scheme
Ed25519,
Expand Down