@aztec/sequencer-client 0.0.1-commit.24de95ac → 0.0.1-commit.2606882
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +281 -21
- package/dest/client/index.d.ts +1 -1
- 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 +78 -37
- package/dest/config.d.ts +37 -8
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +139 -48
- 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 +24 -20
- package/dest/global_variable_builder/global_builder.d.ts.map +1 -1
- package/dest/global_variable_builder/global_builder.js +44 -65
- 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 +55 -20
- package/dest/publisher/config.d.ts.map +1 -1
- package/dest/publisher/config.js +124 -34
- package/dest/publisher/index.d.ts +2 -1
- package/dest/publisher/index.d.ts.map +1 -1
- package/dest/publisher/l1_tx_failed_store/factory.d.ts +11 -0
- package/dest/publisher/l1_tx_failed_store/factory.d.ts.map +1 -0
- package/dest/publisher/l1_tx_failed_store/factory.js +22 -0
- package/dest/publisher/l1_tx_failed_store/failed_tx_store.d.ts +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-bundle-simulator.d.ts +96 -0
- package/dest/publisher/sequencer-bundle-simulator.d.ts.map +1 -0
- package/dest/publisher/sequencer-bundle-simulator.js +198 -0
- package/dest/publisher/sequencer-publisher-factory.d.ts +15 -8
- package/dest/publisher/sequencer-publisher-factory.d.ts.map +1 -1
- package/dest/publisher/sequencer-publisher-factory.js +28 -4
- package/dest/publisher/sequencer-publisher-metrics.d.ts +3 -3
- package/dest/publisher/sequencer-publisher-metrics.d.ts.map +1 -1
- package/dest/publisher/sequencer-publisher-metrics.js +23 -86
- package/dest/publisher/sequencer-publisher.d.ts +137 -97
- package/dest/publisher/sequencer-publisher.d.ts.map +1 -1
- package/dest/publisher/sequencer-publisher.js +1001 -416
- package/dest/sequencer/automine/automine_factory.d.ts +54 -0
- package/dest/sequencer/automine/automine_factory.d.ts.map +1 -0
- package/dest/sequencer/automine/automine_factory.js +84 -0
- package/dest/sequencer/automine/automine_sequencer.d.ts +151 -0
- package/dest/sequencer/automine/automine_sequencer.d.ts.map +1 -0
- package/dest/sequencer/automine/automine_sequencer.js +509 -0
- package/dest/sequencer/chain_state_overrides.d.ts +61 -0
- package/dest/sequencer/chain_state_overrides.d.ts.map +1 -0
- package/dest/sequencer/chain_state_overrides.js +98 -0
- package/dest/sequencer/checkpoint_proposal_job.d.ts +150 -0
- package/dest/sequencer/checkpoint_proposal_job.d.ts.map +1 -0
- package/dest/sequencer/checkpoint_proposal_job.js +1792 -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/errors.d.ts +1 -1
- package/dest/sequencer/errors.d.ts.map +1 -1
- package/dest/sequencer/events.d.ts +92 -0
- package/dest/sequencer/events.d.ts.map +1 -0
- package/dest/sequencer/events.js +1 -0
- package/dest/sequencer/index.d.ts +6 -2
- package/dest/sequencer/index.d.ts.map +1 -1
- package/dest/sequencer/index.js +5 -1
- package/dest/sequencer/metrics.d.ts +48 -4
- package/dest/sequencer/metrics.d.ts.map +1 -1
- package/dest/sequencer/metrics.js +257 -50
- package/dest/sequencer/sequencer.d.ts +175 -144
- package/dest/sequencer/sequencer.d.ts.map +1 -1
- package/dest/sequencer/sequencer.js +1022 -567
- package/dest/sequencer/timetable.d.ts +64 -16
- package/dest/sequencer/timetable.d.ts.map +1 -1
- package/dest/sequencer/timetable.js +154 -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 +105 -0
- package/package.json +32 -30
- package/src/client/sequencer-client.ts +105 -60
- package/src/config.ts +163 -57
- 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 +63 -92
- package/src/global_variable_builder/index.ts +3 -1
- package/src/index.ts +5 -2
- package/src/publisher/config.ts +174 -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-bundle-simulator.ts +254 -0
- package/src/publisher/sequencer-publisher-factory.ts +45 -14
- package/src/publisher/sequencer-publisher-metrics.ts +19 -71
- package/src/publisher/sequencer-publisher.ts +795 -538
- package/src/sequencer/README.md +243 -0
- package/src/sequencer/automine/README.md +46 -0
- package/src/sequencer/automine/automine_factory.ts +145 -0
- package/src/sequencer/automine/automine_sequencer.ts +595 -0
- package/src/sequencer/chain_state_overrides.ts +162 -0
- package/src/sequencer/checkpoint_proposal_job.ts +1632 -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 +76 -0
- package/src/sequencer/index.ts +5 -1
- package/src/sequencer/metrics.ts +330 -62
- package/src/sequencer/sequencer.ts +831 -748
- package/src/sequencer/timetable.ts +181 -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 +185 -0
- package/dest/sequencer/block_builder.d.ts +0 -27
- package/dest/sequencer/block_builder.d.ts.map +0 -1
- package/dest/sequencer/block_builder.js +0 -130
- package/dest/tx_validator/nullifier_cache.d.ts +0 -14
- package/dest/tx_validator/nullifier_cache.d.ts.map +0 -1
- package/dest/tx_validator/nullifier_cache.js +0 -24
- package/dest/tx_validator/tx_validator_factory.d.ts +0 -17
- package/dest/tx_validator/tx_validator_factory.d.ts.map +0 -1
- package/dest/tx_validator/tx_validator_factory.js +0 -53
- package/src/sequencer/block_builder.ts +0 -218
- package/src/tx_validator/nullifier_cache.ts +0 -30
- package/src/tx_validator/tx_validator_factory.ts +0 -132
|
@@ -0,0 +1,1792 @@
|
|
|
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, CheckpointNumber, 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 { InterruptError, TimeoutError } from '@aztec/foundation/error';
|
|
443
|
+
import { filter } from '@aztec/foundation/iterator';
|
|
444
|
+
import { createLogger } from '@aztec/foundation/log';
|
|
445
|
+
import { InterruptibleSleep } from '@aztec/foundation/sleep';
|
|
446
|
+
import { Timer } from '@aztec/foundation/timer';
|
|
447
|
+
import { isErrorClass, unfreeze } from '@aztec/foundation/types';
|
|
448
|
+
import { CommitteeAttestationsAndSigners, MaliciousCommitteeAttestationsAndSigners } from '@aztec/stdlib/block';
|
|
449
|
+
import { getPreviousCheckpointOutHashes, validateCheckpoint } from '@aztec/stdlib/checkpoint';
|
|
450
|
+
import { computeQuorum, getSlotStartBuildTimestamp, getTimestampForSlot } from '@aztec/stdlib/epoch-helpers';
|
|
451
|
+
import { Gas } from '@aztec/stdlib/gas';
|
|
452
|
+
import { InsufficientValidTxsError } from '@aztec/stdlib/interfaces/server';
|
|
453
|
+
import { computeInHashFromL1ToL2Messages } from '@aztec/stdlib/messaging';
|
|
454
|
+
import { orderAttestations, trimAttestations } from '@aztec/stdlib/p2p';
|
|
455
|
+
import { AttestationTimeoutError } from '@aztec/stdlib/validators';
|
|
456
|
+
import { Attributes, trackSpan } from '@aztec/telemetry-client';
|
|
457
|
+
import { DutyAlreadySignedError, SlashingProtectionError } from '@aztec/validator-ha-signer/errors';
|
|
458
|
+
import { buildCheckpointSimulationOverridesPlan } from './chain_state_overrides.js';
|
|
459
|
+
import { CheckpointVoter } from './checkpoint_voter.js';
|
|
460
|
+
import { SequencerInterruptedError } from './errors.js';
|
|
461
|
+
import { SequencerState } from './utils.js';
|
|
462
|
+
/** How much time to sleep while waiting for min transactions to accumulate for a block */ const TXS_POLLING_MS = 500;
|
|
463
|
+
const ARCHIVER_SYNC_POLLING_MS = 200;
|
|
464
|
+
_dec = trackSpan('CheckpointProposalJob.execute'), _dec1 = trackSpan('CheckpointProposalJob.proposeCheckpoint', function() {
|
|
465
|
+
return {
|
|
466
|
+
// nullish operator needed for tests
|
|
467
|
+
[Attributes.COINBASE]: this.validatorClient.getCoinbaseForAttestor(this.attestorAddress)?.toString(),
|
|
468
|
+
[Attributes.SLOT_NUMBER]: this.targetSlot
|
|
469
|
+
};
|
|
470
|
+
}), _dec2 = trackSpan('CheckpointProposalJob.buildBlocksForCheckpoint'), _dec3 = trackSpan('CheckpointProposalJob.waitUntilNextSubslot'), _dec4 = trackSpan('CheckpointProposalJob.buildSingleBlock'), _dec5 = trackSpan('CheckpointProposalJob.waitForMinTxs'), _dec6 = trackSpan('CheckpointProposalJob.waitForAttestations'), _dec7 = trackSpan('CheckpointProposalJob.waitUntilTimeInSlot');
|
|
471
|
+
/**
|
|
472
|
+
* Handles the execution of a checkpoint proposal after the initial preparation phase.
|
|
473
|
+
* This includes building blocks, collecting attestations, and publishing the checkpoint to L1,
|
|
474
|
+
* as well as enqueueing votes for slashing and governance proposals. This class is created from
|
|
475
|
+
* the Sequencer once the check for being the proposer for the slot has succeeded.
|
|
476
|
+
*/ export class CheckpointProposalJob {
|
|
477
|
+
slotNow;
|
|
478
|
+
targetSlot;
|
|
479
|
+
targetEpoch;
|
|
480
|
+
checkpointNumber;
|
|
481
|
+
syncedToBlockNumber;
|
|
482
|
+
checkpointedCheckpointNumber;
|
|
483
|
+
proposer;
|
|
484
|
+
publisher;
|
|
485
|
+
attestorAddress;
|
|
486
|
+
invalidateCheckpoint;
|
|
487
|
+
validatorClient;
|
|
488
|
+
globalsBuilder;
|
|
489
|
+
p2pClient;
|
|
490
|
+
worldState;
|
|
491
|
+
l1ToL2MessageSource;
|
|
492
|
+
l2BlockSource;
|
|
493
|
+
checkpointsBuilder;
|
|
494
|
+
blockSink;
|
|
495
|
+
l1Constants;
|
|
496
|
+
signatureContext;
|
|
497
|
+
config;
|
|
498
|
+
timetable;
|
|
499
|
+
slasherClient;
|
|
500
|
+
epochCache;
|
|
501
|
+
dateProvider;
|
|
502
|
+
metrics;
|
|
503
|
+
checkpointMetrics;
|
|
504
|
+
eventEmitter;
|
|
505
|
+
setStateFn;
|
|
506
|
+
tracer;
|
|
507
|
+
proposedCheckpointData;
|
|
508
|
+
static{
|
|
509
|
+
({ e: [_initProto] } = _apply_decs_2203_r(this, [
|
|
510
|
+
[
|
|
511
|
+
_dec,
|
|
512
|
+
2,
|
|
513
|
+
"execute"
|
|
514
|
+
],
|
|
515
|
+
[
|
|
516
|
+
_dec1,
|
|
517
|
+
2,
|
|
518
|
+
"proposeCheckpoint"
|
|
519
|
+
],
|
|
520
|
+
[
|
|
521
|
+
_dec2,
|
|
522
|
+
2,
|
|
523
|
+
"buildBlocksForCheckpoint"
|
|
524
|
+
],
|
|
525
|
+
[
|
|
526
|
+
_dec3,
|
|
527
|
+
2,
|
|
528
|
+
"waitUntilNextSubslot"
|
|
529
|
+
],
|
|
530
|
+
[
|
|
531
|
+
_dec4,
|
|
532
|
+
2,
|
|
533
|
+
"buildSingleBlock"
|
|
534
|
+
],
|
|
535
|
+
[
|
|
536
|
+
_dec5,
|
|
537
|
+
2,
|
|
538
|
+
"waitForMinTxs"
|
|
539
|
+
],
|
|
540
|
+
[
|
|
541
|
+
_dec6,
|
|
542
|
+
2,
|
|
543
|
+
"waitForAttestations"
|
|
544
|
+
],
|
|
545
|
+
[
|
|
546
|
+
_dec7,
|
|
547
|
+
2,
|
|
548
|
+
"waitUntilTimeInSlot"
|
|
549
|
+
]
|
|
550
|
+
], []));
|
|
551
|
+
}
|
|
552
|
+
log;
|
|
553
|
+
checkpointEventLog;
|
|
554
|
+
/** Tracks the fire-and-forget L1 submission promise so it can be awaited during shutdown. */ pendingL1Submission;
|
|
555
|
+
interruptibleSleep;
|
|
556
|
+
interrupted;
|
|
557
|
+
/**
|
|
558
|
+
* Chain state overrides built once per slot in proposeCheckpoint after the checkpoint is
|
|
559
|
+
* complete. Carries the pending parent override (archive + slot + fee header) for pipelining,
|
|
560
|
+
* or the invalidation pending override when rolling back. Consumed by
|
|
561
|
+
* publisher.validateBlockHeader before broadcast.
|
|
562
|
+
*/ checkpointSimulationOverridesPlan;
|
|
563
|
+
getSignatureContext() {
|
|
564
|
+
return this.signatureContext;
|
|
565
|
+
}
|
|
566
|
+
constructor(slotNow, targetSlot, targetEpoch, checkpointNumber, syncedToBlockNumber, checkpointedCheckpointNumber, // TODO(palla/mbps): Can we remove the proposer in favor of attestorAddress? Need to check fisherman-node flows.
|
|
567
|
+
proposer, publisher, attestorAddress, invalidateCheckpoint, validatorClient, globalsBuilder, p2pClient, worldState, l1ToL2MessageSource, l2BlockSource, checkpointsBuilder, blockSink, l1Constants, signatureContext, config, timetable, slasherClient, epochCache, dateProvider, metrics, checkpointMetrics, eventEmitter, setStateFn, tracer, bindings, proposedCheckpointData){
|
|
568
|
+
this.slotNow = slotNow;
|
|
569
|
+
this.targetSlot = targetSlot;
|
|
570
|
+
this.targetEpoch = targetEpoch;
|
|
571
|
+
this.checkpointNumber = checkpointNumber;
|
|
572
|
+
this.syncedToBlockNumber = syncedToBlockNumber;
|
|
573
|
+
this.checkpointedCheckpointNumber = checkpointedCheckpointNumber;
|
|
574
|
+
this.proposer = proposer;
|
|
575
|
+
this.publisher = publisher;
|
|
576
|
+
this.attestorAddress = attestorAddress;
|
|
577
|
+
this.invalidateCheckpoint = invalidateCheckpoint;
|
|
578
|
+
this.validatorClient = validatorClient;
|
|
579
|
+
this.globalsBuilder = globalsBuilder;
|
|
580
|
+
this.p2pClient = p2pClient;
|
|
581
|
+
this.worldState = worldState;
|
|
582
|
+
this.l1ToL2MessageSource = l1ToL2MessageSource;
|
|
583
|
+
this.l2BlockSource = l2BlockSource;
|
|
584
|
+
this.checkpointsBuilder = checkpointsBuilder;
|
|
585
|
+
this.blockSink = blockSink;
|
|
586
|
+
this.l1Constants = l1Constants;
|
|
587
|
+
this.signatureContext = signatureContext;
|
|
588
|
+
this.config = config;
|
|
589
|
+
this.timetable = timetable;
|
|
590
|
+
this.slasherClient = slasherClient;
|
|
591
|
+
this.epochCache = epochCache;
|
|
592
|
+
this.dateProvider = dateProvider;
|
|
593
|
+
this.metrics = metrics;
|
|
594
|
+
this.checkpointMetrics = checkpointMetrics;
|
|
595
|
+
this.eventEmitter = eventEmitter;
|
|
596
|
+
this.setStateFn = setStateFn;
|
|
597
|
+
this.tracer = tracer;
|
|
598
|
+
this.proposedCheckpointData = proposedCheckpointData;
|
|
599
|
+
this.interruptibleSleep = (_initProto(this), new InterruptibleSleep());
|
|
600
|
+
this.interrupted = false;
|
|
601
|
+
this.log = createLogger('sequencer:checkpoint-proposal', {
|
|
602
|
+
...bindings,
|
|
603
|
+
instanceId: `slot-${this.slotNow}`
|
|
604
|
+
});
|
|
605
|
+
this.checkpointEventLog = createLogger('sequencer:checkpoint-events', {
|
|
606
|
+
...bindings,
|
|
607
|
+
instanceId: `slot-${this.slotNow}`
|
|
608
|
+
});
|
|
609
|
+
}
|
|
610
|
+
/** Awaits the pending L1 submission if one is in progress. Call during shutdown. */ async awaitPendingSubmission() {
|
|
611
|
+
this.log.info('Awaiting pending L1 payload submission');
|
|
612
|
+
await this.pendingL1Submission;
|
|
613
|
+
}
|
|
614
|
+
/** Interrupts job-owned waits so shutdown can finish. */ interrupt() {
|
|
615
|
+
this.interrupted = true;
|
|
616
|
+
this.interruptibleSleep.interrupt(true);
|
|
617
|
+
}
|
|
618
|
+
async awaitInterruptibleSleep(ms) {
|
|
619
|
+
if (this.interrupted) {
|
|
620
|
+
throw new SequencerInterruptedError();
|
|
621
|
+
}
|
|
622
|
+
if (ms <= 0) {
|
|
623
|
+
return;
|
|
624
|
+
}
|
|
625
|
+
try {
|
|
626
|
+
await this.interruptibleSleep.sleep(ms);
|
|
627
|
+
} catch (err) {
|
|
628
|
+
if (err instanceof InterruptError) {
|
|
629
|
+
throw new SequencerInterruptedError();
|
|
630
|
+
}
|
|
631
|
+
throw err;
|
|
632
|
+
}
|
|
633
|
+
}
|
|
634
|
+
logCheckpointEvent(eventName, message, fields) {
|
|
635
|
+
this.checkpointEventLog.debug(message, {
|
|
636
|
+
eventName: `sequencer-checkpoint-${eventName}`,
|
|
637
|
+
...fields
|
|
638
|
+
});
|
|
639
|
+
}
|
|
640
|
+
/**
|
|
641
|
+
* Executes the checkpoint proposal job.
|
|
642
|
+
* Builds blocks, assembles checkpoint, and broadcasts the proposal (blocking).
|
|
643
|
+
* Attestation collection, signing, and L1 submission are backgrounded so the
|
|
644
|
+
* work loop can return to IDLE immediately for consecutive slot proposals.
|
|
645
|
+
* Returns the built checkpoint if successful, undefined otherwise.
|
|
646
|
+
*/ async execute() {
|
|
647
|
+
// Enqueue governance and slashing votes (returns promises that will be awaited later)
|
|
648
|
+
// In fisherman mode, we simulate slashing but don't actually publish to L1
|
|
649
|
+
// These are constant for the whole slot, so we only enqueue them once
|
|
650
|
+
const votesPromises = new CheckpointVoter(this.targetSlot, this.publisher, this.attestorAddress, this.validatorClient, this.slasherClient, this.l1Constants, this.config, this.metrics, this.log).enqueueVotes();
|
|
651
|
+
// Build blocks, assemble checkpoint, and broadcast proposal (BLOCKING).
|
|
652
|
+
// Returns after broadcast — attestation collection is deferred.
|
|
653
|
+
const broadcast = await this.proposeCheckpoint();
|
|
654
|
+
if (!broadcast) {
|
|
655
|
+
await Promise.all(votesPromises);
|
|
656
|
+
// Still submit votes even without a checkpoint.
|
|
657
|
+
// Under proposer pipelining, vote-offenses signatures are EIP-712-bound to `targetSlot`
|
|
658
|
+
// (the pipelined slot in which the multicall is expected to mine). Submitting at the
|
|
659
|
+
// wall-clock time would let the multicall mine in a different L2 slot, causing
|
|
660
|
+
// signature verification to fail silently inside Multicall3. Delay submission to the
|
|
661
|
+
// start of `targetSlot` so the tx mines in the slot the vote was signed for.
|
|
662
|
+
if (!this.config.fishermanMode) {
|
|
663
|
+
this.pendingL1Submission = this.publisher.sendRequestsAt(this.targetSlot).then(()=>{});
|
|
664
|
+
}
|
|
665
|
+
return undefined;
|
|
666
|
+
}
|
|
667
|
+
const { checkpoint } = broadcast;
|
|
668
|
+
this.metrics.recordCheckpointProposalSuccess();
|
|
669
|
+
// Do not post anything to L1 if we are fishermen, but do perform L1 fee analysis
|
|
670
|
+
if (this.config.fishermanMode) {
|
|
671
|
+
await this.handleCheckpointEndAsFisherman(checkpoint);
|
|
672
|
+
return checkpoint;
|
|
673
|
+
}
|
|
674
|
+
// Background the attestation → signing → L1 pipeline so the work loop is unblocked
|
|
675
|
+
this.pendingL1Submission = this.waitForAttestationsAndEnqueueSubmissionAsync(broadcast, votesPromises);
|
|
676
|
+
// Return the built checkpoint immediately — the work loop is now unblocked
|
|
677
|
+
return checkpoint;
|
|
678
|
+
}
|
|
679
|
+
/**
|
|
680
|
+
* Background pipeline: collects attestations, signs them, enqueues the checkpoint, and submits to L1.
|
|
681
|
+
* Runs as a fire-and-forget task stored in `pendingL1Submission` so the work loop is unblocked.
|
|
682
|
+
*/ async waitForAttestationsAndEnqueueSubmissionAsync(broadcast, votesPromises) {
|
|
683
|
+
const { checkpoint } = broadcast;
|
|
684
|
+
try {
|
|
685
|
+
// Wait for all votes actions, enqueued at the beginning, to resolve
|
|
686
|
+
await Promise.all(votesPromises);
|
|
687
|
+
// Try to collect attestations from the committee
|
|
688
|
+
const signedAttestations = await this.getSignedCommitteeAttestations(broadcast);
|
|
689
|
+
// Wait for the previous checkpoint to land on L1 before submitting, so we can check it
|
|
690
|
+
// matches the proposed checkpoint we used as parent, and has valid attestations.
|
|
691
|
+
if (signedAttestations && await this.waitForValidParentCheckpointOnL1()) {
|
|
692
|
+
await this.enqueueCheckpointForSubmission({
|
|
693
|
+
checkpoint,
|
|
694
|
+
...signedAttestations
|
|
695
|
+
});
|
|
696
|
+
}
|
|
697
|
+
// If we failed to collect attestations, at least check if we need to issue an invalidation
|
|
698
|
+
if (!signedAttestations && await this.waitForSyncedL2SlotNumber(this.slotNow)) {
|
|
699
|
+
const validationStatus = await this.l2BlockSource.getPendingChainValidationStatus();
|
|
700
|
+
if (!validationStatus.valid) {
|
|
701
|
+
this.log.warn(`Checkpoint ${validationStatus.checkpoint.checkpointNumber} has invalid attestations, enqueuing invalidation in spite of attestation collection failure`, {
|
|
702
|
+
checkpoint: validationStatus.checkpoint,
|
|
703
|
+
reason: validationStatus.reason
|
|
704
|
+
});
|
|
705
|
+
await this.enqueueInvalidation(validationStatus);
|
|
706
|
+
}
|
|
707
|
+
}
|
|
708
|
+
// Send whatever was enqueued: votes + (propose | invalidation | nothing).
|
|
709
|
+
const l1Response = await this.publisher.sendRequestsAt(this.targetSlot);
|
|
710
|
+
const proposedAction = l1Response?.successfulActions.find((a)=>a === 'propose');
|
|
711
|
+
if (proposedAction) {
|
|
712
|
+
this.logCheckpointEvent('published', `Checkpoint published for slot ${this.targetSlot}`, {
|
|
713
|
+
slot: this.targetSlot,
|
|
714
|
+
checkpointNumber: this.checkpointNumber,
|
|
715
|
+
successfulActions: l1Response?.successfulActions,
|
|
716
|
+
sentActions: l1Response?.sentActions
|
|
717
|
+
});
|
|
718
|
+
this.eventEmitter.emit('checkpoint-published', {
|
|
719
|
+
checkpoint: this.checkpointNumber,
|
|
720
|
+
slot: this.targetSlot
|
|
721
|
+
});
|
|
722
|
+
const coinbase = checkpoint.header.coinbase;
|
|
723
|
+
await this.metrics.incFilledSlot(this.publisher.getSenderAddress().toString(), coinbase);
|
|
724
|
+
} else {
|
|
725
|
+
this.logCheckpointEvent('publish-failed', `Checkpoint publish failed for slot ${this.targetSlot}`, {
|
|
726
|
+
slot: this.targetSlot,
|
|
727
|
+
checkpointNumber: this.checkpointNumber,
|
|
728
|
+
successfulActions: l1Response?.successfulActions,
|
|
729
|
+
failedActions: l1Response?.failedActions,
|
|
730
|
+
sentActions: l1Response?.sentActions,
|
|
731
|
+
expiredActions: l1Response?.expiredActions,
|
|
732
|
+
reason: 'propose_action_not_successful'
|
|
733
|
+
});
|
|
734
|
+
this.log.warn(`Checkpoint publish failed for slot ${this.targetSlot}`, {
|
|
735
|
+
slot: this.targetSlot,
|
|
736
|
+
checkpointNumber: this.checkpointNumber,
|
|
737
|
+
successfulActions: l1Response?.successfulActions,
|
|
738
|
+
failedActions: l1Response?.failedActions,
|
|
739
|
+
sentActions: l1Response?.sentActions,
|
|
740
|
+
expiredActions: l1Response?.expiredActions,
|
|
741
|
+
reason: 'propose_action_not_successful'
|
|
742
|
+
});
|
|
743
|
+
this.eventEmitter.emit('checkpoint-publish-failed', {
|
|
744
|
+
...l1Response,
|
|
745
|
+
slot: this.targetSlot
|
|
746
|
+
});
|
|
747
|
+
this.metrics.recordPipelineDiscard();
|
|
748
|
+
}
|
|
749
|
+
} catch (err) {
|
|
750
|
+
if (err instanceof SequencerInterruptedError) {
|
|
751
|
+
return;
|
|
752
|
+
}
|
|
753
|
+
this.logCheckpointEvent('publish-failed', `Checkpoint publish failed for slot ${this.targetSlot}`, {
|
|
754
|
+
slot: this.targetSlot,
|
|
755
|
+
checkpointNumber: this.checkpointNumber,
|
|
756
|
+
reason: err instanceof Error ? err.message : String(err)
|
|
757
|
+
});
|
|
758
|
+
this.log.error(`Background attestation/L1 pipeline failed for slot ${this.targetSlot}`, err, {
|
|
759
|
+
slot: this.targetSlot,
|
|
760
|
+
checkpointNumber: this.checkpointNumber,
|
|
761
|
+
reason: err instanceof Error ? err.message : String(err)
|
|
762
|
+
});
|
|
763
|
+
this.eventEmitter.emit('checkpoint-publish-failed', {
|
|
764
|
+
slot: this.targetSlot
|
|
765
|
+
});
|
|
766
|
+
this.metrics.recordPipelineDiscard();
|
|
767
|
+
}
|
|
768
|
+
}
|
|
769
|
+
/** Enqueues the checkpoint for L1 submission. Called after pipeline sleep in execute(). */ async enqueueCheckpointForSubmission(result) {
|
|
770
|
+
const { checkpoint, attestations, attestationsSignature } = result;
|
|
771
|
+
// Build-frame deadlines are measured against `slotNow`; observers still see `targetSlot`.
|
|
772
|
+
this.setStateFn(SequencerState.PUBLISHING_CHECKPOINT, this.targetSlot, this.slotNow);
|
|
773
|
+
const aztecSlotDuration = this.l1Constants.slotDuration;
|
|
774
|
+
const submissionSlotStart = Number(getTimestampForSlot(this.targetSlot, this.l1Constants));
|
|
775
|
+
const txTimeoutAt = new Date((submissionSlotStart + aztecSlotDuration) * 1000);
|
|
776
|
+
// If we have been configured to potentially skip publishing checkpoint then roll the dice here
|
|
777
|
+
if (this.config.skipPublishingCheckpointsPercent !== undefined && this.config.skipPublishingCheckpointsPercent > 0) {
|
|
778
|
+
const roll = Math.max(0, randomInt(100));
|
|
779
|
+
if (roll < this.config.skipPublishingCheckpointsPercent) {
|
|
780
|
+
this.log.warn(`Skipping publishing proposal for checkpoint ${checkpoint.number}. Configured percentage: ${this.config.skipPublishingCheckpointsPercent}, generated value: ${roll}`);
|
|
781
|
+
return;
|
|
782
|
+
}
|
|
783
|
+
}
|
|
784
|
+
await this.publisher.enqueueProposeCheckpoint(checkpoint, attestations, attestationsSignature, {
|
|
785
|
+
txTimeoutAt
|
|
786
|
+
});
|
|
787
|
+
}
|
|
788
|
+
/**
|
|
789
|
+
* Wait until the archiver syncs past the given L2 slot number.
|
|
790
|
+
* The deadline is the end of `this.targetSlot`, beyond which any pipelined work would miss its
|
|
791
|
+
* L1 submission window and is no longer useful.
|
|
792
|
+
*/ async waitForSyncedL2SlotNumber(waitForSlot) {
|
|
793
|
+
const targetSlotStart = Number(getTimestampForSlot(this.targetSlot, this.l1Constants));
|
|
794
|
+
const targetSlotEndMs = (targetSlotStart + this.l1Constants.slotDuration) * 1000;
|
|
795
|
+
const syncDelayTolerance = this.l1Constants.ethereumSlotDuration * 2 * 1000;
|
|
796
|
+
const timeoutSeconds = Math.max(0.1, (targetSlotEndMs + syncDelayTolerance - this.dateProvider.now()) / 1000);
|
|
797
|
+
try {
|
|
798
|
+
const timer = new Timer();
|
|
799
|
+
while(true){
|
|
800
|
+
const syncedSlot = await this.l2BlockSource.getSyncedL2SlotNumber();
|
|
801
|
+
if (syncedSlot !== undefined && syncedSlot >= waitForSlot) {
|
|
802
|
+
return true;
|
|
803
|
+
}
|
|
804
|
+
if (timeoutSeconds && timer.s() > timeoutSeconds) {
|
|
805
|
+
throw new TimeoutError(`Timeout awaiting archiver sync past slot ${waitForSlot}`);
|
|
806
|
+
}
|
|
807
|
+
await this.awaitInterruptibleSleep(ARCHIVER_SYNC_POLLING_MS);
|
|
808
|
+
}
|
|
809
|
+
} catch (err) {
|
|
810
|
+
if (err instanceof SequencerInterruptedError) {
|
|
811
|
+
throw err;
|
|
812
|
+
}
|
|
813
|
+
this.log.warn(`Archiver did not sync L1 past slot ${waitForSlot} before slot ${this.targetSlot} expired, discarding pipelined work`, {
|
|
814
|
+
checkpointNumber: this.checkpointNumber
|
|
815
|
+
});
|
|
816
|
+
this.emitPipelinedCheckpointDiscarded('archiver-sync-timeout');
|
|
817
|
+
return false;
|
|
818
|
+
}
|
|
819
|
+
}
|
|
820
|
+
/**
|
|
821
|
+
* Waits for the parent checkpoint to land on L1 before submitting a pipelined checkpoint.
|
|
822
|
+
* Polls until the archiver has synced L1 past the parent's slot, then verifies:
|
|
823
|
+
* - If we built on a proposed parent: it must have landed on L1 with matching hash and valid attestations.
|
|
824
|
+
* - If we built without a proposed parent: no new checkpoint must have appeared for that slot.
|
|
825
|
+
* If the parent has invalid attestations, enqueues an invalidation. Returns whether to proceed with the proposal.
|
|
826
|
+
*/ async waitForValidParentCheckpointOnL1() {
|
|
827
|
+
if (this.config.skipWaitForValidParentCheckpointOnL1) {
|
|
828
|
+
this.log.warn(`Skipping waitForValidParentCheckpointOnL1 due to test configuration`, {
|
|
829
|
+
checkpointNumber: this.checkpointNumber
|
|
830
|
+
});
|
|
831
|
+
return true;
|
|
832
|
+
}
|
|
833
|
+
const parentCheckpointNumber = CheckpointNumber(this.checkpointNumber - 1);
|
|
834
|
+
// Wait until archiver has synced L1 past the parent's slot (slotNow)
|
|
835
|
+
if (!await this.waitForSyncedL2SlotNumber(this.slotNow)) {
|
|
836
|
+
return false;
|
|
837
|
+
}
|
|
838
|
+
const tips = await this.l2BlockSource.getL2Tips();
|
|
839
|
+
const checkpointedNumber = tips.checkpointed.checkpoint.number;
|
|
840
|
+
// We built on top of a proposed checkpoint. Verify it landed on L1 as expected.
|
|
841
|
+
if (this.proposedCheckpointData) {
|
|
842
|
+
// After syncing from L1 we see the chain tip has invalid attestations. This means the parent checkpoint was posted
|
|
843
|
+
// with invalid attestations, or it built on top of something with invalid attestations and didnt invalidate them.
|
|
844
|
+
// Either way, we thought our parent would be valid, so we have to throw away our work. But at least we'll try and
|
|
845
|
+
// invalidate on L1 so we clean up the chain for the next proposer. And we'll slash them, but that's handled elsewhere.
|
|
846
|
+
const validationStatus = await this.l2BlockSource.getPendingChainValidationStatus();
|
|
847
|
+
if (!validationStatus.valid) {
|
|
848
|
+
this.log.warn(`Parent checkpoint ${parentCheckpointNumber} has invalid attestations, discarding pipelined work`, {
|
|
849
|
+
checkpointNumber: this.checkpointNumber,
|
|
850
|
+
reason: validationStatus.reason
|
|
851
|
+
});
|
|
852
|
+
this.emitPipelinedCheckpointDiscarded('parent-invalid-attestations');
|
|
853
|
+
await this.enqueueInvalidation(validationStatus);
|
|
854
|
+
return false;
|
|
855
|
+
}
|
|
856
|
+
// The pending chain is valid. But did the parent checkpoint land on L1 at all?
|
|
857
|
+
if (checkpointedNumber < parentCheckpointNumber) {
|
|
858
|
+
this.log.warn(`Parent checkpoint ${parentCheckpointNumber} did not land on L1, discarding pipelined work`, {
|
|
859
|
+
checkpointNumber: this.checkpointNumber,
|
|
860
|
+
checkpointedNumber
|
|
861
|
+
});
|
|
862
|
+
this.emitPipelinedCheckpointDiscarded('parent-not-on-l1');
|
|
863
|
+
return false;
|
|
864
|
+
}
|
|
865
|
+
// It landed. But is it the one we were expecting?
|
|
866
|
+
const expectedHash = this.proposedCheckpointData.header.hash().toString();
|
|
867
|
+
if (tips.checkpointed.checkpoint.hash !== expectedHash) {
|
|
868
|
+
this.log.warn(`Parent checkpoint ${parentCheckpointNumber} hash mismatch on L1, discarding pipelined work`, {
|
|
869
|
+
checkpointNumber: this.checkpointNumber,
|
|
870
|
+
expectedHash,
|
|
871
|
+
actualHash: tips.checkpointed.checkpoint.hash
|
|
872
|
+
});
|
|
873
|
+
this.emitPipelinedCheckpointDiscarded('parent-hash-mismatch');
|
|
874
|
+
return false;
|
|
875
|
+
}
|
|
876
|
+
return true;
|
|
877
|
+
} else {
|
|
878
|
+
// We didn't see a proposed checkpoint at build time, so we built on checkpointed parent from two slots ago.
|
|
879
|
+
// But if a new checkpoint for the previous slot appeared on L1 in the meantime, our checkpoint assumed the wrong parent,
|
|
880
|
+
// so we have to discard our work. This can happen if we're somehow cut off from p2p and fail to see the checkpoint
|
|
881
|
+
// proposal for the previous slot.
|
|
882
|
+
if (checkpointedNumber > parentCheckpointNumber) {
|
|
883
|
+
this.log.warn(`Unexpected checkpoint ${checkpointedNumber} landed on L1 after we built on top of parent ${parentCheckpointNumber}, discarding pipelined work`, {
|
|
884
|
+
checkpointNumber: this.checkpointNumber,
|
|
885
|
+
checkpointedNumber
|
|
886
|
+
});
|
|
887
|
+
this.emitPipelinedCheckpointDiscarded('unexpected-parent-appeared');
|
|
888
|
+
return false;
|
|
889
|
+
}
|
|
890
|
+
return true;
|
|
891
|
+
}
|
|
892
|
+
}
|
|
893
|
+
/** Emits the pipelined-checkpoint-discarded event and records the metric. */ emitPipelinedCheckpointDiscarded(reason) {
|
|
894
|
+
this.metrics.recordPipelineParentCheckpointMismatch(reason);
|
|
895
|
+
this.eventEmitter.emit('pipelined-checkpoint-discarded', {
|
|
896
|
+
slot: this.targetSlot,
|
|
897
|
+
checkpointNumber: this.checkpointNumber,
|
|
898
|
+
reason
|
|
899
|
+
});
|
|
900
|
+
}
|
|
901
|
+
/** Simulates and enqueues an invalidation request for the invalid parent checkpoint. */ async enqueueInvalidation(validationStatus) {
|
|
902
|
+
if (this.config.skipInvalidateBlockAsProposer) {
|
|
903
|
+
this.log.warn(`Skipping checkpoint invalidation as proposer due to test configuration`);
|
|
904
|
+
return;
|
|
905
|
+
}
|
|
906
|
+
const invalidateRequest = await this.publisher.simulateInvalidateCheckpoint(validationStatus);
|
|
907
|
+
if (invalidateRequest) {
|
|
908
|
+
const submissionSlotStart = Number(getTimestampForSlot(this.targetSlot, this.l1Constants));
|
|
909
|
+
const txTimeoutAt = new Date((submissionSlotStart + this.l1Constants.slotDuration) * 1000);
|
|
910
|
+
this.publisher.enqueueInvalidateCheckpoint(invalidateRequest, {
|
|
911
|
+
txTimeoutAt
|
|
912
|
+
});
|
|
913
|
+
} else {
|
|
914
|
+
this.log.info(`Invalidation simulation returned undefined, checkpoint may have been removed already`, {
|
|
915
|
+
checkpointNumber: this.checkpointNumber
|
|
916
|
+
});
|
|
917
|
+
}
|
|
918
|
+
}
|
|
919
|
+
async proposeCheckpoint() {
|
|
920
|
+
try {
|
|
921
|
+
const env = {
|
|
922
|
+
stack: [],
|
|
923
|
+
error: void 0,
|
|
924
|
+
hasError: false
|
|
925
|
+
};
|
|
926
|
+
try {
|
|
927
|
+
const now = this.dateProvider.now();
|
|
928
|
+
if (this.proposedCheckpointData) {
|
|
929
|
+
// Measure against the wall-clock slot whose build window we are currently using.
|
|
930
|
+
// In pipelining mode `targetSlot` is intentionally one slot ahead, which makes the
|
|
931
|
+
// target-slot boundary a full slot away from the actual build start time.
|
|
932
|
+
const slotBoundaryMs = Number(getTimestampForSlot(this.slotNow, this.l1Constants)) * 1000;
|
|
933
|
+
this.checkpointMetrics.recordPipelinedCheckpointBuildStartOffsetFromSlotBoundary(now - slotBoundaryMs);
|
|
934
|
+
}
|
|
935
|
+
this.checkpointMetrics.startCheckpointTiming(now);
|
|
936
|
+
// Get operator configured coinbase and fee recipient for this attestor
|
|
937
|
+
const coinbase = this.validatorClient.getCoinbaseForAttestor(this.attestorAddress);
|
|
938
|
+
const feeRecipient = this.validatorClient.getFeeRecipientForAttestor(this.attestorAddress);
|
|
939
|
+
// Start the checkpoint
|
|
940
|
+
this.setStateFn(SequencerState.INITIALIZING_CHECKPOINT, this.targetSlot, this.slotNow);
|
|
941
|
+
this.logCheckpointEvent('slot-started', `Starting checkpoint proposal for slot ${this.targetSlot}`, {
|
|
942
|
+
buildSlot: this.slotNow,
|
|
943
|
+
submissionSlot: this.targetSlot,
|
|
944
|
+
slot: this.targetSlot,
|
|
945
|
+
checkpointNumber: this.checkpointNumber,
|
|
946
|
+
proposer: this.proposer?.toString(),
|
|
947
|
+
attestorAddress: this.attestorAddress.toString(),
|
|
948
|
+
publisherAddress: this.publisher.getSenderAddress().toString(),
|
|
949
|
+
coinbase: coinbase.toString()
|
|
950
|
+
});
|
|
951
|
+
this.metrics.incOpenSlot(this.targetSlot, this.proposer?.toString() ?? 'unknown');
|
|
952
|
+
// Enqueues checkpoint invalidation (constant for the whole slot)
|
|
953
|
+
if (this.invalidateCheckpoint && !this.config.skipInvalidateBlockAsProposer) {
|
|
954
|
+
this.publisher.enqueueInvalidateCheckpoint(this.invalidateCheckpoint);
|
|
955
|
+
}
|
|
956
|
+
// Build the simulation plan for this slot. When pipelining, this overrides L1's view of
|
|
957
|
+
// pending/archive/fee-header to "as if the proposed parent had landed", so both the
|
|
958
|
+
// mana-min-fee simulation (in the globals builder) and the pre-broadcast
|
|
959
|
+
// validateBlockHeader see the chain tip the eventual L1 send will see.
|
|
960
|
+
this.checkpointSimulationOverridesPlan = await buildCheckpointSimulationOverridesPlan({
|
|
961
|
+
checkpointNumber: this.checkpointNumber,
|
|
962
|
+
proposedCheckpointData: this.proposedCheckpointData,
|
|
963
|
+
invalidateToPendingCheckpointNumber: this.invalidateCheckpoint?.forcePendingCheckpointNumber,
|
|
964
|
+
checkpointedCheckpointNumber: this.checkpointedCheckpointNumber,
|
|
965
|
+
rollup: this.publisher.rollupContract,
|
|
966
|
+
signatureContext: this.signatureContext,
|
|
967
|
+
log: this.log
|
|
968
|
+
});
|
|
969
|
+
const checkpointGlobalVariables = await this.globalsBuilder.buildCheckpointGlobalVariables(coinbase, feeRecipient, this.targetSlot, this.checkpointSimulationOverridesPlan);
|
|
970
|
+
// Collect L1 to L2 messages for the checkpoint and compute their hash
|
|
971
|
+
const l1ToL2Messages = await this.l1ToL2MessageSource.getL1ToL2Messages(this.checkpointNumber);
|
|
972
|
+
const inHash = computeInHashFromL1ToL2Messages(l1ToL2Messages);
|
|
973
|
+
// Collect the out hashes of all the checkpoints before this one in the same epoch.
|
|
974
|
+
// Under pipelining the parent checkpoint may not be on L1 yet at build time, so the helper
|
|
975
|
+
// splices in the parent's checkpointOutHash from the locally-known proposed checkpoint so
|
|
976
|
+
// the resulting `epochOutHash` matches what validators (and L1) compute once the parent
|
|
977
|
+
// lands on L1.
|
|
978
|
+
const previousCheckpointOutHashes = await getPreviousCheckpointOutHashes({
|
|
979
|
+
blockSource: this.l2BlockSource,
|
|
980
|
+
epoch: this.targetEpoch,
|
|
981
|
+
checkpointNumber: this.checkpointNumber,
|
|
982
|
+
l1Constants: this.epochCache.getL1Constants(),
|
|
983
|
+
pipeliningEnabled: true,
|
|
984
|
+
proposedCheckpointData: this.proposedCheckpointData,
|
|
985
|
+
log: this.log
|
|
986
|
+
});
|
|
987
|
+
// Anchor the modifier to the predicted parent fee header: L1 will apply it against
|
|
988
|
+
// that, not against the latest published checkpoint (which lags by one under pipelining).
|
|
989
|
+
const predictedParentEthPerFeeAssetE12 = this.checkpointSimulationOverridesPlan?.pendingCheckpointState?.feeHeader?.ethPerFeeAsset;
|
|
990
|
+
const feeAssetPriceModifier = await this.publisher.getFeeAssetPriceModifier(predictedParentEthPerFeeAssetE12);
|
|
991
|
+
const fork = _ts_add_disposable_resource(env, await this.worldState.fork(this.syncedToBlockNumber, {
|
|
992
|
+
closeDelayMs: 12_000
|
|
993
|
+
}), true);
|
|
994
|
+
// Create checkpoint builder for the entire slot
|
|
995
|
+
const checkpointBuilder = await this.checkpointsBuilder.startCheckpoint(this.checkpointNumber, checkpointGlobalVariables, feeAssetPriceModifier, l1ToL2Messages, previousCheckpointOutHashes, fork, this.log.getBindings());
|
|
996
|
+
// Options for the validator client when creating block and checkpoint proposals
|
|
997
|
+
const blockProposalOptions = {
|
|
998
|
+
publishFullTxs: !!this.config.publishTxsWithProposals,
|
|
999
|
+
broadcastInvalidBlockProposal: this.config.broadcastInvalidBlockProposal
|
|
1000
|
+
};
|
|
1001
|
+
const checkpointProposalOptions = {
|
|
1002
|
+
publishFullTxs: !!this.config.publishTxsWithProposals,
|
|
1003
|
+
broadcastInvalidCheckpointProposal: this.config.broadcastInvalidCheckpointProposalOnly || this.config.broadcastInvalidBlockProposal
|
|
1004
|
+
};
|
|
1005
|
+
let blocksInCheckpoint = [];
|
|
1006
|
+
let blockPendingBroadcast = undefined;
|
|
1007
|
+
const checkpointBuildTimer = new Timer();
|
|
1008
|
+
try {
|
|
1009
|
+
// Main loop: build blocks for the checkpoint
|
|
1010
|
+
const result = await this.buildBlocksForCheckpoint(checkpointBuilder, checkpointGlobalVariables.timestamp, inHash, blockProposalOptions);
|
|
1011
|
+
blocksInCheckpoint = result.blocksInCheckpoint;
|
|
1012
|
+
blockPendingBroadcast = result.blockPendingBroadcast;
|
|
1013
|
+
} catch (err) {
|
|
1014
|
+
// These errors are expected in HA mode, so we yield and let another HA node handle the slot
|
|
1015
|
+
// The only distinction between the 2 errors is SlashingProtectionError throws when the payload is different,
|
|
1016
|
+
// which is normal for block building (may have picked different txs)
|
|
1017
|
+
if (this.handleHASigningError(err, 'Block proposal')) {
|
|
1018
|
+
return undefined;
|
|
1019
|
+
}
|
|
1020
|
+
throw err;
|
|
1021
|
+
}
|
|
1022
|
+
if (blocksInCheckpoint.length === 0) {
|
|
1023
|
+
this.logCheckpointEvent('build-failed', `Checkpoint build failed for slot ${this.targetSlot}`, {
|
|
1024
|
+
slot: this.targetSlot,
|
|
1025
|
+
checkpointNumber: this.checkpointNumber,
|
|
1026
|
+
reason: 'no_blocks_built'
|
|
1027
|
+
});
|
|
1028
|
+
this.log.warn(`No blocks were built for slot ${this.targetSlot}`, {
|
|
1029
|
+
slot: this.targetSlot,
|
|
1030
|
+
checkpointNumber: this.checkpointNumber,
|
|
1031
|
+
reason: 'no_blocks_built'
|
|
1032
|
+
});
|
|
1033
|
+
this.eventEmitter.emit('checkpoint-empty', {
|
|
1034
|
+
slot: this.targetSlot
|
|
1035
|
+
});
|
|
1036
|
+
return undefined;
|
|
1037
|
+
}
|
|
1038
|
+
const minBlocksForCheckpoint = this.config.minBlocksForCheckpoint;
|
|
1039
|
+
if (minBlocksForCheckpoint !== undefined && blocksInCheckpoint.length < minBlocksForCheckpoint) {
|
|
1040
|
+
this.logCheckpointEvent('build-failed', `Checkpoint build failed for slot ${this.targetSlot}`, {
|
|
1041
|
+
slot: this.targetSlot,
|
|
1042
|
+
checkpointNumber: this.checkpointNumber,
|
|
1043
|
+
blocksBuilt: blocksInCheckpoint.length,
|
|
1044
|
+
minBlocksForCheckpoint,
|
|
1045
|
+
reason: 'min_blocks_not_met'
|
|
1046
|
+
});
|
|
1047
|
+
this.log.warn(`Checkpoint has fewer blocks than minimum (${blocksInCheckpoint.length} < ${minBlocksForCheckpoint}), skipping proposal`, {
|
|
1048
|
+
slot: this.targetSlot,
|
|
1049
|
+
checkpointNumber: this.checkpointNumber,
|
|
1050
|
+
blocksBuilt: blocksInCheckpoint.length,
|
|
1051
|
+
minBlocksForCheckpoint,
|
|
1052
|
+
reason: 'min_blocks_not_met'
|
|
1053
|
+
});
|
|
1054
|
+
return undefined;
|
|
1055
|
+
}
|
|
1056
|
+
// Assemble and broadcast the checkpoint proposal, including the last block that was not
|
|
1057
|
+
// broadcasted yet, and wait to collect the committee attestations.
|
|
1058
|
+
this.setStateFn(SequencerState.ASSEMBLING_CHECKPOINT, this.targetSlot, this.slotNow);
|
|
1059
|
+
const checkpoint = await checkpointBuilder.completeCheckpoint();
|
|
1060
|
+
// Final validation: per-block limits are only checked if the operator set them explicitly.
|
|
1061
|
+
// Otherwise, checkpoint-level budgets were already enforced by the redistribution logic.
|
|
1062
|
+
try {
|
|
1063
|
+
validateCheckpoint(checkpoint, {
|
|
1064
|
+
rollupManaLimit: this.l1Constants.rollupManaLimit,
|
|
1065
|
+
maxL2BlockGas: this.config.maxL2BlockGas,
|
|
1066
|
+
maxDABlockGas: this.config.maxDABlockGas,
|
|
1067
|
+
maxTxsPerBlock: this.config.maxTxsPerBlock,
|
|
1068
|
+
maxTxsPerCheckpoint: this.config.maxTxsPerCheckpoint
|
|
1069
|
+
});
|
|
1070
|
+
} catch (err) {
|
|
1071
|
+
this.logCheckpointEvent('build-failed', `Checkpoint build failed for slot ${this.targetSlot}`, {
|
|
1072
|
+
slot: this.targetSlot,
|
|
1073
|
+
checkpointNumber: this.checkpointNumber,
|
|
1074
|
+
blocksBuilt: blocksInCheckpoint.length,
|
|
1075
|
+
reason: 'invalid_checkpoint',
|
|
1076
|
+
checkpoint: checkpoint.header.toInspect()
|
|
1077
|
+
});
|
|
1078
|
+
this.log.error(`Built an invalid checkpoint at slot ${this.slotNow} (skipping proposal)`, err, {
|
|
1079
|
+
slot: this.targetSlot,
|
|
1080
|
+
checkpointNumber: this.checkpointNumber,
|
|
1081
|
+
blocksBuilt: blocksInCheckpoint.length,
|
|
1082
|
+
reason: 'invalid_checkpoint',
|
|
1083
|
+
checkpoint: checkpoint.header.toInspect()
|
|
1084
|
+
});
|
|
1085
|
+
return undefined;
|
|
1086
|
+
}
|
|
1087
|
+
// Record checkpoint-level build metrics
|
|
1088
|
+
this.checkpointMetrics.recordCheckpointBuild(checkpointBuildTimer.ms(), blocksInCheckpoint.length, checkpoint.getStats().txCount, Number(checkpoint.header.totalManaUsed.toBigInt()));
|
|
1089
|
+
this.logCheckpointEvent('built', `Checkpoint built for slot ${this.targetSlot}`, {
|
|
1090
|
+
slot: this.targetSlot,
|
|
1091
|
+
buildSlot: this.slotNow,
|
|
1092
|
+
checkpointNumber: this.checkpointNumber,
|
|
1093
|
+
proposer: this.proposer?.toString(),
|
|
1094
|
+
attestorAddress: this.attestorAddress.toString(),
|
|
1095
|
+
publisherAddress: this.publisher.getSenderAddress().toString(),
|
|
1096
|
+
blocksBuilt: blocksInCheckpoint.length,
|
|
1097
|
+
txCount: checkpoint.getStats().txCount,
|
|
1098
|
+
totalMana: Number(checkpoint.header.totalManaUsed.toBigInt())
|
|
1099
|
+
});
|
|
1100
|
+
// In fisherman mode, return the checkpoint without broadcasting or collecting attestations
|
|
1101
|
+
if (this.config.fishermanMode) {
|
|
1102
|
+
this.log.info(`Built checkpoint for slot ${this.targetSlot} with ${blocksInCheckpoint.length} blocks. ` + `Skipping proposal in fisherman mode.`, {
|
|
1103
|
+
slot: this.targetSlot,
|
|
1104
|
+
checkpoint: checkpoint.header.toInspect(),
|
|
1105
|
+
blocksBuilt: blocksInCheckpoint.length
|
|
1106
|
+
});
|
|
1107
|
+
this.metrics.recordCheckpointSuccess();
|
|
1108
|
+
// Return a broadcast result with a dummy proposal — fisherman mode skips attestation collection
|
|
1109
|
+
return {
|
|
1110
|
+
checkpoint,
|
|
1111
|
+
proposal: undefined,
|
|
1112
|
+
blockProposedAt: this.dateProvider.now()
|
|
1113
|
+
};
|
|
1114
|
+
}
|
|
1115
|
+
// Validate the header against L1 state before broadcasting.
|
|
1116
|
+
// If this fails the slot is aborted before any gossip work; state drift between here
|
|
1117
|
+
// and the eventual L1 send is caught by the bundle simulate at send time.
|
|
1118
|
+
try {
|
|
1119
|
+
await this.publisher.validateBlockHeader(checkpoint.header, this.checkpointSimulationOverridesPlan);
|
|
1120
|
+
} catch (err) {
|
|
1121
|
+
this.log.error(`Pre-broadcast header validation failed for slot ${this.targetSlot}; aborting`, err, {
|
|
1122
|
+
slot: this.targetSlot,
|
|
1123
|
+
checkpointNumber: this.checkpointNumber
|
|
1124
|
+
});
|
|
1125
|
+
this.metrics.recordCheckpointProposalFailed('header_validation_failed');
|
|
1126
|
+
this.eventEmitter.emit('header-validation-failed', {
|
|
1127
|
+
slot: this.targetSlot,
|
|
1128
|
+
checkpointNumber: this.checkpointNumber,
|
|
1129
|
+
reason: err instanceof Error ? err.message : String(err)
|
|
1130
|
+
});
|
|
1131
|
+
return undefined;
|
|
1132
|
+
}
|
|
1133
|
+
// Create the checkpoint proposal and broadcast it
|
|
1134
|
+
const proposal = await this.validatorClient.createCheckpointProposal(checkpoint.header, checkpoint.archive.root, this.checkpointNumber, feeAssetPriceModifier, blockPendingBroadcast, this.proposer, checkpointProposalOptions);
|
|
1135
|
+
// Advance our own optimistic proposed-checkpoint tip locally before gossiping. Gossipsub
|
|
1136
|
+
// doesn't echo our own messages back, so this is how the proposer makes its own proposed
|
|
1137
|
+
// checkpoint visible for pipelining the next slot. Built from local checkpoint data — never
|
|
1138
|
+
// from the broadcast proposal archive, which may be deliberately corrupted under test flags.
|
|
1139
|
+
// Fail closed: if this throws, the outer catch aborts the slot before gossiping.
|
|
1140
|
+
await this.syncProposedCheckpointToArchiver(checkpoint, blocksInCheckpoint.length, feeAssetPriceModifier);
|
|
1141
|
+
const blockProposedAt = this.dateProvider.now();
|
|
1142
|
+
if (this.config.skipBroadcastCheckpointProposal) {
|
|
1143
|
+
// Test-only: suppress the CheckpointProposal so peers never see a proposed checkpoint for
|
|
1144
|
+
// this slot, but still broadcast the held last block standalone so peers' archivers ingest
|
|
1145
|
+
// it as a proposed-but-uncheckpointed tip — the exact orphan-block state that
|
|
1146
|
+
// pruneOrphanProposedBlocks / checkSync must handle.
|
|
1147
|
+
if (blockPendingBroadcast && !this.config.skipBroadcastProposals) {
|
|
1148
|
+
await this.p2pClient.broadcastProposal(blockPendingBroadcast);
|
|
1149
|
+
}
|
|
1150
|
+
} else if (!this.config.skipBroadcastProposals) {
|
|
1151
|
+
await this.p2pClient.broadcastCheckpointProposal(proposal);
|
|
1152
|
+
this.checkpointMetrics.noteCheckpointBroadcast(this.dateProvider.now());
|
|
1153
|
+
}
|
|
1154
|
+
// Return immediately after broadcast — attestation collection happens in the background
|
|
1155
|
+
return {
|
|
1156
|
+
checkpoint,
|
|
1157
|
+
proposal,
|
|
1158
|
+
blockProposedAt
|
|
1159
|
+
};
|
|
1160
|
+
} catch (e) {
|
|
1161
|
+
env.error = e;
|
|
1162
|
+
env.hasError = true;
|
|
1163
|
+
} finally{
|
|
1164
|
+
const result = _ts_dispose_resources(env);
|
|
1165
|
+
if (result) await result;
|
|
1166
|
+
}
|
|
1167
|
+
} catch (err) {
|
|
1168
|
+
if (err && (err instanceof DutyAlreadySignedError || err instanceof SlashingProtectionError)) {
|
|
1169
|
+
// swallow this error. It's already been logged by a function deeper in the stack
|
|
1170
|
+
return undefined;
|
|
1171
|
+
}
|
|
1172
|
+
this.log.error(`Error building checkpoint at slot ${this.targetSlot}`, err);
|
|
1173
|
+
return undefined;
|
|
1174
|
+
}
|
|
1175
|
+
}
|
|
1176
|
+
/**
|
|
1177
|
+
* Builds blocks for a checkpoint within the current slot.
|
|
1178
|
+
*/ async buildBlocksForCheckpoint(checkpointBuilder, timestamp, inHash, blockProposalOptions) {
|
|
1179
|
+
const blocksInCheckpoint = [];
|
|
1180
|
+
const txHashesAlreadyIncluded = new Set();
|
|
1181
|
+
const initialBlockNumber = BlockNumber(this.syncedToBlockNumber + 1);
|
|
1182
|
+
// Last block in the checkpoint will usually be flagged as pending broadcast, so we send it along with the checkpoint proposal
|
|
1183
|
+
let blockPendingBroadcast = undefined;
|
|
1184
|
+
while(true){
|
|
1185
|
+
const blocksBuilt = blocksInCheckpoint.length;
|
|
1186
|
+
const indexWithinCheckpoint = IndexWithinCheckpoint(blocksBuilt);
|
|
1187
|
+
const blockNumber = BlockNumber(initialBlockNumber + blocksBuilt);
|
|
1188
|
+
if (blocksBuilt >= this.config.maxBlocksPerCheckpoint) {
|
|
1189
|
+
this.log.debug(`Reached max blocks per checkpoint`, {
|
|
1190
|
+
slot: this.targetSlot,
|
|
1191
|
+
blocksBuilt,
|
|
1192
|
+
maxBlocksPerCheckpoint: this.config.maxBlocksPerCheckpoint
|
|
1193
|
+
});
|
|
1194
|
+
break;
|
|
1195
|
+
}
|
|
1196
|
+
const secondsIntoSlot = this.getSecondsIntoSlot();
|
|
1197
|
+
const timingInfo = this.timetable.canStartNextBlock(secondsIntoSlot);
|
|
1198
|
+
if (!timingInfo.canStart) {
|
|
1199
|
+
this.log.debug(`Not enough time left in slot to start another block`, {
|
|
1200
|
+
slot: this.targetSlot,
|
|
1201
|
+
blocksBuilt,
|
|
1202
|
+
secondsIntoSlot
|
|
1203
|
+
});
|
|
1204
|
+
break;
|
|
1205
|
+
}
|
|
1206
|
+
const buildResult = await this.buildSingleBlock(checkpointBuilder, {
|
|
1207
|
+
// Create all blocks with the same timestamp
|
|
1208
|
+
blockTimestamp: timestamp,
|
|
1209
|
+
// Create an empty block if we haven't already and this is the last one
|
|
1210
|
+
forceCreate: timingInfo.isLastBlock && blocksBuilt === 0 && this.config.buildCheckpointIfEmpty,
|
|
1211
|
+
// Build deadline is only set if we are enforcing the timetable
|
|
1212
|
+
buildDeadline: timingInfo.deadline ? new Date((this.getSlotStartBuildTimestamp() + timingInfo.deadline) * 1000) : undefined,
|
|
1213
|
+
blockNumber,
|
|
1214
|
+
indexWithinCheckpoint,
|
|
1215
|
+
txHashesAlreadyIncluded
|
|
1216
|
+
});
|
|
1217
|
+
// If we failed to build the block due to insufficient txs, we try again if there is still time left in the slot
|
|
1218
|
+
if ('failure' in buildResult) {
|
|
1219
|
+
// If this was the last subslot, or we're running with a single block per slot, we're done
|
|
1220
|
+
if (timingInfo.isLastBlock || timingInfo.deadline === undefined) {
|
|
1221
|
+
break;
|
|
1222
|
+
}
|
|
1223
|
+
// Otherwise, if there is still time for more blocks, we wait until the next subslot and try again
|
|
1224
|
+
await this.waitUntilNextSubslot(timingInfo.deadline);
|
|
1225
|
+
continue;
|
|
1226
|
+
}
|
|
1227
|
+
// If there was an error building the block, we just exit the loop and give up the rest of the slot.
|
|
1228
|
+
// We don't want to risk building more blocks if something went wrong.
|
|
1229
|
+
if ('error' in buildResult) {
|
|
1230
|
+
if (!(buildResult.error instanceof SequencerInterruptedError)) {
|
|
1231
|
+
this.log.warn(`Halting block building for slot ${this.targetSlot}`, {
|
|
1232
|
+
slot: this.targetSlot,
|
|
1233
|
+
blocksBuilt,
|
|
1234
|
+
error: buildResult.error
|
|
1235
|
+
});
|
|
1236
|
+
}
|
|
1237
|
+
break;
|
|
1238
|
+
}
|
|
1239
|
+
const { block, usedTxs } = buildResult;
|
|
1240
|
+
this.checkpointMetrics.noteCheckpointBlockBuilt(this.dateProvider.now(), {
|
|
1241
|
+
isFirstBlock: blocksBuilt === 0,
|
|
1242
|
+
isLastBlock: timingInfo.isLastBlock
|
|
1243
|
+
});
|
|
1244
|
+
blocksInCheckpoint.push(block);
|
|
1245
|
+
usedTxs.forEach((tx)=>txHashesAlreadyIncluded.add(tx.txHash.toString()));
|
|
1246
|
+
// Sign the block proposal. This will throw if HA signing fails.
|
|
1247
|
+
const proposal = await this.createBlockProposal(block, inHash, usedTxs, {
|
|
1248
|
+
...blockProposalOptions,
|
|
1249
|
+
broadcastInvalidBlockProposal: blockProposalOptions.broadcastInvalidBlockProposal || block.indexWithinCheckpoint === this.config.invalidBlockProposalIndexWithinCheckpoint
|
|
1250
|
+
});
|
|
1251
|
+
// Sync the proposed block to the archiver to make it available, only after we've managed to sign the proposal,
|
|
1252
|
+
// so we avoid polluting our archive with a block that would fail.
|
|
1253
|
+
// We wait for the sync to succeed, as this helps catch consistency errors, even if it means we lose some time for block-building.
|
|
1254
|
+
// If this throws, we abort the entire checkpoint.
|
|
1255
|
+
await this.syncProposedBlockToArchiver(block);
|
|
1256
|
+
// If this is the last block, do not broadcast it, since it will be included in the checkpoint proposal.
|
|
1257
|
+
if (timingInfo.isLastBlock) {
|
|
1258
|
+
this.log.verbose(`Completed final block ${blockNumber} for slot ${this.targetSlot}`, {
|
|
1259
|
+
slot: this.targetSlot,
|
|
1260
|
+
blockNumber,
|
|
1261
|
+
blocksBuilt
|
|
1262
|
+
});
|
|
1263
|
+
blockPendingBroadcast = proposal;
|
|
1264
|
+
break;
|
|
1265
|
+
}
|
|
1266
|
+
// Once we have a signed proposal and the archiver agreed with our proposed block, then we broadcast it.
|
|
1267
|
+
if (proposal && !this.config.skipBroadcastProposals) {
|
|
1268
|
+
await this.p2pClient.broadcastProposal(proposal);
|
|
1269
|
+
}
|
|
1270
|
+
// Wait until the next block's start time
|
|
1271
|
+
await this.waitUntilNextSubslot(timingInfo.deadline);
|
|
1272
|
+
}
|
|
1273
|
+
this.log.verbose(`Block building loop completed for slot ${this.targetSlot}`, {
|
|
1274
|
+
slot: this.targetSlot,
|
|
1275
|
+
blocksBuilt: blocksInCheckpoint.length
|
|
1276
|
+
});
|
|
1277
|
+
return {
|
|
1278
|
+
blocksInCheckpoint,
|
|
1279
|
+
blockPendingBroadcast
|
|
1280
|
+
};
|
|
1281
|
+
}
|
|
1282
|
+
/** Creates a block proposal for a given block via the validator client (unless in fisherman mode) */ createBlockProposal(block, inHash, usedTxs, blockProposalOptions) {
|
|
1283
|
+
if (this.config.fishermanMode) {
|
|
1284
|
+
this.log.info(`Skipping block proposal for block ${block.number} in fisherman mode`);
|
|
1285
|
+
return Promise.resolve(undefined);
|
|
1286
|
+
}
|
|
1287
|
+
return this.validatorClient.createBlockProposal(block.header, this.checkpointNumber, block.indexWithinCheckpoint, inHash, block.archive.root, usedTxs, this.proposer, blockProposalOptions);
|
|
1288
|
+
}
|
|
1289
|
+
/** Sleeps until it is time to produce the next block in the slot */ async waitUntilNextSubslot(nextSubslotStart) {
|
|
1290
|
+
this.setStateFn(SequencerState.WAITING_UNTIL_NEXT_BLOCK, this.targetSlot, this.slotNow);
|
|
1291
|
+
this.log.verbose(`Waiting until time for the next block at ${nextSubslotStart}s into slot`, {
|
|
1292
|
+
slot: this.targetSlot
|
|
1293
|
+
});
|
|
1294
|
+
await this.waitUntilTimeInSlot(nextSubslotStart);
|
|
1295
|
+
}
|
|
1296
|
+
/** Builds a single block. Called from the main block building loop. */ async buildSingleBlock(checkpointBuilder, opts) {
|
|
1297
|
+
const { blockTimestamp, forceCreate, blockNumber, indexWithinCheckpoint, buildDeadline, txHashesAlreadyIncluded } = opts;
|
|
1298
|
+
this.log.verbose(`Preparing block ${blockNumber} index ${indexWithinCheckpoint} at checkpoint ${this.checkpointNumber} for slot ${this.targetSlot}`, {
|
|
1299
|
+
...checkpointBuilder.getConstantData(),
|
|
1300
|
+
...opts
|
|
1301
|
+
});
|
|
1302
|
+
try {
|
|
1303
|
+
// Wait until we have enough txs to build the block
|
|
1304
|
+
const { availableTxs, canStartBuilding, minTxs } = await this.waitForMinTxs(opts);
|
|
1305
|
+
if (!canStartBuilding) {
|
|
1306
|
+
this.logCheckpointEvent('block-build-failed', `Block build failed for slot ${this.targetSlot}`, {
|
|
1307
|
+
reason: 'insufficient_txs',
|
|
1308
|
+
blockNumber,
|
|
1309
|
+
slot: this.targetSlot,
|
|
1310
|
+
checkpointNumber: this.checkpointNumber,
|
|
1311
|
+
indexWithinCheckpoint,
|
|
1312
|
+
availableTxs,
|
|
1313
|
+
minTxs
|
|
1314
|
+
});
|
|
1315
|
+
this.log.warn(`Not enough txs to build block ${blockNumber} at index ${indexWithinCheckpoint} in slot ${this.targetSlot} (got ${availableTxs} txs but needs ${minTxs})`, {
|
|
1316
|
+
reason: 'insufficient_txs',
|
|
1317
|
+
blockNumber,
|
|
1318
|
+
slot: this.targetSlot,
|
|
1319
|
+
checkpointNumber: this.checkpointNumber,
|
|
1320
|
+
indexWithinCheckpoint,
|
|
1321
|
+
availableTxs,
|
|
1322
|
+
minTxs
|
|
1323
|
+
});
|
|
1324
|
+
this.eventEmitter.emit('block-tx-count-check-failed', {
|
|
1325
|
+
minTxs,
|
|
1326
|
+
availableTxs,
|
|
1327
|
+
slot: this.targetSlot
|
|
1328
|
+
});
|
|
1329
|
+
this.metrics.recordBlockProposalFailed('insufficient_txs');
|
|
1330
|
+
return {
|
|
1331
|
+
failure: 'insufficient-txs'
|
|
1332
|
+
};
|
|
1333
|
+
}
|
|
1334
|
+
// Create iterator to pending txs. We filter out txs already included in previous blocks in the checkpoint
|
|
1335
|
+
// just in case p2p failed to sync the provisional block and didn't get to remove those txs from the mempool yet.
|
|
1336
|
+
const pendingTxs = filter(this.p2pClient.iterateEligiblePendingTxs(), (tx)=>!txHashesAlreadyIncluded.has(tx.txHash.toString()));
|
|
1337
|
+
this.log.debug(`Building block ${blockNumber} at index ${indexWithinCheckpoint} for slot ${this.targetSlot} with ${availableTxs} available txs`, {
|
|
1338
|
+
slot: this.targetSlot,
|
|
1339
|
+
blockNumber,
|
|
1340
|
+
indexWithinCheckpoint
|
|
1341
|
+
});
|
|
1342
|
+
this.setStateFn(SequencerState.CREATING_BLOCK, this.targetSlot, this.slotNow);
|
|
1343
|
+
// Per-block limits are operator overrides (from SEQ_MAX_L2_BLOCK_GAS etc.) further capped
|
|
1344
|
+
// by remaining checkpoint-level budgets inside CheckpointBuilder before each block is built.
|
|
1345
|
+
// minValidTxs is passed into the builder so it can reject the block *before* updating state.
|
|
1346
|
+
const minValidTxs = forceCreate ? 0 : this.config.minValidTxsPerBlock ?? minTxs;
|
|
1347
|
+
const blockBuilderOptions = {
|
|
1348
|
+
maxTransactions: this.config.maxTxsPerBlock,
|
|
1349
|
+
maxBlockGas: this.config.maxL2BlockGas !== undefined || this.config.maxDABlockGas !== undefined ? new Gas(this.config.maxDABlockGas ?? Infinity, this.config.maxL2BlockGas ?? Infinity) : undefined,
|
|
1350
|
+
deadline: buildDeadline,
|
|
1351
|
+
isBuildingProposal: true,
|
|
1352
|
+
minValidTxs,
|
|
1353
|
+
maxBlocksPerCheckpoint: this.timetable.maxNumberOfBlocks,
|
|
1354
|
+
perBlockAllocationMultiplier: this.config.perBlockAllocationMultiplier
|
|
1355
|
+
};
|
|
1356
|
+
// Actually build the block by executing txs. The builder throws InsufficientValidTxsError
|
|
1357
|
+
// if the number of successfully processed txs is below minValidTxs, ensuring state is not
|
|
1358
|
+
// updated for blocks that will be discarded.
|
|
1359
|
+
const buildResult = await this.buildSingleBlockWithCheckpointBuilder(checkpointBuilder, pendingTxs, blockNumber, blockTimestamp, blockBuilderOptions);
|
|
1360
|
+
// If any txs failed during execution, drop them from the mempool so we don't pick them up again
|
|
1361
|
+
await this.dropFailedTxsFromP2P(buildResult.failedTxs);
|
|
1362
|
+
if (buildResult.status === 'insufficient-valid-txs') {
|
|
1363
|
+
this.logCheckpointEvent('block-build-failed', `Block build failed for slot ${this.targetSlot}`, {
|
|
1364
|
+
reason: 'insufficient_valid_txs',
|
|
1365
|
+
slot: this.targetSlot,
|
|
1366
|
+
checkpointNumber: this.checkpointNumber,
|
|
1367
|
+
blockNumber,
|
|
1368
|
+
numTxs: buildResult.processedCount,
|
|
1369
|
+
indexWithinCheckpoint,
|
|
1370
|
+
minValidTxs
|
|
1371
|
+
});
|
|
1372
|
+
this.log.warn(`Block ${blockNumber} at index ${indexWithinCheckpoint} on slot ${this.targetSlot} has too few valid txs to be proposed`, {
|
|
1373
|
+
reason: 'insufficient_valid_txs',
|
|
1374
|
+
slot: this.targetSlot,
|
|
1375
|
+
checkpointNumber: this.checkpointNumber,
|
|
1376
|
+
blockNumber,
|
|
1377
|
+
numTxs: buildResult.processedCount,
|
|
1378
|
+
indexWithinCheckpoint,
|
|
1379
|
+
minValidTxs
|
|
1380
|
+
});
|
|
1381
|
+
this.eventEmitter.emit('block-build-failed', {
|
|
1382
|
+
reason: `Insufficient valid txs`,
|
|
1383
|
+
slot: this.targetSlot
|
|
1384
|
+
});
|
|
1385
|
+
this.metrics.recordBlockProposalFailed('insufficient_valid_txs');
|
|
1386
|
+
return {
|
|
1387
|
+
failure: 'insufficient-valid-txs'
|
|
1388
|
+
};
|
|
1389
|
+
}
|
|
1390
|
+
// Block creation succeeded, emit stats and metrics
|
|
1391
|
+
const { block, publicProcessorDuration, usedTxs, blockBuildDuration, numTxs } = buildResult;
|
|
1392
|
+
const blockStats = {
|
|
1393
|
+
eventName: 'l2-block-built',
|
|
1394
|
+
duration: blockBuildDuration,
|
|
1395
|
+
publicProcessDuration: publicProcessorDuration,
|
|
1396
|
+
...block.getStats()
|
|
1397
|
+
};
|
|
1398
|
+
const blockHash = await block.hash();
|
|
1399
|
+
const txHashes = block.body.txEffects.map((tx)=>tx.txHash);
|
|
1400
|
+
const manaPerSec = block.header.totalManaUsed.toNumberUnsafe() / (blockBuildDuration / 1000);
|
|
1401
|
+
this.log.info(`Built block ${block.number} at checkpoint ${this.checkpointNumber} for slot ${this.targetSlot} with ${numTxs} txs`, {
|
|
1402
|
+
blockHash,
|
|
1403
|
+
txHashes,
|
|
1404
|
+
manaPerSec,
|
|
1405
|
+
...blockStats
|
|
1406
|
+
});
|
|
1407
|
+
// `slot` is the target/submission slot (may be one ahead when pipelining),
|
|
1408
|
+
// `buildSlot` is the wall-clock slot during which the block was actually built.
|
|
1409
|
+
this.eventEmitter.emit('block-proposed', {
|
|
1410
|
+
blockNumber: block.number,
|
|
1411
|
+
blockHash,
|
|
1412
|
+
checkpointNumber: this.checkpointNumber,
|
|
1413
|
+
indexWithinCheckpoint: block.indexWithinCheckpoint,
|
|
1414
|
+
slot: this.targetSlot,
|
|
1415
|
+
buildSlot: this.slotNow
|
|
1416
|
+
});
|
|
1417
|
+
this.metrics.recordBuiltBlock(blockBuildDuration, block.header.totalManaUsed.toNumberUnsafe(), this.targetSlot);
|
|
1418
|
+
return {
|
|
1419
|
+
block,
|
|
1420
|
+
usedTxs
|
|
1421
|
+
};
|
|
1422
|
+
} catch (err) {
|
|
1423
|
+
this.eventEmitter.emit('block-build-failed', {
|
|
1424
|
+
reason: err.message,
|
|
1425
|
+
slot: this.targetSlot
|
|
1426
|
+
});
|
|
1427
|
+
this.logCheckpointEvent('block-build-failed', `Block build failed for slot ${this.targetSlot}`, {
|
|
1428
|
+
reason: err instanceof Error ? err.message : String(err),
|
|
1429
|
+
slot: this.targetSlot,
|
|
1430
|
+
checkpointNumber: this.checkpointNumber,
|
|
1431
|
+
blockNumber
|
|
1432
|
+
});
|
|
1433
|
+
this.log.error(`Error building block`, err, {
|
|
1434
|
+
reason: err instanceof Error ? err.message : String(err),
|
|
1435
|
+
slot: this.targetSlot,
|
|
1436
|
+
checkpointNumber: this.checkpointNumber,
|
|
1437
|
+
blockNumber
|
|
1438
|
+
});
|
|
1439
|
+
this.metrics.recordBlockProposalFailed(err.name || 'unknown_error');
|
|
1440
|
+
this.metrics.recordFailedBlock();
|
|
1441
|
+
return {
|
|
1442
|
+
error: err
|
|
1443
|
+
};
|
|
1444
|
+
}
|
|
1445
|
+
}
|
|
1446
|
+
/** Uses the checkpoint builder to build a block, catching InsufficientValidTxsError. */ async buildSingleBlockWithCheckpointBuilder(checkpointBuilder, pendingTxs, blockNumber, blockTimestamp, blockBuilderOptions) {
|
|
1447
|
+
try {
|
|
1448
|
+
const workTimer = new Timer();
|
|
1449
|
+
const result = await checkpointBuilder.buildBlock(pendingTxs, blockNumber, blockTimestamp, blockBuilderOptions);
|
|
1450
|
+
const blockBuildDuration = workTimer.ms();
|
|
1451
|
+
return {
|
|
1452
|
+
...result,
|
|
1453
|
+
blockBuildDuration,
|
|
1454
|
+
status: 'success'
|
|
1455
|
+
};
|
|
1456
|
+
} catch (err) {
|
|
1457
|
+
if (isErrorClass(err, InsufficientValidTxsError)) {
|
|
1458
|
+
return {
|
|
1459
|
+
failedTxs: err.failedTxs,
|
|
1460
|
+
processedCount: err.processedCount,
|
|
1461
|
+
status: 'insufficient-valid-txs'
|
|
1462
|
+
};
|
|
1463
|
+
}
|
|
1464
|
+
throw err;
|
|
1465
|
+
}
|
|
1466
|
+
}
|
|
1467
|
+
/** Waits until minTxs are available on the pool for building a block. */ async waitForMinTxs(opts) {
|
|
1468
|
+
const { indexWithinCheckpoint, blockNumber, buildDeadline, forceCreate } = opts;
|
|
1469
|
+
// We only allow a block with 0 txs in the first block of the checkpoint
|
|
1470
|
+
const minTxs = indexWithinCheckpoint > 0 && this.config.minTxsPerBlock === 0 ? 1 : this.config.minTxsPerBlock;
|
|
1471
|
+
// Deadline is undefined if we are not enforcing the timetable, meaning we'll exit immediately when out of time
|
|
1472
|
+
const startBuildingDeadline = buildDeadline ? new Date(buildDeadline.getTime() - this.timetable.minExecutionTime * 1000) : undefined;
|
|
1473
|
+
let availableTxs = await this.p2pClient.getPendingTxCount();
|
|
1474
|
+
while(!forceCreate && availableTxs < minTxs){
|
|
1475
|
+
// If we're past deadline, or we have no deadline, give up
|
|
1476
|
+
const now = this.dateProvider.nowAsDate();
|
|
1477
|
+
if (startBuildingDeadline === undefined || now >= startBuildingDeadline) {
|
|
1478
|
+
return {
|
|
1479
|
+
canStartBuilding: false,
|
|
1480
|
+
availableTxs,
|
|
1481
|
+
minTxs
|
|
1482
|
+
};
|
|
1483
|
+
}
|
|
1484
|
+
// Wait a bit before checking again
|
|
1485
|
+
this.setStateFn(SequencerState.WAITING_FOR_TXS, this.targetSlot, this.slotNow);
|
|
1486
|
+
this.log.verbose(`Waiting for enough txs to build block ${blockNumber} at index ${indexWithinCheckpoint} in slot ${this.targetSlot} (have ${availableTxs} but need ${minTxs})`, {
|
|
1487
|
+
blockNumber,
|
|
1488
|
+
slot: this.targetSlot,
|
|
1489
|
+
indexWithinCheckpoint
|
|
1490
|
+
});
|
|
1491
|
+
await this.waitForTxsPollingInterval();
|
|
1492
|
+
availableTxs = await this.p2pClient.getPendingTxCount();
|
|
1493
|
+
}
|
|
1494
|
+
return {
|
|
1495
|
+
canStartBuilding: true,
|
|
1496
|
+
availableTxs,
|
|
1497
|
+
minTxs
|
|
1498
|
+
};
|
|
1499
|
+
}
|
|
1500
|
+
async getSignedCommitteeAttestations(broadcast) {
|
|
1501
|
+
const { proposal, blockProposedAt } = broadcast;
|
|
1502
|
+
this.setStateFn(SequencerState.COLLECTING_ATTESTATIONS, this.targetSlot, this.slotNow);
|
|
1503
|
+
const attestations = await this.waitForAttestations(proposal);
|
|
1504
|
+
if (!attestations) {
|
|
1505
|
+
return undefined;
|
|
1506
|
+
}
|
|
1507
|
+
this.checkpointMetrics.recordCheckpointAttestationDelay(this.dateProvider.now() - blockProposedAt);
|
|
1508
|
+
// Proposer must sign over the attestations before pushing them to L1
|
|
1509
|
+
const signer = this.proposer ?? this.publisher.getSenderAddress();
|
|
1510
|
+
try {
|
|
1511
|
+
const attestationsSignature = await this.validatorClient.signAttestationsAndSigners(attestations, signer, this.targetSlot, this.checkpointNumber);
|
|
1512
|
+
return {
|
|
1513
|
+
attestations,
|
|
1514
|
+
attestationsSignature
|
|
1515
|
+
};
|
|
1516
|
+
} catch (err) {
|
|
1517
|
+
if (this.handleHASigningError(err, 'Attestations signature')) {
|
|
1518
|
+
return;
|
|
1519
|
+
}
|
|
1520
|
+
this.log.error(`Error signing attestations for checkpoint proposal at slot ${proposal.slotNumber}`, err);
|
|
1521
|
+
return undefined;
|
|
1522
|
+
}
|
|
1523
|
+
}
|
|
1524
|
+
/**
|
|
1525
|
+
* Waits for enough attestations to be collected via p2p.
|
|
1526
|
+
* This is run after all blocks for the checkpoint have been built.
|
|
1527
|
+
*/ async waitForAttestations(proposal) {
|
|
1528
|
+
if (this.config.fishermanMode) {
|
|
1529
|
+
this.log.debug('Skipping attestation collection in fisherman mode');
|
|
1530
|
+
return CommitteeAttestationsAndSigners.empty(this.getSignatureContext());
|
|
1531
|
+
}
|
|
1532
|
+
const slotNumber = proposal.slotNumber;
|
|
1533
|
+
const { committee, seed, epoch } = await this.epochCache.getCommittee(slotNumber);
|
|
1534
|
+
if (!committee) {
|
|
1535
|
+
throw new Error('No committee when collecting attestations');
|
|
1536
|
+
} else if (committee.length === 0) {
|
|
1537
|
+
this.log.verbose(`Attesting committee is empty`);
|
|
1538
|
+
return CommitteeAttestationsAndSigners.empty(this.getSignatureContext());
|
|
1539
|
+
} else {
|
|
1540
|
+
this.log.debug(`Attesting committee length is ${committee.length}`, {
|
|
1541
|
+
committee
|
|
1542
|
+
});
|
|
1543
|
+
}
|
|
1544
|
+
const numberOfRequiredAttestations = computeQuorum(committee.length);
|
|
1545
|
+
if (this.config.skipCollectingAttestations) {
|
|
1546
|
+
this.log.warn('Skipping attestation collection as per config (attesting with own keys only)');
|
|
1547
|
+
const attestations = await this.validatorClient?.collectOwnAttestations(proposal, this.checkpointNumber);
|
|
1548
|
+
this.logCheckpointAttestations('collected', committee, attestations ?? [], numberOfRequiredAttestations, {
|
|
1549
|
+
reason: 'collect_own_only'
|
|
1550
|
+
});
|
|
1551
|
+
return new CommitteeAttestationsAndSigners(orderAttestations(attestations ?? [], committee), this.getSignatureContext());
|
|
1552
|
+
}
|
|
1553
|
+
const attestationTimeAllowed = this.config.enforceTimeTable ? this.timetable.getCheckpointAttestationDeadline() : this.l1Constants.slotDuration;
|
|
1554
|
+
const attestationDeadline = new Date((this.getSlotStartBuildTimestamp() + attestationTimeAllowed) * 1000);
|
|
1555
|
+
this.metrics.recordRequiredAttestations(numberOfRequiredAttestations, attestationTimeAllowed);
|
|
1556
|
+
const collectAttestationsTimer = new Timer();
|
|
1557
|
+
let collectedAttestationsCount = 0;
|
|
1558
|
+
try {
|
|
1559
|
+
const attestations = await this.validatorClient.collectAttestations(proposal, numberOfRequiredAttestations, attestationDeadline, this.checkpointNumber);
|
|
1560
|
+
collectedAttestationsCount = attestations.length;
|
|
1561
|
+
// Trim attestations to minimum required to save L1 calldata gas
|
|
1562
|
+
const localAddresses = this.validatorClient.getValidatorAddresses();
|
|
1563
|
+
const trimmed = trimAttestations(attestations, numberOfRequiredAttestations, this.attestorAddress, localAddresses);
|
|
1564
|
+
if (trimmed.length < attestations.length) {
|
|
1565
|
+
this.log.debug(`Trimmed attestations from ${attestations.length} to ${trimmed.length} for L1 submission`);
|
|
1566
|
+
}
|
|
1567
|
+
// Rollup contract requires that the signatures are provided in the order of the committee
|
|
1568
|
+
const sorted = orderAttestations(trimmed, committee);
|
|
1569
|
+
this.logCheckpointAttestations('collected', committee, attestations, numberOfRequiredAttestations, {
|
|
1570
|
+
submittedCount: trimmed.length
|
|
1571
|
+
});
|
|
1572
|
+
// Manipulate the attestations if we've been configured to do so
|
|
1573
|
+
if (this.config.injectFakeAttestation || this.config.injectHighSValueAttestation || this.config.injectUnrecoverableSignatureAttestation || this.config.shuffleAttestationOrdering) {
|
|
1574
|
+
return this.manipulateAttestations(proposal.slotNumber, epoch, seed, committee, sorted);
|
|
1575
|
+
}
|
|
1576
|
+
return new CommitteeAttestationsAndSigners(sorted, this.getSignatureContext());
|
|
1577
|
+
} catch (err) {
|
|
1578
|
+
if (err && err instanceof AttestationTimeoutError) {
|
|
1579
|
+
collectedAttestationsCount = err.collectedCount;
|
|
1580
|
+
this.logCheckpointAttestations('failed', committee, undefined, numberOfRequiredAttestations, {
|
|
1581
|
+
collectedCount: collectedAttestationsCount,
|
|
1582
|
+
reason: 'timeout'
|
|
1583
|
+
});
|
|
1584
|
+
this.log.error(`Timeout while waiting for attestations for checkpoint proposal at slot ${proposal.slotNumber} (collected ${collectedAttestationsCount}/${numberOfRequiredAttestations})`, err);
|
|
1585
|
+
} else {
|
|
1586
|
+
this.logCheckpointAttestations('failed', committee, undefined, numberOfRequiredAttestations, {
|
|
1587
|
+
collectedCount: collectedAttestationsCount,
|
|
1588
|
+
reason: err instanceof Error ? err.message : String(err)
|
|
1589
|
+
});
|
|
1590
|
+
this.log.error(`Error collecting attestations for checkpoint proposal at slot ${proposal.slotNumber}`, err);
|
|
1591
|
+
}
|
|
1592
|
+
return undefined;
|
|
1593
|
+
} finally{
|
|
1594
|
+
this.metrics.recordCollectedAttestations(collectedAttestationsCount, collectAttestationsTimer.ms());
|
|
1595
|
+
}
|
|
1596
|
+
}
|
|
1597
|
+
logCheckpointAttestations(status, committee, attestations, requiredAttestations, opts = {}) {
|
|
1598
|
+
const signedValidators = attestations?.map((attestation)=>attestation.getSender()?.toString()).filter((address)=>address !== undefined) ?? [];
|
|
1599
|
+
const collectedCount = opts.collectedCount ?? new Set(signedValidators).size;
|
|
1600
|
+
const missingValidatorCount = status === 'failed' ? Math.max(0, requiredAttestations - collectedCount) : undefined;
|
|
1601
|
+
this.logCheckpointEvent(`attestations-${status}`, `Checkpoint attestations ${status} for slot ${this.targetSlot}`, {
|
|
1602
|
+
slot: this.targetSlot,
|
|
1603
|
+
checkpointNumber: this.checkpointNumber,
|
|
1604
|
+
committeeSize: committee.length,
|
|
1605
|
+
requiredAttestations,
|
|
1606
|
+
collectedAttestations: collectedCount,
|
|
1607
|
+
...opts.submittedCount !== undefined && {
|
|
1608
|
+
submittedAttestations: opts.submittedCount
|
|
1609
|
+
},
|
|
1610
|
+
...missingValidatorCount !== undefined && {
|
|
1611
|
+
missingValidatorCount
|
|
1612
|
+
},
|
|
1613
|
+
...opts.reason !== undefined && {
|
|
1614
|
+
reason: opts.reason
|
|
1615
|
+
}
|
|
1616
|
+
});
|
|
1617
|
+
}
|
|
1618
|
+
/** Breaks the attestations before publishing based on attack configs */ manipulateAttestations(slotNumber, epoch, seed, committee, attestations) {
|
|
1619
|
+
// Compute the proposer index in the committee, since we dont want to tweak it.
|
|
1620
|
+
// Otherwise, the L1 rollup contract will reject the block outright.
|
|
1621
|
+
const proposerIndex = Number(this.epochCache.computeProposerIndex(slotNumber, epoch, seed, BigInt(committee.length)));
|
|
1622
|
+
if (this.config.injectFakeAttestation || this.config.injectHighSValueAttestation || this.config.injectUnrecoverableSignatureAttestation) {
|
|
1623
|
+
// Find non-empty attestations that are not from the proposer
|
|
1624
|
+
const nonProposerIndices = [];
|
|
1625
|
+
for(let i = 0; i < attestations.length; i++){
|
|
1626
|
+
if (!attestations[i].signature.isEmpty() && i !== proposerIndex) {
|
|
1627
|
+
nonProposerIndices.push(i);
|
|
1628
|
+
}
|
|
1629
|
+
}
|
|
1630
|
+
if (nonProposerIndices.length > 0) {
|
|
1631
|
+
const targetIndex = nonProposerIndices[randomInt(nonProposerIndices.length)];
|
|
1632
|
+
if (this.config.injectHighSValueAttestation) {
|
|
1633
|
+
this.log.warn(`Injecting high-s value attestation in checkpoint for slot ${slotNumber} at index ${targetIndex}`);
|
|
1634
|
+
unfreeze(attestations[targetIndex]).signature = flipSignature(attestations[targetIndex].signature);
|
|
1635
|
+
} else if (this.config.injectUnrecoverableSignatureAttestation) {
|
|
1636
|
+
this.log.warn(`Injecting unrecoverable signature attestation in checkpoint for slot ${slotNumber} at index ${targetIndex}`);
|
|
1637
|
+
unfreeze(attestations[targetIndex]).signature = generateUnrecoverableSignature();
|
|
1638
|
+
} else {
|
|
1639
|
+
this.log.warn(`Injecting fake attestation in checkpoint for slot ${slotNumber} at index ${targetIndex}`);
|
|
1640
|
+
unfreeze(attestations[targetIndex]).signature = generateRecoverableSignature();
|
|
1641
|
+
}
|
|
1642
|
+
}
|
|
1643
|
+
return new CommitteeAttestationsAndSigners(attestations, this.getSignatureContext());
|
|
1644
|
+
}
|
|
1645
|
+
if (this.config.shuffleAttestationOrdering) {
|
|
1646
|
+
this.log.warn(`Shuffling attestation ordering in checkpoint for slot ${slotNumber} (proposer #${proposerIndex})`);
|
|
1647
|
+
const shuffled = [
|
|
1648
|
+
...attestations
|
|
1649
|
+
];
|
|
1650
|
+
// Find two non-proposer positions that both have non-empty signatures to swap.
|
|
1651
|
+
// This ensures the bitmap doesn't change, so the MaliciousCommitteeAttestationsAndSigners
|
|
1652
|
+
// signers array stays correctly aligned with L1's committee reconstruction.
|
|
1653
|
+
const swappable = [];
|
|
1654
|
+
for(let k = 0; k < shuffled.length; k++){
|
|
1655
|
+
if (!shuffled[k].signature.isEmpty() && k !== proposerIndex) {
|
|
1656
|
+
swappable.push(k);
|
|
1657
|
+
}
|
|
1658
|
+
}
|
|
1659
|
+
if (swappable.length >= 2) {
|
|
1660
|
+
const [i, j] = [
|
|
1661
|
+
swappable[0],
|
|
1662
|
+
swappable[1]
|
|
1663
|
+
];
|
|
1664
|
+
[shuffled[i], shuffled[j]] = [
|
|
1665
|
+
shuffled[j],
|
|
1666
|
+
shuffled[i]
|
|
1667
|
+
];
|
|
1668
|
+
}
|
|
1669
|
+
const signers = new CommitteeAttestationsAndSigners(attestations, this.getSignatureContext()).getSigners();
|
|
1670
|
+
return new MaliciousCommitteeAttestationsAndSigners(shuffled, signers, this.getSignatureContext());
|
|
1671
|
+
}
|
|
1672
|
+
return new CommitteeAttestationsAndSigners(attestations, this.getSignatureContext());
|
|
1673
|
+
}
|
|
1674
|
+
async dropFailedTxsFromP2P(failedTxs) {
|
|
1675
|
+
if (failedTxs.length === 0) {
|
|
1676
|
+
return;
|
|
1677
|
+
}
|
|
1678
|
+
const failedTxData = failedTxs.map((fail)=>fail.tx);
|
|
1679
|
+
const failedTxHashes = failedTxData.map((tx)=>tx.getTxHash());
|
|
1680
|
+
this.log.verbose(`Dropping failed txs ${failedTxHashes.join(', ')}`);
|
|
1681
|
+
await this.p2pClient.handleFailedExecution(failedTxHashes);
|
|
1682
|
+
}
|
|
1683
|
+
/**
|
|
1684
|
+
* Adds the proposed block to the archiver so it's available via P2P.
|
|
1685
|
+
* Gossip doesn't echo messages back to the sender, so the proposer's archiver/world-state
|
|
1686
|
+
* would never receive its own block without this explicit sync.
|
|
1687
|
+
*
|
|
1688
|
+
* In fisherman mode we skip this push: the fisherman builds blocks locally for validation
|
|
1689
|
+
* and fee analysis only, and pushing them to the archiver causes spurious reorg cascades
|
|
1690
|
+
* whenever the real proposer's block arrives from L1.
|
|
1691
|
+
*/ async syncProposedBlockToArchiver(block) {
|
|
1692
|
+
if (this.config.skipPushProposedBlocksToArchiver || this.config.fishermanMode) {
|
|
1693
|
+
this.log.warn(`Skipping push of proposed block ${block.number} to archiver`, {
|
|
1694
|
+
blockNumber: block.number,
|
|
1695
|
+
slot: block.header.globalVariables.slotNumber
|
|
1696
|
+
});
|
|
1697
|
+
return;
|
|
1698
|
+
}
|
|
1699
|
+
this.log.debug(`Syncing proposed block ${block.number} to archiver`, {
|
|
1700
|
+
blockNumber: block.number,
|
|
1701
|
+
slot: block.header.globalVariables.slotNumber
|
|
1702
|
+
});
|
|
1703
|
+
await this.blockSink.addBlock(block);
|
|
1704
|
+
}
|
|
1705
|
+
/**
|
|
1706
|
+
* Adds the proposed checkpoint to the archiver so the proposer's optimistic proposed-checkpoint
|
|
1707
|
+
* tip advances locally. Gossip doesn't echo our own messages back, so without this the proposer
|
|
1708
|
+
* would never see its own proposed checkpoint and couldn't pipeline the next slot.
|
|
1709
|
+
*
|
|
1710
|
+
* Skipped whenever proposed blocks aren't pushed (`skipPushProposedBlocksToArchiver`, fisherman
|
|
1711
|
+
* mode): the archiver derives the checkpoint archive from its stored blocks, so without them the
|
|
1712
|
+
* push would fail. All blocks were already added (and awaited) during block building, so this
|
|
1713
|
+
* needs no retry — they are guaranteed present by the time we get here.
|
|
1714
|
+
*/ async syncProposedCheckpointToArchiver(checkpoint, blockCount, feeAssetPriceModifier) {
|
|
1715
|
+
if (this.config.skipPushProposedBlocksToArchiver || this.config.fishermanMode) {
|
|
1716
|
+
return;
|
|
1717
|
+
}
|
|
1718
|
+
const startBlock = BlockNumber(this.syncedToBlockNumber + 1);
|
|
1719
|
+
this.log.debug(`Syncing proposed checkpoint ${this.checkpointNumber} to archiver`, {
|
|
1720
|
+
checkpointNumber: this.checkpointNumber,
|
|
1721
|
+
slot: this.targetSlot,
|
|
1722
|
+
startBlock,
|
|
1723
|
+
blockCount
|
|
1724
|
+
});
|
|
1725
|
+
await this.blockSink.addProposedCheckpoint({
|
|
1726
|
+
header: checkpoint.header,
|
|
1727
|
+
checkpointNumber: this.checkpointNumber,
|
|
1728
|
+
startBlock,
|
|
1729
|
+
blockCount,
|
|
1730
|
+
totalManaUsed: checkpoint.header.totalManaUsed.toBigInt(),
|
|
1731
|
+
feeAssetPriceModifier
|
|
1732
|
+
});
|
|
1733
|
+
}
|
|
1734
|
+
/** Runs fee analysis and logs checkpoint outcome as fisherman */ async handleCheckpointEndAsFisherman(checkpoint) {
|
|
1735
|
+
// Perform L1 fee analysis before clearing requests
|
|
1736
|
+
// The callback is invoked asynchronously after the next block is mined
|
|
1737
|
+
const feeAnalysis = await this.publisher.analyzeL1Fees(this.targetSlot, (analysis)=>this.metrics.recordFishermanFeeAnalysis(analysis));
|
|
1738
|
+
if (checkpoint) {
|
|
1739
|
+
this.log.info(`Validation checkpoint building SUCCEEDED for slot ${this.targetSlot}`, {
|
|
1740
|
+
...checkpoint.toCheckpointInfo(),
|
|
1741
|
+
...checkpoint.getStats(),
|
|
1742
|
+
feeAnalysisId: feeAnalysis?.id
|
|
1743
|
+
});
|
|
1744
|
+
} else {
|
|
1745
|
+
this.log.warn(`Validation block building FAILED for slot ${this.targetSlot}`, {
|
|
1746
|
+
slot: this.targetSlot,
|
|
1747
|
+
feeAnalysisId: feeAnalysis?.id
|
|
1748
|
+
});
|
|
1749
|
+
this.metrics.recordCheckpointProposalFailed('block_build_failed');
|
|
1750
|
+
}
|
|
1751
|
+
this.publisher.clearPendingRequests();
|
|
1752
|
+
}
|
|
1753
|
+
/**
|
|
1754
|
+
* Helper to handle HA double-signing errors. Returns true if the error was handled (caller should yield).
|
|
1755
|
+
*/ handleHASigningError(err, errorContext) {
|
|
1756
|
+
if (err instanceof DutyAlreadySignedError) {
|
|
1757
|
+
this.log.info(`${errorContext} for slot ${this.targetSlot} already signed by another HA node, yielding`, {
|
|
1758
|
+
slot: this.targetSlot,
|
|
1759
|
+
signedByNode: err.signedByNode
|
|
1760
|
+
});
|
|
1761
|
+
return true;
|
|
1762
|
+
}
|
|
1763
|
+
if (err instanceof SlashingProtectionError) {
|
|
1764
|
+
this.log.info(`${errorContext} for slot ${this.targetSlot} blocked by slashing protection, yielding`, {
|
|
1765
|
+
slot: this.targetSlot,
|
|
1766
|
+
existingMessageHash: err.existingMessageHash,
|
|
1767
|
+
attemptedMessageHash: err.attemptedMessageHash
|
|
1768
|
+
});
|
|
1769
|
+
return true;
|
|
1770
|
+
}
|
|
1771
|
+
return false;
|
|
1772
|
+
}
|
|
1773
|
+
/** Waits until a specific time within the current slot */ async waitUntilTimeInSlot(targetSecondsIntoSlot) {
|
|
1774
|
+
const slotStartTimestamp = this.getSlotStartBuildTimestamp();
|
|
1775
|
+
const targetTimestamp = slotStartTimestamp + targetSecondsIntoSlot;
|
|
1776
|
+
const delayMs = targetTimestamp * 1000 - this.dateProvider.nowAsDate().getTime();
|
|
1777
|
+
await this.awaitInterruptibleSleep(delayMs);
|
|
1778
|
+
}
|
|
1779
|
+
/** Pause between mempool polls in waitForMinTxs. Extracted for test overriding. */ async waitForTxsPollingInterval() {
|
|
1780
|
+
await this.awaitInterruptibleSleep(TXS_POLLING_MS);
|
|
1781
|
+
}
|
|
1782
|
+
getSlotStartBuildTimestamp() {
|
|
1783
|
+
return getSlotStartBuildTimestamp(this.slotNow, this.l1Constants);
|
|
1784
|
+
}
|
|
1785
|
+
getSecondsIntoSlot() {
|
|
1786
|
+
const slotStartTimestamp = this.getSlotStartBuildTimestamp();
|
|
1787
|
+
return Number((this.dateProvider.now() / 1000 - slotStartTimestamp).toFixed(3));
|
|
1788
|
+
}
|
|
1789
|
+
getPublisher() {
|
|
1790
|
+
return this.publisher;
|
|
1791
|
+
}
|
|
1792
|
+
}
|