refactor!: new note emission API#16091
Conversation
1932957 to
03ddf58
Compare
nventuro
left a comment
There was a problem hiding this comment.
I would consider renaming OuterNoteEmission to MaybeNoteEmission because OuterNoteEmission is not really descriptive (it being outer feels like an implementation detail and not something you want to communicate to the struct consumer). But devs don't really get exposed to this that much so possibly doesn't matter much.
OptionNoteEmission would be ok, yes. It only exists because none of the Option methods are a good fit - we'd want something like and_then but with no chaining.
noteEmission.discard(...)
I've also noticed that the discard method on the note emission structs is not ever used in our codebase. I feel like notes might be too important to ever be discarded so would revisit whether having the func makes sense.
We could add a discard example I guess. It'd come up in transiento reads, e.g.
let note = priv_mut.get_note().discard(); // discard as it's about to get deleted so no point in emitting anything
priv_mut.replace(Note::new(note + 1)).emit(...);Emitting partial notes as offchain message
None of our partial notes implementations support emission via an offchain message.
Would be good to address this, yes.
fb7c202 to
a6d2ea7
Compare
Refactoring note emission API to use the recently introduced `MessageDelivery` global var. ```diff - note_emission.emit(encode_and_encrypt_note(&mut context, from)); + note_emission.emit(&mut context, from, MessageDelivery.CONSTRAINED_ONCHAIN); ``` ```diff - note_emission.emit(encode_and_encrypt_note_unconstrained(&mut context, from)); + note_emission.emit(&mut context, from, MessageDelivery.UNCONSTRAINED_ONCHAIN); ``` ```diff - note_emission.emit(encode_and_encrypt_note_and_emit_as_offchain_message(&mut context, context.msg_sender()); + note_emission.emit(&mut context, context.msg_sender(), MessageDelivery.UNCONSTRAINED_OFFCHAIN); ``` ## Followup work ### Achieving final imports Would give the highest priority to tackling [this issue](#16771) because the import of `MessageDelivery` affects contract code and we don't want to force devs to do 2 annoying migrations. Plan on tackling that right after this PR is merged. ## Random thoughts that came to my mind while implementing this ### Consider renaming `OuterNoteEmission` I would consider renaming `OuterNoteEmission` to `MaybeNoteEmission` because `OuterNoteEmission` is not really descriptive (it being outer feels like an implementation detail and not something you want to communicate to the struct consumer). But devs don't really get exposed to this that much so possibly doesn't matter much. ### `noteEmission.discard(...)` I've also noticed that the discard method on the note emission structs is not ever used in our codebase. I feel like notes might be too important to ever be discarded so would revisit whether having the func makes sense. ### Emitting partial notes as offchain message None of our partial notes implementations support emission via an offchain message. ## On using AI In this PR there was a lot of repetitive changes in the contracts and I realized that if I write nice migration notes first then I can use that as an input to the prompt. This made the AI output flawless.
ae7a53e to
47c5ec2
Compare
As I mentioned [here](#16091 (comment)) makes sense to move the `emit_note` function directly to the `NoteEmission` struct as that was the only callsite of the function. This allowed me to nuke the old ugly `assert_note_exists` check in [this commit ](https://github.com/AztecProtocol/aztec-packages/pull/16889/commits/8570bd3e0d4d1fa04fad2b0e0437b2d84809ce12)as now the API guarantees that we are emitting a real note. This makes this change a huge win in my opinion. Closes #8589.
As I mentioned [here](#16091 (comment)) makes sense to move the `emit_note` function directly to the `NoteEmission` struct as that was the only callsite of the function. This allowed me to nuke the old ugly `assert_note_exists` check in [this commit ](https://github.com/AztecProtocol/aztec-packages/pull/16889/commits/8570bd3e0d4d1fa04fad2b0e0437b2d84809ce12)as now the API guarantees that we are emitting a real note. This makes this change a huge win in my opinion. Closes #8589.
With [my recent PR](#16091), location of the event and note emission related code became illogical. In this PR i reshuffle it around. I perceive it as quite important to have this merged relatively quickly as that will allow devs to deal with 1 migration instead of 2.
As I mentioned [here](#16091 (comment)) makes sense to move the `emit_note` function directly to the `NoteEmission` struct as that was the only callsite of the function. This allowed me to nuke the old ugly `assert_note_exists` check in [this commit ](https://github.com/AztecProtocol/aztec-packages/pull/16889/commits/8570bd3e0d4d1fa04fad2b0e0437b2d84809ce12)as now the API guarantees that we are emitting a real note. This makes this change a huge win in my opinion. Closes #8589.
As I mentioned [here](AztecProtocol/aztec-packages#16091 (comment)) makes sense to move the `emit_note` function directly to the `NoteEmission` struct as that was the only callsite of the function. This allowed me to nuke the old ugly `assert_note_exists` check in [this commit ](https://github.com/AztecProtocol/aztec-packages/pull/16889/commits/8570bd3e0d4d1fa04fad2b0e0437b2d84809ce12)as now the API guarantees that we are emitting a real note. This makes this change a huge win in my opinion. Closes AztecProtocol/aztec-packages#8589.

Refactoring note emission API to use the recently introduced
MessageDeliveryglobal var.Followup work
Achieving final imports
Would give the highest priority to tackling this issue because the import of
MessageDeliveryaffects contract code and we don't want to force devs to do 2 annoying migrations. Plan on tackling that right after this PR is merged.Random thoughts that came to my mind while implementing this
Consider renaming
OuterNoteEmissionI would consider renaming
OuterNoteEmissiontoMaybeNoteEmissionbecauseOuterNoteEmissionis not really descriptive (it being outer feels like an implementation detail and not something you want to communicate to the struct consumer). But devs don't really get exposed to this that much so possibly doesn't matter much.noteEmission.discard(...)I've also noticed that the discard method on the note emission structs is not ever used in our codebase. I feel like notes might be too important to ever be discarded so would revisit whether having the func makes sense.
Emitting partial notes as offchain message
None of our partial notes implementations support emission via an offchain message.
On using AI
In this PR there was a lot of repetitive changes in the contracts and I realized that if I write nice migration notes first then I can use that as an input to the prompt. This made the AI output flawless.