Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
benesjan committed Mar 17, 2024
1 parent ae7db18 commit 8b58aca
Show file tree
Hide file tree
Showing 15 changed files with 232 additions and 211 deletions.
1 change: 1 addition & 0 deletions yarn-project/archiver/src/archiver/archiver_store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
import { Fr } from '@aztec/circuits.js';
import { AztecAddress } from '@aztec/foundation/aztec-address';
import { ContractClassPublic, ContractInstanceWithAddress } from '@aztec/types/contracts';

import { DataRetrieval } from './data_retrieval.js';

/**
Expand Down
11 changes: 7 additions & 4 deletions yarn-project/archiver/src/archiver/archiver_store_test_suite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,10 @@ export function describeArchiverDataStore(testName: string, getStore: () => Arch
});

it('returns the L1 block number that most recently added messages from inbox', async () => {
await store.addL1ToL2Messages({lastProcessedL1BlockNumber: 1n, retrievedData: [new InboxLeaf(0n, 0n, Fr.ZERO)]});
await store.addL1ToL2Messages({
lastProcessedL1BlockNumber: 1n,
retrievedData: [new InboxLeaf(0n, 0n, Fr.ZERO)],
});
await expect(store.getSynchedL1BlockNumbers()).resolves.toEqual({
blocks: 0n,
messages: 1n,
Expand Down Expand Up @@ -169,7 +172,7 @@ export function describeArchiverDataStore(testName: string, getStore: () => Arch
it('returns messages in correct order', async () => {
const msgs = generateBlockMessages(l2BlockNumber, l1ToL2MessageSubtreeSize);
const shuffledMessages = msgs.slice().sort(() => randomInt(1) - 0.5);
await store.addL1ToL2Messages({lastProcessedL1BlockNumber: 100n, retrievedData: shuffledMessages});
await store.addL1ToL2Messages({ lastProcessedL1BlockNumber: 100n, retrievedData: shuffledMessages });
const retrievedMessages = await store.getL1ToL2Messages(l2BlockNumber);

const expectedLeavesOrder = msgs.map(msg => msg.leaf);
Expand All @@ -182,7 +185,7 @@ export function describeArchiverDataStore(testName: string, getStore: () => Arch
// --> with that there will be a gap and it will be impossible to sequence the messages
msgs[4] = new InboxLeaf(l2BlockNumber, BigInt(l1ToL2MessageSubtreeSize - 1), Fr.random());

await store.addL1ToL2Messages({lastProcessedL1BlockNumber: 100n, retrievedData: msgs});
await store.addL1ToL2Messages({ lastProcessedL1BlockNumber: 100n, retrievedData: msgs });
await expect(async () => {
await store.getL1ToL2Messages(l2BlockNumber);
}).rejects.toThrow(`L1 to L2 message gap found in block ${l2BlockNumber}`);
Expand All @@ -192,7 +195,7 @@ export function describeArchiverDataStore(testName: string, getStore: () => Arch
const msgs = generateBlockMessages(l2BlockNumber, l1ToL2MessageSubtreeSize + 1);

await expect(async () => {
await store.addL1ToL2Messages({lastProcessedL1BlockNumber: 100n, retrievedData: msgs});
await store.addL1ToL2Messages({ lastProcessedL1BlockNumber: 100n, retrievedData: msgs });
}).rejects.toThrow(`Message index ${l1ToL2MessageSubtreeSize} out of subtree range`);
});
});
Expand Down
2 changes: 1 addition & 1 deletion yarn-project/archiver/src/archiver/data_retrieval.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ export async function retrieveL1ToL2Messages(
const l1ToL2Messages = processLeafInsertedLogs(leafInsertedLogs);
retrievedL1ToL2Messages.push(...l1ToL2Messages);
// handles the case when there are no new messages:
searchStartBlock = (leafInsertedLogs.findLast(msgLog => !!msgLog)?.blockNumber || searchStartBlock);
searchStartBlock = leafInsertedLogs.findLast(msgLog => !!msgLog)?.blockNumber || searchStartBlock;
} while (blockUntilSynced && searchStartBlock <= searchEndBlock);
return { lastProcessedL1BlockNumber: searchStartBlock, retrievedData: retrievedL1ToL2Messages };
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ import { AztecKVStore } from '@aztec/kv-store';
import { ContractClassPublic, ContractInstanceWithAddress } from '@aztec/types/contracts';

import { ArchiverDataStore, ArchiverL1SynchPoint } from '../archiver_store.js';
import { DataRetrieval } from '../data_retrieval.js';
import { BlockBodyStore } from './block_body_store.js';
import { BlockStore } from './block_store.js';
import { ContractClassStore } from './contract_class_store.js';
import { ContractInstanceStore } from './contract_instance_store.js';
import { LogStore } from './log_store.js';
import { MessageStore } from './message_store.js';
import { DataRetrieval } from '../data_retrieval.js';

/**
* LMDB implementation of the ArchiverDataStore interface.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
} from '@aztec/circuits.js';
import { createDebugLogger } from '@aztec/foundation/log';
import { AztecKVStore, AztecMap, AztecSingleton } from '@aztec/kv-store';

import { DataRetrieval } from '../data_retrieval.js';

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ import { AztecAddress } from '@aztec/foundation/aztec-address';
import { ContractClassPublic, ContractInstanceWithAddress } from '@aztec/types/contracts';

import { ArchiverDataStore, ArchiverL1SynchPoint } from '../archiver_store.js';
import { L1ToL2MessageStore } from './l1_to_l2_message_store.js';
import { DataRetrieval } from '../data_retrieval.js';
import { L1ToL2MessageStore } from './l1_to_l2_message_store.js';

/**
* Simple, in-memory implementation of an archiver data store.
Expand Down
2 changes: 1 addition & 1 deletion yarn-project/circuit-types/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export * from './function_call.js';
export * from './keys/index.js';
export * from './notes/index.js';
export * from './l1_to_l2_message.js';
export * from './messaging/index.js';
export * from './l2_block.js';
export * from './body.js';
export * from './l2_block_context.js';
Expand Down
203 changes: 0 additions & 203 deletions yarn-project/circuit-types/src/l1_to_l2_message.ts

This file was deleted.

26 changes: 26 additions & 0 deletions yarn-project/circuit-types/src/messaging/inbox_leaf.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { Fr } from '@aztec/circuits.js';
import { toBigIntBE } from '@aztec/foundation/bigint-buffer';
import { BufferReader, serializeToBuffer } from '@aztec/foundation/serialize';

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. */
public readonly index: bigint,
/** Leaf of the subtree. */
public readonly leaf: Fr,
) {}

