blockchain/mod.rs: bound randomx vm keys to be before optional height

This commit is contained in:
skoupidi
2025-07-23 13:14:35 +03:00
parent f32e11af8d
commit d4670375f8

View File

@@ -434,7 +434,7 @@ impl Blockchain {
/// Grab the RandomX VM current and next key, based on provided key
/// changing height and delay. Optionally, a height can be provided
/// to get the keys at it.
/// to get the keys before it.
///
/// NOTE: the height calculation logic is verified using test:
// test_randomx_keys_retrieval_logic
@@ -446,7 +446,7 @@ impl Blockchain {
) -> Result<([u8; 32], [u8; 32])> {
// Grab last known block header
let last = match height {
Some(h) => &self.get_headers_by_heights(&[h])?[0],
Some(h) => &self.get_headers_by_heights(&[if h != 0 { h - 1 } else { 0 }])?[0],
None => &self.last_header()?,
};