Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add note execution_hint to store #441

Merged
merged 13 commits into from
Aug 13, 2024
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
- Support multiple inflight transactions on the same account (#407).
- Added `SyncNotes` endpoint (#424).
- Cache sql statements (#427).
- Added `execution_hint` field to `Notes` table.

### Fixes

Expand Down
80 changes: 48 additions & 32 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 8 additions & 1 deletion bin/faucet/src/handlers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,14 @@ pub async fn get_tokens(
.expect("failed to build note tag for local execution");

// Serialize note into bytes
let bytes = NoteFile::NoteDetails(note_details, Some(note_tag)).to_bytes();
// NOTE: Because this client does not sync, it always effectively executes against block 0.
// Ideally, we should export these note details with a more sensible `after_block_num`
let bytes = NoteFile::NoteDetails {
details: note_details,
after_block_num: 0,
tag: Some(note_tag),
}
.to_bytes();

info!("A new note has been created: {}", note_id);

Expand Down
3 changes: 2 additions & 1 deletion crates/block-producer/src/block_builder/prover/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use miden_objects::{
EmptySubtreeRoots, LeafIndex, MerklePath, Mmr, MmrPeaks, SimpleSmt, Smt, SmtLeaf, SmtProof,
SMT_DEPTH,
},
notes::{NoteHeader, NoteMetadata, NoteTag, NoteType},
notes::{NoteExecutionHint, NoteHeader, NoteMetadata, NoteTag, NoteType},
transaction::{OutputNote, ProvenTransaction},
Felt, BLOCK_NOTES_TREE_DEPTH, ONE, ZERO,
};
Expand Down Expand Up @@ -515,6 +515,7 @@ async fn test_compute_note_root_success() {
account_id,
NoteType::Private,
NoteTag::for_local_use_case(0u16, 0u16).unwrap(),
NoteExecutionHint::none(),
ONE,
)
.unwrap(),
Expand Down
12 changes: 9 additions & 3 deletions crates/block-producer/src/test_utils/proven_tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::ops::Range;
use miden_air::HashFunction;
use miden_objects::{
accounts::AccountId,
notes::{Note, NoteHeader, NoteMetadata, NoteType, Nullifier},
notes::{Note, NoteExecutionHint, NoteHeader, NoteMetadata, NoteType, Nullifier},
transaction::{InputNote, OutputNote, ProvenTransaction, ProvenTransactionBuilder},
vm::ExecutionProof,
Digest, Felt, Hasher, ONE,
Expand Down Expand Up @@ -77,8 +77,14 @@ impl MockProvenTxBuilder {
let notes = range
.map(|note_index| {
let note_id = Hasher::hash(&note_index.to_be_bytes());
let note_metadata =
NoteMetadata::new(self.account_id, NoteType::Private, 0.into(), ONE).unwrap();
let note_metadata = NoteMetadata::new(
self.account_id,
NoteType::Private,
0.into(),
NoteExecutionHint::none(),
ONE,
)
.unwrap();

OutputNote::Header(NoteHeader::new(note_id.into(), note_metadata))
})
Expand Down
16 changes: 13 additions & 3 deletions crates/proto/src/domain/notes.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use miden_objects::{
notes::{NoteMetadata, NoteTag, NoteType},
notes::{NoteExecutionHint, NoteMetadata, NoteTag, NoteType},
Felt,
};

Expand All @@ -15,9 +15,12 @@ impl TryFrom<crate::generated::note::NoteMetadata> for NoteMetadata {
.try_into()?;
let note_type = NoteType::try_from(value.note_type as u64)?;
let tag = NoteTag::from(value.tag);

let execution_hint = NoteExecutionHint::try_from(value.execution_hint)?;

let aux = Felt::try_from(value.aux).map_err(|_| ConversionError::NotAValidFelt)?;

Ok(NoteMetadata::new(sender, note_type, tag, aux)?)
Ok(NoteMetadata::new(sender, note_type, tag, execution_hint, aux)?)
}
}

Expand All @@ -26,8 +29,15 @@ impl From<NoteMetadata> for crate::generated::note::NoteMetadata {
let sender = Some(val.sender().into());
let note_type = val.note_type() as u32;
let tag = val.tag().into();
let execution_hint: u64 = val.execution_hint().into();
let aux = val.aux().into();

crate::generated::note::NoteMetadata { sender, note_type, tag, aux }
crate::generated::note::NoteMetadata {
sender,
note_type,
tag,
execution_hint,
aux,
}
}
}
2 changes: 2 additions & 0 deletions crates/proto/src/generated/note.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ pub struct NoteMetadata {
#[prost(fixed32, tag = "3")]
pub tag: u32,
#[prost(fixed64, tag = "4")]
pub execution_hint: u64,
#[prost(fixed64, tag = "5")]
pub aux: u64,
}
#[allow(clippy::derive_partial_eq_without_eq)]
Expand Down
3 changes: 2 additions & 1 deletion crates/rpc-proto/proto/note.proto
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ message NoteMetadata {
account.AccountId sender = 1;
uint32 note_type = 2;
fixed32 tag = 3;
fixed64 aux = 4;
fixed64 execution_hint = 4;
fixed64 aux = 5;
}

message Note {
Expand Down
21 changes: 11 additions & 10 deletions crates/store/src/db/migrations/001-init.sql
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,17 @@ CREATE TABLE
CREATE TABLE
notes
(
block_num INTEGER NOT NULL,
batch_index INTEGER NOT NULL, -- Index of batch in block, starting from 0
note_index INTEGER NOT NULL, -- Index of note in batch, starting from 0
note_id BLOB NOT NULL,
note_type INTEGER NOT NULL, -- 1-Public (0b01), 2-Private (0b10), 3-Encrypted (0b11)
sender INTEGER NOT NULL,
tag INTEGER NOT NULL,
aux INTEGER NOT NULL,
merkle_path BLOB NOT NULL,
details BLOB,
block_num INTEGER NOT NULL,
batch_index INTEGER NOT NULL, -- Index of batch in block, starting from 0
note_index INTEGER NOT NULL, -- Index of note in batch, starting from 0
note_id BLOB NOT NULL,
note_type INTEGER NOT NULL, -- 1-Public (0b01), 2-Private (0b10), 3-Encrypted (0b11)
sender INTEGER NOT NULL,
tag INTEGER NOT NULL,
aux INTEGER NOT NULL,
execution_hint INTEGER NOT NULL,
merkle_path BLOB NOT NULL,
details BLOB,

PRIMARY KEY (block_num, batch_index, note_index),
FOREIGN KEY (block_num) REFERENCES block_headers(block_num),
Expand Down
Loading
Loading