Skip to content

Commit facb2c5

Browse files
refactor: use NoteMetadataHeader in sync notes
1 parent 58c07c9 commit facb2c5

5 files changed

Lines changed: 105 additions & 28 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
### Changes
2424

25+
- [BREAKING] Refactored `NoteSyncRecord` to returned a fixed-size `NoteMetadataHeader` ([#1720](https://github.com/0xMiden/node/issues/1720)).
2526
- [BREAKING] Removed obsolete `SyncState` RPC endpoint; clients should use `SyncNotes`, `SyncNullifiers`, `SyncAccountVault`, `SyncAccountStorageMaps`, `SyncTransactions`, or `SyncChainMmr` instead ([#1636](https://github.com/0xMiden/node/pull/1636)).
2627
- Added account ID limits for `SyncTransactions`, `SyncAccountVault`, and `SyncAccountStorageMaps` to `GetLimits` responses ([#1636](https://github.com/0xMiden/node/pull/1636)).
2728
- [BREAKING] Added typed `GetAccountError` for `GetAccount` endpoint, splitting `BlockNotAvailable` into `UnknownBlock` and `BlockPruned`. `AccountNotFound` and `AccountNotPublic` now return `InvalidArgument` gRPC status instead of `NotFound`; clients should parse the error details discriminant rather than branching on status codes ([#1646](https://github.com/0xMiden/node/pull/1646)).

‎bin/stress-test/src/store/mod.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ pub async fn bench_sync_nullifiers(
149149
let note_ids = response
150150
.notes
151151
.iter()
152-
.map(|n| n.note_id.unwrap())
152+
.map(|n| n.inclusion_proof.as_ref().unwrap().note_id.unwrap())
153153
.collect::<Vec<proto::note::NoteId>>();
154154

155155
// Get the notes nullifiers, limiting to 20 notes maximum

‎crates/proto/src/domain/note.rs‎

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,13 @@ use miden_protocol::crypto::merkle::SparseMerklePath;
44
use miden_protocol::note::{
55
Note,
66
NoteAttachment,
7+
NoteAttachmentKind,
78
NoteDetails,
89
NoteHeader,
910
NoteId,
1011
NoteInclusionProof,
1112
NoteMetadata,
13+
NoteMetadataHeader,
1214
NoteScript,
1315
NoteTag,
1416
NoteType,
@@ -44,6 +46,49 @@ impl TryFrom<proto::note::NoteType> for NoteType {
4446
}
4547
}
4648

49+
// NOTE ATTACHMENT KIND
50+
// ================================================================================================
51+
52+
impl From<NoteAttachmentKind> for proto::note::NoteAttachmentKind {
53+
fn from(kind: NoteAttachmentKind) -> Self {
54+
match kind {
55+
NoteAttachmentKind::None => proto::note::NoteAttachmentKind::None,
56+
NoteAttachmentKind::Word => proto::note::NoteAttachmentKind::Word,
57+
NoteAttachmentKind::Array => proto::note::NoteAttachmentKind::Array,
58+
}
59+
}
60+
}
61+
62+
impl TryFrom<proto::note::NoteAttachmentKind> for NoteAttachmentKind {
63+
type Error = ConversionError;
64+
65+
fn try_from(kind: proto::note::NoteAttachmentKind) -> Result<Self, Self::Error> {
66+
match kind {
67+
proto::note::NoteAttachmentKind::None => Ok(NoteAttachmentKind::None),
68+
proto::note::NoteAttachmentKind::Word => Ok(NoteAttachmentKind::Word),
69+
proto::note::NoteAttachmentKind::Array => Ok(NoteAttachmentKind::Array),
70+
proto::note::NoteAttachmentKind::Unspecified => {
71+
Err(ConversionError::EnumDiscriminantOutOfRange)
72+
},
73+
}
74+
}
75+
}
76+
77+
// NOTE METADATA HEADER
78+
// ================================================================================================
79+
80+
impl From<NoteMetadataHeader> for proto::note::NoteMetadataHeader {
81+
fn from(header: NoteMetadataHeader) -> Self {
82+
Self {
83+
sender: Some(header.sender().into()),
84+
note_type: proto::note::NoteType::from(header.note_type()) as i32,
85+
tag: header.tag().as_u32(),
86+
attachment_kind: proto::note::NoteAttachmentKind::from(header.attachment_kind()) as i32,
87+
attachment_scheme: header.attachment_scheme().as_u32(),
88+
}
89+
}
90+
}
91+
4792
// NOTE METADATA
4893
// ================================================================================================
4994

‎crates/store/src/db/mod.rs‎

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -197,17 +197,14 @@ impl From<NoteRecord> for proto::note::CommittedNote {
197197

198198
impl From<NoteRecord> for proto::note::NoteSyncRecord {
199199
fn from(value: NoteRecord) -> Self {
200-
let note_id = value.note_id.into();
201-
let note_index_in_block = value.note_index.leaf_index_value().into();
202-
let metadata = value.metadata.into();
203-
let inclusion_path = value.inclusion_path.into();
204-
205-
proto::note::NoteSyncRecord {
206-
note_id: Some(note_id),
207-
note_index_in_block,
208-
metadata: Some(metadata),
209-
inclusion_path: Some(inclusion_path),
210-
}
200+
let metadata_header = Some(value.metadata.to_header().into());
201+
let inclusion_proof = Some(proto::note::NoteInclusionInBlockProof {
202+
note_id: Some(value.note_id.into()),
203+
block_num: value.block_num.as_u32(),
204+
note_index_in_block: value.note_index.leaf_index_value().into(),
205+
inclusion_path: Some(value.inclusion_path.into()),
206+
});
207+
Self { metadata_header, inclusion_proof }
211208
}
212209
}
213210

@@ -228,12 +225,14 @@ pub struct NoteSyncRecord {
228225

229226
impl From<NoteSyncRecord> for proto::note::NoteSyncRecord {
230227
fn from(note: NoteSyncRecord) -> Self {
231-
Self {
232-
note_index_in_block: note.note_index.leaf_index_value().into(),
228+
let metadata_header = Some(note.metadata.to_header().into());
229+
let inclusion_proof = Some(proto::note::NoteInclusionInBlockProof {
233230
note_id: Some(note.note_id.into()),
234-
metadata: Some(note.metadata.into()),
235-
inclusion_path: Some(Into::into(note.inclusion_path)),
236-
}
231+
block_num: note.block_num.as_u32(),
232+
note_index_in_block: note.note_index.leaf_index_value().into(),
233+
inclusion_path: Some(note.inclusion_path.into()),
234+
});
235+
Self { metadata_header, inclusion_proof }
237236
}
238237
}
239238

‎proto/proto/types/note.proto‎

Lines changed: 43 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,18 @@ enum NoteType {
1717
NOTE_TYPE_PRIVATE = 2;
1818
}
1919

20+
// The kind of a note attachment.
21+
enum NoteAttachmentKind {
22+
// Unspecified attachment kind (default value, should not be used).
23+
NOTE_ATTACHMENT_KIND_UNSPECIFIED = 0;
24+
// No attachment.
25+
NOTE_ATTACHMENT_KIND_NONE = 1;
26+
// A single word attachment.
27+
NOTE_ATTACHMENT_KIND_WORD = 2;
28+
// An array attachment.
29+
NOTE_ATTACHMENT_KIND_ARRAY = 3;
30+
}
31+
2032
// Represents a note's ID.
2133
message NoteId {
2234
// A unique identifier of the note which is a 32-byte commitment to the underlying note data.
@@ -29,6 +41,29 @@ message NoteIdList {
2941
repeated NoteId ids = 1;
3042
}
3143

44+
// Represents the header of a note's metadata.
45+
//
46+
// Contains the sender, note type, tag and attachment type information, but not the full
47+
// attachment data. See `miden_protocol::note::NoteMetadataHeader` for more info.
48+
message NoteMetadataHeader {
49+
// The account which sent the note.
50+
account.AccountId sender = 1;
51+
52+
// The type of the note.
53+
NoteType note_type = 2;
54+
55+
// A value which can be used by the recipient to identify notes intended for them.
56+
//
57+
// See `miden_protocol::note::note_tag` for more info.
58+
fixed32 tag = 3;
59+
60+
// The kind of the note attachment.
61+
NoteAttachmentKind attachment_kind = 4;
62+
63+
// The scheme identifier of the note attachment.
64+
fixed32 attachment_scheme = 5;
65+
}
66+
3267
// Represents a note's metadata.
3368
message NoteMetadata {
3469
// The account which sent the note.
@@ -105,19 +140,16 @@ message NoteInclusionInBlockProof {
105140
primitives.SparseMerklePath inclusion_path = 4;
106141
}
107142

108-
// Represents proof of a note inclusion in the block.
143+
// Represents a note's metadata header together with proof of inclusion in a block.
144+
//
145+
// To get the full `NoteMetadata` (including
146+
// attachment), use `GetNotesById`.
109147
message NoteSyncRecord {
110-
// A unique identifier of the note which is a 32-byte commitment to the underlying note data.
111-
NoteId note_id = 1;
148+
// The fixed-size metadata header of the note.
149+
NoteMetadataHeader metadata_header = 1;
112150

113-
// The index of the note in the block.
114-
uint32 note_index_in_block = 2;
115-
116-
// The note's metadata.
117-
NoteMetadata metadata = 3;
118-
119-
// The note's inclusion proof in the block.
120-
primitives.SparseMerklePath inclusion_path = 4;
151+
// Proof of the note's inclusion in a block.
152+
NoteInclusionInBlockProof inclusion_proof = 2;
121153
}
122154

123155
// Represents a note header.

0 commit comments

Comments
 (0)