@aztec/archiver 0.0.1-commit.96bb3f7 → 0.0.1-commit.993d240
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 +164 -22
- package/dest/archiver.d.ts +158 -0
- package/dest/archiver.d.ts.map +1 -0
- package/dest/archiver.js +881 -0
- package/dest/config.d.ts +33 -0
- package/dest/config.d.ts.map +1 -0
- package/dest/{archiver/config.js → config.js} +31 -14
- package/dest/errors.d.ts +87 -0
- package/dest/errors.d.ts.map +1 -0
- package/dest/errors.js +129 -0
- package/dest/factory.d.ts +16 -10
- package/dest/factory.d.ts.map +1 -1
- package/dest/factory.js +112 -20
- package/dest/index.d.ts +19 -4
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +17 -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}/bin/retrieve-calldata.js +35 -32
- package/dest/l1/calldata_retriever.d.ts +136 -0
- package/dest/l1/calldata_retriever.d.ts.map +1 -0
- package/dest/l1/calldata_retriever.js +412 -0
- package/dest/l1/data_retrieval.d.ts +97 -0
- package/dest/l1/data_retrieval.d.ts.map +1 -0
- package/dest/{archiver/l1 → l1}/data_retrieval.js +65 -89
- 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 +5 -5
- package/dest/l1/spire_proposer.d.ts.map +1 -0
- package/dest/{archiver/l1 → l1}/spire_proposer.js +9 -17
- package/dest/l1/trace_tx.d.ts +43 -0
- 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/l1/validate_historical_logs.d.ts +23 -0
- package/dest/l1/validate_historical_logs.d.ts.map +1 -0
- package/dest/l1/validate_historical_logs.js +108 -0
- package/dest/{archiver/l1 → l1}/validate_trace.d.ts +6 -3
- package/dest/l1/validate_trace.d.ts.map +1 -0
- package/dest/{archiver/l1 → l1}/validate_trace.js +13 -9
- package/dest/modules/contract_data_source_adapter.d.ts +25 -0
- package/dest/modules/contract_data_source_adapter.d.ts.map +1 -0
- package/dest/modules/contract_data_source_adapter.js +40 -0
- package/dest/modules/data_source_base.d.ts +113 -0
- package/dest/modules/data_source_base.d.ts.map +1 -0
- package/dest/modules/data_source_base.js +351 -0
- package/dest/modules/data_store_updater.d.ts +105 -0
- package/dest/modules/data_store_updater.d.ts.map +1 -0
- package/dest/modules/data_store_updater.js +392 -0
- package/dest/modules/instrumentation.d.ts +55 -0
- package/dest/modules/instrumentation.d.ts.map +1 -0
- package/dest/{archiver → modules}/instrumentation.js +61 -19
- package/dest/modules/l1_synchronizer.d.ts +77 -0
- package/dest/modules/l1_synchronizer.d.ts.map +1 -0
- package/dest/modules/l1_synchronizer.js +1344 -0
- package/dest/modules/validation.d.ts +18 -0
- package/dest/modules/validation.d.ts.map +1 -0
- package/dest/{archiver → modules}/validation.js +12 -6
- package/dest/store/block_store.d.ts +300 -0
- package/dest/store/block_store.d.ts.map +1 -0
- package/dest/store/block_store.js +1219 -0
- package/dest/store/contract_class_store.d.ts +31 -0
- package/dest/store/contract_class_store.d.ts.map +1 -0
- package/dest/store/contract_class_store.js +80 -0
- package/dest/store/contract_instance_store.d.ts +51 -0
- package/dest/store/contract_instance_store.d.ts.map +1 -0
- package/dest/{archiver/kv_archiver_store → store}/contract_instance_store.js +38 -3
- package/dest/store/data_stores.d.ts +68 -0
- package/dest/store/data_stores.d.ts.map +1 -0
- package/dest/store/data_stores.js +54 -0
- package/dest/store/function_names_cache.d.ts +17 -0
- package/dest/store/function_names_cache.d.ts.map +1 -0
- package/dest/store/function_names_cache.js +30 -0
- package/dest/store/l2_tips_cache.d.ts +25 -0
- package/dest/store/l2_tips_cache.d.ts.map +1 -0
- package/dest/store/l2_tips_cache.js +26 -0
- package/dest/store/log_store.d.ts +59 -0
- package/dest/store/log_store.d.ts.map +1 -0
- package/dest/store/log_store.js +310 -0
- package/dest/store/log_store_codec.d.ts +70 -0
- package/dest/store/log_store_codec.d.ts.map +1 -0
- package/dest/store/log_store_codec.js +101 -0
- package/dest/store/message_store.d.ts +50 -0
- package/dest/store/message_store.d.ts.map +1 -0
- package/dest/{archiver/kv_archiver_store → store}/message_store.js +51 -9
- 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/test/fake_l1_state.d.ts +214 -0
- package/dest/test/fake_l1_state.d.ts.map +1 -0
- package/dest/test/fake_l1_state.js +517 -0
- package/dest/test/index.d.ts +2 -1
- package/dest/test/index.d.ts.map +1 -1
- package/dest/test/index.js +4 -1
- package/dest/test/mock_archiver.d.ts +2 -2
- package/dest/test/mock_archiver.d.ts.map +1 -1
- package/dest/test/mock_archiver.js +3 -3
- package/dest/test/mock_l1_to_l2_message_source.d.ts +1 -1
- package/dest/test/mock_l1_to_l2_message_source.d.ts.map +1 -1
- package/dest/test/mock_l1_to_l2_message_source.js +2 -1
- package/dest/test/mock_l2_block_source.d.ts +65 -41
- package/dest/test/mock_l2_block_source.d.ts.map +1 -1
- package/dest/test/mock_l2_block_source.js +330 -151
- package/dest/test/mock_structs.d.ts +81 -3
- package/dest/test/mock_structs.d.ts.map +1 -1
- package/dest/test/mock_structs.js +152 -7
- package/dest/test/noop_l1_archiver.d.ts +29 -0
- package/dest/test/noop_l1_archiver.d.ts.map +1 -0
- package/dest/test/noop_l1_archiver.js +85 -0
- package/package.json +17 -18
- package/src/archiver.ts +681 -0
- package/src/{archiver/config.ts → config.ts} +43 -12
- package/src/errors.ts +203 -0
- package/src/factory.ts +175 -22
- package/src/index.ts +27 -3
- package/src/interfaces.ts +9 -0
- package/src/l1/README.md +55 -0
- package/src/{archiver/l1 → l1}/bin/retrieve-calldata.ts +45 -33
- package/src/l1/calldata_retriever.ts +522 -0
- package/src/{archiver/l1 → l1}/data_retrieval.ts +106 -134
- package/src/{archiver/l1 → l1}/spire_proposer.ts +7 -15
- package/src/l1/validate_historical_logs.ts +140 -0
- package/src/{archiver/l1 → l1}/validate_trace.ts +24 -6
- package/src/modules/contract_data_source_adapter.ts +55 -0
- package/src/modules/data_source_base.ts +493 -0
- package/src/modules/data_store_updater.ts +518 -0
- package/src/{archiver → modules}/instrumentation.ts +72 -20
- package/src/modules/l1_synchronizer.ts +1257 -0
- package/src/{archiver → modules}/validation.ts +15 -9
- package/src/store/block_store.ts +1590 -0
- package/src/store/contract_class_store.ts +108 -0
- package/src/{archiver/kv_archiver_store → store}/contract_instance_store.ts +52 -6
- package/src/store/data_stores.ts +104 -0
- package/src/store/function_names_cache.ts +37 -0
- package/src/store/l2_tips_cache.ts +35 -0
- package/src/store/log_store.ts +379 -0
- package/src/store/log_store_codec.ts +132 -0
- package/src/{archiver/kv_archiver_store → store}/message_store.ts +60 -10
- package/src/{archiver/structs → structs}/inbox_message.ts +1 -1
- package/src/test/fake_l1_state.ts +770 -0
- package/src/test/index.ts +4 -0
- package/src/test/mock_archiver.ts +4 -3
- package/src/test/mock_l1_to_l2_message_source.ts +1 -0
- package/src/test/mock_l2_block_source.ts +403 -171
- package/src/test/mock_structs.ts +283 -8
- package/src/test/noop_l1_archiver.ts +139 -0
- package/dest/archiver/archiver.d.ts +0 -307
- package/dest/archiver/archiver.d.ts.map +0 -1
- package/dest/archiver/archiver.js +0 -2102
- package/dest/archiver/archiver_store.d.ts +0 -315
- package/dest/archiver/archiver_store.d.ts.map +0 -1
- package/dest/archiver/archiver_store.js +0 -4
- package/dest/archiver/archiver_store_test_suite.d.ts +0 -8
- package/dest/archiver/archiver_store_test_suite.d.ts.map +0 -1
- package/dest/archiver/archiver_store_test_suite.js +0 -2770
- package/dest/archiver/config.d.ts +0 -22
- package/dest/archiver/config.d.ts.map +0 -1
- package/dest/archiver/errors.d.ts +0 -36
- package/dest/archiver/errors.d.ts.map +0 -1
- package/dest/archiver/errors.js +0 -54
- package/dest/archiver/index.d.ts +0 -7
- package/dest/archiver/index.d.ts.map +0 -1
- package/dest/archiver/index.js +0 -4
- 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 +0 -164
- package/dest/archiver/kv_archiver_store/block_store.d.ts.map +0 -1
- package/dest/archiver/kv_archiver_store/block_store.js +0 -626
- 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_class_store.js +0 -120
- 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 +0 -159
- package/dest/archiver/kv_archiver_store/kv_archiver_store.d.ts.map +0 -1
- package/dest/archiver/kv_archiver_store/kv_archiver_store.js +0 -316
- package/dest/archiver/kv_archiver_store/log_store.d.ts +0 -45
- package/dest/archiver/kv_archiver_store/log_store.d.ts.map +0 -1
- package/dest/archiver/kv_archiver_store/log_store.js +0 -401
- package/dest/archiver/kv_archiver_store/message_store.d.ts +0 -40
- 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 +0 -112
- package/dest/archiver/l1/calldata_retriever.d.ts.map +0 -1
- package/dest/archiver/l1/calldata_retriever.js +0 -471
- package/dest/archiver/l1/data_retrieval.d.ts +0 -90
- 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 +0 -97
- 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/validation.d.ts +0 -17
- 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.ts +0 -2265
- package/src/archiver/archiver_store.ts +0 -380
- package/src/archiver/archiver_store_test_suite.ts +0 -2842
- package/src/archiver/errors.ts +0 -90
- package/src/archiver/index.ts +0 -6
- package/src/archiver/kv_archiver_store/block_store.ts +0 -850
- package/src/archiver/kv_archiver_store/contract_class_store.ts +0 -176
- package/src/archiver/kv_archiver_store/kv_archiver_store.ts +0 -442
- package/src/archiver/kv_archiver_store/log_store.ts +0 -516
- package/src/archiver/l1/README.md +0 -98
- package/src/archiver/l1/calldata_retriever.ts +0 -641
- package/src/rpc/index.ts +0 -16
- /package/dest/{archiver/l1 → l1}/debug_tx.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/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/src/{archiver/l1 → l1}/debug_tx.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/structs → structs}/data_retrieval.ts +0 -0
- /package/src/{archiver/structs → structs}/published.ts +0 -0
package/dest/archiver.js
ADDED
|
@@ -0,0 +1,881 @@
|
|
|
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 { BlockTagTooOldError } from '@aztec/ethereum/contracts';
|
|
375
|
+
import { BlockNumber, EpochNumber, SlotNumber } from '@aztec/foundation/branded-types';
|
|
376
|
+
import { Buffer32 } from '@aztec/foundation/buffer';
|
|
377
|
+
import { merge, pick } from '@aztec/foundation/collection';
|
|
378
|
+
import { EthAddress } from '@aztec/foundation/eth-address';
|
|
379
|
+
import { createLogger } from '@aztec/foundation/log';
|
|
380
|
+
import { promiseWithResolvers } from '@aztec/foundation/promise';
|
|
381
|
+
import { RunningPromise, makeLoggingErrorHandler } from '@aztec/foundation/running-promise';
|
|
382
|
+
import { elapsed } from '@aztec/foundation/timer';
|
|
383
|
+
import { L2BlockSourceEvents } from '@aztec/stdlib/block';
|
|
384
|
+
import { getEpochAtSlot, getSlotAtNextL1Block, getSlotRangeForEpoch, getTimestampForSlot, getTimestampRangeForEpoch } from '@aztec/stdlib/epoch-helpers';
|
|
385
|
+
import { trackSpan } from '@aztec/telemetry-client';
|
|
386
|
+
import { mapArchiverConfig } from './config.js';
|
|
387
|
+
import { BlockAlreadyCheckpointedError, BlockOrCheckpointSlotExpiredError, NoBlobBodiesFoundError } from './errors.js';
|
|
388
|
+
import { validateAndLogHistoricalLogsAvailability } from './l1/validate_historical_logs.js';
|
|
389
|
+
import { validateAndLogTraceAvailability } from './l1/validate_trace.js';
|
|
390
|
+
import { ArchiverDataSourceBase } from './modules/data_source_base.js';
|
|
391
|
+
import { ArchiverDataStoreUpdater } from './modules/data_store_updater.js';
|
|
392
|
+
import { backupArchiverDataStores, getArchiverSynchPoint } from './store/data_stores.js';
|
|
393
|
+
_dec = trackSpan('Archiver.sync');
|
|
394
|
+
/**
|
|
395
|
+
* Pulls checkpoints in a non-blocking manner and provides interface for their retrieval.
|
|
396
|
+
* Responsible for handling robust L1 polling so that other components do not need to
|
|
397
|
+
* concern themselves with it.
|
|
398
|
+
*/ export class Archiver extends ArchiverDataSourceBase {
|
|
399
|
+
publicClient;
|
|
400
|
+
debugClient;
|
|
401
|
+
rollup;
|
|
402
|
+
l1Addresses;
|
|
403
|
+
dataStores;
|
|
404
|
+
config;
|
|
405
|
+
blobClient;
|
|
406
|
+
l1Constants;
|
|
407
|
+
epochCache;
|
|
408
|
+
dateProvider;
|
|
409
|
+
log;
|
|
410
|
+
static{
|
|
411
|
+
({ e: [_initProto] } = _apply_decs_2203_r(this, [
|
|
412
|
+
[
|
|
413
|
+
_dec,
|
|
414
|
+
2,
|
|
415
|
+
"sync"
|
|
416
|
+
]
|
|
417
|
+
], []));
|
|
418
|
+
}
|
|
419
|
+
/** Event emitter for archiver events (L2BlockProven, L2PruneUnproven, L2PruneUncheckpointed, etc). */ events;
|
|
420
|
+
/** A loop in which we will be continually fetching new checkpoints. */ runningPromise;
|
|
421
|
+
/** L1 synchronizer that handles fetching checkpoints and messages from L1. */ synchronizer;
|
|
422
|
+
initialSyncComplete;
|
|
423
|
+
initialSyncPromise;
|
|
424
|
+
/** Queue of blocks and checkpoints to be added to the store, processed by the sync loop. */ inboundQueue;
|
|
425
|
+
/** Helper to handle updates to the store */ updater;
|
|
426
|
+
/** In-memory cache for L2 chain tips. */ l2TipsCache;
|
|
427
|
+
tracer;
|
|
428
|
+
instrumentation;
|
|
429
|
+
/**
|
|
430
|
+
* Creates a new instance of the Archiver.
|
|
431
|
+
* @param publicClient - A client for interacting with the Ethereum node.
|
|
432
|
+
* @param debugClient - A client for interacting with the Ethereum node for debug/trace methods.
|
|
433
|
+
* @param rollup - Rollup contract instance.
|
|
434
|
+
* @param inbox - Inbox contract instance.
|
|
435
|
+
* @param l1Addresses - L1 contract addresses (registry, governance proposer, slashing proposer).
|
|
436
|
+
* @param dataStores - Archiver substores for storage & retrieval of blocks, encrypted logs & contract data.
|
|
437
|
+
* @param config - Archiver configuration options.
|
|
438
|
+
* @param blobClient - Client for retrieving blob data.
|
|
439
|
+
* @param instrumentation - Instrumentation for metrics and tracing.
|
|
440
|
+
* @param l1Constants - L1 rollup constants.
|
|
441
|
+
* @param synchronizer - L1 synchronizer that handles fetching checkpoints and messages from L1.
|
|
442
|
+
* @param events - Event emitter shared with the synchronizer.
|
|
443
|
+
* @param initialHeader - Genesis block header.
|
|
444
|
+
* @param initialBlockHash - Precomputed hash of the genesis block header.
|
|
445
|
+
* @param l2TipsCache - In-memory cache for L2 chain tips.
|
|
446
|
+
* @param epochCache - Cache used to compute the proposer pipelining offset.
|
|
447
|
+
* @param dateProvider - Provider for current date/time, used for wall-clock orphan-block pruning.
|
|
448
|
+
* @param log - A logger.
|
|
449
|
+
*/ constructor(publicClient, debugClient, rollup, l1Addresses, dataStores, config, blobClient, instrumentation, l1Constants, synchronizer, events, initialHeader, initialBlockHash, l2TipsCache, epochCache, dateProvider, log = createLogger('archiver')){
|
|
450
|
+
super(dataStores, l1Constants, initialHeader, initialBlockHash, l1Constants.genesisArchiveRoot), this.publicClient = publicClient, this.debugClient = debugClient, this.rollup = rollup, this.l1Addresses = l1Addresses, this.dataStores = dataStores, this.config = config, this.blobClient = blobClient, this.l1Constants = l1Constants, this.epochCache = epochCache, this.dateProvider = dateProvider, this.log = log, this.initialSyncComplete = (_initProto(this), false), this.inboundQueue = [];
|
|
451
|
+
this.tracer = instrumentation.tracer;
|
|
452
|
+
this.instrumentation = instrumentation;
|
|
453
|
+
this.initialSyncPromise = promiseWithResolvers();
|
|
454
|
+
this.synchronizer = synchronizer;
|
|
455
|
+
this.events = events;
|
|
456
|
+
this.l2TipsCache = l2TipsCache;
|
|
457
|
+
this.updater = new ArchiverDataStoreUpdater(this.dataStores, this.l2TipsCache, {
|
|
458
|
+
rollupManaLimit: l1Constants.rollupManaLimit
|
|
459
|
+
});
|
|
460
|
+
// Running promise starts with a small interval inbetween runs, so all iterations needed for the initial sync
|
|
461
|
+
// are done as fast as possible. This then gets updated once the initial sync completes.
|
|
462
|
+
this.runningPromise = new RunningPromise(()=>this.sync(), this.log, this.config.pollingIntervalMs / 10, makeLoggingErrorHandler(this.log, NoBlobBodiesFoundError, BlockTagTooOldError));
|
|
463
|
+
}
|
|
464
|
+
/** Updates archiver config */ updateConfig(newConfig) {
|
|
465
|
+
this.config = merge(this.config, mapArchiverConfig(newConfig));
|
|
466
|
+
this.synchronizer.setConfig(this.config);
|
|
467
|
+
}
|
|
468
|
+
/**
|
|
469
|
+
* Starts sync process.
|
|
470
|
+
* @param blockUntilSynced - If true, blocks until the archiver has fully synced.
|
|
471
|
+
*/ async start(blockUntilSynced) {
|
|
472
|
+
if (this.runningPromise.isRunning()) {
|
|
473
|
+
throw new Error('Archiver is already running');
|
|
474
|
+
}
|
|
475
|
+
await this.blobClient.testSources();
|
|
476
|
+
await this.synchronizer.testEthereumNodeSynced();
|
|
477
|
+
await validateAndLogTraceAvailability(this.debugClient, this.config.ethereumAllowNoDebugHosts ?? false, this.log.getBindings());
|
|
478
|
+
await validateAndLogHistoricalLogsAvailability(this.publicClient, {
|
|
479
|
+
rollupAddress: this.l1Addresses.rollupAddress,
|
|
480
|
+
inboxAddress: this.l1Addresses.inboxAddress,
|
|
481
|
+
registryAddress: this.l1Addresses.registryAddress,
|
|
482
|
+
governanceProposerAddress: this.l1Addresses.governanceProposerAddress
|
|
483
|
+
}, this.config.skipHistoricalLogsCheck ?? false, this.log.getBindings());
|
|
484
|
+
// Log initial state for the archiver
|
|
485
|
+
const { l1StartBlock } = this.l1Constants;
|
|
486
|
+
const { blocksSynchedTo = l1StartBlock, messagesSynchedTo = l1StartBlock } = await getArchiverSynchPoint(this.stores);
|
|
487
|
+
const currentL2Checkpoint = await this.getCheckpointNumber();
|
|
488
|
+
this.log.info(`Starting archiver sync to rollup contract ${this.rollup.address} from L1 block ${blocksSynchedTo} and L2 checkpoint ${currentL2Checkpoint}`, {
|
|
489
|
+
blocksSynchedTo,
|
|
490
|
+
messagesSynchedTo,
|
|
491
|
+
currentL2Checkpoint
|
|
492
|
+
});
|
|
493
|
+
// Start sync loop, and return the wait for initial sync if we are asked to block until synced
|
|
494
|
+
this.runningPromise.start();
|
|
495
|
+
if (blockUntilSynced) {
|
|
496
|
+
return this.waitForInitialSync();
|
|
497
|
+
}
|
|
498
|
+
}
|
|
499
|
+
syncImmediate() {
|
|
500
|
+
return this.runningPromise.trigger();
|
|
501
|
+
}
|
|
502
|
+
trySyncImmediate() {
|
|
503
|
+
try {
|
|
504
|
+
return this.syncImmediate();
|
|
505
|
+
} catch (err) {
|
|
506
|
+
this.log.error(`Failed to trigger immediate archiver sync: ${err}`, err);
|
|
507
|
+
}
|
|
508
|
+
}
|
|
509
|
+
/**
|
|
510
|
+
* Queues a block to be added to the archiver store and triggers processing.
|
|
511
|
+
* The block will be processed by the sync loop.
|
|
512
|
+
* Implements the L2BlockSink interface.
|
|
513
|
+
* @param block - The L2 block to add.
|
|
514
|
+
* @returns A promise that resolves when the block has been added to the store, or rejects on error.
|
|
515
|
+
*/ addBlock(block) {
|
|
516
|
+
const promise = promiseWithResolvers();
|
|
517
|
+
this.inboundQueue.push({
|
|
518
|
+
block,
|
|
519
|
+
...promise,
|
|
520
|
+
type: 'block'
|
|
521
|
+
});
|
|
522
|
+
this.log.debug(`Queued block ${block.number} for processing`);
|
|
523
|
+
void this.trySyncImmediate();
|
|
524
|
+
return promise.promise;
|
|
525
|
+
}
|
|
526
|
+
/**
|
|
527
|
+
* Queues a new proposed checkpoint into the archiver store.
|
|
528
|
+
* Checks that the checkpoint is not for an L2 slot already synced from L1.
|
|
529
|
+
* Resolves once the checkpoint has been processed.
|
|
530
|
+
*/ addProposedCheckpoint(pending) {
|
|
531
|
+
const promise = promiseWithResolvers();
|
|
532
|
+
this.inboundQueue.push({
|
|
533
|
+
checkpoint: pending,
|
|
534
|
+
...promise,
|
|
535
|
+
type: 'checkpoint'
|
|
536
|
+
});
|
|
537
|
+
this.log.debug(`Queued checkpoint ${pending.checkpointNumber} for processing`);
|
|
538
|
+
void this.trySyncImmediate();
|
|
539
|
+
return promise.promise;
|
|
540
|
+
}
|
|
541
|
+
/**
|
|
542
|
+
* Processes all queued blocks and checkpoints, adding them to the store.
|
|
543
|
+
* Called at the beginning of each sync iteration.
|
|
544
|
+
* Items are processed in the order they were queued.
|
|
545
|
+
*/ async processInboundQueue() {
|
|
546
|
+
if (this.inboundQueue.length === 0) {
|
|
547
|
+
return;
|
|
548
|
+
}
|
|
549
|
+
// Take all items from the queue
|
|
550
|
+
const queuedItems = this.inboundQueue.splice(0, this.inboundQueue.length);
|
|
551
|
+
this.log.debug(`Processing ${queuedItems.length} queued inbound items`);
|
|
552
|
+
// Calculate slot threshold for validation
|
|
553
|
+
const l1Timestamp = this.synchronizer.getL1Timestamp();
|
|
554
|
+
const slotAtNextL1Block = l1Timestamp === undefined ? undefined : getSlotAtNextL1Block(l1Timestamp, this.l1Constants);
|
|
555
|
+
// Helpers for manipulating blocks and checkpoints in the queue
|
|
556
|
+
const getSlot = (item)=>item.type === 'block' ? item.block.header.globalVariables.slotNumber : item.checkpoint.header.slotNumber;
|
|
557
|
+
const getNumber = (item)=>item.type === 'block' ? item.block.number : item.checkpoint.checkpointNumber;
|
|
558
|
+
// Process each item individually to properly resolve/reject each promise
|
|
559
|
+
for (const item of queuedItems){
|
|
560
|
+
const { resolve, reject, type } = item;
|
|
561
|
+
const itemSlot = getSlot(item);
|
|
562
|
+
const itemNumber = getNumber(item);
|
|
563
|
+
if (slotAtNextL1Block !== undefined && itemSlot < slotAtNextL1Block) {
|
|
564
|
+
const nextSlotTimestamp = getTimestampForSlot(slotAtNextL1Block, this.l1Constants);
|
|
565
|
+
this.log.warn(`Rejecting proposed ${type} ${itemNumber} for past slot ${itemSlot} (current ${slotAtNextL1Block})`, {
|
|
566
|
+
number: itemNumber,
|
|
567
|
+
type,
|
|
568
|
+
l1Timestamp,
|
|
569
|
+
slotAtNextL1Block,
|
|
570
|
+
nextSlotTimestamp
|
|
571
|
+
});
|
|
572
|
+
reject(new BlockOrCheckpointSlotExpiredError(itemSlot, nextSlotTimestamp, l1Timestamp));
|
|
573
|
+
continue;
|
|
574
|
+
}
|
|
575
|
+
try {
|
|
576
|
+
if (type === 'block') {
|
|
577
|
+
const [durationMs] = await elapsed(()=>this.updater.addProposedBlock(item.block));
|
|
578
|
+
this.instrumentation.processNewProposedBlock(durationMs, item.block);
|
|
579
|
+
} else {
|
|
580
|
+
await this.updater.addProposedCheckpoint(item.checkpoint);
|
|
581
|
+
}
|
|
582
|
+
this.log.debug(`Added ${type} ${itemNumber} to store`);
|
|
583
|
+
resolve();
|
|
584
|
+
} catch (err) {
|
|
585
|
+
if (err instanceof BlockAlreadyCheckpointedError) {
|
|
586
|
+
this.log.debug(`Proposed block ${itemNumber} matches already checkpointed block, ignoring late proposal`);
|
|
587
|
+
resolve();
|
|
588
|
+
continue;
|
|
589
|
+
}
|
|
590
|
+
this.log.error(`Failed to add ${type} ${itemNumber} to store: ${err.message}`, err, {
|
|
591
|
+
number: itemNumber,
|
|
592
|
+
type
|
|
593
|
+
});
|
|
594
|
+
reject(err);
|
|
595
|
+
}
|
|
596
|
+
}
|
|
597
|
+
}
|
|
598
|
+
waitForInitialSync() {
|
|
599
|
+
return this.initialSyncPromise.promise;
|
|
600
|
+
}
|
|
601
|
+
/**
|
|
602
|
+
* Fetches logs from L1 contracts and processes them.
|
|
603
|
+
*/ async sync() {
|
|
604
|
+
// Process any queued blocks first, before doing L1 sync
|
|
605
|
+
await this.processInboundQueue();
|
|
606
|
+
// Now perform L1 sync
|
|
607
|
+
await this.syncFromL1();
|
|
608
|
+
// Prune proposed blocks with no corresponding proposed checkpoint by the end of their build slot.
|
|
609
|
+
await this.pruneOrphanProposedBlocks();
|
|
610
|
+
}
|
|
611
|
+
/**
|
|
612
|
+
* Prunes a block-only local tip that was built atop a checkpoint that was never itself proposed.
|
|
613
|
+
*
|
|
614
|
+
* Under pipelining, a proposer publishes the blocks for a checkpoint (block-only proposals) before
|
|
615
|
+
* assembling and publishing the enclosing proposed checkpoint at the end of the build slot. A node
|
|
616
|
+
* that received those blocks but never the proposed checkpoint is left with an orphan tip it must
|
|
617
|
+
* not build on. We prune it once enough wall-clock time has elapsed that the proposed checkpoint
|
|
618
|
+
* should have arrived. This runs on wall-clock time (not L1 block advancement) so it fires during
|
|
619
|
+
* quiet L1 periods, and is the liveness counterpart to the sequencer's checkSync guard.
|
|
620
|
+
*
|
|
621
|
+
* The uncheckpointed suffix is scanned in order. Blocks covered by proposed checkpoints are left in
|
|
622
|
+
* place; the first block not covered by a proposed checkpoint starts the orphan suffix to prune.
|
|
623
|
+
*/ async pruneOrphanProposedBlocks() {
|
|
624
|
+
const tips = await this.getL2Tips();
|
|
625
|
+
const now = BigInt(this.dateProvider.nowInSeconds());
|
|
626
|
+
const pipeliningOffset = this.epochCache.pipeliningOffset();
|
|
627
|
+
// This only applies under pipelining
|
|
628
|
+
if (pipeliningOffset === 0) {
|
|
629
|
+
this.log.trace(`Pipelining offset is 0, skipping orphan proposed block pruning`);
|
|
630
|
+
return;
|
|
631
|
+
}
|
|
632
|
+
// The proposed tip is a proposed-checkpointed block, so there are no orphan proposed blocks to prune
|
|
633
|
+
if (tips.proposedCheckpoint.block.number === tips.proposed.number) {
|
|
634
|
+
this.log.trace(`No orphan proposed blocks to prune: proposed tip ${tips.proposed.number} is checkpointed`, pick(tips, 'proposed', 'proposedCheckpoint'));
|
|
635
|
+
return;
|
|
636
|
+
}
|
|
637
|
+
// Load the blocks that are candidates for pruning (ie blocks without a proposed checkpoint covering them)
|
|
638
|
+
const blocksWithoutProposedCheckpoint = await this.stores.blocks.getBlocksData({
|
|
639
|
+
from: BlockNumber(tips.proposedCheckpoint.block.number + 1),
|
|
640
|
+
limit: tips.proposed.number - tips.proposedCheckpoint.block.number
|
|
641
|
+
});
|
|
642
|
+
// Iterate through them in order, the first one with a slot that should have received a proposed checkpoint
|
|
643
|
+
// is the first orphan block, and all blocks after it are also orphaned and should be pruned.
|
|
644
|
+
let lastSlotChecked = undefined;
|
|
645
|
+
for (const blockData of blocksWithoutProposedCheckpoint){
|
|
646
|
+
// No need to recheck if this block had the same slot as the previous one.
|
|
647
|
+
const blockSlot = blockData.header.getSlot();
|
|
648
|
+
const blockNumber = blockData.header.getBlockNumber();
|
|
649
|
+
if (lastSlotChecked !== undefined && blockSlot === lastSlotChecked) {
|
|
650
|
+
continue;
|
|
651
|
+
}
|
|
652
|
+
lastSlotChecked = blockSlot;
|
|
653
|
+
// The proposed checkpoint should have landed by the start of the slot after the block's build slot
|
|
654
|
+
// (build slot = blockSlot - pipeliningOffset). Wait a grace period beyond that to tolerate propagation.
|
|
655
|
+
const expectedCheckpointedBySlot = SlotNumber(Number(blockSlot) - pipeliningOffset + 1);
|
|
656
|
+
const expectedCheckpointedByTime = getTimestampForSlot(expectedCheckpointedBySlot, this.l1Constants) + BigInt(this.config.orphanProposedBlockPruneGraceSeconds);
|
|
657
|
+
// If it's not checkpointed by the expected time, prune it along with all blocks after it.
|
|
658
|
+
if (now >= expectedCheckpointedByTime) {
|
|
659
|
+
const pruneAfterBlockNumber = BlockNumber(blockNumber - 1);
|
|
660
|
+
this.log.warn(`Pruning orphan blocks after block ${pruneAfterBlockNumber}: block at slot ${blockSlot} belongs to ` + `checkpoint ${blockData.checkpointNumber} which has no matching proposed checkpoint`, {
|
|
661
|
+
firstUncheckpointedBlockHeader: blockData.header.toInspect(),
|
|
662
|
+
blockCheckpointNumber: blockData.checkpointNumber,
|
|
663
|
+
blockNumber,
|
|
664
|
+
blockSlot,
|
|
665
|
+
pipeliningOffset,
|
|
666
|
+
expectedCheckpointedBySlot,
|
|
667
|
+
expectedCheckpointedByTime,
|
|
668
|
+
now
|
|
669
|
+
});
|
|
670
|
+
const prunedBlocks = await this.updater.removeBlocksWithoutProposedCheckpointAfter(pruneAfterBlockNumber);
|
|
671
|
+
if (prunedBlocks.length > 0) {
|
|
672
|
+
this.events.emit(L2BlockSourceEvents.L2PruneUncheckpointed, {
|
|
673
|
+
type: L2BlockSourceEvents.L2PruneUncheckpointed,
|
|
674
|
+
slotNumber: blockSlot,
|
|
675
|
+
blocks: prunedBlocks
|
|
676
|
+
});
|
|
677
|
+
}
|
|
678
|
+
return;
|
|
679
|
+
}
|
|
680
|
+
}
|
|
681
|
+
this.log.trace('No orphan proposed blocks to prune: all uncheckpointed blocks are still within the grace period', {
|
|
682
|
+
blocksWithoutProposedCheckpoint: blocksWithoutProposedCheckpoint.map((b)=>b.header.toInspect())
|
|
683
|
+
});
|
|
684
|
+
}
|
|
685
|
+
async syncFromL1() {
|
|
686
|
+
// Delegate to the L1 synchronizer
|
|
687
|
+
await this.synchronizer.syncFromL1(this.initialSyncComplete);
|
|
688
|
+
// Check if we've completed initial sync
|
|
689
|
+
const currentL1BlockNumber = this.synchronizer.getL1BlockNumber();
|
|
690
|
+
if (currentL1BlockNumber !== undefined && !this.initialSyncComplete) {
|
|
691
|
+
const l1BlockNumberAtEnd = await this.publicClient.getBlockNumber();
|
|
692
|
+
if (currentL1BlockNumber + 1n >= l1BlockNumberAtEnd) {
|
|
693
|
+
this.log.info(`Initial archiver sync to L1 block ${currentL1BlockNumber} complete`, {
|
|
694
|
+
l1BlockNumber: currentL1BlockNumber,
|
|
695
|
+
syncPoint: await getArchiverSynchPoint(this.stores),
|
|
696
|
+
...await this.getL2Tips()
|
|
697
|
+
});
|
|
698
|
+
this.runningPromise.setPollingIntervalMS(this.config.pollingIntervalMs);
|
|
699
|
+
this.initialSyncComplete = true;
|
|
700
|
+
this.initialSyncPromise.resolve();
|
|
701
|
+
}
|
|
702
|
+
}
|
|
703
|
+
}
|
|
704
|
+
/** Resumes the archiver after a stop. */ resume() {
|
|
705
|
+
if (this.runningPromise.isRunning()) {
|
|
706
|
+
this.log.warn(`Archiver already running`);
|
|
707
|
+
}
|
|
708
|
+
this.log.info(`Restarting archiver`);
|
|
709
|
+
this.runningPromise.start();
|
|
710
|
+
}
|
|
711
|
+
/**
|
|
712
|
+
* Stops the archiver.
|
|
713
|
+
* @returns A promise signalling completion of the stop process.
|
|
714
|
+
*/ async stop() {
|
|
715
|
+
this.log.debug('Stopping...');
|
|
716
|
+
await this.runningPromise.stop();
|
|
717
|
+
this.log.info('Stopped.');
|
|
718
|
+
return Promise.resolve();
|
|
719
|
+
}
|
|
720
|
+
backupTo(destPath) {
|
|
721
|
+
return backupArchiverDataStores(this.dataStores, destPath);
|
|
722
|
+
}
|
|
723
|
+
getL1Constants() {
|
|
724
|
+
return Promise.resolve(this.l1Constants);
|
|
725
|
+
}
|
|
726
|
+
getGenesisValues() {
|
|
727
|
+
return Promise.resolve({
|
|
728
|
+
genesisArchiveRoot: this.l1Constants.genesisArchiveRoot
|
|
729
|
+
});
|
|
730
|
+
}
|
|
731
|
+
getRollupAddress() {
|
|
732
|
+
return Promise.resolve(EthAddress.fromString(this.rollup.address));
|
|
733
|
+
}
|
|
734
|
+
getRegistryAddress() {
|
|
735
|
+
return Promise.resolve(this.l1Addresses.registryAddress);
|
|
736
|
+
}
|
|
737
|
+
getL1BlockNumber() {
|
|
738
|
+
return this.synchronizer.getL1BlockNumber();
|
|
739
|
+
}
|
|
740
|
+
getL1Timestamp() {
|
|
741
|
+
return Promise.resolve(this.synchronizer.getL1Timestamp());
|
|
742
|
+
}
|
|
743
|
+
async getSyncedL2SlotNumber() {
|
|
744
|
+
// The synced L2 slot is the latest slot for which we have all L1 data,
|
|
745
|
+
// either because we have seen all L1 blocks for that slot, or because
|
|
746
|
+
// we have seen the corresponding checkpoint.
|
|
747
|
+
let slotFromL1Sync;
|
|
748
|
+
const l1Timestamp = this.synchronizer.getL1Timestamp();
|
|
749
|
+
if (l1Timestamp !== undefined) {
|
|
750
|
+
const nextL1BlockSlot = getSlotAtNextL1Block(l1Timestamp, this.l1Constants);
|
|
751
|
+
if (Number(nextL1BlockSlot) > 0) {
|
|
752
|
+
slotFromL1Sync = SlotNumber.add(nextL1BlockSlot, -1);
|
|
753
|
+
}
|
|
754
|
+
}
|
|
755
|
+
let slotFromCheckpoint;
|
|
756
|
+
const latestCheckpointNumber = await this.stores.blocks.getLatestCheckpointNumber();
|
|
757
|
+
if (latestCheckpointNumber > 0) {
|
|
758
|
+
const checkpointData = await this.stores.blocks.getCheckpointData(latestCheckpointNumber);
|
|
759
|
+
if (checkpointData) {
|
|
760
|
+
slotFromCheckpoint = checkpointData.header.slotNumber;
|
|
761
|
+
}
|
|
762
|
+
}
|
|
763
|
+
if (slotFromL1Sync === undefined && slotFromCheckpoint === undefined) {
|
|
764
|
+
return undefined;
|
|
765
|
+
}
|
|
766
|
+
return SlotNumber(Math.max(slotFromL1Sync ?? 0, slotFromCheckpoint ?? 0));
|
|
767
|
+
}
|
|
768
|
+
async getSyncedL2EpochNumber() {
|
|
769
|
+
const syncedSlot = await this.getSyncedL2SlotNumber();
|
|
770
|
+
if (syncedSlot === undefined) {
|
|
771
|
+
return undefined;
|
|
772
|
+
}
|
|
773
|
+
// An epoch is fully synced when all its slots are synced.
|
|
774
|
+
// We check if syncedSlot is the last slot of its epoch; if so, that epoch is fully synced.
|
|
775
|
+
// Otherwise, only the previous epoch is fully synced.
|
|
776
|
+
const epoch = getEpochAtSlot(syncedSlot, this.l1Constants);
|
|
777
|
+
const [, endSlot] = getSlotRangeForEpoch(epoch, this.l1Constants);
|
|
778
|
+
if (syncedSlot >= endSlot) {
|
|
779
|
+
return epoch;
|
|
780
|
+
}
|
|
781
|
+
return Number(epoch) > 0 ? EpochNumber(Number(epoch) - 1) : undefined;
|
|
782
|
+
}
|
|
783
|
+
async isEpochComplete(epochNumber) {
|
|
784
|
+
// The epoch is complete if the current checkpointed L2 block is the last one in the epoch (or later).
|
|
785
|
+
// We use the checkpointed block number (synced from L1) instead of 'latest' to avoid returning true
|
|
786
|
+
// prematurely when proposed blocks have been pushed to the archiver but not yet checkpointed on L1.
|
|
787
|
+
const header = (await this.getBlockData({
|
|
788
|
+
tag: 'checkpointed'
|
|
789
|
+
}))?.header;
|
|
790
|
+
const slot = header ? header.globalVariables.slotNumber : undefined;
|
|
791
|
+
const [_startSlot, endSlot] = getSlotRangeForEpoch(epochNumber, this.l1Constants);
|
|
792
|
+
if (slot && slot >= endSlot) {
|
|
793
|
+
return true;
|
|
794
|
+
}
|
|
795
|
+
// If we haven't run an initial sync, just return false.
|
|
796
|
+
const l1Timestamp = this.synchronizer.getL1Timestamp();
|
|
797
|
+
if (l1Timestamp === undefined) {
|
|
798
|
+
return false;
|
|
799
|
+
}
|
|
800
|
+
// If not, the epoch may also be complete if the L2 slot has passed without a block
|
|
801
|
+
// We compute this based on the end timestamp for the given epoch and the timestamp of the last L1 block
|
|
802
|
+
const [_startTimestamp, endTimestamp] = getTimestampRangeForEpoch(epochNumber, this.l1Constants);
|
|
803
|
+
// For this computation, we throw in a few extra seconds just for good measure,
|
|
804
|
+
// since we know the next L1 block won't be mined within this range. Remember that
|
|
805
|
+
// l1timestamp is the timestamp of the last l1 block we've seen, so this relies on
|
|
806
|
+
// the fact that L1 won't mine two blocks within this time of each other.
|
|
807
|
+
// TODO(palla/reorg): Is the above a safe assumption?
|
|
808
|
+
const leeway = 1n;
|
|
809
|
+
return l1Timestamp + leeway >= endTimestamp;
|
|
810
|
+
}
|
|
811
|
+
/** Returns whether the archiver has completed an initial sync run successfully. */ isInitialSyncComplete() {
|
|
812
|
+
return this.initialSyncComplete;
|
|
813
|
+
}
|
|
814
|
+
removeCheckpointsAfter(checkpointNumber) {
|
|
815
|
+
return this.updater.removeCheckpointsAfter(checkpointNumber);
|
|
816
|
+
}
|
|
817
|
+
/** Used by TXE to add checkpoints directly without syncing from L1. */ async addCheckpoints(checkpoints, pendingChainValidationStatus) {
|
|
818
|
+
await this.updater.addCheckpoints(checkpoints, pendingChainValidationStatus);
|
|
819
|
+
return true;
|
|
820
|
+
}
|
|
821
|
+
getL2Tips() {
|
|
822
|
+
return this.l2TipsCache.getL2Tips();
|
|
823
|
+
}
|
|
824
|
+
async rollbackTo(targetL2BlockNumber) {
|
|
825
|
+
const currentBlocks = await this.getL2Tips();
|
|
826
|
+
const currentL2Block = currentBlocks.proposed.number;
|
|
827
|
+
const currentProvenBlock = currentBlocks.proven.block.number;
|
|
828
|
+
if (targetL2BlockNumber >= currentL2Block) {
|
|
829
|
+
throw new Error(`Target L2 block ${targetL2BlockNumber} must be less than current L2 block ${currentL2Block}`);
|
|
830
|
+
}
|
|
831
|
+
const checkpointedTip = await this.stores.blocks.getCheckpointedL2BlockNumber();
|
|
832
|
+
if (targetL2BlockNumber > checkpointedTip) {
|
|
833
|
+
throw new Error(`Target L2 block ${targetL2BlockNumber} is not checkpointed yet`);
|
|
834
|
+
}
|
|
835
|
+
const targetBlockData = await this.stores.blocks.getBlockData({
|
|
836
|
+
number: targetL2BlockNumber
|
|
837
|
+
});
|
|
838
|
+
if (!targetBlockData) {
|
|
839
|
+
throw new Error(`Target L2 block ${targetL2BlockNumber} not found`);
|
|
840
|
+
}
|
|
841
|
+
const targetCheckpointNumber = targetBlockData.checkpointNumber;
|
|
842
|
+
// Rollback operates at checkpoint granularity: the target block must be the last block of its checkpoint.
|
|
843
|
+
const checkpointData = await this.stores.blocks.getCheckpointData(targetCheckpointNumber);
|
|
844
|
+
if (!checkpointData) {
|
|
845
|
+
throw new Error(`Checkpoint ${targetCheckpointNumber} not found for block ${targetL2BlockNumber}`);
|
|
846
|
+
}
|
|
847
|
+
const lastBlockInCheckpoint = BlockNumber(checkpointData.startBlock + checkpointData.blockCount - 1);
|
|
848
|
+
if (targetL2BlockNumber !== lastBlockInCheckpoint) {
|
|
849
|
+
const previousCheckpointBoundary = checkpointData.startBlock > 1 ? BlockNumber(checkpointData.startBlock - 1) : BlockNumber(0);
|
|
850
|
+
throw new Error(`Target L2 block ${targetL2BlockNumber} is not at a checkpoint boundary. ` + `Checkpoint ${targetCheckpointNumber} spans blocks ${checkpointData.startBlock} to ${lastBlockInCheckpoint}. ` + `Use block ${lastBlockInCheckpoint} to roll back to this checkpoint, ` + `or block ${previousCheckpointBoundary} to roll back to the previous one.`);
|
|
851
|
+
}
|
|
852
|
+
const targetL1BlockNumber = checkpointData.l1.blockNumber;
|
|
853
|
+
const targetL1Block = await this.publicClient.getBlock({
|
|
854
|
+
blockNumber: targetL1BlockNumber,
|
|
855
|
+
includeTransactions: false
|
|
856
|
+
});
|
|
857
|
+
if (!targetL1Block) {
|
|
858
|
+
throw new Error(`Missing L1 block ${targetL1BlockNumber}`);
|
|
859
|
+
}
|
|
860
|
+
const targetL1BlockHash = Buffer32.fromString(targetL1Block.hash);
|
|
861
|
+
this.log.info(`Removing checkpoints after checkpoint ${targetCheckpointNumber} (target block ${targetL2BlockNumber})`);
|
|
862
|
+
await this.updater.removeCheckpointsAfter(targetCheckpointNumber);
|
|
863
|
+
this.log.info(`Rolling back L1 to L2 messages to checkpoint ${targetCheckpointNumber}`);
|
|
864
|
+
await this.stores.messages.rollbackL1ToL2MessagesToCheckpoint(targetCheckpointNumber);
|
|
865
|
+
this.log.info(`Setting L1 syncpoints to ${targetL1BlockNumber}`);
|
|
866
|
+
await this.stores.blocks.setSynchedL1BlockNumber(targetL1BlockNumber);
|
|
867
|
+
await this.stores.messages.setMessageSyncState({
|
|
868
|
+
l1BlockNumber: targetL1BlockNumber,
|
|
869
|
+
l1BlockHash: targetL1BlockHash
|
|
870
|
+
}, undefined);
|
|
871
|
+
if (targetL2BlockNumber < currentProvenBlock) {
|
|
872
|
+
this.log.info(`Rolling back proven L2 checkpoint to ${targetCheckpointNumber}`);
|
|
873
|
+
await this.updater.setProvenCheckpointNumber(targetCheckpointNumber);
|
|
874
|
+
}
|
|
875
|
+
const currentFinalizedBlock = currentBlocks.finalized.block.number;
|
|
876
|
+
if (targetL2BlockNumber < currentFinalizedBlock) {
|
|
877
|
+
this.log.info(`Rolling back finalized L2 checkpoint to ${targetCheckpointNumber}`);
|
|
878
|
+
await this.updater.setFinalizedCheckpointNumber(targetCheckpointNumber);
|
|
879
|
+
}
|
|
880
|
+
}
|
|
881
|
+
}
|