From 620d68ea2fce87fcbbdb478b8b8f934e1a6e399e Mon Sep 17 00:00:00 2001 From: Sachin Kamath Date: Tue, 5 Nov 2024 15:47:49 +0530 Subject: [PATCH] nyxd-scraper: add config to make pre-commit storage optional --- common/nyxd-scraper/src/block_processor/mod.rs | 5 ++++- common/nyxd-scraper/src/scraper/mod.rs | 4 ++++ common/nyxd-scraper/src/storage/mod.rs | 12 +++++++----- nym-validator-rewarder/src/config/mod.rs | 5 +++++ 4 files changed, 20 insertions(+), 6 deletions(-) diff --git a/common/nyxd-scraper/src/block_processor/mod.rs b/common/nyxd-scraper/src/block_processor/mod.rs index acb0cbc375..9cb3473c5c 100644 --- a/common/nyxd-scraper/src/block_processor/mod.rs +++ b/common/nyxd-scraper/src/block_processor/mod.rs @@ -44,6 +44,7 @@ impl PendingSync { pub struct BlockProcessor { pruning_options: PruningOptions, + store_precommits: bool, cancel: CancellationToken, synced: Arc, last_processed_height: u32, @@ -68,6 +69,7 @@ pub struct BlockProcessor { impl BlockProcessor { pub async fn new( pruning_options: PruningOptions, + store_precommits: bool, cancel: CancellationToken, synced: Arc, incoming: UnboundedReceiver, @@ -83,6 +85,7 @@ impl BlockProcessor { Ok(BlockProcessor { pruning_options, + store_precommits, cancel, synced, last_processed_height, @@ -128,7 +131,7 @@ impl BlockProcessor { // we won't end up with a corrupted storage. let mut tx = self.storage.begin_processing_tx().await?; - persist_block(&full_info, &mut tx).await?; + persist_block(&full_info, &mut tx, self.store_precommits).await?; // let the modules do whatever they want // the ones wanting the full block: diff --git a/common/nyxd-scraper/src/scraper/mod.rs b/common/nyxd-scraper/src/scraper/mod.rs index 1b3294c914..919a6cae6d 100644 --- a/common/nyxd-scraper/src/scraper/mod.rs +++ b/common/nyxd-scraper/src/scraper/mod.rs @@ -34,6 +34,8 @@ pub struct Config { pub database_path: PathBuf, pub pruning_options: PruningOptions, + + pub store_precommits: bool, } pub struct NyxdScraperBuilder { @@ -62,6 +64,7 @@ impl NyxdScraperBuilder { ); let mut block_processor = BlockProcessor::new( scraper.config.pruning_options, + scraper.config.store_precommits, scraper.cancel_token.clone(), scraper.startup_sync.clone(), processing_rx, @@ -277,6 +280,7 @@ impl NyxdScraper { ) -> Result { BlockProcessor::new( self.config.pruning_options, + self.config.store_precommits, self.cancel_token.clone(), self.startup_sync.clone(), processing_rx, diff --git a/common/nyxd-scraper/src/storage/mod.rs b/common/nyxd-scraper/src/storage/mod.rs index 8ac0f07775..623173df1c 100644 --- a/common/nyxd-scraper/src/storage/mod.rs +++ b/common/nyxd-scraper/src/storage/mod.rs @@ -212,6 +212,7 @@ impl ScraperStorage { pub async fn persist_block( block: &FullBlockInformation, tx: &mut StorageTransaction, + store_precommits: bool, ) -> Result<(), ScraperError> { let total_gas = crate::helpers::tx_gas_sum(&block.transactions); @@ -224,11 +225,12 @@ pub async fn persist_block( // persist block data persist_block_data(&block.block, total_gas, tx).await?; - // persist commits - if let Some(commit) = &block.block.last_commit { - persist_commits(commit, &block.validators, tx).await?; - } else { - warn!("no commits for block {}", block.block.header.height) + if store_precommits { + if let Some(commit) = &block.block.last_commit { + persist_commits(commit, &block.validators, tx).await?; + } else { + warn!("no commits for block {}", block.block.header.height) + } } // persist txs diff --git a/nym-validator-rewarder/src/config/mod.rs b/nym-validator-rewarder/src/config/mod.rs index f0a45069a1..d57dad3afa 100644 --- a/nym-validator-rewarder/src/config/mod.rs +++ b/nym-validator-rewarder/src/config/mod.rs @@ -107,6 +107,7 @@ impl Config { nyxd_scraper: NyxdScraper { websocket_url, pruning: Default::default(), + store_precommits: true, }, base: Base { upstream_nyxd: nyxd_url, @@ -122,6 +123,7 @@ impl Config { rpc_url: self.base.upstream_nyxd.clone(), database_path: self.storage_paths.nyxd_scraper.clone(), pruning_options: self.nyxd_scraper.pruning, + store_precommits: self.nyxd_scraper.store_precommits, } } @@ -249,6 +251,9 @@ pub struct NyxdScraper { // if the value is missing, use `nothing` pruning as this was the past behaviour #[serde(default = "PruningOptions::nothing")] pub pruning: PruningOptions, + + /// Specifies whether to store pre-commits within the database. + pub store_precommits: bool, // TODO: debug with everything that's currently hardcoded in the scraper }