forked from MystenLabs/sui
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[indexer] correctness check vs full node txns against indexers (Myste…
…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
1 parent
69dd197
commit 6a8ac01
Showing
4 changed files
with
108 additions
and
8 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,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, | ||
} |
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