toBuffer(): Buffer {
return serializeToBuffer([this.blockNumber, this.index, this.leaf]);
}

fromBuffer(buffer: Buffer | BufferReader): InboxLeaf {
const reader = BufferReader.asReader(buffer);
const blockNumber = toBigIntBE(reader.readBytes(32));
const index = toBigIntBE(reader.readBytes(32));
const leaf = reader.readObject(Fr);
return new InboxLeaf(blockNumber, index, leaf);
}
}
5 changes: 5 additions & 0 deletions yarn-project/circuit-types/src/messaging/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export * from './inbox_leaf.js';
export * from './l1_to_l2_message.js';
export * from './l1_to_l2_message_source.js';
export * from './l1_actor.js';
export * from './l2_actor.js';
43 changes: 43 additions & 0 deletions yarn-project/circuit-types/src/messaging/l1_actor.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { randomInt } from '@aztec/foundation/crypto';
import { EthAddress } from '@aztec/foundation/eth-address';
import { Fr } from '@aztec/foundation/fields';
import { BufferReader, serializeToBuffer } from '@aztec/foundation/serialize';

/**
* The sender of an L1 to L2 message.
*/
export class L1Actor {
constructor(
/**
* The sender of the message.
*/
public readonly sender: EthAddress,
/**
* The chain id on which the message was sent.
*/
public readonly chainId: number,
) {}

static empty() {
return new L1Actor(EthAddress.ZERO, 0);
}

toFields(): Fr[] {
return [this.sender.toField(), new Fr(BigInt(this.chainId))];
}

toBuffer(): Buffer {
return serializeToBuffer(this.sender, this.chainId);
}

static fromBuffer(buffer: Buffer | BufferReader): L1Actor {
const reader = BufferReader.asReader(buffer);
const ethAddr = reader.readObject(EthAddress);
const chainId = reader.readNumber();
return new L1Actor(ethAddr, chainId);
}

static random(): L1Actor {
return new L1Actor(EthAddress.random(), randomInt(1000));
}
}
Loading

0 comments on commit 8b58aca

Please sign in to comment.