@aztec/sequencer-client 0.0.1-commit.c7c42ec → 0.0.1-commit.d1f2d6c

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.
Files changed (71) hide show
  1. package/dest/client/sequencer-client.d.ts +4 -5
  2. package/dest/client/sequencer-client.d.ts.map +1 -1
  3. package/dest/config.d.ts +1 -1
  4. package/dest/config.d.ts.map +1 -1
  5. package/dest/config.js +6 -1
  6. package/dest/global_variable_builder/global_builder.d.ts +4 -4
  7. package/dest/global_variable_builder/global_builder.d.ts.map +1 -1
  8. package/dest/global_variable_builder/global_builder.js +13 -13
  9. package/dest/index.d.ts +2 -3
  10. package/dest/index.d.ts.map +1 -1
  11. package/dest/index.js +1 -2
  12. package/dest/publisher/sequencer-publisher-metrics.d.ts +1 -1
  13. package/dest/publisher/sequencer-publisher-metrics.d.ts.map +1 -1
  14. package/dest/publisher/sequencer-publisher-metrics.js +15 -86
  15. package/dest/publisher/sequencer-publisher.d.ts +17 -16
  16. package/dest/publisher/sequencer-publisher.d.ts.map +1 -1
  17. package/dest/publisher/sequencer-publisher.js +442 -49
  18. package/dest/sequencer/checkpoint_proposal_job.d.ts +14 -9
  19. package/dest/sequencer/checkpoint_proposal_job.d.ts.map +1 -1
  20. package/dest/sequencer/checkpoint_proposal_job.js +561 -39
  21. package/dest/sequencer/checkpoint_voter.d.ts +3 -2
  22. package/dest/sequencer/checkpoint_voter.d.ts.map +1 -1
  23. package/dest/sequencer/checkpoint_voter.js +34 -10
  24. package/dest/sequencer/index.d.ts +1 -3
  25. package/dest/sequencer/index.d.ts.map +1 -1
  26. package/dest/sequencer/index.js +0 -2
  27. package/dest/sequencer/metrics.d.ts +3 -3
  28. package/dest/sequencer/metrics.d.ts.map +1 -1
  29. package/dest/sequencer/metrics.js +30 -121
  30. package/dest/sequencer/sequencer.d.ts +25 -15
  31. package/dest/sequencer/sequencer.d.ts.map +1 -1
  32. package/dest/sequencer/sequencer.js +486 -42
  33. package/dest/test/index.d.ts +2 -3
  34. package/dest/test/index.d.ts.map +1 -1
  35. package/dest/test/mock_checkpoint_builder.d.ts +19 -10
  36. package/dest/test/mock_checkpoint_builder.d.ts.map +1 -1
  37. package/dest/test/mock_checkpoint_builder.js +32 -3
  38. package/dest/test/utils.d.ts +13 -9
  39. package/dest/test/utils.d.ts.map +1 -1
  40. package/dest/test/utils.js +26 -17
  41. package/package.json +30 -28
  42. package/src/client/sequencer-client.ts +3 -4
  43. package/src/config.ts +5 -0
  44. package/src/global_variable_builder/global_builder.ts +13 -13
  45. package/src/index.ts +1 -9
  46. package/src/publisher/sequencer-publisher-metrics.ts +14 -70
  47. package/src/publisher/sequencer-publisher.ts +84 -73
  48. package/src/sequencer/checkpoint_proposal_job.ts +195 -58
  49. package/src/sequencer/checkpoint_voter.ts +32 -7
  50. package/src/sequencer/index.ts +0 -2
  51. package/src/sequencer/metrics.ts +23 -131
  52. package/src/sequencer/sequencer.ts +124 -41
  53. package/src/test/index.ts +1 -2
  54. package/src/test/mock_checkpoint_builder.ts +70 -22
  55. package/src/test/utils.ts +55 -28
  56. package/dest/sequencer/block_builder.d.ts +0 -26
  57. package/dest/sequencer/block_builder.d.ts.map +0 -1
  58. package/dest/sequencer/block_builder.js +0 -129
  59. package/dest/sequencer/checkpoint_builder.d.ts +0 -63
  60. package/dest/sequencer/checkpoint_builder.d.ts.map +0 -1
  61. package/dest/sequencer/checkpoint_builder.js +0 -131
  62. package/dest/tx_validator/nullifier_cache.d.ts +0 -14
  63. package/dest/tx_validator/nullifier_cache.d.ts.map +0 -1
  64. package/dest/tx_validator/nullifier_cache.js +0 -24
  65. package/dest/tx_validator/tx_validator_factory.d.ts +0 -18
  66. package/dest/tx_validator/tx_validator_factory.d.ts.map +0 -1
  67. package/dest/tx_validator/tx_validator_factory.js +0 -53
  68. package/src/sequencer/block_builder.ts +0 -217
  69. package/src/sequencer/checkpoint_builder.ts +0 -217
  70. package/src/tx_validator/nullifier_cache.ts +0 -30
  71. package/src/tx_validator/tx_validator_factory.ts +0 -133
