@aztec/sequencer-client 0.0.1-commit.b655e406 → 0.0.1-commit.b9865e97
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 +1004 -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 +1793 -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 +798 -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 +1633 -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,176 @@ 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()
|
|
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;
|
|
753
|
+
}
|
|
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;
|
|
195
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;
|
|
196
787
|
}
|
|
197
|
-
return {
|
|
198
|
-
successfulActions,
|
|
199
|
-
failedActions
|
|
200
|
-
};
|
|
201
788
|
}
|
|
202
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
|
+
if (this.interrupted) {
|
|
805
|
+
return undefined;
|
|
806
|
+
}
|
|
807
|
+
const sleepMs = submitAfterMs - this.dateProvider.now();
|
|
808
|
+
if (sleepMs > 0) {
|
|
809
|
+
this.log.debug(`Sleeping ${sleepMs}ms before sending requests`, {
|
|
810
|
+
targetSlot,
|
|
811
|
+
submitAfterMs
|
|
812
|
+
});
|
|
813
|
+
await this.interruptibleSleep.sleep(sleepMs);
|
|
814
|
+
}
|
|
815
|
+
if (this.interrupted) {
|
|
816
|
+
return undefined;
|
|
817
|
+
}
|
|
818
|
+
return this.sendRequests(targetSlot);
|
|
819
|
+
}
|
|
820
|
+
callbackBundledTransactions(requests, result) {
|
|
821
|
+
const actionsListStr = requests.map((r)=>r.action).join(', ');
|
|
822
|
+
this.log.verbose(`Published bundled transactions (${actionsListStr})`, {
|
|
823
|
+
result,
|
|
824
|
+
requests: requests.map((r)=>({
|
|
825
|
+
...r,
|
|
826
|
+
// Avoid logging large blob data
|
|
827
|
+
blobConfig: r.blobConfig ? {
|
|
828
|
+
...r.blobConfig,
|
|
829
|
+
blobs: r.blobConfig.blobs.map((b)=>({
|
|
830
|
+
size: trimmedBytesLength(b)
|
|
831
|
+
}))
|
|
832
|
+
} : undefined
|
|
833
|
+
}))
|
|
834
|
+
});
|
|
835
|
+
const successfulActions = [];
|
|
836
|
+
const failedActions = [];
|
|
837
|
+
for (const request of requests){
|
|
838
|
+
if (request.checkSuccess(request.request, result)) {
|
|
839
|
+
successfulActions.push(request.action);
|
|
840
|
+
} else {
|
|
841
|
+
failedActions.push(request.action);
|
|
842
|
+
}
|
|
843
|
+
}
|
|
844
|
+
return {
|
|
845
|
+
successfulActions,
|
|
846
|
+
failedActions
|
|
847
|
+
};
|
|
848
|
+
}
|
|
203
849
|
/**
|
|
204
|
-
* @notice Will call `
|
|
850
|
+
* @notice Will call `canProposeAt` to make sure that it is possible to propose
|
|
205
851
|
* @param tipArchive - The archive to check
|
|
206
852
|
* @returns The slot and block number if it is possible to propose, undefined otherwise
|
|
207
|
-
*/
|
|
853
|
+
*/ async canProposeAt(tipArchive, msgSender, simulationOverridesPlan) {
|
|
208
854
|
// TODO: #14291 - should loop through multiple keys to check if any of them can propose
|
|
209
|
-
|
|
855
|
+
// These errors are expected when we cannot actually propose right now — usually because our
|
|
856
|
+
// local view of the chain is ahead of L1 (proposed parent hasn't landed yet, or someone
|
|
857
|
+
// else has just landed the slot, or the archive override doesn't match). We log a warn and
|
|
858
|
+
// skip the proposal; we do NOT treat these as bugs.
|
|
859
|
+
const expectedErrors = [
|
|
210
860
|
'SlotAlreadyInChain',
|
|
211
861
|
'InvalidProposer',
|
|
212
862
|
'InvalidArchive'
|
|
213
863
|
];
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
864
|
+
const slotOffset = this.aztecSlotDuration;
|
|
865
|
+
const nextL1SlotTs = this.getNextL1SlotTimestamp() + slotOffset;
|
|
866
|
+
return this.rollupContract.canProposeAt(tipArchive.toBuffer(), msgSender.toString(), nextL1SlotTs, await buildSimulationOverridesStateOverride(this.rollupContract, simulationOverridesPlan)).catch((err)=>{
|
|
867
|
+
if (err instanceof FormattedViemError && expectedErrors.find((e)=>err.message.includes(e))) {
|
|
868
|
+
this.log.warn(`Failed canProposeAtTime check with ${expectedErrors.find((e)=>err.message.includes(e))}`, {
|
|
217
869
|
error: err.message
|
|
218
870
|
});
|
|
219
871
|
} else {
|
|
@@ -227,24 +879,35 @@ export class SequencerPublisher {
|
|
|
227
879
|
* @dev This is a convenience function that can be used by the sequencer to validate a "partial" header.
|
|
228
880
|
* It will throw if the block header is invalid.
|
|
229
881
|
* @param header - The block header to validate
|
|
230
|
-
*/ async validateBlockHeader(header,
|
|
882
|
+
*/ async validateBlockHeader(header, simulationOverridesPlan) {
|
|
231
883
|
const flags = {
|
|
232
884
|
ignoreDA: true,
|
|
233
885
|
ignoreSignatures: true
|
|
234
886
|
};
|
|
235
887
|
const args = [
|
|
236
888
|
header.toViem(),
|
|
237
|
-
CommitteeAttestationsAndSigners.
|
|
889
|
+
CommitteeAttestationsAndSigners.packAttestations([]),
|
|
238
890
|
[],
|
|
239
891
|
Signature.empty().toViemSignature(),
|
|
240
892
|
`0x${'0'.repeat(64)}`,
|
|
241
|
-
header.
|
|
893
|
+
header.blobsHash.toString(),
|
|
242
894
|
flags
|
|
243
895
|
];
|
|
244
|
-
const
|
|
245
|
-
|
|
246
|
-
const
|
|
247
|
-
|
|
896
|
+
const l1Constants = this.epochCache.getL1Constants();
|
|
897
|
+
const ts = getLastL1SlotTimestampForL2Slot(header.slotNumber, l1Constants);
|
|
898
|
+
const stateOverrides = await buildSimulationOverridesStateOverride(this.rollupContract, simulationOverridesPlan);
|
|
899
|
+
let balance = 0n;
|
|
900
|
+
if (this.config.fishermanMode) {
|
|
901
|
+
// In fisherman mode, we can't know where the proposer is publishing from
|
|
902
|
+
// so we just add sufficient balance to the multicall3 address
|
|
903
|
+
balance = 10n * WEI_CONST * WEI_CONST; // 10 ETH
|
|
904
|
+
} else {
|
|
905
|
+
balance = await this.l1TxUtils.getSenderBalance();
|
|
906
|
+
}
|
|
907
|
+
stateOverrides.push({
|
|
908
|
+
address: MULTI_CALL_3_ADDRESS,
|
|
909
|
+
balance
|
|
910
|
+
});
|
|
248
911
|
await this.l1TxUtils.simulate({
|
|
249
912
|
to: this.rollupContract.address,
|
|
250
913
|
data: encodeFunctionData({
|
|
@@ -254,45 +917,43 @@ export class SequencerPublisher {
|
|
|
254
917
|
}),
|
|
255
918
|
from: MULTI_CALL_3_ADDRESS
|
|
256
919
|
}, {
|
|
257
|
-
time: ts
|
|
258
|
-
},
|
|
259
|
-
{
|
|
260
|
-
address: MULTI_CALL_3_ADDRESS,
|
|
261
|
-
balance
|
|
262
|
-
},
|
|
263
|
-
...await this.rollupContract.makePendingBlockNumberOverride(opts?.forcePendingBlockNumber)
|
|
264
|
-
]);
|
|
920
|
+
time: ts
|
|
921
|
+
}, stateOverrides);
|
|
265
922
|
this.log.debug(`Simulated validateHeader`);
|
|
266
923
|
}
|
|
267
924
|
/**
|
|
268
|
-
* Simulate making a call to invalidate a
|
|
269
|
-
* @param
|
|
270
|
-
*/ async
|
|
925
|
+
* Simulate making a call to invalidate a checkpoint with invalid attestations. Returns undefined if no need to invalidate.
|
|
926
|
+
* @param validationResult - The validation result indicating which checkpoint to invalidate (as returned by the archiver)
|
|
927
|
+
*/ async simulateInvalidateCheckpoint(validationResult) {
|
|
271
928
|
if (validationResult.valid) {
|
|
272
929
|
return undefined;
|
|
273
930
|
}
|
|
274
|
-
const { reason,
|
|
275
|
-
const
|
|
931
|
+
const { reason, checkpoint } = validationResult;
|
|
932
|
+
const checkpointNumber = checkpoint.checkpointNumber;
|
|
276
933
|
const logData = {
|
|
277
|
-
...
|
|
934
|
+
...checkpoint,
|
|
278
935
|
reason
|
|
279
936
|
};
|
|
280
|
-
const
|
|
281
|
-
if (
|
|
282
|
-
this.log.verbose(`Skipping
|
|
283
|
-
|
|
937
|
+
const currentCheckpointNumber = await this.rollupContract.getCheckpointNumber();
|
|
938
|
+
if (currentCheckpointNumber < checkpointNumber) {
|
|
939
|
+
this.log.verbose(`Skipping checkpoint ${checkpointNumber} invalidation since it has already been removed from the pending chain`, {
|
|
940
|
+
currentCheckpointNumber,
|
|
284
941
|
...logData
|
|
285
942
|
});
|
|
286
943
|
return undefined;
|
|
287
944
|
}
|
|
288
|
-
const request = this.
|
|
289
|
-
this.log.debug(`Simulating invalidate
|
|
945
|
+
const request = this.buildInvalidateCheckpointRequest(validationResult);
|
|
946
|
+
this.log.debug(`Simulating invalidate checkpoint ${checkpointNumber}`, {
|
|
290
947
|
...logData,
|
|
291
948
|
request
|
|
292
949
|
});
|
|
950
|
+
const l1BlockNumber = await this.l1TxUtils.getBlockNumber();
|
|
293
951
|
try {
|
|
294
|
-
const { gasUsed } = await this.l1TxUtils.simulate(request, undefined, undefined,
|
|
295
|
-
|
|
952
|
+
const { gasUsed } = await this.l1TxUtils.simulate(request, undefined, undefined, mergeAbis([
|
|
953
|
+
request.abi ?? [],
|
|
954
|
+
ErrorsAbi
|
|
955
|
+
]));
|
|
956
|
+
this.log.verbose(`Simulation for invalidate checkpoint ${checkpointNumber} succeeded`, {
|
|
296
957
|
...logData,
|
|
297
958
|
request,
|
|
298
959
|
gasUsed
|
|
@@ -300,102 +961,83 @@ export class SequencerPublisher {
|
|
|
300
961
|
return {
|
|
301
962
|
request,
|
|
302
963
|
gasUsed,
|
|
303
|
-
|
|
304
|
-
|
|
964
|
+
checkpointNumber,
|
|
965
|
+
forcePendingCheckpointNumber: CheckpointNumber(checkpointNumber - 1),
|
|
966
|
+
lastArchive: validationResult.checkpoint.lastArchive,
|
|
305
967
|
reason
|
|
306
968
|
};
|
|
307
969
|
} catch (err) {
|
|
308
970
|
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
|
|
971
|
+
// If the error is due to the checkpoint not being in the pending chain, and it was indeed removed by someone else,
|
|
972
|
+
// we can safely ignore it and return undefined so we go ahead with checkpoint building.
|
|
973
|
+
if (viemError.message?.includes('Rollup__CheckpointNotInPendingChain')) {
|
|
974
|
+
this.log.verbose(`Simulation for invalidate checkpoint ${checkpointNumber} failed due to checkpoint not being in pending chain`, {
|
|
313
975
|
...logData,
|
|
314
976
|
request,
|
|
315
977
|
error: viemError.message
|
|
316
978
|
});
|
|
317
|
-
const
|
|
318
|
-
if (
|
|
319
|
-
this.log.verbose(`
|
|
979
|
+
const latestProposedCheckpointNumber = await this.rollupContract.getCheckpointNumber();
|
|
980
|
+
if (latestProposedCheckpointNumber < checkpointNumber) {
|
|
981
|
+
this.log.verbose(`Checkpoint ${checkpointNumber} has already been invalidated`, {
|
|
320
982
|
...logData
|
|
321
983
|
});
|
|
322
984
|
return undefined;
|
|
323
985
|
} else {
|
|
324
|
-
this.log.error(`Simulation for invalidate ${
|
|
325
|
-
throw new Error(`Failed to simulate invalidate
|
|
986
|
+
this.log.error(`Simulation for invalidate checkpoint ${checkpointNumber} failed and it is still in pending chain`, viemError, logData);
|
|
987
|
+
throw new Error(`Failed to simulate invalidate checkpoint ${checkpointNumber} while it is still in pending chain`, {
|
|
326
988
|
cause: viemError
|
|
327
989
|
});
|
|
328
990
|
}
|
|
329
991
|
}
|
|
330
|
-
// Otherwise, throw. We cannot build the next
|
|
331
|
-
this.log.error(`Simulation for invalidate
|
|
332
|
-
|
|
992
|
+
// Otherwise, throw. We cannot build the next checkpoint if we cannot invalidate the previous one.
|
|
993
|
+
this.log.error(`Simulation for invalidate checkpoint ${checkpointNumber} failed`, viemError, logData);
|
|
994
|
+
this.backupFailedTx({
|
|
995
|
+
id: keccak256(request.data),
|
|
996
|
+
failureType: 'simulation',
|
|
997
|
+
request: {
|
|
998
|
+
to: request.to,
|
|
999
|
+
data: request.data,
|
|
1000
|
+
value: request.value?.toString()
|
|
1001
|
+
},
|
|
1002
|
+
l1BlockNumber: l1BlockNumber.toString(),
|
|
1003
|
+
error: {
|
|
1004
|
+
message: viemError.message,
|
|
1005
|
+
name: viemError.name
|
|
1006
|
+
},
|
|
1007
|
+
context: {
|
|
1008
|
+
actions: [
|
|
1009
|
+
`invalidate-${reason}`
|
|
1010
|
+
],
|
|
1011
|
+
checkpointNumber,
|
|
1012
|
+
sender: this.getSenderAddress().toString()
|
|
1013
|
+
}
|
|
1014
|
+
});
|
|
1015
|
+
throw new Error(`Failed to simulate invalidate checkpoint ${checkpointNumber}`, {
|
|
333
1016
|
cause: viemError
|
|
334
1017
|
});
|
|
335
1018
|
}
|
|
336
1019
|
}
|
|
337
|
-
|
|
1020
|
+
buildInvalidateCheckpointRequest(validationResult) {
|
|
338
1021
|
if (validationResult.valid) {
|
|
339
|
-
throw new Error('Cannot invalidate a valid
|
|
1022
|
+
throw new Error('Cannot invalidate a valid checkpoint');
|
|
340
1023
|
}
|
|
341
|
-
const {
|
|
1024
|
+
const { checkpoint, committee, reason } = validationResult;
|
|
342
1025
|
const logData = {
|
|
343
|
-
...
|
|
1026
|
+
...checkpoint,
|
|
344
1027
|
reason
|
|
345
1028
|
};
|
|
346
|
-
this.log.debug(`
|
|
347
|
-
const attestationsAndSigners =
|
|
1029
|
+
this.log.debug(`Building invalidate checkpoint ${checkpoint.checkpointNumber} request`, logData);
|
|
1030
|
+
const attestationsAndSigners = CommitteeAttestationsAndSigners.packAttestations(validationResult.attestations);
|
|
348
1031
|
if (reason === 'invalid-attestation') {
|
|
349
|
-
return this.rollupContract.buildInvalidateBadAttestationRequest(
|
|
1032
|
+
return this.rollupContract.buildInvalidateBadAttestationRequest(checkpoint.checkpointNumber, attestationsAndSigners, committee, validationResult.invalidIndex);
|
|
350
1033
|
} else if (reason === 'insufficient-attestations') {
|
|
351
|
-
return this.rollupContract.buildInvalidateInsufficientAttestationsRequest(
|
|
1034
|
+
return this.rollupContract.buildInvalidateInsufficientAttestationsRequest(checkpoint.checkpointNumber, attestationsAndSigners, committee);
|
|
352
1035
|
} else {
|
|
353
1036
|
const _ = reason;
|
|
354
1037
|
throw new Error(`Unknown reason for invalidation`);
|
|
355
1038
|
}
|
|
356
1039
|
}
|
|
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) {
|
|
1040
|
+
async enqueueCastSignalHelper(slotNumber, signalType, payload, base, signerAddress, signer) {
|
|
399
1041
|
if (this.lastActions[signalType] && this.lastActions[signalType] === slotNumber) {
|
|
400
1042
|
this.log.debug(`Skipping duplicate vote cast signal ${signalType} for slot ${slotNumber}`);
|
|
401
1043
|
return false;
|
|
@@ -409,9 +1051,34 @@ export class SequencerPublisher {
|
|
|
409
1051
|
}
|
|
410
1052
|
const round = await base.computeRound(slotNumber);
|
|
411
1053
|
const roundInfo = await base.getRoundInfo(this.rollupContract.address, round);
|
|
1054
|
+
if (roundInfo.quorumReached) {
|
|
1055
|
+
return false;
|
|
1056
|
+
}
|
|
412
1057
|
if (roundInfo.lastSignalSlot >= slotNumber) {
|
|
413
1058
|
return false;
|
|
414
1059
|
}
|
|
1060
|
+
if (await base.isPayloadEmpty(payload)) {
|
|
1061
|
+
this.log.warn(`Skipping vote cast for payload with empty code`);
|
|
1062
|
+
return false;
|
|
1063
|
+
}
|
|
1064
|
+
// Skip signaling if there is already a live (non-terminal) Governance proposal for this
|
|
1065
|
+
// payload. This is intentionally not cached: a previously-live proposal may transition to
|
|
1066
|
+
// a terminal state (Dropped/Rejected/Expired/Executed), at which point we may want to re-signal
|
|
1067
|
+
// the same payload in a future round.
|
|
1068
|
+
let proposed = false;
|
|
1069
|
+
try {
|
|
1070
|
+
proposed = await base.hasActiveProposalWithPayload(payload.toString());
|
|
1071
|
+
} catch (err) {
|
|
1072
|
+
// We deliberately swallow the error and proceed to signal. Failing closed (skipping the
|
|
1073
|
+
// signal) on transient RPC errors would let a flaky L1 endpoint silence governance
|
|
1074
|
+
// participation entirely; failing open at worst produces a duplicate signal that the
|
|
1075
|
+
// contract will simply count alongside others in the round.
|
|
1076
|
+
this.log.error(`Failed to check if payload ${payload} was already proposed (signalling anyway)`, err);
|
|
1077
|
+
}
|
|
1078
|
+
if (proposed) {
|
|
1079
|
+
this.log.info(`Payload ${payload} has a live governance proposal, stopping signals`);
|
|
1080
|
+
return false;
|
|
1081
|
+
}
|
|
415
1082
|
const cachedLastVote = this.lastActions[signalType];
|
|
416
1083
|
this.lastActions[signalType] = slotNumber;
|
|
417
1084
|
const action = signalType;
|
|
@@ -422,27 +1089,17 @@ export class SequencerPublisher {
|
|
|
422
1089
|
signer: this.l1TxUtils.client.account?.address,
|
|
423
1090
|
lastValidL2Slot: slotNumber
|
|
424
1091
|
});
|
|
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
1092
|
// TODO(palla/slash): All votes (governance and slashing) should txTimeoutAt at the end of the slot.
|
|
437
1093
|
this.addRequest({
|
|
438
|
-
gasConfig: {
|
|
439
|
-
gasLimit: SequencerPublisher.VOTE_GAS_GUESS
|
|
440
|
-
},
|
|
441
1094
|
action,
|
|
442
1095
|
request,
|
|
443
1096
|
lastValidL2Slot: slotNumber,
|
|
444
1097
|
checkSuccess: (_request, result)=>{
|
|
445
|
-
const success = result &&
|
|
1098
|
+
const success = result && extractEventSuccess(result.receipt, {
|
|
1099
|
+
address: base.address.toString(),
|
|
1100
|
+
abi: EmpireBaseAbi,
|
|
1101
|
+
eventName: 'SignalCast'
|
|
1102
|
+
});
|
|
446
1103
|
const logData = {
|
|
447
1104
|
...result,
|
|
448
1105
|
slotNumber,
|
|
@@ -450,11 +1107,11 @@ export class SequencerPublisher {
|
|
|
450
1107
|
payload: payload.toString()
|
|
451
1108
|
};
|
|
452
1109
|
if (!success) {
|
|
453
|
-
this.log.error(`Signaling in
|
|
1110
|
+
this.log.error(`Signaling in ${action} for ${payload} at slot ${slotNumber} in round ${round} failed`, logData);
|
|
454
1111
|
this.lastActions[signalType] = cachedLastVote;
|
|
455
1112
|
return false;
|
|
456
1113
|
} else {
|
|
457
|
-
this.log.info(`Signaling in
|
|
1114
|
+
this.log.info(`Signaling in ${action} for ${payload} at slot ${slotNumber} in round ${round} succeeded`, logData);
|
|
458
1115
|
return true;
|
|
459
1116
|
}
|
|
460
1117
|
}
|
|
@@ -464,55 +1121,17 @@ export class SequencerPublisher {
|
|
|
464
1121
|
/**
|
|
465
1122
|
* Enqueues a governance castSignal transaction to cast a signal for a given slot number.
|
|
466
1123
|
* @param slotNumber - The slot number to cast a signal for.
|
|
467
|
-
* @param timestamp - The timestamp of the slot to cast a signal for.
|
|
468
1124
|
* @returns True if the signal was successfully enqueued, false otherwise.
|
|
469
|
-
*/ enqueueGovernanceCastSignal(governancePayload, slotNumber,
|
|
470
|
-
return this.enqueueCastSignalHelper(slotNumber,
|
|
1125
|
+
*/ enqueueGovernanceCastSignal(governancePayload, slotNumber, signerAddress, signer) {
|
|
1126
|
+
return this.enqueueCastSignalHelper(slotNumber, 'governance-signal', governancePayload, this.govProposerContract, signerAddress, signer);
|
|
471
1127
|
}
|
|
472
|
-
/** Enqueues all slashing actions as returned by the slasher client. */ async enqueueSlashingActions(actions, slotNumber,
|
|
1128
|
+
/** Enqueues all slashing actions as returned by the slasher client. */ async enqueueSlashingActions(actions, slotNumber, signerAddress, signer) {
|
|
473
1129
|
if (actions.length === 0) {
|
|
474
1130
|
this.log.debug(`No slashing actions to enqueue for slot ${slotNumber}`);
|
|
475
1131
|
return false;
|
|
476
1132
|
}
|
|
477
1133
|
for (const action of actions){
|
|
478
1134
|
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
1135
|
case 'vote-offenses':
|
|
517
1136
|
{
|
|
518
1137
|
this.log.debug(`Enqueuing slashing vote for ${action.votes.length} votes at slot ${slotNumber}`, {
|
|
@@ -521,14 +1140,17 @@ export class SequencerPublisher {
|
|
|
521
1140
|
votesCount: action.votes.length,
|
|
522
1141
|
signerAddress
|
|
523
1142
|
});
|
|
524
|
-
if (this.slashingProposerContract
|
|
525
|
-
this.log.error('
|
|
1143
|
+
if (!this.slashingProposerContract) {
|
|
1144
|
+
this.log.error('No slashing proposer contract available');
|
|
526
1145
|
return false;
|
|
527
1146
|
}
|
|
528
|
-
const tallySlashingProposer = this.slashingProposerContract;
|
|
529
1147
|
const votes = bufferToHex(encodeSlashConsensusVotes(action.votes));
|
|
530
|
-
const request = await
|
|
531
|
-
|
|
1148
|
+
const request = await this.slashingProposerContract.buildVoteRequestFromSigner(votes, slotNumber, signer);
|
|
1149
|
+
this.enqueueRequest('vote-offenses', request, {
|
|
1150
|
+
address: this.slashingProposerContract.address.toString(),
|
|
1151
|
+
abi: SlashingProposerAbi,
|
|
1152
|
+
eventName: 'VoteCast'
|
|
1153
|
+
}, slotNumber);
|
|
532
1154
|
break;
|
|
533
1155
|
}
|
|
534
1156
|
case 'execute-slash':
|
|
@@ -538,13 +1160,16 @@ export class SequencerPublisher {
|
|
|
538
1160
|
round: action.round,
|
|
539
1161
|
signerAddress
|
|
540
1162
|
});
|
|
541
|
-
if (this.slashingProposerContract
|
|
542
|
-
this.log.error('
|
|
1163
|
+
if (!this.slashingProposerContract) {
|
|
1164
|
+
this.log.error('No slashing proposer contract available');
|
|
543
1165
|
return false;
|
|
544
1166
|
}
|
|
545
|
-
const
|
|
546
|
-
|
|
547
|
-
|
|
1167
|
+
const executeRequest = this.slashingProposerContract.buildExecuteRoundRequest(action.round, action.committees);
|
|
1168
|
+
this.enqueueRequest('execute-slash', executeRequest, {
|
|
1169
|
+
address: this.slashingProposerContract.address.toString(),
|
|
1170
|
+
abi: SlashingProposerAbi,
|
|
1171
|
+
eventName: 'RoundExecuted'
|
|
1172
|
+
}, slotNumber);
|
|
548
1173
|
break;
|
|
549
1174
|
}
|
|
550
1175
|
default:
|
|
@@ -556,78 +1181,57 @@ export class SequencerPublisher {
|
|
|
556
1181
|
}
|
|
557
1182
|
return true;
|
|
558
1183
|
}
|
|
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);
|
|
1184
|
+
/** Enqueues a proposal for a checkpoint on L1 */ async enqueueProposeCheckpoint(checkpoint, attestationsAndSigners, attestationsAndSignersSignature, opts = {}) {
|
|
1185
|
+
const checkpointHeader = checkpoint.header;
|
|
1186
|
+
const blobFields = checkpoint.toBlobFields();
|
|
1187
|
+
const blobs = await getBlobsPerL1Block(blobFields);
|
|
568
1188
|
const proposeTxArgs = {
|
|
569
1189
|
header: checkpointHeader,
|
|
570
|
-
archive:
|
|
571
|
-
stateReference: block.header.state,
|
|
572
|
-
body: block.body.toBuffer(),
|
|
1190
|
+
archive: checkpoint.archive.root.toBuffer(),
|
|
573
1191
|
blobs,
|
|
574
1192
|
attestationsAndSigners,
|
|
575
|
-
attestationsAndSignersSignature
|
|
1193
|
+
attestationsAndSignersSignature,
|
|
1194
|
+
feeAssetPriceModifier: checkpoint.feeAssetPriceModifier
|
|
576
1195
|
};
|
|
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
|
|
1196
|
+
this.log.verbose(`Enqueuing checkpoint propose transaction`, {
|
|
1197
|
+
...checkpoint.toCheckpointInfo(),
|
|
1198
|
+
txTimeoutAt: opts.txTimeoutAt
|
|
1199
|
+
});
|
|
1200
|
+
await this.addProposeTx(checkpoint, proposeTxArgs, {
|
|
1201
|
+
txTimeoutAt: opts.txTimeoutAt
|
|
596
1202
|
});
|
|
597
|
-
await this.addProposeTx(block, proposeTxArgs, opts, ts);
|
|
598
|
-
return true;
|
|
599
1203
|
}
|
|
600
|
-
|
|
1204
|
+
enqueueInvalidateCheckpoint(request, opts = {}) {
|
|
601
1205
|
if (!request) {
|
|
602
1206
|
return;
|
|
603
1207
|
}
|
|
604
|
-
|
|
605
|
-
const gasLimit = this.l1TxUtils.bumpGasLimit(BigInt(Math.ceil(Number(request.gasUsed) * 64 / 63)));
|
|
606
|
-
const { gasUsed, blockNumber } = request;
|
|
1208
|
+
const { gasUsed, checkpointNumber } = request;
|
|
607
1209
|
const logData = {
|
|
608
1210
|
gasUsed,
|
|
609
|
-
|
|
610
|
-
gasLimit,
|
|
1211
|
+
checkpointNumber,
|
|
611
1212
|
opts
|
|
612
1213
|
};
|
|
613
|
-
this.log.verbose(`Enqueuing invalidate
|
|
1214
|
+
this.log.verbose(`Enqueuing invalidate checkpoint request`, logData);
|
|
614
1215
|
this.addRequest({
|
|
615
1216
|
action: `invalidate-by-${request.reason}`,
|
|
616
1217
|
request: request.request,
|
|
617
|
-
gasConfig: {
|
|
618
|
-
gasLimit,
|
|
1218
|
+
gasConfig: opts.txTimeoutAt ? {
|
|
619
1219
|
txTimeoutAt: opts.txTimeoutAt
|
|
620
|
-
},
|
|
621
|
-
lastValidL2Slot: this.getCurrentL2Slot() +
|
|
1220
|
+
} : undefined,
|
|
1221
|
+
lastValidL2Slot: SlotNumber(this.getCurrentL2Slot() + 2),
|
|
622
1222
|
checkSuccess: (_req, result)=>{
|
|
623
|
-
const success = result &&
|
|
1223
|
+
const success = result && extractEventSuccess(result.receipt, {
|
|
1224
|
+
address: this.rollupContract.address,
|
|
1225
|
+
abi: RollupAbi,
|
|
1226
|
+
eventName: 'CheckpointInvalidated'
|
|
1227
|
+
});
|
|
624
1228
|
if (!success) {
|
|
625
|
-
this.log.warn(`Invalidate
|
|
1229
|
+
this.log.warn(`Invalidate checkpoint ${request.checkpointNumber} failed`, {
|
|
626
1230
|
...result,
|
|
627
1231
|
...logData
|
|
628
1232
|
});
|
|
629
1233
|
} else {
|
|
630
|
-
this.log.info(`Invalidate
|
|
1234
|
+
this.log.info(`Invalidate checkpoint ${request.checkpointNumber} succeeded`, {
|
|
631
1235
|
...result,
|
|
632
1236
|
...logData
|
|
633
1237
|
});
|
|
@@ -636,57 +1240,36 @@ export class SequencerPublisher {
|
|
|
636
1240
|
}
|
|
637
1241
|
});
|
|
638
1242
|
}
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
};
|
|
1243
|
+
/**
|
|
1244
|
+
* Dedup-checked enqueue helper for actions that are simulated at bundle-send time rather
|
|
1245
|
+
* than at enqueue time. Validates the (action, slot) dedup key, sets `lastActions`, and
|
|
1246
|
+
* enqueues without a gasLimit so the bundle simulate sets the only gasLimit that matters.
|
|
1247
|
+
*/ enqueueRequest(action, request, eventOpts, slotNumber) {
|
|
645
1248
|
if (this.lastActions[action] && this.lastActions[action] === slotNumber) {
|
|
646
1249
|
this.log.debug(`Skipping duplicate action ${action} for slot ${slotNumber}`);
|
|
647
1250
|
return false;
|
|
648
1251
|
}
|
|
649
1252
|
const cachedLastActionSlot = this.lastActions[action];
|
|
650
1253
|
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);
|
|
1254
|
+
this.log.debug(`Enqueuing ${action}`, {
|
|
1255
|
+
slotNumber
|
|
1256
|
+
});
|
|
671
1257
|
this.addRequest({
|
|
672
1258
|
action,
|
|
673
1259
|
request,
|
|
674
|
-
gasConfig: {
|
|
675
|
-
gasLimit
|
|
676
|
-
},
|
|
677
1260
|
lastValidL2Slot: slotNumber,
|
|
678
|
-
checkSuccess: (
|
|
679
|
-
const success = result && result.receipt
|
|
1261
|
+
checkSuccess: (_request, result)=>{
|
|
1262
|
+
const success = result && extractEventSuccess(result.receipt, eventOpts);
|
|
680
1263
|
if (!success) {
|
|
681
1264
|
this.log.warn(`Action ${action} at ${slotNumber} failed`, {
|
|
682
1265
|
...result,
|
|
683
|
-
|
|
1266
|
+
slotNumber
|
|
684
1267
|
});
|
|
685
1268
|
this.lastActions[action] = cachedLastActionSlot;
|
|
686
1269
|
} else {
|
|
687
1270
|
this.log.info(`Action ${action} at ${slotNumber} succeeded`, {
|
|
688
1271
|
...result,
|
|
689
|
-
|
|
1272
|
+
slotNumber
|
|
690
1273
|
});
|
|
691
1274
|
}
|
|
692
1275
|
return !!success;
|
|
@@ -701,46 +1284,87 @@ export class SequencerPublisher {
|
|
|
701
1284
|
* A call to `restart` is required before you can continue publishing.
|
|
702
1285
|
*/ interrupt() {
|
|
703
1286
|
this.interrupted = true;
|
|
1287
|
+
this.interruptibleSleep.interrupt();
|
|
704
1288
|
this.l1TxUtils.interrupt();
|
|
705
1289
|
}
|
|
706
1290
|
/** Restarts the publisher after calling `interrupt`. */ restart() {
|
|
707
1291
|
this.interrupted = false;
|
|
708
1292
|
this.l1TxUtils.restart();
|
|
709
1293
|
}
|
|
710
|
-
async prepareProposeTx(encodedData
|
|
1294
|
+
async prepareProposeTx(encodedData) {
|
|
711
1295
|
const kzg = Blob.getViemKzgInstance();
|
|
712
1296
|
const blobInput = getPrefixedEthBlobCommitments(encodedData.blobs);
|
|
713
1297
|
this.log.debug('Validating blob input', {
|
|
714
1298
|
blobInput
|
|
715
1299
|
});
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
1300
|
+
// Get blob evaluation gas
|
|
1301
|
+
let blobEvaluationGas;
|
|
1302
|
+
if (this.config.fishermanMode) {
|
|
1303
|
+
// In fisherman mode, we can't estimate blob gas because estimateGas doesn't support state overrides
|
|
1304
|
+
// Use a fixed estimate.
|
|
1305
|
+
blobEvaluationGas = BigInt(encodedData.blobs.length) * 21_000n;
|
|
1306
|
+
this.log.debug(`Using fixed blob evaluation gas estimate in fisherman mode: ${blobEvaluationGas}`);
|
|
1307
|
+
} else {
|
|
1308
|
+
// We call validateBlobs via estimateGas with real blob+kzg sidecars as a consistency check
|
|
1309
|
+
// that our locally-built blob commitments match the blob data. The bundle simulate at send
|
|
1310
|
+
// time uses eth_simulateV1, which cannot carry blob inputs, so the rollup's on-chain blob
|
|
1311
|
+
// check is forced off there — making this the only pre-flight detector of a commitment/data
|
|
1312
|
+
// mismatch. The returned gas estimate is stashed on the request for the bundle path to read.
|
|
1313
|
+
blobEvaluationGas = await this.l1TxUtils.estimateGas(this.getSenderAddress().toString(), {
|
|
1314
|
+
to: this.rollupContract.address,
|
|
1315
|
+
data: encodeFunctionData({
|
|
1316
|
+
abi: RollupAbi,
|
|
1317
|
+
functionName: 'validateBlobs',
|
|
1318
|
+
args: [
|
|
1319
|
+
blobInput
|
|
1320
|
+
]
|
|
1321
|
+
})
|
|
1322
|
+
}, {}, {
|
|
1323
|
+
blobs: encodedData.blobs.map((b)=>b.data),
|
|
1324
|
+
kzg
|
|
1325
|
+
}).catch(async (err)=>{
|
|
1326
|
+
const viemError = formatViemError(err);
|
|
1327
|
+
this.log.error(`Failed to validate blobs`, viemError.message, {
|
|
1328
|
+
metaMessages: viemError.metaMessages
|
|
1329
|
+
});
|
|
1330
|
+
const validateBlobsData = encodeFunctionData({
|
|
1331
|
+
abi: RollupAbi,
|
|
1332
|
+
functionName: 'validateBlobs',
|
|
1333
|
+
args: [
|
|
1334
|
+
blobInput
|
|
1335
|
+
]
|
|
1336
|
+
});
|
|
1337
|
+
const l1BlockNumber = await this.l1TxUtils.getBlockNumber();
|
|
1338
|
+
this.backupFailedTx({
|
|
1339
|
+
id: keccak256(validateBlobsData),
|
|
1340
|
+
failureType: 'simulation',
|
|
1341
|
+
request: {
|
|
1342
|
+
to: this.rollupContract.address,
|
|
1343
|
+
data: validateBlobsData
|
|
1344
|
+
},
|
|
1345
|
+
blobData: encodedData.blobs.map((b)=>toHex(b.data)),
|
|
1346
|
+
l1BlockNumber: l1BlockNumber.toString(),
|
|
1347
|
+
error: {
|
|
1348
|
+
message: viemError.message,
|
|
1349
|
+
name: viemError.name
|
|
1350
|
+
},
|
|
1351
|
+
context: {
|
|
1352
|
+
actions: [
|
|
1353
|
+
'validate-blobs'
|
|
1354
|
+
],
|
|
1355
|
+
sender: this.getSenderAddress().toString()
|
|
1356
|
+
}
|
|
1357
|
+
});
|
|
1358
|
+
throw new Error('Failed to validate blobs');
|
|
732
1359
|
});
|
|
733
|
-
|
|
734
|
-
});
|
|
1360
|
+
}
|
|
735
1361
|
const signers = encodedData.attestationsAndSigners.getSigners().map((signer)=>signer.toString());
|
|
736
1362
|
const args = [
|
|
737
1363
|
{
|
|
738
1364
|
header: encodedData.header.toViem(),
|
|
739
1365
|
archive: toHex(encodedData.archive),
|
|
740
|
-
stateReference: encodedData.stateReference.toViem(),
|
|
741
1366
|
oracleInput: {
|
|
742
|
-
|
|
743
|
-
feeAssetPriceModifier: 0n
|
|
1367
|
+
feeAssetPriceModifier: encodedData.feeAssetPriceModifier
|
|
744
1368
|
}
|
|
745
1369
|
},
|
|
746
1370
|
encodedData.attestationsAndSigners.getPackedAttestations(),
|
|
@@ -748,82 +1372,40 @@ export class SequencerPublisher {
|
|
|
748
1372
|
encodedData.attestationsAndSignersSignature.toViemSignature(),
|
|
749
1373
|
blobInput
|
|
750
1374
|
];
|
|
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
1375
|
const rollupData = encodeFunctionData({
|
|
766
1376
|
abi: RollupAbi,
|
|
767
1377
|
functionName: 'propose',
|
|
768
1378
|
args
|
|
769
1379
|
});
|
|
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
1380
|
return {
|
|
801
|
-
|
|
802
|
-
|
|
1381
|
+
args,
|
|
1382
|
+
blobEvaluationGas,
|
|
1383
|
+
rollupData
|
|
803
1384
|
};
|
|
804
1385
|
}
|
|
805
|
-
async addProposeTx(
|
|
1386
|
+
async addProposeTx(checkpoint, encodedData, opts = {}) {
|
|
1387
|
+
const slot = checkpoint.header.slotNumber;
|
|
806
1388
|
const timer = new Timer();
|
|
807
1389
|
const kzg = Blob.getViemKzgInstance();
|
|
808
|
-
const { rollupData,
|
|
1390
|
+
const { rollupData, blobEvaluationGas } = await this.prepareProposeTx(encodedData);
|
|
809
1391
|
const startBlock = await this.l1TxUtils.getBlockNumber();
|
|
810
|
-
|
|
811
|
-
//
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
});
|
|
1392
|
+
// Send the blobs to the blob client preemptively. This helps in tests where the sequencer mistakingly thinks that the propose
|
|
1393
|
+
// tx fails but it does get mined. We make sure that the blobs are sent to the blob client regardless of the tx outcome.
|
|
1394
|
+
void Promise.resolve().then(()=>this.blobClient.sendBlobsToFilestore(encodedData.blobs).catch((_err)=>{
|
|
1395
|
+
this.log.error('Failed to send blobs to blob client');
|
|
1396
|
+
}));
|
|
816
1397
|
return this.addRequest({
|
|
817
1398
|
action: 'propose',
|
|
818
1399
|
request: {
|
|
819
1400
|
to: this.rollupContract.address,
|
|
820
1401
|
data: rollupData
|
|
821
1402
|
},
|
|
822
|
-
lastValidL2Slot:
|
|
1403
|
+
lastValidL2Slot: checkpoint.header.slotNumber,
|
|
823
1404
|
gasConfig: {
|
|
824
|
-
|
|
825
|
-
gasLimit
|
|
1405
|
+
txTimeoutAt: opts.txTimeoutAt,
|
|
1406
|
+
gasLimit: undefined
|
|
826
1407
|
},
|
|
1408
|
+
blobEvaluationGas,
|
|
827
1409
|
blobConfig: {
|
|
828
1410
|
blobs: encodedData.blobs.map((b)=>b.data),
|
|
829
1411
|
kzg
|
|
@@ -833,7 +1415,11 @@ export class SequencerPublisher {
|
|
|
833
1415
|
return false;
|
|
834
1416
|
}
|
|
835
1417
|
const { receipt, stats, errorMsg } = result;
|
|
836
|
-
const success =
|
|
1418
|
+
const success = extractEventSuccess(receipt, {
|
|
1419
|
+
address: this.rollupContract.address,
|
|
1420
|
+
abi: RollupAbi,
|
|
1421
|
+
eventName: 'CheckpointProposed'
|
|
1422
|
+
});
|
|
837
1423
|
if (success) {
|
|
838
1424
|
const endBlock = receipt.blockNumber;
|
|
839
1425
|
const inclusionBlocks = Number(endBlock - startBlock);
|
|
@@ -847,29 +1433,31 @@ export class SequencerPublisher {
|
|
|
847
1433
|
calldataGas,
|
|
848
1434
|
calldataSize,
|
|
849
1435
|
sender,
|
|
850
|
-
...
|
|
1436
|
+
...checkpoint.getStats(),
|
|
851
1437
|
eventName: 'rollup-published-to-l1',
|
|
852
1438
|
blobCount: encodedData.blobs.length,
|
|
853
1439
|
inclusionBlocks
|
|
854
1440
|
};
|
|
855
|
-
this.log.info(`Published
|
|
1441
|
+
this.log.info(`Published checkpoint ${checkpoint.number} at slot ${slot} to rollup contract`, {
|
|
856
1442
|
...stats,
|
|
857
|
-
...
|
|
858
|
-
...receipt
|
|
1443
|
+
...checkpoint.getStats(),
|
|
1444
|
+
...pick(receipt, 'transactionHash', 'blockHash')
|
|
859
1445
|
});
|
|
860
1446
|
this.metrics.recordProcessBlockTx(timer.ms(), publishStats);
|
|
861
1447
|
return true;
|
|
862
1448
|
} else {
|
|
863
1449
|
this.metrics.recordFailedTx('process');
|
|
864
|
-
this.log.error(`
|
|
865
|
-
...
|
|
866
|
-
receipt
|
|
867
|
-
txHash: receipt.transactionHash,
|
|
868
|
-
slotNumber: block.header.globalVariables.slotNumber.toBigInt()
|
|
1450
|
+
this.log.error(`Publishing checkpoint at slot ${slot} failed with ${errorMsg ?? 'no error message'}`, undefined, {
|
|
1451
|
+
...checkpoint.getStats(),
|
|
1452
|
+
...receipt
|
|
869
1453
|
});
|
|
870
1454
|
return false;
|
|
871
1455
|
}
|
|
872
1456
|
}
|
|
873
1457
|
});
|
|
874
1458
|
}
|
|
1459
|
+
/** Returns the timestamp of the next L1 slot boundary after now. */ getNextL1SlotTimestamp() {
|
|
1460
|
+
const l1Constants = this.epochCache.getL1Constants();
|
|
1461
|
+
return getNextL1SlotTimestamp(this.dateProvider.nowInSeconds(), l1Constants);
|
|
1462
|
+
}
|
|
875
1463
|
}
|