@aztec/sequencer-client 1.2.1 → 2.0.0-nightly.20250813
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 +0 -2
- package/dest/client/sequencer-client.d.ts.map +1 -1
- package/dest/client/sequencer-client.js +5 -7
- package/dest/config.d.ts +1 -0
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +27 -0
- package/dest/publisher/index.d.ts +1 -1
- package/dest/publisher/index.d.ts.map +1 -1
- package/dest/publisher/index.js +1 -1
- package/dest/publisher/sequencer-publisher.d.ts +48 -33
- package/dest/publisher/sequencer-publisher.d.ts.map +1 -1
- package/dest/publisher/sequencer-publisher.js +272 -114
- package/dest/sequencer/block_builder.d.ts +2 -7
- package/dest/sequencer/block_builder.d.ts.map +1 -1
- package/dest/sequencer/block_builder.js +3 -7
- package/dest/sequencer/sequencer.d.ts +27 -15
- package/dest/sequencer/sequencer.d.ts.map +1 -1
- package/dest/sequencer/sequencer.js +141 -85
- package/dest/sequencer/timetable.d.ts +15 -5
- package/dest/sequencer/timetable.d.ts.map +1 -1
- package/dest/sequencer/timetable.js +25 -12
- package/dest/sequencer/utils.d.ts +1 -11
- package/dest/sequencer/utils.d.ts.map +1 -1
- package/dest/sequencer/utils.js +0 -23
- package/package.json +26 -26
- package/src/client/sequencer-client.ts +4 -8
- package/src/config.ts +33 -0
- package/src/publisher/index.ts +1 -1
- package/src/publisher/sequencer-publisher.ts +318 -131
- package/src/sequencer/block_builder.ts +15 -8
- package/src/sequencer/sequencer.ts +217 -87
- package/src/sequencer/timetable.ts +43 -7
- package/src/sequencer/utils.ts +6 -37
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { createLogger } from '@aztec/aztec.js';
|
|
2
2
|
|
|
3
|
+
import { DEFAULT_ATTESTATION_PROPAGATION_TIME } from '../config.js';
|
|
3
4
|
import type { SequencerMetrics } from './metrics.js';
|
|
4
5
|
import { SequencerState } from './utils.js';
|
|
5
6
|
|
|
6
7
|
const MIN_EXECUTION_TIME = 1;
|
|
7
8
|
const BLOCK_PREPARE_TIME = 1;
|
|
8
9
|
const BLOCK_VALIDATION_TIME = 1;
|
|
9
|
-
const ATTESTATION_PROPAGATION_TIME = 2;
|
|
10
10
|
|
|
11
11
|
export class SequencerTimetable {
|
|
12
12
|
/**
|
|
@@ -30,20 +30,40 @@ export class SequencerTimetable {
|
|
|
30
30
|
public readonly blockPrepareTime: number = BLOCK_PREPARE_TIME;
|
|
31
31
|
|
|
32
32
|
/** How long it takes to for proposals and attestations to travel across the p2p layer (one-way) */
|
|
33
|
-
public readonly attestationPropagationTime: number
|
|
33
|
+
public readonly attestationPropagationTime: number;
|
|
34
34
|
|
|
35
35
|
/** How much time we spend validating and processing a block after building it, and assembling the proposal to send to attestors */
|
|
36
36
|
public readonly blockValidationTime: number = BLOCK_VALIDATION_TIME;
|
|
37
37
|
|
|
38
|
+
/** Ethereum slot duration in seconds */
|
|
39
|
+
public readonly ethereumSlotDuration: number;
|
|
40
|
+
|
|
41
|
+
/** Aztec slot duration in seconds (must be multiple of ethereum slot duration) */
|
|
42
|
+
public readonly aztecSlotDuration: number;
|
|
43
|
+
|
|
44
|
+
/** 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. */
|
|
45
|
+
public readonly maxL1TxInclusionTimeIntoSlot: number;
|
|
46
|
+
|
|
47
|
+
/** Whether assertTimeLeft will throw if not enough time. */
|
|
48
|
+
public readonly enforce: boolean;
|
|
49
|
+
|
|
38
50
|
constructor(
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
51
|
+
opts: {
|
|
52
|
+
ethereumSlotDuration: number;
|
|
53
|
+
aztecSlotDuration: number;
|
|
54
|
+
maxL1TxInclusionTimeIntoSlot: number;
|
|
55
|
+
attestationPropagationTime?: number;
|
|
56
|
+
enforce: boolean;
|
|
57
|
+
},
|
|
43
58
|
private readonly metrics?: SequencerMetrics,
|
|
44
59
|
private readonly log = createLogger('sequencer:timetable'),
|
|
45
60
|
) {
|
|
61
|
+
this.ethereumSlotDuration = opts.ethereumSlotDuration;
|
|
62
|
+
this.aztecSlotDuration = opts.aztecSlotDuration;
|
|
63
|
+
this.maxL1TxInclusionTimeIntoSlot = opts.maxL1TxInclusionTimeIntoSlot;
|
|
64
|
+
this.attestationPropagationTime = opts.attestationPropagationTime ?? DEFAULT_ATTESTATION_PROPAGATION_TIME;
|
|
46
65
|
this.l1PublishingTime = this.ethereumSlotDuration - this.maxL1TxInclusionTimeIntoSlot;
|
|
66
|
+
this.enforce = opts.enforce;
|
|
47
67
|
|
|
48
68
|
// Assume zero-cost propagation time and faster runs in test environments where L1 slot duration is shortened
|
|
49
69
|
if (this.ethereumSlotDuration < 8) {
|
|
@@ -58,13 +78,29 @@ export class SequencerTimetable {
|
|
|
58
78
|
this.attestationPropagationTime * 2 +
|
|
59
79
|
this.blockValidationTime +
|
|
60
80
|
this.l1PublishingTime;
|
|
81
|
+
|
|
61
82
|
const initializeDeadline = this.aztecSlotDuration - allWorkToDo;
|
|
83
|
+
this.initializeDeadline = initializeDeadline;
|
|
84
|
+
|
|
85
|
+
this.log.verbose(`Sequencer timetable initialized (${this.enforce ? 'enforced' : 'not enforced'})`, {
|
|
86
|
+
ethereumSlotDuration: this.ethereumSlotDuration,
|
|
87
|
+
aztecSlotDuration: this.aztecSlotDuration,
|
|
88
|
+
maxL1TxInclusionTimeIntoSlot: this.maxL1TxInclusionTimeIntoSlot,
|
|
89
|
+
l1PublishingTime: this.l1PublishingTime,
|
|
90
|
+
minExecutionTime: this.minExecutionTime,
|
|
91
|
+
blockPrepareTime: this.blockPrepareTime,
|
|
92
|
+
attestationPropagationTime: this.attestationPropagationTime,
|
|
93
|
+
blockValidationTime: this.blockValidationTime,
|
|
94
|
+
initializeDeadline: this.initializeDeadline,
|
|
95
|
+
enforce: this.enforce,
|
|
96
|
+
allWorkToDo,
|
|
97
|
+
});
|
|
98
|
+
|
|
62
99
|
if (initializeDeadline <= 0) {
|
|
63
100
|
throw new Error(
|
|
64
101
|
`Block proposal initialize deadline cannot be negative (got ${initializeDeadline} from total time needed ${allWorkToDo} and a slot duration of ${this.aztecSlotDuration}).`,
|
|
65
102
|
);
|
|
66
103
|
}
|
|
67
|
-
this.initializeDeadline = initializeDeadline;
|
|
68
104
|
}
|
|
69
105
|
|
|
70
106
|
private get afterBlockBuildingTimeNeededWithoutReexec() {
|
package/src/sequencer/utils.ts
CHANGED
|
@@ -1,7 +1,3 @@
|
|
|
1
|
-
import type { EthAddress } from '@aztec/foundation/eth-address';
|
|
2
|
-
import { CommitteeAttestation } from '@aztec/stdlib/block';
|
|
3
|
-
import type { BlockAttestation } from '@aztec/stdlib/p2p';
|
|
4
|
-
|
|
5
1
|
export enum SequencerState {
|
|
6
2
|
/**
|
|
7
3
|
* Sequencer is stopped and not processing any txs from the pool.
|
|
@@ -37,41 +33,14 @@ export enum SequencerState {
|
|
|
37
33
|
PUBLISHING_BLOCK = 'PUBLISHING_BLOCK',
|
|
38
34
|
}
|
|
39
35
|
|
|
36
|
+
export type SequencerStateWithSlot =
|
|
37
|
+
| SequencerState.INITIALIZING_PROPOSAL
|
|
38
|
+
| SequencerState.CREATING_BLOCK
|
|
39
|
+
| SequencerState.COLLECTING_ATTESTATIONS
|
|
40
|
+
| SequencerState.PUBLISHING_BLOCK;
|
|
41
|
+
|
|
40
42
|
export type SequencerStateCallback = () => SequencerState;
|
|
41
43
|
|
|
42
44
|
export function sequencerStateToNumber(state: SequencerState): number {
|
|
43
45
|
return Object.values(SequencerState).indexOf(state);
|
|
44
46
|
}
|
|
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 function orderAttestations(
|
|
54
|
-
attestations: BlockAttestation[],
|
|
55
|
-
orderAddresses: EthAddress[],
|
|
56
|
-
): CommitteeAttestation[] {
|
|
57
|
-
// Create a map of sender addresses to BlockAttestations
|
|
58
|
-
const attestationMap = new Map<string, CommitteeAttestation>();
|
|
59
|
-
|
|
60
|
-
for (const attestation of attestations) {
|
|
61
|
-
const sender = attestation.getSender();
|
|
62
|
-
if (sender) {
|
|
63
|
-
attestationMap.set(
|
|
64
|
-
sender.toString(),
|
|
65
|
-
CommitteeAttestation.fromAddressAndSignature(sender, attestation.signature),
|
|
66
|
-
);
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
// Create the ordered array based on the orderAddresses, else return an empty attestation
|
|
71
|
-
const orderedAttestations = orderAddresses.map(address => {
|
|
72
|
-
const addressString = address.toString();
|
|
73
|
-
return attestationMap.get(addressString) || CommitteeAttestation.fromAddress(address);
|
|
74
|
-
});
|
|
75
|
-
|
|
76
|
-
return orderedAttestations;
|
|
77
|
-
}
|