Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pw/world state sync #66

Merged
merged 39 commits into from
Mar 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
08096db
Initial work on synching world state
PhilWindle Mar 8, 2023
6271d53
WIP
PhilWindle Mar 8, 2023
24de9a7
WIP
PhilWindle Mar 14, 2023
0f0d837
WIP
PhilWindle Mar 16, 2023
68667f6
Merge branch 'master' into pw/world-state-sync
PhilWindle Mar 16, 2023
6eeba71
WIP
PhilWindle Mar 16, 2023
a5a0198
docs: fixed memory_fifo docs
benesjan Mar 16, 2023
047e305
refactor+docs: updated naming + fixed docs in L2BlockDownloader
benesjan Mar 16, 2023
f4ffdab
refactor+docs: updated naming + fixed docs in Synchronizer
benesjan Mar 16, 2023
bc29ca1
docs: fixed Semaphore docs
benesjan Mar 16, 2023
adaf815
docs: fixed SerialQueue docs
benesjan Mar 16, 2023
9dcae59
docs: fixed docs in InterruptableSleep
benesjan Mar 16, 2023
785ae6b
docs: fixed WorldStateSynchroniser interface
benesjan Mar 16, 2023
06b2d9e
docs: fixed WorldStatedB docs
benesjan Mar 16, 2023
2317722
docs: finished fixing world state docs
benesjan Mar 16, 2023
3c4f960
docs: fixed StandardMerkleTree docs
benesjan Mar 16, 2023
7e298af
docs: fixed SiblingPath docs
benesjan Mar 16, 2023
93bd248
docs: fixed docs of serialise.ts
benesjan Mar 16, 2023
f1ab5f8
docs: fixed MerkleTree docs
benesjan Mar 16, 2023
f8914cf
docs: fixed IndexedTree docs
benesjan Mar 17, 2023
bd35504
docs: other merkle tree fixes
benesjan Mar 17, 2023
f5371a2
docs: fixed archiver
benesjan Mar 17, 2023
68425e7
docs: fixed running promise docs
benesjan Mar 17, 2023
0a10ce4
WIP
PhilWindle Mar 21, 2023
a1a7d34
P2P module (#36)
spypsy Mar 21, 2023
20219b2
WIP
PhilWindle Mar 21, 2023
0b4e038
WIP
PhilWindle Mar 21, 2023
d4edd62
Merge branch 'master' into pw/world-state-sync
PhilWindle Mar 21, 2023
3866df1
WIP
PhilWindle Mar 22, 2023
deaf130
WIP
PhilWindle Mar 22, 2023
1b48d98
Merge branch 'master' into pw/world-state-sync
PhilWindle Mar 23, 2023
32f8944
WIP
PhilWindle Mar 23, 2023
ca8d49a
WIP
PhilWindle Mar 23, 2023
1cfe801
WIP
PhilWindle Mar 23, 2023
f1cb1b0
Renamed public client
PhilWindle Mar 23, 2023
a282329
Removed serialisation code from merkle tree project
PhilWindle Mar 23, 2023
3b9fd04
WIP
PhilWindle Mar 23, 2023
90fe84a
WIP
PhilWindle Mar 23, 2023
7e054c3
WIP
PhilWindle Mar 23, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,9 @@
[submodule "l1-contracts"]
path = l1-contracts
url = [email protected]:AztecProtocol/aztec3-l1-contracts.git
[submodule "barretenberg"]
path = barretenberg
url = [email protected]:AztecProtocol/barretenberg.git
[submodule "yarn-project/foundation"]
path = yarn-project/foundation
url = [email protected]:AztecProtocol/foundation.git
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ The Aztec 3 system consists of the following sub projects.
- `key-store`
- `p2p`
- `prover-client`
- `public-client`
- `aztec-node`
- `sequencer-client`
- `wallet`
1 change: 1 addition & 0 deletions barretenberg
Submodule barretenberg added at f2f8d1
9 changes: 6 additions & 3 deletions bootstrap.sh
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,17 @@ PROJECTS=(
# "yarn-project/aztec-cli:yarn build"
"yarn-project/aztec.js:yarn build"
"yarn-project/archiver:yarn build"
# "yarn-project/ethereum.js:yarn build"
"yarn-project/ethereum.js:yarn build"
"yarn-project/foundation:yarn build"
# "yarn-project/kernel-simulator:yarn build"
"yarn-project/key-store:yarn build"
# "yarn-project/p2p:yarn build"
"yarn-project/merkle-tree:yarn build"
"yarn-project/p2p:yarn build"
# "yarn-project/prover-client:yarn build"
# "yarn-project/public-client:yarn build"
"yarn-project/aztec-node:yarn build"
# "yarn-project/sequencer-client:yarn build"
# "yarn-project/wallet:yarn build"
"yarn-project/world-state:yarn build"
)

for E in "${PROJECTS[@]}"; do
Expand Down
2 changes: 1 addition & 1 deletion build-system
Submodule build-system updated 1 files
+5 −1 README.md
26 changes: 20 additions & 6 deletions build_manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
"projectDir": "yarn-project/archiver",
"dockerfile": "archiver/Dockerfile",
"rebuildPatterns": ["^yarn-project/archiver/"],
"dependencies": ["yarn-project-base"]
"dependencies": ["yarn-project-base", "ethereum.js"]
},
"aztec-cli": {
"buildDir": "yarn-project",
Expand Down Expand Up @@ -94,6 +94,13 @@
"rebuildPatterns": ["^yarn-project/key-store/"],
"dependencies": ["yarn-project-base"]
},
"merkle-tree": {
"buildDir": "yarn-project",
"projectDir": "yarn-project/merkle-tree",
"dockerfile": "merkle-tree/Dockerfile",
"rebuildPatterns": ["^yarn-project/merkle-tree/"],
"dependencies": ["yarn-project-base", "foundation"]
},
"noir-contracts": {
"buildDir": "yarn-project",
"projectDir": "yarn-project/noir-contracts",
Expand All @@ -106,7 +113,7 @@
"projectDir": "yarn-project/p2p",
"dockerfile": "p2p/Dockerfile",
"rebuildPatterns": ["^yarn-project/p2p/"],
"dependencies": ["yarn-project-base"]
"dependencies": ["yarn-project-base", "archiver"]
},
"prover-client": {
"buildDir": "yarn-project",
Expand All @@ -115,11 +122,11 @@
"rebuildPatterns": ["^yarn-project/prover-client/"],
"dependencies": ["yarn-project-base"]
},
"public-client": {
"aztec-node": {
"buildDir": "yarn-project",
"projectDir": "yarn-project/public-client",
"dockerfile": "public-client/Dockerfile",
"rebuildPatterns": ["^yarn-project/public-client/"],
"projectDir": "yarn-project/aztec-node",
"dockerfile": "aztec-node/Dockerfile",
"rebuildPatterns": ["^yarn-project/aztec-node/"],
"dependencies": ["yarn-project-base"]
},
"sequencer-client": {
Expand All @@ -135,5 +142,12 @@
"dockerfile": "wallet/Dockerfile",
"rebuildPatterns": ["^yarn-project/wallet/"],
"dependencies": ["yarn-project-base"]
},
"world-state": {
"buildDir": "yarn-project",
"projectDir": "yarn-project/world-state",
"dockerfile": "world-state/Dockerfile",
"rebuildPatterns": ["^yarn-project/world-state/"],
"dependencies": ["yarn-project-base", "merkle-tree"]
}
}
4 changes: 3 additions & 1 deletion build_manifest.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,11 @@ PROJECTS=(
# ethereum.js:yarn-project
# kernel-simulator:yarn-project
# key-store:yarn-project
# merkle-tree:yarn-project
# p2p:yarn-project
# prover-client:yarn-project
# public-client:yarn-project
# aztec-node:yarn-project
# sequencer-client:yarn-project
# wallet:yarn-project
# world-state:yarn-project
)
3 changes: 0 additions & 3 deletions yarn-project/archiver/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,3 @@ To run:
2. in the aztec3-l1-contracts repo check out my branch `janb/archiver-test-data`,
3. deploy the contracts and generate initial activity with: `forge script --fork-url "http://127.0.0.1:8545/" --ffi GenerateActivityTest --sig "testGenerateActivity()" --private-key 0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80 --broadcast`
4. in this repository run `yarn start:dev` (Note: this repo is currently messy and eslint will not allow it to be built with `yarn start`)

