@aztec/sequencer-client 0.0.1-commit.d3ec352c → 0.0.1-commit.d58ff9d0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +281 -21
- package/dest/client/sequencer-client.d.ts +41 -18
- package/dest/client/sequencer-client.d.ts.map +1 -1
- package/dest/client/sequencer-client.js +88 -43
- package/dest/config.d.ts +41 -8
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +146 -55
- package/dest/global_variable_builder/fee_predictor.d.ts +37 -0
- package/dest/global_variable_builder/fee_predictor.d.ts.map +1 -0
- package/dest/global_variable_builder/fee_predictor.js +138 -0
- package/dest/global_variable_builder/fee_provider.d.ts +21 -0
- package/dest/global_variable_builder/fee_provider.d.ts.map +1 -0
- package/dest/global_variable_builder/fee_provider.js +80 -0
- package/dest/global_variable_builder/global_builder.d.ts +20 -26
- package/dest/global_variable_builder/global_builder.d.ts.map +1 -1
- package/dest/global_variable_builder/global_builder.js +28 -75
- package/dest/global_variable_builder/index.d.ts +4 -2
- package/dest/global_variable_builder/index.d.ts.map +1 -1
- package/dest/global_variable_builder/index.js +2 -0
- package/dest/index.d.ts +2 -3
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +1 -2
- package/dest/publisher/config.d.ts +57 -20
- package/dest/publisher/config.d.ts.map +1 -1
- package/dest/publisher/config.js +134 -39
- package/dest/publisher/index.d.ts +2 -1
- package/dest/publisher/index.d.ts.map +1 -1
- 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 +98 -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 +15 -8
- package/dest/publisher/sequencer-publisher-factory.d.ts.map +1 -1
- package/dest/publisher/sequencer-publisher-factory.js +28 -4
- package/dest/publisher/sequencer-publisher-metrics.d.ts +3 -3
- package/dest/publisher/sequencer-publisher-metrics.d.ts.map +1 -1
- package/dest/publisher/sequencer-publisher-metrics.js +23 -86
- package/dest/publisher/sequencer-publisher.d.ts +152 -90
- package/dest/publisher/sequencer-publisher.d.ts.map +1 -1
- package/dest/publisher/sequencer-publisher.js +1257 -421
- 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 +690 -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 +158 -0
- package/dest/sequencer/checkpoint_proposal_job.d.ts.map +1 -0
- package/dest/sequencer/checkpoint_proposal_job.js +1801 -0
- package/dest/sequencer/checkpoint_proposal_job_metrics.d.ts +34 -0
- package/dest/sequencer/checkpoint_proposal_job_metrics.d.ts.map +1 -0
- package/dest/sequencer/checkpoint_proposal_job_metrics.js +72 -0
- package/dest/sequencer/checkpoint_voter.d.ts +34 -0
- package/dest/sequencer/checkpoint_voter.d.ts.map +1 -0
- package/dest/sequencer/checkpoint_voter.js +106 -0
- package/dest/sequencer/config.d.ts +3 -2
- package/dest/sequencer/config.d.ts.map +1 -1
- package/dest/sequencer/events.d.ts +103 -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 +42 -7
- package/dest/sequencer/metrics.d.ts.map +1 -1
- package/dest/sequencer/metrics.js +241 -72
- 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 +251 -138
- package/dest/sequencer/sequencer.d.ts.map +1 -1
- package/dest/sequencer/sequencer.js +1190 -704
- package/dest/sequencer/types.d.ts +3 -0
- package/dest/sequencer/types.d.ts.map +1 -0
- package/dest/sequencer/types.js +1 -0
- package/dest/sequencer/utils.d.ts +14 -8
- package/dest/sequencer/utils.d.ts.map +1 -1
- package/dest/sequencer/utils.js +7 -4
- package/dest/test/index.d.ts +8 -9
- package/dest/test/index.d.ts.map +1 -1
- package/dest/test/mock_checkpoint_builder.d.ts +95 -0
- package/dest/test/mock_checkpoint_builder.d.ts.map +1 -0
- package/dest/test/mock_checkpoint_builder.js +231 -0
- package/dest/test/utils.d.ts +67 -0
- package/dest/test/utils.d.ts.map +1 -0
- package/dest/test/utils.js +122 -0
- package/package.json +32 -29
- package/src/client/sequencer-client.ts +118 -66
- package/src/config.ts +173 -64
- package/src/global_variable_builder/README.md +44 -0
- package/src/global_variable_builder/fee_predictor.ts +182 -0
- package/src/global_variable_builder/fee_provider.ts +97 -0
- package/src/global_variable_builder/global_builder.ts +45 -110
- package/src/global_variable_builder/index.ts +3 -1
- package/src/index.ts +1 -7
- package/src/publisher/config.ts +182 -46
- package/src/publisher/index.ts +3 -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 +164 -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 +254 -0
- package/src/publisher/sequencer-publisher-factory.ts +43 -13
- package/src/publisher/sequencer-publisher-metrics.ts +19 -71
- package/src/publisher/sequencer-publisher.ts +1042 -542
- package/src/publisher/write_json.ts +78 -0
- package/src/sequencer/README.md +243 -0
- package/src/sequencer/automine/README.md +60 -0
- package/src/sequencer/automine/automine_factory.ts +152 -0
- package/src/sequencer/automine/automine_sequencer.ts +796 -0
- package/src/sequencer/automine/index.ts +6 -0
- package/src/sequencer/checkpoint_proposal_job.ts +1652 -0
- package/src/sequencer/checkpoint_proposal_job_metrics.ts +128 -0
- package/src/sequencer/checkpoint_voter.ts +119 -0
- package/src/sequencer/config.ts +2 -1
- package/src/sequencer/events.ts +88 -0
- package/src/sequencer/index.ts +3 -1
- package/src/sequencer/metrics.ts +302 -83
- package/src/sequencer/requests_tracker.ts +43 -0
- package/src/sequencer/sequencer.ts +1011 -898
- package/src/sequencer/types.ts +6 -0
- package/src/sequencer/utils.ts +18 -9
- package/src/test/index.ts +7 -8
- package/src/test/mock_checkpoint_builder.ts +323 -0
- package/src/test/utils.ts +218 -0
- package/dest/sequencer/block_builder.d.ts +0 -28
- package/dest/sequencer/block_builder.d.ts.map +0 -1
- package/dest/sequencer/block_builder.js +0 -134
- package/dest/sequencer/timetable.d.ts +0 -50
- package/dest/sequencer/timetable.d.ts.map +0 -1
- package/dest/sequencer/timetable.js +0 -137
- package/dest/tx_validator/nullifier_cache.d.ts +0 -14
- package/dest/tx_validator/nullifier_cache.d.ts.map +0 -1
- package/dest/tx_validator/nullifier_cache.js +0 -24
- package/dest/tx_validator/tx_validator_factory.d.ts +0 -18
- package/dest/tx_validator/tx_validator_factory.d.ts.map +0 -1
- package/dest/tx_validator/tx_validator_factory.js +0 -53
- package/src/sequencer/block_builder.ts +0 -222
- package/src/sequencer/timetable.ts +0 -188
- package/src/tx_validator/nullifier_cache.ts +0 -30
- package/src/tx_validator/tx_validator_factory.ts +0 -133
|
@@ -1,76 +1,493 @@
|
|
|
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;
|
|
1
374
|
import { Blob, getBlobsPerL1Block, getPrefixedEthBlobCommitments } from '@aztec/blob-lib';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
375
|
+
import { FeeAssetPriceOracle, MULTI_CALL_3_ADDRESS, Multicall3, MulticallForwarderRevertedError, buildSimulationOverridesStateOverride } from '@aztec/ethereum/contracts';
|
|
376
|
+
import { L1FeeAnalyzer, captureWindowBlockFees } from '@aztec/ethereum/l1-fee-analysis';
|
|
377
|
+
import { L1TxTimeoutError, MAX_L1_TX_LIMIT, WEI_CONST } from '@aztec/ethereum/l1-tx-utils';
|
|
378
|
+
import { FormattedViemError, formatViemError, mergeAbis, tryDecodeRevertReason, tryExtractEvent } from '@aztec/ethereum/utils';
|
|
379
|
+
import { CheckpointNumber, SlotNumber } from '@aztec/foundation/branded-types';
|
|
380
|
+
import { trimmedBytesLength } from '@aztec/foundation/buffer';
|
|
381
|
+
import { pick } from '@aztec/foundation/collection';
|
|
382
|
+
import { TimeoutError } from '@aztec/foundation/error';
|
|
7
383
|
import { EthAddress } from '@aztec/foundation/eth-address';
|
|
8
384
|
import { Signature } from '@aztec/foundation/eth-signature';
|
|
9
385
|
import { createLogger } from '@aztec/foundation/log';
|
|
386
|
+
import { InterruptibleSleep } from '@aztec/foundation/sleep';
|
|
10
387
|
import { bufferToHex } from '@aztec/foundation/string';
|
|
11
388
|
import { Timer } from '@aztec/foundation/timer';
|
|
12
|
-
import { EmpireBaseAbi, ErrorsAbi, RollupAbi } from '@aztec/l1-artifacts';
|
|
389
|
+
import { EmpireBaseAbi, ErrorsAbi, RollupAbi, SlashingProposerAbi } from '@aztec/l1-artifacts';
|
|
13
390
|
import { encodeSlashConsensusVotes } from '@aztec/slasher';
|
|
14
|
-
import {
|
|
15
|
-
import {
|
|
16
|
-
import {
|
|
391
|
+
import { CommitteeAttestationsAndSigners } from '@aztec/stdlib/block';
|
|
392
|
+
import { getLastL1SlotTimestampForL2Slot, getNextL1SlotTimestamp, getTimestampForSlot } from '@aztec/stdlib/epoch-helpers';
|
|
393
|
+
import { getTelemetryClient, trackSpan } from '@aztec/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';
|
|
17
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
|
+
}
|
|
18
408
|
export const Actions = [
|
|
19
409
|
'invalidate-by-invalid-attestation',
|
|
20
410
|
'invalidate-by-insufficient-attestations',
|
|
411
|
+
'prune',
|
|
21
412
|
'propose',
|
|
22
413
|
'governance-signal',
|
|
23
|
-
'empire-slashing-signal',
|
|
24
|
-
'create-empire-payload',
|
|
25
|
-
'execute-empire-payload',
|
|
26
414
|
'vote-offenses',
|
|
27
415
|
'execute-slash'
|
|
28
416
|
];
|
|
29
417
|
// Sorting for actions such that invalidations go before proposals, and proposals go before votes
|
|
30
418
|
export const compareActions = (a, b)=>Actions.indexOf(a) - Actions.indexOf(b);
|
|
419
|
+
_dec = trackSpan('SequencerPublisher.sendRequests'), _dec1 = trackSpan('SequencerPublisher.validateBlockHeader');
|
|
31
420
|
export class SequencerPublisher {
|
|
32
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
|
+
"validateBlockHeader"
|
|
433
|
+
]
|
|
434
|
+
], []));
|
|
435
|
+
}
|
|
33
436
|
interrupted;
|
|
34
437
|
metrics;
|
|
438
|
+
bundleSimulator;
|
|
35
439
|
epochCache;
|
|
36
|
-
|
|
37
|
-
|
|
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;
|
|
38
446
|
lastActions;
|
|
39
447
|
log;
|
|
40
448
|
ethereumSlotDuration;
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
static VOTE_GAS_GUESS = 800_000n;
|
|
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;
|
|
51
458
|
l1TxUtils;
|
|
52
459
|
rollupContract;
|
|
53
460
|
govProposerContract;
|
|
54
461
|
slashingProposerContract;
|
|
55
|
-
|
|
462
|
+
tracer;
|
|
56
463
|
requests;
|
|
57
464
|
constructor(config, deps){
|
|
58
465
|
this.config = config;
|
|
59
|
-
this.interrupted = false;
|
|
60
|
-
this.
|
|
61
|
-
|
|
466
|
+
this.interrupted = (_initProto(this), false);
|
|
467
|
+
this.revertDecoderAbi = mergeAbis([
|
|
468
|
+
RollupAbi,
|
|
469
|
+
SlashingProposerAbi,
|
|
470
|
+
EmpireBaseAbi,
|
|
471
|
+
ErrorsAbi
|
|
472
|
+
]);
|
|
62
473
|
this.lastActions = {};
|
|
474
|
+
this.interruptibleSleep = new InterruptibleSleep();
|
|
63
475
|
this.requests = [];
|
|
64
476
|
this.log = deps.log ?? createLogger('sequencer:publisher');
|
|
65
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;
|
|
66
482
|
this.epochCache = deps.epochCache;
|
|
67
483
|
this.lastActions = deps.lastActions;
|
|
68
|
-
this.
|
|
69
|
-
|
|
70
|
-
});
|
|
484
|
+
this.blobClient = deps.blobClient;
|
|
485
|
+
this.dateProvider = deps.dateProvider;
|
|
71
486
|
const telemetry = deps.telemetry ?? getTelemetryClient();
|
|
72
487
|
this.metrics = deps.metrics ?? new SequencerPublisherMetrics(telemetry, 'SequencerPublisher');
|
|
488
|
+
this.tracer = telemetry.getTracer('SequencerPublisher');
|
|
73
489
|
this.l1TxUtils = deps.l1TxUtils;
|
|
490
|
+
this.getNextPublisher = deps.getNextPublisher;
|
|
74
491
|
this.rollupContract = deps.rollupContract;
|
|
75
492
|
this.govProposerContract = deps.governanceProposerContract;
|
|
76
493
|
this.slashingProposerContract = deps.slashingProposerContract;
|
|
@@ -79,25 +496,130 @@ export class SequencerPublisher {
|
|
|
79
496
|
const newSlashingProposer = await this.rollupContract.getSlashingProposer();
|
|
80
497
|
this.slashingProposerContract = newSlashingProposer;
|
|
81
498
|
});
|
|
82
|
-
|
|
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()}`));
|
|
83
596
|
}
|
|
84
597
|
getRollupContract() {
|
|
85
598
|
return this.rollupContract;
|
|
86
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
|
+
}
|
|
87
610
|
getSenderAddress() {
|
|
88
611
|
return this.l1TxUtils.getSenderAddress();
|
|
89
612
|
}
|
|
90
613
|
/**
|
|
91
|
-
*
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
this.proposerAddressForSimulation = proposerAddress;
|
|
614
|
+
* Gets the L1 fee analyzer instance (only available in fisherman mode)
|
|
615
|
+
*/ getL1FeeAnalyzer() {
|
|
616
|
+
return this.l1FeeAnalyzer;
|
|
95
617
|
}
|
|
96
618
|
addRequest(request) {
|
|
97
619
|
this.requests.push(request);
|
|
98
620
|
}
|
|
99
621
|
getCurrentL2Slot() {
|
|
100
|
-
return this.epochCache.
|
|
622
|
+
return this.epochCache.getSlotNow();
|
|
101
623
|
}
|
|
102
624
|
/**
|
|
103
625
|
* Clears all pending requests without sending them.
|
|
@@ -109,23 +631,66 @@ export class SequencerPublisher {
|
|
|
109
631
|
}
|
|
110
632
|
}
|
|
111
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
|
+
/**
|
|
112
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.
|
|
113
679
|
* @returns one of:
|
|
114
680
|
* - A receipt and stats if the tx succeeded
|
|
115
681
|
* - a receipt and errorMsg if it failed on L1
|
|
116
682
|
* - undefined if no valid requests are found OR the tx failed to send.
|
|
117
|
-
*/ async sendRequests() {
|
|
683
|
+
*/ async sendRequests(targetSlot) {
|
|
118
684
|
const requestsToProcess = [
|
|
119
685
|
...this.requests
|
|
120
686
|
];
|
|
121
687
|
this.requests = [];
|
|
122
|
-
if (this.interrupted) {
|
|
688
|
+
if (this.interrupted || requestsToProcess.length === 0) {
|
|
123
689
|
return undefined;
|
|
124
690
|
}
|
|
125
|
-
const currentL2Slot = this.getCurrentL2Slot();
|
|
691
|
+
const currentL2Slot = targetSlot ?? this.getCurrentL2Slot();
|
|
126
692
|
this.log.debug(`Sending requests on L2 slot ${currentL2Slot}`);
|
|
127
693
|
const validRequests = requestsToProcess.filter((request)=>request.lastValidL2Slot >= currentL2Slot);
|
|
128
|
-
const validActions = validRequests.map((x)=>x.action);
|
|
129
694
|
const expiredActions = requestsToProcess.filter((request)=>request.lastValidL2Slot < currentL2Slot).map((x)=>x.action);
|
|
130
695
|
if (validRequests.length !== requestsToProcess.length) {
|
|
131
696
|
this.log.warn(`Some requests were expired for slot ${currentL2Slot}`, {
|
|
@@ -143,44 +708,98 @@ export class SequencerPublisher {
|
|
|
143
708
|
this.log.debug(`No valid requests to send`);
|
|
144
709
|
return undefined;
|
|
145
710
|
}
|
|
146
|
-
//
|
|
147
|
-
|
|
148
|
-
// See https://github.com/AztecProtocol/aztec-packages/issues/11513
|
|
149
|
-
const gasConfigs = requestsToProcess.filter((request)=>request.gasConfig).map((request)=>request.gasConfig);
|
|
150
|
-
const blobConfigs = requestsToProcess.filter((request)=>request.blobConfig).map((request)=>request.blobConfig);
|
|
151
|
-
if (blobConfigs.length > 1) {
|
|
152
|
-
throw new Error('Multiple blob configs found');
|
|
153
|
-
}
|
|
154
|
-
const blobConfig = blobConfigs[0];
|
|
155
|
-
// Merge gasConfigs. Yields the sum of gasLimits, and the earliest txTimeoutAt, or undefined if no gasConfig sets them.
|
|
156
|
-
const gasLimits = gasConfigs.map((g)=>g?.gasLimit).filter((g)=>g !== undefined);
|
|
157
|
-
const gasLimit = gasLimits.length > 0 ? sumBigint(gasLimits) : undefined; // sum
|
|
711
|
+
// Collect earliest txTimeoutAt across all requests.
|
|
712
|
+
const gasConfigs = validRequests.filter((request)=>request.gasConfig).map((request)=>request.gasConfig);
|
|
158
713
|
const txTimeoutAts = gasConfigs.map((g)=>g?.txTimeoutAt).filter((g)=>g !== undefined);
|
|
159
|
-
const txTimeoutAt = txTimeoutAts.length > 0 ? new Date(Math.min(...txTimeoutAts.map((g)=>g.getTime()))) : undefined;
|
|
160
|
-
const txConfig = {
|
|
161
|
-
gasLimit,
|
|
162
|
-
txTimeoutAt
|
|
163
|
-
};
|
|
714
|
+
const txTimeoutAt = txTimeoutAts.length > 0 ? new Date(Math.min(...txTimeoutAts.map((g)=>g.getTime()))) : undefined;
|
|
164
715
|
// Sort the requests so that proposals always go first
|
|
165
716
|
// This ensures the committee gets precomputed correctly
|
|
166
717
|
validRequests.sort((a, b)=>compareActions(a.action, b.action));
|
|
167
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
|
+
};
|
|
168
739
|
this.log.debug('Forwarding transactions', {
|
|
169
|
-
|
|
740
|
+
requests: requests.map((request)=>request.action),
|
|
170
741
|
txConfig
|
|
171
742
|
});
|
|
172
|
-
const result = await
|
|
173
|
-
|
|
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
|
+
];
|
|
174
752
|
return {
|
|
175
753
|
result,
|
|
176
754
|
expiredActions,
|
|
177
|
-
sentActions:
|
|
755
|
+
sentActions: requests.map((x)=>x.action),
|
|
178
756
|
successfulActions,
|
|
179
|
-
failedActions
|
|
757
|
+
failedActions: allFailedActions
|
|
180
758
|
};
|
|
181
759
|
} catch (err) {
|
|
182
760
|
const viemError = formatViemError(err);
|
|
183
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
|
+
sentGasPriceLadder: timeoutState.gasPriceHistory,
|
|
793
|
+
attempts: timeoutState.attempts,
|
|
794
|
+
gasLimit: timeoutState.gasLimit,
|
|
795
|
+
nonce: timeoutState.nonce
|
|
796
|
+
} : undefined
|
|
797
|
+
}, {
|
|
798
|
+
captureFeeSummary: true,
|
|
799
|
+
targetSlot: currentL2Slot
|
|
800
|
+
});
|
|
801
|
+
})();
|
|
802
|
+
}
|
|
184
803
|
return undefined;
|
|
185
804
|
} finally{
|
|
186
805
|
try {
|
|
@@ -190,49 +809,302 @@ export class SequencerPublisher {
|
|
|
190
809
|
}
|
|
191
810
|
}
|
|
192
811
|
}
|
|
193
|
-
|
|
194
|
-
const
|
|
195
|
-
|
|
196
|
-
this.log.
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
this.log.verbose(`Published bundled transactions (${actionsListStr})`, {
|
|
202
|
-
result,
|
|
203
|
-
requests
|
|
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
|
|
204
820
|
});
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
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;
|
|
212
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;
|
|
213
916
|
}
|
|
214
|
-
return {
|
|
215
|
-
successfulActions,
|
|
216
|
-
failedActions
|
|
217
|
-
};
|
|
218
917
|
}
|
|
219
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
|
+
sentGasPrice: err.txState.gasPrice,
|
|
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
|
+
}
|
|
220
1000
|
/**
|
|
221
|
-
*
|
|
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
|
|
222
1090
|
* @param tipArchive - The archive to check
|
|
223
1091
|
* @returns The slot and block number if it is possible to propose, undefined otherwise
|
|
224
|
-
*/
|
|
1092
|
+
*/ async canProposeAt(tipArchive, msgSender, simulationOverridesPlan) {
|
|
225
1093
|
// TODO: #14291 - should loop through multiple keys to check if any of them can propose
|
|
226
|
-
|
|
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 = [
|
|
227
1099
|
'SlotAlreadyInChain',
|
|
228
1100
|
'InvalidProposer',
|
|
229
1101
|
'InvalidArchive'
|
|
230
1102
|
];
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
if (err instanceof FormattedViemError &&
|
|
235
|
-
this.log.warn(`Failed canProposeAtTime check with ${
|
|
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))}`, {
|
|
236
1108
|
error: err.message
|
|
237
1109
|
});
|
|
238
1110
|
} else {
|
|
@@ -246,23 +1118,23 @@ export class SequencerPublisher {
|
|
|
246
1118
|
* @dev This is a convenience function that can be used by the sequencer to validate a "partial" header.
|
|
247
1119
|
* It will throw if the block header is invalid.
|
|
248
1120
|
* @param header - The block header to validate
|
|
249
|
-
*/ async validateBlockHeader(header,
|
|
1121
|
+
*/ async validateBlockHeader(header, simulationOverridesPlan) {
|
|
250
1122
|
const flags = {
|
|
251
1123
|
ignoreDA: true,
|
|
252
1124
|
ignoreSignatures: true
|
|
253
1125
|
};
|
|
254
1126
|
const args = [
|
|
255
1127
|
header.toViem(),
|
|
256
|
-
CommitteeAttestationsAndSigners.
|
|
1128
|
+
CommitteeAttestationsAndSigners.packAttestations([]),
|
|
257
1129
|
[],
|
|
258
1130
|
Signature.empty().toViemSignature(),
|
|
259
1131
|
`0x${'0'.repeat(64)}`,
|
|
260
|
-
header.
|
|
1132
|
+
header.blobsHash.toString(),
|
|
261
1133
|
flags
|
|
262
1134
|
];
|
|
263
|
-
const
|
|
264
|
-
const
|
|
265
|
-
const stateOverrides = await this.rollupContract
|
|
1135
|
+
const l1Constants = this.epochCache.getL1Constants();
|
|
1136
|
+
const ts = getLastL1SlotTimestampForL2Slot(header.slotNumber, l1Constants);
|
|
1137
|
+
const stateOverrides = await buildSimulationOverridesStateOverride(this.rollupContract, simulationOverridesPlan);
|
|
266
1138
|
let balance = 0n;
|
|
267
1139
|
if (this.config.fishermanMode) {
|
|
268
1140
|
// In fisherman mode, we can't know where the proposer is publishing from
|
|
@@ -284,39 +1156,43 @@ export class SequencerPublisher {
|
|
|
284
1156
|
}),
|
|
285
1157
|
from: MULTI_CALL_3_ADDRESS
|
|
286
1158
|
}, {
|
|
287
|
-
time: ts
|
|
1159
|
+
time: ts
|
|
288
1160
|
}, stateOverrides);
|
|
289
1161
|
this.log.debug(`Simulated validateHeader`);
|
|
290
1162
|
}
|
|
291
1163
|
/**
|
|
292
|
-
* Simulate making a call to invalidate a
|
|
293
|
-
* @param
|
|
294
|
-
*/ async
|
|
1164
|
+
* Simulate making a call to invalidate a checkpoint with invalid attestations. Returns undefined if no need to invalidate.
|
|
1165
|
+
* @param validationResult - The validation result indicating which checkpoint to invalidate (as returned by the archiver)
|
|
1166
|
+
*/ async simulateInvalidateCheckpoint(validationResult) {
|
|
295
1167
|
if (validationResult.valid) {
|
|
296
1168
|
return undefined;
|
|
297
1169
|
}
|
|
298
|
-
const { reason,
|
|
299
|
-
const
|
|
1170
|
+
const { reason, checkpoint } = validationResult;
|
|
1171
|
+
const checkpointNumber = checkpoint.checkpointNumber;
|
|
300
1172
|
const logData = {
|
|
301
|
-
...
|
|
1173
|
+
...checkpoint,
|
|
302
1174
|
reason
|
|
303
1175
|
};
|
|
304
|
-
const
|
|
305
|
-
if (
|
|
306
|
-
this.log.verbose(`Skipping
|
|
307
|
-
|
|
1176
|
+
const currentCheckpointNumber = await this.rollupContract.getCheckpointNumber();
|
|
1177
|
+
if (currentCheckpointNumber < checkpointNumber) {
|
|
1178
|
+
this.log.verbose(`Skipping checkpoint ${checkpointNumber} invalidation since it has already been removed from the pending chain`, {
|
|
1179
|
+
currentCheckpointNumber,
|
|
308
1180
|
...logData
|
|
309
1181
|
});
|
|
310
1182
|
return undefined;
|
|
311
1183
|
}
|
|
312
|
-
const request = this.
|
|
313
|
-
this.log.debug(`Simulating invalidate
|
|
1184
|
+
const request = this.buildInvalidateCheckpointRequest(validationResult);
|
|
1185
|
+
this.log.debug(`Simulating invalidate checkpoint ${checkpointNumber}`, {
|
|
314
1186
|
...logData,
|
|
315
1187
|
request
|
|
316
1188
|
});
|
|
1189
|
+
const l1BlockNumber = await this.l1TxUtils.getBlockNumber();
|
|
317
1190
|
try {
|
|
318
|
-
const { gasUsed } = await this.l1TxUtils.simulate(request, undefined, undefined,
|
|
319
|
-
|
|
1191
|
+
const { gasUsed } = await this.l1TxUtils.simulate(request, undefined, undefined, mergeAbis([
|
|
1192
|
+
request.abi ?? [],
|
|
1193
|
+
ErrorsAbi
|
|
1194
|
+
]));
|
|
1195
|
+
this.log.verbose(`Simulation for invalidate checkpoint ${checkpointNumber} succeeded`, {
|
|
320
1196
|
...logData,
|
|
321
1197
|
request,
|
|
322
1198
|
gasUsed
|
|
@@ -324,101 +1200,91 @@ export class SequencerPublisher {
|
|
|
324
1200
|
return {
|
|
325
1201
|
request,
|
|
326
1202
|
gasUsed,
|
|
327
|
-
|
|
328
|
-
|
|
1203
|
+
checkpointNumber,
|
|
1204
|
+
forcePendingCheckpointNumber: CheckpointNumber(checkpointNumber - 1),
|
|
1205
|
+
lastArchive: validationResult.checkpoint.lastArchive,
|
|
329
1206
|
reason
|
|
330
1207
|
};
|
|
331
1208
|
} catch (err) {
|
|
332
1209
|
const viemError = formatViemError(err);
|
|
333
|
-
// If the error is due to the
|
|
334
|
-
// we can safely ignore it and return undefined so we go ahead with
|
|
335
|
-
if (viemError.message?.includes('
|
|
336
|
-
this.log.verbose(`Simulation for invalidate
|
|
1210
|
+
// If the error is due to the checkpoint not being in the pending chain, and it was indeed removed by someone else,
|
|
1211
|
+
// we can safely ignore it and return undefined so we go ahead with checkpoint building.
|
|
1212
|
+
if (viemError.message?.includes('Rollup__CheckpointNotInPendingChain')) {
|
|
1213
|
+
this.log.verbose(`Simulation for invalidate checkpoint ${checkpointNumber} failed due to checkpoint not being in pending chain`, {
|
|
337
1214
|
...logData,
|
|
338
1215
|
request,
|
|
339
1216
|
error: viemError.message
|
|
340
1217
|
});
|
|
341
|
-
const
|
|
342
|
-
if (
|
|
343
|
-
this.log.verbose(`
|
|
1218
|
+
const latestProposedCheckpointNumber = await this.rollupContract.getCheckpointNumber();
|
|
1219
|
+
if (latestProposedCheckpointNumber < checkpointNumber) {
|
|
1220
|
+
this.log.verbose(`Checkpoint ${checkpointNumber} has already been invalidated`, {
|
|
344
1221
|
...logData
|
|
345
1222
|
});
|
|
346
1223
|
return undefined;
|
|
347
1224
|
} else {
|
|
348
|
-
this.log.error(`Simulation for invalidate ${
|
|
349
|
-
throw new Error(`Failed to simulate invalidate
|
|
1225
|
+
this.log.error(`Simulation for invalidate checkpoint ${checkpointNumber} failed and it is still in pending chain`, viemError, logData);
|
|
1226
|
+
throw new Error(`Failed to simulate invalidate checkpoint ${checkpointNumber} while it is still in pending chain`, {
|
|
350
1227
|
cause: viemError
|
|
351
1228
|
});
|
|
352
1229
|
}
|
|
353
1230
|
}
|
|
354
|
-
// Otherwise, throw. We cannot build the next
|
|
355
|
-
this.log.error(`Simulation for invalidate
|
|
356
|
-
|
|
1231
|
+
// Otherwise, throw. We cannot build the next checkpoint if we cannot invalidate the previous one.
|
|
1232
|
+
this.log.error(`Simulation for invalidate checkpoint ${checkpointNumber} failed`, viemError, logData);
|
|
1233
|
+
this.backupFailedTx({
|
|
1234
|
+
id: keccak256(request.data),
|
|
1235
|
+
failureType: 'simulation',
|
|
1236
|
+
request: {
|
|
1237
|
+
to: request.to,
|
|
1238
|
+
data: request.data,
|
|
1239
|
+
value: request.value
|
|
1240
|
+
},
|
|
1241
|
+
l1BlockNumber,
|
|
1242
|
+
error: {
|
|
1243
|
+
message: viemError.message,
|
|
1244
|
+
name: viemError.name
|
|
1245
|
+
},
|
|
1246
|
+
context: {
|
|
1247
|
+
actions: [
|
|
1248
|
+
`invalidate-${reason}`
|
|
1249
|
+
],
|
|
1250
|
+
checkpointNumber,
|
|
1251
|
+
sender: this.getSenderAddress().toString()
|
|
1252
|
+
},
|
|
1253
|
+
timing: this.computeTimingInfo(this.getCurrentL2Slot())
|
|
1254
|
+
}, {
|
|
1255
|
+
captureFeeSummary: true,
|
|
1256
|
+
targetSlot: this.getCurrentL2Slot()
|
|
1257
|
+
});
|
|
1258
|
+
throw new Error(`Failed to simulate invalidate checkpoint ${checkpointNumber}`, {
|
|
357
1259
|
cause: viemError
|
|
358
1260
|
});
|
|
359
1261
|
}
|
|
360
1262
|
}
|
|
361
|
-
|
|
1263
|
+
buildInvalidateCheckpointRequest(validationResult) {
|
|
362
1264
|
if (validationResult.valid) {
|
|
363
|
-
throw new Error('Cannot invalidate a valid
|
|
1265
|
+
throw new Error('Cannot invalidate a valid checkpoint');
|
|
364
1266
|
}
|
|
365
|
-
const {
|
|
1267
|
+
const { checkpoint, committee, reason } = validationResult;
|
|
366
1268
|
const logData = {
|
|
367
|
-
...
|
|
1269
|
+
...checkpoint,
|
|
368
1270
|
reason
|
|
369
1271
|
};
|
|
370
|
-
this.log.debug(`
|
|
371
|
-
|
|
1272
|
+
this.log.debug(`Building invalidate checkpoint ${checkpoint.checkpointNumber} request`, logData);
|
|
1273
|
+
// Use the exact packed tuple posted to L1 verbatim. A repack via `packAttestations` is not a
|
|
1274
|
+
// byte-faithful inverse of `fromPacked` (a canonicalized yParity byte or an all-zero signature slot
|
|
1275
|
+
// round-trips differently), so it would diverge from the stored `attestationsHash` and revert the
|
|
1276
|
+
// invalidation.
|
|
1277
|
+
const attestationsAndSigners = validationResult.verbatimAttestations;
|
|
372
1278
|
if (reason === 'invalid-attestation') {
|
|
373
|
-
return this.rollupContract.buildInvalidateBadAttestationRequest(
|
|
1279
|
+
return this.rollupContract.buildInvalidateBadAttestationRequest(checkpoint.checkpointNumber, attestationsAndSigners, committee, validationResult.invalidIndex);
|
|
374
1280
|
} else if (reason === 'insufficient-attestations') {
|
|
375
|
-
return this.rollupContract.buildInvalidateInsufficientAttestationsRequest(
|
|
1281
|
+
return this.rollupContract.buildInvalidateInsufficientAttestationsRequest(checkpoint.checkpointNumber, attestationsAndSigners, committee);
|
|
376
1282
|
} else {
|
|
377
1283
|
const _ = reason;
|
|
378
1284
|
throw new Error(`Unknown reason for invalidation`);
|
|
379
1285
|
}
|
|
380
1286
|
}
|
|
381
|
-
|
|
382
|
-
* @notice Will simulate `propose` to make sure that the block is valid for submission
|
|
383
|
-
*
|
|
384
|
-
* @dev Throws if unable to propose
|
|
385
|
-
*
|
|
386
|
-
* @param block - The block to propose
|
|
387
|
-
* @param attestationData - The block's attestation data
|
|
388
|
-
*
|
|
389
|
-
*/ async validateBlockForSubmission(block, attestationsAndSigners, attestationsAndSignersSignature, options) {
|
|
390
|
-
const ts = BigInt((await this.l1TxUtils.getBlock()).timestamp + this.ethereumSlotDuration);
|
|
391
|
-
// If we have no attestations, we still need to provide the empty attestations
|
|
392
|
-
// so that the committee is recalculated correctly
|
|
393
|
-
const ignoreSignatures = attestationsAndSigners.attestations.length === 0;
|
|
394
|
-
if (ignoreSignatures) {
|
|
395
|
-
const { committee } = await this.epochCache.getCommittee(block.header.globalVariables.slotNumber);
|
|
396
|
-
if (!committee) {
|
|
397
|
-
this.log.warn(`No committee found for slot ${block.header.globalVariables.slotNumber}`);
|
|
398
|
-
throw new Error(`No committee found for slot ${block.header.globalVariables.slotNumber}`);
|
|
399
|
-
}
|
|
400
|
-
attestationsAndSigners.attestations = committee.map((committeeMember)=>CommitteeAttestation.fromAddress(committeeMember));
|
|
401
|
-
}
|
|
402
|
-
const blobFields = block.getCheckpointBlobFields();
|
|
403
|
-
const blobs = getBlobsPerL1Block(blobFields);
|
|
404
|
-
const blobInput = getPrefixedEthBlobCommitments(blobs);
|
|
405
|
-
const args = [
|
|
406
|
-
{
|
|
407
|
-
header: block.getCheckpointHeader().toViem(),
|
|
408
|
-
archive: toHex(block.archive.root.toBuffer()),
|
|
409
|
-
oracleInput: {
|
|
410
|
-
feeAssetPriceModifier: 0n
|
|
411
|
-
}
|
|
412
|
-
},
|
|
413
|
-
attestationsAndSigners.getPackedAttestations(),
|
|
414
|
-
attestationsAndSigners.getSigners().map((signer)=>signer.toString()),
|
|
415
|
-
attestationsAndSignersSignature.toViemSignature(),
|
|
416
|
-
blobInput
|
|
417
|
-
];
|
|
418
|
-
await this.simulateProposeTx(args, ts, options);
|
|
419
|
-
return ts;
|
|
420
|
-
}
|
|
421
|
-
async enqueueCastSignalHelper(slotNumber, timestamp, signalType, payload, base, signerAddress, signer) {
|
|
1287
|
+
async enqueueCastSignalHelper(slotNumber, signalType, payload, base, signerAddress, signer) {
|
|
422
1288
|
if (this.lastActions[signalType] && this.lastActions[signalType] === slotNumber) {
|
|
423
1289
|
this.log.debug(`Skipping duplicate vote cast signal ${signalType} for slot ${slotNumber}`);
|
|
424
1290
|
return false;
|
|
@@ -432,9 +1298,34 @@ export class SequencerPublisher {
|
|
|
432
1298
|
}
|
|
433
1299
|
const round = await base.computeRound(slotNumber);
|
|
434
1300
|
const roundInfo = await base.getRoundInfo(this.rollupContract.address, round);
|
|
1301
|
+
if (roundInfo.quorumReached) {
|
|
1302
|
+
return false;
|
|
1303
|
+
}
|
|
435
1304
|
if (roundInfo.lastSignalSlot >= slotNumber) {
|
|
436
1305
|
return false;
|
|
437
1306
|
}
|
|
1307
|
+
if (await base.isPayloadEmpty(payload)) {
|
|
1308
|
+
this.log.warn(`Skipping vote cast for payload with empty code`);
|
|
1309
|
+
return false;
|
|
1310
|
+
}
|
|
1311
|
+
// Skip signaling if there is already a live (non-terminal) Governance proposal for this
|
|
1312
|
+
// payload. This is intentionally not cached: a previously-live proposal may transition to
|
|
1313
|
+
// a terminal state (Dropped/Rejected/Expired/Executed), at which point we may want to re-signal
|
|
1314
|
+
// the same payload in a future round.
|
|
1315
|
+
let proposed = false;
|
|
1316
|
+
try {
|
|
1317
|
+
proposed = await base.hasActiveProposalWithPayload(payload.toString());
|
|
1318
|
+
} catch (err) {
|
|
1319
|
+
// We deliberately swallow the error and proceed to signal. Failing closed (skipping the
|
|
1320
|
+
// signal) on transient RPC errors would let a flaky L1 endpoint silence governance
|
|
1321
|
+
// participation entirely; failing open at worst produces a duplicate signal that the
|
|
1322
|
+
// contract will simply count alongside others in the round.
|
|
1323
|
+
this.log.error(`Failed to check if payload ${payload} was already proposed (signalling anyway)`, err);
|
|
1324
|
+
}
|
|
1325
|
+
if (proposed) {
|
|
1326
|
+
this.log.info(`Payload ${payload} has a live governance proposal, stopping signals`);
|
|
1327
|
+
return false;
|
|
1328
|
+
}
|
|
438
1329
|
const cachedLastVote = this.lastActions[signalType];
|
|
439
1330
|
this.lastActions[signalType] = slotNumber;
|
|
440
1331
|
const action = signalType;
|
|
@@ -445,27 +1336,17 @@ export class SequencerPublisher {
|
|
|
445
1336
|
signer: this.l1TxUtils.client.account?.address,
|
|
446
1337
|
lastValidL2Slot: slotNumber
|
|
447
1338
|
});
|
|
448
|
-
try {
|
|
449
|
-
await this.l1TxUtils.simulate(request, {
|
|
450
|
-
time: timestamp
|
|
451
|
-
}, [], ErrorsAbi);
|
|
452
|
-
this.log.debug(`Simulation for ${action} at slot ${slotNumber} succeeded`, {
|
|
453
|
-
request
|
|
454
|
-
});
|
|
455
|
-
} catch (err) {
|
|
456
|
-
this.log.error(`Failed simulation for ${action} at slot ${slotNumber} (enqueuing the action anyway)`, err);
|
|
457
|
-
// Yes, we enqueue the request anyway, in case there was a bug with the simulation itself
|
|
458
|
-
}
|
|
459
1339
|
// TODO(palla/slash): All votes (governance and slashing) should txTimeoutAt at the end of the slot.
|
|
460
1340
|
this.addRequest({
|
|
461
|
-
gasConfig: {
|
|
462
|
-
gasLimit: SequencerPublisher.VOTE_GAS_GUESS
|
|
463
|
-
},
|
|
464
1341
|
action,
|
|
465
1342
|
request,
|
|
466
1343
|
lastValidL2Slot: slotNumber,
|
|
467
1344
|
checkSuccess: (_request, result)=>{
|
|
468
|
-
const success = result &&
|
|
1345
|
+
const success = result && extractEventSuccess(result.receipt, {
|
|
1346
|
+
address: base.address.toString(),
|
|
1347
|
+
abi: EmpireBaseAbi,
|
|
1348
|
+
eventName: 'SignalCast'
|
|
1349
|
+
});
|
|
469
1350
|
const logData = {
|
|
470
1351
|
...result,
|
|
471
1352
|
slotNumber,
|
|
@@ -473,11 +1354,11 @@ export class SequencerPublisher {
|
|
|
473
1354
|
payload: payload.toString()
|
|
474
1355
|
};
|
|
475
1356
|
if (!success) {
|
|
476
|
-
this.log.error(`Signaling in
|
|
1357
|
+
this.log.error(`Signaling in ${action} for ${payload} at slot ${slotNumber} in round ${round} failed`, logData);
|
|
477
1358
|
this.lastActions[signalType] = cachedLastVote;
|
|
478
1359
|
return false;
|
|
479
1360
|
} else {
|
|
480
|
-
this.log.info(`Signaling in
|
|
1361
|
+
this.log.info(`Signaling in ${action} for ${payload} at slot ${slotNumber} in round ${round} succeeded`, logData);
|
|
481
1362
|
return true;
|
|
482
1363
|
}
|
|
483
1364
|
}
|
|
@@ -487,55 +1368,67 @@ export class SequencerPublisher {
|
|
|
487
1368
|
/**
|
|
488
1369
|
* Enqueues a governance castSignal transaction to cast a signal for a given slot number.
|
|
489
1370
|
* @param slotNumber - The slot number to cast a signal for.
|
|
490
|
-
* @param timestamp - The timestamp of the slot to cast a signal for.
|
|
491
1371
|
* @returns True if the signal was successfully enqueued, false otherwise.
|
|
492
|
-
*/ enqueueGovernanceCastSignal(governancePayload, slotNumber,
|
|
493
|
-
return this.enqueueCastSignalHelper(slotNumber,
|
|
1372
|
+
*/ enqueueGovernanceCastSignal(governancePayload, slotNumber, signerAddress, signer) {
|
|
1373
|
+
return this.enqueueCastSignalHelper(slotNumber, 'governance-signal', governancePayload, this.govProposerContract, signerAddress, signer);
|
|
494
1374
|
}
|
|
495
|
-
/**
|
|
1375
|
+
/**
|
|
1376
|
+
* Enqueues a `prune()` transaction if the rollup is prunable at the given slot's L1 timestamp.
|
|
1377
|
+
* `prune()` is permissionless and idempotent — if the chain is no longer prunable by send time the
|
|
1378
|
+
* bundle simulation usually drops the entry; on a node without `eth_simulateV1` the bundle is sent
|
|
1379
|
+
* as-is and the prune reverts `Rollup__NothingToPrune` inside `aggregate3(allowFailure: true)`
|
|
1380
|
+
* (a failed action, never a whole-tx revert). Used by the failed-sync fallback so a stuck pending
|
|
1381
|
+
* chain (e.g. bad data blocking sync) can be wound back to recover.
|
|
1382
|
+
* @returns true if a prune request was enqueued, false otherwise.
|
|
1383
|
+
*/ async enqueuePruneIfPrunable(slotNumber) {
|
|
1384
|
+
if (this.lastActions['prune'] === slotNumber) {
|
|
1385
|
+
this.log.debug(`Skipping duplicate prune for slot ${slotNumber}`, {
|
|
1386
|
+
slotNumber
|
|
1387
|
+
});
|
|
1388
|
+
return false;
|
|
1389
|
+
}
|
|
1390
|
+
// Use the SAME timestamp the bundle simulator overrides block.timestamp with at send time
|
|
1391
|
+
// (sequencer-bundle-simulator.ts) so this upfront check and the send-time sim agree. Slot-start
|
|
1392
|
+
// and last-L1-slot both fall within the same L2 slot (and epoch, which is what `canPruneAtTime`
|
|
1393
|
+
// derives), so they agree today; matching the simulator keeps it robust if the contract ever uses
|
|
1394
|
+
// the timestamp more granularly.
|
|
1395
|
+
const ts = getLastL1SlotTimestampForL2Slot(slotNumber, this.epochCache.getL1Constants());
|
|
1396
|
+
const canPrune = await this.rollupContract.canPruneAtTime(ts).catch((err)=>{
|
|
1397
|
+
this.log.error(`Failed to check canPruneAtTime for slot ${slotNumber}`, err, {
|
|
1398
|
+
slotNumber
|
|
1399
|
+
});
|
|
1400
|
+
return false;
|
|
1401
|
+
});
|
|
1402
|
+
if (!canPrune) {
|
|
1403
|
+
this.log.debug(`Rollup not prunable at slot ${slotNumber}`, {
|
|
1404
|
+
slotNumber
|
|
1405
|
+
});
|
|
1406
|
+
return false;
|
|
1407
|
+
}
|
|
1408
|
+
const request = {
|
|
1409
|
+
to: this.rollupContract.address,
|
|
1410
|
+
data: encodeFunctionData({
|
|
1411
|
+
abi: RollupAbi,
|
|
1412
|
+
functionName: 'prune',
|
|
1413
|
+
args: []
|
|
1414
|
+
})
|
|
1415
|
+
};
|
|
1416
|
+
this.log.info(`Enqueuing rollup prune for slot ${slotNumber}`, {
|
|
1417
|
+
slotNumber
|
|
1418
|
+
});
|
|
1419
|
+
return this.enqueueRequest('prune', request, {
|
|
1420
|
+
address: this.rollupContract.address,
|
|
1421
|
+
abi: RollupAbi,
|
|
1422
|
+
eventName: 'PrunedPending'
|
|
1423
|
+
}, slotNumber);
|
|
1424
|
+
}
|
|
1425
|
+
/** Enqueues all slashing actions as returned by the slasher client. */ async enqueueSlashingActions(actions, slotNumber, signerAddress, signer) {
|
|
496
1426
|
if (actions.length === 0) {
|
|
497
1427
|
this.log.debug(`No slashing actions to enqueue for slot ${slotNumber}`);
|
|
498
1428
|
return false;
|
|
499
1429
|
}
|
|
500
1430
|
for (const action of actions){
|
|
501
1431
|
switch(action.type){
|
|
502
|
-
case 'vote-empire-payload':
|
|
503
|
-
{
|
|
504
|
-
if (this.slashingProposerContract?.type !== 'empire') {
|
|
505
|
-
this.log.error('Cannot vote for empire payload on non-empire slashing contract');
|
|
506
|
-
break;
|
|
507
|
-
}
|
|
508
|
-
this.log.debug(`Enqueuing slashing vote for payload ${action.payload} at slot ${slotNumber}`, {
|
|
509
|
-
signerAddress
|
|
510
|
-
});
|
|
511
|
-
await this.enqueueCastSignalHelper(slotNumber, timestamp, 'empire-slashing-signal', action.payload, this.slashingProposerContract, signerAddress, signer);
|
|
512
|
-
break;
|
|
513
|
-
}
|
|
514
|
-
case 'create-empire-payload':
|
|
515
|
-
{
|
|
516
|
-
this.log.debug(`Enqueuing slashing create payload at slot ${slotNumber}`, {
|
|
517
|
-
slotNumber,
|
|
518
|
-
signerAddress
|
|
519
|
-
});
|
|
520
|
-
const request = this.slashFactoryContract.buildCreatePayloadRequest(action.data);
|
|
521
|
-
await this.simulateAndEnqueueRequest('create-empire-payload', request, (receipt)=>!!this.slashFactoryContract.tryExtractSlashPayloadCreatedEvent(receipt.logs), slotNumber, timestamp);
|
|
522
|
-
break;
|
|
523
|
-
}
|
|
524
|
-
case 'execute-empire-payload':
|
|
525
|
-
{
|
|
526
|
-
this.log.debug(`Enqueuing slashing execute payload at slot ${slotNumber}`, {
|
|
527
|
-
slotNumber,
|
|
528
|
-
signerAddress
|
|
529
|
-
});
|
|
530
|
-
if (this.slashingProposerContract?.type !== 'empire') {
|
|
531
|
-
this.log.error('Cannot execute slashing payload on non-empire slashing contract');
|
|
532
|
-
return false;
|
|
533
|
-
}
|
|
534
|
-
const empireSlashingProposer = this.slashingProposerContract;
|
|
535
|
-
const request = empireSlashingProposer.buildExecuteRoundRequest(action.round);
|
|
536
|
-
await this.simulateAndEnqueueRequest('execute-empire-payload', request, (receipt)=>!!empireSlashingProposer.tryExtractPayloadSubmittedEvent(receipt.logs), slotNumber, timestamp);
|
|
537
|
-
break;
|
|
538
|
-
}
|
|
539
1432
|
case 'vote-offenses':
|
|
540
1433
|
{
|
|
541
1434
|
this.log.debug(`Enqueuing slashing vote for ${action.votes.length} votes at slot ${slotNumber}`, {
|
|
@@ -544,14 +1437,17 @@ export class SequencerPublisher {
|
|
|
544
1437
|
votesCount: action.votes.length,
|
|
545
1438
|
signerAddress
|
|
546
1439
|
});
|
|
547
|
-
if (this.slashingProposerContract
|
|
548
|
-
this.log.error('
|
|
1440
|
+
if (!this.slashingProposerContract) {
|
|
1441
|
+
this.log.error('No slashing proposer contract available');
|
|
549
1442
|
return false;
|
|
550
1443
|
}
|
|
551
|
-
const tallySlashingProposer = this.slashingProposerContract;
|
|
552
1444
|
const votes = bufferToHex(encodeSlashConsensusVotes(action.votes));
|
|
553
|
-
const request = await
|
|
554
|
-
|
|
1445
|
+
const request = await this.slashingProposerContract.buildVoteRequestFromSigner(votes, slotNumber, signer);
|
|
1446
|
+
this.enqueueRequest('vote-offenses', request, {
|
|
1447
|
+
address: this.slashingProposerContract.address.toString(),
|
|
1448
|
+
abi: SlashingProposerAbi,
|
|
1449
|
+
eventName: 'VoteCast'
|
|
1450
|
+
}, slotNumber);
|
|
555
1451
|
break;
|
|
556
1452
|
}
|
|
557
1453
|
case 'execute-slash':
|
|
@@ -561,13 +1457,16 @@ export class SequencerPublisher {
|
|
|
561
1457
|
round: action.round,
|
|
562
1458
|
signerAddress
|
|
563
1459
|
});
|
|
564
|
-
if (this.slashingProposerContract
|
|
565
|
-
this.log.error('
|
|
1460
|
+
if (!this.slashingProposerContract) {
|
|
1461
|
+
this.log.error('No slashing proposer contract available');
|
|
566
1462
|
return false;
|
|
567
1463
|
}
|
|
568
|
-
const
|
|
569
|
-
|
|
570
|
-
|
|
1464
|
+
const executeRequest = this.slashingProposerContract.buildExecuteRoundRequest(action.round, action.committees);
|
|
1465
|
+
this.enqueueRequest('execute-slash', executeRequest, {
|
|
1466
|
+
address: this.slashingProposerContract.address.toString(),
|
|
1467
|
+
abi: SlashingProposerAbi,
|
|
1468
|
+
eventName: 'RoundExecuted'
|
|
1469
|
+
}, slotNumber);
|
|
571
1470
|
break;
|
|
572
1471
|
}
|
|
573
1472
|
default:
|
|
@@ -579,77 +1478,57 @@ export class SequencerPublisher {
|
|
|
579
1478
|
}
|
|
580
1479
|
return true;
|
|
581
1480
|
}
|
|
582
|
-
/**
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
* @returns True if the tx has been enqueued, throws otherwise. See #9315
|
|
587
|
-
*/ async enqueueProposeL2Block(block, attestationsAndSigners, attestationsAndSignersSignature, opts = {}) {
|
|
588
|
-
const checkpointHeader = block.getCheckpointHeader();
|
|
589
|
-
const blobFields = block.getCheckpointBlobFields();
|
|
590
|
-
const blobs = getBlobsPerL1Block(blobFields);
|
|
1481
|
+
/** Enqueues a proposal for a checkpoint on L1 */ async enqueueProposeCheckpoint(checkpoint, attestationsAndSigners, attestationsAndSignersSignature, opts = {}) {
|
|
1482
|
+
const checkpointHeader = checkpoint.header;
|
|
1483
|
+
const blobFields = checkpoint.toBlobFields();
|
|
1484
|
+
const blobs = await getBlobsPerL1Block(blobFields);
|
|
591
1485
|
const proposeTxArgs = {
|
|
592
1486
|
header: checkpointHeader,
|
|
593
|
-
archive:
|
|
594
|
-
body: block.body.toBuffer(),
|
|
1487
|
+
archive: checkpoint.archive.root.toBuffer(),
|
|
595
1488
|
blobs,
|
|
596
1489
|
attestationsAndSigners,
|
|
597
|
-
attestationsAndSignersSignature
|
|
1490
|
+
attestationsAndSignersSignature,
|
|
1491
|
+
feeAssetPriceModifier: checkpoint.feeAssetPriceModifier
|
|
598
1492
|
};
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
// TODO(palla): Check whether we're validating twice, once here and once within addProposeTx, since we call simulateProposeTx in both places.
|
|
606
|
-
ts = await this.validateBlockForSubmission(block, attestationsAndSigners, attestationsAndSignersSignature, opts);
|
|
607
|
-
} catch (err) {
|
|
608
|
-
this.log.error(`Block validation failed. ${err instanceof Error ? err.message : 'No error message'}`, err, {
|
|
609
|
-
...block.getStats(),
|
|
610
|
-
slotNumber: block.header.globalVariables.slotNumber,
|
|
611
|
-
forcePendingBlockNumber: opts.forcePendingBlockNumber
|
|
612
|
-
});
|
|
613
|
-
throw err;
|
|
614
|
-
}
|
|
615
|
-
this.log.verbose(`Enqueuing block propose transaction`, {
|
|
616
|
-
...block.toBlockInfo(),
|
|
617
|
-
...opts
|
|
1493
|
+
this.log.verbose(`Enqueuing checkpoint propose transaction`, {
|
|
1494
|
+
...checkpoint.toCheckpointInfo(),
|
|
1495
|
+
txTimeoutAt: opts.txTimeoutAt
|
|
1496
|
+
});
|
|
1497
|
+
await this.addProposeTx(checkpoint, proposeTxArgs, {
|
|
1498
|
+
txTimeoutAt: opts.txTimeoutAt
|
|
618
1499
|
});
|
|
619
|
-
await this.addProposeTx(block, proposeTxArgs, opts, ts);
|
|
620
|
-
return true;
|
|
621
1500
|
}
|
|
622
|
-
|
|
1501
|
+
enqueueInvalidateCheckpoint(request, opts = {}) {
|
|
623
1502
|
if (!request) {
|
|
624
1503
|
return;
|
|
625
1504
|
}
|
|
626
|
-
|
|
627
|
-
const gasLimit = this.l1TxUtils.bumpGasLimit(BigInt(Math.ceil(Number(request.gasUsed) * 64 / 63)));
|
|
628
|
-
const { gasUsed, blockNumber } = request;
|
|
1505
|
+
const { gasUsed, checkpointNumber } = request;
|
|
629
1506
|
const logData = {
|
|
630
1507
|
gasUsed,
|
|
631
|
-
|
|
632
|
-
gasLimit,
|
|
1508
|
+
checkpointNumber,
|
|
633
1509
|
opts
|
|
634
1510
|
};
|
|
635
|
-
this.log.verbose(`Enqueuing invalidate
|
|
1511
|
+
this.log.verbose(`Enqueuing invalidate checkpoint request`, logData);
|
|
636
1512
|
this.addRequest({
|
|
637
1513
|
action: `invalidate-by-${request.reason}`,
|
|
638
1514
|
request: request.request,
|
|
639
|
-
gasConfig: {
|
|
640
|
-
gasLimit,
|
|
1515
|
+
gasConfig: opts.txTimeoutAt ? {
|
|
641
1516
|
txTimeoutAt: opts.txTimeoutAt
|
|
642
|
-
},
|
|
1517
|
+
} : undefined,
|
|
643
1518
|
lastValidL2Slot: SlotNumber(this.getCurrentL2Slot() + 2),
|
|
644
1519
|
checkSuccess: (_req, result)=>{
|
|
645
|
-
const success = result &&
|
|
1520
|
+
const success = result && extractEventSuccess(result.receipt, {
|
|
1521
|
+
address: this.rollupContract.address,
|
|
1522
|
+
abi: RollupAbi,
|
|
1523
|
+
eventName: 'CheckpointInvalidated'
|
|
1524
|
+
});
|
|
646
1525
|
if (!success) {
|
|
647
|
-
this.log.warn(`Invalidate
|
|
1526
|
+
this.log.warn(`Invalidate checkpoint ${request.checkpointNumber} failed`, {
|
|
648
1527
|
...result,
|
|
649
1528
|
...logData
|
|
650
1529
|
});
|
|
651
1530
|
} else {
|
|
652
|
-
this.log.info(`Invalidate
|
|
1531
|
+
this.log.info(`Invalidate checkpoint ${request.checkpointNumber} succeeded`, {
|
|
653
1532
|
...result,
|
|
654
1533
|
...logData
|
|
655
1534
|
});
|
|
@@ -658,57 +1537,36 @@ export class SequencerPublisher {
|
|
|
658
1537
|
}
|
|
659
1538
|
});
|
|
660
1539
|
}
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
};
|
|
1540
|
+
/**
|
|
1541
|
+
* Dedup-checked enqueue helper for actions that are simulated at bundle-send time rather
|
|
1542
|
+
* than at enqueue time. Validates the (action, slot) dedup key, sets `lastActions`, and
|
|
1543
|
+
* enqueues without a gasLimit so the bundle simulate sets the only gasLimit that matters.
|
|
1544
|
+
*/ enqueueRequest(action, request, eventOpts, slotNumber) {
|
|
667
1545
|
if (this.lastActions[action] && this.lastActions[action] === slotNumber) {
|
|
668
1546
|
this.log.debug(`Skipping duplicate action ${action} for slot ${slotNumber}`);
|
|
669
1547
|
return false;
|
|
670
1548
|
}
|
|
671
1549
|
const cachedLastActionSlot = this.lastActions[action];
|
|
672
1550
|
this.lastActions[action] = slotNumber;
|
|
673
|
-
this.log.debug(`
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
({ gasUsed } = await this.l1TxUtils.simulate(request, {
|
|
677
|
-
time: timestamp
|
|
678
|
-
}, [], ErrorsAbi)); // TODO(palla/slash): Check the timestamp logic
|
|
679
|
-
this.log.verbose(`Simulation for ${action} succeeded`, {
|
|
680
|
-
...logData,
|
|
681
|
-
request,
|
|
682
|
-
gasUsed
|
|
683
|
-
});
|
|
684
|
-
} catch (err) {
|
|
685
|
-
const viemError = formatViemError(err);
|
|
686
|
-
this.log.error(`Simulation for ${action} at ${slotNumber} failed`, viemError, logData);
|
|
687
|
-
return false;
|
|
688
|
-
}
|
|
689
|
-
// We issued the simulation against the rollup contract, so we need to account for the overhead of the multicall3
|
|
690
|
-
const gasLimit = this.l1TxUtils.bumpGasLimit(BigInt(Math.ceil(Number(gasUsed) * 64 / 63)));
|
|
691
|
-
logData.gasLimit = gasLimit;
|
|
692
|
-
this.log.debug(`Enqueuing ${action}`, logData);
|
|
1551
|
+
this.log.debug(`Enqueuing ${action}`, {
|
|
1552
|
+
slotNumber
|
|
1553
|
+
});
|
|
693
1554
|
this.addRequest({
|
|
694
1555
|
action,
|
|
695
1556
|
request,
|
|
696
|
-
gasConfig: {
|
|
697
|
-
gasLimit
|
|
698
|
-
},
|
|
699
1557
|
lastValidL2Slot: slotNumber,
|
|
700
|
-
checkSuccess: (
|
|
701
|
-
const success = result && result.receipt
|
|
1558
|
+
checkSuccess: (_request, result)=>{
|
|
1559
|
+
const success = result && extractEventSuccess(result.receipt, eventOpts);
|
|
702
1560
|
if (!success) {
|
|
703
1561
|
this.log.warn(`Action ${action} at ${slotNumber} failed`, {
|
|
704
1562
|
...result,
|
|
705
|
-
|
|
1563
|
+
slotNumber
|
|
706
1564
|
});
|
|
707
1565
|
this.lastActions[action] = cachedLastActionSlot;
|
|
708
1566
|
} else {
|
|
709
1567
|
this.log.info(`Action ${action} at ${slotNumber} succeeded`, {
|
|
710
1568
|
...result,
|
|
711
|
-
|
|
1569
|
+
slotNumber
|
|
712
1570
|
});
|
|
713
1571
|
}
|
|
714
1572
|
return !!success;
|
|
@@ -723,13 +1581,14 @@ export class SequencerPublisher {
|
|
|
723
1581
|
* A call to `restart` is required before you can continue publishing.
|
|
724
1582
|
*/ interrupt() {
|
|
725
1583
|
this.interrupted = true;
|
|
1584
|
+
this.interruptibleSleep.interrupt();
|
|
726
1585
|
this.l1TxUtils.interrupt();
|
|
727
1586
|
}
|
|
728
1587
|
/** Restarts the publisher after calling `interrupt`. */ restart() {
|
|
729
1588
|
this.interrupted = false;
|
|
730
1589
|
this.l1TxUtils.restart();
|
|
731
1590
|
}
|
|
732
|
-
async prepareProposeTx(encodedData
|
|
1591
|
+
async prepareProposeTx(encodedData) {
|
|
733
1592
|
const kzg = Blob.getViemKzgInstance();
|
|
734
1593
|
const blobInput = getPrefixedEthBlobCommitments(encodedData.blobs);
|
|
735
1594
|
this.log.debug('Validating blob input', {
|
|
@@ -743,7 +1602,11 @@ export class SequencerPublisher {
|
|
|
743
1602
|
blobEvaluationGas = BigInt(encodedData.blobs.length) * 21_000n;
|
|
744
1603
|
this.log.debug(`Using fixed blob evaluation gas estimate in fisherman mode: ${blobEvaluationGas}`);
|
|
745
1604
|
} else {
|
|
746
|
-
//
|
|
1605
|
+
// We call validateBlobs via estimateGas with real blob+kzg sidecars as a consistency check
|
|
1606
|
+
// that our locally-built blob commitments match the blob data. The bundle simulate at send
|
|
1607
|
+
// time uses eth_simulateV1, which cannot carry blob inputs, so the rollup's on-chain blob
|
|
1608
|
+
// check is forced off there — making this the only pre-flight detector of a commitment/data
|
|
1609
|
+
// mismatch. The returned gas estimate is stashed on the request for the bundle path to read.
|
|
747
1610
|
blobEvaluationGas = await this.l1TxUtils.estimateGas(this.getSenderAddress().toString(), {
|
|
748
1611
|
to: this.rollupContract.address,
|
|
749
1612
|
data: encodeFunctionData({
|
|
@@ -756,10 +1619,42 @@ export class SequencerPublisher {
|
|
|
756
1619
|
}, {}, {
|
|
757
1620
|
blobs: encodedData.blobs.map((b)=>b.data),
|
|
758
1621
|
kzg
|
|
759
|
-
}).catch((err)=>{
|
|
760
|
-
const
|
|
761
|
-
this.log.error(`Failed to validate blobs`, message, {
|
|
762
|
-
metaMessages
|
|
1622
|
+
}).catch(async (err)=>{
|
|
1623
|
+
const viemError = formatViemError(err);
|
|
1624
|
+
this.log.error(`Failed to validate blobs`, viemError.message, {
|
|
1625
|
+
metaMessages: viemError.metaMessages
|
|
1626
|
+
});
|
|
1627
|
+
const validateBlobsData = encodeFunctionData({
|
|
1628
|
+
abi: RollupAbi,
|
|
1629
|
+
functionName: 'validateBlobs',
|
|
1630
|
+
args: [
|
|
1631
|
+
blobInput
|
|
1632
|
+
]
|
|
1633
|
+
});
|
|
1634
|
+
const l1BlockNumber = await this.l1TxUtils.getBlockNumber();
|
|
1635
|
+
this.backupFailedTx({
|
|
1636
|
+
id: keccak256(validateBlobsData),
|
|
1637
|
+
failureType: 'simulation',
|
|
1638
|
+
request: {
|
|
1639
|
+
to: this.rollupContract.address,
|
|
1640
|
+
data: validateBlobsData
|
|
1641
|
+
},
|
|
1642
|
+
blobData: encodedData.blobs.map((b)=>toHex(b.data)),
|
|
1643
|
+
l1BlockNumber,
|
|
1644
|
+
error: {
|
|
1645
|
+
message: viemError.message,
|
|
1646
|
+
name: viemError.name
|
|
1647
|
+
},
|
|
1648
|
+
context: {
|
|
1649
|
+
actions: [
|
|
1650
|
+
'validate-blobs'
|
|
1651
|
+
],
|
|
1652
|
+
sender: this.getSenderAddress().toString()
|
|
1653
|
+
},
|
|
1654
|
+
timing: this.computeTimingInfo(this.getCurrentL2Slot())
|
|
1655
|
+
}, {
|
|
1656
|
+
captureFeeSummary: true,
|
|
1657
|
+
targetSlot: this.getCurrentL2Slot()
|
|
763
1658
|
});
|
|
764
1659
|
throw new Error('Failed to validate blobs');
|
|
765
1660
|
});
|
|
@@ -770,8 +1665,7 @@ export class SequencerPublisher {
|
|
|
770
1665
|
header: encodedData.header.toViem(),
|
|
771
1666
|
archive: toHex(encodedData.archive),
|
|
772
1667
|
oracleInput: {
|
|
773
|
-
|
|
774
|
-
feeAssetPriceModifier: 0n
|
|
1668
|
+
feeAssetPriceModifier: encodedData.feeAssetPriceModifier
|
|
775
1669
|
}
|
|
776
1670
|
},
|
|
777
1671
|
encodedData.attestationsAndSigners.getPackedAttestations(),
|
|
@@ -779,104 +1673,40 @@ export class SequencerPublisher {
|
|
|
779
1673
|
encodedData.attestationsAndSignersSignature.toViemSignature(),
|
|
780
1674
|
blobInput
|
|
781
1675
|
];
|
|
782
|
-
const { rollupData, simulationResult } = await this.simulateProposeTx(args, timestamp, options);
|
|
783
|
-
return {
|
|
784
|
-
args,
|
|
785
|
-
blobEvaluationGas,
|
|
786
|
-
rollupData,
|
|
787
|
-
simulationResult
|
|
788
|
-
};
|
|
789
|
-
}
|
|
790
|
-
/**
|
|
791
|
-
* Simulates the propose tx with eth_simulateV1
|
|
792
|
-
* @param args - The propose tx args
|
|
793
|
-
* @param timestamp - The timestamp to simulate proposal at
|
|
794
|
-
* @returns The simulation result
|
|
795
|
-
*/ async simulateProposeTx(args, timestamp, options) {
|
|
796
1676
|
const rollupData = encodeFunctionData({
|
|
797
1677
|
abi: RollupAbi,
|
|
798
1678
|
functionName: 'propose',
|
|
799
1679
|
args
|
|
800
1680
|
});
|
|
801
|
-
// override the pending checkpoint number if requested
|
|
802
|
-
const optsForcePendingCheckpointNumber = options.forcePendingBlockNumber !== undefined ? CheckpointNumber.fromBlockNumber(options.forcePendingBlockNumber) : undefined;
|
|
803
|
-
const forcePendingCheckpointNumberStateDiff = (optsForcePendingCheckpointNumber !== undefined ? await this.rollupContract.makePendingCheckpointNumberOverride(optsForcePendingCheckpointNumber) : []).flatMap((override)=>override.stateDiff ?? []);
|
|
804
|
-
const stateOverrides = [
|
|
805
|
-
{
|
|
806
|
-
address: this.rollupContract.address,
|
|
807
|
-
// @note we override checkBlob to false since blobs are not part simulate()
|
|
808
|
-
stateDiff: [
|
|
809
|
-
{
|
|
810
|
-
slot: toPaddedHex(RollupContract.checkBlobStorageSlot, true),
|
|
811
|
-
value: toPaddedHex(0n, true)
|
|
812
|
-
},
|
|
813
|
-
...forcePendingCheckpointNumberStateDiff
|
|
814
|
-
]
|
|
815
|
-
}
|
|
816
|
-
];
|
|
817
|
-
// In fisherman mode, simulate as the proposer but with sufficient balance
|
|
818
|
-
if (this.proposerAddressForSimulation) {
|
|
819
|
-
stateOverrides.push({
|
|
820
|
-
address: this.proposerAddressForSimulation.toString(),
|
|
821
|
-
balance: 10n * WEI_CONST * WEI_CONST
|
|
822
|
-
});
|
|
823
|
-
}
|
|
824
|
-
const simulationResult = await this.l1TxUtils.simulate({
|
|
825
|
-
to: this.rollupContract.address,
|
|
826
|
-
data: rollupData,
|
|
827
|
-
gas: SequencerPublisher.PROPOSE_GAS_GUESS,
|
|
828
|
-
...this.proposerAddressForSimulation && {
|
|
829
|
-
from: this.proposerAddressForSimulation.toString()
|
|
830
|
-
}
|
|
831
|
-
}, {
|
|
832
|
-
// @note we add 1n to the timestamp because geth implementation doesn't like simulation timestamp to be equal to the current block timestamp
|
|
833
|
-
time: timestamp + 1n,
|
|
834
|
-
// @note reth should have a 30m gas limit per block but throws errors that this tx is beyond limit so we increase here
|
|
835
|
-
gasLimit: SequencerPublisher.PROPOSE_GAS_GUESS * 2n
|
|
836
|
-
}, stateOverrides, RollupAbi, {
|
|
837
|
-
// @note fallback gas estimate to use if the node doesn't support simulation API
|
|
838
|
-
fallbackGasEstimate: SequencerPublisher.PROPOSE_GAS_GUESS
|
|
839
|
-
}).catch((err)=>{
|
|
840
|
-
// In fisherman mode, we expect ValidatorSelection__MissingProposerSignature since fisherman doesn't have proposer signature
|
|
841
|
-
const viemError = formatViemError(err);
|
|
842
|
-
if (this.config.fishermanMode && viemError.message?.includes('ValidatorSelection__MissingProposerSignature')) {
|
|
843
|
-
this.log.debug(`Ignoring expected ValidatorSelection__MissingProposerSignature error in fisherman mode`);
|
|
844
|
-
// Return a minimal simulation result with the fallback gas estimate
|
|
845
|
-
return {
|
|
846
|
-
gasUsed: SequencerPublisher.PROPOSE_GAS_GUESS,
|
|
847
|
-
logs: []
|
|
848
|
-
};
|
|
849
|
-
}
|
|
850
|
-
this.log.error(`Failed to simulate propose tx`, viemError);
|
|
851
|
-
throw err;
|
|
852
|
-
});
|
|
853
1681
|
return {
|
|
854
|
-
|
|
855
|
-
|
|
1682
|
+
args,
|
|
1683
|
+
blobEvaluationGas,
|
|
1684
|
+
rollupData
|
|
856
1685
|
};
|
|
857
1686
|
}
|
|
858
|
-
async addProposeTx(
|
|
1687
|
+
async addProposeTx(checkpoint, encodedData, opts = {}) {
|
|
1688
|
+
const slot = checkpoint.header.slotNumber;
|
|
859
1689
|
const timer = new Timer();
|
|
860
1690
|
const kzg = Blob.getViemKzgInstance();
|
|
861
|
-
const { rollupData,
|
|
1691
|
+
const { rollupData, blobEvaluationGas } = await this.prepareProposeTx(encodedData);
|
|
862
1692
|
const startBlock = await this.l1TxUtils.getBlockNumber();
|
|
863
|
-
|
|
864
|
-
//
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
});
|
|
1693
|
+
// Send the blobs to the blob client preemptively. This helps in tests where the sequencer mistakingly thinks that the propose
|
|
1694
|
+
// tx fails but it does get mined. We make sure that the blobs are sent to the blob client regardless of the tx outcome.
|
|
1695
|
+
void Promise.resolve().then(()=>this.blobClient.sendBlobsToFilestore(encodedData.blobs).catch((_err)=>{
|
|
1696
|
+
this.log.error('Failed to send blobs to blob client');
|
|
1697
|
+
}));
|
|
869
1698
|
return this.addRequest({
|
|
870
1699
|
action: 'propose',
|
|
871
1700
|
request: {
|
|
872
1701
|
to: this.rollupContract.address,
|
|
873
1702
|
data: rollupData
|
|
874
1703
|
},
|
|
875
|
-
lastValidL2Slot:
|
|
1704
|
+
lastValidL2Slot: checkpoint.header.slotNumber,
|
|
876
1705
|
gasConfig: {
|
|
877
|
-
|
|
878
|
-
gasLimit
|
|
1706
|
+
txTimeoutAt: opts.txTimeoutAt,
|
|
1707
|
+
gasLimit: undefined
|
|
879
1708
|
},
|
|
1709
|
+
blobEvaluationGas,
|
|
880
1710
|
blobConfig: {
|
|
881
1711
|
blobs: encodedData.blobs.map((b)=>b.data),
|
|
882
1712
|
kzg
|
|
@@ -886,7 +1716,11 @@ export class SequencerPublisher {
|
|
|
886
1716
|
return false;
|
|
887
1717
|
}
|
|
888
1718
|
const { receipt, stats, errorMsg } = result;
|
|
889
|
-
const success =
|
|
1719
|
+
const success = extractEventSuccess(receipt, {
|
|
1720
|
+
address: this.rollupContract.address,
|
|
1721
|
+
abi: RollupAbi,
|
|
1722
|
+
eventName: 'CheckpointProposed'
|
|
1723
|
+
});
|
|
890
1724
|
if (success) {
|
|
891
1725
|
const endBlock = receipt.blockNumber;
|
|
892
1726
|
const inclusionBlocks = Number(endBlock - startBlock);
|
|
@@ -900,29 +1734,31 @@ export class SequencerPublisher {
|
|
|
900
1734
|
calldataGas,
|
|
901
1735
|
calldataSize,
|
|
902
1736
|
sender,
|
|
903
|
-
...
|
|
1737
|
+
...checkpoint.getStats(),
|
|
904
1738
|
eventName: 'rollup-published-to-l1',
|
|
905
1739
|
blobCount: encodedData.blobs.length,
|
|
906
1740
|
inclusionBlocks
|
|
907
1741
|
};
|
|
908
|
-
this.log.info(`Published
|
|
1742
|
+
this.log.info(`Published checkpoint ${checkpoint.number} at slot ${slot} to rollup contract`, {
|
|
909
1743
|
...stats,
|
|
910
|
-
...
|
|
911
|
-
...receipt
|
|
1744
|
+
...checkpoint.getStats(),
|
|
1745
|
+
...pick(receipt, 'transactionHash', 'blockHash')
|
|
912
1746
|
});
|
|
913
1747
|
this.metrics.recordProcessBlockTx(timer.ms(), publishStats);
|
|
914
1748
|
return true;
|
|
915
1749
|
} else {
|
|
916
1750
|
this.metrics.recordFailedTx('process');
|
|
917
|
-
this.log.error(`
|
|
918
|
-
...
|
|
919
|
-
receipt
|
|
920
|
-
txHash: receipt.transactionHash,
|
|
921
|
-
slotNumber: block.header.globalVariables.slotNumber
|
|
1751
|
+
this.log.error(`Publishing checkpoint at slot ${slot} failed with ${errorMsg ?? 'no error message'}`, undefined, {
|
|
1752
|
+
...checkpoint.getStats(),
|
|
1753
|
+
...receipt
|
|
922
1754
|
});
|
|
923
1755
|
return false;
|
|
924
1756
|
}
|
|
925
1757
|
}
|
|
926
1758
|
});
|
|
927
1759
|
}
|
|
1760
|
+
/** Returns the timestamp of the next L1 slot boundary after now. */ getNextL1SlotTimestamp() {
|
|
1761
|
+
const l1Constants = this.epochCache.getL1Constants();
|
|
1762
|
+
return getNextL1SlotTimestamp(this.dateProvider.nowInSeconds(), l1Constants);
|
|
1763
|
+
}
|
|
928
1764
|
}
|