diff --git a/.changelog/unreleased/features/1570-tendermint-config.md b/.changelog/unreleased/features/1570-tendermint-config.md new file mode 100644 index 00000000000..888fda89282 --- /dev/null +++ b/.changelog/unreleased/features/1570-tendermint-config.md @@ -0,0 +1,2 @@ +- Enable users to change any tendermint config options via namada config. + ([#1570](https://github.com/anoma/namada/pull/1570)) \ No newline at end of file diff --git a/.changelog/unreleased/miscellaneous/1476-cometbft.md b/.changelog/unreleased/miscellaneous/1476-cometbft.md new file mode 100644 index 00000000000..a1a23432ac7 --- /dev/null +++ b/.changelog/unreleased/miscellaneous/1476-cometbft.md @@ -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)) \ No newline at end of file diff --git a/.github/workflows/build-and-test-bridge.yml b/.github/workflows/build-and-test-bridge.yml index 1f8399a3d44..1cdba9e6a7d 100644 --- a/.github/workflows/build-and-test-bridge.yml +++ b/.github/workflows/build-and-test-bridge.yml @@ -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: diff --git a/apps/src/bin/namada-node/cli.rs b/apps/src/bin/namada-node/cli.rs index 240e81f90cc..5194921de89 100644 --- a/apps/src/bin/namada-node/cli.rs +++ b/apps/src/bin/namada-node/cli.rs @@ -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)) => { diff --git a/apps/src/lib/cli.rs b/apps/src/lib/cli.rs index 352a7a603ae..b3078037ff7 100644 --- a/apps/src/lib/cli.rs +++ b/apps/src/lib/cli.rs @@ -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, })))) }) } @@ -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; @@ -1864,7 +1863,6 @@ pub mod args { pub const MASP_VALUE: Arg = arg("value"); pub const MAX_COMMISSION_RATE_CHANGE: Arg = arg("max-commission-rate-change"); - pub const MODE: ArgOpt = arg_opt("mode"); pub const NET_ADDRESS: Arg = arg("net-address"); pub const NAMADA_START_TIME: ArgOpt = arg_opt("time"); pub const NO_CONVERSIONS: ArgFlag = flag("no-conversions"); @@ -1901,7 +1899,6 @@ pub mod args { pub const STORAGE_KEY: Arg = arg("storage-key"); pub const SUB_PREFIX: ArgOpt = 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 = arg_opt("timeout-height"); pub const TIMEOUT_SEC_OFFSET: ArgOpt = arg_opt("timeout-sec-offset"); pub const TM_ADDRESS: Arg = arg("tm-address"); @@ -1932,7 +1929,6 @@ pub mod args { pub chain_id: Option, pub base_dir: PathBuf, pub wasm_dir: Option, - pub mode: Option, } impl Global { @@ -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, } } @@ -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, - 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 { @@ -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."), - ) } } diff --git a/apps/src/lib/cli/context.rs b/apps/src/lib/cli/context.rs index 630d329515f..dbe1cec667b 100644 --- a/apps/src/lib/cli/context.rs +++ b/apps/src/lib/cli/context.rs @@ -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 diff --git a/apps/src/lib/client/tx.rs b/apps/src/lib/client/tx.rs index 6bbf8a0ffa9..dc59e56f7e1 100644 --- a/apps/src/lib/client/tx.rs +++ b/apps/src/lib/client/tx.rs @@ -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, diff --git a/apps/src/lib/client/utils.rs b/apps/src/lib/client/utils.rs index 328c2b1a70b..ee63ecb1d26 100644 --- a/apps/src/lib/client/utils.rs +++ b/apps/src/lib/client/utils.rs @@ -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; @@ -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(); }) @@ -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( @@ -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 @@ -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( @@ -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)| @@ -755,37 +744,39 @@ 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(); }, @@ -793,19 +784,15 @@ pub fn init_network( // 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) diff --git a/apps/src/lib/config/mod.rs b/apps/src/lib/config/mod.rs index d2ad05ae734..4a6be155aad 100644 --- a/apps/src/lib/config/mod.rs +++ b/apps/src/lib/config/mod.rs @@ -6,9 +6,7 @@ pub mod utils; use std::fs::{create_dir_all, File}; use std::io::Write; -use std::net::{IpAddr, Ipv4Addr, SocketAddr}; use std::path::{Path, PathBuf}; -use std::str::FromStr; use directories::ProjectDirs; use namada::types::chain::ChainId; @@ -18,8 +16,9 @@ use serde::{Deserialize, Serialize}; use thiserror::Error; use crate::cli; -use crate::facade::tendermint::Timeout; -use crate::facade::tendermint_config::net::Address as TendermintAddress; +use crate::facade::tendermint_config::{ + TendermintConfig, TxIndexConfig, TxIndexer, +}; /// Base directory contains global config and chain directories. pub const DEFAULT_BASE_DIR: &str = ".namada"; @@ -30,8 +29,8 @@ pub const DEFAULT_WASM_DIR: &str = "wasm"; pub const DEFAULT_WASM_CHECKSUMS_FILE: &str = "checksums.json"; /// Chain-specific Namada configuration. Nested in chain dirs. pub const FILENAME: &str = "config.toml"; -/// Chain-specific Tendermint configuration. Nested in chain dirs. -pub const TENDERMINT_DIR: &str = "tendermint"; +/// Chain-specific CometBFT configuration. Nested in chain dirs. +pub const COMETBFT_DIR: &str = "cometbft"; /// Chain-specific Namada DB. Nested in chain dirs. pub const DB_DIR: &str = "db"; @@ -95,13 +94,13 @@ pub struct Ledger { pub genesis_time: Rfc3339String, pub chain_id: ChainId, pub shell: Shell, - pub tendermint: Tendermint, + pub cometbft: TendermintConfig, } #[derive(Clone, Debug, Serialize, Deserialize)] pub struct Shell { pub base_dir: PathBuf, - pub ledger_address: SocketAddr, + // pub ledger_address: SocketAddr, /// RocksDB block cache maximum size in bytes. /// When not set, defaults to 1/3 of the available memory. pub block_cache_bytes: Option, @@ -116,40 +115,12 @@ pub struct Shell { pub storage_read_past_height_limit: Option, /// Use the [`Ledger::db_dir()`] method to read the value. db_dir: PathBuf, - /// Use the [`Ledger::tendermint_dir()`] method to read the value. - tendermint_dir: PathBuf, + /// Use the [`Ledger::cometbft_dir()`] method to read the value. + cometbft_dir: PathBuf, /// An optional action to take when a given blockheight is reached. pub action_at_height: Option, -} - -#[derive(Clone, Debug, Serialize, Deserialize)] -pub struct Tendermint { - pub rpc_address: SocketAddr, - pub p2p_address: SocketAddr, - /// The persistent peers addresses must include node ID - pub p2p_persistent_peers: Vec, - /// Turns the peer exchange reactor on or off. Validator node will want the - /// pex turned off. - pub p2p_pex: bool, - /// Toggle to disable guard against peers connecting from the same IP - pub p2p_allow_duplicate_ip: bool, - /// Set `true` for strict address routability rules - /// Set `false` for private or local networks - pub p2p_addr_book_strict: bool, - /// Tendermint Consensus Parameters - pub consensus_timeout_propose: Timeout, - pub consensus_timeout_propose_delta: Timeout, - pub consensus_timeout_prevote: Timeout, - pub consensus_timeout_prevote_delta: Timeout, - pub consensus_timeout_precommit: Timeout, - pub consensus_timeout_precommit_delta: Timeout, - pub consensus_timeout_commit: Timeout, + /// Specify if tendermint is started as validator, fullnode or seednode pub tendermint_mode: TendermintMode, - pub instrumentation_prometheus: bool, - pub instrumentation_prometheus_listen_addr: SocketAddr, - pub instrumentation_namespace: String, - /// Toggle to enable tx indexing - pub tx_index: bool, } impl Ledger { @@ -158,56 +129,28 @@ impl Ledger { chain_id: ChainId, mode: TendermintMode, ) -> Self { + let mut tendermint_config = + TendermintConfig::parse_toml(DEFAULT_COMETBFT_CONFIG).unwrap(); + tendermint_config.instrumentation.namespace = "namada_tm".to_string(); + tendermint_config.tx_index = TxIndexConfig { + indexer: TxIndexer::Null, + }; Self { genesis_time: Rfc3339String("1970-01-01T00:00:00Z".to_owned()), chain_id, shell: Shell { base_dir: base_dir.as_ref().to_owned(), - ledger_address: SocketAddr::new( - IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), - 26658, - ), block_cache_bytes: None, vp_wasm_compilation_cache_bytes: None, tx_wasm_compilation_cache_bytes: None, // Default corresponds to 1 hour of past blocks at 1 block/sec storage_read_past_height_limit: Some(3600), db_dir: DB_DIR.into(), - tendermint_dir: TENDERMINT_DIR.into(), + cometbft_dir: COMETBFT_DIR.into(), action_at_height: None, - }, - tendermint: Tendermint { - rpc_address: SocketAddr::new( - IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), - 26657, - ), - p2p_address: SocketAddr::new( - IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), - 26656, - ), - p2p_persistent_peers: vec![], - p2p_pex: true, - p2p_allow_duplicate_ip: false, - p2p_addr_book_strict: true, - consensus_timeout_propose: Timeout::from_str("3s").unwrap(), - consensus_timeout_propose_delta: Timeout::from_str("500ms") - .unwrap(), - consensus_timeout_prevote: Timeout::from_str("1s").unwrap(), - consensus_timeout_prevote_delta: Timeout::from_str("500ms") - .unwrap(), - consensus_timeout_precommit: Timeout::from_str("1s").unwrap(), - consensus_timeout_precommit_delta: Timeout::from_str("500ms") - .unwrap(), - consensus_timeout_commit: Timeout::from_str("1s").unwrap(), tendermint_mode: mode, - instrumentation_prometheus: false, - instrumentation_prometheus_listen_addr: SocketAddr::new( - IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), - 26661, - ), - instrumentation_namespace: "namadan_tm".to_string(), - tx_index: false, }, + cometbft: tendermint_config, } } @@ -222,8 +165,8 @@ impl Ledger { } /// Get the directory path to Tendermint - pub fn tendermint_dir(&self) -> PathBuf { - self.shell.tendermint_dir(&self.chain_id) + pub fn cometbft_dir(&self) -> PathBuf { + self.shell.cometbft_dir(&self.chain_id) } } @@ -234,10 +177,10 @@ impl Shell { } /// Get the directory path to Tendermint - pub fn tendermint_dir(&self, chain_id: &ChainId) -> PathBuf { + pub fn cometbft_dir(&self, chain_id: &ChainId) -> PathBuf { self.base_dir .join(chain_id.as_str()) - .join(&self.tendermint_dir) + .join(&self.cometbft_dir) } } @@ -421,3 +364,490 @@ And this is correct nested:Nested, } "#; + +pub const DEFAULT_COMETBFT_CONFIG: &str = r#" + +# This is a TOML config file. +# For more information, see https://github.com/toml-lang/toml + +# NOTE: Any path below can be absolute (e.g. "/var/myawesomeapp/data") or +# relative to the home directory (e.g. "data"). The home directory is +# "$HOME/.cometbft" by default, but could be changed via $CMTHOME env variable +# or --home cmd flag. + +####################################################################### +### Main Base Config Options ### +####################################################################### + +# TCP or UNIX socket address of the ABCI application, +# or the name of an ABCI application compiled in with the CometBFT binary +proxy_app = "tcp://127.0.0.1:26658" + +# A custom human readable name for this node +moniker = "technodrome" + +# If this node is many blocks behind the tip of the chain, BlockSync +# allows them to catchup quickly by downloading blocks in parallel +# and verifying their commits +# +# Deprecated: this key will be removed and BlockSync will be enabled +# unconditionally in the next major release. +block_sync = true + +# Database backend: goleveldb | cleveldb | boltdb | rocksdb | badgerdb +# * goleveldb (github.com/syndtr/goleveldb - most popular implementation) +# - pure go +# - stable +# * cleveldb (uses levigo wrapper) +# - fast +# - requires gcc +# - use cleveldb build tag (go build -tags cleveldb) +# * boltdb (uses etcd's fork of bolt - github.com/etcd-io/bbolt) +# - EXPERIMENTAL +# - may be faster is some use-cases (random reads - indexer) +# - use boltdb build tag (go build -tags boltdb) +# * rocksdb (uses github.com/tecbot/gorocksdb) +# - EXPERIMENTAL +# - requires gcc +# - use rocksdb build tag (go build -tags rocksdb) +# * badgerdb (uses github.com/dgraph-io/badger) +# - EXPERIMENTAL +# - use badgerdb build tag (go build -tags badgerdb) +db_backend = "goleveldb" + +# Database directory +db_dir = "data" + +# Output level for logging, including package level options +log_level = "info" + +# Output format: 'plain' (colored text) or 'json' +log_format = "plain" + +##### additional base config options ##### + +# Path to the JSON file containing the initial validator set and other meta data +genesis_file = "config/genesis.json" + +# Path to the JSON file containing the private key to use as a validator in the consensus protocol +priv_validator_key_file = "config/priv_validator_key.json" + +# Path to the JSON file containing the last sign state of a validator +priv_validator_state_file = "data/priv_validator_state.json" + +# TCP or UNIX socket address for CometBFT to listen on for +# connections from an external PrivValidator process +priv_validator_laddr = "" + +# Path to the JSON file containing the private key to use for node authentication in the p2p protocol +node_key_file = "config/node_key.json" + +# Mechanism to connect to the ABCI application: socket | grpc +abci = "socket" + +# If true, query the ABCI app on connecting to a new peer +# so the app can decide if we should keep the connection or not +filter_peers = false + + +####################################################################### +### Advanced Configuration Options ### +####################################################################### + +####################################################### +### RPC Server Configuration Options ### +####################################################### +[rpc] + +# TCP or UNIX socket address for the RPC server to listen on +laddr = "tcp://127.0.0.1:26657" + +# A list of origins a cross-domain request can be executed from +# Default value '[]' disables cors support +# Use '["*"]' to allow any origin +cors_allowed_origins = [] + +# A list of methods the client is allowed to use with cross-domain requests +cors_allowed_methods = ["HEAD", "GET", "POST", ] + +# A list of non simple headers the client is allowed to use with cross-domain requests +cors_allowed_headers = ["Origin", "Accept", "Content-Type", "X-Requested-With", "X-Server-Time", ] + +# TCP or UNIX socket address for the gRPC server to listen on +# NOTE: This server only supports /broadcast_tx_commit +grpc_laddr = "" + +# Maximum number of simultaneous connections. +# Does not include RPC (HTTP&WebSocket) connections. See max_open_connections +# If you want to accept a larger number than the default, make sure +# you increase your OS limits. +# 0 - unlimited. +# Should be < {ulimit -Sn} - {MaxNumInboundPeers} - {MaxNumOutboundPeers} - {N of wal, db and other open files} +# 1024 - 40 - 10 - 50 = 924 = ~900 +grpc_max_open_connections = 900 + +# Activate unsafe RPC commands like /dial_seeds and /unsafe_flush_mempool +unsafe = false + +# Maximum number of simultaneous connections (including WebSocket). +# Does not include gRPC connections. See grpc_max_open_connections +# If you want to accept a larger number than the default, make sure +# you increase your OS limits. +# 0 - unlimited. +# Should be < {ulimit -Sn} - {MaxNumInboundPeers} - {MaxNumOutboundPeers} - {N of wal, db and other open files} +# 1024 - 40 - 10 - 50 = 924 = ~900 +max_open_connections = 900 + +# Maximum number of unique clientIDs that can /subscribe +# If you're using /broadcast_tx_commit, set to the estimated maximum number +# of broadcast_tx_commit calls per block. +max_subscription_clients = 100 + +# Maximum number of unique queries a given client can /subscribe to +# If you're using GRPC (or Local RPC client) and /broadcast_tx_commit, set to +# the estimated # maximum number of broadcast_tx_commit calls per block. +max_subscriptions_per_client = 5 + +# Experimental parameter to specify the maximum number of events a node will +# buffer, per subscription, before returning an error and closing the +# subscription. Must be set to at least 100, but higher values will accommodate +# higher event throughput rates (and will use more memory). +experimental_subscription_buffer_size = 200 + +# Experimental parameter to specify the maximum number of RPC responses that +# can be buffered per WebSocket client. If clients cannot read from the +# WebSocket endpoint fast enough, they will be disconnected, so increasing this +# parameter may reduce the chances of them being disconnected (but will cause +# the node to use more memory). +# +# Must be at least the same as "experimental_subscription_buffer_size", +# otherwise connections could be dropped unnecessarily. This value should +# ideally be somewhat higher than "experimental_subscription_buffer_size" to +# accommodate non-subscription-related RPC responses. +experimental_websocket_write_buffer_size = 200 + +# If a WebSocket client cannot read fast enough, at present we may +# silently drop events instead of generating an error or disconnecting the +# client. +# +# Enabling this experimental parameter will cause the WebSocket connection to +# be closed instead if it cannot read fast enough, allowing for greater +# predictability in subscription behavior. +experimental_close_on_slow_client = false + +# How long to wait for a tx to be committed during /broadcast_tx_commit. +# WARNING: Using a value larger than 10s will result in increasing the +# global HTTP write timeout, which applies to all connections and endpoints. +# See https://github.com/tendermint/tendermint/issues/3435 +timeout_broadcast_tx_commit = "10s" + +# Maximum size of request body, in bytes +max_body_bytes = 1000000 + +# Maximum size of request header, in bytes +max_header_bytes = 1048576 + +# The path to a file containing certificate that is used to create the HTTPS server. +# Might be either absolute path or path related to CometBFT's config directory. +# If the certificate is signed by a certificate authority, +# the certFile should be the concatenation of the server's certificate, any intermediates, +# and the CA's certificate. +# NOTE: both tls_cert_file and tls_key_file must be present for CometBFT to create HTTPS server. +# Otherwise, HTTP server is run. +tls_cert_file = "" + +# The path to a file containing matching private key that is used to create the HTTPS server. +# Might be either absolute path or path related to CometBFT's config directory. +# NOTE: both tls-cert-file and tls-key-file must be present for CometBFT to create HTTPS server. +# Otherwise, HTTP server is run. +tls_key_file = "" + +# pprof listen address (https://golang.org/pkg/net/http/pprof) +pprof_laddr = "" + +####################################################### +### P2P Configuration Options ### +####################################################### +[p2p] + +# Address to listen for incoming connections +laddr = "tcp://0.0.0.0:26656" + +# Address to advertise to peers for them to dial +# If empty, will use the same port as the laddr, +# and will introspect on the listener or use UPnP +# to figure out the address. ip and port are required +# example: 159.89.10.97:26656 +external_address = "" + +# Comma separated list of seed nodes to connect to +seeds = "" + +# Comma separated list of nodes to keep persistent connections to +persistent_peers = "" + +# UPNP port forwarding +upnp = false + +# Path to address book +addr_book_file = "config/addrbook.json" + +# Set true for strict address routability rules +# Set false for private or local networks +addr_book_strict = true + +# Maximum number of inbound peers +max_num_inbound_peers = 40 + +# Maximum number of outbound peers to connect to, excluding persistent peers +max_num_outbound_peers = 10 + +# List of node IDs, to which a connection will be (re)established ignoring any existing limits +unconditional_peer_ids = "" + +# Maximum pause when redialing a persistent peer (if zero, exponential backoff is used) +persistent_peers_max_dial_period = "0s" + +# Time to wait before flushing messages out on the connection +flush_throttle_timeout = "100ms" + +# Maximum size of a message packet payload, in bytes +max_packet_msg_payload_size = 1024 + +# Rate at which packets can be sent, in bytes/second +send_rate = 5120000 + +# Rate at which packets can be received, in bytes/second +recv_rate = 5120000 + +# Set true to enable the peer-exchange reactor +pex = true + +# Seed mode, in which node constantly crawls the network and looks for +# peers. If another node asks it for addresses, it responds and disconnects. +# +# Does not work if the peer-exchange reactor is disabled. +seed_mode = false + +# Comma separated list of peer IDs to keep private (will not be gossiped to other peers) +private_peer_ids = "" + +# Toggle to disable guard against peers connecting from the same ip. +allow_duplicate_ip = false + +# Peer connection configuration. +handshake_timeout = "20s" +dial_timeout = "3s" + +####################################################### +### Mempool Configuration Option ### +####################################################### +[mempool] + +# Mempool version to use: +# 1) "v0" - (default) FIFO mempool. +# 2) "v1" - prioritized mempool (deprecated; will be removed in the next release). +version = "v0" + +recheck = true +broadcast = true +wal_dir = "" + +# Maximum number of transactions in the mempool +size = 5000 + +# Limit the total size of all txs in the mempool. +# This only accounts for raw transactions (e.g. given 1MB transactions and +# max_txs_bytes=5MB, mempool will only accept 5 transactions). +max_txs_bytes = 1073741824 + +# Size of the cache (used to filter transactions we saw earlier) in transactions +cache_size = 10000 + +# Do not remove invalid transactions from the cache (default: false) +# Set to true if it's not possible for any invalid transaction to become valid +# again in the future. +keep-invalid-txs-in-cache = false + +# Maximum size of a single transaction. +# NOTE: the max size of a tx transmitted over the network is {max_tx_bytes}. +max_tx_bytes = 1048576 + +# Maximum size of a batch of transactions to send to a peer +# Including space needed by encoding (one varint per transaction). +# XXX: Unused due to https://github.com/tendermint/tendermint/issues/5796 +max_batch_bytes = 0 + +# ttl-duration, if non-zero, defines the maximum amount of time a transaction +# can exist for in the mempool. +# +# Note, if ttl-num-blocks is also defined, a transaction will be removed if it +# has existed in the mempool at least ttl-num-blocks number of blocks or if it's +# insertion time into the mempool is beyond ttl-duration. +ttl-duration = "0s" + +# ttl-num-blocks, if non-zero, defines the maximum number of blocks a transaction +# can exist for in the mempool. +# +# Note, if ttl-duration is also defined, a transaction will be removed if it +# has existed in the mempool at least ttl-num-blocks number of blocks or if +# it's insertion time into the mempool is beyond ttl-duration. +ttl-num-blocks = 0 + +####################################################### +### State Sync Configuration Options ### +####################################################### +[statesync] +# State sync rapidly bootstraps a new node by discovering, fetching, and restoring a state machine +# snapshot from peers instead of fetching and replaying historical blocks. Requires some peers in +# the network to take and serve state machine snapshots. State sync is not attempted if the node +# has any local state (LastBlockHeight > 0). The node will have a truncated block history, +# starting from the height of the snapshot. +enable = false + +# RPC servers (comma-separated) for light client verification of the synced state machine and +# retrieval of state data for node bootstrapping. Also needs a trusted height and corresponding +# header hash obtained from a trusted source, and a period during which validators can be trusted. +# +# For Cosmos SDK-based chains, trust_period should usually be about 2/3 of the unbonding time (~2 +# weeks) during which they can be financially punished (slashed) for misbehavior. +rpc_servers = "" +trust_height = 0 +trust_hash = "" +trust_period = "168h0m0s" + +# Time to spend discovering snapshots before initiating a restore. +discovery_time = "15s" + +# Temporary directory for state sync snapshot chunks, defaults to the OS tempdir (typically /tmp). +# Will create a new, randomly named directory within, and remove it when done. +temp_dir = "" + +# The timeout duration before re-requesting a chunk, possibly from a different +# peer (default: 1 minute). +chunk_request_timeout = "10s" + +# The number of concurrent chunk fetchers to run (default: 1). +chunk_fetchers = "4" + +####################################################### +### Block Sync Configuration Options ### +####################################################### +[blocksync] + +# Block Sync version to use: +# +# In v0.37, v1 and v2 of the block sync protocols were deprecated. +# Please use v0 instead. +# +# 1) "v0" - the default block sync implementation +version = "v0" + +####################################################### +### Consensus Configuration Options ### +####################################################### +[consensus] + +wal_file = "data/cs.wal/wal" + +# How long we wait for a proposal block before prevoting nil +timeout_propose = "3s" +# How much timeout_propose increases with each round +timeout_propose_delta = "500ms" +# How long we wait after receiving +2/3 prevotes for “anything” (ie. not a single block or nil) +timeout_prevote = "1s" +# How much the timeout_prevote increases with each round +timeout_prevote_delta = "500ms" +# How long we wait after receiving +2/3 precommits for “anything” (ie. not a single block or nil) +timeout_precommit = "1s" +# How much the timeout_precommit increases with each round +timeout_precommit_delta = "500ms" +# How long we wait after committing a block, before starting on the new +# height (this gives us a chance to receive some more precommits, even +# though we already have +2/3). +timeout_commit = "1s" + +# How many blocks to look back to check existence of the node's consensus votes before joining consensus +# When non-zero, the node will panic upon restart +# if the same consensus key was used to sign {double_sign_check_height} last blocks. +# So, validators should stop the state machine, wait for some blocks, and then restart the state machine to avoid panic. +double_sign_check_height = 0 + +# Make progress as soon as we have all the precommits (as if TimeoutCommit = 0) +skip_timeout_commit = false + +# EmptyBlocks mode and possible interval between empty blocks +create_empty_blocks = true +create_empty_blocks_interval = "0s" + +# Reactor sleep duration parameters +peer_gossip_sleep_duration = "100ms" +peer_query_maj23_sleep_duration = "2s" + +####################################################### +### Storage Configuration Options ### +####################################################### +[storage] + +# Set to true to discard ABCI responses from the state store, which can save a +# considerable amount of disk space. Set to false to ensure ABCI responses are +# persisted. ABCI responses are required for /block_results RPC queries, and to +# reindex events in the command-line tool. +discard_abci_responses = false + +####################################################### +### Transaction Indexer Configuration Options ### +####################################################### +[tx_index] + +# What indexer to use for transactions +# +# The application will set which txs to index. In some cases a node operator will be able +# to decide which txs to index based on configuration set in the application. +# +# Options: +# 1) "null" +# 2) "kv" (default) - the simplest possible indexer, backed by key-value storage (defaults to levelDB; see DBBackend). +# - When "kv" is chosen "tx.height" and "tx.hash" will always be indexed. +# 3) "psql" - the indexer services backed by PostgreSQL. +# When "kv" or "psql" is chosen "tx.height" and "tx.hash" will always be indexed. +indexer = "kv" + +# The PostgreSQL connection configuration, the connection format: +# postgresql://:@:/? +psql-conn = "" + +####################################################### +### Instrumentation Configuration Options ### +####################################################### +[instrumentation] + +# When true, Prometheus metrics are served under /metrics on +# PrometheusListenAddr. +# Check out the documentation for the list of available metrics. +prometheus = false + +# Address to listen for Prometheus collector(s) connections +prometheus_listen_addr = ":26660" + +# Maximum number of simultaneous connections. +# If you want to accept a larger number than the default, make sure +# you increase your OS limits. +# 0 - unlimited. +max_open_connections = 3 + +# Instrumentation namespace +namespace = "cometbft" + +"#; + +#[cfg(test)] +mod tests { + use super::DEFAULT_COMETBFT_CONFIG; + use crate::facade::tendermint_config::TendermintConfig; + + #[test] + fn test_default_cometbft_config() { + assert!(TendermintConfig::parse_toml(DEFAULT_COMETBFT_CONFIG).is_ok()); + } +} diff --git a/apps/src/lib/config/utils.rs b/apps/src/lib/config/utils.rs index 19b2648d3b0..ca038dcb422 100644 --- a/apps/src/lib/config/utils.rs +++ b/apps/src/lib/config/utils.rs @@ -1,11 +1,13 @@ //! Configuration utilities +use std::net::{SocketAddr, ToSocketAddrs}; use std::str::FromStr; use std::{cmp, env}; use itertools::Either; use crate::cli; +use crate::facade::tendermint_config::net::Address as TendermintAddress; /// Find how many threads to use from an environment variable if it's set and /// valid (>= 1). If the environment variable is invalid, exits the process with @@ -45,6 +47,24 @@ fn num_of_threads_aux( } } +// fixme: Handle this gracefully with either an Option or a Result. Ensure that +// hostname resolution works. +pub fn convert_tm_addr_to_socket_addr( + tm_addr: &TendermintAddress, +) -> SocketAddr { + let tm_addr = tm_addr.clone(); + match tm_addr { + TendermintAddress::Tcp { + peer_id: _, + host, + port, + } => (host, port).to_socket_addrs().unwrap().next().unwrap(), + TendermintAddress::Unix { path: _ } => { + panic!("Unix addresses aren't currently supported.") + } + } +} + #[cfg(test)] mod test { use std::panic; diff --git a/apps/src/lib/node/ledger/broadcaster.rs b/apps/src/lib/node/ledger/broadcaster.rs index 199ab953c1f..915a7eee67c 100644 --- a/apps/src/lib/node/ledger/broadcaster.rs +++ b/apps/src/lib/node/ledger/broadcaster.rs @@ -1,3 +1,5 @@ +use std::net::SocketAddr; + use tokio::sync::mpsc::UnboundedReceiver; use crate::facade::tendermint_rpc::{Client, HttpClient}; @@ -13,7 +15,7 @@ pub struct Broadcaster { impl Broadcaster { /// Create a new broadcaster that will send Http messages /// over the given url. - pub fn new(url: &str, receiver: UnboundedReceiver>) -> Self { + pub fn new(url: SocketAddr, receiver: UnboundedReceiver>) -> Self { Self { client: HttpClient::new(format!("http://{}", url).as_str()) .unwrap(), diff --git a/apps/src/lib/node/ledger/mod.rs b/apps/src/lib/node/ledger/mod.rs index 39a8460ac2b..12f7c312845 100644 --- a/apps/src/lib/node/ledger/mod.rs +++ b/apps/src/lib/node/ledger/mod.rs @@ -23,7 +23,7 @@ use tower::ServiceBuilder; use self::abortable::AbortableSpawner; use self::shims::abcipp_shim::AbciService; use crate::cli::args; -use crate::config::utils::num_of_threads; +use crate::config::utils::{convert_tm_addr_to_socket_addr, num_of_threads}; use crate::config::TendermintMode; use crate::facade::tendermint_proto::abci::CheckTxType; use crate::facade::tower_abci::{response, split, Server}; @@ -408,7 +408,8 @@ fn start_abci_broadcaster_shell( task::JoinHandle<()>, thread::JoinHandle<()>, ) { - let rpc_address = config.tendermint.rpc_address.to_string(); + let rpc_address = + convert_tm_addr_to_socket_addr(&config.cometbft.rpc.laddr); let RunAuxSetup { vp_wasm_compilation_cache, tx_wasm_compilation_cache, @@ -421,38 +422,37 @@ fn start_abci_broadcaster_shell( tokio::sync::mpsc::unbounded_channel(); // Start broadcaster - let broadcaster = if matches!( - config.tendermint.tendermint_mode, - TendermintMode::Validator - ) { - let (bc_abort_send, bc_abort_recv) = - tokio::sync::oneshot::channel::<()>(); - - spawner - .spawn_abortable("Broadcaster", move |aborter| async move { - // Construct a service for broadcasting protocol txs from the - // ledger - let mut broadcaster = - Broadcaster::new(&rpc_address, broadcaster_receiver); - broadcaster.run(bc_abort_recv).await; - tracing::info!("Broadcaster is no longer running."); - - drop(aborter); - }) - .with_cleanup(async move { - let _ = bc_abort_send.send(()); - }) - } else { - spawn_dummy_task(()) - }; + let broadcaster = + if matches!(config.shell.tendermint_mode, TendermintMode::Validator) { + let (bc_abort_send, bc_abort_recv) = + tokio::sync::oneshot::channel::<()>(); + + spawner + .spawn_abortable("Broadcaster", move |aborter| async move { + // Construct a service for broadcasting protocol txs from + // the ledger + let mut broadcaster = + Broadcaster::new(rpc_address, broadcaster_receiver); + broadcaster.run(bc_abort_recv).await; + tracing::info!("Broadcaster is no longer running."); + + drop(aborter); + }) + .with_cleanup(async move { + let _ = bc_abort_send.send(()); + }) + } else { + spawn_dummy_task(()) + }; // Setup DB cache, it must outlive the DB instance that's in the shell let db_cache = rocksdb::Cache::new_lru_cache(db_block_cache_size_bytes as usize); // Construct our ABCI application. - let tendermint_mode = config.tendermint.tendermint_mode.clone(); - let ledger_address = config.shell.ledger_address; + let tendermint_mode = config.shell.tendermint_mode.clone(); + let proxy_app_address = + convert_tm_addr_to_socket_addr(&config.cometbft.proxy_app); #[cfg(not(feature = "dev"))] let genesis = genesis::genesis(&config.shell.base_dir, &config.chain_id); #[cfg(feature = "dev")] @@ -476,7 +476,7 @@ fn start_abci_broadcaster_shell( let res = run_abci( abci_service, service_handle, - ledger_address, + proxy_app_address, abci_abort_recv, ) .await; @@ -513,7 +513,7 @@ fn start_abci_broadcaster_shell( async fn run_abci( abci_service: AbciService, service_handle: tokio::sync::broadcast::Sender<()>, - ledger_address: SocketAddr, + proxy_app_address: SocketAddr, abort_recv: tokio::sync::oneshot::Receiver<()>, ) -> shell::Result<()> { // Split it into components. @@ -541,7 +541,7 @@ async fn run_abci( .unwrap(); tokio::select! { // Run the server with the ABCI service - status = server.listen(ledger_address) => { + status = server.listen(proxy_app_address) => { status.map_err(|err| Error::TowerServer(err.to_string())) }, resp_sender = abort_recv => { @@ -566,17 +566,17 @@ fn start_tendermint( spawner: &mut AbortableSpawner, config: &config::Ledger, ) -> task::JoinHandle> { - let tendermint_dir = config.tendermint_dir(); + let tendermint_dir = config.cometbft_dir(); let chain_id = config.chain_id.clone(); - let ledger_address = config.shell.ledger_address.to_string(); - let tendermint_config = config.tendermint.clone(); + let proxy_app_address = config.cometbft.proxy_app.to_string(); + let config = config.clone(); let genesis_time = config .genesis_time .clone() .try_into() .expect("expected RFC3339 genesis_time"); - // Channel for signalling shut down to Tendermint process + // Channel for signalling shut down to cometbft process let (tm_abort_send, tm_abort_recv) = tokio::sync::oneshot::channel::>(); @@ -586,8 +586,8 @@ fn start_tendermint( tendermint_dir, chain_id, genesis_time, - ledger_address, - tendermint_config, + proxy_app_address, + config, tm_abort_recv, ) .map_err(Error::Tendermint) diff --git a/apps/src/lib/node/ledger/shell/mod.rs b/apps/src/lib/node/ledger/shell/mod.rs index 457d988e935..3605ff49be6 100644 --- a/apps/src/lib/node/ledger/shell/mod.rs +++ b/apps/src/lib/node/ledger/shell/mod.rs @@ -186,8 +186,7 @@ pub fn reset(config: config::Ledger) -> Result<()> { res => res.map_err(Error::RemoveDB)?, }; // reset Tendermint state - tendermint_node::reset(config.tendermint_dir()) - .map_err(Error::Tendermint)?; + tendermint_node::reset(config.cometbft_dir()).map_err(Error::Tendermint)?; Ok(()) } @@ -195,7 +194,7 @@ pub fn rollback(config: config::Ledger) -> Result<()> { // Rollback Tendermint state tracing::info!("Rollback Tendermint state"); let tendermint_block_height = - tendermint_node::rollback(config.tendermint_dir()) + tendermint_node::rollback(config.cometbft_dir()) .map_err(Error::Tendermint)?; // Rollback Namada state @@ -295,7 +294,7 @@ where let chain_id = config.chain_id; let db_path = config.shell.db_dir(&chain_id); let base_dir = config.shell.base_dir; - let mode = config.tendermint.tendermint_mode; + let mode = config.shell.tendermint_mode; let storage_read_past_height_limit = config.shell.storage_read_past_height_limit; if !Path::new(&base_dir).is_dir() { diff --git a/apps/src/lib/node/ledger/tendermint_node.rs b/apps/src/lib/node/ledger/tendermint_node.rs index a69021e83d6..f5583e70100 100644 --- a/apps/src/lib/node/ledger/tendermint_node.rs +++ b/apps/src/lib/node/ledger/tendermint_node.rs @@ -21,31 +21,30 @@ use tokio::process::Command; use crate::cli::namada_version; use crate::config; use crate::facade::tendermint::{block, Genesis}; -use crate::facade::tendermint_config::net::Address as TendermintAddress; use crate::facade::tendermint_config::{ - Error as TendermintError, TendermintConfig, TxIndexConfig, TxIndexer, + Error as TendermintError, TendermintConfig, }; /// Env. var to output Tendermint log to stdout -pub const ENV_VAR_TM_STDOUT: &str = "NAMADA_TM_STDOUT"; +pub const ENV_VAR_TM_STDOUT: &str = "NAMADA_CMT_STDOUT"; #[derive(Error, Debug)] pub enum Error { - #[error("Failed to initialize Tendermint: {0}")] + #[error("Failed to initialize CometBFT: {0}")] Init(std::io::Error), - #[error("Failed to load Tendermint config file: {0}")] + #[error("Failed to load CometBFT config file: {0}")] LoadConfig(TendermintError), - #[error("Failed to open Tendermint config for writing: {0}")] + #[error("Failed to open CometBFT config for writing: {0}")] OpenWriteConfig(std::io::Error), - #[error("Failed to serialize Tendermint config TOML to string: {0}")] + #[error("Failed to serialize CometBFT config TOML to string: {0}")] ConfigSerializeToml(toml::ser::Error), - #[error("Failed to write Tendermint config: {0}")] + #[error("Failed to write CometBFT config: {0}")] WriteConfig(std::io::Error), - #[error("Failed to start up Tendermint node: {0}")] + #[error("Failed to start up CometBFT node: {0}")] StartUp(std::io::Error), #[error("{0}")] Runtime(String), - #[error("Failed to rollback tendermint state: {0}")] + #[error("Failed to rollback CometBFT state: {0}")] RollBack(String), #[error("Failed to convert to String: {0:?}")] TendermintPath(std::ffi::OsString), @@ -53,17 +52,17 @@ pub enum Error { pub type Result = std::result::Result; -/// Check if the TENDERMINT env var has been set and use that as the -/// location of the tendermint binary. Otherwise, assume it is on path +/// Check if the COMET env var has been set and use that as the +/// location of the COMET binary. Otherwise, assume it is on path /// /// Returns an error if the env var is defined but not a valid Unicode. fn from_env_or_default() -> Result { - match std::env::var("TENDERMINT") { + match std::env::var("COMETBFT") { Ok(path) => { - tracing::info!("Using tendermint path from env variable: {}", path); + tracing::info!("Using CometBFT path from env variable: {}", path); Ok(path) } - Err(std::env::VarError::NotPresent) => Ok(String::from("tendermint")), + Err(std::env::VarError::NotPresent) => Ok(String::from("cometbft")), Err(std::env::VarError::NotUnicode(msg)) => { Err(Error::TendermintPath(msg)) } @@ -75,15 +74,15 @@ pub async fn run( home_dir: PathBuf, chain_id: ChainId, genesis_time: DateTimeUtc, - ledger_address: String, - config: config::Tendermint, + proxy_app_address: String, + config: config::Ledger, abort_recv: tokio::sync::oneshot::Receiver< tokio::sync::oneshot::Sender<()>, >, ) -> Result<()> { let home_dir_string = home_dir.to_string_lossy().to_string(); let tendermint_path = from_env_or_default()?; - let mode = config.tendermint_mode.to_str().to_owned(); + let mode = config.shell.tendermint_mode.to_str().to_owned(); #[cfg(feature = "dev")] // This has to be checked before we run tendermint init @@ -115,13 +114,13 @@ pub async fn run( #[cfg(not(feature = "abcipp"))] write_tm_genesis(&home_dir, chain_id, genesis_time).await; - update_tendermint_config(&home_dir, config).await?; + update_tendermint_config(&home_dir, config.cometbft).await?; let mut tendermint_node = Command::new(&tendermint_path); tendermint_node.args([ "start", "--proxy_app", - &ledger_address, + &proxy_app_address, "--home", &home_dir_string, ]); @@ -138,7 +137,7 @@ pub async fn run( .kill_on_drop(true) .spawn() .map_err(Error::StartUp)?; - tracing::info!("Tendermint node started"); + tracing::info!("CometBFT node started"); tokio::select! { status = tendermint_node.wait() => { @@ -348,24 +347,16 @@ pub fn write_validator_state(home_dir: impl AsRef) { async fn update_tendermint_config( home_dir: impl AsRef, - tendermint_config: config::Tendermint, + config: TendermintConfig, ) -> Result<()> { let home_dir = home_dir.as_ref(); let path = home_dir.join("config").join("config.toml"); - let mut config = - TendermintConfig::load_toml_file(&path).map_err(Error::LoadConfig)?; + let mut config = config.clone(); config.moniker = Moniker::from_str(&format!("{}-{}", config.moniker, namada_version())) .expect("Invalid moniker"); - config.p2p.laddr = - TendermintAddress::from_str(&tendermint_config.p2p_address.to_string()) - .unwrap(); - config.p2p.persistent_peers = tendermint_config.p2p_persistent_peers; - config.p2p.pex = tendermint_config.p2p_pex; - config.p2p.allow_duplicate_ip = tendermint_config.p2p_allow_duplicate_ip; - // In "dev", only produce blocks when there are txs or when the AppHash // changes config.consensus.create_empty_blocks = true; // !cfg!(feature = "dev"); @@ -375,48 +366,10 @@ async fn update_tendermint_config( // again in the future. config.mempool.keep_invalid_txs_in_cache = false; - config.rpc.laddr = - TendermintAddress::from_str(&tendermint_config.rpc_address.to_string()) - .unwrap(); // Bumped from the default `1_000_000`, because some WASMs can be // quite large config.rpc.max_body_bytes = 2_000_000; - config.instrumentation.prometheus = - tendermint_config.instrumentation_prometheus; - config.instrumentation.prometheus_listen_addr = tendermint_config - .instrumentation_prometheus_listen_addr - .to_string(); - config.instrumentation.namespace = - tendermint_config.instrumentation_namespace; - - #[cfg(feature = "abciplus")] - { - config.consensus.timeout_propose = - tendermint_config.consensus_timeout_propose; - config.consensus.timeout_propose_delta = - tendermint_config.consensus_timeout_propose_delta; - config.consensus.timeout_prevote = - tendermint_config.consensus_timeout_prevote; - config.consensus.timeout_prevote_delta = - tendermint_config.consensus_timeout_prevote_delta; - config.consensus.timeout_precommit = - tendermint_config.consensus_timeout_precommit; - config.consensus.timeout_precommit_delta = - tendermint_config.consensus_timeout_precommit_delta; - config.consensus.timeout_commit = - tendermint_config.consensus_timeout_commit; - } - - let indexer = if tendermint_config.tx_index { - TxIndexer::Kv - } else { - TxIndexer::Null - }; - #[cfg(feature = "abcipp")] - let indexer = [indexer]; - config.tx_index = TxIndexConfig { indexer }; - let mut file = OpenOptions::new() .write(true) .truncate(true) @@ -486,8 +439,8 @@ async fn write_tm_genesis( ) }); let data = serde_json::to_vec_pretty(&genesis) - .expect("Couldn't encode the Tendermint genesis file"); + .expect("Couldn't encode the CometBFT genesis file"); file.write_all(&data[..]) .await - .expect("Couldn't write the Tendermint genesis file"); + .expect("Couldn't write the CometBFT genesis file"); } diff --git a/tests/src/e2e/helpers.rs b/tests/src/e2e/helpers.rs index 3eff517d1da..60dc119051d 100644 --- a/tests/src/e2e/helpers.rs +++ b/tests/src/e2e/helpers.rs @@ -15,6 +15,7 @@ use namada::types::key::*; use namada::types::storage::Epoch; use namada::types::token; use namada_apps::config::genesis::genesis_config; +use namada_apps::config::utils::convert_tm_addr_to_socket_addr; use namada_apps::config::{Config, TendermintMode}; use super::setup::{ @@ -99,7 +100,14 @@ pub fn get_actor_rpc(test: &Test, who: &Who) -> String { }; let config = Config::load(base_dir, &test.net.chain_id, Some(tendermint_mode)); - config.ledger.tendermint.rpc_address.to_string() + let ip = convert_tm_addr_to_socket_addr(&config.ledger.cometbft.rpc.laddr) + .ip() + .to_string(); + let port = + convert_tm_addr_to_socket_addr(&config.ledger.cometbft.rpc.laddr) + .port() + .to_string(); + format!("{}:{}", ip, port) } /// Get the public key of the validator diff --git a/tests/src/e2e/ibc_tests.rs b/tests/src/e2e/ibc_tests.rs index 00ee58d52bd..d43d7de2427 100644 --- a/tests/src/e2e/ibc_tests.rs +++ b/tests/src/e2e/ibc_tests.rs @@ -99,7 +99,7 @@ fn run_ledger_ibc() -> Result<()> { test_a, Who::Validator(0), Bin::Node, - &["ledger", "run", "--tx-index"], + &["ledger", "run"], Some(40) )?; ledger_a.exp_string("Namada ledger node started")?; @@ -108,7 +108,7 @@ fn run_ledger_ibc() -> Result<()> { test_b, Who::Validator(0), Bin::Node, - &["ledger", "run", "--tx-index"], + &["ledger", "run"], Some(40) )?; ledger_b.exp_string("Namada ledger node started")?; diff --git a/tests/src/e2e/ledger_tests.rs b/tests/src/e2e/ledger_tests.rs index 5029bea080a..71fe06ecab5 100644 --- a/tests/src/e2e/ledger_tests.rs +++ b/tests/src/e2e/ledger_tests.rs @@ -27,9 +27,11 @@ use namada_apps::client::tx::CLIShieldedUtils; use namada_apps::config::genesis::genesis_config::{ GenesisConfig, ParametersConfig, PosParamsConfig, }; +use namada_apps::config::utils::convert_tm_addr_to_socket_addr; use namada_test_utils::TestWasms; use serde_json::json; use setup::constants::*; +use tendermint_config::net::Address as TendermintAddress; use super::helpers::{ get_height, is_debug_mode, wait_for_block_height, wait_for_wasm_pre_compile, @@ -182,7 +184,7 @@ fn test_namada_shuts_down_if_tendermint_dies() -> Result<()> { // 2. Kill the tendermint node sleep(1); Command::new("pkill") - .args(["tendermint"]) + .args(["cometbft"]) .spawn() .expect("Test failed") .wait() @@ -2535,7 +2537,6 @@ fn pos_init_validator() -> Result<()> { Some(60), &test.working_dir, validator_1_base_dir, - None, loc, )?; @@ -3758,7 +3759,6 @@ fn test_genesis_validators() -> Result<()> { Some(5), &working_dir, &test_dir, - None, format!("{}:{}", std::file!(), std::line!()), )?; init_genesis_validator_0.assert_success(); @@ -3800,7 +3800,6 @@ fn test_genesis_validators() -> Result<()> { Some(5), &working_dir, &test_dir, - None, format!("{}:{}", std::file!(), std::line!()), )?; init_genesis_validator_1.assert_success(); @@ -3877,7 +3876,6 @@ fn test_genesis_validators() -> Result<()> { Some(5), &working_dir, &test_dir, - None, format!("{}:{}", std::file!(), std::line!()), )?; @@ -3959,13 +3957,31 @@ fn test_genesis_validators() -> Result<()> { // `join-network` use the defaults let update_config = |ix: u8, mut config: Config| { let first_port = net_address_port_0 + 6 * (ix as u16 + 1); - config.ledger.tendermint.p2p_address.set_port(first_port); - config - .ledger - .tendermint - .rpc_address - .set_port(first_port + 1); - config.ledger.shell.ledger_address.set_port(first_port + 2); + let p2p_addr = + convert_tm_addr_to_socket_addr(&config.ledger.cometbft.p2p.laddr) + .ip() + .to_string(); + + config.ledger.cometbft.p2p.laddr = TendermintAddress::from_str( + &format!("{}:{}", p2p_addr, first_port), + ) + .unwrap(); + let rpc_addr = + convert_tm_addr_to_socket_addr(&config.ledger.cometbft.rpc.laddr) + .ip() + .to_string(); + config.ledger.cometbft.rpc.laddr = TendermintAddress::from_str( + &format!("{}:{}", rpc_addr, first_port + 1), + ) + .unwrap(); + let proxy_app_addr = + convert_tm_addr_to_socket_addr(&config.ledger.cometbft.proxy_app) + .ip() + .to_string(); + config.ledger.cometbft.proxy_app = TendermintAddress::from_str( + &format!("{}:{}", proxy_app_addr, first_port + 2), + ) + .unwrap(); config }; @@ -4148,13 +4164,31 @@ fn double_signing_gets_slashed() -> Result<()> { let update_config = |ix: u8, mut config: Config| { let first_port = net_address_port_0 + 6 * (ix as u16 + 1); - config.ledger.tendermint.p2p_address.set_port(first_port); - config - .ledger - .tendermint - .rpc_address - .set_port(first_port + 1); - config.ledger.shell.ledger_address.set_port(first_port + 2); + let p2p_addr = + convert_tm_addr_to_socket_addr(&config.ledger.cometbft.p2p.laddr) + .ip() + .to_string(); + + config.ledger.cometbft.p2p.laddr = TendermintAddress::from_str( + &format!("{}:{}", p2p_addr, first_port), + ) + .unwrap(); + let rpc_addr = + convert_tm_addr_to_socket_addr(&config.ledger.cometbft.rpc.laddr) + .ip() + .to_string(); + config.ledger.cometbft.rpc.laddr = TendermintAddress::from_str( + &format!("{}:{}", rpc_addr, first_port + 1), + ) + .unwrap(); + let proxy_app_addr = + convert_tm_addr_to_socket_addr(&config.ledger.cometbft.proxy_app) + .ip() + .to_string(); + config.ledger.cometbft.proxy_app = TendermintAddress::from_str( + &format!("{}:{}", proxy_app_addr, first_port + 2), + ) + .unwrap(); config }; @@ -4175,7 +4209,7 @@ fn double_signing_gets_slashed() -> Result<()> { let node_sk = key::common::SecretKey::Ed25519(node_sk); let tm_home_dir = validator_0_base_dir_copy .join(test.net.chain_id.as_str()) - .join("tendermint"); + .join("cometbft"); let _node_pk = client::utils::write_tendermint_node_key(&tm_home_dir, node_sk); @@ -4189,7 +4223,6 @@ fn double_signing_gets_slashed() -> Result<()> { Some(40), &test.working_dir, validator_0_base_dir_copy, - None, loc, )?; validator_0_copy.exp_string("Namada ledger node started")?; diff --git a/tests/src/e2e/setup.rs b/tests/src/e2e/setup.rs index c6a8eb89596..98ff2012fda 100644 --- a/tests/src/e2e/setup.rs +++ b/tests/src/e2e/setup.rs @@ -167,7 +167,6 @@ pub fn network( Some(5), &working_dir, &test_dir, - None, format!("{}:{}", std::file!(), std::line!()), )?; @@ -394,19 +393,7 @@ impl Test { S: AsRef, { let base_dir = self.get_base_dir(&who); - let mode = match &who { - Who::NonValidator => "full", - Who::Validator(_) => "validator", - }; - run_cmd( - bin, - args, - timeout_sec, - &self.working_dir, - base_dir, - Some(mode), - loc, - ) + run_cmd(bin, args, timeout_sec, &self.working_dir, base_dir, loc) } pub fn get_base_dir(&self, who: &Who) -> PathBuf { @@ -427,16 +414,16 @@ impl Test { pub fn working_dir() -> PathBuf { let working_dir = fs::canonicalize("..").unwrap(); - // Check that tendermint is either on $PATH or `TENDERMINT` env var is set - if std::env::var("TENDERMINT").is_err() { + // Check that cometbft is either on $PATH or `COMETBFT` env var is set + if std::env::var("COMETBFT").is_err() { Command::new("which") - .arg("tendermint") + .arg("cometbft") .assert() .try_success() .expect( - "The env variable TENDERMINT must be set and point to a local \ - build of the tendermint abci++ branch, or the tendermint \ - binary must be on PATH", + "The env variable COMETBFT must be set and point to a local \ + build of the cometbft abci++ branch, or the cometbft binary \ + must be on PATH", ); } working_dir @@ -673,7 +660,6 @@ pub fn run_cmd( timeout_sec: Option, working_dir: impl AsRef, base_dir: impl AsRef, - mode: Option<&str>, loc: String, ) -> Result where @@ -699,10 +685,6 @@ where .current_dir(working_dir) .args(["--base-dir", &base_dir.as_ref().to_string_lossy()]); - if let Some(mode) = mode { - run_cmd.args(["--mode", mode]); - } - run_cmd.args(args); let args: String =