@@ -15,7 +15,7 @@ use solana_account_decoder::{
1515use solana_address_lookup_table_interface:: state:: AddressLookupTable ;
1616use solana_client:: {
1717 rpc_config:: {
18- RpcAccountInfoConfig , RpcLargestAccountsConfig , RpcLargestAccountsFilter ,
18+ RpcAccountInfoConfig , RpcBlockConfig , RpcLargestAccountsConfig , RpcLargestAccountsFilter ,
1919 RpcSignaturesForAddressConfig ,
2020 } ,
2121 rpc_filter:: RpcFilterType ,
@@ -44,7 +44,8 @@ use solana_signature::Signature;
4444use solana_transaction_error:: TransactionError ;
4545use solana_transaction_status:: {
4646 EncodedConfirmedTransactionWithStatusMeta ,
47- TransactionConfirmationStatus as SolanaTransactionConfirmationStatus , UiTransactionEncoding ,
47+ TransactionConfirmationStatus as SolanaTransactionConfirmationStatus , UiConfirmedBlock ,
48+ UiTransactionEncoding ,
4849} ;
4950use spl_token:: state:: Mint ;
5051use spl_token_2022:: extension:: StateWithExtensions ;
@@ -1752,6 +1753,47 @@ impl SurfnetSvmLocker {
17521753}
17531754
17541755impl SurfnetSvmLocker {
1756+ pub fn get_first_local_slot ( & self ) -> Option < Slot > {
1757+ self . with_svm_reader ( |svm_reader| svm_reader. blocks . keys ( ) . min ( ) . copied ( ) )
1758+ }
1759+
1760+ pub async fn get_block (
1761+ & self ,
1762+ remote_ctx : & Option < SurfnetRemoteClient > ,
1763+ slot : & Slot ,
1764+ config : & RpcBlockConfig ,
1765+ ) -> SurfpoolContextualizedResult < Option < UiConfirmedBlock > > {
1766+ let first_local_slot = self . get_first_local_slot ( ) ;
1767+
1768+ let result = if first_local_slot. is_some ( ) && first_local_slot. unwrap ( ) > * slot {
1769+ match remote_ctx {
1770+ Some ( remote_client) => Some ( remote_client. get_block ( slot, * config) . await ?) ,
1771+ None => return Err ( SurfpoolError :: slot_too_old ( * slot) ) ,
1772+ }
1773+ } else {
1774+ self . get_block_local ( slot, config) . inner
1775+ } ;
1776+
1777+ Ok ( SvmAccessContext {
1778+ slot : * slot,
1779+ latest_epoch_info : self . get_epoch_info ( ) ,
1780+ latest_blockhash : self
1781+ . get_latest_blockhash ( & CommitmentConfig :: processed ( ) )
1782+ . unwrap_or_default ( ) ,
1783+ inner : result,
1784+ } )
1785+ }
1786+
1787+ pub fn get_block_local (
1788+ & self ,
1789+ slot : & Slot ,
1790+ config : & RpcBlockConfig ,
1791+ ) -> SvmAccessContext < Option < UiConfirmedBlock > > {
1792+ self . with_contextualized_svm_reader ( |svm_reader| {
1793+ svm_reader. get_block_at_slot ( * slot, config)
1794+ } )
1795+ }
1796+
17551797 pub fn get_genesis_hash_local ( & self ) -> SvmAccessContext < Hash > {
17561798 self . with_contextualized_svm_reader ( |svm_reader| svm_reader. genesis_config . hash ( ) )
17571799 }
@@ -1786,6 +1828,12 @@ impl SurfnetSvmLocker {
17861828 self . with_svm_reader ( |svm_reader| svm_reader. get_latest_absolute_slot ( ) )
17871829 }
17881830
1831+ /// Retrieves the latest blockhash for the given commitment config from the underlying SVM.
1832+ pub fn get_latest_blockhash ( & self , config : & CommitmentConfig ) -> Option < Hash > {
1833+ let slot = self . get_slot_for_commitment ( config) ;
1834+ self . with_svm_reader ( |svm_reader| svm_reader. blockhash_for_slot ( slot) )
1835+ }
1836+
17891837 pub fn get_slot_for_commitment ( & self , commitment : & CommitmentConfig ) -> Slot {
17901838 self . with_svm_reader ( |svm_reader| {
17911839 let slot = svm_reader. get_latest_absolute_slot ( ) ;
0 commit comments