@aztec/aztec-node 0.0.1-commit.934299a21 → 0.0.1-commit.949a33fd8
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/block_response_helpers.d.ts +21 -0
- package/dest/aztec-node/block_response_helpers.d.ts.map +1 -0
- package/dest/aztec-node/block_response_helpers.js +88 -0
- package/dest/aztec-node/config.d.ts +2 -2
- package/dest/aztec-node/config.d.ts.map +1 -1
- package/dest/aztec-node/config.js +1 -1
- package/dest/aztec-node/server.d.ts +47 -81
- package/dest/aztec-node/server.d.ts.map +1 -1
- package/dest/aztec-node/server.js +736 -388
- package/dest/sentinel/factory.d.ts +4 -3
- package/dest/sentinel/factory.d.ts.map +1 -1
- package/dest/sentinel/sentinel.d.ts +6 -3
- package/dest/sentinel/sentinel.d.ts.map +1 -1
- package/dest/sentinel/sentinel.js +16 -10
- package/package.json +26 -27
- package/src/aztec-node/block_response_helpers.ts +131 -0
- package/src/aztec-node/config.ts +1 -1
- package/src/aztec-node/server.ts +855 -490
- package/src/sentinel/factory.ts +3 -2
- package/src/sentinel/sentinel.ts +26 -14
package/src/sentinel/factory.ts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import type { EpochCache } from '@aztec/epoch-cache';
|
|
2
2
|
import { createLogger } from '@aztec/foundation/log';
|
|
3
|
-
import type { DataStoreConfig } from '@aztec/kv-store/config';
|
|
4
3
|
import { createStore } from '@aztec/kv-store/lmdb-v2';
|
|
5
4
|
import type { P2PClient } from '@aztec/p2p';
|
|
6
5
|
import type { L2BlockSource } from '@aztec/stdlib/block';
|
|
6
|
+
import type { ChainConfig } from '@aztec/stdlib/config';
|
|
7
7
|
import type { SlasherConfig } from '@aztec/stdlib/interfaces/server';
|
|
8
|
+
import type { DataStoreConfig } from '@aztec/stdlib/kv-store';
|
|
8
9
|
|
|
9
10
|
import type { SentinelConfig } from './config.js';
|
|
10
11
|
import { Sentinel } from './sentinel.js';
|
|
@@ -14,7 +15,7 @@ export async function createSentinel(
|
|
|
14
15
|
epochCache: EpochCache,
|
|
15
16
|
archiver: L2BlockSource,
|
|
16
17
|
p2p: P2PClient,
|
|
17
|
-
config: SentinelConfig & DataStoreConfig & SlasherConfig,
|
|
18
|
+
config: SentinelConfig & DataStoreConfig & SlasherConfig & Pick<ChainConfig, 'l1ChainId' | 'l1Contracts'>,
|
|
18
19
|
logger = createLogger('node:sentinel'),
|
|
19
20
|
): Promise<Sentinel | undefined> {
|
|
20
21
|
if (!config.sentinelEnabled) {
|
package/src/sentinel/sentinel.ts
CHANGED
|
@@ -21,7 +21,9 @@ import {
|
|
|
21
21
|
type L2BlockStreamEventHandler,
|
|
22
22
|
getAttestationInfoFromPublishedCheckpoint,
|
|
23
23
|
} from '@aztec/stdlib/block';
|
|
24
|
+
import type { ChainConfig } from '@aztec/stdlib/config';
|
|
24
25
|
import { getEpochAtSlot, getSlotRangeForEpoch, getTimestampForSlot } from '@aztec/stdlib/epoch-helpers';
|
|
26
|
+
import type { CoordinationSignatureContext } from '@aztec/stdlib/p2p';
|
|
25
27
|
import type {
|
|
26
28
|
SingleValidatorStats,
|
|
27
29
|
ValidatorStats,
|
|
@@ -36,6 +38,12 @@ import EventEmitter from 'node:events';
|
|
|
36
38
|
|
|
37
39
|
import { SentinelStore } from './store.js';
|
|
38
40
|
|
|
41
|
+
export type SentinelRuntimeConfig = Pick<
|
|
42
|
+
SlasherConfig,
|
|
43
|
+
'slashInactivityTargetPercentage' | 'slashInactivityPenalty' | 'slashInactivityConsecutiveEpochThreshold'
|
|
44
|
+
> &
|
|
45
|
+
Pick<ChainConfig, 'l1ChainId' | 'l1Contracts'>;
|
|
46
|
+
|
|
39
47
|
/** Maps a validator status to its category: proposer or attestation. */
|
|
40
48
|
function statusToCategory(status: ValidatorStatusInSlot): ValidatorStatusType {
|
|
41
49
|
switch (status) {
|
|
@@ -65,10 +73,7 @@ export class Sentinel extends (EventEmitter as new () => WatcherEmitter) impleme
|
|
|
65
73
|
protected archiver: L2BlockSource,
|
|
66
74
|
protected p2p: P2PClient,
|
|
67
75
|
protected store: SentinelStore,
|
|
68
|
-
protected config:
|
|
69
|
-
SlasherConfig,
|
|
70
|
-
'slashInactivityTargetPercentage' | 'slashInactivityPenalty' | 'slashInactivityConsecutiveEpochThreshold'
|
|
71
|
-
>,
|
|
76
|
+
protected config: SentinelRuntimeConfig,
|
|
72
77
|
protected logger = createLogger('node:sentinel'),
|
|
73
78
|
) {
|
|
74
79
|
super();
|
|
@@ -77,6 +82,13 @@ export class Sentinel extends (EventEmitter as new () => WatcherEmitter) impleme
|
|
|
77
82
|
this.runningPromise = new RunningPromise(this.work.bind(this), logger, interval);
|
|
78
83
|
}
|
|
79
84
|
|
|
85
|
+
private getSignatureContext(): CoordinationSignatureContext {
|
|
86
|
+
return {
|
|
87
|
+
chainId: this.config.l1ChainId,
|
|
88
|
+
rollupAddress: this.config.l1Contracts.rollupAddress,
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
|
|
80
92
|
public updateConfig(config: Partial<SlasherConfig>) {
|
|
81
93
|
this.config = { ...this.config, ...config };
|
|
82
94
|
}
|
|
@@ -88,7 +100,7 @@ export class Sentinel extends (EventEmitter as new () => WatcherEmitter) impleme
|
|
|
88
100
|
|
|
89
101
|
/** Loads initial slot and initializes blockstream. We will not process anything at or before the initial slot. */
|
|
90
102
|
protected async init() {
|
|
91
|
-
this.initialSlot = this.epochCache.
|
|
103
|
+
this.initialSlot = this.epochCache.getSlotNow();
|
|
92
104
|
const startingBlock = BlockNumber(await this.archiver.getBlockNumber());
|
|
93
105
|
this.logger.info(`Starting validator sentinel with initial slot ${this.initialSlot} and block ${startingBlock}`);
|
|
94
106
|
this.blockStream = new L2BlockStream(this.archiver, this.l2TipsStore, this, this.logger, { startingBlock });
|
|
@@ -117,7 +129,7 @@ export class Sentinel extends (EventEmitter as new () => WatcherEmitter) impleme
|
|
|
117
129
|
this.slotNumberToCheckpoint.set(checkpoint.checkpoint.header.slotNumber, {
|
|
118
130
|
checkpointNumber: checkpoint.checkpoint.number,
|
|
119
131
|
archive: checkpoint.checkpoint.archive.root.toString(),
|
|
120
|
-
attestors: getAttestationInfoFromPublishedCheckpoint(checkpoint)
|
|
132
|
+
attestors: getAttestationInfoFromPublishedCheckpoint(checkpoint, this.getSignatureContext())
|
|
121
133
|
.filter(a => a.status === 'recovered-from-signature')
|
|
122
134
|
.map(a => a.address!),
|
|
123
135
|
});
|
|
@@ -219,7 +231,7 @@ export class Sentinel extends (EventEmitter as new () => WatcherEmitter) impleme
|
|
|
219
231
|
// Check that we have at least requiredConsecutiveEpochs and that all of them are above the inactivity threshold
|
|
220
232
|
return pastEpochs
|
|
221
233
|
.slice(0, requiredConsecutiveEpochs)
|
|
222
|
-
.every(p => p.missed / p.total >= this.config.slashInactivityTargetPercentage);
|
|
234
|
+
.every(p => (p.total === 0 ? false : p.missed / p.total >= this.config.slashInactivityTargetPercentage));
|
|
223
235
|
}
|
|
224
236
|
|
|
225
237
|
protected async handleProvenPerformance(epoch: EpochNumber, performance: ValidatorsEpochPerformance) {
|
|
@@ -228,7 +240,7 @@ export class Sentinel extends (EventEmitter as new () => WatcherEmitter) impleme
|
|
|
228
240
|
}
|
|
229
241
|
|
|
230
242
|
const inactiveValidators = getEntries(performance)
|
|
231
|
-
.filter(([_, { missed, total }]) => missed / total >= this.config.slashInactivityTargetPercentage)
|
|
243
|
+
.filter(([_, { missed, total }]) => total > 0 && missed / total >= this.config.slashInactivityTargetPercentage)
|
|
232
244
|
.map(([address]) => address);
|
|
233
245
|
|
|
234
246
|
this.logger.debug(`Found ${inactiveValidators.length} inactive validators in epoch ${epoch}`, {
|
|
@@ -264,7 +276,7 @@ export class Sentinel extends (EventEmitter as new () => WatcherEmitter) impleme
|
|
|
264
276
|
* and we don't have that data if we were offline during the period.
|
|
265
277
|
*/
|
|
266
278
|
public async work() {
|
|
267
|
-
const
|
|
279
|
+
const currentSlot = this.epochCache.getSlotNow();
|
|
268
280
|
try {
|
|
269
281
|
// Manually sync the block stream to ensure we have the latest data.
|
|
270
282
|
// Note we never `start` the blockstream, so it loops at the same pace as we do.
|
|
@@ -309,9 +321,9 @@ export class Sentinel extends (EventEmitter as new () => WatcherEmitter) impleme
|
|
|
309
321
|
return false;
|
|
310
322
|
}
|
|
311
323
|
|
|
312
|
-
const
|
|
313
|
-
if (
|
|
314
|
-
this.logger.debug(`Waiting for archiver to sync with L2 slot ${targetSlot}`, {
|
|
324
|
+
const syncedSlot = await this.archiver.getSyncedL2SlotNumber();
|
|
325
|
+
if (syncedSlot === undefined || syncedSlot < targetSlot) {
|
|
326
|
+
this.logger.debug(`Waiting for archiver to sync with L2 slot ${targetSlot}`, { syncedSlot, targetSlot });
|
|
315
327
|
return false;
|
|
316
328
|
}
|
|
317
329
|
|
|
@@ -436,7 +448,7 @@ export class Sentinel extends (EventEmitter as new () => WatcherEmitter) impleme
|
|
|
436
448
|
? fromEntries(await Promise.all(validators.map(async v => [v.toString(), await this.store.getHistory(v)])))
|
|
437
449
|
: await this.store.getHistories();
|
|
438
450
|
|
|
439
|
-
const slotNow = this.epochCache.
|
|
451
|
+
const slotNow = this.epochCache.getSlotNow();
|
|
440
452
|
fromSlot ??= SlotNumber(Math.max((this.lastProcessedSlot ?? slotNow) - this.store.getHistoryLength(), 0));
|
|
441
453
|
toSlot ??= this.lastProcessedSlot ?? slotNow;
|
|
442
454
|
|
|
@@ -464,7 +476,7 @@ export class Sentinel extends (EventEmitter as new () => WatcherEmitter) impleme
|
|
|
464
476
|
return undefined;
|
|
465
477
|
}
|
|
466
478
|
|
|
467
|
-
const slotNow = this.epochCache.
|
|
479
|
+
const slotNow = this.epochCache.getSlotNow();
|
|
468
480
|
const effectiveFromSlot =
|
|
469
481
|
fromSlot ?? SlotNumber(Math.max((this.lastProcessedSlot ?? slotNow) - this.store.getHistoryLength(), 0));
|
|
470
482
|
const effectiveToSlot = toSlot ?? this.lastProcessedSlot ?? slotNow;
|