Relevant unresolved issues:
https://stackoverflow.com/questions/75739742/why-is-eslint-complaining-about-inheritdoc-tag
2 changes: 2 additions & 0 deletions yarn-project/archiver/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
"rootDir": "./src"
},
"dependencies": {
"@aztec/ethereum.js": "workspace:^",
"@aztec/foundation": "workspace:^",
"debug": "^4.3.4",
"tsc-watch": "^6.0.0",
"tslib": "^2.5.0",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import { EthAddress } from '@aztec/ethereum.js/eth_address';
import { jest } from '@jest/globals';
import { getAddress, PublicClient } from 'viem';
import { PublicClient } from 'viem';
import { Archiver } from './archiver.js';

jest.mock('viem');

describe('Archiver', () => {
const rollupAddress = getAddress('0x0000000000000000000000000000000000000000');
const yeeterAddress = getAddress('0x0000000000000000000000000000000000000000');
const rollupAddress = '0x0000000000000000000000000000000000000000';
const yeeterAddress = '0x0000000000000000000000000000000000000000';
let publicClient: PublicClient;

beforeEach(() => {
Expand Down Expand Up @@ -35,9 +36,13 @@ describe('Archiver', () => {
});

it('can start, sync and stop', async () => {
const archiver = new Archiver(publicClient, rollupAddress, yeeterAddress);
const archiver = new Archiver(
publicClient,
EthAddress.fromString(rollupAddress),
EthAddress.fromString(yeeterAddress),
);
let syncStatus = await archiver.getSyncStatus();
let latestBlockNum = archiver.getLatestBlockNum();
let latestBlockNum = await archiver.getLatestBlockNum();
expect(syncStatus).toStrictEqual({
syncedToBlock: -1,
latestBlock: 2,
Expand All @@ -47,13 +52,13 @@ describe('Archiver', () => {
await archiver.start();

syncStatus = await archiver.getSyncStatus();
latestBlockNum = archiver.getLatestBlockNum();
latestBlockNum = await archiver.getLatestBlockNum();
expect(syncStatus).toStrictEqual({
syncedToBlock: 2,
latestBlock: 2,
});
expect(latestBlockNum).toBe(syncStatus.syncedToBlock);

archiver.stop();
await archiver.stop();
});
});
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import { Address, PublicClient } from 'viem';
import { rollupAbi } from './abis/rollup.js';
import { yeeterAbi } from './abis/yeeter.js';
import { ContractData, L2Block } from './l2_block/l2_block.js';
import { randomAppendOnlyTreeSnapshot, randomBytes, randomContractData } from './l2_block/mocks.js';
import { L2BlockSource, SyncStatus } from './l2_block_source.js';
import { createLogger } from './movetofoundation/log/console.js';
import { PublicClient, getAddress, http, createPublicClient } from 'viem';
import { rollupAbi } from '../abis/rollup.js';
import { yeeterAbi } from '../abis/yeeter.js';
import { ContractData, L2Block } from '../l2_block/l2_block.js';
import { randomAppendOnlyTreeSnapshot, randomBytes, randomContractData } from '../l2_block/mocks.js';
import { L2BlockSource, L2BlockSourceSyncStatus } from '../l2_block/l2_block_source.js';
import { EthAddress } from '@aztec/ethereum.js/eth_address';
import { localhost } from 'viem/chains';
import { createDebugLogger } from '@aztec/foundation';

/**
* Pulls L2 blocks in a non-blocking manner and provides interface for their retrieval.
Expand Down Expand Up @@ -33,23 +35,39 @@ export class Archiver implements L2BlockSource {
*/
constructor(
private readonly publicClient: PublicClient,
private readonly rollupAddress: Address,
private readonly yeeterAddress: Address,
private readonly log = createLogger('Archiver'),
private readonly rollupAddress: EthAddress,
private readonly yeeterAddress: EthAddress,
private readonly log = createDebugLogger('aztec:archiver'),
) {}

/**
* {@inheritDoc L2BlockSource.getSyncStatus}
* Creates a new instance of the Archiver.
* @param rpcUrl - The RPC url for connecting to an eth node.
* @param rollupAddress - Ethereum address of the rollup contract.
* @param yeeterAddress - Ethereum address of the yeeter contract.
* @returns - An instance of the archiver.
*/
public static new(rpcUrl: string, rollupAddress: EthAddress, yeeterAddress: EthAddress) {
const publicClient = createPublicClient({
chain: localhost,
transport: http(rpcUrl),
});
return new Archiver(publicClient, rollupAddress, yeeterAddress);
}

/**
* Gets the sync status of the L2 block source.
* @returns The sync status of the L2 block source.
*/
public async getSyncStatus(): Promise<SyncStatus> {
public async getSyncStatus(): Promise<L2BlockSourceSyncStatus> {
const nextBlockNum = await this.publicClient.readContract({
address: this.rollupAddress,
address: getAddress(this.rollupAddress.toString()),
abi: rollupAbi,
functionName: 'nextBlockNum',
});

return {
syncedToBlock: this.getLatestBlockNum(),
syncedToBlock: await this.getLatestBlockNum(),
latestBlock: Number(nextBlockNum) - 1,
};
}
Expand All @@ -70,13 +88,13 @@ export class Archiver implements L2BlockSource {
*/
private async runInitialSync() {
const blockFilter = await this.publicClient.createEventFilter({
address: this.rollupAddress,
address: getAddress(this.rollupAddress.toString()),
fromBlock: 0n,
event: rollupAbi[0],
});

const yeetFilter = await this.publicClient.createEventFilter({
address: this.yeeterAddress,
address: getAddress(this.yeeterAddress.toString()),
event: yeeterAbi[0],
fromBlock: 0n,
});
Expand All @@ -93,13 +111,13 @@ export class Archiver implements L2BlockSource {
*/
private startWatchingEvents() {
this.unwatchBlocks = this.publicClient.watchEvent({
address: this.rollupAddress,
address: getAddress(this.rollupAddress.toString()),
event: rollupAbi[0],
onLogs: logs => this.processBlockLogs(logs),
});

this.unwatchYeets = this.publicClient.watchEvent({
address: this.yeeterAddress,
address: getAddress(this.yeeterAddress.toString()),
event: yeeterAbi[0],
onLogs: logs => this.processYeetLogs(logs),
});
Expand Down Expand Up @@ -147,9 +165,10 @@ export class Archiver implements L2BlockSource {
}

/**
* Stops the event polling loop.
* Stops the archiver.
* @returns A promise signalling completion of the stop process.
*/
public stop() {
public stop(): Promise<void> {
this.log('Stopping...');
if (this.unwatchBlocks === undefined || this.unwatchYeets === undefined) {
throw new Error('Archiver is not running.');
Expand All @@ -159,27 +178,32 @@ export class Archiver implements L2BlockSource {
this.unwatchYeets();

this.log('Stopped.');
return Promise.resolve();
}

/**
* {@inheritDoc L2BlockSource.getL2Blocks}
* Gets the `take` amount of L2 blocks starting from `from`.
* @param from - If of the first rollup to return (inclusive).
* @param take - The number of blocks to return.
* @returns The requested L2 blocks.
*/
public getL2Blocks(from: number, take: number): L2Block[] {
public getL2Blocks(from: number, take: number): Promise<L2Block[]> {
if (from > this.l2Blocks.length) {
return [];
return Promise.resolve([]);
}
if (from + take > this.l2Blocks.length) {
return this.l2Blocks.slice(from);
return Promise.resolve(this.l2Blocks.slice(from));
}

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

/**
* {@inheritDoc L2BlockSource.getLatestBlockNum}
* Gets the number of the latest L2 block processed by the block source implementation.
* @returns The number of the latest L2 block processed by the block source implementation.
*/
public getLatestBlockNum(): number {
return this.l2Blocks.length - 1;
public getLatestBlockNum(): Promise<number> {
return Promise.resolve(this.l2Blocks.length - 1);
}
}

Expand Down
1 change: 1 addition & 0 deletions yarn-project/archiver/src/archiver/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './archiver.js';
1 change: 1 addition & 0 deletions yarn-project/archiver/src/block_downloader/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './l2_block_downloader.js';
Loading