@aztec/archiver 4.0.0-nightly.20260114 → 4.0.0-nightly.20260115
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dest/archiver.d.ts +134 -0
- package/dest/archiver.d.ts.map +1 -0
- package/dest/archiver.js +767 -0
- package/dest/{archiver/config.d.ts → config.d.ts} +9 -1
- package/dest/config.d.ts.map +1 -0
- package/dest/{archiver/config.js → config.js} +9 -0
- package/dest/{archiver/errors.d.ts → errors.d.ts} +1 -1
- package/dest/errors.d.ts.map +1 -0
- package/dest/factory.d.ts +5 -6
- package/dest/factory.d.ts.map +1 -1
- package/dest/factory.js +82 -5
- package/dest/index.d.ts +10 -4
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +8 -3
- package/dest/interfaces.d.ts +9 -0
- package/dest/interfaces.d.ts.map +1 -0
- package/dest/interfaces.js +3 -0
- package/dest/{archiver/l1 → l1}/bin/retrieve-calldata.d.ts +1 -1
- package/dest/l1/bin/retrieve-calldata.d.ts.map +1 -0
- package/dest/{archiver/l1 → l1}/calldata_retriever.d.ts +2 -2
- package/dest/l1/calldata_retriever.d.ts.map +1 -0
- package/dest/{archiver/l1 → l1}/data_retrieval.d.ts +2 -2
- package/dest/l1/data_retrieval.d.ts.map +1 -0
- package/dest/{archiver/l1 → l1}/debug_tx.d.ts +1 -1
- package/dest/l1/debug_tx.d.ts.map +1 -0
- package/dest/{archiver/l1 → l1}/spire_proposer.d.ts +1 -1
- package/dest/l1/spire_proposer.d.ts.map +1 -0
- package/dest/{archiver/l1 → l1}/trace_tx.d.ts +1 -1
- package/dest/l1/trace_tx.d.ts.map +1 -0
- package/dest/l1/types.d.ts +12 -0
- package/dest/l1/types.d.ts.map +1 -0
- package/dest/{archiver/l1 → l1}/validate_trace.d.ts +1 -1
- package/dest/l1/validate_trace.d.ts.map +1 -0
- package/dest/modules/data_source_base.d.ts +83 -0
- package/dest/modules/data_source_base.d.ts.map +1 -0
- package/dest/{archiver/archive_source_base.js → modules/data_source_base.js} +109 -10
- package/dest/modules/data_store_updater.d.ts +46 -0
- package/dest/modules/data_store_updater.d.ts.map +1 -0
- package/dest/modules/data_store_updater.js +216 -0
- package/dest/modules/instrumentation.d.ts +37 -0
- package/dest/modules/instrumentation.d.ts.map +1 -0
- package/dest/modules/l1_synchronizer.d.ts +67 -0
- package/dest/modules/l1_synchronizer.d.ts.map +1 -0
- package/dest/{archiver/archiver.js → modules/l1_synchronizer.js} +60 -543
- package/dest/{archiver → modules}/validation.d.ts +1 -1
- package/dest/modules/validation.d.ts.map +1 -0
- package/dest/{archiver/kv_archiver_store → store}/block_store.d.ts +1 -1
- package/dest/store/block_store.d.ts.map +1 -0
- package/dest/store/contract_class_store.d.ts +18 -0
- package/dest/store/contract_class_store.d.ts.map +1 -0
- package/dest/store/contract_instance_store.d.ts +24 -0
- package/dest/store/contract_instance_store.d.ts.map +1 -0
- package/dest/{archiver/kv_archiver_store → store}/kv_archiver_store.d.ts +2 -2
- package/dest/store/kv_archiver_store.d.ts.map +1 -0
- package/dest/{archiver/kv_archiver_store → store}/log_store.d.ts +1 -1
- package/dest/store/log_store.d.ts.map +1 -0
- package/dest/{archiver/kv_archiver_store → store}/message_store.d.ts +1 -1
- package/dest/store/message_store.d.ts.map +1 -0
- package/dest/{archiver/structs → structs}/data_retrieval.d.ts +1 -1
- package/dest/structs/data_retrieval.d.ts.map +1 -0
- package/dest/structs/inbox_message.d.ts +15 -0
- package/dest/structs/inbox_message.d.ts.map +1 -0
- package/dest/{archiver/structs → structs}/published.d.ts +1 -1
- package/dest/structs/published.d.ts.map +1 -0
- package/dest/{archiver/test → test}/fake_l1_state.d.ts +1 -1
- package/dest/test/fake_l1_state.d.ts.map +1 -0
- package/dest/test/index.d.ts +2 -1
- package/dest/test/index.d.ts.map +1 -1
- package/dest/test/index.js +1 -0
- package/dest/test/mock_structs.d.ts +76 -2
- package/dest/test/mock_structs.d.ts.map +1 -1
- package/dest/test/mock_structs.js +133 -2
- package/package.json +15 -17
- package/src/archiver.ts +522 -0
- package/src/{archiver/config.ts → config.ts} +11 -0
- package/src/factory.ts +118 -6
- package/src/index.ts +10 -3
- package/src/interfaces.ts +9 -0
- package/src/{archiver/l1 → l1}/calldata_retriever.ts +1 -1
- package/src/{archiver/l1 → l1}/data_retrieval.ts +1 -1
- package/src/{archiver/archive_source_base.ts → modules/data_source_base.ts} +130 -30
- package/src/modules/data_store_updater.ts +318 -0
- package/src/{archiver/archiver.ts → modules/l1_synchronizer.ts} +68 -717
- package/src/test/index.ts +1 -0
- package/src/test/mock_structs.ts +247 -2
- package/dest/archiver/archive_source_base.d.ts +0 -75
- package/dest/archiver/archive_source_base.d.ts.map +0 -1
- package/dest/archiver/archiver.d.ts +0 -168
- package/dest/archiver/archiver.d.ts.map +0 -1
- package/dest/archiver/archiver_store_updates.d.ts +0 -38
- package/dest/archiver/archiver_store_updates.d.ts.map +0 -1
- package/dest/archiver/archiver_store_updates.js +0 -212
- package/dest/archiver/config.d.ts.map +0 -1
- package/dest/archiver/errors.d.ts.map +0 -1
- package/dest/archiver/index.d.ts +0 -8
- package/dest/archiver/index.d.ts.map +0 -1
- package/dest/archiver/index.js +0 -6
- package/dest/archiver/instrumentation.d.ts +0 -37
- package/dest/archiver/instrumentation.d.ts.map +0 -1
- package/dest/archiver/kv_archiver_store/block_store.d.ts.map +0 -1
- package/dest/archiver/kv_archiver_store/contract_class_store.d.ts +0 -18
- package/dest/archiver/kv_archiver_store/contract_class_store.d.ts.map +0 -1
- package/dest/archiver/kv_archiver_store/contract_instance_store.d.ts +0 -24
- package/dest/archiver/kv_archiver_store/contract_instance_store.d.ts.map +0 -1
- package/dest/archiver/kv_archiver_store/kv_archiver_store.d.ts.map +0 -1
- package/dest/archiver/kv_archiver_store/log_store.d.ts.map +0 -1
- package/dest/archiver/kv_archiver_store/message_store.d.ts.map +0 -1
- package/dest/archiver/l1/bin/retrieve-calldata.d.ts.map +0 -1
- package/dest/archiver/l1/calldata_retriever.d.ts.map +0 -1
- package/dest/archiver/l1/data_retrieval.d.ts.map +0 -1
- package/dest/archiver/l1/debug_tx.d.ts.map +0 -1
- package/dest/archiver/l1/spire_proposer.d.ts.map +0 -1
- package/dest/archiver/l1/trace_tx.d.ts.map +0 -1
- package/dest/archiver/l1/types.d.ts +0 -12
- package/dest/archiver/l1/types.d.ts.map +0 -1
- package/dest/archiver/l1/validate_trace.d.ts.map +0 -1
- package/dest/archiver/structs/data_retrieval.d.ts.map +0 -1
- package/dest/archiver/structs/inbox_message.d.ts +0 -15
- package/dest/archiver/structs/inbox_message.d.ts.map +0 -1
- package/dest/archiver/structs/published.d.ts.map +0 -1
- package/dest/archiver/test/fake_l1_state.d.ts.map +0 -1
- package/dest/archiver/validation.d.ts.map +0 -1
- package/dest/rpc/index.d.ts +0 -9
- package/dest/rpc/index.d.ts.map +0 -1
- package/dest/rpc/index.js +0 -15
- package/src/archiver/archiver_store_updates.ts +0 -321
- package/src/archiver/index.ts +0 -7
- package/src/rpc/index.ts +0 -16
- /package/dest/{archiver/errors.js → errors.js} +0 -0
- /package/dest/{archiver/l1 → l1}/bin/retrieve-calldata.js +0 -0
- /package/dest/{archiver/l1 → l1}/calldata_retriever.js +0 -0
- /package/dest/{archiver/l1 → l1}/data_retrieval.js +0 -0
- /package/dest/{archiver/l1 → l1}/debug_tx.js +0 -0
- /package/dest/{archiver/l1 → l1}/spire_proposer.js +0 -0
- /package/dest/{archiver/l1 → l1}/trace_tx.js +0 -0
- /package/dest/{archiver/l1 → l1}/types.js +0 -0
- /package/dest/{archiver/l1 → l1}/validate_trace.js +0 -0
- /package/dest/{archiver → modules}/instrumentation.js +0 -0
- /package/dest/{archiver → modules}/validation.js +0 -0
- /package/dest/{archiver/kv_archiver_store → store}/block_store.js +0 -0
- /package/dest/{archiver/kv_archiver_store → store}/contract_class_store.js +0 -0
- /package/dest/{archiver/kv_archiver_store → store}/contract_instance_store.js +0 -0
- /package/dest/{archiver/kv_archiver_store → store}/kv_archiver_store.js +0 -0
- /package/dest/{archiver/kv_archiver_store → store}/log_store.js +0 -0
- /package/dest/{archiver/kv_archiver_store → store}/message_store.js +0 -0
- /package/dest/{archiver/structs → structs}/data_retrieval.js +0 -0
- /package/dest/{archiver/structs → structs}/inbox_message.js +0 -0
- /package/dest/{archiver/structs → structs}/published.js +0 -0
- /package/dest/{archiver/test → test}/fake_l1_state.js +0 -0
- /package/src/{archiver/errors.ts → errors.ts} +0 -0
- /package/src/{archiver/l1 → l1}/README.md +0 -0
- /package/src/{archiver/l1 → l1}/bin/retrieve-calldata.ts +0 -0
- /package/src/{archiver/l1 → l1}/debug_tx.ts +0 -0
- /package/src/{archiver/l1 → l1}/spire_proposer.ts +0 -0
- /package/src/{archiver/l1 → l1}/trace_tx.ts +0 -0
- /package/src/{archiver/l1 → l1}/types.ts +0 -0
- /package/src/{archiver/l1 → l1}/validate_trace.ts +0 -0
- /package/src/{archiver → modules}/instrumentation.ts +0 -0
- /package/src/{archiver → modules}/validation.ts +0 -0
- /package/src/{archiver/kv_archiver_store → store}/block_store.ts +0 -0
- /package/src/{archiver/kv_archiver_store → store}/contract_class_store.ts +0 -0
- /package/src/{archiver/kv_archiver_store → store}/contract_instance_store.ts +0 -0
- /package/src/{archiver/kv_archiver_store → store}/kv_archiver_store.ts +0 -0
- /package/src/{archiver/kv_archiver_store → store}/log_store.ts +0 -0
- /package/src/{archiver/kv_archiver_store → store}/message_store.ts +0 -0
- /package/src/{archiver/structs → structs}/data_retrieval.ts +0 -0
- /package/src/{archiver/structs → structs}/inbox_message.ts +0 -0
- /package/src/{archiver/structs → structs}/published.ts +0 -0
- /package/src/{archiver/test → test}/fake_l1_state.ts +0 -0
package/dest/archiver.js
ADDED
|
@@ -0,0 +1,767 @@
|
|
|
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, _initProto;
|
|
374
|
+
import { GENESIS_BLOCK_HEADER_HASH, INITIAL_L2_BLOCK_NUM } from '@aztec/constants';
|
|
375
|
+
import { BlockTagTooOldError } from '@aztec/ethereum/contracts';
|
|
376
|
+
import { BlockNumber, CheckpointNumber } from '@aztec/foundation/branded-types';
|
|
377
|
+
import { Buffer32 } from '@aztec/foundation/buffer';
|
|
378
|
+
import { merge } from '@aztec/foundation/collection';
|
|
379
|
+
import { EthAddress } from '@aztec/foundation/eth-address';
|
|
380
|
+
import { createLogger } from '@aztec/foundation/log';
|
|
381
|
+
import { promiseWithResolvers } from '@aztec/foundation/promise';
|
|
382
|
+
import { RunningPromise, makeLoggingErrorHandler } from '@aztec/foundation/running-promise';
|
|
383
|
+
import { GENESIS_CHECKPOINT_HEADER_HASH } from '@aztec/stdlib/block';
|
|
384
|
+
import { getEpochNumberAtTimestamp, getSlotAtTimestamp, getSlotRangeForEpoch, getTimestampRangeForEpoch } from '@aztec/stdlib/epoch-helpers';
|
|
385
|
+
import { trackSpan } from '@aztec/telemetry-client';
|
|
386
|
+
import { mapArchiverConfig } from './config.js';
|
|
387
|
+
import { NoBlobBodiesFoundError } from './errors.js';
|
|
388
|
+
import { validateAndLogTraceAvailability } from './l1/validate_trace.js';
|
|
389
|
+
import { ArchiverDataSourceBase } from './modules/data_source_base.js';
|
|
390
|
+
import { ArchiverDataStoreUpdater } from './modules/data_store_updater.js';
|
|
391
|
+
_dec = trackSpan('Archiver.sync');
|
|
392
|
+
/**
|
|
393
|
+
* Pulls checkpoints in a non-blocking manner and provides interface for their retrieval.
|
|
394
|
+
* Responsible for handling robust L1 polling so that other components do not need to
|
|
395
|
+
* concern themselves with it.
|
|
396
|
+
*/ export class Archiver extends ArchiverDataSourceBase {
|
|
397
|
+
publicClient;
|
|
398
|
+
debugClient;
|
|
399
|
+
rollup;
|
|
400
|
+
l1Addresses;
|
|
401
|
+
dataStore;
|
|
402
|
+
config;
|
|
403
|
+
blobClient;
|
|
404
|
+
l1Constants;
|
|
405
|
+
log;
|
|
406
|
+
static{
|
|
407
|
+
({ e: [_initProto] } = _apply_decs_2203_r(this, [
|
|
408
|
+
[
|
|
409
|
+
_dec,
|
|
410
|
+
2,
|
|
411
|
+
"sync"
|
|
412
|
+
]
|
|
413
|
+
], []));
|
|
414
|
+
}
|
|
415
|
+
/** Event emitter for archiver events (L2BlockProven, L2PruneDetected, etc). */ events;
|
|
416
|
+
/** A loop in which we will be continually fetching new checkpoints. */ runningPromise;
|
|
417
|
+
/** L1 synchronizer that handles fetching checkpoints and messages from L1. */ synchronizer;
|
|
418
|
+
initialSyncComplete;
|
|
419
|
+
initialSyncPromise;
|
|
420
|
+
/** Queue of blocks to be added to the store, processed by the sync loop. */ blockQueue;
|
|
421
|
+
/** Helper to handle updates to the store */ updater;
|
|
422
|
+
tracer;
|
|
423
|
+
/**
|
|
424
|
+
* Creates a new instance of the Archiver.
|
|
425
|
+
* @param publicClient - A client for interacting with the Ethereum node.
|
|
426
|
+
* @param debugClient - A client for interacting with the Ethereum node for debug/trace methods.
|
|
427
|
+
* @param rollup - Rollup contract instance.
|
|
428
|
+
* @param inbox - Inbox contract instance.
|
|
429
|
+
* @param l1Addresses - L1 contract addresses (registry, governance proposer, slash factory, slashing proposer).
|
|
430
|
+
* @param dataStore - An archiver data store for storage & retrieval of blocks, encrypted logs & contract data.
|
|
431
|
+
* @param config - Archiver configuration options.
|
|
432
|
+
* @param blobClient - Client for retrieving blob data.
|
|
433
|
+
* @param epochCache - Cache for epoch-related data.
|
|
434
|
+
* @param dateProvider - Provider for current date/time.
|
|
435
|
+
* @param instrumentation - Instrumentation for metrics and tracing.
|
|
436
|
+
* @param l1Constants - L1 rollup constants.
|
|
437
|
+
* @param log - A logger.
|
|
438
|
+
*/ constructor(publicClient, debugClient, rollup, l1Addresses, dataStore, config, blobClient, instrumentation, l1Constants, synchronizer, events, log = createLogger('archiver')){
|
|
439
|
+
super(dataStore, l1Constants), this.publicClient = publicClient, this.debugClient = debugClient, this.rollup = rollup, this.l1Addresses = l1Addresses, this.dataStore = dataStore, this.config = config, this.blobClient = blobClient, this.l1Constants = l1Constants, this.log = log, this.initialSyncComplete = (_initProto(this), false), this.blockQueue = [];
|
|
440
|
+
this.tracer = instrumentation.tracer;
|
|
441
|
+
this.initialSyncPromise = promiseWithResolvers();
|
|
442
|
+
this.synchronizer = synchronizer;
|
|
443
|
+
this.events = events;
|
|
444
|
+
this.updater = new ArchiverDataStoreUpdater(this.dataStore);
|
|
445
|
+
// Running promise starts with a small interval inbetween runs, so all iterations needed for the initial sync
|
|
446
|
+
// are done as fast as possible. This then gets updated once the initial sync completes.
|
|
447
|
+
this.runningPromise = new RunningPromise(()=>this.sync(), this.log, this.config.pollingIntervalMs / 10, makeLoggingErrorHandler(this.log, NoBlobBodiesFoundError, BlockTagTooOldError));
|
|
448
|
+
}
|
|
449
|
+
/** Updates archiver config */ updateConfig(newConfig) {
|
|
450
|
+
this.config = merge(this.config, mapArchiverConfig(newConfig));
|
|
451
|
+
}
|
|
452
|
+
/**
|
|
453
|
+
* Starts sync process.
|
|
454
|
+
* @param blockUntilSynced - If true, blocks until the archiver has fully synced.
|
|
455
|
+
*/ async start(blockUntilSynced) {
|
|
456
|
+
if (this.runningPromise.isRunning()) {
|
|
457
|
+
throw new Error('Archiver is already running');
|
|
458
|
+
}
|
|
459
|
+
await this.blobClient.testSources();
|
|
460
|
+
await this.synchronizer.testEthereumNodeSynced();
|
|
461
|
+
await validateAndLogTraceAvailability(this.debugClient, this.config.ethereumAllowNoDebugHosts ?? false);
|
|
462
|
+
// Log initial state for the archiver
|
|
463
|
+
const { l1StartBlock } = this.l1Constants;
|
|
464
|
+
const { blocksSynchedTo = l1StartBlock, messagesSynchedTo = l1StartBlock } = await this.store.getSynchPoint();
|
|
465
|
+
const currentL2Checkpoint = await this.getSynchedCheckpointNumber();
|
|
466
|
+
this.log.info(`Starting archiver sync to rollup contract ${this.rollup.address} from L1 block ${blocksSynchedTo} and L2 checkpoint ${currentL2Checkpoint}`, {
|
|
467
|
+
blocksSynchedTo,
|
|
468
|
+
messagesSynchedTo,
|
|
469
|
+
currentL2Checkpoint
|
|
470
|
+
});
|
|
471
|
+
// Start sync loop, and return the wait for initial sync if we are asked to block until synced
|
|
472
|
+
this.runningPromise.start();
|
|
473
|
+
if (blockUntilSynced) {
|
|
474
|
+
return this.waitForInitialSync();
|
|
475
|
+
}
|
|
476
|
+
}
|
|
477
|
+
syncImmediate() {
|
|
478
|
+
return this.runningPromise.trigger();
|
|
479
|
+
}
|
|
480
|
+
/**
|
|
481
|
+
* Queues a block to be added to the archiver store and triggers processing.
|
|
482
|
+
* The block will be processed by the sync loop.
|
|
483
|
+
* Implements the L2BlockSink interface.
|
|
484
|
+
* @param block - The L2 block to add.
|
|
485
|
+
* @returns A promise that resolves when the block has been added to the store, or rejects on error.
|
|
486
|
+
*/ addBlock(block) {
|
|
487
|
+
return new Promise((resolve, reject)=>{
|
|
488
|
+
this.blockQueue.push({
|
|
489
|
+
block,
|
|
490
|
+
resolve,
|
|
491
|
+
reject
|
|
492
|
+
});
|
|
493
|
+
this.log.debug(`Queued block ${block.number} for processing`);
|
|
494
|
+
// Trigger an immediate sync, but don't wait for it - the promise resolves when the block is processed
|
|
495
|
+
this.syncImmediate().catch((err)=>{
|
|
496
|
+
this.log.error(`Sync immediate call failed: ${err}`);
|
|
497
|
+
});
|
|
498
|
+
});
|
|
499
|
+
}
|
|
500
|
+
/**
|
|
501
|
+
* Processes all queued blocks, adding them to the store.
|
|
502
|
+
* Called at the beginning of each sync iteration.
|
|
503
|
+
* Blocks are processed in the order they were queued.
|
|
504
|
+
*/ async processQueuedBlocks() {
|
|
505
|
+
if (this.blockQueue.length === 0) {
|
|
506
|
+
return;
|
|
507
|
+
}
|
|
508
|
+
// Take all blocks from the queue
|
|
509
|
+
const queuedItems = this.blockQueue.splice(0, this.blockQueue.length);
|
|
510
|
+
this.log.debug(`Processing ${queuedItems.length} queued block(s)`);
|
|
511
|
+
// Process each block individually to properly resolve/reject each promise
|
|
512
|
+
for (const { block, resolve, reject } of queuedItems){
|
|
513
|
+
try {
|
|
514
|
+
await this.updater.addBlocksWithContractData([
|
|
515
|
+
block
|
|
516
|
+
]);
|
|
517
|
+
this.log.debug(`Added block ${block.number} to store`);
|
|
518
|
+
resolve();
|
|
519
|
+
} catch (err) {
|
|
520
|
+
this.log.error(`Failed to add block ${block.number} to store: ${err.message}`);
|
|
521
|
+
reject(err);
|
|
522
|
+
}
|
|
523
|
+
}
|
|
524
|
+
}
|
|
525
|
+
waitForInitialSync() {
|
|
526
|
+
return this.initialSyncPromise.promise;
|
|
527
|
+
}
|
|
528
|
+
/**
|
|
529
|
+
* Fetches logs from L1 contracts and processes them.
|
|
530
|
+
*/ async sync() {
|
|
531
|
+
// Process any queued blocks first, before doing L1 sync
|
|
532
|
+
await this.processQueuedBlocks();
|
|
533
|
+
// Now perform L1 sync
|
|
534
|
+
await this.syncFromL1();
|
|
535
|
+
}
|
|
536
|
+
async syncFromL1() {
|
|
537
|
+
// Delegate to the L1 synchronizer
|
|
538
|
+
await this.synchronizer.syncFromL1(this.initialSyncComplete);
|
|
539
|
+
// Check if we've completed initial sync
|
|
540
|
+
const currentL1BlockNumber = this.synchronizer.getL1BlockNumber();
|
|
541
|
+
if (currentL1BlockNumber !== undefined && !this.initialSyncComplete) {
|
|
542
|
+
const l1BlockNumberAtEnd = await this.publicClient.getBlockNumber();
|
|
543
|
+
if (currentL1BlockNumber + 1n >= l1BlockNumberAtEnd) {
|
|
544
|
+
this.log.info(`Initial archiver sync to L1 block ${currentL1BlockNumber} complete`, {
|
|
545
|
+
l1BlockNumber: currentL1BlockNumber,
|
|
546
|
+
syncPoint: await this.store.getSynchPoint(),
|
|
547
|
+
...await this.getL2Tips()
|
|
548
|
+
});
|
|
549
|
+
this.runningPromise.setPollingIntervalMS(this.config.pollingIntervalMs);
|
|
550
|
+
this.initialSyncComplete = true;
|
|
551
|
+
this.initialSyncPromise.resolve();
|
|
552
|
+
}
|
|
553
|
+
}
|
|
554
|
+
}
|
|
555
|
+
/** Resumes the archiver after a stop. */ resume() {
|
|
556
|
+
if (this.runningPromise.isRunning()) {
|
|
557
|
+
this.log.warn(`Archiver already running`);
|
|
558
|
+
}
|
|
559
|
+
this.log.info(`Restarting archiver`);
|
|
560
|
+
this.runningPromise.start();
|
|
561
|
+
}
|
|
562
|
+
/**
|
|
563
|
+
* Stops the archiver.
|
|
564
|
+
* @returns A promise signalling completion of the stop process.
|
|
565
|
+
*/ async stop() {
|
|
566
|
+
this.log.debug('Stopping...');
|
|
567
|
+
await this.runningPromise.stop();
|
|
568
|
+
this.log.info('Stopped.');
|
|
569
|
+
return Promise.resolve();
|
|
570
|
+
}
|
|
571
|
+
backupTo(destPath) {
|
|
572
|
+
return this.dataStore.backupTo(destPath);
|
|
573
|
+
}
|
|
574
|
+
getL1Constants() {
|
|
575
|
+
return Promise.resolve(this.l1Constants);
|
|
576
|
+
}
|
|
577
|
+
getGenesisValues() {
|
|
578
|
+
return Promise.resolve({
|
|
579
|
+
genesisArchiveRoot: this.l1Constants.genesisArchiveRoot
|
|
580
|
+
});
|
|
581
|
+
}
|
|
582
|
+
getRollupAddress() {
|
|
583
|
+
return Promise.resolve(EthAddress.fromString(this.rollup.address));
|
|
584
|
+
}
|
|
585
|
+
getRegistryAddress() {
|
|
586
|
+
return Promise.resolve(this.l1Addresses.registryAddress);
|
|
587
|
+
}
|
|
588
|
+
getL1BlockNumber() {
|
|
589
|
+
return this.synchronizer.getL1BlockNumber();
|
|
590
|
+
}
|
|
591
|
+
getL1Timestamp() {
|
|
592
|
+
return Promise.resolve(this.synchronizer.getL1Timestamp());
|
|
593
|
+
}
|
|
594
|
+
getL2SlotNumber() {
|
|
595
|
+
const l1Timestamp = this.synchronizer.getL1Timestamp();
|
|
596
|
+
return Promise.resolve(l1Timestamp === undefined ? undefined : getSlotAtTimestamp(l1Timestamp, this.l1Constants));
|
|
597
|
+
}
|
|
598
|
+
getL2EpochNumber() {
|
|
599
|
+
const l1Timestamp = this.synchronizer.getL1Timestamp();
|
|
600
|
+
return Promise.resolve(l1Timestamp === undefined ? undefined : getEpochNumberAtTimestamp(l1Timestamp, this.l1Constants));
|
|
601
|
+
}
|
|
602
|
+
async isEpochComplete(epochNumber) {
|
|
603
|
+
// The epoch is complete if the current L2 block is the last one in the epoch (or later)
|
|
604
|
+
const header = await this.getBlockHeader('latest');
|
|
605
|
+
const slot = header ? header.globalVariables.slotNumber : undefined;
|
|
606
|
+
const [_startSlot, endSlot] = getSlotRangeForEpoch(epochNumber, this.l1Constants);
|
|
607
|
+
if (slot && slot >= endSlot) {
|
|
608
|
+
return true;
|
|
609
|
+
}
|
|
610
|
+
// If we haven't run an initial sync, just return false.
|
|
611
|
+
const l1Timestamp = this.synchronizer.getL1Timestamp();
|
|
612
|
+
if (l1Timestamp === undefined) {
|
|
613
|
+
return false;
|
|
614
|
+
}
|
|
615
|
+
// If not, the epoch may also be complete if the L2 slot has passed without a block
|
|
616
|
+
// We compute this based on the end timestamp for the given epoch and the timestamp of the last L1 block
|
|
617
|
+
const [_startTimestamp, endTimestamp] = getTimestampRangeForEpoch(epochNumber, this.l1Constants);
|
|
618
|
+
// For this computation, we throw in a few extra seconds just for good measure,
|
|
619
|
+
// since we know the next L1 block won't be mined within this range. Remember that
|
|
620
|
+
// l1timestamp is the timestamp of the last l1 block we've seen, so this relies on
|
|
621
|
+
// the fact that L1 won't mine two blocks within this time of each other.
|
|
622
|
+
// TODO(palla/reorg): Is the above a safe assumption?
|
|
623
|
+
const leeway = 1n;
|
|
624
|
+
return l1Timestamp + leeway >= endTimestamp;
|
|
625
|
+
}
|
|
626
|
+
/** Returns whether the archiver has completed an initial sync run successfully. */ isInitialSyncComplete() {
|
|
627
|
+
return this.initialSyncComplete;
|
|
628
|
+
}
|
|
629
|
+
unwindCheckpoints(from, checkpointsToUnwind) {
|
|
630
|
+
return this.updater.unwindCheckpointsWithContractData(from, checkpointsToUnwind);
|
|
631
|
+
}
|
|
632
|
+
addCheckpoints(checkpoints, pendingChainValidationStatus) {
|
|
633
|
+
return this.updater.addCheckpointsWithContractData(checkpoints, pendingChainValidationStatus);
|
|
634
|
+
}
|
|
635
|
+
async getL2Tips() {
|
|
636
|
+
const [latestBlockNumber, provenBlockNumber, checkpointedBlockNumber] = await Promise.all([
|
|
637
|
+
this.getBlockNumber(),
|
|
638
|
+
this.getProvenBlockNumber(),
|
|
639
|
+
this.getCheckpointedBlockNumber()
|
|
640
|
+
]);
|
|
641
|
+
// TODO(#13569): Compute proper finalized block number based on L1 finalized block.
|
|
642
|
+
// We just force it 2 epochs worth of proven data for now.
|
|
643
|
+
// NOTE: update end-to-end/src/e2e_epochs/epochs_empty_blocks.test.ts as that uses finalized blocks in computations
|
|
644
|
+
const finalizedBlockNumber = BlockNumber(Math.max(provenBlockNumber - this.l1Constants.epochDuration * 2, 0));
|
|
645
|
+
const beforeInitialblockNumber = BlockNumber(INITIAL_L2_BLOCK_NUM - 1);
|
|
646
|
+
// Get the latest block header and checkpointed blocks for proven, finalised and checkpointed blocks
|
|
647
|
+
const [latestBlockHeader, provenCheckpointedBlock, finalizedCheckpointedBlock, checkpointedBlock] = await Promise.all([
|
|
648
|
+
latestBlockNumber > beforeInitialblockNumber ? this.getBlockHeader(latestBlockNumber) : undefined,
|
|
649
|
+
provenBlockNumber > beforeInitialblockNumber ? this.getCheckpointedBlock(provenBlockNumber) : undefined,
|
|
650
|
+
finalizedBlockNumber > beforeInitialblockNumber ? this.getCheckpointedBlock(finalizedBlockNumber) : undefined,
|
|
651
|
+
checkpointedBlockNumber > beforeInitialblockNumber ? this.getCheckpointedBlock(checkpointedBlockNumber) : undefined
|
|
652
|
+
]);
|
|
653
|
+
if (latestBlockNumber > beforeInitialblockNumber && !latestBlockHeader) {
|
|
654
|
+
throw new Error(`Failed to retrieve latest block header for block ${latestBlockNumber}`);
|
|
655
|
+
}
|
|
656
|
+
// Checkpointed blocks must exist for proven, finalized and checkpointed tips if they are beyond the initial block number.
|
|
657
|
+
if (checkpointedBlockNumber > beforeInitialblockNumber && !checkpointedBlock?.block.header) {
|
|
658
|
+
throw new Error(`Failed to retrieve checkpointed block header for block ${checkpointedBlockNumber} (latest block is ${latestBlockNumber})`);
|
|
659
|
+
}
|
|
660
|
+
if (provenBlockNumber > beforeInitialblockNumber && !provenCheckpointedBlock?.block.header) {
|
|
661
|
+
throw new Error(`Failed to retrieve proven checkpointed for block ${provenBlockNumber} (latest block is ${latestBlockNumber})`);
|
|
662
|
+
}
|
|
663
|
+
if (finalizedBlockNumber > beforeInitialblockNumber && !finalizedCheckpointedBlock?.block.header) {
|
|
664
|
+
throw new Error(`Failed to retrieve finalized block header for block ${finalizedBlockNumber} (latest block is ${latestBlockNumber})`);
|
|
665
|
+
}
|
|
666
|
+
const latestBlockHeaderHash = await latestBlockHeader?.hash() ?? GENESIS_BLOCK_HEADER_HASH;
|
|
667
|
+
const provenBlockHeaderHash = await provenCheckpointedBlock?.block.header?.hash() ?? GENESIS_BLOCK_HEADER_HASH;
|
|
668
|
+
const finalizedBlockHeaderHash = await finalizedCheckpointedBlock?.block.header?.hash() ?? GENESIS_BLOCK_HEADER_HASH;
|
|
669
|
+
const checkpointedBlockHeaderHash = await checkpointedBlock?.block.header?.hash() ?? GENESIS_BLOCK_HEADER_HASH;
|
|
670
|
+
// Now attempt to retrieve checkpoints for proven, finalised and checkpointed blocks
|
|
671
|
+
const [[provenBlockCheckpoint], [finalizedBlockCheckpoint], [checkpointedBlockCheckpoint]] = await Promise.all([
|
|
672
|
+
provenCheckpointedBlock !== undefined ? await this.getPublishedCheckpoints(provenCheckpointedBlock?.checkpointNumber, 1) : [
|
|
673
|
+
undefined
|
|
674
|
+
],
|
|
675
|
+
finalizedCheckpointedBlock !== undefined ? await this.getPublishedCheckpoints(finalizedCheckpointedBlock?.checkpointNumber, 1) : [
|
|
676
|
+
undefined
|
|
677
|
+
],
|
|
678
|
+
checkpointedBlock !== undefined ? await this.getPublishedCheckpoints(checkpointedBlock?.checkpointNumber, 1) : [
|
|
679
|
+
undefined
|
|
680
|
+
]
|
|
681
|
+
]);
|
|
682
|
+
const initialcheckpointId = {
|
|
683
|
+
number: CheckpointNumber.ZERO,
|
|
684
|
+
hash: GENESIS_CHECKPOINT_HEADER_HASH.toString()
|
|
685
|
+
};
|
|
686
|
+
const makeCheckpointId = (checkpoint)=>{
|
|
687
|
+
if (checkpoint === undefined) {
|
|
688
|
+
return initialcheckpointId;
|
|
689
|
+
}
|
|
690
|
+
return {
|
|
691
|
+
number: checkpoint.checkpoint.number,
|
|
692
|
+
hash: checkpoint.checkpoint.hash().toString()
|
|
693
|
+
};
|
|
694
|
+
};
|
|
695
|
+
const l2Tips = {
|
|
696
|
+
proposed: {
|
|
697
|
+
number: latestBlockNumber,
|
|
698
|
+
hash: latestBlockHeaderHash.toString()
|
|
699
|
+
},
|
|
700
|
+
proven: {
|
|
701
|
+
block: {
|
|
702
|
+
number: provenBlockNumber,
|
|
703
|
+
hash: provenBlockHeaderHash.toString()
|
|
704
|
+
},
|
|
705
|
+
checkpoint: makeCheckpointId(provenBlockCheckpoint)
|
|
706
|
+
},
|
|
707
|
+
finalized: {
|
|
708
|
+
block: {
|
|
709
|
+
number: finalizedBlockNumber,
|
|
710
|
+
hash: finalizedBlockHeaderHash.toString()
|
|
711
|
+
},
|
|
712
|
+
checkpoint: makeCheckpointId(finalizedBlockCheckpoint)
|
|
713
|
+
},
|
|
714
|
+
checkpointed: {
|
|
715
|
+
block: {
|
|
716
|
+
number: checkpointedBlockNumber,
|
|
717
|
+
hash: checkpointedBlockHeaderHash.toString()
|
|
718
|
+
},
|
|
719
|
+
checkpoint: makeCheckpointId(checkpointedBlockCheckpoint)
|
|
720
|
+
}
|
|
721
|
+
};
|
|
722
|
+
return l2Tips;
|
|
723
|
+
}
|
|
724
|
+
async rollbackTo(targetL2BlockNumber) {
|
|
725
|
+
// TODO(pw/mbps): This still assumes 1 block per checkpoint
|
|
726
|
+
const currentBlocks = await this.getL2Tips();
|
|
727
|
+
const currentL2Block = currentBlocks.proposed.number;
|
|
728
|
+
const currentProvenBlock = currentBlocks.proven.block.number;
|
|
729
|
+
if (targetL2BlockNumber >= currentL2Block) {
|
|
730
|
+
throw new Error(`Target L2 block ${targetL2BlockNumber} must be less than current L2 block ${currentL2Block}`);
|
|
731
|
+
}
|
|
732
|
+
const blocksToUnwind = currentL2Block - targetL2BlockNumber;
|
|
733
|
+
const targetL2Block = await this.store.getCheckpointedBlock(targetL2BlockNumber);
|
|
734
|
+
if (!targetL2Block) {
|
|
735
|
+
throw new Error(`Target L2 block ${targetL2BlockNumber} not found`);
|
|
736
|
+
}
|
|
737
|
+
const targetL1BlockNumber = targetL2Block.l1.blockNumber;
|
|
738
|
+
const targetCheckpointNumber = CheckpointNumber.fromBlockNumber(targetL2BlockNumber);
|
|
739
|
+
const targetL1Block = await this.publicClient.getBlock({
|
|
740
|
+
blockNumber: targetL1BlockNumber,
|
|
741
|
+
includeTransactions: false
|
|
742
|
+
});
|
|
743
|
+
if (!targetL1Block) {
|
|
744
|
+
throw new Error(`Missing L1 block ${targetL1BlockNumber}`);
|
|
745
|
+
}
|
|
746
|
+
const targetL1BlockHash = Buffer32.fromString(targetL1Block.hash);
|
|
747
|
+
this.log.info(`Unwinding ${blocksToUnwind} checkpoints from L2 block ${currentL2Block}`);
|
|
748
|
+
await this.updater.unwindCheckpointsWithContractData(CheckpointNumber(currentL2Block), blocksToUnwind);
|
|
749
|
+
this.log.info(`Unwinding L1 to L2 messages to checkpoint ${targetCheckpointNumber}`);
|
|
750
|
+
await this.store.rollbackL1ToL2MessagesToCheckpoint(targetCheckpointNumber);
|
|
751
|
+
this.log.info(`Setting L1 syncpoints to ${targetL1BlockNumber}`);
|
|
752
|
+
await this.store.setCheckpointSynchedL1BlockNumber(targetL1BlockNumber);
|
|
753
|
+
await this.store.setMessageSynchedL1Block({
|
|
754
|
+
l1BlockNumber: targetL1BlockNumber,
|
|
755
|
+
l1BlockHash: targetL1BlockHash
|
|
756
|
+
});
|
|
757
|
+
if (targetL2BlockNumber < currentProvenBlock) {
|
|
758
|
+
this.log.info(`Clearing proven L2 block number`);
|
|
759
|
+
await this.store.setProvenCheckpointNumber(CheckpointNumber.ZERO);
|
|
760
|
+
}
|
|
761
|
+
// TODO(palla/reorg): Set the finalized block when we add support for it.
|
|
762
|
+
// if (targetL2BlockNumber < currentFinalizedBlock) {
|
|
763
|
+
// this.log.info(`Clearing finalized L2 block number`);
|
|
764
|
+
// await this.store.setFinalizedL2BlockNumber(0);
|
|
765
|
+
// }
|
|
766
|
+
}
|
|
767
|
+
}
|