-
Notifications
You must be signed in to change notification settings - Fork 265
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Standalone Aztec Node and RPC Server (#2522)
This PR addresses the comments of PR [2486](#2486). The feature set here is: 1. Some refactoring of packages dependencies and l1 contract address configuration. 2. Entrypoints to start standalone instances of Aztec Node and Aztec RPC Server. 3. Some initial terraform for Aztec Node deployments. # Checklist: Remove the checklist to signal you've completed it. Enable auto-merge if the PR is ready to merge. - [ ] If the pull request requires a cryptography review (e.g. cryptographic algorithm implementations) I have added the 'crypto' tag. - [ ] I have reviewed my diff in github, line by line and removed unexpected formatting changes, testing logs, or commented-out code. - [ ] Every change is related to the PR description. - [ ] I have [linked](https://docs.github.com/en/issues/tracking-your-work-with-issues/linking-a-pull-request-to-an-issue) this pull request to relevant issues (if any exist).
- Loading branch information
1 parent
87b8080
commit 8e355bc
Showing
69 changed files
with
1,020 additions
and
370 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,4 +6,5 @@ node_modules | |
build/ | ||
.idea | ||
cmake-build-debug | ||
.bootstrapped | ||
.terraform | ||
.bootstrapped |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'; |
Oops, something went wrong.