@aztec/sequencer-client 0.0.0-test.1 → 0.0.1-commit.b655e406
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/client/sequencer-client.d.ts +25 -25
- package/dest/client/sequencer-client.d.ts.map +1 -1
- package/dest/client/sequencer-client.js +65 -51
- package/dest/config.d.ts +6 -14
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +50 -54
- package/dest/global_variable_builder/global_builder.d.ts +11 -6
- package/dest/global_variable_builder/global_builder.d.ts.map +1 -1
- package/dest/global_variable_builder/global_builder.js +39 -34
- package/dest/index.d.ts +1 -2
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +1 -2
- package/dest/publisher/config.d.ts +6 -8
- package/dest/publisher/config.d.ts.map +1 -1
- package/dest/publisher/config.js +19 -17
- package/dest/publisher/index.d.ts +2 -0
- package/dest/publisher/index.d.ts.map +1 -1
- package/dest/publisher/index.js +3 -0
- package/dest/publisher/sequencer-publisher-factory.d.ts +43 -0
- package/dest/publisher/sequencer-publisher-factory.d.ts.map +1 -0
- package/dest/publisher/sequencer-publisher-factory.js +51 -0
- package/dest/publisher/sequencer-publisher-metrics.d.ts +2 -1
- package/dest/publisher/sequencer-publisher-metrics.d.ts.map +1 -1
- package/dest/publisher/sequencer-publisher-metrics.js +37 -2
- package/dest/publisher/sequencer-publisher.d.ts +102 -69
- package/dest/publisher/sequencer-publisher.d.ts.map +1 -1
- package/dest/publisher/sequencer-publisher.js +606 -212
- package/dest/sequencer/block_builder.d.ts +27 -0
- package/dest/sequencer/block_builder.d.ts.map +1 -0
- package/dest/sequencer/block_builder.js +130 -0
- package/dest/sequencer/config.d.ts +5 -0
- package/dest/sequencer/config.d.ts.map +1 -1
- package/dest/sequencer/errors.d.ts +11 -0
- package/dest/sequencer/errors.d.ts.map +1 -0
- package/dest/sequencer/errors.js +15 -0
- package/dest/sequencer/index.d.ts +1 -1
- package/dest/sequencer/index.d.ts.map +1 -1
- package/dest/sequencer/index.js +1 -1
- package/dest/sequencer/metrics.d.ts +18 -11
- package/dest/sequencer/metrics.d.ts.map +1 -1
- package/dest/sequencer/metrics.js +84 -50
- package/dest/sequencer/sequencer.d.ts +120 -81
- package/dest/sequencer/sequencer.d.ts.map +1 -1
- package/dest/sequencer/sequencer.js +589 -359
- package/dest/sequencer/timetable.d.ts +32 -20
- package/dest/sequencer/timetable.d.ts.map +1 -1
- package/dest/sequencer/timetable.js +57 -30
- package/dest/sequencer/utils.d.ts +11 -35
- package/dest/sequencer/utils.d.ts.map +1 -1
- package/dest/sequencer/utils.js +9 -47
- package/dest/test/index.d.ts +7 -0
- package/dest/test/index.d.ts.map +1 -1
- package/dest/test/index.js +0 -4
- package/dest/tx_validator/nullifier_cache.d.ts +0 -2
- package/dest/tx_validator/nullifier_cache.d.ts.map +1 -1
- package/dest/tx_validator/tx_validator_factory.d.ts +9 -10
- package/dest/tx_validator/tx_validator_factory.d.ts.map +1 -1
- package/dest/tx_validator/tx_validator_factory.js +27 -24
- package/package.json +42 -43
- package/src/client/sequencer-client.ts +94 -84
- package/src/config.ts +57 -61
- package/src/global_variable_builder/global_builder.ts +44 -23
- package/src/index.ts +6 -2
- package/src/publisher/config.ts +26 -24
- package/src/publisher/index.ts +4 -0
- package/src/publisher/sequencer-publisher-factory.ts +90 -0
- package/src/publisher/sequencer-publisher-metrics.ts +24 -2
- package/src/publisher/sequencer-publisher.ts +729 -235
- package/src/sequencer/block_builder.ts +218 -0
- package/src/sequencer/config.ts +7 -0
- package/src/sequencer/errors.ts +21 -0
- package/src/sequencer/index.ts +1 -1
- package/src/sequencer/metrics.ts +109 -55
- package/src/sequencer/sequencer.ts +766 -415
- package/src/sequencer/timetable.ts +98 -33
- package/src/sequencer/utils.ts +17 -58
- package/src/test/index.ts +11 -4
- package/src/tx_validator/tx_validator_factory.ts +44 -32
- package/dest/sequencer/allowed.d.ts +0 -3
- package/dest/sequencer/allowed.d.ts.map +0 -1
- package/dest/sequencer/allowed.js +0 -27
- package/dest/slasher/factory.d.ts +0 -7
- package/dest/slasher/factory.d.ts.map +0 -1
- package/dest/slasher/factory.js +0 -8
- package/dest/slasher/index.d.ts +0 -3
- package/dest/slasher/index.d.ts.map +0 -1
- package/dest/slasher/index.js +0 -2
- package/dest/slasher/slasher_client.d.ts +0 -75
- package/dest/slasher/slasher_client.d.ts.map +0 -1
- package/dest/slasher/slasher_client.js +0 -132
- package/dest/tx_validator/archive_cache.d.ts +0 -14
- package/dest/tx_validator/archive_cache.d.ts.map +0 -1
- package/dest/tx_validator/archive_cache.js +0 -22
- package/dest/tx_validator/gas_validator.d.ts +0 -14
- package/dest/tx_validator/gas_validator.d.ts.map +0 -1
- package/dest/tx_validator/gas_validator.js +0 -78
- package/dest/tx_validator/phases_validator.d.ts +0 -12
- package/dest/tx_validator/phases_validator.d.ts.map +0 -1
- package/dest/tx_validator/phases_validator.js +0 -80
- package/dest/tx_validator/test_utils.d.ts +0 -23
- package/dest/tx_validator/test_utils.d.ts.map +0 -1
- package/dest/tx_validator/test_utils.js +0 -26
- package/src/sequencer/allowed.ts +0 -36
- package/src/slasher/factory.ts +0 -15
- package/src/slasher/index.ts +0 -2
- package/src/slasher/slasher_client.ts +0 -193
- package/src/tx_validator/archive_cache.ts +0 -28
- package/src/tx_validator/gas_validator.ts +0 -101
- package/src/tx_validator/phases_validator.ts +0 -98
- package/src/tx_validator/test_utils.ts +0 -48
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { Fr } from '@aztec/foundation/fields';
|
|
2
|
+
import { DateProvider } from '@aztec/foundation/timer';
|
|
3
|
+
import { PublicProcessor } from '@aztec/simulator/server';
|
|
4
|
+
import type { ContractDataSource } from '@aztec/stdlib/contract';
|
|
5
|
+
import { type L1RollupConstants } from '@aztec/stdlib/epoch-helpers';
|
|
6
|
+
import type { BuildBlockResult, FullNodeBlockBuilderConfig, IFullNodeBlockBuilder, MerkleTreeWriteOperations, PublicProcessorLimits, PublicProcessorValidator, WorldStateSynchronizer } from '@aztec/stdlib/interfaces/server';
|
|
7
|
+
import { GlobalVariables, Tx } from '@aztec/stdlib/tx';
|
|
8
|
+
import { type TelemetryClient } from '@aztec/telemetry-client';
|
|
9
|
+
export declare function buildBlock(pendingTxs: Iterable<Tx> | AsyncIterable<Tx>, l1ToL2Messages: Fr[], newGlobalVariables: GlobalVariables, opts: PublicProcessorLimits | undefined, worldStateFork: MerkleTreeWriteOperations, processor: PublicProcessor, validator: PublicProcessorValidator, l1Constants: Pick<L1RollupConstants, 'l1GenesisTime' | 'slotDuration'>, dateProvider: DateProvider, telemetryClient?: TelemetryClient): Promise<BuildBlockResult>;
|
|
10
|
+
export declare class FullNodeBlockBuilder implements IFullNodeBlockBuilder {
|
|
11
|
+
private config;
|
|
12
|
+
private worldState;
|
|
13
|
+
private contractDataSource;
|
|
14
|
+
private dateProvider;
|
|
15
|
+
private telemetryClient;
|
|
16
|
+
constructor(config: FullNodeBlockBuilderConfig, worldState: WorldStateSynchronizer, contractDataSource: ContractDataSource, dateProvider: DateProvider, telemetryClient?: TelemetryClient);
|
|
17
|
+
getConfig(): FullNodeBlockBuilderConfig;
|
|
18
|
+
updateConfig(config: Partial<FullNodeBlockBuilderConfig>): void;
|
|
19
|
+
makeBlockBuilderDeps(globalVariables: GlobalVariables, fork: MerkleTreeWriteOperations): Promise<{
|
|
20
|
+
processor: PublicProcessor;
|
|
21
|
+
validator: PublicProcessorValidator;
|
|
22
|
+
}>;
|
|
23
|
+
private syncToPreviousBlock;
|
|
24
|
+
buildBlock(pendingTxs: Iterable<Tx> | AsyncIterable<Tx>, l1ToL2Messages: Fr[], globalVariables: GlobalVariables, opts: PublicProcessorLimits, suppliedFork?: MerkleTreeWriteOperations): Promise<BuildBlockResult>;
|
|
25
|
+
getFork(blockNumber: number): Promise<MerkleTreeWriteOperations>;
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=block_builder.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"block_builder.d.ts","sourceRoot":"","sources":["../../src/sequencer/block_builder.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,0BAA0B,CAAC;AAInD,OAAO,EAAE,YAAY,EAAkB,MAAM,yBAAyB,CAAC;AAGvE,OAAO,EAGL,eAAe,EAEhB,MAAM,yBAAyB,CAAC;AACjC,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAC;AACjE,OAAO,EAAE,KAAK,iBAAiB,EAAuB,MAAM,6BAA6B,CAAC;AAE1F,OAAO,KAAK,EACV,gBAAgB,EAChB,0BAA0B,EAC1B,qBAAqB,EACrB,yBAAyB,EACzB,qBAAqB,EACrB,wBAAwB,EACxB,sBAAsB,EACvB,MAAM,iCAAiC,CAAC;AACzC,OAAO,EAAE,eAAe,EAAE,EAAE,EAAE,MAAM,kBAAkB,CAAC;AACvD,OAAO,EAAE,KAAK,eAAe,EAAsB,MAAM,yBAAyB,CAAC;AAMnF,wBAAsB,UAAU,CAC9B,UAAU,EAAE,QAAQ,CAAC,EAAE,CAAC,GAAG,aAAa,CAAC,EAAE,CAAC,EAC5C,cAAc,EAAE,EAAE,EAAE,EACpB,kBAAkB,EAAE,eAAe,EACnC,IAAI,EAAE,qBAAqB,YAAK,EAChC,cAAc,EAAE,yBAAyB,EACzC,SAAS,EAAE,eAAe,EAC1B,SAAS,EAAE,wBAAwB,EACnC,WAAW,EAAE,IAAI,CAAC,iBAAiB,EAAE,eAAe,GAAG,cAAc,CAAC,EACtE,YAAY,EAAE,YAAY,EAC1B,eAAe,GAAE,eAAsC,GACtD,OAAO,CAAC,gBAAgB,CAAC,CA4C3B;AAWD,qBAAa,oBAAqB,YAAW,qBAAqB;IAE9D,OAAO,CAAC,MAAM;IACd,OAAO,CAAC,UAAU;IAClB,OAAO,CAAC,kBAAkB;IAC1B,OAAO,CAAC,YAAY;IACpB,OAAO,CAAC,eAAe;gBAJf,MAAM,EAAE,0BAA0B,EAClC,UAAU,EAAE,sBAAsB,EAClC,kBAAkB,EAAE,kBAAkB,EACtC,YAAY,EAAE,YAAY,EAC1B,eAAe,GAAE,eAAsC;IAG1D,SAAS,IAAI,0BAA0B;IAIvC,YAAY,CAAC,MAAM,EAAE,OAAO,CAAC,0BAA0B,CAAC;IAIlD,oBAAoB,CAAC,eAAe,EAAE,eAAe,EAAE,IAAI,EAAE,yBAAyB;;;;YAyCrF,mBAAmB;IAU3B,UAAU,CACd,UAAU,EAAE,QAAQ,CAAC,EAAE,CAAC,GAAG,aAAa,CAAC,EAAE,CAAC,EAC5C,cAAc,EAAE,EAAE,EAAE,EACpB,eAAe,EAAE,eAAe,EAChC,IAAI,EAAE,qBAAqB,EAC3B,YAAY,CAAC,EAAE,yBAAyB,GACvC,OAAO,CAAC,gBAAgB,CAAC;IAwC5B,OAAO,CAAC,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,yBAAyB,CAAC;CAGjE"}
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import { MerkleTreeId } from '@aztec/aztec.js/trees';
|
|
2
|
+
import { merge, pick } from '@aztec/foundation/collection';
|
|
3
|
+
import { createLogger } from '@aztec/foundation/log';
|
|
4
|
+
import { retryUntil } from '@aztec/foundation/retry';
|
|
5
|
+
import { bufferToHex } from '@aztec/foundation/string';
|
|
6
|
+
import { Timer, elapsed } from '@aztec/foundation/timer';
|
|
7
|
+
import { getDefaultAllowedSetupFunctions } from '@aztec/p2p/msg_validators';
|
|
8
|
+
import { LightweightBlockFactory } from '@aztec/prover-client/block-factory';
|
|
9
|
+
import { GuardedMerkleTreeOperations, PublicContractsDB, PublicProcessor, TelemetryPublicTxSimulator } from '@aztec/simulator/server';
|
|
10
|
+
import { getTimestampForSlot } from '@aztec/stdlib/epoch-helpers';
|
|
11
|
+
import { Gas } from '@aztec/stdlib/gas';
|
|
12
|
+
import { getTelemetryClient } from '@aztec/telemetry-client';
|
|
13
|
+
import { createValidatorForBlockBuilding } from '../tx_validator/tx_validator_factory.js';
|
|
14
|
+
const log = createLogger('block-builder');
|
|
15
|
+
export async function buildBlock(pendingTxs, l1ToL2Messages, newGlobalVariables, opts = {}, worldStateFork, processor, validator, l1Constants, dateProvider, telemetryClient = getTelemetryClient()) {
|
|
16
|
+
const blockBuildingTimer = new Timer();
|
|
17
|
+
const blockNumber = newGlobalVariables.blockNumber;
|
|
18
|
+
const slot = newGlobalVariables.slotNumber.toBigInt();
|
|
19
|
+
const msgCount = l1ToL2Messages.length;
|
|
20
|
+
const stateReference = await worldStateFork.getStateReference();
|
|
21
|
+
const archiveTree = await worldStateFork.getTreeInfo(MerkleTreeId.ARCHIVE);
|
|
22
|
+
log.verbose(`Building block ${blockNumber} for slot ${slot}`, {
|
|
23
|
+
slot,
|
|
24
|
+
slotStart: new Date(Number(getTimestampForSlot(slot, l1Constants)) * 1000),
|
|
25
|
+
now: new Date(dateProvider.now()),
|
|
26
|
+
blockNumber,
|
|
27
|
+
msgCount,
|
|
28
|
+
initialStateReference: stateReference.toInspect(),
|
|
29
|
+
initialArchiveRoot: bufferToHex(archiveTree.root),
|
|
30
|
+
opts
|
|
31
|
+
});
|
|
32
|
+
const blockFactory = new LightweightBlockFactory(worldStateFork, telemetryClient);
|
|
33
|
+
await blockFactory.startNewBlock(newGlobalVariables, l1ToL2Messages);
|
|
34
|
+
const [publicProcessorDuration, [processedTxs, failedTxs, usedTxs]] = await elapsed(()=>processor.process(pendingTxs, opts, validator));
|
|
35
|
+
// All real transactions have been added, set the block as full and pad if needed
|
|
36
|
+
await blockFactory.addTxs(processedTxs);
|
|
37
|
+
const block = await blockFactory.setBlockCompleted();
|
|
38
|
+
// How much public gas was processed
|
|
39
|
+
const publicGas = processedTxs.reduce((acc, tx)=>acc.add(tx.gasUsed.publicGas), Gas.empty());
|
|
40
|
+
const res = {
|
|
41
|
+
block,
|
|
42
|
+
publicGas,
|
|
43
|
+
publicProcessorDuration,
|
|
44
|
+
numMsgs: l1ToL2Messages.length,
|
|
45
|
+
numTxs: processedTxs.length,
|
|
46
|
+
failedTxs: failedTxs,
|
|
47
|
+
blockBuildingTimer,
|
|
48
|
+
usedTxs
|
|
49
|
+
};
|
|
50
|
+
log.trace('Built block', res.block.header);
|
|
51
|
+
return res;
|
|
52
|
+
}
|
|
53
|
+
const FullNodeBlockBuilderConfigKeys = [
|
|
54
|
+
'l1GenesisTime',
|
|
55
|
+
'slotDuration',
|
|
56
|
+
'l1ChainId',
|
|
57
|
+
'rollupVersion',
|
|
58
|
+
'txPublicSetupAllowList',
|
|
59
|
+
'fakeProcessingDelayPerTxMs'
|
|
60
|
+
];
|
|
61
|
+
export class FullNodeBlockBuilder {
|
|
62
|
+
config;
|
|
63
|
+
worldState;
|
|
64
|
+
contractDataSource;
|
|
65
|
+
dateProvider;
|
|
66
|
+
telemetryClient;
|
|
67
|
+
constructor(config, worldState, contractDataSource, dateProvider, telemetryClient = getTelemetryClient()){
|
|
68
|
+
this.config = config;
|
|
69
|
+
this.worldState = worldState;
|
|
70
|
+
this.contractDataSource = contractDataSource;
|
|
71
|
+
this.dateProvider = dateProvider;
|
|
72
|
+
this.telemetryClient = telemetryClient;
|
|
73
|
+
}
|
|
74
|
+
getConfig() {
|
|
75
|
+
return pick(this.config, ...FullNodeBlockBuilderConfigKeys);
|
|
76
|
+
}
|
|
77
|
+
updateConfig(config) {
|
|
78
|
+
this.config = merge(this.config, pick(config, ...FullNodeBlockBuilderConfigKeys));
|
|
79
|
+
}
|
|
80
|
+
async makeBlockBuilderDeps(globalVariables, fork) {
|
|
81
|
+
const txPublicSetupAllowList = this.config.txPublicSetupAllowList ?? await getDefaultAllowedSetupFunctions();
|
|
82
|
+
const contractsDB = new PublicContractsDB(this.contractDataSource);
|
|
83
|
+
const guardedFork = new GuardedMerkleTreeOperations(fork);
|
|
84
|
+
const publicTxSimulator = new TelemetryPublicTxSimulator(guardedFork, contractsDB, globalVariables, this.telemetryClient, {
|
|
85
|
+
doMerkleOperations: true,
|
|
86
|
+
skipFeeEnforcement: true,
|
|
87
|
+
clientInitiatedSimulation: false
|
|
88
|
+
});
|
|
89
|
+
const processor = new PublicProcessor(globalVariables, guardedFork, contractsDB, publicTxSimulator, this.dateProvider, this.telemetryClient, undefined, this.config);
|
|
90
|
+
const validator = createValidatorForBlockBuilding(fork, this.contractDataSource, globalVariables, txPublicSetupAllowList);
|
|
91
|
+
return {
|
|
92
|
+
processor,
|
|
93
|
+
validator
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
async syncToPreviousBlock(parentBlockNumber, timeout) {
|
|
97
|
+
await retryUntil(()=>this.worldState.syncImmediate(parentBlockNumber, true).then((syncedTo)=>syncedTo >= parentBlockNumber), 'sync to previous block', timeout, 0.1);
|
|
98
|
+
log.debug(`Synced to previous block ${parentBlockNumber}`);
|
|
99
|
+
}
|
|
100
|
+
async buildBlock(pendingTxs, l1ToL2Messages, globalVariables, opts, suppliedFork) {
|
|
101
|
+
const parentBlockNumber = globalVariables.blockNumber - 1;
|
|
102
|
+
const syncTimeout = opts.deadline ? (opts.deadline.getTime() - this.dateProvider.now()) / 1000 : undefined;
|
|
103
|
+
await this.syncToPreviousBlock(parentBlockNumber, syncTimeout);
|
|
104
|
+
const fork = suppliedFork ?? await this.worldState.fork(parentBlockNumber);
|
|
105
|
+
try {
|
|
106
|
+
const { processor, validator } = await this.makeBlockBuilderDeps(globalVariables, fork);
|
|
107
|
+
const res = await buildBlock(pendingTxs, l1ToL2Messages, globalVariables, opts, fork, processor, validator, this.config, this.dateProvider, this.telemetryClient);
|
|
108
|
+
return res;
|
|
109
|
+
} finally{
|
|
110
|
+
// If the fork was supplied, we don't close it.
|
|
111
|
+
// Otherwise, we wait a bit to close the fork we just created,
|
|
112
|
+
// since the processor may still be working on a dangling tx
|
|
113
|
+
// which was interrupted due to the processingDeadline being hit.
|
|
114
|
+
if (!suppliedFork) {
|
|
115
|
+
// eslint-disable-next-line @typescript-eslint/no-misused-promises
|
|
116
|
+
setTimeout(async ()=>{
|
|
117
|
+
try {
|
|
118
|
+
await fork.close();
|
|
119
|
+
} catch (err) {
|
|
120
|
+
// This can happen if the sequencer is stopped before we hit this timeout.
|
|
121
|
+
log.warn(`Error closing forks for block processing`, err);
|
|
122
|
+
}
|
|
123
|
+
}, 5000);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
getFork(blockNumber) {
|
|
128
|
+
return this.worldState.fork(blockNumber);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
@@ -1,2 +1,7 @@
|
|
|
1
|
+
import type { GovernanceProposerContract, RollupContract } from '@aztec/ethereum';
|
|
1
2
|
export { type SequencerConfig } from '@aztec/stdlib/config';
|
|
3
|
+
export type SequencerContracts = {
|
|
4
|
+
rollupContract: RollupContract;
|
|
5
|
+
governanceProposerContract: GovernanceProposerContract;
|
|
6
|
+
};
|
|
2
7
|
//# sourceMappingURL=config.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/sequencer/config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,eAAe,EAAE,MAAM,sBAAsB,CAAC"}
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/sequencer/config.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,0BAA0B,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAElF,OAAO,EAAE,KAAK,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAE5D,MAAM,MAAM,kBAAkB,GAAG;IAC/B,cAAc,EAAE,cAAc,CAAC;IAC/B,0BAA0B,EAAE,0BAA0B,CAAC;CACxD,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { SequencerState } from './utils.js';
|
|
2
|
+
export declare class SequencerTooSlowError extends Error {
|
|
3
|
+
readonly proposedState: SequencerState;
|
|
4
|
+
readonly maxAllowedTime: number;
|
|
5
|
+
readonly currentTime: number;
|
|
6
|
+
constructor(proposedState: SequencerState, maxAllowedTime: number, currentTime: number);
|
|
7
|
+
}
|
|
8
|
+
export declare class SequencerInterruptedError extends Error {
|
|
9
|
+
constructor();
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/sequencer/errors.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAEjD,qBAAa,qBAAsB,SAAQ,KAAK;aAE5B,aAAa,EAAE,cAAc;aAC7B,cAAc,EAAE,MAAM;aACtB,WAAW,EAAE,MAAM;gBAFnB,aAAa,EAAE,cAAc,EAC7B,cAAc,EAAE,MAAM,EACtB,WAAW,EAAE,MAAM;CAOtC;AAED,qBAAa,yBAA0B,SAAQ,KAAK;;CAKnD"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export class SequencerTooSlowError extends Error {
|
|
2
|
+
proposedState;
|
|
3
|
+
maxAllowedTime;
|
|
4
|
+
currentTime;
|
|
5
|
+
constructor(proposedState, maxAllowedTime, currentTime){
|
|
6
|
+
super(`Too far into slot for ${proposedState} (time into slot ${currentTime}s greater than ${maxAllowedTime}s allowance)`), this.proposedState = proposedState, this.maxAllowedTime = maxAllowedTime, this.currentTime = currentTime;
|
|
7
|
+
this.name = 'SequencerTooSlowError';
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
export class SequencerInterruptedError extends Error {
|
|
11
|
+
constructor(){
|
|
12
|
+
super(`Sequencer was interrupted`);
|
|
13
|
+
this.name = 'SequencerInterruptedError';
|
|
14
|
+
}
|
|
15
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/sequencer/index.ts"],"names":[],"mappings":"AAAA,cAAc,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/sequencer/index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAC;AACnC,cAAc,aAAa,CAAC;AAC5B,cAAc,gBAAgB,CAAC"}
|
package/dest/sequencer/index.js
CHANGED
|
@@ -1,24 +1,31 @@
|
|
|
1
|
+
import { EthAddress } from '@aztec/aztec.js/addresses';
|
|
2
|
+
import type { RollupContract } from '@aztec/ethereum';
|
|
1
3
|
import { type TelemetryClient, type Tracer } from '@aztec/telemetry-client';
|
|
2
|
-
import { type
|
|
4
|
+
import { type Hex } from 'viem';
|
|
5
|
+
import type { SequencerState } from './utils.js';
|
|
3
6
|
export declare class SequencerMetrics {
|
|
7
|
+
private rollup;
|
|
4
8
|
readonly tracer: Tracer;
|
|
9
|
+
private meter;
|
|
5
10
|
private blockCounter;
|
|
6
11
|
private blockBuildDuration;
|
|
7
12
|
private blockBuildManaPerSecond;
|
|
8
13
|
private stateTransitionBufferDuration;
|
|
9
|
-
private currentBlockNumber;
|
|
10
|
-
private currentBlockSize;
|
|
11
|
-
private blockBuilderInsertions;
|
|
12
14
|
private timeToCollectAttestations;
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
15
|
+
private allowanceToCollectAttestations;
|
|
16
|
+
private requiredAttestions;
|
|
17
|
+
private collectedAttestions;
|
|
18
|
+
private rewards;
|
|
19
|
+
private slots;
|
|
20
|
+
private filledSlots;
|
|
21
|
+
private lastSeenSlot?;
|
|
22
|
+
constructor(client: TelemetryClient, rollup: RollupContract, name?: string);
|
|
23
|
+
recordRequiredAttestations(requiredAttestationsCount: number, allowanceMs: number): void;
|
|
24
|
+
recordCollectedAttestations(count: number, durationMs: number): void;
|
|
18
25
|
recordBuiltBlock(buildDurationMs: number, totalMana: number): void;
|
|
19
26
|
recordFailedBlock(): void;
|
|
20
|
-
recordNewBlock(blockNumber: number, txCount: number): void;
|
|
21
27
|
recordStateTransitionBufferMs(durationMs: number, state: SequencerState): void;
|
|
22
|
-
|
|
28
|
+
incOpenSlot(slot: bigint, proposer: string): void;
|
|
29
|
+
incFilledSlot(proposer: string, coinbase: Hex | EthAddress | undefined): Promise<void>;
|
|
23
30
|
}
|
|
24
31
|
//# sourceMappingURL=metrics.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"metrics.d.ts","sourceRoot":"","sources":["../../src/sequencer/metrics.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"metrics.d.ts","sourceRoot":"","sources":["../../src/sequencer/metrics.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAC;AACvD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AACtD,OAAO,EAML,KAAK,eAAe,EACpB,KAAK,MAAM,EAGZ,MAAM,yBAAyB,CAAC;AAEjC,OAAO,EAAE,KAAK,GAAG,EAAe,MAAM,MAAM,CAAC;AAE7C,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAEjD,qBAAa,gBAAgB;IAwBzB,OAAO,CAAC,MAAM;IAvBhB,SAAgB,MAAM,EAAE,MAAM,CAAC;IAC/B,OAAO,CAAC,KAAK,CAAQ;IAErB,OAAO,CAAC,YAAY,CAAgB;IACpC,OAAO,CAAC,kBAAkB,CAAY;IACtC,OAAO,CAAC,uBAAuB,CAAQ;IACvC,OAAO,CAAC,6BAA6B,CAAY;IAGjD,OAAO,CAAC,yBAAyB,CAAQ;IACzC,OAAO,CAAC,8BAA8B,CAAQ;IAC9C,OAAO,CAAC,kBAAkB,CAAQ;IAClC,OAAO,CAAC,mBAAmB,CAAQ;IAEnC,OAAO,CAAC,OAAO,CAAQ;IAEvB,OAAO,CAAC,KAAK,CAAgB;IAC7B,OAAO,CAAC,WAAW,CAAgB;IAEnC,OAAO,CAAC,YAAY,CAAC,CAAS;gBAG5B,MAAM,EAAE,eAAe,EACf,MAAM,EAAE,cAAc,EAC9B,IAAI,SAAc;IAkFb,0BAA0B,CAAC,yBAAyB,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM;IASjF,2BAA2B,CAAC,KAAK,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM;IAKpE,gBAAgB,CAAC,eAAe,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM;IAQ3D,iBAAiB;IAMjB,6BAA6B,CAAC,UAAU,EAAE,MAAM,EAAE,KAAK,EAAE,cAAc;IAMvE,WAAW,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM;IAapC,aAAa,CAAC,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,GAAG,GAAG,UAAU,GAAG,SAAS,GAAG,OAAO,CAAC,IAAI,CAAC;CAkB7F"}
|
|
@@ -1,78 +1,93 @@
|
|
|
1
1
|
import { Attributes, Metrics, ValueType } from '@aztec/telemetry-client';
|
|
2
|
-
import {
|
|
2
|
+
import { formatUnits } from 'viem';
|
|
3
3
|
export class SequencerMetrics {
|
|
4
|
+
rollup;
|
|
4
5
|
tracer;
|
|
6
|
+
meter;
|
|
5
7
|
blockCounter;
|
|
6
8
|
blockBuildDuration;
|
|
7
9
|
blockBuildManaPerSecond;
|
|
8
10
|
stateTransitionBufferDuration;
|
|
9
|
-
|
|
10
|
-
currentBlockSize;
|
|
11
|
-
blockBuilderInsertions;
|
|
11
|
+
// these are gauges because for individual sequencers building a block is not something that happens often enough to warrant a histogram
|
|
12
12
|
timeToCollectAttestations;
|
|
13
|
-
|
|
14
|
-
|
|
13
|
+
allowanceToCollectAttestations;
|
|
14
|
+
requiredAttestions;
|
|
15
|
+
collectedAttestions;
|
|
16
|
+
rewards;
|
|
17
|
+
slots;
|
|
18
|
+
filledSlots;
|
|
19
|
+
lastSeenSlot;
|
|
20
|
+
constructor(client, rollup, name = 'Sequencer'){
|
|
21
|
+
this.rollup = rollup;
|
|
22
|
+
this.meter = client.getMeter(name);
|
|
15
23
|
this.tracer = client.getTracer(name);
|
|
16
|
-
this.blockCounter = meter.createUpDownCounter(Metrics.SEQUENCER_BLOCK_COUNT);
|
|
17
|
-
this.blockBuildDuration = meter.createHistogram(Metrics.SEQUENCER_BLOCK_BUILD_DURATION, {
|
|
24
|
+
this.blockCounter = this.meter.createUpDownCounter(Metrics.SEQUENCER_BLOCK_COUNT);
|
|
25
|
+
this.blockBuildDuration = this.meter.createHistogram(Metrics.SEQUENCER_BLOCK_BUILD_DURATION, {
|
|
18
26
|
unit: 'ms',
|
|
19
27
|
description: 'Duration to build a block',
|
|
20
28
|
valueType: ValueType.INT
|
|
21
29
|
});
|
|
22
|
-
this.blockBuildManaPerSecond = meter.createGauge(Metrics.SEQUENCER_BLOCK_BUILD_MANA_PER_SECOND, {
|
|
30
|
+
this.blockBuildManaPerSecond = this.meter.createGauge(Metrics.SEQUENCER_BLOCK_BUILD_MANA_PER_SECOND, {
|
|
23
31
|
unit: 'mana/s',
|
|
24
32
|
description: 'Mana per second when building a block',
|
|
25
33
|
valueType: ValueType.INT
|
|
26
34
|
});
|
|
27
|
-
this.stateTransitionBufferDuration = meter.createHistogram(Metrics.SEQUENCER_STATE_TRANSITION_BUFFER_DURATION, {
|
|
35
|
+
this.stateTransitionBufferDuration = this.meter.createHistogram(Metrics.SEQUENCER_STATE_TRANSITION_BUFFER_DURATION, {
|
|
28
36
|
unit: 'ms',
|
|
29
37
|
description: 'The time difference between when the sequencer needed to transition to a new state and when it actually did.',
|
|
30
38
|
valueType: ValueType.INT
|
|
31
39
|
});
|
|
32
|
-
|
|
33
|
-
|
|
40
|
+
// Init gauges and counters
|
|
41
|
+
this.blockCounter.add(0, {
|
|
42
|
+
[Attributes.STATUS]: 'failed'
|
|
34
43
|
});
|
|
35
|
-
|
|
36
|
-
|
|
44
|
+
this.blockCounter.add(0, {
|
|
45
|
+
[Attributes.STATUS]: 'built'
|
|
37
46
|
});
|
|
38
|
-
this.
|
|
39
|
-
|
|
40
|
-
|
|
47
|
+
this.rewards = this.meter.createGauge(Metrics.SEQUENCER_CURRENT_BLOCK_REWARDS, {
|
|
48
|
+
valueType: ValueType.DOUBLE,
|
|
49
|
+
description: 'The rewards earned'
|
|
41
50
|
});
|
|
42
|
-
this.
|
|
43
|
-
|
|
44
|
-
|
|
51
|
+
this.slots = this.meter.createUpDownCounter(Metrics.SEQUENCER_SLOT_COUNT, {
|
|
52
|
+
valueType: ValueType.INT,
|
|
53
|
+
description: 'The number of slots this sequencer was selected for'
|
|
54
|
+
});
|
|
55
|
+
/**
|
|
56
|
+
* NOTE: we do not track missed slots as a separate metric. That would be difficult to determine
|
|
57
|
+
* Instead, use a computed metric, `slots - filledSlots` to get the number of slots a sequencer has missed.
|
|
58
|
+
*/ this.filledSlots = this.meter.createUpDownCounter(Metrics.SEQUENCER_FILLED_SLOT_COUNT, {
|
|
59
|
+
valueType: ValueType.INT,
|
|
60
|
+
description: 'The number of slots this sequencer has filled'
|
|
45
61
|
});
|
|
46
|
-
this.timeToCollectAttestations = meter.createGauge(Metrics.
|
|
62
|
+
this.timeToCollectAttestations = this.meter.createGauge(Metrics.SEQUENCER_COLLECT_ATTESTATIONS_DURATION, {
|
|
47
63
|
description: 'The time spent collecting attestations from committee members',
|
|
64
|
+
unit: 'ms',
|
|
48
65
|
valueType: ValueType.INT
|
|
49
66
|
});
|
|
50
|
-
this.
|
|
51
|
-
description: '
|
|
52
|
-
unit: '
|
|
67
|
+
this.allowanceToCollectAttestations = this.meter.createGauge(Metrics.SEQUENCER_COLLECT_ATTESTATIONS_TIME_ALLOWANCE, {
|
|
68
|
+
description: 'Maximum amount of time to collect attestations',
|
|
69
|
+
unit: 'ms',
|
|
53
70
|
valueType: ValueType.INT
|
|
54
71
|
});
|
|
55
|
-
this.
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
};
|
|
63
|
-
return stop.bind(this);
|
|
64
|
-
}
|
|
65
|
-
recordTimeToCollectAttestations(time) {
|
|
66
|
-
this.timeToCollectAttestations.record(time);
|
|
72
|
+
this.requiredAttestions = this.meter.createGauge(Metrics.SEQUENCER_REQUIRED_ATTESTATIONS_COUNT, {
|
|
73
|
+
valueType: ValueType.INT,
|
|
74
|
+
description: 'The minimum number of attestations required to publish a block'
|
|
75
|
+
});
|
|
76
|
+
this.collectedAttestions = this.meter.createGauge(Metrics.SEQUENCER_COLLECTED_ATTESTATIONS_COUNT, {
|
|
77
|
+
valueType: ValueType.INT,
|
|
78
|
+
description: 'The minimum number of attestations required to publish a block'
|
|
79
|
+
});
|
|
67
80
|
}
|
|
68
|
-
|
|
69
|
-
this.
|
|
81
|
+
recordRequiredAttestations(requiredAttestationsCount, allowanceMs) {
|
|
82
|
+
this.requiredAttestions.record(requiredAttestationsCount);
|
|
83
|
+
this.allowanceToCollectAttestations.record(Math.ceil(allowanceMs));
|
|
84
|
+
// reset
|
|
85
|
+
this.collectedAttestions.record(0);
|
|
86
|
+
this.timeToCollectAttestations.record(0);
|
|
70
87
|
}
|
|
71
|
-
|
|
72
|
-
this.
|
|
73
|
-
|
|
74
|
-
});
|
|
75
|
-
this.setCurrentBlock(0, 0);
|
|
88
|
+
recordCollectedAttestations(count, durationMs) {
|
|
89
|
+
this.collectedAttestions.record(count);
|
|
90
|
+
this.timeToCollectAttestations.record(Math.ceil(durationMs));
|
|
76
91
|
}
|
|
77
92
|
recordBuiltBlock(buildDurationMs, totalMana) {
|
|
78
93
|
this.blockCounter.add(1, {
|
|
@@ -85,18 +100,37 @@ export class SequencerMetrics {
|
|
|
85
100
|
this.blockCounter.add(1, {
|
|
86
101
|
[Attributes.STATUS]: 'failed'
|
|
87
102
|
});
|
|
88
|
-
this.setCurrentBlock(0, 0);
|
|
89
|
-
}
|
|
90
|
-
recordNewBlock(blockNumber, txCount) {
|
|
91
|
-
this.setCurrentBlock(blockNumber, txCount);
|
|
92
103
|
}
|
|
93
104
|
recordStateTransitionBufferMs(durationMs, state) {
|
|
94
105
|
this.stateTransitionBufferDuration.record(durationMs, {
|
|
95
106
|
[Attributes.SEQUENCER_STATE]: state
|
|
96
107
|
});
|
|
97
108
|
}
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
this.
|
|
109
|
+
incOpenSlot(slot, proposer) {
|
|
110
|
+
// sequencer went through the loop a second time. Noop
|
|
111
|
+
if (slot === this.lastSeenSlot) {
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
114
|
+
this.slots.add(1, {
|
|
115
|
+
[Attributes.BLOCK_PROPOSER]: proposer
|
|
116
|
+
});
|
|
117
|
+
this.lastSeenSlot = slot;
|
|
118
|
+
}
|
|
119
|
+
async incFilledSlot(proposer, coinbase) {
|
|
120
|
+
this.filledSlots.add(1, {
|
|
121
|
+
[Attributes.BLOCK_PROPOSER]: proposer
|
|
122
|
+
});
|
|
123
|
+
this.lastSeenSlot = undefined;
|
|
124
|
+
if (coinbase) {
|
|
125
|
+
try {
|
|
126
|
+
const rewards = await this.rollup.getSequencerRewards(coinbase);
|
|
127
|
+
const fmt = parseFloat(formatUnits(rewards, 18));
|
|
128
|
+
this.rewards.record(fmt, {
|
|
129
|
+
[Attributes.COINBASE]: coinbase.toString()
|
|
130
|
+
});
|
|
131
|
+
} catch {
|
|
132
|
+
// no-op
|
|
133
|
+
}
|
|
134
|
+
}
|
|
101
135
|
}
|
|
102
136
|
}
|