-
Notifications
You must be signed in to change notification settings - Fork 11.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[indexer-alt] add cp_sequence_numbers table and handler to indexer-al…
…t-framework, add as an optional pipeline to indexer-alt (#20626) ## Description Framework introduces `cp_sequence_numbers` which maps a given checkpoint sequence number to its first tx and containing epoch. This will be used later during pruning, for tables that need more info than the prunable checkpoint range. ## Test plan How did you test the new or updated feature? --- ## Release notes Check each box that your changes affect. If none of the boxes relate to your changes, release notes aren't required. For each box you select, include information after the relevant heading that describes the impact of your changes that a user might notice and any actions they must take to implement updates. - [ ] Protocol: - [ ] Nodes (Validators and Full nodes): - [ ] Indexer: - [ ] JSON-RPC: - [ ] GraphQL: - [ ] CLI: - [ ] Rust SDK: - [ ] REST API:
- Loading branch information
Showing
12 changed files
with
103 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
crates/sui-indexer-alt-framework/migrations/2024-12-11-234958_cp_sequence_numbers/down.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
DROP TABLE IF EXISTS cp_sequence_numbers; |
11 changes: 11 additions & 0 deletions
11
crates/sui-indexer-alt-framework/migrations/2024-12-11-234958_cp_sequence_numbers/up.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
-- 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 | ||
-- transactions in the checkpoint. | ||
tx_lo BIGINT NOT NULL, | ||
-- The epoch this checkpoint belongs to. | ||
epoch BIGINT NOT NULL | ||
); |
53 changes: 53 additions & 0 deletions
53
crates/sui-indexer-alt-framework/src/handlers/cp_sequence_numbers.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
// Copyright (c) Mysten Labs, Inc. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
use std::sync::Arc; | ||
|
||
use crate::pipeline::{concurrent::Handler, Processor}; | ||
use crate::schema::cp_sequence_numbers; | ||
use anyhow::Result; | ||
use diesel::prelude::*; | ||
use diesel_async::RunQueryDsl; | ||
use sui_field_count::FieldCount; | ||
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_sequence_numbers)] | ||
pub struct StoredCpSequenceNumbers { | ||
pub cp_sequence_number: i64, | ||
pub tx_lo: i64, | ||
pub epoch: i64, | ||
} | ||
|
||
pub struct CpSequenceNumbers; | ||
|
||
impl Processor for CpSequenceNumbers { | ||
const NAME: &'static str = "cp_sequence_numbers"; | ||
|
||
type Value = StoredCpSequenceNumbers; | ||
|
||
fn process(&self, checkpoint: &Arc<CheckpointData>) -> Result<Vec<Self::Value>> { | ||
let cp_sequence_number = checkpoint.checkpoint_summary.sequence_number as i64; | ||
let network_total_transactions = | ||
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![StoredCpSequenceNumbers { | ||
cp_sequence_number, | ||
tx_lo, | ||
epoch, | ||
}]) | ||
} | ||
} | ||
|
||
#[async_trait::async_trait] | ||
impl Handler for CpSequenceNumbers { | ||
async fn commit(values: &[Self::Value], conn: &mut db::Connection<'_>) -> Result<usize> { | ||
Ok(diesel::insert_into(cp_sequence_numbers::table) | ||
.values(values) | ||
.on_conflict_do_nothing() | ||
.execute(conn) | ||
.await?) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
// Copyright (c) Mysten Labs, Inc. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
pub mod cp_sequence_numbers; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# sui-indexer-alt | ||
|
||
## Running | ||
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 | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters