Skip to content

Commit

Permalink
bug fix
Browse files Browse the repository at this point in the history
  • Loading branch information
benesjan committed Mar 19, 2024
1 parent e44e68f commit 68d7453
Show file tree
Hide file tree
Showing 13 changed files with 52 additions and 48 deletions.
4 changes: 2 additions & 2 deletions yarn-project/archiver/src/archiver/archiver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -425,9 +425,9 @@ export class Archiver implements ArchiveSource {
/**
* Gets the L1 to L2 message index in the L1 to L2 message tree.
* @param l1ToL2Message - The L1 to L2 message.
* @returns The index of the L1 to L2 message in the L1 to L2 message tree.
* @returns The index of the L1 to L2 message in the L1 to L2 message tree (undefined if not found).
*/
getL1ToL2MessageIndex(l1ToL2Message: Fr): Promise<bigint> {
getL1ToL2MessageIndex(l1ToL2Message: Fr): Promise<bigint | undefined> {
return this.store.getL1ToL2MessageIndex(l1ToL2Message);
}

Expand Down
4 changes: 2 additions & 2 deletions yarn-project/archiver/src/archiver/archiver_store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,9 @@ export interface ArchiverDataStore {
/**
* Gets the L1 to L2 message index in the L1 to L2 message tree.
* @param l1ToL2Message - The L1 to L2 message.
* @returns The index of the L1 to L2 message in the L1 to L2 message tree.
* @returns The index of the L1 to L2 message in the L1 to L2 message tree (undefined if not found).
*/
getL1ToL2MessageIndex(l1ToL2Message: Fr): Promise<bigint>;
getL1ToL2MessageIndex(l1ToL2Message: Fr): Promise<bigint | undefined>;

/**
* Gets up to `limit` amount of logs starting from `from`.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,9 +156,9 @@ export class KVArchiverDataStore implements ArchiverDataStore {
/**
* Gets the L1 to L2 message index in the L1 to L2 message tree.
* @param l1ToL2Message - The L1 to L2 message.
* @returns The index of the L1 to L2 message in the L1 to L2 message tree.
* @returns The index of the L1 to L2 message in the L1 to L2 message tree (undefined if not found).
*/
public getL1ToL2MessageIndex(l1ToL2Message: Fr): Promise<bigint> {
public getL1ToL2MessageIndex(l1ToL2Message: Fr): Promise<bigint | undefined> {
return Promise.resolve(this.#messageStore.getL1ToL2MessageIndex(l1ToL2Message));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,10 @@ export class MessageStore {
/**
* Gets the L1 to L2 message index in the L1 to L2 message tree.
* @param l1ToL2Message - The L1 to L2 message.
* @returns The index of the L1 to L2 message in the L1 to L2 message tree.
* @returns The index of the L1 to L2 message in the L1 to L2 message tree (undefined if not found).
*/
public getL1ToL2MessageIndex(l1ToL2Message: Fr): Promise<bigint> {
public getL1ToL2MessageIndex(l1ToL2Message: Fr): Promise<bigint | undefined> {
const index = this.#l1ToL2MessageIndices.get(l1ToL2Message.toString());
if (index === undefined) {
throw new Error(`L1 to L2 message index not found in the store for message ${l1ToL2Message.toString()}`);
}
return Promise.resolve(index);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ export class L1ToL2MessageStore {
/**
* Gets the L1 to L2 message index in the L1 to L2 message tree.
* @param l1ToL2Message - The L1 to L2 message.
* @returns The index of the L1 to L2 message in the L1 to L2 message tree.
* @returns The index of the L1 to L2 message in the L1 to L2 message tree (undefined if not found).
*/
getMessageIndex(l1ToL2Message: Fr): bigint {
getMessageIndex(l1ToL2Message: Fr): bigint | undefined {
for (const [key, message] of this.store.entries()) {
if (message.equals(l1ToL2Message)) {
const [blockNumber, messageIndex] = key.split('-');
Expand All @@ -64,6 +64,6 @@ export class L1ToL2MessageStore {
return indexInTheWholeTree;
}
}
throw new Error(`L1 to L2 message index not found in the store for message ${l1ToL2Message.toString()}`);
return undefined;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -175,9 +175,9 @@ export class MemoryArchiverStore implements ArchiverDataStore {
/**
* Gets the L1 to L2 message index in the L1 to L2 message tree.
* @param l1ToL2Message - The L1 to L2 message.
* @returns The index of the L1 to L2 message in the L1 to L2 message tree.
* @returns The index of the L1 to L2 message in the L1 to L2 message tree (undefined if not found).
*/
public getL1ToL2MessageIndex(l1ToL2Message: Fr): Promise<bigint> {
public getL1ToL2MessageIndex(l1ToL2Message: Fr): Promise<bigint | undefined> {
return Promise.resolve(this.l1ToL2Messages.getMessageIndex(l1ToL2Message));
}

Expand Down
19 changes: 15 additions & 4 deletions yarn-project/aztec-node/src/aztec-node/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -367,14 +367,16 @@ export class AztecNodeService implements AztecNode {
* Returns the index and a sibling path for a leaf in the committed l1 to l2 data tree.
* @param blockNumber - The block number at which to get the data.
* @param l1ToL2Message - The l1ToL2Message to get the index / sibling path for.
* @throws If the message is not found.
* @returns A tuple of the index and the sibling path of the L1ToL2Message.
* @returns A tuple of the index and the sibling path of the L1ToL2Message (undefined if not found).
*/
public async getL1ToL2MessageIndexAndSiblingPath(
public async getL1ToL2MessageMembershipWitness(
blockNumber: L2BlockNumber,
l1ToL2Message: Fr,
): Promise<[bigint, SiblingPath<typeof L1_TO_L2_MSG_TREE_HEIGHT>]> {
): Promise<[bigint, SiblingPath<typeof L1_TO_L2_MSG_TREE_HEIGHT>] | undefined> {
const index = await this.l1ToL2MessageSource.getL1ToL2MessageIndex(l1ToL2Message);
if (index === undefined) {
return undefined;
}
const committedDb = await this.#getWorldState(blockNumber);
const siblingPath = await committedDb.getSiblingPath<typeof L1_TO_L2_MSG_TREE_HEIGHT>(
MerkleTreeId.L1_TO_L2_MESSAGE_TREE,
Expand All @@ -383,6 +385,15 @@ export class AztecNodeService implements AztecNode {
return [index, siblingPath];
}

/**
* Returns whether an L1 to L2 message is synced by archiver and if it's ready to be included in a block.
* @param l1ToL2Message - The L1 to L2 message to check.
* @returns Whether the message is synced and ready to be included in a block.
*/
public async isL1ToL2MessageSynced(l1ToL2Message: Fr): Promise<boolean> {
return (await this.l1ToL2MessageSource.getL1ToL2MessageIndex(l1ToL2Message)) !== undefined;
}

/**
* Returns the index of a l2ToL1Message in a ephemeral l2 to l1 data tree as well as its sibling path.
* @remarks This tree is considered ephemeral because it is created on-demand by: taking all the l2ToL1 messages
Expand Down
14 changes: 10 additions & 4 deletions yarn-project/circuit-types/src/interfaces/aztec-node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,19 @@ export interface AztecNode {
* Returns the index and a sibling path for a leaf in the committed l1 to l2 data tree.
* @param blockNumber - The block number at which to get the data.
* @param l1ToL2Message - The l1ToL2Message to get the index / sibling path for.
* @throws If the message is not found.
* @returns A tuple of the index and the sibling path of the message.
* @returns A tuple of the index and the sibling path of the message (undefined if not found).
*/
getL1ToL2MessageIndexAndSiblingPath(
getL1ToL2MessageMembershipWitness(
blockNumber: L2BlockNumber,
l1ToL2Message: Fr,
): Promise<[bigint, SiblingPath<typeof L1_TO_L2_MSG_TREE_HEIGHT>]>;
): Promise<[bigint, SiblingPath<typeof L1_TO_L2_MSG_TREE_HEIGHT>] | undefined>;

/**
* Returns whether an L1 to L2 message is synced by archiver and if it's ready to be included in a block.
* @param l1ToL2Message - The L1 to L2 message to check.
* @returns Whether the message is synced and ready to be included in a block.
*/
isL1ToL2MessageSynced(l1ToL2Message: Fr): Promise<boolean>;

/**
* Returns the index of a l2ToL1Message in a ephemeral l2 to l1 data tree as well as its sibling path.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ export interface L1ToL2MessageSource {
/**
* Gets the L1 to L2 message index in the L1 to L2 message tree.
* @param l1ToL2Message - The L1 to L2 message.
* @returns The index of the L1 to L2 message in the L1 to L2 message tree.
* @returns The index of the L1 to L2 message in the L1 to L2 message tree (undefined if not found).
*/
getL1ToL2MessageIndex(l1ToL2Message: Fr): Promise<bigint>;
getL1ToL2MessageIndex(l1ToL2Message: Fr): Promise<bigint | undefined>;

/**
* Gets the number of the latest L2 block processed by the implementation.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ describe('e2e_cross_chain_messaging', () => {
.withWallet(user2Wallet)
.methods.claim_private(secretHashForL2MessageConsumption, bridgeAmount, secretForL2MessageConsumption)
.simulate(),
).rejects.toThrow(`L1 to L2 message index not found in the store for message ${wrongMessage.hash().toString()}`);
).rejects.toThrow(`No L1 to L2 message found for entry key ${wrongMessage.hash().toString()}`);

// send the right one -
const consumptionReceipt = await l2Bridge
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ describe('e2e_public_cross_chain_messaging', () => {

await expect(
l2Bridge.withWallet(user2Wallet).methods.claim_private(secretHash, bridgeAmount, secret).simulate(),
).rejects.toThrow(`L1 to L2 message index not found in the store for message ${wrongMessage.hash().toString()}`);
).rejects.toThrow(`No L1 to L2 message found for entry key ${wrongMessage.hash().toString()}`);
}, 60_000);

// Note: We register one portal address when deploying contract but that address is no-longer the only address
Expand Down
22 changes: 4 additions & 18 deletions yarn-project/end-to-end/src/shared/cross_chain_test_harness.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import {
Wallet,
computeMessageSecretHash,
deployL1Contract,
retryUntil,
sha256,
sleep,
} from '@aztec/aztec.js';
import {
InboxAbi,
Expand Down Expand Up @@ -435,25 +435,11 @@ export class CrossChainTestHarness {
* it's included it becomes available for consumption in the next block because the l1 to l2 message tree.
*/
async makeMessageConsumable(msgLeaf: Fr) {
const messageBlock = Number(await this.inbox.read.inProgress());
// We poll isL1ToL2MessageSynced endpoint until the message is available
await retryUntil(async () => await this.aztecNode.isL1ToL2MessageSynced(msgLeaf), 'message sync', 10);

await this.mintTokensPublicOnL2(0n);
await this.mintTokensPublicOnL2(0n);

// We poll getL1ToL2MessageIndexAndSiblingPath endpoint until the message is available (it's most likely already
// available given that we waited for 2 blocks).
let i = 0;
while (i < 5) {
try {
// The function throws if message is not found
await this.aztecNode.getL1ToL2MessageIndexAndSiblingPath(messageBlock, msgLeaf);
} catch (e) {
i++;
await sleep(1000);
continue;
}
return;
}
throw new Error('Message not available after 5 seconds');
}
}
// docs:end:cross_chain_test_harness
8 changes: 6 additions & 2 deletions yarn-project/pxe/src/simulator_oracle/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,14 +122,18 @@ export class SimulatorOracle implements DBOracle {

/**
* Retrieves the L1ToL2Message associated with a specific entry key
* Throws an error if the entry key is not found
*
* @throws If the entry key is not found
* @param entryKey - The key of the message to be retrieved
* @returns A promise that resolves to the message data, a sibling path and the
* index of the message in the l1ToL2MessageTree
*/
async getL1ToL2MembershipWitness(entryKey: Fr): Promise<MessageLoadOracleInputs<typeof L1_TO_L2_MSG_TREE_HEIGHT>> {
const [index, siblingPath] = await this.aztecNode.getL1ToL2MessageIndexAndSiblingPath('latest', entryKey);
const response = await this.aztecNode.getL1ToL2MessageMembershipWitness('latest', entryKey);
if (!response) {
throw new Error(`No L1 to L2 message found for entry key ${entryKey.toString()}`);
}
const [index, siblingPath] = response;
return new MessageLoadOracleInputs(index, siblingPath);
}

Expand Down

0 comments on commit 68d7453

Please sign in to comment.