From c16721161128a0d4fdd212ef52c28f5d93d80ef8 Mon Sep 17 00:00:00 2001 From: Tyera Eulberg Date: Tue, 17 Aug 2021 16:29:34 -0600 Subject: [PATCH] Expose genesis block time via rpc (#19267) * Expose genesis_creation_time from Bank * Backfill genesis_creation_time for block/block-time requests of slot 0 --- rpc/src/rpc.rs | 28 ++++++++++++++++++++-------- runtime/src/bank.rs | 4 ++++ 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/rpc/src/rpc.rs b/rpc/src/rpc.rs index ca853bec74..dacf1dc696 100644 --- a/rpc/src/rpc.rs +++ b/rpc/src/rpc.rs @@ -71,8 +71,8 @@ use { }, solana_streamer::socket::SocketAddrSpace, solana_transaction_status::{ - EncodedConfirmedTransaction, Reward, RewardType, TransactionConfirmationStatus, - TransactionStatus, UiConfirmedBlock, UiTransactionEncoding, + ConfirmedBlock, EncodedConfirmedTransaction, Reward, RewardType, + TransactionConfirmationStatus, TransactionStatus, UiConfirmedBlock, UiTransactionEncoding, }, solana_vote_program::vote_state::{VoteState, MAX_LOCKOUT_HISTORY}, spl_token_v2_0::{ @@ -232,6 +232,10 @@ impl JsonRpcRequestProcessor { }) } + fn genesis_creation_time(&self) -> UnixTimestamp { + self.bank(None).genesis_creation_time() + } + #[allow(clippy::too_many_arguments)] pub fn new( config: JsonRpcConfig, @@ -960,20 +964,25 @@ impl JsonRpcRequestProcessor { { let result = self.blockstore.get_rooted_block(slot, true); self.check_blockstore_root(&result, slot)?; + let configure_block = |confirmed_block: ConfirmedBlock| { + let mut confirmed_block = + confirmed_block.configure(encoding, transaction_details, show_rewards); + if slot == 0 { + confirmed_block.block_time = Some(self.genesis_creation_time()); + confirmed_block.block_height = Some(0); + } + confirmed_block + }; if result.is_err() { if let Some(bigtable_ledger_storage) = &self.bigtable_ledger_storage { let bigtable_result = bigtable_ledger_storage.get_confirmed_block(slot).await; self.check_bigtable_result(&bigtable_result)?; - return Ok(bigtable_result.ok().map(|confirmed_block| { - confirmed_block.configure(encoding, transaction_details, show_rewards) - })); + return Ok(bigtable_result.ok().map(configure_block)); } } self.check_slot_cleaned_up(&result, slot)?; - return Ok(result.ok().map(|confirmed_block| { - confirmed_block.configure(encoding, transaction_details, show_rewards) - })); + return Ok(result.ok().map(configure_block)); } else if commitment.is_confirmed() { // Check if block is confirmed let confirmed_bank = self.bank(Some(CommitmentConfig::confirmed())); @@ -1155,6 +1164,9 @@ impl JsonRpcRequestProcessor { } pub async fn get_block_time(&self, slot: Slot) -> Result> { + if slot == 0 { + return Ok(Some(self.genesis_creation_time())); + } if slot <= self .block_commitment_cache diff --git a/runtime/src/bank.rs b/runtime/src/bank.rs index e7ebe02835..071402317a 100644 --- a/runtime/src/bank.rs +++ b/runtime/src/bank.rs @@ -1621,6 +1621,10 @@ impl Bank { &self.collector_id } + pub fn genesis_creation_time(&self) -> UnixTimestamp { + self.genesis_creation_time + } + pub fn slot(&self) -> Slot { self.slot }