@aztec/sequencer-client 0.0.1-commit.b655e406 → 0.0.1-commit.b8a057fa
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 +281 -21
- package/dest/client/index.d.ts +1 -1
- package/dest/client/sequencer-client.d.ts +41 -18
- package/dest/client/sequencer-client.d.ts.map +1 -1
- package/dest/client/sequencer-client.js +88 -42
- package/dest/config.d.ts +41 -8
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +153 -53
- package/dest/global_variable_builder/fee_predictor.d.ts +37 -0
- package/dest/global_variable_builder/fee_predictor.d.ts.map +1 -0
- package/dest/global_variable_builder/fee_predictor.js +138 -0
- package/dest/global_variable_builder/fee_provider.d.ts +21 -0
- package/dest/global_variable_builder/fee_provider.d.ts.map +1 -0
- package/dest/global_variable_builder/fee_provider.js +80 -0
- package/dest/global_variable_builder/global_builder.d.ts +20 -29
- package/dest/global_variable_builder/global_builder.d.ts.map +1 -1
- package/dest/global_variable_builder/global_builder.js +28 -72
- package/dest/global_variable_builder/index.d.ts +4 -2
- package/dest/global_variable_builder/index.d.ts.map +1 -1
- package/dest/global_variable_builder/index.js +2 -0
- package/dest/index.d.ts +2 -3
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +1 -2
- package/dest/publisher/config.d.ts +59 -20
- package/dest/publisher/config.d.ts.map +1 -1
- package/dest/publisher/config.js +134 -34
- package/dest/publisher/index.d.ts +2 -1
- package/dest/publisher/index.d.ts.map +1 -1
- package/dest/publisher/l1_to_l2_messaging.d.ts +21 -0
- package/dest/publisher/l1_to_l2_messaging.d.ts.map +1 -0
- package/dest/publisher/l1_to_l2_messaging.js +70 -0
- package/dest/publisher/l1_tx_failed_store/factory.d.ts +11 -0
- package/dest/publisher/l1_tx_failed_store/factory.d.ts.map +1 -0
- package/dest/publisher/l1_tx_failed_store/factory.js +22 -0
- package/dest/publisher/l1_tx_failed_store/failed_tx_store.d.ts +98 -0
- package/dest/publisher/l1_tx_failed_store/failed_tx_store.d.ts.map +1 -0
- package/dest/publisher/l1_tx_failed_store/failed_tx_store.js +68 -0
- package/dest/publisher/l1_tx_failed_store/file_store_failed_tx_store.d.ts +15 -0
- package/dest/publisher/l1_tx_failed_store/file_store_failed_tx_store.d.ts.map +1 -0
- package/dest/publisher/l1_tx_failed_store/file_store_failed_tx_store.js +36 -0
- package/dest/publisher/l1_tx_failed_store/index.d.ts +4 -0
- package/dest/publisher/l1_tx_failed_store/index.d.ts.map +1 -0
- package/dest/publisher/l1_tx_failed_store/index.js +3 -0
- package/dest/publisher/sequencer-bundle-simulator.d.ts +96 -0
- package/dest/publisher/sequencer-bundle-simulator.d.ts.map +1 -0
- package/dest/publisher/sequencer-bundle-simulator.js +198 -0
- package/dest/publisher/sequencer-publisher-factory.d.ts +15 -8
- package/dest/publisher/sequencer-publisher-factory.d.ts.map +1 -1
- package/dest/publisher/sequencer-publisher-factory.js +28 -4
- package/dest/publisher/sequencer-publisher-metrics.d.ts +3 -3
- package/dest/publisher/sequencer-publisher-metrics.d.ts.map +1 -1
- package/dest/publisher/sequencer-publisher-metrics.js +23 -86
- package/dest/publisher/sequencer-publisher.d.ts +164 -96
- package/dest/publisher/sequencer-publisher.d.ts.map +1 -1
- package/dest/publisher/sequencer-publisher.js +1305 -416
- package/dest/publisher/write_json.d.ts +11 -0
- package/dest/publisher/write_json.d.ts.map +1 -0
- package/dest/publisher/write_json.js +57 -0
- package/dest/sequencer/automine/automine_factory.d.ts +56 -0
- package/dest/sequencer/automine/automine_factory.d.ts.map +1 -0
- package/dest/sequencer/automine/automine_factory.js +85 -0
- package/dest/sequencer/automine/automine_sequencer.d.ts +189 -0
- package/dest/sequencer/automine/automine_sequencer.d.ts.map +1 -0
- package/dest/sequencer/automine/automine_sequencer.js +690 -0
- package/dest/sequencer/automine/index.d.ts +3 -0
- package/dest/sequencer/automine/index.d.ts.map +1 -0
- package/dest/sequencer/automine/index.js +2 -0
- package/dest/sequencer/checkpoint_proposal_job.d.ts +158 -0
- package/dest/sequencer/checkpoint_proposal_job.d.ts.map +1 -0
- package/dest/sequencer/checkpoint_proposal_job.js +1801 -0
- package/dest/sequencer/checkpoint_proposal_job_metrics.d.ts +34 -0
- package/dest/sequencer/checkpoint_proposal_job_metrics.d.ts.map +1 -0
- package/dest/sequencer/checkpoint_proposal_job_metrics.js +72 -0
- package/dest/sequencer/checkpoint_voter.d.ts +34 -0
- package/dest/sequencer/checkpoint_voter.d.ts.map +1 -0
- package/dest/sequencer/checkpoint_voter.js +106 -0
- package/dest/sequencer/config.d.ts +3 -2
- package/dest/sequencer/config.d.ts.map +1 -1
- package/dest/sequencer/errors.d.ts +1 -1
- package/dest/sequencer/errors.d.ts.map +1 -1
- package/dest/sequencer/events.d.ts +103 -0
- package/dest/sequencer/events.d.ts.map +1 -0
- package/dest/sequencer/events.js +1 -0
- package/dest/sequencer/index.d.ts +4 -2
- package/dest/sequencer/index.d.ts.map +1 -1
- package/dest/sequencer/index.js +3 -1
- package/dest/sequencer/metrics.d.ts +48 -4
- package/dest/sequencer/metrics.d.ts.map +1 -1
- package/dest/sequencer/metrics.js +257 -50
- package/dest/sequencer/requests_tracker.d.ts +22 -0
- package/dest/sequencer/requests_tracker.d.ts.map +1 -0
- package/dest/sequencer/requests_tracker.js +33 -0
- package/dest/sequencer/sequencer.d.ts +253 -148
- package/dest/sequencer/sequencer.d.ts.map +1 -1
- package/dest/sequencer/sequencer.js +1208 -598
- package/dest/sequencer/types.d.ts +3 -0
- package/dest/sequencer/types.d.ts.map +1 -0
- package/dest/sequencer/types.js +1 -0
- package/dest/sequencer/utils.d.ts +14 -8
- package/dest/sequencer/utils.d.ts.map +1 -1
- package/dest/sequencer/utils.js +7 -4
- package/dest/test/index.d.ts +8 -9
- package/dest/test/index.d.ts.map +1 -1
- package/dest/test/mock_checkpoint_builder.d.ts +95 -0
- package/dest/test/mock_checkpoint_builder.d.ts.map +1 -0
- package/dest/test/mock_checkpoint_builder.js +231 -0
- package/dest/test/utils.d.ts +67 -0
- package/dest/test/utils.d.ts.map +1 -0
- package/dest/test/utils.js +122 -0
- package/package.json +34 -30
- package/src/client/sequencer-client.ts +118 -66
- package/src/config.ts +181 -62
- package/src/global_variable_builder/README.md +44 -0
- package/src/global_variable_builder/fee_predictor.ts +182 -0
- package/src/global_variable_builder/fee_provider.ts +97 -0
- package/src/global_variable_builder/global_builder.ts +45 -106
- package/src/global_variable_builder/index.ts +3 -1
- package/src/index.ts +1 -7
- package/src/publisher/config.ts +190 -46
- package/src/publisher/index.ts +3 -0
- package/src/publisher/l1_to_l2_messaging.ts +85 -0
- package/src/publisher/l1_tx_failed_store/factory.ts +32 -0
- package/src/publisher/l1_tx_failed_store/failed_tx_store.ts +164 -0
- package/src/publisher/l1_tx_failed_store/file_store_failed_tx_store.ts +47 -0
- package/src/publisher/l1_tx_failed_store/index.ts +3 -0
- package/src/publisher/sequencer-bundle-simulator.ts +254 -0
- package/src/publisher/sequencer-publisher-factory.ts +45 -14
- package/src/publisher/sequencer-publisher-metrics.ts +19 -71
- package/src/publisher/sequencer-publisher.ts +1109 -538
- package/src/publisher/write_json.ts +78 -0
- package/src/sequencer/README.md +243 -0
- package/src/sequencer/automine/README.md +60 -0
- package/src/sequencer/automine/automine_factory.ts +152 -0
- package/src/sequencer/automine/automine_sequencer.ts +796 -0
- package/src/sequencer/automine/index.ts +6 -0
- package/src/sequencer/checkpoint_proposal_job.ts +1652 -0
- package/src/sequencer/checkpoint_proposal_job_metrics.ts +128 -0
- package/src/sequencer/checkpoint_voter.ts +119 -0
- package/src/sequencer/config.ts +2 -1
- package/src/sequencer/events.ts +88 -0
- package/src/sequencer/index.ts +3 -1
- package/src/sequencer/metrics.ts +330 -62
- package/src/sequencer/requests_tracker.ts +43 -0
- package/src/sequencer/sequencer.ts +1033 -777
- package/src/sequencer/types.ts +6 -0
- package/src/sequencer/utils.ts +18 -9
- package/src/test/index.ts +7 -8
- package/src/test/mock_checkpoint_builder.ts +323 -0
- package/src/test/utils.ts +218 -0
- package/dest/sequencer/block_builder.d.ts +0 -27
- package/dest/sequencer/block_builder.d.ts.map +0 -1
- package/dest/sequencer/block_builder.js +0 -130
- package/dest/sequencer/timetable.d.ts +0 -50
- package/dest/sequencer/timetable.d.ts.map +0 -1
- package/dest/sequencer/timetable.js +0 -137
- package/dest/tx_validator/nullifier_cache.d.ts +0 -14
- package/dest/tx_validator/nullifier_cache.d.ts.map +0 -1
- package/dest/tx_validator/nullifier_cache.js +0 -24
- package/dest/tx_validator/tx_validator_factory.d.ts +0 -17
- package/dest/tx_validator/tx_validator_factory.d.ts.map +0 -1
- package/dest/tx_validator/tx_validator_factory.js +0 -53
- package/src/sequencer/block_builder.ts +0 -218
- package/src/sequencer/timetable.ts +0 -188
- package/src/tx_validator/nullifier_cache.ts +0 -30
- package/src/tx_validator/tx_validator_factory.ts +0 -132
|
@@ -1,188 +0,0 @@
|
|
|
1
|
-
import { createLogger } from '@aztec/aztec.js/log';
|
|
2
|
-
|
|
3
|
-
import { DEFAULT_ATTESTATION_PROPAGATION_TIME } from '../config.js';
|
|
4
|
-
import { SequencerTooSlowError } from './errors.js';
|
|
5
|
-
import type { SequencerMetrics } from './metrics.js';
|
|
6
|
-
import { SequencerState } from './utils.js';
|
|
7
|
-
|
|
8
|
-
const MIN_EXECUTION_TIME = 1;
|
|
9
|
-
const BLOCK_PREPARE_TIME = 1;
|
|
10
|
-
const BLOCK_VALIDATION_TIME = 1;
|
|
11
|
-
|
|
12
|
-
export class SequencerTimetable {
|
|
13
|
-
/**
|
|
14
|
-
* How late into the slot can we be to start working. Computed as the total time needed for assembling and publishing a block,
|
|
15
|
-
* assuming an execution time equal to `minExecutionTime`, subtracted from the slot duration. This means that, if the proposer
|
|
16
|
-
* starts building at this time, and all times hold, it will have at least `minExecutionTime` to execute txs for the block.
|
|
17
|
-
*/
|
|
18
|
-
public readonly initializeDeadline: number;
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* How long it takes to get a published block into L1. L1 builders typically accept txs up to 4 seconds into their slot,
|
|
22
|
-
* but we'll timeout sooner to give it more time to propagate (remember we also have blobs!). Still, when working in anvil,
|
|
23
|
-
* we can just post in the very last second of the L1 slot and still expect the tx to be accepted.
|
|
24
|
-
*/
|
|
25
|
-
public readonly l1PublishingTime;
|
|
26
|
-
|
|
27
|
-
/** What's the minimum time we want to leave available for execution and reexecution (used to derive init deadline) */
|
|
28
|
-
public readonly minExecutionTime: number = MIN_EXECUTION_TIME;
|
|
29
|
-
|
|
30
|
-
/** How long it takes to get ready to start building */
|
|
31
|
-
public readonly blockPrepareTime: number = BLOCK_PREPARE_TIME;
|
|
32
|
-
|
|
33
|
-
/** How long it takes to for proposals and attestations to travel across the p2p layer (one-way) */
|
|
34
|
-
public readonly attestationPropagationTime: number;
|
|
35
|
-
|
|
36
|
-
/** How much time we spend validating and processing a block after building it, and assembling the proposal to send to attestors */
|
|
37
|
-
public readonly blockValidationTime: number = BLOCK_VALIDATION_TIME;
|
|
38
|
-
|
|
39
|
-
/** Ethereum slot duration in seconds */
|
|
40
|
-
public readonly ethereumSlotDuration: number;
|
|
41
|
-
|
|
42
|
-
/** Aztec slot duration in seconds (must be multiple of ethereum slot duration) */
|
|
43
|
-
public readonly aztecSlotDuration: number;
|
|
44
|
-
|
|
45
|
-
/** How late into an L1 slot we can send a tx to make sure it gets included in the immediate next block. Complement of l1PublishingTime. */
|
|
46
|
-
public readonly maxL1TxInclusionTimeIntoSlot: number;
|
|
47
|
-
|
|
48
|
-
/** Whether assertTimeLeft will throw if not enough time. */
|
|
49
|
-
public readonly enforce: boolean;
|
|
50
|
-
|
|
51
|
-
constructor(
|
|
52
|
-
opts: {
|
|
53
|
-
ethereumSlotDuration: number;
|
|
54
|
-
aztecSlotDuration: number;
|
|
55
|
-
maxL1TxInclusionTimeIntoSlot: number;
|
|
56
|
-
attestationPropagationTime?: number;
|
|
57
|
-
enforce: boolean;
|
|
58
|
-
},
|
|
59
|
-
private readonly metrics?: SequencerMetrics,
|
|
60
|
-
private readonly log = createLogger('sequencer:timetable'),
|
|
61
|
-
) {
|
|
62
|
-
this.ethereumSlotDuration = opts.ethereumSlotDuration;
|
|
63
|
-
this.aztecSlotDuration = opts.aztecSlotDuration;
|
|
64
|
-
this.maxL1TxInclusionTimeIntoSlot = opts.maxL1TxInclusionTimeIntoSlot;
|
|
65
|
-
this.attestationPropagationTime = opts.attestationPropagationTime ?? DEFAULT_ATTESTATION_PROPAGATION_TIME;
|
|
66
|
-
this.l1PublishingTime = this.ethereumSlotDuration - this.maxL1TxInclusionTimeIntoSlot;
|
|
67
|
-
this.enforce = opts.enforce;
|
|
68
|
-
|
|
69
|
-
// Assume zero-cost propagation time and faster runs in test environments where L1 slot duration is shortened
|
|
70
|
-
if (this.ethereumSlotDuration < 8) {
|
|
71
|
-
this.attestationPropagationTime = 0;
|
|
72
|
-
this.blockValidationTime = 0.5;
|
|
73
|
-
this.blockPrepareTime = 0.5;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
const allWorkToDo =
|
|
77
|
-
this.blockPrepareTime +
|
|
78
|
-
this.minExecutionTime * 2 +
|
|
79
|
-
this.attestationPropagationTime * 2 +
|
|
80
|
-
this.blockValidationTime +
|
|
81
|
-
this.l1PublishingTime;
|
|
82
|
-
|
|
83
|
-
const initializeDeadline = this.aztecSlotDuration - allWorkToDo;
|
|
84
|
-
this.initializeDeadline = initializeDeadline;
|
|
85
|
-
|
|
86
|
-
this.log.verbose(`Sequencer timetable initialized (${this.enforce ? 'enforced' : 'not enforced'})`, {
|
|
87
|
-
ethereumSlotDuration: this.ethereumSlotDuration,
|
|
88
|
-
aztecSlotDuration: this.aztecSlotDuration,
|
|
89
|
-
maxL1TxInclusionTimeIntoSlot: this.maxL1TxInclusionTimeIntoSlot,
|
|
90
|
-
l1PublishingTime: this.l1PublishingTime,
|
|
91
|
-
minExecutionTime: this.minExecutionTime,
|
|
92
|
-
blockPrepareTime: this.blockPrepareTime,
|
|
93
|
-
attestationPropagationTime: this.attestationPropagationTime,
|
|
94
|
-
blockValidationTime: this.blockValidationTime,
|
|
95
|
-
initializeDeadline: this.initializeDeadline,
|
|
96
|
-
enforce: this.enforce,
|
|
97
|
-
allWorkToDo,
|
|
98
|
-
});
|
|
99
|
-
|
|
100
|
-
if (initializeDeadline <= 0) {
|
|
101
|
-
throw new Error(
|
|
102
|
-
`Block proposal initialize deadline cannot be negative (got ${initializeDeadline} from total time needed ${allWorkToDo} and a slot duration of ${this.aztecSlotDuration}).`,
|
|
103
|
-
);
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
private get afterBlockBuildingTimeNeededWithoutReexec() {
|
|
108
|
-
return this.blockValidationTime + this.attestationPropagationTime * 2 + this.l1PublishingTime;
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
public getBlockProposalExecTimeEnd(secondsIntoSlot: number): number {
|
|
112
|
-
// We are N seconds into the slot. We need to account for `afterBlockBuildingTimeNeededWithoutReexec` seconds,
|
|
113
|
-
// send then split the remaining time between the re-execution and the block building.
|
|
114
|
-
const maxAllowed = this.aztecSlotDuration - this.afterBlockBuildingTimeNeededWithoutReexec;
|
|
115
|
-
const available = maxAllowed - secondsIntoSlot;
|
|
116
|
-
const executionTimeEnd = secondsIntoSlot + available / 2;
|
|
117
|
-
this.log.debug(`Block proposal execution time deadline is ${executionTimeEnd}`, {
|
|
118
|
-
secondsIntoSlot,
|
|
119
|
-
maxAllowed,
|
|
120
|
-
available,
|
|
121
|
-
executionTimeEnd,
|
|
122
|
-
});
|
|
123
|
-
return executionTimeEnd;
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
private get afterBlockReexecTimeNeeded() {
|
|
127
|
-
return this.attestationPropagationTime + this.l1PublishingTime;
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
public getValidatorReexecTimeEnd(secondsIntoSlot?: number): number {
|
|
131
|
-
// We need to leave for `afterBlockReexecTimeNeeded` seconds available.
|
|
132
|
-
const validationTimeEnd = this.aztecSlotDuration - this.afterBlockReexecTimeNeeded;
|
|
133
|
-
this.log.debug(`Validator re-execution time deadline is ${validationTimeEnd}`, {
|
|
134
|
-
secondsIntoSlot,
|
|
135
|
-
validationTimeEnd,
|
|
136
|
-
});
|
|
137
|
-
return validationTimeEnd;
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
public getMaxAllowedTime(
|
|
141
|
-
state: Extract<SequencerState, SequencerState.STOPPED | SequencerState.IDLE | SequencerState.SYNCHRONIZING>,
|
|
142
|
-
): undefined;
|
|
143
|
-
public getMaxAllowedTime(
|
|
144
|
-
state: Exclude<SequencerState, SequencerState.STOPPED | SequencerState.IDLE | SequencerState.SYNCHRONIZING>,
|
|
145
|
-
): number;
|
|
146
|
-
public getMaxAllowedTime(state: SequencerState): number | undefined;
|
|
147
|
-
public getMaxAllowedTime(state: SequencerState): number | undefined {
|
|
148
|
-
switch (state) {
|
|
149
|
-
case SequencerState.STOPPED:
|
|
150
|
-
case SequencerState.STOPPING:
|
|
151
|
-
case SequencerState.IDLE:
|
|
152
|
-
case SequencerState.SYNCHRONIZING:
|
|
153
|
-
return; // We don't really care about times for this states
|
|
154
|
-
case SequencerState.PROPOSER_CHECK:
|
|
155
|
-
case SequencerState.INITIALIZING_PROPOSAL:
|
|
156
|
-
return this.initializeDeadline;
|
|
157
|
-
case SequencerState.CREATING_BLOCK:
|
|
158
|
-
return this.initializeDeadline + this.blockPrepareTime;
|
|
159
|
-
case SequencerState.COLLECTING_ATTESTATIONS:
|
|
160
|
-
return this.aztecSlotDuration - this.l1PublishingTime - 2 * this.attestationPropagationTime;
|
|
161
|
-
case SequencerState.PUBLISHING_BLOCK:
|
|
162
|
-
return this.aztecSlotDuration - this.l1PublishingTime;
|
|
163
|
-
default: {
|
|
164
|
-
const _exhaustiveCheck: never = state;
|
|
165
|
-
throw new Error(`Unexpected state: ${state}`);
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
public assertTimeLeft(newState: SequencerState, secondsIntoSlot: number) {
|
|
171
|
-
if (!this.enforce) {
|
|
172
|
-
return;
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
const maxAllowedTime = this.getMaxAllowedTime(newState);
|
|
176
|
-
if (maxAllowedTime === undefined) {
|
|
177
|
-
return;
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
const bufferSeconds = maxAllowedTime - secondsIntoSlot;
|
|
181
|
-
if (bufferSeconds < 0) {
|
|
182
|
-
throw new SequencerTooSlowError(newState, maxAllowedTime, secondsIntoSlot);
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
this.metrics?.recordStateTransitionBufferMs(Math.floor(bufferSeconds * 1000), newState);
|
|
186
|
-
this.log.trace(`Enough time to transition to ${newState}`, { maxAllowedTime, secondsIntoSlot });
|
|
187
|
-
}
|
|
188
|
-
}
|
|
@@ -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,132 +0,0 @@
|
|
|
1
|
-
import { Fr } from '@aztec/foundation/fields';
|
|
2
|
-
import { getVKTreeRoot } from '@aztec/noir-protocol-circuits-types/vk-tree';
|
|
3
|
-
import {
|
|
4
|
-
AggregateTxValidator,
|
|
5
|
-
ArchiveCache,
|
|
6
|
-
BlockHeaderTxValidator,
|
|
7
|
-
DataTxValidator,
|
|
8
|
-
DoubleSpendTxValidator,
|
|
9
|
-
GasTxValidator,
|
|
10
|
-
MetadataTxValidator,
|
|
11
|
-
PhasesTxValidator,
|
|
12
|
-
TimestampTxValidator,
|
|
13
|
-
TxPermittedValidator,
|
|
14
|
-
TxProofValidator,
|
|
15
|
-
} from '@aztec/p2p';
|
|
16
|
-
import { ProtocolContractAddress, protocolContractsHash } from '@aztec/protocol-contracts';
|
|
17
|
-
import type { ContractDataSource } from '@aztec/stdlib/contract';
|
|
18
|
-
import type { GasFees } from '@aztec/stdlib/gas';
|
|
19
|
-
import type {
|
|
20
|
-
AllowedElement,
|
|
21
|
-
ClientProtocolCircuitVerifier,
|
|
22
|
-
MerkleTreeReadOperations,
|
|
23
|
-
PublicProcessorValidator,
|
|
24
|
-
} from '@aztec/stdlib/interfaces/server';
|
|
25
|
-
import { DatabasePublicStateSource, type PublicStateSource } from '@aztec/stdlib/trees';
|
|
26
|
-
import { GlobalVariables, type Tx, type TxValidator } from '@aztec/stdlib/tx';
|
|
27
|
-
import type { UInt64 } from '@aztec/stdlib/types';
|
|
28
|
-
|
|
29
|
-
import { NullifierCache } from './nullifier_cache.js';
|
|
30
|
-
|
|
31
|
-
export function createValidatorForAcceptingTxs(
|
|
32
|
-
db: MerkleTreeReadOperations,
|
|
33
|
-
contractDataSource: ContractDataSource,
|
|
34
|
-
verifier: ClientProtocolCircuitVerifier | undefined,
|
|
35
|
-
{
|
|
36
|
-
l1ChainId,
|
|
37
|
-
rollupVersion,
|
|
38
|
-
setupAllowList,
|
|
39
|
-
gasFees,
|
|
40
|
-
skipFeeEnforcement,
|
|
41
|
-
timestamp,
|
|
42
|
-
blockNumber,
|
|
43
|
-
txsPermitted,
|
|
44
|
-
}: {
|
|
45
|
-
l1ChainId: number;
|
|
46
|
-
rollupVersion: number;
|
|
47
|
-
setupAllowList: AllowedElement[];
|
|
48
|
-
gasFees: GasFees;
|
|
49
|
-
skipFeeEnforcement?: boolean;
|
|
50
|
-
timestamp: UInt64;
|
|
51
|
-
blockNumber: number;
|
|
52
|
-
txsPermitted: boolean;
|
|
53
|
-
},
|
|
54
|
-
): TxValidator<Tx> {
|
|
55
|
-
const validators: TxValidator<Tx>[] = [
|
|
56
|
-
new TxPermittedValidator(txsPermitted),
|
|
57
|
-
new DataTxValidator(),
|
|
58
|
-
new MetadataTxValidator({
|
|
59
|
-
l1ChainId: new Fr(l1ChainId),
|
|
60
|
-
rollupVersion: new Fr(rollupVersion),
|
|
61
|
-
protocolContractsHash,
|
|
62
|
-
vkTreeRoot: getVKTreeRoot(),
|
|
63
|
-
}),
|
|
64
|
-
new TimestampTxValidator({
|
|
65
|
-
timestamp,
|
|
66
|
-
blockNumber,
|
|
67
|
-
}),
|
|
68
|
-
new DoubleSpendTxValidator(new NullifierCache(db)),
|
|
69
|
-
new PhasesTxValidator(contractDataSource, setupAllowList, timestamp),
|
|
70
|
-
new BlockHeaderTxValidator(new ArchiveCache(db)),
|
|
71
|
-
];
|
|
72
|
-
|
|
73
|
-
if (!skipFeeEnforcement) {
|
|
74
|
-
validators.push(new GasTxValidator(new DatabasePublicStateSource(db), ProtocolContractAddress.FeeJuice, gasFees));
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
if (verifier) {
|
|
78
|
-
validators.push(new TxProofValidator(verifier));
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
return new AggregateTxValidator(...validators);
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
export function createValidatorForBlockBuilding(
|
|
85
|
-
db: MerkleTreeReadOperations,
|
|
86
|
-
contractDataSource: ContractDataSource,
|
|
87
|
-
globalVariables: GlobalVariables,
|
|
88
|
-
setupAllowList: AllowedElement[],
|
|
89
|
-
): PublicProcessorValidator {
|
|
90
|
-
const nullifierCache = new NullifierCache(db);
|
|
91
|
-
const archiveCache = new ArchiveCache(db);
|
|
92
|
-
const publicStateSource = new DatabasePublicStateSource(db);
|
|
93
|
-
|
|
94
|
-
return {
|
|
95
|
-
preprocessValidator: preprocessValidator(
|
|
96
|
-
nullifierCache,
|
|
97
|
-
archiveCache,
|
|
98
|
-
publicStateSource,
|
|
99
|
-
contractDataSource,
|
|
100
|
-
globalVariables,
|
|
101
|
-
setupAllowList,
|
|
102
|
-
),
|
|
103
|
-
nullifierCache,
|
|
104
|
-
};
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
function preprocessValidator(
|
|
108
|
-
nullifierCache: NullifierCache,
|
|
109
|
-
archiveCache: ArchiveCache,
|
|
110
|
-
publicStateSource: PublicStateSource,
|
|
111
|
-
contractDataSource: ContractDataSource,
|
|
112
|
-
globalVariables: GlobalVariables,
|
|
113
|
-
setupAllowList: AllowedElement[],
|
|
114
|
-
): TxValidator<Tx> {
|
|
115
|
-
// We don't include the TxProofValidator nor the DataTxValidator here because they are already checked by the time we get to block building.
|
|
116
|
-
return new AggregateTxValidator(
|
|
117
|
-
new MetadataTxValidator({
|
|
118
|
-
l1ChainId: globalVariables.chainId,
|
|
119
|
-
rollupVersion: globalVariables.version,
|
|
120
|
-
protocolContractsHash,
|
|
121
|
-
vkTreeRoot: getVKTreeRoot(),
|
|
122
|
-
}),
|
|
123
|
-
new TimestampTxValidator({
|
|
124
|
-
timestamp: globalVariables.timestamp,
|
|
125
|
-
blockNumber: globalVariables.blockNumber,
|
|
126
|
-
}),
|
|
127
|
-
new DoubleSpendTxValidator(nullifierCache),
|
|
128
|
-
new PhasesTxValidator(contractDataSource, setupAllowList, globalVariables.timestamp),
|
|
129
|
-
new GasTxValidator(publicStateSource, ProtocolContractAddress.FeeJuice, globalVariables.gasFees),
|
|
130
|
-
new BlockHeaderTxValidator(archiveCache),
|
|
131
|
-
);
|
|
132
|
-
}
|