miden_client/sync/
state_sync_update.rs

1use alloc::vec::Vec;
2
3use miden_objects::{
4    Digest,
5    account::Account,
6    block::BlockHeader,
7    crypto::merkle::{InOrderIndex, MmrPeaks},
8};
9
10use super::{NoteTagRecord, SyncSummary};
11use crate::{note::NoteUpdates, store::AccountUpdates, transaction::TransactionUpdates};
12
13// STATE SYNC UPDATE
14// ================================================================================================
15
16/// Contains all information needed to apply the update in the store after syncing with the node.
17pub struct StateSyncUpdate {
18    /// The new block header, returned as part of the
19    /// [`StateSyncInfo`](crate::rpc::domain::sync::StateSyncInfo)
20    pub block_header: BlockHeader,
21    /// Whether the block header has notes relevant to the client.
22    pub block_has_relevant_notes: bool,
23    /// New MMR peaks for the locally tracked MMR of the blockchain.
24    pub new_mmr_peaks: MmrPeaks,
25    /// New authentications nodes that are meant to be stored in order to authenticate block
26    /// headers.
27    pub new_authentication_nodes: Vec<(InOrderIndex, Digest)>,
28    /// New and updated notes to be upserted in the store.
29    pub note_updates: NoteUpdates,
30    /// Committed and discarded transactions after the sync.
31    pub transaction_updates: TransactionUpdates,
32    /// Public account updates and mismatched private accounts after the sync.
33    pub account_updates: AccountUpdates,
34    /// Tag records that are no longer relevant.
35    pub tags_to_remove: Vec<NoteTagRecord>,
36}
37
38impl From<&StateSyncUpdate> for SyncSummary {
39    fn from(value: &StateSyncUpdate) -> Self {
40        SyncSummary::new(
41            value.block_header.block_num(),
42            value.note_updates.committed_note_ids().into_iter().collect(),
43            value.note_updates.consumed_note_ids().into_iter().collect(),
44            value
45                .account_updates
46                .updated_public_accounts()
47                .iter()
48                .map(Account::id)
49                .collect(),
50            value
51                .account_updates
52                .mismatched_private_accounts()
53                .iter()
54                .map(|(id, _)| *id)
55                .collect(),
56            value
57                .transaction_updates
58                .committed_transactions()
59                .iter()
60                .map(|t| t.transaction_id)
61                .collect(),
62        )
63    }
64}