@aztec/aztec-node 0.87.7 → 1.0.0-nightly.20250605
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/dest/aztec-node/config.d.ts +2 -1
- package/dest/aztec-node/config.d.ts.map +1 -1
- package/dest/aztec-node/config.js +2 -0
- package/dest/aztec-node/server.d.ts +5 -16
- package/dest/aztec-node/server.d.ts.map +1 -1
- package/dest/aztec-node/server.js +44 -104
- package/dest/sentinel/factory.d.ts +2 -1
- package/dest/sentinel/factory.d.ts.map +1 -1
- package/dest/sentinel/factory.js +1 -1
- package/dest/sentinel/sentinel.d.ts +17 -5
- package/dest/sentinel/sentinel.d.ts.map +1 -1
- package/dest/sentinel/sentinel.js +110 -14
- package/dest/sentinel/store.d.ts +14 -3
- package/dest/sentinel/store.d.ts.map +1 -1
- package/dest/sentinel/store.js +71 -7
- package/package.json +23 -22
- package/src/aztec-node/config.ts +4 -1
- package/src/aztec-node/server.ts +66 -135
- package/src/sentinel/factory.ts +3 -2
- package/src/sentinel/sentinel.ts +129 -6
- package/src/sentinel/store.ts +82 -10
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"store.d.ts","sourceRoot":"","sources":["../../src/sentinel/store.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"store.d.ts","sourceRoot":"","sources":["../../src/sentinel/store.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,+BAA+B,CAAC;AAE3D,OAAO,KAAK,EAAE,iBAAiB,EAAiB,MAAM,iBAAiB,CAAC;AACxE,OAAO,KAAK,EACV,sBAAsB,EACtB,qBAAqB,EACrB,0BAA0B,EAC3B,MAAM,0BAA0B,CAAC;AAElC,qBAAa,aAAa;IAWtB,OAAO,CAAC,KAAK;IACb,OAAO,CAAC,MAAM;IAXhB,gBAAuB,cAAc,KAAK;IAG1C,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAuC;IAIlE,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAuC;gBAGvD,KAAK,EAAE,iBAAiB,EACxB,MAAM,EAAE;QAAE,aAAa,EAAE,MAAM,CAAA;KAAE;IAMpC,gBAAgB;IAIV,uBAAuB,CAAC,KAAK,EAAE,MAAM,EAAE,WAAW,EAAE,0BAA0B;IAQ9E,oBAAoB,CAAC,GAAG,EAAE,UAAU,GAAG,OAAO,CAAC;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,EAAE,CAAC;YAKjG,sCAAsC;IA6BvC,gBAAgB,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,CAAC,KAAK,MAAM,EAAE,EAAE,qBAAqB,GAAG,SAAS,CAAC;YAUhG,0BAA0B;IAU3B,YAAY,IAAI,OAAO,CAAC,MAAM,CAAC,KAAK,MAAM,EAAE,EAAE,sBAAsB,CAAC,CAAC;YAQrE,UAAU;IAKxB,OAAO,CAAC,oBAAoB;IAM5B,OAAO,CAAC,sBAAsB;IAa9B,OAAO,CAAC,gBAAgB;IAMxB,OAAO,CAAC,kBAAkB;IAW1B,OAAO,CAAC,cAAc;IAmBtB,OAAO,CAAC,gBAAgB;CAgBzB"}
|
package/dest/sentinel/store.js
CHANGED
|
@@ -1,22 +1,67 @@
|
|
|
1
|
+
import { EthAddress } from '@aztec/foundation/eth-address';
|
|
1
2
|
import { BufferReader, numToUInt8, numToUInt32BE, serializeToBuffer } from '@aztec/foundation/serialize';
|
|
2
3
|
export class SentinelStore {
|
|
3
4
|
store;
|
|
4
5
|
config;
|
|
5
|
-
static SCHEMA_VERSION =
|
|
6
|
-
map
|
|
6
|
+
static SCHEMA_VERSION = 2;
|
|
7
|
+
// a map from validator address to their ValidatorStatusHistory
|
|
8
|
+
historyMap;
|
|
9
|
+
// a map from validator address to their historical proven epoch performance
|
|
10
|
+
// e.g. { validator: [{ epoch: 1, missed: 1, total: 10 }, { epoch: 2, missed: 3, total: 7 }, ...] }
|
|
11
|
+
provenMap;
|
|
7
12
|
constructor(store, config){
|
|
8
13
|
this.store = store;
|
|
9
14
|
this.config = config;
|
|
10
|
-
this.
|
|
15
|
+
this.historyMap = store.openMap('sentinel-validator-status');
|
|
16
|
+
this.provenMap = store.openMap('sentinel-validator-proven');
|
|
11
17
|
}
|
|
12
18
|
getHistoryLength() {
|
|
13
19
|
return this.config.historyLength;
|
|
14
20
|
}
|
|
21
|
+
async updateProvenPerformance(epoch, performance) {
|
|
22
|
+
await this.store.transactionAsync(async ()=>{
|
|
23
|
+
for (const [who, { missed, total }] of Object.entries(performance)){
|
|
24
|
+
await this.pushValidatorProvenPerformanceForEpoch({
|
|
25
|
+
who: EthAddress.fromString(who),
|
|
26
|
+
missed,
|
|
27
|
+
total,
|
|
28
|
+
epoch
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
async getProvenPerformance(who) {
|
|
34
|
+
const currentPerformanceBuffer = await this.provenMap.getAsync(who.toString());
|
|
35
|
+
return currentPerformanceBuffer ? this.deserializePerformance(currentPerformanceBuffer) : [];
|
|
36
|
+
}
|
|
37
|
+
async pushValidatorProvenPerformanceForEpoch({ who, missed, total, epoch }) {
|
|
38
|
+
const currentPerformance = await this.getProvenPerformance(who);
|
|
39
|
+
const existingIndex = currentPerformance.findIndex((p)=>p.epoch === epoch);
|
|
40
|
+
if (existingIndex !== -1) {
|
|
41
|
+
currentPerformance[existingIndex] = {
|
|
42
|
+
missed,
|
|
43
|
+
total,
|
|
44
|
+
epoch
|
|
45
|
+
};
|
|
46
|
+
} else {
|
|
47
|
+
currentPerformance.push({
|
|
48
|
+
missed,
|
|
49
|
+
total,
|
|
50
|
+
epoch
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
// This should be sorted by epoch, but just in case.
|
|
54
|
+
// Since we keep the size small, this is not a big deal.
|
|
55
|
+
currentPerformance.sort((a, b)=>Number(a.epoch - b.epoch));
|
|
56
|
+
// keep the most recent `historyLength` entries.
|
|
57
|
+
const performanceToKeep = currentPerformance.slice(-this.config.historyLength);
|
|
58
|
+
await this.provenMap.set(who.toString(), this.serializePerformance(performanceToKeep));
|
|
59
|
+
}
|
|
15
60
|
async updateValidators(slot, statuses) {
|
|
16
61
|
await this.store.transactionAsync(async ()=>{
|
|
17
62
|
for (const [who, status] of Object.entries(statuses)){
|
|
18
63
|
if (status) {
|
|
19
|
-
await this.pushValidatorStatusForSlot(who, slot, status);
|
|
64
|
+
await this.pushValidatorStatusForSlot(EthAddress.fromString(who), slot, status);
|
|
20
65
|
}
|
|
21
66
|
}
|
|
22
67
|
});
|
|
@@ -30,19 +75,38 @@ export class SentinelStore {
|
|
|
30
75
|
status
|
|
31
76
|
}
|
|
32
77
|
].slice(-this.config.historyLength);
|
|
33
|
-
await this.
|
|
78
|
+
await this.historyMap.set(who.toString(), this.serializeHistory(newHistory));
|
|
34
79
|
}
|
|
35
80
|
async getHistories() {
|
|
36
81
|
const histories = {};
|
|
37
|
-
for await (const [address, history] of this.
|
|
82
|
+
for await (const [address, history] of this.historyMap.entriesAsync()){
|
|
38
83
|
histories[address] = this.deserializeHistory(history);
|
|
39
84
|
}
|
|
40
85
|
return histories;
|
|
41
86
|
}
|
|
42
87
|
async getHistory(address) {
|
|
43
|
-
const data = await this.
|
|
88
|
+
const data = await this.historyMap.getAsync(address.toString());
|
|
44
89
|
return data && this.deserializeHistory(data);
|
|
45
90
|
}
|
|
91
|
+
serializePerformance(performance) {
|
|
92
|
+
return serializeToBuffer(performance.map((p)=>[
|
|
93
|
+
numToUInt32BE(Number(p.epoch)),
|
|
94
|
+
numToUInt32BE(p.missed),
|
|
95
|
+
numToUInt32BE(p.total)
|
|
96
|
+
]));
|
|
97
|
+
}
|
|
98
|
+
deserializePerformance(buffer) {
|
|
99
|
+
const reader = new BufferReader(buffer);
|
|
100
|
+
const performance = [];
|
|
101
|
+
while(!reader.isEmpty()){
|
|
102
|
+
performance.push({
|
|
103
|
+
epoch: BigInt(reader.readNumber()),
|
|
104
|
+
missed: reader.readNumber(),
|
|
105
|
+
total: reader.readNumber()
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
return performance;
|
|
109
|
+
}
|
|
46
110
|
serializeHistory(history) {
|
|
47
111
|
return serializeToBuffer(history.map((h)=>[
|
|
48
112
|
numToUInt32BE(Number(h.slot)),
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aztec/aztec-node",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "1.0.0-nightly.20250605",
|
|
4
4
|
"main": "dest/index.js",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
@@ -61,27 +61,28 @@
|
|
|
61
61
|
]
|
|
62
62
|
},
|
|
63
63
|
"dependencies": {
|
|
64
|
-
"@aztec/archiver": "0.
|
|
65
|
-
"@aztec/bb-prover": "0.
|
|
66
|
-
"@aztec/blob-sink": "0.
|
|
67
|
-
"@aztec/constants": "0.
|
|
68
|
-
"@aztec/epoch-cache": "0.
|
|
69
|
-
"@aztec/ethereum": "0.
|
|
70
|
-
"@aztec/foundation": "0.
|
|
71
|
-
"@aztec/kv-store": "0.
|
|
72
|
-
"@aztec/l1-artifacts": "0.
|
|
73
|
-
"@aztec/merkle-tree": "0.
|
|
74
|
-
"@aztec/node-lib": "0.
|
|
75
|
-
"@aztec/noir-protocol-circuits-types": "0.
|
|
76
|
-
"@aztec/p2p": "0.
|
|
77
|
-
"@aztec/protocol-contracts": "0.
|
|
78
|
-
"@aztec/prover-client": "0.
|
|
79
|
-
"@aztec/sequencer-client": "0.
|
|
80
|
-
"@aztec/simulator": "0.
|
|
81
|
-
"@aztec/
|
|
82
|
-
"@aztec/
|
|
83
|
-
"@aztec/
|
|
84
|
-
"@aztec/
|
|
64
|
+
"@aztec/archiver": "1.0.0-nightly.20250605",
|
|
65
|
+
"@aztec/bb-prover": "1.0.0-nightly.20250605",
|
|
66
|
+
"@aztec/blob-sink": "1.0.0-nightly.20250605",
|
|
67
|
+
"@aztec/constants": "1.0.0-nightly.20250605",
|
|
68
|
+
"@aztec/epoch-cache": "1.0.0-nightly.20250605",
|
|
69
|
+
"@aztec/ethereum": "1.0.0-nightly.20250605",
|
|
70
|
+
"@aztec/foundation": "1.0.0-nightly.20250605",
|
|
71
|
+
"@aztec/kv-store": "1.0.0-nightly.20250605",
|
|
72
|
+
"@aztec/l1-artifacts": "1.0.0-nightly.20250605",
|
|
73
|
+
"@aztec/merkle-tree": "1.0.0-nightly.20250605",
|
|
74
|
+
"@aztec/node-lib": "1.0.0-nightly.20250605",
|
|
75
|
+
"@aztec/noir-protocol-circuits-types": "1.0.0-nightly.20250605",
|
|
76
|
+
"@aztec/p2p": "1.0.0-nightly.20250605",
|
|
77
|
+
"@aztec/protocol-contracts": "1.0.0-nightly.20250605",
|
|
78
|
+
"@aztec/prover-client": "1.0.0-nightly.20250605",
|
|
79
|
+
"@aztec/sequencer-client": "1.0.0-nightly.20250605",
|
|
80
|
+
"@aztec/simulator": "1.0.0-nightly.20250605",
|
|
81
|
+
"@aztec/slasher": "1.0.0-nightly.20250605",
|
|
82
|
+
"@aztec/stdlib": "1.0.0-nightly.20250605",
|
|
83
|
+
"@aztec/telemetry-client": "1.0.0-nightly.20250605",
|
|
84
|
+
"@aztec/validator-client": "1.0.0-nightly.20250605",
|
|
85
|
+
"@aztec/world-state": "1.0.0-nightly.20250605",
|
|
85
86
|
"koa": "^2.16.1",
|
|
86
87
|
"koa-router": "^12.0.0",
|
|
87
88
|
"tslib": "^2.4.0",
|
package/src/aztec-node/config.ts
CHANGED
|
@@ -11,6 +11,7 @@ import { type SharedNodeConfig, sharedNodeConfigMappings } from '@aztec/node-lib
|
|
|
11
11
|
import { type P2PConfig, p2pConfigMappings } from '@aztec/p2p/config';
|
|
12
12
|
import { type ProverClientUserConfig, proverClientConfigMappings } from '@aztec/prover-client/config';
|
|
13
13
|
import { type SequencerClientConfig, sequencerClientConfigMappings } from '@aztec/sequencer-client/config';
|
|
14
|
+
import { type SlasherConfig, slasherConfigMappings } from '@aztec/slasher';
|
|
14
15
|
import { type NodeRPCConfig, nodeRpcConfigMappings } from '@aztec/stdlib/config';
|
|
15
16
|
import { type ValidatorClientConfig, validatorClientConfigMappings } from '@aztec/validator-client/config';
|
|
16
17
|
import { type WorldStateConfig, worldStateConfigMappings } from '@aztec/world-state/config';
|
|
@@ -33,7 +34,8 @@ export type AztecNodeConfig = ArchiverConfig &
|
|
|
33
34
|
SentinelConfig &
|
|
34
35
|
SharedNodeConfig &
|
|
35
36
|
GenesisStateConfig &
|
|
36
|
-
NodeRPCConfig &
|
|
37
|
+
NodeRPCConfig &
|
|
38
|
+
SlasherConfig & {
|
|
37
39
|
/** L1 contracts addresses */
|
|
38
40
|
l1Contracts: L1ContractAddresses;
|
|
39
41
|
/** Whether the validator is disabled for this node */
|
|
@@ -52,6 +54,7 @@ export const aztecNodeConfigMappings: ConfigMappingsType<AztecNodeConfig> = {
|
|
|
52
54
|
...sharedNodeConfigMappings,
|
|
53
55
|
...genesisStateConfigMappings,
|
|
54
56
|
...nodeRpcConfigMappings,
|
|
57
|
+
...slasherConfigMappings,
|
|
55
58
|
l1Contracts: {
|
|
56
59
|
description: 'The deployed L1 contract addresses',
|
|
57
60
|
nested: l1ContractAddressesMapping,
|
package/src/aztec-node/server.ts
CHANGED
|
@@ -10,7 +10,14 @@ import {
|
|
|
10
10
|
type PUBLIC_DATA_TREE_HEIGHT,
|
|
11
11
|
} from '@aztec/constants';
|
|
12
12
|
import { EpochCache } from '@aztec/epoch-cache';
|
|
13
|
-
import {
|
|
13
|
+
import {
|
|
14
|
+
type L1ContractAddresses,
|
|
15
|
+
RegistryContract,
|
|
16
|
+
RollupContract,
|
|
17
|
+
createEthereumChain,
|
|
18
|
+
createExtendedL1Client,
|
|
19
|
+
} from '@aztec/ethereum';
|
|
20
|
+
import { L1TxUtilsWithBlobs } from '@aztec/ethereum/l1-tx-utils-with-blobs';
|
|
14
21
|
import { compactArray } from '@aztec/foundation/collection';
|
|
15
22
|
import { EthAddress } from '@aztec/foundation/eth-address';
|
|
16
23
|
import { Fr } from '@aztec/foundation/fields';
|
|
@@ -20,20 +27,18 @@ import { SerialQueue } from '@aztec/foundation/queue';
|
|
|
20
27
|
import { count } from '@aztec/foundation/string';
|
|
21
28
|
import { DateProvider, Timer } from '@aztec/foundation/timer';
|
|
22
29
|
import { SiblingPath } from '@aztec/foundation/trees';
|
|
23
|
-
import { openTmpStore } from '@aztec/kv-store/lmdb';
|
|
24
|
-
import { RollupAbi } from '@aztec/l1-artifacts';
|
|
25
|
-
import { SHA256Trunc, StandardTree, UnbalancedTree } from '@aztec/merkle-tree';
|
|
26
30
|
import { trySnapshotSync, uploadSnapshot } from '@aztec/node-lib/actions';
|
|
27
31
|
import { type P2P, createP2PClient, getDefaultAllowedSetupFunctions } from '@aztec/p2p';
|
|
28
32
|
import { ProtocolContractAddress } from '@aztec/protocol-contracts';
|
|
29
33
|
import {
|
|
34
|
+
BlockBuilder,
|
|
30
35
|
GlobalVariableBuilder,
|
|
31
36
|
SequencerClient,
|
|
32
37
|
type SequencerPublisher,
|
|
33
|
-
createSlasherClient,
|
|
34
38
|
createValidatorForAcceptingTxs,
|
|
35
39
|
} from '@aztec/sequencer-client';
|
|
36
40
|
import { PublicProcessorFactory } from '@aztec/simulator/server';
|
|
41
|
+
import { EpochPruneWatcher, SlasherClient, type Watcher } from '@aztec/slasher';
|
|
37
42
|
import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
38
43
|
import type { InBlock, L2Block, L2BlockNumber, L2BlockSource, PublishedL2Block } from '@aztec/stdlib/block';
|
|
39
44
|
import type {
|
|
@@ -90,7 +95,7 @@ import {
|
|
|
90
95
|
import { createValidatorClient } from '@aztec/validator-client';
|
|
91
96
|
import { createWorldStateSynchronizer } from '@aztec/world-state';
|
|
92
97
|
|
|
93
|
-
import { createPublicClient, fallback,
|
|
98
|
+
import { createPublicClient, fallback, http } from 'viem';
|
|
94
99
|
|
|
95
100
|
import { createSentinel } from '../sentinel/factory.js';
|
|
96
101
|
import { Sentinel } from '../sentinel/sentinel.js';
|
|
@@ -181,7 +186,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
181
186
|
|
|
182
187
|
const publicClient = createPublicClient({
|
|
183
188
|
chain: ethereumChain.chainInfo,
|
|
184
|
-
transport: fallback(config.l1RpcUrls.map(url => http(url))),
|
|
189
|
+
transport: fallback(config.l1RpcUrls.map((url: string) => http(url))),
|
|
185
190
|
pollingInterval: config.viemPollingIntervalMS,
|
|
186
191
|
});
|
|
187
192
|
|
|
@@ -194,17 +199,19 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
194
199
|
// Overwrite the passed in vars.
|
|
195
200
|
config.l1Contracts = { ...config.l1Contracts, ...l1ContractsAddresses };
|
|
196
201
|
|
|
197
|
-
const
|
|
198
|
-
|
|
199
|
-
abi: RollupAbi,
|
|
200
|
-
client: publicClient,
|
|
201
|
-
});
|
|
202
|
+
const l1Client = createExtendedL1Client(config.l1RpcUrls, config.publisherPrivateKey, ethereumChain.chainInfo);
|
|
203
|
+
const l1TxUtils = new L1TxUtilsWithBlobs(l1Client, log, config);
|
|
202
204
|
|
|
203
|
-
const
|
|
205
|
+
const rollupContract = new RollupContract(l1Client, config.l1Contracts.rollupAddress.toString());
|
|
206
|
+
const [l1GenesisTime, slotDuration, rollupVersionFromRollup] = await Promise.all([
|
|
207
|
+
rollupContract.getL1GenesisTime(),
|
|
208
|
+
rollupContract.getSlotDuration(),
|
|
209
|
+
rollupContract.getVersion(),
|
|
210
|
+
] as const);
|
|
204
211
|
|
|
205
|
-
config.rollupVersion ??= rollupVersionFromRollup;
|
|
212
|
+
config.rollupVersion ??= Number(rollupVersionFromRollup);
|
|
206
213
|
|
|
207
|
-
if (config.rollupVersion !== rollupVersionFromRollup) {
|
|
214
|
+
if (config.rollupVersion !== Number(rollupVersionFromRollup)) {
|
|
208
215
|
log.warn(
|
|
209
216
|
`Registry looked up and returned a rollup with version (${config.rollupVersion}), but this does not match with version detected from the rollup directly: (${rollupVersionFromRollup}).`,
|
|
210
217
|
);
|
|
@@ -247,32 +254,63 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
247
254
|
// Start p2p. Note that it depends on world state to be running.
|
|
248
255
|
await p2pClient.start();
|
|
249
256
|
|
|
250
|
-
const
|
|
251
|
-
|
|
257
|
+
const watchers: Watcher[] = [];
|
|
258
|
+
|
|
259
|
+
const validatorsSentinel = await createSentinel(epochCache, archiver, p2pClient, config);
|
|
260
|
+
if (validatorsSentinel && config.slashInactivityEnabled) {
|
|
261
|
+
watchers.push(validatorsSentinel);
|
|
262
|
+
}
|
|
263
|
+
if (config.slashPruneEnabled) {
|
|
264
|
+
const epochPruneWatcher = new EpochPruneWatcher(
|
|
265
|
+
archiver,
|
|
266
|
+
epochCache,
|
|
267
|
+
config.slashPrunePenalty,
|
|
268
|
+
config.slashPruneMaxPenalty,
|
|
269
|
+
);
|
|
270
|
+
watchers.push(epochPruneWatcher);
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
const slasherClient = await SlasherClient.new(config, config.l1Contracts, l1TxUtils, watchers, dateProvider);
|
|
274
|
+
await slasherClient.start();
|
|
275
|
+
|
|
276
|
+
const blockBuilder = new BlockBuilder(
|
|
277
|
+
{
|
|
278
|
+
l1GenesisTime,
|
|
279
|
+
slotDuration: Number(slotDuration),
|
|
280
|
+
rollupVersion: config.rollupVersion,
|
|
281
|
+
l1ChainId: config.l1ChainId,
|
|
282
|
+
},
|
|
283
|
+
archiver,
|
|
284
|
+
worldStateSynchronizer,
|
|
285
|
+
archiver,
|
|
286
|
+
dateProvider,
|
|
287
|
+
telemetry,
|
|
288
|
+
);
|
|
252
289
|
|
|
253
290
|
const validatorClient = createValidatorClient(config, {
|
|
254
291
|
p2pClient,
|
|
255
292
|
telemetry,
|
|
256
293
|
dateProvider,
|
|
257
294
|
epochCache,
|
|
295
|
+
blockBuilder,
|
|
258
296
|
blockSource: archiver,
|
|
259
297
|
});
|
|
260
|
-
|
|
261
|
-
const validatorsSentinel = await createSentinel(epochCache, archiver, p2pClient, config);
|
|
262
|
-
await validatorsSentinel?.start();
|
|
263
|
-
|
|
264
298
|
log.verbose(`All Aztec Node subsystems synced`);
|
|
265
299
|
|
|
266
300
|
// now create the sequencer
|
|
267
301
|
const sequencer = config.disableValidator
|
|
268
302
|
? undefined
|
|
269
303
|
: await SequencerClient.new(config, {
|
|
304
|
+
// if deps were provided, they should override the defaults,
|
|
305
|
+
// or things that we created in this function
|
|
270
306
|
...deps,
|
|
307
|
+
epochCache,
|
|
308
|
+
l1TxUtils,
|
|
271
309
|
validatorClient,
|
|
272
310
|
p2pClient,
|
|
273
311
|
worldStateSynchronizer,
|
|
274
312
|
slasherClient,
|
|
275
|
-
|
|
313
|
+
blockBuilder,
|
|
276
314
|
l2BlockSource: archiver,
|
|
277
315
|
l1ToL2MessageSource: archiver,
|
|
278
316
|
telemetry,
|
|
@@ -528,7 +566,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
528
566
|
public async stop() {
|
|
529
567
|
this.log.info(`Stopping`);
|
|
530
568
|
await this.txQueue.end();
|
|
531
|
-
await this.validatorsSentinel?.stop();
|
|
569
|
+
// await this.validatorsSentinel?.stop(); <- The slasher client will stop this
|
|
532
570
|
await this.sequencer?.stop();
|
|
533
571
|
await this.p2pClient.stop();
|
|
534
572
|
await this.worldStateSynchronizer.stop();
|
|
@@ -698,120 +736,13 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
698
736
|
}
|
|
699
737
|
|
|
700
738
|
/**
|
|
701
|
-
* Returns the
|
|
702
|
-
* @
|
|
703
|
-
*
|
|
704
|
-
* The tree is constructed in two layers:
|
|
705
|
-
* 1. Subtree - For each transaction in the block, a subtree is created containing all L2->L1 messages from that
|
|
706
|
-
* transaction.
|
|
707
|
-
* 2. Top tree - A tree containing the roots of all the subtrees as leaves
|
|
708
|
-
* The final path is constructed by concatenating the path in the subtree with the path in the top tree.
|
|
709
|
-
* When there is only one transaction in the block, the subtree itself becomes the block's L2->L1 message tree,
|
|
710
|
-
* and no top tree is needed. The out hash is the root of the the block's L2->L1 message tree.
|
|
711
|
-
* TODO: Handle the case where two messages in the same tx have the same hash.
|
|
712
|
-
* @param blockNumber - Block number to get data from
|
|
713
|
-
* @param l2ToL1Message - Message to get index/path for
|
|
714
|
-
* @returns [index, siblingPath] for the message
|
|
739
|
+
* Returns all the L2 to L1 messages in a block.
|
|
740
|
+
* @param blockNumber - The block number at which to get the data.
|
|
741
|
+
* @returns The L2 to L1 messages (undefined if the block number is not found).
|
|
715
742
|
*/
|
|
716
|
-
public async
|
|
717
|
-
blockNumber: L2BlockNumber,
|
|
718
|
-
l2ToL1Message: Fr,
|
|
719
|
-
): Promise<[bigint, SiblingPath<number>]> {
|
|
743
|
+
public async getL2ToL1Messages(blockNumber: L2BlockNumber): Promise<Fr[][] | undefined> {
|
|
720
744
|
const block = await this.blockSource.getBlock(blockNumber === 'latest' ? await this.getBlockNumber() : blockNumber);
|
|
721
|
-
|
|
722
|
-
if (block === undefined) {
|
|
723
|
-
throw new Error('Block not found in getL2ToL1MessageMembershipWitness');
|
|
724
|
-
}
|
|
725
|
-
|
|
726
|
-
const messagesPerTx = block.body.txEffects.map(txEffect => txEffect.l2ToL1Msgs);
|
|
727
|
-
|
|
728
|
-
// Find index of message in subtree and index of tx in a block
|
|
729
|
-
let messageIndexInTx = -1,
|
|
730
|
-
txIndex = -1;
|
|
731
|
-
{
|
|
732
|
-
txIndex = messagesPerTx.findIndex(messages => {
|
|
733
|
-
const idx = messages.findIndex(msg => msg.equals(l2ToL1Message));
|
|
734
|
-
messageIndexInTx = Math.max(messageIndexInTx, idx);
|
|
735
|
-
return idx !== -1;
|
|
736
|
-
});
|
|
737
|
-
}
|
|
738
|
-
|
|
739
|
-
if (txIndex === -1) {
|
|
740
|
-
throw new Error('The L2ToL1Message you are trying to prove inclusion of does not exist');
|
|
741
|
-
}
|
|
742
|
-
|
|
743
|
-
// Get the message path in subtree and message subtree height
|
|
744
|
-
let messagePathInSubtree: SiblingPath<number>;
|
|
745
|
-
let messageSubtreeHeight: number;
|
|
746
|
-
{
|
|
747
|
-
const subtreeStore = openTmpStore(true);
|
|
748
|
-
const txMessages = messagesPerTx[txIndex];
|
|
749
|
-
messageSubtreeHeight = txMessages.length <= 1 ? 1 : Math.ceil(Math.log2(txMessages.length));
|
|
750
|
-
const subtree = new StandardTree(
|
|
751
|
-
subtreeStore,
|
|
752
|
-
new SHA256Trunc(),
|
|
753
|
-
`subtree_${txIndex}`,
|
|
754
|
-
messageSubtreeHeight,
|
|
755
|
-
0n,
|
|
756
|
-
Fr,
|
|
757
|
-
);
|
|
758
|
-
subtree.appendLeaves(txMessages);
|
|
759
|
-
messagePathInSubtree = await subtree.getSiblingPath(BigInt(messageIndexInTx), true);
|
|
760
|
-
await subtreeStore.delete();
|
|
761
|
-
}
|
|
762
|
-
|
|
763
|
-
// If the number of txs is 1 we are dealing with a special case where the tx subtree itself is the whole block's
|
|
764
|
-
// l2 to l1 message tree.
|
|
765
|
-
const numTransactions = block.body.txEffects.length;
|
|
766
|
-
if (numTransactions === 1) {
|
|
767
|
-
return [BigInt(messageIndexInTx), messagePathInSubtree];
|
|
768
|
-
}
|
|
769
|
-
|
|
770
|
-
// Calculate roots for all tx subtrees
|
|
771
|
-
const txSubtreeRoots = await Promise.all(
|
|
772
|
-
messagesPerTx.map(async (messages, txIdx) => {
|
|
773
|
-
// For a tx with no messages, we have to set an out hash of 0 to match what the circuit does.
|
|
774
|
-
if (messages.length === 0) {
|
|
775
|
-
return Fr.ZERO;
|
|
776
|
-
}
|
|
777
|
-
|
|
778
|
-
const txStore = openTmpStore(true);
|
|
779
|
-
const txTreeHeight = messages.length <= 1 ? 1 : Math.ceil(Math.log2(messages.length));
|
|
780
|
-
const txTree = new StandardTree(
|
|
781
|
-
txStore,
|
|
782
|
-
new SHA256Trunc(),
|
|
783
|
-
`tx_messages_subtree_${txIdx}`,
|
|
784
|
-
txTreeHeight,
|
|
785
|
-
0n,
|
|
786
|
-
Fr,
|
|
787
|
-
);
|
|
788
|
-
txTree.appendLeaves(messages);
|
|
789
|
-
const root = Fr.fromBuffer(txTree.getRoot(true));
|
|
790
|
-
await txStore.delete();
|
|
791
|
-
return root;
|
|
792
|
-
}),
|
|
793
|
-
);
|
|
794
|
-
|
|
795
|
-
// Construct the top tree and compute the combined path
|
|
796
|
-
let combinedPath: Buffer[];
|
|
797
|
-
{
|
|
798
|
-
const topTreeHeight = Math.ceil(Math.log2(txSubtreeRoots.length));
|
|
799
|
-
// The root of this tree is the out_hash calculated in Noir => we truncate to match Noir's SHA
|
|
800
|
-
const topTree = new UnbalancedTree(new SHA256Trunc(), 'top_tree', topTreeHeight, Fr);
|
|
801
|
-
await topTree.appendLeaves(txSubtreeRoots);
|
|
802
|
-
|
|
803
|
-
const txPathInTopTree = await topTree.getSiblingPath(txSubtreeRoots[txIndex].toBigInt());
|
|
804
|
-
// Append subtree path to top tree path
|
|
805
|
-
combinedPath = messagePathInSubtree.toBufferArray().concat(txPathInTopTree.toBufferArray());
|
|
806
|
-
}
|
|
807
|
-
|
|
808
|
-
// Append binary index of subtree path to binary index of top tree path
|
|
809
|
-
const combinedIndex = parseInt(
|
|
810
|
-
txIndex.toString(2).concat(messageIndexInTx.toString(2).padStart(messageSubtreeHeight, '0')),
|
|
811
|
-
2,
|
|
812
|
-
);
|
|
813
|
-
|
|
814
|
-
return [BigInt(combinedIndex), new SiblingPath(combinedPath.length, combinedPath)];
|
|
745
|
+
return block?.body.txEffects.map(txEffect => txEffect.l2ToL1Msgs);
|
|
815
746
|
}
|
|
816
747
|
|
|
817
748
|
/**
|
package/src/sentinel/factory.ts
CHANGED
|
@@ -3,6 +3,7 @@ import { createLogger } from '@aztec/foundation/log';
|
|
|
3
3
|
import type { DataStoreConfig } from '@aztec/kv-store/config';
|
|
4
4
|
import { createStore } from '@aztec/kv-store/lmdb-v2';
|
|
5
5
|
import type { P2PClient } from '@aztec/p2p';
|
|
6
|
+
import type { SlasherConfig } from '@aztec/slasher/config';
|
|
6
7
|
import type { L2BlockSource } from '@aztec/stdlib/block';
|
|
7
8
|
|
|
8
9
|
import type { SentinelConfig } from './config.js';
|
|
@@ -13,7 +14,7 @@ export async function createSentinel(
|
|
|
13
14
|
epochCache: EpochCache,
|
|
14
15
|
archiver: L2BlockSource,
|
|
15
16
|
p2p: P2PClient,
|
|
16
|
-
config: SentinelConfig & DataStoreConfig,
|
|
17
|
+
config: SentinelConfig & DataStoreConfig & SlasherConfig,
|
|
17
18
|
logger = createLogger('node:sentinel'),
|
|
18
19
|
): Promise<Sentinel | undefined> {
|
|
19
20
|
if (!config.sentinelEnabled) {
|
|
@@ -27,5 +28,5 @@ export async function createSentinel(
|
|
|
27
28
|
);
|
|
28
29
|
const storeHistoryLength = config.sentinelHistoryLengthInEpochs * epochCache.getL1Constants().epochDuration;
|
|
29
30
|
const sentinelStore = new SentinelStore(kvStore, { historyLength: storeHistoryLength });
|
|
30
|
-
return new Sentinel(epochCache, archiver, p2p, sentinelStore, logger);
|
|
31
|
+
return new Sentinel(epochCache, archiver, p2p, sentinelStore, config, logger);
|
|
31
32
|
}
|