block store latest_block_hash bug

This commit is contained in:
aniketfuryrocks 2023-02-19 13:26:26 +05:30
parent 2a9324157c
commit 3c3b52b598
No known key found for this signature in database
GPG Key ID: FA6BFCFAA7D4B764
1 changed files with 21 additions and 5 deletions

View File

@ -1,9 +1,12 @@
use std::sync::Arc;
use anyhow::Context;
use dashmap::DashMap;
use solana_client::rpc_config::RpcBlockConfig;
use solana_rpc_client::nonblocking::rpc_client::RpcClient;
use solana_sdk::commitment_config::CommitmentConfig;
use solana_transaction_status::TransactionDetails;
use tokio::sync::RwLock;
use crate::workers::BlockInformation;
@ -38,15 +41,28 @@ impl BlockStore {
rpc_client: &RpcClient,
commitment_config: CommitmentConfig,
) -> anyhow::Result<(String, BlockInformation)> {
let (latest_block_hash, block_height) = rpc_client
.get_latest_blockhash_with_commitment(commitment_config)
.await?;
let latest_block_hash = latest_block_hash.to_string();
let slot = rpc_client
.get_slot_with_commitment(commitment_config)
.await?;
let block = rpc_client
.get_block_with_config(
slot,
RpcBlockConfig {
encoding: None,
transaction_details: Some(TransactionDetails::None),
rewards: None,
commitment: Some(commitment_config),
max_supported_transaction_version: Some(0),
},
)
.await?;
let latest_block_hash = block.blockhash;
let block_height = block
.block_height
.context("Couldn't get block height of latest block for block store")?;
Ok((
latest_block_hash.clone(),
BlockInformation {