nyxd-scraper: add config to make pre-commit storage optional

This commit is contained in:
Sachin Kamath
2024-11-05 15:47:49 +05:30
parent b747308f74
commit 620d68ea2f
4 changed files with 20 additions and 6 deletions
@@ -44,6 +44,7 @@ impl PendingSync {
pub struct BlockProcessor {
pruning_options: PruningOptions,
store_precommits: bool,
cancel: CancellationToken,
synced: Arc<Notify>,
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<Notify>,
incoming: UnboundedReceiver<BlockToProcess>,
@@ -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:
+4
View File
@@ -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, ScraperError> {
BlockProcessor::new(
self.config.pruning_options,
self.config.store_precommits,
self.cancel_token.clone(),
self.startup_sync.clone(),
processing_rx,
+7 -5
View File
@@ -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
+5
View File
@@ -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
}