Add getLowestNonpurgedBlock rpc; use blockstore api in getConfirmedBlocks (#9656) (#9663)

automerge
This commit is contained in:
mergify[bot]
2020-04-22 15:17:51 -07:00
committed by GitHub
parent d8aa107fae
commit 33c51ee75d
3 changed files with 73 additions and 32 deletions

View File

@@ -13,9 +13,7 @@ use jsonrpc_core::{Error, Metadata, Result};
use jsonrpc_derive::rpc;
use solana_client::rpc_response::*;
use solana_faucet::faucet::request_airdrop_transaction;
use solana_ledger::{
bank_forks::BankForks, blockstore::Blockstore, rooted_slot_iterator::RootedSlotIterator,
};
use solana_ledger::{bank_forks::BankForks, blockstore::Blockstore};
use solana_runtime::bank::Bank;
use solana_sdk::{
clock::{Slot, UnixTimestamp},
@@ -381,18 +379,12 @@ impl JsonRpcRequestProcessor {
if end_slot < start_slot {
return Ok(vec![]);
}
let start_slot = (start_slot..end_slot).find(|&slot| self.blockstore.is_root(slot));
if let Some(start_slot) = start_slot {
let mut slots: Vec<Slot> = RootedSlotIterator::new(start_slot, &self.blockstore)
.unwrap()
.map(|(slot, _)| slot)
.collect();
slots.retain(|&x| x <= end_slot);
Ok(slots)
} else {
Ok(vec![])
}
Ok(self
.blockstore
.rooted_slot_iterator(start_slot)
.map_err(|_| Error::internal_error())?
.filter(|&slot| slot <= end_slot)
.collect())
}
pub fn get_block_time(&self, slot: Slot) -> Result<Option<UnixTimestamp>> {
@@ -543,6 +535,13 @@ impl JsonRpcRequestProcessor {
Ok(vec![])
}
}
pub fn get_first_available_block(&self) -> Result<Slot> {
Ok(self
.blockstore
.get_first_available_block()
.unwrap_or_default())
}
}
fn get_tpu_addr(cluster_info: &Arc<RwLock<ClusterInfo>>) -> Result<SocketAddr> {
@@ -801,6 +800,9 @@ pub trait RpcSol {
start_slot: Slot,
end_slot: Slot,
) -> Result<Vec<String>>;
#[rpc(meta, name = "getFirstAvailableBlock")]
fn get_first_available_block(&self, meta: Self::Metadata) -> Result<Slot>;
}
pub struct RpcSolImpl;
@@ -1389,6 +1391,13 @@ impl RpcSol for RpcSolImpl {
.collect()
})
}
fn get_first_available_block(&self, meta: Self::Metadata) -> Result<Slot> {
meta.request_processor
.read()
.unwrap()
.get_first_available_block()
}
}
#[cfg(test)]