global: add mining related datasets

This commit is contained in:
nym21
2025-09-10 21:57:15 +02:00
parent 9b92c5ce38
commit 72bba06e71
7 changed files with 116 additions and 5 deletions
+1 -1
View File
@@ -13,7 +13,7 @@ package.rust-version = "1.89"
[profile.dev]
lto = "thin"
debug = true
codegen-units = 2
codegen-units = 1
opt-level = 3
overflow-checks = true
+83
View File
@@ -23,6 +23,7 @@ use super::{Indexes, indexes, price};
const VERSION: Version = Version::ZERO;
const TARGET_BLOCKS_PER_DAY_F64: f64 = 144.0;
const TARGET_BLOCKS_PER_DAY_F32: f32 = 144.0;
const TARGET_BLOCKS_PER_DAY: u64 = 144;
const TARGET_BLOCKS_PER_WEEK: u64 = 7 * TARGET_BLOCKS_PER_DAY;
const TARGET_BLOCKS_PER_MONTH: u64 = 30 * TARGET_BLOCKS_PER_DAY;
@@ -112,6 +113,9 @@ pub struct Vecs {
pub indexes_to_hash_rate_2m_sma: ComputedVecsFromDateIndex<StoredF32>,
pub indexes_to_hash_rate_1y_sma: ComputedVecsFromDateIndex<StoredF32>,
pub indexes_to_difficulty_as_hash: ComputedVecsFromDateIndex<StoredF32>,
pub indexes_to_difficulty_adjustment: ComputedVecsFromHeight<StoredF32>,
pub indexes_to_blocks_before_next_difficulty_adjustment: ComputedVecsFromHeight<StoredU32>,
pub indexes_to_days_before_next_difficulty_adjustment: ComputedVecsFromHeight<StoredF32>,
}
impl Vecs {
@@ -887,6 +891,32 @@ impl Vecs {
indexes,
VecBuilderOptions::default().add_last(),
)?,
indexes_to_difficulty_adjustment: ComputedVecsFromHeight::forced_import(
&db,
"difficulty_adjustment",
Source::Compute,
version + VERSION + Version::ZERO,
indexes,
VecBuilderOptions::default().add_sum(),
)?,
indexes_to_blocks_before_next_difficulty_adjustment:
ComputedVecsFromHeight::forced_import(
&db,
"blocks_before_next_difficulty_adjustment",
Source::Compute,
version + VERSION + Version::TWO,
indexes,
VecBuilderOptions::default().add_last(),
)?,
indexes_to_days_before_next_difficulty_adjustment:
ComputedVecsFromHeight::forced_import(
&db,
"days_before_next_difficulty_adjustment",
Source::Compute,
version + VERSION + Version::TWO,
indexes,
VecBuilderOptions::default().add_last(),
)?,
txindex_to_is_coinbase,
inputindex_to_value,
@@ -1643,6 +1673,46 @@ impl Vecs {
})?;
}
self.indexes_to_difficulty_adjustment.compute_all(
indexes,
starting_indexes,
exit,
|v| {
v.compute_percentage_change(
starting_indexes.height,
&indexer.vecs.height_to_difficulty,
1,
exit,
)?;
Ok(())
},
)?;
self.indexes_to_blocks_before_next_difficulty_adjustment
.compute_all(indexes, starting_indexes, exit, |v| {
v.compute_transform(
starting_indexes.height,
&indexes.height_to_height,
|(h, ..)| (h, StoredU32::from(h.left_before_next_diff_adj())),
exit,
)?;
Ok(())
})?;
self.indexes_to_days_before_next_difficulty_adjustment
.compute_all(indexes, starting_indexes, exit, |v| {
v.compute_transform(
starting_indexes.height,
self.indexes_to_blocks_before_next_difficulty_adjustment
.height
.as_ref()
.unwrap(),
|(h, blocks, ..)| (h, (*blocks as f32 / TARGET_BLOCKS_PER_DAY_F32).into()),
exit,
)?;
Ok(())
})?;
Ok(())
}
@@ -1691,9 +1761,22 @@ impl Vecs {
iter = Box::new(iter.chain(self.indexes_to_block_weight.iter_any_collectable()));
iter = Box::new(iter.chain(self.indexes_to_difficulty.iter_any_collectable()));
iter = Box::new(iter.chain(self.indexes_to_difficulty_adjustment.iter_any_collectable()));
iter = Box::new(iter.chain(self.indexes_to_difficultyepoch.iter_any_collectable()));
iter = Box::new(iter.chain(self.indexes_to_halvingepoch.iter_any_collectable()));
iter = Box::new(iter.chain(self.indexes_to_difficulty_as_hash.iter_any_collectable()));
iter = Box::new(
iter.chain(
self.indexes_to_blocks_before_next_difficulty_adjustment
.iter_any_collectable(),
),
);
iter = Box::new(
iter.chain(
self.indexes_to_days_before_next_difficulty_adjustment
.iter_any_collectable(),
),
);
iter = Box::new(iter.chain(self.indexes_to_coinbase.iter_any_collectable()));
iter = Box::new(iter.chain(self.indexes_to_fee.iter_any_collectable()));
@@ -10,6 +10,8 @@ use zerocopy_derive::{FromBytes, Immutable, IntoBytes, KnownLayout};
use super::Height;
pub const BLOCKS_PER_DIFF_EPOCHS: u32 = 2016;
#[derive(
Debug,
Clone,
@@ -79,7 +81,7 @@ impl Div<usize> for DifficultyEpoch {
impl From<Height> for DifficultyEpoch {
fn from(value: Height) -> Self {
Self((u32::from(value) / 2016) as u16)
Self((u32::from(value) / BLOCKS_PER_DIFF_EPOCHS) as u16)
}
}
+5 -1
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::copy_first_4bytes;
use crate::{BLOCKS_PER_DIFF_EPOCHS, copy_first_4bytes};
use super::StoredU64;
@@ -72,6 +72,10 @@ impl Height {
pub fn is_not_zero(self) -> bool {
self != Self::ZERO
}
pub fn left_before_next_diff_adj(self) -> u32 {
BLOCKS_PER_DIFF_EPOCHS - (*self % 2016)
}
}
impl PartialEq<u64> for Height {
@@ -691,6 +691,9 @@ function createChartElement({
visible: defaultActive !== false,
priceLineVisible: false,
color: color(),
// lineVisible: false,
// pointMarkersVisible: true,
// pointMarkersRadius: 1.375,
...options,
},
paneIndex,
+8 -2
View File
@@ -39,6 +39,7 @@
* "Bool" |
* "Days" |
* "%mcap" |
* "blocks" |
* "%cmcap" |
* "%cp+l" |
* "%rcap" |
@@ -57,7 +58,6 @@
* "sd" |
* "Epoch" |
* "Height" |
* "Type" |
* "Bytes"
* } Unit
*/
@@ -768,6 +768,9 @@ function createUtils() {
if ((!unit || thoroughUnitCheck) && id === "chain") {
setUnit("block");
}
if ((!unit || thoroughUnitCheck) && id.startsWith("blocks_before")) {
setUnit("blocks");
}
if (
(!unit || thoroughUnitCheck) &&
(id === "emptyaddressdata" || id === "loadedaddressdata")
@@ -835,6 +838,7 @@ function createUtils() {
if (
(!unit || thoroughUnitCheck) &&
(id === "price_drawdown" ||
id === "difficulty_adjustment" ||
id.endsWith("oscillator") ||
id.endsWith("dominance") ||
id.endsWith("returns") ||
@@ -978,7 +982,9 @@ function createUtils() {
}
if (
(!unit || thoroughUnitCheck) &&
(id.includes("days_between") || id.includes("days_since"))
(id.includes("days_between") ||
id.includes("days_since") ||
id.startsWith("days_before"))
) {
setUnit("Days");
}
+13
View File
@@ -3764,6 +3764,19 @@ function createPartialOptions({ env, colors, vecIdToIndexes, pools }) {
key: "difficultyepoch",
name: "Epoch",
}),
{
key: "difficulty_adjustment",
title: "Adjustment",
type: "Baseline",
},
createBaseSeries({
key: "blocks_before_next_difficulty_adjustment",
name: "Before next",
}),
createBaseSeries({
key: "days_before_next_difficulty_adjustment",
name: "Before next",
}),
],
},
{