@aztec/sequencer-client 0.0.1-commit.b655e406 → 0.0.1-commit.b6e433891
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dest/client/index.d.ts +1 -1
- package/dest/client/sequencer-client.d.ts +21 -16
- package/dest/client/sequencer-client.d.ts.map +1 -1
- package/dest/client/sequencer-client.js +75 -28
- package/dest/config.d.ts +35 -9
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +113 -42
- package/dest/global_variable_builder/global_builder.d.ts +20 -16
- package/dest/global_variable_builder/global_builder.d.ts.map +1 -1
- package/dest/global_variable_builder/global_builder.js +54 -40
- package/dest/global_variable_builder/index.d.ts +1 -1
- 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 +43 -20
- package/dest/publisher/config.d.ts.map +1 -1
- package/dest/publisher/config.js +109 -34
- package/dest/publisher/index.d.ts +2 -1
- package/dest/publisher/index.d.ts.map +1 -1
- 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 +59 -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 +1 -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 +34 -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 +2 -0
- package/dest/publisher/sequencer-publisher-factory.d.ts +15 -6
- package/dest/publisher/sequencer-publisher-factory.d.ts.map +1 -1
- package/dest/publisher/sequencer-publisher-factory.js +28 -3
- 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 +103 -69
- package/dest/publisher/sequencer-publisher.d.ts.map +1 -1
- package/dest/publisher/sequencer-publisher.js +999 -190
- package/dest/sequencer/checkpoint_proposal_job.d.ts +108 -0
- package/dest/sequencer/checkpoint_proposal_job.d.ts.map +1 -0
- package/dest/sequencer/checkpoint_proposal_job.js +1289 -0
- package/dest/sequencer/checkpoint_voter.d.ts +35 -0
- package/dest/sequencer/checkpoint_voter.d.ts.map +1 -0
- package/dest/sequencer/checkpoint_voter.js +109 -0
- package/dest/sequencer/config.d.ts +3 -2
- package/dest/sequencer/config.d.ts.map +1 -1
- package/dest/sequencer/errors.d.ts +1 -1
- package/dest/sequencer/errors.d.ts.map +1 -1
- package/dest/sequencer/events.d.ts +47 -0
- package/dest/sequencer/events.d.ts.map +1 -0
- package/dest/sequencer/events.js +1 -0
- package/dest/sequencer/index.d.ts +4 -2
- package/dest/sequencer/index.d.ts.map +1 -1
- package/dest/sequencer/index.js +3 -1
- package/dest/sequencer/metrics.d.ts +48 -3
- package/dest/sequencer/metrics.d.ts.map +1 -1
- package/dest/sequencer/metrics.js +243 -50
- package/dest/sequencer/sequencer.d.ts +127 -144
- package/dest/sequencer/sequencer.d.ts.map +1 -1
- package/dest/sequencer/sequencer.js +770 -545
- package/dest/sequencer/timetable.d.ts +54 -16
- package/dest/sequencer/timetable.d.ts.map +1 -1
- package/dest/sequencer/timetable.js +147 -62
- 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 +6 -7
- 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 +53 -0
- package/dest/test/utils.d.ts.map +1 -0
- package/dest/test/utils.js +104 -0
- package/package.json +32 -30
- package/src/client/sequencer-client.ts +100 -52
- package/src/config.ts +132 -51
- package/src/global_variable_builder/global_builder.ts +69 -60
- package/src/index.ts +1 -7
- package/src/publisher/config.ts +139 -50
- package/src/publisher/index.ts +3 -0
- package/src/publisher/l1_tx_failed_store/factory.ts +32 -0
- package/src/publisher/l1_tx_failed_store/failed_tx_store.ts +55 -0
- package/src/publisher/l1_tx_failed_store/file_store_failed_tx_store.ts +46 -0
- package/src/publisher/l1_tx_failed_store/index.ts +3 -0
- package/src/publisher/sequencer-publisher-factory.ts +45 -11
- package/src/publisher/sequencer-publisher-metrics.ts +19 -71
- package/src/publisher/sequencer-publisher.ts +717 -248
- package/src/sequencer/README.md +531 -0
- package/src/sequencer/checkpoint_proposal_job.ts +1049 -0
- package/src/sequencer/checkpoint_voter.ts +130 -0
- package/src/sequencer/config.ts +2 -1
- package/src/sequencer/events.ts +27 -0
- package/src/sequencer/index.ts +3 -1
- package/src/sequencer/metrics.ts +310 -61
- package/src/sequencer/sequencer.ts +541 -735
- package/src/sequencer/timetable.ts +178 -83
- package/src/sequencer/types.ts +6 -0
- package/src/sequencer/utils.ts +18 -9
- package/src/test/index.ts +5 -6
- package/src/test/mock_checkpoint_builder.ts +323 -0
- package/src/test/utils.ts +167 -0
- package/dest/sequencer/block_builder.d.ts +0 -27
- package/dest/sequencer/block_builder.d.ts.map +0 -1
- package/dest/sequencer/block_builder.js +0 -130
- package/dest/tx_validator/nullifier_cache.d.ts +0 -14
- package/dest/tx_validator/nullifier_cache.d.ts.map +0 -1
- package/dest/tx_validator/nullifier_cache.js +0 -24
- package/dest/tx_validator/tx_validator_factory.d.ts +0 -17
- package/dest/tx_validator/tx_validator_factory.d.ts.map +0 -1
- package/dest/tx_validator/tx_validator_factory.js +0 -53
- package/src/sequencer/block_builder.ts +0 -218
- package/src/tx_validator/nullifier_cache.ts +0 -30
- package/src/tx_validator/tx_validator_factory.ts +0 -132
|
@@ -1,45 +1,411 @@
|
|
|
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
|
+
};
|
|
369
|
+
}
|
|
370
|
+
function _apply_decs_2203_r(targetClass, memberDecs, classDecs, parentClass) {
|
|
371
|
+
return (_apply_decs_2203_r = applyDecs2203RFactory())(targetClass, memberDecs, classDecs, parentClass);
|
|
6
372
|
}
|
|
7
|
-
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
373
|
+
var _dec, _dec1, _dec2, _dec3, _initProto;
|
|
374
|
+
import { getKzg } from '@aztec/blob-lib';
|
|
375
|
+
import { INITIAL_L2_BLOCK_NUM } from '@aztec/constants';
|
|
376
|
+
import { NoCommitteeError } from '@aztec/ethereum/contracts';
|
|
377
|
+
import { BlockNumber, CheckpointNumber } from '@aztec/foundation/branded-types';
|
|
378
|
+
import { merge, omit, pick } from '@aztec/foundation/collection';
|
|
379
|
+
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
11
380
|
import { EthAddress } from '@aztec/foundation/eth-address';
|
|
12
|
-
import { Signature } from '@aztec/foundation/eth-signature';
|
|
13
|
-
import { Fr } from '@aztec/foundation/fields';
|
|
14
381
|
import { createLogger } from '@aztec/foundation/log';
|
|
15
382
|
import { RunningPromise } from '@aztec/foundation/running-promise';
|
|
16
|
-
import {
|
|
17
|
-
import { unfreeze } from '@aztec/foundation/types';
|
|
18
|
-
import { CommitteeAttestationsAndSigners } from '@aztec/stdlib/block';
|
|
19
|
-
import { getSlotAtTimestamp, getSlotStartBuildTimestamp } from '@aztec/stdlib/epoch-helpers';
|
|
20
|
-
import { Gas } from '@aztec/stdlib/gas';
|
|
383
|
+
import { getSlotStartBuildTimestamp } from '@aztec/stdlib/epoch-helpers';
|
|
21
384
|
import { SequencerConfigSchema } from '@aztec/stdlib/interfaces/server';
|
|
22
|
-
import { orderAttestations } from '@aztec/stdlib/p2p';
|
|
23
|
-
import { CheckpointHeader } from '@aztec/stdlib/rollup';
|
|
24
385
|
import { pickFromSchema } from '@aztec/stdlib/schemas';
|
|
25
386
|
import { MerkleTreeId } from '@aztec/stdlib/trees';
|
|
26
|
-
import { ContentCommitment } from '@aztec/stdlib/tx';
|
|
27
|
-
import { AttestationTimeoutError } from '@aztec/stdlib/validators';
|
|
28
387
|
import { Attributes, getTelemetryClient, trackSpan } from '@aztec/telemetry-client';
|
|
29
388
|
import EventEmitter from 'node:events';
|
|
389
|
+
import { DefaultSequencerConfig } from '../config.js';
|
|
390
|
+
import { CheckpointProposalJob } from './checkpoint_proposal_job.js';
|
|
391
|
+
import { CheckpointVoter } from './checkpoint_voter.js';
|
|
30
392
|
import { SequencerInterruptedError, SequencerTooSlowError } from './errors.js';
|
|
31
393
|
import { SequencerMetrics } from './metrics.js';
|
|
32
394
|
import { SequencerTimetable } from './timetable.js';
|
|
33
395
|
import { SequencerState } from './utils.js';
|
|
34
396
|
export { SequencerState };
|
|
397
|
+
_dec = trackSpan('Sequencer.work'), _dec1 = trackSpan('Sequencer.prepareCheckpointProposal'), _dec2 = trackSpan('Seqeuencer.tryVoteWhenSyncFails', ({ slot })=>({
|
|
398
|
+
[Attributes.SLOT_NUMBER]: slot
|
|
399
|
+
})), _dec3 = trackSpan('Sequencer.tryVoteWhenEscapeHatchOpen', ({ slot })=>({
|
|
400
|
+
[Attributes.SLOT_NUMBER]: slot
|
|
401
|
+
}));
|
|
35
402
|
/**
|
|
36
403
|
* Sequencer client
|
|
37
|
-
* -
|
|
38
|
-
* -
|
|
39
|
-
* -
|
|
40
|
-
* -
|
|
41
|
-
* -
|
|
42
|
-
* - Publishes L1 tx(s) to the rollup contract via RollupPublisher.
|
|
404
|
+
* - Checks whether it is elected as proposer for the next slot
|
|
405
|
+
* - Builds multiple blocks and broadcasts them
|
|
406
|
+
* - Collects attestations for the checkpoint
|
|
407
|
+
* - Publishes the checkpoint to L1
|
|
408
|
+
* - Votes for proposals and slashes on L1
|
|
43
409
|
*/ export class Sequencer extends EventEmitter {
|
|
44
410
|
publisherFactory;
|
|
45
411
|
validatorClient;
|
|
@@ -49,145 +415,167 @@ export { SequencerState };
|
|
|
49
415
|
slasherClient;
|
|
50
416
|
l2BlockSource;
|
|
51
417
|
l1ToL2MessageSource;
|
|
52
|
-
|
|
418
|
+
checkpointsBuilder;
|
|
53
419
|
l1Constants;
|
|
54
420
|
dateProvider;
|
|
55
421
|
epochCache;
|
|
56
422
|
rollupContract;
|
|
57
|
-
config;
|
|
58
423
|
telemetry;
|
|
59
424
|
log;
|
|
425
|
+
static{
|
|
426
|
+
({ e: [_initProto] } = _apply_decs_2203_r(this, [
|
|
427
|
+
[
|
|
428
|
+
_dec,
|
|
429
|
+
2,
|
|
430
|
+
"work"
|
|
431
|
+
],
|
|
432
|
+
[
|
|
433
|
+
_dec1,
|
|
434
|
+
2,
|
|
435
|
+
"prepareCheckpointProposal"
|
|
436
|
+
],
|
|
437
|
+
[
|
|
438
|
+
_dec2,
|
|
439
|
+
2,
|
|
440
|
+
"tryVoteWhenSyncFails"
|
|
441
|
+
],
|
|
442
|
+
[
|
|
443
|
+
_dec3,
|
|
444
|
+
2,
|
|
445
|
+
"tryVoteWhenEscapeHatchOpen"
|
|
446
|
+
]
|
|
447
|
+
], []));
|
|
448
|
+
}
|
|
60
449
|
runningPromise;
|
|
61
|
-
pollingIntervalMs;
|
|
62
|
-
maxTxsPerBlock;
|
|
63
|
-
minTxsPerBlock;
|
|
64
|
-
maxL1TxInclusionTimeIntoSlot;
|
|
65
450
|
state;
|
|
66
|
-
maxBlockSizeInBytes;
|
|
67
|
-
maxBlockGas;
|
|
68
451
|
metrics;
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
/** The last slot for which we
|
|
452
|
+
/** The last slot for which we attempted to perform our voting duties with degraded block production */ lastSlotForFallbackVote;
|
|
453
|
+
/** The last slot for which we logged "no committee" warning, to avoid spam */ lastSlotForNoCommitteeWarning;
|
|
454
|
+
/** The last slot for which we triggered a checkpoint proposal job, to prevent duplicate attempts. */ lastSlotForCheckpointProposalJob;
|
|
455
|
+
/** Last successful checkpoint proposed */ lastCheckpointProposed;
|
|
456
|
+
/** The last epoch for which we logged strategy comparison in fisherman mode. */ lastEpochForStrategyComparison;
|
|
72
457
|
/** The maximum number of seconds that the sequencer can be into a slot to transition to a particular state. */ timetable;
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
publisher;
|
|
80
|
-
constructor(publisherFactory, validatorClient, globalsBuilder, p2pClient, worldState, slasherClient, l2BlockSource, l1ToL2MessageSource, blockBuilder, l1Constants, dateProvider, epochCache, rollupContract, config, telemetry = getTelemetryClient(), log = createLogger('sequencer')){
|
|
81
|
-
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.blockBuilder = blockBuilder, this.l1Constants = l1Constants, this.dateProvider = dateProvider, this.epochCache = epochCache, this.rollupContract = rollupContract, this.config = config, this.telemetry = telemetry, this.log = log, this.pollingIntervalMs = 1000, this.maxTxsPerBlock = 32, this.minTxsPerBlock = 1, this.maxL1TxInclusionTimeIntoSlot = 0, this.state = SequencerState.STOPPED, this.maxBlockSizeInBytes = 1024 * 1024, this.maxBlockGas = new Gas(100e9, 100e9), this.enforceTimeTable = false;
|
|
82
|
-
this.metrics = new SequencerMetrics(telemetry, this.rollupContract, 'Sequencer');
|
|
83
|
-
// Initialize config
|
|
84
|
-
this.updateConfig(this.config);
|
|
85
|
-
}
|
|
86
|
-
get tracer() {
|
|
87
|
-
return this.metrics.tracer;
|
|
88
|
-
}
|
|
89
|
-
getValidatorAddresses() {
|
|
90
|
-
return this.validatorClient?.getValidatorAddresses();
|
|
91
|
-
}
|
|
92
|
-
getConfig() {
|
|
93
|
-
return this.config;
|
|
94
|
-
}
|
|
95
|
-
/**
|
|
96
|
-
* Updates sequencer config by the defined values in the config on input.
|
|
97
|
-
* @param config - New parameters.
|
|
98
|
-
*/ updateConfig(config) {
|
|
99
|
-
this.log.info(`Sequencer config set`, omit(pickFromSchema(config, SequencerConfigSchema), 'txPublicSetupAllowList'));
|
|
100
|
-
if (config.transactionPollingIntervalMS !== undefined) {
|
|
101
|
-
this.pollingIntervalMs = config.transactionPollingIntervalMS;
|
|
102
|
-
}
|
|
103
|
-
if (config.maxTxsPerBlock !== undefined) {
|
|
104
|
-
this.maxTxsPerBlock = config.maxTxsPerBlock;
|
|
105
|
-
}
|
|
106
|
-
if (config.minTxsPerBlock !== undefined) {
|
|
107
|
-
this.minTxsPerBlock = config.minTxsPerBlock;
|
|
108
|
-
}
|
|
109
|
-
if (config.maxDABlockGas !== undefined) {
|
|
110
|
-
this.maxBlockGas = new Gas(config.maxDABlockGas, this.maxBlockGas.l2Gas);
|
|
111
|
-
}
|
|
112
|
-
if (config.maxL2BlockGas !== undefined) {
|
|
113
|
-
this.maxBlockGas = new Gas(this.maxBlockGas.daGas, config.maxL2BlockGas);
|
|
114
|
-
}
|
|
115
|
-
if (config.maxBlockSizeInBytes !== undefined) {
|
|
116
|
-
this.maxBlockSizeInBytes = config.maxBlockSizeInBytes;
|
|
117
|
-
}
|
|
118
|
-
if (config.governanceProposerPayload) {
|
|
119
|
-
this.governanceProposerPayload = config.governanceProposerPayload;
|
|
120
|
-
}
|
|
121
|
-
if (config.maxL1TxInclusionTimeIntoSlot !== undefined) {
|
|
122
|
-
this.maxL1TxInclusionTimeIntoSlot = config.maxL1TxInclusionTimeIntoSlot;
|
|
458
|
+
/** Config for the sequencer */ config;
|
|
459
|
+
constructor(publisherFactory, validatorClient, globalsBuilder, p2pClient, worldState, slasherClient, l2BlockSource, l1ToL2MessageSource, checkpointsBuilder, l1Constants, dateProvider, epochCache, rollupContract, config, telemetry = getTelemetryClient(), log = createLogger('sequencer')){
|
|
460
|
+
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.config = DefaultSequencerConfig;
|
|
461
|
+
// Add [FISHERMAN] prefix to logger if in fisherman mode
|
|
462
|
+
if (config.fishermanMode) {
|
|
463
|
+
this.log = log.createChild('[FISHERMAN]');
|
|
123
464
|
}
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
}
|
|
127
|
-
this.setTimeTable();
|
|
128
|
-
// TODO: Just read everything from the config object as needed instead of copying everything into local vars.
|
|
129
|
-
// Update all values on this.config that are populated in the config object.
|
|
130
|
-
Object.assign(this.config, config);
|
|
465
|
+
this.metrics = new SequencerMetrics(telemetry, this.rollupContract, 'Sequencer');
|
|
466
|
+
this.updateConfig(config);
|
|
131
467
|
}
|
|
132
|
-
|
|
468
|
+
/** Updates sequencer config by the defined values and updates the timetable */ updateConfig(config) {
|
|
469
|
+
const filteredConfig = pickFromSchema(config, SequencerConfigSchema);
|
|
470
|
+
this.log.info(`Updated sequencer config`, omit(filteredConfig, 'txPublicSetupAllowListExtend'));
|
|
471
|
+
this.config = merge(this.config, filteredConfig);
|
|
133
472
|
this.timetable = new SequencerTimetable({
|
|
134
473
|
ethereumSlotDuration: this.l1Constants.ethereumSlotDuration,
|
|
135
474
|
aztecSlotDuration: this.aztecSlotDuration,
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
475
|
+
l1PublishingTime: this.l1PublishingTime,
|
|
476
|
+
p2pPropagationTime: this.config.attestationPropagationTime,
|
|
477
|
+
blockDurationMs: this.config.blockDurationMs,
|
|
478
|
+
enforce: this.config.enforceTimeTable
|
|
139
479
|
}, this.metrics, this.log);
|
|
140
480
|
}
|
|
141
|
-
|
|
142
|
-
|
|
481
|
+
/** Initializes the sequencer (precomputes tables). Takes about 3s. */ init() {
|
|
482
|
+
getKzg();
|
|
143
483
|
}
|
|
144
|
-
/**
|
|
145
|
-
|
|
146
|
-
*/ start() {
|
|
147
|
-
this.runningPromise = new RunningPromise(this.safeWork.bind(this), this.log, this.pollingIntervalMs);
|
|
484
|
+
/** Starts the sequencer and moves to IDLE state. */ start() {
|
|
485
|
+
this.runningPromise = new RunningPromise(this.safeWork.bind(this), this.log, this.config.sequencerPollingIntervalMS);
|
|
148
486
|
this.setState(SequencerState.IDLE, undefined, {
|
|
149
487
|
force: true
|
|
150
488
|
});
|
|
151
489
|
this.runningPromise.start();
|
|
152
490
|
this.log.info('Started sequencer');
|
|
153
491
|
}
|
|
154
|
-
/**
|
|
155
|
-
* Stops the sequencer from processing txs and moves to STOPPED state.
|
|
156
|
-
*/ async stop() {
|
|
492
|
+
/** Stops the sequencer from building blocks and moves to STOPPED state. */ async stop() {
|
|
157
493
|
this.log.info(`Stopping sequencer`);
|
|
158
494
|
this.setState(SequencerState.STOPPING, undefined, {
|
|
159
495
|
force: true
|
|
160
496
|
});
|
|
161
|
-
this.
|
|
497
|
+
this.publisherFactory.interruptAll();
|
|
162
498
|
await this.runningPromise?.stop();
|
|
163
499
|
this.setState(SequencerState.STOPPED, undefined, {
|
|
164
500
|
force: true
|
|
165
501
|
});
|
|
166
502
|
this.log.info('Stopped sequencer');
|
|
167
503
|
}
|
|
168
|
-
/**
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
504
|
+
/** Main sequencer loop with a try/catch */ async safeWork() {
|
|
505
|
+
try {
|
|
506
|
+
await this.work();
|
|
507
|
+
} catch (err) {
|
|
508
|
+
this.emit('checkpoint-error', {
|
|
509
|
+
error: err
|
|
510
|
+
});
|
|
511
|
+
if (err instanceof SequencerTooSlowError) {
|
|
512
|
+
// Log as warn only if we had to abort halfway through the block proposal
|
|
513
|
+
const logLvl = [
|
|
514
|
+
SequencerState.INITIALIZING_CHECKPOINT,
|
|
515
|
+
SequencerState.PROPOSER_CHECK
|
|
516
|
+
].includes(err.proposedState) ? 'debug' : 'warn';
|
|
517
|
+
this.log[logLvl](err.message, {
|
|
518
|
+
now: this.dateProvider.nowInSeconds()
|
|
519
|
+
});
|
|
520
|
+
} else {
|
|
521
|
+
// Re-throw other errors
|
|
522
|
+
throw err;
|
|
523
|
+
}
|
|
524
|
+
} finally{
|
|
525
|
+
this.setState(SequencerState.IDLE, undefined);
|
|
526
|
+
}
|
|
527
|
+
}
|
|
528
|
+
/** Returns the current state of the sequencer. */ status() {
|
|
172
529
|
return {
|
|
173
530
|
state: this.state
|
|
174
531
|
};
|
|
175
532
|
}
|
|
176
533
|
/**
|
|
177
|
-
*
|
|
178
|
-
*
|
|
179
|
-
*
|
|
180
|
-
*
|
|
181
|
-
*
|
|
182
|
-
*
|
|
534
|
+
* Main sequencer loop:
|
|
535
|
+
* - Checks if we are up to date
|
|
536
|
+
* - If we are and we are the sequencer, collect txs and build blocks
|
|
537
|
+
* - Build multiple blocks per slot when configured
|
|
538
|
+
* - Collect attestations for the final block
|
|
539
|
+
* - Submit checkpoint
|
|
183
540
|
*/ async work() {
|
|
184
541
|
this.setState(SequencerState.SYNCHRONIZING, undefined);
|
|
185
|
-
const { slot, ts,
|
|
186
|
-
|
|
187
|
-
if
|
|
188
|
-
|
|
542
|
+
const { slot, ts, nowSeconds, epoch } = this.epochCache.getEpochAndSlotInNextL1Slot();
|
|
543
|
+
const { slot: targetSlot, epoch: targetEpoch } = this.epochCache.getTargetEpochAndSlotInNextL1Slot();
|
|
544
|
+
// Check if we are synced and it's our slot, grab a publisher, check previous block invalidation, etc
|
|
545
|
+
const checkpointProposalJob = await this.prepareCheckpointProposal(slot, targetSlot, epoch, targetEpoch, ts, nowSeconds);
|
|
546
|
+
if (!checkpointProposalJob) {
|
|
189
547
|
return;
|
|
190
548
|
}
|
|
549
|
+
// Execute the checkpoint proposal job
|
|
550
|
+
const checkpoint = await checkpointProposalJob.execute();
|
|
551
|
+
// Update last checkpoint proposed (currently unused)
|
|
552
|
+
if (checkpoint) {
|
|
553
|
+
this.lastCheckpointProposed = checkpoint;
|
|
554
|
+
}
|
|
555
|
+
// Log fee strategy comparison if on fisherman (uses target epoch since we mirror the proposer's perspective)
|
|
556
|
+
if (this.config.fishermanMode && (this.lastEpochForStrategyComparison === undefined || targetEpoch > this.lastEpochForStrategyComparison)) {
|
|
557
|
+
this.logStrategyComparison(targetEpoch, checkpointProposalJob.getPublisher());
|
|
558
|
+
this.lastEpochForStrategyComparison = targetEpoch;
|
|
559
|
+
}
|
|
560
|
+
return checkpoint;
|
|
561
|
+
}
|
|
562
|
+
/**
|
|
563
|
+
* Prepares the checkpoint proposal by performing all necessary checks and setup.
|
|
564
|
+
* This is the initial step in the main loop.
|
|
565
|
+
* @returns CheckpointProposalJob if successful, undefined if we are not yet synced or are not the proposer.
|
|
566
|
+
*/ async prepareCheckpointProposal(slot, targetSlot, epoch, targetEpoch, ts, nowSeconds) {
|
|
567
|
+
// Check we have not already processed this target slot (cheapest check)
|
|
568
|
+
// We only check this if enforce timetable is set, since we want to keep processing the same slot if we are not
|
|
569
|
+
// running against actual time (eg when we use sandbox-style automining)
|
|
570
|
+
if (this.lastSlotForCheckpointProposalJob && this.lastSlotForCheckpointProposalJob >= targetSlot && this.config.enforceTimeTable) {
|
|
571
|
+
this.log.trace(`Target slot ${targetSlot} has already been processed`);
|
|
572
|
+
return undefined;
|
|
573
|
+
}
|
|
574
|
+
// But if we have already proposed for this slot, then we definitely have to skip it, automining or not
|
|
575
|
+
if (this.lastCheckpointProposed && this.lastCheckpointProposed.header.slotNumber >= targetSlot) {
|
|
576
|
+
this.log.trace(`Slot ${targetSlot} has already been published as checkpoint ${this.lastCheckpointProposed.number}`);
|
|
577
|
+
return undefined;
|
|
578
|
+
}
|
|
191
579
|
// Check all components are synced to latest as seen by the archiver (queries all subsystems)
|
|
192
580
|
const syncedTo = await this.checkSync({
|
|
193
581
|
ts,
|
|
@@ -196,182 +584,138 @@ export { SequencerState };
|
|
|
196
584
|
if (!syncedTo) {
|
|
197
585
|
await this.tryVoteWhenSyncFails({
|
|
198
586
|
slot,
|
|
587
|
+
targetSlot,
|
|
199
588
|
ts
|
|
200
589
|
});
|
|
201
|
-
return;
|
|
590
|
+
return undefined;
|
|
591
|
+
}
|
|
592
|
+
// If escape hatch is open for the target epoch, do not start checkpoint proposal work and do not attempt invalidations.
|
|
593
|
+
// Still perform governance/slashing voting (as proposer) once per slot.
|
|
594
|
+
// When pipelining, we check the target epoch (slot+1's epoch) since that's the epoch we're building for.
|
|
595
|
+
const isEscapeHatchOpen = await this.epochCache.isEscapeHatchOpen(targetEpoch);
|
|
596
|
+
if (isEscapeHatchOpen) {
|
|
597
|
+
this.setState(SequencerState.PROPOSER_CHECK, slot);
|
|
598
|
+
const [canPropose, proposer] = await this.checkCanPropose(targetSlot);
|
|
599
|
+
if (canPropose) {
|
|
600
|
+
await this.tryVoteWhenEscapeHatchOpen({
|
|
601
|
+
slot,
|
|
602
|
+
proposer
|
|
603
|
+
});
|
|
604
|
+
} else {
|
|
605
|
+
this.log.trace(`Escape hatch open but we are not proposer, skipping vote-only actions`, {
|
|
606
|
+
slot,
|
|
607
|
+
epoch,
|
|
608
|
+
proposer
|
|
609
|
+
});
|
|
610
|
+
}
|
|
611
|
+
return undefined;
|
|
202
612
|
}
|
|
203
|
-
|
|
204
|
-
const
|
|
205
|
-
const
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
newBlockNumber,
|
|
613
|
+
// Next checkpoint follows from the last synced one
|
|
614
|
+
const checkpointNumber = CheckpointNumber(syncedTo.checkpointNumber + 1);
|
|
615
|
+
const logCtx = {
|
|
616
|
+
nowSeconds,
|
|
617
|
+
syncedToL2Slot: syncedTo.syncedL2Slot,
|
|
618
|
+
slot,
|
|
619
|
+
targetSlot,
|
|
620
|
+
slotTs: ts,
|
|
621
|
+
checkpointNumber,
|
|
213
622
|
isPendingChainValid: pick(syncedTo.pendingChainValidationStatus, 'valid', 'reason', 'invalidIndex')
|
|
214
623
|
};
|
|
215
|
-
// Check that we are a proposer for the
|
|
624
|
+
// Check that we are a proposer for the target slot.
|
|
216
625
|
this.setState(SequencerState.PROPOSER_CHECK, slot);
|
|
217
|
-
const [canPropose, proposer] = await this.checkCanPropose(
|
|
218
|
-
// If we are not a proposer
|
|
626
|
+
const [canPropose, proposer] = await this.checkCanPropose(targetSlot);
|
|
627
|
+
// If we are not a proposer check if we should invalidate an invalid checkpoint, and bail
|
|
219
628
|
if (!canPropose) {
|
|
220
|
-
await this.
|
|
221
|
-
return;
|
|
629
|
+
await this.considerInvalidatingCheckpoint(syncedTo, slot);
|
|
630
|
+
return undefined;
|
|
222
631
|
}
|
|
223
|
-
// Check that the slot is not taken by a block already (should never happen, since only us can propose for this slot)
|
|
224
|
-
if (syncedTo.
|
|
225
|
-
this.log.warn(`Cannot propose block at
|
|
226
|
-
...
|
|
227
|
-
block: syncedTo.
|
|
632
|
+
// Check that the target slot is not taken by a block already (should never happen, since only us can propose for this slot)
|
|
633
|
+
if (syncedTo.blockData && syncedTo.blockData.header.getSlot() >= targetSlot) {
|
|
634
|
+
this.log.warn(`Cannot propose block at target slot ${targetSlot} since that slot was taken by block ${syncedTo.blockNumber}`, {
|
|
635
|
+
...logCtx,
|
|
636
|
+
block: syncedTo.blockData.header.toInspect()
|
|
228
637
|
});
|
|
229
|
-
|
|
638
|
+
this.metrics.recordCheckpointPrecheckFailed('slot_already_taken');
|
|
639
|
+
return undefined;
|
|
230
640
|
}
|
|
231
641
|
// We now need to get ourselves a publisher.
|
|
232
642
|
// The returned attestor will be the one we provided if we provided one.
|
|
233
643
|
// Otherwise it will be a valid attestor for the returned publisher.
|
|
234
|
-
|
|
644
|
+
// In fisherman mode, pass undefined to use the fisherman's own keystore instead of the actual proposer's
|
|
645
|
+
const proposerForPublisher = this.config.fishermanMode ? undefined : proposer;
|
|
646
|
+
const { attestorAddress, publisher } = await this.publisherFactory.create(proposerForPublisher);
|
|
235
647
|
this.log.verbose(`Created publisher at address ${publisher.getSenderAddress()} for attestor ${attestorAddress}`);
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
648
|
+
// In fisherman mode, set the actual proposer's address for simulations
|
|
649
|
+
if (this.config.fishermanMode && proposer) {
|
|
650
|
+
publisher.setProposerAddressForSimulation(proposer);
|
|
651
|
+
this.log.debug(`Set proposer address ${proposer} for simulation in fisherman mode`);
|
|
652
|
+
}
|
|
239
653
|
// Prepare invalidation request if the pending chain is invalid (returns undefined if no need)
|
|
240
|
-
const
|
|
241
|
-
// Check with the rollup if we can indeed propose at the
|
|
654
|
+
const invalidateCheckpoint = await publisher.simulateInvalidateCheckpoint(syncedTo.pendingChainValidationStatus);
|
|
655
|
+
// Check with the rollup contract if we can indeed propose at the target slot. This check should not fail
|
|
242
656
|
// if all the previous checks are good, but we do it just in case.
|
|
243
|
-
const canProposeCheck = await publisher.
|
|
657
|
+
const canProposeCheck = await publisher.canProposeAt(syncedTo.archive, proposer ?? EthAddress.ZERO, {
|
|
658
|
+
...invalidateCheckpoint
|
|
659
|
+
});
|
|
244
660
|
if (canProposeCheck === undefined) {
|
|
245
|
-
this.log.warn(`Cannot propose
|
|
661
|
+
this.log.warn(`Cannot propose checkpoint ${checkpointNumber} at slot ${slot} due to failed rollup contract check`, logCtx);
|
|
246
662
|
this.emit('proposer-rollup-check-failed', {
|
|
247
|
-
reason: 'Rollup contract check failed'
|
|
663
|
+
reason: 'Rollup contract check failed',
|
|
664
|
+
slot
|
|
248
665
|
});
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
666
|
+
this.metrics.recordCheckpointPrecheckFailed('rollup_contract_check_failed');
|
|
667
|
+
return undefined;
|
|
668
|
+
}
|
|
669
|
+
if (canProposeCheck.slot !== targetSlot) {
|
|
670
|
+
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}.`, {
|
|
671
|
+
...logCtx,
|
|
253
672
|
rollup: canProposeCheck,
|
|
254
|
-
|
|
255
|
-
expectedSlot: slot
|
|
673
|
+
expectedSlot: targetSlot
|
|
256
674
|
});
|
|
257
675
|
this.emit('proposer-rollup-check-failed', {
|
|
258
|
-
reason: 'Slot mismatch'
|
|
676
|
+
reason: 'Slot mismatch',
|
|
677
|
+
slot
|
|
259
678
|
});
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
679
|
+
this.metrics.recordCheckpointPrecheckFailed('slot_mismatch');
|
|
680
|
+
return undefined;
|
|
681
|
+
}
|
|
682
|
+
if (canProposeCheck.checkpointNumber !== checkpointNumber) {
|
|
683
|
+
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}.`, {
|
|
684
|
+
...logCtx,
|
|
264
685
|
rollup: canProposeCheck,
|
|
265
|
-
newBlockNumber,
|
|
266
686
|
expectedSlot: slot
|
|
267
687
|
});
|
|
268
688
|
this.emit('proposer-rollup-check-failed', {
|
|
269
|
-
reason: 'Block mismatch'
|
|
270
|
-
|
|
271
|
-
return;
|
|
272
|
-
}
|
|
273
|
-
this.log.debug(`Can propose block ${newBlockNumber} at slot ${slot} as ${proposer}`, {
|
|
274
|
-
...syncLogData
|
|
275
|
-
});
|
|
276
|
-
const newGlobalVariables = await this.globalsBuilder.buildGlobalVariables(newBlockNumber, coinbase, feeRecipient, slot);
|
|
277
|
-
// Enqueue governance and slashing votes (returns promises that will be awaited later)
|
|
278
|
-
const votesPromises = this.enqueueGovernanceAndSlashingVotes(publisher, attestorAddress, slot, newGlobalVariables.timestamp);
|
|
279
|
-
// Enqueues block invalidation
|
|
280
|
-
if (invalidateBlock && !this.config.skipInvalidateBlockAsProposer) {
|
|
281
|
-
publisher.enqueueInvalidateBlock(invalidateBlock);
|
|
282
|
-
}
|
|
283
|
-
// Actual block building
|
|
284
|
-
this.setState(SequencerState.INITIALIZING_PROPOSAL, slot);
|
|
285
|
-
const block = await this.tryBuildBlockAndEnqueuePublish(slot, proposer, newBlockNumber, publisher, newGlobalVariables, chainTipArchive, invalidateBlock);
|
|
286
|
-
// Wait until the voting promises have resolved, so all requests are enqueued
|
|
287
|
-
await Promise.all(votesPromises);
|
|
288
|
-
// And send the tx to L1
|
|
289
|
-
const l1Response = await publisher.sendRequests();
|
|
290
|
-
const proposedBlock = l1Response?.successfulActions.find((a)=>a === 'propose');
|
|
291
|
-
if (proposedBlock) {
|
|
292
|
-
this.lastBlockPublished = block;
|
|
293
|
-
this.emit('block-published', {
|
|
294
|
-
blockNumber: newBlockNumber,
|
|
295
|
-
slot: Number(slot)
|
|
689
|
+
reason: 'Block mismatch',
|
|
690
|
+
slot
|
|
296
691
|
});
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
this.emit('block-publish-failed', l1Response ?? {});
|
|
692
|
+
this.metrics.recordCheckpointPrecheckFailed('block_number_mismatch');
|
|
693
|
+
return undefined;
|
|
300
694
|
}
|
|
301
|
-
this.
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
695
|
+
this.lastSlotForCheckpointProposalJob = targetSlot;
|
|
696
|
+
await this.p2pClient.prepareForSlot(targetSlot);
|
|
697
|
+
this.log.info(`Preparing checkpoint proposal ${checkpointNumber} for target slot ${targetSlot} during wall-clock slot ${slot}`, {
|
|
698
|
+
...logCtx,
|
|
305
699
|
proposer,
|
|
306
|
-
|
|
307
|
-
globalVariables: newGlobalVariables.toInspect(),
|
|
308
|
-
chainTipArchive,
|
|
309
|
-
blockNumber: newBlockNumber,
|
|
310
|
-
slot
|
|
700
|
+
pipeliningEnabled: this.epochCache.isProposerPipeliningEnabled()
|
|
311
701
|
});
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
timestamp: newGlobalVariables.timestamp,
|
|
315
|
-
lastArchiveRoot: chainTipArchive,
|
|
316
|
-
contentCommitment: ContentCommitment.empty(),
|
|
317
|
-
totalManaUsed: Fr.ZERO
|
|
318
|
-
});
|
|
319
|
-
let block;
|
|
320
|
-
const pendingTxCount = await this.p2pClient.getPendingTxCount();
|
|
321
|
-
if (pendingTxCount >= this.minTxsPerBlock) {
|
|
322
|
-
// We don't fetch exactly maxTxsPerBlock txs here because we may not need all of them if we hit a limit before,
|
|
323
|
-
// and also we may need to fetch more if we don't have enough valid txs.
|
|
324
|
-
const pendingTxs = this.p2pClient.iteratePendingTxs();
|
|
325
|
-
try {
|
|
326
|
-
block = await this.buildBlockAndEnqueuePublish(pendingTxs, proposalHeader, newGlobalVariables, proposer, invalidateBlock, publisher);
|
|
327
|
-
} catch (err) {
|
|
328
|
-
this.emit('block-build-failed', {
|
|
329
|
-
reason: err.message
|
|
330
|
-
});
|
|
331
|
-
if (err instanceof FormattedViemError) {
|
|
332
|
-
this.log.verbose(`Unable to build/enqueue block ${err.message}`);
|
|
333
|
-
} else {
|
|
334
|
-
this.log.error(`Error building/enqueuing block`, err, {
|
|
335
|
-
blockNumber: newBlockNumber,
|
|
336
|
-
slot
|
|
337
|
-
});
|
|
338
|
-
}
|
|
339
|
-
}
|
|
340
|
-
} else {
|
|
341
|
-
this.log.verbose(`Not enough txs to build block ${newBlockNumber} at slot ${slot} (got ${pendingTxCount} txs, need ${this.minTxsPerBlock})`, {
|
|
342
|
-
chainTipArchive,
|
|
343
|
-
blockNumber: newBlockNumber,
|
|
344
|
-
slot
|
|
345
|
-
});
|
|
346
|
-
this.emit('tx-count-check-failed', {
|
|
347
|
-
minTxs: this.minTxsPerBlock,
|
|
348
|
-
availableTxs: pendingTxCount
|
|
349
|
-
});
|
|
350
|
-
}
|
|
351
|
-
return block;
|
|
702
|
+
// Create and return the checkpoint proposal job
|
|
703
|
+
return this.createCheckpointProposalJob(slot, targetSlot, epoch, targetEpoch, checkpointNumber, syncedTo.blockNumber, proposer, publisher, attestorAddress, invalidateCheckpoint);
|
|
352
704
|
}
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
await this.work();
|
|
356
|
-
} catch (err) {
|
|
357
|
-
if (err instanceof SequencerTooSlowError) {
|
|
358
|
-
// Log as warn only if we had to abort halfway through the block proposal
|
|
359
|
-
const logLvl = [
|
|
360
|
-
SequencerState.INITIALIZING_PROPOSAL,
|
|
361
|
-
SequencerState.PROPOSER_CHECK
|
|
362
|
-
].includes(err.proposedState) ? 'debug' : 'warn';
|
|
363
|
-
this.log[logLvl](err.message, {
|
|
364
|
-
now: this.dateProvider.nowInSeconds()
|
|
365
|
-
});
|
|
366
|
-
} else {
|
|
367
|
-
// Re-throw other errors
|
|
368
|
-
throw err;
|
|
369
|
-
}
|
|
370
|
-
} finally{
|
|
371
|
-
this.setState(SequencerState.IDLE, undefined);
|
|
372
|
-
}
|
|
705
|
+
createCheckpointProposalJob(slot, targetSlot, epoch, targetEpoch, checkpointNumber, syncedToBlockNumber, proposer, publisher, attestorAddress, invalidateCheckpoint) {
|
|
706
|
+
return new CheckpointProposalJob(slot, targetSlot, epoch, targetEpoch, checkpointNumber, syncedToBlockNumber, proposer, publisher, attestorAddress, invalidateCheckpoint, this.validatorClient, this.globalsBuilder, this.p2pClient, this.worldState, this.l1ToL2MessageSource, this.l2BlockSource, this.checkpointsBuilder, this.l2BlockSource, this.l1Constants, this.config, this.timetable, this.slasherClient, this.epochCache, this.dateProvider, this.metrics, this, this.setState.bind(this), this.tracer, this.log.getBindings());
|
|
373
707
|
}
|
|
374
|
-
|
|
708
|
+
/**
|
|
709
|
+
* Returns the current sequencer state.
|
|
710
|
+
*/ getState() {
|
|
711
|
+
return this.state;
|
|
712
|
+
}
|
|
713
|
+
/**
|
|
714
|
+
* Internal helper for setting the sequencer state and checks if we have enough time left in the slot to transition to the new state.
|
|
715
|
+
* @param proposedState - The new state to transition to.
|
|
716
|
+
* @param slotNumber - The current slot number.
|
|
717
|
+
* @param force - Whether to force the transition even if the sequencer is stopped.
|
|
718
|
+
*/ setState(proposedState, slotNumber, opts = {}) {
|
|
375
719
|
if (this.state === SequencerState.STOPPING && proposedState !== SequencerState.STOPPED && !opts.force) {
|
|
376
720
|
this.log.warn(`Cannot set sequencer to ${proposedState} as it is stopping.`);
|
|
377
721
|
throw new SequencerInterruptedError();
|
|
@@ -398,195 +742,23 @@ export { SequencerState };
|
|
|
398
742
|
oldState: this.state,
|
|
399
743
|
newState: proposedState,
|
|
400
744
|
secondsIntoSlot,
|
|
401
|
-
slotNumber
|
|
745
|
+
slot: slotNumber
|
|
402
746
|
});
|
|
403
747
|
this.state = proposedState;
|
|
404
748
|
}
|
|
405
|
-
async dropFailedTxsFromP2P(failedTxs) {
|
|
406
|
-
if (failedTxs.length === 0) {
|
|
407
|
-
return;
|
|
408
|
-
}
|
|
409
|
-
const failedTxData = failedTxs.map((fail)=>fail.tx);
|
|
410
|
-
const failedTxHashes = failedTxData.map((tx)=>tx.getTxHash());
|
|
411
|
-
this.log.verbose(`Dropping failed txs ${failedTxHashes.join(', ')}`);
|
|
412
|
-
await this.p2pClient.deleteTxs(failedTxHashes);
|
|
413
|
-
}
|
|
414
|
-
getBlockBuilderOptions(slot) {
|
|
415
|
-
// Deadline for processing depends on whether we're proposing a block
|
|
416
|
-
const secondsIntoSlot = this.getSecondsIntoSlot(slot);
|
|
417
|
-
const processingEndTimeWithinSlot = this.timetable.getBlockProposalExecTimeEnd(secondsIntoSlot);
|
|
418
|
-
// Deadline is only set if enforceTimeTable is enabled.
|
|
419
|
-
const deadline = this.enforceTimeTable ? new Date((this.getSlotStartBuildTimestamp(slot) + processingEndTimeWithinSlot) * 1000) : undefined;
|
|
420
|
-
return {
|
|
421
|
-
maxTransactions: this.maxTxsPerBlock,
|
|
422
|
-
maxBlockSize: this.maxBlockSizeInBytes,
|
|
423
|
-
maxBlockGas: this.maxBlockGas,
|
|
424
|
-
maxBlobFields: BLOBS_PER_BLOCK * FIELDS_PER_BLOB,
|
|
425
|
-
deadline
|
|
426
|
-
};
|
|
427
|
-
}
|
|
428
|
-
/**
|
|
429
|
-
* @notice Build and propose a block to the chain
|
|
430
|
-
*
|
|
431
|
-
* @dev MUST throw instead of exiting early to ensure that world-state
|
|
432
|
-
* is being rolled back if the block is dropped.
|
|
433
|
-
*
|
|
434
|
-
* @param pendingTxs - Iterable of pending transactions to construct the block from
|
|
435
|
-
* @param proposalHeader - The partial header constructed for the proposal
|
|
436
|
-
* @param newGlobalVariables - The global variables for the new block
|
|
437
|
-
* @param proposerAddress - The address of the proposer
|
|
438
|
-
*/ async buildBlockAndEnqueuePublish(pendingTxs, proposalHeader, newGlobalVariables, proposerAddress, invalidateBlock, publisher) {
|
|
439
|
-
await publisher.validateBlockHeader(proposalHeader, invalidateBlock);
|
|
440
|
-
const blockNumber = newGlobalVariables.blockNumber;
|
|
441
|
-
const slot = proposalHeader.slotNumber.toBigInt();
|
|
442
|
-
const l1ToL2Messages = await this.l1ToL2MessageSource.getL1ToL2Messages(blockNumber);
|
|
443
|
-
const workTimer = new Timer();
|
|
444
|
-
this.setState(SequencerState.CREATING_BLOCK, slot);
|
|
445
|
-
try {
|
|
446
|
-
const blockBuilderOptions = this.getBlockBuilderOptions(Number(slot));
|
|
447
|
-
const buildBlockRes = await this.blockBuilder.buildBlock(pendingTxs, l1ToL2Messages, newGlobalVariables, blockBuilderOptions);
|
|
448
|
-
const { publicGas, block, publicProcessorDuration, numTxs, numMsgs, blockBuildingTimer, usedTxs, failedTxs } = buildBlockRes;
|
|
449
|
-
const blockBuildDuration = workTimer.ms();
|
|
450
|
-
await this.dropFailedTxsFromP2P(failedTxs);
|
|
451
|
-
const minTxsPerBlock = this.minTxsPerBlock;
|
|
452
|
-
if (numTxs < minTxsPerBlock) {
|
|
453
|
-
this.log.warn(`Block ${blockNumber} has too few txs to be proposed (got ${numTxs} but required ${minTxsPerBlock})`, {
|
|
454
|
-
slot,
|
|
455
|
-
blockNumber,
|
|
456
|
-
numTxs
|
|
457
|
-
});
|
|
458
|
-
throw new Error(`Block has too few successful txs to be proposed`);
|
|
459
|
-
}
|
|
460
|
-
// TODO(@PhilWindle) We should probably periodically check for things like another
|
|
461
|
-
// block being published before ours instead of just waiting on our block
|
|
462
|
-
await publisher.validateBlockHeader(block.getCheckpointHeader(), invalidateBlock);
|
|
463
|
-
const blockStats = {
|
|
464
|
-
eventName: 'l2-block-built',
|
|
465
|
-
creator: proposerAddress?.toString() ?? publisher.getSenderAddress().toString(),
|
|
466
|
-
duration: workTimer.ms(),
|
|
467
|
-
publicProcessDuration: publicProcessorDuration,
|
|
468
|
-
rollupCircuitsDuration: blockBuildingTimer.ms(),
|
|
469
|
-
...block.getStats()
|
|
470
|
-
};
|
|
471
|
-
const blockHash = await block.hash();
|
|
472
|
-
const txHashes = block.body.txEffects.map((tx)=>tx.txHash);
|
|
473
|
-
this.log.info(`Built block ${block.number} for slot ${slot} with ${numTxs} txs and ${numMsgs} messages. ${publicGas.l2Gas / workTimer.s()} mana/s`, {
|
|
474
|
-
blockHash,
|
|
475
|
-
globalVariables: block.header.globalVariables.toInspect(),
|
|
476
|
-
txHashes,
|
|
477
|
-
...blockStats
|
|
478
|
-
});
|
|
479
|
-
this.log.debug('Collecting attestations');
|
|
480
|
-
const attestations = await this.collectAttestations(block, usedTxs, proposerAddress);
|
|
481
|
-
if (attestations !== undefined) {
|
|
482
|
-
this.log.verbose(`Collected ${attestations.length} attestations`, {
|
|
483
|
-
blockHash,
|
|
484
|
-
blockNumber
|
|
485
|
-
});
|
|
486
|
-
}
|
|
487
|
-
const attestationsAndSigners = new CommitteeAttestationsAndSigners(attestations ?? []);
|
|
488
|
-
const attestationsAndSignersSignature = this.validatorClient ? await this.validatorClient.signAttestationsAndSigners(attestationsAndSigners, proposerAddress ?? publisher.getSenderAddress()) : Signature.empty();
|
|
489
|
-
await this.enqueuePublishL2Block(block, attestationsAndSigners, attestationsAndSignersSignature, invalidateBlock, publisher);
|
|
490
|
-
this.metrics.recordBuiltBlock(blockBuildDuration, publicGas.l2Gas);
|
|
491
|
-
return block;
|
|
492
|
-
} catch (err) {
|
|
493
|
-
this.metrics.recordFailedBlock();
|
|
494
|
-
throw err;
|
|
495
|
-
}
|
|
496
|
-
}
|
|
497
|
-
async collectAttestations(block, txs, proposerAddress) {
|
|
498
|
-
const { committee } = await this.epochCache.getCommittee(block.header.getSlot());
|
|
499
|
-
// We checked above that the committee is defined, so this should never happen.
|
|
500
|
-
if (!committee) {
|
|
501
|
-
throw new Error('No committee when collecting attestations');
|
|
502
|
-
}
|
|
503
|
-
if (committee.length === 0) {
|
|
504
|
-
this.log.verbose(`Attesting committee is empty`);
|
|
505
|
-
return undefined;
|
|
506
|
-
} else {
|
|
507
|
-
this.log.debug(`Attesting committee length is ${committee.length}`);
|
|
508
|
-
}
|
|
509
|
-
if (!this.validatorClient) {
|
|
510
|
-
const msg = 'Missing validator client: Cannot collect attestations';
|
|
511
|
-
this.log.error(msg);
|
|
512
|
-
throw new Error(msg);
|
|
513
|
-
}
|
|
514
|
-
const numberOfRequiredAttestations = Math.floor(committee.length * 2 / 3) + 1;
|
|
515
|
-
const slotNumber = block.header.globalVariables.slotNumber.toBigInt();
|
|
516
|
-
this.setState(SequencerState.COLLECTING_ATTESTATIONS, slotNumber);
|
|
517
|
-
this.log.debug('Creating block proposal for validators');
|
|
518
|
-
const blockProposalOptions = {
|
|
519
|
-
publishFullTxs: !!this.config.publishTxsWithProposals,
|
|
520
|
-
broadcastInvalidBlockProposal: this.config.broadcastInvalidBlockProposal
|
|
521
|
-
};
|
|
522
|
-
const proposal = await this.validatorClient.createBlockProposal(block.header.globalVariables.blockNumber, block.getCheckpointHeader(), block.archive.root, block.header.state, txs, proposerAddress, blockProposalOptions);
|
|
523
|
-
if (!proposal) {
|
|
524
|
-
throw new Error(`Failed to create block proposal`);
|
|
525
|
-
}
|
|
526
|
-
if (this.config.skipCollectingAttestations) {
|
|
527
|
-
this.log.warn('Skipping attestation collection as per config (attesting with own keys only)');
|
|
528
|
-
const attestations = await this.validatorClient?.collectOwnAttestations(proposal);
|
|
529
|
-
return orderAttestations(attestations ?? [], committee);
|
|
530
|
-
}
|
|
531
|
-
this.log.debug('Broadcasting block proposal to validators');
|
|
532
|
-
await this.validatorClient.broadcastBlockProposal(proposal);
|
|
533
|
-
const attestationTimeAllowed = this.enforceTimeTable ? this.timetable.getMaxAllowedTime(SequencerState.PUBLISHING_BLOCK) : this.aztecSlotDuration;
|
|
534
|
-
this.metrics.recordRequiredAttestations(numberOfRequiredAttestations, attestationTimeAllowed);
|
|
535
|
-
const timer = new Timer();
|
|
536
|
-
let collectedAttestationsCount = 0;
|
|
537
|
-
try {
|
|
538
|
-
const attestationDeadline = new Date(this.dateProvider.now() + attestationTimeAllowed * 1000);
|
|
539
|
-
const attestations = await this.validatorClient.collectAttestations(proposal, numberOfRequiredAttestations, attestationDeadline);
|
|
540
|
-
collectedAttestationsCount = attestations.length;
|
|
541
|
-
// note: the smart contract requires that the signatures are provided in the order of the committee
|
|
542
|
-
const sorted = orderAttestations(attestations, committee);
|
|
543
|
-
if (this.config.injectFakeAttestation) {
|
|
544
|
-
const nonEmpty = sorted.filter((a)=>!a.signature.isEmpty());
|
|
545
|
-
const randomIndex = randomInt(nonEmpty.length);
|
|
546
|
-
this.log.warn(`Injecting fake attestation in block ${block.number}`);
|
|
547
|
-
unfreeze(nonEmpty[randomIndex]).signature = Signature.random();
|
|
548
|
-
}
|
|
549
|
-
return sorted;
|
|
550
|
-
} catch (err) {
|
|
551
|
-
if (err && err instanceof AttestationTimeoutError) {
|
|
552
|
-
collectedAttestationsCount = err.collectedCount;
|
|
553
|
-
}
|
|
554
|
-
throw err;
|
|
555
|
-
} finally{
|
|
556
|
-
this.metrics.recordCollectedAttestations(collectedAttestationsCount, timer.ms());
|
|
557
|
-
}
|
|
558
|
-
}
|
|
559
|
-
/**
|
|
560
|
-
* Publishes the L2Block to the rollup contract.
|
|
561
|
-
* @param block - The L2Block to be published.
|
|
562
|
-
*/ async enqueuePublishL2Block(block, attestationsAndSigners, attestationsAndSignersSignature, invalidateBlock, publisher) {
|
|
563
|
-
// Publishes new block to the network and awaits the tx to be mined
|
|
564
|
-
this.setState(SequencerState.PUBLISHING_BLOCK, block.header.globalVariables.slotNumber.toBigInt());
|
|
565
|
-
// Time out tx at the end of the slot
|
|
566
|
-
const slot = block.header.globalVariables.slotNumber.toNumber();
|
|
567
|
-
const txTimeoutAt = new Date((this.getSlotStartBuildTimestamp(slot) + this.aztecSlotDuration) * 1000);
|
|
568
|
-
const enqueued = await publisher.enqueueProposeL2Block(block, attestationsAndSigners, attestationsAndSignersSignature, {
|
|
569
|
-
txTimeoutAt,
|
|
570
|
-
forcePendingBlockNumber: invalidateBlock?.forcePendingBlockNumber
|
|
571
|
-
});
|
|
572
|
-
if (!enqueued) {
|
|
573
|
-
throw new Error(`Failed to enqueue publish of block ${block.number}`);
|
|
574
|
-
}
|
|
575
|
-
}
|
|
576
749
|
/**
|
|
577
750
|
* Returns whether all dependencies have caught up.
|
|
578
751
|
* We don't check against the previous block submitted since it may have been reorg'd out.
|
|
579
752
|
*/ async checkSync(args) {
|
|
580
|
-
// Check that the archiver
|
|
753
|
+
// Check that the archiver has fully synced the L2 slot before the one we want to propose in.
|
|
581
754
|
// TODO(#14766): Archiver reports L1 timestamp based on L1 blocks seen, which means that a missed L1 block will
|
|
582
755
|
// cause the archiver L1 timestamp to fall behind, and cause this sequencer to start processing one L1 slot later.
|
|
583
|
-
const
|
|
584
|
-
const { slot
|
|
585
|
-
if (
|
|
756
|
+
const syncedL2Slot = await this.l2BlockSource.getSyncedL2SlotNumber();
|
|
757
|
+
const { slot } = args;
|
|
758
|
+
if (syncedL2Slot === undefined || syncedL2Slot + 1 < slot) {
|
|
586
759
|
this.log.debug(`Cannot propose block at next L2 slot ${slot} due to pending sync from L1`, {
|
|
587
760
|
slot,
|
|
588
|
-
|
|
589
|
-
l1Timestamp
|
|
761
|
+
syncedL2Slot
|
|
590
762
|
});
|
|
591
763
|
return undefined;
|
|
592
764
|
}
|
|
@@ -595,15 +767,16 @@ export { SequencerState };
|
|
|
595
767
|
number: syncSummary.latestBlockNumber,
|
|
596
768
|
hash: syncSummary.latestBlockHash
|
|
597
769
|
})),
|
|
598
|
-
this.l2BlockSource.getL2Tips().then((t)=>t.
|
|
770
|
+
this.l2BlockSource.getL2Tips().then((t)=>t.proposed),
|
|
599
771
|
this.p2pClient.getStatus().then((p2p)=>p2p.syncedToL2Block),
|
|
600
|
-
this.l1ToL2MessageSource.getL2Tips().then((t)=>t.
|
|
772
|
+
this.l1ToL2MessageSource.getL2Tips().then((t)=>t.proposed),
|
|
601
773
|
this.l2BlockSource.getPendingChainValidationStatus()
|
|
602
774
|
]);
|
|
603
775
|
const [worldState, l2BlockSource, p2p, l1ToL2MessageSource, pendingChainValidationStatus] = syncedBlocks;
|
|
604
|
-
//
|
|
605
|
-
//
|
|
606
|
-
|
|
776
|
+
// Handle zero as a special case, since the block hash won't match across services if we're changing the prefilled data for the genesis block,
|
|
777
|
+
// as the world state can compute the new genesis block hash, but other components use the hardcoded constant.
|
|
778
|
+
// TODO(palla/mbps): Fix the above. All components should be able to handle dynamic genesis block hashes.
|
|
779
|
+
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;
|
|
607
780
|
if (!result) {
|
|
608
781
|
this.log.debug(`Sequencer sync check failed`, {
|
|
609
782
|
worldState,
|
|
@@ -618,77 +791,47 @@ export { SequencerState };
|
|
|
618
791
|
if (blockNumber < INITIAL_L2_BLOCK_NUM) {
|
|
619
792
|
const archive = new Fr((await this.worldState.getCommitted().getTreeInfo(MerkleTreeId.ARCHIVE)).root);
|
|
620
793
|
return {
|
|
621
|
-
|
|
794
|
+
checkpointNumber: CheckpointNumber.ZERO,
|
|
795
|
+
blockNumber: BlockNumber.ZERO,
|
|
622
796
|
archive,
|
|
623
|
-
|
|
797
|
+
syncedL2Slot,
|
|
624
798
|
pendingChainValidationStatus
|
|
625
799
|
};
|
|
626
800
|
}
|
|
627
|
-
const
|
|
628
|
-
if (!
|
|
801
|
+
const blockData = await this.l2BlockSource.getBlockData(blockNumber);
|
|
802
|
+
if (!blockData) {
|
|
629
803
|
// this shouldn't really happen because a moment ago we checked that all components were in sync
|
|
630
|
-
this.log.error(`Failed to get L2 block ${blockNumber} from the archiver with all components in sync`);
|
|
804
|
+
this.log.error(`Failed to get L2 block data ${blockNumber} from the archiver with all components in sync`);
|
|
631
805
|
return undefined;
|
|
632
806
|
}
|
|
633
807
|
return {
|
|
634
|
-
|
|
635
|
-
blockNumber:
|
|
636
|
-
|
|
637
|
-
|
|
808
|
+
blockData,
|
|
809
|
+
blockNumber: blockData.header.getBlockNumber(),
|
|
810
|
+
checkpointNumber: blockData.checkpointNumber,
|
|
811
|
+
archive: blockData.archive.root,
|
|
812
|
+
syncedL2Slot,
|
|
638
813
|
pendingChainValidationStatus
|
|
639
814
|
};
|
|
640
815
|
}
|
|
641
816
|
/**
|
|
642
|
-
* Enqueues governance and slashing votes with the publisher. Does not block.
|
|
643
|
-
* @param publisher - The publisher to enqueue votes with
|
|
644
|
-
* @param attestorAddress - The attestor address to use for signing
|
|
645
|
-
* @param slot - The slot number
|
|
646
|
-
* @param timestamp - The timestamp for the votes
|
|
647
|
-
* @param context - Optional context for logging (e.g., block number)
|
|
648
|
-
* @returns A tuple of [governanceEnqueued, slashingEnqueued]
|
|
649
|
-
*/ enqueueGovernanceAndSlashingVotes(publisher, attestorAddress, slot, timestamp) {
|
|
650
|
-
try {
|
|
651
|
-
const signerFn = (msg)=>this.validatorClient.signWithAddress(attestorAddress, msg).then((s)=>s.toString());
|
|
652
|
-
const enqueueGovernancePromise = this.governanceProposerPayload && !this.governanceProposerPayload.isZero() ? publisher.enqueueGovernanceCastSignal(this.governanceProposerPayload, slot, timestamp, attestorAddress, signerFn).catch((err)=>{
|
|
653
|
-
this.log.error(`Error enqueuing governance vote`, err, {
|
|
654
|
-
slot
|
|
655
|
-
});
|
|
656
|
-
return false;
|
|
657
|
-
}) : undefined;
|
|
658
|
-
const enqueueSlashingPromise = this.slasherClient ? this.slasherClient.getProposerActions(slot).then((actions)=>publisher.enqueueSlashingActions(actions, slot, timestamp, attestorAddress, signerFn)).catch((err)=>{
|
|
659
|
-
this.log.error(`Error enqueuing slashing actions`, err, {
|
|
660
|
-
slot
|
|
661
|
-
});
|
|
662
|
-
return false;
|
|
663
|
-
}) : undefined;
|
|
664
|
-
return [
|
|
665
|
-
enqueueGovernancePromise,
|
|
666
|
-
enqueueSlashingPromise
|
|
667
|
-
];
|
|
668
|
-
} catch (err) {
|
|
669
|
-
this.log.error(`Error enqueueing governance and slashing votes`, err);
|
|
670
|
-
return [
|
|
671
|
-
undefined,
|
|
672
|
-
undefined
|
|
673
|
-
];
|
|
674
|
-
}
|
|
675
|
-
}
|
|
676
|
-
/**
|
|
677
817
|
* Checks if we are the proposer for the next slot.
|
|
678
818
|
* @returns True if we can propose, and the proposer address (undefined if anyone can propose)
|
|
679
|
-
*/ async checkCanPropose(
|
|
819
|
+
*/ async checkCanPropose(targetSlot) {
|
|
680
820
|
let proposer;
|
|
681
821
|
try {
|
|
682
|
-
proposer = await this.epochCache.getProposerAttesterAddressInSlot(
|
|
822
|
+
proposer = await this.epochCache.getProposerAttesterAddressInSlot(targetSlot);
|
|
683
823
|
} catch (e) {
|
|
684
824
|
if (e instanceof NoCommitteeError) {
|
|
685
|
-
this.
|
|
825
|
+
if (this.lastSlotForNoCommitteeWarning !== targetSlot) {
|
|
826
|
+
this.lastSlotForNoCommitteeWarning = targetSlot;
|
|
827
|
+
this.log.warn(`Cannot propose at target slot ${targetSlot} since the committee does not exist on L1`);
|
|
828
|
+
}
|
|
686
829
|
return [
|
|
687
830
|
false,
|
|
688
831
|
undefined
|
|
689
832
|
];
|
|
690
833
|
}
|
|
691
|
-
this.log.error(`Error getting proposer for slot ${
|
|
834
|
+
this.log.error(`Error getting proposer for target slot ${targetSlot}`, e);
|
|
692
835
|
return [
|
|
693
836
|
false,
|
|
694
837
|
undefined
|
|
@@ -701,10 +844,18 @@ export { SequencerState };
|
|
|
701
844
|
undefined
|
|
702
845
|
];
|
|
703
846
|
}
|
|
847
|
+
// In fisherman mode, just return the current proposer
|
|
848
|
+
if (this.config.fishermanMode) {
|
|
849
|
+
return [
|
|
850
|
+
true,
|
|
851
|
+
proposer
|
|
852
|
+
];
|
|
853
|
+
}
|
|
704
854
|
const validatorAddresses = this.validatorClient.getValidatorAddresses();
|
|
705
855
|
const weAreProposer = validatorAddresses.some((addr)=>addr.equals(proposer));
|
|
706
856
|
if (!weAreProposer) {
|
|
707
|
-
this.log.debug(`Cannot propose at slot ${
|
|
857
|
+
this.log.debug(`Cannot propose at target slot ${targetSlot} since we are not a proposer`, {
|
|
858
|
+
targetSlot,
|
|
708
859
|
validatorAddresses,
|
|
709
860
|
proposer
|
|
710
861
|
});
|
|
@@ -713,6 +864,10 @@ export { SequencerState };
|
|
|
713
864
|
proposer
|
|
714
865
|
];
|
|
715
866
|
}
|
|
867
|
+
this.log.debug(`We are the proposer for target slot ${targetSlot}`, {
|
|
868
|
+
targetSlot,
|
|
869
|
+
proposer
|
|
870
|
+
});
|
|
716
871
|
return [
|
|
717
872
|
true,
|
|
718
873
|
proposer
|
|
@@ -722,49 +877,50 @@ export { SequencerState };
|
|
|
722
877
|
* Tries to vote on slashing actions and governance when the sync check fails but we're past the max time for initializing a proposal.
|
|
723
878
|
* This allows the sequencer to participate in governance/slashing votes even when it cannot build blocks.
|
|
724
879
|
*/ async tryVoteWhenSyncFails(args) {
|
|
725
|
-
const { slot,
|
|
880
|
+
const { slot, targetSlot } = args;
|
|
726
881
|
// Prevent duplicate attempts in the same slot
|
|
727
|
-
if (this.
|
|
728
|
-
this.log.
|
|
882
|
+
if (this.lastSlotForFallbackVote === slot) {
|
|
883
|
+
this.log.trace(`Already attempted to vote in slot ${slot} (skipping)`);
|
|
729
884
|
return;
|
|
730
885
|
}
|
|
731
886
|
// Check if we're past the max time for initializing a proposal
|
|
732
887
|
const secondsIntoSlot = this.getSecondsIntoSlot(slot);
|
|
733
|
-
const maxAllowedTime = this.timetable.getMaxAllowedTime(SequencerState.
|
|
888
|
+
const maxAllowedTime = this.timetable.getMaxAllowedTime(SequencerState.INITIALIZING_CHECKPOINT);
|
|
734
889
|
// If we haven't exceeded the time limit for initializing a proposal, don't proceed with voting
|
|
735
890
|
// We use INITIALIZING_PROPOSAL time limit because if we're past that, we can't build a block anyway
|
|
736
891
|
if (maxAllowedTime === undefined || secondsIntoSlot <= maxAllowedTime) {
|
|
737
|
-
this.log.trace(`Not attempting to vote since there is still for block building`, {
|
|
892
|
+
this.log.trace(`Not attempting to vote since there is still time for block building`, {
|
|
738
893
|
secondsIntoSlot,
|
|
739
894
|
maxAllowedTime
|
|
740
895
|
});
|
|
741
896
|
return;
|
|
742
897
|
}
|
|
743
|
-
this.log.
|
|
898
|
+
this.log.trace(`Sync for slot ${slot} failed, checking for voting opportunities`, {
|
|
744
899
|
secondsIntoSlot,
|
|
745
900
|
maxAllowedTime
|
|
746
901
|
});
|
|
747
902
|
// Check if we're a proposer or proposal is open
|
|
748
|
-
const [canPropose, proposer] = await this.checkCanPropose(
|
|
903
|
+
const [canPropose, proposer] = await this.checkCanPropose(targetSlot);
|
|
749
904
|
if (!canPropose) {
|
|
750
|
-
this.log.
|
|
905
|
+
this.log.trace(`Cannot vote in slot ${slot} since we are not a proposer`, {
|
|
751
906
|
slot,
|
|
752
907
|
proposer
|
|
753
908
|
});
|
|
754
909
|
return;
|
|
755
910
|
}
|
|
756
911
|
// Mark this slot as attempted
|
|
757
|
-
this.
|
|
912
|
+
this.lastSlotForFallbackVote = slot;
|
|
758
913
|
// Get a publisher for voting
|
|
759
914
|
const { attestorAddress, publisher } = await this.publisherFactory.create(proposer);
|
|
760
915
|
this.log.debug(`Attempting to vote despite sync failure at slot ${slot}`, {
|
|
761
916
|
attestorAddress,
|
|
762
917
|
slot
|
|
763
918
|
});
|
|
764
|
-
// Enqueue governance and slashing votes
|
|
765
|
-
const
|
|
766
|
-
|
|
767
|
-
|
|
919
|
+
// Enqueue governance and slashing votes (voter uses the target slot for L1 submission)
|
|
920
|
+
const voter = new CheckpointVoter(targetSlot, publisher, attestorAddress, this.validatorClient, this.slasherClient, this.l1Constants, this.config, this.metrics, this.log);
|
|
921
|
+
const votesPromises = voter.enqueueVotes();
|
|
922
|
+
const votes = await Promise.all(votesPromises);
|
|
923
|
+
if (votes.every((p)=>!p)) {
|
|
768
924
|
this.log.debug(`No votes to enqueue for slot ${slot}`);
|
|
769
925
|
return;
|
|
770
926
|
}
|
|
@@ -774,25 +930,53 @@ export { SequencerState };
|
|
|
774
930
|
await publisher.sendRequests();
|
|
775
931
|
}
|
|
776
932
|
/**
|
|
933
|
+
* Tries to vote on slashing actions and governance proposals when escape hatch is open.
|
|
934
|
+
* This allows the sequencer to participate in voting without performing checkpoint proposal work.
|
|
935
|
+
*/ async tryVoteWhenEscapeHatchOpen(args) {
|
|
936
|
+
const { slot, proposer } = args;
|
|
937
|
+
// Prevent duplicate attempts in the same slot
|
|
938
|
+
if (this.lastSlotForFallbackVote === slot) {
|
|
939
|
+
this.log.trace(`Already attempted to vote in slot ${slot} (escape hatch open, skipping)`);
|
|
940
|
+
return;
|
|
941
|
+
}
|
|
942
|
+
// Mark this slot as attempted
|
|
943
|
+
this.lastSlotForFallbackVote = slot;
|
|
944
|
+
const { attestorAddress, publisher } = await this.publisherFactory.create(proposer);
|
|
945
|
+
this.log.debug(`Escape hatch open for slot ${slot}, attempting vote-only actions`, {
|
|
946
|
+
slot,
|
|
947
|
+
attestorAddress
|
|
948
|
+
});
|
|
949
|
+
const voter = new CheckpointVoter(slot, publisher, attestorAddress, this.validatorClient, this.slasherClient, this.l1Constants, this.config, this.metrics, this.log);
|
|
950
|
+
const votesPromises = voter.enqueueVotes();
|
|
951
|
+
const votes = await Promise.all(votesPromises);
|
|
952
|
+
if (votes.every((p)=>!p)) {
|
|
953
|
+
this.log.debug(`No votes to enqueue for slot ${slot} (escape hatch open)`);
|
|
954
|
+
return;
|
|
955
|
+
}
|
|
956
|
+
this.log.info(`Voting in slot ${slot} (escape hatch open)`, {
|
|
957
|
+
slot
|
|
958
|
+
});
|
|
959
|
+
await publisher.sendRequests();
|
|
960
|
+
}
|
|
961
|
+
/**
|
|
777
962
|
* Considers invalidating a block if the pending chain is invalid. Depends on how long the invalid block
|
|
778
963
|
* has been there without being invalidated and whether the sequencer is in the committee or not. We always
|
|
779
964
|
* have the proposer try to invalidate, but if they fail, the sequencers in the committee are expected to try,
|
|
780
965
|
* and if they fail, any sequencer will try as well.
|
|
781
|
-
*/ async
|
|
782
|
-
const { pendingChainValidationStatus,
|
|
966
|
+
*/ async considerInvalidatingCheckpoint(syncedTo, currentSlot) {
|
|
967
|
+
const { pendingChainValidationStatus, syncedL2Slot } = syncedTo;
|
|
783
968
|
if (pendingChainValidationStatus.valid) {
|
|
784
969
|
return;
|
|
785
970
|
}
|
|
786
|
-
const
|
|
787
|
-
const
|
|
788
|
-
const
|
|
789
|
-
const timeSinceChainInvalid = this.dateProvider.nowInSeconds() - Number(invalidBlockTimestamp);
|
|
971
|
+
const invalidCheckpointNumber = pendingChainValidationStatus.checkpoint.checkpointNumber;
|
|
972
|
+
const invalidCheckpointTimestamp = pendingChainValidationStatus.checkpoint.timestamp;
|
|
973
|
+
const timeSinceChainInvalid = this.dateProvider.nowInSeconds() - Number(invalidCheckpointTimestamp);
|
|
790
974
|
const ourValidatorAddresses = this.validatorClient.getValidatorAddresses();
|
|
791
975
|
const { secondsBeforeInvalidatingBlockAsCommitteeMember, secondsBeforeInvalidatingBlockAsNonCommitteeMember } = this.config;
|
|
792
976
|
const logData = {
|
|
793
|
-
invalidL1Timestamp:
|
|
794
|
-
|
|
795
|
-
|
|
977
|
+
invalidL1Timestamp: invalidCheckpointTimestamp,
|
|
978
|
+
syncedL2Slot,
|
|
979
|
+
invalidCheckpoint: pendingChainValidationStatus.checkpoint,
|
|
796
980
|
secondsBeforeInvalidatingBlockAsCommitteeMember,
|
|
797
981
|
secondsBeforeInvalidatingBlockAsNonCommitteeMember,
|
|
798
982
|
ourValidatorAddresses,
|
|
@@ -805,14 +989,60 @@ export { SequencerState };
|
|
|
805
989
|
this.log.debug(`Not invalidating pending chain`, logData);
|
|
806
990
|
return;
|
|
807
991
|
}
|
|
808
|
-
|
|
809
|
-
if (
|
|
810
|
-
|
|
992
|
+
let validatorToUse;
|
|
993
|
+
if (invalidateAsCommitteeMember) {
|
|
994
|
+
// When invalidating as a committee member, use first validator that's actually in the committee
|
|
995
|
+
const { committee } = await this.epochCache.getCommittee(currentSlot);
|
|
996
|
+
if (committee) {
|
|
997
|
+
const committeeSet = new Set(committee.map((addr)=>addr.toString()));
|
|
998
|
+
validatorToUse = ourValidatorAddresses.find((addr)=>committeeSet.has(addr.toString())) ?? ourValidatorAddresses[0];
|
|
999
|
+
} else {
|
|
1000
|
+
validatorToUse = ourValidatorAddresses[0];
|
|
1001
|
+
}
|
|
1002
|
+
} else {
|
|
1003
|
+
// When invalidating as a non-committee member, use the first validator
|
|
1004
|
+
validatorToUse = ourValidatorAddresses[0];
|
|
1005
|
+
}
|
|
1006
|
+
const { publisher } = await this.publisherFactory.create(validatorToUse);
|
|
1007
|
+
const invalidateCheckpoint = await publisher.simulateInvalidateCheckpoint(pendingChainValidationStatus);
|
|
1008
|
+
if (!invalidateCheckpoint) {
|
|
1009
|
+
this.log.warn(`Failed to simulate invalidate checkpoint`, logData);
|
|
811
1010
|
return;
|
|
812
1011
|
}
|
|
813
|
-
this.log.info(invalidateAsCommitteeMember ? `Invalidating
|
|
814
|
-
publisher.
|
|
815
|
-
|
|
1012
|
+
this.log.info(invalidateAsCommitteeMember ? `Invalidating checkpoint ${invalidCheckpointNumber} as committee member` : `Invalidating checkpoint ${invalidCheckpointNumber} as non-committee member`, logData);
|
|
1013
|
+
publisher.enqueueInvalidateCheckpoint(invalidateCheckpoint);
|
|
1014
|
+
if (!this.config.fishermanMode) {
|
|
1015
|
+
await publisher.sendRequests();
|
|
1016
|
+
} else {
|
|
1017
|
+
this.log.info('Invalidating checkpoint in fisherman mode, clearing pending requests');
|
|
1018
|
+
publisher.clearPendingRequests();
|
|
1019
|
+
}
|
|
1020
|
+
}
|
|
1021
|
+
logStrategyComparison(epoch, publisher) {
|
|
1022
|
+
const feeAnalyzer = publisher.getL1FeeAnalyzer();
|
|
1023
|
+
if (!feeAnalyzer) {
|
|
1024
|
+
return;
|
|
1025
|
+
}
|
|
1026
|
+
const comparison = feeAnalyzer.getStrategyComparison();
|
|
1027
|
+
if (comparison.length === 0) {
|
|
1028
|
+
this.log.debug(`No strategy data available yet for epoch ${epoch}`);
|
|
1029
|
+
return;
|
|
1030
|
+
}
|
|
1031
|
+
this.log.info(`L1 Fee Strategy Performance Report - End of Epoch ${epoch}`, {
|
|
1032
|
+
epoch: Number(epoch),
|
|
1033
|
+
totalAnalyses: comparison[0]?.totalAnalyses,
|
|
1034
|
+
strategies: comparison.map((s)=>({
|
|
1035
|
+
id: s.strategyId,
|
|
1036
|
+
name: s.strategyName,
|
|
1037
|
+
inclusionRate: `${(s.inclusionRate * 100).toFixed(1)}%`,
|
|
1038
|
+
inclusionCount: `${s.inclusionCount}/${s.totalAnalyses}`,
|
|
1039
|
+
avgCostEth: s.avgEstimatedCostEth.toFixed(6),
|
|
1040
|
+
totalCostEth: s.totalEstimatedCostEth.toFixed(6),
|
|
1041
|
+
avgOverpaymentEth: s.avgOverpaymentEth.toFixed(6),
|
|
1042
|
+
totalOverpaymentEth: s.totalOverpaymentEth.toFixed(6),
|
|
1043
|
+
avgPriorityFeeDeltaGwei: s.avgPriorityFeeDeltaGwei.toFixed(2)
|
|
1044
|
+
}))
|
|
1045
|
+
});
|
|
816
1046
|
}
|
|
817
1047
|
getSlotStartBuildTimestamp(slotNumber) {
|
|
818
1048
|
return getSlotStartBuildTimestamp(slotNumber, this.l1Constants);
|
|
@@ -830,24 +1060,19 @@ export { SequencerState };
|
|
|
830
1060
|
getSlasherClient() {
|
|
831
1061
|
return this.slasherClient;
|
|
832
1062
|
}
|
|
1063
|
+
get tracer() {
|
|
1064
|
+
return this.metrics.tracer;
|
|
1065
|
+
}
|
|
1066
|
+
getValidatorAddresses() {
|
|
1067
|
+
return this.validatorClient?.getValidatorAddresses();
|
|
1068
|
+
}
|
|
1069
|
+
/** Updates the publisher factory's node keystore adapter after a keystore reload. */ updatePublisherNodeKeyStore(adapter) {
|
|
1070
|
+
this.publisherFactory.updateNodeKeyStore(adapter);
|
|
1071
|
+
}
|
|
1072
|
+
getConfig() {
|
|
1073
|
+
return this.config;
|
|
1074
|
+
}
|
|
1075
|
+
get l1PublishingTime() {
|
|
1076
|
+
return this.config.l1PublishingTime ?? this.l1Constants.ethereumSlotDuration;
|
|
1077
|
+
}
|
|
833
1078
|
}
|
|
834
|
-
_ts_decorate([
|
|
835
|
-
trackSpan('Sequencer.work')
|
|
836
|
-
], Sequencer.prototype, "safeWork", null);
|
|
837
|
-
_ts_decorate([
|
|
838
|
-
trackSpan('Sequencer.buildBlockAndEnqueuePublish', (_validTxs, _proposalHeader, newGlobalVariables)=>({
|
|
839
|
-
[Attributes.BLOCK_NUMBER]: newGlobalVariables.blockNumber
|
|
840
|
-
}))
|
|
841
|
-
], Sequencer.prototype, "buildBlockAndEnqueuePublish", null);
|
|
842
|
-
_ts_decorate([
|
|
843
|
-
trackSpan('Sequencer.collectAttestations', (block, txHashes)=>({
|
|
844
|
-
[Attributes.BLOCK_NUMBER]: block.number,
|
|
845
|
-
[Attributes.BLOCK_ARCHIVE]: block.archive.toString(),
|
|
846
|
-
[Attributes.BLOCK_TXS_COUNT]: txHashes.length
|
|
847
|
-
}))
|
|
848
|
-
], Sequencer.prototype, "collectAttestations", null);
|
|
849
|
-
_ts_decorate([
|
|
850
|
-
trackSpan('Sequencer.enqueuePublishL2Block', (block)=>({
|
|
851
|
-
[Attributes.BLOCK_NUMBER]: block.number
|
|
852
|
-
}))
|
|
853
|
-
], Sequencer.prototype, "enqueuePublishL2Block", null);
|