Skip to content

Commit

Permalink
[indexer] correctness check vs full node txns against indexers (Myste…
Browse files Browse the repository at this point in the history
…nLabs#8682)

## Description 

Adding txns comparison script between FN and Indexer endpoints.

## Test Plan 

How did you test the new or updated feature?

Running locally, but we do not have generated local txns yet. 

Tested via after starting FN and indexer: 

cargo run --package sui-indexer --bin checkpoint_check --
--fn-rpc-client-url "http://0.0.0.0:9000" --indexer-rpc-client-url
'http://127.0.0.1:3030'

---
If your changes are not user-facing and not a breaking change, you can
skip the following section. Otherwise, please indicate what changed, and
then add to the Release Notes section as highlighted during the release
process.

### Type of Change (Check all that apply)

- [ ] user-visible impact
- [ ] breaking change for a client SDKs
- [ ] breaking change for FNs (FN binary must upgrade)
- [ ] breaking change for validators or node operators (must upgrade
binaries)
- [ ] breaking change for on-chain data layout
- [ ] necessitate either a data wipe or data migration

### Release notes
  • Loading branch information
healthydeve authored Mar 2, 2023
1 parent 69dd197 commit 6a8ac01
Show file tree
Hide file tree
Showing 4 changed files with 108 additions and 8 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions crates/sui-indexer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ chrono = { version = "0.4.23", features = [
"clock",
"serde",
] }
rand = "0.8"
clap = { version = "3.2.17", features = ["derive"] }
diesel = { version = "2.0.0", features = ["chrono", "postgres", "r2d2", "serde_json"] }
futures = "0.3.23"
Expand Down
87 changes: 87 additions & 0 deletions crates/sui-indexer/src/bin/checkpoint_check.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
// Copyright (c) Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0

use anyhow::Result;
use clap::Parser;
use rand::Rng;
use sui_indexer::new_rpc_client;
use sui_json_rpc_types::CheckpointId;
use tracing::info;

#[tokio::main]
async fn main() -> Result<()> {
info!("Running correctness check for indexer...");
let test_config = TestConfig::parse();
let fn_rpc_client = new_rpc_client(test_config.fn_rpc_client_url.clone()).await?;
let indexer_rpc_client = new_rpc_client(test_config.indexer_rpc_client_url.clone()).await?;

let latest_checkpoint = indexer_rpc_client
.read_api()
.get_latest_checkpoint_sequence_number()
.await?;

let num = rand::thread_rng().gen_range(10..100);

let target_checkpoint = if latest_checkpoint - num > 0 {
latest_checkpoint - num
} else {
1
};

let fn_checkpoint = fn_rpc_client
.read_api()
.get_checkpoint(CheckpointId::SequenceNumber(target_checkpoint))
.await?;

let indexer_checkpoint = indexer_rpc_client
.read_api()
.get_checkpoint(CheckpointId::SequenceNumber(target_checkpoint))
.await?;

assert_eq!(
fn_checkpoint.transactions.len(),
indexer_checkpoint.transactions.len(),
"Checkpoint number {} length is not the same for FN and Indexer",
target_checkpoint
);

let fn_checkpoint_transactions = fn_checkpoint.transactions;
let indexer_checkpoint_transactions = indexer_checkpoint.transactions;

for i in 0..fn_checkpoint_transactions.len() {
let fn_txn_digest = fn_checkpoint_transactions.get(i).cloned();
let idx_txn_digest = indexer_checkpoint_transactions.get(i).cloned();
assert_eq!(
fn_txn_digest, idx_txn_digest,
"Checkpoint transactions mismatch found in {}",
target_checkpoint
);

if let (Some(fn_txn_digest), Some(idx_txn_digest)) = (fn_txn_digest, idx_txn_digest) {
let fn_sui_txn_response = fn_rpc_client
.read_api()
.get_transaction(fn_txn_digest)
.await?;
let indexer_sui_txn_response = indexer_rpc_client
.read_api()
.get_transaction(idx_txn_digest)
.await?;
assert_eq!(
fn_sui_txn_response, indexer_sui_txn_response,
"Checkpoint transactions mismatch found in {}",
target_checkpoint
);
}
}

Ok(())
}

#[derive(Parser)]
#[clap(name = "Transactions Test")]
pub struct TestConfig {
#[clap(long)]
pub fn_rpc_client_url: String,
#[clap(long)]
pub indexer_rpc_client_url: String,
}
27 changes: 19 additions & 8 deletions crates/sui-json-rpc-types/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,17 @@ pub struct SuiTransactionResponse {
pub checkpoint: Option<CheckpointSequenceNumber>,
}

/// We are specifically ignoring events for now until events become more stable.
impl PartialEq for SuiTransactionResponse {
fn eq(&self, other: &Self) -> bool {
self.transaction == other.transaction
&& self.effects == other.effects
&& self.timestamp_ms == other.timestamp_ms
&& self.confirmed_local_execution == other.confirmed_local_execution
&& self.checkpoint == other.checkpoint
}
}

#[allow(clippy::large_enum_variant)]
#[derive(Serialize, Deserialize, Debug, JsonSchema)]
pub enum SuiTBlsSignObjectCommitmentType {
Expand Down Expand Up @@ -1376,7 +1387,7 @@ impl From<PayAllSui> for SuiPayAllSui {
}
}

#[derive(Debug, Deserialize, Serialize, JsonSchema, Clone)]
#[derive(Debug, Deserialize, Serialize, JsonSchema, Clone, PartialEq, Eq)]
#[serde(rename = "GasData", rename_all = "camelCase")]
pub struct SuiGasData {
pub payment: SuiObjectRef,
Expand All @@ -1385,7 +1396,7 @@ pub struct SuiGasData {
pub budget: u64,
}

#[derive(Debug, Deserialize, Serialize, JsonSchema, Clone)]
#[derive(Debug, Deserialize, Serialize, JsonSchema, Clone, PartialEq, Eq)]
#[serde(rename = "TransactionData", rename_all = "camelCase")]
pub struct SuiTransactionData {
pub transactions: Vec<SuiTransactionKind>,
Expand Down Expand Up @@ -1452,7 +1463,7 @@ impl TryFrom<TransactionData> for SuiTransactionData {
}
}

#[derive(Debug, Deserialize, Serialize, JsonSchema, Clone)]
#[derive(Debug, Deserialize, Serialize, JsonSchema, Clone, PartialEq, Eq)]
#[serde(rename = "Transaction", rename_all = "camelCase")]
pub struct SuiTransaction {
pub data: SuiTransactionData,
Expand All @@ -1479,19 +1490,19 @@ impl Display for SuiTransaction {
}
}

#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema, PartialEq, Eq)]
pub struct SuiGenesisTransaction {
pub objects: Vec<ObjectID>,
}

#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema, PartialEq, Eq)]
pub struct SuiConsensusCommitPrologue {
pub epoch: u64,
pub round: u64,
pub commit_timestamp_ms: u64,
}

#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema, PartialEq, Eq)]
#[serde(rename = "TransactionKind")]
pub enum SuiTransactionKind {
/// Initiate an object transfer between addresses
Expand Down Expand Up @@ -1686,7 +1697,7 @@ impl TryFrom<SingleTransactionKind> for SuiTransactionKind {
}
}

#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema, PartialEq, Eq)]
#[serde(rename = "MoveCall", rename_all = "camelCase")]
pub struct SuiMoveCall {
pub package: ObjectID,
Expand All @@ -1698,7 +1709,7 @@ pub struct SuiMoveCall {
pub arguments: Vec<SuiJsonValue>,
}

#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema, PartialEq, Eq)]
pub struct SuiChangeEpoch {
pub epoch: EpochId,
pub storage_charge: u64,
Expand Down

0 comments on commit 6a8ac01

Please sign in to comment.