@aztec/sequencer-client 0.0.1-commit.d3ec352c → 0.0.1-commit.d58ff9d0
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/sequencer-client.d.ts +41 -18
- package/dest/client/sequencer-client.d.ts.map +1 -1
- package/dest/client/sequencer-client.js +88 -43
- package/dest/config.d.ts +41 -8
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +146 -55
- 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 -26
- package/dest/global_variable_builder/global_builder.d.ts.map +1 -1
- package/dest/global_variable_builder/global_builder.js +28 -75
- 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 +57 -20
- package/dest/publisher/config.d.ts.map +1 -1
- package/dest/publisher/config.js +134 -39
- 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 +152 -90
- package/dest/publisher/sequencer-publisher.d.ts.map +1 -1
- package/dest/publisher/sequencer-publisher.js +1257 -421
- 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/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 +42 -7
- package/dest/sequencer/metrics.d.ts.map +1 -1
- package/dest/sequencer/metrics.js +241 -72
- 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 +251 -138
- package/dest/sequencer/sequencer.d.ts.map +1 -1
- package/dest/sequencer/sequencer.js +1190 -704
- 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 +32 -29
- package/src/client/sequencer-client.ts +118 -66
- package/src/config.ts +173 -64
- 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 -110
- package/src/global_variable_builder/index.ts +3 -1
- package/src/index.ts +1 -7
- package/src/publisher/config.ts +182 -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 +43 -13
- package/src/publisher/sequencer-publisher-metrics.ts +19 -71
- package/src/publisher/sequencer-publisher.ts +1042 -542
- 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 +302 -83
- package/src/sequencer/requests_tracker.ts +43 -0
- package/src/sequencer/sequencer.ts +1011 -898
- 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 -28
- package/dest/sequencer/block_builder.d.ts.map +0 -1
- package/dest/sequencer/block_builder.js +0 -134
- 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 -18
- 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 -222
- 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 -133
|
@@ -1,46 +1,413 @@
|
|
|
1
|
-
function
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
function applyDecs2203RFactory() {
|
|
2
|
+
function createAddInitializerMethod(initializers, decoratorFinishedRef) {
|
|
3
|
+
return function addInitializer(initializer) {
|
|
4
|
+
assertNotFinished(decoratorFinishedRef, "addInitializer");
|
|
5
|
+
assertCallable(initializer, "An initializer");
|
|
6
|
+
initializers.push(initializer);
|
|
7
|
+
};
|
|
8
|
+
}
|
|
9
|
+
function memberDec(dec, name, desc, initializers, kind, isStatic, isPrivate, metadata, value) {
|
|
10
|
+
var kindStr;
|
|
11
|
+
switch(kind){
|
|
12
|
+
case 1:
|
|
13
|
+
kindStr = "accessor";
|
|
14
|
+
break;
|
|
15
|
+
case 2:
|
|
16
|
+
kindStr = "method";
|
|
17
|
+
break;
|
|
18
|
+
case 3:
|
|
19
|
+
kindStr = "getter";
|
|
20
|
+
break;
|
|
21
|
+
case 4:
|
|
22
|
+
kindStr = "setter";
|
|
23
|
+
break;
|
|
24
|
+
default:
|
|
25
|
+
kindStr = "field";
|
|
26
|
+
}
|
|
27
|
+
var ctx = {
|
|
28
|
+
kind: kindStr,
|
|
29
|
+
name: isPrivate ? "#" + name : name,
|
|
30
|
+
static: isStatic,
|
|
31
|
+
private: isPrivate,
|
|
32
|
+
metadata: metadata
|
|
33
|
+
};
|
|
34
|
+
var decoratorFinishedRef = {
|
|
35
|
+
v: false
|
|
36
|
+
};
|
|
37
|
+
ctx.addInitializer = createAddInitializerMethod(initializers, decoratorFinishedRef);
|
|
38
|
+
var get, set;
|
|
39
|
+
if (kind === 0) {
|
|
40
|
+
if (isPrivate) {
|
|
41
|
+
get = desc.get;
|
|
42
|
+
set = desc.set;
|
|
43
|
+
} else {
|
|
44
|
+
get = function() {
|
|
45
|
+
return this[name];
|
|
46
|
+
};
|
|
47
|
+
set = function(v) {
|
|
48
|
+
this[name] = v;
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
} else if (kind === 2) {
|
|
52
|
+
get = function() {
|
|
53
|
+
return desc.value;
|
|
54
|
+
};
|
|
55
|
+
} else {
|
|
56
|
+
if (kind === 1 || kind === 3) {
|
|
57
|
+
get = function() {
|
|
58
|
+
return desc.get.call(this);
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
if (kind === 1 || kind === 4) {
|
|
62
|
+
set = function(v) {
|
|
63
|
+
desc.set.call(this, v);
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
ctx.access = get && set ? {
|
|
68
|
+
get: get,
|
|
69
|
+
set: set
|
|
70
|
+
} : get ? {
|
|
71
|
+
get: get
|
|
72
|
+
} : {
|
|
73
|
+
set: set
|
|
74
|
+
};
|
|
75
|
+
try {
|
|
76
|
+
return dec(value, ctx);
|
|
77
|
+
} finally{
|
|
78
|
+
decoratorFinishedRef.v = true;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
function assertNotFinished(decoratorFinishedRef, fnName) {
|
|
82
|
+
if (decoratorFinishedRef.v) {
|
|
83
|
+
throw new Error("attempted to call " + fnName + " after decoration was finished");
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
function assertCallable(fn, hint) {
|
|
87
|
+
if (typeof fn !== "function") {
|
|
88
|
+
throw new TypeError(hint + " must be a function");
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
function assertValidReturnValue(kind, value) {
|
|
92
|
+
var type = typeof value;
|
|
93
|
+
if (kind === 1) {
|
|
94
|
+
if (type !== "object" || value === null) {
|
|
95
|
+
throw new TypeError("accessor decorators must return an object with get, set, or init properties or void 0");
|
|
96
|
+
}
|
|
97
|
+
if (value.get !== undefined) {
|
|
98
|
+
assertCallable(value.get, "accessor.get");
|
|
99
|
+
}
|
|
100
|
+
if (value.set !== undefined) {
|
|
101
|
+
assertCallable(value.set, "accessor.set");
|
|
102
|
+
}
|
|
103
|
+
if (value.init !== undefined) {
|
|
104
|
+
assertCallable(value.init, "accessor.init");
|
|
105
|
+
}
|
|
106
|
+
} else if (type !== "function") {
|
|
107
|
+
var hint;
|
|
108
|
+
if (kind === 0) {
|
|
109
|
+
hint = "field";
|
|
110
|
+
} else if (kind === 10) {
|
|
111
|
+
hint = "class";
|
|
112
|
+
} else {
|
|
113
|
+
hint = "method";
|
|
114
|
+
}
|
|
115
|
+
throw new TypeError(hint + " decorators must return a function or void 0");
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
function applyMemberDec(ret, base, decInfo, name, kind, isStatic, isPrivate, initializers, metadata) {
|
|
119
|
+
var decs = decInfo[0];
|
|
120
|
+
var desc, init, value;
|
|
121
|
+
if (isPrivate) {
|
|
122
|
+
if (kind === 0 || kind === 1) {
|
|
123
|
+
desc = {
|
|
124
|
+
get: decInfo[3],
|
|
125
|
+
set: decInfo[4]
|
|
126
|
+
};
|
|
127
|
+
} else if (kind === 3) {
|
|
128
|
+
desc = {
|
|
129
|
+
get: decInfo[3]
|
|
130
|
+
};
|
|
131
|
+
} else if (kind === 4) {
|
|
132
|
+
desc = {
|
|
133
|
+
set: decInfo[3]
|
|
134
|
+
};
|
|
135
|
+
} else {
|
|
136
|
+
desc = {
|
|
137
|
+
value: decInfo[3]
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
} else if (kind !== 0) {
|
|
141
|
+
desc = Object.getOwnPropertyDescriptor(base, name);
|
|
142
|
+
}
|
|
143
|
+
if (kind === 1) {
|
|
144
|
+
value = {
|
|
145
|
+
get: desc.get,
|
|
146
|
+
set: desc.set
|
|
147
|
+
};
|
|
148
|
+
} else if (kind === 2) {
|
|
149
|
+
value = desc.value;
|
|
150
|
+
} else if (kind === 3) {
|
|
151
|
+
value = desc.get;
|
|
152
|
+
} else if (kind === 4) {
|
|
153
|
+
value = desc.set;
|
|
154
|
+
}
|
|
155
|
+
var newValue, get, set;
|
|
156
|
+
if (typeof decs === "function") {
|
|
157
|
+
newValue = memberDec(decs, name, desc, initializers, kind, isStatic, isPrivate, metadata, value);
|
|
158
|
+
if (newValue !== void 0) {
|
|
159
|
+
assertValidReturnValue(kind, newValue);
|
|
160
|
+
if (kind === 0) {
|
|
161
|
+
init = newValue;
|
|
162
|
+
} else if (kind === 1) {
|
|
163
|
+
init = newValue.init;
|
|
164
|
+
get = newValue.get || value.get;
|
|
165
|
+
set = newValue.set || value.set;
|
|
166
|
+
value = {
|
|
167
|
+
get: get,
|
|
168
|
+
set: set
|
|
169
|
+
};
|
|
170
|
+
} else {
|
|
171
|
+
value = newValue;
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
} else {
|
|
175
|
+
for(var i = decs.length - 1; i >= 0; i--){
|
|
176
|
+
var dec = decs[i];
|
|
177
|
+
newValue = memberDec(dec, name, desc, initializers, kind, isStatic, isPrivate, metadata, value);
|
|
178
|
+
if (newValue !== void 0) {
|
|
179
|
+
assertValidReturnValue(kind, newValue);
|
|
180
|
+
var newInit;
|
|
181
|
+
if (kind === 0) {
|
|
182
|
+
newInit = newValue;
|
|
183
|
+
} else if (kind === 1) {
|
|
184
|
+
newInit = newValue.init;
|
|
185
|
+
get = newValue.get || value.get;
|
|
186
|
+
set = newValue.set || value.set;
|
|
187
|
+
value = {
|
|
188
|
+
get: get,
|
|
189
|
+
set: set
|
|
190
|
+
};
|
|
191
|
+
} else {
|
|
192
|
+
value = newValue;
|
|
193
|
+
}
|
|
194
|
+
if (newInit !== void 0) {
|
|
195
|
+
if (init === void 0) {
|
|
196
|
+
init = newInit;
|
|
197
|
+
} else if (typeof init === "function") {
|
|
198
|
+
init = [
|
|
199
|
+
init,
|
|
200
|
+
newInit
|
|
201
|
+
];
|
|
202
|
+
} else {
|
|
203
|
+
init.push(newInit);
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
if (kind === 0 || kind === 1) {
|
|
210
|
+
if (init === void 0) {
|
|
211
|
+
init = function(instance, init) {
|
|
212
|
+
return init;
|
|
213
|
+
};
|
|
214
|
+
} else if (typeof init !== "function") {
|
|
215
|
+
var ownInitializers = init;
|
|
216
|
+
init = function(instance, init) {
|
|
217
|
+
var value = init;
|
|
218
|
+
for(var i = 0; i < ownInitializers.length; i++){
|
|
219
|
+
value = ownInitializers[i].call(instance, value);
|
|
220
|
+
}
|
|
221
|
+
return value;
|
|
222
|
+
};
|
|
223
|
+
} else {
|
|
224
|
+
var originalInitializer = init;
|
|
225
|
+
init = function(instance, init) {
|
|
226
|
+
return originalInitializer.call(instance, init);
|
|
227
|
+
};
|
|
228
|
+
}
|
|
229
|
+
ret.push(init);
|
|
230
|
+
}
|
|
231
|
+
if (kind !== 0) {
|
|
232
|
+
if (kind === 1) {
|
|
233
|
+
desc.get = value.get;
|
|
234
|
+
desc.set = value.set;
|
|
235
|
+
} else if (kind === 2) {
|
|
236
|
+
desc.value = value;
|
|
237
|
+
} else if (kind === 3) {
|
|
238
|
+
desc.get = value;
|
|
239
|
+
} else if (kind === 4) {
|
|
240
|
+
desc.set = value;
|
|
241
|
+
}
|
|
242
|
+
if (isPrivate) {
|
|
243
|
+
if (kind === 1) {
|
|
244
|
+
ret.push(function(instance, args) {
|
|
245
|
+
return value.get.call(instance, args);
|
|
246
|
+
});
|
|
247
|
+
ret.push(function(instance, args) {
|
|
248
|
+
return value.set.call(instance, args);
|
|
249
|
+
});
|
|
250
|
+
} else if (kind === 2) {
|
|
251
|
+
ret.push(value);
|
|
252
|
+
} else {
|
|
253
|
+
ret.push(function(instance, args) {
|
|
254
|
+
return value.call(instance, args);
|
|
255
|
+
});
|
|
256
|
+
}
|
|
257
|
+
} else {
|
|
258
|
+
Object.defineProperty(base, name, desc);
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
function applyMemberDecs(Class, decInfos, metadata) {
|
|
263
|
+
var ret = [];
|
|
264
|
+
var protoInitializers;
|
|
265
|
+
var staticInitializers;
|
|
266
|
+
var existingProtoNonFields = new Map();
|
|
267
|
+
var existingStaticNonFields = new Map();
|
|
268
|
+
for(var i = 0; i < decInfos.length; i++){
|
|
269
|
+
var decInfo = decInfos[i];
|
|
270
|
+
if (!Array.isArray(decInfo)) continue;
|
|
271
|
+
var kind = decInfo[1];
|
|
272
|
+
var name = decInfo[2];
|
|
273
|
+
var isPrivate = decInfo.length > 3;
|
|
274
|
+
var isStatic = kind >= 5;
|
|
275
|
+
var base;
|
|
276
|
+
var initializers;
|
|
277
|
+
if (isStatic) {
|
|
278
|
+
base = Class;
|
|
279
|
+
kind = kind - 5;
|
|
280
|
+
staticInitializers = staticInitializers || [];
|
|
281
|
+
initializers = staticInitializers;
|
|
282
|
+
} else {
|
|
283
|
+
base = Class.prototype;
|
|
284
|
+
protoInitializers = protoInitializers || [];
|
|
285
|
+
initializers = protoInitializers;
|
|
286
|
+
}
|
|
287
|
+
if (kind !== 0 && !isPrivate) {
|
|
288
|
+
var existingNonFields = isStatic ? existingStaticNonFields : existingProtoNonFields;
|
|
289
|
+
var existingKind = existingNonFields.get(name) || 0;
|
|
290
|
+
if (existingKind === true || existingKind === 3 && kind !== 4 || existingKind === 4 && kind !== 3) {
|
|
291
|
+
throw new Error("Attempted to decorate a public method/accessor that has the same name as a previously decorated public method/accessor. This is not currently supported by the decorators plugin. Property name was: " + name);
|
|
292
|
+
} else if (!existingKind && kind > 2) {
|
|
293
|
+
existingNonFields.set(name, kind);
|
|
294
|
+
} else {
|
|
295
|
+
existingNonFields.set(name, true);
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
applyMemberDec(ret, base, decInfo, name, kind, isStatic, isPrivate, initializers, metadata);
|
|
299
|
+
}
|
|
300
|
+
pushInitializers(ret, protoInitializers);
|
|
301
|
+
pushInitializers(ret, staticInitializers);
|
|
302
|
+
return ret;
|
|
303
|
+
}
|
|
304
|
+
function pushInitializers(ret, initializers) {
|
|
305
|
+
if (initializers) {
|
|
306
|
+
ret.push(function(instance) {
|
|
307
|
+
for(var i = 0; i < initializers.length; i++){
|
|
308
|
+
initializers[i].call(instance);
|
|
309
|
+
}
|
|
310
|
+
return instance;
|
|
311
|
+
});
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
function applyClassDecs(targetClass, classDecs, metadata) {
|
|
315
|
+
if (classDecs.length > 0) {
|
|
316
|
+
var initializers = [];
|
|
317
|
+
var newClass = targetClass;
|
|
318
|
+
var name = targetClass.name;
|
|
319
|
+
for(var i = classDecs.length - 1; i >= 0; i--){
|
|
320
|
+
var decoratorFinishedRef = {
|
|
321
|
+
v: false
|
|
322
|
+
};
|
|
323
|
+
try {
|
|
324
|
+
var nextNewClass = classDecs[i](newClass, {
|
|
325
|
+
kind: "class",
|
|
326
|
+
name: name,
|
|
327
|
+
addInitializer: createAddInitializerMethod(initializers, decoratorFinishedRef),
|
|
328
|
+
metadata
|
|
329
|
+
});
|
|
330
|
+
} finally{
|
|
331
|
+
decoratorFinishedRef.v = true;
|
|
332
|
+
}
|
|
333
|
+
if (nextNewClass !== undefined) {
|
|
334
|
+
assertValidReturnValue(10, nextNewClass);
|
|
335
|
+
newClass = nextNewClass;
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
return [
|
|
339
|
+
defineMetadata(newClass, metadata),
|
|
340
|
+
function() {
|
|
341
|
+
for(var i = 0; i < initializers.length; i++){
|
|
342
|
+
initializers[i].call(newClass);
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
];
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
function defineMetadata(Class, metadata) {
|
|
349
|
+
return Object.defineProperty(Class, Symbol.metadata || Symbol.for("Symbol.metadata"), {
|
|
350
|
+
configurable: true,
|
|
351
|
+
enumerable: true,
|
|
352
|
+
value: metadata
|
|
353
|
+
});
|
|
354
|
+
}
|
|
355
|
+
return function applyDecs2203R(targetClass, memberDecs, classDecs, parentClass) {
|
|
356
|
+
if (parentClass !== void 0) {
|
|
357
|
+
var parentMetadata = parentClass[Symbol.metadata || Symbol.for("Symbol.metadata")];
|
|
358
|
+
}
|
|
359
|
+
var metadata = Object.create(parentMetadata === void 0 ? null : parentMetadata);
|
|
360
|
+
var e = applyMemberDecs(targetClass, memberDecs, metadata);
|
|
361
|
+
if (!classDecs.length) defineMetadata(targetClass, metadata);
|
|
362
|
+
return {
|
|
363
|
+
e: e,
|
|
364
|
+
get c () {
|
|
365
|
+
return applyClassDecs(targetClass, classDecs, metadata);
|
|
366
|
+
}
|
|
367
|
+
};
|
|
368
|
+
};
|
|
6
369
|
}
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
import {
|
|
370
|
+
function _apply_decs_2203_r(targetClass, memberDecs, classDecs, parentClass) {
|
|
371
|
+
return (_apply_decs_2203_r = applyDecs2203RFactory())(targetClass, memberDecs, classDecs, parentClass);
|
|
372
|
+
}
|
|
373
|
+
var _dec, _dec1, _dec2, _dec3, _initProto;
|
|
374
|
+
import { getKzg } from '@aztec/blob-lib';
|
|
375
|
+
import { PROPOSER_PIPELINING_SLOT_OFFSET } from '@aztec/epoch-cache';
|
|
376
|
+
import { NoCommitteeError } from '@aztec/ethereum/contracts';
|
|
377
|
+
import { CheckpointNumber, SlotNumber } from '@aztec/foundation/branded-types';
|
|
378
|
+
import { merge, omit, pick } from '@aztec/foundation/collection';
|
|
12
379
|
import { EthAddress } from '@aztec/foundation/eth-address';
|
|
13
|
-
import { Signature } from '@aztec/foundation/eth-signature';
|
|
14
|
-
import { Fr } from '@aztec/foundation/fields';
|
|
15
380
|
import { createLogger } from '@aztec/foundation/log';
|
|
16
381
|
import { RunningPromise } from '@aztec/foundation/running-promise';
|
|
17
|
-
import {
|
|
18
|
-
import {
|
|
19
|
-
import {
|
|
20
|
-
import { getSlotAtTimestamp, getSlotStartBuildTimestamp } from '@aztec/stdlib/epoch-helpers';
|
|
21
|
-
import { Gas } from '@aztec/stdlib/gas';
|
|
382
|
+
import { buildCheckpointSimulationOverridesPlan } from '@aztec/stdlib/checkpoint';
|
|
383
|
+
import { getEpochAtSlot } from '@aztec/stdlib/epoch-helpers';
|
|
384
|
+
import { MIN_PER_BLOCK_ALLOCATION_MULTIPLIER, MIN_PER_BLOCK_DA_ALLOCATION_MULTIPLIER, computeNetworkTxGasLimits } from '@aztec/stdlib/gas';
|
|
22
385
|
import { SequencerConfigSchema } from '@aztec/stdlib/interfaces/server';
|
|
23
|
-
import { orderAttestations } from '@aztec/stdlib/p2p';
|
|
24
|
-
import { CheckpointHeader } from '@aztec/stdlib/rollup';
|
|
25
386
|
import { pickFromSchema } from '@aztec/stdlib/schemas';
|
|
26
|
-
import {
|
|
27
|
-
import { ContentCommitment } from '@aztec/stdlib/tx';
|
|
28
|
-
import { AttestationTimeoutError } from '@aztec/stdlib/validators';
|
|
387
|
+
import { buildProposerTimetable } from '@aztec/stdlib/timetable';
|
|
29
388
|
import { Attributes, getTelemetryClient, trackSpan } from '@aztec/telemetry-client';
|
|
30
389
|
import EventEmitter from 'node:events';
|
|
31
|
-
import {
|
|
390
|
+
import { DefaultSequencerConfig } from '../config.js';
|
|
391
|
+
import { CheckpointProposalJob } from './checkpoint_proposal_job.js';
|
|
392
|
+
import { CheckpointProposalJobMetrics } from './checkpoint_proposal_job_metrics.js';
|
|
393
|
+
import { CheckpointVoter } from './checkpoint_voter.js';
|
|
394
|
+
import { SequencerInterruptedError } from './errors.js';
|
|
32
395
|
import { SequencerMetrics } from './metrics.js';
|
|
33
|
-
import {
|
|
396
|
+
import { RequestsTracker } from './requests_tracker.js';
|
|
34
397
|
import { SequencerState } from './utils.js';
|
|
35
398
|
export { SequencerState };
|
|
399
|
+
_dec = trackSpan('Sequencer.work'), _dec1 = trackSpan('Sequencer.prepareCheckpointProposal'), _dec2 = trackSpan('Sequencer.tryVoteAndPruneWhenCannotBuild', ({ slot })=>({
|
|
400
|
+
[Attributes.SLOT_NUMBER]: slot
|
|
401
|
+
})), _dec3 = trackSpan('Sequencer.tryVoteWhenEscapeHatchOpen', ({ slot })=>({
|
|
402
|
+
[Attributes.SLOT_NUMBER]: slot
|
|
403
|
+
}));
|
|
36
404
|
/**
|
|
37
405
|
* Sequencer client
|
|
38
|
-
* -
|
|
39
|
-
* -
|
|
40
|
-
* -
|
|
41
|
-
* -
|
|
42
|
-
* -
|
|
43
|
-
* - Publishes L1 tx(s) to the rollup contract via RollupPublisher.
|
|
406
|
+
* - Checks whether it is elected as proposer for the next slot
|
|
407
|
+
* - Builds multiple blocks and broadcasts them
|
|
408
|
+
* - Collects attestations for the checkpoint
|
|
409
|
+
* - Publishes the checkpoint to L1
|
|
410
|
+
* - Votes for proposals and slashes on L1
|
|
44
411
|
*/ export class Sequencer extends EventEmitter {
|
|
45
412
|
publisherFactory;
|
|
46
413
|
validatorClient;
|
|
@@ -50,390 +417,587 @@ export { SequencerState };
|
|
|
50
417
|
slasherClient;
|
|
51
418
|
l2BlockSource;
|
|
52
419
|
l1ToL2MessageSource;
|
|
53
|
-
|
|
420
|
+
checkpointsBuilder;
|
|
54
421
|
l1Constants;
|
|
55
422
|
dateProvider;
|
|
56
423
|
epochCache;
|
|
57
424
|
rollupContract;
|
|
58
|
-
config;
|
|
59
425
|
telemetry;
|
|
60
426
|
log;
|
|
427
|
+
static{
|
|
428
|
+
({ e: [_initProto] } = _apply_decs_2203_r(this, [
|
|
429
|
+
[
|
|
430
|
+
_dec,
|
|
431
|
+
2,
|
|
432
|
+
"work"
|
|
433
|
+
],
|
|
434
|
+
[
|
|
435
|
+
_dec1,
|
|
436
|
+
2,
|
|
437
|
+
"prepareCheckpointProposal"
|
|
438
|
+
],
|
|
439
|
+
[
|
|
440
|
+
_dec2,
|
|
441
|
+
2,
|
|
442
|
+
"tryVoteAndPruneWhenCannotBuild"
|
|
443
|
+
],
|
|
444
|
+
[
|
|
445
|
+
_dec3,
|
|
446
|
+
2,
|
|
447
|
+
"tryVoteWhenEscapeHatchOpen"
|
|
448
|
+
]
|
|
449
|
+
], []));
|
|
450
|
+
}
|
|
61
451
|
runningPromise;
|
|
62
|
-
pollingIntervalMs;
|
|
63
|
-
maxTxsPerBlock;
|
|
64
|
-
minTxsPerBlock;
|
|
65
|
-
maxL1TxInclusionTimeIntoSlot;
|
|
66
452
|
state;
|
|
67
|
-
|
|
68
|
-
|
|
453
|
+
stateSlotNumber;
|
|
454
|
+
/** Wall-clock time (ms, via the date provider) at which the current state was entered. */ stateEnteredAtMs;
|
|
69
455
|
metrics;
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
/** The last slot for which we attempted to
|
|
73
|
-
/** The
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
456
|
+
checkpointProposalJobMetrics;
|
|
457
|
+
stateLog;
|
|
458
|
+
/** The last slot for which we attempted to perform our fallback duties (votes and/or prune) with degraded block production */ lastSlotForFallbackAction;
|
|
459
|
+
/** The (checkpoint, slot) of the last invalidation request we successfully simulated, to prevent
|
|
460
|
+
* re-simulating and re-submitting the same invalidation across the many ticks within a single slot. */ lastInvalidationAttempt;
|
|
461
|
+
/** The last slot for which we logged "no committee" warning, to avoid spam */ lastSlotForNoCommitteeWarning;
|
|
462
|
+
/** The last slot for which we triggered a checkpoint proposal job, to prevent duplicate attempts. */ lastSlotForCheckpointProposalJob;
|
|
463
|
+
/** Last successful checkpoint proposed */ lastCheckpointProposed;
|
|
464
|
+
/** The last epoch for which we logged strategy comparison in fisherman mode. */ lastEpochForStrategyComparison;
|
|
465
|
+
/** The last checkpoint proposal job, tracked so we can await its pending L1 submission during shutdown. */ lastCheckpointProposalJob;
|
|
466
|
+
/**
|
|
467
|
+
* In-flight fire-and-forget requests that {@link stop} interrupts and drains, and {@link pause} awaits
|
|
468
|
+
* untouched: the checkpoint proposal jobs' backgrounded L1 submissions (each job is handed this shared
|
|
469
|
+
* tracker) plus the sequencer's own fallback submissions (votes/prune when we cannot build, or
|
|
470
|
+
* escape-hatch votes). Each fallback send is gated by its wrapper publisher's interruptible target-slot
|
|
471
|
+
* sleep; the tracked interrupt wakes that sleep so the send short-circuits without publishing. A wrapper
|
|
472
|
+
* is created for a single send and is never restarted, so once interrupted its sleeper can never publish
|
|
473
|
+
* a stale-slot tx, even after the pooled publishers are restarted by a later {@link start}.
|
|
474
|
+
*/ pendingRequests;
|
|
475
|
+
/** Proposer schedule and block sub-slot timetable for the sequencer, rebuilt on every config update. */ timetable;
|
|
476
|
+
/** Config for the sequencer */ config;
|
|
477
|
+
signatureContext;
|
|
478
|
+
constructor(publisherFactory, validatorClient, globalsBuilder, p2pClient, worldState, slasherClient, l2BlockSource, l1ToL2MessageSource, checkpointsBuilder, l1Constants, dateProvider, epochCache, rollupContract, config, telemetry = getTelemetryClient(), log = createLogger('sequencer')){
|
|
479
|
+
super(), this.publisherFactory = publisherFactory, this.validatorClient = validatorClient, this.globalsBuilder = globalsBuilder, this.p2pClient = p2pClient, this.worldState = worldState, this.slasherClient = slasherClient, this.l2BlockSource = l2BlockSource, this.l1ToL2MessageSource = l1ToL2MessageSource, this.checkpointsBuilder = checkpointsBuilder, this.l1Constants = l1Constants, this.dateProvider = dateProvider, this.epochCache = epochCache, this.rollupContract = rollupContract, this.telemetry = telemetry, this.log = log, this.state = (_initProto(this), SequencerState.STOPPED), this.pendingRequests = new RequestsTracker(), this.config = DefaultSequencerConfig;
|
|
480
|
+
this.stateLog = log.createChild('state');
|
|
481
|
+
this.stateEnteredAtMs = this.dateProvider.now();
|
|
84
482
|
// Add [FISHERMAN] prefix to logger if in fisherman mode
|
|
85
|
-
if (
|
|
483
|
+
if (config.fishermanMode) {
|
|
86
484
|
this.log = log.createChild('[FISHERMAN]');
|
|
87
485
|
}
|
|
486
|
+
this.signatureContext = {
|
|
487
|
+
chainId: config.l1ChainId,
|
|
488
|
+
rollupAddress: config.rollupAddress
|
|
489
|
+
};
|
|
88
490
|
this.metrics = new SequencerMetrics(telemetry, this.rollupContract, 'Sequencer');
|
|
89
|
-
|
|
90
|
-
this.updateConfig(
|
|
91
|
-
}
|
|
92
|
-
get tracer() {
|
|
93
|
-
return this.metrics.tracer;
|
|
94
|
-
}
|
|
95
|
-
getValidatorAddresses() {
|
|
96
|
-
return this.validatorClient?.getValidatorAddresses();
|
|
97
|
-
}
|
|
98
|
-
getConfig() {
|
|
99
|
-
return this.config;
|
|
491
|
+
this.checkpointProposalJobMetrics = new CheckpointProposalJobMetrics(telemetry);
|
|
492
|
+
this.updateConfig(config);
|
|
100
493
|
}
|
|
101
494
|
/**
|
|
102
|
-
* Updates sequencer config by the defined values
|
|
103
|
-
*
|
|
495
|
+
* Updates sequencer config by the defined values and rebuilds the timetable.
|
|
496
|
+
*
|
|
497
|
+
* The merged config is validated against a candidate before being committed: {@link buildTimetable} may
|
|
498
|
+
* reject the candidate (invalid timing geometry, or per-block allocation multipliers below the network
|
|
499
|
+
* minimums). On rejection we leave `this.config` and `this.timetable` untouched and rethrow, so a bad update
|
|
500
|
+
* never leaves the sequencer running with a rejected config and a stale timetable.
|
|
104
501
|
*/ updateConfig(config) {
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
if (config.maxDABlockGas !== undefined) {
|
|
116
|
-
this.maxBlockGas = new Gas(config.maxDABlockGas, this.maxBlockGas.l2Gas);
|
|
117
|
-
}
|
|
118
|
-
if (config.maxL2BlockGas !== undefined) {
|
|
119
|
-
this.maxBlockGas = new Gas(this.maxBlockGas.daGas, config.maxL2BlockGas);
|
|
502
|
+
const filteredConfig = pickFromSchema(config, SequencerConfigSchema);
|
|
503
|
+
const candidate = merge(this.config, filteredConfig);
|
|
504
|
+
let timetable;
|
|
505
|
+
try {
|
|
506
|
+
timetable = this.buildTimetable(candidate);
|
|
507
|
+
} catch (err) {
|
|
508
|
+
this.log.warn(`Rejecting sequencer config update: ${err.message}`, {
|
|
509
|
+
rejectedConfig: omit(filteredConfig, 'txPublicSetupAllowListExtend')
|
|
510
|
+
});
|
|
511
|
+
throw err;
|
|
120
512
|
}
|
|
121
|
-
|
|
122
|
-
|
|
513
|
+
this.config = candidate;
|
|
514
|
+
this.timetable = timetable;
|
|
515
|
+
this.log.info(`Updated sequencer config`, omit(filteredConfig, 'txPublicSetupAllowListExtend'));
|
|
516
|
+
}
|
|
517
|
+
/**
|
|
518
|
+
* Builds the proposer timetable from the given config and L1 constants via the shared
|
|
519
|
+
* {@link buildProposerTimetable} helper, so the sequencer derives the same blocks-per-checkpoint as the p2p
|
|
520
|
+
* layer and `getNodeInfo`. The fast local/e2e profile and budget clamping happen inside
|
|
521
|
+
* {@link ProposerTimetable}.
|
|
522
|
+
*
|
|
523
|
+
* Throws if the timing geometry is invalid or the per-block allocation multipliers are below the network
|
|
524
|
+
* minimums; callers must treat a throw as a rejected config and not commit it.
|
|
525
|
+
*/ buildTimetable(config) {
|
|
526
|
+
const timetable = buildProposerTimetable(config, this.l1Constants);
|
|
527
|
+
const maxNumberOfBlocks = timetable.getMaxBlocksPerCheckpoint();
|
|
528
|
+
this.log.info(`Sequencer timetable initialized with ${maxNumberOfBlocks} blocks per slot`, {
|
|
529
|
+
aztecSlotDuration: timetable.aztecSlotDuration,
|
|
530
|
+
ethereumSlotDuration: timetable.ethereumSlotDuration,
|
|
531
|
+
blockDuration: timetable.blockDuration,
|
|
532
|
+
minBlockDuration: timetable.minBlockDuration,
|
|
533
|
+
p2pPropagationTime: timetable.p2pPropagationTime,
|
|
534
|
+
checkpointProposalPrepareTime: timetable.checkpointProposalPrepareTime,
|
|
535
|
+
maxNumberOfBlocks
|
|
536
|
+
});
|
|
537
|
+
this.assertConfigMeetsNetworkTxLimits(config, maxNumberOfBlocks);
|
|
538
|
+
return timetable;
|
|
539
|
+
}
|
|
540
|
+
/**
|
|
541
|
+
* Checks this node's configured per-block allocation against the network admission limit. A node
|
|
542
|
+
* advertises and admits txs up to the limit derived from the network-minimum multipliers (see
|
|
543
|
+
* {@link computeNetworkTxGasLimits}).
|
|
544
|
+
*
|
|
545
|
+
* Fails startup (and runtime config updates) only when the configured per-block allocation *multipliers*
|
|
546
|
+
* (`perBlockAllocationMultiplier` / `perBlockDAAllocationMultiplier`) are below the network minimums: such
|
|
547
|
+
* a node would accept txs over RPC/gossip that its builder can never pack into a block regardless of block
|
|
548
|
+
* size. Operators may configure a higher (more generous) multiplier, but not a lower one.
|
|
549
|
+
*
|
|
550
|
+
* When the multipliers meet the floor but an absolute per-block gas cap (`maxDABlockGas` / `maxL2BlockGas`)
|
|
551
|
+
* shrinks the builder's effective grant below the network limit, this is legitimate operator
|
|
552
|
+
* restrictiveness — the node simply builds smaller blocks and such txs stay in the pool for other
|
|
553
|
+
* proposers — so we only log a warning rather than failing startup. Restrictive tx-count caps
|
|
554
|
+
* (`maxTxsPerBlock` / `maxTxsPerCheckpoint`) can likewise make the builder skip admitted txs; they are
|
|
555
|
+
* intentionally not modeled here for the same reason.
|
|
556
|
+
*/ assertConfigMeetsNetworkTxLimits(config, maxBlocksPerCheckpoint) {
|
|
557
|
+
// Mirror CheckpointBuilder.capLimitsByCheckpointBudgets: DA falls back to the general multiplier.
|
|
558
|
+
const l2Multiplier = config.perBlockAllocationMultiplier;
|
|
559
|
+
const daMultiplier = config.perBlockDAAllocationMultiplier ?? l2Multiplier;
|
|
560
|
+
// The allocation is monotonic in the multiplier, so a multiplier at or above the network minimum
|
|
561
|
+
// guarantees the builder grants at least the network admission limit. Checking the multipliers directly
|
|
562
|
+
// is sufficient (and strictly more conservative than modeling the resulting gas grant).
|
|
563
|
+
if (daMultiplier < MIN_PER_BLOCK_DA_ALLOCATION_MULTIPLIER) {
|
|
564
|
+
throw new Error(`perBlockDAAllocationMultiplier (${daMultiplier}) is below the network minimum ` + `${MIN_PER_BLOCK_DA_ALLOCATION_MULTIPLIER}; the node would admit txs its own builder can never include.`);
|
|
123
565
|
}
|
|
124
|
-
if (
|
|
125
|
-
|
|
566
|
+
if (l2Multiplier < MIN_PER_BLOCK_ALLOCATION_MULTIPLIER) {
|
|
567
|
+
throw new Error(`perBlockAllocationMultiplier (${l2Multiplier}) is below the network minimum ` + `${MIN_PER_BLOCK_ALLOCATION_MULTIPLIER}; the node would admit txs its own builder can never include.`);
|
|
126
568
|
}
|
|
127
|
-
|
|
128
|
-
|
|
569
|
+
// Absolute per-block gas caps below the network admission limit are legitimate operator restrictiveness:
|
|
570
|
+
// the node simply builds smaller blocks and such txs stay in the pool for other proposers. Warn only.
|
|
571
|
+
const networkLimit = computeNetworkTxGasLimits({
|
|
572
|
+
maxBlocksPerCheckpoint,
|
|
573
|
+
manaCheckpointBudget: this.l1Constants.rollupManaLimit
|
|
574
|
+
});
|
|
575
|
+
if (config.maxDABlockGas !== undefined && config.maxDABlockGas < networkLimit.daGas) {
|
|
576
|
+
this.log.warn(`Sequencer maxDABlockGas (${config.maxDABlockGas}) is below the network DA admission limit ` + `(${networkLimit.daGas}): txs declaring more DA gas are admitted over RPC/gossip but will be skipped ` + `by this proposer's own blocks and left in the pool for other proposers.`, {
|
|
577
|
+
maxDABlockGas: config.maxDABlockGas,
|
|
578
|
+
networkDaGas: networkLimit.daGas,
|
|
579
|
+
maxBlocksPerCheckpoint
|
|
580
|
+
});
|
|
129
581
|
}
|
|
130
|
-
if (config.
|
|
131
|
-
this.
|
|
582
|
+
if (config.maxL2BlockGas !== undefined && config.maxL2BlockGas < networkLimit.l2Gas) {
|
|
583
|
+
this.log.warn(`Sequencer maxL2BlockGas (${config.maxL2BlockGas}) is below the network L2 admission limit ` + `(${networkLimit.l2Gas}): txs declaring more L2 gas are admitted over RPC/gossip but will be skipped ` + `by this proposer's own blocks and left in the pool for other proposers.`, {
|
|
584
|
+
maxL2BlockGas: config.maxL2BlockGas,
|
|
585
|
+
networkL2Gas: networkLimit.l2Gas,
|
|
586
|
+
maxBlocksPerCheckpoint
|
|
587
|
+
});
|
|
132
588
|
}
|
|
133
|
-
this.setTimeTable();
|
|
134
|
-
// TODO: Just read everything from the config object as needed instead of copying everything into local vars.
|
|
135
|
-
// Update all values on this.config that are populated in the config object.
|
|
136
|
-
Object.assign(this.config, config);
|
|
137
589
|
}
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
ethereumSlotDuration: this.l1Constants.ethereumSlotDuration,
|
|
141
|
-
aztecSlotDuration: this.aztecSlotDuration,
|
|
142
|
-
maxL1TxInclusionTimeIntoSlot: this.maxL1TxInclusionTimeIntoSlot,
|
|
143
|
-
attestationPropagationTime: this.config.attestationPropagationTime,
|
|
144
|
-
enforce: this.enforceTimeTable
|
|
145
|
-
}, this.metrics, this.log);
|
|
146
|
-
}
|
|
147
|
-
async init() {
|
|
148
|
-
this.publisher = (await this.publisherFactory.create(undefined)).publisher;
|
|
590
|
+
/** Initializes the sequencer (precomputes tables). Takes about 3s. */ init() {
|
|
591
|
+
getKzg();
|
|
149
592
|
}
|
|
150
593
|
/**
|
|
151
|
-
* Starts the sequencer and moves to IDLE state.
|
|
594
|
+
* Starts (or restarts) the sequencer and moves it to the IDLE state. Idempotent: a start while already
|
|
595
|
+
* running is a no-op, so it never orphans the previous poll loop. A start while STOPPING throws, since the
|
|
596
|
+
* in-flight stop would mark the fresh loop's state STOPPED and orphan it — silently doing nothing would
|
|
597
|
+
* leave the caller believing the sequencer is running when it is on its way to STOPPED. Safe to call after
|
|
598
|
+
* a previous {@link stop} has resolved; the caller must also restart the publishers (see
|
|
599
|
+
* {@link SequencerClient.start}) so L1 publishing is re-enabled.
|
|
152
600
|
*/ start() {
|
|
153
|
-
|
|
601
|
+
if (this.state === SequencerState.STOPPING) {
|
|
602
|
+
throw new Error('Cannot start sequencer while it is stopping');
|
|
603
|
+
}
|
|
604
|
+
if (this.runningPromise?.isRunning()) {
|
|
605
|
+
this.log.warn('Attempted to start sequencer that is already running');
|
|
606
|
+
return;
|
|
607
|
+
}
|
|
608
|
+
this.runningPromise = new RunningPromise(this.safeWork.bind(this), this.log, this.config.sequencerPollingIntervalMS);
|
|
154
609
|
this.setState(SequencerState.IDLE, undefined, {
|
|
155
610
|
force: true
|
|
156
611
|
});
|
|
157
612
|
this.runningPromise.start();
|
|
158
613
|
this.log.info('Started sequencer');
|
|
159
614
|
}
|
|
615
|
+
/** Triggers an immediate run of the sequencer, bypassing the polling interval. */ trigger() {
|
|
616
|
+
return this.runningPromise?.trigger();
|
|
617
|
+
}
|
|
160
618
|
/**
|
|
161
|
-
* Stops the sequencer from
|
|
619
|
+
* Stops the sequencer from building blocks and moves it to STOPPED state, interrupting the in-flight
|
|
620
|
+
* work() iteration and its pending L1 submissions for a fast shutdown, then draining before returning.
|
|
621
|
+
* Idempotent: a second call while already stopped or stopping is a no-op. Lifecycle calls are expected
|
|
622
|
+
* to be serialized by the caller. For a restartable pause that lets in-flight work finish untouched
|
|
623
|
+
* (e.g. around a test clock warp), use {@link pause} instead.
|
|
162
624
|
*/ async stop() {
|
|
625
|
+
if (this.state === SequencerState.STOPPED || this.state === SequencerState.STOPPING) {
|
|
626
|
+
this.log.debug(`Sequencer already ${this.state.toLowerCase()}, ignoring stop`);
|
|
627
|
+
return;
|
|
628
|
+
}
|
|
163
629
|
this.log.info(`Stopping sequencer`);
|
|
164
630
|
this.setState(SequencerState.STOPPING, undefined, {
|
|
165
631
|
force: true
|
|
166
632
|
});
|
|
167
|
-
this.
|
|
633
|
+
this.lastCheckpointProposalJob?.interrupt();
|
|
634
|
+
await this.publisherFactory.stopAll();
|
|
635
|
+
// Stop the poll loop and await the in-flight work() iteration. work() registers its fire-and-forget
|
|
636
|
+
// requests synchronously before returning, so once the loop has stopped, pendingRequests holds every
|
|
637
|
+
// request that will ever exist. Interrupting any earlier could miss a request registered by the last
|
|
638
|
+
// in-flight iteration.
|
|
168
639
|
await this.runningPromise?.stop();
|
|
640
|
+
this.pendingRequests.interruptRequests();
|
|
641
|
+
await this.pendingRequests.awaitRequests();
|
|
169
642
|
this.setState(SequencerState.STOPPED, undefined, {
|
|
170
643
|
force: true
|
|
171
644
|
});
|
|
172
645
|
this.log.info('Stopped sequencer');
|
|
173
646
|
}
|
|
174
647
|
/**
|
|
175
|
-
*
|
|
176
|
-
*
|
|
177
|
-
|
|
648
|
+
* Gracefully pauses block production so the sequencer can later be resumed with {@link start}: halts the
|
|
649
|
+
* poll loop and waits for the in-flight work() iteration and every pending L1 submission / fallback send
|
|
650
|
+
* to finish, without interrupting them. No interrupt lands mid-build, so no spurious checkpoint-error is
|
|
651
|
+
* emitted and no enqueued checkpoint is dropped. Deliberately does not stop inner services (validator/HA
|
|
652
|
+
* signer, publishers), so the slashing-protection store stays open and the sequencer stays restartable.
|
|
653
|
+
* Used by tests that pause sequencers around an L1 clock warp. Idempotent.
|
|
654
|
+
*/ async pause() {
|
|
655
|
+
if (!this.runningPromise?.isRunning()) {
|
|
656
|
+
this.log.debug('Sequencer not running, ignoring pause');
|
|
657
|
+
return;
|
|
658
|
+
}
|
|
659
|
+
this.log.info('Pausing sequencer');
|
|
660
|
+
// Halt the poll loop and let the in-flight iteration finish naturally — no interrupt, and no STOPPING
|
|
661
|
+
// state, since entering STOPPING would make the iteration's own setState calls throw and fail it.
|
|
662
|
+
// work() registers its fire-and-forget requests synchronously before returning, so once the loop has
|
|
663
|
+
// stopped pendingRequests holds every request that will ever exist; awaiting it lets them all finish.
|
|
664
|
+
await this.runningPromise.stop();
|
|
665
|
+
await this.pendingRequests.awaitRequests();
|
|
666
|
+
this.log.info('Paused sequencer');
|
|
667
|
+
}
|
|
668
|
+
/** Main sequencer loop with a try/catch */ async safeWork() {
|
|
669
|
+
try {
|
|
670
|
+
await this.work();
|
|
671
|
+
} catch (err) {
|
|
672
|
+
this.emit('checkpoint-error', {
|
|
673
|
+
error: err
|
|
674
|
+
});
|
|
675
|
+
throw err;
|
|
676
|
+
} finally{
|
|
677
|
+
this.setState(SequencerState.IDLE, undefined);
|
|
678
|
+
}
|
|
679
|
+
}
|
|
680
|
+
/** Returns the current state of the sequencer. */ status() {
|
|
178
681
|
return {
|
|
179
682
|
state: this.state
|
|
180
683
|
};
|
|
181
684
|
}
|
|
182
685
|
/**
|
|
183
|
-
*
|
|
184
|
-
*
|
|
185
|
-
*
|
|
186
|
-
*
|
|
187
|
-
*
|
|
188
|
-
*
|
|
686
|
+
* Main sequencer loop:
|
|
687
|
+
* - Checks if we are up to date
|
|
688
|
+
* - If we are and we are the sequencer, collect txs and build blocks
|
|
689
|
+
* - Build multiple blocks per slot when configured
|
|
690
|
+
* - Collect attestations for the final block
|
|
691
|
+
* - Submit checkpoint
|
|
189
692
|
*/ async work() {
|
|
190
693
|
this.setState(SequencerState.SYNCHRONIZING, undefined);
|
|
191
|
-
const { slot, ts,
|
|
192
|
-
// Check we
|
|
193
|
-
|
|
194
|
-
|
|
694
|
+
const { slot, targetSlot, epoch, targetEpoch, ts, nowSeconds } = this.getSlotContextInNextL1Slot();
|
|
695
|
+
// Check if we are synced and it's our slot, grab a publisher, check previous block invalidation, etc
|
|
696
|
+
const checkpointProposalJob = await this.prepareCheckpointProposal(slot, targetSlot, epoch, targetEpoch, ts, nowSeconds);
|
|
697
|
+
if (!checkpointProposalJob) {
|
|
195
698
|
return;
|
|
196
699
|
}
|
|
197
|
-
//
|
|
700
|
+
// Track the job so we can await its pending L1 submission during shutdown
|
|
701
|
+
this.lastCheckpointProposalJob = checkpointProposalJob;
|
|
702
|
+
// Execute the checkpoint proposal job
|
|
703
|
+
const checkpoint = await checkpointProposalJob.execute();
|
|
704
|
+
// Update last checkpoint proposed (currently unused)
|
|
705
|
+
if (checkpoint) {
|
|
706
|
+
this.lastCheckpointProposed = checkpoint;
|
|
707
|
+
}
|
|
708
|
+
// Log fee strategy comparison if on fisherman (uses target epoch since we mirror the proposer's perspective)
|
|
709
|
+
if (this.config.fishermanMode && (this.lastEpochForStrategyComparison === undefined || targetEpoch > this.lastEpochForStrategyComparison)) {
|
|
710
|
+
this.logStrategyComparison(targetEpoch, checkpointProposalJob.getPublisher());
|
|
711
|
+
this.lastEpochForStrategyComparison = targetEpoch;
|
|
712
|
+
}
|
|
713
|
+
return checkpoint;
|
|
714
|
+
}
|
|
715
|
+
/** Returns slot and target slot from a single clock snapshot. */ getSlotContextInNextL1Slot() {
|
|
716
|
+
const { slot, ts, nowSeconds, epoch } = this.epochCache.getEpochAndSlotInNextL1Slot();
|
|
717
|
+
const targetSlot = SlotNumber(slot + PROPOSER_PIPELINING_SLOT_OFFSET);
|
|
718
|
+
return {
|
|
719
|
+
slot,
|
|
720
|
+
targetSlot,
|
|
721
|
+
epoch,
|
|
722
|
+
targetEpoch: getEpochAtSlot(targetSlot, this.l1Constants),
|
|
723
|
+
ts,
|
|
724
|
+
nowSeconds
|
|
725
|
+
};
|
|
726
|
+
}
|
|
727
|
+
/**
|
|
728
|
+
* Prepares the checkpoint proposal by performing all necessary checks and setup.
|
|
729
|
+
* This is the initial step in the main loop.
|
|
730
|
+
* @returns CheckpointProposalJob if successful, undefined if we are not yet synced or are not the proposer.
|
|
731
|
+
*/ async prepareCheckpointProposal(slot, targetSlot, epoch, targetEpoch, ts, nowSeconds) {
|
|
732
|
+
// Check we have not already processed this target slot (cheapest check).
|
|
733
|
+
if (this.lastSlotForCheckpointProposalJob && this.lastSlotForCheckpointProposalJob >= targetSlot) {
|
|
734
|
+
this.log.trace(`Target slot ${targetSlot} has already been processed`);
|
|
735
|
+
return undefined;
|
|
736
|
+
}
|
|
737
|
+
// But if we have already proposed for this slot, then we definitely have to skip it, automining or not
|
|
738
|
+
if (this.lastCheckpointProposed && this.lastCheckpointProposed.header.slotNumber >= targetSlot) {
|
|
739
|
+
this.log.trace(`Slot ${targetSlot} has already been published as checkpoint ${this.lastCheckpointProposed.number}`);
|
|
740
|
+
return undefined;
|
|
741
|
+
}
|
|
742
|
+
// Test-only: skip proposing for explicitly paused slots. Attestation paths run in the validator
|
|
743
|
+
// client and are not gated by this hook, so paused proposers still attest to others' proposals.
|
|
744
|
+
if (this.config.pauseProposingForSlots?.some((s)=>s === targetSlot)) {
|
|
745
|
+
this.log.warn(`Skipping proposal for paused slot ${targetSlot} (test-only pauseProposingForSlots hook)`, {
|
|
746
|
+
targetSlot
|
|
747
|
+
});
|
|
748
|
+
return undefined;
|
|
749
|
+
}
|
|
750
|
+
// Cheap proposer check first: most nodes are not the proposer for most slots, so gate the
|
|
751
|
+
// expensive multi-subsystem checkSync (and the rest of the build path) behind it. Computed once
|
|
752
|
+
// here and reused for the escape-hatch voting path below. No setState/timing gate on this path:
|
|
753
|
+
// the build-start deadline gate runs only on the proposer build path after a successful checkSync.
|
|
754
|
+
const [canPropose, proposer] = await this.checkCanPropose(targetSlot);
|
|
755
|
+
// If escape hatch is open for the target epoch, do not start checkpoint proposal work and do not attempt invalidations.
|
|
756
|
+
// Still perform governance/slashing voting (as proposer) once per slot.
|
|
757
|
+
// When pipelining, we check the target epoch (slot+1's epoch) since that's the epoch we're building for.
|
|
758
|
+
const isEscapeHatchOpen = await this.epochCache.isEscapeHatchOpen(targetEpoch);
|
|
759
|
+
if (isEscapeHatchOpen) {
|
|
760
|
+
if (canPropose) {
|
|
761
|
+
await this.tryVoteWhenEscapeHatchOpen({
|
|
762
|
+
slot,
|
|
763
|
+
targetSlot,
|
|
764
|
+
proposer
|
|
765
|
+
});
|
|
766
|
+
} else {
|
|
767
|
+
this.log.trace(`Escape hatch open but we are not proposer, skipping vote-only actions`, {
|
|
768
|
+
slot,
|
|
769
|
+
epoch,
|
|
770
|
+
proposer
|
|
771
|
+
});
|
|
772
|
+
}
|
|
773
|
+
return undefined;
|
|
774
|
+
}
|
|
775
|
+
// If we are not the proposer, check whether we should invalidate an invalid pending chain (a
|
|
776
|
+
// liveness backstop) and bail before any sync work or build-timing gate. This reads only the
|
|
777
|
+
// archiver's pending-chain validation status, which is authoritative on its own, instead of
|
|
778
|
+
// running the full sync check. Wrapped in try/catch because this leaner path skips the broader
|
|
779
|
+
// proposed-checkpoint/tip coherence screen that checkSync applied, so transient archiver
|
|
780
|
+
// incoherence surfaces as a quiet skip rather than a work-loop error.
|
|
781
|
+
if (!canPropose) {
|
|
782
|
+
try {
|
|
783
|
+
const pendingChainValidationStatus = await this.l2BlockSource.getPendingChainValidationStatus();
|
|
784
|
+
await this.considerInvalidatingCheckpoint(pendingChainValidationStatus, slot);
|
|
785
|
+
} catch (err) {
|
|
786
|
+
this.log.warn(`Failed to consider invalidating checkpoint`, {
|
|
787
|
+
err,
|
|
788
|
+
slot,
|
|
789
|
+
targetSlot
|
|
790
|
+
});
|
|
791
|
+
}
|
|
792
|
+
return undefined;
|
|
793
|
+
}
|
|
794
|
+
// Explicit build-loop entry gate: if we are past the latest useful block-building start for the
|
|
795
|
+
// target slot, abandon building for this slot. The proposer prioritizes the ideal L1-publish path
|
|
796
|
+
// and does not plan around the late consensus-handoff path. This is the proposer build path's
|
|
797
|
+
// timing gate; it runs only after we know we are the synced proposer, so non-proposer invalidation
|
|
798
|
+
// and escape-hatch voting (which returned above) are never gated by build timing. Vote-only paths
|
|
799
|
+
// still run when block building is abandoned.
|
|
800
|
+
const startDeadline = this.timetable.getBuildStartDeadline(targetSlot);
|
|
801
|
+
const nowForStartGate = this.dateProvider.now() / 1000;
|
|
802
|
+
if (nowForStartGate > startDeadline) {
|
|
803
|
+
this.log.debug(`Past start deadline for slot ${targetSlot}, abandoning block building`, {
|
|
804
|
+
targetSlot,
|
|
805
|
+
nowForStartGate,
|
|
806
|
+
startDeadline
|
|
807
|
+
});
|
|
808
|
+
// Mark the slot as attempted so a deadline abort is not retried within the same slot. Vote-only actions
|
|
809
|
+
// still need to run because sync can succeed even when it is too late to start building a checkpoint.
|
|
810
|
+
await this.tryVoteAndPruneWhenCannotBuild({
|
|
811
|
+
slot,
|
|
812
|
+
targetSlot
|
|
813
|
+
});
|
|
814
|
+
this.lastSlotForCheckpointProposalJob = targetSlot;
|
|
815
|
+
return undefined;
|
|
816
|
+
}
|
|
817
|
+
// We are the proposer, the escape hatch is closed, and we have time before the build start deadline.
|
|
818
|
+
// Now run the full sync check before building.
|
|
198
819
|
const syncedTo = await this.checkSync({
|
|
199
820
|
ts,
|
|
200
821
|
slot
|
|
201
822
|
});
|
|
202
823
|
if (!syncedTo) {
|
|
203
|
-
|
|
204
|
-
slot,
|
|
205
|
-
ts
|
|
206
|
-
});
|
|
207
|
-
return;
|
|
824
|
+
return undefined;
|
|
208
825
|
}
|
|
209
|
-
|
|
210
|
-
const
|
|
211
|
-
const
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
newBlockNumber,
|
|
826
|
+
// Next checkpoint follows from the last synced one
|
|
827
|
+
const checkpointNumber = CheckpointNumber(syncedTo.checkpointNumber + 1);
|
|
828
|
+
const logCtx = {
|
|
829
|
+
nowSeconds,
|
|
830
|
+
syncedToL2Slot: syncedTo.syncedL2Slot,
|
|
831
|
+
slot,
|
|
832
|
+
targetSlot,
|
|
833
|
+
slotTs: ts,
|
|
834
|
+
checkpointNumber,
|
|
219
835
|
isPendingChainValid: pick(syncedTo.pendingChainValidationStatus, 'valid', 'reason', 'invalidIndex')
|
|
220
836
|
};
|
|
221
|
-
//
|
|
222
|
-
this.setState(SequencerState.PROPOSER_CHECK,
|
|
223
|
-
|
|
224
|
-
//
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
837
|
+
// We are the synced proposer within the build window; enter the proposer-check state and build.
|
|
838
|
+
this.setState(SequencerState.PROPOSER_CHECK, targetSlot);
|
|
839
|
+
// Guard: don't exceed 1-deep pipeline. Without a proposed checkpoint, we can only build
|
|
840
|
+
// confirmed + 1. With a proposed checkpoint, we can build confirmed + 2.
|
|
841
|
+
const confirmedCkpt = syncedTo.checkpointedCheckpointNumber;
|
|
842
|
+
if (checkpointNumber > confirmedCkpt + 2) {
|
|
843
|
+
this.log.verbose(`Skipping slot ${targetSlot}: checkpoint ${checkpointNumber} exceeds max pipeline depth (confirmed=${confirmedCkpt})`);
|
|
844
|
+
return undefined;
|
|
228
845
|
}
|
|
229
|
-
//
|
|
230
|
-
if (
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
});
|
|
235
|
-
return;
|
|
236
|
-
}
|
|
237
|
-
this.log.debug(`Building validation block for slot ${slot} (actual proposer: ${proposer?.toString() ?? 'none'})`, {
|
|
238
|
-
slot,
|
|
239
|
-
proposer: proposer?.toString()
|
|
846
|
+
// Check that the target slot is not taken by a block already (should never happen, since only us can propose for this slot)
|
|
847
|
+
if (syncedTo.blockData && syncedTo.blockData.header.getSlot() >= targetSlot) {
|
|
848
|
+
this.log.warn(`Cannot propose block at target slot ${targetSlot} since that slot was taken by block ${syncedTo.blockNumber}`, {
|
|
849
|
+
...logCtx,
|
|
850
|
+
block: syncedTo.blockData.header.toInspect()
|
|
240
851
|
});
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
}
|
|
244
|
-
// Check that the slot is not taken by a block already (should never happen, since only us can propose for this slot)
|
|
245
|
-
if (syncedTo.block && syncedTo.block.header.getSlot() >= slot) {
|
|
246
|
-
this.log.warn(`Cannot propose block at next L2 slot ${slot} since that slot was taken by block ${syncedTo.blockNumber}`, {
|
|
247
|
-
...syncLogData,
|
|
248
|
-
block: syncedTo.block.header.toInspect()
|
|
249
|
-
});
|
|
250
|
-
this.metrics.recordBlockProposalPrecheckFailed('slot_already_taken');
|
|
251
|
-
return;
|
|
852
|
+
this.metrics.recordCheckpointPrecheckFailed('slot_already_taken');
|
|
853
|
+
return undefined;
|
|
252
854
|
}
|
|
253
855
|
// We now need to get ourselves a publisher.
|
|
254
856
|
// The returned attestor will be the one we provided if we provided one.
|
|
255
857
|
// Otherwise it will be a valid attestor for the returned publisher.
|
|
256
858
|
// In fisherman mode, pass undefined to use the fisherman's own keystore instead of the actual proposer's
|
|
257
|
-
const
|
|
859
|
+
const proposerForPublisher = this.config.fishermanMode ? undefined : proposer;
|
|
860
|
+
const { attestorAddress, publisher } = await this.publisherFactory.create(proposerForPublisher);
|
|
258
861
|
this.log.verbose(`Created publisher at address ${publisher.getSenderAddress()} for attestor ${attestorAddress}`);
|
|
259
|
-
|
|
260
|
-
//
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
862
|
+
// Prepare invalidation request if the pending chain is invalid (returns undefined if no need).
|
|
863
|
+
// Only simulate invalidation when there's no proposed parent, since we assume the proposed parent
|
|
864
|
+
// will invalidate the currently invalid checkpoint on L1.
|
|
865
|
+
const invalidateCheckpoint = syncedTo.hasProposedCheckpoint || syncedTo.pendingChainValidationStatus.valid ? undefined : await publisher.simulateInvalidateCheckpoint(syncedTo.pendingChainValidationStatus);
|
|
866
|
+
// Determine the correct archive and L1 state overrides for the canProposeAt check.
|
|
867
|
+
// The L1 contract reads archives[proposedCheckpointNumber] and compares it with the provided archive.
|
|
868
|
+
// When invalidating or pipelining, the local archive may differ from L1's, so we adjust accordingly.
|
|
869
|
+
let archiveForCheck = syncedTo.archive;
|
|
870
|
+
if (syncedTo.hasProposedCheckpoint) {
|
|
871
|
+
this.metrics.recordPipelineDepth(syncedTo.checkpointNumber - syncedTo.checkpointedCheckpointNumber);
|
|
872
|
+
this.log.verbose(`Building on top of proposed checkpoint (pending=${syncedTo.proposedCheckpointData?.checkpointNumber}) for target slot ${targetSlot}`, {
|
|
873
|
+
targetSlot,
|
|
874
|
+
parentCheckpointNumber: CheckpointNumber(checkpointNumber - 1)
|
|
875
|
+
});
|
|
876
|
+
// Match what L1 will see at archives[pending] once the proposed parent lands: the parent's
|
|
877
|
+
// own archive root from the gossiped proposal. `syncedTo.archive` is the world-state-local
|
|
878
|
+
// view and can transiently diverge from the proposed parent (e.g. before the proposed
|
|
879
|
+
// parent's blocks have been applied locally); diverging here would cause the canProposeAt
|
|
880
|
+
// override to set archives[pending] to one value while we present another for comparison.
|
|
881
|
+
archiveForCheck = syncedTo.proposedCheckpointData.archive.root;
|
|
882
|
+
} else if (invalidateCheckpoint) {
|
|
883
|
+
// After invalidation, L1 will roll back to checkpoint N-1. The archive at N-1 already
|
|
884
|
+
// exists on L1, so we just pass the matching archive (the lastArchive of the invalid checkpoint).
|
|
885
|
+
archiveForCheck = invalidateCheckpoint.lastArchive;
|
|
886
|
+
this.metrics.recordPipelineDepth(0);
|
|
887
|
+
} else {
|
|
888
|
+
this.metrics.recordPipelineDepth(0);
|
|
889
|
+
}
|
|
890
|
+
// Build the simulation plan: pending/proven override from pipelining or invalidation (or the
|
|
891
|
+
// current snapshot when neither applies, to short-circuit any pending prune in simulation),
|
|
892
|
+
// plus the parent checkpoint cell and fee header when pipelining.
|
|
893
|
+
const simulationOverridesPlan = await buildCheckpointSimulationOverridesPlan({
|
|
894
|
+
checkpointNumber,
|
|
895
|
+
proposedCheckpointData: syncedTo.hasProposedCheckpoint ? syncedTo.proposedCheckpointData : undefined,
|
|
896
|
+
invalidateToPendingCheckpointNumber: invalidateCheckpoint?.forcePendingCheckpointNumber,
|
|
897
|
+
checkpointedCheckpointNumber: syncedTo.checkpointedCheckpointNumber,
|
|
898
|
+
rollup: this.rollupContract,
|
|
899
|
+
signatureContext: this.signatureContext,
|
|
900
|
+
log: this.log
|
|
901
|
+
});
|
|
902
|
+
// The plan always pins both pending/proven (to short-circuit `canPruneAtTime` in simulation),
|
|
903
|
+
// so `provenOverride` always reflects the assumed proven checkpoint we are pinning the
|
|
904
|
+
// simulation to. We additionally warn when the pin is load-bearing — i.e. when a prune would
|
|
905
|
+
// actually fire at the target slot without it — so observers can spot "we are building
|
|
906
|
+
// optimistically across a pruning boundary" in the logs.
|
|
907
|
+
const provenOverride = simulationOverridesPlan?.chainTipsOverride?.proven;
|
|
908
|
+
if (provenOverride !== undefined && await this.l2BlockSource.isPruneDueAtSlot(targetSlot)) {
|
|
909
|
+
this.log.warn(`Assuming proof for epoch ending at checkpoint ${provenOverride} lands by target slot ${targetSlot}`, {
|
|
910
|
+
checkpointNumber,
|
|
911
|
+
slot,
|
|
912
|
+
targetSlot,
|
|
913
|
+
provenOverride
|
|
914
|
+
});
|
|
266
915
|
}
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
const canProposeCheck = await publisher.
|
|
916
|
+
this.emit('preparing-checkpoint', {
|
|
917
|
+
targetSlot,
|
|
918
|
+
checkpointNumber,
|
|
919
|
+
hadProposedParent: syncedTo.hasProposedCheckpoint,
|
|
920
|
+
provenOverride,
|
|
921
|
+
simulatedPending: simulationOverridesPlan?.chainTipsOverride?.pending
|
|
922
|
+
});
|
|
923
|
+
const canProposeCheck = await publisher.canProposeAt(archiveForCheck, proposer ?? EthAddress.ZERO, simulationOverridesPlan);
|
|
924
|
+
const proposeContext = {
|
|
925
|
+
hasProposedCheckpoint: syncedTo.hasProposedCheckpoint,
|
|
926
|
+
proposedCheckpointNumber: syncedTo.proposedCheckpointData?.checkpointNumber,
|
|
927
|
+
checkpointedCheckpointNumber: syncedTo.checkpointedCheckpointNumber,
|
|
928
|
+
isInvalidating: !!invalidateCheckpoint,
|
|
929
|
+
invalidatingCheckpointNumber: invalidateCheckpoint?.checkpointNumber,
|
|
930
|
+
archiveForCheck: archiveForCheck.toString(),
|
|
931
|
+
overridePendingCheckpointNumber: simulationOverridesPlan?.chainTipsOverride?.pending,
|
|
932
|
+
overrideArchive: simulationOverridesPlan?.pendingCheckpointState?.archive,
|
|
933
|
+
overrideFeeHeader: simulationOverridesPlan?.pendingCheckpointState?.feeHeader
|
|
934
|
+
};
|
|
275
935
|
if (canProposeCheck === undefined) {
|
|
276
|
-
this.log.warn(`Cannot propose
|
|
936
|
+
this.log.warn(`Cannot propose checkpoint ${checkpointNumber} at slot ${slot} due to failed rollup contract check`, {
|
|
937
|
+
...logCtx,
|
|
938
|
+
...proposeContext
|
|
939
|
+
});
|
|
277
940
|
this.emit('proposer-rollup-check-failed', {
|
|
278
|
-
reason: 'Rollup contract check failed'
|
|
941
|
+
reason: 'Rollup contract check failed',
|
|
942
|
+
slot
|
|
279
943
|
});
|
|
280
|
-
this.metrics.
|
|
281
|
-
return;
|
|
282
|
-
}
|
|
283
|
-
|
|
284
|
-
|
|
944
|
+
this.metrics.recordCheckpointPrecheckFailed('rollup_contract_check_failed');
|
|
945
|
+
return undefined;
|
|
946
|
+
}
|
|
947
|
+
if (canProposeCheck.slot !== targetSlot) {
|
|
948
|
+
this.log.warn(`Cannot propose block due to slot mismatch with rollup contract (this can be caused by a clock out of sync). Expected slot ${targetSlot} but got ${canProposeCheck.slot}.`, {
|
|
949
|
+
...logCtx,
|
|
950
|
+
...proposeContext,
|
|
285
951
|
rollup: canProposeCheck,
|
|
286
|
-
|
|
287
|
-
expectedSlot: slot
|
|
952
|
+
expectedSlot: targetSlot
|
|
288
953
|
});
|
|
289
954
|
this.emit('proposer-rollup-check-failed', {
|
|
290
|
-
reason: 'Slot mismatch'
|
|
955
|
+
reason: 'Slot mismatch',
|
|
956
|
+
slot
|
|
291
957
|
});
|
|
292
|
-
this.metrics.
|
|
293
|
-
return;
|
|
294
|
-
}
|
|
295
|
-
|
|
296
|
-
|
|
958
|
+
this.metrics.recordCheckpointPrecheckFailed('slot_mismatch');
|
|
959
|
+
return undefined;
|
|
960
|
+
}
|
|
961
|
+
if (canProposeCheck.checkpointNumber !== checkpointNumber) {
|
|
962
|
+
this.log.warn(`Cannot propose due to block mismatch with rollup contract (this can be caused by a pending archiver sync). Expected checkpoint ${checkpointNumber} but got ${canProposeCheck.checkpointNumber}.`, {
|
|
963
|
+
...logCtx,
|
|
964
|
+
...proposeContext,
|
|
297
965
|
rollup: canProposeCheck,
|
|
298
|
-
newBlockNumber,
|
|
299
966
|
expectedSlot: slot
|
|
300
967
|
});
|
|
301
968
|
this.emit('proposer-rollup-check-failed', {
|
|
302
|
-
reason: 'Block mismatch'
|
|
969
|
+
reason: 'Block mismatch',
|
|
970
|
+
slot
|
|
303
971
|
});
|
|
304
|
-
this.metrics.
|
|
305
|
-
return;
|
|
972
|
+
this.metrics.recordCheckpointPrecheckFailed('block_number_mismatch');
|
|
973
|
+
return undefined;
|
|
306
974
|
}
|
|
307
|
-
this.
|
|
308
|
-
|
|
975
|
+
this.lastSlotForCheckpointProposalJob = targetSlot;
|
|
976
|
+
await this.p2pClient.prepareForSlot(targetSlot);
|
|
977
|
+
this.log.info(`Preparing checkpoint proposal ${checkpointNumber} for target slot ${targetSlot} during wall-clock slot ${slot}`, {
|
|
978
|
+
...logCtx,
|
|
979
|
+
...proposeContext,
|
|
980
|
+
proposer
|
|
309
981
|
});
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
// In fisherman mode, we simulate slashing but don't actually publish to L1
|
|
313
|
-
const votesPromises = this.enqueueGovernanceAndSlashingVotes(publisher, attestorAddress, slot, newGlobalVariables.timestamp);
|
|
314
|
-
// Enqueues block invalidation
|
|
315
|
-
if (invalidateBlock && !this.config.skipInvalidateBlockAsProposer) {
|
|
316
|
-
publisher.enqueueInvalidateBlock(invalidateBlock);
|
|
317
|
-
}
|
|
318
|
-
// Actual block building
|
|
319
|
-
this.setState(SequencerState.INITIALIZING_PROPOSAL, slot);
|
|
320
|
-
this.metrics.incOpenSlot(slot, proposer?.toString() ?? 'unknown');
|
|
321
|
-
const block = await this.tryBuildBlockAndEnqueuePublish(slot, proposer, newBlockNumber, publisher, newGlobalVariables, chainTipArchive, invalidateBlock);
|
|
322
|
-
// Wait until the voting promises have resolved, so all requests are enqueued
|
|
323
|
-
await Promise.all(votesPromises);
|
|
324
|
-
// In fisherman mode, we don't publish to L1
|
|
325
|
-
if (this.config.fishermanMode) {
|
|
326
|
-
// Clear pending requests
|
|
327
|
-
publisher.clearPendingRequests();
|
|
328
|
-
if (block) {
|
|
329
|
-
this.log.info(`Validation block building SUCCEEDED for slot ${slot}`, {
|
|
330
|
-
blockNumber: newBlockNumber,
|
|
331
|
-
slot: Number(slot),
|
|
332
|
-
archive: block.archive.toString(),
|
|
333
|
-
txCount: block.body.txEffects.length
|
|
334
|
-
});
|
|
335
|
-
this.lastBlockPublished = block;
|
|
336
|
-
this.metrics.recordBlockProposalSuccess();
|
|
337
|
-
} else {
|
|
338
|
-
// Block building failed in fisherman mode
|
|
339
|
-
this.log.warn(`Validation block building FAILED for slot ${slot}`, {
|
|
340
|
-
blockNumber: newBlockNumber,
|
|
341
|
-
slot: Number(slot)
|
|
342
|
-
});
|
|
343
|
-
this.metrics.recordBlockProposalFailed('block_build_failed');
|
|
344
|
-
}
|
|
345
|
-
} else {
|
|
346
|
-
// Normal mode: send the tx to L1
|
|
347
|
-
const l1Response = await publisher.sendRequests();
|
|
348
|
-
const proposedBlock = l1Response?.successfulActions.find((a)=>a === 'propose');
|
|
349
|
-
if (proposedBlock) {
|
|
350
|
-
this.lastBlockPublished = block;
|
|
351
|
-
this.emit('block-published', {
|
|
352
|
-
blockNumber: newBlockNumber,
|
|
353
|
-
slot: Number(slot)
|
|
354
|
-
});
|
|
355
|
-
await this.metrics.incFilledSlot(publisher.getSenderAddress().toString(), coinbase);
|
|
356
|
-
} else if (block) {
|
|
357
|
-
this.emit('block-publish-failed', l1Response ?? {});
|
|
358
|
-
}
|
|
359
|
-
}
|
|
360
|
-
this.setState(SequencerState.IDLE, undefined);
|
|
982
|
+
// Create and return the checkpoint proposal job
|
|
983
|
+
return this.createCheckpointProposalJob(targetSlot, targetEpoch, checkpointNumber, syncedTo.blockNumber, syncedTo.checkpointedCheckpointNumber, proposer, publisher, attestorAddress, invalidateCheckpoint, syncedTo.proposedCheckpointData);
|
|
361
984
|
}
|
|
362
|
-
|
|
363
|
-
this.
|
|
364
|
-
proposer,
|
|
365
|
-
publisher: publisher.getSenderAddress(),
|
|
366
|
-
globalVariables: newGlobalVariables.toInspect(),
|
|
367
|
-
chainTipArchive,
|
|
368
|
-
blockNumber: newBlockNumber,
|
|
369
|
-
slot
|
|
370
|
-
});
|
|
371
|
-
const proposalHeader = CheckpointHeader.from({
|
|
372
|
-
...newGlobalVariables,
|
|
373
|
-
timestamp: newGlobalVariables.timestamp,
|
|
374
|
-
lastArchiveRoot: chainTipArchive,
|
|
375
|
-
blockHeadersHash: Fr.ZERO,
|
|
376
|
-
contentCommitment: ContentCommitment.empty(),
|
|
377
|
-
totalManaUsed: Fr.ZERO
|
|
378
|
-
});
|
|
379
|
-
let block;
|
|
380
|
-
const pendingTxCount = await this.p2pClient.getPendingTxCount();
|
|
381
|
-
if (pendingTxCount >= this.minTxsPerBlock) {
|
|
382
|
-
// We don't fetch exactly maxTxsPerBlock txs here because we may not need all of them if we hit a limit before,
|
|
383
|
-
// and also we may need to fetch more if we don't have enough valid txs.
|
|
384
|
-
const pendingTxs = this.p2pClient.iteratePendingTxs();
|
|
385
|
-
try {
|
|
386
|
-
block = await this.buildBlockAndEnqueuePublish(pendingTxs, proposalHeader, newGlobalVariables, proposer, invalidateBlock, publisher);
|
|
387
|
-
} catch (err) {
|
|
388
|
-
this.emit('block-build-failed', {
|
|
389
|
-
reason: err.message
|
|
390
|
-
});
|
|
391
|
-
if (err instanceof FormattedViemError) {
|
|
392
|
-
this.log.verbose(`Unable to build/enqueue block ${err.message}`);
|
|
393
|
-
} else {
|
|
394
|
-
this.log.error(`Error building/enqueuing block`, err, {
|
|
395
|
-
blockNumber: newBlockNumber,
|
|
396
|
-
slot
|
|
397
|
-
});
|
|
398
|
-
}
|
|
399
|
-
this.metrics.recordBlockProposalFailed(err.name || 'unknown_error');
|
|
400
|
-
}
|
|
401
|
-
} else {
|
|
402
|
-
this.log.verbose(`Not enough txs to build block ${newBlockNumber} at slot ${slot} (got ${pendingTxCount} txs, need ${this.minTxsPerBlock})`, {
|
|
403
|
-
chainTipArchive,
|
|
404
|
-
blockNumber: newBlockNumber,
|
|
405
|
-
slot
|
|
406
|
-
});
|
|
407
|
-
this.emit('tx-count-check-failed', {
|
|
408
|
-
minTxs: this.minTxsPerBlock,
|
|
409
|
-
availableTxs: pendingTxCount
|
|
410
|
-
});
|
|
411
|
-
this.metrics.recordBlockProposalFailed('insufficient_txs');
|
|
412
|
-
}
|
|
413
|
-
return block;
|
|
985
|
+
createCheckpointProposalJob(targetSlot, targetEpoch, checkpointNumber, syncedToBlockNumber, checkpointedCheckpointNumber, proposer, publisher, attestorAddress, invalidateCheckpoint, proposedCheckpointData) {
|
|
986
|
+
return new CheckpointProposalJob(targetSlot, targetEpoch, checkpointNumber, syncedToBlockNumber, checkpointedCheckpointNumber, proposer, publisher, attestorAddress, invalidateCheckpoint, this.validatorClient, this.globalsBuilder, this.p2pClient, this.worldState, this.l1ToL2MessageSource, this.l2BlockSource, this.checkpointsBuilder, this.l2BlockSource, this.l1Constants, this.signatureContext, this.config, this.timetable, this.slasherClient, this.epochCache, this.dateProvider, this.metrics, this.checkpointProposalJobMetrics.createRecorder(), this, this.pendingRequests, this.setState.bind(this), this.tracer, this.log.getBindings(), proposedCheckpointData);
|
|
414
987
|
}
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
if (err instanceof SequencerTooSlowError) {
|
|
420
|
-
// Log as warn only if we had to abort halfway through the block proposal
|
|
421
|
-
const logLvl = [
|
|
422
|
-
SequencerState.INITIALIZING_PROPOSAL,
|
|
423
|
-
SequencerState.PROPOSER_CHECK
|
|
424
|
-
].includes(err.proposedState) ? 'debug' : 'warn';
|
|
425
|
-
this.log[logLvl](err.message, {
|
|
426
|
-
now: this.dateProvider.nowInSeconds()
|
|
427
|
-
});
|
|
428
|
-
} else {
|
|
429
|
-
// Re-throw other errors
|
|
430
|
-
throw err;
|
|
431
|
-
}
|
|
432
|
-
} finally{
|
|
433
|
-
this.setState(SequencerState.IDLE, undefined);
|
|
434
|
-
}
|
|
988
|
+
/**
|
|
989
|
+
* Returns the current sequencer state.
|
|
990
|
+
*/ getState() {
|
|
991
|
+
return this.state;
|
|
435
992
|
}
|
|
436
|
-
|
|
993
|
+
/**
|
|
994
|
+
* Internal helper for setting the sequencer state. Pure: sets the state, emits `state-changed`, and
|
|
995
|
+
* records metrics. Timing deadlines are queried explicitly at the relevant call sites, not gated here.
|
|
996
|
+
* @param proposedState - The new state to transition to.
|
|
997
|
+
* @param slotNumber - The target slot being proposed for, emitted as `targetSlot` on the event payload
|
|
998
|
+
* and used to anchor `secondsIntoBuildFrame`. Undefined for lifecycle states with no associated slot.
|
|
999
|
+
* @param force - Whether to force the transition even if the sequencer is stopped.
|
|
1000
|
+
*/ setState(proposedState, slotNumber, opts = {}) {
|
|
437
1001
|
if (this.state === SequencerState.STOPPING && proposedState !== SequencerState.STOPPED && !opts.force) {
|
|
438
1002
|
this.log.warn(`Cannot set sequencer to ${proposedState} as it is stopping.`);
|
|
439
1003
|
throw new SequencerInterruptedError();
|
|
@@ -442,252 +1006,55 @@ export { SequencerState };
|
|
|
442
1006
|
this.log.warn(`Cannot set sequencer from ${this.state} to ${proposedState} as it is stopped.`);
|
|
443
1007
|
return;
|
|
444
1008
|
}
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
1009
|
+
const secondsIntoBuildFrame = slotNumber !== undefined ? this.getSecondsIntoBuildFrame(slotNumber) : undefined;
|
|
1010
|
+
const oldState = this.state;
|
|
1011
|
+
const oldStateSlotNumber = this.stateSlotNumber;
|
|
1012
|
+
const stateChanged = proposedState !== oldState;
|
|
1013
|
+
// Wall-clock time spent in the previous state: the delta between consecutive state-changing setState
|
|
1014
|
+
// calls, read from the date provider so it tracks simulated time under a test/manual clock.
|
|
1015
|
+
const transitionAtMs = this.dateProvider.now();
|
|
1016
|
+
const stateDurationMs = transitionAtMs - this.stateEnteredAtMs;
|
|
450
1017
|
const boringStates = [
|
|
451
1018
|
SequencerState.IDLE,
|
|
452
1019
|
SequencerState.SYNCHRONIZING
|
|
453
1020
|
];
|
|
454
|
-
const logLevel = boringStates.includes(proposedState) && boringStates.includes(
|
|
455
|
-
this.
|
|
1021
|
+
const logLevel = boringStates.includes(proposedState) && boringStates.includes(oldState) ? 'trace' : 'debug';
|
|
1022
|
+
this.stateLog[logLevel](`Transitioning from ${oldState} to ${proposedState}`, {
|
|
1023
|
+
oldState,
|
|
1024
|
+
newState: proposedState,
|
|
456
1025
|
slotNumber,
|
|
457
|
-
|
|
1026
|
+
stateSlotNumber: oldStateSlotNumber,
|
|
1027
|
+
secondsIntoBuildFrame,
|
|
1028
|
+
...stateChanged && {
|
|
1029
|
+
stateDurationMs: Math.ceil(stateDurationMs)
|
|
1030
|
+
}
|
|
458
1031
|
});
|
|
459
1032
|
this.emit('state-changed', {
|
|
460
|
-
oldState
|
|
1033
|
+
oldState,
|
|
461
1034
|
newState: proposedState,
|
|
462
|
-
|
|
463
|
-
slotNumber
|
|
464
|
-
});
|
|
465
|
-
this.state = proposedState;
|
|
466
|
-
}
|
|
467
|
-
async dropFailedTxsFromP2P(failedTxs) {
|
|
468
|
-
if (failedTxs.length === 0) {
|
|
469
|
-
return;
|
|
470
|
-
}
|
|
471
|
-
const failedTxData = failedTxs.map((fail)=>fail.tx);
|
|
472
|
-
const failedTxHashes = failedTxData.map((tx)=>tx.getTxHash());
|
|
473
|
-
this.log.verbose(`Dropping failed txs ${failedTxHashes.join(', ')}`);
|
|
474
|
-
await this.p2pClient.deleteTxs(failedTxHashes);
|
|
475
|
-
}
|
|
476
|
-
getBlockBuilderOptions(slot) {
|
|
477
|
-
// Deadline for processing depends on whether we're proposing a block
|
|
478
|
-
const secondsIntoSlot = this.getSecondsIntoSlot(slot);
|
|
479
|
-
const processingEndTimeWithinSlot = this.timetable.getBlockProposalExecTimeEnd(secondsIntoSlot);
|
|
480
|
-
// Deadline is only set if enforceTimeTable is enabled.
|
|
481
|
-
const deadline = this.enforceTimeTable ? new Date((this.getSlotStartBuildTimestamp(slot) + processingEndTimeWithinSlot) * 1000) : undefined;
|
|
482
|
-
return {
|
|
483
|
-
maxTransactions: this.maxTxsPerBlock,
|
|
484
|
-
maxBlockSize: this.maxBlockSizeInBytes,
|
|
485
|
-
maxBlockGas: this.maxBlockGas,
|
|
486
|
-
maxBlobFields: BLOBS_PER_CHECKPOINT * FIELDS_PER_BLOB,
|
|
487
|
-
deadline
|
|
488
|
-
};
|
|
489
|
-
}
|
|
490
|
-
/**
|
|
491
|
-
* @notice Build and propose a block to the chain
|
|
492
|
-
*
|
|
493
|
-
* @dev MUST throw instead of exiting early to ensure that world-state
|
|
494
|
-
* is being rolled back if the block is dropped.
|
|
495
|
-
*
|
|
496
|
-
* @param pendingTxs - Iterable of pending transactions to construct the block from
|
|
497
|
-
* @param proposalHeader - The partial header constructed for the proposal
|
|
498
|
-
* @param newGlobalVariables - The global variables for the new block
|
|
499
|
-
* @param proposerAddress - The address of the proposer
|
|
500
|
-
*/ async buildBlockAndEnqueuePublish(pendingTxs, proposalHeader, newGlobalVariables, proposerAddress, invalidateBlock, publisher) {
|
|
501
|
-
await publisher.validateBlockHeader(proposalHeader, invalidateBlock);
|
|
502
|
-
const blockNumber = newGlobalVariables.blockNumber;
|
|
503
|
-
const slot = proposalHeader.slotNumber;
|
|
504
|
-
const l1ToL2Messages = await this.l1ToL2MessageSource.getL1ToL2Messages(blockNumber);
|
|
505
|
-
const workTimer = new Timer();
|
|
506
|
-
this.setState(SequencerState.CREATING_BLOCK, slot);
|
|
507
|
-
try {
|
|
508
|
-
const blockBuilderOptions = this.getBlockBuilderOptions(slot);
|
|
509
|
-
const buildBlockRes = await this.blockBuilder.buildBlock(pendingTxs, l1ToL2Messages, newGlobalVariables, blockBuilderOptions);
|
|
510
|
-
const { publicGas, block, publicProcessorDuration, numTxs, numMsgs, blockBuildingTimer, usedTxs, failedTxs } = buildBlockRes;
|
|
511
|
-
const blockBuildDuration = workTimer.ms();
|
|
512
|
-
await this.dropFailedTxsFromP2P(failedTxs);
|
|
513
|
-
const minTxsPerBlock = this.minTxsPerBlock;
|
|
514
|
-
if (numTxs < minTxsPerBlock) {
|
|
515
|
-
this.log.warn(`Block ${blockNumber} has too few txs to be proposed (got ${numTxs} but required ${minTxsPerBlock})`, {
|
|
516
|
-
slot,
|
|
517
|
-
blockNumber,
|
|
518
|
-
numTxs
|
|
519
|
-
});
|
|
520
|
-
throw new Error(`Block has too few successful txs to be proposed`);
|
|
521
|
-
}
|
|
522
|
-
// TODO(@PhilWindle) We should probably periodically check for things like another
|
|
523
|
-
// block being published before ours instead of just waiting on our block
|
|
524
|
-
await publisher.validateBlockHeader(block.getCheckpointHeader(), invalidateBlock);
|
|
525
|
-
const blockStats = {
|
|
526
|
-
eventName: 'l2-block-built',
|
|
527
|
-
creator: proposerAddress?.toString() ?? publisher.getSenderAddress().toString(),
|
|
528
|
-
duration: workTimer.ms(),
|
|
529
|
-
publicProcessDuration: publicProcessorDuration,
|
|
530
|
-
rollupCircuitsDuration: blockBuildingTimer.ms(),
|
|
531
|
-
...block.getStats()
|
|
532
|
-
};
|
|
533
|
-
const blockHash = await block.hash();
|
|
534
|
-
const txHashes = block.body.txEffects.map((tx)=>tx.txHash);
|
|
535
|
-
this.log.info(`Built block ${block.number} for slot ${slot} with ${numTxs} txs and ${numMsgs} messages. ${publicGas.l2Gas / workTimer.s()} mana/s`, {
|
|
536
|
-
blockHash,
|
|
537
|
-
globalVariables: block.header.globalVariables.toInspect(),
|
|
538
|
-
txHashes,
|
|
539
|
-
...blockStats
|
|
540
|
-
});
|
|
541
|
-
// In fisherman mode, skip attestation collection
|
|
542
|
-
let attestationsAndSigners;
|
|
543
|
-
if (this.config.fishermanMode) {
|
|
544
|
-
this.log.debug('Skipping attestation collection');
|
|
545
|
-
attestationsAndSigners = CommitteeAttestationsAndSigners.empty();
|
|
546
|
-
} else {
|
|
547
|
-
this.log.debug('Collecting attestations');
|
|
548
|
-
attestationsAndSigners = await this.collectAttestations(block, usedTxs, proposerAddress);
|
|
549
|
-
this.log.verbose(`Collected ${attestationsAndSigners.attestations.length} attestations for block ${blockNumber} at slot ${slot}`, {
|
|
550
|
-
blockHash,
|
|
551
|
-
blockNumber,
|
|
552
|
-
slot
|
|
553
|
-
});
|
|
554
|
-
}
|
|
555
|
-
// In fisherman mode, skip attestation signing
|
|
556
|
-
const attestationsAndSignersSignature = this.config.fishermanMode || !this.validatorClient ? Signature.empty() : await this.validatorClient.signAttestationsAndSigners(attestationsAndSigners, proposerAddress ?? publisher.getSenderAddress());
|
|
557
|
-
await this.enqueuePublishL2Block(block, attestationsAndSigners, attestationsAndSignersSignature, invalidateBlock, publisher);
|
|
558
|
-
this.metrics.recordBuiltBlock(blockBuildDuration, publicGas.l2Gas);
|
|
559
|
-
return block;
|
|
560
|
-
} catch (err) {
|
|
561
|
-
this.metrics.recordFailedBlock();
|
|
562
|
-
throw err;
|
|
563
|
-
}
|
|
564
|
-
}
|
|
565
|
-
async collectAttestations(block, txs, proposerAddress) {
|
|
566
|
-
const { committee, seed, epoch } = await this.epochCache.getCommittee(block.slot);
|
|
567
|
-
// We checked above that the committee is defined, so this should never happen.
|
|
568
|
-
if (!committee) {
|
|
569
|
-
throw new Error('No committee when collecting attestations');
|
|
570
|
-
}
|
|
571
|
-
if (committee.length === 0) {
|
|
572
|
-
this.log.verbose(`Attesting committee is empty`);
|
|
573
|
-
return CommitteeAttestationsAndSigners.empty();
|
|
574
|
-
} else {
|
|
575
|
-
this.log.debug(`Attesting committee length is ${committee.length}`);
|
|
576
|
-
}
|
|
577
|
-
if (!this.validatorClient) {
|
|
578
|
-
throw new Error('Missing validator client: Cannot collect attestations');
|
|
579
|
-
}
|
|
580
|
-
const numberOfRequiredAttestations = Math.floor(committee.length * 2 / 3) + 1;
|
|
581
|
-
const slotNumber = block.header.globalVariables.slotNumber;
|
|
582
|
-
this.setState(SequencerState.COLLECTING_ATTESTATIONS, slotNumber);
|
|
583
|
-
this.log.debug('Creating block proposal for validators');
|
|
584
|
-
const blockProposalOptions = {
|
|
585
|
-
publishFullTxs: !!this.config.publishTxsWithProposals,
|
|
586
|
-
broadcastInvalidBlockProposal: this.config.broadcastInvalidBlockProposal
|
|
587
|
-
};
|
|
588
|
-
const proposal = await this.validatorClient.createBlockProposal(block.header.globalVariables.blockNumber, block.getCheckpointHeader(), block.archive.root, txs, proposerAddress, blockProposalOptions);
|
|
589
|
-
if (!proposal) {
|
|
590
|
-
throw new Error(`Failed to create block proposal`);
|
|
591
|
-
}
|
|
592
|
-
if (this.config.skipCollectingAttestations) {
|
|
593
|
-
this.log.warn('Skipping attestation collection as per config (attesting with own keys only)');
|
|
594
|
-
const attestations = await this.validatorClient?.collectOwnAttestations(proposal);
|
|
595
|
-
return new CommitteeAttestationsAndSigners(orderAttestations(attestations ?? [], committee));
|
|
596
|
-
}
|
|
597
|
-
this.log.debug('Broadcasting block proposal to validators');
|
|
598
|
-
await this.validatorClient.broadcastBlockProposal(proposal);
|
|
599
|
-
const attestationTimeAllowed = this.enforceTimeTable ? this.timetable.getMaxAllowedTime(SequencerState.PUBLISHING_BLOCK) : this.aztecSlotDuration;
|
|
600
|
-
this.metrics.recordRequiredAttestations(numberOfRequiredAttestations, attestationTimeAllowed);
|
|
601
|
-
const timer = new Timer();
|
|
602
|
-
let collectedAttestationsCount = 0;
|
|
603
|
-
try {
|
|
604
|
-
const attestationDeadline = new Date(this.dateProvider.now() + attestationTimeAllowed * 1000);
|
|
605
|
-
const attestations = await this.validatorClient.collectAttestations(proposal, numberOfRequiredAttestations, attestationDeadline);
|
|
606
|
-
collectedAttestationsCount = attestations.length;
|
|
607
|
-
// note: the smart contract requires that the signatures are provided in the order of the committee
|
|
608
|
-
const sorted = orderAttestations(attestations, committee);
|
|
609
|
-
// manipulate the attestations if we've been configured to do so
|
|
610
|
-
if (this.config.injectFakeAttestation || this.config.shuffleAttestationOrdering) {
|
|
611
|
-
return this.manipulateAttestations(block, epoch, seed, committee, sorted);
|
|
612
|
-
}
|
|
613
|
-
return new CommitteeAttestationsAndSigners(sorted);
|
|
614
|
-
} catch (err) {
|
|
615
|
-
if (err && err instanceof AttestationTimeoutError) {
|
|
616
|
-
collectedAttestationsCount = err.collectedCount;
|
|
617
|
-
}
|
|
618
|
-
throw err;
|
|
619
|
-
} finally{
|
|
620
|
-
this.metrics.recordCollectedAttestations(collectedAttestationsCount, timer.ms());
|
|
621
|
-
}
|
|
622
|
-
}
|
|
623
|
-
/** Breaks the attestations before publishing based on attack configs */ manipulateAttestations(block, epoch, seed, committee, attestations) {
|
|
624
|
-
// Compute the proposer index in the committee, since we dont want to tweak it.
|
|
625
|
-
// Otherwise, the L1 rollup contract will reject the block outright.
|
|
626
|
-
const proposerIndex = Number(this.epochCache.computeProposerIndex(block.slot, epoch, seed, BigInt(committee.length)));
|
|
627
|
-
if (this.config.injectFakeAttestation) {
|
|
628
|
-
// Find non-empty attestations that are not from the proposer
|
|
629
|
-
const nonProposerIndices = [];
|
|
630
|
-
for(let i = 0; i < attestations.length; i++){
|
|
631
|
-
if (!attestations[i].signature.isEmpty() && i !== proposerIndex) {
|
|
632
|
-
nonProposerIndices.push(i);
|
|
633
|
-
}
|
|
634
|
-
}
|
|
635
|
-
if (nonProposerIndices.length > 0) {
|
|
636
|
-
const targetIndex = nonProposerIndices[randomInt(nonProposerIndices.length)];
|
|
637
|
-
this.log.warn(`Injecting fake attestation in block ${block.number} at index ${targetIndex}`);
|
|
638
|
-
unfreeze(attestations[targetIndex]).signature = Signature.random();
|
|
639
|
-
}
|
|
640
|
-
return new CommitteeAttestationsAndSigners(attestations);
|
|
641
|
-
}
|
|
642
|
-
if (this.config.shuffleAttestationOrdering) {
|
|
643
|
-
this.log.warn(`Shuffling attestation ordering in block ${block.number} (proposer index ${proposerIndex})`);
|
|
644
|
-
const shuffled = [
|
|
645
|
-
...attestations
|
|
646
|
-
];
|
|
647
|
-
const [i, j] = [
|
|
648
|
-
(proposerIndex + 1) % shuffled.length,
|
|
649
|
-
(proposerIndex + 2) % shuffled.length
|
|
650
|
-
];
|
|
651
|
-
const valueI = shuffled[i];
|
|
652
|
-
const valueJ = shuffled[j];
|
|
653
|
-
shuffled[i] = valueJ;
|
|
654
|
-
shuffled[j] = valueI;
|
|
655
|
-
const signers = new CommitteeAttestationsAndSigners(attestations).getSigners();
|
|
656
|
-
return new MaliciousCommitteeAttestationsAndSigners(shuffled, signers);
|
|
657
|
-
}
|
|
658
|
-
return new CommitteeAttestationsAndSigners(attestations);
|
|
659
|
-
}
|
|
660
|
-
/**
|
|
661
|
-
* Publishes the L2Block to the rollup contract.
|
|
662
|
-
* @param block - The L2Block to be published.
|
|
663
|
-
*/ async enqueuePublishL2Block(block, attestationsAndSigners, attestationsAndSignersSignature, invalidateBlock, publisher) {
|
|
664
|
-
// Publishes new block to the network and awaits the tx to be mined
|
|
665
|
-
this.setState(SequencerState.PUBLISHING_BLOCK, block.header.globalVariables.slotNumber);
|
|
666
|
-
// Time out tx at the end of the slot
|
|
667
|
-
const slot = block.header.globalVariables.slotNumber;
|
|
668
|
-
const txTimeoutAt = new Date((this.getSlotStartBuildTimestamp(slot) + this.aztecSlotDuration) * 1000);
|
|
669
|
-
const enqueued = await publisher.enqueueProposeL2Block(block, attestationsAndSigners, attestationsAndSignersSignature, {
|
|
670
|
-
txTimeoutAt,
|
|
671
|
-
forcePendingBlockNumber: invalidateBlock?.forcePendingBlockNumber
|
|
1035
|
+
secondsIntoBuildFrame,
|
|
1036
|
+
targetSlot: slotNumber
|
|
672
1037
|
});
|
|
673
|
-
if (
|
|
674
|
-
|
|
1038
|
+
if (stateChanged) {
|
|
1039
|
+
this.metrics.recordStateDuration(stateDurationMs, oldState);
|
|
1040
|
+
this.stateEnteredAtMs = transitionAtMs;
|
|
1041
|
+
this.stateSlotNumber = slotNumber;
|
|
675
1042
|
}
|
|
1043
|
+
this.state = proposedState;
|
|
676
1044
|
}
|
|
677
1045
|
/**
|
|
678
1046
|
* Returns whether all dependencies have caught up.
|
|
679
1047
|
* We don't check against the previous block submitted since it may have been reorg'd out.
|
|
680
1048
|
*/ async checkSync(args) {
|
|
681
|
-
// Check that the archiver
|
|
682
|
-
//
|
|
683
|
-
//
|
|
684
|
-
const
|
|
685
|
-
const { slot
|
|
686
|
-
if (
|
|
1049
|
+
// Check that the archiver has fully synced the L2 slot before the one we want to propose in.
|
|
1050
|
+
// The archiver reports sync progress via L1 block timestamps and synced checkpoint slots.
|
|
1051
|
+
// See getSyncedL2SlotNumber for how missed L1 blocks are handled.
|
|
1052
|
+
const syncedL2Slot = await this.l2BlockSource.getSyncedL2SlotNumber();
|
|
1053
|
+
const { slot } = args;
|
|
1054
|
+
if (syncedL2Slot === undefined || syncedL2Slot + 1 < slot) {
|
|
687
1055
|
this.log.debug(`Cannot propose block at next L2 slot ${slot} due to pending sync from L1`, {
|
|
688
1056
|
slot,
|
|
689
|
-
|
|
690
|
-
l1Timestamp
|
|
1057
|
+
syncedL2Slot
|
|
691
1058
|
});
|
|
692
1059
|
return undefined;
|
|
693
1060
|
}
|
|
@@ -696,111 +1063,107 @@ export { SequencerState };
|
|
|
696
1063
|
number: syncSummary.latestBlockNumber,
|
|
697
1064
|
hash: syncSummary.latestBlockHash
|
|
698
1065
|
})),
|
|
699
|
-
this.l2BlockSource.getL2Tips().then((t)=>
|
|
1066
|
+
this.l2BlockSource.getL2Tips().then((t)=>({
|
|
1067
|
+
proposed: t.proposed,
|
|
1068
|
+
checkpointed: t.checkpointed
|
|
1069
|
+
})),
|
|
700
1070
|
this.p2pClient.getStatus().then((p2p)=>p2p.syncedToL2Block),
|
|
701
|
-
this.l1ToL2MessageSource.getL2Tips().then((t)=>
|
|
702
|
-
|
|
1071
|
+
this.l1ToL2MessageSource.getL2Tips().then((t)=>({
|
|
1072
|
+
proposed: t.proposed,
|
|
1073
|
+
checkpointed: t.checkpointed
|
|
1074
|
+
})),
|
|
1075
|
+
this.l2BlockSource.getPendingChainValidationStatus(),
|
|
1076
|
+
this.l2BlockSource.getProposedCheckpointData()
|
|
703
1077
|
]);
|
|
704
|
-
const [worldState,
|
|
705
|
-
|
|
706
|
-
// as the world state can compute the new genesis block hash, but other components use the hardcoded constant.
|
|
707
|
-
const result = l2BlockSource.number === 0 && worldState.number === 0 && p2p.number === 0 && l1ToL2MessageSource.number === 0 || worldState.hash === l2BlockSource.hash && p2p.hash === l2BlockSource.hash && l1ToL2MessageSource.hash === l2BlockSource.hash;
|
|
1078
|
+
const [worldState, l2Tips, p2p, l1ToL2MessageSourceTips, pendingChainValidationStatus, proposedCheckpointData] = syncedBlocks;
|
|
1079
|
+
const result = worldState.hash === l2Tips.proposed.hash && p2p.hash === l2Tips.proposed.hash && l1ToL2MessageSourceTips.proposed.hash === l2Tips.proposed.hash && l1ToL2MessageSourceTips.checkpointed.block.hash === l2Tips.checkpointed.block.hash && l1ToL2MessageSourceTips.checkpointed.checkpoint.hash === l2Tips.checkpointed.checkpoint.hash;
|
|
708
1080
|
if (!result) {
|
|
709
1081
|
this.log.debug(`Sequencer sync check failed`, {
|
|
710
1082
|
worldState,
|
|
711
|
-
l2BlockSource,
|
|
1083
|
+
l2BlockSource: l2Tips.proposed,
|
|
712
1084
|
p2p,
|
|
713
|
-
|
|
1085
|
+
l1ToL2MessageSourceTips
|
|
714
1086
|
});
|
|
715
1087
|
return undefined;
|
|
716
1088
|
}
|
|
717
|
-
// Special case for genesis state
|
|
718
1089
|
const blockNumber = worldState.number;
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
1090
|
+
const blockData = await this.l2BlockSource.getBlockData({
|
|
1091
|
+
number: blockNumber
|
|
1092
|
+
});
|
|
1093
|
+
if (!blockData) {
|
|
1094
|
+
this.log.warn(`Sequencer sync check failed: failed to get L2 block data ${blockNumber} from the archiver`, {
|
|
1095
|
+
blockNumber,
|
|
1096
|
+
l2Tips,
|
|
1097
|
+
syncedL2Slot,
|
|
1098
|
+
...args
|
|
1099
|
+
});
|
|
1100
|
+
return undefined;
|
|
1101
|
+
}
|
|
1102
|
+
// Refuse to build a checkpoint on top of a proposed block whose enclosing checkpoint was never
|
|
1103
|
+
// proposed. Under pipelining we may have received and reexecuted such a block locally — advancing
|
|
1104
|
+
// our world-state tip past the checkpointed tip — while the proposing node never published the
|
|
1105
|
+
// matching proposed checkpoint (e.g. it crashed before assembling it). Building on this orphan block
|
|
1106
|
+
// would fork the chain off a tip no other node can follow. The archiver prunes these orphan blocks
|
|
1107
|
+
// once their build slot ends; this guard is the correctness barrier during the grace window before.
|
|
1108
|
+
// `getProposedCheckpointData()` returns the latest proposed checkpoint payload, which is always
|
|
1109
|
+
// the leading one (a proposed entry is only stored beyond the confirmed frontier and is deleted
|
|
1110
|
+
// on confirmation). It carries no tip, so there is no tip-vs-payload split read to reconcile.
|
|
1111
|
+
if (blockData.checkpointNumber > l2Tips.checkpointed.checkpoint.number && proposedCheckpointData?.checkpointNumber !== blockData.checkpointNumber) {
|
|
1112
|
+
const logCtx = {
|
|
1113
|
+
blockCheckpointNumber: blockData.checkpointNumber,
|
|
1114
|
+
checkpointedCheckpointNumber: l2Tips.checkpointed.checkpoint.number,
|
|
1115
|
+
proposedCheckpointTipNumber: proposedCheckpointData?.checkpointNumber,
|
|
1116
|
+
blockNumber: blockData.header.getBlockNumber(),
|
|
1117
|
+
blockSlot: blockData.header.getSlot(),
|
|
1118
|
+
syncedL2Slot,
|
|
1119
|
+
...args
|
|
726
1120
|
};
|
|
1121
|
+
this.log.debug(`Waiting for proposed checkpoint to catch up with reexecuted block`, logCtx);
|
|
1122
|
+
return undefined;
|
|
727
1123
|
}
|
|
728
|
-
const
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
1124
|
+
const hasProposedCheckpoint = proposedCheckpointData !== undefined;
|
|
1125
|
+
// Check that the proposed checkpoint is indeed the parent of the checkpoint we'll be building
|
|
1126
|
+
// The checkpoint number to build is derived as blockData.checkpointNumber + 1
|
|
1127
|
+
if (proposedCheckpointData && proposedCheckpointData.checkpointNumber !== blockData.checkpointNumber) {
|
|
1128
|
+
this.log.warn(`Sequencer sync check failed: proposed checkpoint number mismatch`, {
|
|
1129
|
+
proposedCheckpointNumber: proposedCheckpointData.checkpointNumber,
|
|
1130
|
+
blockCheckpointNumber: blockData.checkpointNumber,
|
|
1131
|
+
syncedL2Slot,
|
|
1132
|
+
...args
|
|
1133
|
+
});
|
|
732
1134
|
return undefined;
|
|
733
1135
|
}
|
|
734
1136
|
return {
|
|
735
|
-
|
|
736
|
-
blockNumber:
|
|
737
|
-
|
|
738
|
-
|
|
1137
|
+
blockData,
|
|
1138
|
+
blockNumber: blockData.header.getBlockNumber(),
|
|
1139
|
+
checkpointNumber: blockData.checkpointNumber,
|
|
1140
|
+
checkpointedCheckpointNumber: l2Tips.checkpointed.checkpoint.number,
|
|
1141
|
+
archive: blockData.archive.root,
|
|
1142
|
+
hasProposedCheckpoint,
|
|
1143
|
+
proposedCheckpointData,
|
|
1144
|
+
syncedL2Slot,
|
|
739
1145
|
pendingChainValidationStatus
|
|
740
1146
|
};
|
|
741
1147
|
}
|
|
742
1148
|
/**
|
|
743
|
-
* Enqueues governance and slashing votes with the publisher. Does not block.
|
|
744
|
-
* @param publisher - The publisher to enqueue votes with
|
|
745
|
-
* @param attestorAddress - The attestor address to use for signing
|
|
746
|
-
* @param slot - The slot number
|
|
747
|
-
* @param timestamp - The timestamp for the votes
|
|
748
|
-
* @param context - Optional context for logging (e.g., block number)
|
|
749
|
-
* @returns A tuple of [governanceEnqueued, slashingEnqueued]
|
|
750
|
-
*/ enqueueGovernanceAndSlashingVotes(publisher, attestorAddress, slot, timestamp) {
|
|
751
|
-
try {
|
|
752
|
-
const signerFn = (msg)=>this.validatorClient.signWithAddress(attestorAddress, msg).then((s)=>s.toString());
|
|
753
|
-
const enqueueGovernancePromise = this.governanceProposerPayload && !this.governanceProposerPayload.isZero() ? publisher.enqueueGovernanceCastSignal(this.governanceProposerPayload, slot, timestamp, attestorAddress, signerFn).catch((err)=>{
|
|
754
|
-
this.log.error(`Error enqueuing governance vote`, err, {
|
|
755
|
-
slot
|
|
756
|
-
});
|
|
757
|
-
return false;
|
|
758
|
-
}) : undefined;
|
|
759
|
-
const enqueueSlashingPromise = this.slasherClient ? this.slasherClient.getProposerActions(slot).then((actions)=>{
|
|
760
|
-
// Record metrics for fisherman mode
|
|
761
|
-
if (this.config.fishermanMode && actions.length > 0) {
|
|
762
|
-
this.log.debug(`Fisherman mode: simulating ${actions.length} slashing action(s) for slot ${slot}`, {
|
|
763
|
-
slot,
|
|
764
|
-
actionCount: actions.length
|
|
765
|
-
});
|
|
766
|
-
this.metrics.recordSlashingAttempt(actions.length);
|
|
767
|
-
}
|
|
768
|
-
// Enqueue the actions to fully simulate L1 tx building (they won't be sent in fisherman mode)
|
|
769
|
-
return publisher.enqueueSlashingActions(actions, slot, timestamp, attestorAddress, signerFn);
|
|
770
|
-
}).catch((err)=>{
|
|
771
|
-
this.log.error(`Error enqueuing slashing actions`, err, {
|
|
772
|
-
slot
|
|
773
|
-
});
|
|
774
|
-
return false;
|
|
775
|
-
}) : undefined;
|
|
776
|
-
return [
|
|
777
|
-
enqueueGovernancePromise,
|
|
778
|
-
enqueueSlashingPromise
|
|
779
|
-
];
|
|
780
|
-
} catch (err) {
|
|
781
|
-
this.log.error(`Error enqueueing governance and slashing votes`, err);
|
|
782
|
-
return [
|
|
783
|
-
undefined,
|
|
784
|
-
undefined
|
|
785
|
-
];
|
|
786
|
-
}
|
|
787
|
-
}
|
|
788
|
-
/**
|
|
789
1149
|
* Checks if we are the proposer for the next slot.
|
|
790
1150
|
* @returns True if we can propose, and the proposer address (undefined if anyone can propose)
|
|
791
|
-
*/ async checkCanPropose(
|
|
1151
|
+
*/ async checkCanPropose(targetSlot) {
|
|
792
1152
|
let proposer;
|
|
793
1153
|
try {
|
|
794
|
-
proposer = await this.epochCache.getProposerAttesterAddressInSlot(
|
|
1154
|
+
proposer = await this.epochCache.getProposerAttesterAddressInSlot(targetSlot);
|
|
795
1155
|
} catch (e) {
|
|
796
1156
|
if (e instanceof NoCommitteeError) {
|
|
797
|
-
this.
|
|
1157
|
+
if (this.lastSlotForNoCommitteeWarning !== targetSlot) {
|
|
1158
|
+
this.lastSlotForNoCommitteeWarning = targetSlot;
|
|
1159
|
+
this.log.warn(`Cannot propose at target slot ${targetSlot} since the committee does not exist on L1`);
|
|
1160
|
+
}
|
|
798
1161
|
return [
|
|
799
1162
|
false,
|
|
800
1163
|
undefined
|
|
801
1164
|
];
|
|
802
1165
|
}
|
|
803
|
-
this.log.error(`Error getting proposer for slot ${
|
|
1166
|
+
this.log.error(`Error getting proposer for target slot ${targetSlot}`, e);
|
|
804
1167
|
return [
|
|
805
1168
|
false,
|
|
806
1169
|
undefined
|
|
@@ -823,7 +1186,8 @@ export { SequencerState };
|
|
|
823
1186
|
const validatorAddresses = this.validatorClient.getValidatorAddresses();
|
|
824
1187
|
const weAreProposer = validatorAddresses.some((addr)=>addr.equals(proposer));
|
|
825
1188
|
if (!weAreProposer) {
|
|
826
|
-
this.log.debug(`Cannot propose at slot ${
|
|
1189
|
+
this.log.debug(`Cannot propose at target slot ${targetSlot} since we are not a proposer`, {
|
|
1190
|
+
targetSlot,
|
|
827
1191
|
validatorAddresses,
|
|
828
1192
|
proposer
|
|
829
1193
|
});
|
|
@@ -832,86 +1196,169 @@ export { SequencerState };
|
|
|
832
1196
|
proposer
|
|
833
1197
|
];
|
|
834
1198
|
}
|
|
1199
|
+
this.log.info(`We are the proposer for pipeline slot ${targetSlot}`, {
|
|
1200
|
+
targetSlot,
|
|
1201
|
+
proposer
|
|
1202
|
+
});
|
|
835
1203
|
return [
|
|
836
1204
|
true,
|
|
837
1205
|
proposer
|
|
838
1206
|
];
|
|
839
1207
|
}
|
|
840
1208
|
/**
|
|
841
|
-
* Tries to vote on slashing actions and governance
|
|
842
|
-
* This allows the sequencer to participate in governance/slashing votes even when it
|
|
843
|
-
|
|
844
|
-
|
|
1209
|
+
* Tries to vote on slashing actions and governance and to prune when we cannot build and are past the
|
|
1210
|
+
* block-building window. This allows the sequencer to participate in governance/slashing votes even when it
|
|
1211
|
+
* cannot build blocks, and to prune the pending chain so it can recover from bad data that is blocking sync.
|
|
1212
|
+
*/ async tryVoteAndPruneWhenCannotBuild(args) {
|
|
1213
|
+
const { slot, targetSlot } = args;
|
|
845
1214
|
// Prevent duplicate attempts in the same slot
|
|
846
|
-
if (this.
|
|
847
|
-
this.log.
|
|
1215
|
+
if (this.lastSlotForFallbackAction === slot) {
|
|
1216
|
+
this.log.trace(`Already attempted fallback actions in slot ${slot} (skipping)`);
|
|
848
1217
|
return;
|
|
849
1218
|
}
|
|
850
|
-
//
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
maxAllowedTime
|
|
859
|
-
});
|
|
860
|
-
return;
|
|
861
|
-
}
|
|
862
|
-
this.log.debug(`Sync for slot ${slot} failed, checking for voting opportunities`, {
|
|
863
|
-
secondsIntoSlot,
|
|
864
|
-
maxAllowedTime
|
|
1219
|
+
// Vote-only actions do not give up the slot: if sync recovers, a later work-loop iteration can still build.
|
|
1220
|
+
// Under proposer pipelining the work loop reasons about the next L1 slot, so waiting for the target slot's
|
|
1221
|
+
// build-start deadline can miss the whole fallback window when the target advances with the clock.
|
|
1222
|
+
const nowSeconds = this.dateProvider.now() / 1000;
|
|
1223
|
+
const startDeadline = this.timetable.getBuildStartDeadline(targetSlot);
|
|
1224
|
+
this.log.trace(`Cannot build for slot ${slot}, checking for voting opportunities`, {
|
|
1225
|
+
nowSeconds,
|
|
1226
|
+
startDeadline
|
|
865
1227
|
});
|
|
866
1228
|
// Check if we're a proposer or proposal is open
|
|
867
|
-
const [canPropose, proposer] = await this.checkCanPropose(
|
|
1229
|
+
const [canPropose, proposer] = await this.checkCanPropose(targetSlot);
|
|
868
1230
|
if (!canPropose) {
|
|
869
|
-
this.log.
|
|
1231
|
+
this.log.trace(`Cannot vote in slot ${slot} since we are not a proposer`, {
|
|
870
1232
|
slot,
|
|
871
1233
|
proposer
|
|
872
1234
|
});
|
|
873
1235
|
return;
|
|
874
1236
|
}
|
|
875
1237
|
// Mark this slot as attempted
|
|
876
|
-
this.
|
|
1238
|
+
this.lastSlotForFallbackAction = slot;
|
|
877
1239
|
// Get a publisher for voting
|
|
878
1240
|
const { attestorAddress, publisher } = await this.publisherFactory.create(proposer);
|
|
879
1241
|
this.log.debug(`Attempting to vote despite sync failure at slot ${slot}`, {
|
|
880
1242
|
attestorAddress,
|
|
881
1243
|
slot
|
|
882
1244
|
});
|
|
883
|
-
// Enqueue governance and slashing votes
|
|
884
|
-
const
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
1245
|
+
// Enqueue governance and slashing votes (voter uses the target slot for L1 submission)
|
|
1246
|
+
const voter = new CheckpointVoter(targetSlot, publisher, attestorAddress, this.validatorClient, this.slasherClient, this.l1Constants, this.config, this.metrics, this.log);
|
|
1247
|
+
const votesPromises = voter.enqueueVotes();
|
|
1248
|
+
const votes = await Promise.all(votesPromises);
|
|
1249
|
+
// Even if we cannot build, try to prune so a stuck pending chain (e.g. bad data blocking sync) can
|
|
1250
|
+
// recover. prune() is permissionless, so it rides the same fallback multicall as the votes.
|
|
1251
|
+
const pruneEnqueued = await this.tryEnqueuePruneIfPrunable(targetSlot, publisher);
|
|
1252
|
+
// Bail if nothing to do
|
|
1253
|
+
if (votes.every((p)=>!p) && !pruneEnqueued) {
|
|
1254
|
+
this.log.debug(`Nothing to enqueue for slot ${slot} (no votes, not prunable)`);
|
|
888
1255
|
return;
|
|
889
1256
|
}
|
|
890
|
-
|
|
891
|
-
|
|
1257
|
+
const [governanceVoteEnqueued, slashingVoteEnqueued] = votes;
|
|
1258
|
+
this.log.info(`Submitting fallback requests in slot ${slot} despite sync failure`, {
|
|
1259
|
+
slot,
|
|
1260
|
+
pruneEnqueued,
|
|
1261
|
+
governanceVoteEnqueued: !!governanceVoteEnqueued,
|
|
1262
|
+
slashingVoteEnqueued: !!slashingVoteEnqueued
|
|
892
1263
|
});
|
|
893
|
-
|
|
1264
|
+
// Votes are EIP-712-signed for `targetSlot` (the pipelined slot in which the multicall is
|
|
1265
|
+
// expected to mine). Delay submission to the start of `targetSlot` so the tx mines in the
|
|
1266
|
+
// slot the votes were signed for. We fire-and-forget so we don't block the sequencer's
|
|
1267
|
+
// work loop while waiting for the target slot to start, but track it so stop() can drain it.
|
|
1268
|
+
const send = publisher.sendRequestsAt(targetSlot).catch((err)=>{
|
|
1269
|
+
this.log.error(`Failed to publish fallback requests despite sync failure for slot ${slot}`, err, {
|
|
1270
|
+
slot
|
|
1271
|
+
});
|
|
1272
|
+
});
|
|
1273
|
+
this.pendingRequests.trackRequest(send, ()=>publisher.interrupt());
|
|
1274
|
+
}
|
|
1275
|
+
async tryEnqueuePruneIfPrunable(targetSlot, publisher) {
|
|
1276
|
+
try {
|
|
1277
|
+
return await publisher.enqueuePruneIfPrunable(targetSlot);
|
|
1278
|
+
} catch (err) {
|
|
1279
|
+
this.log.error(`Failed to enqueue rollup prune for slot ${targetSlot}`, err, {
|
|
1280
|
+
targetSlot
|
|
1281
|
+
});
|
|
1282
|
+
return false;
|
|
1283
|
+
}
|
|
1284
|
+
}
|
|
1285
|
+
/**
|
|
1286
|
+
* Tries to vote on slashing actions and governance proposals when escape hatch is open.
|
|
1287
|
+
* This allows the sequencer to participate in voting without performing checkpoint proposal work.
|
|
1288
|
+
*/ async tryVoteWhenEscapeHatchOpen(args) {
|
|
1289
|
+
const { slot, targetSlot, proposer } = args;
|
|
1290
|
+
// Prevent duplicate attempts in the same slot
|
|
1291
|
+
if (this.lastSlotForFallbackAction === slot) {
|
|
1292
|
+
this.log.trace(`Already attempted to vote in slot ${slot} (escape hatch open, skipping)`);
|
|
1293
|
+
return;
|
|
1294
|
+
}
|
|
1295
|
+
// Mark this slot as attempted
|
|
1296
|
+
this.lastSlotForFallbackAction = slot;
|
|
1297
|
+
const { attestorAddress, publisher } = await this.publisherFactory.create(proposer);
|
|
1298
|
+
this.log.debug(`Escape hatch open for slot ${slot}, attempting vote-only actions`, {
|
|
1299
|
+
slot,
|
|
1300
|
+
targetSlot,
|
|
1301
|
+
attestorAddress
|
|
1302
|
+
});
|
|
1303
|
+
// Under proposer pipelining, the multicall is expected to mine in `targetSlot` (slot + 1).
|
|
1304
|
+
// Governance and slashing votes are EIP-712-signed against the slot they will mine in, and the
|
|
1305
|
+
// L1 contract checks `msg.sender == getCurrentProposer()` using the mining slot. So we must
|
|
1306
|
+
// sign for `targetSlot` and delay submission to the start of `targetSlot`.
|
|
1307
|
+
const voter = new CheckpointVoter(targetSlot, publisher, attestorAddress, this.validatorClient, this.slasherClient, this.l1Constants, this.config, this.metrics, this.log);
|
|
1308
|
+
const votesPromises = voter.enqueueVotes();
|
|
1309
|
+
const votes = await Promise.all(votesPromises);
|
|
1310
|
+
if (votes.every((p)=>!p)) {
|
|
1311
|
+
this.log.debug(`No votes to enqueue for slot ${slot} (escape hatch open)`);
|
|
1312
|
+
return;
|
|
1313
|
+
}
|
|
1314
|
+
this.log.info(`Voting in slot ${slot} (escape hatch open)`, {
|
|
1315
|
+
slot,
|
|
1316
|
+
targetSlot
|
|
1317
|
+
});
|
|
1318
|
+
// Votes are EIP-712-signed for `targetSlot`. Delay submission to the start of `targetSlot` so
|
|
1319
|
+
// the multicall mines in the slot the votes were signed for; otherwise the L1 contract reads
|
|
1320
|
+
// `signaler = getCurrentProposer()` against the wrong slot and signature verification fails
|
|
1321
|
+
// silently inside Multicall3. Fire-and-forget so we don't block the sequencer's work loop while
|
|
1322
|
+
// waiting for the target slot to start, mirroring tryVoteAndPruneWhenCannotBuild, but tracked so
|
|
1323
|
+
// stop() can drain it.
|
|
1324
|
+
const send = publisher.sendRequestsAt(targetSlot).catch((err)=>{
|
|
1325
|
+
this.log.error(`Failed to publish escape-hatch votes for slot ${slot}`, err, {
|
|
1326
|
+
slot,
|
|
1327
|
+
targetSlot
|
|
1328
|
+
});
|
|
1329
|
+
});
|
|
1330
|
+
this.pendingRequests.trackRequest(send, ()=>publisher.interrupt());
|
|
894
1331
|
}
|
|
895
1332
|
/**
|
|
896
1333
|
* Considers invalidating a block if the pending chain is invalid. Depends on how long the invalid block
|
|
897
1334
|
* has been there without being invalidated and whether the sequencer is in the committee or not. We always
|
|
898
1335
|
* have the proposer try to invalidate, but if they fail, the sequencers in the committee are expected to try,
|
|
899
1336
|
* and if they fail, any sequencer will try as well.
|
|
900
|
-
|
|
901
|
-
|
|
1337
|
+
* @param pendingChainValidationStatus - The archiver's pending-chain validation status, authoritative on its own.
|
|
1338
|
+
* @param currentSlot - The wall-clock slot, used for committee lookup, the per-(checkpoint, slot) dedup guard, and logging.
|
|
1339
|
+
*/ async considerInvalidatingCheckpoint(pendingChainValidationStatus, currentSlot) {
|
|
902
1340
|
if (pendingChainValidationStatus.valid) {
|
|
903
1341
|
return;
|
|
904
1342
|
}
|
|
905
|
-
const
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
1343
|
+
const invalidCheckpointNumber = pendingChainValidationStatus.checkpoint.checkpointNumber;
|
|
1344
|
+
// Avoid re-running the committee lookup, simulation, and submission on every tick within a slot.
|
|
1345
|
+
// The guard is keyed by (checkpoint, slot) — so a different invalid checkpoint surfacing later in
|
|
1346
|
+
// the same slot is not suppressed — and is set only after a request is successfully simulated below,
|
|
1347
|
+
// so a transient simulation failure (or thresholds not yet met) still retries on the next tick.
|
|
1348
|
+
if (this.lastInvalidationAttempt?.slot === currentSlot && this.lastInvalidationAttempt.checkpointNumber === invalidCheckpointNumber) {
|
|
1349
|
+
this.log.trace(`Already attempted to invalidate checkpoint ${invalidCheckpointNumber} in slot ${currentSlot}`, {
|
|
1350
|
+
currentSlot,
|
|
1351
|
+
invalidCheckpointNumber
|
|
1352
|
+
});
|
|
1353
|
+
return;
|
|
1354
|
+
}
|
|
1355
|
+
const invalidCheckpointTimestamp = pendingChainValidationStatus.checkpoint.timestamp;
|
|
1356
|
+
const timeSinceChainInvalid = this.dateProvider.nowInSeconds() - Number(invalidCheckpointTimestamp);
|
|
909
1357
|
const ourValidatorAddresses = this.validatorClient.getValidatorAddresses();
|
|
910
1358
|
const { secondsBeforeInvalidatingBlockAsCommitteeMember, secondsBeforeInvalidatingBlockAsNonCommitteeMember } = this.config;
|
|
911
1359
|
const logData = {
|
|
912
|
-
invalidL1Timestamp:
|
|
913
|
-
|
|
914
|
-
invalidBlock: pendingChainValidationStatus.block,
|
|
1360
|
+
invalidL1Timestamp: invalidCheckpointTimestamp,
|
|
1361
|
+
invalidCheckpoint: pendingChainValidationStatus.checkpoint,
|
|
915
1362
|
secondsBeforeInvalidatingBlockAsCommitteeMember,
|
|
916
1363
|
secondsBeforeInvalidatingBlockAsNonCommitteeMember,
|
|
917
1364
|
ourValidatorAddresses,
|
|
@@ -924,26 +1371,73 @@ export { SequencerState };
|
|
|
924
1371
|
this.log.debug(`Not invalidating pending chain`, logData);
|
|
925
1372
|
return;
|
|
926
1373
|
}
|
|
927
|
-
|
|
928
|
-
if (
|
|
929
|
-
|
|
1374
|
+
let validatorToUse;
|
|
1375
|
+
if (invalidateAsCommitteeMember) {
|
|
1376
|
+
// When invalidating as a committee member, use first validator that's actually in the committee
|
|
1377
|
+
const { committee } = await this.epochCache.getCommittee(currentSlot);
|
|
1378
|
+
if (committee) {
|
|
1379
|
+
const committeeSet = new Set(committee.map((addr)=>addr.toString()));
|
|
1380
|
+
validatorToUse = ourValidatorAddresses.find((addr)=>committeeSet.has(addr.toString())) ?? ourValidatorAddresses[0];
|
|
1381
|
+
} else {
|
|
1382
|
+
validatorToUse = ourValidatorAddresses[0];
|
|
1383
|
+
}
|
|
1384
|
+
} else {
|
|
1385
|
+
// When invalidating as a non-committee member, use the first validator
|
|
1386
|
+
validatorToUse = ourValidatorAddresses[0];
|
|
1387
|
+
}
|
|
1388
|
+
const { publisher } = await this.publisherFactory.create(validatorToUse);
|
|
1389
|
+
const invalidateCheckpoint = await publisher.simulateInvalidateCheckpoint(pendingChainValidationStatus);
|
|
1390
|
+
if (!invalidateCheckpoint) {
|
|
1391
|
+
this.log.warn(`Failed to simulate invalidate checkpoint`, logData);
|
|
930
1392
|
return;
|
|
931
1393
|
}
|
|
932
|
-
|
|
933
|
-
|
|
1394
|
+
// We produced a valid invalidation request; record it so further ticks within this slot skip the
|
|
1395
|
+
// committee lookup, simulation, and submission above for this same invalid checkpoint.
|
|
1396
|
+
this.lastInvalidationAttempt = {
|
|
1397
|
+
slot: currentSlot,
|
|
1398
|
+
checkpointNumber: invalidCheckpointNumber
|
|
1399
|
+
};
|
|
1400
|
+
this.log.info(invalidateAsCommitteeMember ? `Invalidating checkpoint ${invalidCheckpointNumber} as committee member` : `Invalidating checkpoint ${invalidCheckpointNumber} as non-committee member`, logData);
|
|
1401
|
+
publisher.enqueueInvalidateCheckpoint(invalidateCheckpoint);
|
|
934
1402
|
if (!this.config.fishermanMode) {
|
|
935
1403
|
await publisher.sendRequests();
|
|
936
1404
|
} else {
|
|
937
|
-
this.log.info('Invalidating
|
|
1405
|
+
this.log.info('Invalidating checkpoint in fisherman mode, clearing pending requests');
|
|
938
1406
|
publisher.clearPendingRequests();
|
|
939
1407
|
}
|
|
940
1408
|
}
|
|
941
|
-
|
|
942
|
-
|
|
1409
|
+
logStrategyComparison(epoch, publisher) {
|
|
1410
|
+
const feeAnalyzer = publisher.getL1FeeAnalyzer();
|
|
1411
|
+
if (!feeAnalyzer) {
|
|
1412
|
+
return;
|
|
1413
|
+
}
|
|
1414
|
+
const comparison = feeAnalyzer.getStrategyComparison();
|
|
1415
|
+
if (comparison.length === 0) {
|
|
1416
|
+
this.log.debug(`No strategy data available yet for epoch ${epoch}`);
|
|
1417
|
+
return;
|
|
1418
|
+
}
|
|
1419
|
+
this.log.info(`L1 Fee Strategy Performance Report - End of Epoch ${epoch}`, {
|
|
1420
|
+
epoch: Number(epoch),
|
|
1421
|
+
totalAnalyses: comparison[0]?.totalAnalyses,
|
|
1422
|
+
strategies: comparison.map((s)=>({
|
|
1423
|
+
id: s.strategyId,
|
|
1424
|
+
name: s.strategyName,
|
|
1425
|
+
inclusionRate: `${(s.inclusionRate * 100).toFixed(1)}%`,
|
|
1426
|
+
inclusionCount: `${s.inclusionCount}/${s.totalAnalyses}`,
|
|
1427
|
+
avgCostEth: s.avgEstimatedCostEth.toFixed(6),
|
|
1428
|
+
totalCostEth: s.totalEstimatedCostEth.toFixed(6),
|
|
1429
|
+
avgOverpaymentEth: s.avgOverpaymentEth.toFixed(6),
|
|
1430
|
+
totalOverpaymentEth: s.totalOverpaymentEth.toFixed(6),
|
|
1431
|
+
avgPriorityFeeDeltaGwei: s.avgPriorityFeeDeltaGwei.toFixed(2)
|
|
1432
|
+
}))
|
|
1433
|
+
});
|
|
943
1434
|
}
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
1435
|
+
/**
|
|
1436
|
+
* Wall-clock seconds elapsed since the build-frame start of the given target slot
|
|
1437
|
+
* (`now − getBuildFrameStart(targetSlot)`). May be negative if called before the build frame opens.
|
|
1438
|
+
*/ getSecondsIntoBuildFrame(targetSlot) {
|
|
1439
|
+
const buildFrameStart = this.timetable.getBuildFrameStart(targetSlot);
|
|
1440
|
+
return Number((this.dateProvider.now() / 1000 - buildFrameStart).toFixed(3));
|
|
947
1441
|
}
|
|
948
1442
|
get aztecSlotDuration() {
|
|
949
1443
|
return this.l1Constants.slotDuration;
|
|
@@ -954,24 +1448,16 @@ export { SequencerState };
|
|
|
954
1448
|
getSlasherClient() {
|
|
955
1449
|
return this.slasherClient;
|
|
956
1450
|
}
|
|
1451
|
+
get tracer() {
|
|
1452
|
+
return this.metrics.tracer;
|
|
1453
|
+
}
|
|
1454
|
+
getValidatorAddresses() {
|
|
1455
|
+
return this.validatorClient?.getValidatorAddresses();
|
|
1456
|
+
}
|
|
1457
|
+
/** Updates the publisher factory's node keystore adapter after a keystore reload. */ updatePublisherNodeKeyStore(adapter) {
|
|
1458
|
+
this.publisherFactory.updateNodeKeyStore(adapter);
|
|
1459
|
+
}
|
|
1460
|
+
getConfig() {
|
|
1461
|
+
return this.config;
|
|
1462
|
+
}
|
|
957
1463
|
}
|
|
958
|
-
_ts_decorate([
|
|
959
|
-
trackSpan('Sequencer.work')
|
|
960
|
-
], Sequencer.prototype, "safeWork", null);
|
|
961
|
-
_ts_decorate([
|
|
962
|
-
trackSpan('Sequencer.buildBlockAndEnqueuePublish', (_validTxs, _proposalHeader, newGlobalVariables)=>({
|
|
963
|
-
[Attributes.BLOCK_NUMBER]: newGlobalVariables.blockNumber
|
|
964
|
-
}))
|
|
965
|
-
], Sequencer.prototype, "buildBlockAndEnqueuePublish", null);
|
|
966
|
-
_ts_decorate([
|
|
967
|
-
trackSpan('Sequencer.collectAttestations', (block, txHashes)=>({
|
|
968
|
-
[Attributes.BLOCK_NUMBER]: block.number,
|
|
969
|
-
[Attributes.BLOCK_ARCHIVE]: block.archive.toString(),
|
|
970
|
-
[Attributes.BLOCK_TXS_COUNT]: txHashes.length
|
|
971
|
-
}))
|
|
972
|
-
], Sequencer.prototype, "collectAttestations", null);
|
|
973
|
-
_ts_decorate([
|
|
974
|
-
trackSpan('Sequencer.enqueuePublishL2Block', (block)=>({
|
|
975
|
-
[Attributes.BLOCK_NUMBER]: block.number
|
|
976
|
-
}))
|
|
977
|
-
], Sequencer.prototype, "enqueuePublishL2Block", null);
|