Skip to content

Commit

Permalink
fix archiver
Browse files Browse the repository at this point in the history
  • Loading branch information
rahul-kothari committed Oct 9, 2024
1 parent 2e67de9 commit aa106cc
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 8 deletions.
3 changes: 2 additions & 1 deletion l1-contracts/src/core/messagebridge/Inbox.sol
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,8 @@ contract Inbox is IInbox {
// this is the global leaf index and not index in the l2Block subtree
// such that users can simply use it and don't need access to a node if they are to consume it in public.
// trees are constant size so global index = tree number * size + subtree index
uint256 index = (inProgress - 1) * SIZE + currentTree.insertLeaf(leaf);
uint256 index =
(inProgress - Constants.INITIAL_L2_BLOCK_NUM) * SIZE + currentTree.insertLeaf(leaf);
totalMessagesInserted++;
emit MessageSent(inProgress, index, leaf);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,16 +61,18 @@ export class MessageStore {
void this.#lastSynchedL1Block.set(messages.lastProcessedL1BlockNumber);

for (const message of messages.retrievedData) {
if (message.index >= this.#l1ToL2MessagesSubtreeSize) {
// inbox event emits index the whole tree. We need index in the L1 to L2 message subtree.
// reverse of what is done in inbox.sol
const indexInTheWholeTree = message.index;
const indexInSubtree =
indexInTheWholeTree -
(message.blockNumber - BigInt(INITIAL_L2_BLOCK_NUM)) * BigInt(NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP);
if (indexInSubtree >= this.#l1ToL2MessagesSubtreeSize) {
throw new Error(`Message index ${message.index} out of subtree range`);
}
const key = `${message.blockNumber}-${message.index}`;
const key = `${message.blockNumber}-${indexInSubtree}`;
void this.#l1ToL2Messages.setIfNotExists(key, message.leaf.toBuffer());

const indexInTheWholeTree =
(message.blockNumber - BigInt(INITIAL_L2_BLOCK_NUM)) * BigInt(NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP) +
message.index;

const indices = this.#l1ToL2MessageIndices.get(message.leaf.toString()) ?? [];
indices.push(indexInTheWholeTree);
void this.#l1ToL2MessageIndices.set(message.leaf.toString(), indices);
Expand Down
2 changes: 1 addition & 1 deletion yarn-project/circuit-types/src/messaging/inbox_leaf.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export class InboxLeaf {
constructor(
/** L2 block number in which the message will be included. */
public readonly blockNumber: bigint,
/** Index of the leaf in L2 block message subtree. */
/** Index of the leaf in the whole tree. */
public readonly index: bigint,
/** Leaf in the subtree/message hash. */
public readonly leaf: Fr,
Expand Down

0 comments on commit aa106cc

Please sign in to comment.