Skip to content

Commit

Permalink
chore: purging more msg-key
Browse files Browse the repository at this point in the history
  • Loading branch information
LHerskind committed Feb 29, 2024
1 parent 32809f9 commit 4b9fe54
Show file tree
Hide file tree
Showing 28 changed files with 200 additions and 146 deletions.
4 changes: 2 additions & 2 deletions docs/docs/developers/debugging/sandbox-errors.md
Original file line number Diff line number Diff line change
Expand Up @@ -177,9 +177,9 @@ Users may create a proof against a historical state in Aztec. The rollup circuit

## Archiver Errors

- "L1 to L2 Message with key ${messageKey.toString()} not found in the confirmed messages store" - happens when the L1 to L2 message doesn't exist or is "pending", when the user has sent a message on L1 via the Inbox contract but it has yet to be included in an L2 block by the sequencer - user has to wait for sequencer to pick it up and the archiver to sync the respective L2 block. You can get the sequencer to pick it up by doing an arbitrary transaction on L2 (eg send DAI to yourself). This would give the sequencer a transaction to process and as a side effect it would look for any pending messages it should include.
- "L1 to L2 Message with key ${entryKey.toString()} not found in the confirmed messages store" - happens when the L1 to L2 message doesn't exist or is "pending", when the user has sent a message on L1 via the Inbox contract but it has yet to be included in an L2 block by the sequencer - user has to wait for sequencer to pick it up and the archiver to sync the respective L2 block. You can get the sequencer to pick it up by doing an arbitrary transaction on L2 (eg send DAI to yourself). This would give the sequencer a transaction to process and as a side effect it would look for any pending messages it should include.

- "Unable to remove message: L1 to L2 Message with key ${messageKeyBigInt} not found in store" - happens when trying to confirm a non-existent pending message or cancelling such a message. Perhaps the sequencer has already confirmed the message?
- "Unable to remove message: L1 to L2 Message with key ${entryKeyBigInt} not found in store" - happens when trying to confirm a non-existent pending message or cancelling such a message. Perhaps the sequencer has already confirmed the message?

- "Block number mismatch: expected ${l2BlockNum} but got ${block.number}" - The archiver keeps track of the next expected L2 block number. It throws this error if it got a different one when trying to sync with the rollup contract's events on L1.

Expand Down
2 changes: 1 addition & 1 deletion l1-contracts/test/portals/GasPortal.sol
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ contract GasPortal {
fee: _fee
});
bytes32 entryKey = inbox.cancelL2Message(message, address(this));
// release the funds to msg.sender (since the content hash (& message key) is derived by hashing the caller,
// release the funds to msg.sender (since the content hash) is derived by hashing the caller,
// we confirm that msg.sender is same as `_canceller` supplied when creating the message)
underlying.transfer(msg.sender, _amount);
return entryKey;
Expand Down
4 changes: 2 additions & 2 deletions l1-contracts/test/portals/TokenPortal.sol
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ contract TokenPortal {
fee: _fee
});
bytes32 entryKey = inbox.cancelL2Message(message, address(this));
// release the funds to msg.sender (since the content hash (& message key) is derived by hashing the caller,
// release the funds to msg.sender (since the content hash (& entry key) is derived by hashing the caller,
// we confirm that msg.sender is same as `_canceller` supplied when creating the message)
underlying.transfer(msg.sender, _amount);
return entryKey;
Expand Down Expand Up @@ -175,7 +175,7 @@ contract TokenPortal {
fee: _fee
});
bytes32 entryKey = inbox.cancelL2Message(message, address(this));
// release the funds to msg.sender (since the content hash (& message key) is derived by hashing the caller,
// release the funds to msg.sender (since the content hash (& entry key) is derived by hashing the caller,
// we confirm that msg.sender is same as `_canceller` supplied when creating the message)
underlying.transfer(msg.sender, _amount);
return entryKey;
Expand Down
20 changes: 10 additions & 10 deletions l1-contracts/test/portals/UniswapPortal.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -154,10 +154,10 @@ contract UniswapPortalTest is Test {
entryKey = outbox.computeEntryKey(message);
}

