From e20a2e425739ddd9e540c8c76ea3ffb9929bc619 Mon Sep 17 00:00:00 2001 From: Godmode Galactus Date: Tue, 6 Dec 2022 20:21:52 +0100 Subject: [PATCH 1/2] Adding getLatestBlockhash in rpc --- src/rpc.rs | 40 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) diff --git a/src/rpc.rs b/src/rpc.rs index 41967012..6ef36112 100644 --- a/src/rpc.rs +++ b/src/rpc.rs @@ -316,6 +316,13 @@ pub mod lite_rpc { &self, meta: Self::Metadata, ) -> Result; + + #[rpc(meta, name = "getLatestBlockhash")] + fn get_latest_blockhash( + &self, + meta: Self::Metadata, + config: Option, + ) -> Result>; } pub struct LightRpc; impl Lite for LightRpc { @@ -355,7 +362,7 @@ pub mod lite_rpc { ) -> Result> { let commitment = match commitment { Some(x) => x.commitment, - None => CommitmentLevel::Confirmed, + None => CommitmentLevel::Finalized, }; let (block_hash, slot) = match commitment { CommitmentLevel::Finalized => { @@ -387,6 +394,37 @@ pub mod lite_rpc { }) } + fn get_latest_blockhash( + &self, + meta: Self::Metadata, + config: Option, + ) -> Result> { + let commitment = match config { + Some(x) => match x.commitment { + Some(x) => x.commitment, + None => CommitmentLevel::Finalized, + }, + None => CommitmentLevel::Finalized, + }; + + let block_info = match commitment { + CommitmentLevel::Finalized => &meta.context.finalized_block_info, + _ => &meta.context.confirmed_block_info, + }; + + let slot = block_info.slot.load(Ordering::Relaxed); + let last_valid_block_height = block_info.block_height.load(Ordering::Relaxed); + let blockhash = block_info.block_hash.read().unwrap().clone(); + + Ok(RpcResponse { + context: RpcResponseContext::new(slot), + value: RpcBlockhash { + blockhash, + last_valid_block_height, + }, + }) + } + fn confirm_transaction( &self, meta: Self::Metadata, From 73f9f0bd3db9cf1231f59e19fc64ac1f82cd0eb7 Mon Sep 17 00:00:00 2001 From: Godmode Galactus Date: Tue, 6 Dec 2022 22:25:24 +0100 Subject: [PATCH 2/2] adding get signature statuses --- src/context.rs | 5 ---- src/rpc.rs | 64 ++++++++++++++++++++++++++++++++++++++++++++------ 2 files changed, 57 insertions(+), 12 deletions(-) diff --git a/src/context.rs b/src/context.rs index cfdd8bf0..66ef583d 100644 --- a/src/context.rs +++ b/src/context.rs @@ -169,11 +169,6 @@ impl LiteRpcSubsrciptionControl { Ok(notification_type) => { let rpc_notification = match notification_type { NotificationType::Signature(data) => { - println!( - "getting signature notification {} confirmation {}", - data.signature, - data.commitment.to_string() - ); let signature_params = SignatureSubscriptionParams { commitment: CommitmentConfig { commitment: data.commitment, diff --git a/src/rpc.rs b/src/rpc.rs index 6ef36112..936fe54e 100644 --- a/src/rpc.rs +++ b/src/rpc.rs @@ -160,7 +160,6 @@ impl LightRpcRequestProcessor { notification_sender: &crossbeam_channel::Sender, block_information: &BlockInformation, ) { - println!("processing blocks for {}", commitment); loop { let block_data = reciever.recv(); @@ -196,10 +195,7 @@ impl LightRpcRequestProcessor { for signature in signatures { match signature_status.entry(signature.clone()) { dashmap::mapref::entry::Entry::Occupied(mut x) => { - println!( - "found signature {} for commitment {}", - signature, commitment - ); + let signature_notification = SignatureNotification { signature: Signature::from_str(signature.as_str()) .unwrap(), @@ -272,7 +268,9 @@ pub struct RpcPerformanceCounterResults { pub mod lite_rpc { use std::str::FromStr; + use itertools::Itertools; use solana_sdk::{fee_calculator::FeeCalculator, pubkey::Pubkey}; + use solana_transaction_status::{TransactionStatus, TransactionConfirmationStatus}; use super::*; #[rpc] @@ -323,6 +321,15 @@ pub mod lite_rpc { meta: Self::Metadata, config: Option, ) -> Result>; + + #[rpc(meta, name = "getSignatureStatuses")] + fn get_signature_statuses( + &self, + meta: Self::Metadata, + signature_strs: Vec, + config: Option, + ) -> Result>>>; + } pub struct LightRpc; impl Lite for LightRpc { @@ -349,7 +356,6 @@ pub mod lite_rpc { meta.context .signature_status .insert(transaction.signatures[0].to_string(), None); - println!("added {} to map", transaction.signatures[0]); meta.tpu_client.send_wire_transaction(wire_transaction); meta.performance_counter.update_sent_transactions_counter(); Ok(transaction.signatures[0].to_string()) @@ -456,7 +462,6 @@ pub mod lite_rpc { match k_value { Some(value) => match *value { Some(commitment_for_signature) => { - println!("found in cache"); Ok(RpcResponse { context: RpcResponseContext::new(slot), value: if commitment.eq(&CommitmentLevel::Finalized) { @@ -491,6 +496,51 @@ pub mod lite_rpc { } } + fn get_signature_statuses( + &self, + meta: Self::Metadata, + signature_strs: Vec, + _config: Option, + ) -> Result>>> { + let confirmed_slot = meta.context.confirmed_block_info.slot.load(Ordering::Relaxed); + let status = signature_strs.iter().map(|x| { + let singature_status = meta.context.signature_status.get(x); + let k_value = singature_status; + match k_value { + Some(value) => match *value { + Some(commitment_for_signature) => { + let slot = meta.context + .confirmed_block_info + .slot + .load(Ordering::Relaxed); + meta.performance_counter + .update_confirm_transaction_counter(); + + let status = match commitment_for_signature { + CommitmentLevel::Finalized => TransactionConfirmationStatus::Finalized, + _ => TransactionConfirmationStatus::Confirmed, + }; + Some(TransactionStatus { + slot, + confirmations: Some(1), + status: Ok(()), + err: None, + confirmation_status : Some(status) + }) + } + None => None, + }, + None => None + } + }).collect_vec(); + Ok( + RpcResponse { + context : RpcResponseContext::new(confirmed_slot), + value: status, + } + ) + } + fn request_airdrop( &self, meta: Self::Metadata,