@@ -1,131 +0,0 @@
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 { bufferToHex } from '@aztec/foundation/string';
5
- import { Timer, elapsed } from '@aztec/foundation/timer';
6
- import { getDefaultAllowedSetupFunctions } from '@aztec/p2p/msg_validators';
7
- import { LightweightCheckpointBuilder } from '@aztec/prover-client/light';
8
- import { GuardedMerkleTreeOperations, PublicContractsDB, PublicProcessor, createPublicTxSimulatorForBlockBuilding } from '@aztec/simulator/server';
9
- import { Gas } from '@aztec/stdlib/gas';
10
- import { FullNodeBlockBuilderConfigKeys } from '@aztec/stdlib/interfaces/server';
11
- import { GlobalVariables } from '@aztec/stdlib/tx';
12
- import { getTelemetryClient } from '@aztec/telemetry-client';
13
- import { createValidatorForBlockBuilding } from '../tx_validator/tx_validator_factory.js';
14
- const log = createLogger('checkpoint-builder');
15
- /**
16
- * Builder for a single checkpoint. Handles building blocks within the checkpoint
17
- * and completing it.
18
- */ export class CheckpointBuilder {
19
- checkpointBuilder;
20
- fork;
21
- config;
22
- contractDataSource;
23
- dateProvider;
24
- telemetryClient;
25
- constructor(checkpointBuilder, fork, config, contractDataSource, dateProvider, telemetryClient){
26
- this.checkpointBuilder = checkpointBuilder;
27
- this.fork = fork;
28
- this.config = config;
29
- this.contractDataSource = contractDataSource;
30
- this.dateProvider = dateProvider;
31
- this.telemetryClient = telemetryClient;
32
- }
33
- getConstantData() {
34
- return this.checkpointBuilder.constants;
35
- }
36
- /**
37
- * Builds a single block within this checkpoint.
38
- */ async buildBlock(pendingTxs, blockNumber, timestamp, opts) {
39
- const blockBuildingTimer = new Timer();
40
- const slot = this.checkpointBuilder.constants.slotNumber;
41
- log.verbose(`Building block ${blockNumber} for slot ${slot} within checkpoint`, {
42
- slot,
43
- blockNumber,
44
- ...opts
45
- });
46
- const constants = this.checkpointBuilder.constants;
47
- const globalVariables = GlobalVariables.from({
48
- chainId: constants.chainId,
49
- version: constants.version,
50
- blockNumber,
51
- slotNumber: constants.slotNumber,
52
- timestamp,
53
- coinbase: constants.coinbase,
54
- feeRecipient: constants.feeRecipient,
55
- gasFees: constants.gasFees
56
- });
57
- const { processor, validator } = await this.makeBlockBuilderDeps(globalVariables, this.fork);
58
- const [publicProcessorDuration, [processedTxs, failedTxs, usedTxs]] = await elapsed(()=>processor.process(pendingTxs, opts, validator));
59
- // Add block to checkpoint
60
- const block = await this.checkpointBuilder.addBlock(globalVariables, processedTxs);
61
- // How much public gas was processed
62
- const publicGas = processedTxs.reduce((acc, tx)=>acc.add(tx.gasUsed.publicGas), Gas.empty());
63
- const res = {
64
- block,
65
- publicGas,
66
- publicProcessorDuration,
67
- numTxs: processedTxs.length,
68
- failedTxs,
69
- blockBuildingTimer,
70
- usedTxs
71
- };
72
- log.debug('Built block within checkpoint', res.block.header);
73
- return res;
74
- }
75
- /** Completes the checkpoint and returns it. */ async completeCheckpoint() {
76
- const checkpoint = await this.checkpointBuilder.completeCheckpoint();
77
- log.verbose(`Completed checkpoint ${checkpoint.number}`, {
78
- checkpointNumber: checkpoint.number,
79
- numBlocks: checkpoint.blocks.length,
80
- archiveRoot: checkpoint.archive.root.toString()
81
- });
82
- return checkpoint;
83
- }
84
- /** Gets the checkpoint currently in progress. */ getCheckpoint() {
85
- return this.checkpointBuilder.clone().completeCheckpoint();
86
- }
87
- async makeBlockBuilderDeps(globalVariables, fork) {
88
- const txPublicSetupAllowList = this.config.txPublicSetupAllowList ?? await getDefaultAllowedSetupFunctions();
89
- const contractsDB = new PublicContractsDB(this.contractDataSource);
90
- const guardedFork = new GuardedMerkleTreeOperations(fork);
91
- const publicTxSimulator = createPublicTxSimulatorForBlockBuilding(guardedFork, contractsDB, globalVariables, this.telemetryClient);
92
- const processor = new PublicProcessor(globalVariables, guardedFork, contractsDB, publicTxSimulator, this.dateProvider, this.telemetryClient, undefined, this.config);
93
- const validator = createValidatorForBlockBuilding(fork, this.contractDataSource, globalVariables, txPublicSetupAllowList);
94
- return {
95
- processor,
96
- validator
97
- };
98
- }
99
- }
100
- /**
101
- * Factory for creating checkpoint builders.
102
- */ export class FullNodeCheckpointsBuilder {
103
- config;
104
- contractDataSource;
105
- dateProvider;
106
- telemetryClient;
107
- constructor(config, contractDataSource, dateProvider, telemetryClient = getTelemetryClient()){
108
- this.config = config;
109
- this.contractDataSource = contractDataSource;
110
- this.dateProvider = dateProvider;
111
- this.telemetryClient = telemetryClient;
112
- }
113
- updateConfig(config) {
114
- this.config = merge(this.config, pick(config, ...FullNodeBlockBuilderConfigKeys));
115
- }
116
- /**
117
- * Starts a new checkpoint and returns a CheckpointBuilder to build blocks within it.
118
- */ async startCheckpoint(checkpointNumber, constants, l1ToL2Messages, fork) {
119
- const stateReference = await fork.getStateReference();
120
- const archiveTree = await fork.getTreeInfo(MerkleTreeId.ARCHIVE);
121
- log.verbose(`Building checkpoint ${checkpointNumber}`, {
122
- checkpointNumber,
123
- msgCount: l1ToL2Messages.length,
124
- initialStateReference: stateReference.toInspect(),
125
- initialArchiveRoot: bufferToHex(archiveTree.root),
126
- constants
127
- });
128
- const lightweightBuilder = await LightweightCheckpointBuilder.startNewCheckpoint(checkpointNumber, constants, l1ToL2Messages, fork);
129
- return new CheckpointBuilder(lightweightBuilder, fork, this.config, this.contractDataSource, this.dateProvider, this.telemetryClient);
130
- }
131
- }
@@ -1,14 +0,0 @@
1
- import type { NullifierSource } from '@aztec/p2p';
2
- import type { MerkleTreeReadOperations } from '@aztec/stdlib/interfaces/server';
3
- /**
4
- * Implements a nullifier source by checking a DB and an in-memory collection.
5
- * Intended for validating transactions as they are added to a block.
6
- */
7
- export declare class NullifierCache implements NullifierSource {
8
- private db;
9
- nullifiers: Set<string>;
10
- constructor(db: MerkleTreeReadOperations);
11
- nullifiersExist(nullifiers: Buffer[]): Promise<boolean[]>;
12
- addNullifiers(nullifiers: Buffer[]): void;
13
- }
14
- //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibnVsbGlmaWVyX2NhY2hlLmQudHMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvdHhfdmFsaWRhdG9yL251bGxpZmllcl9jYWNoZS50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxPQUFPLEtBQUssRUFBRSxlQUFlLEVBQUUsTUFBTSxZQUFZLENBQUM7QUFDbEQsT0FBTyxLQUFLLEVBQUUsd0JBQXdCLEVBQUUsTUFBTSxpQ0FBaUMsQ0FBQztBQUdoRjs7O0dBR0c7QUFDSCxxQkFBYSxjQUFlLFlBQVcsZUFBZTtJQUd4QyxPQUFPLENBQUMsRUFBRTtJQUZ0QixVQUFVLEVBQUUsR0FBRyxDQUFDLE1BQU0sQ0FBQyxDQUFDO0lBRXhCLFlBQW9CLEVBQUUsRUFBRSx3QkFBd0IsRUFFL0M7SUFFWSxlQUFlLENBQUMsVUFBVSxFQUFFLE1BQU0sRUFBRSxHQUFHLE9BQU8sQ0FBQyxPQUFPLEVBQUUsQ0FBQyxDQU9yRTtJQUVNLGFBQWEsQ0FBQyxVQUFVLEVBQUUsTUFBTSxFQUFFLFFBSXhDO0NBQ0YifQ==
@@ -1 +0,0 @@
1
- {"version":3,"file":"nullifier_cache.d.ts","sourceRoot":"","sources":["../../src/tx_validator/nullifier_cache.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAClD,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,iCAAiC,CAAC;AAGhF;;;GAGG;AACH,qBAAa,cAAe,YAAW,eAAe;IAGxC,OAAO,CAAC,EAAE;IAFtB,UAAU,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC;IAExB,YAAoB,EAAE,EAAE,wBAAwB,EAE/C;IAEY,eAAe,CAAC,UAAU,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,OAAO,EAAE,CAAC,CAOrE;IAEM,aAAa,CAAC,UAAU,EAAE,MAAM,EAAE,QAIxC;CACF"}
@@ -1,24 +0,0 @@
1
- import { MerkleTreeId } from '@aztec/stdlib/trees';
2
- /**
3
- * Implements a nullifier source by checking a DB and an in-memory collection.
4
- * Intended for validating transactions as they are added to a block.
5
- */ export class NullifierCache {
6
- db;
7
- nullifiers;
8
- constructor(db){
9
- this.db = db;
10
- this.nullifiers = new Set();
11
- }
12
- async nullifiersExist(nullifiers) {
13
- const cacheResults = nullifiers.map((n)=>this.nullifiers.has(n.toString()));
14
- const toCheckDb = nullifiers.filter((_n, index)=>!cacheResults[index]);
15
- const dbHits = await this.db.findLeafIndices(MerkleTreeId.NULLIFIER_TREE, toCheckDb);
16
- let dbIndex = 0;
17
- return nullifiers.map((_n, index)=>cacheResults[index] || dbHits[dbIndex++] !== undefined);
18
- }
19
- addNullifiers(nullifiers) {
20
- for (const nullifier of nullifiers){
21
- this.nullifiers.add(nullifier.toString());
22
- }
23
- }
24
- }
@@ -1,18 +0,0 @@
1
- import { BlockNumber } from '@aztec/foundation/branded-types';
2
- import type { ContractDataSource } from '@aztec/stdlib/contract';
3
- import type { GasFees } from '@aztec/stdlib/gas';
4
- import type { AllowedElement, ClientProtocolCircuitVerifier, MerkleTreeReadOperations, PublicProcessorValidator } from '@aztec/stdlib/interfaces/server';
5
- import { GlobalVariables, type Tx, type TxValidator } from '@aztec/stdlib/tx';
6
- import type { UInt64 } from '@aztec/stdlib/types';
7
- export declare function createValidatorForAcceptingTxs(db: MerkleTreeReadOperations, contractDataSource: ContractDataSource, verifier: ClientProtocolCircuitVerifier | undefined, { l1ChainId, rollupVersion, setupAllowList, gasFees, skipFeeEnforcement, timestamp, blockNumber, txsPermitted }: {
8
- l1ChainId: number;
9
- rollupVersion: number;
10
- setupAllowList: AllowedElement[];
11
- gasFees: GasFees;
12
- skipFeeEnforcement?: boolean;
13
- timestamp: UInt64;
14
- blockNumber: BlockNumber;
15
- txsPermitted: boolean;
16
- }): TxValidator<Tx>;
17
- export declare function createValidatorForBlockBuilding(db: MerkleTreeReadOperations, contractDataSource: ContractDataSource, globalVariables: GlobalVariables, setupAllowList: AllowedElement[]): PublicProcessorValidator;
18
- //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidHhfdmFsaWRhdG9yX2ZhY3RvcnkuZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy90eF92YWxpZGF0b3IvdHhfdmFsaWRhdG9yX2ZhY3RvcnkudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsT0FBTyxFQUFFLFdBQVcsRUFBRSxNQUFNLGlDQUFpQyxDQUFDO0FBaUI5RCxPQUFPLEtBQUssRUFBRSxrQkFBa0IsRUFBRSxNQUFNLHdCQUF3QixDQUFDO0FBQ2pFLE9BQU8sS0FBSyxFQUFFLE9BQU8sRUFBRSxNQUFNLG1CQUFtQixDQUFDO0FBQ2pELE9BQU8sS0FBSyxFQUNWLGNBQWMsRUFDZCw2QkFBNkIsRUFDN0Isd0JBQXdCLEVBQ3hCLHdCQUF3QixFQUN6QixNQUFNLGlDQUFpQyxDQUFDO0FBRXpDLE9BQU8sRUFBRSxlQUFlLEVBQUUsS0FBSyxFQUFFLEVBQUUsS0FBSyxXQUFXLEVBQUUsTUFBTSxrQkFBa0IsQ0FBQztBQUM5RSxPQUFPLEtBQUssRUFBRSxNQUFNLEVBQUUsTUFBTSxxQkFBcUIsQ0FBQztBQUlsRCx3QkFBZ0IsOEJBQThCLENBQzVDLEVBQUUsRUFBRSx3QkFBd0IsRUFDNUIsa0JBQWtCLEVBQUUsa0JBQWtCLEVBQ3RDLFFBQVEsRUFBRSw2QkFBNkIsR0FBRyxTQUFTLEVBQ25ELEVBQ0UsU0FBUyxFQUNULGFBQWEsRUFDYixjQUFjLEVBQ2QsT0FBTyxFQUNQLGtCQUFrQixFQUNsQixTQUFTLEVBQ1QsV0FBVyxFQUNYLFlBQVksRUFDYixFQUFFO0lBQ0QsU0FBUyxFQUFFLE1BQU0sQ0FBQztJQUNsQixhQUFhLEVBQUUsTUFBTSxDQUFDO0lBQ3RCLGNBQWMsRUFBRSxjQUFjLEVBQUUsQ0FBQztJQUNqQyxPQUFPLEVBQUUsT0FBTyxDQUFDO0lBQ2pCLGtCQUFrQixDQUFDLEVBQUUsT0FBTyxDQUFDO0lBQzdCLFNBQVMsRUFBRSxNQUFNLENBQUM7SUFDbEIsV0FBVyxFQUFFLFdBQVcsQ0FBQztJQUN6QixZQUFZLEVBQUUsT0FBTyxDQUFDO0NBQ3ZCLEdBQ0EsV0FBVyxDQUFDLEVBQUUsQ0FBQyxDQTRCakI7QUFFRCx3QkFBZ0IsK0JBQStCLENBQzdDLEVBQUUsRUFBRSx3QkFBd0IsRUFDNUIsa0JBQWtCLEVBQUUsa0JBQWtCLEVBQ3RDLGVBQWUsRUFBRSxlQUFlLEVBQ2hDLGNBQWMsRUFBRSxjQUFjLEVBQUUsR0FDL0Isd0JBQXdCLENBZ0IxQiJ9
@@ -1 +0,0 @@
1
- {"version":3,"file":"tx_validator_factory.d.ts","sourceRoot":"","sources":["../../src/tx_validator/tx_validator_factory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,iCAAiC,CAAC;AAiB9D,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAC;AACjE,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AACjD,OAAO,KAAK,EACV,cAAc,EACd,6BAA6B,EAC7B,wBAAwB,EACxB,wBAAwB,EACzB,MAAM,iCAAiC,CAAC;AAEzC,OAAO,EAAE,eAAe,EAAE,KAAK,EAAE,EAAE,KAAK,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC9E,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAIlD,wBAAgB,8BAA8B,CAC5C,EAAE,EAAE,wBAAwB,EAC5B,kBAAkB,EAAE,kBAAkB,EACtC,QAAQ,EAAE,6BAA6B,GAAG,SAAS,EACnD,EACE,SAAS,EACT,aAAa,EACb,cAAc,EACd,OAAO,EACP,kBAAkB,EAClB,SAAS,EACT,WAAW,EACX,YAAY,EACb,EAAE;IACD,SAAS,EAAE,MAAM,CAAC;IAClB,aAAa,EAAE,MAAM,CAAC;IACtB,cAAc,EAAE,cAAc,EAAE,CAAC;IACjC,OAAO,EAAE,OAAO,CAAC;IACjB,kBAAkB,CAAC,EAAE,OAAO,CAAC;IAC7B,SAAS,EAAE,MAAM,CAAC;IAClB,WAAW,EAAE,WAAW,CAAC;IACzB,YAAY,EAAE,OAAO,CAAC;CACvB,GACA,WAAW,CAAC,EAAE,CAAC,CA4BjB;AAED,wBAAgB,+BAA+B,CAC7C,EAAE,EAAE,wBAAwB,EAC5B,kBAAkB,EAAE,kBAAkB,EACtC,eAAe,EAAE,eAAe,EAChC,cAAc,EAAE,cAAc,EAAE,GAC/B,wBAAwB,CAgB1B"}
@@ -1,53 +0,0 @@
1
- import { Fr } from '@aztec/foundation/curves/bn254';
2
- import { getVKTreeRoot } from '@aztec/noir-protocol-circuits-types/vk-tree';
3
- import { AggregateTxValidator, ArchiveCache, BlockHeaderTxValidator, DataTxValidator, DoubleSpendTxValidator, GasTxValidator, MetadataTxValidator, PhasesTxValidator, TimestampTxValidator, TxPermittedValidator, TxProofValidator } from '@aztec/p2p';
4
- import { ProtocolContractAddress, protocolContractsHash } from '@aztec/protocol-contracts';
5
- import { DatabasePublicStateSource } from '@aztec/stdlib/trees';
6
- import { NullifierCache } from './nullifier_cache.js';
7
- export function createValidatorForAcceptingTxs(db, contractDataSource, verifier, { l1ChainId, rollupVersion, setupAllowList, gasFees, skipFeeEnforcement, timestamp, blockNumber, txsPermitted }) {
8
- const validators = [
9
- new TxPermittedValidator(txsPermitted),
10
- new DataTxValidator(),
11
- new MetadataTxValidator({
12
- l1ChainId: new Fr(l1ChainId),
13
- rollupVersion: new Fr(rollupVersion),
14
- protocolContractsHash,
15
- vkTreeRoot: getVKTreeRoot()
16
- }),
17
- new TimestampTxValidator({
18
- timestamp,
19
- blockNumber
20
- }),
21
- new DoubleSpendTxValidator(new NullifierCache(db)),
22
- new PhasesTxValidator(contractDataSource, setupAllowList, timestamp),
23
- new BlockHeaderTxValidator(new ArchiveCache(db))
24
- ];
25
- if (!skipFeeEnforcement) {
26
- validators.push(new GasTxValidator(new DatabasePublicStateSource(db), ProtocolContractAddress.FeeJuice, gasFees));
27
- }
28
- if (verifier) {
29
- validators.push(new TxProofValidator(verifier));
30
- }
31
- return new AggregateTxValidator(...validators);
32
- }
33
- export function createValidatorForBlockBuilding(db, contractDataSource, globalVariables, setupAllowList) {
34
- const nullifierCache = new NullifierCache(db);
35
- const archiveCache = new ArchiveCache(db);
36
- const publicStateSource = new DatabasePublicStateSource(db);
37
- return {
38
- preprocessValidator: preprocessValidator(nullifierCache, archiveCache, publicStateSource, contractDataSource, globalVariables, setupAllowList),
39
- nullifierCache
40
- };
41
- }
42
- function preprocessValidator(nullifierCache, archiveCache, publicStateSource, contractDataSource, globalVariables, setupAllowList) {
43
- // We don't include the TxProofValidator nor the DataTxValidator here because they are already checked by the time we get to block building.
44
- return new AggregateTxValidator(new MetadataTxValidator({
45
- l1ChainId: globalVariables.chainId,
46
- rollupVersion: globalVariables.version,
47
- protocolContractsHash,
48
- vkTreeRoot: getVKTreeRoot()
49
- }), new TimestampTxValidator({
50
- timestamp: globalVariables.timestamp,
51
- blockNumber: globalVariables.blockNumber
52
- }), new DoubleSpendTxValidator(nullifierCache), new PhasesTxValidator(contractDataSource, setupAllowList, globalVariables.timestamp), new GasTxValidator(publicStateSource, ProtocolContractAddress.FeeJuice, globalVariables.gasFees), new BlockHeaderTxValidator(archiveCache));
53
- }
@@ -1,217 +0,0 @@
1
- import { MerkleTreeId } from '@aztec/aztec.js/trees';
2
- import { BlockNumber } from '@aztec/foundation/branded-types';
3
- import { merge, pick } from '@aztec/foundation/collection';
4
- import type { Fr } from '@aztec/foundation/curves/bn254';
5
- import { createLogger } from '@aztec/foundation/log';
6
- import { retryUntil } from '@aztec/foundation/retry';
7
- import { bufferToHex } from '@aztec/foundation/string';
8
- import { DateProvider, Timer, elapsed } from '@aztec/foundation/timer';
9
- import { getDefaultAllowedSetupFunctions } from '@aztec/p2p/msg_validators';
10
- import { LightweightBlockFactory } from '@aztec/prover-client/block-factory';
11
- import {
12
- GuardedMerkleTreeOperations,
13
- PublicContractsDB,
14
- PublicProcessor,
15
- createPublicTxSimulatorForBlockBuilding,
16
- } from '@aztec/simulator/server';
17
- import type { ContractDataSource } from '@aztec/stdlib/contract';
18
- import { type L1RollupConstants, getTimestampForSlot } from '@aztec/stdlib/epoch-helpers';
19
- import { Gas } from '@aztec/stdlib/gas';
20
- import type {
21
- BuildBlockResult,
22
- FullNodeBlockBuilderConfig,
23
- IFullNodeBlockBuilder,
24
- MerkleTreeWriteOperations,
25
- PublicProcessorLimits,
26
- PublicProcessorValidator,
27
- WorldStateSynchronizer,
28
- } from '@aztec/stdlib/interfaces/server';
29
- import { GlobalVariables, Tx } from '@aztec/stdlib/tx';
30
- import { type TelemetryClient, getTelemetryClient } from '@aztec/telemetry-client';
31
-
32
- import { createValidatorForBlockBuilding } from '../tx_validator/tx_validator_factory.js';
33
-
34
- const log = createLogger('block-builder');
35
-
36
- /** Builds a block out of pending txs */
37
- async function buildBlock(
38
- pendingTxs: Iterable<Tx> | AsyncIterable<Tx>,
39
- l1ToL2Messages: Fr[],
40
- newGlobalVariables: GlobalVariables,
41
- opts: PublicProcessorLimits = {},
42
- worldStateFork: MerkleTreeWriteOperations,
43
- processor: PublicProcessor,
44
- validator: PublicProcessorValidator,
45
- l1Constants: Pick<L1RollupConstants, 'l1GenesisTime' | 'slotDuration'>,
46
- dateProvider: DateProvider,
47
- telemetryClient: TelemetryClient = getTelemetryClient(),
48
- ): Promise<BuildBlockResult> {
49
- const blockBuildingTimer = new Timer();
50
- const blockNumber = newGlobalVariables.blockNumber;
51
- const slot = newGlobalVariables.slotNumber;
52
- const msgCount = l1ToL2Messages.length;
53
- const stateReference = await worldStateFork.getStateReference();
54
- const archiveTree = await worldStateFork.getTreeInfo(MerkleTreeId.ARCHIVE);
55
-
56
- log.verbose(`Building block ${blockNumber} for slot ${slot}`, {
57
- slot,
58
- slotStart: new Date(Number(getTimestampForSlot(slot, l1Constants)) * 1000),
59
- now: new Date(dateProvider.now()),
60
- blockNumber,
61
- msgCount,
62
- initialStateReference: stateReference.toInspect(),
63
- initialArchiveRoot: bufferToHex(archiveTree.root),
64
- opts,
65
- });
66
- const blockFactory = new LightweightBlockFactory(worldStateFork, telemetryClient);
67
- await blockFactory.startNewBlock(newGlobalVariables, l1ToL2Messages);
68
-
69
- const [publicProcessorDuration, [processedTxs, failedTxs, usedTxs]] = await elapsed(() =>
70
- processor.process(pendingTxs, opts, validator),
71
- );
72
-
73
- // All real transactions have been added, set the block as full and pad if needed
74
- await blockFactory.addTxs(processedTxs);
75
- const block = await blockFactory.setBlockCompleted();
76
-
77
- // How much public gas was processed
78
- const publicGas = processedTxs.reduce((acc, tx) => acc.add(tx.gasUsed.publicGas), Gas.empty());
79
-
80
- const res = {
81
- block,
82
- publicGas,
83
- publicProcessorDuration,
84
- numMsgs: l1ToL2Messages.length,
85
- numTxs: processedTxs.length,
86
- failedTxs: failedTxs,
87
- blockBuildingTimer,
88
- usedTxs,
89
- };
90
- log.trace('Built block', res.block.header);
91
- return res;
92
- }
93
-
94
- const FullNodeBlockBuilderConfigKeys = [
95
- 'l1GenesisTime',
96
- 'slotDuration',
97
- 'l1ChainId',
98
- 'rollupVersion',
99
- 'txPublicSetupAllowList',
100
- 'fakeProcessingDelayPerTxMs',
101
- 'fakeThrowAfterProcessingTxCount',
102
- ] as const;
103
-
104
- // TODO(palla/mbps): Try killing this in favor of the CheckpointsBuilder
105
- export class FullNodeBlockBuilder implements IFullNodeBlockBuilder {
106
- constructor(
107
- private config: FullNodeBlockBuilderConfig,
108
- private worldState: WorldStateSynchronizer,
109
- private contractDataSource: ContractDataSource,
110
- private dateProvider: DateProvider,
111
- private telemetryClient: TelemetryClient = getTelemetryClient(),
112
- ) {}
113
-
114
- public getConfig(): FullNodeBlockBuilderConfig {
115
- return pick(this.config, ...FullNodeBlockBuilderConfigKeys);
116
- }
117
-
118
- public updateConfig(config: Partial<FullNodeBlockBuilderConfig>) {
119
- this.config = merge(this.config, pick(config, ...FullNodeBlockBuilderConfigKeys));
120
- }
121
-
122
- public async makeBlockBuilderDeps(globalVariables: GlobalVariables, fork: MerkleTreeWriteOperations) {
123
- const txPublicSetupAllowList = this.config.txPublicSetupAllowList ?? (await getDefaultAllowedSetupFunctions());
124
- const contractsDB = new PublicContractsDB(this.contractDataSource);
125
- const guardedFork = new GuardedMerkleTreeOperations(fork);
126
-
127
- const publicTxSimulator = createPublicTxSimulatorForBlockBuilding(
128
- guardedFork,
129
- contractsDB,
130
- globalVariables,
131
- this.telemetryClient,
132
- );
133
-
134
- const processor = new PublicProcessor(
135
- globalVariables,
136
- guardedFork,
137
- contractsDB,
138
- publicTxSimulator,
139
- this.dateProvider,
140
- this.telemetryClient,
141
- undefined,
142
- this.config,
143
- );
144
-
145
- const validator = createValidatorForBlockBuilding(
146
- fork,
147
- this.contractDataSource,
148
- globalVariables,
149
- txPublicSetupAllowList,
150
- );
151
-
152
- return {
153
- processor,
154
- validator,
155
- };
156
- }
157
-
158
- private async syncToPreviousBlock(parentBlockNumber: BlockNumber, timeout: number | undefined) {
159
- await retryUntil(
160
- () => this.worldState.syncImmediate(parentBlockNumber, true).then(syncedTo => syncedTo >= parentBlockNumber),
161
- 'sync to previous block',
162
- timeout,
163
- 0.1,
164
- );
165
- log.debug(`Synced to previous block ${parentBlockNumber}`);
166
- }
167
-
168
- async buildBlock(
169
- pendingTxs: Iterable<Tx> | AsyncIterable<Tx>,
170
- l1ToL2Messages: Fr[],
171
- globalVariables: GlobalVariables,
172
- opts: PublicProcessorLimits,
173
- suppliedFork?: MerkleTreeWriteOperations,
174
- ): Promise<BuildBlockResult> {
175
- const parentBlockNumber = BlockNumber(globalVariables.blockNumber - 1);
176
- const syncTimeout = opts.deadline ? (opts.deadline.getTime() - this.dateProvider.now()) / 1000 : undefined;
177
- await this.syncToPreviousBlock(parentBlockNumber, syncTimeout);
178
- const fork = suppliedFork ?? (await this.worldState.fork(parentBlockNumber));
179
-
180
- try {
181
- const { processor, validator } = await this.makeBlockBuilderDeps(globalVariables, fork);
182
- const res = await buildBlock(
183
- pendingTxs,
184
- l1ToL2Messages,
185
- globalVariables,
186
- opts,
187
- fork,
188
- processor,
189
- validator,
190
- this.config,
191
- this.dateProvider,
192
- this.telemetryClient,
193
- );
194
- return res;
195
- } finally {
196
- // If the fork was supplied, we don't close it.
197
- // Otherwise, we wait a bit to close the fork we just created,
198
- // since the processor may still be working on a dangling tx
199
- // which was interrupted due to the processingDeadline being hit.
200
- if (!suppliedFork) {
201
- // eslint-disable-next-line @typescript-eslint/no-misused-promises
202
- setTimeout(async () => {
203
- try {
204
- await fork.close();
205
- } catch (err) {
206
- // This can happen if the sequencer is stopped before we hit this timeout.
207
- log.warn(`Error closing forks for block processing`, err);
208
- }
209
- }, 5000);
210
- }
211
- }
212
- }
213
-
214
- getFork(blockNumber: BlockNumber): Promise<MerkleTreeWriteOperations> {
215
- return this.worldState.fork(blockNumber);
216
- }
217
- }