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

update tendermint config v2 #1570

Closed
wants to merge 14 commits into from
2 changes: 2 additions & 0 deletions .changelog/unreleased/features/1570-tendermint-config.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- Enable users to change any tendermint config options via namada config.
([#1570](https://github.com/anoma/namada/pull/1570))
2 changes: 2 additions & 0 deletions .changelog/unreleased/miscellaneous/1476-cometbft.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- Switch from unreleased Tendermint fork to an official CometBFT release
v0.37.1. ([\#1476](https://github.com/anoma/namada/pull/1476))
6 changes: 0 additions & 6 deletions .github/workflows/build-and-test-bridge.yml
Original file line number Diff line number Diff line change
Expand Up @@ -440,12 +440,6 @@ jobs:
run: |
wget -q -O- https://github.com/rui314/mold/releases/download/v${{ matrix.mold_version }}/mold-${{ matrix.mold_version }}-x86_64-linux.tar.gz | tar -xz
mv mold-${{ matrix.mold_version }}-x86_64-linux/bin/mold /usr/local/bin
- name: Download masp parameters
run: |
mkdir /home/runner/work/masp
curl -o /home/runner/work/masp/masp-spend.params -sLO https://github.com/anoma/masp-mpc/releases/download/namada-trusted-setup/masp-spend.params?raw=true
curl -o /home/runner/work/masp/masp-output.params -sLO https://github.com/anoma/masp-mpc/releases/download/namada-trusted-setup/masp-output.params?raw=true
curl -o /home/runner/work/masp/masp-convert.params -sLO https://github.com/anoma/masp-mpc/releases/download/namada-trusted-setup/masp-convert.params?raw=true
- name: Build
run: make build
env:
Expand Down
5 changes: 1 addition & 4 deletions apps/src/bin/namada-node/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,12 @@ use namada_apps::node::ledger;

pub fn main() -> Result<()> {
let (cmd, mut ctx) = cli::namada_node_cli()?;
if let Some(mode) = ctx.global_args.mode.clone() {
ctx.config.ledger.tendermint.tendermint_mode = mode;
}

match cmd {
cmds::NamadaNode::Ledger(sub) => match sub {
cmds::Ledger::Run(cmds::LedgerRun(args)) => {
let wasm_dir = ctx.wasm_dir();
sleep_until(args.start_time);
ctx.config.ledger.tendermint.tx_index = args.tx_index;
ledger::run(ctx.config.ledger, wasm_dir);
}
cmds::Ledger::RunUntil(cmds::LedgerRunUntil(args)) => {
Expand Down
24 changes: 2 additions & 22 deletions apps/src/lib/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -843,7 +843,6 @@ pub mod cmds {
// The `run` command is the default if no sub-command given
.or(Some(Self::Run(LedgerRun(args::LedgerRun {
start_time: None,
tx_index: false,
}))))
})
}
Expand Down Expand Up @@ -1777,7 +1776,7 @@ pub mod args {
use super::context::*;
use super::utils::*;
use super::{ArgGroup, ArgMatches};
use crate::config::{self, Action, ActionAtHeight, TendermintMode};
use crate::config::{self, Action, ActionAtHeight};
use crate::facade::tendermint::Timeout;
use crate::facade::tendermint_config::net::Address as TendermintAddress;

Expand Down Expand Up @@ -1864,7 +1863,6 @@ pub mod args {
pub const MASP_VALUE: Arg<MaspValue> = arg("value");
pub const MAX_COMMISSION_RATE_CHANGE: Arg<Decimal> =
arg("max-commission-rate-change");
pub const MODE: ArgOpt<String> = arg_opt("mode");
pub const NET_ADDRESS: Arg<SocketAddr> = arg("net-address");
pub const NAMADA_START_TIME: ArgOpt<DateTimeUtc> = arg_opt("time");
pub const NO_CONVERSIONS: ArgFlag = flag("no-conversions");
Expand Down Expand Up @@ -1901,7 +1899,6 @@ pub mod args {
pub const STORAGE_KEY: Arg<storage::Key> = arg("storage-key");
pub const SUB_PREFIX: ArgOpt<String> = arg_opt("sub-prefix");
pub const SUSPEND_ACTION: ArgFlag = flag("suspend");
pub const TENDERMINT_TX_INDEX: ArgFlag = flag("tx-index");
pub const TIMEOUT_HEIGHT: ArgOpt<u64> = arg_opt("timeout-height");
pub const TIMEOUT_SEC_OFFSET: ArgOpt<u64> = arg_opt("timeout-sec-offset");
pub const TM_ADDRESS: Arg<String> = arg("tm-address");
Expand Down Expand Up @@ -1932,7 +1929,6 @@ pub mod args {
pub chain_id: Option<ChainId>,
pub base_dir: PathBuf,
pub wasm_dir: Option<PathBuf>,
pub mode: Option<TendermintMode>,
}

impl Global {
Expand All @@ -1941,12 +1937,10 @@ pub mod args {
let chain_id = CHAIN_ID_OPT.parse(matches);
let base_dir = BASE_DIR.parse(matches);
let wasm_dir = WASM_DIR.parse(matches);
let mode = MODE.parse(matches).map(TendermintMode::from);
Global {
chain_id,
base_dir,
wasm_dir,
mode,
}
}

Expand All @@ -1970,27 +1964,18 @@ pub mod args {
`NAMADA_WASM_DIR` environment variable, but the argument \
takes precedence, if specified.",
))
.arg(MODE.def().about(
"The mode in which to run Namada. Options are \n\t * \
Validator (default)\n\t * Full\n\t * Seed",
))
}
}

#[derive(Clone, Debug)]
pub struct LedgerRun {
pub start_time: Option<DateTimeUtc>,
pub tx_index: bool,
}

impl Args for LedgerRun {
fn parse(matches: &ArgMatches) -> Self {
let start_time = NAMADA_START_TIME.parse(matches);
let tx_index = TENDERMINT_TX_INDEX.parse(matches);
Self {
start_time,
tx_index,
}
Self { start_time }
}

fn def(app: App) -> App {
Expand All @@ -2002,11 +1987,6 @@ pub mod args {
equivalent:\n2023-01-20T12:12:12Z\n2023-01-20 \
12:12:12Z\n2023- 01-20T12: 12:12Z",
))
.arg(
TENDERMINT_TX_INDEX
.def()
.about("Enable Tendermint tx indexing."),
)
}
}

Expand Down
2 changes: 1 addition & 1 deletion apps/src/lib/cli/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ impl Context {
let mut config = Config::load(
&global_args.base_dir,
&global_config.default_chain_id,
global_args.mode.clone(),
None,
);

let chain_dir = global_args
Expand Down
5 changes: 2 additions & 3 deletions apps/src/lib/client/tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -292,14 +292,13 @@ pub async fn submit_init_validator<
crate::wallet::save(&ctx.wallet)
.unwrap_or_else(|err| eprintln!("{}", err));

let tendermint_home = ctx.config.ledger.tendermint_dir();
let tendermint_home = ctx.config.ledger.cometbft_dir();
tendermint_node::write_validator_key(&tendermint_home, &consensus_key);
tendermint_node::write_validator_state(tendermint_home);

// Write Namada config stuff or figure out how to do the above
// tendermint_node things two epochs in the future!!!
ctx.config.ledger.tendermint.tendermint_mode =
TendermintMode::Validator;
ctx.config.ledger.shell.tendermint_mode = TendermintMode::Validator;
ctx.config
.write(
&ctx.config.ledger.shell.base_dir,
Expand Down
109 changes: 48 additions & 61 deletions apps/src/lib/client/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::collections::HashMap;
use std::env;
use std::fs::{self, File, OpenOptions};
use std::io::Write;
use std::net::{IpAddr, Ipv4Addr, SocketAddr};
use std::net::SocketAddr;
use std::path::{Path, PathBuf};
use std::str::FromStr;

Expand Down Expand Up @@ -233,11 +233,7 @@ pub async fn join_network(
let base_dir = base_dir.clone();
let chain_id = chain_id.clone();
tokio::task::spawn_blocking(move || {
let mut config = Config::load(
&base_dir,
&chain_id,
global_args.mode.clone(),
);
let mut config = Config::load(&base_dir, &chain_id, None);
config.wasm_dir = wasm_dir;
config.write(&base_dir, &chain_id, true).unwrap();
})
Expand Down Expand Up @@ -290,7 +286,7 @@ pub async fn join_network(
})
.clone();

let tm_home_dir = chain_dir.join("tendermint");
let tm_home_dir = chain_dir.join("cometbft");

// Write consensus key to tendermint home
tendermint_node::write_validator_key(
Expand Down Expand Up @@ -323,27 +319,20 @@ pub async fn join_network(
let chain_id = chain_id.clone();
tokio::task::spawn_blocking(move || {
let mut config = Config::load(&base_dir, &chain_id, None);
config.ledger.shell.tendermint_mode = TendermintMode::Validator;

config.ledger.tendermint.tendermint_mode =
TendermintMode::Validator;
// Validator node should turned off peer exchange reactor
config.ledger.tendermint.p2p_pex = false;
// Remove self from persistent peers
config
.ledger
.tendermint
.p2p_persistent_peers
.retain(|peer| {
if let TendermintAddress::Tcp {
peer_id: Some(peer_id),
..
} = peer
{
node_id != *peer_id
} else {
true
}
});
config.ledger.cometbft.p2p.persistent_peers.retain(|peer| {
if let TendermintAddress::Tcp {
peer_id: Some(peer_id),
..
} = peer
{
node_id != *peer_id
} else {
true
}
});
config.write(&base_dir, &chain_id, true).unwrap();
})
.await
Expand Down Expand Up @@ -456,7 +445,7 @@ pub fn init_network(
let validator_dir = accounts_dir.join(name);

let chain_dir = validator_dir.join(&accounts_temp_dir);
let tm_home_dir = chain_dir.join("tendermint");
let tm_home_dir = chain_dir.join("cometbft");

// Find or generate tendermint node key
let node_pk = try_parse_public_key(
Expand Down Expand Up @@ -744,7 +733,7 @@ pub fn init_network(
// directories.
config.ledger.shell.base_dir = config::DEFAULT_BASE_DIR.into();
// Add a ledger P2P persistent peers
config.ledger.tendermint.p2p_persistent_peers = persistent_peers
config.ledger.cometbft.p2p.persistent_peers = persistent_peers
.iter()
.enumerate()
.filter_map(|(index, peer)|
Expand All @@ -755,57 +744,55 @@ pub fn init_network(
None
})
.collect();
config.ledger.tendermint.consensus_timeout_commit =

config.ledger.cometbft.consensus.timeout_commit =
consensus_timeout_commit;
config.ledger.tendermint.p2p_allow_duplicate_ip =
allow_duplicate_ip;
config.ledger.tendermint.p2p_addr_book_strict = !localhost;
config.ledger.cometbft.p2p.allow_duplicate_ip = allow_duplicate_ip;
config.ledger.cometbft.p2p.addr_book_strict = !localhost;
// Clear the net address from the config and use it to set ports
let net_address = validator_config.net_address.take().unwrap();
let ip = SocketAddr::from_str(&net_address).unwrap().ip();
let first_port = SocketAddr::from_str(&net_address).unwrap().port();
if !localhost {
config
.ledger
.tendermint
.p2p_address
.set_ip(IpAddr::V4(Ipv4Addr::new(0, 0, 0, 0)));
config.ledger.cometbft.p2p.laddr = TendermintAddress::from_str(
&format!("0.0.0.0:{}", first_port),
)
.unwrap();
}
config.ledger.tendermint.p2p_address.set_port(first_port);
config.ledger.cometbft.p2p.laddr =
TendermintAddress::from_str(&format!("{}:{}", ip, first_port))
.unwrap();
if !localhost {
config
.ledger
.tendermint
.rpc_address
.set_ip(IpAddr::V4(Ipv4Addr::new(0, 0, 0, 0)));
config.ledger.cometbft.rpc.laddr = TendermintAddress::from_str(
&format!("0.0.0.0:{}", first_port + 1),
)
.unwrap();
}
config
.ledger
.tendermint
.rpc_address
.set_port(first_port + 1);
config.ledger.shell.ledger_address.set_port(first_port + 2);
// Validator node should turned off peer exchange reactor
config.ledger.tendermint.p2p_pex = false;
config.ledger.cometbft.rpc.laddr = TendermintAddress::from_str(
&format!("{}:{}", ip, first_port + 1),
)
.unwrap();

config.ledger.cometbft.proxy_app = TendermintAddress::from_str(
&format!("{}:{}", ip, first_port + 2),
)
.unwrap();

config.write(&validator_dir, &chain_id, true).unwrap();
},
);

// Update the ledger config persistent peers and save it
let mut config = Config::load(&global_args.base_dir, &chain_id, None);
config.ledger.tendermint.p2p_persistent_peers = persistent_peers;
config.ledger.tendermint.consensus_timeout_commit =
consensus_timeout_commit;
config.ledger.tendermint.p2p_allow_duplicate_ip = allow_duplicate_ip;
config.ledger.cometbft.p2p.persistent_peers = persistent_peers;
config.ledger.cometbft.consensus.timeout_commit = consensus_timeout_commit;
config.ledger.cometbft.p2p.allow_duplicate_ip = allow_duplicate_ip;
// Open P2P address
if !localhost {
config
.ledger
.tendermint
.p2p_address
.set_ip(IpAddr::V4(Ipv4Addr::new(0, 0, 0, 0)));
config.ledger.cometbft.p2p.laddr =
TendermintAddress::from_str("0.0.0.0:26656").unwrap();
}
config.ledger.tendermint.p2p_addr_book_strict = !localhost;
config.ledger.cometbft.p2p.addr_book_strict = !localhost;
config.ledger.genesis_time = genesis.genesis_time.into();
config
.write(&global_args.base_dir, &chain_id, true)
Expand Down
Loading