diff --git a/CHANGELOG.md b/CHANGELOG.md index ce1470f63..84b1105c1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -42,6 +42,7 @@ - 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)). - Removed gRPC reflection v1-alpha support ([#1795](https://github.com/0xMiden/node/pull/1795)). - [BREAKING] Rust requirement bumped from `v1.91` to `v1.93` ([#1803](https://github.com/0xMiden/node/pull/1803)). +- [BREAKING] Refactored `NoteSyncRecord` to returned a fixed-size `NoteMetadataHeader` ([#1837](https://github.com/0xMiden/node/pull/1837)). ### Fixes diff --git a/bin/stress-test/src/store/mod.rs b/bin/stress-test/src/store/mod.rs index a9f1491fe..bb2d9b477 100644 --- a/bin/stress-test/src/store/mod.rs +++ b/bin/stress-test/src/store/mod.rs @@ -149,7 +149,7 @@ pub async fn bench_sync_nullifiers( let note_ids = response .notes .iter() - .map(|n| n.note_id.unwrap()) + .map(|n| n.inclusion_proof.as_ref().unwrap().note_id.unwrap()) .collect::>(); // Get the notes nullifiers, limiting to 20 notes maximum diff --git a/crates/proto/src/domain/note.rs b/crates/proto/src/domain/note.rs index 7fbe698ff..def699748 100644 --- a/crates/proto/src/domain/note.rs +++ b/crates/proto/src/domain/note.rs @@ -4,11 +4,13 @@ use miden_protocol::crypto::merkle::SparseMerklePath; use miden_protocol::note::{ Note, NoteAttachment, + NoteAttachmentKind, NoteDetails, NoteHeader, NoteId, NoteInclusionProof, NoteMetadata, + NoteMetadataHeader, NoteScript, NoteTag, NoteType, @@ -44,6 +46,49 @@ impl TryFrom for NoteType { } } +// NOTE ATTACHMENT KIND +// ================================================================================================ + +impl From for proto::note::NoteAttachmentKind { + fn from(kind: NoteAttachmentKind) -> Self { + match kind { + NoteAttachmentKind::None => proto::note::NoteAttachmentKind::None, + NoteAttachmentKind::Word => proto::note::NoteAttachmentKind::Word, + NoteAttachmentKind::Array => proto::note::NoteAttachmentKind::Array, + } + } +} + +impl TryFrom for NoteAttachmentKind { + type Error = ConversionError; + + fn try_from(kind: proto::note::NoteAttachmentKind) -> Result { + match kind { + proto::note::NoteAttachmentKind::None => Ok(NoteAttachmentKind::None), + proto::note::NoteAttachmentKind::Word => Ok(NoteAttachmentKind::Word), + proto::note::NoteAttachmentKind::Array => Ok(NoteAttachmentKind::Array), + proto::note::NoteAttachmentKind::Unspecified => { + Err(ConversionError::EnumDiscriminantOutOfRange) + }, + } + } +} + +// NOTE METADATA HEADER +// ================================================================================================ + +impl From for proto::note::NoteMetadataHeader { + fn from(header: NoteMetadataHeader) -> Self { + Self { + sender: Some(header.sender().into()), + note_type: proto::note::NoteType::from(header.note_type()) as i32, + tag: header.tag().as_u32(), + attachment_kind: proto::note::NoteAttachmentKind::from(header.attachment_kind()) as i32, + attachment_scheme: header.attachment_scheme().as_u32(), + } + } +} + // NOTE METADATA // ================================================================================================ diff --git a/crates/store/src/db/mod.rs b/crates/store/src/db/mod.rs index 6fb5fd35c..2e2f32949 100644 --- a/crates/store/src/db/mod.rs +++ b/crates/store/src/db/mod.rs @@ -195,22 +195,6 @@ impl From for proto::note::CommittedNote { } } -impl From for proto::note::NoteSyncRecord { - fn from(value: NoteRecord) -> Self { - let note_id = value.note_id.into(); - let note_index_in_block = value.note_index.leaf_index_value().into(); - let metadata = value.metadata.into(); - let inclusion_path = value.inclusion_path.into(); - - proto::note::NoteSyncRecord { - note_id: Some(note_id), - note_index_in_block, - metadata: Some(metadata), - inclusion_path: Some(inclusion_path), - } - } -} - #[derive(Debug, PartialEq)] pub struct NoteSyncUpdate { pub notes: Vec, @@ -228,12 +212,14 @@ pub struct NoteSyncRecord { impl From for proto::note::NoteSyncRecord { fn from(note: NoteSyncRecord) -> Self { - Self { - note_index_in_block: note.note_index.leaf_index_value().into(), + let metadata_header = Some(note.metadata.to_header().into()); + let inclusion_proof = Some(proto::note::NoteInclusionInBlockProof { note_id: Some(note.note_id.into()), - metadata: Some(note.metadata.into()), - inclusion_path: Some(Into::into(note.inclusion_path)), - } + block_num: note.block_num.as_u32(), + note_index_in_block: note.note_index.leaf_index_value().into(), + inclusion_path: Some(note.inclusion_path.into()), + }); + Self { metadata_header, inclusion_proof } } } diff --git a/proto/proto/types/note.proto b/proto/proto/types/note.proto index a17a9c0a4..8b365b152 100644 --- a/proto/proto/types/note.proto +++ b/proto/proto/types/note.proto @@ -17,6 +17,18 @@ enum NoteType { NOTE_TYPE_PRIVATE = 2; } +// The kind of a note attachment. +enum NoteAttachmentKind { + // Unspecified attachment kind (default value, should not be used). + NOTE_ATTACHMENT_KIND_UNSPECIFIED = 0; + // No attachment. + NOTE_ATTACHMENT_KIND_NONE = 1; + // A single word attachment. + NOTE_ATTACHMENT_KIND_WORD = 2; + // An array attachment. + NOTE_ATTACHMENT_KIND_ARRAY = 3; +} + // Represents a note's ID. message NoteId { // A unique identifier of the note which is a 32-byte commitment to the underlying note data. @@ -29,6 +41,29 @@ message NoteIdList { repeated NoteId ids = 1; } +// Represents the header of a note's metadata. +// +// Contains the sender, note type, tag and attachment type information, but not the full +// attachment data. See `miden_protocol::note::NoteMetadataHeader` for more info. +message NoteMetadataHeader { + // The account which sent the note. + account.AccountId sender = 1; + + // The type of the note. + NoteType note_type = 2; + + // A value which can be used by the recipient to identify notes intended for them. + // + // See `miden_protocol::note::note_tag` for more info. + fixed32 tag = 3; + + // The kind of the note attachment. + NoteAttachmentKind attachment_kind = 4; + + // The scheme identifier of the note attachment. + fixed32 attachment_scheme = 5; +} + // Represents a note's metadata. message NoteMetadata { // The account which sent the note. @@ -105,19 +140,15 @@ message NoteInclusionInBlockProof { primitives.SparseMerklePath inclusion_path = 4; } -// Represents proof of a note inclusion in the block. +// Represents a note's metadata header together with proof of inclusion in a block. +// +// To get the full `NoteMetadata` (including attachment), use `GetNotesById`. message NoteSyncRecord { - // A unique identifier of the note which is a 32-byte commitment to the underlying note data. - NoteId note_id = 1; + // The fixed-size metadata header of the note. + NoteMetadataHeader metadata_header = 1; - // The index of the note in the block. - uint32 note_index_in_block = 2; - - // The note's metadata. - NoteMetadata metadata = 3; - - // The note's inclusion proof in the block. - primitives.SparseMerklePath inclusion_path = 4; + // Proof of the note's inclusion in a block. + NoteInclusionInBlockProof inclusion_proof = 2; } // Represents a note header.