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
This commit is contained in:
@ -71,8 +71,8 @@ use {
|
|||||||
},
|
},
|
||||||
solana_streamer::socket::SocketAddrSpace,
|
solana_streamer::socket::SocketAddrSpace,
|
||||||
solana_transaction_status::{
|
solana_transaction_status::{
|
||||||
EncodedConfirmedTransaction, Reward, RewardType, TransactionConfirmationStatus,
|
ConfirmedBlock, EncodedConfirmedTransaction, Reward, RewardType,
|
||||||
TransactionStatus, UiConfirmedBlock, UiTransactionEncoding,
|
TransactionConfirmationStatus, TransactionStatus, UiConfirmedBlock, UiTransactionEncoding,
|
||||||
},
|
},
|
||||||
solana_vote_program::vote_state::{VoteState, MAX_LOCKOUT_HISTORY},
|
solana_vote_program::vote_state::{VoteState, MAX_LOCKOUT_HISTORY},
|
||||||
spl_token_v2_0::{
|
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)]
|
#[allow(clippy::too_many_arguments)]
|
||||||
pub fn new(
|
pub fn new(
|
||||||
config: JsonRpcConfig,
|
config: JsonRpcConfig,
|
||||||
@ -960,20 +964,25 @@ impl JsonRpcRequestProcessor {
|
|||||||
{
|
{
|
||||||
let result = self.blockstore.get_rooted_block(slot, true);
|
let result = self.blockstore.get_rooted_block(slot, true);
|
||||||
self.check_blockstore_root(&result, slot)?;
|
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 result.is_err() {
|
||||||
if let Some(bigtable_ledger_storage) = &self.bigtable_ledger_storage {
|
if let Some(bigtable_ledger_storage) = &self.bigtable_ledger_storage {
|
||||||
let bigtable_result =
|
let bigtable_result =
|
||||||
bigtable_ledger_storage.get_confirmed_block(slot).await;
|
bigtable_ledger_storage.get_confirmed_block(slot).await;
|
||||||
self.check_bigtable_result(&bigtable_result)?;
|
self.check_bigtable_result(&bigtable_result)?;
|
||||||
return Ok(bigtable_result.ok().map(|confirmed_block| {
|
return Ok(bigtable_result.ok().map(configure_block));
|
||||||
confirmed_block.configure(encoding, transaction_details, show_rewards)
|
|
||||||
}));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
self.check_slot_cleaned_up(&result, slot)?;
|
self.check_slot_cleaned_up(&result, slot)?;
|
||||||
return Ok(result.ok().map(|confirmed_block| {
|
return Ok(result.ok().map(configure_block));
|
||||||
confirmed_block.configure(encoding, transaction_details, show_rewards)
|
|
||||||
}));
|
|
||||||
} else if commitment.is_confirmed() {
|
} else if commitment.is_confirmed() {
|
||||||
// Check if block is confirmed
|
// Check if block is confirmed
|
||||||
let confirmed_bank = self.bank(Some(CommitmentConfig::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<Option<UnixTimestamp>> {
|
pub async fn get_block_time(&self, slot: Slot) -> Result<Option<UnixTimestamp>> {
|
||||||
|
if slot == 0 {
|
||||||
|
return Ok(Some(self.genesis_creation_time()));
|
||||||
|
}
|
||||||
if slot
|
if slot
|
||||||
<= self
|
<= self
|
||||||
.block_commitment_cache
|
.block_commitment_cache
|
||||||
|
@ -1621,6 +1621,10 @@ impl Bank {
|
|||||||
&self.collector_id
|
&self.collector_id
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn genesis_creation_time(&self) -> UnixTimestamp {
|
||||||
|
self.genesis_creation_time
|
||||||
|
}
|
||||||
|
|
||||||
pub fn slot(&self) -> Slot {
|
pub fn slot(&self) -> Slot {
|
||||||
self.slot
|
self.slot
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user