@aztec/sequencer-client 0.0.0-test.1 → 0.0.1-commit.0b941701
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 +31 -31
- package/dest/client/sequencer-client.d.ts.map +1 -1
- package/dest/client/sequencer-client.js +82 -60
- package/dest/config.d.ts +15 -16
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +118 -70
- package/dest/global_variable_builder/global_builder.d.ts +26 -15
- package/dest/global_variable_builder/global_builder.d.ts.map +1 -1
- package/dest/global_variable_builder/global_builder.js +62 -44
- package/dest/global_variable_builder/index.d.ts +1 -1
- package/dest/index.d.ts +2 -4
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +1 -3
- package/dest/publisher/config.d.ts +15 -12
- package/dest/publisher/config.d.ts.map +1 -1
- package/dest/publisher/config.js +32 -19
- package/dest/publisher/index.d.ts +3 -1
- package/dest/publisher/index.d.ts.map +1 -1
- package/dest/publisher/index.js +3 -0
- package/dest/publisher/sequencer-publisher-factory.d.ts +44 -0
- package/dest/publisher/sequencer-publisher-factory.d.ts.map +1 -0
- package/dest/publisher/sequencer-publisher-factory.js +51 -0
- package/dest/publisher/sequencer-publisher-metrics.d.ts +5 -4
- package/dest/publisher/sequencer-publisher-metrics.d.ts.map +1 -1
- package/dest/publisher/sequencer-publisher-metrics.js +26 -62
- package/dest/publisher/sequencer-publisher.d.ts +134 -87
- package/dest/publisher/sequencer-publisher.d.ts.map +1 -1
- package/dest/publisher/sequencer-publisher.js +1146 -249
- package/dest/sequencer/checkpoint_proposal_job.d.ts +79 -0
- package/dest/sequencer/checkpoint_proposal_job.d.ts.map +1 -0
- package/dest/sequencer/checkpoint_proposal_job.js +1165 -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 +7 -1
- package/dest/sequencer/config.d.ts.map +1 -1
- package/dest/sequencer/errors.d.ts +11 -0
- package/dest/sequencer/errors.d.ts.map +1 -0
- package/dest/sequencer/errors.js +15 -0
- package/dest/sequencer/events.d.ts +46 -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 -12
- package/dest/sequencer/metrics.d.ts.map +1 -1
- package/dest/sequencer/metrics.js +204 -69
- package/dest/sequencer/sequencer.d.ts +144 -137
- package/dest/sequencer/sequencer.d.ts.map +1 -1
- package/dest/sequencer/sequencer.js +967 -525
- package/dest/sequencer/timetable.d.ts +76 -24
- package/dest/sequencer/timetable.d.ts.map +1 -1
- package/dest/sequencer/timetable.js +177 -61
- 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 +20 -38
- package/dest/sequencer/utils.d.ts.map +1 -1
- package/dest/sequencer/utils.js +12 -47
- package/dest/test/index.d.ts +9 -1
- package/dest/test/index.d.ts.map +1 -1
- package/dest/test/index.js +0 -4
- 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 +222 -0
- package/dest/test/utils.d.ts +53 -0
- package/dest/test/utils.d.ts.map +1 -0
- package/dest/test/utils.js +103 -0
- package/package.json +47 -45
- package/src/client/sequencer-client.ts +106 -107
- package/src/config.ts +131 -81
- package/src/global_variable_builder/global_builder.ts +84 -55
- package/src/index.ts +1 -3
- package/src/publisher/config.ts +45 -32
- package/src/publisher/index.ts +4 -0
- package/src/publisher/sequencer-publisher-factory.ts +92 -0
- package/src/publisher/sequencer-publisher-metrics.ts +30 -64
- package/src/publisher/sequencer-publisher.ts +967 -295
- package/src/sequencer/README.md +531 -0
- package/src/sequencer/checkpoint_proposal_job.ts +845 -0
- package/src/sequencer/checkpoint_voter.ts +130 -0
- package/src/sequencer/config.ts +8 -0
- package/src/sequencer/errors.ts +21 -0
- package/src/sequencer/events.ts +27 -0
- package/src/sequencer/index.ts +3 -1
- package/src/sequencer/metrics.ts +269 -72
- package/src/sequencer/sequencer.ts +708 -588
- package/src/sequencer/timetable.ts +221 -62
- package/src/sequencer/types.ts +6 -0
- package/src/sequencer/utils.ts +28 -60
- package/src/test/index.ts +12 -4
- package/src/test/mock_checkpoint_builder.ts +311 -0
- package/src/test/utils.ts +164 -0
- package/dest/sequencer/allowed.d.ts +0 -3
- package/dest/sequencer/allowed.d.ts.map +0 -1
- package/dest/sequencer/allowed.js +0 -27
- package/dest/slasher/factory.d.ts +0 -7
- package/dest/slasher/factory.d.ts.map +0 -1
- package/dest/slasher/factory.js +0 -8
- package/dest/slasher/index.d.ts +0 -3
- package/dest/slasher/index.d.ts.map +0 -1
- package/dest/slasher/index.js +0 -2
- package/dest/slasher/slasher_client.d.ts +0 -75
- package/dest/slasher/slasher_client.d.ts.map +0 -1
- package/dest/slasher/slasher_client.js +0 -132
- package/dest/tx_validator/archive_cache.d.ts +0 -14
- package/dest/tx_validator/archive_cache.d.ts.map +0 -1
- package/dest/tx_validator/archive_cache.js +0 -22
- package/dest/tx_validator/gas_validator.d.ts +0 -14
- package/dest/tx_validator/gas_validator.d.ts.map +0 -1
- package/dest/tx_validator/gas_validator.js +0 -78
- package/dest/tx_validator/nullifier_cache.d.ts +0 -16
- package/dest/tx_validator/nullifier_cache.d.ts.map +0 -1
- package/dest/tx_validator/nullifier_cache.js +0 -24
- package/dest/tx_validator/phases_validator.d.ts +0 -12
- package/dest/tx_validator/phases_validator.d.ts.map +0 -1
- package/dest/tx_validator/phases_validator.js +0 -80
- package/dest/tx_validator/test_utils.d.ts +0 -23
- package/dest/tx_validator/test_utils.d.ts.map +0 -1
- package/dest/tx_validator/test_utils.js +0 -26
- package/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 -50
- package/src/sequencer/allowed.ts +0 -36
- package/src/slasher/factory.ts +0 -15
- package/src/slasher/index.ts +0 -2
- package/src/slasher/slasher_client.ts +0 -193
- package/src/tx_validator/archive_cache.ts +0 -28
- package/src/tx_validator/gas_validator.ts +0 -101
- package/src/tx_validator/nullifier_cache.ts +0 -30
- package/src/tx_validator/phases_validator.ts +0 -98
- package/src/tx_validator/test_utils.ts +0 -48
- package/src/tx_validator/tx_validator_factory.ts +0 -120
|
@@ -1,623 +1,1065 @@
|
|
|
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
|
}
|
|
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';
|
|
7
375
|
import { INITIAL_L2_BLOCK_NUM } from '@aztec/constants';
|
|
8
|
-
import {
|
|
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';
|
|
9
380
|
import { EthAddress } from '@aztec/foundation/eth-address';
|
|
10
|
-
import { Fr } from '@aztec/foundation/fields';
|
|
11
381
|
import { createLogger } from '@aztec/foundation/log';
|
|
12
382
|
import { RunningPromise } from '@aztec/foundation/running-promise';
|
|
13
|
-
import {
|
|
14
|
-
import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
15
|
-
import { Gas } from '@aztec/stdlib/gas';
|
|
383
|
+
import { getSlotAtTimestamp, getSlotStartBuildTimestamp } from '@aztec/stdlib/epoch-helpers';
|
|
16
384
|
import { SequencerConfigSchema } from '@aztec/stdlib/interfaces/server';
|
|
17
385
|
import { pickFromSchema } from '@aztec/stdlib/schemas';
|
|
18
|
-
import {
|
|
19
|
-
import { BlockHeader, ContentCommitment, StateReference, Tx } from '@aztec/stdlib/tx';
|
|
386
|
+
import { MerkleTreeId } from '@aztec/stdlib/trees';
|
|
20
387
|
import { Attributes, getTelemetryClient, trackSpan } from '@aztec/telemetry-client';
|
|
21
|
-
import
|
|
22
|
-
import {
|
|
23
|
-
import {
|
|
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';
|
|
392
|
+
import { SequencerInterruptedError, SequencerTooSlowError } from './errors.js';
|
|
24
393
|
import { SequencerMetrics } from './metrics.js';
|
|
25
|
-
import { SequencerTimetable
|
|
26
|
-
import { SequencerState
|
|
394
|
+
import { SequencerTimetable } from './timetable.js';
|
|
395
|
+
import { SequencerState } from './utils.js';
|
|
27
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
|
+
}));
|
|
28
402
|
/**
|
|
29
403
|
* Sequencer client
|
|
30
|
-
* -
|
|
31
|
-
* -
|
|
32
|
-
* -
|
|
33
|
-
* -
|
|
34
|
-
* -
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
publisher;
|
|
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
|
|
409
|
+
*/ export class Sequencer extends EventEmitter {
|
|
410
|
+
publisherFactory;
|
|
38
411
|
validatorClient;
|
|
39
412
|
globalsBuilder;
|
|
40
413
|
p2pClient;
|
|
41
414
|
worldState;
|
|
42
415
|
slasherClient;
|
|
43
|
-
blockBuilderFactory;
|
|
44
416
|
l2BlockSource;
|
|
45
417
|
l1ToL2MessageSource;
|
|
46
|
-
|
|
47
|
-
contractDataSource;
|
|
418
|
+
checkpointsBuilder;
|
|
48
419
|
l1Constants;
|
|
49
420
|
dateProvider;
|
|
50
|
-
|
|
421
|
+
epochCache;
|
|
422
|
+
rollupContract;
|
|
423
|
+
telemetry;
|
|
51
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
|
+
}
|
|
52
449
|
runningPromise;
|
|
53
|
-
pollingIntervalMs;
|
|
54
|
-
maxTxsPerBlock;
|
|
55
|
-
minTxsPerBlock;
|
|
56
|
-
maxL1TxInclusionTimeIntoSlot;
|
|
57
|
-
// TODO: zero values should not be allowed for the following 2 values in PROD
|
|
58
|
-
_coinbase;
|
|
59
|
-
_feeRecipient;
|
|
60
450
|
state;
|
|
61
|
-
allowedInSetup;
|
|
62
|
-
maxBlockSizeInBytes;
|
|
63
|
-
maxBlockGas;
|
|
64
451
|
metrics;
|
|
65
|
-
|
|
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 triggered a checkpoint proposal job, to prevent duplicate attempts. */ lastSlotForCheckpointProposalJob;
|
|
454
|
+
/** Last successful checkpoint proposed */ lastCheckpointProposed;
|
|
455
|
+
/** The last epoch for which we logged strategy comparison in fisherman mode. */ lastEpochForStrategyComparison;
|
|
66
456
|
/** The maximum number of seconds that the sequencer can be into a slot to transition to a particular state. */ timetable;
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
this.l2BlockSource = l2BlockSource;
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
this.
|
|
82
|
-
this.config
|
|
83
|
-
this.log = log;
|
|
84
|
-
this.pollingIntervalMs = 1000;
|
|
85
|
-
this.maxTxsPerBlock = 32;
|
|
86
|
-
this.minTxsPerBlock = 1;
|
|
87
|
-
this.maxL1TxInclusionTimeIntoSlot = 0;
|
|
88
|
-
this._coinbase = EthAddress.ZERO;
|
|
89
|
-
this._feeRecipient = AztecAddress.ZERO;
|
|
90
|
-
this.state = SequencerState.STOPPED;
|
|
91
|
-
this.allowedInSetup = [];
|
|
92
|
-
this.maxBlockSizeInBytes = 1024 * 1024;
|
|
93
|
-
this.maxBlockGas = new Gas(100e9, 100e9);
|
|
94
|
-
this.isFlushing = false;
|
|
95
|
-
this.enforceTimeTable = false;
|
|
96
|
-
this.metrics = new SequencerMetrics(telemetry, ()=>this.state, 'Sequencer');
|
|
97
|
-
// Register the block builder with the validator client for re-execution
|
|
98
|
-
this.validatorClient?.registerBlockBuilder(this.buildBlock.bind(this));
|
|
99
|
-
// Register the slasher on the publisher to fetch slashing payloads
|
|
100
|
-
this.publisher.registerSlashPayloadGetter(this.slasherClient.getSlashPayload.bind(this.slasherClient));
|
|
457
|
+
// This shouldn't be here as this gets re-created each time we build/propose a block.
|
|
458
|
+
// But we have a number of tests that abuse/rely on this class having a permanent publisher.
|
|
459
|
+
// As long as those tests only configure a single publisher they will continue to work.
|
|
460
|
+
// This will get re-assigned every time the sequencer goes to build a new block to a publisher that is valid
|
|
461
|
+
// for the block proposer.
|
|
462
|
+
// TODO(palla/mbps): Remove this field and fix tests
|
|
463
|
+
publisher;
|
|
464
|
+
/** Config for the sequencer */ config;
|
|
465
|
+
constructor(publisherFactory, validatorClient, globalsBuilder, p2pClient, worldState, slasherClient, l2BlockSource, l1ToL2MessageSource, checkpointsBuilder, l1Constants, dateProvider, epochCache, rollupContract, config, telemetry = getTelemetryClient(), log = createLogger('sequencer')){
|
|
466
|
+
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;
|
|
467
|
+
// Add [FISHERMAN] prefix to logger if in fisherman mode
|
|
468
|
+
if (config.fishermanMode) {
|
|
469
|
+
this.log = log.createChild('[FISHERMAN]');
|
|
470
|
+
}
|
|
471
|
+
this.metrics = new SequencerMetrics(telemetry, this.rollupContract, 'Sequencer');
|
|
472
|
+
this.updateConfig(config);
|
|
101
473
|
}
|
|
102
|
-
|
|
103
|
-
|
|
474
|
+
/** Updates sequencer config by the defined values and updates the timetable */ updateConfig(config) {
|
|
475
|
+
const filteredConfig = pickFromSchema(config, SequencerConfigSchema);
|
|
476
|
+
this.log.info(`Updated sequencer config`, omit(filteredConfig, 'txPublicSetupAllowList'));
|
|
477
|
+
this.config = merge(this.config, filteredConfig);
|
|
478
|
+
this.timetable = new SequencerTimetable({
|
|
479
|
+
ethereumSlotDuration: this.l1Constants.ethereumSlotDuration,
|
|
480
|
+
aztecSlotDuration: this.aztecSlotDuration,
|
|
481
|
+
l1PublishingTime: this.l1PublishingTime,
|
|
482
|
+
p2pPropagationTime: this.config.attestationPropagationTime,
|
|
483
|
+
blockDurationMs: this.config.blockDurationMs,
|
|
484
|
+
enforce: this.config.enforceTimeTable
|
|
485
|
+
}, this.metrics, this.log);
|
|
104
486
|
}
|
|
105
|
-
/**
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
*/ async updateConfig(config) {
|
|
109
|
-
this.log.info(`Sequencer config set`, omit(pickFromSchema(config, SequencerConfigSchema), 'allowedInSetup'));
|
|
110
|
-
if (config.transactionPollingIntervalMS !== undefined) {
|
|
111
|
-
this.pollingIntervalMs = config.transactionPollingIntervalMS;
|
|
112
|
-
}
|
|
113
|
-
if (config.maxTxsPerBlock !== undefined) {
|
|
114
|
-
this.maxTxsPerBlock = config.maxTxsPerBlock;
|
|
115
|
-
}
|
|
116
|
-
if (config.minTxsPerBlock !== undefined) {
|
|
117
|
-
this.minTxsPerBlock = config.minTxsPerBlock;
|
|
118
|
-
}
|
|
119
|
-
if (config.maxDABlockGas !== undefined) {
|
|
120
|
-
this.maxBlockGas = new Gas(config.maxDABlockGas, this.maxBlockGas.l2Gas);
|
|
121
|
-
}
|
|
122
|
-
if (config.maxL2BlockGas !== undefined) {
|
|
123
|
-
this.maxBlockGas = new Gas(this.maxBlockGas.daGas, config.maxL2BlockGas);
|
|
124
|
-
}
|
|
125
|
-
if (config.coinbase) {
|
|
126
|
-
this._coinbase = config.coinbase;
|
|
127
|
-
}
|
|
128
|
-
if (config.feeRecipient) {
|
|
129
|
-
this._feeRecipient = config.feeRecipient;
|
|
130
|
-
}
|
|
131
|
-
if (config.allowedInSetup) {
|
|
132
|
-
this.allowedInSetup = config.allowedInSetup;
|
|
133
|
-
} else {
|
|
134
|
-
this.allowedInSetup = await getDefaultAllowedSetupFunctions();
|
|
135
|
-
}
|
|
136
|
-
if (config.maxBlockSizeInBytes !== undefined) {
|
|
137
|
-
this.maxBlockSizeInBytes = config.maxBlockSizeInBytes;
|
|
138
|
-
}
|
|
139
|
-
if (config.governanceProposerPayload) {
|
|
140
|
-
this.publisher.setGovernancePayload(config.governanceProposerPayload);
|
|
141
|
-
}
|
|
142
|
-
if (config.maxL1TxInclusionTimeIntoSlot !== undefined) {
|
|
143
|
-
this.maxL1TxInclusionTimeIntoSlot = config.maxL1TxInclusionTimeIntoSlot;
|
|
144
|
-
}
|
|
145
|
-
if (config.enforceTimeTable !== undefined) {
|
|
146
|
-
this.enforceTimeTable = config.enforceTimeTable;
|
|
147
|
-
}
|
|
148
|
-
this.setTimeTable();
|
|
149
|
-
// TODO: Just read everything from the config object as needed instead of copying everything into local vars.
|
|
150
|
-
this.config = config;
|
|
487
|
+
/** Initializes the sequencer (precomputes tables and creates a publisher). Takes about 3s. */ async init() {
|
|
488
|
+
getKzg();
|
|
489
|
+
this.publisher = (await this.publisherFactory.create(undefined)).publisher;
|
|
151
490
|
}
|
|
152
|
-
|
|
153
|
-
this.
|
|
154
|
-
this.
|
|
155
|
-
|
|
491
|
+
/** Starts the sequencer and moves to IDLE state. */ start() {
|
|
492
|
+
this.runningPromise = new RunningPromise(this.safeWork.bind(this), this.log, this.config.sequencerPollingIntervalMS);
|
|
493
|
+
this.setState(SequencerState.IDLE, undefined, {
|
|
494
|
+
force: true
|
|
156
495
|
});
|
|
157
|
-
}
|
|
158
|
-
/**
|
|
159
|
-
* Starts the sequencer and moves to IDLE state.
|
|
160
|
-
*/ async start() {
|
|
161
|
-
await this.updateConfig(this.config);
|
|
162
|
-
this.runningPromise = new RunningPromise(this.work.bind(this), this.log, this.pollingIntervalMs);
|
|
163
|
-
this.setState(SequencerState.IDLE, 0n, true);
|
|
164
496
|
this.runningPromise.start();
|
|
165
|
-
this.log.info(
|
|
497
|
+
this.log.info('Started sequencer');
|
|
166
498
|
}
|
|
167
|
-
/**
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
499
|
+
/** Stops the sequencer from building blocks and moves to STOPPED state. */ async stop() {
|
|
500
|
+
this.log.info(`Stopping sequencer`);
|
|
501
|
+
this.setState(SequencerState.STOPPING, undefined, {
|
|
502
|
+
force: true
|
|
503
|
+
});
|
|
504
|
+
this.publisher?.interrupt();
|
|
172
505
|
await this.runningPromise?.stop();
|
|
173
|
-
this.
|
|
174
|
-
|
|
175
|
-
|
|
506
|
+
this.setState(SequencerState.STOPPED, undefined, {
|
|
507
|
+
force: true
|
|
508
|
+
});
|
|
176
509
|
this.log.info('Stopped sequencer');
|
|
177
510
|
}
|
|
178
|
-
/**
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
511
|
+
/** Main sequencer loop with a try/catch */ async safeWork() {
|
|
512
|
+
try {
|
|
513
|
+
await this.work();
|
|
514
|
+
} catch (err) {
|
|
515
|
+
this.emit('checkpoint-error', {
|
|
516
|
+
error: err
|
|
517
|
+
});
|
|
518
|
+
if (err instanceof SequencerTooSlowError) {
|
|
519
|
+
// TODO(palla/mbps): Add missing states
|
|
520
|
+
// Log as warn only if we had to abort halfway through the block proposal
|
|
521
|
+
const logLvl = [
|
|
522
|
+
SequencerState.INITIALIZING_CHECKPOINT,
|
|
523
|
+
SequencerState.PROPOSER_CHECK
|
|
524
|
+
].includes(err.proposedState) ? 'debug' : 'warn';
|
|
525
|
+
this.log[logLvl](err.message, {
|
|
526
|
+
now: this.dateProvider.nowInSeconds()
|
|
527
|
+
});
|
|
528
|
+
} else {
|
|
529
|
+
// Re-throw other errors
|
|
530
|
+
throw err;
|
|
531
|
+
}
|
|
532
|
+
} finally{
|
|
533
|
+
this.setState(SequencerState.IDLE, undefined);
|
|
534
|
+
}
|
|
185
535
|
}
|
|
186
|
-
/**
|
|
187
|
-
* Returns the current state of the sequencer.
|
|
188
|
-
* @returns An object with a state entry with one of SequencerState.
|
|
189
|
-
*/ status() {
|
|
536
|
+
/** Returns the current state of the sequencer. */ status() {
|
|
190
537
|
return {
|
|
191
538
|
state: this.state
|
|
192
539
|
};
|
|
193
540
|
}
|
|
194
|
-
/** Forces the sequencer to bypass all time and tx count checks for the next block and build anyway. */ flush() {
|
|
195
|
-
this.isFlushing = true;
|
|
196
|
-
}
|
|
197
541
|
/**
|
|
198
|
-
*
|
|
199
|
-
*
|
|
200
|
-
*
|
|
201
|
-
*
|
|
202
|
-
*
|
|
203
|
-
*
|
|
204
|
-
*/ async
|
|
205
|
-
this.setState(SequencerState.SYNCHRONIZING,
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
if (!
|
|
542
|
+
* Main sequencer loop:
|
|
543
|
+
* - Checks if we are up to date
|
|
544
|
+
* - If we are and we are the sequencer, collect txs and build blocks
|
|
545
|
+
* - Build multiple blocks per slot when configured
|
|
546
|
+
* - Collect attestations for the final block
|
|
547
|
+
* - Submit checkpoint
|
|
548
|
+
*/ async work() {
|
|
549
|
+
this.setState(SequencerState.SYNCHRONIZING, undefined);
|
|
550
|
+
const { slot, ts, now, epoch } = this.epochCache.getEpochAndSlotInNextL1Slot();
|
|
551
|
+
// Check if we are synced and it's our slot, grab a publisher, check previous block invalidation, etc
|
|
552
|
+
const checkpointProposalJob = await this.prepareCheckpointProposal(epoch, slot, ts, now);
|
|
553
|
+
if (!checkpointProposalJob) {
|
|
210
554
|
return;
|
|
211
555
|
}
|
|
212
|
-
|
|
213
|
-
const
|
|
214
|
-
//
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
556
|
+
// Execute the checkpoint proposal job
|
|
557
|
+
const checkpoint = await checkpointProposalJob.execute();
|
|
558
|
+
// Update last checkpoint proposed (currently unused)
|
|
559
|
+
if (checkpoint) {
|
|
560
|
+
this.lastCheckpointProposed = checkpoint;
|
|
561
|
+
}
|
|
562
|
+
// Log fee strategy comparison if on fisherman
|
|
563
|
+
if (this.config.fishermanMode && (this.lastEpochForStrategyComparison === undefined || epoch > this.lastEpochForStrategyComparison)) {
|
|
564
|
+
this.logStrategyComparison(epoch, checkpointProposalJob.getPublisher());
|
|
565
|
+
this.lastEpochForStrategyComparison = epoch;
|
|
566
|
+
}
|
|
567
|
+
return checkpoint;
|
|
568
|
+
}
|
|
569
|
+
/**
|
|
570
|
+
* Prepares the checkpoint proposal by performing all necessary checks and setup.
|
|
571
|
+
* This is the initial step in the main loop.
|
|
572
|
+
* @returns CheckpointProposalJob if successful, undefined if we are not yet synced or are not the proposer.
|
|
573
|
+
*/ async prepareCheckpointProposal(epoch, slot, ts, now) {
|
|
574
|
+
// Check we have not already processed this slot (cheapest check)
|
|
575
|
+
// We only check this if enforce timetable is set, since we want to keep processing the same slot if we are not
|
|
576
|
+
// running against actual time (eg when we use sandbox-style automining)
|
|
577
|
+
if (this.lastSlotForCheckpointProposalJob && this.lastSlotForCheckpointProposalJob >= slot && this.config.enforceTimeTable) {
|
|
578
|
+
this.log.trace(`Slot ${slot} has already been processed`);
|
|
579
|
+
return undefined;
|
|
220
580
|
}
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
581
|
+
// But if we have already proposed for this slot, the we definitely have to skip it, automining or not
|
|
582
|
+
if (this.lastCheckpointProposed && this.lastCheckpointProposed.header.slotNumber >= slot) {
|
|
583
|
+
this.log.trace(`Slot ${slot} has already been published as checkpoint ${this.lastCheckpointProposed.number}`);
|
|
584
|
+
return undefined;
|
|
585
|
+
}
|
|
586
|
+
// Check all components are synced to latest as seen by the archiver (queries all subsystems)
|
|
587
|
+
const syncedTo = await this.checkSync({
|
|
588
|
+
ts,
|
|
229
589
|
slot
|
|
230
590
|
});
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
591
|
+
if (!syncedTo) {
|
|
592
|
+
await this.tryVoteWhenSyncFails({
|
|
593
|
+
slot,
|
|
594
|
+
ts
|
|
595
|
+
});
|
|
596
|
+
return undefined;
|
|
597
|
+
}
|
|
598
|
+
// If escape hatch is open for this epoch, do not start checkpoint proposal work and do not attempt invalidations.
|
|
599
|
+
// Still perform governance/slashing voting (as proposer) once per slot.
|
|
600
|
+
const isEscapeHatchOpen = await this.epochCache.isEscapeHatchOpen(epoch);
|
|
601
|
+
if (isEscapeHatchOpen) {
|
|
602
|
+
this.setState(SequencerState.PROPOSER_CHECK, slot);
|
|
603
|
+
const [canPropose, proposer] = await this.checkCanPropose(slot);
|
|
604
|
+
if (canPropose) {
|
|
605
|
+
await this.tryVoteWhenEscapeHatchOpen({
|
|
606
|
+
slot,
|
|
607
|
+
proposer
|
|
243
608
|
});
|
|
609
|
+
} else {
|
|
610
|
+
this.log.trace(`Escape hatch open but we are not proposer, skipping vote-only actions`, {
|
|
611
|
+
slot,
|
|
612
|
+
epoch,
|
|
613
|
+
proposer
|
|
614
|
+
});
|
|
615
|
+
}
|
|
616
|
+
return undefined;
|
|
617
|
+
}
|
|
618
|
+
// Next checkpoint follows from the last synced one
|
|
619
|
+
const checkpointNumber = CheckpointNumber(syncedTo.checkpointNumber + 1);
|
|
620
|
+
const logCtx = {
|
|
621
|
+
now,
|
|
622
|
+
syncedToL1Ts: syncedTo.l1Timestamp,
|
|
623
|
+
syncedToL2Slot: getSlotAtTimestamp(syncedTo.l1Timestamp, this.l1Constants),
|
|
624
|
+
slot,
|
|
625
|
+
slotTs: ts,
|
|
626
|
+
checkpointNumber,
|
|
627
|
+
isPendingChainValid: pick(syncedTo.pendingChainValidationStatus, 'valid', 'reason', 'invalidIndex')
|
|
628
|
+
};
|
|
629
|
+
// Check that we are a proposer for the next slot
|
|
630
|
+
this.setState(SequencerState.PROPOSER_CHECK, slot);
|
|
631
|
+
const [canPropose, proposer] = await this.checkCanPropose(slot);
|
|
632
|
+
// If we are not a proposer check if we should invalidate an invalid checkpoint, and bail
|
|
633
|
+
if (!canPropose) {
|
|
634
|
+
await this.considerInvalidatingCheckpoint(syncedTo, slot);
|
|
635
|
+
return undefined;
|
|
636
|
+
}
|
|
637
|
+
// Check that the slot is not taken by a block already (should never happen, since only us can propose for this slot)
|
|
638
|
+
if (syncedTo.block && syncedTo.block.header.getSlot() >= slot) {
|
|
639
|
+
this.log.warn(`Cannot propose block at next L2 slot ${slot} since that slot was taken by block ${syncedTo.blockNumber}`, {
|
|
640
|
+
...logCtx,
|
|
641
|
+
block: syncedTo.block.header.toInspect()
|
|
244
642
|
});
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
this.log.debug(`Not enough txs to build block ${newBlockNumber} at slot ${slot}: got ${pendingTxCount} txs, need ${this.minTxsPerBlock}`);
|
|
643
|
+
this.metrics.recordBlockProposalPrecheckFailed('slot_already_taken');
|
|
644
|
+
return undefined;
|
|
248
645
|
}
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
646
|
+
// We now need to get ourselves a publisher.
|
|
647
|
+
// The returned attestor will be the one we provided if we provided one.
|
|
648
|
+
// Otherwise it will be a valid attestor for the returned publisher.
|
|
649
|
+
// In fisherman mode, pass undefined to use the fisherman's own keystore instead of the actual proposer's
|
|
650
|
+
const proposerForPublisher = this.config.fishermanMode ? undefined : proposer;
|
|
651
|
+
const { attestorAddress, publisher } = await this.publisherFactory.create(proposerForPublisher);
|
|
652
|
+
this.log.verbose(`Created publisher at address ${publisher.getSenderAddress()} for attestor ${attestorAddress}`);
|
|
653
|
+
this.publisher = publisher;
|
|
654
|
+
// In fisherman mode, set the actual proposer's address for simulations
|
|
655
|
+
if (this.config.fishermanMode && proposer) {
|
|
656
|
+
publisher.setProposerAddressForSimulation(proposer);
|
|
657
|
+
this.log.debug(`Set proposer address ${proposer} for simulation in fisherman mode`);
|
|
658
|
+
}
|
|
659
|
+
// Prepare invalidation request if the pending chain is invalid (returns undefined if no need)
|
|
660
|
+
const invalidateCheckpoint = await publisher.simulateInvalidateCheckpoint(syncedTo.pendingChainValidationStatus);
|
|
661
|
+
// Check with the rollup contract if we can indeed propose at the next L2 slot. This check should not fail
|
|
662
|
+
// if all the previous checks are good, but we do it just in case.
|
|
663
|
+
const canProposeCheck = await publisher.canProposeAtNextEthBlock(syncedTo.archive, proposer ?? EthAddress.ZERO, invalidateCheckpoint);
|
|
664
|
+
if (canProposeCheck === undefined) {
|
|
665
|
+
this.log.warn(`Cannot propose checkpoint ${checkpointNumber} at slot ${slot} due to failed rollup contract check`, logCtx);
|
|
666
|
+
this.emit('proposer-rollup-check-failed', {
|
|
667
|
+
reason: 'Rollup contract check failed',
|
|
252
668
|
slot
|
|
253
669
|
});
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
670
|
+
this.metrics.recordBlockProposalPrecheckFailed('rollup_contract_check_failed');
|
|
671
|
+
return undefined;
|
|
672
|
+
}
|
|
673
|
+
if (canProposeCheck.slot !== slot) {
|
|
674
|
+
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 ${slot} but got ${canProposeCheck.slot}.`, {
|
|
675
|
+
...logCtx,
|
|
676
|
+
rollup: canProposeCheck,
|
|
677
|
+
expectedSlot: slot
|
|
678
|
+
});
|
|
679
|
+
this.emit('proposer-rollup-check-failed', {
|
|
680
|
+
reason: 'Slot mismatch',
|
|
258
681
|
slot
|
|
259
682
|
});
|
|
260
|
-
|
|
261
|
-
await this.publisher.sendRequests();
|
|
262
|
-
if (finishedFlushing) {
|
|
263
|
-
this.isFlushing = false;
|
|
264
|
-
}
|
|
265
|
-
this.setState(SequencerState.IDLE, 0n);
|
|
266
|
-
}
|
|
267
|
-
async work() {
|
|
268
|
-
try {
|
|
269
|
-
await this.doRealWork();
|
|
270
|
-
} catch (err) {
|
|
271
|
-
if (err instanceof SequencerTooSlowError) {
|
|
272
|
-
this.log.warn(err.message);
|
|
273
|
-
} else {
|
|
274
|
-
// Re-throw other errors
|
|
275
|
-
throw err;
|
|
276
|
-
}
|
|
277
|
-
} finally{
|
|
278
|
-
this.setState(SequencerState.IDLE, 0n);
|
|
279
|
-
}
|
|
280
|
-
}
|
|
281
|
-
getForwarderAddress() {
|
|
282
|
-
return this.publisher.getForwarderAddress();
|
|
283
|
-
}
|
|
284
|
-
/**
|
|
285
|
-
* Checks if we can propose at the next block and returns the slot number if we can.
|
|
286
|
-
* @param tipArchive - The archive of the previous block.
|
|
287
|
-
* @param proposalBlockNumber - The block number of the proposal.
|
|
288
|
-
* @returns The slot number if we can propose at the next block, otherwise undefined.
|
|
289
|
-
*/ async slotForProposal(tipArchive, proposalBlockNumber) {
|
|
290
|
-
const result = await this.publisher.canProposeAtNextEthBlock(tipArchive);
|
|
291
|
-
if (!result) {
|
|
683
|
+
this.metrics.recordBlockProposalPrecheckFailed('slot_mismatch');
|
|
292
684
|
return undefined;
|
|
293
685
|
}
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
686
|
+
if (canProposeCheck.checkpointNumber !== checkpointNumber) {
|
|
687
|
+
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}.`, {
|
|
688
|
+
...logCtx,
|
|
689
|
+
rollup: canProposeCheck,
|
|
690
|
+
expectedSlot: slot
|
|
691
|
+
});
|
|
692
|
+
this.emit('proposer-rollup-check-failed', {
|
|
693
|
+
reason: 'Block mismatch',
|
|
694
|
+
slot
|
|
695
|
+
});
|
|
696
|
+
this.metrics.recordBlockProposalPrecheckFailed('block_number_mismatch');
|
|
697
|
+
return undefined;
|
|
299
698
|
}
|
|
300
|
-
|
|
699
|
+
this.lastSlotForCheckpointProposalJob = slot;
|
|
700
|
+
this.log.info(`Preparing checkpoint proposal ${checkpointNumber} at slot ${slot}`, {
|
|
701
|
+
...logCtx,
|
|
702
|
+
proposer
|
|
703
|
+
});
|
|
704
|
+
// Create and return the checkpoint proposal job
|
|
705
|
+
return this.createCheckpointProposalJob(epoch, slot, checkpointNumber, syncedTo.blockNumber, proposer, publisher, attestorAddress, invalidateCheckpoint);
|
|
706
|
+
}
|
|
707
|
+
createCheckpointProposalJob(epoch, slot, checkpointNumber, syncedToBlockNumber, proposer, publisher, attestorAddress, invalidateCheckpoint) {
|
|
708
|
+
return new CheckpointProposalJob(epoch, slot, 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.log, this.tracer);
|
|
301
709
|
}
|
|
302
710
|
/**
|
|
303
|
-
*
|
|
711
|
+
* Internal helper for setting the sequencer state and checks if we have enough time left in the slot to transition to the new state.
|
|
304
712
|
* @param proposedState - The new state to transition to.
|
|
305
|
-
* @param
|
|
713
|
+
* @param slotNumber - The current slot number.
|
|
306
714
|
* @param force - Whether to force the transition even if the sequencer is stopped.
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
715
|
+
*/ setState(proposedState, slotNumber, opts = {}) {
|
|
716
|
+
if (this.state === SequencerState.STOPPING && proposedState !== SequencerState.STOPPED && !opts.force) {
|
|
717
|
+
this.log.warn(`Cannot set sequencer to ${proposedState} as it is stopping.`);
|
|
718
|
+
throw new SequencerInterruptedError();
|
|
719
|
+
}
|
|
720
|
+
if (this.state === SequencerState.STOPPED && !opts.force) {
|
|
312
721
|
this.log.warn(`Cannot set sequencer from ${this.state} to ${proposedState} as it is stopped.`);
|
|
313
722
|
return;
|
|
314
723
|
}
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
724
|
+
let secondsIntoSlot = undefined;
|
|
725
|
+
if (slotNumber !== undefined) {
|
|
726
|
+
secondsIntoSlot = this.getSecondsIntoSlot(slotNumber);
|
|
727
|
+
this.timetable.assertTimeLeft(proposedState, secondsIntoSlot);
|
|
728
|
+
}
|
|
729
|
+
const boringStates = [
|
|
730
|
+
SequencerState.IDLE,
|
|
731
|
+
SequencerState.SYNCHRONIZING
|
|
732
|
+
];
|
|
733
|
+
const logLevel = boringStates.includes(proposedState) && boringStates.includes(this.state) ? 'trace' : 'debug';
|
|
734
|
+
this.log[logLevel](`Transitioning from ${this.state} to ${proposedState}`, {
|
|
735
|
+
slotNumber,
|
|
736
|
+
secondsIntoSlot
|
|
737
|
+
});
|
|
738
|
+
this.emit('state-changed', {
|
|
739
|
+
oldState: this.state,
|
|
740
|
+
newState: proposedState,
|
|
741
|
+
secondsIntoSlot,
|
|
742
|
+
slot: slotNumber
|
|
743
|
+
});
|
|
318
744
|
this.state = proposedState;
|
|
319
745
|
}
|
|
320
746
|
/**
|
|
321
|
-
*
|
|
322
|
-
*
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
const slot = newGlobalVariables.slotNumber.toBigInt();
|
|
332
|
-
this.log.debug(`Requesting L1 to L2 messages from contract for block ${blockNumber}`);
|
|
333
|
-
const l1ToL2Messages = await this.l1ToL2MessageSource.getL1ToL2Messages(BigInt(blockNumber));
|
|
334
|
-
const msgCount = l1ToL2Messages.length;
|
|
335
|
-
this.log.verbose(`Building block ${blockNumber} for slot ${slot}`, {
|
|
336
|
-
slot,
|
|
337
|
-
blockNumber,
|
|
338
|
-
msgCount,
|
|
339
|
-
validator: opts.validateOnly
|
|
340
|
-
});
|
|
341
|
-
// Sync to the previous block at least
|
|
342
|
-
await this.worldState.syncImmediate(blockNumber - 1);
|
|
343
|
-
this.log.debug(`Synced to previous block ${blockNumber - 1}`);
|
|
344
|
-
// NB: separating the dbs because both should update the state
|
|
345
|
-
const publicProcessorFork = await this.worldState.fork();
|
|
346
|
-
const orchestratorFork = await this.worldState.fork();
|
|
347
|
-
const previousBlockHeader = (await this.l2BlockSource.getBlock(blockNumber - 1))?.header ?? orchestratorFork.getInitialHeader();
|
|
348
|
-
try {
|
|
349
|
-
const processor = this.publicProcessorFactory.create(publicProcessorFork, newGlobalVariables, true);
|
|
350
|
-
const blockBuildingTimer = new Timer();
|
|
351
|
-
const blockBuilder = this.blockBuilderFactory.create(orchestratorFork);
|
|
352
|
-
await blockBuilder.startNewBlock(newGlobalVariables, l1ToL2Messages, previousBlockHeader);
|
|
353
|
-
// Deadline for processing depends on whether we're proposing a block
|
|
354
|
-
const secondsIntoSlot = this.getSecondsIntoSlot(slot);
|
|
355
|
-
const processingEndTimeWithinSlot = opts.validateOnly ? this.timetable.getValidatorReexecTimeEnd(secondsIntoSlot) : this.timetable.getBlockProposalExecTimeEnd(secondsIntoSlot);
|
|
356
|
-
// Deadline is only set if enforceTimeTable is enabled.
|
|
357
|
-
const deadline = this.enforceTimeTable ? new Date((this.getSlotStartTimestamp(slot) + processingEndTimeWithinSlot) * 1000) : undefined;
|
|
358
|
-
this.log.verbose(`Processing pending txs`, {
|
|
747
|
+
* Returns whether all dependencies have caught up.
|
|
748
|
+
* We don't check against the previous block submitted since it may have been reorg'd out.
|
|
749
|
+
*/ async checkSync(args) {
|
|
750
|
+
// Check that the archiver and dependencies have synced to the previous L1 slot at least
|
|
751
|
+
// TODO(#14766): Archiver reports L1 timestamp based on L1 blocks seen, which means that a missed L1 block will
|
|
752
|
+
// cause the archiver L1 timestamp to fall behind, and cause this sequencer to start processing one L1 slot later.
|
|
753
|
+
const l1Timestamp = await this.l2BlockSource.getL1Timestamp();
|
|
754
|
+
const { slot, ts } = args;
|
|
755
|
+
if (l1Timestamp === undefined || l1Timestamp + BigInt(this.l1Constants.ethereumSlotDuration) < ts) {
|
|
756
|
+
this.log.debug(`Cannot propose block at next L2 slot ${slot} due to pending sync from L1`, {
|
|
359
757
|
slot,
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
deadline
|
|
758
|
+
ts,
|
|
759
|
+
l1Timestamp
|
|
363
760
|
});
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
throw new Error(`Block has too few successful txs to be proposed`);
|
|
395
|
-
}
|
|
396
|
-
const start = process.hrtime.bigint();
|
|
397
|
-
await blockBuilder.addTxs(processedTxs);
|
|
398
|
-
const end = process.hrtime.bigint();
|
|
399
|
-
const duration = Number(end - start) / 1_000;
|
|
400
|
-
this.metrics.recordBlockBuilderTreeInsertions(duration);
|
|
401
|
-
// All real transactions have been added, set the block as full and pad if needed
|
|
402
|
-
const block = await blockBuilder.setBlockCompleted();
|
|
403
|
-
// How much public gas was processed
|
|
404
|
-
const publicGas = processedTxs.reduce((acc, tx)=>acc.add(tx.gasUsed.publicGas), Gas.empty());
|
|
761
|
+
return undefined;
|
|
762
|
+
}
|
|
763
|
+
const syncedBlocks = await Promise.all([
|
|
764
|
+
this.worldState.status().then(({ syncSummary })=>({
|
|
765
|
+
number: syncSummary.latestBlockNumber,
|
|
766
|
+
hash: syncSummary.latestBlockHash
|
|
767
|
+
})),
|
|
768
|
+
this.l2BlockSource.getL2Tips().then((t)=>t.proposed),
|
|
769
|
+
this.p2pClient.getStatus().then((p2p)=>p2p.syncedToL2Block),
|
|
770
|
+
this.l1ToL2MessageSource.getL2Tips().then((t)=>t.proposed),
|
|
771
|
+
this.l2BlockSource.getPendingChainValidationStatus()
|
|
772
|
+
]);
|
|
773
|
+
const [worldState, l2BlockSource, p2p, l1ToL2MessageSource, pendingChainValidationStatus] = syncedBlocks;
|
|
774
|
+
// 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,
|
|
775
|
+
// as the world state can compute the new genesis block hash, but other components use the hardcoded constant.
|
|
776
|
+
// TODO(palla/mbps): Fix the above. All components should be able to handle dynamic genesis block hashes.
|
|
777
|
+
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;
|
|
778
|
+
if (!result) {
|
|
779
|
+
this.log.debug(`Sequencer sync check failed`, {
|
|
780
|
+
worldState,
|
|
781
|
+
l2BlockSource,
|
|
782
|
+
p2p,
|
|
783
|
+
l1ToL2MessageSource
|
|
784
|
+
});
|
|
785
|
+
return undefined;
|
|
786
|
+
}
|
|
787
|
+
// Special case for genesis state
|
|
788
|
+
const blockNumber = worldState.number;
|
|
789
|
+
if (blockNumber < INITIAL_L2_BLOCK_NUM) {
|
|
790
|
+
const archive = new Fr((await this.worldState.getCommitted().getTreeInfo(MerkleTreeId.ARCHIVE)).root);
|
|
405
791
|
return {
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
numFailedTxs: failedTxs.length,
|
|
412
|
-
blockBuildingTimer
|
|
792
|
+
checkpointNumber: CheckpointNumber.ZERO,
|
|
793
|
+
blockNumber: BlockNumber.ZERO,
|
|
794
|
+
archive,
|
|
795
|
+
l1Timestamp,
|
|
796
|
+
pendingChainValidationStatus
|
|
413
797
|
};
|
|
414
|
-
} finally{
|
|
415
|
-
// We create a fresh processor each time to reset any cached state (eg storage writes)
|
|
416
|
-
// We wait a bit to close the forks since the processor may still be working on a dangling tx
|
|
417
|
-
// which was interrupted due to the processingDeadline being hit.
|
|
418
|
-
// eslint-disable-next-line @typescript-eslint/no-misused-promises
|
|
419
|
-
setTimeout(async ()=>{
|
|
420
|
-
try {
|
|
421
|
-
await publicProcessorFork.close();
|
|
422
|
-
await orchestratorFork.close();
|
|
423
|
-
} catch (err) {
|
|
424
|
-
// This can happen if the sequencer is stopped before we hit this timeout.
|
|
425
|
-
this.log.warn(`Error closing forks for block processing`, err);
|
|
426
|
-
}
|
|
427
|
-
}, 5000);
|
|
428
798
|
}
|
|
799
|
+
const block = await this.l2BlockSource.getL2Block(blockNumber);
|
|
800
|
+
if (!block) {
|
|
801
|
+
// this shouldn't really happen because a moment ago we checked that all components were in sync
|
|
802
|
+
this.log.error(`Failed to get L2 block ${blockNumber} from the archiver with all components in sync`);
|
|
803
|
+
return undefined;
|
|
804
|
+
}
|
|
805
|
+
return {
|
|
806
|
+
block,
|
|
807
|
+
blockNumber: block.number,
|
|
808
|
+
checkpointNumber: block.checkpointNumber,
|
|
809
|
+
archive: block.archive.root,
|
|
810
|
+
l1Timestamp,
|
|
811
|
+
pendingChainValidationStatus
|
|
812
|
+
};
|
|
429
813
|
}
|
|
430
814
|
/**
|
|
431
|
-
*
|
|
432
|
-
*
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
*
|
|
436
|
-
* @param pendingTxs - Iterable of pending transactions to construct the block from
|
|
437
|
-
* @param proposalHeader - The partial header constructed for the proposal
|
|
438
|
-
*/ async buildBlockAndEnqueuePublish(pendingTxs, proposalHeader) {
|
|
439
|
-
await this.publisher.validateBlockForSubmission(proposalHeader);
|
|
440
|
-
const newGlobalVariables = proposalHeader.globalVariables;
|
|
441
|
-
const blockNumber = newGlobalVariables.blockNumber.toNumber();
|
|
442
|
-
const slot = newGlobalVariables.slotNumber.toBigInt();
|
|
443
|
-
// this.metrics.recordNewBlock(blockNumber, validTxs.length);
|
|
444
|
-
const workTimer = new Timer();
|
|
445
|
-
this.setState(SequencerState.CREATING_BLOCK, slot);
|
|
815
|
+
* Checks if we are the proposer for the next slot.
|
|
816
|
+
* @returns True if we can propose, and the proposer address (undefined if anyone can propose)
|
|
817
|
+
*/ async checkCanPropose(slot) {
|
|
818
|
+
let proposer;
|
|
446
819
|
try {
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
creator: this.publisher.getSenderAddress().toString(),
|
|
456
|
-
duration: workTimer.ms(),
|
|
457
|
-
publicProcessDuration: publicProcessorDuration,
|
|
458
|
-
rollupCircuitsDuration: blockBuildingTimer.ms(),
|
|
459
|
-
...block.getStats()
|
|
460
|
-
};
|
|
461
|
-
const blockHash = await block.hash();
|
|
462
|
-
const txHashes = block.body.txEffects.map((tx)=>tx.txHash);
|
|
463
|
-
this.log.info(`Built block ${block.number} for slot ${slot} with ${numTxs} txs and ${numMsgs} messages. ${publicGas.l2Gas / workTimer.s()} mana/s`, {
|
|
464
|
-
blockHash,
|
|
465
|
-
globalVariables: block.header.globalVariables.toInspect(),
|
|
466
|
-
txHashes,
|
|
467
|
-
...blockStats
|
|
468
|
-
});
|
|
469
|
-
this.log.debug('Collecting attestations');
|
|
470
|
-
const stopCollectingAttestationsTimer = this.metrics.startCollectingAttestationsTimer();
|
|
471
|
-
const attestations = await this.collectAttestations(block, txHashes);
|
|
472
|
-
if (attestations !== undefined) {
|
|
473
|
-
this.log.verbose(`Collected ${attestations.length} attestations`, {
|
|
474
|
-
blockHash,
|
|
475
|
-
blockNumber
|
|
476
|
-
});
|
|
820
|
+
proposer = await this.epochCache.getProposerAttesterAddressInSlot(slot);
|
|
821
|
+
} catch (e) {
|
|
822
|
+
if (e instanceof NoCommitteeError) {
|
|
823
|
+
this.log.warn(`Cannot propose at next L2 slot ${slot} since the committee does not exist on L1`);
|
|
824
|
+
return [
|
|
825
|
+
false,
|
|
826
|
+
undefined
|
|
827
|
+
];
|
|
477
828
|
}
|
|
478
|
-
|
|
479
|
-
return
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
829
|
+
this.log.error(`Error getting proposer for slot ${slot}`, e);
|
|
830
|
+
return [
|
|
831
|
+
false,
|
|
832
|
+
undefined
|
|
833
|
+
];
|
|
483
834
|
}
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
const
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
return orderAttestations(attestations, committee);
|
|
835
|
+
// If proposer is undefined, then the committee is empty and anyone may propose
|
|
836
|
+
if (proposer === undefined) {
|
|
837
|
+
return [
|
|
838
|
+
true,
|
|
839
|
+
undefined
|
|
840
|
+
];
|
|
841
|
+
}
|
|
842
|
+
// In fisherman mode, just return the current proposer
|
|
843
|
+
if (this.config.fishermanMode) {
|
|
844
|
+
return [
|
|
845
|
+
true,
|
|
846
|
+
proposer
|
|
847
|
+
];
|
|
848
|
+
}
|
|
849
|
+
const validatorAddresses = this.validatorClient.getValidatorAddresses();
|
|
850
|
+
const weAreProposer = validatorAddresses.some((addr)=>addr.equals(proposer));
|
|
851
|
+
if (!weAreProposer) {
|
|
852
|
+
this.log.debug(`Cannot propose at slot ${slot} since we are not a proposer`, {
|
|
853
|
+
validatorAddresses,
|
|
854
|
+
proposer
|
|
855
|
+
});
|
|
856
|
+
return [
|
|
857
|
+
false,
|
|
858
|
+
proposer
|
|
859
|
+
];
|
|
860
|
+
}
|
|
861
|
+
return [
|
|
862
|
+
true,
|
|
863
|
+
proposer
|
|
864
|
+
];
|
|
515
865
|
}
|
|
516
866
|
/**
|
|
517
|
-
*
|
|
518
|
-
*
|
|
519
|
-
*/ async
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
867
|
+
* Tries to vote on slashing actions and governance when the sync check fails but we're past the max time for initializing a proposal.
|
|
868
|
+
* This allows the sequencer to participate in governance/slashing votes even when it cannot build blocks.
|
|
869
|
+
*/ async tryVoteWhenSyncFails(args) {
|
|
870
|
+
const { slot } = args;
|
|
871
|
+
// Prevent duplicate attempts in the same slot
|
|
872
|
+
if (this.lastSlotForFallbackVote === slot) {
|
|
873
|
+
this.log.trace(`Already attempted to vote in slot ${slot} (skipping)`);
|
|
874
|
+
return;
|
|
875
|
+
}
|
|
876
|
+
// Check if we're past the max time for initializing a proposal
|
|
877
|
+
const secondsIntoSlot = this.getSecondsIntoSlot(slot);
|
|
878
|
+
const maxAllowedTime = this.timetable.getMaxAllowedTime(SequencerState.INITIALIZING_CHECKPOINT);
|
|
879
|
+
// If we haven't exceeded the time limit for initializing a proposal, don't proceed with voting
|
|
880
|
+
// We use INITIALIZING_PROPOSAL time limit because if we're past that, we can't build a block anyway
|
|
881
|
+
if (maxAllowedTime === undefined || secondsIntoSlot <= maxAllowedTime) {
|
|
882
|
+
this.log.trace(`Not attempting to vote since there is still time for block building`, {
|
|
883
|
+
secondsIntoSlot,
|
|
884
|
+
maxAllowedTime
|
|
885
|
+
});
|
|
886
|
+
return;
|
|
887
|
+
}
|
|
888
|
+
this.log.trace(`Sync for slot ${slot} failed, checking for voting opportunities`, {
|
|
889
|
+
secondsIntoSlot,
|
|
890
|
+
maxAllowedTime
|
|
527
891
|
});
|
|
528
|
-
if
|
|
529
|
-
|
|
892
|
+
// Check if we're a proposer or proposal is open
|
|
893
|
+
const [canPropose, proposer] = await this.checkCanPropose(slot);
|
|
894
|
+
if (!canPropose) {
|
|
895
|
+
this.log.trace(`Cannot vote in slot ${slot} since we are not a proposer`, {
|
|
896
|
+
slot,
|
|
897
|
+
proposer
|
|
898
|
+
});
|
|
899
|
+
return;
|
|
530
900
|
}
|
|
901
|
+
// Mark this slot as attempted
|
|
902
|
+
this.lastSlotForFallbackVote = slot;
|
|
903
|
+
// Get a publisher for voting
|
|
904
|
+
const { attestorAddress, publisher } = await this.publisherFactory.create(proposer);
|
|
905
|
+
this.log.debug(`Attempting to vote despite sync failure at slot ${slot}`, {
|
|
906
|
+
attestorAddress,
|
|
907
|
+
slot
|
|
908
|
+
});
|
|
909
|
+
// Enqueue governance and slashing votes
|
|
910
|
+
const voter = new CheckpointVoter(slot, publisher, attestorAddress, this.validatorClient, this.slasherClient, this.l1Constants, this.config, this.metrics, this.log);
|
|
911
|
+
const votesPromises = voter.enqueueVotes();
|
|
912
|
+
const votes = await Promise.all(votesPromises);
|
|
913
|
+
if (votes.every((p)=>!p)) {
|
|
914
|
+
this.log.debug(`No votes to enqueue for slot ${slot}`);
|
|
915
|
+
return;
|
|
916
|
+
}
|
|
917
|
+
this.log.info(`Voting in slot ${slot} despite sync failure`, {
|
|
918
|
+
slot
|
|
919
|
+
});
|
|
920
|
+
await publisher.sendRequests();
|
|
531
921
|
}
|
|
532
922
|
/**
|
|
533
|
-
*
|
|
534
|
-
*
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
const [worldState, l2BlockSource, p2p, l1ToL2MessageSource] = syncedBlocks;
|
|
549
|
-
const result = // check that world state has caught up with archiver
|
|
550
|
-
// note that the archiver reports undefined hash for the genesis block
|
|
551
|
-
// because it doesn't have access to world state to compute it (facepalm)
|
|
552
|
-
(l2BlockSource.hash === undefined || worldState.hash === l2BlockSource.hash) && // and p2p client and message source are at least at the same block
|
|
553
|
-
// this should change to hashes once p2p client handles reorgs
|
|
554
|
-
// and once we stop pretending that the l1tol2message source is not
|
|
555
|
-
// just the archiver under a different name
|
|
556
|
-
(!l2BlockSource.hash || p2p.hash === l2BlockSource.hash) && l1ToL2MessageSource === l2BlockSource.number;
|
|
557
|
-
this.log.debug(`Sequencer sync check ${result ? 'succeeded' : 'failed'}`, {
|
|
558
|
-
worldStateNumber: worldState.number,
|
|
559
|
-
worldStateHash: worldState.hash,
|
|
560
|
-
l2BlockSourceNumber: l2BlockSource.number,
|
|
561
|
-
l2BlockSourceHash: l2BlockSource.hash,
|
|
562
|
-
p2pNumber: p2p.number,
|
|
563
|
-
p2pHash: p2p.hash,
|
|
564
|
-
l1ToL2MessageSourceNumber: l1ToL2MessageSource
|
|
923
|
+
* Tries to vote on slashing actions and governance proposals when escape hatch is open.
|
|
924
|
+
* This allows the sequencer to participate in voting without performing checkpoint proposal work.
|
|
925
|
+
*/ async tryVoteWhenEscapeHatchOpen(args) {
|
|
926
|
+
const { slot, proposer } = args;
|
|
927
|
+
// Prevent duplicate attempts in the same slot
|
|
928
|
+
if (this.lastSlotForFallbackVote === slot) {
|
|
929
|
+
this.log.trace(`Already attempted to vote in slot ${slot} (escape hatch open, skipping)`);
|
|
930
|
+
return;
|
|
931
|
+
}
|
|
932
|
+
// Mark this slot as attempted
|
|
933
|
+
this.lastSlotForFallbackVote = slot;
|
|
934
|
+
const { attestorAddress, publisher } = await this.publisherFactory.create(proposer);
|
|
935
|
+
this.log.debug(`Escape hatch open for slot ${slot}, attempting vote-only actions`, {
|
|
936
|
+
slot,
|
|
937
|
+
attestorAddress
|
|
565
938
|
});
|
|
566
|
-
|
|
567
|
-
|
|
939
|
+
const voter = new CheckpointVoter(slot, publisher, attestorAddress, this.validatorClient, this.slasherClient, this.l1Constants, this.config, this.metrics, this.log);
|
|
940
|
+
const votesPromises = voter.enqueueVotes();
|
|
941
|
+
const votes = await Promise.all(votesPromises);
|
|
942
|
+
if (votes.every((p)=>!p)) {
|
|
943
|
+
this.log.debug(`No votes to enqueue for slot ${slot} (escape hatch open)`);
|
|
944
|
+
return;
|
|
945
|
+
}
|
|
946
|
+
this.log.info(`Voting in slot ${slot} (escape hatch open)`, {
|
|
947
|
+
slot
|
|
948
|
+
});
|
|
949
|
+
await publisher.sendRequests();
|
|
950
|
+
}
|
|
951
|
+
/**
|
|
952
|
+
* Considers invalidating a block if the pending chain is invalid. Depends on how long the invalid block
|
|
953
|
+
* has been there without being invalidated and whether the sequencer is in the committee or not. We always
|
|
954
|
+
* have the proposer try to invalidate, but if they fail, the sequencers in the committee are expected to try,
|
|
955
|
+
* and if they fail, any sequencer will try as well.
|
|
956
|
+
*/ async considerInvalidatingCheckpoint(syncedTo, currentSlot) {
|
|
957
|
+
const { pendingChainValidationStatus, l1Timestamp } = syncedTo;
|
|
958
|
+
if (pendingChainValidationStatus.valid) {
|
|
959
|
+
return;
|
|
568
960
|
}
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
961
|
+
const invalidCheckpointNumber = pendingChainValidationStatus.checkpoint.checkpointNumber;
|
|
962
|
+
const invalidCheckpointTimestamp = pendingChainValidationStatus.checkpoint.timestamp;
|
|
963
|
+
const timeSinceChainInvalid = this.dateProvider.nowInSeconds() - Number(invalidCheckpointTimestamp);
|
|
964
|
+
const ourValidatorAddresses = this.validatorClient.getValidatorAddresses();
|
|
965
|
+
const { secondsBeforeInvalidatingBlockAsCommitteeMember, secondsBeforeInvalidatingBlockAsNonCommitteeMember } = this.config;
|
|
966
|
+
const logData = {
|
|
967
|
+
invalidL1Timestamp: invalidCheckpointTimestamp,
|
|
968
|
+
l1Timestamp,
|
|
969
|
+
invalidCheckpoint: pendingChainValidationStatus.checkpoint,
|
|
970
|
+
secondsBeforeInvalidatingBlockAsCommitteeMember,
|
|
971
|
+
secondsBeforeInvalidatingBlockAsNonCommitteeMember,
|
|
972
|
+
ourValidatorAddresses,
|
|
973
|
+
currentSlot
|
|
974
|
+
};
|
|
975
|
+
const inCurrentCommittee = ()=>this.epochCache.getCommittee(currentSlot).then((c)=>c?.committee?.some((member)=>ourValidatorAddresses.some((addr)=>addr.equals(member))));
|
|
976
|
+
const invalidateAsCommitteeMember = secondsBeforeInvalidatingBlockAsCommitteeMember !== undefined && secondsBeforeInvalidatingBlockAsCommitteeMember > 0 && timeSinceChainInvalid > secondsBeforeInvalidatingBlockAsCommitteeMember && await inCurrentCommittee();
|
|
977
|
+
const invalidateAsNonCommitteeMember = secondsBeforeInvalidatingBlockAsNonCommitteeMember !== undefined && secondsBeforeInvalidatingBlockAsNonCommitteeMember > 0 && timeSinceChainInvalid > secondsBeforeInvalidatingBlockAsNonCommitteeMember;
|
|
978
|
+
if (!invalidateAsCommitteeMember && !invalidateAsNonCommitteeMember) {
|
|
979
|
+
this.log.debug(`Not invalidating pending chain`, logData);
|
|
980
|
+
return;
|
|
981
|
+
}
|
|
982
|
+
let validatorToUse;
|
|
983
|
+
if (invalidateAsCommitteeMember) {
|
|
984
|
+
// When invalidating as a committee member, use first validator that's actually in the committee
|
|
985
|
+
const { committee } = await this.epochCache.getCommittee(currentSlot);
|
|
986
|
+
if (committee) {
|
|
987
|
+
const committeeSet = new Set(committee.map((addr)=>addr.toString()));
|
|
988
|
+
validatorToUse = ourValidatorAddresses.find((addr)=>committeeSet.has(addr.toString())) ?? ourValidatorAddresses[0];
|
|
989
|
+
} else {
|
|
990
|
+
validatorToUse = ourValidatorAddresses[0];
|
|
574
991
|
}
|
|
575
|
-
return {
|
|
576
|
-
blockNumber: block.number,
|
|
577
|
-
archive: block.archive.root
|
|
578
|
-
};
|
|
579
992
|
} else {
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
993
|
+
// When invalidating as a non-committee member, use the first validator
|
|
994
|
+
validatorToUse = ourValidatorAddresses[0];
|
|
995
|
+
}
|
|
996
|
+
const { publisher } = await this.publisherFactory.create(validatorToUse);
|
|
997
|
+
const invalidateCheckpoint = await publisher.simulateInvalidateCheckpoint(pendingChainValidationStatus);
|
|
998
|
+
if (!invalidateCheckpoint) {
|
|
999
|
+
this.log.warn(`Failed to simulate invalidate checkpoint`, logData);
|
|
1000
|
+
return;
|
|
1001
|
+
}
|
|
1002
|
+
this.log.info(invalidateAsCommitteeMember ? `Invalidating checkpoint ${invalidCheckpointNumber} as committee member` : `Invalidating checkpoint ${invalidCheckpointNumber} as non-committee member`, logData);
|
|
1003
|
+
publisher.enqueueInvalidateCheckpoint(invalidateCheckpoint);
|
|
1004
|
+
if (!this.config.fishermanMode) {
|
|
1005
|
+
await publisher.sendRequests();
|
|
1006
|
+
} else {
|
|
1007
|
+
this.log.info('Invalidating checkpoint in fisherman mode, clearing pending requests');
|
|
1008
|
+
publisher.clearPendingRequests();
|
|
585
1009
|
}
|
|
586
1010
|
}
|
|
587
|
-
|
|
588
|
-
|
|
1011
|
+
logStrategyComparison(epoch, publisher) {
|
|
1012
|
+
const feeAnalyzer = publisher.getL1FeeAnalyzer();
|
|
1013
|
+
if (!feeAnalyzer) {
|
|
1014
|
+
return;
|
|
1015
|
+
}
|
|
1016
|
+
const comparison = feeAnalyzer.getStrategyComparison();
|
|
1017
|
+
if (comparison.length === 0) {
|
|
1018
|
+
this.log.debug(`No strategy data available yet for epoch ${epoch}`);
|
|
1019
|
+
return;
|
|
1020
|
+
}
|
|
1021
|
+
this.log.info(`L1 Fee Strategy Performance Report - End of Epoch ${epoch}`, {
|
|
1022
|
+
epoch: Number(epoch),
|
|
1023
|
+
totalAnalyses: comparison[0]?.totalAnalyses,
|
|
1024
|
+
strategies: comparison.map((s)=>({
|
|
1025
|
+
id: s.strategyId,
|
|
1026
|
+
name: s.strategyName,
|
|
1027
|
+
inclusionRate: `${(s.inclusionRate * 100).toFixed(1)}%`,
|
|
1028
|
+
inclusionCount: `${s.inclusionCount}/${s.totalAnalyses}`,
|
|
1029
|
+
avgCostEth: s.avgEstimatedCostEth.toFixed(6),
|
|
1030
|
+
totalCostEth: s.totalEstimatedCostEth.toFixed(6),
|
|
1031
|
+
avgOverpaymentEth: s.avgOverpaymentEth.toFixed(6),
|
|
1032
|
+
totalOverpaymentEth: s.totalOverpaymentEth.toFixed(6),
|
|
1033
|
+
avgPriorityFeeDeltaGwei: s.avgPriorityFeeDeltaGwei.toFixed(2)
|
|
1034
|
+
}))
|
|
1035
|
+
});
|
|
1036
|
+
}
|
|
1037
|
+
getSlotStartBuildTimestamp(slotNumber) {
|
|
1038
|
+
return getSlotStartBuildTimestamp(slotNumber, this.l1Constants);
|
|
589
1039
|
}
|
|
590
1040
|
getSecondsIntoSlot(slotNumber) {
|
|
591
|
-
const slotStartTimestamp = this.
|
|
1041
|
+
const slotStartTimestamp = this.getSlotStartBuildTimestamp(slotNumber);
|
|
592
1042
|
return Number((this.dateProvider.now() / 1000 - slotStartTimestamp).toFixed(3));
|
|
593
1043
|
}
|
|
594
1044
|
get aztecSlotDuration() {
|
|
595
1045
|
return this.l1Constants.slotDuration;
|
|
596
1046
|
}
|
|
597
|
-
get
|
|
598
|
-
return this.
|
|
1047
|
+
get maxL2BlockGas() {
|
|
1048
|
+
return this.config.maxL2BlockGas;
|
|
1049
|
+
}
|
|
1050
|
+
getSlasherClient() {
|
|
1051
|
+
return this.slasherClient;
|
|
1052
|
+
}
|
|
1053
|
+
get tracer() {
|
|
1054
|
+
return this.metrics.tracer;
|
|
1055
|
+
}
|
|
1056
|
+
getValidatorAddresses() {
|
|
1057
|
+
return this.validatorClient?.getValidatorAddresses();
|
|
1058
|
+
}
|
|
1059
|
+
getConfig() {
|
|
1060
|
+
return this.config;
|
|
599
1061
|
}
|
|
600
|
-
get
|
|
601
|
-
return this.
|
|
1062
|
+
get l1PublishingTime() {
|
|
1063
|
+
return this.config.l1PublishingTime ?? this.l1Constants.ethereumSlotDuration;
|
|
602
1064
|
}
|
|
603
1065
|
}
|
|
604
|
-
_ts_decorate([
|
|
605
|
-
trackSpan('Sequencer.work')
|
|
606
|
-
], Sequencer.prototype, "work", null);
|
|
607
|
-
_ts_decorate([
|
|
608
|
-
trackSpan('Sequencer.buildBlockAndEnqueuePublish', (_validTxs, proposalHeader)=>({
|
|
609
|
-
[Attributes.BLOCK_NUMBER]: proposalHeader.globalVariables.blockNumber.toNumber()
|
|
610
|
-
}))
|
|
611
|
-
], Sequencer.prototype, "buildBlockAndEnqueuePublish", null);
|
|
612
|
-
_ts_decorate([
|
|
613
|
-
trackSpan('Sequencer.collectAttestations', (block, txHashes)=>({
|
|
614
|
-
[Attributes.BLOCK_NUMBER]: block.number,
|
|
615
|
-
[Attributes.BLOCK_ARCHIVE]: block.archive.toString(),
|
|
616
|
-
[Attributes.BLOCK_TXS_COUNT]: txHashes.length
|
|
617
|
-
}))
|
|
618
|
-
], Sequencer.prototype, "collectAttestations", null);
|
|
619
|
-
_ts_decorate([
|
|
620
|
-
trackSpan('Sequencer.enqueuePublishL2Block', (block)=>({
|
|
621
|
-
[Attributes.BLOCK_NUMBER]: block.number
|
|
622
|
-
}))
|
|
623
|
-
], Sequencer.prototype, "enqueuePublishL2Block", null);
|