Skip to content

Commit

Permalink
fix: commitments/by-index/:index/blocks route should return only fi…
Browse files Browse the repository at this point in the history
…nalized blocks (#1385)

* filter out non-finalized blocks

* remove block state analytics

* update dashboard

* much better

---------

Co-authored-by: DaughterOfMars <[email protected]>
  • Loading branch information
Alex6323 and DaughterOfMars authored May 6, 2024
1 parent 5012bd8 commit 18b69fd
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 128 deletions.
84 changes: 0 additions & 84 deletions docker/assets/grafana/dashboards/analytics_dashboard.json
Original file line number Diff line number Diff line change
Expand Up @@ -281,48 +281,6 @@
"refId": "A",
"resultFormat": "time_series",
"select": [
[
{
"params": ["block_pending_count"],
"type": "field"
},
{
"params": [],
"type": "sum"
},
{
"params": ["Pending"],
"type": "alias"
}
],
[
{
"params": ["block_accepted_count"],
"type": "field"
},
{
"params": [],
"type": "sum"
},
{
"params": ["Accepted"],
"type": "alias"
}
],
[
{
"params": ["block_confirmed_count"],
"type": "field"
},
{
"params": [],
"type": "sum"
},
{
"params": ["Confirmed"],
"type": "alias"
}
],
[
{
"params": ["block_finalized_count"],
Expand All @@ -336,48 +294,6 @@
"params": ["Finalized"],
"type": "alias"
}
],
[
{
"params": ["block_rejected_count"],
"type": "field"
},
{
"params": [],
"type": "sum"
},
{
"params": ["Rejected"],
"type": "alias"
}
],
[
{
"params": ["block_failed_count"],
"type": "field"
},
{
"params": [],
"type": "sum"
},
{
"params": ["Failed"],
"type": "alias"
}
],
[
{
"params": ["block_unknown_count"],
"type": "field"
},
{
"params": [],
"type": "sum"
},
{
"params": ["Unknown"],
"type": "alias"
}
]
],
"tags": []
Expand Down
6 changes: 0 additions & 6 deletions src/analytics/influx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,13 +178,7 @@ impl Measurement for BlockActivityMeasurement {
.add_field("tagged_data_count", self.tagged_data_count as u64)
.add_field("candidacy_announcement_count", self.candidacy_announcement_count as u64)
.add_field("no_payload_count", self.no_payload_count as u64)
.add_field("block_pending_count", self.block_pending_count as u64)
.add_field("block_accepted_count", self.block_accepted_count as u64)
.add_field("block_confirmed_count", self.block_confirmed_count as u64)
.add_field("block_finalized_count", self.block_finalized_count as u64)
.add_field("block_dropped_count", self.block_dropped_count as u64)
.add_field("block_orphaned_count", self.block_orphaned_count as u64)
.add_field("block_unknown_count", self.block_unknown_count as u64)
.add_field("txn_pending_count", self.txn_pending_count as u64)
.add_field("txn_accepted_count", self.txn_accepted_count as u64)
.add_field("txn_committed_count", self.txn_committed_count as u64)
Expand Down
24 changes: 5 additions & 19 deletions src/analytics/tangle/block_activity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// SPDX-License-Identifier: Apache-2.0

use iota_sdk::types::{
api::core::{BlockState, TransactionState},
api::core::TransactionState,
block::{
payload::{Payload, SignedTransactionPayload},
Block, BlockBody,
Expand All @@ -26,13 +26,7 @@ pub(crate) struct BlockActivityMeasurement {
pub(crate) tagged_data_count: usize,
pub(crate) transaction_count: usize,
pub(crate) candidacy_announcement_count: usize,
pub(crate) block_pending_count: usize,
pub(crate) block_accepted_count: usize,
pub(crate) block_confirmed_count: usize,
pub(crate) block_finalized_count: usize,
pub(crate) block_dropped_count: usize,
pub(crate) block_orphaned_count: usize,
pub(crate) block_unknown_count: usize,
pub(crate) txn_pending_count: usize,
pub(crate) txn_accepted_count: usize,
pub(crate) txn_committed_count: usize,
Expand All @@ -47,7 +41,7 @@ impl Analytics for BlockActivityMeasurement {
async fn handle_block(
&mut self,
block: &Block,
block_metadata: &BlockMetadata,
_block_metadata: &BlockMetadata,
_ctx: &dyn AnalyticsContext,
) -> eyre::Result<()> {
match block.body() {
Expand All @@ -62,17 +56,9 @@ impl Analytics for BlockActivityMeasurement {
}
BlockBody::Validation(_) => self.validation_count += 1,
}
match &block_metadata.block_state {
Some(state) => match state {
BlockState::Pending => self.block_pending_count += 1,
BlockState::Accepted => self.block_accepted_count += 1,
BlockState::Confirmed => self.block_confirmed_count += 1,
BlockState::Finalized => self.block_finalized_count += 1,
BlockState::Dropped => self.block_dropped_count += 1,
BlockState::Orphaned => self.block_orphaned_count += 1,
},
None => self.block_unknown_count += 1,
}

// non-finalized blocks, or blocks without a block state have been filtered out.
self.block_finalized_count += 1;

Ok(())
}
Expand Down
48 changes: 29 additions & 19 deletions src/tangle/slot_stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ use std::{
};

use futures::{stream::BoxStream, Stream, TryStreamExt};
use iota_sdk::types::block::slot::{SlotCommitment, SlotCommitmentId, SlotIndex};
use iota_sdk::types::{
api::core::BlockState,
block::slot::{SlotCommitment, SlotCommitmentId, SlotIndex},
};

use super::InputSource;
use crate::model::{
Expand Down Expand Up @@ -43,25 +46,32 @@ impl<'a, I: InputSource> Slot<'a, I> {
pub async fn accepted_block_stream(
&self,
) -> Result<impl Stream<Item = Result<BlockWithTransactionMetadata, I::Error>> + '_, I::Error> {
Ok(self.source.accepted_blocks(self.index()).await?.and_then(|res| async {
let transaction = if let Some(transaction_id) = res
.block
.inner()
.body()
.as_basic_opt()
.and_then(|body| body.payload())
.and_then(|p| p.as_signed_transaction_opt())
.map(|txn| txn.transaction().id())
{
Some(self.source.transaction_metadata(transaction_id).await?)
} else {
None
};
Ok(BlockWithTransactionMetadata {
transaction,
block: res,
Ok(self
.source
.accepted_blocks(self.index())
.await?
.try_filter(|block_with_metadata| {
futures::future::ready(block_with_metadata.metadata.block_state == Some(BlockState::Finalized))
})
}))
.and_then(|res| async {
let transaction = if let Some(transaction_id) = res
.block
.inner()
.body()
.as_basic_opt()
.and_then(|body| body.payload())
.and_then(|p| p.as_signed_transaction_opt())
.map(|txn| txn.transaction().id())
{
Some(self.source.transaction_metadata(transaction_id).await?)
} else {
None
};
Ok(BlockWithTransactionMetadata {
transaction,
block: res,
})
}))
}

/// Returns the ledger update store.
Expand Down

0 comments on commit 18b69fd

Please sign in to comment.