From ec15e98b7095b5ec2b783749ce7623b48fc89650 Mon Sep 17 00:00:00 2001 From: aniketfuryrocks Date: Fri, 3 Feb 2023 15:42:41 +0530 Subject: [PATCH] test --- src/block_store.rs | 2 ++ src/workers/block_listenser.rs | 11 ++++------- tests/diff.rs | 34 ++++++++++++++++++++++++++++++++++ 3 files changed, 40 insertions(+), 7 deletions(-) create mode 100644 tests/diff.rs diff --git a/src/block_store.rs b/src/block_store.rs index 323a63a4..c9da7320 100644 --- a/src/block_store.rs +++ b/src/block_store.rs @@ -1,6 +1,7 @@ use std::sync::Arc; use dashmap::DashMap; +use log::info; use solana_rpc_client::nonblocking::rpc_client::RpcClient; use solana_sdk::commitment_config::CommitmentConfig; use tokio::sync::RwLock; @@ -91,6 +92,7 @@ impl BlockStore { block_info: BlockInformation, commitment_config: CommitmentConfig, ) { + info!("{commitment_config:?} {blockhash:?}, {block_info:?}"); // Write to block store first in order to prevent // any race condition i.e prevent some one to // ask the map what it doesn't have rn diff --git a/src/workers/block_listenser.rs b/src/workers/block_listenser.rs index b60a5183..8044e122 100644 --- a/src/workers/block_listenser.rs +++ b/src/workers/block_listenser.rs @@ -18,13 +18,10 @@ use solana_transaction_status::{ option_serializer::OptionSerializer, RewardType, TransactionConfirmationStatus, TransactionStatus, UiConfirmedBlock, UiTransactionStatusMeta, }; -use tokio::{ - sync::{mpsc::Sender}, - task::JoinHandle, -}; +use tokio::{sync::mpsc::Sender, task::JoinHandle}; use crate::{ - block_store::{BlockStore}, + block_store::BlockStore, workers::{PostgresBlock, PostgresMsg, PostgresUpdateTx}, }; @@ -40,7 +37,7 @@ pub struct BlockListener { pub signature_subscribers: Arc>, } -#[derive(Clone)] +#[derive(Clone, Debug)] pub struct BlockInformation { pub slot: u64, pub block_height: u64, @@ -119,7 +116,7 @@ impl BlockListener { info!("Listening to {commitment:?} blocks"); while let Some(block) = recv.as_mut().next().await { - let slot = block.value.slot; + let slot = block.context.slot; let Some(block) = block.value.block else { continue; diff --git a/tests/diff.rs b/tests/diff.rs new file mode 100644 index 00000000..4605333c --- /dev/null +++ b/tests/diff.rs @@ -0,0 +1,34 @@ +use lite_rpc::{DEFAULT_LITE_RPC_ADDR, DEFAULT_RPC_ADDR}; +use solana_rpc_client::nonblocking::rpc_client::RpcClient; +use solana_sdk::commitment_config::CommitmentConfig; + +#[tokio::test] +async fn diff_rpc() -> anyhow::Result<()> { + let rpc_client = RpcClient::new(DEFAULT_RPC_ADDR.to_string()); + let lite_rpc_client = RpcClient::new(DEFAULT_LITE_RPC_ADDR.to_string()); + + check_block_hash(&rpc_client, &lite_rpc_client, CommitmentConfig::confirmed()).await?; + check_block_hash(&rpc_client, &lite_rpc_client, CommitmentConfig::finalized()).await?; + + Ok(()) +} + +async fn check_block_hash( + rpc_client: &RpcClient, + lite_rpc_client: &RpcClient, + commitment_config: CommitmentConfig, +) -> anyhow::Result<()> { + let rpc_blockhash = rpc_client + .get_latest_blockhash_with_commitment(commitment_config) + .await?; + let lite_blockhash = lite_rpc_client + .get_latest_blockhash_with_commitment(commitment_config) + .await?; + + println!("{commitment_config:?} {rpc_blockhash:?} {lite_blockhash:?}"); + + assert_eq!(rpc_blockhash.0, lite_blockhash.0); + assert_eq!(rpc_blockhash.1, lite_blockhash.1); + + Ok(()) +}