Skip to content

Commit c27bbda

Browse files
refactor(rpc): normalize NoteSyncRecord with NoteMetadataHeader (#1837)
Co-authored-by: Bobbin Threadbare <[email protected]>
1 parent 06f9d6a commit c27bbda

File tree

5 files changed

+96
-33
lines changed

5 files changed

+96
-33
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
- NTX Builder now deactivates network accounts which crash repeatedly (configurable via `--ntx-builder.max-account-crashes`, default 10) ([#1712](https://github.com/0xMiden/miden-node/pull/1712)).
4343
- Removed gRPC reflection v1-alpha support ([#1795](https://github.com/0xMiden/node/pull/1795)).
4444
- [BREAKING] Rust requirement bumped from `v1.91` to `v1.93` ([#1803](https://github.com/0xMiden/node/pull/1803)).
45+
- [BREAKING] Refactored `NoteSyncRecord` to returned a fixed-size `NoteMetadataHeader` ([#1837](https://github.com/0xMiden/node/pull/1837)).
4546

4647
### Fixes
4748

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: 7 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -195,22 +195,6 @@ impl From<NoteRecord> for proto::note::CommittedNote {
195195
}
196196
}
197197

198-
impl From<NoteRecord> for proto::note::NoteSyncRecord {
199-
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-
}
211-
}
212-
}
213-
214198
#[derive(Debug, PartialEq)]
215199
pub struct NoteSyncUpdate {
216200
pub notes: Vec<NoteSyncRecord>,
@@ -228,12 +212,14 @@ pub struct NoteSyncRecord {
228212

229213
impl From<NoteSyncRecord> for proto::note::NoteSyncRecord {
230214
fn from(note: NoteSyncRecord) -> Self {
231-
Self {
232-
note_index_in_block: note.note_index.leaf_index_value().into(),
215+
let metadata_header = Some(note.metadata.to_header().into());
216+
let inclusion_proof = Some(proto::note::NoteInclusionInBlockProof {
233217
note_id: Some(note.note_id.into()),
234-
metadata: Some(note.metadata.into()),
235-
inclusion_path: Some(Into::into(note.inclusion_path)),
236-
}
218+
block_num: note.block_num.as_u32(),
219+
note_index_in_block: note.note_index.leaf_index_value().into(),
220+
inclusion_path: Some(note.inclusion_path.into()),
221+
});
222+
Self { metadata_header, inclusion_proof }
237223
}
238224
}
239225

proto/proto/types/note.proto

Lines changed: 42 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,15 @@ 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 attachment), use `GetNotesById`.
109146
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;
147+
// The fixed-size metadata header of the note.
148+
NoteMetadataHeader metadata_header = 1;
112149

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;
150+
// Proof of the note's inclusion in a block.
151+
NoteInclusionInBlockProof inclusion_proof = 2;
121152
}
122153

123154
// Represents a note header.

0 commit comments

Comments
 (0)