Skip to content
This repository was archived by the owner on Jan 22, 2025. It is now read-only.

Commit b6e708a

Browse files
mergify[bot]CriesofCarrots
authored andcommitted
v1.18: RPC: rewards, return error if epoch_boundary_block is a lie (backport of #2758) (#2781)
* RPC: rewards, return error if epoch_boundary_block is a lie (#2758) * Return error if epoch_boundary_block is not actually the epoch boundary block * Update rpc-client-api/src/custom_error.rs Co-authored-by: Trent Nelson <[email protected]> --------- Co-authored-by: Trent Nelson <[email protected]> (cherry picked from commit 9a4b094) # Conflicts: # rpc-client-api/src/custom_error.rs # rpc/src/rpc.rs * Fix conflicts --------- Co-authored-by: Tyera <[email protected]>
1 parent 4f9e1fb commit b6e708a

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

rpc-client-api/src/custom_error.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ pub const JSON_RPC_SERVER_ERROR_TRANSACTION_SIGNATURE_LEN_MISMATCH: i64 = -32013
2424
pub const JSON_RPC_SERVER_ERROR_BLOCK_STATUS_NOT_AVAILABLE_YET: i64 = -32014;
2525
pub const JSON_RPC_SERVER_ERROR_UNSUPPORTED_TRANSACTION_VERSION: i64 = -32015;
2626
pub 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)]
2931
pub 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
}

rpc/src/rpc.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff 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())

0 commit comments

Comments
 (0)