Skip to content

Commit b74102a

Browse files
mverzillinchamo
andauthored
refactor!: reimplement partial notes on FactStore (#24369)
Closes F-771 --------- Co-authored-by: Nicolas Chamo <nicolas@chamo.com.ar>
1 parent db2b240 commit b74102a

35 files changed

Lines changed: 743 additions & 318 deletions

File tree

docs/docs-developers/docs/resources/migration_notes.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,31 @@ Aztec is in active development. Each version may introduce breaking changes that
99

1010
## TBD
1111

12+
### [Aztec.nr] `MessageContext` removed: message processing uses `ResolvedTx`
13+
14+
`aztec::messages::processing::MessageContext` has been removed in favor of the new `ResolvedTx`, which carries the same `tx_hash`, `unique_note_hashes_in_tx`, and `first_nullifier_in_tx`, plus `block_number` and `block_hash`. The offchain handoff type `OffchainMessageWithContext` is likewise renamed to `OffchainMessageWithTx`.
15+
16+
This affects contracts that implement a custom message handler (registered via `AztecConfig::custom_message_handler`): the handler's context parameter is now a `ResolvedTx`.
17+
18+
**Migration:**
19+
20+
```diff
21+
use aztec::messages::processing::{
22+
- enqueue_event_for_validation, MessageContext,
23+
+ enqueue_event_for_validation, ResolvedTx,
24+
};
25+
26+
unconstrained fn handle_my_message(
27+
// ...
28+
- message_context: MessageContext,
29+
+ resolved_tx: ResolvedTx,
30+
scope: AztecAddress,
31+
) {
32+
- // ...message_context.tx_hash...
33+
+ // ...resolved_tx.tx_hash...
34+
}
35+
```
36+
1237
### [PXE] `pxe.updateContract` removed and `pxe.registerContract` no longer takes an artifact
1338

1439
Registering classes and instances are now separate, unvalidated operations. `registerContractClass(artifact)` registers a class, `registerContract(instance)` registers an instance and no longer takes an artifact. `registerContract` does not check that PXE knows the contract's artifact: a missing artifact surfaces only when the contract is later simulated.

noir-projects/aztec-nr/aztec/src/lib.nr

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ pub mod transient;
4545
pub mod event;
4646
pub mod facts;
4747
pub mod messages;
48+
pub(crate) mod partial_notes;
4849
pub use protocol_types as protocol;
4950
pub(crate) mod logging;
5051
pub mod utils;

noir-projects/aztec-nr/aztec/src/messages/discovery/mod.nr

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ use crate::messages::{
44
delivery::handshake::{get_handshake_secrets, PROVIDED_SECRETS_ARRAY_BASE_SLOT},
55
processing::provided_secret::ProvidedSecret,
66
};
7+
use crate::partial_notes;
78
use crate::protocol::address::AztecAddress;
89

910
pub(crate) mod nonce_discovery;
10-
pub(crate) mod partial_notes;
1111
pub(crate) mod private_events;
1212
pub mod private_notes;
1313
pub mod process_message;
@@ -18,8 +18,8 @@ use crate::{
1818
encoding::MAX_MESSAGE_CONTENT_LEN,
1919
logs::note::MAX_NOTE_PACKED_LEN,
2020
processing::{
21-
MessageContext, offchain::OffchainInboxSync, OffchainMessageWithContext,
22-
pending_tagged_log::PendingTaggedLog, validate_and_store_enqueued_notes_and_events,
21+
offchain::OffchainInboxSync, OffchainMessageWithTx, pending_tagged_log::PendingTaggedLog, ResolvedTx,
22+
validate_and_store_enqueued_notes_and_events,
2323
},
2424
},
2525
oracle::message_processing,
@@ -108,7 +108,7 @@ pub type CustomMessageHandler = unconstrained fn(
108108
/* msg_type_id */ u64,
109109
/* msg_metadata */ u64,
110110
/* msg_content */ BoundedVec<Field, MAX_MESSAGE_CONTENT_LEN>,
111-
/* message_context */ MessageContext,
111+
/* resolved_tx */ ResolvedTx,
112112
/* scope */ AztecAddress);
113113

114114
/// Custom state synchronization handler.
@@ -209,22 +209,22 @@ unconstrained fn sync_state_with_secrets(
209209

210210
if offchain_inbox_sync.is_some() {
211211
let msgs = offchain_inbox_sync.unwrap()(contract_address, scope);
212-
msgs.for_each(|_i, msg: OffchainMessageWithContext| {
212+
msgs.for_each(|_i, msg: OffchainMessageWithTx| {
213213
process_message_ciphertext(
214214
contract_address,
215215
compute_note_hash,
216216
compute_note_nullifier,
217217
process_custom_message,
218218
msg.message_ciphertext,
219-
msg.message_context,
219+
msg.resolved_tx,
220220
scope,
221221
);
222222
});
223223
}
224224

225225
// Then we process all pending partial notes, regardless of whether they were found in the current or previous
226226
// executions.
227-
partial_notes::fetch_and_process_partial_note_completion_logs(
227+
partial_notes::sync(
228228
contract_address,
229229
compute_note_hash,
230230
compute_note_nullifier,
@@ -264,7 +264,7 @@ mod test {
264264
// Mock the oracle call to return a known base slot, then populate an ephemeral
265265
// array at that slot so do_sync_state processes a non-empty log list.
266266
let base_slot = 42;
267-
let mock = std::test::OracleMock::mock("aztec_utl_getPendingTaggedLogs");
267+
let mock = std::test::OracleMock::mock("aztec_utl_getPendingTaggedLogsV2");
268268
let _ = mock.returns(base_slot);
269269

270270
let logs: EphemeralArray<PendingTaggedLog> = EphemeralArray::at(base_slot);
@@ -281,6 +281,10 @@ mod test {
281281
no_inbox_sync,
282282
scope,
283283
);
284+
285+
// Guards against the mocked oracle name going stale: if sync stops calling it, the crafted empty log
286+
// above is never consumed and the test silently stops covering the empty-payload path.
287+
assert_eq(mock.times_called(), 1);
284288
});
285289
}
286290

noir-projects/aztec-nr/aztec/src/messages/discovery/partial_notes.nr

Lines changed: 0 additions & 182 deletions
This file was deleted.

0 commit comments

Comments
 (0)