Skip to content

Commit

Permalink
refactor: naming
Browse files Browse the repository at this point in the history
  • Loading branch information
benesjan committed Mar 13, 2023
1 parent b157911 commit ba6ddde
Show file tree
Hide file tree
Showing 30 changed files with 281 additions and 296 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ The Aztec 3 system consists of the following sub projects.
- `aztec.js`
- `barretenberg.js`
- `circuit.js`
- `rollup-archiver`
- `data-archiver`
- `ethereum.js`
- `kernel-simulator`
- `key-store`
Expand Down
2 changes: 1 addition & 1 deletion bootstrap.sh
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ PROJECTS=(
"yarn-project/aztec.js:yarn build"
# "yarn-project/barretenberg.js:yarn build"
# "yarn-project/circuit.js:yarn build"
# "yarn-project/rollup-archiver:yarn build"
# "yarn-project/data-archiver:yarn build"
# "yarn-project/ethereum.js:yarn build"
# "yarn-project/kernel-simulator:yarn build"
"yarn-project/key-store:yarn build"
Expand Down
8 changes: 4 additions & 4 deletions build_manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,11 @@
"rebuildPatterns": ["^yarn-project/circuit.js/"],
"dependencies": ["yarn-project-base"]
},
"rollup-archiver": {
"data-archiver": {
"buildDir": "yarn-project",
"projectDir": "yarn-project/rollup-archiver",
"dockerfile": "rollup-archiver/Dockerfile",
"rebuildPatterns": ["^yarn-project/rollup-archiver/"],
"projectDir": "yarn-project/data-archiver",
"dockerfile": "data-archiver/Dockerfile",
"rebuildPatterns": ["^yarn-project/data-archiver/"],
"dependencies": ["yarn-project-base"]
},
"end-to-end": {
Expand Down
2 changes: 1 addition & 1 deletion build_manifest.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ PROJECTS=(
# aztec.js:yarn-project
# barretenberg.js:yarn-project
# circuit.js:yarn-project
# rollup-archiver:yarn-project
# data-archiver:yarn-project
# end-to-end:yarn-project
# ethereum.js:yarn-project
# kernel-simulator:yarn-project
Expand Down
292 changes: 146 additions & 146 deletions yarn-project/.pnp.cjs

Large diffs are not rendered by default.

File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
FROM 278380418400.dkr.ecr.eu-west-2.amazonaws.com/yarn-project-base AS builder

COPY rollup-archiver rollup-archiver
WORKDIR /usr/src/yarn-project/rollup-archiver
COPY data-archiver data-archiver
WORKDIR /usr/src/yarn-project/data-archiver
RUN yarn build && yarn formatting && yarn test

# Prune dev dependencies. See comment in base image.
RUN yarn cache clean
RUN yarn workspaces focus --production > /dev/null

FROM node:18-alpine
COPY --from=builder /usr/src/yarn-project/rollup-archiver /usr/src/yarn-project/rollup-archiver
WORKDIR /usr/src/yarn-project/rollup-archiver
COPY --from=builder /usr/src/yarn-project/data-archiver /usr/src/yarn-project/data-archiver
WORKDIR /usr/src/yarn-project/data-archiver
ENTRYPOINT ["yarn"]
1 change: 1 addition & 0 deletions yarn-project/data-archiver/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Data Archiver
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "@aztec/rollup-archiver",
"name": "@aztec/data-archiver",
"version": "0.0.0",
"type": "module",
"exports": "./dest/index.js",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { getAddress } from 'viem';
import { RollupArchiver } from './rollup_archiver.js';
import { DataArchiver } from './data_archiver.js';

describe('RollupArchiver', () => {
describe('DataArchiver', () => {
const ethHost = 'http://localhost:8545/';
const rollupAddress = getAddress('0x0000000000000000000000000000000000000000');
const yeeterAddress = getAddress('0x0000000000000000000000000000000000000000');

it('can start and stop', async () => {
const rollupArchiver = new RollupArchiver(ethHost, rollupAddress, yeeterAddress);
await rollupArchiver.start();
rollupArchiver.stop();
const dataArchiver = new DataArchiver(ethHost, rollupAddress, yeeterAddress);
await dataArchiver.start();
dataArchiver.stop();
});

it('successfully syncs', async () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,30 +1,29 @@
import { Address, createPublicClient, http, parseAbiItem, PublicClient } from 'viem';
import { localhost } from 'viem/chains';
import { L2BlockData } from './l2_block_data/l2_block_data.js';
import { L2BlockSource, SyncStatus } from './l2_block_source.js';
import { createLogger } from './movetofoundation/log/console.js';
import { RollupBlockData } from './rollup_block_data/rollup_block_data.js';
import { RollupBlockSource } from './rollup_source.js';
import { State, Status } from './status.js';

/**
* Pulls rollups in a non-blocking manner and provides interface for their retrieval.
* Pulls L2 blocks in a non-blocking manner and provides interface for their retrieval.
*/
export class RollupArchiver implements Status, RollupBlockSource {
export class DataArchiver implements L2BlockSource {
/**
* A logger.
*/
private log = createLogger('Archiver');

/**
* An array containing all the rollups that have been fetched so far.
* An array containing all the L2 blocks that have been fetched so far.
*/
private rollupBlocks: RollupBlockData[] = [];
private l2Blocks: L2BlockData[] = [];

/**
* A client for interacting with the Ethereum node.
*/
private client: PublicClient;

private readonly blockEvent = parseAbiItem('event RollupBlockProcessed(uint256 indexed rollupBlockNumber)');
private readonly blockEvent = parseAbiItem('event L2BlockProcessed(uint256 indexed blockNum)');
private readonly yeetEvent = parseAbiItem(
'event Yeet(uint256 indexed blockNum, address indexed sender, bytes blabber)',
);
Expand All @@ -33,7 +32,7 @@ export class RollupArchiver implements Status, RollupBlockSource {
private unwatchYeets: (() => void) | undefined;

/**
* Creates a new instance of the RollupArchiver.
* Creates a new instance of the DataArchiver.
* @param ethereumHost - Ethereum provider
* @param rollupAddress - Ethereum address of the rollup contract
* @param yeeterAddress - Ethereum address of the yeeter contract
Expand All @@ -51,11 +50,11 @@ export class RollupArchiver implements Status, RollupBlockSource {
}

/**
* {@inheritDoc Status.state}
* {@inheritDoc L2BlockSource.getSyncStatus}
*/
public state(): State {
public getSyncStatus(): SyncStatus {
return {
syncedToBlock: this.getSyncedToBlockNum(),
syncedToBlock: -1, // TODO: fetch directly from contract
latestBlock: this.getLastBlockNum(),
};
}
Expand Down Expand Up @@ -126,7 +125,7 @@ export class RollupArchiver implements Status, RollupBlockSource {
public stop() {
this.log('Stopping...');
if (this.unwatchBlocks === undefined || this.unwatchYeets === undefined) {
throw new Error('RollupArchiver is not running.');
throw new Error('DataArchiver is not running.');
}

this.unwatchBlocks();
Expand All @@ -136,45 +135,37 @@ export class RollupArchiver implements Status, RollupBlockSource {
}

/**
* {@inheritDoc RollupBlockSource.getSyncedToBlockNum}
* {@inheritDoc L2BlockSource.getL2Blocks}
*/
public getSyncedToBlockNum(): number {
return this.rollupBlocks.length === 0 ? -1 : this.rollupBlocks[this.rollupBlocks.length - 1].rollupBlockNumber;
}

/**
* {@inheritDoc RollupBlockSource.getRollupBlocks}
*/
public getRollupBlocks(from: number, take: number): RollupBlockData[] {
if (from > this.rollupBlocks.length) {
const rollups: RollupBlockData[] = [];
return rollups;
public getL2Blocks(from: number, take: number): L2BlockData[] {
if (from > this.l2Blocks.length) {
return [];
}
if (from + take > this.rollupBlocks.length) {
return this.rollupBlocks.slice(from);
if (from + take > this.l2Blocks.length) {
return this.l2Blocks.slice(from);
}

return this.rollupBlocks.slice(from, from + take);
return this.l2Blocks.slice(from, from + take);
}

/**
* {@inheritDoc RollupBlockSource.getLastBlockNum}
* {@inheritDoc L2BlockSource.getLastBlockNum}
*/
public getLastBlockNum(): number {
// TODO: fetch the last block number from the rollup contract
return this.rollupBlocks.length + 100;
return this.l2Blocks.length + 100;
}
}

// not bothering with docs since it will be removed once L1 JS lib is in place
// function mockRandomRollupBlock(rollupBlockNumber: number): RollupBlockData {
// function mockRandomL2Block(l2BlockNum: number): L2BlockData {
// const newNullifiers = [randomBytes(32), randomBytes(32), randomBytes(32), randomBytes(32)];
// const newCommitments = [randomBytes(32), randomBytes(32), randomBytes(32), randomBytes(32)];
// const newContracts: Buffer[] = [randomBytes(32)];
// const newContractsData: ContractData[] = [randomContractData()];

// return new RollupBlockData(
// rollupBlockNumber,
// return new L2BlockData(
// l2BlockNum,
// randomAppendOnlyTreeSnapshot(0),
// randomAppendOnlyTreeSnapshot(0),
// randomAppendOnlyTreeSnapshot(0),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { getAddress } from 'viem';
import { RollupArchiver } from './rollup_archiver.js';
import { DataArchiver } from './data_archiver.js';

const {
ETHEREUM_HOST = 'http://localhost:8545/',
Expand All @@ -8,29 +8,29 @@ const {
} = process.env;

/**
* A function which instantiates and starts RollupArchiver.
* A function which instantiates and starts DataArchiver.
*/
async function main() {
const rollupAddress = getAddress(ROLLUP_ADDRESS);
const yeeterAddress = getAddress(YEETER_ADDRESS);
const rollupArchiver = new RollupArchiver(ETHEREUM_HOST, rollupAddress, yeeterAddress);
const dataArchiver = new DataArchiver(ETHEREUM_HOST, rollupAddress, yeeterAddress);

const shutdown = () => {
rollupArchiver.stop();
dataArchiver.stop();
process.exit(0);
};
process.once('SIGINT', shutdown);
process.once('SIGTERM', shutdown);

await rollupArchiver.start();
await dataArchiver.start();
}

main().then(
() => {
console.log('Rollup archiver has started successfully.');
console.log('DataArchiver has started successfully.');
},
err => {
console.error('Rollup archiver has failed to start:', err);
console.error('DataArchiver has failed to start:', err);
process.exit(1);
},
);
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { randomAppendOnlyTreeSnapshot, randomBytes, randomContractData } from './mocks.js';
import { ContractData, RollupBlockData } from './rollup_block_data.js';
import { ContractData, L2BlockData } from './l2_block_data.js';

describe('RollupProofData', () => {
it('can encode a rollup proof data object to buffer and back', () => {
describe('L2BlockData', () => {
it('can encode a L2 block data object to buffer and back', () => {
const newNullifiers = [randomBytes(32), randomBytes(32), randomBytes(32), randomBytes(32)];
const newCommitments = [randomBytes(32), randomBytes(32), randomBytes(32), randomBytes(32)];
const newContracts: Buffer[] = [randomBytes(32)];
const newContractsData: ContractData[] = [randomContractData()];

const rollupProofData = new RollupBlockData(
const l2BlockData = new L2BlockData(
0,
randomAppendOnlyTreeSnapshot(0),
randomAppendOnlyTreeSnapshot(0),
Expand All @@ -26,9 +26,9 @@ describe('RollupProofData', () => {
newContractsData,
);

const buffer = rollupProofData.encode();
const recovered = RollupBlockData.decode(buffer);
const buffer = l2BlockData.encode();
const recovered = L2BlockData.decode(buffer);

expect(recovered).toEqual(rollupProofData);
expect(recovered).toEqual(l2BlockData);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ export type ContractData = {
/**
* The data that makes up the rollup proof, with encoder decoder functions.
*/
export class RollupBlockData {
export class L2BlockData {
/**
* Construct a new RollupBlockData object.
* Construct a new L2BlockData object.
* The data that goes into the rollup, BUT without the proof.
* @param rollupBlockNumber - The number of the rollup block.
* @param number - The number of the L2 block.
* @param startPrivateDataTreeSnapshot - The tree snapshot of the private data tree at the start of the rollup.
* @param startNullifierTreeSnapshot - The tree snapshot of the nullifier tree at the start of the rollup.
* @param startContractTreeSnapshot - The tree snapshot of the contract tree at the start of the rollup.
Expand All @@ -50,7 +50,7 @@ export class RollupBlockData {
* @param newContractData - The aztec_address and eth_address for the deployed contract and its portal contract.
*/
constructor(
public rollupBlockNumber: number,
public number: number,
public startPrivateDataTreeSnapshot: AppendOnlyTreeSnapshot,
public startNullifierTreeSnapshot: AppendOnlyTreeSnapshot,
public startContractTreeSnapshot: AppendOnlyTreeSnapshot,
Expand All @@ -68,12 +68,12 @@ export class RollupBlockData {
) {}

/**
* Encode the rollup block data into a buffer that can be pushed to the rollup contract.
* @returns The encoded rollup block data.
* Encode the L2 block data into a buffer that can be pushed to the rollup contract.
* @returns The encoded L2 block data.
*/
encode(): Buffer {
return Buffer.concat([
numToUInt32BE(this.rollupBlockNumber),
numToUInt32BE(this.number),
appendOnlyTreeSnapshotToBuffer(this.startPrivateDataTreeSnapshot),
appendOnlyTreeSnapshotToBuffer(this.startNullifierTreeSnapshot),
appendOnlyTreeSnapshotToBuffer(this.startContractTreeSnapshot),
Expand All @@ -95,9 +95,9 @@ export class RollupBlockData {
}

/**
* Decode the rollup block data from a buffer.
* @param encoded - The encoded rollup block data.
* @returns The decoded rollup block data.
* Decode the L2 block data from a buffer.
* @param encoded - The encoded L2 block data.
* @returns The decoded L2 block data.
*/
static decode(encoded: Buffer) {
let offset = 0;
Expand Down Expand Up @@ -161,7 +161,7 @@ export class RollupBlockData {
offset += 52;
}

return new RollupBlockData(
return new L2BlockData(
rollupId,
startPrivateDataTreeSnapshot,
startNullifierTreeSnapshot,
Expand Down Expand Up @@ -252,7 +252,7 @@ export function numToUInt32BE(n: number, bufferSize = 4): Buffer {
/**
* The fixed size data that makes up the rollup header.
*/
export type RollupBlockCalldataHeader = {
export type L2BlockCalldataHeader = {
/**
* The id of the rollup.
* Similar to the block number in Ethereum.
Expand Down Expand Up @@ -305,11 +305,11 @@ export type RollupBlockCalldataHeader = {
/**
* The data that makes up the rollup calldata.
*/
export type RollupBlockCalldata = {
export type L2BlockCalldata = {
/**
* The header of the rollup calldata.
*/
header: RollupBlockCalldataHeader;
header: L2BlockCalldataHeader;
/**
* The commitments to be inserted into the private data tree.
* The commitments are field elements, and 4 commitments are inserted for each kernel proof.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import nodeCrypto from 'crypto';
import { AppendOnlyTreeSnapshot, ContractData } from './rollup_block_data.js';
import { AppendOnlyTreeSnapshot, ContractData } from './l2_block_data.js';

export const randomBytes = (len: number) => {
return nodeCrypto.randomBytes(len) as Buffer;
Expand Down
Loading

0 comments on commit ba6ddde

Please sign in to comment.