function _addMessagesToOutbox(bytes32 daiWithdrawMessageKey, bytes32 swapMessageKey) internal {
function _addMessagesToOutbox(bytes32 daiWithdrawentryKey, bytes32 swapentryKey) internal {
bytes32[] memory entryKeys = new bytes32[](2);
entryKeys[0] = daiWithdrawMessageKey;
entryKeys[1] = swapMessageKey;
entryKeys[0] = daiWithdrawentryKey;
entryKeys[1] = swapentryKey;
vm.prank(address(rollup));

outbox.sendL1Messages(entryKeys);
Expand Down Expand Up @@ -246,7 +246,7 @@ contract UniswapPortalTest is Test {
bytes32 swapMsgKey = _createUniswapSwapMessagePublic(aztecRecipient, address(this));
_addMessagesToOutbox(daiWithdrawMsgKey, swapMsgKey);

bytes32 l1ToL2MessageKey = uniswapPortal.swapPublic(
bytes32 l1ToL2entryKey = uniswapPortal.swapPublic(
address(daiTokenPortal),
amount,
uniswapFeePool,
Expand All @@ -264,7 +264,7 @@ contract UniswapPortalTest is Test {
// there should be some weth in the weth portal
assertGt(WETH9.balanceOf(address(wethTokenPortal)), 0);
// there should be a message in the inbox:
assertEq(inbox.get(l1ToL2MessageKey).count, 1);
assertEq(inbox.get(l1ToL2entryKey).count, 1);
// there should be no message in the outbox:
assertFalse(outbox.contains(daiWithdrawMsgKey));
assertFalse(outbox.contains(swapMsgKey));
Expand All @@ -279,7 +279,7 @@ contract UniswapPortalTest is Test {
_addMessagesToOutbox(daiWithdrawMsgKey, swapMsgKey);

vm.prank(_caller);
bytes32 l1ToL2MessageKey = uniswapPortal.swapPublic(
bytes32 l1ToL2entryKey = uniswapPortal.swapPublic(
address(daiTokenPortal),
amount,
uniswapFeePool,
Expand All @@ -297,7 +297,7 @@ contract UniswapPortalTest is Test {
// there should be some weth in the weth portal
assertGt(WETH9.balanceOf(address(wethTokenPortal)), 0);
// there should be a message in the inbox:
assertEq(inbox.get(l1ToL2MessageKey).count, 1);
assertEq(inbox.get(l1ToL2entryKey).count, 1);
// there should be no message in the outbox:
assertFalse(outbox.contains(daiWithdrawMsgKey));
assertFalse(outbox.contains(swapMsgKey));
Expand Down Expand Up @@ -357,7 +357,7 @@ contract UniswapPortalTest is Test {
bytes32 swapMsgKey = _createUniswapSwapMessagePublic(aztecRecipient, address(this));
_addMessagesToOutbox(daiWithdrawMsgKey, swapMsgKey);

bytes32 l1ToL2MessageKey = uniswapPortal.swapPublic{value: 1 ether}(
bytes32 l1ToL2entryKey = uniswapPortal.swapPublic{value: 1 ether}(
address(daiTokenPortal),
amount,
uniswapFeePool,
Expand All @@ -376,13 +376,13 @@ contract UniswapPortalTest is Test {
// check event was emitted
vm.expectEmit(true, false, false, false);
// expected event:
emit L1ToL2MessageCancelled(l1ToL2MessageKey);
emit L1ToL2MessageCancelled(l1ToL2entryKey);
// perform op
// TODO(2167) - Update UniswapPortal properly with new portal standard.
bytes32 entryKey = wethTokenPortal.cancelL1ToAztecMessagePublic(
aztecRecipient, wethAmountOut, deadlineForL1ToL2Message, secretHash, 1 ether
);
assertEq(entryKey, l1ToL2MessageKey, "returned entry key and calculated entryKey should match");
assertEq(entryKey, l1ToL2entryKey, "returned entry key and calculated entryKey should match");
assertFalse(inbox.contains(entryKey), "entry still in inbox");
assertEq(
WETH9.balanceOf(address(this)),
Expand Down
14 changes: 14 additions & 0 deletions noir-projects/aztec-nr/aztec/src/messaging.nr
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ mod l1_to_l2_message;

use crate::oracle::get_l1_to_l2_membership_witness::get_l1_to_l2_membership_witness;

use crate::oracle::debug_log::debug_log_format;

use dep::std::merkle::compute_merkle_root;
use crate::messaging::l1_to_l2_message::L1ToL2Message;
use dep::protocol_types::{constants::L1_TO_L2_MSG_TREE_HEIGHT, address::{AztecAddress, EthAddress}, utils::arr_copy_slice};
Expand All @@ -24,6 +26,18 @@ pub fn process_l1_to_l2_message(
secret
);
let entry_key = msg.hash();
debug_log_format(
"L1ToL2Message entry_key: H({0}, {1}, {2}, {3}, {4}, {5}) = {6} ",
[
portal_contract_address.to_field(),
chain_id,
storage_contract_address.to_field(),
version,
content,
secret,
entry_key
]
);

let returned_message = get_l1_to_l2_membership_witness(entry_key);
let leaf_index = returned_message[0];
Expand Down
12 changes: 6 additions & 6 deletions yarn-project/archiver/src/archiver/archiver.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,12 +101,12 @@ describe('Archiver', () => {

// Check that only 2 messages (l1ToL2MessageAddedEvents[3][2] and l1ToL2MessageAddedEvents[3][3]) are pending.
// Other two (l1ToL2MessageAddedEvents[3][0..2]) were cancelled. And the previous messages were confirmed.
const expectedPendingMessageKeys = [
const expectedPendingentryKeys = [
l1ToL2MessageAddedEvents[3][2].args.entryKey,
l1ToL2MessageAddedEvents[3][3].args.entryKey,
];
const actualPendingMessageKeys = (await archiver.getPendingL1ToL2Messages(10)).map(key => key.toString());
expect(expectedPendingMessageKeys).toEqual(actualPendingMessageKeys);
const actualPendingentryKeys = (await archiver.getPendingL1ToL2EntryKeys(10)).map(key => key.toString());
expect(expectedPendingentryKeys).toEqual(actualPendingentryKeys);

// Expect logs to correspond to what is set by L2Block.random(...)
const encryptedLogs = await archiver.getLogs(1, 100, LogType.ENCRYPTED);
Expand Down Expand Up @@ -199,9 +199,9 @@ describe('Archiver', () => {
expect(latestBlockNum).toEqual(numL2BlocksInTest);

// Check that the only pending L1 to L2 messages are those from eth bock 102
const expectedPendingMessageKeys = additionalL1ToL2MessagesBlock102;
const actualPendingMessageKeys = (await archiver.getPendingL1ToL2Messages(100)).map(key => key.toString());
expect(actualPendingMessageKeys).toEqual(expectedPendingMessageKeys);
const expectedPendingentryKeys = additionalL1ToL2MessagesBlock102;
const actualPendingentryKeys = (await archiver.getPendingL1ToL2EntryKeys(100)).map(key => key.toString());
expect(actualPendingentryKeys).toEqual(expectedPendingentryKeys);

await archiver.stop();
}, 10_000);
Expand Down
14 changes: 7 additions & 7 deletions yarn-project/archiver/src/archiver/archiver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ export class Archiver implements ArchiveSource {
`Adding ${newMessages.length} new messages and ${cancelledMessages.length} cancelled messages in L1 block ${l1Block}`,
);
await this.store.addPendingL1ToL2Messages(newMessages, l1Block);
await this.store.cancelPendingL1ToL2Messages(cancelledMessages, l1Block);
await this.store.cancelPendingL1ToL2EntryKeys(cancelledMessages, l1Block);
}

// ********** Events that are processed per L2 block **********
Expand Down Expand Up @@ -307,10 +307,10 @@ export class Archiver implements ArchiveSource {
);

// from retrieved L2Blocks, confirm L1 to L2 messages that have been published
// from each l2block fetch all messageKeys in a flattened array:
// from each l2block fetch all entryKeys in a flattened array:
this.log(`Confirming l1 to l2 messages in store`);
for (const block of retrievedBlocks.retrievedData) {
await this.store.confirmL1ToL2Messages(block.body.l1ToL2Messages);
await this.store.confirmL1ToL2EntryKeys(block.body.l1ToL2Messages);
}

// store retrieved L2 blocks after removing new logs information.
Expand Down Expand Up @@ -550,13 +550,13 @@ export class Archiver implements ArchiveSource {
* @param limit - The number of messages to return.
* @returns The requested L1 to L2 messages' keys.
*/
getPendingL1ToL2Messages(limit: number): Promise<Fr[]> {
return this.store.getPendingL1ToL2MessageKeys(limit);
getPendingL1ToL2EntryKeys(limit: number): Promise<Fr[]> {
return this.store.getPendingL1ToL2entryKeys(limit);
}

/**
* Gets the confirmed/consumed L1 to L2 message associated with the given message key
* @param entryKey - The message key.
* Gets the confirmed/consumed L1 to L2 message associated with the given entry key
* @param entryKey - The entry key.
* @returns The L1 to L2 message (throws if not found).
*/
getConfirmedL1ToL2Message(entryKey: Fr): Promise<L1ToL2Message> {
Expand Down
18 changes: 9 additions & 9 deletions yarn-project/archiver/src/archiver/archiver_store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,30 +76,30 @@ export interface ArchiverDataStore {

/**
* Remove pending L1 to L2 messages from the store (if they were cancelled).
* @param message - The message keys to be removed from the store.
* @param entryKeys - The entry keys to be removed from the store.
* @param l1BlockNumber - The block number of the L1 block that cancelled the messages.
* @returns True if the operation is successful.
*/
cancelPendingL1ToL2Messages(message: Fr[], l1BlockNumber: bigint): Promise<boolean>;
cancelPendingL1ToL2EntryKeys(entryKeys: Fr[], l1BlockNumber: bigint): Promise<boolean>;

/**
* Messages that have been published in an L2 block are confirmed.
* Add them to the confirmed store, also remove them from the pending store.
* @param messageKeys - The message keys to be removed from the store.
* @param entryKeys - The entry keys to be removed from the store.
* @returns True if the operation is successful.
*/
confirmL1ToL2Messages(messageKeys: Fr[]): Promise<boolean>;
confirmL1ToL2EntryKeys(entryKeys: Fr[]): Promise<boolean>;

/**
* Gets up to `limit` amount of pending L1 to L2 messages, sorted by fee
* @param limit - The number of messages to return (by default NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP).
* @returns The requested L1 to L2 message keys.
* @param limit - The number of entries to return (by default NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP).
* @returns The requested L1 to L2 entry keys.
*/
getPendingL1ToL2MessageKeys(limit: number): Promise<Fr[]>;
getPendingL1ToL2entryKeys(limit: number): Promise<Fr[]>;

/**
* Gets the confirmed L1 to L2 message corresponding to the given message key.
* @param entryKey - The message key to look up.
* Gets the confirmed L1 to L2 message corresponding to the given entry key.
* @param entryKey - The entry key to look up.
* @returns The requested L1 to L2 message or throws if not found.
*/
getConfirmedL1ToL2Message(entryKey: Fr): Promise<L1ToL2Message>;
Expand Down
Loading

0 comments on commit 4b9fe54

Please sign in to comment.