This repository was archived by the owner on Jan 22, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +26
-0
lines changed Expand file tree Collapse file tree 2 files changed +26
-0
lines changed Original file line number Diff line number Diff line change @@ -24,6 +24,8 @@ pub const JSON_RPC_SERVER_ERROR_TRANSACTION_SIGNATURE_LEN_MISMATCH: i64 = -32013
2424pub const JSON_RPC_SERVER_ERROR_BLOCK_STATUS_NOT_AVAILABLE_YET : i64 = -32014 ;
2525pub const JSON_RPC_SERVER_ERROR_UNSUPPORTED_TRANSACTION_VERSION : i64 = -32015 ;
2626pub const JSON_RPC_SERVER_ERROR_MIN_CONTEXT_SLOT_NOT_REACHED : i64 = -32016 ;
27+ const _RESERVED_FOR_V2_0_ERROR: i64 = -32017 ;
28+ pub const JSON_RPC_SERVER_ERROR_SLOT_NOT_EPOCH_BOUNDARY : i64 = -32018 ;
2729
2830#[ derive( Error , Debug ) ]
2931pub enum RpcCustomError {
@@ -65,6 +67,8 @@ pub enum RpcCustomError {
6567 UnsupportedTransactionVersion ( u8 ) ,
6668 #[ error( "MinContextSlotNotReached" ) ]
6769 MinContextSlotNotReached { context_slot : Slot } ,
70+ #[ error( "SlotNotEpochBoundary" ) ]
71+ SlotNotEpochBoundary { slot : Slot } ,
6872}
6973
7074#[ derive( Debug , Serialize , Deserialize ) ]
@@ -206,6 +210,14 @@ impl From<RpcCustomError> for Error {
206210 context_slot,
207211 } ) ) ,
208212 } ,
213+ RpcCustomError :: SlotNotEpochBoundary { slot } => Self {
214+ code : ErrorCode :: ServerError ( JSON_RPC_SERVER_ERROR_SLOT_NOT_EPOCH_BOUNDARY ) ,
215+ message : format ! (
216+ "Rewards cannot be found because slot {slot} is not the epoch boundary. This \
217+ may be due to gap in the queried node's local ledger or long-term storage"
218+ ) ,
219+ data : None ,
220+ } ,
209221 }
210222 }
211223}
Original file line number Diff line number Diff line change @@ -575,6 +575,20 @@ impl JsonRpcRequestProcessor {
575575 . into ( ) ) ;
576576 } ;
577577
578+ // If there is a gap in blockstore or long-term historical storage that
579+ // includes the epoch boundary, the `get_blocks_with_limit()` call above
580+ // will return the slot of the block at the end of that gap, not a
581+ // legitimate epoch-boundary block. Therefore, verify that the parent of
582+ // `epoch_boundary_block` occurred before the `first_slot_in_epoch`. If
583+ // it didn't, return an error; it will be impossible to locate
584+ // rewards properly.
585+ if first_confirmed_block. parent_slot >= first_slot_in_epoch {
586+ return Err ( RpcCustomError :: SlotNotEpochBoundary {
587+ slot : first_confirmed_block_in_epoch,
588+ }
589+ . into ( ) ) ;
590+ }
591+
578592 let addresses: Vec < String > = addresses
579593 . into_iter ( )
580594 . map ( |pubkey| pubkey. to_string ( ) )
You can’t perform that action at this time.
0 commit comments