1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
use miden_protocol::account::AccountId;
use miden_protocol::account::delta::AccountUpdateDetails;
use miden_protocol::block::{BlockHeader, SignedBlock};
use miden_protocol::note::Nullifier;
use miden_protocol::transaction::{OutputNote, TransactionId};
use miden_standards::note::AccountTargetNetworkNote;
/// Network-relevant state extracted from a committed [`SignedBlock`].
///
/// Produced once per committed block on the ntx-builder side. Downstream code (DB layer,
/// coordinator) applies the contained effects to local state.
#[derive(Debug, Clone)]
pub struct CommittedBlockEffects {
pub header: BlockHeader,
pub network_notes: Vec<AccountTargetNetworkNote>,
pub nullifiers: Vec<Nullifier>,
pub network_account_updates: Vec<(AccountId, AccountUpdateDetails)>,
/// Transaction id paired with the account it updated, for every transaction in the block.
/// `apply_committed_block` uses this to record the latest landed transaction per network
/// account so actors can confirm their own submitted transaction landed.
pub account_transactions: Vec<(AccountId, TransactionId)>,
}
impl CommittedBlockEffects {
/// Filters the committed block down to the slice the ntx-builder cares about: public network
/// notes, network-account updates, and all created nullifiers.
///
/// Private output notes cannot be network notes (which must be public) and are skipped. Non-
/// network output notes and non-network account updates are also dropped.
pub fn from_signed_block(block: &SignedBlock) -> Self {
let header = block.header().clone();
let body = block.body();
let mut network_notes = Vec::new();
for batch in body.output_note_batches() {
for (_idx, output_note) in batch {
if let OutputNote::Public(public) = output_note
&& let Ok(network_note) =
AccountTargetNetworkNote::new(public.as_note().clone())
{
network_notes.push(network_note);
}
}
}
let nullifiers = body.created_nullifiers().to_vec();
// Public accounts are a superset of network accounts; `apply_committed_block` does the
// final network-only filtering via `NetworkAccountEffect::from_protocol` (full-state
// storage check) and a DB lookup for partial deltas.
let network_account_updates = body
.updated_accounts()
.iter()
.filter_map(|update| {
let account_id = update.account_id();
if !account_id.is_public() {
return None;
}
Some((account_id, update.details().clone()))
})
.collect();
let account_transactions = body
.transactions()
.as_slice()
.iter()
.map(|tx| (tx.account_id(), tx.id()))
.collect();
Self {
header,
network_notes,
nullifiers,
network_account_updates,
account_transactions,
}
}
}