Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,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

Expand Down
2 changes: 1 addition & 1 deletion bin/stress-test/src/store/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<Vec<proto::note::NoteId>>();

// Get the notes nullifiers, limiting to 20 notes maximum
Expand Down
45 changes: 45 additions & 0 deletions crates/proto/src/domain/note.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -44,6 +46,49 @@ impl TryFrom<proto::note::NoteType> for NoteType {
}
}

// NOTE ATTACHMENT KIND
// ================================================================================================

impl From<NoteAttachmentKind> 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<proto::note::NoteAttachmentKind> for NoteAttachmentKind {
type Error = ConversionError;

fn try_from(kind: proto::note::NoteAttachmentKind) -> Result<Self, Self::Error> {
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<NoteMetadataHeader> 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
// ================================================================================================

Expand Down
31 changes: 15 additions & 16 deletions crates/store/src/db/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,17 +197,14 @@ impl From<NoteRecord> for proto::note::CommittedNote {

impl From<NoteRecord> 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),
}
let metadata_header = Some(value.metadata.to_header().into());
let inclusion_proof = Some(proto::note::NoteInclusionInBlockProof {
note_id: Some(value.note_id.into()),
block_num: value.block_num.as_u32(),
note_index_in_block: value.note_index.leaf_index_value().into(),
inclusion_path: Some(value.inclusion_path.into()),
});
Self { metadata_header, inclusion_proof }
}
}

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

impl From<NoteSyncRecord> 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 }
}
}

Expand Down
54 changes: 43 additions & 11 deletions proto/proto/types/note.proto
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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.
Expand Down Expand Up @@ -105,19 +140,16 @@ 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.
Expand Down
Loading