Skip to content

Commit

Permalink
Expose genesis block time via rpc (solana-labs#19267)
Browse files Browse the repository at this point in the history
* Expose genesis_creation_time from Bank

* Backfill genesis_creation_time for block/block-time requests of slot 0
  • Loading branch information
CriesofCarrots authored Aug 17, 2021
1 parent c50b01c commit c167211
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 8 deletions.
28 changes: 20 additions & 8 deletions rpc/src/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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()));
Expand Down Expand Up @@ -1155,6 +1164,9 @@ impl JsonRpcRequestProcessor {
}

pub async fn get_block_time(&self, slot: Slot) -> Result<Option<UnixTimestamp>> {
if slot == 0 {
return Ok(Some(self.genesis_creation_time()));
}
if slot
<= self
.block_commitment_cache
Expand Down
4 changes: 4 additions & 0 deletions runtime/src/bank.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit c167211

Please sign in to comment.