@aztec/sequencer-client 0.0.0-test.1 → 0.0.1-commit.001888fc
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dest/client/index.d.ts +1 -1
- package/dest/client/sequencer-client.d.ts +50 -33
- package/dest/client/sequencer-client.d.ts.map +1 -1
- package/dest/client/sequencer-client.js +164 -57
- package/dest/config.d.ts +35 -17
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +150 -81
- package/dest/global_variable_builder/global_builder.d.ts +24 -15
- package/dest/global_variable_builder/global_builder.d.ts.map +1 -1
- package/dest/global_variable_builder/global_builder.js +63 -44
- package/dest/global_variable_builder/index.d.ts +1 -1
- package/dest/index.d.ts +2 -4
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +1 -3
- package/dest/publisher/config.d.ts +48 -27
- package/dest/publisher/config.d.ts.map +1 -1
- package/dest/publisher/config.js +109 -32
- package/dest/publisher/index.d.ts +4 -1
- package/dest/publisher/index.d.ts.map +1 -1
- package/dest/publisher/index.js +3 -0
- package/dest/publisher/l1_tx_failed_store/factory.d.ts +11 -0
- package/dest/publisher/l1_tx_failed_store/factory.d.ts.map +1 -0
- package/dest/publisher/l1_tx_failed_store/factory.js +22 -0
- package/dest/publisher/l1_tx_failed_store/failed_tx_store.d.ts +59 -0
- package/dest/publisher/l1_tx_failed_store/failed_tx_store.d.ts.map +1 -0
- package/dest/publisher/l1_tx_failed_store/failed_tx_store.js +1 -0
- package/dest/publisher/l1_tx_failed_store/file_store_failed_tx_store.d.ts +15 -0
- package/dest/publisher/l1_tx_failed_store/file_store_failed_tx_store.d.ts.map +1 -0
- package/dest/publisher/l1_tx_failed_store/file_store_failed_tx_store.js +34 -0
- package/dest/publisher/l1_tx_failed_store/index.d.ts +4 -0
- package/dest/publisher/l1_tx_failed_store/index.d.ts.map +1 -0
- package/dest/publisher/l1_tx_failed_store/index.js +2 -0
- package/dest/publisher/sequencer-publisher-factory.d.ts +52 -0
- package/dest/publisher/sequencer-publisher-factory.d.ts.map +1 -0
- package/dest/publisher/sequencer-publisher-factory.js +76 -0
- package/dest/publisher/sequencer-publisher-metrics.d.ts +5 -4
- package/dest/publisher/sequencer-publisher-metrics.d.ts.map +1 -1
- package/dest/publisher/sequencer-publisher-metrics.js +34 -62
- package/dest/publisher/sequencer-publisher.d.ts +158 -93
- package/dest/publisher/sequencer-publisher.d.ts.map +1 -1
- package/dest/publisher/sequencer-publisher.js +1452 -255
- package/dest/sequencer/checkpoint_proposal_job.d.ts +100 -0
- package/dest/sequencer/checkpoint_proposal_job.d.ts.map +1 -0
- package/dest/sequencer/checkpoint_proposal_job.js +1240 -0
- package/dest/sequencer/checkpoint_voter.d.ts +35 -0
- package/dest/sequencer/checkpoint_voter.d.ts.map +1 -0
- package/dest/sequencer/checkpoint_voter.js +109 -0
- package/dest/sequencer/config.d.ts +7 -1
- package/dest/sequencer/config.d.ts.map +1 -1
- package/dest/sequencer/errors.d.ts +11 -0
- package/dest/sequencer/errors.d.ts.map +1 -0
- package/dest/sequencer/errors.js +15 -0
- package/dest/sequencer/events.d.ts +46 -0
- package/dest/sequencer/events.d.ts.map +1 -0
- package/dest/sequencer/events.js +1 -0
- package/dest/sequencer/index.d.ts +4 -2
- package/dest/sequencer/index.d.ts.map +1 -1
- package/dest/sequencer/index.js +3 -1
- package/dest/sequencer/metrics.d.ts +60 -12
- package/dest/sequencer/metrics.d.ts.map +1 -1
- package/dest/sequencer/metrics.js +283 -67
- package/dest/sequencer/sequencer.d.ts +157 -135
- package/dest/sequencer/sequencer.d.ts.map +1 -1
- package/dest/sequencer/sequencer.js +966 -523
- package/dest/sequencer/timetable.d.ts +75 -25
- package/dest/sequencer/timetable.d.ts.map +1 -1
- package/dest/sequencer/timetable.js +174 -62
- package/dest/sequencer/types.d.ts +3 -0
- package/dest/sequencer/types.d.ts.map +1 -0
- package/dest/sequencer/types.js +1 -0
- package/dest/sequencer/utils.d.ts +20 -38
- package/dest/sequencer/utils.d.ts.map +1 -1
- package/dest/sequencer/utils.js +12 -47
- package/dest/test/index.d.ts +9 -3
- package/dest/test/index.d.ts.map +1 -1
- package/dest/test/index.js +0 -4
- package/dest/test/mock_checkpoint_builder.d.ts +99 -0
- package/dest/test/mock_checkpoint_builder.d.ts.map +1 -0
- package/dest/test/mock_checkpoint_builder.js +231 -0
- package/dest/test/utils.d.ts +53 -0
- package/dest/test/utils.d.ts.map +1 -0
- package/dest/test/utils.js +104 -0
- package/package.json +46 -45
- package/src/client/sequencer-client.ts +220 -104
- package/src/config.ts +172 -96
- package/src/global_variable_builder/global_builder.ts +85 -55
- package/src/index.ts +1 -3
- package/src/publisher/config.ts +150 -59
- package/src/publisher/index.ts +7 -0
- package/src/publisher/l1_tx_failed_store/factory.ts +32 -0
- package/src/publisher/l1_tx_failed_store/failed_tx_store.ts +55 -0
- package/src/publisher/l1_tx_failed_store/file_store_failed_tx_store.ts +46 -0
- package/src/publisher/l1_tx_failed_store/index.ts +3 -0
- package/src/publisher/sequencer-publisher-factory.ts +124 -0
- package/src/publisher/sequencer-publisher-metrics.ts +33 -63
- package/src/publisher/sequencer-publisher.ts +1266 -311
- package/src/sequencer/README.md +531 -0
- package/src/sequencer/checkpoint_proposal_job.ts +967 -0
- package/src/sequencer/checkpoint_voter.ts +130 -0
- package/src/sequencer/config.ts +8 -0
- package/src/sequencer/errors.ts +21 -0
- package/src/sequencer/events.ts +27 -0
- package/src/sequencer/index.ts +3 -1
- package/src/sequencer/metrics.ts +362 -73
- package/src/sequencer/sequencer.ts +712 -586
- package/src/sequencer/timetable.ts +224 -64
- package/src/sequencer/types.ts +6 -0
- package/src/sequencer/utils.ts +28 -60
- package/src/test/index.ts +11 -5
- package/src/test/mock_checkpoint_builder.ts +323 -0
- package/src/test/utils.ts +167 -0
- package/dest/sequencer/allowed.d.ts +0 -3
- package/dest/sequencer/allowed.d.ts.map +0 -1
- package/dest/sequencer/allowed.js +0 -27
- package/dest/slasher/factory.d.ts +0 -7
- package/dest/slasher/factory.d.ts.map +0 -1
- package/dest/slasher/factory.js +0 -8
- package/dest/slasher/index.d.ts +0 -3
- package/dest/slasher/index.d.ts.map +0 -1
- package/dest/slasher/index.js +0 -2
- package/dest/slasher/slasher_client.d.ts +0 -75
- package/dest/slasher/slasher_client.d.ts.map +0 -1
- package/dest/slasher/slasher_client.js +0 -132
- package/dest/tx_validator/archive_cache.d.ts +0 -14
- package/dest/tx_validator/archive_cache.d.ts.map +0 -1
- package/dest/tx_validator/archive_cache.js +0 -22
- package/dest/tx_validator/gas_validator.d.ts +0 -14
- package/dest/tx_validator/gas_validator.d.ts.map +0 -1
- package/dest/tx_validator/gas_validator.js +0 -78
- package/dest/tx_validator/nullifier_cache.d.ts +0 -16
- package/dest/tx_validator/nullifier_cache.d.ts.map +0 -1
- package/dest/tx_validator/nullifier_cache.js +0 -24
- package/dest/tx_validator/phases_validator.d.ts +0 -12
- package/dest/tx_validator/phases_validator.d.ts.map +0 -1
- package/dest/tx_validator/phases_validator.js +0 -80
- package/dest/tx_validator/test_utils.d.ts +0 -23
- package/dest/tx_validator/test_utils.d.ts.map +0 -1
- package/dest/tx_validator/test_utils.js +0 -26
- package/dest/tx_validator/tx_validator_factory.d.ts +0 -18
- package/dest/tx_validator/tx_validator_factory.d.ts.map +0 -1
- package/dest/tx_validator/tx_validator_factory.js +0 -50
- package/src/sequencer/allowed.ts +0 -36
- package/src/slasher/factory.ts +0 -15
- package/src/slasher/index.ts +0 -2
- package/src/slasher/slasher_client.ts +0 -193
- package/src/tx_validator/archive_cache.ts +0 -28
- package/src/tx_validator/gas_validator.ts +0 -101
- package/src/tx_validator/nullifier_cache.ts +0 -30
- package/src/tx_validator/phases_validator.ts +0 -98
- package/src/tx_validator/test_utils.ts +0 -48
- package/src/tx_validator/tx_validator_factory.ts +0 -120
|
@@ -1,74 +1,537 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
function applyDecs2203RFactory() {
|
|
2
|
+
function createAddInitializerMethod(initializers, decoratorFinishedRef) {
|
|
3
|
+
return function addInitializer(initializer) {
|
|
4
|
+
assertNotFinished(decoratorFinishedRef, "addInitializer");
|
|
5
|
+
assertCallable(initializer, "An initializer");
|
|
6
|
+
initializers.push(initializer);
|
|
7
|
+
};
|
|
8
|
+
}
|
|
9
|
+
function memberDec(dec, name, desc, initializers, kind, isStatic, isPrivate, metadata, value) {
|
|
10
|
+
var kindStr;
|
|
11
|
+
switch(kind){
|
|
12
|
+
case 1:
|
|
13
|
+
kindStr = "accessor";
|
|
14
|
+
break;
|
|
15
|
+
case 2:
|
|
16
|
+
kindStr = "method";
|
|
17
|
+
break;
|
|
18
|
+
case 3:
|
|
19
|
+
kindStr = "getter";
|
|
20
|
+
break;
|
|
21
|
+
case 4:
|
|
22
|
+
kindStr = "setter";
|
|
23
|
+
break;
|
|
24
|
+
default:
|
|
25
|
+
kindStr = "field";
|
|
26
|
+
}
|
|
27
|
+
var ctx = {
|
|
28
|
+
kind: kindStr,
|
|
29
|
+
name: isPrivate ? "#" + name : name,
|
|
30
|
+
static: isStatic,
|
|
31
|
+
private: isPrivate,
|
|
32
|
+
metadata: metadata
|
|
33
|
+
};
|
|
34
|
+
var decoratorFinishedRef = {
|
|
35
|
+
v: false
|
|
36
|
+
};
|
|
37
|
+
ctx.addInitializer = createAddInitializerMethod(initializers, decoratorFinishedRef);
|
|
38
|
+
var get, set;
|
|
39
|
+
if (kind === 0) {
|
|
40
|
+
if (isPrivate) {
|
|
41
|
+
get = desc.get;
|
|
42
|
+
set = desc.set;
|
|
43
|
+
} else {
|
|
44
|
+
get = function() {
|
|
45
|
+
return this[name];
|
|
46
|
+
};
|
|
47
|
+
set = function(v) {
|
|
48
|
+
this[name] = v;
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
} else if (kind === 2) {
|
|
52
|
+
get = function() {
|
|
53
|
+
return desc.value;
|
|
54
|
+
};
|
|
55
|
+
} else {
|
|
56
|
+
if (kind === 1 || kind === 3) {
|
|
57
|
+
get = function() {
|
|
58
|
+
return desc.get.call(this);
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
if (kind === 1 || kind === 4) {
|
|
62
|
+
set = function(v) {
|
|
63
|
+
desc.set.call(this, v);
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
ctx.access = get && set ? {
|
|
68
|
+
get: get,
|
|
69
|
+
set: set
|
|
70
|
+
} : get ? {
|
|
71
|
+
get: get
|
|
72
|
+
} : {
|
|
73
|
+
set: set
|
|
74
|
+
};
|
|
75
|
+
try {
|
|
76
|
+
return dec(value, ctx);
|
|
77
|
+
} finally{
|
|
78
|
+
decoratorFinishedRef.v = true;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
function assertNotFinished(decoratorFinishedRef, fnName) {
|
|
82
|
+
if (decoratorFinishedRef.v) {
|
|
83
|
+
throw new Error("attempted to call " + fnName + " after decoration was finished");
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
function assertCallable(fn, hint) {
|
|
87
|
+
if (typeof fn !== "function") {
|
|
88
|
+
throw new TypeError(hint + " must be a function");
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
function assertValidReturnValue(kind, value) {
|
|
92
|
+
var type = typeof value;
|
|
93
|
+
if (kind === 1) {
|
|
94
|
+
if (type !== "object" || value === null) {
|
|
95
|
+
throw new TypeError("accessor decorators must return an object with get, set, or init properties or void 0");
|
|
96
|
+
}
|
|
97
|
+
if (value.get !== undefined) {
|
|
98
|
+
assertCallable(value.get, "accessor.get");
|
|
99
|
+
}
|
|
100
|
+
if (value.set !== undefined) {
|
|
101
|
+
assertCallable(value.set, "accessor.set");
|
|
102
|
+
}
|
|
103
|
+
if (value.init !== undefined) {
|
|
104
|
+
assertCallable(value.init, "accessor.init");
|
|
105
|
+
}
|
|
106
|
+
} else if (type !== "function") {
|
|
107
|
+
var hint;
|
|
108
|
+
if (kind === 0) {
|
|
109
|
+
hint = "field";
|
|
110
|
+
} else if (kind === 10) {
|
|
111
|
+
hint = "class";
|
|
112
|
+
} else {
|
|
113
|
+
hint = "method";
|
|
114
|
+
}
|
|
115
|
+
throw new TypeError(hint + " decorators must return a function or void 0");
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
function applyMemberDec(ret, base, decInfo, name, kind, isStatic, isPrivate, initializers, metadata) {
|
|
119
|
+
var decs = decInfo[0];
|
|
120
|
+
var desc, init, value;
|
|
121
|
+
if (isPrivate) {
|
|
122
|
+
if (kind === 0 || kind === 1) {
|
|
123
|
+
desc = {
|
|
124
|
+
get: decInfo[3],
|
|
125
|
+
set: decInfo[4]
|
|
126
|
+
};
|
|
127
|
+
} else if (kind === 3) {
|
|
128
|
+
desc = {
|
|
129
|
+
get: decInfo[3]
|
|
130
|
+
};
|
|
131
|
+
} else if (kind === 4) {
|
|
132
|
+
desc = {
|
|
133
|
+
set: decInfo[3]
|
|
134
|
+
};
|
|
135
|
+
} else {
|
|
136
|
+
desc = {
|
|
137
|
+
value: decInfo[3]
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
} else if (kind !== 0) {
|
|
141
|
+
desc = Object.getOwnPropertyDescriptor(base, name);
|
|
142
|
+
}
|
|
143
|
+
if (kind === 1) {
|
|
144
|
+
value = {
|
|
145
|
+
get: desc.get,
|
|
146
|
+
set: desc.set
|
|
147
|
+
};
|
|
148
|
+
} else if (kind === 2) {
|
|
149
|
+
value = desc.value;
|
|
150
|
+
} else if (kind === 3) {
|
|
151
|
+
value = desc.get;
|
|
152
|
+
} else if (kind === 4) {
|
|
153
|
+
value = desc.set;
|
|
154
|
+
}
|
|
155
|
+
var newValue, get, set;
|
|
156
|
+
if (typeof decs === "function") {
|
|
157
|
+
newValue = memberDec(decs, name, desc, initializers, kind, isStatic, isPrivate, metadata, value);
|
|
158
|
+
if (newValue !== void 0) {
|
|
159
|
+
assertValidReturnValue(kind, newValue);
|
|
160
|
+
if (kind === 0) {
|
|
161
|
+
init = newValue;
|
|
162
|
+
} else if (kind === 1) {
|
|
163
|
+
init = newValue.init;
|
|
164
|
+
get = newValue.get || value.get;
|
|
165
|
+
set = newValue.set || value.set;
|
|
166
|
+
value = {
|
|
167
|
+
get: get,
|
|
168
|
+
set: set
|
|
169
|
+
};
|
|
170
|
+
} else {
|
|
171
|
+
value = newValue;
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
} else {
|
|
175
|
+
for(var i = decs.length - 1; i >= 0; i--){
|
|
176
|
+
var dec = decs[i];
|
|
177
|
+
newValue = memberDec(dec, name, desc, initializers, kind, isStatic, isPrivate, metadata, value);
|
|
178
|
+
if (newValue !== void 0) {
|
|
179
|
+
assertValidReturnValue(kind, newValue);
|
|
180
|
+
var newInit;
|
|
181
|
+
if (kind === 0) {
|
|
182
|
+
newInit = newValue;
|
|
183
|
+
} else if (kind === 1) {
|
|
184
|
+
newInit = newValue.init;
|
|
185
|
+
get = newValue.get || value.get;
|
|
186
|
+
set = newValue.set || value.set;
|
|
187
|
+
value = {
|
|
188
|
+
get: get,
|
|
189
|
+
set: set
|
|
190
|
+
};
|
|
191
|
+
} else {
|
|
192
|
+
value = newValue;
|
|
193
|
+
}
|
|
194
|
+
if (newInit !== void 0) {
|
|
195
|
+
if (init === void 0) {
|
|
196
|
+
init = newInit;
|
|
197
|
+
} else if (typeof init === "function") {
|
|
198
|
+
init = [
|
|
199
|
+
init,
|
|
200
|
+
newInit
|
|
201
|
+
];
|
|
202
|
+
} else {
|
|
203
|
+
init.push(newInit);
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
if (kind === 0 || kind === 1) {
|
|
210
|
+
if (init === void 0) {
|
|
211
|
+
init = function(instance, init) {
|
|
212
|
+
return init;
|
|
213
|
+
};
|
|
214
|
+
} else if (typeof init !== "function") {
|
|
215
|
+
var ownInitializers = init;
|
|
216
|
+
init = function(instance, init) {
|
|
217
|
+
var value = init;
|
|
218
|
+
for(var i = 0; i < ownInitializers.length; i++){
|
|
219
|
+
value = ownInitializers[i].call(instance, value);
|
|
220
|
+
}
|
|
221
|
+
return value;
|
|
222
|
+
};
|
|
223
|
+
} else {
|
|
224
|
+
var originalInitializer = init;
|
|
225
|
+
init = function(instance, init) {
|
|
226
|
+
return originalInitializer.call(instance, init);
|
|
227
|
+
};
|
|
228
|
+
}
|
|
229
|
+
ret.push(init);
|
|
230
|
+
}
|
|
231
|
+
if (kind !== 0) {
|
|
232
|
+
if (kind === 1) {
|
|
233
|
+
desc.get = value.get;
|
|
234
|
+
desc.set = value.set;
|
|
235
|
+
} else if (kind === 2) {
|
|
236
|
+
desc.value = value;
|
|
237
|
+
} else if (kind === 3) {
|
|
238
|
+
desc.get = value;
|
|
239
|
+
} else if (kind === 4) {
|
|
240
|
+
desc.set = value;
|
|
241
|
+
}
|
|
242
|
+
if (isPrivate) {
|
|
243
|
+
if (kind === 1) {
|
|
244
|
+
ret.push(function(instance, args) {
|
|
245
|
+
return value.get.call(instance, args);
|
|
246
|
+
});
|
|
247
|
+
ret.push(function(instance, args) {
|
|
248
|
+
return value.set.call(instance, args);
|
|
249
|
+
});
|
|
250
|
+
} else if (kind === 2) {
|
|
251
|
+
ret.push(value);
|
|
252
|
+
} else {
|
|
253
|
+
ret.push(function(instance, args) {
|
|
254
|
+
return value.call(instance, args);
|
|
255
|
+
});
|
|
256
|
+
}
|
|
257
|
+
} else {
|
|
258
|
+
Object.defineProperty(base, name, desc);
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
function applyMemberDecs(Class, decInfos, metadata) {
|
|
263
|
+
var ret = [];
|
|
264
|
+
var protoInitializers;
|
|
265
|
+
var staticInitializers;
|
|
266
|
+
var existingProtoNonFields = new Map();
|
|
267
|
+
var existingStaticNonFields = new Map();
|
|
268
|
+
for(var i = 0; i < decInfos.length; i++){
|
|
269
|
+
var decInfo = decInfos[i];
|
|
270
|
+
if (!Array.isArray(decInfo)) continue;
|
|
271
|
+
var kind = decInfo[1];
|
|
272
|
+
var name = decInfo[2];
|
|
273
|
+
var isPrivate = decInfo.length > 3;
|
|
274
|
+
var isStatic = kind >= 5;
|
|
275
|
+
var base;
|
|
276
|
+
var initializers;
|
|
277
|
+
if (isStatic) {
|
|
278
|
+
base = Class;
|
|
279
|
+
kind = kind - 5;
|
|
280
|
+
staticInitializers = staticInitializers || [];
|
|
281
|
+
initializers = staticInitializers;
|
|
282
|
+
} else {
|
|
283
|
+
base = Class.prototype;
|
|
284
|
+
protoInitializers = protoInitializers || [];
|
|
285
|
+
initializers = protoInitializers;
|
|
286
|
+
}
|
|
287
|
+
if (kind !== 0 && !isPrivate) {
|
|
288
|
+
var existingNonFields = isStatic ? existingStaticNonFields : existingProtoNonFields;
|
|
289
|
+
var existingKind = existingNonFields.get(name) || 0;
|
|
290
|
+
if (existingKind === true || existingKind === 3 && kind !== 4 || existingKind === 4 && kind !== 3) {
|
|
291
|
+
throw new Error("Attempted to decorate a public method/accessor that has the same name as a previously decorated public method/accessor. This is not currently supported by the decorators plugin. Property name was: " + name);
|
|
292
|
+
} else if (!existingKind && kind > 2) {
|
|
293
|
+
existingNonFields.set(name, kind);
|
|
294
|
+
} else {
|
|
295
|
+
existingNonFields.set(name, true);
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
applyMemberDec(ret, base, decInfo, name, kind, isStatic, isPrivate, initializers, metadata);
|
|
299
|
+
}
|
|
300
|
+
pushInitializers(ret, protoInitializers);
|
|
301
|
+
pushInitializers(ret, staticInitializers);
|
|
302
|
+
return ret;
|
|
303
|
+
}
|
|
304
|
+
function pushInitializers(ret, initializers) {
|
|
305
|
+
if (initializers) {
|
|
306
|
+
ret.push(function(instance) {
|
|
307
|
+
for(var i = 0; i < initializers.length; i++){
|
|
308
|
+
initializers[i].call(instance);
|
|
309
|
+
}
|
|
310
|
+
return instance;
|
|
311
|
+
});
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
function applyClassDecs(targetClass, classDecs, metadata) {
|
|
315
|
+
if (classDecs.length > 0) {
|
|
316
|
+
var initializers = [];
|
|
317
|
+
var newClass = targetClass;
|
|
318
|
+
var name = targetClass.name;
|
|
319
|
+
for(var i = classDecs.length - 1; i >= 0; i--){
|
|
320
|
+
var decoratorFinishedRef = {
|
|
321
|
+
v: false
|
|
322
|
+
};
|
|
323
|
+
try {
|
|
324
|
+
var nextNewClass = classDecs[i](newClass, {
|
|
325
|
+
kind: "class",
|
|
326
|
+
name: name,
|
|
327
|
+
addInitializer: createAddInitializerMethod(initializers, decoratorFinishedRef),
|
|
328
|
+
metadata
|
|
329
|
+
});
|
|
330
|
+
} finally{
|
|
331
|
+
decoratorFinishedRef.v = true;
|
|
332
|
+
}
|
|
333
|
+
if (nextNewClass !== undefined) {
|
|
334
|
+
assertValidReturnValue(10, nextNewClass);
|
|
335
|
+
newClass = nextNewClass;
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
return [
|
|
339
|
+
defineMetadata(newClass, metadata),
|
|
340
|
+
function() {
|
|
341
|
+
for(var i = 0; i < initializers.length; i++){
|
|
342
|
+
initializers[i].call(newClass);
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
];
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
function defineMetadata(Class, metadata) {
|
|
349
|
+
return Object.defineProperty(Class, Symbol.metadata || Symbol.for("Symbol.metadata"), {
|
|
350
|
+
configurable: true,
|
|
351
|
+
enumerable: true,
|
|
352
|
+
value: metadata
|
|
353
|
+
});
|
|
354
|
+
}
|
|
355
|
+
return function applyDecs2203R(targetClass, memberDecs, classDecs, parentClass) {
|
|
356
|
+
if (parentClass !== void 0) {
|
|
357
|
+
var parentMetadata = parentClass[Symbol.metadata || Symbol.for("Symbol.metadata")];
|
|
358
|
+
}
|
|
359
|
+
var metadata = Object.create(parentMetadata === void 0 ? null : parentMetadata);
|
|
360
|
+
var e = applyMemberDecs(targetClass, memberDecs, metadata);
|
|
361
|
+
if (!classDecs.length) defineMetadata(targetClass, metadata);
|
|
362
|
+
return {
|
|
363
|
+
e: e,
|
|
364
|
+
get c () {
|
|
365
|
+
return applyClassDecs(targetClass, classDecs, metadata);
|
|
366
|
+
}
|
|
367
|
+
};
|
|
368
|
+
};
|
|
369
|
+
}
|
|
370
|
+
function _apply_decs_2203_r(targetClass, memberDecs, classDecs, parentClass) {
|
|
371
|
+
return (_apply_decs_2203_r = applyDecs2203RFactory())(targetClass, memberDecs, classDecs, parentClass);
|
|
372
|
+
}
|
|
373
|
+
var _dec, _dec1, _dec2, _initProto;
|
|
374
|
+
import { Blob, getBlobsPerL1Block, getPrefixedEthBlobCommitments } from '@aztec/blob-lib';
|
|
375
|
+
import { FeeAssetPriceOracle, MULTI_CALL_3_ADDRESS, Multicall3, RollupContract } from '@aztec/ethereum/contracts';
|
|
376
|
+
import { L1FeeAnalyzer } from '@aztec/ethereum/l1-fee-analysis';
|
|
377
|
+
import { MAX_L1_TX_LIMIT, WEI_CONST } from '@aztec/ethereum/l1-tx-utils';
|
|
378
|
+
import { FormattedViemError, formatViemError, mergeAbis, tryExtractEvent } from '@aztec/ethereum/utils';
|
|
379
|
+
import { sumBigint } from '@aztec/foundation/bigint';
|
|
380
|
+
import { toHex as toPaddedHex } from '@aztec/foundation/bigint-buffer';
|
|
381
|
+
import { CheckpointNumber, SlotNumber } from '@aztec/foundation/branded-types';
|
|
382
|
+
import { trimmedBytesLength } from '@aztec/foundation/buffer';
|
|
383
|
+
import { pick } from '@aztec/foundation/collection';
|
|
384
|
+
import { TimeoutError } from '@aztec/foundation/error';
|
|
5
385
|
import { EthAddress } from '@aztec/foundation/eth-address';
|
|
386
|
+
import { Signature } from '@aztec/foundation/eth-signature';
|
|
6
387
|
import { createLogger } from '@aztec/foundation/log';
|
|
388
|
+
import { makeBackoff, retry } from '@aztec/foundation/retry';
|
|
389
|
+
import { bufferToHex } from '@aztec/foundation/string';
|
|
7
390
|
import { Timer } from '@aztec/foundation/timer';
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import
|
|
12
|
-
import { encodeFunctionData } from 'viem';
|
|
391
|
+
import { EmpireBaseAbi, ErrorsAbi, RollupAbi } from '@aztec/l1-artifacts';
|
|
392
|
+
import { encodeSlashConsensusVotes } from '@aztec/slasher';
|
|
393
|
+
import { CommitteeAttestationsAndSigners } from '@aztec/stdlib/block';
|
|
394
|
+
import { getTelemetryClient, trackSpan } from '@aztec/telemetry-client';
|
|
395
|
+
import { encodeFunctionData, keccak256, multicall3Abi, toHex } from 'viem';
|
|
396
|
+
import { createL1TxFailedStore } from './l1_tx_failed_store/index.js';
|
|
13
397
|
import { SequencerPublisherMetrics } from './sequencer-publisher-metrics.js';
|
|
14
|
-
export
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
398
|
+
export const Actions = [
|
|
399
|
+
'invalidate-by-invalid-attestation',
|
|
400
|
+
'invalidate-by-insufficient-attestations',
|
|
401
|
+
'propose',
|
|
402
|
+
'governance-signal',
|
|
403
|
+
'empire-slashing-signal',
|
|
404
|
+
'create-empire-payload',
|
|
405
|
+
'execute-empire-payload',
|
|
406
|
+
'vote-offenses',
|
|
407
|
+
'execute-slash'
|
|
408
|
+
];
|
|
409
|
+
// Sorting for actions such that invalidations go before proposals, and proposals go before votes
|
|
410
|
+
export const compareActions = (a, b)=>Actions.indexOf(a) - Actions.indexOf(b);
|
|
411
|
+
_dec = trackSpan('SequencerPublisher.sendRequests'), _dec1 = trackSpan('SequencerPublisher.validateBlockHeader'), _dec2 = trackSpan('SequencerPublisher.validateCheckpointForSubmission');
|
|
19
412
|
export class SequencerPublisher {
|
|
20
|
-
|
|
413
|
+
config;
|
|
414
|
+
static{
|
|
415
|
+
({ e: [_initProto] } = _apply_decs_2203_r(this, [
|
|
416
|
+
[
|
|
417
|
+
_dec,
|
|
418
|
+
2,
|
|
419
|
+
"sendRequests"
|
|
420
|
+
],
|
|
421
|
+
[
|
|
422
|
+
_dec1,
|
|
423
|
+
2,
|
|
424
|
+
"validateBlockHeader"
|
|
425
|
+
],
|
|
426
|
+
[
|
|
427
|
+
_dec2,
|
|
428
|
+
2,
|
|
429
|
+
"validateCheckpointForSubmission"
|
|
430
|
+
]
|
|
431
|
+
], []));
|
|
432
|
+
}
|
|
433
|
+
interrupted;
|
|
21
434
|
metrics;
|
|
22
435
|
epochCache;
|
|
23
|
-
|
|
24
|
-
governanceLog
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
myLastVotes = {
|
|
31
|
-
[0]: 0n,
|
|
32
|
-
[1]: 0n
|
|
33
|
-
};
|
|
34
|
-
log = createLogger('sequencer:publisher');
|
|
436
|
+
failedTxStore;
|
|
437
|
+
governanceLog;
|
|
438
|
+
slashingLog;
|
|
439
|
+
lastActions;
|
|
440
|
+
isPayloadEmptyCache;
|
|
441
|
+
payloadProposedCache;
|
|
442
|
+
log;
|
|
35
443
|
ethereumSlotDuration;
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
444
|
+
blobClient;
|
|
445
|
+
/** Address to use for simulations in fisherman mode (actual proposer's address) */ proposerAddressForSimulation;
|
|
446
|
+
/** Optional callback to obtain a replacement publisher when the current one fails to send. */ getNextPublisher;
|
|
447
|
+
/** L1 fee analyzer for fisherman mode */ l1FeeAnalyzer;
|
|
448
|
+
/** Fee asset price oracle for computing price modifiers from Uniswap V4 */ feeAssetPriceOracle;
|
|
449
|
+
// A CALL to a cold address is 2700 gas
|
|
450
|
+
static MULTICALL_OVERHEAD_GAS_GUESS = 5000n;
|
|
451
|
+
// Gas report for VotingWithSigTest shows a max gas of 100k, but we've seen it cost 700k+ in testnet
|
|
452
|
+
static VOTE_GAS_GUESS = 800_000n;
|
|
41
453
|
l1TxUtils;
|
|
42
454
|
rollupContract;
|
|
43
455
|
govProposerContract;
|
|
44
456
|
slashingProposerContract;
|
|
45
|
-
|
|
457
|
+
slashFactoryContract;
|
|
458
|
+
tracer;
|
|
459
|
+
requests;
|
|
46
460
|
constructor(config, deps){
|
|
461
|
+
this.config = config;
|
|
462
|
+
this.interrupted = (_initProto(this), false);
|
|
463
|
+
this.governanceLog = createLogger('sequencer:publisher:governance');
|
|
464
|
+
this.slashingLog = createLogger('sequencer:publisher:slashing');
|
|
465
|
+
this.lastActions = {};
|
|
466
|
+
this.isPayloadEmptyCache = new Map();
|
|
467
|
+
this.payloadProposedCache = new Set();
|
|
468
|
+
this.requests = [];
|
|
469
|
+
this.log = deps.log ?? createLogger('sequencer:publisher');
|
|
47
470
|
this.ethereumSlotDuration = BigInt(config.ethereumSlotDuration);
|
|
48
471
|
this.epochCache = deps.epochCache;
|
|
49
|
-
this.
|
|
472
|
+
this.lastActions = deps.lastActions;
|
|
473
|
+
this.blobClient = deps.blobClient;
|
|
50
474
|
const telemetry = deps.telemetry ?? getTelemetryClient();
|
|
51
|
-
this.metrics = new SequencerPublisherMetrics(telemetry, 'SequencerPublisher');
|
|
475
|
+
this.metrics = deps.metrics ?? new SequencerPublisherMetrics(telemetry, 'SequencerPublisher');
|
|
476
|
+
this.tracer = telemetry.getTracer('SequencerPublisher');
|
|
52
477
|
this.l1TxUtils = deps.l1TxUtils;
|
|
478
|
+
this.getNextPublisher = deps.getNextPublisher;
|
|
53
479
|
this.rollupContract = deps.rollupContract;
|
|
54
|
-
this.forwarderContract = deps.forwarderContract;
|
|
55
480
|
this.govProposerContract = deps.governanceProposerContract;
|
|
56
481
|
this.slashingProposerContract = deps.slashingProposerContract;
|
|
482
|
+
this.rollupContract.listenToSlasherChanged(async ()=>{
|
|
483
|
+
this.log.info('Slashing proposer changed');
|
|
484
|
+
const newSlashingProposer = await this.rollupContract.getSlashingProposer();
|
|
485
|
+
this.slashingProposerContract = newSlashingProposer;
|
|
486
|
+
});
|
|
487
|
+
this.slashFactoryContract = deps.slashFactoryContract;
|
|
488
|
+
// Initialize L1 fee analyzer for fisherman mode
|
|
489
|
+
if (config.fishermanMode) {
|
|
490
|
+
this.l1FeeAnalyzer = new L1FeeAnalyzer(this.l1TxUtils.client, deps.dateProvider, createLogger('sequencer:publisher:fee-analyzer'));
|
|
491
|
+
}
|
|
492
|
+
// Initialize fee asset price oracle
|
|
493
|
+
this.feeAssetPriceOracle = new FeeAssetPriceOracle(this.l1TxUtils.client, this.rollupContract, createLogger('sequencer:publisher:price-oracle'));
|
|
494
|
+
// Initialize failed L1 tx store (optional, for test networks)
|
|
495
|
+
this.failedTxStore = createL1TxFailedStore(config.l1TxFailedStore, this.log);
|
|
57
496
|
}
|
|
58
|
-
|
|
59
|
-
|
|
497
|
+
/**
|
|
498
|
+
* Backs up a failed L1 transaction to the configured store for debugging.
|
|
499
|
+
* Does nothing if no store is configured.
|
|
500
|
+
*/ backupFailedTx(failedTx) {
|
|
501
|
+
if (!this.failedTxStore) {
|
|
502
|
+
return;
|
|
503
|
+
}
|
|
504
|
+
const tx = {
|
|
505
|
+
...failedTx,
|
|
506
|
+
timestamp: Date.now()
|
|
507
|
+
};
|
|
508
|
+
// Fire and forget - don't block on backup
|
|
509
|
+
void this.failedTxStore.then((store)=>store?.saveFailedTx(tx)).catch((err)=>{
|
|
510
|
+
this.log.warn(`Failed to backup failed L1 tx to store`, err);
|
|
511
|
+
});
|
|
60
512
|
}
|
|
61
|
-
|
|
62
|
-
return
|
|
513
|
+
getRollupContract() {
|
|
514
|
+
return this.rollupContract;
|
|
515
|
+
}
|
|
516
|
+
/**
|
|
517
|
+
* Gets the fee asset price modifier from the oracle.
|
|
518
|
+
* Returns 0n if the oracle query fails.
|
|
519
|
+
*/ getFeeAssetPriceModifier() {
|
|
520
|
+
return this.feeAssetPriceOracle.computePriceModifier();
|
|
63
521
|
}
|
|
64
522
|
getSenderAddress() {
|
|
65
|
-
return
|
|
523
|
+
return this.l1TxUtils.getSenderAddress();
|
|
66
524
|
}
|
|
67
|
-
|
|
68
|
-
|
|
525
|
+
/**
|
|
526
|
+
* Gets the L1 fee analyzer instance (only available in fisherman mode)
|
|
527
|
+
*/ getL1FeeAnalyzer() {
|
|
528
|
+
return this.l1FeeAnalyzer;
|
|
69
529
|
}
|
|
70
|
-
|
|
71
|
-
|
|
530
|
+
/**
|
|
531
|
+
* Sets the proposer address to use for simulations in fisherman mode.
|
|
532
|
+
* @param proposerAddress - The actual proposer's address to use for balance lookups in simulations
|
|
533
|
+
*/ setProposerAddressForSimulation(proposerAddress) {
|
|
534
|
+
this.proposerAddressForSimulation = proposerAddress;
|
|
72
535
|
}
|
|
73
536
|
addRequest(request) {
|
|
74
537
|
this.requests.push(request);
|
|
@@ -77,6 +540,55 @@ export class SequencerPublisher {
|
|
|
77
540
|
return this.epochCache.getEpochAndSlotNow().slot;
|
|
78
541
|
}
|
|
79
542
|
/**
|
|
543
|
+
* Clears all pending requests without sending them.
|
|
544
|
+
*/ clearPendingRequests() {
|
|
545
|
+
const count = this.requests.length;
|
|
546
|
+
this.requests = [];
|
|
547
|
+
if (count > 0) {
|
|
548
|
+
this.log.debug(`Cleared ${count} pending request(s)`);
|
|
549
|
+
}
|
|
550
|
+
}
|
|
551
|
+
/**
|
|
552
|
+
* Analyzes L1 fees for the pending requests without sending them.
|
|
553
|
+
* This is used in fisherman mode to validate fee calculations.
|
|
554
|
+
* @param l2SlotNumber - The L2 slot number for this analysis
|
|
555
|
+
* @param onComplete - Optional callback to invoke when analysis completes (after block is mined)
|
|
556
|
+
* @returns The analysis result (incomplete until block mines), or undefined if no requests
|
|
557
|
+
*/ async analyzeL1Fees(l2SlotNumber, onComplete) {
|
|
558
|
+
if (!this.l1FeeAnalyzer) {
|
|
559
|
+
this.log.warn('L1 fee analyzer not available (not in fisherman mode)');
|
|
560
|
+
return undefined;
|
|
561
|
+
}
|
|
562
|
+
const requestsToAnalyze = [
|
|
563
|
+
...this.requests
|
|
564
|
+
];
|
|
565
|
+
if (requestsToAnalyze.length === 0) {
|
|
566
|
+
this.log.debug('No requests to analyze for L1 fees');
|
|
567
|
+
return undefined;
|
|
568
|
+
}
|
|
569
|
+
// Extract blob config from requests (if any)
|
|
570
|
+
const blobConfigs = requestsToAnalyze.filter((request)=>request.blobConfig).map((request)=>request.blobConfig);
|
|
571
|
+
const blobConfig = blobConfigs[0];
|
|
572
|
+
// Get gas configs
|
|
573
|
+
const gasConfigs = requestsToAnalyze.filter((request)=>request.gasConfig).map((request)=>request.gasConfig);
|
|
574
|
+
const gasLimits = gasConfigs.map((g)=>g?.gasLimit).filter((g)=>g !== undefined);
|
|
575
|
+
const gasLimit = gasLimits.length > 0 ? gasLimits.reduce((sum, g)=>sum + g, 0n) : 0n;
|
|
576
|
+
// Get the transaction requests
|
|
577
|
+
const l1Requests = requestsToAnalyze.map((r)=>r.request);
|
|
578
|
+
// Start the analysis
|
|
579
|
+
const analysisId = await this.l1FeeAnalyzer.startAnalysis(l2SlotNumber, gasLimit > 0n ? gasLimit : MAX_L1_TX_LIMIT, l1Requests, blobConfig, onComplete);
|
|
580
|
+
this.log.info('Started L1 fee analysis', {
|
|
581
|
+
analysisId,
|
|
582
|
+
l2SlotNumber: l2SlotNumber.toString(),
|
|
583
|
+
requestCount: requestsToAnalyze.length,
|
|
584
|
+
hasBlobConfig: !!blobConfig,
|
|
585
|
+
gasLimit: gasLimit.toString(),
|
|
586
|
+
actions: requestsToAnalyze.map((r)=>r.action)
|
|
587
|
+
});
|
|
588
|
+
// Return the analysis result (will be incomplete until block mines)
|
|
589
|
+
return this.l1FeeAnalyzer.getAnalysis(analysisId);
|
|
590
|
+
}
|
|
591
|
+
/**
|
|
80
592
|
* Sends all requests that are still valid.
|
|
81
593
|
* @returns one of:
|
|
82
594
|
* - A receipt and stats if the tx succeeded
|
|
@@ -87,12 +599,14 @@ export class SequencerPublisher {
|
|
|
87
599
|
...this.requests
|
|
88
600
|
];
|
|
89
601
|
this.requests = [];
|
|
90
|
-
if (this.interrupted) {
|
|
602
|
+
if (this.interrupted || requestsToProcess.length === 0) {
|
|
91
603
|
return undefined;
|
|
92
604
|
}
|
|
93
605
|
const currentL2Slot = this.getCurrentL2Slot();
|
|
94
|
-
this.log.debug(`
|
|
606
|
+
this.log.debug(`Sending requests on L2 slot ${currentL2Slot}`);
|
|
95
607
|
const validRequests = requestsToProcess.filter((request)=>request.lastValidL2Slot >= currentL2Slot);
|
|
608
|
+
const validActions = validRequests.map((x)=>x.action);
|
|
609
|
+
const expiredActions = requestsToProcess.filter((request)=>request.lastValidL2Slot < currentL2Slot).map((x)=>x.action);
|
|
96
610
|
if (validRequests.length !== requestsToProcess.length) {
|
|
97
611
|
this.log.warn(`Some requests were expired for slot ${currentL2Slot}`, {
|
|
98
612
|
validRequests: validRequests.map((request)=>({
|
|
@@ -109,56 +623,226 @@ export class SequencerPublisher {
|
|
|
109
623
|
this.log.debug(`No valid requests to send`);
|
|
110
624
|
return undefined;
|
|
111
625
|
}
|
|
112
|
-
// @note - we can only have one
|
|
626
|
+
// @note - we can only have one blob config per bundle
|
|
113
627
|
// find requests with gas and blob configs
|
|
114
628
|
// See https://github.com/AztecProtocol/aztec-packages/issues/11513
|
|
115
|
-
const gasConfigs = requestsToProcess.filter((request)=>request.gasConfig);
|
|
116
|
-
const blobConfigs = requestsToProcess.filter((request)=>request.blobConfig);
|
|
117
|
-
if (
|
|
118
|
-
throw new Error('Multiple
|
|
629
|
+
const gasConfigs = requestsToProcess.filter((request)=>request.gasConfig).map((request)=>request.gasConfig);
|
|
630
|
+
const blobConfigs = requestsToProcess.filter((request)=>request.blobConfig).map((request)=>request.blobConfig);
|
|
631
|
+
if (blobConfigs.length > 1) {
|
|
632
|
+
throw new Error('Multiple blob configs found');
|
|
119
633
|
}
|
|
120
|
-
const
|
|
121
|
-
|
|
634
|
+
const blobConfig = blobConfigs[0];
|
|
635
|
+
// Merge gasConfigs. Yields the sum of gasLimits, and the earliest txTimeoutAt, or undefined if no gasConfig sets them.
|
|
636
|
+
const gasLimits = gasConfigs.map((g)=>g?.gasLimit).filter((g)=>g !== undefined);
|
|
637
|
+
let gasLimit = gasLimits.length > 0 ? sumBigint(gasLimits) : undefined; // sum
|
|
638
|
+
// Cap at L1 block gas limit so the node accepts the tx ("gas limit too high" otherwise).
|
|
639
|
+
const maxGas = MAX_L1_TX_LIMIT;
|
|
640
|
+
if (gasLimit !== undefined && gasLimit > maxGas) {
|
|
641
|
+
this.log.debug('Capping bundled tx gas limit to L1 max', {
|
|
642
|
+
requested: gasLimit,
|
|
643
|
+
capped: maxGas
|
|
644
|
+
});
|
|
645
|
+
gasLimit = maxGas;
|
|
646
|
+
}
|
|
647
|
+
const txTimeoutAts = gasConfigs.map((g)=>g?.txTimeoutAt).filter((g)=>g !== undefined);
|
|
648
|
+
const txTimeoutAt = txTimeoutAts.length > 0 ? new Date(Math.min(...txTimeoutAts.map((g)=>g.getTime()))) : undefined; // earliest
|
|
649
|
+
const txConfig = {
|
|
650
|
+
gasLimit,
|
|
651
|
+
txTimeoutAt
|
|
652
|
+
};
|
|
653
|
+
// Sort the requests so that proposals always go first
|
|
654
|
+
// This ensures the committee gets precomputed correctly
|
|
655
|
+
validRequests.sort((a, b)=>compareActions(a.action, b.action));
|
|
122
656
|
try {
|
|
657
|
+
// Capture context for failed tx backup before sending
|
|
658
|
+
const l1BlockNumber = await this.l1TxUtils.getBlockNumber();
|
|
659
|
+
const multicallData = encodeFunctionData({
|
|
660
|
+
abi: multicall3Abi,
|
|
661
|
+
functionName: 'aggregate3',
|
|
662
|
+
args: [
|
|
663
|
+
validRequests.map((r)=>({
|
|
664
|
+
target: r.request.to,
|
|
665
|
+
callData: r.request.data,
|
|
666
|
+
allowFailure: true
|
|
667
|
+
}))
|
|
668
|
+
]
|
|
669
|
+
});
|
|
670
|
+
const blobDataHex = blobConfig?.blobs?.map((b)=>toHex(b));
|
|
671
|
+
const txContext = {
|
|
672
|
+
multicallData,
|
|
673
|
+
blobData: blobDataHex,
|
|
674
|
+
l1BlockNumber
|
|
675
|
+
};
|
|
123
676
|
this.log.debug('Forwarding transactions', {
|
|
124
|
-
validRequests: validRequests.map((request)=>request.action)
|
|
677
|
+
validRequests: validRequests.map((request)=>request.action),
|
|
678
|
+
txConfig
|
|
125
679
|
});
|
|
126
|
-
const result = await this.
|
|
127
|
-
|
|
128
|
-
|
|
680
|
+
const result = await this.forwardWithPublisherRotation(validRequests, txConfig, blobConfig);
|
|
681
|
+
if (result === undefined) {
|
|
682
|
+
return undefined;
|
|
683
|
+
}
|
|
684
|
+
const { successfulActions = [], failedActions = [] } = this.callbackBundledTransactions(validRequests, result, txContext);
|
|
685
|
+
return {
|
|
686
|
+
result,
|
|
687
|
+
expiredActions,
|
|
688
|
+
sentActions: validActions,
|
|
689
|
+
successfulActions,
|
|
690
|
+
failedActions
|
|
691
|
+
};
|
|
129
692
|
} catch (err) {
|
|
130
693
|
const viemError = formatViemError(err);
|
|
131
694
|
this.log.error(`Failed to publish bundled transactions`, viemError);
|
|
132
695
|
return undefined;
|
|
133
696
|
} finally{
|
|
134
697
|
try {
|
|
135
|
-
this.metrics.recordSenderBalance(await this.l1TxUtils.getSenderBalance(), this.l1TxUtils.getSenderAddress());
|
|
698
|
+
this.metrics.recordSenderBalance(await this.l1TxUtils.getSenderBalance(), this.l1TxUtils.getSenderAddress().toString());
|
|
136
699
|
} catch (err) {
|
|
137
700
|
this.log.warn(`Failed to record balance after sending tx: ${err}`);
|
|
138
701
|
}
|
|
139
702
|
}
|
|
140
703
|
}
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
704
|
+
/**
|
|
705
|
+
* Forwards transactions via Multicall3, rotating to the next available publisher if a send
|
|
706
|
+
* failure occurs (i.e. the tx never reached the chain).
|
|
707
|
+
* On-chain reverts and simulation errors are returned as-is without rotation.
|
|
708
|
+
*/ async forwardWithPublisherRotation(validRequests, txConfig, blobConfig) {
|
|
709
|
+
const triedAddresses = [];
|
|
710
|
+
let currentPublisher = this.l1TxUtils;
|
|
711
|
+
while(true){
|
|
712
|
+
triedAddresses.push(currentPublisher.getSenderAddress());
|
|
713
|
+
try {
|
|
714
|
+
const result = await Multicall3.forward(validRequests.map((r)=>r.request), currentPublisher, txConfig, blobConfig, this.rollupContract.address, this.log);
|
|
715
|
+
this.l1TxUtils = currentPublisher;
|
|
716
|
+
return result;
|
|
717
|
+
} catch (err) {
|
|
718
|
+
if (err instanceof TimeoutError) {
|
|
719
|
+
throw err;
|
|
720
|
+
}
|
|
721
|
+
const viemError = formatViemError(err);
|
|
722
|
+
if (!this.getNextPublisher) {
|
|
723
|
+
this.log.error('Failed to publish bundled transactions', viemError);
|
|
724
|
+
return undefined;
|
|
725
|
+
}
|
|
726
|
+
this.log.warn(`Publisher ${currentPublisher.getSenderAddress()} failed to send, rotating to next publisher`, viemError);
|
|
727
|
+
const nextPublisher = await this.getNextPublisher([
|
|
728
|
+
...triedAddresses
|
|
729
|
+
]);
|
|
730
|
+
if (!nextPublisher) {
|
|
731
|
+
this.log.error('All available publishers exhausted, failed to publish bundled transactions');
|
|
732
|
+
return undefined;
|
|
733
|
+
}
|
|
734
|
+
currentPublisher = nextPublisher;
|
|
735
|
+
}
|
|
736
|
+
}
|
|
737
|
+
}
|
|
738
|
+
callbackBundledTransactions(requests, result, txContext) {
|
|
739
|
+
const actionsListStr = requests.map((r)=>r.action).join(', ');
|
|
740
|
+
if (result instanceof FormattedViemError) {
|
|
741
|
+
this.log.error(`Failed to publish bundled transactions (${actionsListStr})`, result);
|
|
742
|
+
this.backupFailedTx({
|
|
743
|
+
id: keccak256(txContext.multicallData),
|
|
744
|
+
failureType: 'send-error',
|
|
745
|
+
request: {
|
|
746
|
+
to: MULTI_CALL_3_ADDRESS,
|
|
747
|
+
data: txContext.multicallData
|
|
748
|
+
},
|
|
749
|
+
blobData: txContext.blobData,
|
|
750
|
+
l1BlockNumber: txContext.l1BlockNumber.toString(),
|
|
751
|
+
error: {
|
|
752
|
+
message: result.message,
|
|
753
|
+
name: result.name
|
|
754
|
+
},
|
|
755
|
+
context: {
|
|
756
|
+
actions: requests.map((r)=>r.action),
|
|
757
|
+
requests: requests.map((r)=>({
|
|
758
|
+
action: r.action,
|
|
759
|
+
to: r.request.to,
|
|
760
|
+
data: r.request.data
|
|
761
|
+
})),
|
|
762
|
+
sender: this.getSenderAddress().toString()
|
|
763
|
+
}
|
|
764
|
+
});
|
|
765
|
+
return {
|
|
766
|
+
failedActions: requests.map((r)=>r.action)
|
|
767
|
+
};
|
|
768
|
+
} else {
|
|
769
|
+
this.log.verbose(`Published bundled transactions (${actionsListStr})`, {
|
|
770
|
+
result,
|
|
771
|
+
requests: requests.map((r)=>({
|
|
772
|
+
...r,
|
|
773
|
+
// Avoid logging large blob data
|
|
774
|
+
blobConfig: r.blobConfig ? {
|
|
775
|
+
...r.blobConfig,
|
|
776
|
+
blobs: r.blobConfig.blobs.map((b)=>({
|
|
777
|
+
size: trimmedBytesLength(b)
|
|
778
|
+
}))
|
|
779
|
+
} : undefined
|
|
780
|
+
}))
|
|
781
|
+
});
|
|
782
|
+
const successfulActions = [];
|
|
783
|
+
const failedActions = [];
|
|
784
|
+
for (const request of requests){
|
|
785
|
+
if (request.checkSuccess(request.request, result)) {
|
|
786
|
+
successfulActions.push(request.action);
|
|
787
|
+
} else {
|
|
788
|
+
failedActions.push(request.action);
|
|
789
|
+
}
|
|
790
|
+
}
|
|
791
|
+
// Single backup for the whole reverted tx
|
|
792
|
+
if (failedActions.length > 0 && result?.receipt?.status === 'reverted') {
|
|
793
|
+
this.backupFailedTx({
|
|
794
|
+
id: result.receipt.transactionHash,
|
|
795
|
+
failureType: 'revert',
|
|
796
|
+
request: {
|
|
797
|
+
to: MULTI_CALL_3_ADDRESS,
|
|
798
|
+
data: txContext.multicallData
|
|
799
|
+
},
|
|
800
|
+
blobData: txContext.blobData,
|
|
801
|
+
l1BlockNumber: result.receipt.blockNumber.toString(),
|
|
802
|
+
receipt: {
|
|
803
|
+
transactionHash: result.receipt.transactionHash,
|
|
804
|
+
blockNumber: result.receipt.blockNumber.toString(),
|
|
805
|
+
gasUsed: (result.receipt.gasUsed ?? 0n).toString(),
|
|
806
|
+
status: 'reverted'
|
|
807
|
+
},
|
|
808
|
+
error: {
|
|
809
|
+
message: result.errorMsg ?? 'Transaction reverted'
|
|
810
|
+
},
|
|
811
|
+
context: {
|
|
812
|
+
actions: failedActions,
|
|
813
|
+
requests: requests.filter((r)=>failedActions.includes(r.action)).map((r)=>({
|
|
814
|
+
action: r.action,
|
|
815
|
+
to: r.request.to,
|
|
816
|
+
data: r.request.data
|
|
817
|
+
})),
|
|
818
|
+
sender: this.getSenderAddress().toString()
|
|
819
|
+
}
|
|
820
|
+
});
|
|
821
|
+
}
|
|
822
|
+
return {
|
|
823
|
+
successfulActions,
|
|
824
|
+
failedActions
|
|
825
|
+
};
|
|
147
826
|
}
|
|
148
827
|
}
|
|
149
828
|
/**
|
|
150
829
|
* @notice Will call `canProposeAtNextEthBlock` to make sure that it is possible to propose
|
|
151
830
|
* @param tipArchive - The archive to check
|
|
152
831
|
* @returns The slot and block number if it is possible to propose, undefined otherwise
|
|
153
|
-
*/ canProposeAtNextEthBlock(tipArchive) {
|
|
832
|
+
*/ canProposeAtNextEthBlock(tipArchive, msgSender, opts = {}) {
|
|
833
|
+
// TODO: #14291 - should loop through multiple keys to check if any of them can propose
|
|
154
834
|
const ignoredErrors = [
|
|
155
835
|
'SlotAlreadyInChain',
|
|
156
836
|
'InvalidProposer',
|
|
157
837
|
'InvalidArchive'
|
|
158
838
|
];
|
|
159
|
-
return this.rollupContract.canProposeAtNextEthBlock(tipArchive
|
|
839
|
+
return this.rollupContract.canProposeAtNextEthBlock(tipArchive.toBuffer(), msgSender.toString(), Number(this.ethereumSlotDuration), {
|
|
840
|
+
forcePendingCheckpointNumber: opts.forcePendingCheckpointNumber
|
|
841
|
+
}).catch((err)=>{
|
|
160
842
|
if (err instanceof FormattedViemError && ignoredErrors.find((e)=>err.message.includes(e))) {
|
|
161
|
-
this.log.
|
|
843
|
+
this.log.warn(`Failed canProposeAtTime check with ${ignoredErrors.find((e)=>err.message.includes(e))}`, {
|
|
844
|
+
error: err.message
|
|
845
|
+
});
|
|
162
846
|
} else {
|
|
163
847
|
this.log.error(err.name, err);
|
|
164
848
|
}
|
|
@@ -166,135 +850,574 @@ export class SequencerPublisher {
|
|
|
166
850
|
});
|
|
167
851
|
}
|
|
168
852
|
/**
|
|
169
|
-
* @notice Will
|
|
170
|
-
*
|
|
171
|
-
*
|
|
172
|
-
*
|
|
173
|
-
|
|
174
|
-
* @param digest - The digest that attestations are signing over
|
|
175
|
-
*
|
|
176
|
-
*/ async validateBlockForSubmission(header, attestationData = {
|
|
177
|
-
digest: Buffer.alloc(32),
|
|
178
|
-
signatures: []
|
|
179
|
-
}) {
|
|
180
|
-
const ts = BigInt((await this.l1TxUtils.getBlock()).timestamp + this.ethereumSlotDuration);
|
|
181
|
-
const formattedSignatures = attestationData.signatures.map((attest)=>attest.toViemSignature());
|
|
853
|
+
* @notice Will simulate `validateHeader` to make sure that the block header is valid
|
|
854
|
+
* @dev This is a convenience function that can be used by the sequencer to validate a "partial" header.
|
|
855
|
+
* It will throw if the block header is invalid.
|
|
856
|
+
* @param header - The block header to validate
|
|
857
|
+
*/ async validateBlockHeader(header, opts) {
|
|
182
858
|
const flags = {
|
|
183
859
|
ignoreDA: true,
|
|
184
|
-
ignoreSignatures:
|
|
860
|
+
ignoreSignatures: true
|
|
185
861
|
};
|
|
186
862
|
const args = [
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
`0x${
|
|
863
|
+
header.toViem(),
|
|
864
|
+
CommitteeAttestationsAndSigners.empty().getPackedAttestations(),
|
|
865
|
+
[],
|
|
866
|
+
Signature.empty().toViemSignature(),
|
|
867
|
+
`0x${'0'.repeat(64)}`,
|
|
868
|
+
header.blobsHash.toString(),
|
|
192
869
|
flags
|
|
193
870
|
];
|
|
194
|
-
await this.
|
|
195
|
-
|
|
871
|
+
const ts = BigInt((await this.l1TxUtils.getBlock()).timestamp + this.ethereumSlotDuration);
|
|
872
|
+
const stateOverrides = await this.rollupContract.makePendingCheckpointNumberOverride(opts?.forcePendingCheckpointNumber);
|
|
873
|
+
let balance = 0n;
|
|
874
|
+
if (this.config.fishermanMode) {
|
|
875
|
+
// In fisherman mode, we can't know where the proposer is publishing from
|
|
876
|
+
// so we just add sufficient balance to the multicall3 address
|
|
877
|
+
balance = 10n * WEI_CONST * WEI_CONST; // 10 ETH
|
|
878
|
+
} else {
|
|
879
|
+
balance = await this.l1TxUtils.getSenderBalance();
|
|
880
|
+
}
|
|
881
|
+
stateOverrides.push({
|
|
882
|
+
address: MULTI_CALL_3_ADDRESS,
|
|
883
|
+
balance
|
|
884
|
+
});
|
|
885
|
+
await this.l1TxUtils.simulate({
|
|
886
|
+
to: this.rollupContract.address,
|
|
887
|
+
data: encodeFunctionData({
|
|
888
|
+
abi: RollupAbi,
|
|
889
|
+
functionName: 'validateHeaderWithAttestations',
|
|
890
|
+
args
|
|
891
|
+
}),
|
|
892
|
+
from: MULTI_CALL_3_ADDRESS
|
|
893
|
+
}, {
|
|
894
|
+
time: ts + 1n
|
|
895
|
+
}, stateOverrides);
|
|
896
|
+
this.log.debug(`Simulated validateHeader`);
|
|
196
897
|
}
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
898
|
+
/**
|
|
899
|
+
* Simulate making a call to invalidate a checkpoint with invalid attestations. Returns undefined if no need to invalidate.
|
|
900
|
+
* @param validationResult - The validation result indicating which checkpoint to invalidate (as returned by the archiver)
|
|
901
|
+
*/ async simulateInvalidateCheckpoint(validationResult) {
|
|
902
|
+
if (validationResult.valid) {
|
|
903
|
+
return undefined;
|
|
904
|
+
}
|
|
905
|
+
const { reason, checkpoint } = validationResult;
|
|
906
|
+
const checkpointNumber = checkpoint.checkpointNumber;
|
|
907
|
+
const logData = {
|
|
908
|
+
...checkpoint,
|
|
909
|
+
reason
|
|
910
|
+
};
|
|
911
|
+
const currentCheckpointNumber = await this.rollupContract.getCheckpointNumber();
|
|
912
|
+
if (currentCheckpointNumber < checkpointNumber) {
|
|
913
|
+
this.log.verbose(`Skipping checkpoint ${checkpointNumber} invalidation since it has already been removed from the pending chain`, {
|
|
914
|
+
currentCheckpointNumber,
|
|
915
|
+
...logData
|
|
916
|
+
});
|
|
917
|
+
return undefined;
|
|
918
|
+
}
|
|
919
|
+
const request = this.buildInvalidateCheckpointRequest(validationResult);
|
|
920
|
+
this.log.debug(`Simulating invalidate checkpoint ${checkpointNumber}`, {
|
|
921
|
+
...logData,
|
|
922
|
+
request
|
|
923
|
+
});
|
|
924
|
+
const l1BlockNumber = await this.l1TxUtils.getBlockNumber();
|
|
925
|
+
try {
|
|
926
|
+
const { gasUsed } = await this.l1TxUtils.simulate(request, undefined, undefined, mergeAbis([
|
|
927
|
+
request.abi ?? [],
|
|
928
|
+
ErrorsAbi
|
|
929
|
+
]));
|
|
930
|
+
this.log.verbose(`Simulation for invalidate checkpoint ${checkpointNumber} succeeded`, {
|
|
931
|
+
...logData,
|
|
932
|
+
request,
|
|
933
|
+
gasUsed
|
|
934
|
+
});
|
|
935
|
+
return {
|
|
936
|
+
request,
|
|
937
|
+
gasUsed,
|
|
938
|
+
checkpointNumber,
|
|
939
|
+
forcePendingCheckpointNumber: CheckpointNumber(checkpointNumber - 1),
|
|
940
|
+
reason
|
|
941
|
+
};
|
|
942
|
+
} catch (err) {
|
|
943
|
+
const viemError = formatViemError(err);
|
|
944
|
+
// If the error is due to the checkpoint not being in the pending chain, and it was indeed removed by someone else,
|
|
945
|
+
// we can safely ignore it and return undefined so we go ahead with checkpoint building.
|
|
946
|
+
if (viemError.message?.includes('Rollup__CheckpointNotInPendingChain')) {
|
|
947
|
+
this.log.verbose(`Simulation for invalidate checkpoint ${checkpointNumber} failed due to checkpoint not being in pending chain`, {
|
|
948
|
+
...logData,
|
|
949
|
+
request,
|
|
950
|
+
error: viemError.message
|
|
951
|
+
});
|
|
952
|
+
const latestPendingCheckpointNumber = await this.rollupContract.getCheckpointNumber();
|
|
953
|
+
if (latestPendingCheckpointNumber < checkpointNumber) {
|
|
954
|
+
this.log.verbose(`Checkpoint ${checkpointNumber} has already been invalidated`, {
|
|
955
|
+
...logData
|
|
956
|
+
});
|
|
957
|
+
return undefined;
|
|
958
|
+
} else {
|
|
959
|
+
this.log.error(`Simulation for invalidate checkpoint ${checkpointNumber} failed and it is still in pending chain`, viemError, logData);
|
|
960
|
+
throw new Error(`Failed to simulate invalidate checkpoint ${checkpointNumber} while it is still in pending chain`, {
|
|
961
|
+
cause: viemError
|
|
962
|
+
});
|
|
963
|
+
}
|
|
964
|
+
}
|
|
965
|
+
// Otherwise, throw. We cannot build the next checkpoint if we cannot invalidate the previous one.
|
|
966
|
+
this.log.error(`Simulation for invalidate checkpoint ${checkpointNumber} failed`, viemError, logData);
|
|
967
|
+
this.backupFailedTx({
|
|
968
|
+
id: keccak256(request.data),
|
|
969
|
+
failureType: 'simulation',
|
|
970
|
+
request: {
|
|
971
|
+
to: request.to,
|
|
972
|
+
data: request.data,
|
|
973
|
+
value: request.value?.toString()
|
|
974
|
+
},
|
|
975
|
+
l1BlockNumber: l1BlockNumber.toString(),
|
|
976
|
+
error: {
|
|
977
|
+
message: viemError.message,
|
|
978
|
+
name: viemError.name
|
|
979
|
+
},
|
|
980
|
+
context: {
|
|
981
|
+
actions: [
|
|
982
|
+
`invalidate-${reason}`
|
|
983
|
+
],
|
|
984
|
+
checkpointNumber,
|
|
985
|
+
sender: this.getSenderAddress().toString()
|
|
986
|
+
}
|
|
987
|
+
});
|
|
988
|
+
throw new Error(`Failed to simulate invalidate checkpoint ${checkpointNumber}`, {
|
|
989
|
+
cause: viemError
|
|
990
|
+
});
|
|
991
|
+
}
|
|
992
|
+
}
|
|
993
|
+
buildInvalidateCheckpointRequest(validationResult) {
|
|
994
|
+
if (validationResult.valid) {
|
|
995
|
+
throw new Error('Cannot invalidate a valid checkpoint');
|
|
996
|
+
}
|
|
997
|
+
const { checkpoint, committee, reason } = validationResult;
|
|
998
|
+
const logData = {
|
|
999
|
+
...checkpoint,
|
|
1000
|
+
reason
|
|
1001
|
+
};
|
|
1002
|
+
this.log.debug(`Building invalidate checkpoint ${checkpoint.checkpointNumber} request`, logData);
|
|
1003
|
+
const attestationsAndSigners = new CommitteeAttestationsAndSigners(validationResult.attestations).getPackedAttestations();
|
|
1004
|
+
if (reason === 'invalid-attestation') {
|
|
1005
|
+
return this.rollupContract.buildInvalidateBadAttestationRequest(checkpoint.checkpointNumber, attestationsAndSigners, committee, validationResult.invalidIndex);
|
|
1006
|
+
} else if (reason === 'insufficient-attestations') {
|
|
1007
|
+
return this.rollupContract.buildInvalidateInsufficientAttestationsRequest(checkpoint.checkpointNumber, attestationsAndSigners, committee);
|
|
1008
|
+
} else {
|
|
1009
|
+
const _ = reason;
|
|
1010
|
+
throw new Error(`Unknown reason for invalidation`);
|
|
1011
|
+
}
|
|
1012
|
+
}
|
|
1013
|
+
/** Simulates `propose` to make sure that the checkpoint is valid for submission */ async validateCheckpointForSubmission(checkpoint, attestationsAndSigners, attestationsAndSignersSignature, options) {
|
|
1014
|
+
const ts = BigInt((await this.l1TxUtils.getBlock()).timestamp + this.ethereumSlotDuration);
|
|
1015
|
+
const blobFields = checkpoint.toBlobFields();
|
|
1016
|
+
const blobs = await getBlobsPerL1Block(blobFields);
|
|
1017
|
+
const blobInput = getPrefixedEthBlobCommitments(blobs);
|
|
1018
|
+
const args = [
|
|
1019
|
+
{
|
|
1020
|
+
header: checkpoint.header.toViem(),
|
|
1021
|
+
archive: toHex(checkpoint.archive.root.toBuffer()),
|
|
1022
|
+
oracleInput: {
|
|
1023
|
+
feeAssetPriceModifier: checkpoint.feeAssetPriceModifier
|
|
1024
|
+
}
|
|
1025
|
+
},
|
|
1026
|
+
attestationsAndSigners.getPackedAttestations(),
|
|
1027
|
+
attestationsAndSigners.getSigners().map((signer)=>signer.toString()),
|
|
1028
|
+
attestationsAndSignersSignature.toViemSignature(),
|
|
1029
|
+
blobInput
|
|
1030
|
+
];
|
|
1031
|
+
await this.simulateProposeTx(args, ts, options);
|
|
1032
|
+
return ts;
|
|
200
1033
|
}
|
|
201
|
-
async
|
|
202
|
-
if (this.
|
|
1034
|
+
async enqueueCastSignalHelper(slotNumber, timestamp, signalType, payload, base, signerAddress, signer) {
|
|
1035
|
+
if (this.lastActions[signalType] && this.lastActions[signalType] === slotNumber) {
|
|
1036
|
+
this.log.debug(`Skipping duplicate vote cast signal ${signalType} for slot ${slotNumber}`);
|
|
203
1037
|
return false;
|
|
204
1038
|
}
|
|
205
1039
|
if (payload.equals(EthAddress.ZERO)) {
|
|
206
1040
|
return false;
|
|
207
1041
|
}
|
|
1042
|
+
if (signerAddress.equals(EthAddress.ZERO)) {
|
|
1043
|
+
this.log.warn(`Cannot enqueue vote cast signal ${signalType} for address zero at slot ${slotNumber}`);
|
|
1044
|
+
return false;
|
|
1045
|
+
}
|
|
208
1046
|
const round = await base.computeRound(slotNumber);
|
|
209
|
-
const
|
|
210
|
-
|
|
211
|
-
base.getRoundInfo(this.rollupContract.address, round)
|
|
212
|
-
]);
|
|
213
|
-
if (proposer.toLowerCase() !== this.getForwarderAddress().toString().toLowerCase()) {
|
|
1047
|
+
const roundInfo = await base.getRoundInfo(this.rollupContract.address, round);
|
|
1048
|
+
if (roundInfo.quorumReached) {
|
|
214
1049
|
return false;
|
|
215
1050
|
}
|
|
216
|
-
if (roundInfo.
|
|
1051
|
+
if (roundInfo.lastSignalSlot >= slotNumber) {
|
|
217
1052
|
return false;
|
|
218
1053
|
}
|
|
219
|
-
|
|
220
|
-
|
|
1054
|
+
if (await this.isPayloadEmpty(payload)) {
|
|
1055
|
+
this.log.warn(`Skipping vote cast for payload with empty code`);
|
|
1056
|
+
return false;
|
|
1057
|
+
}
|
|
1058
|
+
// Check if payload was already submitted to governance
|
|
1059
|
+
const cacheKey = payload.toString();
|
|
1060
|
+
if (!this.payloadProposedCache.has(cacheKey)) {
|
|
1061
|
+
try {
|
|
1062
|
+
const l1StartBlock = await this.rollupContract.getL1StartBlock();
|
|
1063
|
+
const proposed = await retry(()=>base.hasPayloadBeenProposed(payload.toString(), l1StartBlock), 'Check if payload was proposed', makeBackoff([
|
|
1064
|
+
0,
|
|
1065
|
+
1,
|
|
1066
|
+
2
|
|
1067
|
+
]), this.log, true);
|
|
1068
|
+
if (proposed) {
|
|
1069
|
+
this.payloadProposedCache.add(cacheKey);
|
|
1070
|
+
}
|
|
1071
|
+
} catch (err) {
|
|
1072
|
+
this.log.warn(`Failed to check if payload ${payload} was proposed after retries, skipping signal`, err);
|
|
1073
|
+
return false;
|
|
1074
|
+
}
|
|
1075
|
+
}
|
|
1076
|
+
if (this.payloadProposedCache.has(cacheKey)) {
|
|
1077
|
+
this.log.info(`Payload ${payload} was already proposed to governance, stopping signals`);
|
|
1078
|
+
return false;
|
|
1079
|
+
}
|
|
1080
|
+
const cachedLastVote = this.lastActions[signalType];
|
|
1081
|
+
this.lastActions[signalType] = slotNumber;
|
|
1082
|
+
const action = signalType;
|
|
1083
|
+
const request = await base.createSignalRequestWithSignature(payload.toString(), slotNumber, this.config.l1ChainId, signerAddress.toString(), signer);
|
|
1084
|
+
this.log.debug(`Created ${action} request with signature`, {
|
|
1085
|
+
request,
|
|
1086
|
+
round,
|
|
1087
|
+
signer: this.l1TxUtils.client.account?.address,
|
|
1088
|
+
lastValidL2Slot: slotNumber
|
|
1089
|
+
});
|
|
1090
|
+
const l1BlockNumber = await this.l1TxUtils.getBlockNumber();
|
|
1091
|
+
try {
|
|
1092
|
+
await this.l1TxUtils.simulate(request, {
|
|
1093
|
+
time: timestamp
|
|
1094
|
+
}, [], mergeAbis([
|
|
1095
|
+
request.abi ?? [],
|
|
1096
|
+
ErrorsAbi
|
|
1097
|
+
]));
|
|
1098
|
+
this.log.debug(`Simulation for ${action} at slot ${slotNumber} succeeded`, {
|
|
1099
|
+
request
|
|
1100
|
+
});
|
|
1101
|
+
} catch (err) {
|
|
1102
|
+
const viemError = formatViemError(err);
|
|
1103
|
+
this.log.error(`Failed simulation for ${action} at slot ${slotNumber} (enqueuing the action anyway)`, viemError);
|
|
1104
|
+
this.backupFailedTx({
|
|
1105
|
+
id: keccak256(request.data),
|
|
1106
|
+
failureType: 'simulation',
|
|
1107
|
+
request: {
|
|
1108
|
+
to: request.to,
|
|
1109
|
+
data: request.data,
|
|
1110
|
+
value: request.value?.toString()
|
|
1111
|
+
},
|
|
1112
|
+
l1BlockNumber: l1BlockNumber.toString(),
|
|
1113
|
+
error: {
|
|
1114
|
+
message: viemError.message,
|
|
1115
|
+
name: viemError.name
|
|
1116
|
+
},
|
|
1117
|
+
context: {
|
|
1118
|
+
actions: [
|
|
1119
|
+
action
|
|
1120
|
+
],
|
|
1121
|
+
slot: slotNumber,
|
|
1122
|
+
sender: this.getSenderAddress().toString()
|
|
1123
|
+
}
|
|
1124
|
+
});
|
|
1125
|
+
// Yes, we enqueue the request anyway, in case there was a bug with the simulation itself
|
|
1126
|
+
}
|
|
1127
|
+
// TODO(palla/slash): All votes (governance and slashing) should txTimeoutAt at the end of the slot.
|
|
221
1128
|
this.addRequest({
|
|
222
|
-
|
|
223
|
-
|
|
1129
|
+
gasConfig: {
|
|
1130
|
+
gasLimit: SequencerPublisher.VOTE_GAS_GUESS
|
|
1131
|
+
},
|
|
1132
|
+
action,
|
|
1133
|
+
request,
|
|
224
1134
|
lastValidL2Slot: slotNumber,
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
1135
|
+
checkSuccess: (_request, result)=>{
|
|
1136
|
+
const success = result && result.receipt && result.receipt.status === 'success' && tryExtractEvent(result.receipt.logs, base.address.toString(), EmpireBaseAbi, 'SignalCast');
|
|
1137
|
+
const logData = {
|
|
1138
|
+
...result,
|
|
1139
|
+
slotNumber,
|
|
1140
|
+
round,
|
|
1141
|
+
payload: payload.toString()
|
|
1142
|
+
};
|
|
1143
|
+
if (!success) {
|
|
1144
|
+
this.log.error(`Signaling in ${action} for ${payload} at slot ${slotNumber} in round ${round} failed`, logData);
|
|
1145
|
+
this.lastActions[signalType] = cachedLastVote;
|
|
1146
|
+
return false;
|
|
228
1147
|
} else {
|
|
229
|
-
this.log.info(`
|
|
1148
|
+
this.log.info(`Signaling in ${action} for ${payload} at slot ${slotNumber} in round ${round} succeeded`, logData);
|
|
1149
|
+
return true;
|
|
230
1150
|
}
|
|
231
1151
|
}
|
|
232
1152
|
});
|
|
233
1153
|
return true;
|
|
234
1154
|
}
|
|
235
|
-
async
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
};
|
|
241
|
-
} else if (voteType === 1) {
|
|
242
|
-
if (!this.getSlashPayload) {
|
|
243
|
-
return undefined;
|
|
244
|
-
}
|
|
245
|
-
const slashPayload = await this.getSlashPayload(slotNumber);
|
|
246
|
-
if (!slashPayload) {
|
|
247
|
-
return undefined;
|
|
248
|
-
}
|
|
249
|
-
return {
|
|
250
|
-
payload: slashPayload,
|
|
251
|
-
base: this.slashingProposerContract
|
|
252
|
-
};
|
|
1155
|
+
async isPayloadEmpty(payload) {
|
|
1156
|
+
const key = payload.toString();
|
|
1157
|
+
const cached = this.isPayloadEmptyCache.get(key);
|
|
1158
|
+
if (cached) {
|
|
1159
|
+
return cached;
|
|
253
1160
|
}
|
|
254
|
-
|
|
1161
|
+
const isEmpty = !await this.l1TxUtils.getCode(payload);
|
|
1162
|
+
this.isPayloadEmptyCache.set(key, isEmpty);
|
|
1163
|
+
return isEmpty;
|
|
255
1164
|
}
|
|
256
1165
|
/**
|
|
257
|
-
* Enqueues a
|
|
258
|
-
* @param slotNumber - The slot number to cast a
|
|
259
|
-
* @param timestamp - The timestamp of the slot to cast a
|
|
260
|
-
* @
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
1166
|
+
* Enqueues a governance castSignal transaction to cast a signal for a given slot number.
|
|
1167
|
+
* @param slotNumber - The slot number to cast a signal for.
|
|
1168
|
+
* @param timestamp - The timestamp of the slot to cast a signal for.
|
|
1169
|
+
* @returns True if the signal was successfully enqueued, false otherwise.
|
|
1170
|
+
*/ enqueueGovernanceCastSignal(governancePayload, slotNumber, timestamp, signerAddress, signer) {
|
|
1171
|
+
return this.enqueueCastSignalHelper(slotNumber, timestamp, 'governance-signal', governancePayload, this.govProposerContract, signerAddress, signer);
|
|
1172
|
+
}
|
|
1173
|
+
/** Enqueues all slashing actions as returned by the slasher client. */ async enqueueSlashingActions(actions, slotNumber, timestamp, signerAddress, signer) {
|
|
1174
|
+
if (actions.length === 0) {
|
|
1175
|
+
this.log.debug(`No slashing actions to enqueue for slot ${slotNumber}`);
|
|
265
1176
|
return false;
|
|
266
1177
|
}
|
|
267
|
-
const
|
|
268
|
-
|
|
1178
|
+
for (const action of actions){
|
|
1179
|
+
switch(action.type){
|
|
1180
|
+
case 'vote-empire-payload':
|
|
1181
|
+
{
|
|
1182
|
+
if (this.slashingProposerContract?.type !== 'empire') {
|
|
1183
|
+
this.log.error('Cannot vote for empire payload on non-empire slashing contract');
|
|
1184
|
+
break;
|
|
1185
|
+
}
|
|
1186
|
+
this.log.debug(`Enqueuing slashing vote for payload ${action.payload} at slot ${slotNumber}`, {
|
|
1187
|
+
signerAddress
|
|
1188
|
+
});
|
|
1189
|
+
await this.enqueueCastSignalHelper(slotNumber, timestamp, 'empire-slashing-signal', action.payload, this.slashingProposerContract, signerAddress, signer);
|
|
1190
|
+
break;
|
|
1191
|
+
}
|
|
1192
|
+
case 'create-empire-payload':
|
|
1193
|
+
{
|
|
1194
|
+
this.log.debug(`Enqueuing slashing create payload at slot ${slotNumber}`, {
|
|
1195
|
+
slotNumber,
|
|
1196
|
+
signerAddress
|
|
1197
|
+
});
|
|
1198
|
+
const request = this.slashFactoryContract.buildCreatePayloadRequest(action.data);
|
|
1199
|
+
await this.simulateAndEnqueueRequest('create-empire-payload', request, (receipt)=>!!this.slashFactoryContract.tryExtractSlashPayloadCreatedEvent(receipt.logs), slotNumber, timestamp);
|
|
1200
|
+
break;
|
|
1201
|
+
}
|
|
1202
|
+
case 'execute-empire-payload':
|
|
1203
|
+
{
|
|
1204
|
+
this.log.debug(`Enqueuing slashing execute payload at slot ${slotNumber}`, {
|
|
1205
|
+
slotNumber,
|
|
1206
|
+
signerAddress
|
|
1207
|
+
});
|
|
1208
|
+
if (this.slashingProposerContract?.type !== 'empire') {
|
|
1209
|
+
this.log.error('Cannot execute slashing payload on non-empire slashing contract');
|
|
1210
|
+
return false;
|
|
1211
|
+
}
|
|
1212
|
+
const empireSlashingProposer = this.slashingProposerContract;
|
|
1213
|
+
const request = empireSlashingProposer.buildExecuteRoundRequest(action.round);
|
|
1214
|
+
await this.simulateAndEnqueueRequest('execute-empire-payload', request, (receipt)=>!!empireSlashingProposer.tryExtractPayloadSubmittedEvent(receipt.logs), slotNumber, timestamp);
|
|
1215
|
+
break;
|
|
1216
|
+
}
|
|
1217
|
+
case 'vote-offenses':
|
|
1218
|
+
{
|
|
1219
|
+
this.log.debug(`Enqueuing slashing vote for ${action.votes.length} votes at slot ${slotNumber}`, {
|
|
1220
|
+
slotNumber,
|
|
1221
|
+
round: action.round,
|
|
1222
|
+
votesCount: action.votes.length,
|
|
1223
|
+
signerAddress
|
|
1224
|
+
});
|
|
1225
|
+
if (this.slashingProposerContract?.type !== 'tally') {
|
|
1226
|
+
this.log.error('Cannot vote for slashing offenses on non-tally slashing contract');
|
|
1227
|
+
return false;
|
|
1228
|
+
}
|
|
1229
|
+
const tallySlashingProposer = this.slashingProposerContract;
|
|
1230
|
+
const votes = bufferToHex(encodeSlashConsensusVotes(action.votes));
|
|
1231
|
+
const request = await tallySlashingProposer.buildVoteRequestFromSigner(votes, slotNumber, signer);
|
|
1232
|
+
await this.simulateAndEnqueueRequest('vote-offenses', request, (receipt)=>!!tallySlashingProposer.tryExtractVoteCastEvent(receipt.logs), slotNumber, timestamp);
|
|
1233
|
+
break;
|
|
1234
|
+
}
|
|
1235
|
+
case 'execute-slash':
|
|
1236
|
+
{
|
|
1237
|
+
this.log.debug(`Enqueuing slash execution for round ${action.round} at slot ${slotNumber}`, {
|
|
1238
|
+
slotNumber,
|
|
1239
|
+
round: action.round,
|
|
1240
|
+
signerAddress
|
|
1241
|
+
});
|
|
1242
|
+
if (this.slashingProposerContract?.type !== 'tally') {
|
|
1243
|
+
this.log.error('Cannot execute slashing offenses on non-tally slashing contract');
|
|
1244
|
+
return false;
|
|
1245
|
+
}
|
|
1246
|
+
const tallySlashingProposer = this.slashingProposerContract;
|
|
1247
|
+
const request = tallySlashingProposer.buildExecuteRoundRequest(action.round, action.committees);
|
|
1248
|
+
await this.simulateAndEnqueueRequest('execute-slash', request, (receipt)=>!!tallySlashingProposer.tryExtractRoundExecutedEvent(receipt.logs), slotNumber, timestamp);
|
|
1249
|
+
break;
|
|
1250
|
+
}
|
|
1251
|
+
default:
|
|
1252
|
+
{
|
|
1253
|
+
const _ = action;
|
|
1254
|
+
throw new Error(`Unknown slashing action type: ${action.type}`);
|
|
1255
|
+
}
|
|
1256
|
+
}
|
|
1257
|
+
}
|
|
1258
|
+
return true;
|
|
269
1259
|
}
|
|
270
|
-
/**
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
* @returns True if the tx has been enqueued, throws otherwise. See #9315
|
|
275
|
-
*/ async enqueueProposeL2Block(block, attestations, txHashes, opts = {}) {
|
|
276
|
-
const consensusPayload = new ConsensusPayload(block.header, block.archive.root, txHashes ?? []);
|
|
277
|
-
const digest = await getHashedSignaturePayload(consensusPayload, SignatureDomainSeparator.blockAttestation);
|
|
278
|
-
const blobs = await Blob.getBlobs(block.body.toBlobFields());
|
|
1260
|
+
/** Simulates and enqueues a proposal for a checkpoint on L1 */ async enqueueProposeCheckpoint(checkpoint, attestationsAndSigners, attestationsAndSignersSignature, opts = {}) {
|
|
1261
|
+
const checkpointHeader = checkpoint.header;
|
|
1262
|
+
const blobFields = checkpoint.toBlobFields();
|
|
1263
|
+
const blobs = await getBlobsPerL1Block(blobFields);
|
|
279
1264
|
const proposeTxArgs = {
|
|
280
|
-
header:
|
|
281
|
-
archive:
|
|
282
|
-
blockHash: (await block.header.hash()).toBuffer(),
|
|
283
|
-
body: block.body.toBuffer(),
|
|
1265
|
+
header: checkpointHeader,
|
|
1266
|
+
archive: checkpoint.archive.root.toBuffer(),
|
|
284
1267
|
blobs,
|
|
285
|
-
|
|
286
|
-
|
|
1268
|
+
attestationsAndSigners,
|
|
1269
|
+
attestationsAndSignersSignature,
|
|
1270
|
+
feeAssetPriceModifier: checkpoint.feeAssetPriceModifier
|
|
1271
|
+
};
|
|
1272
|
+
let ts;
|
|
1273
|
+
try {
|
|
1274
|
+
// @note This will make sure that we are passing the checks for our header ASSUMING that the data is also made available
|
|
1275
|
+
// This means that we can avoid the simulation issues in later checks.
|
|
1276
|
+
// By simulation issue, I mean the fact that the block.timestamp is equal to the last block, not the next, which
|
|
1277
|
+
// make time consistency checks break.
|
|
1278
|
+
// TODO(palla): Check whether we're validating twice, once here and once within addProposeTx, since we call simulateProposeTx in both places.
|
|
1279
|
+
ts = await this.validateCheckpointForSubmission(checkpoint, attestationsAndSigners, attestationsAndSignersSignature, opts);
|
|
1280
|
+
} catch (err) {
|
|
1281
|
+
this.log.error(`Checkpoint validation failed. ${err instanceof Error ? err.message : 'No error message'}`, err, {
|
|
1282
|
+
...checkpoint.getStats(),
|
|
1283
|
+
slotNumber: checkpoint.header.slotNumber,
|
|
1284
|
+
forcePendingCheckpointNumber: opts.forcePendingCheckpointNumber
|
|
1285
|
+
});
|
|
1286
|
+
throw err;
|
|
1287
|
+
}
|
|
1288
|
+
this.log.verbose(`Enqueuing checkpoint propose transaction`, {
|
|
1289
|
+
...checkpoint.toCheckpointInfo(),
|
|
1290
|
+
...opts
|
|
1291
|
+
});
|
|
1292
|
+
await this.addProposeTx(checkpoint, proposeTxArgs, opts, ts);
|
|
1293
|
+
}
|
|
1294
|
+
enqueueInvalidateCheckpoint(request, opts = {}) {
|
|
1295
|
+
if (!request) {
|
|
1296
|
+
return;
|
|
1297
|
+
}
|
|
1298
|
+
// We issued the simulation against the rollup contract, so we need to account for the overhead of the multicall3
|
|
1299
|
+
const gasLimit = this.l1TxUtils.bumpGasLimit(BigInt(Math.ceil(Number(request.gasUsed) * 64 / 63)));
|
|
1300
|
+
const { gasUsed, checkpointNumber } = request;
|
|
1301
|
+
const logData = {
|
|
1302
|
+
gasUsed,
|
|
1303
|
+
checkpointNumber,
|
|
1304
|
+
gasLimit,
|
|
1305
|
+
opts
|
|
1306
|
+
};
|
|
1307
|
+
this.log.verbose(`Enqueuing invalidate checkpoint request`, logData);
|
|
1308
|
+
this.addRequest({
|
|
1309
|
+
action: `invalidate-by-${request.reason}`,
|
|
1310
|
+
request: request.request,
|
|
1311
|
+
gasConfig: {
|
|
1312
|
+
gasLimit,
|
|
1313
|
+
txTimeoutAt: opts.txTimeoutAt
|
|
1314
|
+
},
|
|
1315
|
+
lastValidL2Slot: SlotNumber(this.getCurrentL2Slot() + 2),
|
|
1316
|
+
checkSuccess: (_req, result)=>{
|
|
1317
|
+
const success = result && result.receipt && result.receipt.status === 'success' && tryExtractEvent(result.receipt.logs, this.rollupContract.address, RollupAbi, 'CheckpointInvalidated');
|
|
1318
|
+
if (!success) {
|
|
1319
|
+
this.log.warn(`Invalidate checkpoint ${request.checkpointNumber} failed`, {
|
|
1320
|
+
...result,
|
|
1321
|
+
...logData
|
|
1322
|
+
});
|
|
1323
|
+
} else {
|
|
1324
|
+
this.log.info(`Invalidate checkpoint ${request.checkpointNumber} succeeded`, {
|
|
1325
|
+
...result,
|
|
1326
|
+
...logData
|
|
1327
|
+
});
|
|
1328
|
+
}
|
|
1329
|
+
return !!success;
|
|
1330
|
+
}
|
|
1331
|
+
});
|
|
1332
|
+
}
|
|
1333
|
+
async simulateAndEnqueueRequest(action, request, checkSuccess, slotNumber, timestamp) {
|
|
1334
|
+
const logData = {
|
|
1335
|
+
slotNumber,
|
|
1336
|
+
timestamp,
|
|
1337
|
+
gasLimit: undefined
|
|
1338
|
+
};
|
|
1339
|
+
if (this.lastActions[action] && this.lastActions[action] === slotNumber) {
|
|
1340
|
+
this.log.debug(`Skipping duplicate action ${action} for slot ${slotNumber}`);
|
|
1341
|
+
return false;
|
|
1342
|
+
}
|
|
1343
|
+
const cachedLastActionSlot = this.lastActions[action];
|
|
1344
|
+
this.lastActions[action] = slotNumber;
|
|
1345
|
+
this.log.debug(`Simulating ${action} for slot ${slotNumber}`, logData);
|
|
1346
|
+
const l1BlockNumber = await this.l1TxUtils.getBlockNumber();
|
|
1347
|
+
let gasUsed;
|
|
1348
|
+
const simulateAbi = mergeAbis([
|
|
1349
|
+
request.abi ?? [],
|
|
1350
|
+
ErrorsAbi
|
|
1351
|
+
]);
|
|
1352
|
+
try {
|
|
1353
|
+
({ gasUsed } = await this.l1TxUtils.simulate(request, {
|
|
1354
|
+
time: timestamp
|
|
1355
|
+
}, [], simulateAbi)); // TODO(palla/slash): Check the timestamp logic
|
|
1356
|
+
this.log.verbose(`Simulation for ${action} succeeded`, {
|
|
1357
|
+
...logData,
|
|
1358
|
+
request,
|
|
1359
|
+
gasUsed
|
|
1360
|
+
});
|
|
1361
|
+
} catch (err) {
|
|
1362
|
+
const viemError = formatViemError(err, simulateAbi);
|
|
1363
|
+
this.log.error(`Simulation for ${action} at ${slotNumber} failed`, viemError, logData);
|
|
1364
|
+
this.backupFailedTx({
|
|
1365
|
+
id: keccak256(request.data),
|
|
1366
|
+
failureType: 'simulation',
|
|
1367
|
+
request: {
|
|
1368
|
+
to: request.to,
|
|
1369
|
+
data: request.data,
|
|
1370
|
+
value: request.value?.toString()
|
|
1371
|
+
},
|
|
1372
|
+
l1BlockNumber: l1BlockNumber.toString(),
|
|
1373
|
+
error: {
|
|
1374
|
+
message: viemError.message,
|
|
1375
|
+
name: viemError.name
|
|
1376
|
+
},
|
|
1377
|
+
context: {
|
|
1378
|
+
actions: [
|
|
1379
|
+
action
|
|
1380
|
+
],
|
|
1381
|
+
slot: slotNumber,
|
|
1382
|
+
sender: this.getSenderAddress().toString()
|
|
1383
|
+
}
|
|
1384
|
+
});
|
|
1385
|
+
return false;
|
|
1386
|
+
}
|
|
1387
|
+
// We issued the simulation against the rollup contract, so we need to account for the overhead of the multicall3
|
|
1388
|
+
const gasLimit = this.l1TxUtils.bumpGasLimit(BigInt(Math.ceil(Number(gasUsed) * 64 / 63)));
|
|
1389
|
+
logData.gasLimit = gasLimit;
|
|
1390
|
+
// Store the ABI used for simulation on the request so Multicall3.forward can decode errors
|
|
1391
|
+
// when the tx is sent and a revert is diagnosed via simulation.
|
|
1392
|
+
const requestWithAbi = {
|
|
1393
|
+
...request,
|
|
1394
|
+
abi: simulateAbi
|
|
287
1395
|
};
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
1396
|
+
this.log.debug(`Enqueuing ${action}`, logData);
|
|
1397
|
+
this.addRequest({
|
|
1398
|
+
action,
|
|
1399
|
+
request: requestWithAbi,
|
|
1400
|
+
gasConfig: {
|
|
1401
|
+
gasLimit
|
|
1402
|
+
},
|
|
1403
|
+
lastValidL2Slot: slotNumber,
|
|
1404
|
+
checkSuccess: (_req, result)=>{
|
|
1405
|
+
const success = result && result.receipt && result.receipt.status === 'success' && checkSuccess(result.receipt);
|
|
1406
|
+
if (!success) {
|
|
1407
|
+
this.log.warn(`Action ${action} at ${slotNumber} failed`, {
|
|
1408
|
+
...result,
|
|
1409
|
+
...logData
|
|
1410
|
+
});
|
|
1411
|
+
this.lastActions[action] = cachedLastActionSlot;
|
|
1412
|
+
} else {
|
|
1413
|
+
this.log.info(`Action ${action} at ${slotNumber} succeeded`, {
|
|
1414
|
+
...result,
|
|
1415
|
+
...logData
|
|
1416
|
+
});
|
|
1417
|
+
}
|
|
1418
|
+
return !!success;
|
|
1419
|
+
}
|
|
295
1420
|
});
|
|
296
|
-
this.log.debug(`Submitting propose transaction`);
|
|
297
|
-
await this.addProposeTx(block, proposeTxArgs, opts, ts);
|
|
298
1421
|
return true;
|
|
299
1422
|
}
|
|
300
1423
|
/**
|
|
@@ -310,172 +1433,246 @@ export class SequencerPublisher {
|
|
|
310
1433
|
this.interrupted = false;
|
|
311
1434
|
this.l1TxUtils.restart();
|
|
312
1435
|
}
|
|
313
|
-
async prepareProposeTx(encodedData, timestamp) {
|
|
1436
|
+
async prepareProposeTx(encodedData, timestamp, options) {
|
|
314
1437
|
const kzg = Blob.getViemKzgInstance();
|
|
315
|
-
const blobInput =
|
|
1438
|
+
const blobInput = getPrefixedEthBlobCommitments(encodedData.blobs);
|
|
316
1439
|
this.log.debug('Validating blob input', {
|
|
317
1440
|
blobInput
|
|
318
1441
|
});
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
1442
|
+
// Get blob evaluation gas
|
|
1443
|
+
let blobEvaluationGas;
|
|
1444
|
+
if (this.config.fishermanMode) {
|
|
1445
|
+
// In fisherman mode, we can't estimate blob gas because estimateGas doesn't support state overrides
|
|
1446
|
+
// Use a fixed estimate.
|
|
1447
|
+
blobEvaluationGas = BigInt(encodedData.blobs.length) * 21_000n;
|
|
1448
|
+
this.log.debug(`Using fixed blob evaluation gas estimate in fisherman mode: ${blobEvaluationGas}`);
|
|
1449
|
+
} else {
|
|
1450
|
+
// Normal mode - use estimateGas with blob inputs
|
|
1451
|
+
blobEvaluationGas = await this.l1TxUtils.estimateGas(this.getSenderAddress().toString(), {
|
|
1452
|
+
to: this.rollupContract.address,
|
|
1453
|
+
data: encodeFunctionData({
|
|
1454
|
+
abi: RollupAbi,
|
|
1455
|
+
functionName: 'validateBlobs',
|
|
1456
|
+
args: [
|
|
1457
|
+
blobInput
|
|
1458
|
+
]
|
|
1459
|
+
})
|
|
1460
|
+
}, {}, {
|
|
1461
|
+
blobs: encodedData.blobs.map((b)=>b.data),
|
|
1462
|
+
kzg
|
|
1463
|
+
}).catch(async (err)=>{
|
|
1464
|
+
const viemError = formatViemError(err);
|
|
1465
|
+
this.log.error(`Failed to validate blobs`, viemError.message, {
|
|
1466
|
+
metaMessages: viemError.metaMessages
|
|
1467
|
+
});
|
|
1468
|
+
const validateBlobsData = encodeFunctionData({
|
|
1469
|
+
abi: RollupAbi,
|
|
1470
|
+
functionName: 'validateBlobs',
|
|
1471
|
+
args: [
|
|
1472
|
+
blobInput
|
|
1473
|
+
]
|
|
1474
|
+
});
|
|
1475
|
+
const l1BlockNumber = await this.l1TxUtils.getBlockNumber();
|
|
1476
|
+
this.backupFailedTx({
|
|
1477
|
+
id: keccak256(validateBlobsData),
|
|
1478
|
+
failureType: 'simulation',
|
|
1479
|
+
request: {
|
|
1480
|
+
to: this.rollupContract.address,
|
|
1481
|
+
data: validateBlobsData
|
|
1482
|
+
},
|
|
1483
|
+
blobData: encodedData.blobs.map((b)=>toHex(b.data)),
|
|
1484
|
+
l1BlockNumber: l1BlockNumber.toString(),
|
|
1485
|
+
error: {
|
|
1486
|
+
message: viemError.message,
|
|
1487
|
+
name: viemError.name
|
|
1488
|
+
},
|
|
1489
|
+
context: {
|
|
1490
|
+
actions: [
|
|
1491
|
+
'validate-blobs'
|
|
1492
|
+
],
|
|
1493
|
+
sender: this.getSenderAddress().toString()
|
|
1494
|
+
}
|
|
1495
|
+
});
|
|
1496
|
+
throw new Error('Failed to validate blobs');
|
|
335
1497
|
});
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
const attestations = encodedData.attestations ? encodedData.attestations.map((attest)=>attest.toViemSignature()) : [];
|
|
339
|
-
const txHashes = encodedData.txHashes ? encodedData.txHashes.map((txHash)=>txHash.toString()) : [];
|
|
1498
|
+
}
|
|
1499
|
+
const signers = encodedData.attestationsAndSigners.getSigners().map((signer)=>signer.toString());
|
|
340
1500
|
const args = [
|
|
341
1501
|
{
|
|
342
|
-
header:
|
|
343
|
-
archive:
|
|
1502
|
+
header: encodedData.header.toViem(),
|
|
1503
|
+
archive: toHex(encodedData.archive),
|
|
344
1504
|
oracleInput: {
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
},
|
|
348
|
-
blockHash: `0x${encodedData.blockHash.toString('hex')}`,
|
|
349
|
-
txHashes
|
|
1505
|
+
feeAssetPriceModifier: encodedData.feeAssetPriceModifier
|
|
1506
|
+
}
|
|
350
1507
|
},
|
|
351
|
-
|
|
1508
|
+
encodedData.attestationsAndSigners.getPackedAttestations(),
|
|
1509
|
+
signers,
|
|
1510
|
+
encodedData.attestationsAndSignersSignature.toViemSignature(),
|
|
352
1511
|
blobInput
|
|
353
1512
|
];
|
|
1513
|
+
const { rollupData, simulationResult } = await this.simulateProposeTx(args, timestamp, options);
|
|
1514
|
+
return {
|
|
1515
|
+
args,
|
|
1516
|
+
blobEvaluationGas,
|
|
1517
|
+
rollupData,
|
|
1518
|
+
simulationResult
|
|
1519
|
+
};
|
|
1520
|
+
}
|
|
1521
|
+
/**
|
|
1522
|
+
* Simulates the propose tx with eth_simulateV1
|
|
1523
|
+
* @param args - The propose tx args
|
|
1524
|
+
* @param timestamp - The timestamp to simulate proposal at
|
|
1525
|
+
* @returns The simulation result
|
|
1526
|
+
*/ async simulateProposeTx(args, timestamp, options) {
|
|
354
1527
|
const rollupData = encodeFunctionData({
|
|
355
1528
|
abi: RollupAbi,
|
|
356
1529
|
functionName: 'propose',
|
|
357
1530
|
args
|
|
358
1531
|
});
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
args: [
|
|
363
|
-
[
|
|
364
|
-
this.rollupContract.address
|
|
365
|
-
],
|
|
366
|
-
[
|
|
367
|
-
rollupData
|
|
368
|
-
]
|
|
369
|
-
]
|
|
370
|
-
});
|
|
371
|
-
const simulationResult = await this.l1TxUtils.simulateGasUsed({
|
|
372
|
-
to: this.getForwarderAddress().toString(),
|
|
373
|
-
data: forwarderData,
|
|
374
|
-
gas: SequencerPublisher.PROPOSE_GAS_GUESS
|
|
375
|
-
}, {
|
|
376
|
-
// @note we add 1n to the timestamp because geth implementation doesn't like simulation timestamp to be equal to the current block timestamp
|
|
377
|
-
time: timestamp + 1n,
|
|
378
|
-
// @note reth should have a 30m gas limit per block but throws errors that this tx is beyond limit
|
|
379
|
-
gasLimit: SequencerPublisher.PROPOSE_GAS_GUESS * 2n
|
|
380
|
-
}, [
|
|
1532
|
+
// override the pending checkpoint number if requested
|
|
1533
|
+
const forcePendingCheckpointNumberStateDiff = (options.forcePendingCheckpointNumber !== undefined ? await this.rollupContract.makePendingCheckpointNumberOverride(options.forcePendingCheckpointNumber) : []).flatMap((override)=>override.stateDiff ?? []);
|
|
1534
|
+
const stateOverrides = [
|
|
381
1535
|
{
|
|
382
1536
|
address: this.rollupContract.address,
|
|
383
1537
|
// @note we override checkBlob to false since blobs are not part simulate()
|
|
384
1538
|
stateDiff: [
|
|
385
1539
|
{
|
|
386
|
-
slot:
|
|
387
|
-
value:
|
|
388
|
-
}
|
|
1540
|
+
slot: toPaddedHex(RollupContract.checkBlobStorageSlot, true),
|
|
1541
|
+
value: toPaddedHex(0n, true)
|
|
1542
|
+
},
|
|
1543
|
+
...forcePendingCheckpointNumberStateDiff
|
|
389
1544
|
]
|
|
390
1545
|
}
|
|
391
|
-
]
|
|
1546
|
+
];
|
|
1547
|
+
// In fisherman mode, simulate as the proposer but with sufficient balance
|
|
1548
|
+
if (this.proposerAddressForSimulation) {
|
|
1549
|
+
stateOverrides.push({
|
|
1550
|
+
address: this.proposerAddressForSimulation.toString(),
|
|
1551
|
+
balance: 10n * WEI_CONST * WEI_CONST
|
|
1552
|
+
});
|
|
1553
|
+
}
|
|
1554
|
+
const l1BlockNumber = await this.l1TxUtils.getBlockNumber();
|
|
1555
|
+
const simulationResult = await this.l1TxUtils.simulate({
|
|
1556
|
+
to: this.rollupContract.address,
|
|
1557
|
+
data: rollupData,
|
|
1558
|
+
gas: MAX_L1_TX_LIMIT,
|
|
1559
|
+
...this.proposerAddressForSimulation && {
|
|
1560
|
+
from: this.proposerAddressForSimulation.toString()
|
|
1561
|
+
}
|
|
1562
|
+
}, {
|
|
1563
|
+
// @note we add 1n to the timestamp because geth implementation doesn't like simulation timestamp to be equal to the current block timestamp
|
|
1564
|
+
time: timestamp + 1n,
|
|
1565
|
+
// @note reth should have a 30m gas limit per block but throws errors that this tx is beyond limit so we increase here
|
|
1566
|
+
gasLimit: MAX_L1_TX_LIMIT * 2n
|
|
1567
|
+
}, stateOverrides, RollupAbi, {
|
|
392
1568
|
// @note fallback gas estimate to use if the node doesn't support simulation API
|
|
393
|
-
fallbackGasEstimate:
|
|
1569
|
+
fallbackGasEstimate: MAX_L1_TX_LIMIT
|
|
394
1570
|
}).catch((err)=>{
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
1571
|
+
// In fisherman mode, we expect ValidatorSelection__MissingProposerSignature since fisherman doesn't have proposer signature
|
|
1572
|
+
const viemError = formatViemError(err);
|
|
1573
|
+
if (this.config.fishermanMode && viemError.message?.includes('ValidatorSelection__MissingProposerSignature')) {
|
|
1574
|
+
this.log.debug(`Ignoring expected ValidatorSelection__MissingProposerSignature error in fisherman mode`);
|
|
1575
|
+
// Return a minimal simulation result with the fallback gas estimate
|
|
1576
|
+
return {
|
|
1577
|
+
gasUsed: MAX_L1_TX_LIMIT,
|
|
1578
|
+
logs: []
|
|
1579
|
+
};
|
|
1580
|
+
}
|
|
1581
|
+
this.log.error(`Failed to simulate propose tx`, viemError);
|
|
1582
|
+
this.backupFailedTx({
|
|
1583
|
+
id: keccak256(rollupData),
|
|
1584
|
+
failureType: 'simulation',
|
|
1585
|
+
request: {
|
|
1586
|
+
to: this.rollupContract.address,
|
|
1587
|
+
data: rollupData
|
|
1588
|
+
},
|
|
1589
|
+
l1BlockNumber: l1BlockNumber.toString(),
|
|
1590
|
+
error: {
|
|
1591
|
+
message: viemError.message,
|
|
1592
|
+
name: viemError.name
|
|
1593
|
+
},
|
|
1594
|
+
context: {
|
|
1595
|
+
actions: [
|
|
1596
|
+
'propose'
|
|
1597
|
+
],
|
|
1598
|
+
slot: Number(args[0].header.slotNumber),
|
|
1599
|
+
sender: this.getSenderAddress().toString()
|
|
1600
|
+
}
|
|
398
1601
|
});
|
|
399
|
-
throw
|
|
1602
|
+
throw err;
|
|
400
1603
|
});
|
|
401
1604
|
return {
|
|
402
|
-
args,
|
|
403
|
-
blobEvaluationGas,
|
|
404
1605
|
rollupData,
|
|
405
1606
|
simulationResult
|
|
406
1607
|
};
|
|
407
1608
|
}
|
|
408
|
-
async addProposeTx(
|
|
1609
|
+
async addProposeTx(checkpoint, encodedData, opts = {}, timestamp) {
|
|
1610
|
+
const slot = checkpoint.header.slotNumber;
|
|
409
1611
|
const timer = new Timer();
|
|
410
1612
|
const kzg = Blob.getViemKzgInstance();
|
|
411
|
-
const { rollupData, simulationResult, blobEvaluationGas } = await this.prepareProposeTx(encodedData, timestamp);
|
|
1613
|
+
const { rollupData, simulationResult, blobEvaluationGas } = await this.prepareProposeTx(encodedData, timestamp, opts);
|
|
412
1614
|
const startBlock = await this.l1TxUtils.getBlockNumber();
|
|
413
|
-
const
|
|
1615
|
+
const gasLimit = this.l1TxUtils.bumpGasLimit(BigInt(Math.ceil(Number(simulationResult.gasUsed) * 64 / 63)) + blobEvaluationGas + SequencerPublisher.MULTICALL_OVERHEAD_GAS_GUESS);
|
|
1616
|
+
// Send the blobs to the blob client preemptively. This helps in tests where the sequencer mistakingly thinks that the propose
|
|
1617
|
+
// tx fails but it does get mined. We make sure that the blobs are sent to the blob client regardless of the tx outcome.
|
|
1618
|
+
void Promise.resolve().then(()=>this.blobClient.sendBlobsToFilestore(encodedData.blobs).catch((_err)=>{
|
|
1619
|
+
this.log.error('Failed to send blobs to blob client');
|
|
1620
|
+
}));
|
|
414
1621
|
return this.addRequest({
|
|
415
1622
|
action: 'propose',
|
|
416
1623
|
request: {
|
|
417
1624
|
to: this.rollupContract.address,
|
|
418
1625
|
data: rollupData
|
|
419
1626
|
},
|
|
420
|
-
lastValidL2Slot:
|
|
1627
|
+
lastValidL2Slot: checkpoint.header.slotNumber,
|
|
421
1628
|
gasConfig: {
|
|
422
1629
|
...opts,
|
|
423
|
-
gasLimit
|
|
1630
|
+
gasLimit
|
|
424
1631
|
},
|
|
425
1632
|
blobConfig: {
|
|
426
1633
|
blobs: encodedData.blobs.map((b)=>b.data),
|
|
427
1634
|
kzg
|
|
428
1635
|
},
|
|
429
|
-
|
|
1636
|
+
checkSuccess: (_request, result)=>{
|
|
430
1637
|
if (!result) {
|
|
431
|
-
return;
|
|
1638
|
+
return false;
|
|
432
1639
|
}
|
|
433
1640
|
const { receipt, stats, errorMsg } = result;
|
|
434
|
-
|
|
1641
|
+
const success = receipt && receipt.status === 'success' && tryExtractEvent(receipt.logs, this.rollupContract.address, RollupAbi, 'CheckpointProposed');
|
|
1642
|
+
if (success) {
|
|
435
1643
|
const endBlock = receipt.blockNumber;
|
|
436
1644
|
const inclusionBlocks = Number(endBlock - startBlock);
|
|
1645
|
+
const { calldataGas, calldataSize, sender } = stats;
|
|
437
1646
|
const publishStats = {
|
|
438
1647
|
gasPrice: receipt.effectiveGasPrice,
|
|
439
1648
|
gasUsed: receipt.gasUsed,
|
|
440
1649
|
blobGasUsed: receipt.blobGasUsed ?? 0n,
|
|
441
1650
|
blobDataGas: receipt.blobGasPrice ?? 0n,
|
|
442
1651
|
transactionHash: receipt.transactionHash,
|
|
443
|
-
|
|
444
|
-
|
|
1652
|
+
calldataGas,
|
|
1653
|
+
calldataSize,
|
|
1654
|
+
sender,
|
|
1655
|
+
...checkpoint.getStats(),
|
|
445
1656
|
eventName: 'rollup-published-to-l1',
|
|
446
1657
|
blobCount: encodedData.blobs.length,
|
|
447
1658
|
inclusionBlocks
|
|
448
1659
|
};
|
|
449
|
-
this.log.
|
|
1660
|
+
this.log.info(`Published checkpoint ${checkpoint.number} at slot ${slot} to rollup contract`, {
|
|
450
1661
|
...stats,
|
|
451
|
-
...
|
|
1662
|
+
...checkpoint.getStats(),
|
|
1663
|
+
...pick(receipt, 'transactionHash', 'blockHash')
|
|
452
1664
|
});
|
|
453
1665
|
this.metrics.recordProcessBlockTx(timer.ms(), publishStats);
|
|
454
|
-
// Send the blobs to the blob sink
|
|
455
|
-
this.sendBlobsToBlobSink(receipt.blockHash, encodedData.blobs).catch((_err)=>{
|
|
456
|
-
this.log.error('Failed to send blobs to blob sink');
|
|
457
|
-
});
|
|
458
1666
|
return true;
|
|
459
1667
|
} else {
|
|
460
1668
|
this.metrics.recordFailedTx('process');
|
|
461
|
-
this.log.error(`
|
|
462
|
-
...
|
|
463
|
-
|
|
464
|
-
blockHash,
|
|
465
|
-
slotNumber: block.header.globalVariables.slotNumber.toBigInt()
|
|
1669
|
+
this.log.error(`Publishing checkpoint at slot ${slot} failed with ${errorMsg ?? 'no error message'}`, undefined, {
|
|
1670
|
+
...checkpoint.getStats(),
|
|
1671
|
+
...receipt
|
|
466
1672
|
});
|
|
1673
|
+
return false;
|
|
467
1674
|
}
|
|
468
1675
|
}
|
|
469
1676
|
});
|
|
470
1677
|
}
|
|
471
|
-
/**
|
|
472
|
-
* Send blobs to the blob sink
|
|
473
|
-
*
|
|
474
|
-
* If a blob sink url is configured, then we send blobs to the blob sink
|
|
475
|
-
* - for now we use the blockHash as the identifier for the blobs;
|
|
476
|
-
* In the future this will move to be the beacon block id - which takes a bit more work
|
|
477
|
-
* to calculate and will need to be mocked in e2e tests
|
|
478
|
-
*/ sendBlobsToBlobSink(blockHash, blobs) {
|
|
479
|
-
return this.blobSinkClient.sendBlobsToBlobSink(blockHash, blobs);
|
|
480
|
-
}
|
|
481
1678
|
}
|