From 183e9d829361100c784eb7a563109f7edd1f688f Mon Sep 17 00:00:00 2001 From: Will Yang Date: Thu, 19 Dec 2024 09:57:28 -0800 Subject: [PATCH] rename cp_mapping to cp_sequence_numbers --- .../2024-12-11-234958_cp_mapping/down.sql | 1 - .../down.sql | 1 + .../up.sql | 4 +++- .../{cp_mapping.rs => cp_sequence_numbers.rs} | 20 +++++++++---------- .../src/handlers/mod.rs | 2 +- .../sui-indexer-alt-framework/src/schema.rs | 4 ++-- crates/sui-indexer-alt/src/README.md | 2 +- crates/sui-indexer-alt/src/config.rs | 6 +++--- crates/sui-indexer-alt/src/lib.rs | 6 +++--- 9 files changed, 24 insertions(+), 22 deletions(-) delete mode 100644 crates/sui-indexer-alt-framework/migrations/2024-12-11-234958_cp_mapping/down.sql create mode 100644 crates/sui-indexer-alt-framework/migrations/2024-12-11-234958_cp_sequence_numbers/down.sql rename crates/sui-indexer-alt-framework/migrations/{2024-12-11-234958_cp_mapping => 2024-12-11-234958_cp_sequence_numbers}/up.sql (67%) rename crates/sui-indexer-alt-framework/src/handlers/{cp_mapping.rs => cp_sequence_numbers.rs} (75%) diff --git a/crates/sui-indexer-alt-framework/migrations/2024-12-11-234958_cp_mapping/down.sql b/crates/sui-indexer-alt-framework/migrations/2024-12-11-234958_cp_mapping/down.sql deleted file mode 100644 index 1ee485b90186d..0000000000000 --- a/crates/sui-indexer-alt-framework/migrations/2024-12-11-234958_cp_mapping/down.sql +++ /dev/null @@ -1 +0,0 @@ -DROP TABLE IF EXISTS cp_mapping; diff --git a/crates/sui-indexer-alt-framework/migrations/2024-12-11-234958_cp_sequence_numbers/down.sql b/crates/sui-indexer-alt-framework/migrations/2024-12-11-234958_cp_sequence_numbers/down.sql new file mode 100644 index 0000000000000..b505389104886 --- /dev/null +++ b/crates/sui-indexer-alt-framework/migrations/2024-12-11-234958_cp_sequence_numbers/down.sql @@ -0,0 +1 @@ +DROP TABLE IF EXISTS cp_sequence_numbers; diff --git a/crates/sui-indexer-alt-framework/migrations/2024-12-11-234958_cp_mapping/up.sql b/crates/sui-indexer-alt-framework/migrations/2024-12-11-234958_cp_sequence_numbers/up.sql similarity index 67% rename from crates/sui-indexer-alt-framework/migrations/2024-12-11-234958_cp_mapping/up.sql rename to crates/sui-indexer-alt-framework/migrations/2024-12-11-234958_cp_sequence_numbers/up.sql index e4c6f00b5aecc..0a37896190447 100644 --- a/crates/sui-indexer-alt-framework/migrations/2024-12-11-234958_cp_mapping/up.sql +++ b/crates/sui-indexer-alt-framework/migrations/2024-12-11-234958_cp_sequence_numbers/up.sql @@ -1,4 +1,6 @@ -CREATE TABLE IF NOT EXISTS cp_mapping +-- This table maps a checkpoint sequence number to the containing epoch and first transaction +-- sequence number in the checkpoint. +CREATE TABLE IF NOT EXISTS cp_sequence_numbers ( cp_sequence_number BIGINT PRIMARY KEY, -- The network total transactions at the end of this checkpoint subtracted by the number of diff --git a/crates/sui-indexer-alt-framework/src/handlers/cp_mapping.rs b/crates/sui-indexer-alt-framework/src/handlers/cp_sequence_numbers.rs similarity index 75% rename from crates/sui-indexer-alt-framework/src/handlers/cp_mapping.rs rename to crates/sui-indexer-alt-framework/src/handlers/cp_sequence_numbers.rs index 7cb933bd89b09..0948c74a9c789 100644 --- a/crates/sui-indexer-alt-framework/src/handlers/cp_mapping.rs +++ b/crates/sui-indexer-alt-framework/src/handlers/cp_sequence_numbers.rs @@ -4,7 +4,7 @@ use std::sync::Arc; use crate::pipeline::{concurrent::Handler, Processor}; -use crate::schema::cp_mapping; +use crate::schema::cp_sequence_numbers; use anyhow::Result; use diesel::prelude::*; use diesel_async::RunQueryDsl; @@ -13,19 +13,19 @@ use sui_pg_db::{self as db}; use sui_types::full_checkpoint_content::CheckpointData; #[derive(Insertable, Selectable, Queryable, Debug, Clone, FieldCount)] -#[diesel(table_name = cp_mapping)] -pub struct StoredCpMapping { +#[diesel(table_name = cp_sequence_numbers)] +pub struct StoredCpSequenceNumbers { pub cp_sequence_number: i64, pub tx_lo: i64, pub epoch: i64, } -pub struct CpMapping; +pub struct CpSequenceNumbers; -impl Processor for CpMapping { - const NAME: &'static str = "cp_mapping"; +impl Processor for CpSequenceNumbers { + const NAME: &'static str = "cp_sequence_numbers"; - type Value = StoredCpMapping; + type Value = StoredCpSequenceNumbers; fn process(&self, checkpoint: &Arc) -> Result> { let cp_sequence_number = checkpoint.checkpoint_summary.sequence_number as i64; @@ -33,7 +33,7 @@ impl Processor for CpMapping { checkpoint.checkpoint_summary.network_total_transactions as i64; let tx_lo = network_total_transactions - checkpoint.transactions.len() as i64; let epoch = checkpoint.checkpoint_summary.epoch as i64; - Ok(vec![StoredCpMapping { + Ok(vec![StoredCpSequenceNumbers { cp_sequence_number, tx_lo, epoch, @@ -42,9 +42,9 @@ impl Processor for CpMapping { } #[async_trait::async_trait] -impl Handler for CpMapping { +impl Handler for CpSequenceNumbers { async fn commit(values: &[Self::Value], conn: &mut db::Connection<'_>) -> Result { - Ok(diesel::insert_into(cp_mapping::table) + Ok(diesel::insert_into(cp_sequence_numbers::table) .values(values) .on_conflict_do_nothing() .execute(conn) diff --git a/crates/sui-indexer-alt-framework/src/handlers/mod.rs b/crates/sui-indexer-alt-framework/src/handlers/mod.rs index f0a0685a64044..350ec29d5fd25 100644 --- a/crates/sui-indexer-alt-framework/src/handlers/mod.rs +++ b/crates/sui-indexer-alt-framework/src/handlers/mod.rs @@ -1,4 +1,4 @@ // Copyright (c) Mysten Labs, Inc. // SPDX-License-Identifier: Apache-2.0 -pub mod cp_mapping; +pub mod cp_sequence_numbers; diff --git a/crates/sui-indexer-alt-framework/src/schema.rs b/crates/sui-indexer-alt-framework/src/schema.rs index d6c361f246fce..4a9d30cf9bbeb 100644 --- a/crates/sui-indexer-alt-framework/src/schema.rs +++ b/crates/sui-indexer-alt-framework/src/schema.rs @@ -3,7 +3,7 @@ // @generated automatically by Diesel CLI. diesel::table! { - cp_mapping (cp_sequence_number) { + cp_sequence_numbers (cp_sequence_number) { cp_sequence_number -> Int8, tx_lo -> Int8, epoch -> Int8, @@ -23,4 +23,4 @@ diesel::table! { } } -diesel::allow_tables_to_appear_in_same_query!(cp_mapping, watermarks,); +diesel::allow_tables_to_appear_in_same_query!(cp_sequence_numbers, watermarks,); diff --git a/crates/sui-indexer-alt/src/README.md b/crates/sui-indexer-alt/src/README.md index 337bbf0cd6e25..d4f0046058251 100644 --- a/crates/sui-indexer-alt/src/README.md +++ b/crates/sui-indexer-alt/src/README.md @@ -1,7 +1,7 @@ # sui-indexer-alt ## Running -Need to provide a config file, and either remote-store-url or local-ingestion-path. If both are provided, remote-store-url will be used. +The required flags are --remote-store-url (or --local-ingestion-path) and the --config. If both are provided, remote-store-url will be used. ``` cargo run --bin sui-indexer-alt -- --database-url {url} indexer --remote-store-url https://checkpoints.mainnet.sui.io --skip-watermark --first-checkpoint 68918060 --last-checkpoint 68919060 --config indexer_alt_config.toml diff --git a/crates/sui-indexer-alt/src/config.rs b/crates/sui-indexer-alt/src/config.rs index 5b30464a39c66..22472a1209fc7 100644 --- a/crates/sui-indexer-alt/src/config.rs +++ b/crates/sui-indexer-alt/src/config.rs @@ -140,7 +140,7 @@ pub struct PipelineLayer { pub coin_balance_buckets_pruner: Option, // All concurrent pipelines - pub cp_mapping: Option, + pub cp_sequence_numbers: Option, pub ev_emit_mod: Option, pub ev_struct_inst: Option, pub kv_checkpoints: Option, @@ -274,7 +274,7 @@ impl PipelineLayer { obj_info_pruner: Some(Default::default()), coin_balance_buckets: Some(Default::default()), coin_balance_buckets_pruner: Some(Default::default()), - cp_mapping: Some(Default::default()), + cp_sequence_numbers: Some(Default::default()), ev_emit_mod: Some(Default::default()), ev_struct_inst: Some(Default::default()), kv_checkpoints: Some(Default::default()), @@ -411,7 +411,7 @@ impl Merge for PipelineLayer { coin_balance_buckets_pruner: self .coin_balance_buckets_pruner .merge(other.coin_balance_buckets_pruner), - cp_mapping: self.cp_mapping.merge(other.cp_mapping), + cp_sequence_numbers: self.cp_sequence_numbers.merge(other.cp_sequence_numbers), ev_emit_mod: self.ev_emit_mod.merge(other.ev_emit_mod), ev_struct_inst: self.ev_struct_inst.merge(other.ev_struct_inst), kv_checkpoints: self.kv_checkpoints.merge(other.kv_checkpoints), diff --git a/crates/sui-indexer-alt/src/lib.rs b/crates/sui-indexer-alt/src/lib.rs index 96023e505e2b3..ba4c59c3052de 100644 --- a/crates/sui-indexer-alt/src/lib.rs +++ b/crates/sui-indexer-alt/src/lib.rs @@ -16,7 +16,7 @@ use handlers::{ tx_affected_objects::TxAffectedObjects, tx_balance_changes::TxBalanceChanges, tx_calls::TxCalls, tx_digests::TxDigests, tx_kinds::TxKinds, }; -use sui_indexer_alt_framework::handlers::cp_mapping::CpMapping; +use sui_indexer_alt_framework::handlers::cp_sequence_numbers::CpSequenceNumbers; use sui_indexer_alt_framework::ingestion::{ClientArgs, IngestionConfig}; use sui_indexer_alt_framework::pipeline::{ concurrent::{ConcurrentConfig, PrunerConfig}, @@ -63,7 +63,7 @@ pub async fn start_indexer( obj_info_pruner, coin_balance_buckets, coin_balance_buckets_pruner, - cp_mapping, + cp_sequence_numbers, ev_emit_mod, ev_struct_inst, kv_checkpoints, @@ -203,7 +203,7 @@ pub async fn start_indexer( ); // Unpruned concurrent pipelines - add_concurrent!(CpMapping, cp_mapping); + add_concurrent!(CpSequenceNumbers, cp_sequence_numbers); add_concurrent!(EvEmitMod, ev_emit_mod); add_concurrent!(EvStructInst, ev_struct_inst); add_concurrent!(KvCheckpoints, kv_checkpoints);