@aztec/sequencer-client 0.0.1-commit.d3ec352c → 0.0.1-commit.d431d1c
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dest/client/sequencer-client.d.ts +12 -12
- package/dest/client/sequencer-client.d.ts.map +1 -1
- package/dest/client/sequencer-client.js +32 -25
- package/dest/config.d.ts +12 -5
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +75 -30
- package/dest/global_variable_builder/global_builder.d.ts +21 -12
- package/dest/global_variable_builder/global_builder.d.ts.map +1 -1
- package/dest/global_variable_builder/global_builder.js +51 -41
- 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 +7 -4
- package/dest/publisher/config.d.ts.map +1 -1
- package/dest/publisher/config.js +9 -3
- package/dest/publisher/sequencer-publisher-factory.d.ts +5 -4
- package/dest/publisher/sequencer-publisher-factory.d.ts.map +1 -1
- package/dest/publisher/sequencer-publisher-factory.js +1 -1
- 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 +15 -86
- package/dest/publisher/sequencer-publisher.d.ts +48 -40
- package/dest/publisher/sequencer-publisher.d.ts.map +1 -1
- package/dest/publisher/sequencer-publisher.js +564 -114
- 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 +1159 -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/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 +22 -2
- package/dest/sequencer/metrics.d.ts.map +1 -1
- package/dest/sequencer/metrics.js +125 -62
- package/dest/sequencer/sequencer.d.ts +107 -131
- package/dest/sequencer/sequencer.d.ts.map +1 -1
- package/dest/sequencer/sequencer.js +690 -602
- package/dest/sequencer/timetable.d.ts +54 -14
- package/dest/sequencer/timetable.d.ts.map +1 -1
- package/dest/sequencer/timetable.js +148 -59
- 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 +4 -3
- package/dest/test/index.d.ts.map +1 -1
- package/dest/test/mock_checkpoint_builder.d.ts +92 -0
- package/dest/test/mock_checkpoint_builder.d.ts.map +1 -0
- package/dest/test/mock_checkpoint_builder.js +208 -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 +30 -28
- package/src/client/sequencer-client.ts +30 -41
- package/src/config.ts +80 -34
- package/src/global_variable_builder/global_builder.ts +63 -59
- package/src/index.ts +1 -7
- package/src/publisher/config.ts +12 -9
- package/src/publisher/sequencer-publisher-factory.ts +5 -4
- package/src/publisher/sequencer-publisher-metrics.ts +16 -72
- package/src/publisher/sequencer-publisher.ts +262 -155
- package/src/sequencer/README.md +531 -0
- package/src/sequencer/checkpoint_proposal_job.ts +841 -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 +164 -70
- package/src/sequencer/sequencer.ts +430 -804
- package/src/sequencer/timetable.ts +173 -79
- package/src/sequencer/types.ts +6 -0
- package/src/sequencer/utils.ts +18 -9
- package/src/test/index.ts +3 -2
- package/src/test/mock_checkpoint_builder.ts +295 -0
- package/src/test/utils.ts +158 -0
- package/dest/sequencer/block_builder.d.ts +0 -28
- package/dest/sequencer/block_builder.d.ts.map +0 -1
- package/dest/sequencer/block_builder.js +0 -134
- package/dest/tx_validator/nullifier_cache.d.ts +0 -14
- package/dest/tx_validator/nullifier_cache.d.ts.map +0 -1
- package/dest/tx_validator/nullifier_cache.js +0 -24
- package/dest/tx_validator/tx_validator_factory.d.ts +0 -18
- package/dest/tx_validator/tx_validator_factory.d.ts.map +0 -1
- package/dest/tx_validator/tx_validator_factory.js +0 -53
- package/src/sequencer/block_builder.ts +0 -222
- package/src/tx_validator/nullifier_cache.ts +0 -30
- package/src/tx_validator/tx_validator_factory.ts +0 -133
|
@@ -0,0 +1,1159 @@
|
|
|
1
|
+
function _ts_add_disposable_resource(env, value, async) {
|
|
2
|
+
if (value !== null && value !== void 0) {
|
|
3
|
+
if (typeof value !== "object" && typeof value !== "function") throw new TypeError("Object expected.");
|
|
4
|
+
var dispose, inner;
|
|
5
|
+
if (async) {
|
|
6
|
+
if (!Symbol.asyncDispose) throw new TypeError("Symbol.asyncDispose is not defined.");
|
|
7
|
+
dispose = value[Symbol.asyncDispose];
|
|
8
|
+
}
|
|
9
|
+
if (dispose === void 0) {
|
|
10
|
+
if (!Symbol.dispose) throw new TypeError("Symbol.dispose is not defined.");
|
|
11
|
+
dispose = value[Symbol.dispose];
|
|
12
|
+
if (async) inner = dispose;
|
|
13
|
+
}
|
|
14
|
+
if (typeof dispose !== "function") throw new TypeError("Object not disposable.");
|
|
15
|
+
if (inner) dispose = function() {
|
|
16
|
+
try {
|
|
17
|
+
inner.call(this);
|
|
18
|
+
} catch (e) {
|
|
19
|
+
return Promise.reject(e);
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
env.stack.push({
|
|
23
|
+
value: value,
|
|
24
|
+
dispose: dispose,
|
|
25
|
+
async: async
|
|
26
|
+
});
|
|
27
|
+
} else if (async) {
|
|
28
|
+
env.stack.push({
|
|
29
|
+
async: true
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
return value;
|
|
33
|
+
}
|
|
34
|
+
function _ts_dispose_resources(env) {
|
|
35
|
+
var _SuppressedError = typeof SuppressedError === "function" ? SuppressedError : function(error, suppressed, message) {
|
|
36
|
+
var e = new Error(message);
|
|
37
|
+
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
38
|
+
};
|
|
39
|
+
return (_ts_dispose_resources = function _ts_dispose_resources(env) {
|
|
40
|
+
function fail(e) {
|
|
41
|
+
env.error = env.hasError ? new _SuppressedError(e, env.error, "An error was suppressed during disposal.") : e;
|
|
42
|
+
env.hasError = true;
|
|
43
|
+
}
|
|
44
|
+
var r, s = 0;
|
|
45
|
+
function next() {
|
|
46
|
+
while(r = env.stack.pop()){
|
|
47
|
+
try {
|
|
48
|
+
if (!r.async && s === 1) return s = 0, env.stack.push(r), Promise.resolve().then(next);
|
|
49
|
+
if (r.dispose) {
|
|
50
|
+
var result = r.dispose.call(r.value);
|
|
51
|
+
if (r.async) return s |= 2, Promise.resolve(result).then(next, function(e) {
|
|
52
|
+
fail(e);
|
|
53
|
+
return next();
|
|
54
|
+
});
|
|
55
|
+
} else s |= 1;
|
|
56
|
+
} catch (e) {
|
|
57
|
+
fail(e);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
if (s === 1) return env.hasError ? Promise.reject(env.error) : Promise.resolve();
|
|
61
|
+
if (env.hasError) throw env.error;
|
|
62
|
+
}
|
|
63
|
+
return next();
|
|
64
|
+
})(env);
|
|
65
|
+
}
|
|
66
|
+
function applyDecs2203RFactory() {
|
|
67
|
+
function createAddInitializerMethod(initializers, decoratorFinishedRef) {
|
|
68
|
+
return function addInitializer(initializer) {
|
|
69
|
+
assertNotFinished(decoratorFinishedRef, "addInitializer");
|
|
70
|
+
assertCallable(initializer, "An initializer");
|
|
71
|
+
initializers.push(initializer);
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
function memberDec(dec, name, desc, initializers, kind, isStatic, isPrivate, metadata, value) {
|
|
75
|
+
var kindStr;
|
|
76
|
+
switch(kind){
|
|
77
|
+
case 1:
|
|
78
|
+
kindStr = "accessor";
|
|
79
|
+
break;
|
|
80
|
+
case 2:
|
|
81
|
+
kindStr = "method";
|
|
82
|
+
break;
|
|
83
|
+
case 3:
|
|
84
|
+
kindStr = "getter";
|
|
85
|
+
break;
|
|
86
|
+
case 4:
|
|
87
|
+
kindStr = "setter";
|
|
88
|
+
break;
|
|
89
|
+
default:
|
|
90
|
+
kindStr = "field";
|
|
91
|
+
}
|
|
92
|
+
var ctx = {
|
|
93
|
+
kind: kindStr,
|
|
94
|
+
name: isPrivate ? "#" + name : name,
|
|
95
|
+
static: isStatic,
|
|
96
|
+
private: isPrivate,
|
|
97
|
+
metadata: metadata
|
|
98
|
+
};
|
|
99
|
+
var decoratorFinishedRef = {
|
|
100
|
+
v: false
|
|
101
|
+
};
|
|
102
|
+
ctx.addInitializer = createAddInitializerMethod(initializers, decoratorFinishedRef);
|
|
103
|
+
var get, set;
|
|
104
|
+
if (kind === 0) {
|
|
105
|
+
if (isPrivate) {
|
|
106
|
+
get = desc.get;
|
|
107
|
+
set = desc.set;
|
|
108
|
+
} else {
|
|
109
|
+
get = function() {
|
|
110
|
+
return this[name];
|
|
111
|
+
};
|
|
112
|
+
set = function(v) {
|
|
113
|
+
this[name] = v;
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
} else if (kind === 2) {
|
|
117
|
+
get = function() {
|
|
118
|
+
return desc.value;
|
|
119
|
+
};
|
|
120
|
+
} else {
|
|
121
|
+
if (kind === 1 || kind === 3) {
|
|
122
|
+
get = function() {
|
|
123
|
+
return desc.get.call(this);
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
if (kind === 1 || kind === 4) {
|
|
127
|
+
set = function(v) {
|
|
128
|
+
desc.set.call(this, v);
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
ctx.access = get && set ? {
|
|
133
|
+
get: get,
|
|
134
|
+
set: set
|
|
135
|
+
} : get ? {
|
|
136
|
+
get: get
|
|
137
|
+
} : {
|
|
138
|
+
set: set
|
|
139
|
+
};
|
|
140
|
+
try {
|
|
141
|
+
return dec(value, ctx);
|
|
142
|
+
} finally{
|
|
143
|
+
decoratorFinishedRef.v = true;
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
function assertNotFinished(decoratorFinishedRef, fnName) {
|
|
147
|
+
if (decoratorFinishedRef.v) {
|
|
148
|
+
throw new Error("attempted to call " + fnName + " after decoration was finished");
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
function assertCallable(fn, hint) {
|
|
152
|
+
if (typeof fn !== "function") {
|
|
153
|
+
throw new TypeError(hint + " must be a function");
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
function assertValidReturnValue(kind, value) {
|
|
157
|
+
var type = typeof value;
|
|
158
|
+
if (kind === 1) {
|
|
159
|
+
if (type !== "object" || value === null) {
|
|
160
|
+
throw new TypeError("accessor decorators must return an object with get, set, or init properties or void 0");
|
|
161
|
+
}
|
|
162
|
+
if (value.get !== undefined) {
|
|
163
|
+
assertCallable(value.get, "accessor.get");
|
|
164
|
+
}
|
|
165
|
+
if (value.set !== undefined) {
|
|
166
|
+
assertCallable(value.set, "accessor.set");
|
|
167
|
+
}
|
|
168
|
+
if (value.init !== undefined) {
|
|
169
|
+
assertCallable(value.init, "accessor.init");
|
|
170
|
+
}
|
|
171
|
+
} else if (type !== "function") {
|
|
172
|
+
var hint;
|
|
173
|
+
if (kind === 0) {
|
|
174
|
+
hint = "field";
|
|
175
|
+
} else if (kind === 10) {
|
|
176
|
+
hint = "class";
|
|
177
|
+
} else {
|
|
178
|
+
hint = "method";
|
|
179
|
+
}
|
|
180
|
+
throw new TypeError(hint + " decorators must return a function or void 0");
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
function applyMemberDec(ret, base, decInfo, name, kind, isStatic, isPrivate, initializers, metadata) {
|
|
184
|
+
var decs = decInfo[0];
|
|
185
|
+
var desc, init, value;
|
|
186
|
+
if (isPrivate) {
|
|
187
|
+
if (kind === 0 || kind === 1) {
|
|
188
|
+
desc = {
|
|
189
|
+
get: decInfo[3],
|
|
190
|
+
set: decInfo[4]
|
|
191
|
+
};
|
|
192
|
+
} else if (kind === 3) {
|
|
193
|
+
desc = {
|
|
194
|
+
get: decInfo[3]
|
|
195
|
+
};
|
|
196
|
+
} else if (kind === 4) {
|
|
197
|
+
desc = {
|
|
198
|
+
set: decInfo[3]
|
|
199
|
+
};
|
|
200
|
+
} else {
|
|
201
|
+
desc = {
|
|
202
|
+
value: decInfo[3]
|
|
203
|
+
};
|
|
204
|
+
}
|
|
205
|
+
} else if (kind !== 0) {
|
|
206
|
+
desc = Object.getOwnPropertyDescriptor(base, name);
|
|
207
|
+
}
|
|
208
|
+
if (kind === 1) {
|
|
209
|
+
value = {
|
|
210
|
+
get: desc.get,
|
|
211
|
+
set: desc.set
|
|
212
|
+
};
|
|
213
|
+
} else if (kind === 2) {
|
|
214
|
+
value = desc.value;
|
|
215
|
+
} else if (kind === 3) {
|
|
216
|
+
value = desc.get;
|
|
217
|
+
} else if (kind === 4) {
|
|
218
|
+
value = desc.set;
|
|
219
|
+
}
|
|
220
|
+
var newValue, get, set;
|
|
221
|
+
if (typeof decs === "function") {
|
|
222
|
+
newValue = memberDec(decs, name, desc, initializers, kind, isStatic, isPrivate, metadata, value);
|
|
223
|
+
if (newValue !== void 0) {
|
|
224
|
+
assertValidReturnValue(kind, newValue);
|
|
225
|
+
if (kind === 0) {
|
|
226
|
+
init = newValue;
|
|
227
|
+
} else if (kind === 1) {
|
|
228
|
+
init = newValue.init;
|
|
229
|
+
get = newValue.get || value.get;
|
|
230
|
+
set = newValue.set || value.set;
|
|
231
|
+
value = {
|
|
232
|
+
get: get,
|
|
233
|
+
set: set
|
|
234
|
+
};
|
|
235
|
+
} else {
|
|
236
|
+
value = newValue;
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
} else {
|
|
240
|
+
for(var i = decs.length - 1; i >= 0; i--){
|
|
241
|
+
var dec = decs[i];
|
|
242
|
+
newValue = memberDec(dec, name, desc, initializers, kind, isStatic, isPrivate, metadata, value);
|
|
243
|
+
if (newValue !== void 0) {
|
|
244
|
+
assertValidReturnValue(kind, newValue);
|
|
245
|
+
var newInit;
|
|
246
|
+
if (kind === 0) {
|
|
247
|
+
newInit = newValue;
|
|
248
|
+
} else if (kind === 1) {
|
|
249
|
+
newInit = newValue.init;
|
|
250
|
+
get = newValue.get || value.get;
|
|
251
|
+
set = newValue.set || value.set;
|
|
252
|
+
value = {
|
|
253
|
+
get: get,
|
|
254
|
+
set: set
|
|
255
|
+
};
|
|
256
|
+
} else {
|
|
257
|
+
value = newValue;
|
|
258
|
+
}
|
|
259
|
+
if (newInit !== void 0) {
|
|
260
|
+
if (init === void 0) {
|
|
261
|
+
init = newInit;
|
|
262
|
+
} else if (typeof init === "function") {
|
|
263
|
+
init = [
|
|
264
|
+
init,
|
|
265
|
+
newInit
|
|
266
|
+
];
|
|
267
|
+
} else {
|
|
268
|
+
init.push(newInit);
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
if (kind === 0 || kind === 1) {
|
|
275
|
+
if (init === void 0) {
|
|
276
|
+
init = function(instance, init) {
|
|
277
|
+
return init;
|
|
278
|
+
};
|
|
279
|
+
} else if (typeof init !== "function") {
|
|
280
|
+
var ownInitializers = init;
|
|
281
|
+
init = function(instance, init) {
|
|
282
|
+
var value = init;
|
|
283
|
+
for(var i = 0; i < ownInitializers.length; i++){
|
|
284
|
+
value = ownInitializers[i].call(instance, value);
|
|
285
|
+
}
|
|
286
|
+
return value;
|
|
287
|
+
};
|
|
288
|
+
} else {
|
|
289
|
+
var originalInitializer = init;
|
|
290
|
+
init = function(instance, init) {
|
|
291
|
+
return originalInitializer.call(instance, init);
|
|
292
|
+
};
|
|
293
|
+
}
|
|
294
|
+
ret.push(init);
|
|
295
|
+
}
|
|
296
|
+
if (kind !== 0) {
|
|
297
|
+
if (kind === 1) {
|
|
298
|
+
desc.get = value.get;
|
|
299
|
+
desc.set = value.set;
|
|
300
|
+
} else if (kind === 2) {
|
|
301
|
+
desc.value = value;
|
|
302
|
+
} else if (kind === 3) {
|
|
303
|
+
desc.get = value;
|
|
304
|
+
} else if (kind === 4) {
|
|
305
|
+
desc.set = value;
|
|
306
|
+
}
|
|
307
|
+
if (isPrivate) {
|
|
308
|
+
if (kind === 1) {
|
|
309
|
+
ret.push(function(instance, args) {
|
|
310
|
+
return value.get.call(instance, args);
|
|
311
|
+
});
|
|
312
|
+
ret.push(function(instance, args) {
|
|
313
|
+
return value.set.call(instance, args);
|
|
314
|
+
});
|
|
315
|
+
} else if (kind === 2) {
|
|
316
|
+
ret.push(value);
|
|
317
|
+
} else {
|
|
318
|
+
ret.push(function(instance, args) {
|
|
319
|
+
return value.call(instance, args);
|
|
320
|
+
});
|
|
321
|
+
}
|
|
322
|
+
} else {
|
|
323
|
+
Object.defineProperty(base, name, desc);
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
function applyMemberDecs(Class, decInfos, metadata) {
|
|
328
|
+
var ret = [];
|
|
329
|
+
var protoInitializers;
|
|
330
|
+
var staticInitializers;
|
|
331
|
+
var existingProtoNonFields = new Map();
|
|
332
|
+
var existingStaticNonFields = new Map();
|
|
333
|
+
for(var i = 0; i < decInfos.length; i++){
|
|
334
|
+
var decInfo = decInfos[i];
|
|
335
|
+
if (!Array.isArray(decInfo)) continue;
|
|
336
|
+
var kind = decInfo[1];
|
|
337
|
+
var name = decInfo[2];
|
|
338
|
+
var isPrivate = decInfo.length > 3;
|
|
339
|
+
var isStatic = kind >= 5;
|
|
340
|
+
var base;
|
|
341
|
+
var initializers;
|
|
342
|
+
if (isStatic) {
|
|
343
|
+
base = Class;
|
|
344
|
+
kind = kind - 5;
|
|
345
|
+
staticInitializers = staticInitializers || [];
|
|
346
|
+
initializers = staticInitializers;
|
|
347
|
+
} else {
|
|
348
|
+
base = Class.prototype;
|
|
349
|
+
protoInitializers = protoInitializers || [];
|
|
350
|
+
initializers = protoInitializers;
|
|
351
|
+
}
|
|
352
|
+
if (kind !== 0 && !isPrivate) {
|
|
353
|
+
var existingNonFields = isStatic ? existingStaticNonFields : existingProtoNonFields;
|
|
354
|
+
var existingKind = existingNonFields.get(name) || 0;
|
|
355
|
+
if (existingKind === true || existingKind === 3 && kind !== 4 || existingKind === 4 && kind !== 3) {
|
|
356
|
+
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);
|
|
357
|
+
} else if (!existingKind && kind > 2) {
|
|
358
|
+
existingNonFields.set(name, kind);
|
|
359
|
+
} else {
|
|
360
|
+
existingNonFields.set(name, true);
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
applyMemberDec(ret, base, decInfo, name, kind, isStatic, isPrivate, initializers, metadata);
|
|
364
|
+
}
|
|
365
|
+
pushInitializers(ret, protoInitializers);
|
|
366
|
+
pushInitializers(ret, staticInitializers);
|
|
367
|
+
return ret;
|
|
368
|
+
}
|
|
369
|
+
function pushInitializers(ret, initializers) {
|
|
370
|
+
if (initializers) {
|
|
371
|
+
ret.push(function(instance) {
|
|
372
|
+
for(var i = 0; i < initializers.length; i++){
|
|
373
|
+
initializers[i].call(instance);
|
|
374
|
+
}
|
|
375
|
+
return instance;
|
|
376
|
+
});
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
function applyClassDecs(targetClass, classDecs, metadata) {
|
|
380
|
+
if (classDecs.length > 0) {
|
|
381
|
+
var initializers = [];
|
|
382
|
+
var newClass = targetClass;
|
|
383
|
+
var name = targetClass.name;
|
|
384
|
+
for(var i = classDecs.length - 1; i >= 0; i--){
|
|
385
|
+
var decoratorFinishedRef = {
|
|
386
|
+
v: false
|
|
387
|
+
};
|
|
388
|
+
try {
|
|
389
|
+
var nextNewClass = classDecs[i](newClass, {
|
|
390
|
+
kind: "class",
|
|
391
|
+
name: name,
|
|
392
|
+
addInitializer: createAddInitializerMethod(initializers, decoratorFinishedRef),
|
|
393
|
+
metadata
|
|
394
|
+
});
|
|
395
|
+
} finally{
|
|
396
|
+
decoratorFinishedRef.v = true;
|
|
397
|
+
}
|
|
398
|
+
if (nextNewClass !== undefined) {
|
|
399
|
+
assertValidReturnValue(10, nextNewClass);
|
|
400
|
+
newClass = nextNewClass;
|
|
401
|
+
}
|
|
402
|
+
}
|
|
403
|
+
return [
|
|
404
|
+
defineMetadata(newClass, metadata),
|
|
405
|
+
function() {
|
|
406
|
+
for(var i = 0; i < initializers.length; i++){
|
|
407
|
+
initializers[i].call(newClass);
|
|
408
|
+
}
|
|
409
|
+
}
|
|
410
|
+
];
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
function defineMetadata(Class, metadata) {
|
|
414
|
+
return Object.defineProperty(Class, Symbol.metadata || Symbol.for("Symbol.metadata"), {
|
|
415
|
+
configurable: true,
|
|
416
|
+
enumerable: true,
|
|
417
|
+
value: metadata
|
|
418
|
+
});
|
|
419
|
+
}
|
|
420
|
+
return function applyDecs2203R(targetClass, memberDecs, classDecs, parentClass) {
|
|
421
|
+
if (parentClass !== void 0) {
|
|
422
|
+
var parentMetadata = parentClass[Symbol.metadata || Symbol.for("Symbol.metadata")];
|
|
423
|
+
}
|
|
424
|
+
var metadata = Object.create(parentMetadata === void 0 ? null : parentMetadata);
|
|
425
|
+
var e = applyMemberDecs(targetClass, memberDecs, metadata);
|
|
426
|
+
if (!classDecs.length) defineMetadata(targetClass, metadata);
|
|
427
|
+
return {
|
|
428
|
+
e: e,
|
|
429
|
+
get c () {
|
|
430
|
+
return applyClassDecs(targetClass, classDecs, metadata);
|
|
431
|
+
}
|
|
432
|
+
};
|
|
433
|
+
};
|
|
434
|
+
}
|
|
435
|
+
function _apply_decs_2203_r(targetClass, memberDecs, classDecs, parentClass) {
|
|
436
|
+
return (_apply_decs_2203_r = applyDecs2203RFactory())(targetClass, memberDecs, classDecs, parentClass);
|
|
437
|
+
}
|
|
438
|
+
var _dec, _dec1, _dec2, _dec3, _dec4, _dec5, _dec6, _dec7, _initProto;
|
|
439
|
+
import { NUM_CHECKPOINT_END_MARKER_FIELDS, getNumBlockEndBlobFields } from '@aztec/blob-lib/encoding';
|
|
440
|
+
import { BLOBS_PER_CHECKPOINT, FIELDS_PER_BLOB } from '@aztec/constants';
|
|
441
|
+
import { BlockNumber } from '@aztec/foundation/branded-types';
|
|
442
|
+
import { randomInt } from '@aztec/foundation/crypto/random';
|
|
443
|
+
import { Signature } from '@aztec/foundation/eth-signature';
|
|
444
|
+
import { filter } from '@aztec/foundation/iterator';
|
|
445
|
+
import { sleep, sleepUntil } from '@aztec/foundation/sleep';
|
|
446
|
+
import { Timer } from '@aztec/foundation/timer';
|
|
447
|
+
import { unfreeze } from '@aztec/foundation/types';
|
|
448
|
+
import { CommitteeAttestationsAndSigners, MaliciousCommitteeAttestationsAndSigners } from '@aztec/stdlib/block';
|
|
449
|
+
import { getSlotStartBuildTimestamp } from '@aztec/stdlib/epoch-helpers';
|
|
450
|
+
import { Gas } from '@aztec/stdlib/gas';
|
|
451
|
+
import { computeInHashFromL1ToL2Messages } from '@aztec/stdlib/messaging';
|
|
452
|
+
import { orderAttestations } from '@aztec/stdlib/p2p';
|
|
453
|
+
import { AttestationTimeoutError } from '@aztec/stdlib/validators';
|
|
454
|
+
import { Attributes, trackSpan } from '@aztec/telemetry-client';
|
|
455
|
+
import { DutyAlreadySignedError, SlashingProtectionError } from '@aztec/validator-ha-signer/errors';
|
|
456
|
+
import { CheckpointVoter } from './checkpoint_voter.js';
|
|
457
|
+
import { SequencerInterruptedError } from './errors.js';
|
|
458
|
+
import { SequencerState } from './utils.js';
|
|
459
|
+
/** How much time to sleep while waiting for min transactions to accumulate for a block */ const TXS_POLLING_MS = 500;
|
|
460
|
+
_dec = trackSpan('CheckpointProposalJob.execute'), _dec1 = trackSpan('CheckpointProposalJob.proposeCheckpoint', function() {
|
|
461
|
+
return {
|
|
462
|
+
// nullish operator needed for tests
|
|
463
|
+
[Attributes.COINBASE]: this.validatorClient.getCoinbaseForAttestor(this.attestorAddress)?.toString(),
|
|
464
|
+
[Attributes.SLOT_NUMBER]: this.slot
|
|
465
|
+
};
|
|
466
|
+
}), _dec2 = trackSpan('CheckpointProposalJob.buildBlocksForCheckpoint'), _dec3 = trackSpan('CheckpointProposalJob.waitUntilNextSubslot'), _dec4 = trackSpan('CheckpointProposalJob.buildSingleBlock'), _dec5 = trackSpan('CheckpointProposalJob.waitForMinTxs'), _dec6 = trackSpan('CheckpointProposalJob.waitForAttestations'), _dec7 = trackSpan('CheckpointProposalJob.waitUntilTimeInSlot');
|
|
467
|
+
/**
|
|
468
|
+
* Handles the execution of a checkpoint proposal after the initial preparation phase.
|
|
469
|
+
* This includes building blocks, collecting attestations, and publishing the checkpoint to L1,
|
|
470
|
+
* as well as enqueueing votes for slashing and governance proposals. This class is created from
|
|
471
|
+
* the Sequencer once the check for being the proposer for the slot has succeeded.
|
|
472
|
+
*/ export class CheckpointProposalJob {
|
|
473
|
+
epoch;
|
|
474
|
+
slot;
|
|
475
|
+
checkpointNumber;
|
|
476
|
+
syncedToBlockNumber;
|
|
477
|
+
proposer;
|
|
478
|
+
publisher;
|
|
479
|
+
attestorAddress;
|
|
480
|
+
invalidateCheckpoint;
|
|
481
|
+
validatorClient;
|
|
482
|
+
globalsBuilder;
|
|
483
|
+
p2pClient;
|
|
484
|
+
worldState;
|
|
485
|
+
l1ToL2MessageSource;
|
|
486
|
+
l2BlockSource;
|
|
487
|
+
checkpointsBuilder;
|
|
488
|
+
blockSink;
|
|
489
|
+
l1Constants;
|
|
490
|
+
config;
|
|
491
|
+
timetable;
|
|
492
|
+
slasherClient;
|
|
493
|
+
epochCache;
|
|
494
|
+
dateProvider;
|
|
495
|
+
metrics;
|
|
496
|
+
eventEmitter;
|
|
497
|
+
setStateFn;
|
|
498
|
+
log;
|
|
499
|
+
tracer;
|
|
500
|
+
static{
|
|
501
|
+
({ e: [_initProto] } = _apply_decs_2203_r(this, [
|
|
502
|
+
[
|
|
503
|
+
_dec,
|
|
504
|
+
2,
|
|
505
|
+
"execute"
|
|
506
|
+
],
|
|
507
|
+
[
|
|
508
|
+
_dec1,
|
|
509
|
+
2,
|
|
510
|
+
"proposeCheckpoint"
|
|
511
|
+
],
|
|
512
|
+
[
|
|
513
|
+
_dec2,
|
|
514
|
+
2,
|
|
515
|
+
"buildBlocksForCheckpoint"
|
|
516
|
+
],
|
|
517
|
+
[
|
|
518
|
+
_dec3,
|
|
519
|
+
2,
|
|
520
|
+
"waitUntilNextSubslot"
|
|
521
|
+
],
|
|
522
|
+
[
|
|
523
|
+
_dec4,
|
|
524
|
+
2,
|
|
525
|
+
"buildSingleBlock"
|
|
526
|
+
],
|
|
527
|
+
[
|
|
528
|
+
_dec5,
|
|
529
|
+
2,
|
|
530
|
+
"waitForMinTxs"
|
|
531
|
+
],
|
|
532
|
+
[
|
|
533
|
+
_dec6,
|
|
534
|
+
2,
|
|
535
|
+
"waitForAttestations"
|
|
536
|
+
],
|
|
537
|
+
[
|
|
538
|
+
_dec7,
|
|
539
|
+
2,
|
|
540
|
+
"waitUntilTimeInSlot"
|
|
541
|
+
]
|
|
542
|
+
], []));
|
|
543
|
+
}
|
|
544
|
+
constructor(epoch, slot, checkpointNumber, syncedToBlockNumber, // TODO(palla/mbps): Can we remove the proposer in favor of attestorAddress? Need to check fisherman-node flows.
|
|
545
|
+
proposer, publisher, attestorAddress, invalidateCheckpoint, validatorClient, globalsBuilder, p2pClient, worldState, l1ToL2MessageSource, l2BlockSource, checkpointsBuilder, blockSink, l1Constants, config, timetable, slasherClient, epochCache, dateProvider, metrics, eventEmitter, setStateFn, log, tracer){
|
|
546
|
+
this.epoch = epoch;
|
|
547
|
+
this.slot = slot;
|
|
548
|
+
this.checkpointNumber = checkpointNumber;
|
|
549
|
+
this.syncedToBlockNumber = syncedToBlockNumber;
|
|
550
|
+
this.proposer = proposer;
|
|
551
|
+
this.publisher = publisher;
|
|
552
|
+
this.attestorAddress = attestorAddress;
|
|
553
|
+
this.invalidateCheckpoint = invalidateCheckpoint;
|
|
554
|
+
this.validatorClient = validatorClient;
|
|
555
|
+
this.globalsBuilder = globalsBuilder;
|
|
556
|
+
this.p2pClient = p2pClient;
|
|
557
|
+
this.worldState = worldState;
|
|
558
|
+
this.l1ToL2MessageSource = l1ToL2MessageSource;
|
|
559
|
+
this.l2BlockSource = l2BlockSource;
|
|
560
|
+
this.checkpointsBuilder = checkpointsBuilder;
|
|
561
|
+
this.blockSink = blockSink;
|
|
562
|
+
this.l1Constants = l1Constants;
|
|
563
|
+
this.config = config;
|
|
564
|
+
this.timetable = timetable;
|
|
565
|
+
this.slasherClient = slasherClient;
|
|
566
|
+
this.epochCache = epochCache;
|
|
567
|
+
this.dateProvider = dateProvider;
|
|
568
|
+
this.metrics = metrics;
|
|
569
|
+
this.eventEmitter = eventEmitter;
|
|
570
|
+
this.setStateFn = setStateFn;
|
|
571
|
+
this.log = log;
|
|
572
|
+
this.tracer = tracer;
|
|
573
|
+
_initProto(this);
|
|
574
|
+
}
|
|
575
|
+
/**
|
|
576
|
+
* Executes the checkpoint proposal job.
|
|
577
|
+
* Returns the published checkpoint if successful, undefined otherwise.
|
|
578
|
+
*/ async execute() {
|
|
579
|
+
// Enqueue governance and slashing votes (returns promises that will be awaited later)
|
|
580
|
+
// In fisherman mode, we simulate slashing but don't actually publish to L1
|
|
581
|
+
// These are constant for the whole slot, so we only enqueue them once
|
|
582
|
+
const votesPromises = new CheckpointVoter(this.slot, this.publisher, this.attestorAddress, this.validatorClient, this.slasherClient, this.l1Constants, this.config, this.metrics, this.log).enqueueVotes();
|
|
583
|
+
// Build and propose the checkpoint. This will enqueue the request on the publisher if a checkpoint is built.
|
|
584
|
+
const checkpoint = await this.proposeCheckpoint();
|
|
585
|
+
// Wait until the voting promises have resolved, so all requests are enqueued (not sent)
|
|
586
|
+
await Promise.all(votesPromises);
|
|
587
|
+
if (checkpoint) {
|
|
588
|
+
this.metrics.recordBlockProposalSuccess();
|
|
589
|
+
}
|
|
590
|
+
// Do not post anything to L1 if we are fishermen, but do perform L1 fee analysis
|
|
591
|
+
if (this.config.fishermanMode) {
|
|
592
|
+
await this.handleCheckpointEndAsFisherman(checkpoint);
|
|
593
|
+
return;
|
|
594
|
+
}
|
|
595
|
+
// Then send everything to L1
|
|
596
|
+
const l1Response = await this.publisher.sendRequests();
|
|
597
|
+
const proposedAction = l1Response?.successfulActions.find((a)=>a === 'propose');
|
|
598
|
+
if (proposedAction) {
|
|
599
|
+
this.eventEmitter.emit('checkpoint-published', {
|
|
600
|
+
checkpoint: this.checkpointNumber,
|
|
601
|
+
slot: this.slot
|
|
602
|
+
});
|
|
603
|
+
const coinbase = checkpoint?.header.coinbase;
|
|
604
|
+
await this.metrics.incFilledSlot(this.publisher.getSenderAddress().toString(), coinbase);
|
|
605
|
+
return checkpoint;
|
|
606
|
+
} else if (checkpoint) {
|
|
607
|
+
this.eventEmitter.emit('checkpoint-publish-failed', {
|
|
608
|
+
...l1Response,
|
|
609
|
+
slot: this.slot
|
|
610
|
+
});
|
|
611
|
+
return undefined;
|
|
612
|
+
}
|
|
613
|
+
}
|
|
614
|
+
async proposeCheckpoint() {
|
|
615
|
+
try {
|
|
616
|
+
const env = {
|
|
617
|
+
stack: [],
|
|
618
|
+
error: void 0,
|
|
619
|
+
hasError: false
|
|
620
|
+
};
|
|
621
|
+
try {
|
|
622
|
+
// Get operator configured coinbase and fee recipient for this attestor
|
|
623
|
+
const coinbase = this.validatorClient.getCoinbaseForAttestor(this.attestorAddress);
|
|
624
|
+
const feeRecipient = this.validatorClient.getFeeRecipientForAttestor(this.attestorAddress);
|
|
625
|
+
// Start the checkpoint
|
|
626
|
+
this.setStateFn(SequencerState.INITIALIZING_CHECKPOINT, this.slot);
|
|
627
|
+
this.metrics.incOpenSlot(this.slot, this.proposer?.toString() ?? 'unknown');
|
|
628
|
+
// Enqueues checkpoint invalidation (constant for the whole slot)
|
|
629
|
+
if (this.invalidateCheckpoint && !this.config.skipInvalidateBlockAsProposer) {
|
|
630
|
+
this.publisher.enqueueInvalidateCheckpoint(this.invalidateCheckpoint);
|
|
631
|
+
}
|
|
632
|
+
// Create checkpoint builder for the slot
|
|
633
|
+
const checkpointGlobalVariables = await this.globalsBuilder.buildCheckpointGlobalVariables(coinbase, feeRecipient, this.slot);
|
|
634
|
+
// Collect L1 to L2 messages for the checkpoint and compute their hash
|
|
635
|
+
const l1ToL2Messages = await this.l1ToL2MessageSource.getL1ToL2Messages(this.checkpointNumber);
|
|
636
|
+
const inHash = computeInHashFromL1ToL2Messages(l1ToL2Messages);
|
|
637
|
+
// Collect the out hashes of all the checkpoints before this one in the same epoch
|
|
638
|
+
const previousCheckpoints = (await this.l2BlockSource.getCheckpointsForEpoch(this.epoch)).filter((c)=>c.number < this.checkpointNumber);
|
|
639
|
+
const previousCheckpointOutHashes = previousCheckpoints.map((c)=>c.getCheckpointOutHash());
|
|
640
|
+
const fork = _ts_add_disposable_resource(env, await this.worldState.fork(this.syncedToBlockNumber, {
|
|
641
|
+
closeDelayMs: 12_000
|
|
642
|
+
}), false);
|
|
643
|
+
// Create checkpoint builder for the entire slot
|
|
644
|
+
const checkpointBuilder = await this.checkpointsBuilder.startCheckpoint(this.checkpointNumber, checkpointGlobalVariables, l1ToL2Messages, previousCheckpointOutHashes, fork);
|
|
645
|
+
// Options for the validator client when creating block and checkpoint proposals
|
|
646
|
+
const blockProposalOptions = {
|
|
647
|
+
publishFullTxs: !!this.config.publishTxsWithProposals,
|
|
648
|
+
broadcastInvalidBlockProposal: this.config.broadcastInvalidBlockProposal
|
|
649
|
+
};
|
|
650
|
+
const checkpointProposalOptions = {
|
|
651
|
+
publishFullTxs: !!this.config.publishTxsWithProposals,
|
|
652
|
+
broadcastInvalidCheckpointProposal: this.config.broadcastInvalidBlockProposal
|
|
653
|
+
};
|
|
654
|
+
let blocksInCheckpoint = [];
|
|
655
|
+
let blockPendingBroadcast = undefined;
|
|
656
|
+
try {
|
|
657
|
+
// Main loop: build blocks for the checkpoint
|
|
658
|
+
const result = await this.buildBlocksForCheckpoint(checkpointBuilder, checkpointGlobalVariables.timestamp, inHash, blockProposalOptions);
|
|
659
|
+
blocksInCheckpoint = result.blocksInCheckpoint;
|
|
660
|
+
blockPendingBroadcast = result.blockPendingBroadcast;
|
|
661
|
+
} catch (err) {
|
|
662
|
+
// These errors are expected in HA mode, so we yield and let another HA node handle the slot
|
|
663
|
+
// The only distinction between the 2 errors is SlashingProtectionError throws when the payload is different,
|
|
664
|
+
// which is normal for block building (may have picked different txs)
|
|
665
|
+
if (err instanceof DutyAlreadySignedError) {
|
|
666
|
+
this.log.info(`Checkpoint proposal for slot ${this.slot} already signed by another HA node, yielding`, {
|
|
667
|
+
slot: this.slot,
|
|
668
|
+
signedByNode: err.signedByNode
|
|
669
|
+
});
|
|
670
|
+
return undefined;
|
|
671
|
+
}
|
|
672
|
+
if (err instanceof SlashingProtectionError) {
|
|
673
|
+
this.log.info(`Checkpoint proposal for slot ${this.slot} blocked by slashing protection, yielding`, {
|
|
674
|
+
slot: this.slot,
|
|
675
|
+
existingMessageHash: err.existingMessageHash,
|
|
676
|
+
attemptedMessageHash: err.attemptedMessageHash
|
|
677
|
+
});
|
|
678
|
+
return undefined;
|
|
679
|
+
}
|
|
680
|
+
throw err;
|
|
681
|
+
}
|
|
682
|
+
if (blocksInCheckpoint.length === 0) {
|
|
683
|
+
this.log.warn(`No blocks were built for slot ${this.slot}`, {
|
|
684
|
+
slot: this.slot
|
|
685
|
+
});
|
|
686
|
+
this.eventEmitter.emit('checkpoint-empty', {
|
|
687
|
+
slot: this.slot
|
|
688
|
+
});
|
|
689
|
+
return undefined;
|
|
690
|
+
}
|
|
691
|
+
// Assemble and broadcast the checkpoint proposal, including the last block that was not
|
|
692
|
+
// broadcasted yet, and wait to collect the committee attestations.
|
|
693
|
+
this.setStateFn(SequencerState.ASSEMBLING_CHECKPOINT, this.slot);
|
|
694
|
+
const checkpoint = await checkpointBuilder.completeCheckpoint();
|
|
695
|
+
// Do not collect attestations nor publish to L1 in fisherman mode
|
|
696
|
+
if (this.config.fishermanMode) {
|
|
697
|
+
this.log.info(`Built checkpoint for slot ${this.slot} with ${blocksInCheckpoint.length} blocks. ` + `Skipping proposal in fisherman mode.`, {
|
|
698
|
+
slot: this.slot,
|
|
699
|
+
checkpoint: checkpoint.header.toInspect(),
|
|
700
|
+
blocksBuilt: blocksInCheckpoint.length
|
|
701
|
+
});
|
|
702
|
+
this.metrics.recordCheckpointSuccess();
|
|
703
|
+
return checkpoint;
|
|
704
|
+
}
|
|
705
|
+
// Include the block pending broadcast in the checkpoint proposal if any
|
|
706
|
+
const lastBlock = blockPendingBroadcast && {
|
|
707
|
+
blockHeader: blockPendingBroadcast.block.header,
|
|
708
|
+
indexWithinCheckpoint: blockPendingBroadcast.block.indexWithinCheckpoint,
|
|
709
|
+
txs: blockPendingBroadcast.txs
|
|
710
|
+
};
|
|
711
|
+
// Create the checkpoint proposal and broadcast it
|
|
712
|
+
const proposal = await this.validatorClient.createCheckpointProposal(checkpoint.header, checkpoint.archive.root, lastBlock, this.proposer, checkpointProposalOptions);
|
|
713
|
+
const blockProposedAt = this.dateProvider.now();
|
|
714
|
+
await this.p2pClient.broadcastCheckpointProposal(proposal);
|
|
715
|
+
this.setStateFn(SequencerState.COLLECTING_ATTESTATIONS, this.slot);
|
|
716
|
+
const attestations = await this.waitForAttestations(proposal);
|
|
717
|
+
const blockAttestedAt = this.dateProvider.now();
|
|
718
|
+
this.metrics.recordCheckpointAttestationDelay(blockAttestedAt - blockProposedAt);
|
|
719
|
+
// Proposer must sign over the attestations before pushing them to L1
|
|
720
|
+
const signer = this.proposer ?? this.publisher.getSenderAddress();
|
|
721
|
+
let attestationsSignature;
|
|
722
|
+
try {
|
|
723
|
+
attestationsSignature = await this.validatorClient.signAttestationsAndSigners(attestations, signer, this.slot, this.checkpointNumber);
|
|
724
|
+
} catch (err) {
|
|
725
|
+
// We shouldn't really get here since we yield to another HA node
|
|
726
|
+
// as soon as we see these errors when creating block proposals.
|
|
727
|
+
if (err instanceof DutyAlreadySignedError) {
|
|
728
|
+
this.log.info(`Attestations signature for slot ${this.slot} already signed by another HA node, yielding`, {
|
|
729
|
+
slot: this.slot,
|
|
730
|
+
signedByNode: err.signedByNode
|
|
731
|
+
});
|
|
732
|
+
return undefined;
|
|
733
|
+
}
|
|
734
|
+
if (err instanceof SlashingProtectionError) {
|
|
735
|
+
this.log.info(`Attestations signature for slot ${this.slot} blocked by slashing protection, yielding`, {
|
|
736
|
+
slot: this.slot,
|
|
737
|
+
existingMessageHash: err.existingMessageHash,
|
|
738
|
+
attemptedMessageHash: err.attemptedMessageHash
|
|
739
|
+
});
|
|
740
|
+
return undefined;
|
|
741
|
+
}
|
|
742
|
+
throw err;
|
|
743
|
+
}
|
|
744
|
+
// Enqueue publishing the checkpoint to L1
|
|
745
|
+
this.setStateFn(SequencerState.PUBLISHING_CHECKPOINT, this.slot);
|
|
746
|
+
const aztecSlotDuration = this.l1Constants.slotDuration;
|
|
747
|
+
const slotStartBuildTimestamp = this.getSlotStartBuildTimestamp();
|
|
748
|
+
const txTimeoutAt = new Date((slotStartBuildTimestamp + aztecSlotDuration) * 1000);
|
|
749
|
+
await this.publisher.enqueueProposeCheckpoint(checkpoint, attestations, attestationsSignature, {
|
|
750
|
+
txTimeoutAt,
|
|
751
|
+
forcePendingCheckpointNumber: this.invalidateCheckpoint?.forcePendingCheckpointNumber
|
|
752
|
+
});
|
|
753
|
+
return checkpoint;
|
|
754
|
+
} catch (e) {
|
|
755
|
+
env.error = e;
|
|
756
|
+
env.hasError = true;
|
|
757
|
+
} finally{
|
|
758
|
+
_ts_dispose_resources(env);
|
|
759
|
+
}
|
|
760
|
+
} catch (err) {
|
|
761
|
+
if (err && (err instanceof DutyAlreadySignedError || err instanceof SlashingProtectionError)) {
|
|
762
|
+
// swallow this error. It's already been logged by a function deeper in the stack
|
|
763
|
+
return undefined;
|
|
764
|
+
}
|
|
765
|
+
this.log.error(`Error building checkpoint at slot ${this.slot}`, err);
|
|
766
|
+
return undefined;
|
|
767
|
+
}
|
|
768
|
+
}
|
|
769
|
+
/**
|
|
770
|
+
* Builds blocks for a checkpoint within the current slot.
|
|
771
|
+
*/ async buildBlocksForCheckpoint(checkpointBuilder, timestamp, inHash, blockProposalOptions) {
|
|
772
|
+
const blocksInCheckpoint = [];
|
|
773
|
+
const txHashesAlreadyIncluded = new Set();
|
|
774
|
+
const initialBlockNumber = BlockNumber(this.syncedToBlockNumber + 1);
|
|
775
|
+
// Remaining blob fields available for blocks (checkpoint end marker already subtracted)
|
|
776
|
+
let remainingBlobFields = BLOBS_PER_CHECKPOINT * FIELDS_PER_BLOB - NUM_CHECKPOINT_END_MARKER_FIELDS;
|
|
777
|
+
// Last block in the checkpoint will usually be flagged as pending broadcast, so we send it along with the checkpoint proposal
|
|
778
|
+
let blockPendingBroadcast = undefined;
|
|
779
|
+
while(true){
|
|
780
|
+
const blocksBuilt = blocksInCheckpoint.length;
|
|
781
|
+
const indexWithinCheckpoint = blocksBuilt;
|
|
782
|
+
const blockNumber = BlockNumber(initialBlockNumber + blocksBuilt);
|
|
783
|
+
const secondsIntoSlot = this.getSecondsIntoSlot();
|
|
784
|
+
const timingInfo = this.timetable.canStartNextBlock(secondsIntoSlot);
|
|
785
|
+
if (!timingInfo.canStart) {
|
|
786
|
+
this.log.debug(`Not enough time left in slot to start another block`, {
|
|
787
|
+
slot: this.slot,
|
|
788
|
+
blocksBuilt,
|
|
789
|
+
secondsIntoSlot
|
|
790
|
+
});
|
|
791
|
+
break;
|
|
792
|
+
}
|
|
793
|
+
const buildResult = await this.buildSingleBlock(checkpointBuilder, {
|
|
794
|
+
// Create all blocks with the same timestamp
|
|
795
|
+
blockTimestamp: timestamp,
|
|
796
|
+
// Create an empty block if we haven't already and this is the last one
|
|
797
|
+
forceCreate: timingInfo.isLastBlock && blocksBuilt === 0 && this.config.buildCheckpointIfEmpty,
|
|
798
|
+
// Build deadline is only set if we are enforcing the timetable
|
|
799
|
+
buildDeadline: timingInfo.deadline ? new Date((this.getSlotStartBuildTimestamp() + timingInfo.deadline) * 1000) : undefined,
|
|
800
|
+
blockNumber,
|
|
801
|
+
indexWithinCheckpoint,
|
|
802
|
+
txHashesAlreadyIncluded,
|
|
803
|
+
remainingBlobFields
|
|
804
|
+
});
|
|
805
|
+
if (!buildResult && timingInfo.isLastBlock) {
|
|
806
|
+
break;
|
|
807
|
+
} else if (!buildResult && timingInfo.deadline !== undefined) {
|
|
808
|
+
// But if there is still time for more blocks, wait until the next subslot and try again
|
|
809
|
+
await this.waitUntilNextSubslot(timingInfo.deadline);
|
|
810
|
+
continue;
|
|
811
|
+
} else if (!buildResult) {
|
|
812
|
+
break;
|
|
813
|
+
} else if ('error' in buildResult) {
|
|
814
|
+
// If there was an error building the block, just exit the loop and give up the rest of the slot
|
|
815
|
+
if (!(buildResult.error instanceof SequencerInterruptedError)) {
|
|
816
|
+
this.log.warn(`Halting block building for slot ${this.slot}`, {
|
|
817
|
+
slot: this.slot,
|
|
818
|
+
blocksBuilt,
|
|
819
|
+
error: buildResult.error
|
|
820
|
+
});
|
|
821
|
+
}
|
|
822
|
+
break;
|
|
823
|
+
}
|
|
824
|
+
const { block, usedTxs, remainingBlobFields: newRemainingBlobFields } = buildResult;
|
|
825
|
+
blocksInCheckpoint.push(block);
|
|
826
|
+
// Update remaining blob fields for the next block
|
|
827
|
+
remainingBlobFields = newRemainingBlobFields;
|
|
828
|
+
// Sync the proposed block to the archiver to make it available
|
|
829
|
+
// Note that the checkpoint builder uses its own fork so it should not need to wait for this syncing
|
|
830
|
+
// Eventually we should refactor the checkpoint builder to not need a separate long-lived fork
|
|
831
|
+
await this.syncProposedBlockToArchiver(block);
|
|
832
|
+
// If this is the last block, exit the loop now so we start collecting attestations
|
|
833
|
+
if (timingInfo.isLastBlock) {
|
|
834
|
+
this.log.verbose(`Completed final block ${blockNumber} for slot ${this.slot}`, {
|
|
835
|
+
slot: this.slot,
|
|
836
|
+
blockNumber,
|
|
837
|
+
blocksBuilt
|
|
838
|
+
});
|
|
839
|
+
blockPendingBroadcast = {
|
|
840
|
+
block,
|
|
841
|
+
txs: usedTxs
|
|
842
|
+
};
|
|
843
|
+
break;
|
|
844
|
+
}
|
|
845
|
+
// For non-last blocks, broadcast the block proposal (unless we're in fisherman mode)
|
|
846
|
+
// If the block is the last one, we'll broadcast it along with the checkpoint at the end of the loop
|
|
847
|
+
if (!this.config.fishermanMode) {
|
|
848
|
+
const proposal = await this.validatorClient.createBlockProposal(block.header, block.indexWithinCheckpoint, inHash, block.archive.root, usedTxs, this.proposer, blockProposalOptions);
|
|
849
|
+
await this.p2pClient.broadcastProposal(proposal);
|
|
850
|
+
}
|
|
851
|
+
// Wait until the next block's start time
|
|
852
|
+
await this.waitUntilNextSubslot(timingInfo.deadline);
|
|
853
|
+
}
|
|
854
|
+
this.log.verbose(`Block building loop completed for slot ${this.slot}`, {
|
|
855
|
+
slot: this.slot,
|
|
856
|
+
blocksBuilt: blocksInCheckpoint.length
|
|
857
|
+
});
|
|
858
|
+
return {
|
|
859
|
+
blocksInCheckpoint,
|
|
860
|
+
blockPendingBroadcast
|
|
861
|
+
};
|
|
862
|
+
}
|
|
863
|
+
/** Sleeps until it is time to produce the next block in the slot */ async waitUntilNextSubslot(nextSubslotStart) {
|
|
864
|
+
this.setStateFn(SequencerState.WAITING_UNTIL_NEXT_BLOCK, this.slot);
|
|
865
|
+
this.log.verbose(`Waiting until time for the next block at ${nextSubslotStart}s into slot`, {
|
|
866
|
+
slot: this.slot
|
|
867
|
+
});
|
|
868
|
+
await this.waitUntilTimeInSlot(nextSubslotStart);
|
|
869
|
+
}
|
|
870
|
+
/** Builds a single block. Called from the main block building loop. */ async buildSingleBlock(checkpointBuilder, opts) {
|
|
871
|
+
const { blockTimestamp, forceCreate, blockNumber, indexWithinCheckpoint, buildDeadline, txHashesAlreadyIncluded, remainingBlobFields } = opts;
|
|
872
|
+
this.log.verbose(`Preparing block ${blockNumber} index ${indexWithinCheckpoint} at checkpoint ${this.checkpointNumber} for slot ${this.slot}`, {
|
|
873
|
+
...checkpointBuilder.getConstantData(),
|
|
874
|
+
...opts
|
|
875
|
+
});
|
|
876
|
+
try {
|
|
877
|
+
// Wait until we have enough txs to build the block
|
|
878
|
+
const minTxs = this.config.minTxsPerBlock;
|
|
879
|
+
const { availableTxs, canStartBuilding } = await this.waitForMinTxs(opts);
|
|
880
|
+
if (!canStartBuilding) {
|
|
881
|
+
this.log.warn(`Not enough txs to build block ${blockNumber} at index ${indexWithinCheckpoint} in slot ${this.slot} (got ${availableTxs} txs but needs ${minTxs})`, {
|
|
882
|
+
blockNumber,
|
|
883
|
+
slot: this.slot,
|
|
884
|
+
indexWithinCheckpoint
|
|
885
|
+
});
|
|
886
|
+
this.eventEmitter.emit('block-tx-count-check-failed', {
|
|
887
|
+
minTxs,
|
|
888
|
+
availableTxs,
|
|
889
|
+
slot: this.slot
|
|
890
|
+
});
|
|
891
|
+
this.metrics.recordBlockProposalFailed('insufficient_txs');
|
|
892
|
+
return undefined;
|
|
893
|
+
}
|
|
894
|
+
// Create iterator to pending txs. We filter out txs already included in previous blocks in the checkpoint
|
|
895
|
+
// just in case p2p failed to sync the provisional block and didn't get to remove those txs from the mempool yet.
|
|
896
|
+
const pendingTxs = filter(this.p2pClient.iteratePendingTxs(), (tx)=>!txHashesAlreadyIncluded.has(tx.txHash.toString()));
|
|
897
|
+
this.log.debug(`Building block ${blockNumber} at index ${indexWithinCheckpoint} for slot ${this.slot} with ${availableTxs} available txs`, {
|
|
898
|
+
slot: this.slot,
|
|
899
|
+
blockNumber,
|
|
900
|
+
indexWithinCheckpoint
|
|
901
|
+
});
|
|
902
|
+
this.setStateFn(SequencerState.CREATING_BLOCK, this.slot);
|
|
903
|
+
// Calculate blob fields limit for txs (remaining capacity - this block's end overhead)
|
|
904
|
+
const blockEndOverhead = getNumBlockEndBlobFields(indexWithinCheckpoint === 0);
|
|
905
|
+
const maxBlobFieldsForTxs = remainingBlobFields - blockEndOverhead;
|
|
906
|
+
const blockBuilderOptions = {
|
|
907
|
+
maxTransactions: this.config.maxTxsPerBlock,
|
|
908
|
+
maxBlockSize: this.config.maxBlockSizeInBytes,
|
|
909
|
+
maxBlockGas: new Gas(this.config.maxDABlockGas, this.config.maxL2BlockGas),
|
|
910
|
+
maxBlobFields: maxBlobFieldsForTxs,
|
|
911
|
+
deadline: buildDeadline
|
|
912
|
+
};
|
|
913
|
+
// Actually build the block by executing txs
|
|
914
|
+
const workTimer = new Timer();
|
|
915
|
+
const { publicGas, block, publicProcessorDuration, numTxs, blockBuildingTimer, usedTxs, failedTxs, usedTxBlobFields } = await checkpointBuilder.buildBlock(pendingTxs, blockNumber, blockTimestamp, blockBuilderOptions);
|
|
916
|
+
const blockBuildDuration = workTimer.ms();
|
|
917
|
+
// If any txs failed during execution, drop them from the mempool so we don't pick them up again
|
|
918
|
+
await this.dropFailedTxsFromP2P(failedTxs);
|
|
919
|
+
// Check if we have created a block with enough txs. If there were invalid txs in the pool, or if execution took
|
|
920
|
+
// too long, then we may not get to minTxsPerBlock after executing public functions.
|
|
921
|
+
const minValidTxs = this.config.minValidTxsPerBlock ?? minTxs;
|
|
922
|
+
if (!forceCreate && numTxs < minValidTxs) {
|
|
923
|
+
this.log.warn(`Block ${blockNumber} at index ${indexWithinCheckpoint} on slot ${this.slot} has too few valid txs to be proposed (got ${numTxs} but required ${minValidTxs})`, {
|
|
924
|
+
slot: this.slot,
|
|
925
|
+
blockNumber,
|
|
926
|
+
numTxs,
|
|
927
|
+
indexWithinCheckpoint
|
|
928
|
+
});
|
|
929
|
+
this.eventEmitter.emit('block-tx-count-check-failed', {
|
|
930
|
+
minTxs: minValidTxs,
|
|
931
|
+
availableTxs: numTxs,
|
|
932
|
+
slot: this.slot
|
|
933
|
+
});
|
|
934
|
+
this.metrics.recordBlockProposalFailed('insufficient_valid_txs');
|
|
935
|
+
return undefined;
|
|
936
|
+
}
|
|
937
|
+
// Block creation succeeded, emit stats and metrics
|
|
938
|
+
const blockStats = {
|
|
939
|
+
eventName: 'l2-block-built',
|
|
940
|
+
duration: blockBuildDuration,
|
|
941
|
+
publicProcessDuration: publicProcessorDuration,
|
|
942
|
+
rollupCircuitsDuration: blockBuildingTimer.ms(),
|
|
943
|
+
...block.getStats()
|
|
944
|
+
};
|
|
945
|
+
const blockHash = await block.hash();
|
|
946
|
+
const txHashes = block.body.txEffects.map((tx)=>tx.txHash);
|
|
947
|
+
const manaPerSec = publicGas.l2Gas / (blockBuildDuration / 1000);
|
|
948
|
+
this.log.info(`Built block ${block.number} at checkpoint ${this.checkpointNumber} for slot ${this.slot} with ${numTxs} txs`, {
|
|
949
|
+
blockHash,
|
|
950
|
+
txHashes,
|
|
951
|
+
manaPerSec,
|
|
952
|
+
...blockStats
|
|
953
|
+
});
|
|
954
|
+
this.eventEmitter.emit('block-proposed', {
|
|
955
|
+
blockNumber: block.number,
|
|
956
|
+
slot: this.slot
|
|
957
|
+
});
|
|
958
|
+
this.metrics.recordBuiltBlock(blockBuildDuration, publicGas.l2Gas);
|
|
959
|
+
return {
|
|
960
|
+
block,
|
|
961
|
+
usedTxs,
|
|
962
|
+
remainingBlobFields: maxBlobFieldsForTxs - usedTxBlobFields
|
|
963
|
+
};
|
|
964
|
+
} catch (err) {
|
|
965
|
+
this.eventEmitter.emit('block-build-failed', {
|
|
966
|
+
reason: err.message,
|
|
967
|
+
slot: this.slot
|
|
968
|
+
});
|
|
969
|
+
this.log.error(`Error building block`, err, {
|
|
970
|
+
blockNumber,
|
|
971
|
+
slot: this.slot
|
|
972
|
+
});
|
|
973
|
+
this.metrics.recordBlockProposalFailed(err.name || 'unknown_error');
|
|
974
|
+
this.metrics.recordFailedBlock();
|
|
975
|
+
return {
|
|
976
|
+
error: err
|
|
977
|
+
};
|
|
978
|
+
}
|
|
979
|
+
}
|
|
980
|
+
/** Waits until minTxs are available on the pool for building a block. */ async waitForMinTxs(opts) {
|
|
981
|
+
const minTxs = this.config.minTxsPerBlock;
|
|
982
|
+
const { indexWithinCheckpoint, blockNumber, buildDeadline, forceCreate } = opts;
|
|
983
|
+
// Deadline is undefined if we are not enforcing the timetable, meaning we'll exit immediately when out of time
|
|
984
|
+
const startBuildingDeadline = buildDeadline ? new Date(buildDeadline.getTime() - this.timetable.minExecutionTime * 1000) : undefined;
|
|
985
|
+
let availableTxs = await this.p2pClient.getPendingTxCount();
|
|
986
|
+
while(!forceCreate && availableTxs < minTxs){
|
|
987
|
+
// If we're past deadline, or we have no deadline, give up
|
|
988
|
+
const now = this.dateProvider.nowAsDate();
|
|
989
|
+
if (startBuildingDeadline === undefined || now >= startBuildingDeadline) {
|
|
990
|
+
return {
|
|
991
|
+
canStartBuilding: false,
|
|
992
|
+
availableTxs: availableTxs
|
|
993
|
+
};
|
|
994
|
+
}
|
|
995
|
+
// Wait a bit before checking again
|
|
996
|
+
this.setStateFn(SequencerState.WAITING_FOR_TXS, this.slot);
|
|
997
|
+
this.log.verbose(`Waiting for enough txs to build block ${blockNumber} at index ${indexWithinCheckpoint} in slot ${this.slot} (have ${availableTxs} but need ${minTxs})`, {
|
|
998
|
+
blockNumber,
|
|
999
|
+
slot: this.slot,
|
|
1000
|
+
indexWithinCheckpoint
|
|
1001
|
+
});
|
|
1002
|
+
await sleep(TXS_POLLING_MS);
|
|
1003
|
+
availableTxs = await this.p2pClient.getPendingTxCount();
|
|
1004
|
+
}
|
|
1005
|
+
return {
|
|
1006
|
+
canStartBuilding: true,
|
|
1007
|
+
availableTxs
|
|
1008
|
+
};
|
|
1009
|
+
}
|
|
1010
|
+
/**
|
|
1011
|
+
* Waits for enough attestations to be collected via p2p.
|
|
1012
|
+
* This is run after all blocks for the checkpoint have been built.
|
|
1013
|
+
*/ async waitForAttestations(proposal) {
|
|
1014
|
+
if (this.config.fishermanMode) {
|
|
1015
|
+
this.log.debug('Skipping attestation collection in fisherman mode');
|
|
1016
|
+
return CommitteeAttestationsAndSigners.empty();
|
|
1017
|
+
}
|
|
1018
|
+
const slotNumber = proposal.slotNumber;
|
|
1019
|
+
const { committee, seed, epoch } = await this.epochCache.getCommittee(slotNumber);
|
|
1020
|
+
if (!committee) {
|
|
1021
|
+
throw new Error('No committee when collecting attestations');
|
|
1022
|
+
} else if (committee.length === 0) {
|
|
1023
|
+
this.log.verbose(`Attesting committee is empty`);
|
|
1024
|
+
return CommitteeAttestationsAndSigners.empty();
|
|
1025
|
+
} else {
|
|
1026
|
+
this.log.debug(`Attesting committee length is ${committee.length}`, {
|
|
1027
|
+
committee
|
|
1028
|
+
});
|
|
1029
|
+
}
|
|
1030
|
+
const numberOfRequiredAttestations = Math.floor(committee.length * 2 / 3) + 1;
|
|
1031
|
+
if (this.config.skipCollectingAttestations) {
|
|
1032
|
+
this.log.warn('Skipping attestation collection as per config (attesting with own keys only)');
|
|
1033
|
+
const attestations = await this.validatorClient?.collectOwnAttestations(proposal);
|
|
1034
|
+
return new CommitteeAttestationsAndSigners(orderAttestations(attestations ?? [], committee));
|
|
1035
|
+
}
|
|
1036
|
+
const attestationTimeAllowed = this.config.enforceTimeTable ? this.timetable.getMaxAllowedTime(SequencerState.PUBLISHING_CHECKPOINT) : this.l1Constants.slotDuration;
|
|
1037
|
+
const attestationDeadline = new Date(this.dateProvider.now() + attestationTimeAllowed * 1000);
|
|
1038
|
+
this.metrics.recordRequiredAttestations(numberOfRequiredAttestations, attestationTimeAllowed);
|
|
1039
|
+
const collectAttestationsTimer = new Timer();
|
|
1040
|
+
let collectedAttestationsCount = 0;
|
|
1041
|
+
try {
|
|
1042
|
+
const attestations = await this.validatorClient.collectAttestations(proposal, numberOfRequiredAttestations, attestationDeadline);
|
|
1043
|
+
collectedAttestationsCount = attestations.length;
|
|
1044
|
+
// Rollup contract requires that the signatures are provided in the order of the committee
|
|
1045
|
+
const sorted = orderAttestations(attestations, committee);
|
|
1046
|
+
// Manipulate the attestations if we've been configured to do so
|
|
1047
|
+
if (this.config.injectFakeAttestation || this.config.shuffleAttestationOrdering) {
|
|
1048
|
+
return this.manipulateAttestations(proposal.slotNumber, epoch, seed, committee, sorted);
|
|
1049
|
+
}
|
|
1050
|
+
return new CommitteeAttestationsAndSigners(sorted);
|
|
1051
|
+
} catch (err) {
|
|
1052
|
+
if (err && err instanceof AttestationTimeoutError) {
|
|
1053
|
+
collectedAttestationsCount = err.collectedCount;
|
|
1054
|
+
}
|
|
1055
|
+
throw err;
|
|
1056
|
+
} finally{
|
|
1057
|
+
this.metrics.recordCollectedAttestations(collectedAttestationsCount, collectAttestationsTimer.ms());
|
|
1058
|
+
}
|
|
1059
|
+
}
|
|
1060
|
+
/** Breaks the attestations before publishing based on attack configs */ manipulateAttestations(slotNumber, epoch, seed, committee, attestations) {
|
|
1061
|
+
// Compute the proposer index in the committee, since we dont want to tweak it.
|
|
1062
|
+
// Otherwise, the L1 rollup contract will reject the block outright.
|
|
1063
|
+
const proposerIndex = Number(this.epochCache.computeProposerIndex(slotNumber, epoch, seed, BigInt(committee.length)));
|
|
1064
|
+
if (this.config.injectFakeAttestation) {
|
|
1065
|
+
// Find non-empty attestations that are not from the proposer
|
|
1066
|
+
const nonProposerIndices = [];
|
|
1067
|
+
for(let i = 0; i < attestations.length; i++){
|
|
1068
|
+
if (!attestations[i].signature.isEmpty() && i !== proposerIndex) {
|
|
1069
|
+
nonProposerIndices.push(i);
|
|
1070
|
+
}
|
|
1071
|
+
}
|
|
1072
|
+
if (nonProposerIndices.length > 0) {
|
|
1073
|
+
const targetIndex = nonProposerIndices[randomInt(nonProposerIndices.length)];
|
|
1074
|
+
this.log.warn(`Injecting fake attestation in checkpoint for slot ${slotNumber} at index ${targetIndex}`);
|
|
1075
|
+
unfreeze(attestations[targetIndex]).signature = Signature.random();
|
|
1076
|
+
}
|
|
1077
|
+
return new CommitteeAttestationsAndSigners(attestations);
|
|
1078
|
+
}
|
|
1079
|
+
if (this.config.shuffleAttestationOrdering) {
|
|
1080
|
+
this.log.warn(`Shuffling attestation ordering in checkpoint for slot ${slotNumber} (proposer #${proposerIndex})`);
|
|
1081
|
+
const shuffled = [
|
|
1082
|
+
...attestations
|
|
1083
|
+
];
|
|
1084
|
+
const [i, j] = [
|
|
1085
|
+
(proposerIndex + 1) % shuffled.length,
|
|
1086
|
+
(proposerIndex + 2) % shuffled.length
|
|
1087
|
+
];
|
|
1088
|
+
const valueI = shuffled[i];
|
|
1089
|
+
const valueJ = shuffled[j];
|
|
1090
|
+
shuffled[i] = valueJ;
|
|
1091
|
+
shuffled[j] = valueI;
|
|
1092
|
+
const signers = new CommitteeAttestationsAndSigners(attestations).getSigners();
|
|
1093
|
+
return new MaliciousCommitteeAttestationsAndSigners(shuffled, signers);
|
|
1094
|
+
}
|
|
1095
|
+
return new CommitteeAttestationsAndSigners(attestations);
|
|
1096
|
+
}
|
|
1097
|
+
async dropFailedTxsFromP2P(failedTxs) {
|
|
1098
|
+
if (failedTxs.length === 0) {
|
|
1099
|
+
return;
|
|
1100
|
+
}
|
|
1101
|
+
const failedTxData = failedTxs.map((fail)=>fail.tx);
|
|
1102
|
+
const failedTxHashes = failedTxData.map((tx)=>tx.getTxHash());
|
|
1103
|
+
this.log.verbose(`Dropping failed txs ${failedTxHashes.join(', ')}`);
|
|
1104
|
+
await this.p2pClient.deleteTxs(failedTxHashes);
|
|
1105
|
+
}
|
|
1106
|
+
/**
|
|
1107
|
+
* Adds the proposed block to the archiver so it's available via P2P.
|
|
1108
|
+
* Gossip doesn't echo messages back to the sender, so the proposer's archiver/world-state
|
|
1109
|
+
* would never receive its own block without this explicit sync.
|
|
1110
|
+
*/ async syncProposedBlockToArchiver(block) {
|
|
1111
|
+
// TODO(palla/mbps): Change default to false once block sync is stable.
|
|
1112
|
+
if (this.config.skipPushProposedBlocksToArchiver !== false) {
|
|
1113
|
+
this.log.warn(`Skipping push of proposed block ${block.number} to archiver`, {
|
|
1114
|
+
blockNumber: block.number,
|
|
1115
|
+
slot: block.header.globalVariables.slotNumber
|
|
1116
|
+
});
|
|
1117
|
+
return;
|
|
1118
|
+
}
|
|
1119
|
+
this.log.debug(`Syncing proposed block ${block.number} to archiver`, {
|
|
1120
|
+
blockNumber: block.number,
|
|
1121
|
+
slot: block.header.globalVariables.slotNumber
|
|
1122
|
+
});
|
|
1123
|
+
await this.blockSink.addBlock(block);
|
|
1124
|
+
}
|
|
1125
|
+
/** Runs fee analysis and logs checkpoint outcome as fisherman */ async handleCheckpointEndAsFisherman(checkpoint) {
|
|
1126
|
+
// Perform L1 fee analysis before clearing requests
|
|
1127
|
+
// The callback is invoked asynchronously after the next block is mined
|
|
1128
|
+
const feeAnalysis = await this.publisher.analyzeL1Fees(this.slot, (analysis)=>this.metrics.recordFishermanFeeAnalysis(analysis));
|
|
1129
|
+
if (checkpoint) {
|
|
1130
|
+
this.log.info(`Validation checkpoint building SUCCEEDED for slot ${this.slot}`, {
|
|
1131
|
+
...checkpoint.toCheckpointInfo(),
|
|
1132
|
+
...checkpoint.getStats(),
|
|
1133
|
+
feeAnalysisId: feeAnalysis?.id
|
|
1134
|
+
});
|
|
1135
|
+
} else {
|
|
1136
|
+
this.log.warn(`Validation block building FAILED for slot ${this.slot}`, {
|
|
1137
|
+
slot: this.slot,
|
|
1138
|
+
feeAnalysisId: feeAnalysis?.id
|
|
1139
|
+
});
|
|
1140
|
+
this.metrics.recordBlockProposalFailed('block_build_failed');
|
|
1141
|
+
}
|
|
1142
|
+
this.publisher.clearPendingRequests();
|
|
1143
|
+
}
|
|
1144
|
+
/** Waits until a specific time within the current slot */ async waitUntilTimeInSlot(targetSecondsIntoSlot) {
|
|
1145
|
+
const slotStartTimestamp = this.getSlotStartBuildTimestamp();
|
|
1146
|
+
const targetTimestamp = slotStartTimestamp + targetSecondsIntoSlot;
|
|
1147
|
+
await sleepUntil(new Date(targetTimestamp * 1000), this.dateProvider.nowAsDate());
|
|
1148
|
+
}
|
|
1149
|
+
getSlotStartBuildTimestamp() {
|
|
1150
|
+
return getSlotStartBuildTimestamp(this.slot, this.l1Constants);
|
|
1151
|
+
}
|
|
1152
|
+
getSecondsIntoSlot() {
|
|
1153
|
+
const slotStartTimestamp = this.getSlotStartBuildTimestamp();
|
|
1154
|
+
return Number((this.dateProvider.now() / 1000 - slotStartTimestamp).toFixed(3));
|
|
1155
|
+
}
|
|
1156
|
+
getPublisher() {
|
|
1157
|
+
return this.publisher;
|
|
1158
|
+
}
|
|
1159
|
+
}
|