calimero_node_primitives/
sync.rs

1#![expect(single_use_lifetimes, reason = "borsh shenanigans")]
2
3use std::borrow::Cow;
4use std::num::NonZeroUsize;
5
6use borsh::{BorshDeserialize, BorshSerialize};
7use calimero_crypto::Nonce;
8use calimero_primitives::application::ApplicationId;
9use calimero_primitives::blobs::BlobId;
10use calimero_primitives::context::ContextId;
11use calimero_primitives::hash::Hash;
12use calimero_primitives::identity::{PrivateKey, PublicKey};
13
14#[derive(Debug, BorshSerialize, BorshDeserialize)]
15#[non_exhaustive]
16#[expect(clippy::large_enum_variant, reason = "Of no consequence here")]
17pub enum BroadcastMessage<'a> {
18    StateDelta {
19        context_id: ContextId,
20        author_id: PublicKey,
21        root_hash: Hash, // todo! shouldn't be cleartext
22        artifact: Cow<'a, [u8]>,
23        height: NonZeroUsize, // todo! shouldn't be cleartext
24        nonce: Nonce,
25    },
26}
27
28#[derive(Debug, BorshSerialize, BorshDeserialize)]
29pub enum StreamMessage<'a> {
30    Init {
31        context_id: ContextId,
32        party_id: PublicKey,
33        payload: InitPayload,
34        next_nonce: Nonce,
35    },
36    Message {
37        sequence_id: usize,
38        payload: MessagePayload<'a>,
39        next_nonce: Nonce,
40    },
41    /// Other peers must not learn anything about the node's state if anything goes wrong.
42    OpaqueError,
43}
44
45#[derive(Copy, Clone, Debug, BorshSerialize, BorshDeserialize)]
46pub enum InitPayload {
47    BlobShare {
48        blob_id: BlobId,
49    },
50    StateSync {
51        root_hash: Hash,
52        application_id: ApplicationId,
53    },
54    KeyShare,
55    DeltaSync {
56        root_hash: Hash,
57        application_id: ApplicationId,
58    },
59}
60
61#[derive(Debug, BorshSerialize, BorshDeserialize)]
62pub enum MessagePayload<'a> {
63    StateSync {
64        artifact: Cow<'a, [u8]>,
65    },
66    BlobShare {
67        chunk: Cow<'a, [u8]>,
68    },
69    KeyShare {
70        sender_key: PrivateKey,
71    },
72    DeltaSync {
73        member: PublicKey,
74        height: NonZeroUsize,
75        delta: Option<Cow<'a, [u8]>>,
76    },
77}