diff --git a/crates/block-producer/src/domain/batch.rs b/crates/block-producer/src/domain/batch.rs index 9c3cbb7e1..ca739b796 100644 --- a/crates/block-producer/src/domain/batch.rs +++ b/crates/block-producer/src/domain/batch.rs @@ -1,4 +1,4 @@ -use std::collections::HashMap; +use std::collections::{HashMap, HashSet}; use std::sync::Arc; use miden_protocol::Word; @@ -23,6 +23,7 @@ pub(crate) struct SelectedBatch { txs: Vec>, id: BatchId, account_updates: HashMap)>, + unauthenticated_notes: HashSet, } impl SelectedBatch { @@ -55,6 +56,10 @@ impl SelectedBatch { .map(|(account, (from, to, store))| (*account, *from, *to, *store)) } + pub(crate) fn unauthenticated_note_commitments(&self) -> impl Iterator { + self.unauthenticated_notes.iter().copied() + } + pub(crate) fn expires_at(&self) -> BlockNumber { self.txs .iter() @@ -116,6 +121,18 @@ not match the current commitment {}", let Self { txs, account_updates } = self; let id = BatchId::from_ids(txs.iter().map(|tx| (tx.id(), tx.account_id()))); - SelectedBatch { txs, id, account_updates } + let mut unauthenticated_notes: HashSet<_> = + txs.iter().flat_map(|tx| tx.unauthenticated_note_commitments()).collect(); + + for output_note in txs.iter().flat_map(|tx| tx.output_note_commitments()) { + unauthenticated_notes.remove(&output_note); + } + + SelectedBatch { + txs, + id, + account_updates, + unauthenticated_notes, + } } } diff --git a/crates/block-producer/src/mempool/graph/batch.rs b/crates/block-producer/src/mempool/graph/batch.rs index e46cb6e56..a3200de16 100644 --- a/crates/block-producer/src/mempool/graph/batch.rs +++ b/crates/block-producer/src/mempool/graph/batch.rs @@ -1,4 +1,4 @@ -use std::collections::{HashMap, HashSet}; +use std::collections::HashMap; use std::sync::Arc; use miden_protocol::Word; @@ -29,14 +29,7 @@ impl GraphNode for SelectedBatch { } fn unauthenticated_notes(&self) -> Box + '_> { - // Filter notes that are produced within this batch. - let output_notes: HashSet = self.output_notes().collect(); - Box::new( - self.transactions() - .iter() - .flat_map(|tx| tx.unauthenticated_note_commitments()) - .filter(move |note| !output_notes.contains(note)), - ) + Box::new(self.unauthenticated_note_commitments()) } fn account_updates(