From dd79f5e9cfb6ebc687a36bd908b85818b8625a55 Mon Sep 17 00:00:00 2001 From: Conor Schaefer Date: Thu, 13 Jun 2024 16:14:22 -0700 Subject: [PATCH] migration: update cometbft tx size for t78 migration Refs #4594, #4582. --- crates/bin/pd/src/migrate.rs | 8 ++++- crates/bin/pd/src/migrate/testnet78.rs | 45 +++++++++++++++++++++++++- 2 files changed, 51 insertions(+), 2 deletions(-) diff --git a/crates/bin/pd/src/migrate.rs b/crates/bin/pd/src/migrate.rs index c793dc2c37..3a4a8e7095 100644 --- a/crates/bin/pd/src/migrate.rs +++ b/crates/bin/pd/src/migrate.rs @@ -89,7 +89,13 @@ 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() { + testnet78::update_cometbft_mempool_settings(comet_home)?; + } 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. diff --git a/crates/bin/pd/src/migrate/testnet78.rs b/crates/bin/pd/src/migrate/testnet78.rs index 642cbbb5f6..c11eab7d21 100644 --- a/crates/bin/pd/src/migrate/testnet78.rs +++ b/crates/bin/pd/src/migrate/testnet78.rs @@ -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}; @@ -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; @@ -520,8 +524,47 @@ fn truncate(s: &str, max_bytes: usize) -> &str { &s[..closest] } -mod tests { +/// Edit the node's CometBFT config file to set mempool.max_tx_bytes to the required value. +/// This value will affect consensus, but the config setting is 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")?; + // We expect this value to be '1073741824', assuming it's unedited from `pd testnet join`. + let pre_migration_value = cometbft_config.mempool.max_txs_bytes; + // The new value was updated in GH4594 and represents ~10MB or (2^20 * 10). + let post_migration_value = 10485760; + // Set new value + cometbft_config.mempool.max_txs_bytes = post_migration_value; + // 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")?; + + // These asseratiosn are left over from debugging, can be removed. + let config_munged = TendermintConfig::load_toml_file(&cometbft_config_path)?; + let new_block_size = config_munged.mempool.max_txs_bytes; + assert_ne!( + new_block_size, pre_migration_value, + "post-migration max_txs_bytes remains pre-migration value" + ); + assert_eq!( + new_block_size, post_migration_value, + "post-migration max_txs_bytes value not correctly updated" + ); + Ok(()) +} + +mod tests { #[test] fn truncation() { use super::truncate;