automerge
This commit is contained in:
		@@ -36,7 +36,7 @@ use solana_transaction_status::{
 | 
			
		||||
};
 | 
			
		||||
use solana_vote_program::vote_state::{VoteState, MAX_LOCKOUT_HISTORY};
 | 
			
		||||
use std::{
 | 
			
		||||
    cmp::max,
 | 
			
		||||
    cmp::{max, min},
 | 
			
		||||
    collections::{HashMap, HashSet},
 | 
			
		||||
    net::{SocketAddr, UdpSocket},
 | 
			
		||||
    str::FromStr,
 | 
			
		||||
@@ -409,7 +409,14 @@ impl JsonRpcRequestProcessor {
 | 
			
		||||
        slot: Slot,
 | 
			
		||||
        encoding: Option<TransactionEncoding>,
 | 
			
		||||
    ) -> Result<Option<ConfirmedBlock>> {
 | 
			
		||||
        if self.config.enable_rpc_transaction_history {
 | 
			
		||||
        if self.config.enable_rpc_transaction_history
 | 
			
		||||
            && slot
 | 
			
		||||
                <= self
 | 
			
		||||
                    .block_commitment_cache
 | 
			
		||||
                    .read()
 | 
			
		||||
                    .unwrap()
 | 
			
		||||
                    .largest_confirmed_root()
 | 
			
		||||
        {
 | 
			
		||||
            Ok(self.blockstore.get_confirmed_block(slot, encoding).ok())
 | 
			
		||||
        } else {
 | 
			
		||||
            Ok(None)
 | 
			
		||||
@@ -421,11 +428,13 @@ impl JsonRpcRequestProcessor {
 | 
			
		||||
        start_slot: Slot,
 | 
			
		||||
        end_slot: Option<Slot>,
 | 
			
		||||
    ) -> Result<Vec<Slot>> {
 | 
			
		||||
        let end_slot = if let Some(end_slot) = end_slot {
 | 
			
		||||
            end_slot
 | 
			
		||||
        } else {
 | 
			
		||||
            self.bank(None)?.slot()
 | 
			
		||||
        };
 | 
			
		||||
        let end_slot = min(
 | 
			
		||||
            end_slot.unwrap_or(std::u64::MAX),
 | 
			
		||||
            self.block_commitment_cache
 | 
			
		||||
                .read()
 | 
			
		||||
                .unwrap()
 | 
			
		||||
                .largest_confirmed_root(),
 | 
			
		||||
        );
 | 
			
		||||
        if end_slot < start_slot {
 | 
			
		||||
            return Ok(vec![]);
 | 
			
		||||
        }
 | 
			
		||||
@@ -438,6 +447,13 @@ impl JsonRpcRequestProcessor {
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    pub fn get_block_time(&self, slot: Slot) -> Result<Option<UnixTimestamp>> {
 | 
			
		||||
        if slot
 | 
			
		||||
            <= self
 | 
			
		||||
                .block_commitment_cache
 | 
			
		||||
                .read()
 | 
			
		||||
                .unwrap()
 | 
			
		||||
                .largest_confirmed_root()
 | 
			
		||||
        {
 | 
			
		||||
            // This calculation currently assumes that bank.slots_per_year will remain unchanged after
 | 
			
		||||
            // genesis (ie. that this bank's slot_per_year will be applicable to any rooted slot being
 | 
			
		||||
            // queried). If these values will be variable in the future, those timing parameters will
 | 
			
		||||
@@ -454,6 +470,9 @@ impl JsonRpcRequestProcessor {
 | 
			
		||||
                .get_block_time(slot, slot_duration, stakes)
 | 
			
		||||
                .ok()
 | 
			
		||||
                .unwrap_or(None))
 | 
			
		||||
        } else {
 | 
			
		||||
            Ok(None)
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    pub fn get_signature_confirmation_status(
 | 
			
		||||
@@ -510,6 +529,13 @@ impl JsonRpcRequestProcessor {
 | 
			
		||||
                self.blockstore
 | 
			
		||||
                    .get_transaction_status(signature)
 | 
			
		||||
                    .map_err(|_| Error::internal_error())?
 | 
			
		||||
                    .filter(|(slot, _status_meta)| {
 | 
			
		||||
                        slot <= &self
 | 
			
		||||
                            .block_commitment_cache
 | 
			
		||||
                            .read()
 | 
			
		||||
                            .unwrap()
 | 
			
		||||
                            .largest_confirmed_root()
 | 
			
		||||
                    })
 | 
			
		||||
                    .map(|(slot, status_meta)| {
 | 
			
		||||
                        let err = status_meta.status.clone().err();
 | 
			
		||||
                        TransactionStatus {
 | 
			
		||||
@@ -567,7 +593,15 @@ impl JsonRpcRequestProcessor {
 | 
			
		||||
            Ok(self
 | 
			
		||||
                .blockstore
 | 
			
		||||
                .get_confirmed_transaction(signature, encoding)
 | 
			
		||||
                .unwrap_or(None))
 | 
			
		||||
                .unwrap_or(None)
 | 
			
		||||
                .filter(|confirmed_transaction| {
 | 
			
		||||
                    confirmed_transaction.slot
 | 
			
		||||
                        <= self
 | 
			
		||||
                            .block_commitment_cache
 | 
			
		||||
                            .read()
 | 
			
		||||
                            .unwrap()
 | 
			
		||||
                            .largest_confirmed_root()
 | 
			
		||||
                }))
 | 
			
		||||
        } else {
 | 
			
		||||
            Ok(None)
 | 
			
		||||
        }
 | 
			
		||||
@@ -580,6 +614,13 @@ impl JsonRpcRequestProcessor {
 | 
			
		||||
        end_slot: Slot,
 | 
			
		||||
    ) -> Result<Vec<Signature>> {
 | 
			
		||||
        if self.config.enable_rpc_transaction_history {
 | 
			
		||||
            let end_slot = min(
 | 
			
		||||
                end_slot,
 | 
			
		||||
                self.block_commitment_cache
 | 
			
		||||
                    .read()
 | 
			
		||||
                    .unwrap()
 | 
			
		||||
                    .largest_confirmed_root(),
 | 
			
		||||
            );
 | 
			
		||||
            Ok(self
 | 
			
		||||
                .blockstore
 | 
			
		||||
                .get_confirmed_signatures_for_address(pubkey, start_slot, end_slot)
 | 
			
		||||
@@ -2819,11 +2860,21 @@ pub mod tests {
 | 
			
		||||
    fn test_get_block_time() {
 | 
			
		||||
        let bob_pubkey = Pubkey::new_rand();
 | 
			
		||||
        let base_timestamp = 1576183541;
 | 
			
		||||
        let RpcHandler { io, meta, bank, .. } = start_rpc_handler_with_tx_and_blockstore(
 | 
			
		||||
        let RpcHandler {
 | 
			
		||||
            io,
 | 
			
		||||
            meta,
 | 
			
		||||
            bank,
 | 
			
		||||
            block_commitment_cache,
 | 
			
		||||
            ..
 | 
			
		||||
        } = start_rpc_handler_with_tx_and_blockstore(
 | 
			
		||||
            &bob_pubkey,
 | 
			
		||||
            vec![1, 2, 3, 4, 5, 6, 7],
 | 
			
		||||
            base_timestamp,
 | 
			
		||||
        );
 | 
			
		||||
        block_commitment_cache
 | 
			
		||||
            .write()
 | 
			
		||||
            .unwrap()
 | 
			
		||||
            .set_get_largest_confirmed_root(7);
 | 
			
		||||
 | 
			
		||||
        let slot_duration = slot_duration_from_slots_per_year(bank.slots_per_year());
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user