@aztec/validator-client 0.0.1-commit.fce3e4f → 0.0.1-commit.ff7989d6c
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/README.md +285 -0
- package/dest/block_proposal_handler.d.ts +24 -13
- package/dest/block_proposal_handler.d.ts.map +1 -1
- package/dest/block_proposal_handler.js +329 -87
- package/dest/checkpoint_builder.d.ts +66 -0
- package/dest/checkpoint_builder.d.ts.map +1 -0
- package/dest/checkpoint_builder.js +175 -0
- package/dest/config.d.ts +1 -1
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +16 -8
- package/dest/duties/validation_service.d.ts +42 -13
- package/dest/duties/validation_service.d.ts.map +1 -1
- package/dest/duties/validation_service.js +111 -28
- package/dest/factory.d.ts +13 -8
- package/dest/factory.d.ts.map +1 -1
- package/dest/factory.js +2 -2
- package/dest/index.d.ts +3 -1
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +2 -0
- package/dest/key_store/ha_key_store.d.ts +99 -0
- package/dest/key_store/ha_key_store.d.ts.map +1 -0
- package/dest/key_store/ha_key_store.js +208 -0
- package/dest/key_store/index.d.ts +2 -1
- package/dest/key_store/index.d.ts.map +1 -1
- package/dest/key_store/index.js +1 -0
- package/dest/key_store/interface.d.ts +36 -6
- package/dest/key_store/interface.d.ts.map +1 -1
- package/dest/key_store/local_key_store.d.ts +10 -5
- package/dest/key_store/local_key_store.d.ts.map +1 -1
- package/dest/key_store/local_key_store.js +9 -5
- package/dest/key_store/node_keystore_adapter.d.ts +18 -5
- package/dest/key_store/node_keystore_adapter.d.ts.map +1 -1
- package/dest/key_store/node_keystore_adapter.js +18 -4
- package/dest/key_store/web3signer_key_store.d.ts +10 -5
- package/dest/key_store/web3signer_key_store.d.ts.map +1 -1
- package/dest/key_store/web3signer_key_store.js +9 -5
- package/dest/metrics.d.ts +4 -3
- package/dest/metrics.d.ts.map +1 -1
- package/dest/metrics.js +34 -30
- package/dest/tx_validator/index.d.ts +3 -0
- package/dest/tx_validator/index.d.ts.map +1 -0
- package/dest/tx_validator/index.js +2 -0
- package/dest/tx_validator/nullifier_cache.d.ts +14 -0
- package/dest/tx_validator/nullifier_cache.d.ts.map +1 -0
- package/dest/tx_validator/nullifier_cache.js +24 -0
- package/dest/tx_validator/tx_validator_factory.d.ts +19 -0
- package/dest/tx_validator/tx_validator_factory.d.ts.map +1 -0
- package/dest/tx_validator/tx_validator_factory.js +54 -0
- package/dest/validator.d.ts +74 -21
- package/dest/validator.d.ts.map +1 -1
- package/dest/validator.js +452 -56
- package/package.json +23 -13
- package/src/block_proposal_handler.ts +253 -59
- package/src/checkpoint_builder.ts +321 -0
- package/src/config.ts +15 -7
- package/src/duties/validation_service.ts +162 -33
- package/src/factory.ts +17 -8
- package/src/index.ts +2 -0
- package/src/key_store/ha_key_store.ts +269 -0
- package/src/key_store/index.ts +1 -0
- package/src/key_store/interface.ts +44 -5
- package/src/key_store/local_key_store.ts +14 -5
- package/src/key_store/node_keystore_adapter.ts +28 -5
- package/src/key_store/web3signer_key_store.ts +18 -5
- package/src/metrics.ts +45 -33
- package/src/tx_validator/index.ts +2 -0
- package/src/tx_validator/nullifier_cache.ts +30 -0
- package/src/tx_validator/tx_validator_factory.ts +154 -0
- package/src/validator.ts +619 -85
package/src/metrics.ts
CHANGED
|
@@ -1,13 +1,16 @@
|
|
|
1
1
|
import type { BlockProposal } from '@aztec/stdlib/p2p';
|
|
2
2
|
import {
|
|
3
3
|
Attributes,
|
|
4
|
+
type Gauge,
|
|
4
5
|
type Histogram,
|
|
5
6
|
Metrics,
|
|
6
7
|
type TelemetryClient,
|
|
7
8
|
type UpDownCounter,
|
|
8
|
-
|
|
9
|
+
createUpDownCounterWithDefault,
|
|
9
10
|
} from '@aztec/telemetry-client';
|
|
10
11
|
|
|
12
|
+
import type { BlockProposalValidationFailureReason } from './block_proposal_handler.js';
|
|
13
|
+
|
|
11
14
|
export class ValidatorMetrics {
|
|
12
15
|
private failedReexecutionCounter: UpDownCounter;
|
|
13
16
|
private successfulAttestationsCount: UpDownCounter;
|
|
@@ -16,55 +19,56 @@ export class ValidatorMetrics {
|
|
|
16
19
|
|
|
17
20
|
private reexMana: Histogram;
|
|
18
21
|
private reexTx: Histogram;
|
|
19
|
-
private reexDuration:
|
|
22
|
+
private reexDuration: Gauge;
|
|
20
23
|
|
|
21
24
|
constructor(telemetryClient: TelemetryClient) {
|
|
22
25
|
const meter = telemetryClient.getMeter('Validator');
|
|
23
26
|
|
|
24
|
-
this.failedReexecutionCounter = meter
|
|
25
|
-
|
|
26
|
-
unit: 'count',
|
|
27
|
-
valueType: ValueType.INT,
|
|
27
|
+
this.failedReexecutionCounter = createUpDownCounterWithDefault(meter, Metrics.VALIDATOR_FAILED_REEXECUTION_COUNT, {
|
|
28
|
+
[Attributes.STATUS]: ['failed'],
|
|
28
29
|
});
|
|
29
30
|
|
|
30
|
-
this.successfulAttestationsCount =
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
31
|
+
this.successfulAttestationsCount = createUpDownCounterWithDefault(
|
|
32
|
+
meter,
|
|
33
|
+
Metrics.VALIDATOR_ATTESTATION_SUCCESS_COUNT,
|
|
34
|
+
);
|
|
34
35
|
|
|
35
|
-
this.failedAttestationsBadProposalCount =
|
|
36
|
+
this.failedAttestationsBadProposalCount = createUpDownCounterWithDefault(
|
|
37
|
+
meter,
|
|
36
38
|
Metrics.VALIDATOR_ATTESTATION_FAILED_BAD_PROPOSAL_COUNT,
|
|
37
39
|
{
|
|
38
|
-
|
|
39
|
-
|
|
40
|
+
[Attributes.ERROR_TYPE]: [
|
|
41
|
+
'invalid_proposal',
|
|
42
|
+
'state_mismatch',
|
|
43
|
+
'failed_txs',
|
|
44
|
+
'in_hash_mismatch',
|
|
45
|
+
'parent_block_wrong_slot',
|
|
46
|
+
],
|
|
47
|
+
[Attributes.IS_COMMITTEE_MEMBER]: [true, false],
|
|
40
48
|
},
|
|
41
49
|
);
|
|
42
50
|
|
|
43
|
-
this.failedAttestationsNodeIssueCount =
|
|
51
|
+
this.failedAttestationsNodeIssueCount = createUpDownCounterWithDefault(
|
|
52
|
+
meter,
|
|
44
53
|
Metrics.VALIDATOR_ATTESTATION_FAILED_NODE_ISSUE_COUNT,
|
|
45
54
|
{
|
|
46
|
-
|
|
47
|
-
|
|
55
|
+
[Attributes.ERROR_TYPE]: [
|
|
56
|
+
'parent_block_not_found',
|
|
57
|
+
'global_variables_mismatch',
|
|
58
|
+
'block_number_already_exists',
|
|
59
|
+
'txs_not_available',
|
|
60
|
+
'timeout',
|
|
61
|
+
'unknown_error',
|
|
62
|
+
],
|
|
63
|
+
[Attributes.IS_COMMITTEE_MEMBER]: [true, false],
|
|
48
64
|
},
|
|
49
65
|
);
|
|
50
66
|
|
|
51
|
-
this.reexMana = meter.createHistogram(Metrics.VALIDATOR_RE_EXECUTION_MANA
|
|
52
|
-
description: 'The mana consumed by blocks',
|
|
53
|
-
valueType: ValueType.DOUBLE,
|
|
54
|
-
unit: 'Mmana',
|
|
55
|
-
});
|
|
67
|
+
this.reexMana = meter.createHistogram(Metrics.VALIDATOR_RE_EXECUTION_MANA);
|
|
56
68
|
|
|
57
|
-
this.reexTx = meter.createHistogram(Metrics.VALIDATOR_RE_EXECUTION_TX_COUNT
|
|
58
|
-
description: 'The number of txs in a block proposal',
|
|
59
|
-
valueType: ValueType.INT,
|
|
60
|
-
unit: 'tx',
|
|
61
|
-
});
|
|
69
|
+
this.reexTx = meter.createHistogram(Metrics.VALIDATOR_RE_EXECUTION_TX_COUNT);
|
|
62
70
|
|
|
63
|
-
this.reexDuration = meter.createGauge(Metrics.VALIDATOR_RE_EXECUTION_TIME
|
|
64
|
-
description: 'The time taken to re-execute a transaction',
|
|
65
|
-
unit: 'ms',
|
|
66
|
-
valueType: ValueType.INT,
|
|
67
|
-
});
|
|
71
|
+
this.reexDuration = meter.createGauge(Metrics.VALIDATOR_RE_EXECUTION_TIME);
|
|
68
72
|
}
|
|
69
73
|
|
|
70
74
|
public recordReex(time: number, txs: number, mManaTotal: number) {
|
|
@@ -85,14 +89,22 @@ export class ValidatorMetrics {
|
|
|
85
89
|
this.successfulAttestationsCount.add(num);
|
|
86
90
|
}
|
|
87
91
|
|
|
88
|
-
public incFailedAttestationsBadProposal(
|
|
92
|
+
public incFailedAttestationsBadProposal(
|
|
93
|
+
num: number,
|
|
94
|
+
reason: BlockProposalValidationFailureReason,
|
|
95
|
+
inCommittee: boolean,
|
|
96
|
+
) {
|
|
89
97
|
this.failedAttestationsBadProposalCount.add(num, {
|
|
90
98
|
[Attributes.ERROR_TYPE]: reason,
|
|
91
99
|
[Attributes.IS_COMMITTEE_MEMBER]: inCommittee,
|
|
92
100
|
});
|
|
93
101
|
}
|
|
94
102
|
|
|
95
|
-
public incFailedAttestationsNodeIssue(
|
|
103
|
+
public incFailedAttestationsNodeIssue(
|
|
104
|
+
num: number,
|
|
105
|
+
reason: BlockProposalValidationFailureReason,
|
|
106
|
+
inCommittee: boolean,
|
|
107
|
+
) {
|
|
96
108
|
this.failedAttestationsNodeIssueCount.add(num, {
|
|
97
109
|
[Attributes.ERROR_TYPE]: reason,
|
|
98
110
|
[Attributes.IS_COMMITTEE_MEMBER]: inCommittee,
|
|
@@ -0,0 +1,30 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
import { BlockNumber } from '@aztec/foundation/branded-types';
|
|
2
|
+
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
3
|
+
import type { LoggerBindings } from '@aztec/foundation/log';
|
|
4
|
+
import { getVKTreeRoot } from '@aztec/noir-protocol-circuits-types/vk-tree';
|
|
5
|
+
import {
|
|
6
|
+
AggregateTxValidator,
|
|
7
|
+
ArchiveCache,
|
|
8
|
+
BlockHeaderTxValidator,
|
|
9
|
+
DataTxValidator,
|
|
10
|
+
DoubleSpendTxValidator,
|
|
11
|
+
GasTxValidator,
|
|
12
|
+
MetadataTxValidator,
|
|
13
|
+
PhasesTxValidator,
|
|
14
|
+
SizeTxValidator,
|
|
15
|
+
TimestampTxValidator,
|
|
16
|
+
TxPermittedValidator,
|
|
17
|
+
TxProofValidator,
|
|
18
|
+
} from '@aztec/p2p';
|
|
19
|
+
import { ProtocolContractAddress, protocolContractsHash } from '@aztec/protocol-contracts';
|
|
20
|
+
import type { ContractDataSource } from '@aztec/stdlib/contract';
|
|
21
|
+
import type { GasFees } from '@aztec/stdlib/gas';
|
|
22
|
+
import type {
|
|
23
|
+
AllowedElement,
|
|
24
|
+
ClientProtocolCircuitVerifier,
|
|
25
|
+
MerkleTreeReadOperations,
|
|
26
|
+
PublicProcessorValidator,
|
|
27
|
+
} from '@aztec/stdlib/interfaces/server';
|
|
28
|
+
import { DatabasePublicStateSource, type PublicStateSource } from '@aztec/stdlib/trees';
|
|
29
|
+
import { GlobalVariables, type Tx, type TxValidator } from '@aztec/stdlib/tx';
|
|
30
|
+
import type { UInt64 } from '@aztec/stdlib/types';
|
|
31
|
+
|
|
32
|
+
import { NullifierCache } from './nullifier_cache.js';
|
|
33
|
+
|
|
34
|
+
export function createValidatorForAcceptingTxs(
|
|
35
|
+
db: MerkleTreeReadOperations,
|
|
36
|
+
contractDataSource: ContractDataSource,
|
|
37
|
+
verifier: ClientProtocolCircuitVerifier | undefined,
|
|
38
|
+
{
|
|
39
|
+
l1ChainId,
|
|
40
|
+
rollupVersion,
|
|
41
|
+
setupAllowList,
|
|
42
|
+
gasFees,
|
|
43
|
+
skipFeeEnforcement,
|
|
44
|
+
timestamp,
|
|
45
|
+
blockNumber,
|
|
46
|
+
txsPermitted,
|
|
47
|
+
}: {
|
|
48
|
+
l1ChainId: number;
|
|
49
|
+
rollupVersion: number;
|
|
50
|
+
setupAllowList: AllowedElement[];
|
|
51
|
+
gasFees: GasFees;
|
|
52
|
+
skipFeeEnforcement?: boolean;
|
|
53
|
+
timestamp: UInt64;
|
|
54
|
+
blockNumber: BlockNumber;
|
|
55
|
+
txsPermitted: boolean;
|
|
56
|
+
},
|
|
57
|
+
bindings?: LoggerBindings,
|
|
58
|
+
): TxValidator<Tx> {
|
|
59
|
+
const validators: TxValidator<Tx>[] = [
|
|
60
|
+
new TxPermittedValidator(txsPermitted, bindings),
|
|
61
|
+
new SizeTxValidator(bindings),
|
|
62
|
+
new DataTxValidator(bindings),
|
|
63
|
+
new MetadataTxValidator(
|
|
64
|
+
{
|
|
65
|
+
l1ChainId: new Fr(l1ChainId),
|
|
66
|
+
rollupVersion: new Fr(rollupVersion),
|
|
67
|
+
protocolContractsHash,
|
|
68
|
+
vkTreeRoot: getVKTreeRoot(),
|
|
69
|
+
},
|
|
70
|
+
bindings,
|
|
71
|
+
),
|
|
72
|
+
new TimestampTxValidator(
|
|
73
|
+
{
|
|
74
|
+
timestamp,
|
|
75
|
+
blockNumber,
|
|
76
|
+
},
|
|
77
|
+
bindings,
|
|
78
|
+
),
|
|
79
|
+
new DoubleSpendTxValidator(new NullifierCache(db), bindings),
|
|
80
|
+
new PhasesTxValidator(contractDataSource, setupAllowList, timestamp, bindings),
|
|
81
|
+
new BlockHeaderTxValidator(new ArchiveCache(db), bindings),
|
|
82
|
+
];
|
|
83
|
+
|
|
84
|
+
if (!skipFeeEnforcement) {
|
|
85
|
+
validators.push(
|
|
86
|
+
new GasTxValidator(new DatabasePublicStateSource(db), ProtocolContractAddress.FeeJuice, gasFees, bindings),
|
|
87
|
+
);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
if (verifier) {
|
|
91
|
+
validators.push(new TxProofValidator(verifier, bindings));
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
return new AggregateTxValidator(...validators);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
export function createValidatorForBlockBuilding(
|
|
98
|
+
db: MerkleTreeReadOperations,
|
|
99
|
+
contractDataSource: ContractDataSource,
|
|
100
|
+
globalVariables: GlobalVariables,
|
|
101
|
+
setupAllowList: AllowedElement[],
|
|
102
|
+
bindings?: LoggerBindings,
|
|
103
|
+
): PublicProcessorValidator {
|
|
104
|
+
const nullifierCache = new NullifierCache(db);
|
|
105
|
+
const archiveCache = new ArchiveCache(db);
|
|
106
|
+
const publicStateSource = new DatabasePublicStateSource(db);
|
|
107
|
+
|
|
108
|
+
return {
|
|
109
|
+
preprocessValidator: preprocessValidator(
|
|
110
|
+
nullifierCache,
|
|
111
|
+
archiveCache,
|
|
112
|
+
publicStateSource,
|
|
113
|
+
contractDataSource,
|
|
114
|
+
globalVariables,
|
|
115
|
+
setupAllowList,
|
|
116
|
+
bindings,
|
|
117
|
+
),
|
|
118
|
+
nullifierCache,
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
function preprocessValidator(
|
|
123
|
+
nullifierCache: NullifierCache,
|
|
124
|
+
archiveCache: ArchiveCache,
|
|
125
|
+
publicStateSource: PublicStateSource,
|
|
126
|
+
contractDataSource: ContractDataSource,
|
|
127
|
+
globalVariables: GlobalVariables,
|
|
128
|
+
setupAllowList: AllowedElement[],
|
|
129
|
+
bindings?: LoggerBindings,
|
|
130
|
+
): TxValidator<Tx> {
|
|
131
|
+
// We don't include the TxProofValidator nor the DataTxValidator here because they are already checked by the time we get to block building.
|
|
132
|
+
return new AggregateTxValidator(
|
|
133
|
+
new MetadataTxValidator(
|
|
134
|
+
{
|
|
135
|
+
l1ChainId: globalVariables.chainId,
|
|
136
|
+
rollupVersion: globalVariables.version,
|
|
137
|
+
protocolContractsHash,
|
|
138
|
+
vkTreeRoot: getVKTreeRoot(),
|
|
139
|
+
},
|
|
140
|
+
bindings,
|
|
141
|
+
),
|
|
142
|
+
new TimestampTxValidator(
|
|
143
|
+
{
|
|
144
|
+
timestamp: globalVariables.timestamp,
|
|
145
|
+
blockNumber: globalVariables.blockNumber,
|
|
146
|
+
},
|
|
147
|
+
bindings,
|
|
148
|
+
),
|
|
149
|
+
new DoubleSpendTxValidator(nullifierCache, bindings),
|
|
150
|
+
new PhasesTxValidator(contractDataSource, setupAllowList, globalVariables.timestamp, bindings),
|
|
151
|
+
new GasTxValidator(publicStateSource, ProtocolContractAddress.FeeJuice, globalVariables.gasFees, bindings),
|
|
152
|
+
new BlockHeaderTxValidator(archiveCache, bindings),
|
|
153
|
+
);
|
|
154
|
+
}
|