Skip to content

Commit 6b170d9

Browse files
authored
fix: use block height instead of slot for lastValidBlockHeight in getLatestBlockhash (#387)
1 parent f2fdda9 commit 6b170d9

File tree

1 file changed

+8
-17
lines changed

1 file changed

+8
-17
lines changed

crates/core/src/rpc/full.rs

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2152,8 +2152,8 @@ impl Full for SurfpoolFullRpc {
21522152
.get_latest_blockhash(&commitment)
21532153
.unwrap_or_else(|| svm_locker.latest_absolute_blockhash());
21542154

2155-
let last_valid_block_height =
2156-
committed_latest_slot + MAX_RECENT_BLOCKHASHES_STANDARD as u64;
2155+
let current_block_height = svm_locker.get_epoch_info().block_height;
2156+
let last_valid_block_height = current_block_height + MAX_RECENT_BLOCKHASHES_STANDARD as u64;
21572157
Ok(RpcResponse {
21582158
context: RpcResponseContext::new(svm_locker.get_latest_absolute_slot()),
21592159
value: RpcBlockhash {
@@ -3243,12 +3243,9 @@ mod tests {
32433243
.get_latest_blockhash(&commitment)
32443244
.unwrap();
32453245

3246-
let committed_slot = setup
3247-
.context
3248-
.svm_locker
3249-
.get_slot_for_commitment(&commitment);
3246+
let current_block_height = setup.context.svm_locker.get_epoch_info().block_height;
32503247
let expected_last_valid_block_height =
3251-
committed_slot + MAX_RECENT_BLOCKHASHES_STANDARD as u64;
3248+
current_block_height + MAX_RECENT_BLOCKHASHES_STANDARD as u64;
32523249

32533250
assert_eq!(
32543251
res.value.blockhash,
@@ -3280,12 +3277,9 @@ mod tests {
32803277
.get_latest_blockhash(&commitment)
32813278
.unwrap();
32823279

3283-
let committed_slot = setup
3284-
.context
3285-
.svm_locker
3286-
.get_slot_for_commitment(&commitment);
3280+
let current_block_height = setup.context.svm_locker.get_epoch_info().block_height;
32873281
let expected_last_valid_block_height =
3288-
committed_slot + MAX_RECENT_BLOCKHASHES_STANDARD as u64;
3282+
current_block_height + MAX_RECENT_BLOCKHASHES_STANDARD as u64;
32893283

32903284
assert_eq!(
32913285
res.value.blockhash,
@@ -3317,12 +3311,9 @@ mod tests {
33173311
.get_latest_blockhash(&commitment)
33183312
.unwrap();
33193313

3320-
let committed_slot = setup
3321-
.context
3322-
.svm_locker
3323-
.get_slot_for_commitment(&commitment);
3314+
let current_block_height = setup.context.svm_locker.get_epoch_info().block_height;
33243315
let expected_last_valid_block_height =
3325-
committed_slot + MAX_RECENT_BLOCKHASHES_STANDARD as u64;
3316+
current_block_height + MAX_RECENT_BLOCKHASHES_STANDARD as u64;
33263317

33273318
assert_eq!(
33283319
res.value.blockhash,

0 commit comments

Comments
 (0)