@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
|
@@ -1,20 +1,21 @@
|
|
|
1
|
-
import { createLogger } from '@aztec/aztec.js';
|
|
1
|
+
import { createLogger } from '@aztec/aztec.js/log';
|
|
2
2
|
|
|
3
|
+
import { DEFAULT_ATTESTATION_PROPAGATION_TIME } from '../config.js';
|
|
4
|
+
import { SequencerTooSlowError } from './errors.js';
|
|
3
5
|
import type { SequencerMetrics } from './metrics.js';
|
|
4
6
|
import { SequencerState } from './utils.js';
|
|
5
7
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
/** How long it takes to get ready to start building */
|
|
11
|
-
public readonly blockPrepareTime = 1;
|
|
12
|
-
|
|
13
|
-
/** How long it takes to for proposals and attestations to travel across the p2p layer (one-way) */
|
|
14
|
-
public readonly attestationPropagationTime = 2;
|
|
8
|
+
const MIN_EXECUTION_TIME = 1;
|
|
9
|
+
const BLOCK_PREPARE_TIME = 1;
|
|
10
|
+
const BLOCK_VALIDATION_TIME = 1;
|
|
15
11
|
|
|
16
|
-
|
|
17
|
-
|
|
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;
|
|
18
19
|
|
|
19
20
|
/**
|
|
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,
|
|
@@ -23,15 +24,84 @@ export class SequencerTimetable {
|
|
|
23
24
|
*/
|
|
24
25
|
public readonly l1PublishingTime;
|
|
25
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
|
+
|
|
26
51
|
constructor(
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
52
|
+
opts: {
|
|
53
|
+
ethereumSlotDuration: number;
|
|
54
|
+
aztecSlotDuration: number;
|
|
55
|
+
maxL1TxInclusionTimeIntoSlot: number;
|
|
56
|
+
attestationPropagationTime?: number;
|
|
57
|
+
enforce: boolean;
|
|
58
|
+
},
|
|
31
59
|
private readonly metrics?: SequencerMetrics,
|
|
32
60
|
private readonly log = createLogger('sequencer:timetable'),
|
|
33
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;
|
|
34
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
|
+
}
|
|
35
105
|
}
|
|
36
106
|
|
|
37
107
|
private get afterBlockBuildingTimeNeededWithoutReexec() {
|
|
@@ -57,7 +127,7 @@ export class SequencerTimetable {
|
|
|
57
127
|
return this.attestationPropagationTime + this.l1PublishingTime;
|
|
58
128
|
}
|
|
59
129
|
|
|
60
|
-
public getValidatorReexecTimeEnd(secondsIntoSlot
|
|
130
|
+
public getValidatorReexecTimeEnd(secondsIntoSlot?: number): number {
|
|
61
131
|
// We need to leave for `afterBlockReexecTimeNeeded` seconds available.
|
|
62
132
|
const validationTimeEnd = this.aztecSlotDuration - this.afterBlockReexecTimeNeeded;
|
|
63
133
|
this.log.debug(`Validator re-execution time deadline is ${validationTimeEnd}`, {
|
|
@@ -67,17 +137,25 @@ export class SequencerTimetable {
|
|
|
67
137
|
return validationTimeEnd;
|
|
68
138
|
}
|
|
69
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;
|
|
70
147
|
public getMaxAllowedTime(state: SequencerState): number | undefined {
|
|
71
148
|
switch (state) {
|
|
72
149
|
case SequencerState.STOPPED:
|
|
150
|
+
case SequencerState.STOPPING:
|
|
73
151
|
case SequencerState.IDLE:
|
|
74
152
|
case SequencerState.SYNCHRONIZING:
|
|
75
|
-
case SequencerState.PROPOSER_CHECK:
|
|
76
153
|
return; // We don't really care about times for this states
|
|
154
|
+
case SequencerState.PROPOSER_CHECK:
|
|
77
155
|
case SequencerState.INITIALIZING_PROPOSAL:
|
|
78
|
-
return this.
|
|
156
|
+
return this.initializeDeadline;
|
|
79
157
|
case SequencerState.CREATING_BLOCK:
|
|
80
|
-
return this.
|
|
158
|
+
return this.initializeDeadline + this.blockPrepareTime;
|
|
81
159
|
case SequencerState.COLLECTING_ATTESTATIONS:
|
|
82
160
|
return this.aztecSlotDuration - this.l1PublishingTime - 2 * this.attestationPropagationTime;
|
|
83
161
|
case SequencerState.PUBLISHING_BLOCK:
|
|
@@ -108,16 +186,3 @@ export class SequencerTimetable {
|
|
|
108
186
|
this.log.trace(`Enough time to transition to ${newState}`, { maxAllowedTime, secondsIntoSlot });
|
|
109
187
|
}
|
|
110
188
|
}
|
|
111
|
-
|
|
112
|
-
export class SequencerTooSlowError extends Error {
|
|
113
|
-
constructor(
|
|
114
|
-
public readonly proposedState: SequencerState,
|
|
115
|
-
public readonly maxAllowedTime: number,
|
|
116
|
-
public readonly currentTime: number,
|
|
117
|
-
) {
|
|
118
|
-
super(
|
|
119
|
-
`Too far into slot for ${proposedState} (time into slot ${currentTime}s greater than ${maxAllowedTime}s allowance)`,
|
|
120
|
-
);
|
|
121
|
-
this.name = 'SequencerTooSlowError';
|
|
122
|
-
}
|
|
123
|
-
}
|
package/src/sequencer/utils.ts
CHANGED
|
@@ -1,74 +1,33 @@
|
|
|
1
|
-
import type { EthAddress } from '@aztec/foundation/eth-address';
|
|
2
|
-
import { Signature } from '@aztec/foundation/eth-signature';
|
|
3
|
-
import type { BlockAttestation } from '@aztec/stdlib/p2p';
|
|
4
|
-
|
|
5
1
|
export enum SequencerState {
|
|
6
|
-
/**
|
|
7
|
-
* Sequencer is stopped and not processing any txs from the pool.
|
|
8
|
-
*/
|
|
2
|
+
/** Sequencer is stopped and not processing any txs from the pool. */
|
|
9
3
|
STOPPED = 'STOPPED',
|
|
10
|
-
/**
|
|
11
|
-
|
|
12
|
-
|
|
4
|
+
/** Sequencer is being stopped. Will move to STOPPED shortly. */
|
|
5
|
+
STOPPING = 'STOPPING',
|
|
6
|
+
/** Sequencer is awaiting the next call to work(). */
|
|
13
7
|
IDLE = 'IDLE',
|
|
14
|
-
/**
|
|
15
|
-
* Synchronizing with the L2 chain.
|
|
16
|
-
*/
|
|
8
|
+
/** Synchronizing with the L2 chain. */
|
|
17
9
|
SYNCHRONIZING = 'SYNCHRONIZING',
|
|
18
|
-
/**
|
|
19
|
-
* Checking if we are the proposer for the current slot.
|
|
20
|
-
*/
|
|
10
|
+
/** Checking if we are the proposer for the current slot. */
|
|
21
11
|
PROPOSER_CHECK = 'PROPOSER_CHECK',
|
|
22
|
-
/**
|
|
23
|
-
* Initializing the block proposal. Will move to CREATING_BLOCK if there are valid txs to include, or back to SYNCHRONIZING otherwise.
|
|
24
|
-
*/
|
|
12
|
+
/** Initializing the block proposal. Will move to CREATING_BLOCK if there are valid txs to include, or back to SYNCHRONIZING otherwise. */
|
|
25
13
|
INITIALIZING_PROPOSAL = 'INITIALIZING_PROPOSAL',
|
|
26
|
-
/**
|
|
27
|
-
* Creating a new L2 block. Includes processing public function calls and running rollup circuits. Will move to PUBLISHING_CONTRACT_DATA.
|
|
28
|
-
*/
|
|
14
|
+
/** Creating a new L2 block. Includes processing public function calls and running rollup circuits. Will move to PUBLISHING_CONTRACT_DATA. */
|
|
29
15
|
CREATING_BLOCK = 'CREATING_BLOCK',
|
|
30
|
-
/**
|
|
31
|
-
* Collecting attestations from its peers. Will move to PUBLISHING_BLOCK.
|
|
32
|
-
*/
|
|
16
|
+
/** Collecting attestations from its peers. Will move to PUBLISHING_BLOCK. */
|
|
33
17
|
COLLECTING_ATTESTATIONS = 'COLLECTING_ATTESTATIONS',
|
|
34
|
-
/**
|
|
35
|
-
* Sending the tx to L1 with the L2 block data and awaiting it to be mined. Will move to SYNCHRONIZING.
|
|
36
|
-
*/
|
|
18
|
+
/** Sending the tx to L1 with the L2 block data and awaiting it to be mined. Will move to SYNCHRONIZING. */
|
|
37
19
|
PUBLISHING_BLOCK = 'PUBLISHING_BLOCK',
|
|
38
20
|
}
|
|
39
21
|
|
|
22
|
+
export type SequencerStateWithSlot =
|
|
23
|
+
| SequencerState.INITIALIZING_PROPOSAL
|
|
24
|
+
| SequencerState.CREATING_BLOCK
|
|
25
|
+
| SequencerState.COLLECTING_ATTESTATIONS
|
|
26
|
+
| SequencerState.PUBLISHING_BLOCK
|
|
27
|
+
| SequencerState.PROPOSER_CHECK;
|
|
28
|
+
|
|
40
29
|
export type SequencerStateCallback = () => SequencerState;
|
|
41
30
|
|
|
42
31
|
export function sequencerStateToNumber(state: SequencerState): number {
|
|
43
32
|
return Object.values(SequencerState).indexOf(state);
|
|
44
33
|
}
|
|
45
|
-
|
|
46
|
-
/** Order Attestations
|
|
47
|
-
*
|
|
48
|
-
* Returns attestation signatures in the order of a series of provided ethereum addresses
|
|
49
|
-
* The rollup smart contract expects attestations to appear in the order of the committee
|
|
50
|
-
*
|
|
51
|
-
* @todo: perform this logic within the memory attestation store instead?
|
|
52
|
-
*/
|
|
53
|
-
export async function orderAttestations(
|
|
54
|
-
attestations: BlockAttestation[],
|
|
55
|
-
orderAddresses: EthAddress[],
|
|
56
|
-
): Promise<Signature[]> {
|
|
57
|
-
// Create a map of sender addresses to BlockAttestations
|
|
58
|
-
const attestationMap = new Map<string, BlockAttestation>();
|
|
59
|
-
|
|
60
|
-
for (const attestation of attestations) {
|
|
61
|
-
const sender = await attestation.getSender();
|
|
62
|
-
if (sender) {
|
|
63
|
-
attestationMap.set(sender.toString(), attestation);
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
// Create the ordered array based on the orderAddresses, else return an empty signature
|
|
68
|
-
const orderedAttestations = orderAddresses.map(address => {
|
|
69
|
-
const addressString = address.toString();
|
|
70
|
-
return attestationMap.get(addressString)?.signature || Signature.empty();
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
return orderedAttestations;
|
|
74
|
-
}
|
package/src/test/index.ts
CHANGED
|
@@ -1,20 +1,27 @@
|
|
|
1
|
+
import type { PublisherManager } from '@aztec/ethereum';
|
|
2
|
+
import type { L1TxUtilsWithBlobs } from '@aztec/ethereum/l1-tx-utils-with-blobs';
|
|
1
3
|
import type { PublicProcessorFactory } from '@aztec/simulator/server';
|
|
4
|
+
import type { ValidatorClient } from '@aztec/validator-client';
|
|
2
5
|
|
|
3
6
|
import { SequencerClient } from '../client/sequencer-client.js';
|
|
7
|
+
import type { SequencerPublisherFactory } from '../publisher/sequencer-publisher-factory.js';
|
|
4
8
|
import type { SequencerPublisher } from '../publisher/sequencer-publisher.js';
|
|
5
9
|
import { Sequencer } from '../sequencer/sequencer.js';
|
|
6
10
|
import type { SequencerTimetable } from '../sequencer/timetable.js';
|
|
7
11
|
|
|
8
12
|
class TestSequencer_ extends Sequencer {
|
|
9
|
-
public
|
|
10
|
-
public
|
|
11
|
-
public
|
|
13
|
+
declare public publicProcessorFactory: PublicProcessorFactory;
|
|
14
|
+
declare public timetable: SequencerTimetable;
|
|
15
|
+
declare public publisher: SequencerPublisher;
|
|
16
|
+
declare public publisherFactory: SequencerPublisherFactory;
|
|
17
|
+
declare public validatorClient: ValidatorClient;
|
|
12
18
|
}
|
|
13
19
|
|
|
14
20
|
export type TestSequencer = TestSequencer_;
|
|
15
21
|
|
|
16
22
|
class TestSequencerClient_ extends SequencerClient {
|
|
17
|
-
public
|
|
23
|
+
declare public sequencer: TestSequencer;
|
|
24
|
+
declare public publisherManager: PublisherManager<L1TxUtilsWithBlobs>;
|
|
18
25
|
}
|
|
19
26
|
|
|
20
27
|
export type TestSequencerClient = TestSequencerClient_;
|
|
@@ -1,52 +1,72 @@
|
|
|
1
1
|
import { Fr } from '@aztec/foundation/fields';
|
|
2
|
+
import { getVKTreeRoot } from '@aztec/noir-protocol-circuits-types/vk-tree';
|
|
2
3
|
import {
|
|
3
4
|
AggregateTxValidator,
|
|
5
|
+
ArchiveCache,
|
|
4
6
|
BlockHeaderTxValidator,
|
|
5
7
|
DataTxValidator,
|
|
6
8
|
DoubleSpendTxValidator,
|
|
9
|
+
GasTxValidator,
|
|
7
10
|
MetadataTxValidator,
|
|
11
|
+
PhasesTxValidator,
|
|
12
|
+
TimestampTxValidator,
|
|
13
|
+
TxPermittedValidator,
|
|
8
14
|
TxProofValidator,
|
|
9
15
|
} from '@aztec/p2p';
|
|
10
|
-
import { ProtocolContractAddress } from '@aztec/protocol-contracts';
|
|
11
|
-
import { readPublicState } from '@aztec/simulator/server';
|
|
12
|
-
import type { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
16
|
+
import { ProtocolContractAddress, protocolContractsHash } from '@aztec/protocol-contracts';
|
|
13
17
|
import type { ContractDataSource } from '@aztec/stdlib/contract';
|
|
14
18
|
import type { GasFees } from '@aztec/stdlib/gas';
|
|
15
19
|
import type {
|
|
16
20
|
AllowedElement,
|
|
17
21
|
ClientProtocolCircuitVerifier,
|
|
18
22
|
MerkleTreeReadOperations,
|
|
23
|
+
PublicProcessorValidator,
|
|
19
24
|
} from '@aztec/stdlib/interfaces/server';
|
|
20
|
-
import {
|
|
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';
|
|
21
28
|
|
|
22
|
-
import { ArchiveCache } from './archive_cache.js';
|
|
23
|
-
import { GasTxValidator, type PublicStateSource } from './gas_validator.js';
|
|
24
29
|
import { NullifierCache } from './nullifier_cache.js';
|
|
25
|
-
import { PhasesTxValidator } from './phases_validator.js';
|
|
26
30
|
|
|
27
31
|
export function createValidatorForAcceptingTxs(
|
|
28
32
|
db: MerkleTreeReadOperations,
|
|
29
33
|
contractDataSource: ContractDataSource,
|
|
30
34
|
verifier: ClientProtocolCircuitVerifier | undefined,
|
|
31
35
|
{
|
|
32
|
-
blockNumber,
|
|
33
36
|
l1ChainId,
|
|
37
|
+
rollupVersion,
|
|
34
38
|
setupAllowList,
|
|
35
39
|
gasFees,
|
|
36
40
|
skipFeeEnforcement,
|
|
41
|
+
timestamp,
|
|
42
|
+
blockNumber,
|
|
43
|
+
txsPermitted,
|
|
37
44
|
}: {
|
|
38
|
-
blockNumber: number;
|
|
39
45
|
l1ChainId: number;
|
|
46
|
+
rollupVersion: number;
|
|
40
47
|
setupAllowList: AllowedElement[];
|
|
41
48
|
gasFees: GasFees;
|
|
42
49
|
skipFeeEnforcement?: boolean;
|
|
50
|
+
timestamp: UInt64;
|
|
51
|
+
blockNumber: number;
|
|
52
|
+
txsPermitted: boolean;
|
|
43
53
|
},
|
|
44
54
|
): TxValidator<Tx> {
|
|
45
55
|
const validators: TxValidator<Tx>[] = [
|
|
56
|
+
new TxPermittedValidator(txsPermitted),
|
|
46
57
|
new DataTxValidator(),
|
|
47
|
-
new MetadataTxValidator(
|
|
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
|
+
}),
|
|
48
68
|
new DoubleSpendTxValidator(new NullifierCache(db)),
|
|
49
|
-
new PhasesTxValidator(contractDataSource, setupAllowList),
|
|
69
|
+
new PhasesTxValidator(contractDataSource, setupAllowList, timestamp),
|
|
50
70
|
new BlockHeaderTxValidator(new ArchiveCache(db)),
|
|
51
71
|
];
|
|
52
72
|
|
|
@@ -61,16 +81,12 @@ export function createValidatorForAcceptingTxs(
|
|
|
61
81
|
return new AggregateTxValidator(...validators);
|
|
62
82
|
}
|
|
63
83
|
|
|
64
|
-
export function
|
|
84
|
+
export function createValidatorForBlockBuilding(
|
|
65
85
|
db: MerkleTreeReadOperations,
|
|
66
86
|
contractDataSource: ContractDataSource,
|
|
67
87
|
globalVariables: GlobalVariables,
|
|
68
88
|
setupAllowList: AllowedElement[],
|
|
69
|
-
): {
|
|
70
|
-
preprocessValidator: TxValidator<Tx>;
|
|
71
|
-
postprocessValidator: TxValidator<ProcessedTx>;
|
|
72
|
-
nullifierCache: NullifierCache;
|
|
73
|
-
} {
|
|
89
|
+
): PublicProcessorValidator {
|
|
74
90
|
const nullifierCache = new NullifierCache(db);
|
|
75
91
|
const archiveCache = new ArchiveCache(db);
|
|
76
92
|
const publicStateSource = new DatabasePublicStateSource(db);
|
|
@@ -84,19 +100,10 @@ export function createValidatorsForBlockBuilding(
|
|
|
84
100
|
globalVariables,
|
|
85
101
|
setupAllowList,
|
|
86
102
|
),
|
|
87
|
-
postprocessValidator: postprocessValidator(nullifierCache),
|
|
88
103
|
nullifierCache,
|
|
89
104
|
};
|
|
90
105
|
}
|
|
91
106
|
|
|
92
|
-
class DatabasePublicStateSource implements PublicStateSource {
|
|
93
|
-
constructor(private db: MerkleTreeReadOperations) {}
|
|
94
|
-
|
|
95
|
-
storageRead(contractAddress: AztecAddress, slot: Fr): Promise<Fr> {
|
|
96
|
-
return readPublicState(this.db, contractAddress, slot);
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
|
|
100
107
|
function preprocessValidator(
|
|
101
108
|
nullifierCache: NullifierCache,
|
|
102
109
|
archiveCache: ArchiveCache,
|
|
@@ -107,14 +114,19 @@ function preprocessValidator(
|
|
|
107
114
|
): TxValidator<Tx> {
|
|
108
115
|
// We don't include the TxProofValidator nor the DataTxValidator here because they are already checked by the time we get to block building.
|
|
109
116
|
return new AggregateTxValidator(
|
|
110
|
-
new MetadataTxValidator(
|
|
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
|
+
}),
|
|
111
127
|
new DoubleSpendTxValidator(nullifierCache),
|
|
112
|
-
new PhasesTxValidator(contractDataSource, setupAllowList),
|
|
128
|
+
new PhasesTxValidator(contractDataSource, setupAllowList, globalVariables.timestamp),
|
|
113
129
|
new GasTxValidator(publicStateSource, ProtocolContractAddress.FeeJuice, globalVariables.gasFees),
|
|
114
130
|
new BlockHeaderTxValidator(archiveCache),
|
|
115
131
|
);
|
|
116
132
|
}
|
|
117
|
-
|
|
118
|
-
function postprocessValidator(nullifierCache: NullifierCache): TxValidator<ProcessedTx> {
|
|
119
|
-
return new DoubleSpendTxValidator(nullifierCache);
|
|
120
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"allowed.d.ts","sourceRoot":"","sources":["../../src/sequencer/allowed.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,iCAAiC,CAAC;AAItE,wBAAsB,+BAA+B,IAAI,OAAO,CAAC,cAAc,EAAE,CAAC,CA2BjF"}
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import { FPCContract } from '@aztec/noir-contracts.js/FPC';
|
|
2
|
-
import { TokenContractArtifact } from '@aztec/noir-contracts.js/Token';
|
|
3
|
-
import { ProtocolContractAddress } from '@aztec/protocol-contracts';
|
|
4
|
-
import { getContractClassFromArtifact } from '@aztec/stdlib/contract';
|
|
5
|
-
let defaultAllowedSetupFunctions = undefined;
|
|
6
|
-
export async function getDefaultAllowedSetupFunctions() {
|
|
7
|
-
if (defaultAllowedSetupFunctions === undefined) {
|
|
8
|
-
defaultAllowedSetupFunctions = [
|
|
9
|
-
// needed for authwit support
|
|
10
|
-
{
|
|
11
|
-
address: ProtocolContractAddress.AuthRegistry
|
|
12
|
-
},
|
|
13
|
-
// needed for claiming on the same tx as a spend
|
|
14
|
-
{
|
|
15
|
-
address: ProtocolContractAddress.FeeJuice
|
|
16
|
-
},
|
|
17
|
-
// needed for private transfers via FPC
|
|
18
|
-
{
|
|
19
|
-
classId: (await getContractClassFromArtifact(TokenContractArtifact)).id
|
|
20
|
-
},
|
|
21
|
-
{
|
|
22
|
-
classId: (await getContractClassFromArtifact(FPCContract.artifact)).id
|
|
23
|
-
}
|
|
24
|
-
];
|
|
25
|
-
}
|
|
26
|
-
return defaultAllowedSetupFunctions;
|
|
27
|
-
}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import type { L1ContractsConfig, L1ReaderConfig } from '@aztec/ethereum';
|
|
2
|
-
import type { L2BlockSourceEventEmitter } from '@aztec/stdlib/block';
|
|
3
|
-
import { type TelemetryClient } from '@aztec/telemetry-client';
|
|
4
|
-
import { SlasherClient } from './slasher_client.js';
|
|
5
|
-
import type { SlasherConfig } from './slasher_client.js';
|
|
6
|
-
export declare const createSlasherClient: (_config: SlasherConfig & L1ContractsConfig & L1ReaderConfig, l2BlockSource: L2BlockSourceEventEmitter, telemetry?: TelemetryClient) => SlasherClient;
|
|
7
|
-
//# sourceMappingURL=factory.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"factory.d.ts","sourceRoot":"","sources":["../../src/slasher/factory.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AACzE,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,qBAAqB,CAAC;AACrE,OAAO,EAAE,KAAK,eAAe,EAAsB,MAAM,yBAAyB,CAAC;AAEnF,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAEzD,eAAO,MAAM,mBAAmB,YACrB,aAAa,GAAG,iBAAiB,GAAG,cAAc,iBAC5C,yBAAyB,cAC7B,eAAe,kBAI3B,CAAC"}
|
package/dest/slasher/factory.js
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { getTelemetryClient } from '@aztec/telemetry-client';
|
|
2
|
-
import { SlasherClient } from './slasher_client.js';
|
|
3
|
-
export const createSlasherClient = (_config, l2BlockSource, telemetry = getTelemetryClient())=>{
|
|
4
|
-
const config = {
|
|
5
|
-
..._config
|
|
6
|
-
};
|
|
7
|
-
return new SlasherClient(config, l2BlockSource, telemetry);
|
|
8
|
-
};
|
package/dest/slasher/index.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/slasher/index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAC;AACpC,OAAO,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAC"}
|
package/dest/slasher/index.js
DELETED
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
import { type L1ContractsConfig, type L1ReaderConfig, type ViemPublicClient } from '@aztec/ethereum';
|
|
2
|
-
import { EthAddress } from '@aztec/foundation/eth-address';
|
|
3
|
-
import { SlashFactoryAbi } from '@aztec/l1-artifacts';
|
|
4
|
-
import { type L2BlockId, type L2BlockSourceEvent, type L2BlockSourceEventEmitter } from '@aztec/stdlib/block';
|
|
5
|
-
import { type TelemetryClient, WithTracer } from '@aztec/telemetry-client';
|
|
6
|
-
import { type GetContractReturnType } from 'viem';
|
|
7
|
-
/**
|
|
8
|
-
* Enum defining the possible states of the Slasher client.
|
|
9
|
-
*/
|
|
10
|
-
export declare enum SlasherClientState {
|
|
11
|
-
IDLE = 0,
|
|
12
|
-
RUNNING = 1,
|
|
13
|
-
STOPPED = 2
|
|
14
|
-
}
|
|
15
|
-
/**
|
|
16
|
-
* The synchronization status of the Slasher client.
|
|
17
|
-
*/
|
|
18
|
-
export interface SlasherSyncState {
|
|
19
|
-
/**
|
|
20
|
-
* The current state of the slasher client.
|
|
21
|
-
*/
|
|
22
|
-
state: SlasherClientState;
|
|
23
|
-
/**
|
|
24
|
-
* The block number that the slasher client is synced to.
|
|
25
|
-
*/
|
|
26
|
-
syncedToL2Block: L2BlockId;
|
|
27
|
-
}
|
|
28
|
-
export interface SlasherConfig {
|
|
29
|
-
blockCheckIntervalMS: number;
|
|
30
|
-
blockRequestBatchSize: number;
|
|
31
|
-
}
|
|
32
|
-
/**
|
|
33
|
-
* @notice A Hypomeiones slasher client implementation
|
|
34
|
-
*
|
|
35
|
-
* Hypomeiones: a class of individuals in ancient Sparta who were considered inferior or lesser citizens compared
|
|
36
|
-
* to the full Spartan citizens.
|
|
37
|
-
*
|
|
38
|
-
* The implementation here is less than ideal. It exists, not to be the end all be all, but to show that
|
|
39
|
-
* slashing can be done with this mechanism.
|
|
40
|
-
*
|
|
41
|
-
* The implementation is VERY brute in the sense that it only looks for pruned blocks and then tries to slash
|
|
42
|
-
* the full committee of that.
|
|
43
|
-
* If it sees a prune, it will mark the full epoch as "to be slashed".
|
|
44
|
-
*
|
|
45
|
-
* Also, it is not particularly smart around what it should if there were to be multiple slashing events.
|
|
46
|
-
*
|
|
47
|
-
* A few improvements:
|
|
48
|
-
* - Only vote on the proposal if it is possible to reach, e.g., if 6 votes are needed and only 4 slots are left don't vote.
|
|
49
|
-
* - Stop voting on a payload once it is processed.
|
|
50
|
-
* - Only vote on the proposal if it have not already been executed
|
|
51
|
-
* - Caveat, we need to fully decide if it is acceptable to have the same payload address multiple times. In the current
|
|
52
|
-
* slash factory that could mean slashing the same committee for the same error multiple times.
|
|
53
|
-
* - Decide how to deal with multiple slashing events in the same round.
|
|
54
|
-
* - This could be that multiple epochs are pruned in the same round, but with the current naive implementation we could end up
|
|
55
|
-
* slashing only the first, because the "lifetime" of the second would have passed after that vote
|
|
56
|
-
*/
|
|
57
|
-
export declare class SlasherClient extends WithTracer {
|
|
58
|
-
private config;
|
|
59
|
-
private l2BlockSource;
|
|
60
|
-
private log;
|
|
61
|
-
private slashEvents;
|
|
62
|
-
protected slashFactoryContract?: GetContractReturnType<typeof SlashFactoryAbi, ViemPublicClient>;
|
|
63
|
-
private slashingAmount;
|
|
64
|
-
constructor(config: SlasherConfig & L1ContractsConfig & L1ReaderConfig, l2BlockSource: L2BlockSourceEventEmitter, telemetry?: TelemetryClient, log?: import("@aztec/foundation/log").Logger);
|
|
65
|
-
start(): void;
|
|
66
|
-
getSlashPayload(slotNumber: bigint): Promise<EthAddress | undefined>;
|
|
67
|
-
handleBlockStreamEvent(event: L2BlockSourceEvent): Promise<void>;
|
|
68
|
-
/**
|
|
69
|
-
* Allows consumers to stop the instance of the slasher client.
|
|
70
|
-
* 'ready' will now return 'false' and the running promise that keeps the client synced is interrupted.
|
|
71
|
-
*/
|
|
72
|
-
stop(): void;
|
|
73
|
-
private handlePruneL2Blocks;
|
|
74
|
-
}
|
|
75
|
-
//# sourceMappingURL=slasher_client.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"slasher_client.d.ts","sourceRoot":"","sources":["../../src/slasher/slasher_client.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,iBAAiB,EACtB,KAAK,cAAc,EACnB,KAAK,gBAAgB,EAEtB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,UAAU,EAAE,MAAM,+BAA+B,CAAC;AAE3D,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AACtD,OAAO,EACL,KAAK,SAAS,EACd,KAAK,kBAAkB,EACvB,KAAK,yBAAyB,EAE/B,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,KAAK,eAAe,EAAE,UAAU,EAAsB,MAAM,yBAAyB,CAAC;AAE/F,OAAO,EAAE,KAAK,qBAAqB,EAA+D,MAAM,MAAM,CAAC;AAE/G;;GAEG;AACH,oBAAY,kBAAkB;IAC5B,IAAI,IAAA;IACJ,OAAO,IAAA;IACP,OAAO,IAAA;CACR;AAED;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B;;OAEG;IACH,KAAK,EAAE,kBAAkB,CAAC;IAC1B;;OAEG;IACH,eAAe,EAAE,SAAS,CAAC;CAC5B;AAED,MAAM,WAAW,aAAa;IAC5B,oBAAoB,EAAE,MAAM,CAAC;IAC7B,qBAAqB,EAAE,MAAM,CAAC;CAC/B;AAQD;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,qBAAa,aAAc,SAAQ,UAAU;IAWzC,OAAO,CAAC,MAAM;IACd,OAAO,CAAC,aAAa;IAErB,OAAO,CAAC,GAAG;IAbb,OAAO,CAAC,WAAW,CAAoB;IAEvC,SAAS,CAAC,oBAAoB,CAAC,EAAE,qBAAqB,CAAC,OAAO,eAAe,EAAE,gBAAgB,CAAC,CAAa;IAK7G,OAAO,CAAC,cAAc,CAAc;gBAG1B,MAAM,EAAE,aAAa,GAAG,iBAAiB,GAAG,cAAc,EAC1D,aAAa,EAAE,yBAAyB,EAChD,SAAS,GAAE,eAAsC,EACzC,GAAG,yCAA0B;IAwBhC,KAAK;IAMC,eAAe,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,GAAG,SAAS,CAAC;IA8B1E,sBAAsB,CAAC,KAAK,EAAE,kBAAkB,GAAG,OAAO,CAAC,IAAI,CAAC;IAavE;;;OAGG;IACI,IAAI;IAOX,OAAO,CAAC,mBAAmB;CAgB5B"}
|