@aztec/sequencer-client 0.0.1-commit.24de95ac → 0.0.1-commit.2606882
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +281 -21
- package/dest/client/index.d.ts +1 -1
- package/dest/client/sequencer-client.d.ts +26 -16
- package/dest/client/sequencer-client.d.ts.map +1 -1
- package/dest/client/sequencer-client.js +78 -37
- package/dest/config.d.ts +37 -8
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +139 -48
- package/dest/global_variable_builder/fee_predictor.d.ts +37 -0
- package/dest/global_variable_builder/fee_predictor.d.ts.map +1 -0
- package/dest/global_variable_builder/fee_predictor.js +128 -0
- package/dest/global_variable_builder/fee_provider.d.ts +21 -0
- package/dest/global_variable_builder/fee_provider.d.ts.map +1 -0
- package/dest/global_variable_builder/fee_provider.js +58 -0
- package/dest/global_variable_builder/global_builder.d.ts +24 -20
- package/dest/global_variable_builder/global_builder.d.ts.map +1 -1
- package/dest/global_variable_builder/global_builder.js +44 -65
- package/dest/global_variable_builder/index.d.ts +4 -2
- package/dest/global_variable_builder/index.d.ts.map +1 -1
- package/dest/global_variable_builder/index.js +2 -0
- package/dest/index.d.ts +2 -3
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +1 -2
- package/dest/publisher/config.d.ts +55 -20
- package/dest/publisher/config.d.ts.map +1 -1
- package/dest/publisher/config.js +124 -34
- package/dest/publisher/index.d.ts +2 -1
- package/dest/publisher/index.d.ts.map +1 -1
- package/dest/publisher/l1_tx_failed_store/factory.d.ts +11 -0
- package/dest/publisher/l1_tx_failed_store/factory.d.ts.map +1 -0
- package/dest/publisher/l1_tx_failed_store/factory.js +22 -0
- package/dest/publisher/l1_tx_failed_store/failed_tx_store.d.ts +58 -0
- package/dest/publisher/l1_tx_failed_store/failed_tx_store.d.ts.map +1 -0
- package/dest/publisher/l1_tx_failed_store/failed_tx_store.js +1 -0
- package/dest/publisher/l1_tx_failed_store/file_store_failed_tx_store.d.ts +15 -0
- package/dest/publisher/l1_tx_failed_store/file_store_failed_tx_store.d.ts.map +1 -0
- package/dest/publisher/l1_tx_failed_store/file_store_failed_tx_store.js +34 -0
- package/dest/publisher/l1_tx_failed_store/index.d.ts +4 -0
- package/dest/publisher/l1_tx_failed_store/index.d.ts.map +1 -0
- package/dest/publisher/l1_tx_failed_store/index.js +2 -0
- package/dest/publisher/sequencer-bundle-simulator.d.ts +96 -0
- package/dest/publisher/sequencer-bundle-simulator.d.ts.map +1 -0
- package/dest/publisher/sequencer-bundle-simulator.js +198 -0
- package/dest/publisher/sequencer-publisher-factory.d.ts +15 -8
- package/dest/publisher/sequencer-publisher-factory.d.ts.map +1 -1
- package/dest/publisher/sequencer-publisher-factory.js +28 -4
- package/dest/publisher/sequencer-publisher-metrics.d.ts +3 -3
- package/dest/publisher/sequencer-publisher-metrics.d.ts.map +1 -1
- package/dest/publisher/sequencer-publisher-metrics.js +23 -86
- package/dest/publisher/sequencer-publisher.d.ts +137 -97
- package/dest/publisher/sequencer-publisher.d.ts.map +1 -1
- package/dest/publisher/sequencer-publisher.js +1001 -416
- package/dest/sequencer/automine/automine_factory.d.ts +54 -0
- package/dest/sequencer/automine/automine_factory.d.ts.map +1 -0
- package/dest/sequencer/automine/automine_factory.js +84 -0
- package/dest/sequencer/automine/automine_sequencer.d.ts +151 -0
- package/dest/sequencer/automine/automine_sequencer.d.ts.map +1 -0
- package/dest/sequencer/automine/automine_sequencer.js +509 -0
- package/dest/sequencer/chain_state_overrides.d.ts +61 -0
- package/dest/sequencer/chain_state_overrides.d.ts.map +1 -0
- package/dest/sequencer/chain_state_overrides.js +98 -0
- package/dest/sequencer/checkpoint_proposal_job.d.ts +150 -0
- package/dest/sequencer/checkpoint_proposal_job.d.ts.map +1 -0
- package/dest/sequencer/checkpoint_proposal_job.js +1792 -0
- package/dest/sequencer/checkpoint_proposal_job_metrics.d.ts +34 -0
- package/dest/sequencer/checkpoint_proposal_job_metrics.d.ts.map +1 -0
- package/dest/sequencer/checkpoint_proposal_job_metrics.js +72 -0
- package/dest/sequencer/checkpoint_voter.d.ts +34 -0
- package/dest/sequencer/checkpoint_voter.d.ts.map +1 -0
- package/dest/sequencer/checkpoint_voter.js +106 -0
- package/dest/sequencer/config.d.ts +3 -2
- package/dest/sequencer/config.d.ts.map +1 -1
- package/dest/sequencer/errors.d.ts +1 -1
- package/dest/sequencer/errors.d.ts.map +1 -1
- package/dest/sequencer/events.d.ts +92 -0
- package/dest/sequencer/events.d.ts.map +1 -0
- package/dest/sequencer/events.js +1 -0
- package/dest/sequencer/index.d.ts +6 -2
- package/dest/sequencer/index.d.ts.map +1 -1
- package/dest/sequencer/index.js +5 -1
- package/dest/sequencer/metrics.d.ts +48 -4
- package/dest/sequencer/metrics.d.ts.map +1 -1
- package/dest/sequencer/metrics.js +257 -50
- package/dest/sequencer/sequencer.d.ts +175 -144
- package/dest/sequencer/sequencer.d.ts.map +1 -1
- package/dest/sequencer/sequencer.js +1022 -567
- package/dest/sequencer/timetable.d.ts +64 -16
- package/dest/sequencer/timetable.d.ts.map +1 -1
- package/dest/sequencer/timetable.js +154 -64
- package/dest/sequencer/types.d.ts +3 -0
- package/dest/sequencer/types.d.ts.map +1 -0
- package/dest/sequencer/types.js +1 -0
- package/dest/sequencer/utils.d.ts +14 -8
- package/dest/sequencer/utils.d.ts.map +1 -1
- package/dest/sequencer/utils.js +7 -4
- package/dest/test/index.d.ts +6 -7
- package/dest/test/index.d.ts.map +1 -1
- package/dest/test/mock_checkpoint_builder.d.ts +95 -0
- package/dest/test/mock_checkpoint_builder.d.ts.map +1 -0
- package/dest/test/mock_checkpoint_builder.js +231 -0
- package/dest/test/utils.d.ts +53 -0
- package/dest/test/utils.d.ts.map +1 -0
- package/dest/test/utils.js +105 -0
- package/package.json +32 -30
- package/src/client/sequencer-client.ts +105 -60
- package/src/config.ts +163 -57
- package/src/global_variable_builder/README.md +44 -0
- package/src/global_variable_builder/fee_predictor.ts +172 -0
- package/src/global_variable_builder/fee_provider.ts +75 -0
- package/src/global_variable_builder/global_builder.ts +63 -92
- package/src/global_variable_builder/index.ts +3 -1
- package/src/index.ts +5 -2
- package/src/publisher/config.ts +174 -51
- package/src/publisher/index.ts +3 -0
- package/src/publisher/l1_tx_failed_store/factory.ts +32 -0
- package/src/publisher/l1_tx_failed_store/failed_tx_store.ts +57 -0
- package/src/publisher/l1_tx_failed_store/file_store_failed_tx_store.ts +46 -0
- package/src/publisher/l1_tx_failed_store/index.ts +3 -0
- package/src/publisher/sequencer-bundle-simulator.ts +254 -0
- package/src/publisher/sequencer-publisher-factory.ts +45 -14
- package/src/publisher/sequencer-publisher-metrics.ts +19 -71
- package/src/publisher/sequencer-publisher.ts +795 -538
- package/src/sequencer/README.md +243 -0
- package/src/sequencer/automine/README.md +46 -0
- package/src/sequencer/automine/automine_factory.ts +145 -0
- package/src/sequencer/automine/automine_sequencer.ts +595 -0
- package/src/sequencer/chain_state_overrides.ts +162 -0
- package/src/sequencer/checkpoint_proposal_job.ts +1632 -0
- package/src/sequencer/checkpoint_proposal_job_metrics.ts +128 -0
- package/src/sequencer/checkpoint_voter.ts +119 -0
- package/src/sequencer/config.ts +2 -1
- package/src/sequencer/events.ts +76 -0
- package/src/sequencer/index.ts +5 -1
- package/src/sequencer/metrics.ts +330 -62
- package/src/sequencer/sequencer.ts +831 -748
- package/src/sequencer/timetable.ts +181 -81
- package/src/sequencer/types.ts +6 -0
- package/src/sequencer/utils.ts +18 -9
- package/src/test/index.ts +5 -6
- package/src/test/mock_checkpoint_builder.ts +323 -0
- package/src/test/utils.ts +185 -0
- package/dest/sequencer/block_builder.d.ts +0 -27
- package/dest/sequencer/block_builder.d.ts.map +0 -1
- package/dest/sequencer/block_builder.js +0 -130
- package/dest/tx_validator/nullifier_cache.d.ts +0 -14
- package/dest/tx_validator/nullifier_cache.d.ts.map +0 -1
- package/dest/tx_validator/nullifier_cache.js +0 -24
- package/dest/tx_validator/tx_validator_factory.d.ts +0 -17
- package/dest/tx_validator/tx_validator_factory.d.ts.map +0 -1
- package/dest/tx_validator/tx_validator_factory.js +0 -53
- package/src/sequencer/block_builder.ts +0 -218
- package/src/tx_validator/nullifier_cache.ts +0 -30
- package/src/tx_validator/tx_validator_factory.ts +0 -132
|
@@ -1,74 +1,488 @@
|
|
|
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 {
|
|
375
|
+
import { FeeAssetPriceOracle, MULTI_CALL_3_ADDRESS, Multicall3, MulticallForwarderRevertedError, buildSimulationOverridesStateOverride } from '@aztec/ethereum/contracts';
|
|
376
|
+
import { L1FeeAnalyzer } from '@aztec/ethereum/l1-fee-analysis';
|
|
377
|
+
import { MAX_L1_TX_LIMIT, WEI_CONST } from '@aztec/ethereum/l1-tx-utils';
|
|
378
|
+
import { FormattedViemError, formatViemError, mergeAbis, 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';
|
|
6
383
|
import { EthAddress } from '@aztec/foundation/eth-address';
|
|
7
384
|
import { Signature } from '@aztec/foundation/eth-signature';
|
|
8
385
|
import { createLogger } from '@aztec/foundation/log';
|
|
386
|
+
import { InterruptibleSleep } from '@aztec/foundation/sleep';
|
|
9
387
|
import { bufferToHex } from '@aztec/foundation/string';
|
|
10
388
|
import { Timer } from '@aztec/foundation/timer';
|
|
11
|
-
import { EmpireBaseAbi, ErrorsAbi, RollupAbi } from '@aztec/l1-artifacts';
|
|
389
|
+
import { EmpireBaseAbi, ErrorsAbi, RollupAbi, SlashingProposerAbi } from '@aztec/l1-artifacts';
|
|
12
390
|
import { encodeSlashConsensusVotes } from '@aztec/slasher';
|
|
13
|
-
import {
|
|
14
|
-
import {
|
|
15
|
-
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';
|
|
16
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
|
+
}
|
|
17
408
|
export const Actions = [
|
|
18
409
|
'invalidate-by-invalid-attestation',
|
|
19
410
|
'invalidate-by-insufficient-attestations',
|
|
20
411
|
'propose',
|
|
21
412
|
'governance-signal',
|
|
22
|
-
'empire-slashing-signal',
|
|
23
|
-
'create-empire-payload',
|
|
24
|
-
'execute-empire-payload',
|
|
25
413
|
'vote-offenses',
|
|
26
414
|
'execute-slash'
|
|
27
415
|
];
|
|
28
416
|
// Sorting for actions such that invalidations go before proposals, and proposals go before votes
|
|
29
417
|
export const compareActions = (a, b)=>Actions.indexOf(a) - Actions.indexOf(b);
|
|
418
|
+
_dec = trackSpan('SequencerPublisher.sendRequests'), _dec1 = trackSpan('SequencerPublisher.validateBlockHeader');
|
|
30
419
|
export class SequencerPublisher {
|
|
31
420
|
config;
|
|
421
|
+
static{
|
|
422
|
+
({ e: [_initProto] } = _apply_decs_2203_r(this, [
|
|
423
|
+
[
|
|
424
|
+
_dec,
|
|
425
|
+
2,
|
|
426
|
+
"sendRequests"
|
|
427
|
+
],
|
|
428
|
+
[
|
|
429
|
+
_dec1,
|
|
430
|
+
2,
|
|
431
|
+
"validateBlockHeader"
|
|
432
|
+
]
|
|
433
|
+
], []));
|
|
434
|
+
}
|
|
32
435
|
interrupted;
|
|
33
436
|
metrics;
|
|
437
|
+
bundleSimulator;
|
|
34
438
|
epochCache;
|
|
35
|
-
|
|
36
|
-
|
|
439
|
+
failedTxStore;
|
|
440
|
+
/**
|
|
441
|
+
* ABI used to decode raw revert payloads from dropped bundle entries when the original
|
|
442
|
+
* request did not carry an abi (e.g. the propose request). Merges every contract the
|
|
443
|
+
* publisher can route to so any of their custom errors decode against it.
|
|
444
|
+
*/ revertDecoderAbi;
|
|
37
445
|
lastActions;
|
|
38
446
|
log;
|
|
39
447
|
ethereumSlotDuration;
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
// Gas report for VotingWithSigTest shows a max gas of 100k, but we've seen it cost 700k+ in testnet
|
|
48
|
-
static VOTE_GAS_GUESS = 800_000n;
|
|
448
|
+
aztecSlotDuration;
|
|
449
|
+
/** Date provider for wall-clock time. */ dateProvider;
|
|
450
|
+
blobClient;
|
|
451
|
+
/** Optional callback to obtain a replacement publisher when the current one fails to send. */ getNextPublisher;
|
|
452
|
+
/** L1 fee analyzer for fisherman mode */ l1FeeAnalyzer;
|
|
453
|
+
/** Fee asset price oracle for computing price modifiers from Uniswap V4 */ feeAssetPriceOracle;
|
|
454
|
+
/** Interruptible sleep used by sendRequestsAt to wait until a target timestamp. */ interruptibleSleep;
|
|
49
455
|
l1TxUtils;
|
|
50
456
|
rollupContract;
|
|
51
457
|
govProposerContract;
|
|
52
458
|
slashingProposerContract;
|
|
53
|
-
|
|
459
|
+
tracer;
|
|
54
460
|
requests;
|
|
55
461
|
constructor(config, deps){
|
|
56
462
|
this.config = config;
|
|
57
|
-
this.interrupted = false;
|
|
58
|
-
this.
|
|
59
|
-
|
|
463
|
+
this.interrupted = (_initProto(this), false);
|
|
464
|
+
this.revertDecoderAbi = mergeAbis([
|
|
465
|
+
RollupAbi,
|
|
466
|
+
SlashingProposerAbi,
|
|
467
|
+
EmpireBaseAbi,
|
|
468
|
+
ErrorsAbi
|
|
469
|
+
]);
|
|
60
470
|
this.lastActions = {};
|
|
471
|
+
this.interruptibleSleep = new InterruptibleSleep();
|
|
61
472
|
this.requests = [];
|
|
62
473
|
this.log = deps.log ?? createLogger('sequencer:publisher');
|
|
63
474
|
this.ethereumSlotDuration = BigInt(config.ethereumSlotDuration);
|
|
475
|
+
this.aztecSlotDuration = BigInt(config.aztecSlotDuration);
|
|
476
|
+
this.dateProvider = deps.dateProvider;
|
|
64
477
|
this.epochCache = deps.epochCache;
|
|
65
478
|
this.lastActions = deps.lastActions;
|
|
66
|
-
this.
|
|
67
|
-
|
|
68
|
-
});
|
|
479
|
+
this.blobClient = deps.blobClient;
|
|
480
|
+
this.dateProvider = deps.dateProvider;
|
|
69
481
|
const telemetry = deps.telemetry ?? getTelemetryClient();
|
|
70
482
|
this.metrics = deps.metrics ?? new SequencerPublisherMetrics(telemetry, 'SequencerPublisher');
|
|
483
|
+
this.tracer = telemetry.getTracer('SequencerPublisher');
|
|
71
484
|
this.l1TxUtils = deps.l1TxUtils;
|
|
485
|
+
this.getNextPublisher = deps.getNextPublisher;
|
|
72
486
|
this.rollupContract = deps.rollupContract;
|
|
73
487
|
this.govProposerContract = deps.governanceProposerContract;
|
|
74
488
|
this.slashingProposerContract = deps.slashingProposerContract;
|
|
@@ -77,38 +491,134 @@ export class SequencerPublisher {
|
|
|
77
491
|
const newSlashingProposer = await this.rollupContract.getSlashingProposer();
|
|
78
492
|
this.slashingProposerContract = newSlashingProposer;
|
|
79
493
|
});
|
|
80
|
-
|
|
494
|
+
// Initialize L1 fee analyzer for fisherman mode
|
|
495
|
+
if (config.fishermanMode) {
|
|
496
|
+
this.l1FeeAnalyzer = new L1FeeAnalyzer(this.l1TxUtils.client, deps.dateProvider, this.log.createChild('fee-analyzer'));
|
|
497
|
+
}
|
|
498
|
+
// Initialize fee asset price oracle
|
|
499
|
+
this.feeAssetPriceOracle = new FeeAssetPriceOracle(this.l1TxUtils.client, this.rollupContract, this.log.createChild('price-oracle'));
|
|
500
|
+
// Initialize failed L1 tx store (optional, for test networks)
|
|
501
|
+
this.failedTxStore = createL1TxFailedStore(config.l1TxFailedStore, this.log);
|
|
502
|
+
this.bundleSimulator = new SequencerBundleSimulator({
|
|
503
|
+
getL1TxUtils: ()=>this.l1TxUtils,
|
|
504
|
+
rollupContract: this.rollupContract,
|
|
505
|
+
epochCache: this.epochCache,
|
|
506
|
+
log: this.log.createChild('bundle-simulator')
|
|
507
|
+
});
|
|
508
|
+
}
|
|
509
|
+
/**
|
|
510
|
+
* Backs up a failed L1 transaction to the configured store for debugging.
|
|
511
|
+
* Does nothing if no store is configured.
|
|
512
|
+
*/ backupFailedTx(failedTx) {
|
|
513
|
+
if (!this.failedTxStore) {
|
|
514
|
+
return;
|
|
515
|
+
}
|
|
516
|
+
const tx = {
|
|
517
|
+
...failedTx,
|
|
518
|
+
timestamp: Date.now()
|
|
519
|
+
};
|
|
520
|
+
// Fire and forget - don't block on backup
|
|
521
|
+
void this.failedTxStore.then((store)=>store?.saveFailedTx(tx)).catch((err)=>{
|
|
522
|
+
this.log.warn(`Failed to backup failed L1 tx to store`, err);
|
|
523
|
+
});
|
|
81
524
|
}
|
|
82
525
|
getRollupContract() {
|
|
83
526
|
return this.rollupContract;
|
|
84
527
|
}
|
|
528
|
+
/**
|
|
529
|
+
* Gets the fee asset price modifier from the oracle.
|
|
530
|
+
*
|
|
531
|
+
* @param predictedParentEthPerFeeAssetE12 - Optional predicted parent eth-per-fee-asset (E12).
|
|
532
|
+
* Pipelined proposers should pass the value from the predicted parent fee header so the
|
|
533
|
+
* modifier matches the parent L1 will use when applying it.
|
|
534
|
+
* @returns The fee asset price modifier in basis points, or 0n if the oracle query fails.
|
|
535
|
+
*/ getFeeAssetPriceModifier(predictedParentEthPerFeeAssetE12) {
|
|
536
|
+
return this.feeAssetPriceOracle.computePriceModifier(predictedParentEthPerFeeAssetE12);
|
|
537
|
+
}
|
|
85
538
|
getSenderAddress() {
|
|
86
539
|
return this.l1TxUtils.getSenderAddress();
|
|
87
540
|
}
|
|
541
|
+
/**
|
|
542
|
+
* Gets the L1 fee analyzer instance (only available in fisherman mode)
|
|
543
|
+
*/ getL1FeeAnalyzer() {
|
|
544
|
+
return this.l1FeeAnalyzer;
|
|
545
|
+
}
|
|
88
546
|
addRequest(request) {
|
|
89
547
|
this.requests.push(request);
|
|
90
548
|
}
|
|
91
549
|
getCurrentL2Slot() {
|
|
92
|
-
return this.epochCache.
|
|
550
|
+
return this.epochCache.getSlotNow();
|
|
551
|
+
}
|
|
552
|
+
/**
|
|
553
|
+
* Clears all pending requests without sending them.
|
|
554
|
+
*/ clearPendingRequests() {
|
|
555
|
+
const count = this.requests.length;
|
|
556
|
+
this.requests = [];
|
|
557
|
+
if (count > 0) {
|
|
558
|
+
this.log.debug(`Cleared ${count} pending request(s)`);
|
|
559
|
+
}
|
|
560
|
+
}
|
|
561
|
+
/**
|
|
562
|
+
* Analyzes L1 fees for the pending requests without sending them.
|
|
563
|
+
* This is used in fisherman mode to validate fee calculations.
|
|
564
|
+
* @param l2SlotNumber - The L2 slot number for this analysis
|
|
565
|
+
* @param onComplete - Optional callback to invoke when analysis completes (after block is mined)
|
|
566
|
+
* @returns The analysis result (incomplete until block mines), or undefined if no requests
|
|
567
|
+
*/ async analyzeL1Fees(l2SlotNumber, onComplete) {
|
|
568
|
+
if (!this.l1FeeAnalyzer) {
|
|
569
|
+
this.log.warn('L1 fee analyzer not available (not in fisherman mode)');
|
|
570
|
+
return undefined;
|
|
571
|
+
}
|
|
572
|
+
const requestsToAnalyze = [
|
|
573
|
+
...this.requests
|
|
574
|
+
];
|
|
575
|
+
if (requestsToAnalyze.length === 0) {
|
|
576
|
+
this.log.debug('No requests to analyze for L1 fees');
|
|
577
|
+
return undefined;
|
|
578
|
+
}
|
|
579
|
+
// Extract blob config from requests (if any)
|
|
580
|
+
const blobConfigs = requestsToAnalyze.filter((request)=>request.blobConfig).map((request)=>request.blobConfig);
|
|
581
|
+
const blobConfig = blobConfigs[0];
|
|
582
|
+
// Get gas configs
|
|
583
|
+
const gasConfigs = requestsToAnalyze.filter((request)=>request.gasConfig).map((request)=>request.gasConfig);
|
|
584
|
+
const gasLimits = gasConfigs.map((g)=>g?.gasLimit).filter((g)=>g !== undefined);
|
|
585
|
+
const gasLimit = gasLimits.length > 0 ? gasLimits.reduce((sum, g)=>sum + g, 0n) : 0n;
|
|
586
|
+
// Get the transaction requests
|
|
587
|
+
const l1Requests = requestsToAnalyze.map((r)=>r.request);
|
|
588
|
+
// Start the analysis
|
|
589
|
+
const analysisId = await this.l1FeeAnalyzer.startAnalysis(l2SlotNumber, gasLimit > 0n ? gasLimit : MAX_L1_TX_LIMIT, l1Requests, blobConfig, onComplete);
|
|
590
|
+
this.log.info('Started L1 fee analysis', {
|
|
591
|
+
analysisId,
|
|
592
|
+
l2SlotNumber: l2SlotNumber.toString(),
|
|
593
|
+
requestCount: requestsToAnalyze.length,
|
|
594
|
+
hasBlobConfig: !!blobConfig,
|
|
595
|
+
gasLimit: gasLimit.toString(),
|
|
596
|
+
actions: requestsToAnalyze.map((r)=>r.action)
|
|
597
|
+
});
|
|
598
|
+
// Return the analysis result (will be incomplete until block mines)
|
|
599
|
+
return this.l1FeeAnalyzer.getAnalysis(analysisId);
|
|
93
600
|
}
|
|
94
601
|
/**
|
|
95
602
|
* Sends all requests that are still valid.
|
|
603
|
+
* @param targetSlot - The target L2 slot for this send. When provided (the production path, via
|
|
604
|
+
* sendRequestsAt), it is threaded into bundleSimulate so the block.timestamp override matches
|
|
605
|
+
* the slot the propose is built for. When omitted, falls back to getCurrentL2Slot() for the
|
|
606
|
+
* AutomineSequencer, which publishes synchronously within the current slot.
|
|
96
607
|
* @returns one of:
|
|
97
608
|
* - A receipt and stats if the tx succeeded
|
|
98
609
|
* - a receipt and errorMsg if it failed on L1
|
|
99
610
|
* - undefined if no valid requests are found OR the tx failed to send.
|
|
100
|
-
*/ async sendRequests() {
|
|
611
|
+
*/ async sendRequests(targetSlot) {
|
|
101
612
|
const requestsToProcess = [
|
|
102
613
|
...this.requests
|
|
103
614
|
];
|
|
104
615
|
this.requests = [];
|
|
105
|
-
if (this.interrupted) {
|
|
616
|
+
if (this.interrupted || requestsToProcess.length === 0) {
|
|
106
617
|
return undefined;
|
|
107
618
|
}
|
|
108
|
-
const currentL2Slot = this.getCurrentL2Slot();
|
|
619
|
+
const currentL2Slot = targetSlot ?? this.getCurrentL2Slot();
|
|
109
620
|
this.log.debug(`Sending requests on L2 slot ${currentL2Slot}`);
|
|
110
621
|
const validRequests = requestsToProcess.filter((request)=>request.lastValidL2Slot >= currentL2Slot);
|
|
111
|
-
const validActions = validRequests.map((x)=>x.action);
|
|
112
622
|
const expiredActions = requestsToProcess.filter((request)=>request.lastValidL2Slot < currentL2Slot).map((x)=>x.action);
|
|
113
623
|
if (validRequests.length !== requestsToProcess.length) {
|
|
114
624
|
this.log.warn(`Some requests were expired for slot ${currentL2Slot}`, {
|
|
@@ -126,40 +636,53 @@ export class SequencerPublisher {
|
|
|
126
636
|
this.log.debug(`No valid requests to send`);
|
|
127
637
|
return undefined;
|
|
128
638
|
}
|
|
129
|
-
//
|
|
130
|
-
|
|
131
|
-
// See https://github.com/AztecProtocol/aztec-packages/issues/11513
|
|
132
|
-
const gasConfigs = requestsToProcess.filter((request)=>request.gasConfig).map((request)=>request.gasConfig);
|
|
133
|
-
const blobConfigs = requestsToProcess.filter((request)=>request.blobConfig).map((request)=>request.blobConfig);
|
|
134
|
-
if (blobConfigs.length > 1) {
|
|
135
|
-
throw new Error('Multiple blob configs found');
|
|
136
|
-
}
|
|
137
|
-
const blobConfig = blobConfigs[0];
|
|
138
|
-
// Merge gasConfigs. Yields the sum of gasLimits, and the earliest txTimeoutAt, or undefined if no gasConfig sets them.
|
|
139
|
-
const gasLimits = gasConfigs.map((g)=>g?.gasLimit).filter((g)=>g !== undefined);
|
|
140
|
-
const gasLimit = gasLimits.length > 0 ? sumBigint(gasLimits) : undefined; // sum
|
|
639
|
+
// Collect earliest txTimeoutAt across all requests.
|
|
640
|
+
const gasConfigs = validRequests.filter((request)=>request.gasConfig).map((request)=>request.gasConfig);
|
|
141
641
|
const txTimeoutAts = gasConfigs.map((g)=>g?.txTimeoutAt).filter((g)=>g !== undefined);
|
|
142
|
-
const txTimeoutAt = txTimeoutAts.length > 0 ? new Date(Math.min(...txTimeoutAts.map((g)=>g.getTime()))) : undefined;
|
|
143
|
-
const txConfig = {
|
|
144
|
-
gasLimit,
|
|
145
|
-
txTimeoutAt
|
|
146
|
-
};
|
|
642
|
+
const txTimeoutAt = txTimeoutAts.length > 0 ? new Date(Math.min(...txTimeoutAts.map((g)=>g.getTime()))) : undefined;
|
|
147
643
|
// Sort the requests so that proposals always go first
|
|
148
644
|
// This ensures the committee gets precomputed correctly
|
|
149
645
|
validRequests.sort((a, b)=>compareActions(a.action, b.action));
|
|
150
646
|
try {
|
|
647
|
+
// Bundle-level eth_simulateV1: filters out entries that revert and derives the gasLimit.
|
|
648
|
+
const bundleResult = await this.bundleSimulator.simulate(validRequests, currentL2Slot);
|
|
649
|
+
if (bundleResult.kind === 'aborted') {
|
|
650
|
+
this.logDroppedInSim(bundleResult.droppedRequests);
|
|
651
|
+
void this.backupDroppedInSim(bundleResult.droppedRequests);
|
|
652
|
+
return undefined;
|
|
653
|
+
}
|
|
654
|
+
const { requests, droppedRequests, gasLimit } = bundleResult.kind === 'fallback' ? {
|
|
655
|
+
requests: bundleResult.requests,
|
|
656
|
+
droppedRequests: bundleResult.droppedRequests,
|
|
657
|
+
gasLimit: MAX_L1_TX_LIMIT
|
|
658
|
+
} : bundleResult;
|
|
659
|
+
this.logDroppedInSim(droppedRequests);
|
|
660
|
+
// Compute blobConfig from survivors (not original validRequests) so that if the propose
|
|
661
|
+
// entry was dropped by bundleSimulate we don't attach a blob-typed config to a non-blob tx.
|
|
662
|
+
const [blobConfig] = requests.filter((r)=>r.blobConfig).map((r)=>r.blobConfig);
|
|
663
|
+
const txConfig = {
|
|
664
|
+
gasLimit,
|
|
665
|
+
txTimeoutAt
|
|
666
|
+
};
|
|
151
667
|
this.log.debug('Forwarding transactions', {
|
|
152
|
-
|
|
668
|
+
requests: requests.map((request)=>request.action),
|
|
153
669
|
txConfig
|
|
154
670
|
});
|
|
155
|
-
const result = await
|
|
156
|
-
|
|
671
|
+
const result = await this.forwardWithPublisherRotation(requests, txConfig, blobConfig);
|
|
672
|
+
if (result === undefined) {
|
|
673
|
+
return undefined;
|
|
674
|
+
}
|
|
675
|
+
const { successfulActions = [], failedActions = [] } = this.callbackBundledTransactions(requests, result);
|
|
676
|
+
const allFailedActions = [
|
|
677
|
+
...failedActions,
|
|
678
|
+
...droppedRequests.map((d)=>d.request.action)
|
|
679
|
+
];
|
|
157
680
|
return {
|
|
158
681
|
result,
|
|
159
682
|
expiredActions,
|
|
160
|
-
sentActions:
|
|
683
|
+
sentActions: requests.map((x)=>x.action),
|
|
161
684
|
successfulActions,
|
|
162
|
-
failedActions
|
|
685
|
+
failedActions: allFailedActions
|
|
163
686
|
};
|
|
164
687
|
} catch (err) {
|
|
165
688
|
const viemError = formatViemError(err);
|
|
@@ -173,47 +696,173 @@ export class SequencerPublisher {
|
|
|
173
696
|
}
|
|
174
697
|
}
|
|
175
698
|
}
|
|
176
|
-
|
|
177
|
-
const
|
|
178
|
-
|
|
179
|
-
this.log.
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
this.log.verbose(`Published bundled transactions (${actionsListStr})`, {
|
|
185
|
-
result,
|
|
186
|
-
requests
|
|
699
|
+
/** Logs entries dropped by bundle simulation as warnings on the publisher's logger. */ logDroppedInSim(dropped) {
|
|
700
|
+
for (const drop of dropped){
|
|
701
|
+
const revertReasonDecoded = drop.revertReason ?? tryDecodeRevertReason(drop.returnData, this.revertDecoderAbi);
|
|
702
|
+
this.log.warn('Bundle entry dropped: action reverted in sim', {
|
|
703
|
+
action: drop.request.action,
|
|
704
|
+
revertReason: revertReasonDecoded ?? drop.returnData,
|
|
705
|
+
revertReasonDecoded,
|
|
706
|
+
returnData: drop.returnData
|
|
187
707
|
});
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
708
|
+
}
|
|
709
|
+
}
|
|
710
|
+
/** Backs up entries dropped by bundle simulation, one record per dropped action. */ async backupDroppedInSim(dropped) {
|
|
711
|
+
if (dropped.length === 0) {
|
|
712
|
+
return;
|
|
713
|
+
}
|
|
714
|
+
const l1BlockNumber = await this.l1TxUtils.getBlockNumber();
|
|
715
|
+
for (const { request: req } of dropped){
|
|
716
|
+
this.backupFailedTx({
|
|
717
|
+
id: keccak256(req.request.data),
|
|
718
|
+
failureType: 'simulation',
|
|
719
|
+
request: {
|
|
720
|
+
to: req.request.to,
|
|
721
|
+
data: req.request.data
|
|
722
|
+
},
|
|
723
|
+
l1BlockNumber: l1BlockNumber.toString(),
|
|
724
|
+
error: {
|
|
725
|
+
message: 'Bundle entry dropped: action reverted in sim'
|
|
726
|
+
},
|
|
727
|
+
context: {
|
|
728
|
+
actions: [
|
|
729
|
+
req.action
|
|
730
|
+
],
|
|
731
|
+
sender: this.getSenderAddress().toString()
|
|
195
732
|
}
|
|
733
|
+
});
|
|
734
|
+
}
|
|
735
|
+
}
|
|
736
|
+
/**
|
|
737
|
+
* Forwards transactions via Multicall3, rotating to the next available publisher if a send
|
|
738
|
+
* failure occurs (i.e. the tx never reached the chain).
|
|
739
|
+
* On-chain reverts and simulation errors are returned as-is without rotation.
|
|
740
|
+
*/ async forwardWithPublisherRotation(validRequests, txConfig, blobConfig) {
|
|
741
|
+
if (!txConfig?.gasLimit) {
|
|
742
|
+
throw new Error('gasLimit is required for bundled transactions');
|
|
743
|
+
}
|
|
744
|
+
const txConfigWithGasLimit = txConfig;
|
|
745
|
+
const triedAddresses = [];
|
|
746
|
+
let currentPublisher = this.l1TxUtils;
|
|
747
|
+
while(true){
|
|
748
|
+
if (txConfig.txTimeoutAt && new Date() > txConfig.txTimeoutAt) {
|
|
749
|
+
this.log.warn(`Tx timeout (${txConfig.txTimeoutAt.toISOString()}) elapsed; stopping publisher rotation`, {
|
|
750
|
+
triedAddresses: triedAddresses.map((a)=>a.toString())
|
|
751
|
+
});
|
|
752
|
+
return undefined;
|
|
196
753
|
}
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
754
|
+
triedAddresses.push(currentPublisher.getSenderAddress());
|
|
755
|
+
try {
|
|
756
|
+
const result = await Multicall3.forward(validRequests.map((r)=>r.request), currentPublisher, txConfigWithGasLimit, blobConfig, {
|
|
757
|
+
gasLimitRequired: true
|
|
758
|
+
});
|
|
759
|
+
this.l1TxUtils = currentPublisher;
|
|
760
|
+
return result;
|
|
761
|
+
} catch (err) {
|
|
762
|
+
if (err instanceof TimeoutError) {
|
|
763
|
+
throw err;
|
|
764
|
+
}
|
|
765
|
+
if (err instanceof MulticallForwarderRevertedError) {
|
|
766
|
+
this.log.error('Forwarder transaction reverted on-chain; not rotating publisher', err, {
|
|
767
|
+
transactionHash: err.receipt.transactionHash
|
|
768
|
+
});
|
|
769
|
+
return undefined;
|
|
770
|
+
}
|
|
771
|
+
const viemError = formatViemError(err);
|
|
772
|
+
if (!this.getNextPublisher) {
|
|
773
|
+
this.log.error('Failed to publish bundled transactions', viemError);
|
|
774
|
+
return undefined;
|
|
775
|
+
}
|
|
776
|
+
this.log.warn(`Publisher ${currentPublisher.getSenderAddress()} failed to send, rotating to next publisher`, viemError);
|
|
777
|
+
const nextPublisher = await this.getNextPublisher([
|
|
778
|
+
...triedAddresses
|
|
779
|
+
]);
|
|
780
|
+
if (!nextPublisher) {
|
|
781
|
+
this.log.error(`All available publishers exhausted (tried ${triedAddresses.length}), failed to publish bundled transactions`, viemError, {
|
|
782
|
+
triedAddresses: triedAddresses.map((a)=>a.toString())
|
|
783
|
+
});
|
|
784
|
+
return undefined;
|
|
785
|
+
}
|
|
786
|
+
currentPublisher = nextPublisher;
|
|
787
|
+
}
|
|
788
|
+
}
|
|
789
|
+
}
|
|
790
|
+
/*
|
|
791
|
+
* Schedules sending all enqueued requests at (or after) the start of the given L2 slot.
|
|
792
|
+
* Sleeps until one L1 slot before the L2 slot boundary so the tx has a chance of being
|
|
793
|
+
* picked up by the first L1 block of the L2 slot.
|
|
794
|
+
* NB: there is a known correctness risk — being included in the L1 block right before the
|
|
795
|
+
* L2 slot starts would revert propose with HeaderLib__InvalidSlotNumber.
|
|
796
|
+
* Uses InterruptibleSleep so it can be cancelled via interrupt().
|
|
797
|
+
*/ async sendRequestsAt(targetSlot) {
|
|
798
|
+
const l1Constants = this.epochCache.getL1Constants();
|
|
799
|
+
// Start of the target L2 slot, in ms (getTimestampForSlot returns seconds).
|
|
800
|
+
const startOfTargetSlotMs = Number(getTimestampForSlot(targetSlot, l1Constants)) * 1000;
|
|
801
|
+
// Aim to be in the mempool one L1 slot before the L2 slot starts, so we have a chance of
|
|
802
|
+
// being picked up by the first L1 block of the L2 slot.
|
|
803
|
+
const submitAfterMs = startOfTargetSlotMs - Number(this.ethereumSlotDuration) * 1000;
|
|
804
|
+
const sleepMs = submitAfterMs - this.dateProvider.now();
|
|
805
|
+
if (sleepMs > 0) {
|
|
806
|
+
this.log.debug(`Sleeping ${sleepMs}ms before sending requests`, {
|
|
807
|
+
targetSlot,
|
|
808
|
+
submitAfterMs
|
|
809
|
+
});
|
|
810
|
+
await this.interruptibleSleep.sleep(sleepMs);
|
|
201
811
|
}
|
|
812
|
+
if (this.interrupted) {
|
|
813
|
+
return undefined;
|
|
814
|
+
}
|
|
815
|
+
return this.sendRequests(targetSlot);
|
|
816
|
+
}
|
|
817
|
+
callbackBundledTransactions(requests, result) {
|
|
818
|
+
const actionsListStr = requests.map((r)=>r.action).join(', ');
|
|
819
|
+
this.log.verbose(`Published bundled transactions (${actionsListStr})`, {
|
|
820
|
+
result,
|
|
821
|
+
requests: requests.map((r)=>({
|
|
822
|
+
...r,
|
|
823
|
+
// Avoid logging large blob data
|
|
824
|
+
blobConfig: r.blobConfig ? {
|
|
825
|
+
...r.blobConfig,
|
|
826
|
+
blobs: r.blobConfig.blobs.map((b)=>({
|
|
827
|
+
size: trimmedBytesLength(b)
|
|
828
|
+
}))
|
|
829
|
+
} : undefined
|
|
830
|
+
}))
|
|
831
|
+
});
|
|
832
|
+
const successfulActions = [];
|
|
833
|
+
const failedActions = [];
|
|
834
|
+
for (const request of requests){
|
|
835
|
+
if (request.checkSuccess(request.request, result)) {
|
|
836
|
+
successfulActions.push(request.action);
|
|
837
|
+
} else {
|
|
838
|
+
failedActions.push(request.action);
|
|
839
|
+
}
|
|
840
|
+
}
|
|
841
|
+
return {
|
|
842
|
+
successfulActions,
|
|
843
|
+
failedActions
|
|
844
|
+
};
|
|
202
845
|
}
|
|
203
846
|
/**
|
|
204
|
-
* @notice Will call `
|
|
847
|
+
* @notice Will call `canProposeAt` to make sure that it is possible to propose
|
|
205
848
|
* @param tipArchive - The archive to check
|
|
206
849
|
* @returns The slot and block number if it is possible to propose, undefined otherwise
|
|
207
|
-
*/
|
|
850
|
+
*/ async canProposeAt(tipArchive, msgSender, simulationOverridesPlan) {
|
|
208
851
|
// TODO: #14291 - should loop through multiple keys to check if any of them can propose
|
|
209
|
-
|
|
852
|
+
// These errors are expected when we cannot actually propose right now — usually because our
|
|
853
|
+
// local view of the chain is ahead of L1 (proposed parent hasn't landed yet, or someone
|
|
854
|
+
// else has just landed the slot, or the archive override doesn't match). We log a warn and
|
|
855
|
+
// skip the proposal; we do NOT treat these as bugs.
|
|
856
|
+
const expectedErrors = [
|
|
210
857
|
'SlotAlreadyInChain',
|
|
211
858
|
'InvalidProposer',
|
|
212
859
|
'InvalidArchive'
|
|
213
860
|
];
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
861
|
+
const slotOffset = this.aztecSlotDuration;
|
|
862
|
+
const nextL1SlotTs = this.getNextL1SlotTimestamp() + slotOffset;
|
|
863
|
+
return this.rollupContract.canProposeAt(tipArchive.toBuffer(), msgSender.toString(), nextL1SlotTs, await buildSimulationOverridesStateOverride(this.rollupContract, simulationOverridesPlan)).catch((err)=>{
|
|
864
|
+
if (err instanceof FormattedViemError && expectedErrors.find((e)=>err.message.includes(e))) {
|
|
865
|
+
this.log.warn(`Failed canProposeAtTime check with ${expectedErrors.find((e)=>err.message.includes(e))}`, {
|
|
217
866
|
error: err.message
|
|
218
867
|
});
|
|
219
868
|
} else {
|
|
@@ -227,24 +876,35 @@ export class SequencerPublisher {
|
|
|
227
876
|
* @dev This is a convenience function that can be used by the sequencer to validate a "partial" header.
|
|
228
877
|
* It will throw if the block header is invalid.
|
|
229
878
|
* @param header - The block header to validate
|
|
230
|
-
*/ async validateBlockHeader(header,
|
|
879
|
+
*/ async validateBlockHeader(header, simulationOverridesPlan) {
|
|
231
880
|
const flags = {
|
|
232
881
|
ignoreDA: true,
|
|
233
882
|
ignoreSignatures: true
|
|
234
883
|
};
|
|
235
884
|
const args = [
|
|
236
885
|
header.toViem(),
|
|
237
|
-
CommitteeAttestationsAndSigners.
|
|
886
|
+
CommitteeAttestationsAndSigners.packAttestations([]),
|
|
238
887
|
[],
|
|
239
888
|
Signature.empty().toViemSignature(),
|
|
240
889
|
`0x${'0'.repeat(64)}`,
|
|
241
|
-
header.
|
|
890
|
+
header.blobsHash.toString(),
|
|
242
891
|
flags
|
|
243
892
|
];
|
|
244
|
-
const
|
|
245
|
-
|
|
246
|
-
const
|
|
247
|
-
|
|
893
|
+
const l1Constants = this.epochCache.getL1Constants();
|
|
894
|
+
const ts = getLastL1SlotTimestampForL2Slot(header.slotNumber, l1Constants);
|
|
895
|
+
const stateOverrides = await buildSimulationOverridesStateOverride(this.rollupContract, simulationOverridesPlan);
|
|
896
|
+
let balance = 0n;
|
|
897
|
+
if (this.config.fishermanMode) {
|
|
898
|
+
// In fisherman mode, we can't know where the proposer is publishing from
|
|
899
|
+
// so we just add sufficient balance to the multicall3 address
|
|
900
|
+
balance = 10n * WEI_CONST * WEI_CONST; // 10 ETH
|
|
901
|
+
} else {
|
|
902
|
+
balance = await this.l1TxUtils.getSenderBalance();
|
|
903
|
+
}
|
|
904
|
+
stateOverrides.push({
|
|
905
|
+
address: MULTI_CALL_3_ADDRESS,
|
|
906
|
+
balance
|
|
907
|
+
});
|
|
248
908
|
await this.l1TxUtils.simulate({
|
|
249
909
|
to: this.rollupContract.address,
|
|
250
910
|
data: encodeFunctionData({
|
|
@@ -254,45 +914,43 @@ export class SequencerPublisher {
|
|
|
254
914
|
}),
|
|
255
915
|
from: MULTI_CALL_3_ADDRESS
|
|
256
916
|
}, {
|
|
257
|
-
time: ts
|
|
258
|
-
},
|
|
259
|
-
{
|
|
260
|
-
address: MULTI_CALL_3_ADDRESS,
|
|
261
|
-
balance
|
|
262
|
-
},
|
|
263
|
-
...await this.rollupContract.makePendingBlockNumberOverride(opts?.forcePendingBlockNumber)
|
|
264
|
-
]);
|
|
917
|
+
time: ts
|
|
918
|
+
}, stateOverrides);
|
|
265
919
|
this.log.debug(`Simulated validateHeader`);
|
|
266
920
|
}
|
|
267
921
|
/**
|
|
268
|
-
* Simulate making a call to invalidate a
|
|
269
|
-
* @param
|
|
270
|
-
*/ async
|
|
922
|
+
* Simulate making a call to invalidate a checkpoint with invalid attestations. Returns undefined if no need to invalidate.
|
|
923
|
+
* @param validationResult - The validation result indicating which checkpoint to invalidate (as returned by the archiver)
|
|
924
|
+
*/ async simulateInvalidateCheckpoint(validationResult) {
|
|
271
925
|
if (validationResult.valid) {
|
|
272
926
|
return undefined;
|
|
273
927
|
}
|
|
274
|
-
const { reason,
|
|
275
|
-
const
|
|
928
|
+
const { reason, checkpoint } = validationResult;
|
|
929
|
+
const checkpointNumber = checkpoint.checkpointNumber;
|
|
276
930
|
const logData = {
|
|
277
|
-
...
|
|
931
|
+
...checkpoint,
|
|
278
932
|
reason
|
|
279
933
|
};
|
|
280
|
-
const
|
|
281
|
-
if (
|
|
282
|
-
this.log.verbose(`Skipping
|
|
283
|
-
|
|
934
|
+
const currentCheckpointNumber = await this.rollupContract.getCheckpointNumber();
|
|
935
|
+
if (currentCheckpointNumber < checkpointNumber) {
|
|
936
|
+
this.log.verbose(`Skipping checkpoint ${checkpointNumber} invalidation since it has already been removed from the pending chain`, {
|
|
937
|
+
currentCheckpointNumber,
|
|
284
938
|
...logData
|
|
285
939
|
});
|
|
286
940
|
return undefined;
|
|
287
941
|
}
|
|
288
|
-
const request = this.
|
|
289
|
-
this.log.debug(`Simulating invalidate
|
|
942
|
+
const request = this.buildInvalidateCheckpointRequest(validationResult);
|
|
943
|
+
this.log.debug(`Simulating invalidate checkpoint ${checkpointNumber}`, {
|
|
290
944
|
...logData,
|
|
291
945
|
request
|
|
292
946
|
});
|
|
947
|
+
const l1BlockNumber = await this.l1TxUtils.getBlockNumber();
|
|
293
948
|
try {
|
|
294
|
-
const { gasUsed } = await this.l1TxUtils.simulate(request, undefined, undefined,
|
|
295
|
-
|
|
949
|
+
const { gasUsed } = await this.l1TxUtils.simulate(request, undefined, undefined, mergeAbis([
|
|
950
|
+
request.abi ?? [],
|
|
951
|
+
ErrorsAbi
|
|
952
|
+
]));
|
|
953
|
+
this.log.verbose(`Simulation for invalidate checkpoint ${checkpointNumber} succeeded`, {
|
|
296
954
|
...logData,
|
|
297
955
|
request,
|
|
298
956
|
gasUsed
|
|
@@ -300,102 +958,83 @@ export class SequencerPublisher {
|
|
|
300
958
|
return {
|
|
301
959
|
request,
|
|
302
960
|
gasUsed,
|
|
303
|
-
|
|
304
|
-
|
|
961
|
+
checkpointNumber,
|
|
962
|
+
forcePendingCheckpointNumber: CheckpointNumber(checkpointNumber - 1),
|
|
963
|
+
lastArchive: validationResult.checkpoint.lastArchive,
|
|
305
964
|
reason
|
|
306
965
|
};
|
|
307
966
|
} catch (err) {
|
|
308
967
|
const viemError = formatViemError(err);
|
|
309
|
-
// If the error is due to the
|
|
310
|
-
// we can safely ignore it and return undefined so we go ahead with
|
|
311
|
-
if (viemError.message?.includes('
|
|
312
|
-
this.log.verbose(`Simulation for invalidate
|
|
968
|
+
// If the error is due to the checkpoint not being in the pending chain, and it was indeed removed by someone else,
|
|
969
|
+
// we can safely ignore it and return undefined so we go ahead with checkpoint building.
|
|
970
|
+
if (viemError.message?.includes('Rollup__CheckpointNotInPendingChain')) {
|
|
971
|
+
this.log.verbose(`Simulation for invalidate checkpoint ${checkpointNumber} failed due to checkpoint not being in pending chain`, {
|
|
313
972
|
...logData,
|
|
314
973
|
request,
|
|
315
974
|
error: viemError.message
|
|
316
975
|
});
|
|
317
|
-
const
|
|
318
|
-
if (
|
|
319
|
-
this.log.verbose(`
|
|
976
|
+
const latestProposedCheckpointNumber = await this.rollupContract.getCheckpointNumber();
|
|
977
|
+
if (latestProposedCheckpointNumber < checkpointNumber) {
|
|
978
|
+
this.log.verbose(`Checkpoint ${checkpointNumber} has already been invalidated`, {
|
|
320
979
|
...logData
|
|
321
980
|
});
|
|
322
981
|
return undefined;
|
|
323
982
|
} else {
|
|
324
|
-
this.log.error(`Simulation for invalidate ${
|
|
325
|
-
throw new Error(`Failed to simulate invalidate
|
|
983
|
+
this.log.error(`Simulation for invalidate checkpoint ${checkpointNumber} failed and it is still in pending chain`, viemError, logData);
|
|
984
|
+
throw new Error(`Failed to simulate invalidate checkpoint ${checkpointNumber} while it is still in pending chain`, {
|
|
326
985
|
cause: viemError
|
|
327
986
|
});
|
|
328
987
|
}
|
|
329
988
|
}
|
|
330
|
-
// Otherwise, throw. We cannot build the next
|
|
331
|
-
this.log.error(`Simulation for invalidate
|
|
332
|
-
|
|
989
|
+
// Otherwise, throw. We cannot build the next checkpoint if we cannot invalidate the previous one.
|
|
990
|
+
this.log.error(`Simulation for invalidate checkpoint ${checkpointNumber} failed`, viemError, logData);
|
|
991
|
+
this.backupFailedTx({
|
|
992
|
+
id: keccak256(request.data),
|
|
993
|
+
failureType: 'simulation',
|
|
994
|
+
request: {
|
|
995
|
+
to: request.to,
|
|
996
|
+
data: request.data,
|
|
997
|
+
value: request.value?.toString()
|
|
998
|
+
},
|
|
999
|
+
l1BlockNumber: l1BlockNumber.toString(),
|
|
1000
|
+
error: {
|
|
1001
|
+
message: viemError.message,
|
|
1002
|
+
name: viemError.name
|
|
1003
|
+
},
|
|
1004
|
+
context: {
|
|
1005
|
+
actions: [
|
|
1006
|
+
`invalidate-${reason}`
|
|
1007
|
+
],
|
|
1008
|
+
checkpointNumber,
|
|
1009
|
+
sender: this.getSenderAddress().toString()
|
|
1010
|
+
}
|
|
1011
|
+
});
|
|
1012
|
+
throw new Error(`Failed to simulate invalidate checkpoint ${checkpointNumber}`, {
|
|
333
1013
|
cause: viemError
|
|
334
1014
|
});
|
|
335
1015
|
}
|
|
336
1016
|
}
|
|
337
|
-
|
|
1017
|
+
buildInvalidateCheckpointRequest(validationResult) {
|
|
338
1018
|
if (validationResult.valid) {
|
|
339
|
-
throw new Error('Cannot invalidate a valid
|
|
1019
|
+
throw new Error('Cannot invalidate a valid checkpoint');
|
|
340
1020
|
}
|
|
341
|
-
const {
|
|
1021
|
+
const { checkpoint, committee, reason } = validationResult;
|
|
342
1022
|
const logData = {
|
|
343
|
-
...
|
|
1023
|
+
...checkpoint,
|
|
344
1024
|
reason
|
|
345
1025
|
};
|
|
346
|
-
this.log.debug(`
|
|
347
|
-
const attestationsAndSigners =
|
|
1026
|
+
this.log.debug(`Building invalidate checkpoint ${checkpoint.checkpointNumber} request`, logData);
|
|
1027
|
+
const attestationsAndSigners = CommitteeAttestationsAndSigners.packAttestations(validationResult.attestations);
|
|
348
1028
|
if (reason === 'invalid-attestation') {
|
|
349
|
-
return this.rollupContract.buildInvalidateBadAttestationRequest(
|
|
1029
|
+
return this.rollupContract.buildInvalidateBadAttestationRequest(checkpoint.checkpointNumber, attestationsAndSigners, committee, validationResult.invalidIndex);
|
|
350
1030
|
} else if (reason === 'insufficient-attestations') {
|
|
351
|
-
return this.rollupContract.buildInvalidateInsufficientAttestationsRequest(
|
|
1031
|
+
return this.rollupContract.buildInvalidateInsufficientAttestationsRequest(checkpoint.checkpointNumber, attestationsAndSigners, committee);
|
|
352
1032
|
} else {
|
|
353
1033
|
const _ = reason;
|
|
354
1034
|
throw new Error(`Unknown reason for invalidation`);
|
|
355
1035
|
}
|
|
356
1036
|
}
|
|
357
|
-
|
|
358
|
-
* @notice Will simulate `propose` to make sure that the block is valid for submission
|
|
359
|
-
*
|
|
360
|
-
* @dev Throws if unable to propose
|
|
361
|
-
*
|
|
362
|
-
* @param block - The block to propose
|
|
363
|
-
* @param attestationData - The block's attestation data
|
|
364
|
-
*
|
|
365
|
-
*/ async validateBlockForSubmission(block, attestationsAndSigners, attestationsAndSignersSignature, options) {
|
|
366
|
-
const ts = BigInt((await this.l1TxUtils.getBlock()).timestamp + this.ethereumSlotDuration);
|
|
367
|
-
// If we have no attestations, we still need to provide the empty attestations
|
|
368
|
-
// so that the committee is recalculated correctly
|
|
369
|
-
const ignoreSignatures = attestationsAndSigners.attestations.length === 0;
|
|
370
|
-
if (ignoreSignatures) {
|
|
371
|
-
const { committee } = await this.epochCache.getCommittee(block.header.globalVariables.slotNumber.toBigInt());
|
|
372
|
-
if (!committee) {
|
|
373
|
-
this.log.warn(`No committee found for slot ${block.header.globalVariables.slotNumber.toBigInt()}`);
|
|
374
|
-
throw new Error(`No committee found for slot ${block.header.globalVariables.slotNumber.toBigInt()}`);
|
|
375
|
-
}
|
|
376
|
-
attestationsAndSigners.attestations = committee.map((committeeMember)=>CommitteeAttestation.fromAddress(committeeMember));
|
|
377
|
-
}
|
|
378
|
-
const blobFields = block.getCheckpointBlobFields();
|
|
379
|
-
const blobs = getBlobsPerL1Block(blobFields);
|
|
380
|
-
const blobInput = getPrefixedEthBlobCommitments(blobs);
|
|
381
|
-
const args = [
|
|
382
|
-
{
|
|
383
|
-
header: block.getCheckpointHeader().toViem(),
|
|
384
|
-
archive: toHex(block.archive.root.toBuffer()),
|
|
385
|
-
stateReference: block.header.state.toViem(),
|
|
386
|
-
oracleInput: {
|
|
387
|
-
feeAssetPriceModifier: 0n
|
|
388
|
-
}
|
|
389
|
-
},
|
|
390
|
-
attestationsAndSigners.getPackedAttestations(),
|
|
391
|
-
attestationsAndSigners.getSigners().map((signer)=>signer.toString()),
|
|
392
|
-
attestationsAndSignersSignature.toViemSignature(),
|
|
393
|
-
blobInput
|
|
394
|
-
];
|
|
395
|
-
await this.simulateProposeTx(args, ts, options);
|
|
396
|
-
return ts;
|
|
397
|
-
}
|
|
398
|
-
async enqueueCastSignalHelper(slotNumber, timestamp, signalType, payload, base, signerAddress, signer) {
|
|
1037
|
+
async enqueueCastSignalHelper(slotNumber, signalType, payload, base, signerAddress, signer) {
|
|
399
1038
|
if (this.lastActions[signalType] && this.lastActions[signalType] === slotNumber) {
|
|
400
1039
|
this.log.debug(`Skipping duplicate vote cast signal ${signalType} for slot ${slotNumber}`);
|
|
401
1040
|
return false;
|
|
@@ -409,9 +1048,34 @@ export class SequencerPublisher {
|
|
|
409
1048
|
}
|
|
410
1049
|
const round = await base.computeRound(slotNumber);
|
|
411
1050
|
const roundInfo = await base.getRoundInfo(this.rollupContract.address, round);
|
|
1051
|
+
if (roundInfo.quorumReached) {
|
|
1052
|
+
return false;
|
|
1053
|
+
}
|
|
412
1054
|
if (roundInfo.lastSignalSlot >= slotNumber) {
|
|
413
1055
|
return false;
|
|
414
1056
|
}
|
|
1057
|
+
if (await base.isPayloadEmpty(payload)) {
|
|
1058
|
+
this.log.warn(`Skipping vote cast for payload with empty code`);
|
|
1059
|
+
return false;
|
|
1060
|
+
}
|
|
1061
|
+
// Skip signaling if there is already a live (non-terminal) Governance proposal for this
|
|
1062
|
+
// payload. This is intentionally not cached: a previously-live proposal may transition to
|
|
1063
|
+
// a terminal state (Dropped/Rejected/Expired/Executed), at which point we may want to re-signal
|
|
1064
|
+
// the same payload in a future round.
|
|
1065
|
+
let proposed = false;
|
|
1066
|
+
try {
|
|
1067
|
+
proposed = await base.hasActiveProposalWithPayload(payload.toString());
|
|
1068
|
+
} catch (err) {
|
|
1069
|
+
// We deliberately swallow the error and proceed to signal. Failing closed (skipping the
|
|
1070
|
+
// signal) on transient RPC errors would let a flaky L1 endpoint silence governance
|
|
1071
|
+
// participation entirely; failing open at worst produces a duplicate signal that the
|
|
1072
|
+
// contract will simply count alongside others in the round.
|
|
1073
|
+
this.log.error(`Failed to check if payload ${payload} was already proposed (signalling anyway)`, err);
|
|
1074
|
+
}
|
|
1075
|
+
if (proposed) {
|
|
1076
|
+
this.log.info(`Payload ${payload} has a live governance proposal, stopping signals`);
|
|
1077
|
+
return false;
|
|
1078
|
+
}
|
|
415
1079
|
const cachedLastVote = this.lastActions[signalType];
|
|
416
1080
|
this.lastActions[signalType] = slotNumber;
|
|
417
1081
|
const action = signalType;
|
|
@@ -422,27 +1086,17 @@ export class SequencerPublisher {
|
|
|
422
1086
|
signer: this.l1TxUtils.client.account?.address,
|
|
423
1087
|
lastValidL2Slot: slotNumber
|
|
424
1088
|
});
|
|
425
|
-
try {
|
|
426
|
-
await this.l1TxUtils.simulate(request, {
|
|
427
|
-
time: timestamp
|
|
428
|
-
}, [], ErrorsAbi);
|
|
429
|
-
this.log.debug(`Simulation for ${action} at slot ${slotNumber} succeeded`, {
|
|
430
|
-
request
|
|
431
|
-
});
|
|
432
|
-
} catch (err) {
|
|
433
|
-
this.log.error(`Failed simulation for ${action} at slot ${slotNumber} (enqueuing the action anyway)`, err);
|
|
434
|
-
// Yes, we enqueue the request anyway, in case there was a bug with the simulation itself
|
|
435
|
-
}
|
|
436
1089
|
// TODO(palla/slash): All votes (governance and slashing) should txTimeoutAt at the end of the slot.
|
|
437
1090
|
this.addRequest({
|
|
438
|
-
gasConfig: {
|
|
439
|
-
gasLimit: SequencerPublisher.VOTE_GAS_GUESS
|
|
440
|
-
},
|
|
441
1091
|
action,
|
|
442
1092
|
request,
|
|
443
1093
|
lastValidL2Slot: slotNumber,
|
|
444
1094
|
checkSuccess: (_request, result)=>{
|
|
445
|
-
const success = result &&
|
|
1095
|
+
const success = result && extractEventSuccess(result.receipt, {
|
|
1096
|
+
address: base.address.toString(),
|
|
1097
|
+
abi: EmpireBaseAbi,
|
|
1098
|
+
eventName: 'SignalCast'
|
|
1099
|
+
});
|
|
446
1100
|
const logData = {
|
|
447
1101
|
...result,
|
|
448
1102
|
slotNumber,
|
|
@@ -450,11 +1104,11 @@ export class SequencerPublisher {
|
|
|
450
1104
|
payload: payload.toString()
|
|
451
1105
|
};
|
|
452
1106
|
if (!success) {
|
|
453
|
-
this.log.error(`Signaling in
|
|
1107
|
+
this.log.error(`Signaling in ${action} for ${payload} at slot ${slotNumber} in round ${round} failed`, logData);
|
|
454
1108
|
this.lastActions[signalType] = cachedLastVote;
|
|
455
1109
|
return false;
|
|
456
1110
|
} else {
|
|
457
|
-
this.log.info(`Signaling in
|
|
1111
|
+
this.log.info(`Signaling in ${action} for ${payload} at slot ${slotNumber} in round ${round} succeeded`, logData);
|
|
458
1112
|
return true;
|
|
459
1113
|
}
|
|
460
1114
|
}
|
|
@@ -464,55 +1118,17 @@ export class SequencerPublisher {
|
|
|
464
1118
|
/**
|
|
465
1119
|
* Enqueues a governance castSignal transaction to cast a signal for a given slot number.
|
|
466
1120
|
* @param slotNumber - The slot number to cast a signal for.
|
|
467
|
-
* @param timestamp - The timestamp of the slot to cast a signal for.
|
|
468
1121
|
* @returns True if the signal was successfully enqueued, false otherwise.
|
|
469
|
-
*/ enqueueGovernanceCastSignal(governancePayload, slotNumber,
|
|
470
|
-
return this.enqueueCastSignalHelper(slotNumber,
|
|
1122
|
+
*/ enqueueGovernanceCastSignal(governancePayload, slotNumber, signerAddress, signer) {
|
|
1123
|
+
return this.enqueueCastSignalHelper(slotNumber, 'governance-signal', governancePayload, this.govProposerContract, signerAddress, signer);
|
|
471
1124
|
}
|
|
472
|
-
/** Enqueues all slashing actions as returned by the slasher client. */ async enqueueSlashingActions(actions, slotNumber,
|
|
1125
|
+
/** Enqueues all slashing actions as returned by the slasher client. */ async enqueueSlashingActions(actions, slotNumber, signerAddress, signer) {
|
|
473
1126
|
if (actions.length === 0) {
|
|
474
1127
|
this.log.debug(`No slashing actions to enqueue for slot ${slotNumber}`);
|
|
475
1128
|
return false;
|
|
476
1129
|
}
|
|
477
1130
|
for (const action of actions){
|
|
478
1131
|
switch(action.type){
|
|
479
|
-
case 'vote-empire-payload':
|
|
480
|
-
{
|
|
481
|
-
if (this.slashingProposerContract?.type !== 'empire') {
|
|
482
|
-
this.log.error('Cannot vote for empire payload on non-empire slashing contract');
|
|
483
|
-
break;
|
|
484
|
-
}
|
|
485
|
-
this.log.debug(`Enqueuing slashing vote for payload ${action.payload} at slot ${slotNumber}`, {
|
|
486
|
-
signerAddress
|
|
487
|
-
});
|
|
488
|
-
await this.enqueueCastSignalHelper(slotNumber, timestamp, 'empire-slashing-signal', action.payload, this.slashingProposerContract, signerAddress, signer);
|
|
489
|
-
break;
|
|
490
|
-
}
|
|
491
|
-
case 'create-empire-payload':
|
|
492
|
-
{
|
|
493
|
-
this.log.debug(`Enqueuing slashing create payload at slot ${slotNumber}`, {
|
|
494
|
-
slotNumber,
|
|
495
|
-
signerAddress
|
|
496
|
-
});
|
|
497
|
-
const request = this.slashFactoryContract.buildCreatePayloadRequest(action.data);
|
|
498
|
-
await this.simulateAndEnqueueRequest('create-empire-payload', request, (receipt)=>!!this.slashFactoryContract.tryExtractSlashPayloadCreatedEvent(receipt.logs), slotNumber, timestamp);
|
|
499
|
-
break;
|
|
500
|
-
}
|
|
501
|
-
case 'execute-empire-payload':
|
|
502
|
-
{
|
|
503
|
-
this.log.debug(`Enqueuing slashing execute payload at slot ${slotNumber}`, {
|
|
504
|
-
slotNumber,
|
|
505
|
-
signerAddress
|
|
506
|
-
});
|
|
507
|
-
if (this.slashingProposerContract?.type !== 'empire') {
|
|
508
|
-
this.log.error('Cannot execute slashing payload on non-empire slashing contract');
|
|
509
|
-
return false;
|
|
510
|
-
}
|
|
511
|
-
const empireSlashingProposer = this.slashingProposerContract;
|
|
512
|
-
const request = empireSlashingProposer.buildExecuteRoundRequest(action.round);
|
|
513
|
-
await this.simulateAndEnqueueRequest('execute-empire-payload', request, (receipt)=>!!empireSlashingProposer.tryExtractPayloadSubmittedEvent(receipt.logs), slotNumber, timestamp);
|
|
514
|
-
break;
|
|
515
|
-
}
|
|
516
1132
|
case 'vote-offenses':
|
|
517
1133
|
{
|
|
518
1134
|
this.log.debug(`Enqueuing slashing vote for ${action.votes.length} votes at slot ${slotNumber}`, {
|
|
@@ -521,14 +1137,17 @@ export class SequencerPublisher {
|
|
|
521
1137
|
votesCount: action.votes.length,
|
|
522
1138
|
signerAddress
|
|
523
1139
|
});
|
|
524
|
-
if (this.slashingProposerContract
|
|
525
|
-
this.log.error('
|
|
1140
|
+
if (!this.slashingProposerContract) {
|
|
1141
|
+
this.log.error('No slashing proposer contract available');
|
|
526
1142
|
return false;
|
|
527
1143
|
}
|
|
528
|
-
const tallySlashingProposer = this.slashingProposerContract;
|
|
529
1144
|
const votes = bufferToHex(encodeSlashConsensusVotes(action.votes));
|
|
530
|
-
const request = await
|
|
531
|
-
|
|
1145
|
+
const request = await this.slashingProposerContract.buildVoteRequestFromSigner(votes, slotNumber, signer);
|
|
1146
|
+
this.enqueueRequest('vote-offenses', request, {
|
|
1147
|
+
address: this.slashingProposerContract.address.toString(),
|
|
1148
|
+
abi: SlashingProposerAbi,
|
|
1149
|
+
eventName: 'VoteCast'
|
|
1150
|
+
}, slotNumber);
|
|
532
1151
|
break;
|
|
533
1152
|
}
|
|
534
1153
|
case 'execute-slash':
|
|
@@ -538,13 +1157,16 @@ export class SequencerPublisher {
|
|
|
538
1157
|
round: action.round,
|
|
539
1158
|
signerAddress
|
|
540
1159
|
});
|
|
541
|
-
if (this.slashingProposerContract
|
|
542
|
-
this.log.error('
|
|
1160
|
+
if (!this.slashingProposerContract) {
|
|
1161
|
+
this.log.error('No slashing proposer contract available');
|
|
543
1162
|
return false;
|
|
544
1163
|
}
|
|
545
|
-
const
|
|
546
|
-
|
|
547
|
-
|
|
1164
|
+
const executeRequest = this.slashingProposerContract.buildExecuteRoundRequest(action.round, action.committees);
|
|
1165
|
+
this.enqueueRequest('execute-slash', executeRequest, {
|
|
1166
|
+
address: this.slashingProposerContract.address.toString(),
|
|
1167
|
+
abi: SlashingProposerAbi,
|
|
1168
|
+
eventName: 'RoundExecuted'
|
|
1169
|
+
}, slotNumber);
|
|
548
1170
|
break;
|
|
549
1171
|
}
|
|
550
1172
|
default:
|
|
@@ -556,78 +1178,57 @@ export class SequencerPublisher {
|
|
|
556
1178
|
}
|
|
557
1179
|
return true;
|
|
558
1180
|
}
|
|
559
|
-
/**
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
* @returns True if the tx has been enqueued, throws otherwise. See #9315
|
|
564
|
-
*/ async enqueueProposeL2Block(block, attestationsAndSigners, attestationsAndSignersSignature, opts = {}) {
|
|
565
|
-
const checkpointHeader = block.getCheckpointHeader();
|
|
566
|
-
const blobFields = block.getCheckpointBlobFields();
|
|
567
|
-
const blobs = getBlobsPerL1Block(blobFields);
|
|
1181
|
+
/** Enqueues a proposal for a checkpoint on L1 */ async enqueueProposeCheckpoint(checkpoint, attestationsAndSigners, attestationsAndSignersSignature, opts = {}) {
|
|
1182
|
+
const checkpointHeader = checkpoint.header;
|
|
1183
|
+
const blobFields = checkpoint.toBlobFields();
|
|
1184
|
+
const blobs = await getBlobsPerL1Block(blobFields);
|
|
568
1185
|
const proposeTxArgs = {
|
|
569
1186
|
header: checkpointHeader,
|
|
570
|
-
archive:
|
|
571
|
-
stateReference: block.header.state,
|
|
572
|
-
body: block.body.toBuffer(),
|
|
1187
|
+
archive: checkpoint.archive.root.toBuffer(),
|
|
573
1188
|
blobs,
|
|
574
1189
|
attestationsAndSigners,
|
|
575
|
-
attestationsAndSignersSignature
|
|
1190
|
+
attestationsAndSignersSignature,
|
|
1191
|
+
feeAssetPriceModifier: checkpoint.feeAssetPriceModifier
|
|
576
1192
|
};
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
// TODO(palla): Check whether we're validating twice, once here and once within addProposeTx, since we call simulateProposeTx in both places.
|
|
584
|
-
ts = await this.validateBlockForSubmission(block, attestationsAndSigners, attestationsAndSignersSignature, opts);
|
|
585
|
-
} catch (err) {
|
|
586
|
-
this.log.error(`Block validation failed. ${err instanceof Error ? err.message : 'No error message'}`, err, {
|
|
587
|
-
...block.getStats(),
|
|
588
|
-
slotNumber: block.header.globalVariables.slotNumber.toBigInt(),
|
|
589
|
-
forcePendingBlockNumber: opts.forcePendingBlockNumber
|
|
590
|
-
});
|
|
591
|
-
throw err;
|
|
592
|
-
}
|
|
593
|
-
this.log.verbose(`Enqueuing block propose transaction`, {
|
|
594
|
-
...block.toBlockInfo(),
|
|
595
|
-
...opts
|
|
1193
|
+
this.log.verbose(`Enqueuing checkpoint propose transaction`, {
|
|
1194
|
+
...checkpoint.toCheckpointInfo(),
|
|
1195
|
+
txTimeoutAt: opts.txTimeoutAt
|
|
1196
|
+
});
|
|
1197
|
+
await this.addProposeTx(checkpoint, proposeTxArgs, {
|
|
1198
|
+
txTimeoutAt: opts.txTimeoutAt
|
|
596
1199
|
});
|
|
597
|
-
await this.addProposeTx(block, proposeTxArgs, opts, ts);
|
|
598
|
-
return true;
|
|
599
1200
|
}
|
|
600
|
-
|
|
1201
|
+
enqueueInvalidateCheckpoint(request, opts = {}) {
|
|
601
1202
|
if (!request) {
|
|
602
1203
|
return;
|
|
603
1204
|
}
|
|
604
|
-
|
|
605
|
-
const gasLimit = this.l1TxUtils.bumpGasLimit(BigInt(Math.ceil(Number(request.gasUsed) * 64 / 63)));
|
|
606
|
-
const { gasUsed, blockNumber } = request;
|
|
1205
|
+
const { gasUsed, checkpointNumber } = request;
|
|
607
1206
|
const logData = {
|
|
608
1207
|
gasUsed,
|
|
609
|
-
|
|
610
|
-
gasLimit,
|
|
1208
|
+
checkpointNumber,
|
|
611
1209
|
opts
|
|
612
1210
|
};
|
|
613
|
-
this.log.verbose(`Enqueuing invalidate
|
|
1211
|
+
this.log.verbose(`Enqueuing invalidate checkpoint request`, logData);
|
|
614
1212
|
this.addRequest({
|
|
615
1213
|
action: `invalidate-by-${request.reason}`,
|
|
616
1214
|
request: request.request,
|
|
617
|
-
gasConfig: {
|
|
618
|
-
gasLimit,
|
|
1215
|
+
gasConfig: opts.txTimeoutAt ? {
|
|
619
1216
|
txTimeoutAt: opts.txTimeoutAt
|
|
620
|
-
},
|
|
621
|
-
lastValidL2Slot: this.getCurrentL2Slot() +
|
|
1217
|
+
} : undefined,
|
|
1218
|
+
lastValidL2Slot: SlotNumber(this.getCurrentL2Slot() + 2),
|
|
622
1219
|
checkSuccess: (_req, result)=>{
|
|
623
|
-
const success = result &&
|
|
1220
|
+
const success = result && extractEventSuccess(result.receipt, {
|
|
1221
|
+
address: this.rollupContract.address,
|
|
1222
|
+
abi: RollupAbi,
|
|
1223
|
+
eventName: 'CheckpointInvalidated'
|
|
1224
|
+
});
|
|
624
1225
|
if (!success) {
|
|
625
|
-
this.log.warn(`Invalidate
|
|
1226
|
+
this.log.warn(`Invalidate checkpoint ${request.checkpointNumber} failed`, {
|
|
626
1227
|
...result,
|
|
627
1228
|
...logData
|
|
628
1229
|
});
|
|
629
1230
|
} else {
|
|
630
|
-
this.log.info(`Invalidate
|
|
1231
|
+
this.log.info(`Invalidate checkpoint ${request.checkpointNumber} succeeded`, {
|
|
631
1232
|
...result,
|
|
632
1233
|
...logData
|
|
633
1234
|
});
|
|
@@ -636,57 +1237,36 @@ export class SequencerPublisher {
|
|
|
636
1237
|
}
|
|
637
1238
|
});
|
|
638
1239
|
}
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
};
|
|
1240
|
+
/**
|
|
1241
|
+
* Dedup-checked enqueue helper for actions that are simulated at bundle-send time rather
|
|
1242
|
+
* than at enqueue time. Validates the (action, slot) dedup key, sets `lastActions`, and
|
|
1243
|
+
* enqueues without a gasLimit so the bundle simulate sets the only gasLimit that matters.
|
|
1244
|
+
*/ enqueueRequest(action, request, eventOpts, slotNumber) {
|
|
645
1245
|
if (this.lastActions[action] && this.lastActions[action] === slotNumber) {
|
|
646
1246
|
this.log.debug(`Skipping duplicate action ${action} for slot ${slotNumber}`);
|
|
647
1247
|
return false;
|
|
648
1248
|
}
|
|
649
1249
|
const cachedLastActionSlot = this.lastActions[action];
|
|
650
1250
|
this.lastActions[action] = slotNumber;
|
|
651
|
-
this.log.debug(`
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
({ gasUsed } = await this.l1TxUtils.simulate(request, {
|
|
655
|
-
time: timestamp
|
|
656
|
-
}, [], ErrorsAbi)); // TODO(palla/slash): Check the timestamp logic
|
|
657
|
-
this.log.verbose(`Simulation for ${action} succeeded`, {
|
|
658
|
-
...logData,
|
|
659
|
-
request,
|
|
660
|
-
gasUsed
|
|
661
|
-
});
|
|
662
|
-
} catch (err) {
|
|
663
|
-
const viemError = formatViemError(err);
|
|
664
|
-
this.log.error(`Simulation for ${action} at ${slotNumber} failed`, viemError, logData);
|
|
665
|
-
return false;
|
|
666
|
-
}
|
|
667
|
-
// We issued the simulation against the rollup contract, so we need to account for the overhead of the multicall3
|
|
668
|
-
const gasLimit = this.l1TxUtils.bumpGasLimit(BigInt(Math.ceil(Number(gasUsed) * 64 / 63)));
|
|
669
|
-
logData.gasLimit = gasLimit;
|
|
670
|
-
this.log.debug(`Enqueuing ${action}`, logData);
|
|
1251
|
+
this.log.debug(`Enqueuing ${action}`, {
|
|
1252
|
+
slotNumber
|
|
1253
|
+
});
|
|
671
1254
|
this.addRequest({
|
|
672
1255
|
action,
|
|
673
1256
|
request,
|
|
674
|
-
gasConfig: {
|
|
675
|
-
gasLimit
|
|
676
|
-
},
|
|
677
1257
|
lastValidL2Slot: slotNumber,
|
|
678
|
-
checkSuccess: (
|
|
679
|
-
const success = result && result.receipt
|
|
1258
|
+
checkSuccess: (_request, result)=>{
|
|
1259
|
+
const success = result && extractEventSuccess(result.receipt, eventOpts);
|
|
680
1260
|
if (!success) {
|
|
681
1261
|
this.log.warn(`Action ${action} at ${slotNumber} failed`, {
|
|
682
1262
|
...result,
|
|
683
|
-
|
|
1263
|
+
slotNumber
|
|
684
1264
|
});
|
|
685
1265
|
this.lastActions[action] = cachedLastActionSlot;
|
|
686
1266
|
} else {
|
|
687
1267
|
this.log.info(`Action ${action} at ${slotNumber} succeeded`, {
|
|
688
1268
|
...result,
|
|
689
|
-
|
|
1269
|
+
slotNumber
|
|
690
1270
|
});
|
|
691
1271
|
}
|
|
692
1272
|
return !!success;
|
|
@@ -701,46 +1281,87 @@ export class SequencerPublisher {
|
|
|
701
1281
|
* A call to `restart` is required before you can continue publishing.
|
|
702
1282
|
*/ interrupt() {
|
|
703
1283
|
this.interrupted = true;
|
|
1284
|
+
this.interruptibleSleep.interrupt();
|
|
704
1285
|
this.l1TxUtils.interrupt();
|
|
705
1286
|
}
|
|
706
1287
|
/** Restarts the publisher after calling `interrupt`. */ restart() {
|
|
707
1288
|
this.interrupted = false;
|
|
708
1289
|
this.l1TxUtils.restart();
|
|
709
1290
|
}
|
|
710
|
-
async prepareProposeTx(encodedData
|
|
1291
|
+
async prepareProposeTx(encodedData) {
|
|
711
1292
|
const kzg = Blob.getViemKzgInstance();
|
|
712
1293
|
const blobInput = getPrefixedEthBlobCommitments(encodedData.blobs);
|
|
713
1294
|
this.log.debug('Validating blob input', {
|
|
714
1295
|
blobInput
|
|
715
1296
|
});
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
1297
|
+
// Get blob evaluation gas
|
|
1298
|
+
let blobEvaluationGas;
|
|
1299
|
+
if (this.config.fishermanMode) {
|
|
1300
|
+
// In fisherman mode, we can't estimate blob gas because estimateGas doesn't support state overrides
|
|
1301
|
+
// Use a fixed estimate.
|
|
1302
|
+
blobEvaluationGas = BigInt(encodedData.blobs.length) * 21_000n;
|
|
1303
|
+
this.log.debug(`Using fixed blob evaluation gas estimate in fisherman mode: ${blobEvaluationGas}`);
|
|
1304
|
+
} else {
|
|
1305
|
+
// We call validateBlobs via estimateGas with real blob+kzg sidecars as a consistency check
|
|
1306
|
+
// that our locally-built blob commitments match the blob data. The bundle simulate at send
|
|
1307
|
+
// time uses eth_simulateV1, which cannot carry blob inputs, so the rollup's on-chain blob
|
|
1308
|
+
// check is forced off there — making this the only pre-flight detector of a commitment/data
|
|
1309
|
+
// mismatch. The returned gas estimate is stashed on the request for the bundle path to read.
|
|
1310
|
+
blobEvaluationGas = await this.l1TxUtils.estimateGas(this.getSenderAddress().toString(), {
|
|
1311
|
+
to: this.rollupContract.address,
|
|
1312
|
+
data: encodeFunctionData({
|
|
1313
|
+
abi: RollupAbi,
|
|
1314
|
+
functionName: 'validateBlobs',
|
|
1315
|
+
args: [
|
|
1316
|
+
blobInput
|
|
1317
|
+
]
|
|
1318
|
+
})
|
|
1319
|
+
}, {}, {
|
|
1320
|
+
blobs: encodedData.blobs.map((b)=>b.data),
|
|
1321
|
+
kzg
|
|
1322
|
+
}).catch(async (err)=>{
|
|
1323
|
+
const viemError = formatViemError(err);
|
|
1324
|
+
this.log.error(`Failed to validate blobs`, viemError.message, {
|
|
1325
|
+
metaMessages: viemError.metaMessages
|
|
1326
|
+
});
|
|
1327
|
+
const validateBlobsData = encodeFunctionData({
|
|
1328
|
+
abi: RollupAbi,
|
|
1329
|
+
functionName: 'validateBlobs',
|
|
1330
|
+
args: [
|
|
1331
|
+
blobInput
|
|
1332
|
+
]
|
|
1333
|
+
});
|
|
1334
|
+
const l1BlockNumber = await this.l1TxUtils.getBlockNumber();
|
|
1335
|
+
this.backupFailedTx({
|
|
1336
|
+
id: keccak256(validateBlobsData),
|
|
1337
|
+
failureType: 'simulation',
|
|
1338
|
+
request: {
|
|
1339
|
+
to: this.rollupContract.address,
|
|
1340
|
+
data: validateBlobsData
|
|
1341
|
+
},
|
|
1342
|
+
blobData: encodedData.blobs.map((b)=>toHex(b.data)),
|
|
1343
|
+
l1BlockNumber: l1BlockNumber.toString(),
|
|
1344
|
+
error: {
|
|
1345
|
+
message: viemError.message,
|
|
1346
|
+
name: viemError.name
|
|
1347
|
+
},
|
|
1348
|
+
context: {
|
|
1349
|
+
actions: [
|
|
1350
|
+
'validate-blobs'
|
|
1351
|
+
],
|
|
1352
|
+
sender: this.getSenderAddress().toString()
|
|
1353
|
+
}
|
|
1354
|
+
});
|
|
1355
|
+
throw new Error('Failed to validate blobs');
|
|
732
1356
|
});
|
|
733
|
-
|
|
734
|
-
});
|
|
1357
|
+
}
|
|
735
1358
|
const signers = encodedData.attestationsAndSigners.getSigners().map((signer)=>signer.toString());
|
|
736
1359
|
const args = [
|
|
737
1360
|
{
|
|
738
1361
|
header: encodedData.header.toViem(),
|
|
739
1362
|
archive: toHex(encodedData.archive),
|
|
740
|
-
stateReference: encodedData.stateReference.toViem(),
|
|
741
1363
|
oracleInput: {
|
|
742
|
-
|
|
743
|
-
feeAssetPriceModifier: 0n
|
|
1364
|
+
feeAssetPriceModifier: encodedData.feeAssetPriceModifier
|
|
744
1365
|
}
|
|
745
1366
|
},
|
|
746
1367
|
encodedData.attestationsAndSigners.getPackedAttestations(),
|
|
@@ -748,82 +1369,40 @@ export class SequencerPublisher {
|
|
|
748
1369
|
encodedData.attestationsAndSignersSignature.toViemSignature(),
|
|
749
1370
|
blobInput
|
|
750
1371
|
];
|
|
751
|
-
const { rollupData, simulationResult } = await this.simulateProposeTx(args, timestamp, options);
|
|
752
|
-
return {
|
|
753
|
-
args,
|
|
754
|
-
blobEvaluationGas,
|
|
755
|
-
rollupData,
|
|
756
|
-
simulationResult
|
|
757
|
-
};
|
|
758
|
-
}
|
|
759
|
-
/**
|
|
760
|
-
* Simulates the propose tx with eth_simulateV1
|
|
761
|
-
* @param args - The propose tx args
|
|
762
|
-
* @param timestamp - The timestamp to simulate proposal at
|
|
763
|
-
* @returns The simulation result
|
|
764
|
-
*/ async simulateProposeTx(args, timestamp, options) {
|
|
765
1372
|
const rollupData = encodeFunctionData({
|
|
766
1373
|
abi: RollupAbi,
|
|
767
1374
|
functionName: 'propose',
|
|
768
1375
|
args
|
|
769
1376
|
});
|
|
770
|
-
// override the pending block number if requested
|
|
771
|
-
const forcePendingBlockNumberStateDiff = (options.forcePendingBlockNumber !== undefined ? await this.rollupContract.makePendingBlockNumberOverride(options.forcePendingBlockNumber) : []).flatMap((override)=>override.stateDiff ?? []);
|
|
772
|
-
const simulationResult = await this.l1TxUtils.simulate({
|
|
773
|
-
to: this.rollupContract.address,
|
|
774
|
-
data: rollupData,
|
|
775
|
-
gas: SequencerPublisher.PROPOSE_GAS_GUESS
|
|
776
|
-
}, {
|
|
777
|
-
// @note we add 1n to the timestamp because geth implementation doesn't like simulation timestamp to be equal to the current block timestamp
|
|
778
|
-
time: timestamp + 1n,
|
|
779
|
-
// @note reth should have a 30m gas limit per block but throws errors that this tx is beyond limit so we increase here
|
|
780
|
-
gasLimit: SequencerPublisher.PROPOSE_GAS_GUESS * 2n
|
|
781
|
-
}, [
|
|
782
|
-
{
|
|
783
|
-
address: this.rollupContract.address,
|
|
784
|
-
// @note we override checkBlob to false since blobs are not part simulate()
|
|
785
|
-
stateDiff: [
|
|
786
|
-
{
|
|
787
|
-
slot: toPaddedHex(RollupContract.checkBlobStorageSlot, true),
|
|
788
|
-
value: toPaddedHex(0n, true)
|
|
789
|
-
},
|
|
790
|
-
...forcePendingBlockNumberStateDiff
|
|
791
|
-
]
|
|
792
|
-
}
|
|
793
|
-
], RollupAbi, {
|
|
794
|
-
// @note fallback gas estimate to use if the node doesn't support simulation API
|
|
795
|
-
fallbackGasEstimate: SequencerPublisher.PROPOSE_GAS_GUESS
|
|
796
|
-
}).catch((err)=>{
|
|
797
|
-
this.log.error(`Failed to simulate propose tx`, err);
|
|
798
|
-
throw err;
|
|
799
|
-
});
|
|
800
1377
|
return {
|
|
801
|
-
|
|
802
|
-
|
|
1378
|
+
args,
|
|
1379
|
+
blobEvaluationGas,
|
|
1380
|
+
rollupData
|
|
803
1381
|
};
|
|
804
1382
|
}
|
|
805
|
-
async addProposeTx(
|
|
1383
|
+
async addProposeTx(checkpoint, encodedData, opts = {}) {
|
|
1384
|
+
const slot = checkpoint.header.slotNumber;
|
|
806
1385
|
const timer = new Timer();
|
|
807
1386
|
const kzg = Blob.getViemKzgInstance();
|
|
808
|
-
const { rollupData,
|
|
1387
|
+
const { rollupData, blobEvaluationGas } = await this.prepareProposeTx(encodedData);
|
|
809
1388
|
const startBlock = await this.l1TxUtils.getBlockNumber();
|
|
810
|
-
|
|
811
|
-
//
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
});
|
|
1389
|
+
// Send the blobs to the blob client preemptively. This helps in tests where the sequencer mistakingly thinks that the propose
|
|
1390
|
+
// tx fails but it does get mined. We make sure that the blobs are sent to the blob client regardless of the tx outcome.
|
|
1391
|
+
void Promise.resolve().then(()=>this.blobClient.sendBlobsToFilestore(encodedData.blobs).catch((_err)=>{
|
|
1392
|
+
this.log.error('Failed to send blobs to blob client');
|
|
1393
|
+
}));
|
|
816
1394
|
return this.addRequest({
|
|
817
1395
|
action: 'propose',
|
|
818
1396
|
request: {
|
|
819
1397
|
to: this.rollupContract.address,
|
|
820
1398
|
data: rollupData
|
|
821
1399
|
},
|
|
822
|
-
lastValidL2Slot:
|
|
1400
|
+
lastValidL2Slot: checkpoint.header.slotNumber,
|
|
823
1401
|
gasConfig: {
|
|
824
|
-
|
|
825
|
-
gasLimit
|
|
1402
|
+
txTimeoutAt: opts.txTimeoutAt,
|
|
1403
|
+
gasLimit: undefined
|
|
826
1404
|
},
|
|
1405
|
+
blobEvaluationGas,
|
|
827
1406
|
blobConfig: {
|
|
828
1407
|
blobs: encodedData.blobs.map((b)=>b.data),
|
|
829
1408
|
kzg
|
|
@@ -833,7 +1412,11 @@ export class SequencerPublisher {
|
|
|
833
1412
|
return false;
|
|
834
1413
|
}
|
|
835
1414
|
const { receipt, stats, errorMsg } = result;
|
|
836
|
-
const success =
|
|
1415
|
+
const success = extractEventSuccess(receipt, {
|
|
1416
|
+
address: this.rollupContract.address,
|
|
1417
|
+
abi: RollupAbi,
|
|
1418
|
+
eventName: 'CheckpointProposed'
|
|
1419
|
+
});
|
|
837
1420
|
if (success) {
|
|
838
1421
|
const endBlock = receipt.blockNumber;
|
|
839
1422
|
const inclusionBlocks = Number(endBlock - startBlock);
|
|
@@ -847,29 +1430,31 @@ export class SequencerPublisher {
|
|
|
847
1430
|
calldataGas,
|
|
848
1431
|
calldataSize,
|
|
849
1432
|
sender,
|
|
850
|
-
...
|
|
1433
|
+
...checkpoint.getStats(),
|
|
851
1434
|
eventName: 'rollup-published-to-l1',
|
|
852
1435
|
blobCount: encodedData.blobs.length,
|
|
853
1436
|
inclusionBlocks
|
|
854
1437
|
};
|
|
855
|
-
this.log.info(`Published
|
|
1438
|
+
this.log.info(`Published checkpoint ${checkpoint.number} at slot ${slot} to rollup contract`, {
|
|
856
1439
|
...stats,
|
|
857
|
-
...
|
|
858
|
-
...receipt
|
|
1440
|
+
...checkpoint.getStats(),
|
|
1441
|
+
...pick(receipt, 'transactionHash', 'blockHash')
|
|
859
1442
|
});
|
|
860
1443
|
this.metrics.recordProcessBlockTx(timer.ms(), publishStats);
|
|
861
1444
|
return true;
|
|
862
1445
|
} else {
|
|
863
1446
|
this.metrics.recordFailedTx('process');
|
|
864
|
-
this.log.error(`
|
|
865
|
-
...
|
|
866
|
-
receipt
|
|
867
|
-
txHash: receipt.transactionHash,
|
|
868
|
-
slotNumber: block.header.globalVariables.slotNumber.toBigInt()
|
|
1447
|
+
this.log.error(`Publishing checkpoint at slot ${slot} failed with ${errorMsg ?? 'no error message'}`, undefined, {
|
|
1448
|
+
...checkpoint.getStats(),
|
|
1449
|
+
...receipt
|
|
869
1450
|
});
|
|
870
1451
|
return false;
|
|
871
1452
|
}
|
|
872
1453
|
}
|
|
873
1454
|
});
|
|
874
1455
|
}
|
|
1456
|
+
/** Returns the timestamp of the next L1 slot boundary after now. */ getNextL1SlotTimestamp() {
|
|
1457
|
+
const l1Constants = this.epochCache.getL1Constants();
|
|
1458
|
+
return getNextL1SlotTimestamp(this.dateProvider.nowInSeconds(), l1Constants);
|
|
1459
|
+
}
|
|
875
1460
|
}
|