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

feat: Standalone Aztec Node and RPC Server #2522

Merged
merged 47 commits into from
Sep 26, 2023
Merged
Show file tree
Hide file tree
Changes from 39 commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
9b02d53
WIP
PhilWindle Sep 8, 2023
5798a4a
WIP
PhilWindle Sep 11, 2023
2107fb6
Merge branch 'master' into pw/devnet
PhilWindle Sep 22, 2023
bb04391
WIP
PhilWindle Sep 23, 2023
61594a1
Merge branch 'master' into pw/devnet
PhilWindle Sep 23, 2023
ed810e7
Fix
PhilWindle Sep 23, 2023
5e6e8b2
Merge fixes
PhilWindle Sep 23, 2023
3b9e08e
Fixes
PhilWindle Sep 23, 2023
4518654
Fix
PhilWindle Sep 23, 2023
1343d91
fix
PhilWindle Sep 23, 2023
f2821aa
Update version
PhilWindle Sep 23, 2023
0223f16
yarn lock
PhilWindle Sep 23, 2023
a11de0f
Fix
PhilWindle Sep 23, 2023
395f24e
WIP
PhilWindle Sep 24, 2023
6dfee39
Fix
PhilWindle Sep 24, 2023
7fbc059
Fix
PhilWindle Sep 24, 2023
51ab998
Serialise node info
PhilWindle Sep 24, 2023
236634e
Fixes
PhilWindle Sep 24, 2023
ec7ef72
Fixes
PhilWindle Sep 24, 2023
f65c0fa
WIP
PhilWindle Sep 25, 2023
f98b077
Merge branch 'master' into pw/devnet
PhilWindle Sep 25, 2023
657b780
WIP
PhilWindle Sep 25, 2023
ee9f7d2
Merge branch 'master' into pw/devnet
PhilWindle Sep 25, 2023
c9f7c27
Remove old terraform
PhilWindle Sep 25, 2023
5c7336f
WIP
PhilWindle Sep 25, 2023
471159b
Cleanup
PhilWindle Sep 25, 2023
1c9da9a
Refactor
PhilWindle Sep 26, 2023
fa0b43a
Fixes
PhilWindle Sep 26, 2023
6042766
Updated lock file
PhilWindle Sep 26, 2023
a0ff7a3
Fix
PhilWindle Sep 26, 2023
f14ead4
Refactor
PhilWindle Sep 26, 2023
cd35270
Refactoring
PhilWindle Sep 26, 2023
ee4f11d
Don't default the entrypoint command
PhilWindle Sep 26, 2023
fd346e8
Removed unused code
PhilWindle Sep 26, 2023
90e3154
Removed unused code
PhilWindle Sep 26, 2023
fc1ef8f
Merge branch 'master' into pw/revert-l1-addresses
PhilWindle Sep 26, 2023
8fce9db
Yarn lock file
PhilWindle Sep 26, 2023
99350cf
Merge branch 'master' into pw/revert-l1-addresses
PhilWindle Sep 26, 2023
72089ae
Merge fix
PhilWindle Sep 26, 2023
e644544
Cleanup
PhilWindle Sep 26, 2023
f3d354f
Cleanup
PhilWindle Sep 26, 2023
dc531c1
Cleanup
PhilWindle Sep 26, 2023
2a87895
Cleanup
PhilWindle Sep 26, 2023
ce74c31
Cleanup
PhilWindle Sep 26, 2023
776967f
Merge branch 'master' into pw/revert-l1-addresses
PhilWindle Sep 26, 2023
4471ee2
Bump ts version in docs
PhilWindle Sep 26, 2023
aad1429
Merge branch 'pw/revert-l1-addresses' of github.com:AztecProtocol/azt…
PhilWindle Sep 26, 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
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ node_modules
build/
.idea
cmake-build-debug
.bootstrapped
.terraform
.bootstrapped
8 changes: 4 additions & 4 deletions yarn-project/archiver/src/archiver/archiver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,10 @@ export class Archiver implements L2BlockSource, L2LogsSource, ContractDataSource
const archiverStore = new MemoryArchiverStore();
const archiver = new Archiver(
publicClient,
config.rollupContract,
config.inboxContract,
config.registryContract,
config.contractDeploymentEmitterContract,
config.l1Contracts.rollupAddress,
config.l1Contracts.inboxAddress,
config.l1Contracts.registryAddress,
config.l1Contracts.contractDeploymentEmitterAddress,
config.searchStartBlock,
archiverStore,
config.archiverPollingIntervalMS,
Expand Down
27 changes: 19 additions & 8 deletions yarn-project/archiver/src/archiver/config.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { L1ContractAddresses } from '@aztec/ethereum';
import { EthAddress } from '@aztec/foundation/eth-address';
import { L1Addresses } from '@aztec/types';

/**
* There are 2 polling intervals used in this configuration. The first is the archiver polling interval, archiverPollingIntervalMS.
Expand All @@ -11,7 +11,7 @@ import { L1Addresses } from '@aztec/types';
/**
* The archiver configuration.
*/
export interface ArchiverConfig extends L1Addresses {
export interface ArchiverConfig {
/**
* The url of the Ethereum RPC node.
*/
Expand All @@ -36,6 +36,11 @@ export interface ArchiverConfig extends L1Addresses {
* Eth block from which we start scanning for L2Blocks.
*/
searchStartBlock: number;

/**
* The deployed L1 contract addresses
*/
l1Contracts: L1ContractAddresses;
}

/**
Expand All @@ -55,17 +60,23 @@ export function getConfigEnvVars(): ArchiverConfig {
INBOX_CONTRACT_ADDRESS,
REGISTRY_CONTRACT_ADDRESS,
} = process.env;
// Populate the relevant addresses for use by the archiver.
const addresses: L1ContractAddresses = {
rollupAddress: ROLLUP_CONTRACT_ADDRESS ? EthAddress.fromString(ROLLUP_CONTRACT_ADDRESS) : EthAddress.ZERO,
registryAddress: REGISTRY_CONTRACT_ADDRESS ? EthAddress.fromString(REGISTRY_CONTRACT_ADDRESS) : EthAddress.ZERO,
inboxAddress: INBOX_CONTRACT_ADDRESS ? EthAddress.fromString(INBOX_CONTRACT_ADDRESS) : EthAddress.ZERO,
outboxAddress: EthAddress.ZERO,
contractDeploymentEmitterAddress: CONTRACT_DEPLOYMENT_EMITTER_ADDRESS
? EthAddress.fromString(CONTRACT_DEPLOYMENT_EMITTER_ADDRESS)
: EthAddress.ZERO,
decoderHelperAddress: EthAddress.ZERO,
};
return {
rpcUrl: ETHEREUM_HOST || 'http://127.0.0.1:8545/',
archiverPollingIntervalMS: ARCHIVER_POLLING_INTERVAL_MS ? +ARCHIVER_POLLING_INTERVAL_MS : 1_000,
viemPollingIntervalMS: ARCHIVER_VIEM_POLLING_INTERVAL_MS ? +ARCHIVER_VIEM_POLLING_INTERVAL_MS : 1_000,
rollupContract: ROLLUP_CONTRACT_ADDRESS ? EthAddress.fromString(ROLLUP_CONTRACT_ADDRESS) : EthAddress.ZERO,
registryContract: REGISTRY_CONTRACT_ADDRESS ? EthAddress.fromString(REGISTRY_CONTRACT_ADDRESS) : EthAddress.ZERO,
inboxContract: INBOX_CONTRACT_ADDRESS ? EthAddress.fromString(INBOX_CONTRACT_ADDRESS) : EthAddress.ZERO,
contractDeploymentEmitterContract: CONTRACT_DEPLOYMENT_EMITTER_ADDRESS
? EthAddress.fromString(CONTRACT_DEPLOYMENT_EMITTER_ADDRESS)
: EthAddress.ZERO,
searchStartBlock: SEARCH_START_BLOCK ? +SEARCH_START_BLOCK : 0,
apiKey: API_KEY,
l1Contracts: addresses,
};
}
17 changes: 5 additions & 12 deletions yarn-project/archiver/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,7 @@ const log = createDebugLogger('aztec:archiver');
// eslint-disable-next-line require-await
async function main() {
const config = getConfigEnvVars();
const {
rpcUrl,
rollupContract,
inboxContract,
registryContract,
contractDeploymentEmitterContract,
searchStartBlock,
} = config;
const { rpcUrl, l1Contracts, searchStartBlock } = config;

const publicClient = createPublicClient({
chain: localhost,
Expand All @@ -35,10 +28,10 @@ async function main() {

const archiver = new Archiver(
publicClient,
rollupContract,
inboxContract,
registryContract,
contractDeploymentEmitterContract,
l1Contracts.rollupAddress,
l1Contracts.inboxAddress,
l1Contracts.registryAddress,
l1Contracts.contractDeploymentEmitterAddress,
searchStartBlock,
archiverStore,
);
Expand Down
5 changes: 3 additions & 2 deletions yarn-project/aztec-node/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ RUN yarn cache clean
RUN yarn workspaces focus --production > /dev/null

FROM node:18-alpine
COPY --from=builder /usr/src/yarn-project/aztec-node /usr/src/yarn-project/aztec-node
COPY --from=builder /usr/src /usr/src
WORKDIR /usr/src/yarn-project/aztec-node
ENTRYPOINT ["yarn"]
ENTRYPOINT ["yarn"]
CMD [ "start" ]
5 changes: 5 additions & 0 deletions yarn-project/aztec-node/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"main": "dest/index.js",
"type": "module",
"exports": "./dest/index.js",
"bin": "./dest/bin/index.js",
"typedocOptions": {
"entryPoints": [
"./src/index.ts"
Expand All @@ -12,6 +13,7 @@
"tsconfig": "./tsconfig.json"
},
"scripts": {
"start": "node --no-warnings ./dest/bin",
"build": "yarn clean && tsc -b",
"build:dev": "tsc -b --watch",
"clean": "rm -rf ./dest .tsbuildinfo",
Expand All @@ -33,13 +35,16 @@
"dependencies": {
"@aztec/archiver": "workspace:^",
"@aztec/circuits.js": "workspace:^",
"@aztec/ethereum": "workspace:^",
"@aztec/foundation": "workspace:^",
"@aztec/l1-artifacts": "workspace:^",
"@aztec/merkle-tree": "workspace:^",
"@aztec/p2p": "workspace:^",
"@aztec/sequencer-client": "workspace:^",
"@aztec/types": "workspace:^",
"@aztec/world-state": "workspace:^",
"koa": "^2.14.2",
"koa-router": "^12.0.0",
"tslib": "^2.4.0"
},
"devDependencies": {
Expand Down
26 changes: 12 additions & 14 deletions yarn-project/aztec-node/src/aztec-node/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ import { Archiver } from '@aztec/archiver';
import {
CONTRACT_TREE_HEIGHT,
CircuitsWasm,
EthAddress,
Fr,
GlobalVariables,
HistoricBlockData,
L1_TO_L2_MSG_TREE_HEIGHT,
PRIVATE_DATA_TREE_HEIGHT,
} from '@aztec/circuits.js';
import { L1ContractAddresses } from '@aztec/ethereum';
import { AztecAddress } from '@aztec/foundation/aztec-address';
import { createDebugLogger } from '@aztec/foundation/log';
import { InMemoryTxPool, P2P, createP2PClient } from '@aztec/p2p';
Expand Down Expand Up @@ -57,6 +57,7 @@ export const createMemDown = () => (memdown as any)() as MemDown<any, any>;
*/
export class AztecNodeService implements AztecNode {
constructor(
protected config: AztecNodeConfig,
protected p2pClient: P2P,
protected blockSource: L2BlockSource,
protected encryptedLogsSource: L2LogsSource,
Expand All @@ -83,7 +84,7 @@ export class AztecNodeService implements AztecNode {

// we identify the P2P transaction protocol by using the rollup contract address.
// this may well change in future
config.transactionProtocol = `/aztec/tx/${config.rollupContract.toString()}`;
config.transactionProtocol = `/aztec/tx/${config.l1Contracts.rollupAddress.toString()}`;

// create the tx pool and the p2p client, which will need the l2 block source
const p2pClient = await createP2PClient(config, new InMemoryTxPool(), archiver);
Expand All @@ -107,6 +108,7 @@ export class AztecNodeService implements AztecNode {
archiver,
);
return new AztecNodeService(
config,
p2pClient,
archiver,
archiver,
Expand All @@ -122,6 +124,14 @@ export class AztecNodeService implements AztecNode {
);
}

/**
* Method to return the currently deployed L1 contract addresses.
* @returns - The currently deployed L1 contract addresses.
*/
public getL1ContractAddresses(): Promise<L1ContractAddresses> {
return Promise.resolve(this.config.l1Contracts);
}

/**
* Method to determine if the node is ready to accept transactions.
* @returns - Flag indicating the readiness for tx submission.
Expand Down Expand Up @@ -173,18 +183,6 @@ export class AztecNodeService implements AztecNode {
return Promise.resolve(this.chainId);
}

/**
* Method to fetch the rollup contract address at the base-layer.
* @returns The rollup address.
*/
public getRollupAddress(): Promise<EthAddress> {
return this.blockSource.getRollupAddress();
}

public getRegistryAddress(): Promise<EthAddress> {
return this.blockSource.getRegistryAddress();
}

/**
* Get the extended contract data for this contract.
* @param contractAddress - The contract data address.
Expand Down
67 changes: 67 additions & 0 deletions yarn-project/aztec-node/src/bin/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
#!/usr/bin/env -S node --no-warnings
import { createDebugLogger } from '@aztec/foundation/log';

import http from 'http';
import Koa from 'koa';
import Router from 'koa-router';

import { AztecNodeConfig, AztecNodeService, getConfigEnvVars, createAztecNodeRpcServer } from '../index.js';

const { SERVER_PORT = 8081, API_PREFIX = '' } = process.env;

const logger = createDebugLogger('aztec:node');

/**
* Creates the node from provided config
*/
async function createAndDeployAztecNode() {
const aztecNodeConfig: AztecNodeConfig = { ...getConfigEnvVars() };

return await AztecNodeService.createAndSync(aztecNodeConfig);
}

/**
* Creates a router for helper API endpoints of the Aztec RPC Server.
* @param apiPrefix - The prefix to use for all api requests
* @returns - The router for handling status requests.
*/
export function createStatusRouter(apiPrefix: string) {
const router = new Router({ prefix: `${apiPrefix}` });
router.get('/status', (ctx: Koa.Context) => {
ctx.status = 200;
});
return router;
}

/**
* Create and start a new Aztec Node HTTP Server
*/
async function main() {
logger.info(`Setting up Aztec Node...`);

const aztecNode = await createAndDeployAztecNode();

const shutdown = async () => {
logger.info('Shutting down...');
await aztecNode.stop();
process.exit(0);
};

process.once('SIGINT', shutdown);
process.once('SIGTERM', shutdown);

const rpcServer = createAztecNodeRpcServer(aztecNode);
const app = rpcServer.getApp(API_PREFIX);
const apiRouter = createStatusRouter(API_PREFIX);
app.use(apiRouter.routes());
app.use(apiRouter.allowedMethods());

const httpServer = http.createServer(app.callback());
httpServer.listen(+SERVER_PORT);
logger.info(`Aztec Node JSON-RPC Server listening on port ${SERVER_PORT}`);
}

main().catch(err => {
logger.error(err);
process.exit(1);
});
3 changes: 1 addition & 2 deletions yarn-project/aztec-node/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
export * from './aztec-node/config.js';
export * from './aztec-node/server.js';
export * from './rpc/http_rpc_server.js';
export * from './rpc/http_rpc_client.js';
export * from './aztec-node/http_rpc_server.js';
Loading