Skip to content

Commit

Permalink
Change all indexer-r to ckb-rich-indexer.
Browse files Browse the repository at this point in the history
  • Loading branch information
EthanYuan committed Dec 17, 2023
1 parent 3f925bb commit a20dec5
Show file tree
Hide file tree
Showing 19 changed files with 138 additions and 136 deletions.
6 changes: 3 additions & 3 deletions resource/ckb.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down Expand Up @@ -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"
Expand Down
6 changes: 3 additions & 3 deletions rpc/src/module/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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};
24 changes: 12 additions & 12 deletions rpc/src/module/indexer_r.rs → rpc/src/module/rich_indexer.rs
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -23,7 +23,7 @@ pub trait IndexerRRpc {
/// {
/// "id": 2,
/// "jsonrpc": "2.0",
/// "method": "get_indexer_r_tip"
/// "method": "get_rich_indexer_tip"
/// }
/// ```
///
Expand All @@ -39,24 +39,24 @@ pub trait IndexerRRpc {
/// "id": 2
/// }
/// ```
#[rpc(name = "get_indexer_r_tip")]
async fn get_indexer_r_tip(&self) -> Result<Option<IndexerTip>>;
#[rpc(name = "get_rich_indexer_tip")]
async fn get_rich_indexer_tip(&self) -> Result<Option<IndexerTip>>;
}

#[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<Option<IndexerTip>> {
impl RichIndexerRpc for RichIndexerRpcImpl {
async fn get_rich_indexer_tip(&self) -> Result<Option<IndexerTip>> {
self.handle
.query_indexer_tip()
.await
Expand Down
35 changes: 17 additions & 18 deletions rpc/src/service_builder.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand All @@ -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;
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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
)
}

Expand Down
4 changes: 2 additions & 2 deletions util/app-config/src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]`.
Expand Down
10 changes: 5 additions & 5 deletions util/app-config/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Expand Down Expand Up @@ -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"),
)
}

Expand Down
14 changes: 7 additions & 7 deletions util/app-config/src/configs/indexer.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand Down Expand Up @@ -30,9 +30,9 @@ pub struct IndexerConfig {
/// Maximal db info log files to be kept.
#[serde(default)]
pub db_keep_log_file_num: Option<NonZeroUsize>,
/// IndexerR config options
/// Rich indexer config options
#[serde(default)]
pub indexer_r: IndexerRConfig,
pub rich_indexer: RichIndexerConfig,
}

const fn default_poll_interval() -> u64 {
Expand All @@ -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(),
}
}
}
Expand All @@ -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
Expand All @@ -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",
);
}
Expand Down
4 changes: 2 additions & 2 deletions util/app-config/src/configs/mod.rs
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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<u64>,
/// The init tip block hash
#[serde(default)]
pub init_tip_hash: Option<H256>,
/// 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.
Expand All @@ -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,
Expand All @@ -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 {
Expand Down
8 changes: 4 additions & 4 deletions util/app-config/src/configs/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ pub enum Module {
Subscription,
Debug,
Indexer,
IndexerR,
RichIndexer,
}

/// RPC config options.
Expand Down Expand Up @@ -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)
}
}
2 changes: 1 addition & 1 deletion util/app-config/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
})
}

Expand Down
4 changes: 2 additions & 2 deletions util/launcher/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
Loading

0 comments on commit a20dec5

Please sign in to comment.