@aztec/validator-client 0.0.1-commit.d431d1c → 0.0.1-commit.dbf9cec

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 (46) hide show
  1. package/README.md +22 -19
  2. package/dest/block_proposal_handler.d.ts +6 -8
  3. package/dest/block_proposal_handler.d.ts.map +1 -1
  4. package/dest/block_proposal_handler.js +28 -57
  5. package/dest/checkpoint_builder.d.ts +15 -13
  6. package/dest/checkpoint_builder.d.ts.map +1 -1
  7. package/dest/checkpoint_builder.js +51 -31
  8. package/dest/config.d.ts +1 -1
  9. package/dest/config.d.ts.map +1 -1
  10. package/dest/config.js +9 -7
  11. package/dest/duties/validation_service.d.ts +2 -2
  12. package/dest/duties/validation_service.d.ts.map +1 -1
  13. package/dest/duties/validation_service.js +3 -3
  14. package/dest/index.d.ts +1 -2
  15. package/dest/index.d.ts.map +1 -1
  16. package/dest/index.js +0 -1
  17. package/dest/key_store/ha_key_store.d.ts +1 -1
  18. package/dest/key_store/ha_key_store.d.ts.map +1 -1
  19. package/dest/key_store/ha_key_store.js +2 -2
  20. package/dest/metrics.d.ts +4 -3
  21. package/dest/metrics.d.ts.map +1 -1
  22. package/dest/metrics.js +34 -5
  23. package/dest/validator.d.ts +38 -14
  24. package/dest/validator.d.ts.map +1 -1
  25. package/dest/validator.js +182 -51
  26. package/package.json +19 -17
  27. package/src/block_proposal_handler.ts +40 -81
  28. package/src/checkpoint_builder.ts +76 -32
  29. package/src/config.ts +9 -7
  30. package/src/duties/validation_service.ts +9 -2
  31. package/src/index.ts +0 -1
  32. package/src/key_store/ha_key_store.ts +2 -2
  33. package/src/metrics.ts +45 -6
  34. package/src/validator.ts +238 -65
  35. package/dest/tx_validator/index.d.ts +0 -3
  36. package/dest/tx_validator/index.d.ts.map +0 -1
  37. package/dest/tx_validator/index.js +0 -2
  38. package/dest/tx_validator/nullifier_cache.d.ts +0 -14
  39. package/dest/tx_validator/nullifier_cache.d.ts.map +0 -1
  40. package/dest/tx_validator/nullifier_cache.js +0 -24
  41. package/dest/tx_validator/tx_validator_factory.d.ts +0 -18
  42. package/dest/tx_validator/tx_validator_factory.d.ts.map +0 -1
  43. package/dest/tx_validator/tx_validator_factory.js +0 -54
  44. package/src/tx_validator/index.ts +0 -2
  45. package/src/tx_validator/nullifier_cache.ts +0 -30
  46. package/src/tx_validator/tx_validator_factory.ts +0 -135
