diff --git a/resource/ckb.toml b/resource/ckb.toml index 18a0add42b..750ad86d16 100644 --- a/resource/ckb.toml +++ b/resource/ckb.toml @@ -115,7 +115,7 @@ listen_address = "127.0.0.1:8114" # {{ # Default is 10MiB = 10 * 1024 * 1024 max_request_body_size = 10485760 -# List of API modules: ["Net", "Pool", "Miner", "Chain", "Stats", "Subscription", "Experiment", "Debug", "Indexer", "IndexerR"] +# List of API modules: ["Net", "Pool", "Miner", "Chain", "Stats", "Subscription", "Experiment", "Debug", "Indexer", "RichIndexer"] modules = ["Net", "Pool", "Miner", "Chain", "Stats", "Subscription", "Experiment"] # {{ # dev => modules = ["Net", "Pool", "Miner", "Chain", "Stats", "Subscription", "Experiment", "Debug"] # integration => modules = ["Net", "Pool", "Miner", "Chain", "Experiment", "Stats", "IntegrationTest"] @@ -203,8 +203,8 @@ block_uncles_cache_size = 30 # cell_filter = "let script = output.type;script.code_hash == \"0xbbad126377d45f90a8ee120da988a2d7332c78ba8fd679aab478a19d6c133494\" && script.hash_type == \"data1\"" # # # The 'ckb-rich-indexer' is an indexer built on relational databases. -# [indexer_v2.indexer_r] -# # The initial tip number and hash can be set as the starting height for building indexes in indexer-r. Effective only during the initial index creation. +# [indexer_v2.rich_indexer] +# # The initial tip number and hash can be set as the starting height for building indexes in rich-indexer. Effective only during the initial index creation. # init_tip_number = 0 # # The initial tip hash must match the tip number; otherwise, it will result in a rollback. # init_tip_hash = "0x92b197aa1fba0f63633922c61c92375c9c074a93e85963554f5499fe1450d0e5" diff --git a/rpc/src/module/mod.rs b/rpc/src/module/mod.rs index 0ed412c9a2..bc688b4252 100644 --- a/rpc/src/module/mod.rs +++ b/rpc/src/module/mod.rs @@ -115,10 +115,10 @@ pub(crate) mod chain; mod debug; mod experiment; mod indexer; -mod indexer_r; mod miner; mod net; pub(crate) mod pool; +mod rich_indexer; mod stats; mod subscription; mod test; @@ -128,10 +128,10 @@ pub(crate) use self::chain::ChainRpcImpl; pub(crate) use self::debug::DebugRpcImpl; pub(crate) use self::experiment::ExperimentRpcImpl; pub(crate) use self::indexer::IndexerRpcImpl; -pub(crate) use self::indexer_r::IndexerRRpcImpl; pub(crate) use self::miner::MinerRpcImpl; pub(crate) use self::net::NetRpcImpl; pub(crate) use self::pool::PoolRpcImpl; +pub(crate) use self::rich_indexer::RichIndexerRpcImpl; pub(crate) use self::stats::StatsRpcImpl; pub(crate) use self::subscription::SubscriptionRpcImpl; pub(crate) use self::test::IntegrationTestRpcImpl; @@ -141,10 +141,10 @@ pub use self::chain::{add_chain_rpc_methods, ChainRpc}; pub use self::debug::{add_debug_rpc_methods, DebugRpc}; pub use self::experiment::{add_experiment_rpc_methods, ExperimentRpc}; pub use self::indexer::{add_indexer_rpc_methods, IndexerRpc}; -pub use self::indexer_r::{add_indexer_r_rpc_methods, IndexerRRpc}; pub use self::miner::{add_miner_rpc_methods, MinerRpc}; pub use self::net::{add_net_rpc_methods, NetRpc}; pub use self::pool::{add_pool_rpc_methods, PoolRpc}; +pub use self::rich_indexer::{add_rich_indexer_rpc_methods, RichIndexerRpc}; pub use self::stats::{add_stats_rpc_methods, StatsRpc}; pub use self::subscription::{add_subscription_rpc_methods, SubscriptionRpc}; pub use self::test::{add_integration_test_rpc_methods, IntegrationTestRpc}; diff --git a/rpc/src/module/indexer_r.rs b/rpc/src/module/rich_indexer.rs similarity index 64% rename from rpc/src/module/indexer_r.rs rename to rpc/src/module/rich_indexer.rs index 4088eed8ec..81c2dd35f6 100644 --- a/rpc/src/module/indexer_r.rs +++ b/rpc/src/module/rich_indexer.rs @@ -1,14 +1,14 @@ use crate::error::RPCError; use async_trait::async_trait; use ckb_jsonrpc_types::IndexerTip; -use ckb_rich_indexer::AsyncIndexerRHandle; +use ckb_rich_indexer::AsyncRichIndexerHandle; use jsonrpc_core::Result; use jsonrpc_utils::rpc; /// RPC Module Indexer. #[rpc] #[async_trait] -pub trait IndexerRRpc { +pub trait RichIndexerRpc { /// Returns the indexed tip /// /// ## Returns @@ -23,7 +23,7 @@ pub trait IndexerRRpc { /// { /// "id": 2, /// "jsonrpc": "2.0", - /// "method": "get_indexer_r_tip" + /// "method": "get_rich_indexer_tip" /// } /// ``` /// @@ -39,24 +39,24 @@ pub trait IndexerRRpc { /// "id": 2 /// } /// ``` - #[rpc(name = "get_indexer_r_tip")] - async fn get_indexer_r_tip(&self) -> Result>; + #[rpc(name = "get_rich_indexer_tip")] + async fn get_rich_indexer_tip(&self) -> Result>; } #[derive(Clone)] -pub(crate) struct IndexerRRpcImpl { - pub(crate) handle: AsyncIndexerRHandle, +pub(crate) struct RichIndexerRpcImpl { + pub(crate) handle: AsyncRichIndexerHandle, } -impl IndexerRRpcImpl { - pub fn new(handle: AsyncIndexerRHandle) -> Self { - IndexerRRpcImpl { handle } +impl RichIndexerRpcImpl { + pub fn new(handle: AsyncRichIndexerHandle) -> Self { + RichIndexerRpcImpl { handle } } } #[async_trait] -impl IndexerRRpc for IndexerRRpcImpl { - async fn get_indexer_r_tip(&self) -> Result> { +impl RichIndexerRpc for RichIndexerRpcImpl { + async fn get_rich_indexer_tip(&self) -> Result> { self.handle .query_indexer_tip() .await diff --git a/rpc/src/service_builder.rs b/rpc/src/service_builder.rs index 8fc912d327..37021d841b 100644 --- a/rpc/src/service_builder.rs +++ b/rpc/src/service_builder.rs @@ -1,12 +1,11 @@ #![allow(deprecated)] use crate::module::{ add_alert_rpc_methods, add_chain_rpc_methods, add_debug_rpc_methods, - add_experiment_rpc_methods, add_indexer_r_rpc_methods, add_indexer_rpc_methods, - add_integration_test_rpc_methods, add_miner_rpc_methods, add_net_rpc_methods, - add_pool_rpc_methods, add_stats_rpc_methods, add_subscription_rpc_methods, AlertRpcImpl, - ChainRpcImpl, DebugRpcImpl, ExperimentRpcImpl, IndexerRRpcImpl, IndexerRpcImpl, - IntegrationTestRpcImpl, MinerRpcImpl, NetRpcImpl, PoolRpcImpl, StatsRpcImpl, - SubscriptionRpcImpl, + add_experiment_rpc_methods, add_indexer_rpc_methods, add_integration_test_rpc_methods, + add_miner_rpc_methods, add_net_rpc_methods, add_pool_rpc_methods, add_rich_indexer_rpc_methods, + add_stats_rpc_methods, add_subscription_rpc_methods, AlertRpcImpl, ChainRpcImpl, DebugRpcImpl, + ExperimentRpcImpl, IndexerRpcImpl, IntegrationTestRpcImpl, MinerRpcImpl, NetRpcImpl, + PoolRpcImpl, RichIndexerRpcImpl, StatsRpcImpl, SubscriptionRpcImpl, }; use crate::{IoHandler, RPCError}; use ckb_app_config::{DBConfig, IndexerConfig, RpcConfig}; @@ -16,7 +15,7 @@ use ckb_indexer_sync::{new_secondary_db, PoolService}; use ckb_network::NetworkController; use ckb_network_alert::{notifier::Notifier as AlertNotifier, verifier::Verifier as AlertVerifier}; use ckb_pow::Pow; -use ckb_rich_indexer::IndexerRService; +use ckb_rich_indexer::RichIndexerService; use ckb_shared::shared::Shared; use ckb_sync::SyncShared; use ckb_types::packed::Script; @@ -191,7 +190,7 @@ impl<'a> ServiceBuilder<'a> { db_config: &DBConfig, indexer_config: &IndexerConfig, ) -> Self { - // Initialize instances of data sources that will be shared for use by indexer and indexer-r. + // Initialize instances of data sources that will be shared for use by indexer and rich-indexer. let ckb_secondary_db = new_secondary_db(db_config, &indexer_config.into()); let mut pool_service = PoolService::new(indexer_config.index_tx_pool, shared.async_handle().clone()); @@ -219,27 +218,27 @@ impl<'a> ServiceBuilder<'a> { methods ); - // Init indexer-r service - let indexer_r = IndexerRService::new( + // Init rich-indexer service + let rich_indexer = RichIndexerService::new( ckb_secondary_db, pool_service.clone(), indexer_config, shared.async_handle().clone(), ); - let indexer_r_handle = indexer_r.async_handle(); - let indexer_r_methods = IndexerRRpcImpl::new(indexer_r_handle); - if self.config.indexer_r_enable() { - indexer_r.spawn_poll(shared.notify_controller().clone()); + let rich_indexer_handle = rich_indexer.async_handle(); + let rich_indexer_methods = RichIndexerRpcImpl::new(rich_indexer_handle); + if self.config.rich_indexer_enable() { + rich_indexer.spawn_poll(shared.notify_controller().clone()); if indexer_config.index_tx_pool { pool_service.index_tx_pool(shared.notify_controller().clone()); } } set_rpc_module_methods!( self, - "IndexerR", - indexer_r_enable, - add_indexer_r_rpc_methods, - indexer_r_methods + "RichIndexer", + rich_indexer_enable, + add_rich_indexer_rpc_methods, + rich_indexer_methods ) } diff --git a/util/app-config/src/args.rs b/util/app-config/src/args.rs index 678096327b..70d419fcb7 100644 --- a/util/app-config/src/args.rs +++ b/util/app-config/src/args.rs @@ -45,8 +45,8 @@ pub struct RunArgs { pub chain_spec_hash: Byte32, /// Whether start indexer, default false pub indexer: bool, - /// Whether start indexer-r, default false - pub indexer_r: bool, + /// Whether start rich-indexer, default false + pub rich_indexer: bool, } /// Enable profile on blocks in the range `[from, to]`. diff --git a/util/app-config/src/cli.rs b/util/app-config/src/cli.rs index 5685a47ae5..dc1d0c0bbc 100644 --- a/util/app-config/src/cli.rs +++ b/util/app-config/src/cli.rs @@ -75,8 +75,8 @@ pub const ARG_BA_MESSAGE: &str = "ba-message"; pub const ARG_BA_ADVANCED: &str = "ba-advanced"; /// Command line argument `--indexer`. pub const ARG_INDEXER: &str = "indexer"; -/// Command line argument `--indexer-r`. -pub const ARG_INDEXER_R: &str = "indexer-r"; +/// Command line argument `--rich-indexer`. +pub const ARG_RICH_INDEXER: &str = "rich-indexer"; /// Command line argument `--from`. pub const ARG_FROM: &str = "from"; /// Command line argument `--to`. @@ -202,10 +202,10 @@ fn run() -> Command { .help("Start the built-in indexer service"), ) .arg( - Arg::new(ARG_INDEXER_R) - .long(ARG_INDEXER_R) + Arg::new(ARG_RICH_INDEXER) + .long(ARG_RICH_INDEXER) .action(clap::ArgAction::SetTrue) - .help("Start the built-in indexer-r service"), + .help("Start the built-in rich-indexer service"), ) } diff --git a/util/app-config/src/configs/indexer.rs b/util/app-config/src/configs/indexer.rs index d167d92d59..a7da095e26 100644 --- a/util/app-config/src/configs/indexer.rs +++ b/util/app-config/src/configs/indexer.rs @@ -1,4 +1,4 @@ -use super::indexer_r::{DBDriver, IndexerRConfig}; +use super::rich_indexer::{DBDriver, RichIndexerConfig}; use serde::{Deserialize, Serialize}; use std::num::NonZeroUsize; use std::path::{Path, PathBuf}; @@ -30,9 +30,9 @@ pub struct IndexerConfig { /// Maximal db info log files to be kept. #[serde(default)] pub db_keep_log_file_num: Option, - /// IndexerR config options + /// Rich indexer config options #[serde(default)] - pub indexer_r: IndexerRConfig, + pub rich_indexer: RichIndexerConfig, } const fn default_poll_interval() -> u64 { @@ -50,7 +50,7 @@ impl Default for IndexerConfig { cell_filter: None, db_background_jobs: None, db_keep_log_file_num: None, - indexer_r: IndexerRConfig::default(), + rich_indexer: RichIndexerConfig::default(), } } } @@ -62,7 +62,7 @@ impl IndexerConfig { /// /// If `self.secondary_path` is not set, set it to `data_dir / indexer / secondary_path`. /// - /// If `self.indexer_r` is `Sqlite`, and `self.indexer_r.sqlite.store` is not set, + /// If `self.rich_indexer` is `Sqlite`, and `self.rich_indexer.sqlite.store` is not set, /// set it to `data_dir / indexer / sqlite / sqlite.db`. /// /// If any of the above paths is relative, convert them to absolute path using @@ -75,11 +75,11 @@ impl IndexerConfig { &mut self.secondary_path, "secondary_path", ); - if let DBDriver::Sqlite = &mut self.indexer_r.db_type { + if let DBDriver::Sqlite = &mut self.rich_indexer.db_type { _adjust( root_dir, indexer_dir.as_ref(), - &mut self.indexer_r.store, + &mut self.rich_indexer.store, "sqlite/sqlite.db", ); } diff --git a/util/app-config/src/configs/mod.rs b/util/app-config/src/configs/mod.rs index 6690db44e6..95b0c79508 100644 --- a/util/app-config/src/configs/mod.rs +++ b/util/app-config/src/configs/mod.rs @@ -1,18 +1,17 @@ mod db; mod indexer; -mod indexer_r; mod memory_tracker; mod miner; mod network; mod network_alert; mod notify; +mod rich_indexer; mod rpc; mod store; mod tx_pool; pub use db::Config as DBConfig; pub use indexer::{IndexerConfig, IndexerSyncConfig}; -pub use indexer_r::{DBDriver, IndexerRConfig}; pub use memory_tracker::Config as MemoryTrackerConfig; pub use miner::{ ClientConfig as MinerClientConfig, Config as MinerConfig, DummyConfig, EaglesongSimpleConfig, @@ -24,6 +23,7 @@ pub use network::{ }; pub use network_alert::Config as NetworkAlertConfig; pub use notify::Config as NotifyConfig; +pub use rich_indexer::{DBDriver, RichIndexerConfig}; pub use rpc::{Config as RpcConfig, Module as RpcModule}; pub use store::Config as StoreConfig; pub use tx_pool::{BlockAssemblerConfig, TxPoolConfig}; diff --git a/util/app-config/src/configs/indexer_r.rs b/util/app-config/src/configs/rich_indexer.rs similarity index 89% rename from util/app-config/src/configs/indexer_r.rs rename to util/app-config/src/configs/rich_indexer.rs index 615f7802be..2666d2030e 100644 --- a/util/app-config/src/configs/indexer_r.rs +++ b/util/app-config/src/configs/rich_indexer.rs @@ -5,7 +5,7 @@ use std::{default::Default, path::PathBuf}; const PGSQL: &str = "postgres://"; const SQLITE: &str = "sqlite://"; -/// IndexerR database type. +/// Rich indexer database type. #[derive(Clone, Debug, Serialize, Deserialize, Default, PartialEq, Eq)] #[serde(rename_all = "lowercase")] pub enum DBDriver { @@ -25,23 +25,23 @@ impl ToString for DBDriver { } } -/// IndexerR config options. +/// Rich indexer config options. #[derive(Clone, Debug, Serialize, Deserialize)] -pub struct IndexerRConfig { +pub struct RichIndexerConfig { /// The init tip block number #[serde(default)] pub init_tip_number: Option, /// The init tip block hash #[serde(default)] pub init_tip_hash: Option, - /// IndexerR database type. + /// Rich indexer database type. #[serde(default)] pub db_type: DBDriver, /// The index-r store path, default `data_dir / indexer / sqlite / sqlite.db`, /// which will be realized through IndexerConfig::adjust. #[serde(default)] pub store: PathBuf, - /// The database name, default `indexer_r`. + /// The database name, default `ckb-rich-indexer`. #[serde(default = "default_db_name")] pub db_name: String, /// The database host. @@ -58,7 +58,7 @@ pub struct IndexerRConfig { pub db_password: String, } -impl Default for IndexerRConfig { +impl Default for RichIndexerConfig { fn default() -> Self { Self { init_tip_number: None, @@ -75,7 +75,7 @@ impl Default for IndexerRConfig { } fn default_db_name() -> String { - "indexer_r".to_string() + "ckb-rich-indexer".to_string() } fn default_db_host() -> String { diff --git a/util/app-config/src/configs/rpc.rs b/util/app-config/src/configs/rpc.rs index ebeb065257..abd357cbf6 100644 --- a/util/app-config/src/configs/rpc.rs +++ b/util/app-config/src/configs/rpc.rs @@ -16,7 +16,7 @@ pub enum Module { Subscription, Debug, Indexer, - IndexerR, + RichIndexer, } /// RPC config options. @@ -113,8 +113,8 @@ impl Config { self.modules.contains(&Module::Indexer) } - /// Checks whether the IndexerR module is enabled. - pub fn indexer_r_enable(&self) -> bool { - self.modules.contains(&Module::IndexerR) + /// Checks whether the Rich Indexer module is enabled. + pub fn rich_indexer_enable(&self) -> bool { + self.modules.contains(&Module::RichIndexer) } } diff --git a/util/app-config/src/lib.rs b/util/app-config/src/lib.rs index 9c338c4926..68e3d98810 100644 --- a/util/app-config/src/lib.rs +++ b/util/app-config/src/lib.rs @@ -98,7 +98,7 @@ impl Setup { overwrite_chain_spec: matches.get_flag(cli::ARG_OVERWRITE_CHAIN_SPEC), chain_spec_hash, indexer: matches.get_flag(cli::ARG_INDEXER), - indexer_r: matches.get_flag(cli::ARG_INDEXER_R), + rich_indexer: matches.get_flag(cli::ARG_RICH_INDEXER), }) } diff --git a/util/launcher/src/lib.rs b/util/launcher/src/lib.rs index ba84879e38..6e8de2251c 100644 --- a/util/launcher/src/lib.rs +++ b/util/launcher/src/lib.rs @@ -237,8 +237,8 @@ impl Launcher { if self.args.indexer && !config.indexer_enable() { config.modules.push(RpcModule::Indexer); } - if self.args.indexer_r && !config.indexer_r_enable() { - config.modules.push(RpcModule::IndexerR); + if self.args.rich_indexer && !config.rich_indexer_enable() { + config.modules.push(RpcModule::RichIndexer); } config } diff --git a/util/rich-indexer/src/indexer/mod.rs b/util/rich-indexer/src/indexer/mod.rs index 32c3faa2dd..723fb127b2 100644 --- a/util/rich-indexer/src/indexer/mod.rs +++ b/util/rich-indexer/src/indexer/mod.rs @@ -4,7 +4,7 @@ mod remove; pub(crate) use insert::*; pub(crate) use remove::*; -use crate::{service::SUBSCRIBER_NAME, store::SQLXPool, IndexerRHandle}; +use crate::{service::SUBSCRIBER_NAME, store::SQLXPool, RichIndexerHandle}; use ckb_async_runtime::Handle; use ckb_indexer_sync::{CustomFilters, Error, IndexerSync, Pool}; @@ -31,15 +31,15 @@ use std::sync::{Arc, RwLock}; /// - tx_association_cell_dep /// The detailed table design can be found in the SQL files in the resources folder of this crate -/// Indexer-r, which is based on a relational database +/// Rich-Indexer, which is based on a relational database #[derive(Clone)] -pub(crate) struct IndexerR { - async_indexer_r: AsyncIndexerR, +pub(crate) struct RichIndexer { + async_rich_indexer: AsyncRichIndexer, async_runtime: Handle, } -impl IndexerR { - /// Construct new IndexerR instance +impl RichIndexer { + /// Construct new Rich Indexer instance pub fn new( store: SQLXPool, keep_num: u64, @@ -49,7 +49,7 @@ impl IndexerR { async_runtime: Handle, ) -> Self { Self { - async_indexer_r: AsyncIndexerR::new( + async_rich_indexer: AsyncRichIndexer::new( store, keep_num, prune_interval, @@ -61,12 +61,12 @@ impl IndexerR { } } -impl IndexerSync for IndexerR { +impl IndexerSync for RichIndexer { /// Retrieves the tip of the indexer fn tip(&self) -> Result, Error> { - let indexer_handle = IndexerRHandle::new( - self.async_indexer_r.store.clone(), - self.async_indexer_r.pool.clone(), + let indexer_handle = RichIndexerHandle::new( + self.async_rich_indexer.store.clone(), + self.async_rich_indexer.pool.clone(), self.async_runtime.clone(), ); indexer_handle @@ -77,13 +77,13 @@ impl IndexerSync for IndexerR { /// Appends a new block to the indexer fn append(&self, block: &BlockView) -> Result<(), Error> { - let future = self.async_indexer_r.append(block); + let future = self.async_rich_indexer.append(block); self.async_runtime.block_on(future) } /// Rollback the indexer to a previous state fn rollback(&self) -> Result<(), Error> { - let future = self.async_indexer_r.rollback(); + let future = self.async_rich_indexer.rollback(); self.async_runtime.block_on(future) } @@ -93,9 +93,9 @@ impl IndexerSync for IndexerR { } } -/// Async indexer-r. +/// Async rich-indexer. #[derive(Clone)] -pub(crate) struct AsyncIndexerR { +pub(crate) struct AsyncRichIndexer { /// storage pub(crate) store: SQLXPool, /// number of blocks to keep for rollback and forking, for example: @@ -110,8 +110,8 @@ pub(crate) struct AsyncIndexerR { custom_filters: CustomFilters, } -impl AsyncIndexerR { - /// Construct new AsyncIndexerR instance +impl AsyncRichIndexer { + /// Construct new AsyncRichIndexer instance pub fn new( store: SQLXPool, keep_num: u64, @@ -129,7 +129,7 @@ impl AsyncIndexerR { } } -impl AsyncIndexerR { +impl AsyncRichIndexer { pub(crate) async fn append(&self, block: &BlockView) -> Result<(), Error> { let mut tx = self .store diff --git a/util/rich-indexer/src/indexer_handle/async_indexer_handle.rs b/util/rich-indexer/src/indexer_handle/async_indexer_handle.rs index ce1fae8efd..221578050e 100644 --- a/util/rich-indexer/src/indexer_handle/async_indexer_handle.rs +++ b/util/rich-indexer/src/indexer_handle/async_indexer_handle.rs @@ -7,21 +7,21 @@ use sqlx::{any::AnyRow, Row}; use std::sync::{Arc, RwLock}; -/// Async handle to the indexer-r. +/// Async handle to the rich-indexer. #[derive(Clone)] -pub struct AsyncIndexerRHandle { +pub struct AsyncRichIndexerHandle { store: SQLXPool, _pool: Option>>, } -impl AsyncIndexerRHandle { - /// Construct new AsyncIndexerRHandle instance +impl AsyncRichIndexerHandle { + /// Construct new AsyncRichIndexerHandle instance pub fn new(store: SQLXPool, pool: Option>>) -> Self { Self { store, _pool: pool } } } -impl AsyncIndexerRHandle { +impl AsyncRichIndexerHandle { /// Get indexer current tip pub async fn query_indexer_tip(&self) -> Result, Error> { let query = SQLXPool::new_query( diff --git a/util/rich-indexer/src/indexer_handle/mod.rs b/util/rich-indexer/src/indexer_handle/mod.rs index 210587ebea..5c183e2cc2 100644 --- a/util/rich-indexer/src/indexer_handle/mod.rs +++ b/util/rich-indexer/src/indexer_handle/mod.rs @@ -10,21 +10,21 @@ use ckb_jsonrpc_types::IndexerTip; use std::sync::{Arc, RwLock}; -/// Handle to the indexer-r. +/// Handle to the rich-indexer. /// /// The handle is internally reference-counted and can be freely cloned. -/// A handle can be obtained using the IndexerRService::handle method. +/// A handle can be obtained using the RichIndexerService::handle method. #[derive(Clone)] -pub struct IndexerRHandle { - async_handle: AsyncIndexerRHandle, +pub struct RichIndexerHandle { + async_handle: AsyncRichIndexerHandle, async_runtime: Handle, } -impl IndexerRHandle { - /// Construct new IndexerRHandle instance +impl RichIndexerHandle { + /// Construct new RichIndexerHandle instance pub fn new(store: SQLXPool, pool: Option>>, async_handle: Handle) -> Self { Self { - async_handle: AsyncIndexerRHandle::new(store, pool), + async_handle: AsyncRichIndexerHandle::new(store, pool), async_runtime: async_handle, } } diff --git a/util/rich-indexer/src/lib.rs b/util/rich-indexer/src/lib.rs index a6373f950b..fae4db8d20 100644 --- a/util/rich-indexer/src/lib.rs +++ b/util/rich-indexer/src/lib.rs @@ -1,4 +1,4 @@ -//! CKB's built-in indexer-r, based on relational database, +//! CKB's built-in rich-indexer, based on relational database, //! which shares data with the ckb node by creating secondary db instances. mod indexer; @@ -6,11 +6,11 @@ mod indexer_handle; mod service; mod store; -pub use indexer_handle::{AsyncIndexerRHandle, IndexerRHandle}; -pub use service::IndexerRService; +pub use indexer_handle::{AsyncRichIndexerHandle, RichIndexerHandle}; +pub use service::RichIndexerService; #[cfg(test)] mod tests; #[cfg(test)] -pub(crate) use indexer::AsyncIndexerR; +pub(crate) use indexer::AsyncRichIndexer; diff --git a/util/rich-indexer/src/service.rs b/util/rich-indexer/src/service.rs index 66fc6d5fe5..ddfa7bd103 100644 --- a/util/rich-indexer/src/service.rs +++ b/util/rich-indexer/src/service.rs @@ -1,19 +1,19 @@ -//!The indexer-r service. +//!The rich-indexer service. -use crate::indexer::IndexerR; +use crate::indexer::RichIndexer; use crate::store::SQLXPool; -use crate::{AsyncIndexerRHandle, IndexerRHandle}; +use crate::{AsyncRichIndexerHandle, RichIndexerHandle}; use ckb_app_config::IndexerConfig; use ckb_async_runtime::Handle; use ckb_indexer_sync::{CustomFilters, IndexerSyncService, PoolService, SecondaryDB}; use ckb_notify::NotifyController; -pub(crate) const SUBSCRIBER_NAME: &str = "Indexer-R"; +pub(crate) const SUBSCRIBER_NAME: &str = "Rich-Indexer"; -/// Indexer-R service +/// Rich-Indexer service #[derive(Clone)] -pub struct IndexerRService { +pub struct RichIndexerService { store: SQLXPool, sync: IndexerSyncService, block_filter: Option, @@ -21,8 +21,8 @@ pub struct IndexerRService { async_handle: Handle, } -impl IndexerRService { - /// Construct new IndexerRService instance +impl RichIndexerService { + /// Construct new RichIndexerService instance pub fn new( ckb_db: SecondaryDB, pool_service: PoolService, @@ -31,8 +31,8 @@ impl IndexerRService { ) -> Self { let mut store = SQLXPool::default(); async_handle - .block_on(store.connect(&config.indexer_r)) - .expect("Failed to connect to indexer-r database"); + .block_on(store.connect(&config.rich_indexer)) + .expect("Failed to connect to rich-indexer database"); let sync = IndexerSyncService::new(ckb_db, pool_service, &config.into(), async_handle.clone()); @@ -45,10 +45,10 @@ impl IndexerRService { } } - fn get_indexer(&self) -> IndexerR { + fn get_indexer(&self) -> RichIndexer { // assume that long fork will not happen >= 100 blocks. let keep_num = 100; - IndexerR::new( + RichIndexer::new( self.store.clone(), keep_num, 1000, @@ -67,23 +67,23 @@ impl IndexerRService { ) } - /// Returns a handle to the indexer-r. + /// Returns a handle to the rich-indexer. /// - /// The returned handle can be used to get data from indexer-r, + /// The returned handle can be used to get data from rich-indexer, /// and can be cloned to allow moving the Handle to other threads. - pub fn handle(&self) -> IndexerRHandle { - IndexerRHandle::new( + pub fn handle(&self) -> RichIndexerHandle { + RichIndexerHandle::new( self.store.clone(), self.sync.pool(), self.async_handle.clone(), ) } - /// Returns a handle to the indexer-r. + /// Returns a handle to the rich-indexer. /// - /// The returned handle can be used to get data from indexer-r, + /// The returned handle can be used to get data from rich-indexer, /// and can be cloned to allow moving the Handle to other threads. - pub fn async_handle(&self) -> AsyncIndexerRHandle { - AsyncIndexerRHandle::new(self.store.clone(), self.sync.pool()) + pub fn async_handle(&self) -> AsyncRichIndexerHandle { + AsyncRichIndexerHandle::new(self.store.clone(), self.sync.pool()) } } diff --git a/util/rich-indexer/src/store/mod.rs b/util/rich-indexer/src/store/mod.rs index 72d6fb1120..2b085d6f95 100644 --- a/util/rich-indexer/src/store/mod.rs +++ b/util/rich-indexer/src/store/mod.rs @@ -5,7 +5,7 @@ use page::COUNT_COLUMN; pub use page::{build_next_cursor, PaginationRequest, PaginationResponse}; use anyhow::{anyhow, Result}; -use ckb_app_config::{DBDriver, IndexerRConfig}; +use ckb_app_config::{DBDriver, RichIndexerConfig}; use futures::TryStreamExt; use log::LevelFilter; use once_cell::sync::OnceCell; @@ -72,7 +72,7 @@ impl SQLXPool { SQLXPool::new(10, 0, 60, 1800, 30) } - pub async fn connect(&mut self, db_config: &IndexerRConfig) -> Result<()> { + pub async fn connect(&mut self, db_config: &RichIndexerConfig) -> Result<()> { self.driver .set(db_config.db_type.clone()) .map_err(|_| anyhow!("set db driver failed!"))?; @@ -234,7 +234,7 @@ impl SQLXPool { self.max_conn } - async fn create_tables_for_sqlite(&self, config: &IndexerRConfig) -> Result<()> { + async fn create_tables_for_sqlite(&self, config: &RichIndexerConfig) -> Result<()> { let mut tx = self.transaction().await?; sqlx::query(SQL_SQLITE_CREATE_TABLE) .execute(&mut *tx) @@ -252,7 +252,7 @@ impl SQLXPool { tx.commit().await.map_err(Into::into) } - async fn create_tables_for_postgres(&mut self, config: &IndexerRConfig) -> Result<()> { + async fn create_tables_for_postgres(&mut self, config: &RichIndexerConfig) -> Result<()> { let commands_table = SQL_POSTGRES_CREATE_TABLE.split(';'); let commands_index = SQL_POSTGRES_CREATE_INDEX.split(';'); for command in commands_table.chain(commands_index) { @@ -272,7 +272,10 @@ impl SQLXPool { tx.commit().await.map_err(Into::into) } - pub async fn is_postgres_require_init(&mut self, db_config: &IndexerRConfig) -> Result { + pub async fn is_postgres_require_init( + &mut self, + db_config: &RichIndexerConfig, + ) -> Result { // Connect to the "postgres" database first let mut temp_config = db_config.clone(); temp_config.db_name = "postgres".to_string(); @@ -304,11 +307,11 @@ pub(crate) fn fetch_count_sql(table_name: &str) -> String { format!("SELECT COUNT(*) as {} FROM {}", COUNT_COLUMN, table_name) } -fn build_url_for_sqlite(db_config: &IndexerRConfig) -> String { +fn build_url_for_sqlite(db_config: &RichIndexerConfig) -> String { db_config.db_type.to_string() + db_config.store.to_str().expect("get store path") } -fn build_url_for_postgres(db_config: &IndexerRConfig) -> String { +fn build_url_for_postgres(db_config: &RichIndexerConfig) -> String { db_config.db_type.to_string() + db_config.db_user.as_str() + ":" @@ -321,7 +324,7 @@ fn build_url_for_postgres(db_config: &IndexerRConfig) -> String { + db_config.db_name.as_str() } -fn is_sqlite_require_init(db_config: &IndexerRConfig) -> bool { +fn is_sqlite_require_init(db_config: &RichIndexerConfig) -> bool { // for test if db_config.store == Into::::into(MEMORY_DB) { return true; diff --git a/util/rich-indexer/src/tests/mod.rs b/util/rich-indexer/src/tests/mod.rs index 1712723554..551cc594ec 100644 --- a/util/rich-indexer/src/tests/mod.rs +++ b/util/rich-indexer/src/tests/mod.rs @@ -1,7 +1,7 @@ use crate::store::SQLXPool; -use crate::{AsyncIndexerR, AsyncIndexerRHandle}; +use crate::{AsyncRichIndexer, AsyncRichIndexerHandle}; -use ckb_app_config::IndexerRConfig; +use ckb_app_config::RichIndexerConfig; use ckb_indexer_sync::CustomFilters; use ckb_jsonrpc_types::BlockView as JsonBlockView; @@ -10,7 +10,7 @@ const BLOCK_DIR: &str = "./src/tests/data/blocks/"; async fn connect_sqlite(store_path: &str) -> SQLXPool { let mut pool = SQLXPool::default(); - let config = IndexerRConfig { + let config = RichIndexerConfig { store: store_path.into(), ..Default::default() }; @@ -20,7 +20,7 @@ async fn connect_sqlite(store_path: &str) -> SQLXPool { async fn insert_blocks(store: SQLXPool) { let data_path = String::from(BLOCK_DIR); - let indexer = AsyncIndexerR::new(store, 100, 1000, None, CustomFilters::new(None, None)); + let indexer = AsyncRichIndexer::new(store, 100, 1000, None, CustomFilters::new(None, None)); for i in 0..10 { indexer .append(&read_block_view(i, data_path.clone()).into()) @@ -38,7 +38,7 @@ pub fn read_block_view(number: u64, dir_path: String) -> JsonBlockView { #[tokio::test] async fn test_query_tip() { let pool = connect_sqlite(MEMORY_DB).await; - let indexer = AsyncIndexerRHandle::new(pool.clone(), None); + let indexer = AsyncRichIndexerHandle::new(pool.clone(), None); let res = indexer.query_indexer_tip().await.unwrap(); assert!(res.is_none()); @@ -54,7 +54,7 @@ async fn test_query_tip() { #[tokio::test] async fn test_append_blocks() { let storage = connect_sqlite(MEMORY_DB).await; - let indexer = AsyncIndexerR::new( + let indexer = AsyncRichIndexer::new( storage.clone(), 100, 1000, @@ -110,7 +110,7 @@ async fn test_append_blocks() { #[tokio::test] async fn test_rollback_block() { let storage = connect_sqlite(MEMORY_DB).await; - let indexer = AsyncIndexerR::new( + let indexer = AsyncRichIndexer::new( storage.clone(), 100, 1000, @@ -168,7 +168,7 @@ async fn test_rollback_block() { #[tokio::test] async fn test_block_filter_and_rollback_block() { let storage = connect_sqlite(MEMORY_DB).await; - let indexer = AsyncIndexerR::new( + let indexer = AsyncRichIndexer::new( storage.clone(), 100, 1000,