global: add hash related datasets

This commit is contained in:
nym21
2025-09-11 01:02:29 +02:00
parent 72bba06e71
commit 47f7cef4f4
5 changed files with 430 additions and 25 deletions
@@ -10,6 +10,8 @@ use zerocopy_derive::{FromBytes, Immutable, IntoBytes, KnownLayout};
use super::Height;
pub const BLOCKS_PER_HALVING: u32 = 210_000;
#[derive(
Debug,
Clone,
@@ -78,7 +80,7 @@ impl Add<usize> for HalvingEpoch {
impl From<Height> for HalvingEpoch {
fn from(value: Height) -> Self {
Self((u32::from(value) / 210_000) as u16)
Self((u32::from(value) / BLOCKS_PER_HALVING) as u16)
}
}
+6 -2
View File
@@ -12,7 +12,7 @@ use vecdb::{CheckedSub, Printable, Stamp, StoredCompressed};
use zerocopy::{FromBytes, IntoBytes};
use zerocopy_derive::{FromBytes, Immutable, IntoBytes, KnownLayout};
use crate::{BLOCKS_PER_DIFF_EPOCHS, copy_first_4bytes};
use crate::{BLOCKS_PER_DIFF_EPOCHS, BLOCKS_PER_HALVING, copy_first_4bytes};
use super::StoredU64;
@@ -74,7 +74,11 @@ impl Height {
}
pub fn left_before_next_diff_adj(self) -> u32 {
BLOCKS_PER_DIFF_EPOCHS - (*self % 2016)
BLOCKS_PER_DIFF_EPOCHS - (*self % BLOCKS_PER_DIFF_EPOCHS)
}
pub fn left_before_next_halving(self) -> u32 {
BLOCKS_PER_HALVING - (*self % BLOCKS_PER_HALVING)
}
}