@aztec-labs/sequencer-client 6.0.0-nightly.20260829
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 +307 -0
- package/dest/client/index.d.ts +2 -0
- package/dest/client/index.d.ts.map +1 -0
- package/dest/client/index.js +1 -0
- package/dest/client/sequencer-client.d.ts +94 -0
- package/dest/client/sequencer-client.d.ts.map +1 -0
- package/dest/client/sequencer-client.js +177 -0
- package/dest/config.d.ts +56 -0
- package/dest/config.d.ts.map +1 -0
- package/dest/config.js +251 -0
- package/dest/global_variable_builder/fee_predictor.d.ts +49 -0
- package/dest/global_variable_builder/fee_predictor.d.ts.map +1 -0
- package/dest/global_variable_builder/fee_predictor.js +127 -0
- package/dest/global_variable_builder/fee_provider.d.ts +28 -0
- package/dest/global_variable_builder/fee_provider.d.ts.map +1 -0
- package/dest/global_variable_builder/fee_provider.js +87 -0
- package/dest/global_variable_builder/global_builder.d.ts +28 -0
- package/dest/global_variable_builder/global_builder.d.ts.map +1 -0
- package/dest/global_variable_builder/global_builder.js +40 -0
- package/dest/global_variable_builder/index.d.ts +4 -0
- package/dest/global_variable_builder/index.d.ts.map +1 -0
- package/dest/global_variable_builder/index.js +3 -0
- package/dest/index.d.ts +7 -0
- package/dest/index.d.ts.map +1 -0
- package/dest/index.js +8 -0
- package/dest/publisher/config.d.ts +68 -0
- package/dest/publisher/config.d.ts.map +1 -0
- package/dest/publisher/config.js +137 -0
- package/dest/publisher/index.d.ts +5 -0
- package/dest/publisher/index.d.ts.map +1 -0
- package/dest/publisher/index.js +4 -0
- package/dest/publisher/l1_to_l2_messaging.d.ts +21 -0
- package/dest/publisher/l1_to_l2_messaging.d.ts.map +1 -0
- package/dest/publisher/l1_to_l2_messaging.js +70 -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 +101 -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 +68 -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 +36 -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 +3 -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 +50 -0
- package/dest/publisher/sequencer-publisher-factory.d.ts.map +1 -0
- package/dest/publisher/sequencer-publisher-factory.js +75 -0
- package/dest/publisher/sequencer-publisher-metrics.d.ts +26 -0
- package/dest/publisher/sequencer-publisher-metrics.d.ts.map +1 -0
- package/dest/publisher/sequencer-publisher-metrics.js +101 -0
- package/dest/publisher/sequencer-publisher.d.ts +254 -0
- package/dest/publisher/sequencer-publisher.d.ts.map +1 -0
- package/dest/publisher/sequencer-publisher.js +1784 -0
- package/dest/publisher/write_json.d.ts +11 -0
- package/dest/publisher/write_json.d.ts.map +1 -0
- package/dest/publisher/write_json.js +57 -0
- package/dest/sequencer/automine/automine_factory.d.ts +56 -0
- package/dest/sequencer/automine/automine_factory.d.ts.map +1 -0
- package/dest/sequencer/automine/automine_factory.js +85 -0
- package/dest/sequencer/automine/automine_sequencer.d.ts +189 -0
- package/dest/sequencer/automine/automine_sequencer.d.ts.map +1 -0
- package/dest/sequencer/automine/automine_sequencer.js +732 -0
- package/dest/sequencer/automine/index.d.ts +3 -0
- package/dest/sequencer/automine/index.d.ts.map +1 -0
- package/dest/sequencer/automine/index.js +2 -0
- package/dest/sequencer/checkpoint_proposal_job.d.ts +169 -0
- package/dest/sequencer/checkpoint_proposal_job.d.ts.map +1 -0
- package/dest/sequencer/checkpoint_proposal_job.js +1961 -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 +8 -0
- package/dest/sequencer/config.d.ts.map +1 -0
- package/dest/sequencer/config.js +1 -0
- 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 +103 -0
- package/dest/sequencer/events.d.ts.map +1 -0
- package/dest/sequencer/events.js +1 -0
- package/dest/sequencer/inbox_bucket_selector.d.ts +88 -0
- package/dest/sequencer/inbox_bucket_selector.d.ts.map +1 -0
- package/dest/sequencer/inbox_bucket_selector.js +80 -0
- package/dest/sequencer/index.d.ts +6 -0
- package/dest/sequencer/index.d.ts.map +1 -0
- package/dest/sequencer/index.js +5 -0
- package/dest/sequencer/metrics.d.ts +75 -0
- package/dest/sequencer/metrics.d.ts.map +1 -0
- package/dest/sequencer/metrics.js +343 -0
- package/dest/sequencer/missing_committee.d.ts +72 -0
- package/dest/sequencer/missing_committee.d.ts.map +1 -0
- package/dest/sequencer/missing_committee.js +139 -0
- package/dest/sequencer/requests_tracker.d.ts +22 -0
- package/dest/sequencer/requests_tracker.d.ts.map +1 -0
- package/dest/sequencer/requests_tracker.js +33 -0
- package/dest/sequencer/sequencer.d.ts +326 -0
- package/dest/sequencer/sequencer.d.ts.map +1 -0
- package/dest/sequencer/sequencer.js +1495 -0
- 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 +30 -0
- package/dest/sequencer/utils.d.ts.map +1 -0
- package/dest/sequencer/utils.js +18 -0
- package/dest/test/index.d.ts +23 -0
- package/dest/test/index.d.ts.map +1 -0
- package/dest/test/index.js +6 -0
- 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 +230 -0
- package/dest/test/utils.d.ts +67 -0
- package/dest/test/utils.d.ts.map +1 -0
- package/dest/test/utils.js +121 -0
- package/package.json +118 -0
- package/src/client/index.ts +1 -0
- package/src/client/sequencer-client.ts +281 -0
- package/src/config.ts +309 -0
- package/src/global_variable_builder/README.md +44 -0
- package/src/global_variable_builder/fee_predictor.ts +176 -0
- package/src/global_variable_builder/fee_provider.ts +104 -0
- package/src/global_variable_builder/global_builder.ts +68 -0
- package/src/global_variable_builder/index.ts +3 -0
- package/src/index.ts +15 -0
- package/src/publisher/config.ts +220 -0
- package/src/publisher/index.ts +8 -0
- package/src/publisher/l1_to_l2_messaging.ts +85 -0
- package/src/publisher/l1_tx_failed_store/factory.ts +32 -0
- package/src/publisher/l1_tx_failed_store/failed_tx_store.ts +166 -0
- package/src/publisher/l1_tx_failed_store/file_store_failed_tx_store.ts +47 -0
- package/src/publisher/l1_tx_failed_store/index.ts +3 -0
- package/src/publisher/sequencer-bundle-simulator.ts +253 -0
- package/src/publisher/sequencer-publisher-factory.ts +121 -0
- package/src/publisher/sequencer-publisher-metrics.ts +145 -0
- package/src/publisher/sequencer-publisher.ts +1719 -0
- package/src/publisher/write_json.ts +77 -0
- package/src/sequencer/README.md +243 -0
- package/src/sequencer/automine/README.md +60 -0
- package/src/sequencer/automine/automine_factory.ts +156 -0
- package/src/sequencer/automine/automine_sequencer.ts +841 -0
- package/src/sequencer/automine/index.ts +6 -0
- package/src/sequencer/checkpoint_proposal_job.ts +1889 -0
- package/src/sequencer/checkpoint_proposal_job_metrics.ts +128 -0
- package/src/sequencer/checkpoint_voter.ts +118 -0
- package/src/sequencer/config.ts +9 -0
- package/src/sequencer/errors.ts +21 -0
- package/src/sequencer/events.ts +93 -0
- package/src/sequencer/inbox_bucket_selector.ts +160 -0
- package/src/sequencer/index.ts +5 -0
- package/src/sequencer/metrics.ts +463 -0
- package/src/sequencer/missing_committee.ts +192 -0
- package/src/sequencer/requests_tracker.ts +43 -0
- package/src/sequencer/sequencer.ts +1401 -0
- package/src/sequencer/types.ts +6 -0
- package/src/sequencer/utils.ts +42 -0
- package/src/test/index.ts +26 -0
- package/src/test/mock_checkpoint_builder.ts +324 -0
- package/src/test/utils.ts +215 -0
|
@@ -0,0 +1,1784 @@
|
|
|
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, _initProto;
|
|
374
|
+
import { EmpireBaseAbi, ErrorsAbi, RollupAbi, SlashingProposerAbi } from '@aztec/l1-artifacts';
|
|
375
|
+
import { Blob, getBlobsPerL1Block, getPrefixedEthBlobCommitments } from '@aztec-labs/blob-lib';
|
|
376
|
+
import { FeeAssetPriceOracle, MULTI_CALL_3_ADDRESS, Multicall3, MulticallForwarderRevertedError, buildSimulationOverridesStateOverride } from '@aztec-labs/ethereum/contracts';
|
|
377
|
+
import { L1FeeAnalyzer, captureWindowBlockFees } from '@aztec-labs/ethereum/l1-fee-analysis';
|
|
378
|
+
import { L1TxTimeoutError, MAX_L1_TX_LIMIT, WEI_CONST } from '@aztec-labs/ethereum/l1-tx-utils';
|
|
379
|
+
import { FormattedViemError, formatViemError, mergeAbis, tryDecodeRevertReason, tryExtractEvent } from '@aztec-labs/ethereum/utils';
|
|
380
|
+
import { CheckpointNumber, SlotNumber } from '@aztec-labs/foundation/branded-types';
|
|
381
|
+
import { trimmedBytesLength } from '@aztec-labs/foundation/buffer';
|
|
382
|
+
import { pick } from '@aztec-labs/foundation/collection';
|
|
383
|
+
import { TimeoutError } from '@aztec-labs/foundation/error';
|
|
384
|
+
import { EthAddress } from '@aztec-labs/foundation/eth-address';
|
|
385
|
+
import { Signature } from '@aztec-labs/foundation/eth-signature';
|
|
386
|
+
import { createLogger } from '@aztec-labs/foundation/log';
|
|
387
|
+
import { InterruptibleSleep } from '@aztec-labs/foundation/sleep';
|
|
388
|
+
import { bufferToHex } from '@aztec-labs/foundation/string';
|
|
389
|
+
import { Timer } from '@aztec-labs/foundation/timer';
|
|
390
|
+
import { encodeSlashConsensusVotes } from '@aztec-labs/slasher';
|
|
391
|
+
import { CommitteeAttestationsAndSigners } from '@aztec-labs/stdlib/block';
|
|
392
|
+
import { getLastL1SlotTimestampForL2Slot, getNextL1SlotTimestamp, getTimestampForSlot } from '@aztec-labs/stdlib/epoch-helpers';
|
|
393
|
+
import { getTelemetryClient, trackSpan } from '@aztec-labs/telemetry-client';
|
|
394
|
+
import { encodeFunctionData, keccak256, toHex } from 'viem';
|
|
395
|
+
import { createL1TxFailedStore } from './l1_tx_failed_store/index.js';
|
|
396
|
+
import { SequencerBundleSimulator } from './sequencer-bundle-simulator.js';
|
|
397
|
+
import { SequencerPublisherMetrics } from './sequencer-publisher-metrics.js';
|
|
398
|
+
/**
|
|
399
|
+
* Returns true if the receipt indicates a successful send AND the expected event was emitted
|
|
400
|
+
* by the target contract. Both pieces are required: an aggregate3 entry that reverted will
|
|
401
|
+
* have receipt.status === 'success' but no event log.
|
|
402
|
+
*/ function extractEventSuccess(receipt, opts) {
|
|
403
|
+
if (!receipt || receipt.status !== 'success') {
|
|
404
|
+
return false;
|
|
405
|
+
}
|
|
406
|
+
return !!tryExtractEvent(receipt.logs, opts.address.toString(), opts.abi, opts.eventName);
|
|
407
|
+
}
|
|
408
|
+
export const Actions = [
|
|
409
|
+
'invalidate-by-invalid-attestation',
|
|
410
|
+
'invalidate-by-insufficient-attestations',
|
|
411
|
+
'prune',
|
|
412
|
+
'propose',
|
|
413
|
+
'governance-signal',
|
|
414
|
+
'vote-offenses',
|
|
415
|
+
'execute-slash'
|
|
416
|
+
];
|
|
417
|
+
// Sorting for actions such that invalidations go before proposals, and proposals go before votes
|
|
418
|
+
export const compareActions = (a, b)=>Actions.indexOf(a) - Actions.indexOf(b);
|
|
419
|
+
_dec = trackSpan('SequencerPublisher.sendRequests'), _dec1 = trackSpan('SequencerPublisher.validateCheckpointHeader');
|
|
420
|
+
export class SequencerPublisher {
|
|
421
|
+
config;
|
|
422
|
+
static{
|
|
423
|
+
({ e: [_initProto] } = _apply_decs_2203_r(this, [
|
|
424
|
+
[
|
|
425
|
+
_dec,
|
|
426
|
+
2,
|
|
427
|
+
"sendRequests"
|
|
428
|
+
],
|
|
429
|
+
[
|
|
430
|
+
_dec1,
|
|
431
|
+
2,
|
|
432
|
+
"validateCheckpointHeader"
|
|
433
|
+
]
|
|
434
|
+
], []));
|
|
435
|
+
}
|
|
436
|
+
interrupted;
|
|
437
|
+
metrics;
|
|
438
|
+
bundleSimulator;
|
|
439
|
+
epochCache;
|
|
440
|
+
failedTxStore;
|
|
441
|
+
/**
|
|
442
|
+
* ABI used to decode raw revert payloads from dropped bundle entries when the original
|
|
443
|
+
* request did not carry an abi (e.g. the propose request). Merges every contract the
|
|
444
|
+
* publisher can route to so any of their custom errors decode against it.
|
|
445
|
+
*/ revertDecoderAbi;
|
|
446
|
+
lastActions;
|
|
447
|
+
log;
|
|
448
|
+
ethereumSlotDuration;
|
|
449
|
+
aztecSlotDuration;
|
|
450
|
+
previousL1BlockWaitTimeoutMs;
|
|
451
|
+
previousL1BlockWaitPollIntervalMs;
|
|
452
|
+
/** Date provider for wall-clock time. */ dateProvider;
|
|
453
|
+
blobClient;
|
|
454
|
+
/** Optional callback to obtain a replacement publisher when the current one fails to send. */ getNextPublisher;
|
|
455
|
+
/** L1 fee analyzer for fisherman mode */ l1FeeAnalyzer;
|
|
456
|
+
/** Fee asset price oracle for computing price modifiers from Uniswap V4 */ feeAssetPriceOracle;
|
|
457
|
+
/** Interruptible sleep used by sendRequestsAt to wait until a target timestamp. */ interruptibleSleep;
|
|
458
|
+
l1TxUtils;
|
|
459
|
+
rollupContract;
|
|
460
|
+
govProposerContract;
|
|
461
|
+
slashingProposerContract;
|
|
462
|
+
tracer;
|
|
463
|
+
requests;
|
|
464
|
+
constructor(config, deps){
|
|
465
|
+
this.config = config;
|
|
466
|
+
this.interrupted = (_initProto(this), false);
|
|
467
|
+
this.revertDecoderAbi = mergeAbis([
|
|
468
|
+
RollupAbi,
|
|
469
|
+
SlashingProposerAbi,
|
|
470
|
+
EmpireBaseAbi,
|
|
471
|
+
ErrorsAbi
|
|
472
|
+
]);
|
|
473
|
+
this.lastActions = {};
|
|
474
|
+
this.interruptibleSleep = new InterruptibleSleep();
|
|
475
|
+
this.requests = [];
|
|
476
|
+
this.log = deps.log ?? createLogger('sequencer:publisher');
|
|
477
|
+
this.ethereumSlotDuration = BigInt(config.ethereumSlotDuration);
|
|
478
|
+
this.aztecSlotDuration = BigInt(config.aztecSlotDuration);
|
|
479
|
+
this.previousL1BlockWaitTimeoutMs = config.sequencerPublisherPreviousL1BlockWaitTimeoutMs;
|
|
480
|
+
this.previousL1BlockWaitPollIntervalMs = config.sequencerPublisherPreviousL1BlockWaitPollIntervalMs;
|
|
481
|
+
this.dateProvider = deps.dateProvider;
|
|
482
|
+
this.epochCache = deps.epochCache;
|
|
483
|
+
this.lastActions = deps.lastActions;
|
|
484
|
+
this.blobClient = deps.blobClient;
|
|
485
|
+
this.dateProvider = deps.dateProvider;
|
|
486
|
+
const telemetry = deps.telemetry ?? getTelemetryClient();
|
|
487
|
+
this.metrics = deps.metrics ?? new SequencerPublisherMetrics(telemetry, 'SequencerPublisher');
|
|
488
|
+
this.tracer = telemetry.getTracer('SequencerPublisher');
|
|
489
|
+
this.l1TxUtils = deps.l1TxUtils;
|
|
490
|
+
this.getNextPublisher = deps.getNextPublisher;
|
|
491
|
+
this.rollupContract = deps.rollupContract;
|
|
492
|
+
this.govProposerContract = deps.governanceProposerContract;
|
|
493
|
+
this.slashingProposerContract = deps.slashingProposerContract;
|
|
494
|
+
this.rollupContract.listenToSlasherChanged(async ()=>{
|
|
495
|
+
this.log.info('Slashing proposer changed');
|
|
496
|
+
const newSlashingProposer = await this.rollupContract.getSlashingProposer();
|
|
497
|
+
this.slashingProposerContract = newSlashingProposer;
|
|
498
|
+
});
|
|
499
|
+
// Initialize L1 fee analyzer for fisherman mode
|
|
500
|
+
if (config.fishermanMode) {
|
|
501
|
+
this.l1FeeAnalyzer = new L1FeeAnalyzer(this.l1TxUtils.client, deps.dateProvider, this.log.createChild('fee-analyzer'));
|
|
502
|
+
}
|
|
503
|
+
// Initialize fee asset price oracle
|
|
504
|
+
this.feeAssetPriceOracle = new FeeAssetPriceOracle(this.l1TxUtils.client, this.rollupContract, this.log.createChild('price-oracle'));
|
|
505
|
+
// Initialize failed L1 tx store (optional, for test networks)
|
|
506
|
+
this.failedTxStore = createL1TxFailedStore(config.l1TxFailedStore, this.log);
|
|
507
|
+
this.bundleSimulator = new SequencerBundleSimulator({
|
|
508
|
+
getL1TxUtils: ()=>this.l1TxUtils,
|
|
509
|
+
rollupContract: this.rollupContract,
|
|
510
|
+
epochCache: this.epochCache,
|
|
511
|
+
log: this.log.createChild('bundle-simulator')
|
|
512
|
+
});
|
|
513
|
+
}
|
|
514
|
+
/**
|
|
515
|
+
* Logs the gas-pricing data of a failed L1 transaction at warn — so underpricing is diagnosable
|
|
516
|
+
* from logs even with no failed-tx store configured — and backs the record up to the store when
|
|
517
|
+
* one is. When captureFeeSummary is true, also records the fee data of the already-mined L1
|
|
518
|
+
* blocks in the target slot's inclusion window.
|
|
519
|
+
*/ backupFailedTx(failedTx, opts) {
|
|
520
|
+
const tx = {
|
|
521
|
+
...failedTx,
|
|
522
|
+
timestamp: Date.now()
|
|
523
|
+
};
|
|
524
|
+
// Fire and forget - don't block on backup
|
|
525
|
+
void (async ()=>{
|
|
526
|
+
try {
|
|
527
|
+
// Prefer a pre-captured summary (shared across a batch of failures in the same slot) so we
|
|
528
|
+
// don't re-read the fee window per record. A capture error must not lose the record itself.
|
|
529
|
+
const feeSummary = opts?.sharedFeeSummary ?? (opts?.captureFeeSummary ? await this.captureFeeEnvironment(opts.targetSlot).catch(()=>undefined) : undefined);
|
|
530
|
+
if (feeSummary) {
|
|
531
|
+
tx.gasInfo = {
|
|
532
|
+
...tx.gasInfo,
|
|
533
|
+
...feeSummary
|
|
534
|
+
};
|
|
535
|
+
}
|
|
536
|
+
if (tx.gasInfo) {
|
|
537
|
+
this.log.warn(`Gas pricing data for failed L1 tx (${tx.failureType})`, {
|
|
538
|
+
failureType: tx.failureType,
|
|
539
|
+
actions: tx.context.actions,
|
|
540
|
+
slot: tx.context.slot,
|
|
541
|
+
...tx.gasInfo,
|
|
542
|
+
...tx.timing
|
|
543
|
+
});
|
|
544
|
+
}
|
|
545
|
+
const store = await this.failedTxStore;
|
|
546
|
+
if (store) {
|
|
547
|
+
await store.saveFailedTx(tx);
|
|
548
|
+
}
|
|
549
|
+
} catch (err) {
|
|
550
|
+
this.log.warn(`Failed to backup failed L1 tx to store`, err);
|
|
551
|
+
}
|
|
552
|
+
})();
|
|
553
|
+
}
|
|
554
|
+
/**
|
|
555
|
+
* Captures per-block fee data for the L1 blocks in the target slot's inclusion window (the blocks the
|
|
556
|
+
* tx could have landed in) for underpricing diagnostics. Reads only already-mined blocks, so it never
|
|
557
|
+
* waits on the chain. Safe to call off the critical path: the underlying capture never throws, and this
|
|
558
|
+
* returns undefined when there is no target slot or the window is not yet mined (e.g. an early send
|
|
559
|
+
* failure), in which case the record simply carries no window data.
|
|
560
|
+
*/ async captureFeeEnvironment(targetL2Slot) {
|
|
561
|
+
if (targetL2Slot === undefined) {
|
|
562
|
+
return undefined;
|
|
563
|
+
}
|
|
564
|
+
const l1Constants = this.epochCache.getL1Constants();
|
|
565
|
+
// The inclusion window is [start of slot N, start of slot N+1): all L1 blocks that can include a tx
|
|
566
|
+
// for this L2 slot. getTimestampForSlot returns seconds, matching block.timestamp.
|
|
567
|
+
const windowStartS = getTimestampForSlot(targetL2Slot, l1Constants);
|
|
568
|
+
const windowEndS = getTimestampForSlot(SlotNumber(Number(targetL2Slot) + 1), l1Constants);
|
|
569
|
+
const windowBlocks = await captureWindowBlockFees(this.l1TxUtils.client, windowStartS, windowEndS);
|
|
570
|
+
if (windowBlocks.length === 0) {
|
|
571
|
+
return undefined;
|
|
572
|
+
}
|
|
573
|
+
return {
|
|
574
|
+
windowBlocks
|
|
575
|
+
};
|
|
576
|
+
}
|
|
577
|
+
/** Computes timing info relative to the L2 slot deadline. */ computeTimingInfo(targetL2Slot) {
|
|
578
|
+
if (targetL2Slot === undefined) {
|
|
579
|
+
return undefined;
|
|
580
|
+
}
|
|
581
|
+
const l1Constants = this.epochCache.getL1Constants();
|
|
582
|
+
const slotDeadlineS = getTimestampForSlot(SlotNumber(Number(targetL2Slot) + 1), l1Constants);
|
|
583
|
+
const slotDeadlineMs = Number(slotDeadlineS) * 1000;
|
|
584
|
+
return {
|
|
585
|
+
targetL2Slot: Number(targetL2Slot),
|
|
586
|
+
slotDeadlineTimestampS: slotDeadlineS,
|
|
587
|
+
msUntilSlotDeadline: slotDeadlineMs - this.dateProvider.now()
|
|
588
|
+
};
|
|
589
|
+
}
|
|
590
|
+
/**
|
|
591
|
+
* Builds an id for a synthetic failure record (send-error/timeout) that has no on-chain tx hash.
|
|
592
|
+
* Includes the failure time so each attempt — including retries of the same slot — is stored as its
|
|
593
|
+
* own record rather than overwriting the previous one.
|
|
594
|
+
*/ failureRecordId(actions, targetSlot) {
|
|
595
|
+
return keccak256(toHex(`${actions.join(',')}:${targetSlot ?? ''}:${Date.now()}`));
|
|
596
|
+
}
|
|
597
|
+
getRollupContract() {
|
|
598
|
+
return this.rollupContract;
|
|
599
|
+
}
|
|
600
|
+
/**
|
|
601
|
+
* Gets the fee asset price modifier from the oracle.
|
|
602
|
+
*
|
|
603
|
+
* @param predictedParentEthPerFeeAssetE12 - Optional predicted parent eth-per-fee-asset (E12).
|
|
604
|
+
* Pipelined proposers should pass the value from the predicted parent fee header so the
|
|
605
|
+
* modifier matches the parent L1 will use when applying it.
|
|
606
|
+
* @returns The fee asset price modifier in basis points, or 0n if the oracle query fails.
|
|
607
|
+
*/ getFeeAssetPriceModifier(predictedParentEthPerFeeAssetE12) {
|
|
608
|
+
return this.feeAssetPriceOracle.computePriceModifier(predictedParentEthPerFeeAssetE12);
|
|
609
|
+
}
|
|
610
|
+
getSenderAddress() {
|
|
611
|
+
return this.l1TxUtils.getSenderAddress();
|
|
612
|
+
}
|
|
613
|
+
/**
|
|
614
|
+
* Gets the L1 fee analyzer instance (only available in fisherman mode)
|
|
615
|
+
*/ getL1FeeAnalyzer() {
|
|
616
|
+
return this.l1FeeAnalyzer;
|
|
617
|
+
}
|
|
618
|
+
addRequest(request) {
|
|
619
|
+
this.requests.push(request);
|
|
620
|
+
}
|
|
621
|
+
getCurrentL2Slot() {
|
|
622
|
+
return this.epochCache.getSlotNow();
|
|
623
|
+
}
|
|
624
|
+
/**
|
|
625
|
+
* Clears all pending requests without sending them.
|
|
626
|
+
*/ clearPendingRequests() {
|
|
627
|
+
const count = this.requests.length;
|
|
628
|
+
this.requests = [];
|
|
629
|
+
if (count > 0) {
|
|
630
|
+
this.log.debug(`Cleared ${count} pending request(s)`);
|
|
631
|
+
}
|
|
632
|
+
}
|
|
633
|
+
/**
|
|
634
|
+
* Analyzes L1 fees for the pending requests without sending them.
|
|
635
|
+
* This is used in fisherman mode to validate fee calculations.
|
|
636
|
+
* @param l2SlotNumber - The L2 slot number for this analysis
|
|
637
|
+
* @param onComplete - Optional callback to invoke when analysis completes (after block is mined)
|
|
638
|
+
* @returns The analysis result (incomplete until block mines), or undefined if no requests
|
|
639
|
+
*/ async analyzeL1Fees(l2SlotNumber, onComplete) {
|
|
640
|
+
if (!this.l1FeeAnalyzer) {
|
|
641
|
+
this.log.warn('L1 fee analyzer not available (not in fisherman mode)');
|
|
642
|
+
return undefined;
|
|
643
|
+
}
|
|
644
|
+
const requestsToAnalyze = [
|
|
645
|
+
...this.requests
|
|
646
|
+
];
|
|
647
|
+
if (requestsToAnalyze.length === 0) {
|
|
648
|
+
this.log.debug('No requests to analyze for L1 fees');
|
|
649
|
+
return undefined;
|
|
650
|
+
}
|
|
651
|
+
// Extract blob config from requests (if any)
|
|
652
|
+
const blobConfigs = requestsToAnalyze.filter((request)=>request.blobConfig).map((request)=>request.blobConfig);
|
|
653
|
+
const blobConfig = blobConfigs[0];
|
|
654
|
+
// Get gas configs
|
|
655
|
+
const gasConfigs = requestsToAnalyze.filter((request)=>request.gasConfig).map((request)=>request.gasConfig);
|
|
656
|
+
const gasLimits = gasConfigs.map((g)=>g?.gasLimit).filter((g)=>g !== undefined);
|
|
657
|
+
const gasLimit = gasLimits.length > 0 ? gasLimits.reduce((sum, g)=>sum + g, 0n) : 0n;
|
|
658
|
+
// Get the transaction requests
|
|
659
|
+
const l1Requests = requestsToAnalyze.map((r)=>r.request);
|
|
660
|
+
// Start the analysis
|
|
661
|
+
const analysisId = await this.l1FeeAnalyzer.startAnalysis(l2SlotNumber, gasLimit > 0n ? gasLimit : MAX_L1_TX_LIMIT, l1Requests, blobConfig, onComplete);
|
|
662
|
+
this.log.info('Started L1 fee analysis', {
|
|
663
|
+
analysisId,
|
|
664
|
+
l2SlotNumber: l2SlotNumber.toString(),
|
|
665
|
+
requestCount: requestsToAnalyze.length,
|
|
666
|
+
hasBlobConfig: !!blobConfig,
|
|
667
|
+
gasLimit: gasLimit.toString(),
|
|
668
|
+
actions: requestsToAnalyze.map((r)=>r.action)
|
|
669
|
+
});
|
|
670
|
+
// Return the analysis result (will be incomplete until block mines)
|
|
671
|
+
return this.l1FeeAnalyzer.getAnalysis(analysisId);
|
|
672
|
+
}
|
|
673
|
+
/**
|
|
674
|
+
* Sends all requests that are still valid.
|
|
675
|
+
* @param targetSlot - The target L2 slot for this send. When provided (the production path, via
|
|
676
|
+
* sendRequestsAt), it is threaded into bundleSimulate so the block.timestamp override matches
|
|
677
|
+
* the slot the propose is built for. When omitted, falls back to getCurrentL2Slot() for the
|
|
678
|
+
* AutomineSequencer, which publishes synchronously within the current slot.
|
|
679
|
+
* @returns one of:
|
|
680
|
+
* - A receipt and stats if the tx succeeded
|
|
681
|
+
* - a receipt and errorMsg if it failed on L1
|
|
682
|
+
* - undefined if no valid requests are found OR the tx failed to send.
|
|
683
|
+
*/ async sendRequests(targetSlot) {
|
|
684
|
+
const requestsToProcess = [
|
|
685
|
+
...this.requests
|
|
686
|
+
];
|
|
687
|
+
this.requests = [];
|
|
688
|
+
if (this.interrupted || requestsToProcess.length === 0) {
|
|
689
|
+
return undefined;
|
|
690
|
+
}
|
|
691
|
+
const currentL2Slot = targetSlot ?? this.getCurrentL2Slot();
|
|
692
|
+
this.log.debug(`Sending requests on L2 slot ${currentL2Slot}`);
|
|
693
|
+
const validRequests = requestsToProcess.filter((request)=>request.lastValidL2Slot >= currentL2Slot);
|
|
694
|
+
const expiredActions = requestsToProcess.filter((request)=>request.lastValidL2Slot < currentL2Slot).map((x)=>x.action);
|
|
695
|
+
if (validRequests.length !== requestsToProcess.length) {
|
|
696
|
+
this.log.warn(`Some requests were expired for slot ${currentL2Slot}`, {
|
|
697
|
+
validRequests: validRequests.map((request)=>({
|
|
698
|
+
action: request.action,
|
|
699
|
+
lastValidL2Slot: request.lastValidL2Slot
|
|
700
|
+
})),
|
|
701
|
+
requests: requestsToProcess.map((request)=>({
|
|
702
|
+
action: request.action,
|
|
703
|
+
lastValidL2Slot: request.lastValidL2Slot
|
|
704
|
+
}))
|
|
705
|
+
});
|
|
706
|
+
}
|
|
707
|
+
if (validRequests.length === 0) {
|
|
708
|
+
this.log.debug(`No valid requests to send`);
|
|
709
|
+
return undefined;
|
|
710
|
+
}
|
|
711
|
+
// Collect earliest txTimeoutAt across all requests.
|
|
712
|
+
const gasConfigs = validRequests.filter((request)=>request.gasConfig).map((request)=>request.gasConfig);
|
|
713
|
+
const txTimeoutAts = gasConfigs.map((g)=>g?.txTimeoutAt).filter((g)=>g !== undefined);
|
|
714
|
+
const txTimeoutAt = txTimeoutAts.length > 0 ? new Date(Math.min(...txTimeoutAts.map((g)=>g.getTime()))) : undefined;
|
|
715
|
+
// Sort the requests so that proposals always go first
|
|
716
|
+
// This ensures the committee gets precomputed correctly
|
|
717
|
+
validRequests.sort((a, b)=>compareActions(a.action, b.action));
|
|
718
|
+
try {
|
|
719
|
+
// Bundle-level eth_simulateV1: filters out entries that revert and derives the gasLimit.
|
|
720
|
+
const bundleResult = await this.bundleSimulator.simulate(validRequests, currentL2Slot);
|
|
721
|
+
if (bundleResult.kind === 'aborted') {
|
|
722
|
+
this.logDroppedInSim(bundleResult.droppedRequests);
|
|
723
|
+
void this.backupDroppedInSim(bundleResult.droppedRequests, currentL2Slot).catch((err)=>this.log.error(`Failed to backup requests dropped in simulation`, err));
|
|
724
|
+
return undefined;
|
|
725
|
+
}
|
|
726
|
+
const { requests, droppedRequests, gasLimit } = bundleResult.kind === 'fallback' ? {
|
|
727
|
+
requests: bundleResult.requests,
|
|
728
|
+
droppedRequests: bundleResult.droppedRequests,
|
|
729
|
+
gasLimit: MAX_L1_TX_LIMIT
|
|
730
|
+
} : bundleResult;
|
|
731
|
+
this.logDroppedInSim(droppedRequests);
|
|
732
|
+
// Compute blobConfig from survivors (not original validRequests) so that if the propose
|
|
733
|
+
// entry was dropped by bundleSimulate we don't attach a blob-typed config to a non-blob tx.
|
|
734
|
+
const [blobConfig] = requests.filter((r)=>r.blobConfig).map((r)=>r.blobConfig);
|
|
735
|
+
const txConfig = {
|
|
736
|
+
gasLimit,
|
|
737
|
+
txTimeoutAt
|
|
738
|
+
};
|
|
739
|
+
this.log.debug('Forwarding transactions', {
|
|
740
|
+
requests: requests.map((request)=>request.action),
|
|
741
|
+
txConfig
|
|
742
|
+
});
|
|
743
|
+
const result = await this.forwardWithPublisherRotation(requests, txConfig, blobConfig, currentL2Slot);
|
|
744
|
+
if (result === undefined) {
|
|
745
|
+
return undefined;
|
|
746
|
+
}
|
|
747
|
+
const { successfulActions = [], failedActions = [] } = this.callbackBundledTransactions(requests, result);
|
|
748
|
+
const allFailedActions = [
|
|
749
|
+
...failedActions,
|
|
750
|
+
...droppedRequests.map((d)=>d.request.action)
|
|
751
|
+
];
|
|
752
|
+
return {
|
|
753
|
+
result,
|
|
754
|
+
expiredActions,
|
|
755
|
+
sentActions: requests.map((x)=>x.action),
|
|
756
|
+
successfulActions,
|
|
757
|
+
failedActions: allFailedActions
|
|
758
|
+
};
|
|
759
|
+
} catch (err) {
|
|
760
|
+
const viemError = formatViemError(err);
|
|
761
|
+
this.log.error(`Failed to publish bundled transactions`, viemError);
|
|
762
|
+
if (err instanceof TimeoutError) {
|
|
763
|
+
const timeoutState = err instanceof L1TxTimeoutError ? err.txState : undefined;
|
|
764
|
+
void (async ()=>{
|
|
765
|
+
// The RPC is likely degraded right after a timeout, so back up without the block number
|
|
766
|
+
// rather than leaking an unhandled rejection.
|
|
767
|
+
const l1BlockNumber = await this.l1TxUtils.getBlockNumber().catch(()=>0n);
|
|
768
|
+
this.backupFailedTx({
|
|
769
|
+
id: this.failureRecordId(validRequests.map((r)=>r.action), currentL2Slot),
|
|
770
|
+
failureType: 'timeout',
|
|
771
|
+
request: {
|
|
772
|
+
to: MULTI_CALL_3_ADDRESS,
|
|
773
|
+
data: '0x'
|
|
774
|
+
},
|
|
775
|
+
l1BlockNumber,
|
|
776
|
+
error: {
|
|
777
|
+
message: viemError.message,
|
|
778
|
+
name: 'TimeoutError'
|
|
779
|
+
},
|
|
780
|
+
context: {
|
|
781
|
+
actions: validRequests.map((r)=>r.action),
|
|
782
|
+
requests: validRequests.filter((r)=>r.request.to !== null).map((r)=>({
|
|
783
|
+
action: r.action,
|
|
784
|
+
to: r.request.to,
|
|
785
|
+
data: r.request.data
|
|
786
|
+
})),
|
|
787
|
+
sender: this.getSenderAddress().toString(),
|
|
788
|
+
slot: Number(currentL2Slot)
|
|
789
|
+
},
|
|
790
|
+
timing: this.computeTimingInfo(currentL2Slot),
|
|
791
|
+
gasInfo: timeoutState ? {
|
|
792
|
+
sentFeesPerGasLadder: timeoutState.feesPerGasHistory,
|
|
793
|
+
attempts: timeoutState.attempts,
|
|
794
|
+
gasLimit: timeoutState.gasLimit,
|
|
795
|
+
nonce: timeoutState.nonce
|
|
796
|
+
} : undefined
|
|
797
|
+
}, {
|
|
798
|
+
captureFeeSummary: true,
|
|
799
|
+
targetSlot: currentL2Slot
|
|
800
|
+
});
|
|
801
|
+
})();
|
|
802
|
+
}
|
|
803
|
+
return undefined;
|
|
804
|
+
} finally{
|
|
805
|
+
try {
|
|
806
|
+
this.metrics.recordSenderBalance(await this.l1TxUtils.getSenderBalance(), this.l1TxUtils.getSenderAddress().toString());
|
|
807
|
+
} catch (err) {
|
|
808
|
+
this.log.warn(`Failed to record balance after sending tx: ${err}`);
|
|
809
|
+
}
|
|
810
|
+
}
|
|
811
|
+
}
|
|
812
|
+
/** Logs entries dropped by bundle simulation as warnings on the publisher's logger. */ logDroppedInSim(dropped) {
|
|
813
|
+
for (const drop of dropped){
|
|
814
|
+
const revertReasonDecoded = drop.revertReason ?? tryDecodeRevertReason(drop.returnData, this.revertDecoderAbi);
|
|
815
|
+
this.log.warn('Bundle entry dropped: action reverted in sim', {
|
|
816
|
+
action: drop.request.action,
|
|
817
|
+
revertReason: revertReasonDecoded ?? drop.returnData,
|
|
818
|
+
revertReasonDecoded,
|
|
819
|
+
returnData: drop.returnData
|
|
820
|
+
});
|
|
821
|
+
}
|
|
822
|
+
}
|
|
823
|
+
/** Backs up entries dropped by bundle simulation, one record per dropped action. */ async backupDroppedInSim(dropped, targetSlot) {
|
|
824
|
+
if (dropped.length === 0) {
|
|
825
|
+
return;
|
|
826
|
+
}
|
|
827
|
+
// Invoked as `void backupDroppedInSim(...)` on the publish path, so it must not throw.
|
|
828
|
+
try {
|
|
829
|
+
const l1BlockNumber = await this.l1TxUtils.getBlockNumber();
|
|
830
|
+
// Every dropped entry failed in the same slot against the same L1 fee conditions, so capture
|
|
831
|
+
// the fee environment once and share it rather than re-reading the window per entry.
|
|
832
|
+
const sharedFeeSummary = await this.captureFeeEnvironment(targetSlot).catch(()=>undefined);
|
|
833
|
+
const timing = this.computeTimingInfo(targetSlot);
|
|
834
|
+
for (const { request: req } of dropped){
|
|
835
|
+
this.backupFailedTx({
|
|
836
|
+
id: keccak256(req.request.data),
|
|
837
|
+
failureType: 'simulation',
|
|
838
|
+
request: {
|
|
839
|
+
to: req.request.to,
|
|
840
|
+
data: req.request.data
|
|
841
|
+
},
|
|
842
|
+
l1BlockNumber,
|
|
843
|
+
error: {
|
|
844
|
+
message: 'Bundle entry dropped: action reverted in sim'
|
|
845
|
+
},
|
|
846
|
+
context: {
|
|
847
|
+
actions: [
|
|
848
|
+
req.action
|
|
849
|
+
],
|
|
850
|
+
sender: this.getSenderAddress().toString(),
|
|
851
|
+
slot: targetSlot !== undefined ? Number(targetSlot) : undefined
|
|
852
|
+
},
|
|
853
|
+
timing
|
|
854
|
+
}, {
|
|
855
|
+
sharedFeeSummary
|
|
856
|
+
});
|
|
857
|
+
}
|
|
858
|
+
} catch (err) {
|
|
859
|
+
this.log.warn(`Failed to back up dropped-in-sim entries`, err);
|
|
860
|
+
}
|
|
861
|
+
}
|
|
862
|
+
/**
|
|
863
|
+
* Forwards transactions via Multicall3, rotating to the next available publisher if a send
|
|
864
|
+
* failure occurs (i.e. the tx never reached the chain).
|
|
865
|
+
* On-chain reverts and simulation errors are returned as-is without rotation.
|
|
866
|
+
*/ async forwardWithPublisherRotation(validRequests, txConfig, blobConfig, targetSlot) {
|
|
867
|
+
if (!txConfig?.gasLimit) {
|
|
868
|
+
throw new Error('gasLimit is required for bundled transactions');
|
|
869
|
+
}
|
|
870
|
+
const txConfigWithGasLimit = txConfig;
|
|
871
|
+
const triedAddresses = [];
|
|
872
|
+
let currentPublisher = this.l1TxUtils;
|
|
873
|
+
while(true){
|
|
874
|
+
if (txConfig.txTimeoutAt && new Date() > txConfig.txTimeoutAt) {
|
|
875
|
+
this.log.warn(`Tx timeout (${txConfig.txTimeoutAt.toISOString()}) elapsed; stopping publisher rotation`, {
|
|
876
|
+
triedAddresses: triedAddresses.map((a)=>a.toString())
|
|
877
|
+
});
|
|
878
|
+
return undefined;
|
|
879
|
+
}
|
|
880
|
+
triedAddresses.push(currentPublisher.getSenderAddress());
|
|
881
|
+
try {
|
|
882
|
+
const result = await Multicall3.forward(validRequests.map((r)=>r.request), currentPublisher, txConfigWithGasLimit, blobConfig, {
|
|
883
|
+
gasLimitRequired: true
|
|
884
|
+
});
|
|
885
|
+
this.l1TxUtils = currentPublisher;
|
|
886
|
+
return result;
|
|
887
|
+
} catch (err) {
|
|
888
|
+
if (err instanceof TimeoutError) {
|
|
889
|
+
throw err;
|
|
890
|
+
}
|
|
891
|
+
if (err instanceof MulticallForwarderRevertedError) {
|
|
892
|
+
this.log.error('Forwarder transaction reverted on-chain; not rotating publisher', err, {
|
|
893
|
+
transactionHash: err.receipt.transactionHash
|
|
894
|
+
});
|
|
895
|
+
this.backupRevertFailure(validRequests, err, currentPublisher, targetSlot);
|
|
896
|
+
return undefined;
|
|
897
|
+
}
|
|
898
|
+
const viemError = formatViemError(err);
|
|
899
|
+
if (!this.getNextPublisher) {
|
|
900
|
+
this.log.error('Failed to publish bundled transactions', viemError);
|
|
901
|
+
this.backupSendFailure(validRequests, viemError, currentPublisher, targetSlot);
|
|
902
|
+
return undefined;
|
|
903
|
+
}
|
|
904
|
+
this.log.warn(`Publisher ${currentPublisher.getSenderAddress()} failed to send, rotating to next publisher`, viemError);
|
|
905
|
+
const nextPublisher = await this.getNextPublisher([
|
|
906
|
+
...triedAddresses
|
|
907
|
+
]);
|
|
908
|
+
if (!nextPublisher) {
|
|
909
|
+
this.log.error(`All available publishers exhausted (tried ${triedAddresses.length}), failed to publish bundled transactions`, viemError, {
|
|
910
|
+
triedAddresses: triedAddresses.map((a)=>a.toString())
|
|
911
|
+
});
|
|
912
|
+
this.backupSendFailure(validRequests, viemError, currentPublisher, targetSlot);
|
|
913
|
+
return undefined;
|
|
914
|
+
}
|
|
915
|
+
currentPublisher = nextPublisher;
|
|
916
|
+
}
|
|
917
|
+
}
|
|
918
|
+
}
|
|
919
|
+
/** Backs up an on-chain revert failure to the failed tx store. */ backupRevertFailure(requests, err, publisher, targetSlot) {
|
|
920
|
+
this.backupFailedTx({
|
|
921
|
+
id: err.receipt.transactionHash,
|
|
922
|
+
failureType: 'revert',
|
|
923
|
+
request: {
|
|
924
|
+
to: MULTI_CALL_3_ADDRESS,
|
|
925
|
+
data: '0x'
|
|
926
|
+
},
|
|
927
|
+
l1BlockNumber: err.receipt.blockNumber,
|
|
928
|
+
receipt: {
|
|
929
|
+
transactionHash: err.receipt.transactionHash,
|
|
930
|
+
blockNumber: err.receipt.blockNumber,
|
|
931
|
+
gasUsed: err.receipt.gasUsed,
|
|
932
|
+
status: 'reverted'
|
|
933
|
+
},
|
|
934
|
+
error: {
|
|
935
|
+
message: err.message,
|
|
936
|
+
name: err.name
|
|
937
|
+
},
|
|
938
|
+
context: {
|
|
939
|
+
actions: requests.map((r)=>r.action),
|
|
940
|
+
requests: requests.filter((r)=>r.request.to !== null).map((r)=>({
|
|
941
|
+
action: r.action,
|
|
942
|
+
to: r.request.to,
|
|
943
|
+
data: r.request.data
|
|
944
|
+
})),
|
|
945
|
+
sender: publisher.getSenderAddress().toString(),
|
|
946
|
+
slot: targetSlot !== undefined ? Number(targetSlot) : undefined
|
|
947
|
+
},
|
|
948
|
+
gasInfo: err.txState ? {
|
|
949
|
+
sentFeesPerGas: err.txState.feesPerGas,
|
|
950
|
+
gasLimit: err.txState.gasLimit,
|
|
951
|
+
nonce: err.txState.nonce
|
|
952
|
+
} : undefined,
|
|
953
|
+
timing: this.computeTimingInfo(targetSlot)
|
|
954
|
+
}, {
|
|
955
|
+
captureFeeSummary: true,
|
|
956
|
+
targetSlot
|
|
957
|
+
});
|
|
958
|
+
}
|
|
959
|
+
/** Backs up a send failure (tx never reached chain) to the failed tx store. */ backupSendFailure(requests, error, publisher, targetSlot) {
|
|
960
|
+
// If we can't get the block number, still back up without it.
|
|
961
|
+
void this.l1TxUtils.getBlockNumber().catch(()=>0n).then((l1BlockNumber)=>{
|
|
962
|
+
this.backupFailedTx({
|
|
963
|
+
id: this.failureRecordId(requests.map((r)=>r.action), targetSlot),
|
|
964
|
+
failureType: 'send-error',
|
|
965
|
+
request: {
|
|
966
|
+
to: MULTI_CALL_3_ADDRESS,
|
|
967
|
+
data: '0x'
|
|
968
|
+
},
|
|
969
|
+
l1BlockNumber,
|
|
970
|
+
error: {
|
|
971
|
+
message: error.message,
|
|
972
|
+
name: 'name' in error ? error.name : undefined
|
|
973
|
+
},
|
|
974
|
+
context: {
|
|
975
|
+
actions: requests.map((r)=>r.action),
|
|
976
|
+
requests: requests.filter((r)=>r.request.to !== null).map((r)=>({
|
|
977
|
+
action: r.action,
|
|
978
|
+
to: r.request.to,
|
|
979
|
+
data: r.request.data
|
|
980
|
+
})),
|
|
981
|
+
sender: publisher.getSenderAddress().toString(),
|
|
982
|
+
slot: targetSlot !== undefined ? Number(targetSlot) : undefined
|
|
983
|
+
},
|
|
984
|
+
timing: this.computeTimingInfo(targetSlot)
|
|
985
|
+
}, {
|
|
986
|
+
captureFeeSummary: true,
|
|
987
|
+
targetSlot
|
|
988
|
+
});
|
|
989
|
+
});
|
|
990
|
+
}
|
|
991
|
+
/*
|
|
992
|
+
* Schedules sending all enqueued requests at (or after) the start of the given L2 slot.
|
|
993
|
+
*/ async sendRequestsAt(targetSlot) {
|
|
994
|
+
await this.waitForTargetSlot(targetSlot);
|
|
995
|
+
if (this.interrupted) {
|
|
996
|
+
return undefined;
|
|
997
|
+
}
|
|
998
|
+
return this.sendRequests(targetSlot);
|
|
999
|
+
}
|
|
1000
|
+
/**
|
|
1001
|
+
* Sleeps until one L1 slot before the L2 slot boundary, and then waits for that L1 block
|
|
1002
|
+
* to be mined, so we don't risk being included in it. If that block never gets mined after
|
|
1003
|
+
* a timeout, we assume it got skipped on L1, so we send the tx anyway.
|
|
1004
|
+
*/ async waitForTargetSlot(targetSlot) {
|
|
1005
|
+
const l1Constants = this.epochCache.getL1Constants();
|
|
1006
|
+
const nowInSeconds = this.dateProvider.nowInSeconds();
|
|
1007
|
+
const startOfTargetSlotTs = getTimestampForSlot(targetSlot, l1Constants);
|
|
1008
|
+
const previousL1BlockTs = startOfTargetSlotTs - this.ethereumSlotDuration;
|
|
1009
|
+
const waitDeadlineTs = previousL1BlockTs + BigInt(this.previousL1BlockWaitTimeoutMs / 1000);
|
|
1010
|
+
const logCtx = {
|
|
1011
|
+
targetSlot,
|
|
1012
|
+
startOfTargetSlotTs,
|
|
1013
|
+
nowInSeconds,
|
|
1014
|
+
previousL1BlockTs,
|
|
1015
|
+
waitDeadlineTs
|
|
1016
|
+
};
|
|
1017
|
+
// Check if we are already past time
|
|
1018
|
+
if (nowInSeconds >= startOfTargetSlotTs) {
|
|
1019
|
+
this.log.verbose(`Target slot ${targetSlot} already started, sending requests immediately`, logCtx);
|
|
1020
|
+
return;
|
|
1021
|
+
}
|
|
1022
|
+
// Otherwise we wait
|
|
1023
|
+
this.log.debug(`Waiting for slot ${targetSlot} before sending requests`, logCtx);
|
|
1024
|
+
// Wait until previous L1 block timestamp first
|
|
1025
|
+
const sleepMs = (Number(previousL1BlockTs) - nowInSeconds) * 1000;
|
|
1026
|
+
if (sleepMs > 0 && !this.interrupted) {
|
|
1027
|
+
this.log.trace(`Sleeping ${sleepMs}ms before waiting for previous L1 block`, logCtx);
|
|
1028
|
+
await this.interruptibleSleep.sleep(sleepMs);
|
|
1029
|
+
}
|
|
1030
|
+
// Then loop until we see the previous L1 block, so we know that we cannot be included in it.
|
|
1031
|
+
// We time out after a while, once we are sure that that block is skipped in L1.
|
|
1032
|
+
while(!this.interrupted){
|
|
1033
|
+
try {
|
|
1034
|
+
const nowInSeconds = this.dateProvider.nowInSeconds();
|
|
1035
|
+
logCtx.nowInSeconds = nowInSeconds;
|
|
1036
|
+
if (nowInSeconds >= waitDeadlineTs) {
|
|
1037
|
+
this.log.warn(`Timed out waiting for previous L1 block before sending requests, proceeding`, logCtx);
|
|
1038
|
+
return;
|
|
1039
|
+
}
|
|
1040
|
+
const latestBlockTs = await this.l1TxUtils.getBlock().then((b)=>b.timestamp);
|
|
1041
|
+
if (latestBlockTs >= previousL1BlockTs) {
|
|
1042
|
+
this.log.debug(`Previous L1 block mined, proceeding to send requests`, {
|
|
1043
|
+
...logCtx,
|
|
1044
|
+
latestBlockTs
|
|
1045
|
+
});
|
|
1046
|
+
return;
|
|
1047
|
+
}
|
|
1048
|
+
this.log.trace(`Previous L1 block not mined yet, continuing to wait`, {
|
|
1049
|
+
...logCtx,
|
|
1050
|
+
latestBlockTs
|
|
1051
|
+
});
|
|
1052
|
+
} catch (err) {
|
|
1053
|
+
this.log.error(`Error while waiting for previous L1 block before sending requests; retrying`, err, logCtx);
|
|
1054
|
+
} finally{
|
|
1055
|
+
await this.interruptibleSleep.sleep(this.previousL1BlockWaitPollIntervalMs);
|
|
1056
|
+
}
|
|
1057
|
+
}
|
|
1058
|
+
}
|
|
1059
|
+
callbackBundledTransactions(requests, result) {
|
|
1060
|
+
const actionsListStr = requests.map((r)=>r.action).join(', ');
|
|
1061
|
+
this.log.verbose(`Published bundled transactions (${actionsListStr})`, {
|
|
1062
|
+
result,
|
|
1063
|
+
requests: requests.map((r)=>({
|
|
1064
|
+
...r,
|
|
1065
|
+
// Avoid logging large blob data
|
|
1066
|
+
blobConfig: r.blobConfig ? {
|
|
1067
|
+
...r.blobConfig,
|
|
1068
|
+
blobs: r.blobConfig.blobs.map((b)=>({
|
|
1069
|
+
size: trimmedBytesLength(b)
|
|
1070
|
+
}))
|
|
1071
|
+
} : undefined
|
|
1072
|
+
}))
|
|
1073
|
+
});
|
|
1074
|
+
const successfulActions = [];
|
|
1075
|
+
const failedActions = [];
|
|
1076
|
+
for (const request of requests){
|
|
1077
|
+
if (request.checkSuccess(request.request, result)) {
|
|
1078
|
+
successfulActions.push(request.action);
|
|
1079
|
+
} else {
|
|
1080
|
+
failedActions.push(request.action);
|
|
1081
|
+
}
|
|
1082
|
+
}
|
|
1083
|
+
return {
|
|
1084
|
+
successfulActions,
|
|
1085
|
+
failedActions
|
|
1086
|
+
};
|
|
1087
|
+
}
|
|
1088
|
+
/**
|
|
1089
|
+
* @notice Will call `canProposeAt` to make sure that it is possible to propose
|
|
1090
|
+
* @param tipArchive - The archive to check
|
|
1091
|
+
* @returns The slot and block number if it is possible to propose, undefined otherwise
|
|
1092
|
+
*/ async canProposeAt(tipArchive, msgSender, simulationOverridesPlan) {
|
|
1093
|
+
// TODO: #14291 - should loop through multiple keys to check if any of them can propose
|
|
1094
|
+
// These errors are expected when we cannot actually propose right now — usually because our
|
|
1095
|
+
// local view of the chain is ahead of L1 (proposed parent hasn't landed yet, or someone
|
|
1096
|
+
// else has just landed the slot, or the archive override doesn't match). We log a warn and
|
|
1097
|
+
// skip the proposal; we do NOT treat these as bugs.
|
|
1098
|
+
const expectedErrors = [
|
|
1099
|
+
'SlotAlreadyInChain',
|
|
1100
|
+
'InvalidProposer',
|
|
1101
|
+
'InvalidArchive'
|
|
1102
|
+
];
|
|
1103
|
+
const slotOffset = this.aztecSlotDuration;
|
|
1104
|
+
const nextL1SlotTs = this.getNextL1SlotTimestamp() + slotOffset;
|
|
1105
|
+
return this.rollupContract.canProposeAt(tipArchive.toBuffer(), msgSender.toString(), nextL1SlotTs, await buildSimulationOverridesStateOverride(this.rollupContract, simulationOverridesPlan)).catch((err)=>{
|
|
1106
|
+
if (err instanceof FormattedViemError && expectedErrors.find((e)=>err.message.includes(e))) {
|
|
1107
|
+
this.log.warn(`Failed canProposeAtTime check with ${expectedErrors.find((e)=>err.message.includes(e))}`, {
|
|
1108
|
+
error: err.message
|
|
1109
|
+
});
|
|
1110
|
+
} else {
|
|
1111
|
+
this.log.error(err.name, err);
|
|
1112
|
+
}
|
|
1113
|
+
return undefined;
|
|
1114
|
+
});
|
|
1115
|
+
}
|
|
1116
|
+
/**
|
|
1117
|
+
* @notice Will simulate the rollup's `validateHeaderWithAttestations` to make sure the checkpoint header is valid
|
|
1118
|
+
* @dev This is a convenience function that can be used by the sequencer to validate a "partial" header,
|
|
1119
|
+
* skipping the DA and signature checks. It will throw if the checkpoint header is invalid.
|
|
1120
|
+
* @param header - The checkpoint header to validate
|
|
1121
|
+
*/ async validateCheckpointHeader(header, simulationOverridesPlan) {
|
|
1122
|
+
const flags = {
|
|
1123
|
+
ignoreDA: true,
|
|
1124
|
+
ignoreSignatures: true
|
|
1125
|
+
};
|
|
1126
|
+
const args = [
|
|
1127
|
+
header.toViem(),
|
|
1128
|
+
CommitteeAttestationsAndSigners.packAttestations([]),
|
|
1129
|
+
[],
|
|
1130
|
+
Signature.empty().toViemSignature(),
|
|
1131
|
+
`0x${'0'.repeat(64)}`,
|
|
1132
|
+
header.blobsHash.toString(),
|
|
1133
|
+
flags
|
|
1134
|
+
];
|
|
1135
|
+
const l1Constants = this.epochCache.getL1Constants();
|
|
1136
|
+
const ts = getLastL1SlotTimestampForL2Slot(header.slotNumber, l1Constants);
|
|
1137
|
+
const stateOverrides = await buildSimulationOverridesStateOverride(this.rollupContract, simulationOverridesPlan);
|
|
1138
|
+
// Balance override for compatibility with providers that apply an upfront funds check to simulated calls.
|
|
1139
|
+
stateOverrides.push({
|
|
1140
|
+
address: MULTI_CALL_3_ADDRESS,
|
|
1141
|
+
balance: 10n * WEI_CONST * WEI_CONST
|
|
1142
|
+
});
|
|
1143
|
+
await this.l1TxUtils.simulate({
|
|
1144
|
+
to: this.rollupContract.address,
|
|
1145
|
+
data: encodeFunctionData({
|
|
1146
|
+
abi: RollupAbi,
|
|
1147
|
+
functionName: 'validateHeaderWithAttestations',
|
|
1148
|
+
args
|
|
1149
|
+
}),
|
|
1150
|
+
from: MULTI_CALL_3_ADDRESS
|
|
1151
|
+
}, {
|
|
1152
|
+
time: ts
|
|
1153
|
+
}, stateOverrides);
|
|
1154
|
+
this.log.debug(`Simulated validateHeader`);
|
|
1155
|
+
}
|
|
1156
|
+
/**
|
|
1157
|
+
* Simulate making a call to invalidate a checkpoint with invalid attestations. Returns undefined if no need to invalidate.
|
|
1158
|
+
* @param validationResult - The validation result indicating which checkpoint to invalidate (as returned by the archiver)
|
|
1159
|
+
*/ async simulateInvalidateCheckpoint(validationResult) {
|
|
1160
|
+
if (validationResult.valid) {
|
|
1161
|
+
return undefined;
|
|
1162
|
+
}
|
|
1163
|
+
const { reason, checkpoint } = validationResult;
|
|
1164
|
+
const checkpointNumber = checkpoint.checkpointNumber;
|
|
1165
|
+
const logData = {
|
|
1166
|
+
...checkpoint,
|
|
1167
|
+
reason
|
|
1168
|
+
};
|
|
1169
|
+
const currentCheckpointNumber = await this.rollupContract.getCheckpointNumber();
|
|
1170
|
+
if (currentCheckpointNumber < checkpointNumber) {
|
|
1171
|
+
this.log.verbose(`Skipping checkpoint ${checkpointNumber} invalidation since it has already been removed from the pending chain`, {
|
|
1172
|
+
currentCheckpointNumber,
|
|
1173
|
+
...logData
|
|
1174
|
+
});
|
|
1175
|
+
return undefined;
|
|
1176
|
+
}
|
|
1177
|
+
const request = this.buildInvalidateCheckpointRequest(validationResult);
|
|
1178
|
+
this.log.debug(`Simulating invalidate checkpoint ${checkpointNumber}`, {
|
|
1179
|
+
...logData,
|
|
1180
|
+
request
|
|
1181
|
+
});
|
|
1182
|
+
const l1BlockNumber = await this.l1TxUtils.getBlockNumber();
|
|
1183
|
+
try {
|
|
1184
|
+
const { gasUsed } = await this.l1TxUtils.simulate(request, undefined, undefined, mergeAbis([
|
|
1185
|
+
request.abi ?? [],
|
|
1186
|
+
ErrorsAbi
|
|
1187
|
+
]));
|
|
1188
|
+
this.log.verbose(`Simulation for invalidate checkpoint ${checkpointNumber} succeeded`, {
|
|
1189
|
+
...logData,
|
|
1190
|
+
request,
|
|
1191
|
+
gasUsed
|
|
1192
|
+
});
|
|
1193
|
+
return {
|
|
1194
|
+
request,
|
|
1195
|
+
gasUsed,
|
|
1196
|
+
checkpointNumber,
|
|
1197
|
+
forcePendingCheckpointNumber: CheckpointNumber(checkpointNumber - 1),
|
|
1198
|
+
lastArchive: validationResult.checkpoint.lastArchive,
|
|
1199
|
+
reason
|
|
1200
|
+
};
|
|
1201
|
+
} catch (err) {
|
|
1202
|
+
const viemError = formatViemError(err);
|
|
1203
|
+
// If the error is due to the checkpoint not being in the pending chain, and it was indeed removed by someone else,
|
|
1204
|
+
// we can safely ignore it and return undefined so we go ahead with checkpoint building.
|
|
1205
|
+
if (viemError.message?.includes('Rollup__CheckpointNotInPendingChain')) {
|
|
1206
|
+
this.log.verbose(`Simulation for invalidate checkpoint ${checkpointNumber} failed due to checkpoint not being in pending chain`, {
|
|
1207
|
+
...logData,
|
|
1208
|
+
request,
|
|
1209
|
+
error: viemError.message
|
|
1210
|
+
});
|
|
1211
|
+
const latestProposedCheckpointNumber = await this.rollupContract.getCheckpointNumber();
|
|
1212
|
+
if (latestProposedCheckpointNumber < checkpointNumber) {
|
|
1213
|
+
this.log.verbose(`Checkpoint ${checkpointNumber} has already been invalidated`, {
|
|
1214
|
+
...logData
|
|
1215
|
+
});
|
|
1216
|
+
return undefined;
|
|
1217
|
+
} else {
|
|
1218
|
+
this.log.error(`Simulation for invalidate checkpoint ${checkpointNumber} failed and it is still in pending chain`, viemError, logData);
|
|
1219
|
+
throw new Error(`Failed to simulate invalidate checkpoint ${checkpointNumber} while it is still in pending chain`, {
|
|
1220
|
+
cause: viemError
|
|
1221
|
+
});
|
|
1222
|
+
}
|
|
1223
|
+
}
|
|
1224
|
+
// Otherwise, throw. We cannot build the next checkpoint if we cannot invalidate the previous one.
|
|
1225
|
+
this.log.error(`Simulation for invalidate checkpoint ${checkpointNumber} failed`, viemError, logData);
|
|
1226
|
+
this.backupFailedTx({
|
|
1227
|
+
id: keccak256(request.data),
|
|
1228
|
+
failureType: 'simulation',
|
|
1229
|
+
request: {
|
|
1230
|
+
to: request.to,
|
|
1231
|
+
data: request.data,
|
|
1232
|
+
value: request.value
|
|
1233
|
+
},
|
|
1234
|
+
l1BlockNumber,
|
|
1235
|
+
error: {
|
|
1236
|
+
message: viemError.message,
|
|
1237
|
+
name: viemError.name
|
|
1238
|
+
},
|
|
1239
|
+
context: {
|
|
1240
|
+
actions: [
|
|
1241
|
+
`invalidate-${reason}`
|
|
1242
|
+
],
|
|
1243
|
+
checkpointNumber,
|
|
1244
|
+
sender: this.getSenderAddress().toString()
|
|
1245
|
+
},
|
|
1246
|
+
timing: this.computeTimingInfo(this.getCurrentL2Slot())
|
|
1247
|
+
}, {
|
|
1248
|
+
captureFeeSummary: true,
|
|
1249
|
+
targetSlot: this.getCurrentL2Slot()
|
|
1250
|
+
});
|
|
1251
|
+
throw new Error(`Failed to simulate invalidate checkpoint ${checkpointNumber}`, {
|
|
1252
|
+
cause: viemError
|
|
1253
|
+
});
|
|
1254
|
+
}
|
|
1255
|
+
}
|
|
1256
|
+
buildInvalidateCheckpointRequest(validationResult) {
|
|
1257
|
+
if (validationResult.valid) {
|
|
1258
|
+
throw new Error('Cannot invalidate a valid checkpoint');
|
|
1259
|
+
}
|
|
1260
|
+
const { checkpoint, committee, reason } = validationResult;
|
|
1261
|
+
const logData = {
|
|
1262
|
+
...checkpoint,
|
|
1263
|
+
reason
|
|
1264
|
+
};
|
|
1265
|
+
this.log.debug(`Building invalidate checkpoint ${checkpoint.checkpointNumber} request`, logData);
|
|
1266
|
+
// Use the exact packed tuple posted to L1 verbatim. A repack via `packAttestations` is not a
|
|
1267
|
+
// byte-faithful inverse of `fromPacked` (a canonicalized yParity byte or an all-zero signature slot
|
|
1268
|
+
// round-trips differently), so it would diverge from the stored `attestationsHash` and revert the
|
|
1269
|
+
// invalidation.
|
|
1270
|
+
const attestationsAndSigners = validationResult.verbatimAttestations;
|
|
1271
|
+
if (reason === 'invalid-attestation') {
|
|
1272
|
+
return this.rollupContract.buildInvalidateBadAttestationRequest(checkpoint.checkpointNumber, attestationsAndSigners, committee, validationResult.invalidIndex);
|
|
1273
|
+
} else if (reason === 'insufficient-attestations') {
|
|
1274
|
+
return this.rollupContract.buildInvalidateInsufficientAttestationsRequest(checkpoint.checkpointNumber, attestationsAndSigners, committee);
|
|
1275
|
+
} else {
|
|
1276
|
+
const _ = reason;
|
|
1277
|
+
throw new Error(`Unknown reason for invalidation`);
|
|
1278
|
+
}
|
|
1279
|
+
}
|
|
1280
|
+
async enqueueCastSignalHelper(slotNumber, signalType, payload, base, signerAddress, signer) {
|
|
1281
|
+
if (this.lastActions[signalType] && this.lastActions[signalType] === slotNumber) {
|
|
1282
|
+
this.log.debug(`Skipping duplicate vote cast signal ${signalType} for slot ${slotNumber}`);
|
|
1283
|
+
return false;
|
|
1284
|
+
}
|
|
1285
|
+
if (payload.equals(EthAddress.ZERO)) {
|
|
1286
|
+
return false;
|
|
1287
|
+
}
|
|
1288
|
+
if (signerAddress.equals(EthAddress.ZERO)) {
|
|
1289
|
+
this.log.warn(`Cannot enqueue vote cast signal ${signalType} for address zero at slot ${slotNumber}`);
|
|
1290
|
+
return false;
|
|
1291
|
+
}
|
|
1292
|
+
const canonicalRollup = await base.getRollupAddress();
|
|
1293
|
+
if (!canonicalRollup.equals(EthAddress.fromString(this.rollupContract.address))) {
|
|
1294
|
+
this.log.warn(`Rollup ${this.rollupContract.address} is not canonical, skipping governance signal`, {
|
|
1295
|
+
slotNumber,
|
|
1296
|
+
signalType,
|
|
1297
|
+
canonicalRollup,
|
|
1298
|
+
targetRollup: this.rollupContract.address,
|
|
1299
|
+
payload: payload.toString()
|
|
1300
|
+
});
|
|
1301
|
+
return false;
|
|
1302
|
+
}
|
|
1303
|
+
const round = await base.computeRound(slotNumber);
|
|
1304
|
+
const roundInfo = await base.getRoundInfo(this.rollupContract.address, round);
|
|
1305
|
+
if (roundInfo.quorumReached) {
|
|
1306
|
+
return false;
|
|
1307
|
+
}
|
|
1308
|
+
if (roundInfo.lastSignalSlot >= slotNumber) {
|
|
1309
|
+
return false;
|
|
1310
|
+
}
|
|
1311
|
+
if (await base.isPayloadEmpty(payload)) {
|
|
1312
|
+
this.log.warn(`Skipping vote cast for payload with empty code`);
|
|
1313
|
+
return false;
|
|
1314
|
+
}
|
|
1315
|
+
// Classify the payload against the Governance proposal history so we stop signalling once its
|
|
1316
|
+
// proposal is live or was already executed, while still re-signalling one whose proposal was
|
|
1317
|
+
// merely rejected/dropped/expired.
|
|
1318
|
+
let status = 'none';
|
|
1319
|
+
try {
|
|
1320
|
+
status = await base.getPayloadProposalStatus(payload.toString());
|
|
1321
|
+
} catch (err) {
|
|
1322
|
+
// We deliberately swallow the error and proceed to signal. Failing closed (skipping the
|
|
1323
|
+
// signal) on transient RPC errors would let a flaky L1 endpoint silence governance
|
|
1324
|
+
// participation entirely; failing open at worst produces a duplicate signal that the
|
|
1325
|
+
// contract will simply count alongside others in the round.
|
|
1326
|
+
this.log.error(`Failed to check governance proposal status for payload ${payload} (signalling anyway)`, err, {
|
|
1327
|
+
slotNumber,
|
|
1328
|
+
signalType
|
|
1329
|
+
});
|
|
1330
|
+
}
|
|
1331
|
+
if (status === 'live') {
|
|
1332
|
+
this.log.info(`Payload ${payload} has a live governance proposal, stopping signals`, {
|
|
1333
|
+
slotNumber,
|
|
1334
|
+
signalType,
|
|
1335
|
+
payload: payload.toString()
|
|
1336
|
+
});
|
|
1337
|
+
return false;
|
|
1338
|
+
}
|
|
1339
|
+
if (status === 'executed' && !this.config.governanceProposerForcePayloadVote) {
|
|
1340
|
+
this.log.info(`Payload ${payload} was executed by governance within lookback, stopping signals ` + `(set GOVERNANCE_PROPOSER_FORCE_PAYLOAD_VOTE to re-signal)`, {
|
|
1341
|
+
slotNumber,
|
|
1342
|
+
signalType,
|
|
1343
|
+
payload: payload.toString()
|
|
1344
|
+
});
|
|
1345
|
+
return false;
|
|
1346
|
+
}
|
|
1347
|
+
const cachedLastVote = this.lastActions[signalType];
|
|
1348
|
+
this.lastActions[signalType] = slotNumber;
|
|
1349
|
+
const action = signalType;
|
|
1350
|
+
const request = await base.createSignalRequestWithSignature(payload.toString(), slotNumber, this.config.l1ChainId, signerAddress.toString(), signer);
|
|
1351
|
+
this.log.debug(`Created ${action} request with signature`, {
|
|
1352
|
+
request,
|
|
1353
|
+
round,
|
|
1354
|
+
signer: this.l1TxUtils.client.account?.address,
|
|
1355
|
+
lastValidL2Slot: slotNumber
|
|
1356
|
+
});
|
|
1357
|
+
// TODO(palla/slash): All votes (governance and slashing) should txTimeoutAt at the end of the slot.
|
|
1358
|
+
this.addRequest({
|
|
1359
|
+
action,
|
|
1360
|
+
request,
|
|
1361
|
+
lastValidL2Slot: slotNumber,
|
|
1362
|
+
checkSuccess: (_request, result)=>{
|
|
1363
|
+
const success = result && extractEventSuccess(result.receipt, {
|
|
1364
|
+
address: base.address.toString(),
|
|
1365
|
+
abi: EmpireBaseAbi,
|
|
1366
|
+
eventName: 'SignalCast'
|
|
1367
|
+
});
|
|
1368
|
+
const logData = {
|
|
1369
|
+
...result,
|
|
1370
|
+
slotNumber,
|
|
1371
|
+
round,
|
|
1372
|
+
payload: payload.toString()
|
|
1373
|
+
};
|
|
1374
|
+
if (!success) {
|
|
1375
|
+
this.log.error(`Signaling in ${action} for ${payload} at slot ${slotNumber} in round ${round} failed`, logData);
|
|
1376
|
+
this.lastActions[signalType] = cachedLastVote;
|
|
1377
|
+
return false;
|
|
1378
|
+
} else {
|
|
1379
|
+
this.log.info(`Signaling in ${action} for ${payload} at slot ${slotNumber} in round ${round} succeeded`, logData);
|
|
1380
|
+
return true;
|
|
1381
|
+
}
|
|
1382
|
+
}
|
|
1383
|
+
});
|
|
1384
|
+
return true;
|
|
1385
|
+
}
|
|
1386
|
+
/**
|
|
1387
|
+
* Enqueues a governance castSignal transaction to cast a signal for a given slot number.
|
|
1388
|
+
* @param slotNumber - The slot number to cast a signal for.
|
|
1389
|
+
* @returns True if the signal was successfully enqueued, false otherwise.
|
|
1390
|
+
*/ enqueueGovernanceCastSignal(governancePayload, slotNumber, signerAddress, signer) {
|
|
1391
|
+
return this.enqueueCastSignalHelper(slotNumber, 'governance-signal', governancePayload, this.govProposerContract, signerAddress, signer);
|
|
1392
|
+
}
|
|
1393
|
+
/**
|
|
1394
|
+
* Enqueues a `prune()` transaction if the rollup is prunable at the given slot's L1 timestamp.
|
|
1395
|
+
* `prune()` is permissionless and idempotent — if the chain is no longer prunable by send time the
|
|
1396
|
+
* bundle simulation usually drops the entry; on a node without `eth_simulateV1` the bundle is sent
|
|
1397
|
+
* as-is and the prune reverts `Rollup__NothingToPrune` inside `aggregate3(allowFailure: true)`
|
|
1398
|
+
* (a failed action, never a whole-tx revert). Used by the failed-sync fallback so a stuck pending
|
|
1399
|
+
* chain (e.g. bad data blocking sync) can be wound back to recover.
|
|
1400
|
+
* @returns true if a prune request was enqueued, false otherwise.
|
|
1401
|
+
*/ async enqueuePruneIfPrunable(slotNumber) {
|
|
1402
|
+
if (this.lastActions['prune'] === slotNumber) {
|
|
1403
|
+
this.log.debug(`Skipping duplicate prune for slot ${slotNumber}`, {
|
|
1404
|
+
slotNumber
|
|
1405
|
+
});
|
|
1406
|
+
return false;
|
|
1407
|
+
}
|
|
1408
|
+
// Use the SAME timestamp the bundle simulator overrides block.timestamp with at send time
|
|
1409
|
+
// (sequencer-bundle-simulator.ts) so this upfront check and the send-time sim agree. Slot-start
|
|
1410
|
+
// and last-L1-slot both fall within the same L2 slot (and epoch, which is what `canPruneAtTime`
|
|
1411
|
+
// derives), so they agree today; matching the simulator keeps it robust if the contract ever uses
|
|
1412
|
+
// the timestamp more granularly.
|
|
1413
|
+
const ts = getLastL1SlotTimestampForL2Slot(slotNumber, this.epochCache.getL1Constants());
|
|
1414
|
+
const canPrune = await this.rollupContract.canPruneAtTime(ts).catch((err)=>{
|
|
1415
|
+
this.log.error(`Failed to check canPruneAtTime for slot ${slotNumber}`, err, {
|
|
1416
|
+
slotNumber
|
|
1417
|
+
});
|
|
1418
|
+
return false;
|
|
1419
|
+
});
|
|
1420
|
+
if (!canPrune) {
|
|
1421
|
+
this.log.debug(`Rollup not prunable at slot ${slotNumber}`, {
|
|
1422
|
+
slotNumber
|
|
1423
|
+
});
|
|
1424
|
+
return false;
|
|
1425
|
+
}
|
|
1426
|
+
const request = {
|
|
1427
|
+
to: this.rollupContract.address,
|
|
1428
|
+
data: encodeFunctionData({
|
|
1429
|
+
abi: RollupAbi,
|
|
1430
|
+
functionName: 'prune',
|
|
1431
|
+
args: []
|
|
1432
|
+
})
|
|
1433
|
+
};
|
|
1434
|
+
this.log.info(`Enqueuing rollup prune for slot ${slotNumber}`, {
|
|
1435
|
+
slotNumber
|
|
1436
|
+
});
|
|
1437
|
+
return this.enqueueRequest('prune', request, {
|
|
1438
|
+
address: this.rollupContract.address,
|
|
1439
|
+
abi: RollupAbi,
|
|
1440
|
+
eventName: 'PrunedPending'
|
|
1441
|
+
}, slotNumber);
|
|
1442
|
+
}
|
|
1443
|
+
/** Enqueues all slashing actions as returned by the slasher client. */ async enqueueSlashingActions(actions, slotNumber, signerAddress, signer) {
|
|
1444
|
+
if (actions.length === 0) {
|
|
1445
|
+
this.log.debug(`No slashing actions to enqueue for slot ${slotNumber}`);
|
|
1446
|
+
return false;
|
|
1447
|
+
}
|
|
1448
|
+
for (const action of actions){
|
|
1449
|
+
switch(action.type){
|
|
1450
|
+
case 'vote-offenses':
|
|
1451
|
+
{
|
|
1452
|
+
this.log.debug(`Enqueuing slashing vote for ${action.votes.length} votes at slot ${slotNumber}`, {
|
|
1453
|
+
slotNumber,
|
|
1454
|
+
round: action.round,
|
|
1455
|
+
votesCount: action.votes.length,
|
|
1456
|
+
signerAddress
|
|
1457
|
+
});
|
|
1458
|
+
if (!this.slashingProposerContract) {
|
|
1459
|
+
this.log.error('No slashing proposer contract available');
|
|
1460
|
+
return false;
|
|
1461
|
+
}
|
|
1462
|
+
const votes = bufferToHex(encodeSlashConsensusVotes(action.votes));
|
|
1463
|
+
const request = await this.slashingProposerContract.buildVoteRequestFromSigner(votes, slotNumber, signer);
|
|
1464
|
+
this.enqueueRequest('vote-offenses', request, {
|
|
1465
|
+
address: this.slashingProposerContract.address.toString(),
|
|
1466
|
+
abi: SlashingProposerAbi,
|
|
1467
|
+
eventName: 'VoteCast'
|
|
1468
|
+
}, slotNumber);
|
|
1469
|
+
break;
|
|
1470
|
+
}
|
|
1471
|
+
case 'execute-slash':
|
|
1472
|
+
{
|
|
1473
|
+
this.log.debug(`Enqueuing slash execution for round ${action.round} at slot ${slotNumber}`, {
|
|
1474
|
+
slotNumber,
|
|
1475
|
+
round: action.round,
|
|
1476
|
+
signerAddress
|
|
1477
|
+
});
|
|
1478
|
+
if (!this.slashingProposerContract) {
|
|
1479
|
+
this.log.error('No slashing proposer contract available');
|
|
1480
|
+
return false;
|
|
1481
|
+
}
|
|
1482
|
+
const executeRequest = this.slashingProposerContract.buildExecuteRoundRequest(action.round, action.committees);
|
|
1483
|
+
this.enqueueRequest('execute-slash', executeRequest, {
|
|
1484
|
+
address: this.slashingProposerContract.address.toString(),
|
|
1485
|
+
abi: SlashingProposerAbi,
|
|
1486
|
+
eventName: 'RoundExecuted'
|
|
1487
|
+
}, slotNumber);
|
|
1488
|
+
break;
|
|
1489
|
+
}
|
|
1490
|
+
default:
|
|
1491
|
+
{
|
|
1492
|
+
const _ = action;
|
|
1493
|
+
throw new Error(`Unknown slashing action type: ${action.type}`);
|
|
1494
|
+
}
|
|
1495
|
+
}
|
|
1496
|
+
}
|
|
1497
|
+
return true;
|
|
1498
|
+
}
|
|
1499
|
+
/** Enqueues a proposal for a checkpoint on L1 */ async enqueueProposeCheckpoint(checkpoint, attestationsAndSigners, attestationsAndSignersSignature, bucketHint, opts = {}) {
|
|
1500
|
+
const checkpointHeader = checkpoint.header;
|
|
1501
|
+
const blobFields = checkpoint.toBlobFields();
|
|
1502
|
+
const blobs = await getBlobsPerL1Block(blobFields);
|
|
1503
|
+
const proposeTxArgs = {
|
|
1504
|
+
header: checkpointHeader,
|
|
1505
|
+
archive: checkpoint.archive.root.toBuffer(),
|
|
1506
|
+
blobs,
|
|
1507
|
+
attestationsAndSigners,
|
|
1508
|
+
attestationsAndSignersSignature,
|
|
1509
|
+
feeAssetPriceModifier: checkpoint.feeAssetPriceModifier,
|
|
1510
|
+
bucketHint
|
|
1511
|
+
};
|
|
1512
|
+
this.log.verbose(`Enqueuing checkpoint propose transaction`, {
|
|
1513
|
+
...checkpoint.toCheckpointInfo(),
|
|
1514
|
+
txTimeoutAt: opts.txTimeoutAt
|
|
1515
|
+
});
|
|
1516
|
+
await this.addProposeTx(checkpoint, proposeTxArgs, {
|
|
1517
|
+
txTimeoutAt: opts.txTimeoutAt
|
|
1518
|
+
});
|
|
1519
|
+
}
|
|
1520
|
+
enqueueInvalidateCheckpoint(request, opts = {}) {
|
|
1521
|
+
if (!request) {
|
|
1522
|
+
return;
|
|
1523
|
+
}
|
|
1524
|
+
const { gasUsed, checkpointNumber } = request;
|
|
1525
|
+
const logData = {
|
|
1526
|
+
gasUsed,
|
|
1527
|
+
checkpointNumber,
|
|
1528
|
+
opts
|
|
1529
|
+
};
|
|
1530
|
+
this.log.verbose(`Enqueuing invalidate checkpoint request`, logData);
|
|
1531
|
+
this.addRequest({
|
|
1532
|
+
action: `invalidate-by-${request.reason}`,
|
|
1533
|
+
request: request.request,
|
|
1534
|
+
gasConfig: opts.txTimeoutAt ? {
|
|
1535
|
+
txTimeoutAt: opts.txTimeoutAt
|
|
1536
|
+
} : undefined,
|
|
1537
|
+
lastValidL2Slot: SlotNumber(this.getCurrentL2Slot() + 2),
|
|
1538
|
+
checkSuccess: (_req, result)=>{
|
|
1539
|
+
const success = result && extractEventSuccess(result.receipt, {
|
|
1540
|
+
address: this.rollupContract.address,
|
|
1541
|
+
abi: RollupAbi,
|
|
1542
|
+
eventName: 'CheckpointInvalidated'
|
|
1543
|
+
});
|
|
1544
|
+
if (!success) {
|
|
1545
|
+
this.log.warn(`Invalidate checkpoint ${request.checkpointNumber} failed`, {
|
|
1546
|
+
...result,
|
|
1547
|
+
...logData
|
|
1548
|
+
});
|
|
1549
|
+
} else {
|
|
1550
|
+
this.log.info(`Invalidate checkpoint ${request.checkpointNumber} succeeded`, {
|
|
1551
|
+
...result,
|
|
1552
|
+
...logData
|
|
1553
|
+
});
|
|
1554
|
+
}
|
|
1555
|
+
return !!success;
|
|
1556
|
+
}
|
|
1557
|
+
});
|
|
1558
|
+
}
|
|
1559
|
+
/**
|
|
1560
|
+
* Dedup-checked enqueue helper for actions that are simulated at bundle-send time rather
|
|
1561
|
+
* than at enqueue time. Validates the (action, slot) dedup key, sets `lastActions`, and
|
|
1562
|
+
* enqueues without a gasLimit so the bundle simulate sets the only gasLimit that matters.
|
|
1563
|
+
*/ enqueueRequest(action, request, eventOpts, slotNumber) {
|
|
1564
|
+
if (this.lastActions[action] && this.lastActions[action] === slotNumber) {
|
|
1565
|
+
this.log.debug(`Skipping duplicate action ${action} for slot ${slotNumber}`);
|
|
1566
|
+
return false;
|
|
1567
|
+
}
|
|
1568
|
+
const cachedLastActionSlot = this.lastActions[action];
|
|
1569
|
+
this.lastActions[action] = slotNumber;
|
|
1570
|
+
this.log.debug(`Enqueuing ${action}`, {
|
|
1571
|
+
slotNumber
|
|
1572
|
+
});
|
|
1573
|
+
this.addRequest({
|
|
1574
|
+
action,
|
|
1575
|
+
request,
|
|
1576
|
+
lastValidL2Slot: slotNumber,
|
|
1577
|
+
checkSuccess: (_request, result)=>{
|
|
1578
|
+
const success = result && extractEventSuccess(result.receipt, eventOpts);
|
|
1579
|
+
if (!success) {
|
|
1580
|
+
this.log.warn(`Action ${action} at ${slotNumber} failed`, {
|
|
1581
|
+
...result,
|
|
1582
|
+
slotNumber
|
|
1583
|
+
});
|
|
1584
|
+
this.lastActions[action] = cachedLastActionSlot;
|
|
1585
|
+
} else {
|
|
1586
|
+
this.log.info(`Action ${action} at ${slotNumber} succeeded`, {
|
|
1587
|
+
...result,
|
|
1588
|
+
slotNumber
|
|
1589
|
+
});
|
|
1590
|
+
}
|
|
1591
|
+
return !!success;
|
|
1592
|
+
}
|
|
1593
|
+
});
|
|
1594
|
+
return true;
|
|
1595
|
+
}
|
|
1596
|
+
/**
|
|
1597
|
+
* Calling `interrupt` will cause any in progress call to `publishRollup` to return `false` asap.
|
|
1598
|
+
* Be warned, the call may return false even if the tx subsequently gets successfully mined.
|
|
1599
|
+
* In practice this shouldn't matter, as we'll only ever be calling `interrupt` when we know it's going to fail.
|
|
1600
|
+
* A call to `restart` is required before you can continue publishing.
|
|
1601
|
+
*/ interrupt() {
|
|
1602
|
+
this.interrupted = true;
|
|
1603
|
+
this.interruptibleSleep.interrupt();
|
|
1604
|
+
this.l1TxUtils.interrupt();
|
|
1605
|
+
}
|
|
1606
|
+
/** Restarts the publisher after calling `interrupt`. */ restart() {
|
|
1607
|
+
this.interrupted = false;
|
|
1608
|
+
this.l1TxUtils.restart();
|
|
1609
|
+
}
|
|
1610
|
+
async prepareProposeTx(encodedData) {
|
|
1611
|
+
const kzg = Blob.getViemKzgInstance();
|
|
1612
|
+
const blobInput = getPrefixedEthBlobCommitments(encodedData.blobs);
|
|
1613
|
+
this.log.debug('Validating blob input', {
|
|
1614
|
+
blobInput
|
|
1615
|
+
});
|
|
1616
|
+
// Get blob evaluation gas
|
|
1617
|
+
let blobEvaluationGas;
|
|
1618
|
+
if (this.config.fishermanMode) {
|
|
1619
|
+
// In fisherman mode, we can't estimate blob gas because estimateGas doesn't support state overrides
|
|
1620
|
+
// Use a fixed estimate.
|
|
1621
|
+
blobEvaluationGas = BigInt(encodedData.blobs.length) * 21_000n;
|
|
1622
|
+
this.log.debug(`Using fixed blob evaluation gas estimate in fisherman mode: ${blobEvaluationGas}`);
|
|
1623
|
+
} else {
|
|
1624
|
+
// We call validateBlobs via estimateGas with real blob+kzg sidecars as a consistency check
|
|
1625
|
+
// that our locally-built blob commitments match the blob data. The bundle simulate at send
|
|
1626
|
+
// time uses eth_simulateV1, which cannot carry blob inputs, so the rollup's on-chain blob
|
|
1627
|
+
// check is forced off there — making this the only pre-flight detector of a commitment/data
|
|
1628
|
+
// mismatch. The returned gas estimate is stashed on the request for the bundle path to read.
|
|
1629
|
+
blobEvaluationGas = await this.l1TxUtils.estimateGas(this.getSenderAddress().toString(), {
|
|
1630
|
+
to: this.rollupContract.address,
|
|
1631
|
+
data: encodeFunctionData({
|
|
1632
|
+
abi: RollupAbi,
|
|
1633
|
+
functionName: 'validateBlobs',
|
|
1634
|
+
args: [
|
|
1635
|
+
blobInput
|
|
1636
|
+
]
|
|
1637
|
+
})
|
|
1638
|
+
}, {}, {
|
|
1639
|
+
blobs: encodedData.blobs.map((b)=>b.data),
|
|
1640
|
+
kzg
|
|
1641
|
+
}).catch(async (err)=>{
|
|
1642
|
+
const viemError = formatViemError(err);
|
|
1643
|
+
this.log.error(`Failed to validate blobs`, viemError.message, {
|
|
1644
|
+
metaMessages: viemError.metaMessages
|
|
1645
|
+
});
|
|
1646
|
+
const validateBlobsData = encodeFunctionData({
|
|
1647
|
+
abi: RollupAbi,
|
|
1648
|
+
functionName: 'validateBlobs',
|
|
1649
|
+
args: [
|
|
1650
|
+
blobInput
|
|
1651
|
+
]
|
|
1652
|
+
});
|
|
1653
|
+
const l1BlockNumber = await this.l1TxUtils.getBlockNumber();
|
|
1654
|
+
this.backupFailedTx({
|
|
1655
|
+
id: keccak256(validateBlobsData),
|
|
1656
|
+
failureType: 'simulation',
|
|
1657
|
+
request: {
|
|
1658
|
+
to: this.rollupContract.address,
|
|
1659
|
+
data: validateBlobsData
|
|
1660
|
+
},
|
|
1661
|
+
blobData: encodedData.blobs.map((b)=>toHex(b.data)),
|
|
1662
|
+
l1BlockNumber,
|
|
1663
|
+
error: {
|
|
1664
|
+
message: viemError.message,
|
|
1665
|
+
name: viemError.name
|
|
1666
|
+
},
|
|
1667
|
+
context: {
|
|
1668
|
+
actions: [
|
|
1669
|
+
'validate-blobs'
|
|
1670
|
+
],
|
|
1671
|
+
sender: this.getSenderAddress().toString()
|
|
1672
|
+
},
|
|
1673
|
+
timing: this.computeTimingInfo(this.getCurrentL2Slot())
|
|
1674
|
+
}, {
|
|
1675
|
+
captureFeeSummary: true,
|
|
1676
|
+
targetSlot: this.getCurrentL2Slot()
|
|
1677
|
+
});
|
|
1678
|
+
throw new Error('Failed to validate blobs');
|
|
1679
|
+
});
|
|
1680
|
+
}
|
|
1681
|
+
const signers = encodedData.attestationsAndSigners.getSigners().map((signer)=>signer.toString());
|
|
1682
|
+
const args = [
|
|
1683
|
+
{
|
|
1684
|
+
header: encodedData.header.toViem(),
|
|
1685
|
+
archive: toHex(encodedData.archive),
|
|
1686
|
+
oracleInput: {
|
|
1687
|
+
feeAssetPriceModifier: encodedData.feeAssetPriceModifier
|
|
1688
|
+
},
|
|
1689
|
+
bucketHint: encodedData.bucketHint
|
|
1690
|
+
},
|
|
1691
|
+
encodedData.attestationsAndSigners.getPackedAttestations(),
|
|
1692
|
+
signers,
|
|
1693
|
+
encodedData.attestationsAndSignersSignature.toViemSignature(),
|
|
1694
|
+
blobInput
|
|
1695
|
+
];
|
|
1696
|
+
const rollupData = encodeFunctionData({
|
|
1697
|
+
abi: RollupAbi,
|
|
1698
|
+
functionName: 'propose',
|
|
1699
|
+
args
|
|
1700
|
+
});
|
|
1701
|
+
return {
|
|
1702
|
+
args,
|
|
1703
|
+
blobEvaluationGas,
|
|
1704
|
+
rollupData
|
|
1705
|
+
};
|
|
1706
|
+
}
|
|
1707
|
+
async addProposeTx(checkpoint, encodedData, opts = {}) {
|
|
1708
|
+
const slot = checkpoint.header.slotNumber;
|
|
1709
|
+
const timer = new Timer();
|
|
1710
|
+
const kzg = Blob.getViemKzgInstance();
|
|
1711
|
+
const { rollupData, blobEvaluationGas } = await this.prepareProposeTx(encodedData);
|
|
1712
|
+
const startBlock = await this.l1TxUtils.getBlockNumber();
|
|
1713
|
+
// Send the blobs to the blob client preemptively. This helps in tests where the sequencer mistakingly thinks that the propose
|
|
1714
|
+
// tx fails but it does get mined. We make sure that the blobs are sent to the blob client regardless of the tx outcome.
|
|
1715
|
+
void Promise.resolve().then(()=>this.blobClient.sendBlobsToFilestore(encodedData.blobs).catch((_err)=>{
|
|
1716
|
+
this.log.error('Failed to send blobs to blob client');
|
|
1717
|
+
}));
|
|
1718
|
+
return this.addRequest({
|
|
1719
|
+
action: 'propose',
|
|
1720
|
+
request: {
|
|
1721
|
+
to: this.rollupContract.address,
|
|
1722
|
+
data: rollupData
|
|
1723
|
+
},
|
|
1724
|
+
lastValidL2Slot: checkpoint.header.slotNumber,
|
|
1725
|
+
gasConfig: {
|
|
1726
|
+
txTimeoutAt: opts.txTimeoutAt,
|
|
1727
|
+
gasLimit: undefined
|
|
1728
|
+
},
|
|
1729
|
+
blobEvaluationGas,
|
|
1730
|
+
blobConfig: {
|
|
1731
|
+
blobs: encodedData.blobs.map((b)=>b.data),
|
|
1732
|
+
kzg
|
|
1733
|
+
},
|
|
1734
|
+
checkSuccess: (_request, result)=>{
|
|
1735
|
+
if (!result) {
|
|
1736
|
+
return false;
|
|
1737
|
+
}
|
|
1738
|
+
const { receipt, stats, errorMsg } = result;
|
|
1739
|
+
const success = extractEventSuccess(receipt, {
|
|
1740
|
+
address: this.rollupContract.address,
|
|
1741
|
+
abi: RollupAbi,
|
|
1742
|
+
eventName: 'CheckpointProposed'
|
|
1743
|
+
});
|
|
1744
|
+
if (success) {
|
|
1745
|
+
const endBlock = receipt.blockNumber;
|
|
1746
|
+
const inclusionBlocks = Number(endBlock - startBlock);
|
|
1747
|
+
const { calldataGas, calldataSize, sender } = stats;
|
|
1748
|
+
const publishStats = {
|
|
1749
|
+
gasPrice: receipt.effectiveGasPrice,
|
|
1750
|
+
gasUsed: receipt.gasUsed,
|
|
1751
|
+
blobGasUsed: receipt.blobGasUsed ?? 0n,
|
|
1752
|
+
blobDataGas: receipt.blobGasPrice ?? 0n,
|
|
1753
|
+
transactionHash: receipt.transactionHash,
|
|
1754
|
+
calldataGas,
|
|
1755
|
+
calldataSize,
|
|
1756
|
+
sender,
|
|
1757
|
+
...checkpoint.getStats(),
|
|
1758
|
+
eventName: 'rollup-published-to-l1',
|
|
1759
|
+
blobCount: encodedData.blobs.length,
|
|
1760
|
+
inclusionBlocks
|
|
1761
|
+
};
|
|
1762
|
+
this.log.info(`Published checkpoint ${checkpoint.number} at slot ${slot} to rollup contract`, {
|
|
1763
|
+
...stats,
|
|
1764
|
+
...checkpoint.getStats(),
|
|
1765
|
+
...pick(receipt, 'transactionHash', 'blockHash')
|
|
1766
|
+
});
|
|
1767
|
+
this.metrics.recordProcessBlockTx(timer.ms(), publishStats);
|
|
1768
|
+
return true;
|
|
1769
|
+
} else {
|
|
1770
|
+
this.metrics.recordFailedTx('process');
|
|
1771
|
+
this.log.error(`Publishing checkpoint at slot ${slot} failed with ${errorMsg ?? 'no error message'}`, undefined, {
|
|
1772
|
+
...checkpoint.getStats(),
|
|
1773
|
+
...receipt
|
|
1774
|
+
});
|
|
1775
|
+
return false;
|
|
1776
|
+
}
|
|
1777
|
+
}
|
|
1778
|
+
});
|
|
1779
|
+
}
|
|
1780
|
+
/** Returns the timestamp of the next L1 slot boundary after now. */ getNextL1SlotTimestamp() {
|
|
1781
|
+
const l1Constants = this.epochCache.getL1Constants();
|
|
1782
|
+
return getNextL1SlotTimestamp(this.dateProvider.nowInSeconds(), l1Constants);
|
|
1783
|
+
}
|
|
1784
|
+
}
|