@aztec/aztec-node 0.0.0-test.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +15 -0
- package/dest/aztec-node/config.d.ts +29 -0
- package/dest/aztec-node/config.d.ts.map +1 -0
- package/dest/aztec-node/config.js +44 -0
- package/dest/aztec-node/http_rpc_server.d.ts +8 -0
- package/dest/aztec-node/http_rpc_server.d.ts.map +1 -0
- package/dest/aztec-node/http_rpc_server.js +9 -0
- package/dest/aztec-node/node_metrics.d.ts +8 -0
- package/dest/aztec-node/node_metrics.d.ts.map +1 -0
- package/dest/aztec-node/node_metrics.js +22 -0
- package/dest/aztec-node/server.d.ts +303 -0
- package/dest/aztec-node/server.d.ts.map +1 -0
- package/dest/aztec-node/server.js +725 -0
- package/dest/bin/index.d.ts +3 -0
- package/dest/bin/index.d.ts.map +1 -0
- package/dest/bin/index.js +39 -0
- package/dest/index.d.ts +4 -0
- package/dest/index.d.ts.map +1 -0
- package/dest/index.js +3 -0
- package/package.json +105 -0
- package/src/aztec-node/config.ts +71 -0
- package/src/aztec-node/http_rpc_server.ts +11 -0
- package/src/aztec-node/node_metrics.ts +32 -0
- package/src/aztec-node/server.ts +994 -0
- package/src/bin/index.ts +52 -0
- package/src/index.ts +3 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/bin/index.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
#!/usr/bin/env -S node --no-warnings
|
|
2
|
+
import { createLogger } from '@aztec/foundation/log';
|
|
3
|
+
import http from 'http';
|
|
4
|
+
import { AztecNodeService, createAztecNodeRpcServer, getConfigEnvVars } from '../index.js';
|
|
5
|
+
const { AZTEC_NODE_PORT = 8081, API_PREFIX = '' } = process.env;
|
|
6
|
+
const logger = createLogger('node');
|
|
7
|
+
/**
|
|
8
|
+
* Creates the node from provided config
|
|
9
|
+
*/ async function createAndDeployAztecNode() {
|
|
10
|
+
const aztecNodeConfig = {
|
|
11
|
+
...getConfigEnvVars()
|
|
12
|
+
};
|
|
13
|
+
return await AztecNodeService.createAndSync(aztecNodeConfig);
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Create and start a new Aztec Node HTTP Server
|
|
17
|
+
*/ async function main() {
|
|
18
|
+
logger.info(`Setting up Aztec Node...`);
|
|
19
|
+
const aztecNode = await createAndDeployAztecNode();
|
|
20
|
+
const shutdown = async ()=>{
|
|
21
|
+
logger.info('Shutting down...');
|
|
22
|
+
await aztecNode.stop();
|
|
23
|
+
process.exit(0);
|
|
24
|
+
};
|
|
25
|
+
// eslint-disable-next-line @typescript-eslint/no-misused-promises
|
|
26
|
+
process.once('SIGINT', shutdown);
|
|
27
|
+
// eslint-disable-next-line @typescript-eslint/no-misused-promises
|
|
28
|
+
process.once('SIGTERM', shutdown);
|
|
29
|
+
const rpcServer = createAztecNodeRpcServer(aztecNode);
|
|
30
|
+
const app = rpcServer.getApp(API_PREFIX);
|
|
31
|
+
// eslint-disable-next-line @typescript-eslint/no-misused-promises
|
|
32
|
+
const httpServer = http.createServer(app.callback());
|
|
33
|
+
httpServer.listen(+AZTEC_NODE_PORT);
|
|
34
|
+
logger.info(`Aztec Node JSON-RPC Server listening on port ${AZTEC_NODE_PORT}`);
|
|
35
|
+
}
|
|
36
|
+
main().catch((err)=>{
|
|
37
|
+
logger.error(err);
|
|
38
|
+
process.exit(1);
|
|
39
|
+
});
|
package/dest/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,wBAAwB,CAAC;AACvC,cAAc,wBAAwB,CAAC;AACvC,cAAc,iCAAiC,CAAC"}
|
package/dest/index.js
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@aztec/aztec-node",
|
|
3
|
+
"version": "0.0.0-test.0",
|
|
4
|
+
"main": "dest/index.js",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"exports": {
|
|
7
|
+
".": "./dest/index.js",
|
|
8
|
+
"./config": "./dest/aztec-node/config.js"
|
|
9
|
+
},
|
|
10
|
+
"bin": "./dest/bin/index.js",
|
|
11
|
+
"typedocOptions": {
|
|
12
|
+
"entryPoints": [
|
|
13
|
+
"./src/index.ts"
|
|
14
|
+
],
|
|
15
|
+
"name": "Aztec Node",
|
|
16
|
+
"tsconfig": "./tsconfig.json"
|
|
17
|
+
},
|
|
18
|
+
"scripts": {
|
|
19
|
+
"start": "node --no-warnings ./dest/bin",
|
|
20
|
+
"start:debug": "node --no-warnings --inspect ./dest/bin",
|
|
21
|
+
"build": "yarn clean && tsc -b",
|
|
22
|
+
"build:dev": "tsc -b --watch",
|
|
23
|
+
"clean": "rm -rf ./dest .tsbuildinfo",
|
|
24
|
+
"formatting": "run -T prettier --check ./src && run -T eslint ./src",
|
|
25
|
+
"formatting:fix": "run -T eslint --fix ./src && run -T prettier -w ./src",
|
|
26
|
+
"test": "NODE_NO_WARNINGS=1 node --experimental-vm-modules ../node_modules/.bin/jest --passWithNoTests --maxWorkers=${JEST_MAX_WORKERS:-8}"
|
|
27
|
+
},
|
|
28
|
+
"inherits": [
|
|
29
|
+
"../package.common.json"
|
|
30
|
+
],
|
|
31
|
+
"jest": {
|
|
32
|
+
"extensionsToTreatAsEsm": [
|
|
33
|
+
".ts"
|
|
34
|
+
],
|
|
35
|
+
"transform": {
|
|
36
|
+
"^.+\\.tsx?$": [
|
|
37
|
+
"@swc/jest",
|
|
38
|
+
{
|
|
39
|
+
"jsc": {
|
|
40
|
+
"parser": {
|
|
41
|
+
"syntax": "typescript",
|
|
42
|
+
"decorators": true
|
|
43
|
+
},
|
|
44
|
+
"transform": {
|
|
45
|
+
"decoratorVersion": "2022-03"
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
]
|
|
50
|
+
},
|
|
51
|
+
"moduleNameMapper": {
|
|
52
|
+
"^(\\.{1,2}/.*)\\.[cm]?js$": "$1"
|
|
53
|
+
},
|
|
54
|
+
"testRegex": "./src/.*\\.test\\.(js|mjs|ts)$",
|
|
55
|
+
"rootDir": "./src",
|
|
56
|
+
"reporters": [
|
|
57
|
+
"default"
|
|
58
|
+
],
|
|
59
|
+
"testTimeout": 120000,
|
|
60
|
+
"setupFiles": [
|
|
61
|
+
"../../foundation/src/jest/setup.mjs"
|
|
62
|
+
]
|
|
63
|
+
},
|
|
64
|
+
"dependencies": {
|
|
65
|
+
"@aztec/archiver": "0.0.0-test.0",
|
|
66
|
+
"@aztec/bb-prover": "0.0.0-test.0",
|
|
67
|
+
"@aztec/blob-sink": "0.0.0-test.0",
|
|
68
|
+
"@aztec/constants": "0.0.0-test.0",
|
|
69
|
+
"@aztec/epoch-cache": "0.0.0-test.0",
|
|
70
|
+
"@aztec/ethereum": "0.0.0-test.0",
|
|
71
|
+
"@aztec/foundation": "0.0.0-test.0",
|
|
72
|
+
"@aztec/kv-store": "0.0.0-test.0",
|
|
73
|
+
"@aztec/merkle-tree": "0.0.0-test.0",
|
|
74
|
+
"@aztec/p2p": "0.0.0-test.0",
|
|
75
|
+
"@aztec/protocol-contracts": "0.0.0-test.0",
|
|
76
|
+
"@aztec/prover-client": "0.0.0-test.0",
|
|
77
|
+
"@aztec/sequencer-client": "0.0.0-test.0",
|
|
78
|
+
"@aztec/simulator": "0.0.0-test.0",
|
|
79
|
+
"@aztec/stdlib": "0.0.0-test.0",
|
|
80
|
+
"@aztec/telemetry-client": "0.0.0-test.0",
|
|
81
|
+
"@aztec/validator-client": "0.0.0-test.0",
|
|
82
|
+
"@aztec/world-state": "0.0.0-test.0",
|
|
83
|
+
"koa": "^2.14.2",
|
|
84
|
+
"koa-router": "^12.0.0",
|
|
85
|
+
"tslib": "^2.4.0"
|
|
86
|
+
},
|
|
87
|
+
"devDependencies": {
|
|
88
|
+
"@jest/globals": "^29.5.0",
|
|
89
|
+
"@types/jest": "^29.5.0",
|
|
90
|
+
"@types/node": "^18.7.23",
|
|
91
|
+
"jest": "^29.5.0",
|
|
92
|
+
"jest-mock-extended": "^3.0.3",
|
|
93
|
+
"ts-node": "^10.9.1",
|
|
94
|
+
"typescript": "^5.0.4"
|
|
95
|
+
},
|
|
96
|
+
"files": [
|
|
97
|
+
"dest",
|
|
98
|
+
"src",
|
|
99
|
+
"!*.test.*"
|
|
100
|
+
],
|
|
101
|
+
"types": "./dest/index.d.ts",
|
|
102
|
+
"engines": {
|
|
103
|
+
"node": ">=18"
|
|
104
|
+
}
|
|
105
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { type ArchiverConfig, archiverConfigMappings } from '@aztec/archiver/config';
|
|
2
|
+
import { type ConfigMappingsType, booleanConfigHelper, getConfigFromMappings } from '@aztec/foundation/config';
|
|
3
|
+
import { type DataStoreConfig, dataConfigMappings } from '@aztec/kv-store/config';
|
|
4
|
+
import { type P2PConfig, p2pConfigMappings } from '@aztec/p2p/config';
|
|
5
|
+
import { type ProverClientConfig, proverClientConfigMappings } from '@aztec/prover-client/config';
|
|
6
|
+
import { type SequencerClientConfig, sequencerClientConfigMappings } from '@aztec/sequencer-client/config';
|
|
7
|
+
import { type ValidatorClientConfig, validatorClientConfigMappings } from '@aztec/validator-client/config';
|
|
8
|
+
import { type WorldStateConfig, worldStateConfigMappings } from '@aztec/world-state/config';
|
|
9
|
+
|
|
10
|
+
import { readFileSync } from 'fs';
|
|
11
|
+
import { dirname, resolve } from 'path';
|
|
12
|
+
import { fileURLToPath } from 'url';
|
|
13
|
+
|
|
14
|
+
export { sequencerClientConfigMappings, type SequencerClientConfig };
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* The configuration the aztec node.
|
|
18
|
+
*/
|
|
19
|
+
export type AztecNodeConfig = ArchiverConfig &
|
|
20
|
+
SequencerClientConfig &
|
|
21
|
+
ValidatorClientConfig &
|
|
22
|
+
ProverClientConfig &
|
|
23
|
+
WorldStateConfig &
|
|
24
|
+
Pick<ProverClientConfig, 'bbBinaryPath' | 'bbWorkingDirectory' | 'realProofs'> &
|
|
25
|
+
P2PConfig &
|
|
26
|
+
DataStoreConfig & {
|
|
27
|
+
/** Whether the validator is disabled for this node */
|
|
28
|
+
disableValidator: boolean;
|
|
29
|
+
/** Whether to populate the genesis state with initial fee juice for the test accounts */
|
|
30
|
+
testAccounts: boolean;
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
export const aztecNodeConfigMappings: ConfigMappingsType<AztecNodeConfig> = {
|
|
34
|
+
...archiverConfigMappings,
|
|
35
|
+
...sequencerClientConfigMappings,
|
|
36
|
+
...validatorClientConfigMappings,
|
|
37
|
+
...proverClientConfigMappings,
|
|
38
|
+
...worldStateConfigMappings,
|
|
39
|
+
...p2pConfigMappings,
|
|
40
|
+
...dataConfigMappings,
|
|
41
|
+
disableValidator: {
|
|
42
|
+
env: 'VALIDATOR_DISABLED',
|
|
43
|
+
description: 'Whether the validator is disabled for this node.',
|
|
44
|
+
...booleanConfigHelper(),
|
|
45
|
+
},
|
|
46
|
+
testAccounts: {
|
|
47
|
+
env: 'TEST_ACCOUNTS',
|
|
48
|
+
description: 'Whether to populate the genesis state with initial fee juice for the test accounts.',
|
|
49
|
+
...booleanConfigHelper(),
|
|
50
|
+
},
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Returns the config of the aztec node from environment variables with reasonable defaults.
|
|
55
|
+
* @returns A valid aztec node config.
|
|
56
|
+
*/
|
|
57
|
+
export function getConfigEnvVars(): AztecNodeConfig {
|
|
58
|
+
return getConfigFromMappings<AztecNodeConfig>(aztecNodeConfigMappings);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Returns package version.
|
|
63
|
+
*/
|
|
64
|
+
export function getPackageVersion() {
|
|
65
|
+
const releasePleaseManifestPath = resolve(
|
|
66
|
+
dirname(fileURLToPath(import.meta.url)),
|
|
67
|
+
'../../../../.release-please-manifest.json',
|
|
68
|
+
);
|
|
69
|
+
const version = JSON.parse(readFileSync(releasePleaseManifestPath).toString());
|
|
70
|
+
return version['.'];
|
|
71
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { type AztecNode, AztecNodeApiSchema } from '@aztec/stdlib/interfaces/client';
|
|
2
|
+
import { createTracedJsonRpcServer } from '@aztec/telemetry-client';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Wrap an AztecNode instance with a JSON RPC HTTP server.
|
|
6
|
+
* @param node - The AztecNode
|
|
7
|
+
* @returns An JSON-RPC HTTP server
|
|
8
|
+
*/
|
|
9
|
+
export function createAztecNodeRpcServer(node: AztecNode) {
|
|
10
|
+
return createTracedJsonRpcServer(node, AztecNodeApiSchema);
|
|
11
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Attributes,
|
|
3
|
+
type Histogram,
|
|
4
|
+
Metrics,
|
|
5
|
+
type TelemetryClient,
|
|
6
|
+
type UpDownCounter,
|
|
7
|
+
ValueType,
|
|
8
|
+
} from '@aztec/telemetry-client';
|
|
9
|
+
|
|
10
|
+
export class NodeMetrics {
|
|
11
|
+
private receiveTxCount: UpDownCounter;
|
|
12
|
+
private receiveTxDuration: Histogram;
|
|
13
|
+
|
|
14
|
+
constructor(client: TelemetryClient, name = 'AztecNode') {
|
|
15
|
+
const meter = client.getMeter(name);
|
|
16
|
+
this.receiveTxCount = meter.createUpDownCounter(Metrics.NODE_RECEIVE_TX_COUNT, {});
|
|
17
|
+
this.receiveTxDuration = meter.createHistogram(Metrics.NODE_RECEIVE_TX_DURATION, {
|
|
18
|
+
description: 'The duration of the receiveTx method',
|
|
19
|
+
unit: 'ms',
|
|
20
|
+
valueType: ValueType.INT,
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
receivedTx(durationMs: number, isAccepted: boolean) {
|
|
25
|
+
this.receiveTxDuration.record(Math.ceil(durationMs), {
|
|
26
|
+
[Attributes.OK]: isAccepted,
|
|
27
|
+
});
|
|
28
|
+
this.receiveTxCount.add(1, {
|
|
29
|
+
[Attributes.OK]: isAccepted,
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
}
|