Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
asdf

edit

asdf

add

asdf

asdf

yes

asdf

asdf

fix

asdf

Add

test

more fixes

adsf

asdf

asdf

NOT REALLY WORKING

test
  • Loading branch information
sklppy88 committed Feb 12, 2024
1 parent 2fccdf2 commit 2a9d399
Show file tree
Hide file tree
Showing 23 changed files with 483 additions and 472 deletions.
20 changes: 10 additions & 10 deletions yarn-project/archiver/src/archiver/archiver.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,15 @@ describe('Archiver', () => {
const l1ToL2MessageAddedEvents = [
makeL1ToL2MessageAddedEvents(
100n,
blocks[0].newL1ToL2Messages.map(key => key.toString()),
blocks[0].body.l1ToL2Messages.map(key => key.toString()),
),
makeL1ToL2MessageAddedEvents(
100n,
blocks[1].newL1ToL2Messages.map(key => key.toString()),
blocks[1].body.l1ToL2Messages.map(key => key.toString()),
),
makeL1ToL2MessageAddedEvents(
2501n,
blocks[2].newL1ToL2Messages.map(key => key.toString()),
blocks[2].body.l1ToL2Messages.map(key => key.toString()),
),
makeL1ToL2MessageAddedEvents(2502n, [
messageToCancel1,
Expand Down Expand Up @@ -162,11 +162,11 @@ describe('Archiver', () => {
const l1ToL2MessageAddedEvents = [
makeL1ToL2MessageAddedEvents(
100n,
blocks[0].newL1ToL2Messages.map(key => key.toString()),
blocks[0].body.l1ToL2Messages.map(key => key.toString()),
),
makeL1ToL2MessageAddedEvents(
101n,
blocks[1].newL1ToL2Messages.map(key => key.toString()),
blocks[1].body.l1ToL2Messages.map(key => key.toString()),
),
makeL1ToL2MessageAddedEvents(102n, additionalL1ToL2MessagesBlock102),
makeL1ToL2MessageAddedEvents(103n, additionalL1ToL2MessagesBlock103),
Expand Down Expand Up @@ -223,7 +223,7 @@ describe('Archiver', () => {
expect(latestBlockNum).toEqual(0);

const block = L2Block.random(1, 4, 1, 2, 4, 6);
block.newL1ToL2Messages = times(2, Fr.random);
block.body.l1ToL2Messages = times(2, Fr.random);
const rollupTx = makeRollupTx(block);

publicClient.getBlockNumber.mockResolvedValueOnce(2500n);
Expand All @@ -232,7 +232,7 @@ describe('Archiver', () => {
.mockResolvedValueOnce(
makeL1ToL2MessageAddedEvents(
100n,
block.newL1ToL2Messages.map(x => x.toString()),
block.body.l1ToL2Messages.map(x => x.toString()),
),
)
.mockResolvedValueOnce([])
Expand All @@ -250,11 +250,11 @@ describe('Archiver', () => {
latestBlockNum = await archiver.getBlockNumber();
expect(latestBlockNum).toEqual(1);

const expectedL1Messages = block.newL1ToL2Messages
const expectedL1Messages = block.body.l1ToL2Messages
.concat(times(NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP - NUM_RECEIVED_L1_MESSAGES, () => Fr.ZERO))
.map(x => x.value);
const receivedBlock = await archiver.getBlock(1);
expect(receivedBlock?.newL1ToL2Messages.map(x => x.value)).toEqual(expectedL1Messages);
expect(receivedBlock?.body.l1ToL2Messages.map(x => x.value)).toEqual(expectedL1Messages);

await archiver.stop();
}, 10_000);
Expand Down Expand Up @@ -352,7 +352,7 @@ function makeRollupTx(l2Block: L2Block) {
const header = toHex(l2Block.header.toBuffer());
const archive = toHex(l2Block.archive.root.toBuffer());
const txsHash = toHex(l2Block.getCalldataHash());
const body = toHex(l2Block.bodyToBuffer());
const body = toHex(l2Block.toBuffer(true, false));
const proof = `0x`;
const input = encodeFunctionData({
abi: RollupAbi,
Expand Down
24 changes: 17 additions & 7 deletions yarn-project/archiver/src/archiver/archiver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -283,15 +283,18 @@ export class Archiver implements ArchiveSource {
this.log(`Retrieved ${retrievedBlocks.retrievedData.length} block(s) from chain`);

await Promise.all(
retrievedBlocks.retrievedData.map(block =>
this.store.addLogs(block.newEncryptedLogs, block.newUnencryptedLogs, block.number),
),
retrievedBlocks.retrievedData.map(block =>{
const encryptedLogs = new L2BlockL2Logs(block.body.txEffects.map(txEffect => txEffect.logs!.encryptedLogs));
const unencryptedLogs = new L2BlockL2Logs(block.body.txEffects.map(txEffect => txEffect.logs!.unencryptedLogs));

this.store.addLogs(encryptedLogs, unencryptedLogs, block.number);
}),
);

// Unroll all logs emitted during the retrieved blocks and extract any contract classes and instances from them
await Promise.all(
retrievedBlocks.retrievedData.map(async block => {
const blockLogs = (block.newUnencryptedLogs?.txLogs ?? [])
const blockLogs = (block.body.txEffects.flatMap(txEffect => txEffect.logs ? [txEffect.logs?.unencryptedLogs] : [] ))
.flatMap(txLog => txLog.unrollLogs())
.map(log => UnencryptedL2Log.fromBuffer(log));
await this.storeRegisteredContractClasses(blockLogs, block.number);
Expand All @@ -315,16 +318,23 @@ export class Archiver implements ArchiveSource {
// from each l2block fetch all messageKeys in a flattened array:
this.log(`Confirming l1 to l2 messages in store`);
for (const block of retrievedBlocks.retrievedData) {
await this.store.confirmL1ToL2Messages(block.newL1ToL2Messages);
await this.store.confirmL1ToL2Messages(block.body.l1ToL2Messages);
}

// store retrieved L2 blocks after removing new logs information.
// remove logs to serve "lightweight" block information. Logs can be fetched separately if needed.
await this.store.addBlocks(
retrievedBlocks.retrievedData.map(block => {
// Ensure we pad the L1 to L2 message array to the full size before storing.
block.newL1ToL2Messages = padArrayEnd(block.newL1ToL2Messages, Fr.ZERO, NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP);
return L2Block.fromFields(omit(block, ['newEncryptedLogs', 'newUnencryptedLogs']), block.getL1BlockNumber());
block.body.l1ToL2Messages = padArrayEnd(block.body.l1ToL2Messages, Fr.ZERO, NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP);

block.body.txEffects.forEach(txEffect => delete txEffect.logs);

return L2Block.fromFields({
archive: block.archive,
header: block.header,
body: block.body,
}, block.getL1BlockNumber());
}),
);
}
Expand Down
51 changes: 35 additions & 16 deletions yarn-project/archiver/src/archiver/archiver_store_test_suite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
L1ToL2Message,
L2Block,
L2BlockContext,
L2BlockL2Logs,
LogId,
LogType,
TxHash,
Expand Down Expand Up @@ -127,7 +128,7 @@ export function describeArchiverDataStore(testName: string, getStore: () => Arch
describe('addLogs', () => {
it('adds encrypted & unencrypted logs', async () => {
await expect(
store.addLogs(blocks[0].newEncryptedLogs, blocks[0].newUnencryptedLogs, blocks[0].number),
store.addLogs(new L2BlockL2Logs(blocks[0].body.txEffects.map(txEffect => txEffect.logs!.encryptedLogs)), new L2BlockL2Logs(blocks[0].body.txEffects.map(txEffect => txEffect.logs!.unencryptedLogs)), blocks[0].number),
).resolves.toEqual(true);
});
});
Expand All @@ -138,14 +139,18 @@ export function describeArchiverDataStore(testName: string, getStore: () => Arch
])('getLogs (%s)', (_, logType) => {
beforeEach(async () => {
await Promise.all(
blocks.map(block => store.addLogs(block.newEncryptedLogs, block.newUnencryptedLogs, block.number)),
blocks.map(block =>
store.addLogs(
new L2BlockL2Logs(block.body.txEffects.map(txEffect => txEffect.logs!.encryptedLogs)),
new L2BlockL2Logs(block.body.txEffects.map(txEffect => txEffect.logs!.unencryptedLogs)),
block.number,
),
),
);
});

it.each(blockTests)('retrieves previously stored logs', async (from, limit, getExpectedBlocks) => {
const expectedLogs = getExpectedBlocks().map(block =>
logType === LogType.ENCRYPTED ? block.newEncryptedLogs : block.newUnencryptedLogs,
);
const expectedLogs = getExpectedBlocks().map(block => (logType === LogType.ENCRYPTED) ? new L2BlockL2Logs(block.body.txEffects.flatMap(txEffect => txEffect.logs!.encryptedLogs)) : new L2BlockL2Logs(block.body.txEffects.flatMap(txEffect => txEffect.logs!.unencryptedLogs)))
const actualLogs = await store.getLogs(from, limit, logType);
expect(actualLogs).toEqual(expectedLogs);
});
Expand All @@ -154,7 +159,13 @@ export function describeArchiverDataStore(testName: string, getStore: () => Arch
describe('getL2Tx', () => {
beforeEach(async () => {
await Promise.all(
blocks.map(block => store.addLogs(block.newEncryptedLogs, block.newUnencryptedLogs, block.number)),
blocks.map(block =>
store.addLogs(
new L2BlockL2Logs(block.body.txEffects.map(txEffect => txEffect.logs!.encryptedLogs)),
new L2BlockL2Logs(block.body.txEffects.map(txEffect => txEffect.logs!.unencryptedLogs)),
block.number,
),
),
);
await store.addBlocks(blocks);
});
Expand Down Expand Up @@ -366,8 +377,9 @@ export function describeArchiverDataStore(testName: string, getStore: () => Arch
});

it('returns previously stored contract data', async () => {
await expect(store.getContractData(block.newContractData[0].contractAddress)).resolves.toEqual(
block.newContractData[0],
// Assuming the first (and only) contract data in the first TX
await expect(store.getContractData(block.body.txEffects[0].contractData[0].contractAddress)).resolves.toEqual(
block.body.txEffects[0].contractData[0],
);
});

Expand All @@ -384,7 +396,7 @@ export function describeArchiverDataStore(testName: string, getStore: () => Arch
});

it('returns the contract data for a known block', async () => {
await expect(store.getContractDataInBlock(block.number)).resolves.toEqual(block.newContractData);
await expect(store.getContractDataInBlock(block.number)).resolves.toEqual(block.body.txEffects.flatMap(txEffect => txEffect.contractData));
});

it('returns an empty array if contract data is not found', async () => {
Expand All @@ -409,10 +421,11 @@ export function describeArchiverDataStore(testName: string, getStore: () => Arch
const block = L2Block.random(1);
await store.addBlocks([block]);

const firstContract = ExtendedContractData.random(block.newContractData[0]);
// Assuming one contract per tx, and the first two txs
const firstContract = ExtendedContractData.random(block.body.txEffects[0].contractData[0]);
await store.addExtendedContractData([firstContract], block.number);

const secondContract = ExtendedContractData.random(block.newContractData[1]);
const secondContract = ExtendedContractData.random(block.body.txEffects[1].contractData[0]);
await store.addExtendedContractData([secondContract], block.number);

await expect(store.getExtendedContractDataInBlock(block.number)).resolves.toEqual([
Expand All @@ -427,7 +440,7 @@ export function describeArchiverDataStore(testName: string, getStore: () => Arch
let extendedContractData: ExtendedContractData;
beforeEach(async () => {
block = L2Block.random(1);
extendedContractData = ExtendedContractData.random(block.newContractData[0]);
extendedContractData = ExtendedContractData.random(block.body.txEffects[0].contractData[0]);
await store.addBlocks([block]);
await store.addExtendedContractData([extendedContractData], block.number);
});
Expand All @@ -448,7 +461,7 @@ export function describeArchiverDataStore(testName: string, getStore: () => Arch
let extendedContractData: ExtendedContractData;
beforeEach(async () => {
block = L2Block.random(1);
extendedContractData = ExtendedContractData.random(block.newContractData[0]);
extendedContractData = ExtendedContractData.random(block.body.txEffects[0].contractData[0]);
await store.addBlocks([block]);
await store.addExtendedContractData([extendedContractData], block.number);
});
Expand Down Expand Up @@ -478,7 +491,13 @@ export function describeArchiverDataStore(testName: string, getStore: () => Arch

await store.addBlocks(blocks);
await Promise.all(
blocks.map(block => store.addLogs(block.newEncryptedLogs, block.newUnencryptedLogs, block.number)),
blocks.map(block =>
store.addLogs(
new L2BlockL2Logs(block.body.txEffects.map(txEffect => txEffect.logs!.encryptedLogs)),
new L2BlockL2Logs(block.body.txEffects.map(txEffect => txEffect.logs!.unencryptedLogs)),
block.number,
),
),
);
});

Expand Down Expand Up @@ -530,7 +549,7 @@ export function describeArchiverDataStore(testName: string, getStore: () => Arch
const targetFunctionLogIndex = Math.floor(Math.random() * numPublicFunctionCalls);
const targetLogIndex = Math.floor(Math.random() * numUnencryptedLogs);
const targetContractAddress = UnencryptedL2Log.fromBuffer(
blocks[targetBlockIndex].newUnencryptedLogs!.txLogs[targetTxIndex].functionLogs[targetFunctionLogIndex].logs[
blocks[targetBlockIndex].body.txEffects[targetTxIndex].logs!.unencryptedLogs.functionLogs[targetFunctionLogIndex].logs[
targetLogIndex
],
).contractAddress;
Expand All @@ -551,7 +570,7 @@ export function describeArchiverDataStore(testName: string, getStore: () => Arch
const targetFunctionLogIndex = Math.floor(Math.random() * numPublicFunctionCalls);
const targetLogIndex = Math.floor(Math.random() * numUnencryptedLogs);
const targetSelector = UnencryptedL2Log.fromBuffer(
blocks[targetBlockIndex].newUnencryptedLogs!.txLogs[targetTxIndex].functionLogs[targetFunctionLogIndex].logs[
blocks[targetBlockIndex].body.txEffects[targetTxIndex].logs!.unencryptedLogs.functionLogs[targetFunctionLogIndex].logs[
targetLogIndex
],
).selector;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export class BlockStore {
void this.#txIndex.set(tx.txHash.toString(), [block.number, i]);
}

for (const [i, contractData] of block.newContractData.entries()) {
for (const [i, contractData] of block.body.txEffects.flatMap(txEffect => txEffect.contractData).entries()) {
if (contractData.contractAddress.isZero()) {
continue;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ export class ContractStore {
}

const block = this.#blockStore.getBlock(blockNumber);
return block?.newContractData[index];
// Assuming each txEffect only has one contract
return block?.body.txEffects[index].contractData[0];
}

/**
Expand All @@ -88,6 +89,6 @@ export class ContractStore {
*/
getContractDataInBlock(blockNumber: number): ContractData[] {
const block = this.#blockStore.getBlock(blockNumber);
return block?.newContractData ?? [];
return block?.body.txEffects.flatMap(txEffect => txEffect.contractData) ?? [];
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { L2Block } from '@aztec/circuit-types';
import { L2Block, L2BlockL2Logs } from '@aztec/circuit-types';

import { ArchiverDataStore } from '../archiver_store.js';
import { describeArchiverDataStore } from '../archiver_store_test_suite.js';
Expand All @@ -23,7 +23,13 @@ describe('MemoryArchiverStore', () => {

await archiverStore.addBlocks(blocks);
await Promise.all(
blocks.map(block => archiverStore.addLogs(block.newEncryptedLogs, block.newUnencryptedLogs, block.number)),
blocks.map(block =>
archiverStore.addLogs(
new L2BlockL2Logs(blocks[0].body.txEffects.map(txEffect => txEffect.logs!.encryptedLogs)),
new L2BlockL2Logs(blocks[0].body.txEffects.map(txEffect => txEffect.logs!.unencryptedLogs)),
block.number,
),
),
);

const response = await archiverStore.getUnencryptedLogs({});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,7 @@ export class MemoryArchiverStore implements ArchiverDataStore {
return Promise.resolve(undefined);
}
for (const blockContext of this.l2BlockContexts) {
for (const contractData of blockContext.block.newContractData) {
for (const contractData of blockContext.block.body.txEffects.flatMap(txEffect => txEffect.contractData)) {
if (contractData.contractAddress.equals(contractAddress)) {
return Promise.resolve(contractData);
}
Expand All @@ -416,7 +416,7 @@ export class MemoryArchiverStore implements ArchiverDataStore {
return Promise.resolve([]);
}
const block: L2Block | undefined = this.l2BlockContexts[l2BlockNum - INITIAL_L2_BLOCK_NUM]?.block;
return Promise.resolve(block?.newContractData);
return Promise.resolve(block?.body.txEffects.flatMap(txEffect => txEffect.contractData));
}

/**
Expand Down
16 changes: 11 additions & 5 deletions yarn-project/circuit-types/src/l2_block.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ describe('L2Block', () => {
it('can serialize an L2 block with logs to a buffer and back', () => {
const block = L2Block.random(42);

const buffer = block.toBufferWithLogs();
const recovered = L2Block.fromBufferWithLogs(buffer);
const buffer = block.toBuffer(true, true);
const recovered = L2Block.fromBuffer(buffer, true);

// TODO(#3868): encoding and decoding is currently hacked and bodyHash is not recovered yet
recovered.header.bodyHash = block.header.bodyHash;
Expand All @@ -15,9 +15,15 @@ describe('L2Block', () => {
});

it('can serialize an L2 block without logs to a buffer and back', () => {
const block = L2Block.random(42);
block.newEncryptedLogs = undefined;
block.newUnencryptedLogs = undefined;
const block = L2Block.random(
42,
4,
2,
3,
2,
1,
false,
);

const serialized = block.toString();
const recovered = L2Block.fromString(serialized);
Expand Down
Loading

0 comments on commit 2a9d399

Please sign in to comment.