Skip to content

Commit

Permalink
migration: update cometbft config for testnet78
Browse files Browse the repository at this point in the history
We've already updated the CometBFT config template, but running nodes on
the current testnet will still be using the prior values, generated at
time of join. Let's update the values as part of `pd migrate`, logging a
warning if we fail to do so.

Refs #4594, #4582.
  • Loading branch information
conorsch committed Jun 20, 2024
1 parent 757d224 commit 7698ce5
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 2 deletions.
12 changes: 11 additions & 1 deletion crates/bin/pd/src/migrate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,17 @@ impl Migration {
}

Migration::Testnet78 => {
testnet78::migrate(storage, pd_home.clone(), genesis_start).await?
testnet78::migrate(storage, pd_home.clone(), genesis_start).await?;
// Testnet78 migration munges CometBFT config TOML directly
if let Some(comet_home) = comet_home.clone() {
// Don't bail out on error: the TendermintConfig struct doesn't understand some
// valid config files, so we should just warn, not abort the overall migration.
let _ = testnet78::update_cometbft_mempool_settings(comet_home).map_err(|e| {
tracing::warn!(%e, "failed to update 'max_txs_bytes' value in cometbft config, set it manually before restarting")
});
} else {
tracing::warn!("cometbft home not specified, update 'max_txs_bytes' value manually before restarting");
}
}
// We keep historical migrations around for now, this will help inform an abstracted
// design. Feel free to remove it if it's causing you trouble.
Expand Down
36 changes: 35 additions & 1 deletion crates/bin/pd/src/migrate/testnet78.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
//! Contains functions related to the migration script of Testnet78.
use anyhow::Context;
use cnidarium::{Snapshot, StateDelta, StateWrite, Storage};
use futures::TryStreamExt as _;
use futures::{pin_mut, StreamExt};
Expand All @@ -16,7 +17,10 @@ use penumbra_proto::{StateReadProto, StateWriteProto};
use penumbra_sct::component::clock::EpochManager;
use penumbra_sct::component::clock::EpochRead;
use penumbra_stake::validator::Validator;
use std::fs::OpenOptions;
use std::io::Write;
use std::path::PathBuf;
use tendermint_config::TendermintConfig;
use tracing::instrument;

use crate::testnet::generate::TestnetConfig;
Expand Down Expand Up @@ -536,8 +540,38 @@ fn truncate(s: &str, max_bytes: usize) -> &str {
&s[..closest]
}

mod tests {
/// Edit the node's CometBFT config file to set two values:
///
/// * mempool.max_tx_bytes
/// * mempool.max_txs_bytes
///
/// These values will affect consensus, but the config settings are specified for CometBFT
/// specifically.
#[instrument]
pub(crate) fn update_cometbft_mempool_settings(cometbft_home: PathBuf) -> anyhow::Result<()> {
let cometbft_config_path = cometbft_home.join("config").join("config.toml");
tracing::debug!(cometbft_config_path = %cometbft_config_path.display(), "opening cometbft config file");
let mut cometbft_config = TendermintConfig::load_toml_file(&cometbft_config_path)
.context("failed to load pre-migration cometbft config file")?;
// The new values were updated in GH4594 & GH4632.
let desired_max_txs_bytes = 10485760;
let desired_max_tx_bytes = 30720;
// Set new value
cometbft_config.mempool.max_txs_bytes = desired_max_txs_bytes;
cometbft_config.mempool.max_tx_bytes = desired_max_tx_bytes;
// Overwrite file
let mut fh = OpenOptions::new()
.create(false)
.write(true)
.truncate(true)
.open(cometbft_config_path.clone())
.context("failed to open cometbft config file for writing")?;
fh.write_all(toml::to_string(&cometbft_config)?.as_bytes())
.context("failed to write updated cometbft config to toml file")?;
Ok(())
}

mod tests {
#[test]
fn truncation() {
use super::truncate;
Expand Down

0 comments on commit 7698ce5

Please sign in to comment.