@aztec/sequencer-client 0.0.1-commit.9b94fc1 → 0.0.1-commit.9badcec54
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 +26 -16
- package/dest/client/sequencer-client.d.ts.map +1 -1
- package/dest/client/sequencer-client.js +76 -36
- package/dest/config.d.ts +35 -9
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +109 -50
- package/dest/global_variable_builder/fee_predictor.d.ts +37 -0
- package/dest/global_variable_builder/fee_predictor.d.ts.map +1 -0
- package/dest/global_variable_builder/fee_predictor.js +128 -0
- package/dest/global_variable_builder/fee_provider.d.ts +21 -0
- package/dest/global_variable_builder/fee_provider.d.ts.map +1 -0
- package/dest/global_variable_builder/fee_provider.js +58 -0
- package/dest/global_variable_builder/global_builder.d.ts +25 -17
- package/dest/global_variable_builder/global_builder.d.ts.map +1 -1
- package/dest/global_variable_builder/global_builder.js +44 -68
- package/dest/global_variable_builder/index.d.ts +4 -2
- package/dest/global_variable_builder/index.d.ts.map +1 -1
- package/dest/global_variable_builder/index.js +2 -0
- package/dest/index.d.ts +2 -3
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +1 -2
- package/dest/publisher/config.d.ts +53 -20
- package/dest/publisher/config.d.ts.map +1 -1
- package/dest/publisher/config.js +124 -39
- package/dest/publisher/index.d.ts +2 -1
- package/dest/publisher/index.d.ts.map +1 -1
- package/dest/publisher/l1_tx_failed_store/factory.d.ts +11 -0
- package/dest/publisher/l1_tx_failed_store/factory.d.ts.map +1 -0
- package/dest/publisher/l1_tx_failed_store/factory.js +22 -0
- package/dest/publisher/l1_tx_failed_store/failed_tx_store.d.ts +58 -0
- package/dest/publisher/l1_tx_failed_store/failed_tx_store.d.ts.map +1 -0
- package/dest/publisher/l1_tx_failed_store/failed_tx_store.js +1 -0
- package/dest/publisher/l1_tx_failed_store/file_store_failed_tx_store.d.ts +15 -0
- package/dest/publisher/l1_tx_failed_store/file_store_failed_tx_store.d.ts.map +1 -0
- package/dest/publisher/l1_tx_failed_store/file_store_failed_tx_store.js +34 -0
- package/dest/publisher/l1_tx_failed_store/index.d.ts +4 -0
- package/dest/publisher/l1_tx_failed_store/index.d.ts.map +1 -0
- package/dest/publisher/l1_tx_failed_store/index.js +2 -0
- package/dest/publisher/sequencer-publisher-factory.d.ts +15 -8
- package/dest/publisher/sequencer-publisher-factory.d.ts.map +1 -1
- package/dest/publisher/sequencer-publisher-factory.js +28 -4
- package/dest/publisher/sequencer-publisher-metrics.d.ts +3 -3
- package/dest/publisher/sequencer-publisher-metrics.d.ts.map +1 -1
- package/dest/publisher/sequencer-publisher-metrics.js +23 -86
- package/dest/publisher/sequencer-publisher.d.ts +114 -80
- package/dest/publisher/sequencer-publisher.d.ts.map +1 -1
- package/dest/publisher/sequencer-publisher.js +1008 -242
- package/dest/sequencer/chain_state_overrides.d.ts +25 -0
- package/dest/sequencer/chain_state_overrides.d.ts.map +1 -0
- package/dest/sequencer/chain_state_overrides.js +39 -0
- package/dest/sequencer/checkpoint_proposal_job.d.ts +119 -0
- package/dest/sequencer/checkpoint_proposal_job.d.ts.map +1 -0
- package/dest/sequencer/checkpoint_proposal_job.js +1355 -0
- package/dest/sequencer/checkpoint_proposal_job_metrics.d.ts +34 -0
- package/dest/sequencer/checkpoint_proposal_job_metrics.d.ts.map +1 -0
- package/dest/sequencer/checkpoint_proposal_job_metrics.js +72 -0
- package/dest/sequencer/checkpoint_voter.d.ts +34 -0
- package/dest/sequencer/checkpoint_voter.d.ts.map +1 -0
- package/dest/sequencer/checkpoint_voter.js +106 -0
- package/dest/sequencer/config.d.ts +3 -2
- package/dest/sequencer/config.d.ts.map +1 -1
- package/dest/sequencer/events.d.ts +47 -0
- package/dest/sequencer/events.d.ts.map +1 -0
- package/dest/sequencer/events.js +1 -0
- package/dest/sequencer/index.d.ts +4 -2
- package/dest/sequencer/index.d.ts.map +1 -1
- package/dest/sequencer/index.js +3 -1
- package/dest/sequencer/metrics.d.ts +38 -7
- package/dest/sequencer/metrics.d.ts.map +1 -1
- package/dest/sequencer/metrics.js +220 -73
- package/dest/sequencer/sequencer.d.ts +138 -134
- package/dest/sequencer/sequencer.d.ts.map +1 -1
- package/dest/sequencer/sequencer.js +812 -657
- package/dest/sequencer/timetable.d.ts +67 -16
- package/dest/sequencer/timetable.d.ts.map +1 -1
- package/dest/sequencer/timetable.js +158 -64
- package/dest/sequencer/types.d.ts +3 -0
- package/dest/sequencer/types.d.ts.map +1 -0
- package/dest/sequencer/types.js +1 -0
- package/dest/sequencer/utils.d.ts +14 -8
- package/dest/sequencer/utils.d.ts.map +1 -1
- package/dest/sequencer/utils.js +7 -4
- package/dest/test/index.d.ts +6 -7
- package/dest/test/index.d.ts.map +1 -1
- package/dest/test/mock_checkpoint_builder.d.ts +95 -0
- package/dest/test/mock_checkpoint_builder.d.ts.map +1 -0
- package/dest/test/mock_checkpoint_builder.js +231 -0
- package/dest/test/utils.d.ts +53 -0
- package/dest/test/utils.d.ts.map +1 -0
- package/dest/test/utils.js +104 -0
- package/package.json +31 -30
- package/src/client/sequencer-client.ts +102 -62
- package/src/config.ts +128 -60
- package/src/global_variable_builder/README.md +44 -0
- package/src/global_variable_builder/fee_predictor.ts +172 -0
- package/src/global_variable_builder/fee_provider.ts +75 -0
- package/src/global_variable_builder/global_builder.ts +64 -96
- package/src/global_variable_builder/index.ts +3 -1
- package/src/index.ts +1 -7
- package/src/publisher/config.ts +166 -51
- package/src/publisher/index.ts +3 -0
- package/src/publisher/l1_tx_failed_store/factory.ts +32 -0
- package/src/publisher/l1_tx_failed_store/failed_tx_store.ts +57 -0
- package/src/publisher/l1_tx_failed_store/file_store_failed_tx_store.ts +46 -0
- package/src/publisher/l1_tx_failed_store/index.ts +3 -0
- package/src/publisher/sequencer-publisher-factory.ts +43 -13
- package/src/publisher/sequencer-publisher-metrics.ts +19 -71
- package/src/publisher/sequencer-publisher.ts +761 -321
- package/src/sequencer/README.md +601 -0
- package/src/sequencer/chain_state_overrides.ts +87 -0
- package/src/sequencer/checkpoint_proposal_job.ts +1137 -0
- package/src/sequencer/checkpoint_proposal_job_metrics.ts +128 -0
- package/src/sequencer/checkpoint_voter.ts +119 -0
- package/src/sequencer/config.ts +2 -1
- package/src/sequencer/events.ts +27 -0
- package/src/sequencer/index.ts +3 -1
- package/src/sequencer/metrics.ts +273 -83
- package/src/sequencer/sequencer.ts +607 -857
- package/src/sequencer/timetable.ts +188 -81
- package/src/sequencer/types.ts +6 -0
- package/src/sequencer/utils.ts +18 -9
- package/src/test/index.ts +5 -6
- package/src/test/mock_checkpoint_builder.ts +323 -0
- package/src/test/utils.ts +167 -0
- package/dest/sequencer/block_builder.d.ts +0 -27
- package/dest/sequencer/block_builder.d.ts.map +0 -1
- package/dest/sequencer/block_builder.js +0 -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 -17
- package/dest/tx_validator/tx_validator_factory.d.ts.map +0 -1
- package/dest/tx_validator/tx_validator_factory.js +0 -53
- package/src/sequencer/block_builder.ts +0 -222
- package/src/tx_validator/nullifier_cache.ts +0 -30
- package/src/tx_validator/tx_validator_factory.ts +0 -132
|
@@ -0,0 +1,1355 @@
|
|
|
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 { BlockNumber, IndexWithinCheckpoint } from '@aztec/foundation/branded-types';
|
|
440
|
+
import { randomInt } from '@aztec/foundation/crypto/random';
|
|
441
|
+
import { flipSignature, generateRecoverableSignature, generateUnrecoverableSignature } from '@aztec/foundation/crypto/secp256k1-signer';
|
|
442
|
+
import { filter } from '@aztec/foundation/iterator';
|
|
443
|
+
import { createLogger } from '@aztec/foundation/log';
|
|
444
|
+
import { sleep, sleepUntil } from '@aztec/foundation/sleep';
|
|
445
|
+
import { Timer } from '@aztec/foundation/timer';
|
|
446
|
+
import { isErrorClass, unfreeze } from '@aztec/foundation/types';
|
|
447
|
+
import { CommitteeAttestationsAndSigners, MaliciousCommitteeAttestationsAndSigners } from '@aztec/stdlib/block';
|
|
448
|
+
import { validateCheckpoint } from '@aztec/stdlib/checkpoint';
|
|
449
|
+
import { computeQuorum, getSlotStartBuildTimestamp, getTimestampForSlot } from '@aztec/stdlib/epoch-helpers';
|
|
450
|
+
import { Gas } from '@aztec/stdlib/gas';
|
|
451
|
+
import { InsufficientValidTxsError } from '@aztec/stdlib/interfaces/server';
|
|
452
|
+
import { computeInHashFromL1ToL2Messages } from '@aztec/stdlib/messaging';
|
|
453
|
+
import { orderAttestations, trimAttestations } from '@aztec/stdlib/p2p';
|
|
454
|
+
import { AttestationTimeoutError } from '@aztec/stdlib/validators';
|
|
455
|
+
import { Attributes, trackSpan } from '@aztec/telemetry-client';
|
|
456
|
+
import { DutyAlreadySignedError, SlashingProtectionError } from '@aztec/validator-ha-signer/errors';
|
|
457
|
+
import { buildPipelinedParentSimulationOverridesPlan, buildSubmissionSimulationOverridesPlan } from './chain_state_overrides.js';
|
|
458
|
+
import { CheckpointVoter } from './checkpoint_voter.js';
|
|
459
|
+
import { SequencerInterruptedError } from './errors.js';
|
|
460
|
+
import { SequencerState } from './utils.js';
|
|
461
|
+
/** How much time to sleep while waiting for min transactions to accumulate for a block */ const TXS_POLLING_MS = 500;
|
|
462
|
+
_dec = trackSpan('CheckpointProposalJob.execute'), _dec1 = trackSpan('CheckpointProposalJob.proposeCheckpoint', function() {
|
|
463
|
+
return {
|
|
464
|
+
// nullish operator needed for tests
|
|
465
|
+
[Attributes.COINBASE]: this.validatorClient.getCoinbaseForAttestor(this.attestorAddress)?.toString(),
|
|
466
|
+
[Attributes.SLOT_NUMBER]: this.targetSlot
|
|
467
|
+
};
|
|
468
|
+
}), _dec2 = trackSpan('CheckpointProposalJob.buildBlocksForCheckpoint'), _dec3 = trackSpan('CheckpointProposalJob.waitUntilNextSubslot'), _dec4 = trackSpan('CheckpointProposalJob.buildSingleBlock'), _dec5 = trackSpan('CheckpointProposalJob.waitForMinTxs'), _dec6 = trackSpan('CheckpointProposalJob.waitForAttestations'), _dec7 = trackSpan('CheckpointProposalJob.waitUntilTimeInSlot');
|
|
469
|
+
/**
|
|
470
|
+
* Handles the execution of a checkpoint proposal after the initial preparation phase.
|
|
471
|
+
* This includes building blocks, collecting attestations, and publishing the checkpoint to L1,
|
|
472
|
+
* as well as enqueueing votes for slashing and governance proposals. This class is created from
|
|
473
|
+
* the Sequencer once the check for being the proposer for the slot has succeeded.
|
|
474
|
+
*/ export class CheckpointProposalJob {
|
|
475
|
+
slotNow;
|
|
476
|
+
targetSlot;
|
|
477
|
+
targetEpoch;
|
|
478
|
+
checkpointNumber;
|
|
479
|
+
syncedToBlockNumber;
|
|
480
|
+
proposer;
|
|
481
|
+
publisher;
|
|
482
|
+
attestorAddress;
|
|
483
|
+
invalidateCheckpoint;
|
|
484
|
+
validatorClient;
|
|
485
|
+
globalsBuilder;
|
|
486
|
+
p2pClient;
|
|
487
|
+
worldState;
|
|
488
|
+
l1ToL2MessageSource;
|
|
489
|
+
l2BlockSource;
|
|
490
|
+
checkpointsBuilder;
|
|
491
|
+
blockSink;
|
|
492
|
+
l1Constants;
|
|
493
|
+
config;
|
|
494
|
+
timetable;
|
|
495
|
+
slasherClient;
|
|
496
|
+
epochCache;
|
|
497
|
+
dateProvider;
|
|
498
|
+
metrics;
|
|
499
|
+
checkpointMetrics;
|
|
500
|
+
eventEmitter;
|
|
501
|
+
setStateFn;
|
|
502
|
+
tracer;
|
|
503
|
+
proposedCheckpointData;
|
|
504
|
+
static{
|
|
505
|
+
({ e: [_initProto] } = _apply_decs_2203_r(this, [
|
|
506
|
+
[
|
|
507
|
+
_dec,
|
|
508
|
+
2,
|
|
509
|
+
"execute"
|
|
510
|
+
],
|
|
511
|
+
[
|
|
512
|
+
_dec1,
|
|
513
|
+
2,
|
|
514
|
+
"proposeCheckpoint"
|
|
515
|
+
],
|
|
516
|
+
[
|
|
517
|
+
_dec2,
|
|
518
|
+
2,
|
|
519
|
+
"buildBlocksForCheckpoint"
|
|
520
|
+
],
|
|
521
|
+
[
|
|
522
|
+
_dec3,
|
|
523
|
+
2,
|
|
524
|
+
"waitUntilNextSubslot"
|
|
525
|
+
],
|
|
526
|
+
[
|
|
527
|
+
_dec4,
|
|
528
|
+
2,
|
|
529
|
+
"buildSingleBlock"
|
|
530
|
+
],
|
|
531
|
+
[
|
|
532
|
+
_dec5,
|
|
533
|
+
2,
|
|
534
|
+
"waitForMinTxs"
|
|
535
|
+
],
|
|
536
|
+
[
|
|
537
|
+
_dec6,
|
|
538
|
+
2,
|
|
539
|
+
"waitForAttestations"
|
|
540
|
+
],
|
|
541
|
+
[
|
|
542
|
+
_dec7,
|
|
543
|
+
2,
|
|
544
|
+
"waitUntilTimeInSlot"
|
|
545
|
+
]
|
|
546
|
+
], []));
|
|
547
|
+
}
|
|
548
|
+
log;
|
|
549
|
+
/** Tracks the fire-and-forget L1 submission promise so it can be awaited during shutdown. */ pendingL1Submission;
|
|
550
|
+
/** Pipelined parent chain state used while building and later submitting this checkpoint. */ pipelinedParentSimulationOverridesPlan;
|
|
551
|
+
constructor(slotNow, targetSlot, targetEpoch, checkpointNumber, syncedToBlockNumber, // TODO(palla/mbps): Can we remove the proposer in favor of attestorAddress? Need to check fisherman-node flows.
|
|
552
|
+
proposer, publisher, attestorAddress, invalidateCheckpoint, validatorClient, globalsBuilder, p2pClient, worldState, l1ToL2MessageSource, l2BlockSource, checkpointsBuilder, blockSink, l1Constants, config, timetable, slasherClient, epochCache, dateProvider, metrics, checkpointMetrics, eventEmitter, setStateFn, tracer, bindings, proposedCheckpointData){
|
|
553
|
+
this.slotNow = slotNow;
|
|
554
|
+
this.targetSlot = targetSlot;
|
|
555
|
+
this.targetEpoch = targetEpoch;
|
|
556
|
+
this.checkpointNumber = checkpointNumber;
|
|
557
|
+
this.syncedToBlockNumber = syncedToBlockNumber;
|
|
558
|
+
this.proposer = proposer;
|
|
559
|
+
this.publisher = publisher;
|
|
560
|
+
this.attestorAddress = attestorAddress;
|
|
561
|
+
this.invalidateCheckpoint = invalidateCheckpoint;
|
|
562
|
+
this.validatorClient = validatorClient;
|
|
563
|
+
this.globalsBuilder = globalsBuilder;
|
|
564
|
+
this.p2pClient = p2pClient;
|
|
565
|
+
this.worldState = worldState;
|
|
566
|
+
this.l1ToL2MessageSource = l1ToL2MessageSource;
|
|
567
|
+
this.l2BlockSource = l2BlockSource;
|
|
568
|
+
this.checkpointsBuilder = checkpointsBuilder;
|
|
569
|
+
this.blockSink = blockSink;
|
|
570
|
+
this.l1Constants = l1Constants;
|
|
571
|
+
this.config = config;
|
|
572
|
+
this.timetable = timetable;
|
|
573
|
+
this.slasherClient = slasherClient;
|
|
574
|
+
this.epochCache = epochCache;
|
|
575
|
+
this.dateProvider = dateProvider;
|
|
576
|
+
this.metrics = metrics;
|
|
577
|
+
this.checkpointMetrics = checkpointMetrics;
|
|
578
|
+
this.eventEmitter = eventEmitter;
|
|
579
|
+
this.setStateFn = setStateFn;
|
|
580
|
+
this.tracer = tracer;
|
|
581
|
+
this.proposedCheckpointData = proposedCheckpointData;
|
|
582
|
+
_initProto(this);
|
|
583
|
+
this.log = createLogger('sequencer:checkpoint-proposal', {
|
|
584
|
+
...bindings,
|
|
585
|
+
instanceId: `slot-${this.slotNow}`
|
|
586
|
+
});
|
|
587
|
+
}
|
|
588
|
+
/** Awaits the pending L1 submission if one is in progress. Call during shutdown. */ async awaitPendingSubmission() {
|
|
589
|
+
this.log.info('Awaiting pending L1 payload submission');
|
|
590
|
+
await this.pendingL1Submission;
|
|
591
|
+
}
|
|
592
|
+
/**
|
|
593
|
+
* Executes the checkpoint proposal job.
|
|
594
|
+
* Builds blocks, assembles checkpoint, and broadcasts the proposal (blocking).
|
|
595
|
+
* Attestation collection, signing, and L1 submission are backgrounded so the
|
|
596
|
+
* work loop can return to IDLE immediately for consecutive slot proposals.
|
|
597
|
+
* Returns the built checkpoint if successful, undefined otherwise.
|
|
598
|
+
*/ async execute() {
|
|
599
|
+
// Enqueue governance and slashing votes (returns promises that will be awaited later)
|
|
600
|
+
// In fisherman mode, we simulate slashing but don't actually publish to L1
|
|
601
|
+
// These are constant for the whole slot, so we only enqueue them once
|
|
602
|
+
const votesPromises = new CheckpointVoter(this.targetSlot, this.publisher, this.attestorAddress, this.validatorClient, this.slasherClient, this.l1Constants, this.config, this.metrics, this.log).enqueueVotes();
|
|
603
|
+
// Build blocks, assemble checkpoint, and broadcast proposal (BLOCKING).
|
|
604
|
+
// Returns after broadcast — attestation collection is deferred.
|
|
605
|
+
const broadcast = await this.proposeCheckpoint();
|
|
606
|
+
if (!broadcast) {
|
|
607
|
+
await Promise.all(votesPromises);
|
|
608
|
+
// Still submit votes even without a checkpoint
|
|
609
|
+
if (!this.config.fishermanMode) {
|
|
610
|
+
this.pendingL1Submission = this.publisher.sendRequestsAt(this.dateProvider.nowAsDate()).then(()=>{});
|
|
611
|
+
}
|
|
612
|
+
return undefined;
|
|
613
|
+
}
|
|
614
|
+
const { checkpoint } = broadcast;
|
|
615
|
+
this.metrics.recordCheckpointProposalSuccess();
|
|
616
|
+
// Do not post anything to L1 if we are fishermen, but do perform L1 fee analysis
|
|
617
|
+
if (this.config.fishermanMode) {
|
|
618
|
+
await this.handleCheckpointEndAsFisherman(checkpoint);
|
|
619
|
+
return checkpoint;
|
|
620
|
+
}
|
|
621
|
+
// Background the attestation → signing → L1 pipeline so the work loop is unblocked
|
|
622
|
+
this.pendingL1Submission = this.waitForAttestationsAndEnqueueSubmissionAsync(broadcast, votesPromises);
|
|
623
|
+
// Return the built checkpoint immediately — the work loop is now unblocked
|
|
624
|
+
return checkpoint;
|
|
625
|
+
}
|
|
626
|
+
/**
|
|
627
|
+
* Background pipeline: collects attestations, signs them, enqueues the checkpoint, and submits to L1.
|
|
628
|
+
* Runs as a fire-and-forget task stored in `pendingL1Submission` so the work loop is unblocked.
|
|
629
|
+
*/ async waitForAttestationsAndEnqueueSubmissionAsync(broadcast, votesPromises) {
|
|
630
|
+
const { checkpoint, proposal, blockProposedAt } = broadcast;
|
|
631
|
+
try {
|
|
632
|
+
await Promise.all(votesPromises);
|
|
633
|
+
this.setStateFn(SequencerState.COLLECTING_ATTESTATIONS, this.targetSlot);
|
|
634
|
+
const attestations = await this.waitForAttestations(proposal);
|
|
635
|
+
this.checkpointMetrics.recordCheckpointAttestationDelay(this.dateProvider.now() - blockProposedAt);
|
|
636
|
+
// Proposer must sign over the attestations before pushing them to L1
|
|
637
|
+
const signer = this.proposer ?? this.publisher.getSenderAddress();
|
|
638
|
+
let attestationsSignature;
|
|
639
|
+
try {
|
|
640
|
+
attestationsSignature = await this.validatorClient.signAttestationsAndSigners(attestations, signer, this.targetSlot, this.checkpointNumber);
|
|
641
|
+
} catch (err) {
|
|
642
|
+
if (this.handleHASigningError(err, 'Attestations signature')) {
|
|
643
|
+
return;
|
|
644
|
+
}
|
|
645
|
+
throw err;
|
|
646
|
+
}
|
|
647
|
+
// Enqueue the checkpoint for L1 submission
|
|
648
|
+
await this.enqueueCheckpointForSubmission({
|
|
649
|
+
checkpoint,
|
|
650
|
+
attestations,
|
|
651
|
+
attestationsSignature
|
|
652
|
+
});
|
|
653
|
+
// Compute the earliest time to submit: pipeline slot start when pipelining, now otherwise.
|
|
654
|
+
const submitAfter = this.epochCache.isProposerPipeliningEnabled() ? new Date(Number(getTimestampForSlot(this.targetSlot, this.l1Constants)) * 1000) : new Date(this.dateProvider.now());
|
|
655
|
+
const l1Response = await this.publisher.sendRequestsAt(submitAfter);
|
|
656
|
+
const proposedAction = l1Response?.successfulActions.find((a)=>a === 'propose');
|
|
657
|
+
if (proposedAction) {
|
|
658
|
+
this.eventEmitter.emit('checkpoint-published', {
|
|
659
|
+
checkpoint: this.checkpointNumber,
|
|
660
|
+
slot: this.targetSlot
|
|
661
|
+
});
|
|
662
|
+
const coinbase = checkpoint.header.coinbase;
|
|
663
|
+
await this.metrics.incFilledSlot(this.publisher.getSenderAddress().toString(), coinbase);
|
|
664
|
+
} else {
|
|
665
|
+
this.eventEmitter.emit('checkpoint-publish-failed', {
|
|
666
|
+
...l1Response,
|
|
667
|
+
slot: this.targetSlot
|
|
668
|
+
});
|
|
669
|
+
if (this.epochCache.isProposerPipeliningEnabled()) {
|
|
670
|
+
this.metrics.recordPipelineDiscard();
|
|
671
|
+
}
|
|
672
|
+
}
|
|
673
|
+
} catch (err) {
|
|
674
|
+
if (err instanceof SequencerInterruptedError) {
|
|
675
|
+
return;
|
|
676
|
+
}
|
|
677
|
+
this.log.error(`Background attestation/L1 pipeline failed for slot ${this.targetSlot}`, err);
|
|
678
|
+
this.eventEmitter.emit('checkpoint-publish-failed', {
|
|
679
|
+
slot: this.targetSlot
|
|
680
|
+
});
|
|
681
|
+
if (this.epochCache.isProposerPipeliningEnabled()) {
|
|
682
|
+
this.metrics.recordPipelineDiscard();
|
|
683
|
+
}
|
|
684
|
+
}
|
|
685
|
+
}
|
|
686
|
+
/** Enqueues the checkpoint for L1 submission. Called after pipeline sleep in execute(). */ async enqueueCheckpointForSubmission(result) {
|
|
687
|
+
const { checkpoint, attestations, attestationsSignature } = result;
|
|
688
|
+
this.setStateFn(SequencerState.PUBLISHING_CHECKPOINT, this.targetSlot);
|
|
689
|
+
const aztecSlotDuration = this.l1Constants.slotDuration;
|
|
690
|
+
const submissionSlotStart = Number(getTimestampForSlot(this.targetSlot, this.l1Constants));
|
|
691
|
+
const txTimeoutAt = new Date((submissionSlotStart + aztecSlotDuration) * 1000);
|
|
692
|
+
// If we have been configured to potentially skip publishing checkpoint then roll the dice here
|
|
693
|
+
if (this.config.skipPublishingCheckpointsPercent !== undefined && this.config.skipPublishingCheckpointsPercent > 0) {
|
|
694
|
+
const roll = Math.max(0, randomInt(100));
|
|
695
|
+
if (roll < this.config.skipPublishingCheckpointsPercent) {
|
|
696
|
+
this.log.warn(`Skipping publishing proposal for checkpoint ${checkpoint.number}. Configured percentage: ${this.config.skipPublishingCheckpointsPercent}, generated value: ${roll}`);
|
|
697
|
+
return;
|
|
698
|
+
}
|
|
699
|
+
}
|
|
700
|
+
const isPipelining = this.epochCache.isProposerPipeliningEnabled();
|
|
701
|
+
const submissionSimulationOverridesPlan = buildSubmissionSimulationOverridesPlan({
|
|
702
|
+
pipelinedParentPlan: this.pipelinedParentSimulationOverridesPlan,
|
|
703
|
+
invalidateToPendingCheckpointNumber: this.invalidateCheckpoint?.forcePendingCheckpointNumber,
|
|
704
|
+
lastArchiveRoot: checkpoint.header.lastArchiveRoot,
|
|
705
|
+
pipeliningEnabled: isPipelining
|
|
706
|
+
});
|
|
707
|
+
await this.publisher.enqueueProposeCheckpoint(checkpoint, attestations, attestationsSignature, {
|
|
708
|
+
txTimeoutAt,
|
|
709
|
+
...submissionSimulationOverridesPlan ? {
|
|
710
|
+
simulationOverridesPlan: submissionSimulationOverridesPlan
|
|
711
|
+
} : {}
|
|
712
|
+
});
|
|
713
|
+
}
|
|
714
|
+
async proposeCheckpoint() {
|
|
715
|
+
try {
|
|
716
|
+
const env = {
|
|
717
|
+
stack: [],
|
|
718
|
+
error: void 0,
|
|
719
|
+
hasError: false
|
|
720
|
+
};
|
|
721
|
+
try {
|
|
722
|
+
const now = this.dateProvider.now();
|
|
723
|
+
if (this.epochCache.isProposerPipeliningEnabled() && this.proposedCheckpointData) {
|
|
724
|
+
// Measure against the wall-clock slot whose build window we are currently using.
|
|
725
|
+
// In pipelining mode `targetSlot` is intentionally one slot ahead, which makes the
|
|
726
|
+
// target-slot boundary a full slot away from the actual build start time.
|
|
727
|
+
const slotBoundaryMs = Number(getTimestampForSlot(this.slotNow, this.l1Constants)) * 1000;
|
|
728
|
+
this.checkpointMetrics.recordPipelinedCheckpointBuildStartOffsetFromSlotBoundary(now - slotBoundaryMs);
|
|
729
|
+
}
|
|
730
|
+
this.checkpointMetrics.startCheckpointTiming(now);
|
|
731
|
+
// Get operator configured coinbase and fee recipient for this attestor
|
|
732
|
+
const coinbase = this.validatorClient.getCoinbaseForAttestor(this.attestorAddress);
|
|
733
|
+
const feeRecipient = this.validatorClient.getFeeRecipientForAttestor(this.attestorAddress);
|
|
734
|
+
// Start the checkpoint
|
|
735
|
+
this.setStateFn(SequencerState.INITIALIZING_CHECKPOINT, this.targetSlot);
|
|
736
|
+
this.log.info(`Starting checkpoint proposal`, {
|
|
737
|
+
buildSlot: this.slotNow,
|
|
738
|
+
submissionSlot: this.targetSlot,
|
|
739
|
+
pipelining: this.epochCache.isProposerPipeliningEnabled(),
|
|
740
|
+
proposer: this.proposer?.toString(),
|
|
741
|
+
coinbase: coinbase.toString()
|
|
742
|
+
});
|
|
743
|
+
this.metrics.incOpenSlot(this.targetSlot, this.proposer?.toString() ?? 'unknown');
|
|
744
|
+
// Enqueues checkpoint invalidation (constant for the whole slot)
|
|
745
|
+
if (this.invalidateCheckpoint && !this.config.skipInvalidateBlockAsProposer) {
|
|
746
|
+
this.publisher.enqueueInvalidateCheckpoint(this.invalidateCheckpoint);
|
|
747
|
+
}
|
|
748
|
+
// Create checkpoint builder for the slot.
|
|
749
|
+
// When pipelining, force the proposed checkpoint number and fee header to our parent so the
|
|
750
|
+
// fee computation sees the same chain tip that L1 will see once the previous pipelined checkpoint lands.
|
|
751
|
+
const isPipelining = this.epochCache.isProposerPipeliningEnabled();
|
|
752
|
+
this.pipelinedParentSimulationOverridesPlan = isPipelining ? await buildPipelinedParentSimulationOverridesPlan({
|
|
753
|
+
checkpointNumber: this.checkpointNumber,
|
|
754
|
+
proposedCheckpointData: this.proposedCheckpointData,
|
|
755
|
+
rollup: this.publisher.rollupContract,
|
|
756
|
+
log: this.log
|
|
757
|
+
}) : undefined;
|
|
758
|
+
const checkpointGlobalVariables = await this.globalsBuilder.buildCheckpointGlobalVariables(coinbase, feeRecipient, this.targetSlot, this.pipelinedParentSimulationOverridesPlan);
|
|
759
|
+
// Collect L1 to L2 messages for the checkpoint and compute their hash
|
|
760
|
+
const l1ToL2Messages = await this.l1ToL2MessageSource.getL1ToL2Messages(this.checkpointNumber);
|
|
761
|
+
const inHash = computeInHashFromL1ToL2Messages(l1ToL2Messages);
|
|
762
|
+
// Collect the out hashes of all the checkpoints before this one in the same epoch
|
|
763
|
+
const previousCheckpointOutHashes = (await this.l2BlockSource.getCheckpointsDataForEpoch(this.targetEpoch)).filter((c)=>c.checkpointNumber < this.checkpointNumber).map((c)=>c.checkpointOutHash);
|
|
764
|
+
// Get the fee asset price modifier from the oracle
|
|
765
|
+
const feeAssetPriceModifier = await this.publisher.getFeeAssetPriceModifier();
|
|
766
|
+
const fork = _ts_add_disposable_resource(env, await this.worldState.fork(this.syncedToBlockNumber, {
|
|
767
|
+
closeDelayMs: 12_000
|
|
768
|
+
}), true);
|
|
769
|
+
// Create checkpoint builder for the entire slot
|
|
770
|
+
const checkpointBuilder = await this.checkpointsBuilder.startCheckpoint(this.checkpointNumber, checkpointGlobalVariables, feeAssetPriceModifier, l1ToL2Messages, previousCheckpointOutHashes, fork, this.log.getBindings());
|
|
771
|
+
// Options for the validator client when creating block and checkpoint proposals
|
|
772
|
+
const blockProposalOptions = {
|
|
773
|
+
publishFullTxs: !!this.config.publishTxsWithProposals,
|
|
774
|
+
broadcastInvalidBlockProposal: this.config.broadcastInvalidBlockProposal
|
|
775
|
+
};
|
|
776
|
+
const checkpointProposalOptions = {
|
|
777
|
+
publishFullTxs: !!this.config.publishTxsWithProposals,
|
|
778
|
+
broadcastInvalidCheckpointProposal: this.config.broadcastInvalidBlockProposal
|
|
779
|
+
};
|
|
780
|
+
let blocksInCheckpoint = [];
|
|
781
|
+
let blockPendingBroadcast = undefined;
|
|
782
|
+
const checkpointBuildTimer = new Timer();
|
|
783
|
+
try {
|
|
784
|
+
// Main loop: build blocks for the checkpoint
|
|
785
|
+
const result = await this.buildBlocksForCheckpoint(checkpointBuilder, checkpointGlobalVariables.timestamp, inHash, blockProposalOptions);
|
|
786
|
+
blocksInCheckpoint = result.blocksInCheckpoint;
|
|
787
|
+
blockPendingBroadcast = result.blockPendingBroadcast;
|
|
788
|
+
} catch (err) {
|
|
789
|
+
// These errors are expected in HA mode, so we yield and let another HA node handle the slot
|
|
790
|
+
// The only distinction between the 2 errors is SlashingProtectionError throws when the payload is different,
|
|
791
|
+
// which is normal for block building (may have picked different txs)
|
|
792
|
+
if (this.handleHASigningError(err, 'Block proposal')) {
|
|
793
|
+
return undefined;
|
|
794
|
+
}
|
|
795
|
+
throw err;
|
|
796
|
+
}
|
|
797
|
+
if (blocksInCheckpoint.length === 0) {
|
|
798
|
+
this.log.warn(`No blocks were built for slot ${this.targetSlot}`, {
|
|
799
|
+
slot: this.targetSlot
|
|
800
|
+
});
|
|
801
|
+
this.eventEmitter.emit('checkpoint-empty', {
|
|
802
|
+
slot: this.targetSlot
|
|
803
|
+
});
|
|
804
|
+
return undefined;
|
|
805
|
+
}
|
|
806
|
+
const minBlocksForCheckpoint = this.config.minBlocksForCheckpoint;
|
|
807
|
+
if (minBlocksForCheckpoint !== undefined && blocksInCheckpoint.length < minBlocksForCheckpoint) {
|
|
808
|
+
this.log.warn(`Checkpoint has fewer blocks than minimum (${blocksInCheckpoint.length} < ${minBlocksForCheckpoint}), skipping proposal`, {
|
|
809
|
+
slot: this.targetSlot,
|
|
810
|
+
blocksBuilt: blocksInCheckpoint.length,
|
|
811
|
+
minBlocksForCheckpoint
|
|
812
|
+
});
|
|
813
|
+
return undefined;
|
|
814
|
+
}
|
|
815
|
+
// Assemble and broadcast the checkpoint proposal, including the last block that was not
|
|
816
|
+
// broadcasted yet, and wait to collect the committee attestations.
|
|
817
|
+
this.setStateFn(SequencerState.ASSEMBLING_CHECKPOINT, this.targetSlot);
|
|
818
|
+
const checkpoint = await checkpointBuilder.completeCheckpoint();
|
|
819
|
+
// Final validation: per-block limits are only checked if the operator set them explicitly.
|
|
820
|
+
// Otherwise, checkpoint-level budgets were already enforced by the redistribution logic.
|
|
821
|
+
try {
|
|
822
|
+
validateCheckpoint(checkpoint, {
|
|
823
|
+
rollupManaLimit: this.l1Constants.rollupManaLimit,
|
|
824
|
+
maxL2BlockGas: this.config.maxL2BlockGas,
|
|
825
|
+
maxDABlockGas: this.config.maxDABlockGas,
|
|
826
|
+
maxTxsPerBlock: this.config.maxTxsPerBlock,
|
|
827
|
+
maxTxsPerCheckpoint: this.config.maxTxsPerCheckpoint
|
|
828
|
+
});
|
|
829
|
+
} catch (err) {
|
|
830
|
+
this.log.error(`Built an invalid checkpoint at slot ${this.slotNow} (skipping proposal)`, err, {
|
|
831
|
+
checkpoint: checkpoint.header.toInspect()
|
|
832
|
+
});
|
|
833
|
+
return undefined;
|
|
834
|
+
}
|
|
835
|
+
// Record checkpoint-level build metrics
|
|
836
|
+
this.checkpointMetrics.recordCheckpointBuild(checkpointBuildTimer.ms(), blocksInCheckpoint.length, checkpoint.getStats().txCount, Number(checkpoint.header.totalManaUsed.toBigInt()));
|
|
837
|
+
// In fisherman mode, return the checkpoint without broadcasting or collecting attestations
|
|
838
|
+
if (this.config.fishermanMode) {
|
|
839
|
+
this.log.info(`Built checkpoint for slot ${this.targetSlot} with ${blocksInCheckpoint.length} blocks. ` + `Skipping proposal in fisherman mode.`, {
|
|
840
|
+
slot: this.targetSlot,
|
|
841
|
+
checkpoint: checkpoint.header.toInspect(),
|
|
842
|
+
blocksBuilt: blocksInCheckpoint.length
|
|
843
|
+
});
|
|
844
|
+
this.metrics.recordCheckpointSuccess();
|
|
845
|
+
// Return a broadcast result with a dummy proposal — fisherman mode skips attestation collection
|
|
846
|
+
return {
|
|
847
|
+
checkpoint,
|
|
848
|
+
proposal: undefined,
|
|
849
|
+
blockProposedAt: this.dateProvider.now()
|
|
850
|
+
};
|
|
851
|
+
}
|
|
852
|
+
// Create the checkpoint proposal and broadcast it
|
|
853
|
+
const proposal = await this.validatorClient.createCheckpointProposal(checkpoint.header, checkpoint.archive.root, this.checkpointNumber, feeAssetPriceModifier, blockPendingBroadcast, this.proposer, checkpointProposalOptions);
|
|
854
|
+
const blockProposedAt = this.dateProvider.now();
|
|
855
|
+
await this.p2pClient.broadcastCheckpointProposal(proposal);
|
|
856
|
+
this.checkpointMetrics.noteCheckpointBroadcast(this.dateProvider.now());
|
|
857
|
+
// Return immediately after broadcast — attestation collection happens in the background
|
|
858
|
+
return {
|
|
859
|
+
checkpoint,
|
|
860
|
+
proposal,
|
|
861
|
+
blockProposedAt
|
|
862
|
+
};
|
|
863
|
+
} catch (e) {
|
|
864
|
+
env.error = e;
|
|
865
|
+
env.hasError = true;
|
|
866
|
+
} finally{
|
|
867
|
+
const result = _ts_dispose_resources(env);
|
|
868
|
+
if (result) await result;
|
|
869
|
+
}
|
|
870
|
+
} catch (err) {
|
|
871
|
+
if (err && (err instanceof DutyAlreadySignedError || err instanceof SlashingProtectionError)) {
|
|
872
|
+
// swallow this error. It's already been logged by a function deeper in the stack
|
|
873
|
+
return undefined;
|
|
874
|
+
}
|
|
875
|
+
this.log.error(`Error building checkpoint at slot ${this.targetSlot}`, err);
|
|
876
|
+
return undefined;
|
|
877
|
+
}
|
|
878
|
+
}
|
|
879
|
+
/**
|
|
880
|
+
* Builds blocks for a checkpoint within the current slot.
|
|
881
|
+
*/ async buildBlocksForCheckpoint(checkpointBuilder, timestamp, inHash, blockProposalOptions) {
|
|
882
|
+
const blocksInCheckpoint = [];
|
|
883
|
+
const txHashesAlreadyIncluded = new Set();
|
|
884
|
+
const initialBlockNumber = BlockNumber(this.syncedToBlockNumber + 1);
|
|
885
|
+
// Last block in the checkpoint will usually be flagged as pending broadcast, so we send it along with the checkpoint proposal
|
|
886
|
+
let blockPendingBroadcast = undefined;
|
|
887
|
+
while(true){
|
|
888
|
+
const blocksBuilt = blocksInCheckpoint.length;
|
|
889
|
+
const indexWithinCheckpoint = IndexWithinCheckpoint(blocksBuilt);
|
|
890
|
+
const blockNumber = BlockNumber(initialBlockNumber + blocksBuilt);
|
|
891
|
+
const secondsIntoSlot = this.getSecondsIntoSlot();
|
|
892
|
+
const timingInfo = this.timetable.canStartNextBlock(secondsIntoSlot);
|
|
893
|
+
if (!timingInfo.canStart) {
|
|
894
|
+
this.log.debug(`Not enough time left in slot to start another block`, {
|
|
895
|
+
slot: this.targetSlot,
|
|
896
|
+
blocksBuilt,
|
|
897
|
+
secondsIntoSlot
|
|
898
|
+
});
|
|
899
|
+
break;
|
|
900
|
+
}
|
|
901
|
+
const buildResult = await this.buildSingleBlock(checkpointBuilder, {
|
|
902
|
+
// Create all blocks with the same timestamp
|
|
903
|
+
blockTimestamp: timestamp,
|
|
904
|
+
// Create an empty block if we haven't already and this is the last one
|
|
905
|
+
forceCreate: timingInfo.isLastBlock && blocksBuilt === 0 && this.config.buildCheckpointIfEmpty,
|
|
906
|
+
// Build deadline is only set if we are enforcing the timetable
|
|
907
|
+
buildDeadline: timingInfo.deadline ? new Date((this.getSlotStartBuildTimestamp() + timingInfo.deadline) * 1000) : undefined,
|
|
908
|
+
blockNumber,
|
|
909
|
+
indexWithinCheckpoint,
|
|
910
|
+
txHashesAlreadyIncluded
|
|
911
|
+
});
|
|
912
|
+
// If we failed to build the block due to insufficient txs, we try again if there is still time left in the slot
|
|
913
|
+
if ('failure' in buildResult) {
|
|
914
|
+
// If this was the last subslot, or we're running with a single block per slot, we're done
|
|
915
|
+
if (timingInfo.isLastBlock || timingInfo.deadline === undefined) {
|
|
916
|
+
break;
|
|
917
|
+
}
|
|
918
|
+
// Otherwise, if there is still time for more blocks, we wait until the next subslot and try again
|
|
919
|
+
await this.waitUntilNextSubslot(timingInfo.deadline);
|
|
920
|
+
continue;
|
|
921
|
+
}
|
|
922
|
+
// If there was an error building the block, we just exit the loop and give up the rest of the slot.
|
|
923
|
+
// We don't want to risk building more blocks if something went wrong.
|
|
924
|
+
if ('error' in buildResult) {
|
|
925
|
+
if (!(buildResult.error instanceof SequencerInterruptedError)) {
|
|
926
|
+
this.log.warn(`Halting block building for slot ${this.targetSlot}`, {
|
|
927
|
+
slot: this.targetSlot,
|
|
928
|
+
blocksBuilt,
|
|
929
|
+
error: buildResult.error
|
|
930
|
+
});
|
|
931
|
+
}
|
|
932
|
+
break;
|
|
933
|
+
}
|
|
934
|
+
const { block, usedTxs } = buildResult;
|
|
935
|
+
this.checkpointMetrics.noteCheckpointBlockBuilt(this.dateProvider.now(), {
|
|
936
|
+
isFirstBlock: blocksBuilt === 0,
|
|
937
|
+
isLastBlock: timingInfo.isLastBlock
|
|
938
|
+
});
|
|
939
|
+
blocksInCheckpoint.push(block);
|
|
940
|
+
usedTxs.forEach((tx)=>txHashesAlreadyIncluded.add(tx.txHash.toString()));
|
|
941
|
+
// Sign the block proposal. This will throw if HA signing fails.
|
|
942
|
+
const proposal = await this.createBlockProposal(block, inHash, usedTxs, blockProposalOptions);
|
|
943
|
+
// Sync the proposed block to the archiver to make it available, only after we've managed to sign the proposal,
|
|
944
|
+
// so we avoid polluting our archive with a block that would fail.
|
|
945
|
+
// We wait for the sync to succeed, as this helps catch consistency errors, even if it means we lose some time for block-building.
|
|
946
|
+
// If this throws, we abort the entire checkpoint.
|
|
947
|
+
await this.syncProposedBlockToArchiver(block);
|
|
948
|
+
// If this is the last block, do not broadcast it, since it will be included in the checkpoint proposal.
|
|
949
|
+
if (timingInfo.isLastBlock) {
|
|
950
|
+
this.log.verbose(`Completed final block ${blockNumber} for slot ${this.targetSlot}`, {
|
|
951
|
+
slot: this.targetSlot,
|
|
952
|
+
blockNumber,
|
|
953
|
+
blocksBuilt
|
|
954
|
+
});
|
|
955
|
+
blockPendingBroadcast = proposal;
|
|
956
|
+
break;
|
|
957
|
+
}
|
|
958
|
+
// Once we have a signed proposal and the archiver agreed with our proposed block, then we broadcast it.
|
|
959
|
+
proposal && await this.p2pClient.broadcastProposal(proposal);
|
|
960
|
+
// Wait until the next block's start time
|
|
961
|
+
await this.waitUntilNextSubslot(timingInfo.deadline);
|
|
962
|
+
}
|
|
963
|
+
this.log.verbose(`Block building loop completed for slot ${this.targetSlot}`, {
|
|
964
|
+
slot: this.targetSlot,
|
|
965
|
+
blocksBuilt: blocksInCheckpoint.length
|
|
966
|
+
});
|
|
967
|
+
return {
|
|
968
|
+
blocksInCheckpoint,
|
|
969
|
+
blockPendingBroadcast
|
|
970
|
+
};
|
|
971
|
+
}
|
|
972
|
+
/** Creates a block proposal for a given block via the validator client (unless in fisherman mode) */ createBlockProposal(block, inHash, usedTxs, blockProposalOptions) {
|
|
973
|
+
if (this.config.fishermanMode) {
|
|
974
|
+
this.log.info(`Skipping block proposal for block ${block.number} in fisherman mode`);
|
|
975
|
+
return Promise.resolve(undefined);
|
|
976
|
+
}
|
|
977
|
+
return this.validatorClient.createBlockProposal(block.header, this.checkpointNumber, block.indexWithinCheckpoint, inHash, block.archive.root, usedTxs, this.proposer, blockProposalOptions);
|
|
978
|
+
}
|
|
979
|
+
/** Sleeps until it is time to produce the next block in the slot */ async waitUntilNextSubslot(nextSubslotStart) {
|
|
980
|
+
this.setStateFn(SequencerState.WAITING_UNTIL_NEXT_BLOCK, this.targetSlot);
|
|
981
|
+
this.log.verbose(`Waiting until time for the next block at ${nextSubslotStart}s into slot`, {
|
|
982
|
+
slot: this.targetSlot
|
|
983
|
+
});
|
|
984
|
+
await this.waitUntilTimeInSlot(nextSubslotStart);
|
|
985
|
+
}
|
|
986
|
+
/** Builds a single block. Called from the main block building loop. */ async buildSingleBlock(checkpointBuilder, opts) {
|
|
987
|
+
const { blockTimestamp, forceCreate, blockNumber, indexWithinCheckpoint, buildDeadline, txHashesAlreadyIncluded } = opts;
|
|
988
|
+
this.log.verbose(`Preparing block ${blockNumber} index ${indexWithinCheckpoint} at checkpoint ${this.checkpointNumber} for slot ${this.targetSlot}`, {
|
|
989
|
+
...checkpointBuilder.getConstantData(),
|
|
990
|
+
...opts
|
|
991
|
+
});
|
|
992
|
+
try {
|
|
993
|
+
// Wait until we have enough txs to build the block
|
|
994
|
+
const { availableTxs, canStartBuilding, minTxs } = await this.waitForMinTxs(opts);
|
|
995
|
+
if (!canStartBuilding) {
|
|
996
|
+
this.log.warn(`Not enough txs to build block ${blockNumber} at index ${indexWithinCheckpoint} in slot ${this.targetSlot} (got ${availableTxs} txs but needs ${minTxs})`, {
|
|
997
|
+
blockNumber,
|
|
998
|
+
slot: this.targetSlot,
|
|
999
|
+
indexWithinCheckpoint
|
|
1000
|
+
});
|
|
1001
|
+
this.eventEmitter.emit('block-tx-count-check-failed', {
|
|
1002
|
+
minTxs,
|
|
1003
|
+
availableTxs,
|
|
1004
|
+
slot: this.targetSlot
|
|
1005
|
+
});
|
|
1006
|
+
this.metrics.recordBlockProposalFailed('insufficient_txs');
|
|
1007
|
+
return {
|
|
1008
|
+
failure: 'insufficient-txs'
|
|
1009
|
+
};
|
|
1010
|
+
}
|
|
1011
|
+
// Create iterator to pending txs. We filter out txs already included in previous blocks in the checkpoint
|
|
1012
|
+
// just in case p2p failed to sync the provisional block and didn't get to remove those txs from the mempool yet.
|
|
1013
|
+
const pendingTxs = filter(this.p2pClient.iterateEligiblePendingTxs(), (tx)=>!txHashesAlreadyIncluded.has(tx.txHash.toString()));
|
|
1014
|
+
this.log.debug(`Building block ${blockNumber} at index ${indexWithinCheckpoint} for slot ${this.targetSlot} with ${availableTxs} available txs`, {
|
|
1015
|
+
slot: this.targetSlot,
|
|
1016
|
+
blockNumber,
|
|
1017
|
+
indexWithinCheckpoint
|
|
1018
|
+
});
|
|
1019
|
+
this.setStateFn(SequencerState.CREATING_BLOCK, this.targetSlot);
|
|
1020
|
+
// Per-block limits are operator overrides (from SEQ_MAX_L2_BLOCK_GAS etc.) further capped
|
|
1021
|
+
// by remaining checkpoint-level budgets inside CheckpointBuilder before each block is built.
|
|
1022
|
+
// minValidTxs is passed into the builder so it can reject the block *before* updating state.
|
|
1023
|
+
const minValidTxs = forceCreate ? 0 : this.config.minValidTxsPerBlock ?? minTxs;
|
|
1024
|
+
const blockBuilderOptions = {
|
|
1025
|
+
maxTransactions: this.config.maxTxsPerBlock,
|
|
1026
|
+
maxBlockGas: this.config.maxL2BlockGas !== undefined || this.config.maxDABlockGas !== undefined ? new Gas(this.config.maxDABlockGas ?? Infinity, this.config.maxL2BlockGas ?? Infinity) : undefined,
|
|
1027
|
+
deadline: buildDeadline,
|
|
1028
|
+
isBuildingProposal: true,
|
|
1029
|
+
minValidTxs,
|
|
1030
|
+
maxBlocksPerCheckpoint: this.timetable.maxNumberOfBlocks,
|
|
1031
|
+
perBlockAllocationMultiplier: this.config.perBlockAllocationMultiplier
|
|
1032
|
+
};
|
|
1033
|
+
// Actually build the block by executing txs. The builder throws InsufficientValidTxsError
|
|
1034
|
+
// if the number of successfully processed txs is below minValidTxs, ensuring state is not
|
|
1035
|
+
// updated for blocks that will be discarded.
|
|
1036
|
+
const buildResult = await this.buildSingleBlockWithCheckpointBuilder(checkpointBuilder, pendingTxs, blockNumber, blockTimestamp, blockBuilderOptions);
|
|
1037
|
+
// If any txs failed during execution, drop them from the mempool so we don't pick them up again
|
|
1038
|
+
await this.dropFailedTxsFromP2P(buildResult.failedTxs);
|
|
1039
|
+
if (buildResult.status === 'insufficient-valid-txs') {
|
|
1040
|
+
this.log.warn(`Block ${blockNumber} at index ${indexWithinCheckpoint} on slot ${this.targetSlot} has too few valid txs to be proposed`, {
|
|
1041
|
+
slot: this.targetSlot,
|
|
1042
|
+
blockNumber,
|
|
1043
|
+
numTxs: buildResult.processedCount,
|
|
1044
|
+
indexWithinCheckpoint,
|
|
1045
|
+
minValidTxs
|
|
1046
|
+
});
|
|
1047
|
+
this.eventEmitter.emit('block-build-failed', {
|
|
1048
|
+
reason: `Insufficient valid txs`,
|
|
1049
|
+
slot: this.targetSlot
|
|
1050
|
+
});
|
|
1051
|
+
this.metrics.recordBlockProposalFailed('insufficient_valid_txs');
|
|
1052
|
+
return {
|
|
1053
|
+
failure: 'insufficient-valid-txs'
|
|
1054
|
+
};
|
|
1055
|
+
}
|
|
1056
|
+
// Block creation succeeded, emit stats and metrics
|
|
1057
|
+
const { block, publicProcessorDuration, usedTxs, blockBuildDuration, numTxs } = buildResult;
|
|
1058
|
+
const blockStats = {
|
|
1059
|
+
eventName: 'l2-block-built',
|
|
1060
|
+
duration: blockBuildDuration,
|
|
1061
|
+
publicProcessDuration: publicProcessorDuration,
|
|
1062
|
+
...block.getStats()
|
|
1063
|
+
};
|
|
1064
|
+
const blockHash = await block.hash();
|
|
1065
|
+
const txHashes = block.body.txEffects.map((tx)=>tx.txHash);
|
|
1066
|
+
const manaPerSec = block.header.totalManaUsed.toNumberUnsafe() / (blockBuildDuration / 1000);
|
|
1067
|
+
this.log.info(`Built block ${block.number} at checkpoint ${this.checkpointNumber} for slot ${this.targetSlot} with ${numTxs} txs`, {
|
|
1068
|
+
blockHash,
|
|
1069
|
+
txHashes,
|
|
1070
|
+
manaPerSec,
|
|
1071
|
+
...blockStats
|
|
1072
|
+
});
|
|
1073
|
+
// `slot` is the target/submission slot (may be one ahead when pipelining),
|
|
1074
|
+
// `buildSlot` is the wall-clock slot during which the block was actually built.
|
|
1075
|
+
this.eventEmitter.emit('block-proposed', {
|
|
1076
|
+
blockNumber: block.number,
|
|
1077
|
+
slot: this.targetSlot,
|
|
1078
|
+
buildSlot: this.slotNow
|
|
1079
|
+
});
|
|
1080
|
+
this.metrics.recordBuiltBlock(blockBuildDuration, block.header.totalManaUsed.toNumberUnsafe(), this.targetSlot);
|
|
1081
|
+
return {
|
|
1082
|
+
block,
|
|
1083
|
+
usedTxs
|
|
1084
|
+
};
|
|
1085
|
+
} catch (err) {
|
|
1086
|
+
this.eventEmitter.emit('block-build-failed', {
|
|
1087
|
+
reason: err.message,
|
|
1088
|
+
slot: this.targetSlot
|
|
1089
|
+
});
|
|
1090
|
+
this.log.error(`Error building block`, err, {
|
|
1091
|
+
blockNumber,
|
|
1092
|
+
slot: this.targetSlot
|
|
1093
|
+
});
|
|
1094
|
+
this.metrics.recordBlockProposalFailed(err.name || 'unknown_error');
|
|
1095
|
+
this.metrics.recordFailedBlock();
|
|
1096
|
+
return {
|
|
1097
|
+
error: err
|
|
1098
|
+
};
|
|
1099
|
+
}
|
|
1100
|
+
}
|
|
1101
|
+
/** Uses the checkpoint builder to build a block, catching InsufficientValidTxsError. */ async buildSingleBlockWithCheckpointBuilder(checkpointBuilder, pendingTxs, blockNumber, blockTimestamp, blockBuilderOptions) {
|
|
1102
|
+
try {
|
|
1103
|
+
const workTimer = new Timer();
|
|
1104
|
+
const result = await checkpointBuilder.buildBlock(pendingTxs, blockNumber, blockTimestamp, blockBuilderOptions);
|
|
1105
|
+
const blockBuildDuration = workTimer.ms();
|
|
1106
|
+
return {
|
|
1107
|
+
...result,
|
|
1108
|
+
blockBuildDuration,
|
|
1109
|
+
status: 'success'
|
|
1110
|
+
};
|
|
1111
|
+
} catch (err) {
|
|
1112
|
+
if (isErrorClass(err, InsufficientValidTxsError)) {
|
|
1113
|
+
return {
|
|
1114
|
+
failedTxs: err.failedTxs,
|
|
1115
|
+
processedCount: err.processedCount,
|
|
1116
|
+
status: 'insufficient-valid-txs'
|
|
1117
|
+
};
|
|
1118
|
+
}
|
|
1119
|
+
throw err;
|
|
1120
|
+
}
|
|
1121
|
+
}
|
|
1122
|
+
/** Waits until minTxs are available on the pool for building a block. */ async waitForMinTxs(opts) {
|
|
1123
|
+
const { indexWithinCheckpoint, blockNumber, buildDeadline, forceCreate } = opts;
|
|
1124
|
+
// We only allow a block with 0 txs in the first block of the checkpoint
|
|
1125
|
+
const minTxs = indexWithinCheckpoint > 0 && this.config.minTxsPerBlock === 0 ? 1 : this.config.minTxsPerBlock;
|
|
1126
|
+
// Deadline is undefined if we are not enforcing the timetable, meaning we'll exit immediately when out of time
|
|
1127
|
+
const startBuildingDeadline = buildDeadline ? new Date(buildDeadline.getTime() - this.timetable.minExecutionTime * 1000) : undefined;
|
|
1128
|
+
let availableTxs = await this.p2pClient.getPendingTxCount();
|
|
1129
|
+
while(!forceCreate && availableTxs < minTxs){
|
|
1130
|
+
// If we're past deadline, or we have no deadline, give up
|
|
1131
|
+
const now = this.dateProvider.nowAsDate();
|
|
1132
|
+
if (startBuildingDeadline === undefined || now >= startBuildingDeadline) {
|
|
1133
|
+
return {
|
|
1134
|
+
canStartBuilding: false,
|
|
1135
|
+
availableTxs,
|
|
1136
|
+
minTxs
|
|
1137
|
+
};
|
|
1138
|
+
}
|
|
1139
|
+
// Wait a bit before checking again
|
|
1140
|
+
this.setStateFn(SequencerState.WAITING_FOR_TXS, this.targetSlot);
|
|
1141
|
+
this.log.verbose(`Waiting for enough txs to build block ${blockNumber} at index ${indexWithinCheckpoint} in slot ${this.targetSlot} (have ${availableTxs} but need ${minTxs})`, {
|
|
1142
|
+
blockNumber,
|
|
1143
|
+
slot: this.targetSlot,
|
|
1144
|
+
indexWithinCheckpoint
|
|
1145
|
+
});
|
|
1146
|
+
await this.waitForTxsPollingInterval();
|
|
1147
|
+
availableTxs = await this.p2pClient.getPendingTxCount();
|
|
1148
|
+
}
|
|
1149
|
+
return {
|
|
1150
|
+
canStartBuilding: true,
|
|
1151
|
+
availableTxs,
|
|
1152
|
+
minTxs
|
|
1153
|
+
};
|
|
1154
|
+
}
|
|
1155
|
+
/**
|
|
1156
|
+
* Waits for enough attestations to be collected via p2p.
|
|
1157
|
+
* This is run after all blocks for the checkpoint have been built.
|
|
1158
|
+
*/ async waitForAttestations(proposal) {
|
|
1159
|
+
if (this.config.fishermanMode) {
|
|
1160
|
+
this.log.debug('Skipping attestation collection in fisherman mode');
|
|
1161
|
+
return CommitteeAttestationsAndSigners.empty();
|
|
1162
|
+
}
|
|
1163
|
+
const slotNumber = proposal.slotNumber;
|
|
1164
|
+
const { committee, seed, epoch } = await this.epochCache.getCommittee(slotNumber);
|
|
1165
|
+
if (!committee) {
|
|
1166
|
+
throw new Error('No committee when collecting attestations');
|
|
1167
|
+
} else if (committee.length === 0) {
|
|
1168
|
+
this.log.verbose(`Attesting committee is empty`);
|
|
1169
|
+
return CommitteeAttestationsAndSigners.empty();
|
|
1170
|
+
} else {
|
|
1171
|
+
this.log.debug(`Attesting committee length is ${committee.length}`, {
|
|
1172
|
+
committee
|
|
1173
|
+
});
|
|
1174
|
+
}
|
|
1175
|
+
const numberOfRequiredAttestations = computeQuorum(committee.length);
|
|
1176
|
+
if (this.config.skipCollectingAttestations) {
|
|
1177
|
+
this.log.warn('Skipping attestation collection as per config (attesting with own keys only)');
|
|
1178
|
+
const attestations = await this.validatorClient?.collectOwnAttestations(proposal, this.checkpointNumber);
|
|
1179
|
+
return new CommitteeAttestationsAndSigners(orderAttestations(attestations ?? [], committee));
|
|
1180
|
+
}
|
|
1181
|
+
const attestationTimeAllowed = this.config.enforceTimeTable ? this.timetable.getCheckpointAttestationDeadline() : this.l1Constants.slotDuration;
|
|
1182
|
+
const attestationDeadline = new Date((this.getSlotStartBuildTimestamp() + attestationTimeAllowed) * 1000);
|
|
1183
|
+
this.metrics.recordRequiredAttestations(numberOfRequiredAttestations, attestationTimeAllowed);
|
|
1184
|
+
const collectAttestationsTimer = new Timer();
|
|
1185
|
+
let collectedAttestationsCount = 0;
|
|
1186
|
+
try {
|
|
1187
|
+
const attestations = await this.validatorClient.collectAttestations(proposal, numberOfRequiredAttestations, attestationDeadline, this.checkpointNumber);
|
|
1188
|
+
collectedAttestationsCount = attestations.length;
|
|
1189
|
+
// Trim attestations to minimum required to save L1 calldata gas
|
|
1190
|
+
const localAddresses = this.validatorClient.getValidatorAddresses();
|
|
1191
|
+
const trimmed = trimAttestations(attestations, numberOfRequiredAttestations, this.attestorAddress, localAddresses);
|
|
1192
|
+
if (trimmed.length < attestations.length) {
|
|
1193
|
+
this.log.debug(`Trimmed attestations from ${attestations.length} to ${trimmed.length} for L1 submission`);
|
|
1194
|
+
}
|
|
1195
|
+
// Rollup contract requires that the signatures are provided in the order of the committee
|
|
1196
|
+
const sorted = orderAttestations(trimmed, committee);
|
|
1197
|
+
// Manipulate the attestations if we've been configured to do so
|
|
1198
|
+
if (this.config.injectFakeAttestation || this.config.injectHighSValueAttestation || this.config.injectUnrecoverableSignatureAttestation || this.config.shuffleAttestationOrdering) {
|
|
1199
|
+
return this.manipulateAttestations(proposal.slotNumber, epoch, seed, committee, sorted);
|
|
1200
|
+
}
|
|
1201
|
+
return new CommitteeAttestationsAndSigners(sorted);
|
|
1202
|
+
} catch (err) {
|
|
1203
|
+
if (err && err instanceof AttestationTimeoutError) {
|
|
1204
|
+
collectedAttestationsCount = err.collectedCount;
|
|
1205
|
+
}
|
|
1206
|
+
throw err;
|
|
1207
|
+
} finally{
|
|
1208
|
+
this.metrics.recordCollectedAttestations(collectedAttestationsCount, collectAttestationsTimer.ms());
|
|
1209
|
+
}
|
|
1210
|
+
}
|
|
1211
|
+
/** Breaks the attestations before publishing based on attack configs */ manipulateAttestations(slotNumber, epoch, seed, committee, attestations) {
|
|
1212
|
+
// Compute the proposer index in the committee, since we dont want to tweak it.
|
|
1213
|
+
// Otherwise, the L1 rollup contract will reject the block outright.
|
|
1214
|
+
const proposerIndex = Number(this.epochCache.computeProposerIndex(slotNumber, epoch, seed, BigInt(committee.length)));
|
|
1215
|
+
if (this.config.injectFakeAttestation || this.config.injectHighSValueAttestation || this.config.injectUnrecoverableSignatureAttestation) {
|
|
1216
|
+
// Find non-empty attestations that are not from the proposer
|
|
1217
|
+
const nonProposerIndices = [];
|
|
1218
|
+
for(let i = 0; i < attestations.length; i++){
|
|
1219
|
+
if (!attestations[i].signature.isEmpty() && i !== proposerIndex) {
|
|
1220
|
+
nonProposerIndices.push(i);
|
|
1221
|
+
}
|
|
1222
|
+
}
|
|
1223
|
+
if (nonProposerIndices.length > 0) {
|
|
1224
|
+
const targetIndex = nonProposerIndices[randomInt(nonProposerIndices.length)];
|
|
1225
|
+
if (this.config.injectHighSValueAttestation) {
|
|
1226
|
+
this.log.warn(`Injecting high-s value attestation in checkpoint for slot ${slotNumber} at index ${targetIndex}`);
|
|
1227
|
+
unfreeze(attestations[targetIndex]).signature = flipSignature(attestations[targetIndex].signature);
|
|
1228
|
+
} else if (this.config.injectUnrecoverableSignatureAttestation) {
|
|
1229
|
+
this.log.warn(`Injecting unrecoverable signature attestation in checkpoint for slot ${slotNumber} at index ${targetIndex}`);
|
|
1230
|
+
unfreeze(attestations[targetIndex]).signature = generateUnrecoverableSignature();
|
|
1231
|
+
} else {
|
|
1232
|
+
this.log.warn(`Injecting fake attestation in checkpoint for slot ${slotNumber} at index ${targetIndex}`);
|
|
1233
|
+
unfreeze(attestations[targetIndex]).signature = generateRecoverableSignature();
|
|
1234
|
+
}
|
|
1235
|
+
}
|
|
1236
|
+
return new CommitteeAttestationsAndSigners(attestations);
|
|
1237
|
+
}
|
|
1238
|
+
if (this.config.shuffleAttestationOrdering) {
|
|
1239
|
+
this.log.warn(`Shuffling attestation ordering in checkpoint for slot ${slotNumber} (proposer #${proposerIndex})`);
|
|
1240
|
+
const shuffled = [
|
|
1241
|
+
...attestations
|
|
1242
|
+
];
|
|
1243
|
+
// Find two non-proposer positions that both have non-empty signatures to swap.
|
|
1244
|
+
// This ensures the bitmap doesn't change, so the MaliciousCommitteeAttestationsAndSigners
|
|
1245
|
+
// signers array stays correctly aligned with L1's committee reconstruction.
|
|
1246
|
+
const swappable = [];
|
|
1247
|
+
for(let k = 0; k < shuffled.length; k++){
|
|
1248
|
+
if (!shuffled[k].signature.isEmpty() && k !== proposerIndex) {
|
|
1249
|
+
swappable.push(k);
|
|
1250
|
+
}
|
|
1251
|
+
}
|
|
1252
|
+
if (swappable.length >= 2) {
|
|
1253
|
+
const [i, j] = [
|
|
1254
|
+
swappable[0],
|
|
1255
|
+
swappable[1]
|
|
1256
|
+
];
|
|
1257
|
+
[shuffled[i], shuffled[j]] = [
|
|
1258
|
+
shuffled[j],
|
|
1259
|
+
shuffled[i]
|
|
1260
|
+
];
|
|
1261
|
+
}
|
|
1262
|
+
const signers = new CommitteeAttestationsAndSigners(attestations).getSigners();
|
|
1263
|
+
return new MaliciousCommitteeAttestationsAndSigners(shuffled, signers);
|
|
1264
|
+
}
|
|
1265
|
+
return new CommitteeAttestationsAndSigners(attestations);
|
|
1266
|
+
}
|
|
1267
|
+
async dropFailedTxsFromP2P(failedTxs) {
|
|
1268
|
+
if (failedTxs.length === 0) {
|
|
1269
|
+
return;
|
|
1270
|
+
}
|
|
1271
|
+
const failedTxData = failedTxs.map((fail)=>fail.tx);
|
|
1272
|
+
const failedTxHashes = failedTxData.map((tx)=>tx.getTxHash());
|
|
1273
|
+
this.log.verbose(`Dropping failed txs ${failedTxHashes.join(', ')}`);
|
|
1274
|
+
await this.p2pClient.handleFailedExecution(failedTxHashes);
|
|
1275
|
+
}
|
|
1276
|
+
/**
|
|
1277
|
+
* Adds the proposed block to the archiver so it's available via P2P.
|
|
1278
|
+
* Gossip doesn't echo messages back to the sender, so the proposer's archiver/world-state
|
|
1279
|
+
* would never receive its own block without this explicit sync.
|
|
1280
|
+
*
|
|
1281
|
+
* In fisherman mode we skip this push: the fisherman builds blocks locally for validation
|
|
1282
|
+
* and fee analysis only, and pushing them to the archiver causes spurious reorg cascades
|
|
1283
|
+
* whenever the real proposer's block arrives from L1.
|
|
1284
|
+
*/ async syncProposedBlockToArchiver(block) {
|
|
1285
|
+
if (this.config.skipPushProposedBlocksToArchiver || this.config.fishermanMode) {
|
|
1286
|
+
this.log.warn(`Skipping push of proposed block ${block.number} to archiver`, {
|
|
1287
|
+
blockNumber: block.number,
|
|
1288
|
+
slot: block.header.globalVariables.slotNumber
|
|
1289
|
+
});
|
|
1290
|
+
return;
|
|
1291
|
+
}
|
|
1292
|
+
this.log.debug(`Syncing proposed block ${block.number} to archiver`, {
|
|
1293
|
+
blockNumber: block.number,
|
|
1294
|
+
slot: block.header.globalVariables.slotNumber
|
|
1295
|
+
});
|
|
1296
|
+
await this.blockSink.addBlock(block);
|
|
1297
|
+
}
|
|
1298
|
+
/** Runs fee analysis and logs checkpoint outcome as fisherman */ async handleCheckpointEndAsFisherman(checkpoint) {
|
|
1299
|
+
// Perform L1 fee analysis before clearing requests
|
|
1300
|
+
// The callback is invoked asynchronously after the next block is mined
|
|
1301
|
+
const feeAnalysis = await this.publisher.analyzeL1Fees(this.targetSlot, (analysis)=>this.metrics.recordFishermanFeeAnalysis(analysis));
|
|
1302
|
+
if (checkpoint) {
|
|
1303
|
+
this.log.info(`Validation checkpoint building SUCCEEDED for slot ${this.targetSlot}`, {
|
|
1304
|
+
...checkpoint.toCheckpointInfo(),
|
|
1305
|
+
...checkpoint.getStats(),
|
|
1306
|
+
feeAnalysisId: feeAnalysis?.id
|
|
1307
|
+
});
|
|
1308
|
+
} else {
|
|
1309
|
+
this.log.warn(`Validation block building FAILED for slot ${this.targetSlot}`, {
|
|
1310
|
+
slot: this.targetSlot,
|
|
1311
|
+
feeAnalysisId: feeAnalysis?.id
|
|
1312
|
+
});
|
|
1313
|
+
this.metrics.recordCheckpointProposalFailed('block_build_failed');
|
|
1314
|
+
}
|
|
1315
|
+
this.publisher.clearPendingRequests();
|
|
1316
|
+
}
|
|
1317
|
+
/**
|
|
1318
|
+
* Helper to handle HA double-signing errors. Returns true if the error was handled (caller should yield).
|
|
1319
|
+
*/ handleHASigningError(err, errorContext) {
|
|
1320
|
+
if (err instanceof DutyAlreadySignedError) {
|
|
1321
|
+
this.log.info(`${errorContext} for slot ${this.targetSlot} already signed by another HA node, yielding`, {
|
|
1322
|
+
slot: this.targetSlot,
|
|
1323
|
+
signedByNode: err.signedByNode
|
|
1324
|
+
});
|
|
1325
|
+
return true;
|
|
1326
|
+
}
|
|
1327
|
+
if (err instanceof SlashingProtectionError) {
|
|
1328
|
+
this.log.info(`${errorContext} for slot ${this.targetSlot} blocked by slashing protection, yielding`, {
|
|
1329
|
+
slot: this.targetSlot,
|
|
1330
|
+
existingMessageHash: err.existingMessageHash,
|
|
1331
|
+
attemptedMessageHash: err.attemptedMessageHash
|
|
1332
|
+
});
|
|
1333
|
+
return true;
|
|
1334
|
+
}
|
|
1335
|
+
return false;
|
|
1336
|
+
}
|
|
1337
|
+
/** Waits until a specific time within the current slot */ async waitUntilTimeInSlot(targetSecondsIntoSlot) {
|
|
1338
|
+
const slotStartTimestamp = this.getSlotStartBuildTimestamp();
|
|
1339
|
+
const targetTimestamp = slotStartTimestamp + targetSecondsIntoSlot;
|
|
1340
|
+
await sleepUntil(new Date(targetTimestamp * 1000), this.dateProvider.nowAsDate());
|
|
1341
|
+
}
|
|
1342
|
+
/** Waits the polling interval for transactions. Extracted for test overriding. */ async waitForTxsPollingInterval() {
|
|
1343
|
+
await sleep(TXS_POLLING_MS);
|
|
1344
|
+
}
|
|
1345
|
+
getSlotStartBuildTimestamp() {
|
|
1346
|
+
return getSlotStartBuildTimestamp(this.slotNow, this.l1Constants);
|
|
1347
|
+
}
|
|
1348
|
+
getSecondsIntoSlot() {
|
|
1349
|
+
const slotStartTimestamp = this.getSlotStartBuildTimestamp();
|
|
1350
|
+
return Number((this.dateProvider.now() / 1000 - slotStartTimestamp).toFixed(3));
|
|
1351
|
+
}
|
|
1352
|
+
getPublisher() {
|
|
1353
|
+
return this.publisher;
|
|
1354
|
+
}
|
|
1355
|
+
}
|