computer: snapshot

This commit is contained in:
nym21
2026-03-09 14:44:40 +01:00
parent cba3b7dc38
commit 362e8d1603
36 changed files with 213 additions and 213 deletions

View File

@@ -1,7 +1,7 @@
use std::time::{SystemTime, UNIX_EPOCH};
use brk_error::Result;
use brk_types::{DifficultyAdjustment, DifficultyEpoch, Height};
use brk_types::{DifficultyAdjustment, Epoch, Height};
use vecdb::ReadableVec;
use crate::Query;
@@ -23,7 +23,7 @@ impl Query {
let current_epoch = computer
.indexes
.height
.difficulty
.epoch
.collect_one(current_height)
.unwrap();
let current_epoch_usize: usize = current_epoch.into();
@@ -31,7 +31,7 @@ impl Query {
// Get epoch start height
let epoch_start_height = computer
.indexes
.difficulty
.epoch
.first_height
.collect_one(current_epoch)
.unwrap();
@@ -48,7 +48,7 @@ impl Query {
.blocks
.time
.timestamp
.difficulty
.epoch
.collect_one(current_epoch)
.unwrap();
let current_timestamp = indexer
@@ -87,10 +87,10 @@ impl Query {
// Calculate previous retarget using stored difficulty values
let previous_retarget = if current_epoch_usize > 0 {
let prev_epoch = DifficultyEpoch::from(current_epoch_usize - 1);
let prev_epoch = Epoch::from(current_epoch_usize - 1);
let prev_epoch_start = computer
.indexes
.difficulty
.epoch
.first_height
.collect_one(prev_epoch)
.unwrap();

View File

@@ -1,5 +1,5 @@
use brk_computer::Computer;
use brk_types::{DifficultyAdjustmentEntry, DifficultyEpoch, Height};
use brk_types::{DifficultyAdjustmentEntry, Epoch, Height};
use vecdb::{ReadableVec, Ro, VecIndex};
/// Iterate over difficulty epochs within a height range.
@@ -11,25 +11,25 @@ pub fn iter_difficulty_epochs(
let start_epoch = computer
.indexes
.height
.difficulty
.epoch
.collect_one(Height::from(start_height))
.unwrap_or_default();
let end_epoch = computer
.indexes
.height
.difficulty
.epoch
.collect_one(Height::from(end_height))
.unwrap_or_default();
let epoch_to_height = &computer.indexes.difficulty.first_height;
let epoch_to_timestamp = &computer.blocks.time.timestamp.difficulty;
let epoch_to_difficulty = &computer.blocks.difficulty.raw.difficulty;
let epoch_to_height = &computer.indexes.epoch.first_height;
let epoch_to_timestamp = &computer.blocks.time.timestamp.epoch;
let epoch_to_difficulty = &computer.blocks.difficulty.raw.epoch;
let mut results = Vec::with_capacity(end_epoch.to_usize() - start_epoch.to_usize() + 1);
let mut prev_difficulty: Option<f64> = None;
for epoch_usize in start_epoch.to_usize()..=end_epoch.to_usize() {
let epoch = DifficultyEpoch::from(epoch_usize);
let epoch = Epoch::from(epoch_usize);
let epoch_height = epoch_to_height.collect_one(epoch).unwrap_or_default();
// Skip epochs before our start height but track difficulty