-
Notifications
You must be signed in to change notification settings - Fork 38
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
Add support for on-chain notes to block-producer
#303
Conversation
+ add dabase to gitignore
@hackaugusto as we discussed note and tx validation together a few days ago I have the feeling that it is a full other PR in of itself. Should we open another issue to address that thoroughly? |
@bobbinth Indeed I wasn't fully getting the extent of the trouble we could get into when using the Miden client as a dep for faucet or end-to-end testing. Here is an example where not having a dep on the client to send ProvenTransactions to the Block-Producer for testing could be very useful. That should be something to address: #291 |
let created_notes: Vec<NoteCreated> = txs | ||
.iter() | ||
.flat_map(|tx| { | ||
tx.output_notes().iter().map(|note| { | ||
if let Some(note_with_details) = tx.get_output_note_details(¬e.note_id()) | ||
{ | ||
NoteCreated { | ||
batch_index: 0, | ||
note_index: 0, | ||
note_id: Some(note.note_id().into()), | ||
sender: Some(note.metadata().sender().into()), | ||
tag: note.metadata().tag().into(), | ||
details: Some(note_with_details.to_bytes()), | ||
} | ||
} else { | ||
NoteCreated { | ||
batch_index: 0, | ||
note_index: 0, | ||
note_id: Some(note.note_id().into()), | ||
sender: Some(note.metadata().sender().into()), | ||
tag: note.metadata().tag().into(), | ||
details: None, | ||
} | ||
} | ||
}) | ||
}) | ||
.collect(); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will likely have to change after 0xPolygonMiden/miden-base#572. Maybe it's best to point at that branch for now to not have to redo this soonish.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This implementation missing note_index
field within the batch.
I would write something like this:
let created_notes: Vec<NoteCreated> = txs
.iter()
.flat_map(|tx| {
tx.output_notes().iter().map(|note| {
(note, tx.get_output_note_details(¬e.note_id())
})
})
.enumerate()
.map(|(note_index, (note, details))| NoteCreated {
batch_index: 0,
note_index: note_index as u32,
note_id: Some(note.note_id().into()),
sender: Some(note.metadata().sender().into()),
tag: note.metadata().tag().into(),
details: details.map(Note::to_bytes),
})
.collect();
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the heads up, fixed the implementation.
Nice, only this is remaining, I suppose? |
Yes exactly, rebasing atm. |
This PR has been rebased on continued here: #310 |
@@ -26,9 +27,10 @@ pub struct TransactionBatch { | |||
id: BatchId, | |||
updated_accounts: BTreeMap<AccountId, AccountStates>, | |||
produced_nullifiers: Vec<Nullifier>, | |||
created_notes_smt: BatchNoteTree, | |||
/// The notes stored `created_notes_smt` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems this comment is not in the right place now. And I think, it is confusing a bit, maybe it would be better to get rid of this comment at all?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That is also what I thought, I did not know if I had to remove it.
Removed.
let created_notes: Vec<NoteCreated> = txs | ||
.iter() | ||
.flat_map(|tx| { | ||
tx.output_notes().iter().map(|note| { | ||
if let Some(note_with_details) = tx.get_output_note_details(¬e.note_id()) | ||
{ | ||
NoteCreated { | ||
batch_index: 0, | ||
note_index: 0, | ||
note_id: Some(note.note_id().into()), | ||
sender: Some(note.metadata().sender().into()), | ||
tag: note.metadata().tag().into(), | ||
details: Some(note_with_details.to_bytes()), | ||
} | ||
} else { | ||
NoteCreated { | ||
batch_index: 0, | ||
note_index: 0, | ||
note_id: Some(note.note_id().into()), | ||
sender: Some(note.metadata().sender().into()), | ||
tag: note.metadata().tag().into(), | ||
details: None, | ||
} | ||
} | ||
}) | ||
}) | ||
.collect(); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This implementation missing note_index
field within the batch.
I would write something like this:
let created_notes: Vec<NoteCreated> = txs
.iter()
.flat_map(|tx| {
tx.output_notes().iter().map(|note| {
(note, tx.get_output_note_details(¬e.note_id())
})
})
.enumerate()
.map(|(note_index, (note, details))| NoteCreated {
batch_index: 0,
note_index: note_index as u32,
note_id: Some(note.note_id().into()),
sender: Some(note.metadata().sender().into()),
tag: note.metadata().tag().into(),
details: details.map(Note::to_bytes),
})
.collect();
created_notes: Vec<NoteEnvelope>, | ||
created_notes_smt: BatchNoteTree, | ||
created_notes: Vec<NoteCreated>, | ||
created_note_envelopes: Vec<NoteEnvelope>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need these envelopes anywhere else?
@@ -79,14 +80,13 @@ where | |||
|
|||
let updated_accounts: Vec<_> = | |||
batches.iter().flat_map(TransactionBatch::updated_accounts).collect(); | |||
let created_notes = batches | |||
let created_notes: Vec<(usize, usize, NoteCreated)> = batches |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't need these two additional usize
s, because we already have batch_index
and note_index
fields in NoteCreated
structure. The task is to fill them here. I would probably set note_index
in the batch builder (as in my proposed piece of code) and batch_index
here.
I think, the best solution would be to not to create NoteCreated
in the batch builder, but just to add serialized details field in the TransactionBatch::created_note_envelopes
vector:
created_note_envelopes_with_details: Vec<(NoteEnvelope, Option<Vec<u8>>)>,
And after that we would be able to produce NoteCreated
here and init its batch_index
and note_index
fields during creation.
@@ -19,7 +19,7 @@ use crate::store::BlockInputsError; | |||
pub struct Block { | |||
pub header: BlockHeader, | |||
pub updated_accounts: Vec<UpdatedAccount>, | |||
pub created_notes: Vec<(usize, usize, NoteEnvelope)>, | |||
pub created_notes: Vec<(usize, usize, NoteCreated)>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we put NoteCreated
here, we don't need to provide additionally batch_index
and note_index
here.
@@ -20,14 +18,15 @@ impl From<note::Note> for note::NoteSyncRecord { | |||
// NoteCreated | |||
// ================================================================================================ | |||
|
|||
impl From<(usize, usize, NoteEnvelope)> for note::NoteCreated { | |||
fn from((batch_idx, note_idx, note): (usize, usize, NoteEnvelope)) -> Self { | |||
impl From<(usize, usize, NoteCreated)> for note::NoteCreated { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure we need such conversion.
@@ -24,6 +24,7 @@ pub static MIGRATIONS: Lazy<Migrations> = Lazy::new(|| { | |||
sender INTEGER NOT NULL, | |||
tag INTEGER NOT NULL, | |||
merkle_path BLOB NOT NULL, | |||
details BLOB NOT NULL, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please, consider making details
nullable.
In this PR I propose to update the block-proposer to enable addition of on-chain notes to the
store
throughapply_block
apiCloses: #141