Skip to content

Commit

Permalink
Undo breaking rpc removal of getSignatureConfirmation (#9245) (#9250)
Browse files Browse the repository at this point in the history
automerge
  • Loading branch information
mergify[bot] authored Apr 2, 2020
1 parent 32ab57f commit c4c96e1
Showing 1 changed file with 69 additions and 18 deletions.
87 changes: 69 additions & 18 deletions core/src/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,24 @@ impl JsonRpcRequestProcessor {
.unwrap_or(None))
}

pub fn get_signature_confirmation_status(
&self,
signature: Signature,
commitment: Option<CommitmentConfig>,
) -> Option<RpcSignatureConfirmation> {
self.get_transaction_status(signature, &self.bank(commitment))
.map(
|TransactionStatus {
status,
confirmations,
..
}| RpcSignatureConfirmation {
confirmations: confirmations.unwrap_or(MAX_LOCKOUT_HISTORY + 1),
status,
},
)
}

pub fn get_signature_status(
&self,
signature: Signature,
Expand All @@ -417,31 +435,38 @@ impl JsonRpcRequestProcessor {
let bank = self.bank(commitment);

for signature in signatures {
let status = bank
.get_signature_status_slot(&signature)
.map(|(slot, status)| {
let r_block_commitment_cache = self.block_commitment_cache.read().unwrap();

let confirmations = if r_block_commitment_cache.root() >= slot {
None
} else {
r_block_commitment_cache
.get_confirmation_count(slot)
.or(Some(0))
};
TransactionStatus {
slot,
status,
confirmations,
}
});
let status = self.get_transaction_status(signature, &bank);
statuses.push(status);
}
Ok(Response {
context: RpcResponseContext { slot: bank.slot() },
value: statuses,
})
}

fn get_transaction_status(
&self,
signature: Signature,
bank: &Arc<Bank>,
) -> Option<TransactionStatus> {
bank.get_signature_status_slot(&signature)
.map(|(slot, status)| {
let r_block_commitment_cache = self.block_commitment_cache.read().unwrap();

let confirmations = if r_block_commitment_cache.root() >= slot {
None
} else {
r_block_commitment_cache
.get_confirmation_count(slot)
.or(Some(0))
};
TransactionStatus {
slot,
status,
confirmations,
}
})
}
}

fn get_tpu_addr(cluster_info: &Arc<RwLock<ClusterInfo>>) -> Result<SocketAddr> {
Expand Down Expand Up @@ -564,6 +589,14 @@ pub trait RpcSol {
#[rpc(meta, name = "getFeeRateGovernor")]
fn get_fee_rate_governor(&self, meta: Self::Metadata) -> RpcResponse<RpcFeeRateGovernor>;

#[rpc(meta, name = "getSignatureConfirmation")]
fn get_signature_confirmation(
&self,
meta: Self::Metadata,
signature_str: String,
commitment: Option<CommitmentConfig>,
) -> Result<Option<RpcSignatureConfirmation>>;

#[rpc(meta, name = "getSignatureStatus")]
fn get_signature_status(
&self,
Expand Down Expand Up @@ -903,6 +936,24 @@ impl RpcSol for RpcSolImpl {
.get_fee_rate_governor()
}

fn get_signature_confirmation(
&self,
meta: Self::Metadata,
signature_str: String,
commitment: Option<CommitmentConfig>,
) -> Result<Option<RpcSignatureConfirmation>> {
debug!(
"get_signature_confirmation rpc request received: {:?}",
signature_str
);
let signature = verify_signature(&signature_str)?;
Ok(meta
.request_processor
.read()
.unwrap()
.get_signature_confirmation_status(signature, commitment))
}

fn get_signature_status(
&self,
meta: Self::Metadata,
Expand Down

0 comments on commit c4c96e1

Please sign in to comment.