@@ -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,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidHhfdmFsaWRhdG9yX2ZhY3RvcnkuZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy90eF92YWxpZGF0b3IvdHhfdmFsaWRhdG9yX2ZhY3RvcnkudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsT0FBTyxFQUFFLFdBQVcsRUFBRSxNQUFNLGlDQUFpQyxDQUFDO0FBa0I5RCxPQUFPLEtBQUssRUFBRSxrQkFBa0IsRUFBRSxNQUFNLHdCQUF3QixDQUFDO0FBQ2pFLE9BQU8sS0FBSyxFQUFFLE9BQU8sRUFBRSxNQUFNLG1CQUFtQixDQUFDO0FBQ2pELE9BQU8sS0FBSyxFQUNWLGNBQWMsRUFDZCw2QkFBNkIsRUFDN0Isd0JBQXdCLEVBQ3hCLHdCQUF3QixFQUN6QixNQUFNLGlDQUFpQyxDQUFDO0FBRXpDLE9BQU8sRUFBRSxlQUFlLEVBQUUsS0FBSyxFQUFFLEVBQUUsS0FBSyxXQUFXLEVBQUUsTUFBTSxrQkFBa0IsQ0FBQztBQUM5RSxPQUFPLEtBQUssRUFBRSxNQUFNLEVBQUUsTUFBTSxxQkFBcUIsQ0FBQztBQUlsRCx3QkFBZ0IsOEJBQThCLENBQzVDLEVBQUUsRUFBRSx3QkFBd0IsRUFDNUIsa0JBQWtCLEVBQUUsa0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,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,CA6BjB;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,54 +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, SizeTxValidator, 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 SizeTxValidator(),
11
- new DataTxValidator(),
12
- new MetadataTxValidator({
13
- l1ChainId: new Fr(l1ChainId),
14
- rollupVersion: new Fr(rollupVersion),
15
- protocolContractsHash,
16
- vkTreeRoot: getVKTreeRoot()
17
- }),
18
- new TimestampTxValidator({
19
- timestamp,
20
- blockNumber
21
- }),
22
- new DoubleSpendTxValidator(new NullifierCache(db)),
23
- new PhasesTxValidator(contractDataSource, setupAllowList, timestamp),
24
- new BlockHeaderTxValidator(new ArchiveCache(db))
25
- ];
26
- if (!skipFeeEnforcement) {
27
- validators.push(new GasTxValidator(new DatabasePublicStateSource(db), ProtocolContractAddress.FeeJuice, gasFees));
28
- }
29
- if (verifier) {
30
- validators.push(new TxProofValidator(verifier));
31
- }
32
- return new AggregateTxValidator(...validators);
33
- }
34
- export function createValidatorForBlockBuilding(db, contractDataSource, globalVariables, setupAllowList) {
35
- const nullifierCache = new NullifierCache(db);
36
- const archiveCache = new ArchiveCache(db);
37
- const publicStateSource = new DatabasePublicStateSource(db);
38
- return {
39
- preprocessValidator: preprocessValidator(nullifierCache, archiveCache, publicStateSource, contractDataSource, globalVariables, setupAllowList),
40
- nullifierCache
41
- };
42
- }
43
- function preprocessValidator(nullifierCache, archiveCache, publicStateSource, contractDataSource, globalVariables, setupAllowList) {
44
- // We don't include the TxProofValidator nor the DataTxValidator here because they are already checked by the time we get to block building.
45
- return new AggregateTxValidator(new MetadataTxValidator({
46
- l1ChainId: globalVariables.chainId,
47
- rollupVersion: globalVariables.version,
48
- protocolContractsHash,
49
- vkTreeRoot: getVKTreeRoot()
50
- }), new TimestampTxValidator({
51
- timestamp: globalVariables.timestamp,
52
- blockNumber: globalVariables.blockNumber
53
- }), new DoubleSpendTxValidator(nullifierCache), new PhasesTxValidator(contractDataSource, setupAllowList, globalVariables.timestamp), new GasTxValidator(publicStateSource, ProtocolContractAddress.FeeJuice, globalVariables.gasFees), new BlockHeaderTxValidator(archiveCache));
54
- }
@@ -1,2 +0,0 @@
1
- export * from './nullifier_cache.js';
2
- export * from './tx_validator_factory.js';
@@ -1,30 +0,0 @@
1
- import type { NullifierSource } from '@aztec/p2p';
2
- import type { MerkleTreeReadOperations } from '@aztec/stdlib/interfaces/server';
3
- import { MerkleTreeId } from '@aztec/stdlib/trees';
4
-
5
- /**
6
- * Implements a nullifier source by checking a DB and an in-memory collection.
7
- * Intended for validating transactions as they are added to a block.
8
- */
9
- export class NullifierCache implements NullifierSource {
10
- nullifiers: Set<string>;
11
-
12
- constructor(private db: MerkleTreeReadOperations) {
13
- this.nullifiers = new Set();
14
- }
15
-
16
- public async nullifiersExist(nullifiers: Buffer[]): Promise<boolean[]> {
17
- const cacheResults = nullifiers.map(n => this.nullifiers.has(n.toString()));
18
- const toCheckDb = nullifiers.filter((_n, index) => !cacheResults[index]);
19
- const dbHits = await this.db.findLeafIndices(MerkleTreeId.NULLIFIER_TREE, toCheckDb);
20
-
21
- let dbIndex = 0;
22
- return nullifiers.map((_n, index) => cacheResults[index] || dbHits[dbIndex++] !== undefined);
23
- }
24
-
25
- public addNullifiers(nullifiers: Buffer[]) {
26
- for (const nullifier of nullifiers) {
27
- this.nullifiers.add(nullifier.toString());
28
- }
29
- }
30
- }
@@ -1,135 +0,0 @@
1
- import { BlockNumber } from '@aztec/foundation/branded-types';
2
- import { Fr } from '@aztec/foundation/curves/bn254';
3
- import { getVKTreeRoot } from '@aztec/noir-protocol-circuits-types/vk-tree';
4
- import {
5
- AggregateTxValidator,
6
- ArchiveCache,
7
- BlockHeaderTxValidator,
8
- DataTxValidator,
9
- DoubleSpendTxValidator,
10
- GasTxValidator,
11
- MetadataTxValidator,
12
- PhasesTxValidator,
13
- SizeTxValidator,
14
- TimestampTxValidator,
15
- TxPermittedValidator,
16
- TxProofValidator,
17
- } from '@aztec/p2p';
18
- import { ProtocolContractAddress, protocolContractsHash } from '@aztec/protocol-contracts';
19
- import type { ContractDataSource } from '@aztec/stdlib/contract';
20
- import type { GasFees } from '@aztec/stdlib/gas';
21
- import type {
22
- AllowedElement,
23
- ClientProtocolCircuitVerifier,
24
- MerkleTreeReadOperations,
25
- PublicProcessorValidator,
26
- } from '@aztec/stdlib/interfaces/server';
27
- import { DatabasePublicStateSource, type PublicStateSource } from '@aztec/stdlib/trees';
28
- import { GlobalVariables, type Tx, type TxValidator } from '@aztec/stdlib/tx';
29
- import type { UInt64 } from '@aztec/stdlib/types';
30
-
31
- import { NullifierCache } from './nullifier_cache.js';
32
-
33
- export function createValidatorForAcceptingTxs(
34
- db: MerkleTreeReadOperations,
35
- contractDataSource: ContractDataSource,
36
- verifier: ClientProtocolCircuitVerifier | undefined,
37
- {
38
- l1ChainId,
39
- rollupVersion,
40
- setupAllowList,
41
- gasFees,
42
- skipFeeEnforcement,
43
- timestamp,
44
- blockNumber,
45
- txsPermitted,
46
- }: {
47
- l1ChainId: number;
48
- rollupVersion: number;
49
- setupAllowList: AllowedElement[];
50
- gasFees: GasFees;
51
- skipFeeEnforcement?: boolean;
52
- timestamp: UInt64;
53
- blockNumber: BlockNumber;
54
- txsPermitted: boolean;
55
- },
56
- ): TxValidator<Tx> {
57
- const validators: TxValidator<Tx>[] = [
58
- new TxPermittedValidator(txsPermitted),
59
- new SizeTxValidator(),
60
- new DataTxValidator(),
61
- new MetadataTxValidator({
62
- l1ChainId: new Fr(l1ChainId),
63
- rollupVersion: new Fr(rollupVersion),
64
- protocolContractsHash,
65
- vkTreeRoot: getVKTreeRoot(),
66
- }),
67
- new TimestampTxValidator({
68
- timestamp,
69
- blockNumber,
70
- }),
71
- new DoubleSpendTxValidator(new NullifierCache(db)),
72
- new PhasesTxValidator(contractDataSource, setupAllowList, timestamp),
73
- new BlockHeaderTxValidator(new ArchiveCache(db)),
74
- ];
75
-
76
- if (!skipFeeEnforcement) {
77
- validators.push(new GasTxValidator(new DatabasePublicStateSource(db), ProtocolContractAddress.FeeJuice, gasFees));
78
- }
79
-
80
- if (verifier) {
81
- validators.push(new TxProofValidator(verifier));
82
- }
83
-
84
- return new AggregateTxValidator(...validators);
85
- }
86
-
87
- export function createValidatorForBlockBuilding(
88
- db: MerkleTreeReadOperations,
89
- contractDataSource: ContractDataSource,
90
- globalVariables: GlobalVariables,
91
- setupAllowList: AllowedElement[],
92
- ): PublicProcessorValidator {
93
- const nullifierCache = new NullifierCache(db);
94
- const archiveCache = new ArchiveCache(db);
95
- const publicStateSource = new DatabasePublicStateSource(db);
96
-
97
- return {
98
- preprocessValidator: preprocessValidator(
99
- nullifierCache,
100
- archiveCache,
101
- publicStateSource,
102
- contractDataSource,
103
- globalVariables,
104
- setupAllowList,
105
- ),
106
- nullifierCache,
107
- };
108
- }
109
-
110
- function preprocessValidator(
111
- nullifierCache: NullifierCache,
112
- archiveCache: ArchiveCache,
113
- publicStateSource: PublicStateSource,
114
- contractDataSource: ContractDataSource,
115
- globalVariables: GlobalVariables,
116
- setupAllowList: AllowedElement[],
117
- ): TxValidator<Tx> {
118
- // We don't include the TxProofValidator nor the DataTxValidator here because they are already checked by the time we get to block building.
119
- return new AggregateTxValidator(
120
- new MetadataTxValidator({
121
- l1ChainId: globalVariables.chainId,
122
- rollupVersion: globalVariables.version,
123
- protocolContractsHash,
124
- vkTreeRoot: getVKTreeRoot(),
125
- }),
126
- new TimestampTxValidator({
127
- timestamp: globalVariables.timestamp,
128
- blockNumber: globalVariables.blockNumber,
129
- }),
130
- new DoubleSpendTxValidator(nullifierCache),
131
- new PhasesTxValidator(contractDataSource, setupAllowList, globalVariables.timestamp),
132
- new GasTxValidator(publicStateSource, ProtocolContractAddress.FeeJuice, globalVariables.gasFees),
133
- new BlockHeaderTxValidator(archiveCache),
134
- );
135
- }