parent
0645a0c96d
commit
af8c21c559
|
@ -253,6 +253,12 @@ pub struct ClusterInfo {
|
||||||
start_time: u64,
|
start_time: u64,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Default for ClusterInfo {
|
||||||
|
fn default() -> Self {
|
||||||
|
Self::new_with_invalid_keypair(ContactInfo::default())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Default, Clone)]
|
#[derive(Default, Clone)]
|
||||||
pub struct Locality {
|
pub struct Locality {
|
||||||
/// The bounds of the neighborhood represented by this locality
|
/// The bounds of the neighborhood represented by this locality
|
||||||
|
|
291
core/src/rpc.rs
291
core/src/rpc.rs
|
@ -76,7 +76,10 @@ pub struct JsonRpcRequestProcessor {
|
||||||
config: JsonRpcConfig,
|
config: JsonRpcConfig,
|
||||||
validator_exit: Arc<RwLock<Option<ValidatorExit>>>,
|
validator_exit: Arc<RwLock<Option<ValidatorExit>>>,
|
||||||
health: Arc<RpcHealth>,
|
health: Arc<RpcHealth>,
|
||||||
|
cluster_info: Arc<ClusterInfo>,
|
||||||
|
genesis_hash: Hash,
|
||||||
}
|
}
|
||||||
|
impl Metadata for JsonRpcRequestProcessor {}
|
||||||
|
|
||||||
impl JsonRpcRequestProcessor {
|
impl JsonRpcRequestProcessor {
|
||||||
fn bank(&self, commitment: Option<CommitmentConfig>) -> Result<Arc<Bank>> {
|
fn bank(&self, commitment: Option<CommitmentConfig>) -> Result<Arc<Bank>> {
|
||||||
|
@ -131,14 +134,18 @@ impl JsonRpcRequestProcessor {
|
||||||
blockstore: Arc<Blockstore>,
|
blockstore: Arc<Blockstore>,
|
||||||
validator_exit: Arc<RwLock<Option<ValidatorExit>>>,
|
validator_exit: Arc<RwLock<Option<ValidatorExit>>>,
|
||||||
health: Arc<RpcHealth>,
|
health: Arc<RpcHealth>,
|
||||||
|
cluster_info: Arc<ClusterInfo>,
|
||||||
|
genesis_hash: Hash,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
JsonRpcRequestProcessor {
|
Self {
|
||||||
config,
|
config,
|
||||||
bank_forks,
|
bank_forks,
|
||||||
block_commitment_cache,
|
block_commitment_cache,
|
||||||
blockstore,
|
blockstore,
|
||||||
validator_exit,
|
validator_exit,
|
||||||
health,
|
health,
|
||||||
|
cluster_info,
|
||||||
|
genesis_hash,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -736,14 +743,6 @@ fn run_transaction_simulation(
|
||||||
(executed[0].0.clone().map(|_| ()), log_collector.output())
|
(executed[0].0.clone().map(|_| ()), log_collector.output())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone)]
|
|
||||||
pub struct Meta {
|
|
||||||
pub request_processor: Arc<RwLock<JsonRpcRequestProcessor>>,
|
|
||||||
pub cluster_info: Arc<ClusterInfo>,
|
|
||||||
pub genesis_hash: Hash,
|
|
||||||
}
|
|
||||||
impl Metadata for Meta {}
|
|
||||||
|
|
||||||
#[rpc(server)]
|
#[rpc(server)]
|
||||||
pub trait RpcSol {
|
pub trait RpcSol {
|
||||||
type Metadata;
|
type Metadata;
|
||||||
|
@ -1013,7 +1012,7 @@ pub trait RpcSol {
|
||||||
|
|
||||||
pub struct RpcSolImpl;
|
pub struct RpcSolImpl;
|
||||||
impl RpcSol for RpcSolImpl {
|
impl RpcSol for RpcSolImpl {
|
||||||
type Metadata = Meta;
|
type Metadata = JsonRpcRequestProcessor;
|
||||||
|
|
||||||
fn confirm_transaction(
|
fn confirm_transaction(
|
||||||
&self,
|
&self,
|
||||||
|
@ -1023,10 +1022,7 @@ impl RpcSol for RpcSolImpl {
|
||||||
) -> RpcResponse<bool> {
|
) -> RpcResponse<bool> {
|
||||||
debug!("confirm_transaction rpc request received: {:?}", id);
|
debug!("confirm_transaction rpc request received: {:?}", id);
|
||||||
let signature = verify_signature(&id);
|
let signature = verify_signature(&id);
|
||||||
meta.request_processor
|
meta.confirm_transaction(signature, commitment)
|
||||||
.read()
|
|
||||||
.unwrap()
|
|
||||||
.confirm_transaction(signature, commitment)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_account_info(
|
fn get_account_info(
|
||||||
|
@ -1037,10 +1033,7 @@ impl RpcSol for RpcSolImpl {
|
||||||
) -> RpcResponse<Option<RpcAccount>> {
|
) -> RpcResponse<Option<RpcAccount>> {
|
||||||
debug!("get_account_info rpc request received: {:?}", pubkey_str);
|
debug!("get_account_info rpc request received: {:?}", pubkey_str);
|
||||||
let pubkey = verify_pubkey(pubkey_str);
|
let pubkey = verify_pubkey(pubkey_str);
|
||||||
meta.request_processor
|
meta.get_account_info(pubkey, commitment)
|
||||||
.read()
|
|
||||||
.unwrap()
|
|
||||||
.get_account_info(pubkey, commitment)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_minimum_balance_for_rent_exemption(
|
fn get_minimum_balance_for_rent_exemption(
|
||||||
|
@ -1053,10 +1046,7 @@ impl RpcSol for RpcSolImpl {
|
||||||
"get_minimum_balance_for_rent_exemption rpc request received: {:?}",
|
"get_minimum_balance_for_rent_exemption rpc request received: {:?}",
|
||||||
data_len
|
data_len
|
||||||
);
|
);
|
||||||
meta.request_processor
|
meta.get_minimum_balance_for_rent_exemption(data_len, commitment)
|
||||||
.read()
|
|
||||||
.unwrap()
|
|
||||||
.get_minimum_balance_for_rent_exemption(data_len, commitment)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_program_accounts(
|
fn get_program_accounts(
|
||||||
|
@ -1070,10 +1060,7 @@ impl RpcSol for RpcSolImpl {
|
||||||
program_id_str
|
program_id_str
|
||||||
);
|
);
|
||||||
let program_id = verify_pubkey(program_id_str)?;
|
let program_id = verify_pubkey(program_id_str)?;
|
||||||
meta.request_processor
|
meta.get_program_accounts(&program_id, commitment)
|
||||||
.read()
|
|
||||||
.unwrap()
|
|
||||||
.get_program_accounts(&program_id, commitment)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_inflation_governor(
|
fn get_inflation_governor(
|
||||||
|
@ -1082,10 +1069,7 @@ impl RpcSol for RpcSolImpl {
|
||||||
commitment: Option<CommitmentConfig>,
|
commitment: Option<CommitmentConfig>,
|
||||||
) -> Result<RpcInflationGovernor> {
|
) -> Result<RpcInflationGovernor> {
|
||||||
debug!("get_inflation_governor rpc request received");
|
debug!("get_inflation_governor rpc request received");
|
||||||
meta.request_processor
|
meta.get_inflation_governor(commitment)
|
||||||
.read()
|
|
||||||
.unwrap()
|
|
||||||
.get_inflation_governor(commitment)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_inflation_rate(
|
fn get_inflation_rate(
|
||||||
|
@ -1094,15 +1078,12 @@ impl RpcSol for RpcSolImpl {
|
||||||
epoch: Option<Epoch>,
|
epoch: Option<Epoch>,
|
||||||
) -> Result<RpcInflationRate> {
|
) -> Result<RpcInflationRate> {
|
||||||
debug!("get_inflation_rate rpc request received");
|
debug!("get_inflation_rate rpc request received");
|
||||||
meta.request_processor
|
meta.get_inflation_rate(epoch)
|
||||||
.read()
|
|
||||||
.unwrap()
|
|
||||||
.get_inflation_rate(epoch)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_epoch_schedule(&self, meta: Self::Metadata) -> Result<EpochSchedule> {
|
fn get_epoch_schedule(&self, meta: Self::Metadata) -> Result<EpochSchedule> {
|
||||||
debug!("get_epoch_schedule rpc request received");
|
debug!("get_epoch_schedule rpc request received");
|
||||||
meta.request_processor.read().unwrap().get_epoch_schedule()
|
meta.get_epoch_schedule()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_balance(
|
fn get_balance(
|
||||||
|
@ -1113,10 +1094,7 @@ impl RpcSol for RpcSolImpl {
|
||||||
) -> RpcResponse<u64> {
|
) -> RpcResponse<u64> {
|
||||||
debug!("get_balance rpc request received: {:?}", pubkey_str);
|
debug!("get_balance rpc request received: {:?}", pubkey_str);
|
||||||
let pubkey = verify_pubkey(pubkey_str);
|
let pubkey = verify_pubkey(pubkey_str);
|
||||||
meta.request_processor
|
meta.get_balance(pubkey, commitment)
|
||||||
.read()
|
|
||||||
.unwrap()
|
|
||||||
.get_balance(pubkey, commitment)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_cluster_nodes(&self, meta: Self::Metadata) -> Result<Vec<RpcContactInfo>> {
|
fn get_cluster_nodes(&self, meta: Self::Metadata) -> Result<Vec<RpcContactInfo>> {
|
||||||
|
@ -1157,7 +1135,7 @@ impl RpcSol for RpcSolImpl {
|
||||||
meta: Self::Metadata,
|
meta: Self::Metadata,
|
||||||
commitment: Option<CommitmentConfig>,
|
commitment: Option<CommitmentConfig>,
|
||||||
) -> Result<EpochInfo> {
|
) -> Result<EpochInfo> {
|
||||||
let bank = meta.request_processor.read().unwrap().bank(commitment)?;
|
let bank = meta.bank(commitment)?;
|
||||||
Ok(bank.get_epoch_info())
|
Ok(bank.get_epoch_info())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1166,11 +1144,7 @@ impl RpcSol for RpcSolImpl {
|
||||||
meta: Self::Metadata,
|
meta: Self::Metadata,
|
||||||
block: Slot,
|
block: Slot,
|
||||||
) -> Result<RpcBlockCommitment<BlockCommitmentArray>> {
|
) -> Result<RpcBlockCommitment<BlockCommitmentArray>> {
|
||||||
Ok(meta
|
Ok(meta.get_block_commitment(block))
|
||||||
.request_processor
|
|
||||||
.read()
|
|
||||||
.unwrap()
|
|
||||||
.get_block_commitment(block))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_genesis_hash(&self, meta: Self::Metadata) -> Result<String> {
|
fn get_genesis_hash(&self, meta: Self::Metadata) -> Result<String> {
|
||||||
|
@ -1184,7 +1158,7 @@ impl RpcSol for RpcSolImpl {
|
||||||
slot: Option<Slot>,
|
slot: Option<Slot>,
|
||||||
commitment: Option<CommitmentConfig>,
|
commitment: Option<CommitmentConfig>,
|
||||||
) -> Result<Option<RpcLeaderSchedule>> {
|
) -> Result<Option<RpcLeaderSchedule>> {
|
||||||
let bank = meta.request_processor.read().unwrap().bank(commitment)?;
|
let bank = meta.bank(commitment)?;
|
||||||
let slot = slot.unwrap_or_else(|| bank.slot());
|
let slot = slot.unwrap_or_else(|| bank.slot());
|
||||||
let epoch = bank.epoch_schedule().get_epoch(slot);
|
let epoch = bank.epoch_schedule().get_epoch(slot);
|
||||||
|
|
||||||
|
@ -1211,10 +1185,7 @@ impl RpcSol for RpcSolImpl {
|
||||||
commitment: Option<CommitmentConfig>,
|
commitment: Option<CommitmentConfig>,
|
||||||
) -> RpcResponse<RpcBlockhashFeeCalculator> {
|
) -> RpcResponse<RpcBlockhashFeeCalculator> {
|
||||||
debug!("get_recent_blockhash rpc request received");
|
debug!("get_recent_blockhash rpc request received");
|
||||||
meta.request_processor
|
meta.get_recent_blockhash(commitment)
|
||||||
.read()
|
|
||||||
.unwrap()
|
|
||||||
.get_recent_blockhash(commitment)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_fees(
|
fn get_fees(
|
||||||
|
@ -1223,7 +1194,7 @@ impl RpcSol for RpcSolImpl {
|
||||||
commitment: Option<CommitmentConfig>,
|
commitment: Option<CommitmentConfig>,
|
||||||
) -> RpcResponse<RpcFees> {
|
) -> RpcResponse<RpcFees> {
|
||||||
debug!("get_fees rpc request received");
|
debug!("get_fees rpc request received");
|
||||||
meta.request_processor.read().unwrap().get_fees(commitment)
|
meta.get_fees(commitment)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_fee_calculator_for_blockhash(
|
fn get_fee_calculator_for_blockhash(
|
||||||
|
@ -1235,18 +1206,12 @@ impl RpcSol for RpcSolImpl {
|
||||||
debug!("get_fee_calculator_for_blockhash rpc request received");
|
debug!("get_fee_calculator_for_blockhash rpc request received");
|
||||||
let blockhash =
|
let blockhash =
|
||||||
Hash::from_str(&blockhash).map_err(|e| Error::invalid_params(format!("{:?}", e)))?;
|
Hash::from_str(&blockhash).map_err(|e| Error::invalid_params(format!("{:?}", e)))?;
|
||||||
meta.request_processor
|
meta.get_fee_calculator_for_blockhash(&blockhash, commitment)
|
||||||
.read()
|
|
||||||
.unwrap()
|
|
||||||
.get_fee_calculator_for_blockhash(&blockhash, commitment)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_fee_rate_governor(&self, meta: Self::Metadata) -> RpcResponse<RpcFeeRateGovernor> {
|
fn get_fee_rate_governor(&self, meta: Self::Metadata) -> RpcResponse<RpcFeeRateGovernor> {
|
||||||
debug!("get_fee_rate_governor rpc request received");
|
debug!("get_fee_rate_governor rpc request received");
|
||||||
meta.request_processor
|
meta.get_fee_rate_governor()
|
||||||
.read()
|
|
||||||
.unwrap()
|
|
||||||
.get_fee_rate_governor()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_signature_confirmation(
|
fn get_signature_confirmation(
|
||||||
|
@ -1260,11 +1225,7 @@ impl RpcSol for RpcSolImpl {
|
||||||
signature_str
|
signature_str
|
||||||
);
|
);
|
||||||
let signature = verify_signature(&signature_str)?;
|
let signature = verify_signature(&signature_str)?;
|
||||||
Ok(meta
|
Ok(meta.get_signature_confirmation_status(signature, commitment))
|
||||||
.request_processor
|
|
||||||
.read()
|
|
||||||
.unwrap()
|
|
||||||
.get_signature_confirmation_status(signature, commitment))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_signature_status(
|
fn get_signature_status(
|
||||||
|
@ -1274,11 +1235,7 @@ impl RpcSol for RpcSolImpl {
|
||||||
commitment: Option<CommitmentConfig>,
|
commitment: Option<CommitmentConfig>,
|
||||||
) -> Result<Option<transaction::Result<()>>> {
|
) -> Result<Option<transaction::Result<()>>> {
|
||||||
let signature = verify_signature(&signature_str)?;
|
let signature = verify_signature(&signature_str)?;
|
||||||
Ok(meta
|
Ok(meta.get_signature_status(signature, commitment))
|
||||||
.request_processor
|
|
||||||
.read()
|
|
||||||
.unwrap()
|
|
||||||
.get_signature_status(signature, commitment))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_signature_statuses(
|
fn get_signature_statuses(
|
||||||
|
@ -1297,14 +1254,11 @@ impl RpcSol for RpcSolImpl {
|
||||||
for signature_str in signature_strs {
|
for signature_str in signature_strs {
|
||||||
signatures.push(verify_signature(&signature_str)?);
|
signatures.push(verify_signature(&signature_str)?);
|
||||||
}
|
}
|
||||||
meta.request_processor
|
meta.get_signature_statuses(signatures, config)
|
||||||
.read()
|
|
||||||
.unwrap()
|
|
||||||
.get_signature_statuses(signatures, config)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_slot(&self, meta: Self::Metadata, commitment: Option<CommitmentConfig>) -> Result<u64> {
|
fn get_slot(&self, meta: Self::Metadata, commitment: Option<CommitmentConfig>) -> Result<u64> {
|
||||||
meta.request_processor.read().unwrap().get_slot(commitment)
|
meta.get_slot(commitment)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_transaction_count(
|
fn get_transaction_count(
|
||||||
|
@ -1313,10 +1267,7 @@ impl RpcSol for RpcSolImpl {
|
||||||
commitment: Option<CommitmentConfig>,
|
commitment: Option<CommitmentConfig>,
|
||||||
) -> Result<u64> {
|
) -> Result<u64> {
|
||||||
debug!("get_transaction_count rpc request received");
|
debug!("get_transaction_count rpc request received");
|
||||||
meta.request_processor
|
meta.get_transaction_count(commitment)
|
||||||
.read()
|
|
||||||
.unwrap()
|
|
||||||
.get_transaction_count(commitment)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_total_supply(
|
fn get_total_supply(
|
||||||
|
@ -1325,10 +1276,7 @@ impl RpcSol for RpcSolImpl {
|
||||||
commitment: Option<CommitmentConfig>,
|
commitment: Option<CommitmentConfig>,
|
||||||
) -> Result<u64> {
|
) -> Result<u64> {
|
||||||
debug!("get_total_supply rpc request received");
|
debug!("get_total_supply rpc request received");
|
||||||
meta.request_processor
|
meta.get_total_supply(commitment)
|
||||||
.read()
|
|
||||||
.unwrap()
|
|
||||||
.get_total_supply(commitment)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_largest_accounts(
|
fn get_largest_accounts(
|
||||||
|
@ -1337,10 +1285,7 @@ impl RpcSol for RpcSolImpl {
|
||||||
config: Option<RpcLargestAccountsConfig>,
|
config: Option<RpcLargestAccountsConfig>,
|
||||||
) -> RpcResponse<Vec<RpcAccountBalance>> {
|
) -> RpcResponse<Vec<RpcAccountBalance>> {
|
||||||
debug!("get_largest_accounts rpc request received");
|
debug!("get_largest_accounts rpc request received");
|
||||||
meta.request_processor
|
meta.get_largest_accounts(config)
|
||||||
.read()
|
|
||||||
.unwrap()
|
|
||||||
.get_largest_accounts(config)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_supply(
|
fn get_supply(
|
||||||
|
@ -1349,10 +1294,7 @@ impl RpcSol for RpcSolImpl {
|
||||||
commitment: Option<CommitmentConfig>,
|
commitment: Option<CommitmentConfig>,
|
||||||
) -> RpcResponse<RpcSupply> {
|
) -> RpcResponse<RpcSupply> {
|
||||||
debug!("get_supply rpc request received");
|
debug!("get_supply rpc request received");
|
||||||
meta.request_processor
|
meta.get_supply(commitment)
|
||||||
.read()
|
|
||||||
.unwrap()
|
|
||||||
.get_supply(commitment)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn request_airdrop(
|
fn request_airdrop(
|
||||||
|
@ -1369,22 +1311,10 @@ impl RpcSol for RpcSolImpl {
|
||||||
&commitment
|
&commitment
|
||||||
);
|
);
|
||||||
|
|
||||||
let faucet_addr = meta
|
let faucet_addr = meta.config.faucet_addr.ok_or_else(Error::invalid_request)?;
|
||||||
.request_processor
|
|
||||||
.read()
|
|
||||||
.unwrap()
|
|
||||||
.config
|
|
||||||
.faucet_addr
|
|
||||||
.ok_or_else(Error::invalid_request)?;
|
|
||||||
let pubkey = verify_pubkey(pubkey_str)?;
|
let pubkey = verify_pubkey(pubkey_str)?;
|
||||||
|
|
||||||
let blockhash = meta
|
let blockhash = meta.bank(commitment.clone())?.confirmed_last_blockhash().0;
|
||||||
.request_processor
|
|
||||||
.read()
|
|
||||||
.unwrap()
|
|
||||||
.bank(commitment.clone())?
|
|
||||||
.confirmed_last_blockhash()
|
|
||||||
.0;
|
|
||||||
let transaction = request_airdrop_transaction(&faucet_addr, &pubkey, lamports, blockhash)
|
let transaction = request_airdrop_transaction(&faucet_addr, &pubkey, lamports, blockhash)
|
||||||
.map_err(|err| {
|
.map_err(|err| {
|
||||||
info!("request_airdrop_transaction failed: {:?}", err);
|
info!("request_airdrop_transaction failed: {:?}", err);
|
||||||
|
@ -1413,12 +1343,7 @@ impl RpcSol for RpcSolImpl {
|
||||||
_ => 30,
|
_ => 30,
|
||||||
};
|
};
|
||||||
loop {
|
loop {
|
||||||
signature_status = meta
|
signature_status = meta.get_signature_statuses(vec![signature], None)?.value[0]
|
||||||
.request_processor
|
|
||||||
.read()
|
|
||||||
.unwrap()
|
|
||||||
.get_signature_statuses(vec![signature], None)?
|
|
||||||
.value[0]
|
|
||||||
.clone()
|
.clone()
|
||||||
.filter(|result| result.satisfies_commitment(commitment.unwrap_or_default()))
|
.filter(|result| result.satisfies_commitment(commitment.unwrap_or_default()))
|
||||||
.map(|x| x.status);
|
.map(|x| x.status);
|
||||||
|
@ -1452,14 +1377,14 @@ impl RpcSol for RpcSolImpl {
|
||||||
.into());
|
.into());
|
||||||
}
|
}
|
||||||
|
|
||||||
if meta.request_processor.read().unwrap().health.check() != RpcHealthStatus::Ok {
|
if meta.health.check() != RpcHealthStatus::Ok {
|
||||||
return Err(RpcCustomError::SendTransactionPreflightFailure {
|
return Err(RpcCustomError::SendTransactionPreflightFailure {
|
||||||
message: "RPC node is unhealthy, unable to simulate transaction".into(),
|
message: "RPC node is unhealthy, unable to simulate transaction".into(),
|
||||||
}
|
}
|
||||||
.into());
|
.into());
|
||||||
}
|
}
|
||||||
|
|
||||||
let bank = &*meta.request_processor.read().unwrap().bank(None)?;
|
let bank = &*meta.bank(None)?;
|
||||||
if let (Err(err), _log_output) = run_transaction_simulation(&bank, transaction) {
|
if let (Err(err), _log_output) = run_transaction_simulation(&bank, transaction) {
|
||||||
// Note: it's possible that the transaction simulation failed but the actual
|
// Note: it's possible that the transaction simulation failed but the actual
|
||||||
// transaction would succeed, such as when a transaction depends on an earlier
|
// transaction would succeed, such as when a transaction depends on an earlier
|
||||||
|
@ -1504,7 +1429,7 @@ impl RpcSol for RpcSolImpl {
|
||||||
Ok(())
|
Ok(())
|
||||||
};
|
};
|
||||||
|
|
||||||
let bank = &*meta.request_processor.read().unwrap().bank(None)?;
|
let bank = &*meta.bank(None)?;
|
||||||
let logs = if result.is_ok() {
|
let logs = if result.is_ok() {
|
||||||
let sim_result = run_transaction_simulation(&bank, transaction);
|
let sim_result = run_transaction_simulation(&bank, transaction);
|
||||||
result = sim_result.0;
|
result = sim_result.0;
|
||||||
|
@ -1527,14 +1452,11 @@ impl RpcSol for RpcSolImpl {
|
||||||
meta: Self::Metadata,
|
meta: Self::Metadata,
|
||||||
commitment: Option<CommitmentConfig>,
|
commitment: Option<CommitmentConfig>,
|
||||||
) -> Result<String> {
|
) -> Result<String> {
|
||||||
meta.request_processor
|
meta.get_slot_leader(commitment)
|
||||||
.read()
|
|
||||||
.unwrap()
|
|
||||||
.get_slot_leader(commitment)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn minimum_ledger_slot(&self, meta: Self::Metadata) -> Result<Slot> {
|
fn minimum_ledger_slot(&self, meta: Self::Metadata) -> Result<Slot> {
|
||||||
meta.request_processor.read().unwrap().minimum_ledger_slot()
|
meta.minimum_ledger_slot()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_vote_accounts(
|
fn get_vote_accounts(
|
||||||
|
@ -1542,25 +1464,16 @@ impl RpcSol for RpcSolImpl {
|
||||||
meta: Self::Metadata,
|
meta: Self::Metadata,
|
||||||
commitment: Option<CommitmentConfig>,
|
commitment: Option<CommitmentConfig>,
|
||||||
) -> Result<RpcVoteAccountStatus> {
|
) -> Result<RpcVoteAccountStatus> {
|
||||||
meta.request_processor
|
meta.get_vote_accounts(commitment)
|
||||||
.read()
|
|
||||||
.unwrap()
|
|
||||||
.get_vote_accounts(commitment)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn validator_exit(&self, meta: Self::Metadata) -> Result<bool> {
|
fn validator_exit(&self, meta: Self::Metadata) -> Result<bool> {
|
||||||
meta.request_processor.read().unwrap().validator_exit()
|
meta.validator_exit()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_identity(&self, meta: Self::Metadata) -> Result<RpcIdentity> {
|
fn get_identity(&self, meta: Self::Metadata) -> Result<RpcIdentity> {
|
||||||
Ok(RpcIdentity {
|
Ok(RpcIdentity {
|
||||||
identity: meta
|
identity: meta.config.identity_pubkey.to_string(),
|
||||||
.request_processor
|
|
||||||
.read()
|
|
||||||
.unwrap()
|
|
||||||
.config
|
|
||||||
.identity_pubkey
|
|
||||||
.to_string(),
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1571,10 +1484,7 @@ impl RpcSol for RpcSolImpl {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn set_log_filter(&self, meta: Self::Metadata, filter: String) -> Result<()> {
|
fn set_log_filter(&self, meta: Self::Metadata, filter: String) -> Result<()> {
|
||||||
meta.request_processor
|
meta.set_log_filter(filter)
|
||||||
.read()
|
|
||||||
.unwrap()
|
|
||||||
.set_log_filter(filter)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_confirmed_block(
|
fn get_confirmed_block(
|
||||||
|
@ -1583,10 +1493,7 @@ impl RpcSol for RpcSolImpl {
|
||||||
slot: Slot,
|
slot: Slot,
|
||||||
encoding: Option<TransactionEncoding>,
|
encoding: Option<TransactionEncoding>,
|
||||||
) -> Result<Option<ConfirmedBlock>> {
|
) -> Result<Option<ConfirmedBlock>> {
|
||||||
meta.request_processor
|
meta.get_confirmed_block(slot, encoding)
|
||||||
.read()
|
|
||||||
.unwrap()
|
|
||||||
.get_confirmed_block(slot, encoding)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_confirmed_blocks(
|
fn get_confirmed_blocks(
|
||||||
|
@ -1595,14 +1502,11 @@ impl RpcSol for RpcSolImpl {
|
||||||
start_slot: Slot,
|
start_slot: Slot,
|
||||||
end_slot: Option<Slot>,
|
end_slot: Option<Slot>,
|
||||||
) -> Result<Vec<Slot>> {
|
) -> Result<Vec<Slot>> {
|
||||||
meta.request_processor
|
meta.get_confirmed_blocks(start_slot, end_slot)
|
||||||
.read()
|
|
||||||
.unwrap()
|
|
||||||
.get_confirmed_blocks(start_slot, end_slot)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_block_time(&self, meta: Self::Metadata, slot: Slot) -> Result<Option<UnixTimestamp>> {
|
fn get_block_time(&self, meta: Self::Metadata, slot: Slot) -> Result<Option<UnixTimestamp>> {
|
||||||
meta.request_processor.read().unwrap().get_block_time(slot)
|
meta.get_block_time(slot)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_confirmed_transaction(
|
fn get_confirmed_transaction(
|
||||||
|
@ -1612,10 +1516,7 @@ impl RpcSol for RpcSolImpl {
|
||||||
encoding: Option<TransactionEncoding>,
|
encoding: Option<TransactionEncoding>,
|
||||||
) -> Result<Option<ConfirmedTransaction>> {
|
) -> Result<Option<ConfirmedTransaction>> {
|
||||||
let signature = verify_signature(&signature_str)?;
|
let signature = verify_signature(&signature_str)?;
|
||||||
meta.request_processor
|
meta.get_confirmed_transaction(signature, encoding)
|
||||||
.read()
|
|
||||||
.unwrap()
|
|
||||||
.get_confirmed_transaction(signature, encoding)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_confirmed_signatures_for_address(
|
fn get_confirmed_signatures_for_address(
|
||||||
|
@ -1638,10 +1539,7 @@ impl RpcSol for RpcSolImpl {
|
||||||
MAX_GET_CONFIRMED_SIGNATURES_FOR_ADDRESS_SLOT_RANGE
|
MAX_GET_CONFIRMED_SIGNATURES_FOR_ADDRESS_SLOT_RANGE
|
||||||
)));
|
)));
|
||||||
}
|
}
|
||||||
meta.request_processor
|
meta.get_confirmed_signatures_for_address(pubkey, start_slot, end_slot)
|
||||||
.read()
|
|
||||||
.unwrap()
|
|
||||||
.get_confirmed_signatures_for_address(pubkey, start_slot, end_slot)
|
|
||||||
.map(|signatures| {
|
.map(|signatures| {
|
||||||
signatures
|
signatures
|
||||||
.iter()
|
.iter()
|
||||||
|
@ -1651,10 +1549,7 @@ impl RpcSol for RpcSolImpl {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_first_available_block(&self, meta: Self::Metadata) -> Result<Slot> {
|
fn get_first_available_block(&self, meta: Self::Metadata) -> Result<Slot> {
|
||||||
meta.request_processor
|
meta.get_first_available_block()
|
||||||
.read()
|
|
||||||
.unwrap()
|
|
||||||
.get_first_available_block()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1724,8 +1619,8 @@ pub mod tests {
|
||||||
const TEST_SLOTS_PER_EPOCH: u64 = 50;
|
const TEST_SLOTS_PER_EPOCH: u64 = 50;
|
||||||
|
|
||||||
struct RpcHandler {
|
struct RpcHandler {
|
||||||
io: MetaIoHandler<Meta>,
|
io: MetaIoHandler<JsonRpcRequestProcessor>,
|
||||||
meta: Meta,
|
meta: JsonRpcRequestProcessor,
|
||||||
bank: Arc<Bank>,
|
bank: Arc<Bank>,
|
||||||
bank_forks: Arc<RwLock<BankForks>>,
|
bank_forks: Arc<RwLock<BankForks>>,
|
||||||
blockhash: Hash,
|
blockhash: Hash,
|
||||||
|
@ -1842,7 +1737,14 @@ pub mod tests {
|
||||||
let tx = system_transaction::transfer(&alice, pubkey, std::u64::MAX, blockhash);
|
let tx = system_transaction::transfer(&alice, pubkey, std::u64::MAX, blockhash);
|
||||||
let _ = bank.process_transaction(&tx);
|
let _ = bank.process_transaction(&tx);
|
||||||
|
|
||||||
let request_processor = Arc::new(RwLock::new(JsonRpcRequestProcessor::new(
|
let cluster_info = Arc::new(ClusterInfo::default());
|
||||||
|
|
||||||
|
cluster_info.insert_info(ContactInfo::new_with_pubkey_socketaddr(
|
||||||
|
&leader_pubkey,
|
||||||
|
&socketaddr!("127.0.0.1:1234"),
|
||||||
|
));
|
||||||
|
|
||||||
|
let meta = JsonRpcRequestProcessor::new(
|
||||||
JsonRpcConfig {
|
JsonRpcConfig {
|
||||||
enable_rpc_transaction_history: true,
|
enable_rpc_transaction_history: true,
|
||||||
identity_pubkey: *pubkey,
|
identity_pubkey: *pubkey,
|
||||||
|
@ -1853,22 +1755,13 @@ pub mod tests {
|
||||||
blockstore,
|
blockstore,
|
||||||
validator_exit,
|
validator_exit,
|
||||||
RpcHealth::stub(),
|
RpcHealth::stub(),
|
||||||
)));
|
cluster_info,
|
||||||
let cluster_info = Arc::new(ClusterInfo::new_with_invalid_keypair(ContactInfo::default()));
|
Hash::default(),
|
||||||
|
);
|
||||||
cluster_info.insert_info(ContactInfo::new_with_pubkey_socketaddr(
|
|
||||||
&leader_pubkey,
|
|
||||||
&socketaddr!("127.0.0.1:1234"),
|
|
||||||
));
|
|
||||||
|
|
||||||
let mut io = MetaIoHandler::default();
|
let mut io = MetaIoHandler::default();
|
||||||
let rpc = RpcSolImpl;
|
let rpc = RpcSolImpl;
|
||||||
io.extend_with(rpc.to_delegate());
|
io.extend_with(rpc.to_delegate());
|
||||||
let meta = Meta {
|
|
||||||
request_processor,
|
|
||||||
cluster_info,
|
|
||||||
genesis_hash: Hash::default(),
|
|
||||||
};
|
|
||||||
RpcHandler {
|
RpcHandler {
|
||||||
io,
|
io,
|
||||||
meta,
|
meta,
|
||||||
|
@ -1902,6 +1795,8 @@ pub mod tests {
|
||||||
blockstore,
|
blockstore,
|
||||||
validator_exit,
|
validator_exit,
|
||||||
RpcHealth::stub(),
|
RpcHealth::stub(),
|
||||||
|
Arc::new(ClusterInfo::default()),
|
||||||
|
Hash::default(),
|
||||||
);
|
);
|
||||||
thread::spawn(move || {
|
thread::spawn(move || {
|
||||||
let blockhash = bank.confirmed_last_blockhash().0;
|
let blockhash = bank.confirmed_last_blockhash().0;
|
||||||
|
@ -2838,21 +2733,16 @@ pub mod tests {
|
||||||
let mut io = MetaIoHandler::default();
|
let mut io = MetaIoHandler::default();
|
||||||
let rpc = RpcSolImpl;
|
let rpc = RpcSolImpl;
|
||||||
io.extend_with(rpc.to_delegate());
|
io.extend_with(rpc.to_delegate());
|
||||||
let meta = Meta {
|
let meta = JsonRpcRequestProcessor::new(
|
||||||
request_processor: {
|
JsonRpcConfig::default(),
|
||||||
let request_processor = JsonRpcRequestProcessor::new(
|
new_bank_forks().0,
|
||||||
JsonRpcConfig::default(),
|
block_commitment_cache,
|
||||||
new_bank_forks().0,
|
blockstore,
|
||||||
block_commitment_cache,
|
validator_exit,
|
||||||
blockstore,
|
RpcHealth::stub(),
|
||||||
validator_exit,
|
Arc::new(ClusterInfo::default()),
|
||||||
RpcHealth::stub(),
|
Hash::default(),
|
||||||
);
|
);
|
||||||
Arc::new(RwLock::new(request_processor))
|
|
||||||
},
|
|
||||||
cluster_info: Arc::new(ClusterInfo::new_with_invalid_keypair(ContactInfo::default())),
|
|
||||||
genesis_hash: Hash::default(),
|
|
||||||
};
|
|
||||||
|
|
||||||
let req = r#"{"jsonrpc":"2.0","id":1,"method":"sendTransaction","params":["37u9WtQpcm6ULa3Vmu7ySnANv"]}"#;
|
let req = r#"{"jsonrpc":"2.0","id":1,"method":"sendTransaction","params":["37u9WtQpcm6ULa3Vmu7ySnANv"]}"#;
|
||||||
let res = io.handle_request_sync(req, meta);
|
let res = io.handle_request_sync(req, meta);
|
||||||
|
@ -2879,23 +2769,18 @@ pub mod tests {
|
||||||
let mut io = MetaIoHandler::default();
|
let mut io = MetaIoHandler::default();
|
||||||
let rpc = RpcSolImpl;
|
let rpc = RpcSolImpl;
|
||||||
io.extend_with(rpc.to_delegate());
|
io.extend_with(rpc.to_delegate());
|
||||||
let meta = Meta {
|
let meta = JsonRpcRequestProcessor::new(
|
||||||
request_processor: {
|
JsonRpcConfig::default(),
|
||||||
let request_processor = JsonRpcRequestProcessor::new(
|
bank_forks,
|
||||||
JsonRpcConfig::default(),
|
block_commitment_cache,
|
||||||
bank_forks,
|
blockstore,
|
||||||
block_commitment_cache,
|
validator_exit,
|
||||||
blockstore,
|
health.clone(),
|
||||||
validator_exit,
|
Arc::new(ClusterInfo::new_with_invalid_keypair(
|
||||||
health.clone(),
|
|
||||||
);
|
|
||||||
Arc::new(RwLock::new(request_processor))
|
|
||||||
},
|
|
||||||
cluster_info: Arc::new(ClusterInfo::new_with_invalid_keypair(
|
|
||||||
ContactInfo::new_with_socketaddr(&socketaddr!("127.0.0.1:1234")),
|
ContactInfo::new_with_socketaddr(&socketaddr!("127.0.0.1:1234")),
|
||||||
)),
|
)),
|
||||||
genesis_hash: Hash::default(),
|
Hash::default(),
|
||||||
};
|
);
|
||||||
|
|
||||||
let mut bad_transaction =
|
let mut bad_transaction =
|
||||||
system_transaction::transfer(&Keypair::new(), &Pubkey::default(), 42, Hash::default());
|
system_transaction::transfer(&Keypair::new(), &Pubkey::default(), 42, Hash::default());
|
||||||
|
@ -3039,6 +2924,8 @@ pub mod tests {
|
||||||
blockstore,
|
blockstore,
|
||||||
validator_exit,
|
validator_exit,
|
||||||
RpcHealth::stub(),
|
RpcHealth::stub(),
|
||||||
|
Arc::new(ClusterInfo::default()),
|
||||||
|
Hash::default(),
|
||||||
);
|
);
|
||||||
assert_eq!(request_processor.validator_exit(), Ok(false));
|
assert_eq!(request_processor.validator_exit(), Ok(false));
|
||||||
assert_eq!(exit.load(Ordering::Relaxed), false);
|
assert_eq!(exit.load(Ordering::Relaxed), false);
|
||||||
|
@ -3062,6 +2949,8 @@ pub mod tests {
|
||||||
blockstore,
|
blockstore,
|
||||||
validator_exit,
|
validator_exit,
|
||||||
RpcHealth::stub(),
|
RpcHealth::stub(),
|
||||||
|
Arc::new(ClusterInfo::default()),
|
||||||
|
Hash::default(),
|
||||||
);
|
);
|
||||||
assert_eq!(request_processor.validator_exit(), Ok(true));
|
assert_eq!(request_processor.validator_exit(), Ok(true));
|
||||||
assert_eq!(exit.load(Ordering::Relaxed), true);
|
assert_eq!(exit.load(Ordering::Relaxed), true);
|
||||||
|
@ -3145,6 +3034,8 @@ pub mod tests {
|
||||||
blockstore,
|
blockstore,
|
||||||
validator_exit,
|
validator_exit,
|
||||||
RpcHealth::stub(),
|
RpcHealth::stub(),
|
||||||
|
Arc::new(ClusterInfo::default()),
|
||||||
|
Hash::default(),
|
||||||
);
|
);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
request_processor.get_block_commitment(0),
|
request_processor.get_block_commitment(0),
|
||||||
|
|
|
@ -104,9 +104,7 @@ impl RpcHealth {
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
pub(crate) fn stub() -> Arc<Self> {
|
pub(crate) fn stub() -> Arc<Self> {
|
||||||
Arc::new(Self::new(
|
Arc::new(Self::new(
|
||||||
Arc::new(ClusterInfo::new_with_invalid_keypair(
|
Arc::new(ClusterInfo::default()),
|
||||||
crate::contact_info::ContactInfo::default(),
|
|
||||||
)),
|
|
||||||
None,
|
None,
|
||||||
42,
|
42,
|
||||||
Arc::new(AtomicBool::new(false)),
|
Arc::new(AtomicBool::new(false)),
|
||||||
|
|
|
@ -30,7 +30,7 @@ pub struct JsonRpcService {
|
||||||
thread_hdl: JoinHandle<()>,
|
thread_hdl: JoinHandle<()>,
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
pub request_processor: Arc<RwLock<JsonRpcRequestProcessor>>, // Used only by test_rpc_new()...
|
pub request_processor: JsonRpcRequestProcessor, // Used only by test_rpc_new()...
|
||||||
|
|
||||||
close_handle: Option<CloseHandle>,
|
close_handle: Option<CloseHandle>,
|
||||||
}
|
}
|
||||||
|
@ -249,14 +249,16 @@ impl JsonRpcService {
|
||||||
override_health_check,
|
override_health_check,
|
||||||
));
|
));
|
||||||
|
|
||||||
let request_processor = Arc::new(RwLock::new(JsonRpcRequestProcessor::new(
|
let request_processor = JsonRpcRequestProcessor::new(
|
||||||
config,
|
config,
|
||||||
bank_forks.clone(),
|
bank_forks.clone(),
|
||||||
block_commitment_cache,
|
block_commitment_cache,
|
||||||
blockstore,
|
blockstore,
|
||||||
validator_exit.clone(),
|
validator_exit.clone(),
|
||||||
health.clone(),
|
health.clone(),
|
||||||
)));
|
cluster_info,
|
||||||
|
genesis_hash,
|
||||||
|
);
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
let test_request_processor = request_processor.clone();
|
let test_request_processor = request_processor.clone();
|
||||||
|
@ -279,11 +281,7 @@ impl JsonRpcService {
|
||||||
);
|
);
|
||||||
let server = ServerBuilder::with_meta_extractor(
|
let server = ServerBuilder::with_meta_extractor(
|
||||||
io,
|
io,
|
||||||
move |_req: &hyper::Request<hyper::Body>| Meta {
|
move |_req: &hyper::Request<hyper::Body>| request_processor.clone(),
|
||||||
request_processor: request_processor.clone(),
|
|
||||||
cluster_info: cluster_info.clone(),
|
|
||||||
genesis_hash,
|
|
||||||
},
|
|
||||||
)
|
)
|
||||||
.threads(num_cpus::get())
|
.threads(num_cpus::get())
|
||||||
.cors(DomainsValidation::AllowOnly(vec![
|
.cors(DomainsValidation::AllowOnly(vec![
|
||||||
|
@ -339,7 +337,6 @@ impl JsonRpcService {
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
use crate::{
|
use crate::{
|
||||||
contact_info::ContactInfo,
|
|
||||||
crds_value::{CrdsData, CrdsValue, SnapshotHash},
|
crds_value::{CrdsData, CrdsValue, SnapshotHash},
|
||||||
rpc::tests::create_validator_exit,
|
rpc::tests::create_validator_exit,
|
||||||
};
|
};
|
||||||
|
@ -365,7 +362,7 @@ mod tests {
|
||||||
let exit = Arc::new(AtomicBool::new(false));
|
let exit = Arc::new(AtomicBool::new(false));
|
||||||
let validator_exit = create_validator_exit(&exit);
|
let validator_exit = create_validator_exit(&exit);
|
||||||
let bank = Bank::new(&genesis_config);
|
let bank = Bank::new(&genesis_config);
|
||||||
let cluster_info = Arc::new(ClusterInfo::new_with_invalid_keypair(ContactInfo::default()));
|
let cluster_info = Arc::new(ClusterInfo::default());
|
||||||
let ip_addr = IpAddr::V4(Ipv4Addr::new(0, 0, 0, 0));
|
let ip_addr = IpAddr::V4(Ipv4Addr::new(0, 0, 0, 0));
|
||||||
let rpc_addr = SocketAddr::new(
|
let rpc_addr = SocketAddr::new(
|
||||||
ip_addr,
|
ip_addr,
|
||||||
|
@ -398,8 +395,6 @@ mod tests {
|
||||||
10_000,
|
10_000,
|
||||||
rpc_service
|
rpc_service
|
||||||
.request_processor
|
.request_processor
|
||||||
.read()
|
|
||||||
.unwrap()
|
|
||||||
.get_balance(Ok(mint_keypair.pubkey()), None)
|
.get_balance(Ok(mint_keypair.pubkey()), None)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.value
|
.value
|
||||||
|
@ -484,7 +479,7 @@ mod tests {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_health_check_with_trusted_validators() {
|
fn test_health_check_with_trusted_validators() {
|
||||||
let cluster_info = Arc::new(ClusterInfo::new_with_invalid_keypair(ContactInfo::default()));
|
let cluster_info = Arc::new(ClusterInfo::default());
|
||||||
let health_check_slot_distance = 123;
|
let health_check_slot_distance = 123;
|
||||||
let override_health_check = Arc::new(AtomicBool::new(false));
|
let override_health_check = Arc::new(AtomicBool::new(false));
|
||||||
let trusted_validators = vec![Pubkey::new_rand(), Pubkey::new_rand(), Pubkey::new_rand()];
|
let trusted_validators = vec![Pubkey::new_rand(), Pubkey::new_rand(), Pubkey::new_rand()];
|
||||||
|
|
Loading…
Reference in New Issue