Skip to content

Commit

Permalink
use RMC from slot commitment
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Coats committed Feb 27, 2024
1 parent 553f54f commit 0e241e2
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 16 deletions.
23 changes: 16 additions & 7 deletions src/analytics/influx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ use super::{
LedgerOutputMeasurement, LedgerSizeMeasurement, OutputActivityMeasurement, TransactionSizeMeasurement,
UnlockConditionMeasurement,
},
tangle::{BlockActivityMeasurement, BlockIssuerMeasurement, ManaActivityMeasurement, SlotSizeMeasurement},
tangle::{
BlockActivityMeasurement, BlockIssuerMeasurement, ManaActivityMeasurement, SlotCommitmentMeasurement,
SlotSizeMeasurement,
},
AnalyticsInterval, PerInterval, PerSlot,
};
use crate::db::influxdb::InfluxDb;
Expand Down Expand Up @@ -62,12 +65,10 @@ where
M: Measurement,
{
fn prepare_query(&self) -> Vec<WriteQuery> {
vec![
influxdb::Timestamp::Seconds(self.slot_timestamp as _)
.into_query(M::NAME)
.add_field("slot_index", self.slot_index.0)
.add_fields(&self.inner),
]
vec![influxdb::Timestamp::Seconds(self.slot_timestamp as _)
.into_query(M::NAME)
.add_field("slot_index", self.slot_index.0)
.add_fields(&self.inner)]
}
}

Expand Down Expand Up @@ -281,6 +282,14 @@ impl Measurement for LedgerSizeMeasurement {
}
}

impl Measurement for SlotCommitmentMeasurement {
const NAME: &'static str = "iota_slot_commitment";

fn add_fields(&self, query: WriteQuery) -> WriteQuery {
query.add_field("reference_mana_cost", self.reference_mana_cost)
}
}

impl Measurement for SlotSizeMeasurement {
const NAME: &'static str = "iota_slot_size";

Expand Down
23 changes: 16 additions & 7 deletions src/analytics/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@
use futures::TryStreamExt;
use iota_sdk::types::block::{
output::OutputId, payload::SignedTransactionPayload, protocol::ProtocolParameters, slot::SlotIndex, Block,
output::OutputId,
payload::SignedTransactionPayload,
protocol::ProtocolParameters,
slot::{SlotCommitment, SlotIndex},
Block,
};
use rayon::iter::{IntoParallelRefMutIterator, ParallelIterator};
use thiserror::Error;
Expand All @@ -19,7 +23,7 @@ use self::{
},
tangle::{
BlockActivityMeasurement, BlockIssuerAnalytics, ManaActivityMeasurement, ProtocolParamsAnalytics,
SlotSizeMeasurement,
SlotCommitmentMeasurement, SlotSizeMeasurement,
},
};
use crate::{
Expand All @@ -43,7 +47,11 @@ mod tangle;
pub trait AnalyticsContext: Send + Sync {
fn protocol_parameters(&self) -> &ProtocolParameters;

fn slot_index(&self) -> SlotIndex;
fn slot_index(&self) -> SlotIndex {
self.slot_commitment().slot()
}

fn slot_commitment(&self) -> &SlotCommitment;
}

/// Defines how analytics are gathered.
Expand Down Expand Up @@ -181,6 +189,7 @@ impl Analytic {
AnalyticsChoice::ManaActivity => Box::<ManaActivityMeasurement>::default() as _,
AnalyticsChoice::OutputActivity => Box::<OutputActivityMeasurement>::default() as _,
AnalyticsChoice::ProtocolParameters => Box::<ProtocolParamsAnalytics>::default() as _,
AnalyticsChoice::SlotCommitment => Box::<SlotCommitmentMeasurement>::default() as _,
AnalyticsChoice::SlotSize => Box::<SlotSizeMeasurement>::default() as _,
AnalyticsChoice::TransactionSizeDistribution => Box::<TransactionSizeMeasurement>::default() as _,
})
Expand Down Expand Up @@ -249,7 +258,7 @@ impl<'a, I: InputSource> Slot<'a, I> {
PerSlot<A::Measurement>: 'static + PrepareQuery,
{
let ctx = BasicContext {
slot_index: self.index(),
slot_commitment: self.commitment().inner(),
protocol_parameters,
};

Expand Down Expand Up @@ -323,7 +332,7 @@ impl<'a, I: InputSource> Slot<'a, I> {
}

struct BasicContext<'a> {
slot_index: SlotIndex,
slot_commitment: &'a SlotCommitment,
protocol_parameters: &'a ProtocolParameters,
}

Expand All @@ -332,8 +341,8 @@ impl<'a> AnalyticsContext for BasicContext<'a> {
self.protocol_parameters
}

fn slot_index(&self) -> SlotIndex {
self.slot_index
fn slot_commitment(&self) -> &SlotCommitment {
self.slot_commitment
}
}

Expand Down
3 changes: 1 addition & 2 deletions src/analytics/tangle/mana_activity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,7 @@ impl Analytics for ManaActivityMeasurement {
}

fn handle_block(&mut self, block: &Block, _metadata: &BlockMetadata, ctx: &dyn AnalyticsContext) {
// TODO: need RMC from INX
let rmc = 1;
let rmc = ctx.slot_commitment().reference_mana_cost();
if let Some(body) = block.body().as_basic_opt() {
self.bic_burned += body.work_score(ctx.protocol_parameters().work_score_parameters()) as u64 * rmc;
}
Expand Down
2 changes: 2 additions & 0 deletions src/analytics/tangle/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@ pub(crate) use self::{
block_issuers::{BlockIssuerAnalytics, BlockIssuerMeasurement},
mana_activity::ManaActivityMeasurement,
protocol_params::ProtocolParamsAnalytics,
slot_commitment::SlotCommitmentMeasurement,
slot_size::SlotSizeMeasurement,
};

mod block_activity;
mod block_issuers;
mod mana_activity;
mod protocol_params;
mod slot_commitment;
mod slot_size;

// #[cfg(test)]
Expand Down
20 changes: 20 additions & 0 deletions src/analytics/tangle/slot_commitment.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Copyright 2024 IOTA Stiftung
// SPDX-License-Identifier: Apache-2.0

use crate::analytics::{Analytics, AnalyticsContext};

/// Slot size statistics.
#[derive(Copy, Clone, Debug, Default)]
pub(crate) struct SlotCommitmentMeasurement {
pub(crate) reference_mana_cost: u64,
}

impl Analytics for SlotCommitmentMeasurement {
type Measurement = Self;

fn take_measurement(&mut self, ctx: &dyn AnalyticsContext) -> Self::Measurement {
SlotCommitmentMeasurement {
reference_mana_cost: ctx.slot_commitment().reference_mana_cost(),
}
}
}
2 changes: 2 additions & 0 deletions src/db/influxdb/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ pub enum AnalyticsChoice {
ManaActivity,
OutputActivity,
ProtocolParameters,
SlotCommitment,
SlotSize,
TransactionSizeDistribution,
UnlockConditions,
Expand All @@ -106,6 +107,7 @@ pub fn all_analytics() -> HashSet<AnalyticsChoice> {
AnalyticsChoice::ManaActivity,
AnalyticsChoice::OutputActivity,
AnalyticsChoice::ProtocolParameters,
AnalyticsChoice::SlotCommitment,
AnalyticsChoice::SlotSize,
AnalyticsChoice::TransactionSizeDistribution,
AnalyticsChoice::UnlockConditions,
Expand Down

0 comments on commit 0e241e2

Please sign in to comment.