From 655fd421a6847e47717fe380c38bdda1c22aaab2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C4=99drzej=20Stuczy=C5=84ski?= Date: Fri, 4 Jul 2025 12:25:08 +0100 Subject: [PATCH] using sqlite instance for rewarder and chain watcher --- common/nyxd-scraper-shared/src/lib.rs | 1 + common/nyxd-scraper-shared/src/scraper/mod.rs | 4 ++++ common/nyxd-scraper-sqlite/src/lib.rs | 16 +++++++++++++++- nym-validator-rewarder/src/cli/process_block.rs | 4 ++-- nym-validator-rewarder/src/cli/process_until.rs | 4 ++-- nym-validator-rewarder/src/error.rs | 9 ++++++++- .../src/rewarder/block_signing/mod.rs | 4 ++-- nym-validator-rewarder/src/rewarder/mod.rs | 4 ++-- nyx-chain-watcher/src/chain_scraper/mod.rs | 10 +++++----- 9 files changed, 41 insertions(+), 15 deletions(-) diff --git a/common/nyxd-scraper-shared/src/lib.rs b/common/nyxd-scraper-shared/src/lib.rs index 43f6ffdcf2..74694867e2 100644 --- a/common/nyxd-scraper-shared/src/lib.rs +++ b/common/nyxd-scraper-shared/src/lib.rs @@ -15,3 +15,4 @@ pub use block_processor::pruning::{PruningOptions, PruningStrategy}; pub use block_processor::types::ParsedTransactionResponse; pub use modules::{BlockModule, MsgModule, TxModule}; pub use scraper::{Config, NyxdScraper, StartingBlockOpts}; +pub use storage::{NyxdScraperStorage, NyxdScraperTransaction}; diff --git a/common/nyxd-scraper-shared/src/scraper/mod.rs b/common/nyxd-scraper-shared/src/scraper/mod.rs index 9d630b91dd..e852b4ab30 100644 --- a/common/nyxd-scraper-shared/src/scraper/mod.rs +++ b/common/nyxd-scraper-shared/src/scraper/mod.rs @@ -174,6 +174,10 @@ where }) } + pub fn storage(&self) -> &S { + &self.storage + } + fn start_tasks( &self, mut block_requester: BlockRequester, diff --git a/common/nyxd-scraper-sqlite/src/lib.rs b/common/nyxd-scraper-sqlite/src/lib.rs index d3068b5fd5..56c202b63f 100644 --- a/common/nyxd-scraper-sqlite/src/lib.rs +++ b/common/nyxd-scraper-sqlite/src/lib.rs @@ -1,7 +1,21 @@ // Copyright 2023 - Nym Technologies SA // SPDX-License-Identifier: Apache-2.0 +use crate::storage::block_storage::SqliteScraperStorage; +use nyxd_scraper_shared::NyxdScraper; + +pub use nyxd_scraper_shared::constants; +pub use nyxd_scraper_shared::error::ScraperError; +pub use nyxd_scraper_shared::{ + BlockModule, MsgModule, NyxdScraperTransaction, ParsedTransactionResponse, PruningOptions, + PruningStrategy, StartingBlockOpts, TxModule, +}; +pub use storage::models; + pub mod error; pub mod storage; -pub use storage::models; +pub type SqliteNyxdScraper = NyxdScraper; + +// TODO: for now just use exactly the same config +pub use nyxd_scraper_shared::Config; diff --git a/nym-validator-rewarder/src/cli/process_block.rs b/nym-validator-rewarder/src/cli/process_block.rs index 3892846850..fcad87e0a6 100644 --- a/nym-validator-rewarder/src/cli/process_block.rs +++ b/nym-validator-rewarder/src/cli/process_block.rs @@ -3,7 +3,7 @@ use crate::cli::{try_load_current_config, ConfigOverridableArgs}; use crate::error::NymRewarderError; -use nyxd_scraper_sqlite::NyxdScraper; +use nyxd_scraper_sqlite::SqliteNyxdScraper; use std::path::PathBuf; #[derive(Debug, clap::Args)] @@ -24,7 +24,7 @@ pub(crate) async fn execute(args: Args) -> Result<(), NymRewarderError> { let config = try_load_current_config(&args.custom_config_path)?.with_override(args.config_override); - NyxdScraper::new(config.scraper_config()) + SqliteNyxdScraper::new(config.scraper_config()) .await? .unsafe_process_single_block(args.height) .await?; diff --git a/nym-validator-rewarder/src/cli/process_until.rs b/nym-validator-rewarder/src/cli/process_until.rs index dac40cf4ab..660991c5a6 100644 --- a/nym-validator-rewarder/src/cli/process_until.rs +++ b/nym-validator-rewarder/src/cli/process_until.rs @@ -3,7 +3,7 @@ use crate::cli::{try_load_current_config, ConfigOverridableArgs}; use crate::error::NymRewarderError; -use nyxd_scraper_sqlite::NyxdScraper; +use nyxd_scraper_sqlite::SqliteNyxdScraper; use std::path::PathBuf; #[derive(Debug, clap::Args)] @@ -37,7 +37,7 @@ pub(crate) async fn execute(args: Args) -> Result<(), NymRewarderError> { let config = try_load_current_config(&args.custom_config_path)?.with_override(args.config_override); - NyxdScraper::new(config.scraper_config()) + SqliteNyxdScraper::new(config.scraper_config()) .await? .unsafe_process_block_range(args.start_height, args.stop_height) .await?; diff --git a/nym-validator-rewarder/src/error.rs b/nym-validator-rewarder/src/error.rs index 858634e620..6032d829ff 100644 --- a/nym-validator-rewarder/src/error.rs +++ b/nym-validator-rewarder/src/error.rs @@ -9,6 +9,7 @@ use nym_validator_client::nym_api::error::NymAPIError; use nym_validator_client::nyxd::error::NyxdError; use nym_validator_client::nyxd::tx::ErrorReport; use nym_validator_client::nyxd::{AccountId, Coin}; +use nyxd_scraper_sqlite::error::SqliteScraperError; use std::io; use std::path::PathBuf; use thiserror::Error; @@ -78,7 +79,13 @@ pub enum NymRewarderError { #[error("chain scraping failure: {source}")] ScraperFailure { #[from] - source: nyxd_scraper_sqlite::error::ScraperError, + source: nyxd_scraper_sqlite::ScraperError, + }, + + #[error("chain scraper storage failure: {source}")] + ScraperStorageFailure { + #[from] + source: SqliteScraperError, }, // this should never happen but unwrapping everywhere was more cumbersome than just propagating the error diff --git a/nym-validator-rewarder/src/rewarder/block_signing/mod.rs b/nym-validator-rewarder/src/rewarder/block_signing/mod.rs index 9309c85ebc..6435cd15ea 100644 --- a/nym-validator-rewarder/src/rewarder/block_signing/mod.rs +++ b/nym-validator-rewarder/src/rewarder/block_signing/mod.rs @@ -7,7 +7,7 @@ use crate::rewarder::epoch::Epoch; use crate::rewarder::nyxd_client::NyxdClient; use nym_validator_client::nyxd::module_traits::staking; use nym_validator_client::nyxd::{AccountId, PageRequest}; -use nyxd_scraper_sqlite::NyxdScraper; +use nyxd_scraper_sqlite::SqliteNyxdScraper; use std::cmp::min; use std::collections::HashMap; use std::ops::Range; @@ -17,7 +17,7 @@ pub(crate) mod types; pub struct EpochSigning { pub(crate) nyxd_client: NyxdClient, - pub(crate) nyxd_scraper: NyxdScraper, + pub(crate) nyxd_scraper: SqliteNyxdScraper, pub(crate) whitelist: Vec, } diff --git a/nym-validator-rewarder/src/rewarder/mod.rs b/nym-validator-rewarder/src/rewarder/mod.rs index 46a8b39187..e5580b467d 100644 --- a/nym-validator-rewarder/src/rewarder/mod.rs +++ b/nym-validator-rewarder/src/rewarder/mod.rs @@ -16,7 +16,7 @@ use nym_crypto::asymmetric::ed25519; use nym_ecash_time::{ecash_today, ecash_today_date, EcashTime}; use nym_task::TaskManager; use nym_validator_client::nyxd::{AccountId, Coin, Hash}; -use nyxd_scraper_sqlite::NyxdScraper; +use nyxd_scraper_sqlite::SqliteNyxdScraper; use std::sync::Arc; use time::Date; use tokio::pin; @@ -188,7 +188,7 @@ impl Rewarder { info!("the block signing rewarding is running in monitor only mode"); } - let nyxd_scraper = NyxdScraper::new(config.scraper_config()).await?; + let nyxd_scraper = SqliteNyxdScraper::new(config.scraper_config()).await?; Some(EpochSigning { nyxd_scraper, diff --git a/nyx-chain-watcher/src/chain_scraper/mod.rs b/nyx-chain-watcher/src/chain_scraper/mod.rs index 561b40558d..b08ee27fbc 100644 --- a/nyx-chain-watcher/src/chain_scraper/mod.rs +++ b/nyx-chain-watcher/src/chain_scraper/mod.rs @@ -7,8 +7,8 @@ use crate::http::state::BankScraperModuleState; use async_trait::async_trait; use nym_validator_client::nyxd::{Any, Coin, CosmosCoin, Hash, Msg, MsgSend, Name}; use nyxd_scraper_sqlite::{ - error::ScraperError, storage::StorageTransaction, MsgModule, NyxdScraper, - ParsedTransactionResponse, PruningOptions, + MsgModule, NyxdScraperTransaction, ParsedTransactionResponse, PruningOptions, ScraperError, + SqliteNyxdScraper, }; use sqlx::SqlitePool; use std::fs; @@ -18,7 +18,7 @@ pub(crate) async fn run_chain_scraper( config: &crate::config::Config, db_pool: SqlitePool, shared_state: BankScraperModuleState, -) -> anyhow::Result { +) -> anyhow::Result { let websocket_url = std::env::var("NYXD_WS").expect("NYXD_WS not defined"); let rpc_url = std::env::var("NYXD").expect("NYXD not defined"); @@ -50,7 +50,7 @@ pub(crate) async fn run_chain_scraper( fs::remove_file(config.chain_scraper_database_path())?; } - let scraper = NyxdScraper::builder(nyxd_scraper_sqlite::Config { + let scraper = SqliteNyxdScraper::builder(nyxd_scraper_sqlite::Config { websocket_url, rpc_url, database_path: config.chain_scraper_database_path().into(), @@ -157,7 +157,7 @@ impl MsgModule for BankScraperModule { index: usize, msg: &Any, tx: &ParsedTransactionResponse, - _storage_tx: &mut StorageTransaction, + _storage_tx: &mut dyn NyxdScraperTransaction, ) -> Result<(), ScraperError> { let memo = tx.tx.body.memo.clone();