Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure transactions are finalized so outputs are available in the ledger update store #1381

Merged
merged 2 commits into from
Apr 23, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
89 changes: 47 additions & 42 deletions src/analytics/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,15 @@
//! Various analytics that give insight into the usage of the tangle.

use futures::{prelude::stream::StreamExt, TryStreamExt};
use iota_sdk::types::block::{
output::OutputId,
payload::SignedTransactionPayload,
protocol::ProtocolParameters,
slot::{EpochIndex, SlotCommitment, SlotIndex},
Block,
use iota_sdk::types::{
api::core::TransactionState,
block::{
output::OutputId,
payload::SignedTransactionPayload,
protocol::ProtocolParameters,
slot::{EpochIndex, SlotCommitment, SlotIndex},
Block,
},
};
use thiserror::Error;

Expand Down Expand Up @@ -343,42 +346,44 @@ impl<'a, I: InputSource> Slot<'a, I> {
metadata: &TransactionMetadata,
ctx: &BasicContext<'_>,
) -> eyre::Result<()> {
let consumed = payload
.transaction()
.inputs()
.iter()
.map(|input| input.as_utxo().output_id())
.map(|output_id| {
Ok(self
.ledger_updates()
.get_consumed(output_id)
.ok_or(AnalyticsError::MissingLedgerSpent {
output_id: *output_id,
slot_index: metadata.transaction_id.slot_index(),
})?
.clone())
})
.collect::<eyre::Result<Vec<_>>>()?;
let created = payload
.transaction()
.outputs()
.iter()
.enumerate()
.map(|(index, _)| {
let output_id = metadata.transaction_id.into_output_id(index as _);
Ok(self
.ledger_updates()
.get_created(&output_id)
.ok_or(AnalyticsError::MissingLedgerOutput {
output_id,
slot_index: metadata.transaction_id.slot_index(),
})?
.clone())
})
.collect::<eyre::Result<Vec<_>>>()?;
analytics
.handle_transaction(payload, metadata, &consumed, &created, ctx)
.await?;
if let Some(TransactionState::Finalized) = metadata.transaction_state {
Alex6323 marked this conversation as resolved.
Show resolved Hide resolved
let consumed = payload
.transaction()
.inputs()
.iter()
.map(|input| input.as_utxo().output_id())
.map(|output_id| {
Ok(self
.ledger_updates()
.get_consumed(output_id)
.ok_or(AnalyticsError::MissingLedgerSpent {
output_id: *output_id,
slot_index: metadata.transaction_id.slot_index(),
})?
.clone())
})
.collect::<eyre::Result<Vec<_>>>()?;
let created = payload
.transaction()
.outputs()
.iter()
.enumerate()
.map(|(index, _)| {
let output_id = metadata.transaction_id.into_output_id(index as _);
Ok(self
.ledger_updates()
.get_created(&output_id)
.ok_or(AnalyticsError::MissingLedgerOutput {
output_id,
slot_index: metadata.transaction_id.slot_index(),
})?
.clone())
})
.collect::<eyre::Result<Vec<_>>>()?;
analytics
.handle_transaction(payload, metadata, &consumed, &created, ctx)
.await?;
}
Ok(())
}

Expand Down
Loading