@aztec/p2p 0.0.1-commit.fcb71a6 → 0.0.1-commit.fffb133c
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/client/interface.d.ts +18 -5
- package/dest/client/interface.d.ts.map +1 -1
- package/dest/client/p2p_client.d.ts +10 -13
- package/dest/client/p2p_client.d.ts.map +1 -1
- package/dest/client/p2p_client.js +449 -118
- package/dest/config.js +2 -2
- package/dest/mem_pools/attestation_pool/attestation_pool.d.ts +61 -42
- package/dest/mem_pools/attestation_pool/attestation_pool.d.ts.map +1 -1
- package/dest/mem_pools/attestation_pool/attestation_pool_test_suite.d.ts +1 -1
- package/dest/mem_pools/attestation_pool/attestation_pool_test_suite.d.ts.map +1 -1
- package/dest/mem_pools/attestation_pool/attestation_pool_test_suite.js +237 -263
- package/dest/mem_pools/attestation_pool/kv_attestation_pool.d.ts +21 -18
- package/dest/mem_pools/attestation_pool/kv_attestation_pool.d.ts.map +1 -1
- package/dest/mem_pools/attestation_pool/kv_attestation_pool.js +113 -108
- package/dest/mem_pools/attestation_pool/memory_attestation_pool.d.ts +17 -16
- package/dest/mem_pools/attestation_pool/memory_attestation_pool.d.ts.map +1 -1
- package/dest/mem_pools/attestation_pool/memory_attestation_pool.js +89 -128
- package/dest/mem_pools/attestation_pool/mocks.d.ts +9 -6
- package/dest/mem_pools/attestation_pool/mocks.d.ts.map +1 -1
- package/dest/mem_pools/attestation_pool/mocks.js +16 -12
- package/dest/mem_pools/instrumentation.d.ts +1 -1
- package/dest/mem_pools/instrumentation.d.ts.map +1 -1
- package/dest/mem_pools/instrumentation.js +4 -13
- package/dest/mem_pools/tx_pool/aztec_kv_tx_pool.d.ts +15 -10
- package/dest/mem_pools/tx_pool/aztec_kv_tx_pool.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool/aztec_kv_tx_pool.js +91 -50
- package/dest/mem_pools/tx_pool/eviction/eviction_manager.d.ts +19 -5
- package/dest/mem_pools/tx_pool/eviction/eviction_manager.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool/eviction/eviction_manager.js +59 -3
- package/dest/mem_pools/tx_pool/eviction/eviction_strategy.d.ts +79 -5
- package/dest/mem_pools/tx_pool/eviction/eviction_strategy.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool/eviction/eviction_strategy.js +47 -0
- package/dest/mem_pools/tx_pool/eviction/fee_payer_balance_eviction_rule.d.ts +16 -0
- package/dest/mem_pools/tx_pool/eviction/fee_payer_balance_eviction_rule.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool/eviction/fee_payer_balance_eviction_rule.js +122 -0
- package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_mining_rule.d.ts +2 -2
- package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_mining_rule.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_reorg_rule.d.ts +4 -4
- package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_reorg_rule.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_reorg_rule.js +2 -0
- package/dest/mem_pools/tx_pool/eviction/low_priority_eviction_rule.d.ts +2 -2
- package/dest/mem_pools/tx_pool/eviction/low_priority_eviction_rule.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool/eviction/nullifier_conflict_pre_add_rule.d.ts +25 -0
- package/dest/mem_pools/tx_pool/eviction/nullifier_conflict_pre_add_rule.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool/eviction/nullifier_conflict_pre_add_rule.js +57 -0
- package/dest/msg_validators/attestation_validator/attestation_validator.d.ts +4 -4
- package/dest/msg_validators/attestation_validator/attestation_validator.d.ts.map +1 -1
- package/dest/msg_validators/attestation_validator/attestation_validator.js +51 -18
- package/dest/msg_validators/attestation_validator/fisherman_attestation_validator.d.ts +5 -5
- package/dest/msg_validators/attestation_validator/fisherman_attestation_validator.d.ts.map +1 -1
- package/dest/msg_validators/attestation_validator/fisherman_attestation_validator.js +18 -14
- package/dest/msg_validators/clock_tolerance.d.ts +21 -0
- package/dest/msg_validators/clock_tolerance.d.ts.map +1 -0
- package/dest/msg_validators/clock_tolerance.js +37 -0
- package/dest/msg_validators/index.d.ts +2 -2
- package/dest/msg_validators/index.d.ts.map +1 -1
- package/dest/msg_validators/index.js +1 -1
- package/dest/msg_validators/proposal_validator/block_proposal_validator.d.ts +9 -0
- package/dest/msg_validators/proposal_validator/block_proposal_validator.d.ts.map +1 -0
- package/dest/msg_validators/proposal_validator/block_proposal_validator.js +6 -0
- package/dest/msg_validators/proposal_validator/checkpoint_proposal_validator.d.ts +9 -0
- package/dest/msg_validators/proposal_validator/checkpoint_proposal_validator.d.ts.map +1 -0
- package/dest/msg_validators/proposal_validator/checkpoint_proposal_validator.js +6 -0
- package/dest/msg_validators/proposal_validator/index.d.ts +4 -0
- package/dest/msg_validators/proposal_validator/index.d.ts.map +1 -0
- package/dest/msg_validators/proposal_validator/index.js +3 -0
- package/dest/msg_validators/proposal_validator/proposal_validator.d.ts +13 -0
- package/dest/msg_validators/proposal_validator/proposal_validator.d.ts.map +1 -0
- package/dest/msg_validators/proposal_validator/proposal_validator.js +104 -0
- package/dest/msg_validators/proposal_validator/proposal_validator_test_suite.d.ts +23 -0
- package/dest/msg_validators/proposal_validator/proposal_validator_test_suite.d.ts.map +1 -0
- package/dest/msg_validators/proposal_validator/proposal_validator_test_suite.js +212 -0
- package/dest/msg_validators/tx_validator/block_header_validator.d.ts +1 -1
- package/dest/msg_validators/tx_validator/block_header_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/block_header_validator.js +1 -1
- package/dest/msg_validators/tx_validator/data_validator.d.ts +1 -1
- package/dest/msg_validators/tx_validator/data_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/fee_payer_balance.d.ts +10 -0
- package/dest/msg_validators/tx_validator/fee_payer_balance.d.ts.map +1 -0
- package/dest/msg_validators/tx_validator/fee_payer_balance.js +20 -0
- package/dest/msg_validators/tx_validator/gas_validator.d.ts +1 -1
- package/dest/msg_validators/tx_validator/gas_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/gas_validator.js +8 -14
- package/dest/msg_validators/tx_validator/index.d.ts +2 -1
- package/dest/msg_validators/tx_validator/index.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/index.js +1 -0
- package/dest/msg_validators/tx_validator/metadata_validator.d.ts +1 -1
- package/dest/msg_validators/tx_validator/metadata_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/size_validator.d.ts +6 -0
- package/dest/msg_validators/tx_validator/size_validator.d.ts.map +1 -0
- package/dest/msg_validators/tx_validator/size_validator.js +20 -0
- package/dest/msg_validators/tx_validator/timestamp_validator.d.ts +1 -1
- package/dest/msg_validators/tx_validator/timestamp_validator.d.ts.map +1 -1
- package/dest/services/dummy_service.d.ts +6 -2
- package/dest/services/dummy_service.d.ts.map +1 -1
- package/dest/services/dummy_service.js +3 -0
- package/dest/services/encoding.d.ts +1 -1
- package/dest/services/encoding.d.ts.map +1 -1
- package/dest/services/encoding.js +6 -5
- package/dest/services/libp2p/instrumentation.d.ts +1 -1
- package/dest/services/libp2p/instrumentation.d.ts.map +1 -1
- package/dest/services/libp2p/instrumentation.js +20 -73
- package/dest/services/libp2p/libp2p_service.d.ts +28 -11
- package/dest/services/libp2p/libp2p_service.d.ts.map +1 -1
- package/dest/services/libp2p/libp2p_service.js +711 -152
- package/dest/services/peer-manager/metrics.d.ts +1 -1
- package/dest/services/peer-manager/metrics.d.ts.map +1 -1
- package/dest/services/peer-manager/metrics.js +6 -26
- package/dest/services/peer-manager/peer_manager.d.ts +2 -2
- package/dest/services/peer-manager/peer_manager.d.ts.map +1 -1
- package/dest/services/peer-manager/peer_manager.js +0 -10
- package/dest/services/peer-manager/peer_scoring.d.ts +1 -1
- package/dest/services/peer-manager/peer_scoring.d.ts.map +1 -1
- package/dest/services/peer-manager/peer_scoring.js +2 -5
- package/dest/services/reqresp/connection-sampler/connection_sampler.d.ts +1 -1
- package/dest/services/reqresp/connection-sampler/connection_sampler.d.ts.map +1 -1
- package/dest/services/reqresp/constants.d.ts +12 -0
- package/dest/services/reqresp/constants.d.ts.map +1 -0
- package/dest/services/reqresp/constants.js +7 -0
- package/dest/services/reqresp/metrics.d.ts +1 -1
- package/dest/services/reqresp/metrics.d.ts.map +1 -1
- package/dest/services/reqresp/metrics.js +5 -21
- package/dest/services/reqresp/protocols/block_txs/bitvector.d.ts +1 -1
- package/dest/services/reqresp/protocols/block_txs/bitvector.d.ts.map +1 -1
- package/dest/services/reqresp/protocols/block_txs/bitvector.js +7 -0
- package/dest/services/reqresp/protocols/status.d.ts +1 -1
- package/dest/services/reqresp/protocols/status.d.ts.map +1 -1
- package/dest/services/reqresp/protocols/status.js +4 -1
- package/dest/services/reqresp/reqresp.js +402 -24
- package/dest/services/service.d.ts +16 -3
- package/dest/services/service.d.ts.map +1 -1
- package/dest/services/tx_collection/instrumentation.d.ts +1 -1
- package/dest/services/tx_collection/instrumentation.d.ts.map +1 -1
- package/dest/services/tx_collection/instrumentation.js +4 -14
- package/dest/services/tx_collection/slow_tx_collection.d.ts +3 -3
- package/dest/services/tx_collection/slow_tx_collection.d.ts.map +1 -1
- package/dest/services/tx_collection/tx_collection.d.ts +5 -5
- package/dest/services/tx_collection/tx_collection.d.ts.map +1 -1
- package/dest/services/tx_provider.d.ts +3 -3
- package/dest/services/tx_provider.d.ts.map +1 -1
- package/dest/services/tx_provider_instrumentation.d.ts +1 -1
- package/dest/services/tx_provider_instrumentation.d.ts.map +1 -1
- package/dest/services/tx_provider_instrumentation.js +6 -19
- package/dest/testbench/p2p_client_testbench_worker.js +30 -17
- package/dest/testbench/worker_client_manager.d.ts +1 -1
- package/dest/testbench/worker_client_manager.d.ts.map +1 -1
- package/dest/testbench/worker_client_manager.js +6 -1
- package/package.json +16 -16
- package/src/client/interface.ts +19 -4
- package/src/client/p2p_client.ts +82 -132
- package/src/config.ts +2 -2
- package/src/mem_pools/attestation_pool/attestation_pool.ts +68 -41
- package/src/mem_pools/attestation_pool/attestation_pool_test_suite.ts +239 -287
- package/src/mem_pools/attestation_pool/kv_attestation_pool.ts +162 -140
- package/src/mem_pools/attestation_pool/memory_attestation_pool.ts +141 -164
- package/src/mem_pools/attestation_pool/mocks.ts +19 -13
- package/src/mem_pools/instrumentation.ts +9 -18
- package/src/mem_pools/tx_pool/README.md +28 -13
- package/src/mem_pools/tx_pool/aztec_kv_tx_pool.ts +130 -75
- package/src/mem_pools/tx_pool/eviction/eviction_manager.ts +66 -5
- package/src/mem_pools/tx_pool/eviction/eviction_strategy.ts +119 -4
- package/src/mem_pools/tx_pool/eviction/fee_payer_balance_eviction_rule.ts +162 -0
- package/src/mem_pools/tx_pool/eviction/invalid_txs_after_reorg_rule.ts +4 -2
- package/src/mem_pools/tx_pool/eviction/nullifier_conflict_pre_add_rule.ts +75 -0
- package/src/msg_validators/attestation_validator/attestation_validator.ts +36 -21
- package/src/msg_validators/attestation_validator/fisherman_attestation_validator.ts +13 -16
- package/src/msg_validators/clock_tolerance.ts +51 -0
- package/src/msg_validators/index.ts +1 -1
- package/src/msg_validators/proposal_validator/block_proposal_validator.ts +10 -0
- package/src/msg_validators/proposal_validator/checkpoint_proposal_validator.ts +13 -0
- package/src/msg_validators/proposal_validator/index.ts +3 -0
- package/src/msg_validators/proposal_validator/proposal_validator.ts +92 -0
- package/src/msg_validators/proposal_validator/proposal_validator_test_suite.ts +230 -0
- package/src/msg_validators/tx_validator/block_header_validator.ts +3 -1
- package/src/msg_validators/tx_validator/data_validator.ts +12 -4
- package/src/msg_validators/tx_validator/fee_payer_balance.ts +40 -0
- package/src/msg_validators/tx_validator/gas_validator.ts +8 -25
- package/src/msg_validators/tx_validator/index.ts +1 -0
- package/src/msg_validators/tx_validator/metadata_validator.ts +12 -4
- package/src/msg_validators/tx_validator/size_validator.ts +18 -0
- package/src/msg_validators/tx_validator/timestamp_validator.ts +3 -1
- package/src/services/dummy_service.ts +6 -0
- package/src/services/encoding.ts +5 -4
- package/src/services/libp2p/instrumentation.ts +19 -73
- package/src/services/libp2p/libp2p_service.ts +351 -115
- package/src/services/peer-manager/metrics.ts +5 -26
- package/src/services/peer-manager/peer_manager.ts +1 -2
- package/src/services/peer-manager/peer_scoring.ts +1 -5
- package/src/services/reqresp/connection-sampler/connection_sampler.ts +3 -1
- package/src/services/reqresp/constants.ts +14 -0
- package/src/services/reqresp/metrics.ts +7 -23
- package/src/services/reqresp/protocols/block_txs/bitvector.ts +9 -0
- package/src/services/reqresp/protocols/status.ts +7 -4
- package/src/services/service.ts +19 -4
- package/src/services/tx_collection/instrumentation.ts +4 -21
- package/src/services/tx_collection/slow_tx_collection.ts +2 -2
- package/src/services/tx_collection/tx_collection.ts +4 -4
- package/src/services/tx_provider.ts +2 -2
- package/src/services/tx_provider_instrumentation.ts +11 -24
- package/src/testbench/p2p_client_testbench_worker.ts +40 -21
- package/src/testbench/worker_client_manager.ts +6 -1
- package/dest/mem_pools/tx_pool/eviction/insufficient_fee_payer_balance_rule.d.ts +0 -15
- package/dest/mem_pools/tx_pool/eviction/insufficient_fee_payer_balance_rule.d.ts.map +0 -1
- package/dest/mem_pools/tx_pool/eviction/insufficient_fee_payer_balance_rule.js +0 -88
- package/dest/msg_validators/block_proposal_validator/block_proposal_validator.d.ts +0 -12
- package/dest/msg_validators/block_proposal_validator/block_proposal_validator.d.ts.map +0 -1
- package/dest/msg_validators/block_proposal_validator/block_proposal_validator.js +0 -82
- package/dest/msg_validators/block_proposal_validator/index.d.ts +0 -2
- package/dest/msg_validators/block_proposal_validator/index.d.ts.map +0 -1
- package/dest/msg_validators/block_proposal_validator/index.js +0 -1
- package/src/mem_pools/tx_pool/eviction/insufficient_fee_payer_balance_rule.ts +0 -108
- package/src/msg_validators/block_proposal_validator/block_proposal_validator.ts +0 -97
- package/src/msg_validators/block_proposal_validator/index.ts +0 -1
|
@@ -1,21 +1,399 @@
|
|
|
1
|
-
function
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
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);
|
|
6
372
|
}
|
|
7
|
-
|
|
373
|
+
var _dec, _dec1, _initProto;
|
|
374
|
+
import { GENESIS_BLOCK_HEADER_HASH } from '@aztec/constants';
|
|
8
375
|
import { BlockNumber, SlotNumber } from '@aztec/foundation/branded-types';
|
|
9
376
|
import { createLogger } from '@aztec/foundation/log';
|
|
10
377
|
import { DateProvider } from '@aztec/foundation/timer';
|
|
378
|
+
import { L2TipsKVStore } from '@aztec/kv-store/stores';
|
|
379
|
+
import { L2BlockStream } from '@aztec/stdlib/block';
|
|
11
380
|
import { getTimestampForSlot } from '@aztec/stdlib/epoch-helpers';
|
|
12
381
|
import { tryStop } from '@aztec/stdlib/interfaces/server';
|
|
13
|
-
import { Attributes,
|
|
382
|
+
import { Attributes, WithTracer, getTelemetryClient, trackSpan } from '@aztec/telemetry-client';
|
|
14
383
|
import { getP2PDefaultConfig } from '../config.js';
|
|
15
384
|
import { ReqRespSubProtocol } from '../services/reqresp/interface.js';
|
|
16
385
|
import { chunkTxHashesRequest } from '../services/reqresp/protocols/tx.js';
|
|
17
386
|
import { TxProvider } from '../services/tx_provider.js';
|
|
18
387
|
import { P2PClientState } from './interface.js';
|
|
388
|
+
_dec = trackSpan('p2pClient.broadcastProposal', async (proposal)=>({
|
|
389
|
+
[Attributes.SLOT_NUMBER]: proposal.slotNumber,
|
|
390
|
+
[Attributes.BLOCK_ARCHIVE]: proposal.archive.toString(),
|
|
391
|
+
[Attributes.P2P_ID]: (await proposal.p2pMessageLoggingIdentifier()).toString()
|
|
392
|
+
})), _dec1 = trackSpan('p2pClient.broadcastCheckpointProposal', async (proposal)=>({
|
|
393
|
+
[Attributes.SLOT_NUMBER]: proposal.slotNumber,
|
|
394
|
+
[Attributes.BLOCK_ARCHIVE]: proposal.archive.toString(),
|
|
395
|
+
[Attributes.P2P_ID]: (await proposal.p2pMessageLoggingIdentifier()).toString()
|
|
396
|
+
}));
|
|
19
397
|
/**
|
|
20
398
|
* The P2P client implementation.
|
|
21
399
|
*/ export class P2PClient extends WithTracer {
|
|
@@ -26,6 +404,20 @@ import { P2PClientState } from './interface.js';
|
|
|
26
404
|
_dateProvider;
|
|
27
405
|
telemetry;
|
|
28
406
|
log;
|
|
407
|
+
static{
|
|
408
|
+
({ e: [_initProto] } = _apply_decs_2203_r(this, [
|
|
409
|
+
[
|
|
410
|
+
_dec,
|
|
411
|
+
2,
|
|
412
|
+
"broadcastProposal"
|
|
413
|
+
],
|
|
414
|
+
[
|
|
415
|
+
_dec1,
|
|
416
|
+
2,
|
|
417
|
+
"broadcastCheckpointProposal"
|
|
418
|
+
]
|
|
419
|
+
], []));
|
|
420
|
+
}
|
|
29
421
|
/** The JS promise that will be running to keep the client's data in sync. Can be interrupted if the client is stopped. */ runningPromise;
|
|
30
422
|
currentState;
|
|
31
423
|
syncPromise;
|
|
@@ -33,10 +425,7 @@ import { P2PClientState } from './interface.js';
|
|
|
33
425
|
latestBlockNumberAtStart;
|
|
34
426
|
provenBlockNumberAtStart;
|
|
35
427
|
finalizedBlockNumberAtStart;
|
|
36
|
-
|
|
37
|
-
synchedLatestBlockNumber;
|
|
38
|
-
synchedProvenBlockNumber;
|
|
39
|
-
synchedFinalizedBlockNumber;
|
|
428
|
+
l2Tips;
|
|
40
429
|
synchedLatestSlot;
|
|
41
430
|
txPool;
|
|
42
431
|
attestationPool;
|
|
@@ -52,7 +441,7 @@ import { P2PClientState } from './interface.js';
|
|
|
52
441
|
* @param p2pService - The concrete instance of p2p networking to use.
|
|
53
442
|
* @param log - A logger.
|
|
54
443
|
*/ constructor(_clientType, store, l2BlockSource, mempools, p2pService, txCollection, config = {}, _dateProvider = new DateProvider(), telemetry = getTelemetryClient(), log = createLogger('p2p')){
|
|
55
|
-
super(telemetry, 'P2PClient'), this.store = store, this.l2BlockSource = l2BlockSource, this.p2pService = p2pService, this.txCollection = txCollection, this._dateProvider = _dateProvider, this.telemetry = telemetry, this.log = log, this.currentState = P2PClientState.IDLE, this.syncPromise = Promise.resolve(), this.syncResolve = undefined, this.latestBlockNumberAtStart = -1, this.provenBlockNumberAtStart = -1, this.finalizedBlockNumberAtStart = -1, this.validatorAddresses = [];
|
|
444
|
+
super(telemetry, 'P2PClient'), this.store = store, this.l2BlockSource = l2BlockSource, this.p2pService = p2pService, this.txCollection = txCollection, this._dateProvider = _dateProvider, this.telemetry = telemetry, this.log = log, this.currentState = (_initProto(this), P2PClientState.IDLE), this.syncPromise = Promise.resolve(), this.syncResolve = undefined, this.latestBlockNumberAtStart = -1, this.provenBlockNumberAtStart = -1, this.finalizedBlockNumberAtStart = -1, this.validatorAddresses = [];
|
|
56
445
|
this.config = {
|
|
57
446
|
...getP2PDefaultConfig(),
|
|
58
447
|
...config
|
|
@@ -61,7 +450,8 @@ import { P2PClientState } from './interface.js';
|
|
|
61
450
|
this.attestationPool = mempools.attestationPool;
|
|
62
451
|
this.txProvider = new TxProvider(this.txCollection, this.txPool, this, this.log.createChild('tx-provider'), this.telemetry);
|
|
63
452
|
// Default to collecting all txs when we see a valid proposal
|
|
64
|
-
// This can be overridden by the validator client to
|
|
453
|
+
// This can be overridden by the validator client to validate, and it will call getTxsForBlockProposal on its own
|
|
454
|
+
// Note: Validators do NOT attest to individual blocks - attestations are only for checkpoint proposals.
|
|
65
455
|
// TODO(palla/txs): We should not trigger a request for txs on a proposal before fully validating it. We need to bring
|
|
66
456
|
// validator-client code into here so we can validate a proposal is reasonable.
|
|
67
457
|
this.registerBlockProposalHandler(async (block, sender)=>{
|
|
@@ -70,23 +460,19 @@ import { P2PClientState } from './interface.js';
|
|
|
70
460
|
const constants = this.txCollection.getConstants();
|
|
71
461
|
const nextSlotTimestampSeconds = Number(getTimestampForSlot(SlotNumber(block.slotNumber + 1), constants));
|
|
72
462
|
const deadline = new Date(nextSlotTimestampSeconds * 1000);
|
|
73
|
-
const parentBlock = await this.l2BlockSource.getBlockHeaderByArchive(block.
|
|
463
|
+
const parentBlock = await this.l2BlockSource.getBlockHeaderByArchive(block.blockHeader.lastArchive.root);
|
|
74
464
|
if (!parentBlock) {
|
|
75
465
|
this.log.debug(`Cannot collect txs for proposal as parent block not found`);
|
|
76
|
-
return;
|
|
466
|
+
return false;
|
|
77
467
|
}
|
|
78
468
|
const blockNumber = BlockNumber(parentBlock.getBlockNumber() + 1);
|
|
79
469
|
await this.txProvider.getTxsForBlockProposal(block, blockNumber, {
|
|
80
470
|
pinnedPeer: sender,
|
|
81
471
|
deadline
|
|
82
472
|
});
|
|
83
|
-
return
|
|
473
|
+
return true;
|
|
84
474
|
});
|
|
85
|
-
|
|
86
|
-
this.synchedBlockHashes = store.openMap('p2p_pool_block_hashes');
|
|
87
|
-
this.synchedLatestBlockNumber = store.openSingleton('p2p_pool_last_l2_block');
|
|
88
|
-
this.synchedProvenBlockNumber = store.openSingleton('p2p_pool_last_proven_l2_block');
|
|
89
|
-
this.synchedFinalizedBlockNumber = store.openSingleton('p2p_pool_last_finalized_l2_block');
|
|
475
|
+
this.l2Tips = new L2TipsKVStore(store, 'p2p_client');
|
|
90
476
|
this.synchedLatestSlot = store.openSingleton('p2p_pool_last_l2_slot');
|
|
91
477
|
}
|
|
92
478
|
registerThisValidatorAddresses(addresses) {
|
|
@@ -108,95 +494,51 @@ import { P2PClientState } from './interface.js';
|
|
|
108
494
|
return Promise.resolve(this.p2pService.getPeers(includePending));
|
|
109
495
|
}
|
|
110
496
|
getL2BlockHash(number) {
|
|
111
|
-
return this.
|
|
497
|
+
return this.l2Tips.getL2BlockHash(number);
|
|
112
498
|
}
|
|
113
499
|
updateP2PConfig(config) {
|
|
114
500
|
this.txPool.updateConfig(config);
|
|
115
501
|
this.p2pService.updateConfig(config);
|
|
116
502
|
return Promise.resolve();
|
|
117
503
|
}
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
let latestBlockHash;
|
|
121
|
-
const provenBlockNumber = await this.getSyncedProvenBlockNum();
|
|
122
|
-
let provenBlockHash;
|
|
123
|
-
const finalizedBlockNumber = await this.getSyncedFinalizedBlockNum();
|
|
124
|
-
let finalizedBlockHash;
|
|
125
|
-
if (latestBlockNumber > 0) {
|
|
126
|
-
latestBlockHash = await this.synchedBlockHashes.getAsync(latestBlockNumber);
|
|
127
|
-
if (typeof latestBlockHash === 'undefined') {
|
|
128
|
-
throw new Error(`Block hash for latest block ${latestBlockNumber} not found in p2p client`);
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
if (provenBlockNumber > 0) {
|
|
132
|
-
provenBlockHash = await this.synchedBlockHashes.getAsync(provenBlockNumber);
|
|
133
|
-
if (typeof provenBlockHash === 'undefined') {
|
|
134
|
-
throw new Error(`Block hash for proven block ${provenBlockNumber} not found in p2p client`);
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
if (finalizedBlockNumber > 0) {
|
|
138
|
-
finalizedBlockHash = await this.synchedBlockHashes.getAsync(finalizedBlockNumber);
|
|
139
|
-
if (typeof finalizedBlockHash === 'undefined') {
|
|
140
|
-
throw new Error(`Block hash for finalized block ${finalizedBlockNumber} not found in p2p client`);
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
const genesisHash = GENESIS_BLOCK_HEADER_HASH.toString();
|
|
144
|
-
return {
|
|
145
|
-
latest: {
|
|
146
|
-
hash: latestBlockHash ?? genesisHash,
|
|
147
|
-
number: latestBlockNumber
|
|
148
|
-
},
|
|
149
|
-
proven: {
|
|
150
|
-
hash: provenBlockHash ?? genesisHash,
|
|
151
|
-
number: provenBlockNumber
|
|
152
|
-
},
|
|
153
|
-
finalized: {
|
|
154
|
-
hash: finalizedBlockHash ?? genesisHash,
|
|
155
|
-
number: finalizedBlockNumber
|
|
156
|
-
}
|
|
157
|
-
};
|
|
504
|
+
getL2Tips() {
|
|
505
|
+
return this.l2Tips.getL2Tips();
|
|
158
506
|
}
|
|
159
507
|
async handleBlockStreamEvent(event) {
|
|
160
508
|
this.log.debug(`Handling block stream event ${event.type}`);
|
|
161
509
|
switch(event.type){
|
|
162
510
|
case 'blocks-added':
|
|
163
|
-
await this.handleLatestL2Blocks(event.blocks
|
|
511
|
+
await this.handleLatestL2Blocks(event.blocks);
|
|
164
512
|
break;
|
|
165
513
|
case 'chain-finalized':
|
|
166
514
|
{
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
const from = BlockNumber(await this.getSyncedFinalizedBlockNum() + 1);
|
|
515
|
+
const oldFinalizedBlockNum = await this.getSyncedFinalizedBlockNum();
|
|
516
|
+
const from = BlockNumber(oldFinalizedBlockNum + 1);
|
|
170
517
|
const limit = event.block.number - from + 1;
|
|
171
518
|
if (limit > 0) {
|
|
172
519
|
const oldBlocks = await this.l2BlockSource.getBlocks(from, limit);
|
|
173
|
-
await this.handleFinalizedL2Blocks(oldBlocks
|
|
520
|
+
await this.handleFinalizedL2Blocks(oldBlocks);
|
|
174
521
|
}
|
|
175
522
|
break;
|
|
176
523
|
}
|
|
177
524
|
case 'chain-proven':
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
this.txCollection.stopCollectingForBlocksUpTo(event.block.number);
|
|
181
|
-
await this.synchedProvenBlockNumber.set(event.block.number);
|
|
182
|
-
break;
|
|
183
|
-
}
|
|
525
|
+
this.txCollection.stopCollectingForBlocksUpTo(event.block.number);
|
|
526
|
+
break;
|
|
184
527
|
case 'chain-pruned':
|
|
185
|
-
await this.setBlockHash(event.block);
|
|
186
528
|
this.txCollection.stopCollectingForBlocksAfter(event.block.number);
|
|
187
529
|
await this.handlePruneL2Blocks(event.block.number);
|
|
188
530
|
break;
|
|
531
|
+
case 'chain-checkpointed':
|
|
532
|
+
break;
|
|
189
533
|
default:
|
|
190
534
|
{
|
|
191
535
|
const _ = event;
|
|
192
536
|
break;
|
|
193
537
|
}
|
|
194
538
|
}
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
await this.synchedBlockHashes.set(block.number, block.hash.toString());
|
|
199
|
-
}
|
|
539
|
+
// Pass the event through to our l2 tips store
|
|
540
|
+
await this.l2Tips.handleBlockStreamEvent(event);
|
|
541
|
+
await this.startServiceIfSynched();
|
|
200
542
|
}
|
|
201
543
|
#assertIsReady() {
|
|
202
544
|
// this.log.info('Checking if p2p client is ready, current state: ', this.currentState);
|
|
@@ -216,9 +558,9 @@ import { P2PClientState } from './interface.js';
|
|
|
216
558
|
}
|
|
217
559
|
// get the current latest block numbers
|
|
218
560
|
const latestBlockNumbers = await this.l2BlockSource.getL2Tips();
|
|
219
|
-
this.latestBlockNumberAtStart = latestBlockNumbers.
|
|
220
|
-
this.provenBlockNumberAtStart = latestBlockNumbers.proven.number;
|
|
221
|
-
this.finalizedBlockNumberAtStart = latestBlockNumbers.finalized.number;
|
|
561
|
+
this.latestBlockNumberAtStart = latestBlockNumbers.proposed.number;
|
|
562
|
+
this.provenBlockNumberAtStart = latestBlockNumbers.proven.block.number;
|
|
563
|
+
this.finalizedBlockNumberAtStart = latestBlockNumbers.finalized.block.number;
|
|
222
564
|
const syncedLatestBlock = await this.getSyncedLatestBlockNum() + 1;
|
|
223
565
|
const syncedProvenBlock = await this.getSyncedProvenBlockNum() + 1;
|
|
224
566
|
const syncedFinalizedBlock = await this.getSyncedFinalizedBlockNum() + 1;
|
|
@@ -264,7 +606,7 @@ import { P2PClientState } from './interface.js';
|
|
|
264
606
|
initBlockStream(startingBlock) {
|
|
265
607
|
if (!this.blockStream) {
|
|
266
608
|
const { blockRequestBatchSize: batchSize, blockCheckIntervalMS: pollIntervalMS } = this.config;
|
|
267
|
-
this.blockStream = new
|
|
609
|
+
this.blockStream = new L2BlockStream(this.l2BlockSource, this, this, createLogger(`${this.log.module}:l2-block-stream`), {
|
|
268
610
|
batchSize,
|
|
269
611
|
pollIntervalMS,
|
|
270
612
|
startingBlock
|
|
@@ -294,26 +636,28 @@ import { P2PClientState } from './interface.js';
|
|
|
294
636
|
this.log.verbose(`Broadcasting proposal for slot ${proposal.slotNumber} to peers`);
|
|
295
637
|
return this.p2pService.propagate(proposal);
|
|
296
638
|
}
|
|
297
|
-
|
|
298
|
-
this.log.verbose(`Broadcasting ${
|
|
299
|
-
|
|
639
|
+
broadcastCheckpointProposal(proposal) {
|
|
640
|
+
this.log.verbose(`Broadcasting checkpoint proposal for slot ${proposal.slotNumber} to peers`);
|
|
641
|
+
return this.p2pService.propagate(proposal);
|
|
300
642
|
}
|
|
301
|
-
async
|
|
302
|
-
|
|
643
|
+
async broadcastCheckpointAttestations(attestations) {
|
|
644
|
+
this.log.verbose(`Broadcasting ${attestations.length} checkpoint attestations to peers`);
|
|
645
|
+
await Promise.all(attestations.map((att)=>this.p2pService.propagate(att)));
|
|
303
646
|
}
|
|
304
|
-
|
|
305
|
-
return this.attestationPool.
|
|
647
|
+
async getCheckpointAttestationsForSlot(slot, proposalId) {
|
|
648
|
+
return await (proposalId ? this.attestationPool.getCheckpointAttestationsForSlotAndProposal(slot, proposalId) : this.attestationPool.getCheckpointAttestationsForSlot(slot));
|
|
306
649
|
}
|
|
307
|
-
|
|
308
|
-
return this.attestationPool.
|
|
309
|
-
attestation
|
|
310
|
-
]);
|
|
650
|
+
addCheckpointAttestations(attestations) {
|
|
651
|
+
return this.attestationPool.addCheckpointAttestations(attestations);
|
|
311
652
|
}
|
|
312
653
|
// REVIEW: https://github.com/AztecProtocol/aztec-packages/issues/7963
|
|
313
654
|
// ^ This pattern is not my favorite (md)
|
|
314
655
|
registerBlockProposalHandler(handler) {
|
|
315
656
|
this.p2pService.registerBlockReceivedCallback(handler);
|
|
316
657
|
}
|
|
658
|
+
registerCheckpointProposalHandler(handler) {
|
|
659
|
+
this.p2pService.registerCheckpointReceivedCallback(handler);
|
|
660
|
+
}
|
|
317
661
|
/**
|
|
318
662
|
* Uses the batched Request Response protocol to request a set of transactions from the network.
|
|
319
663
|
*/ async requestTxsByHash(txHashes, pinnedPeerId) {
|
|
@@ -504,16 +848,19 @@ import { P2PClientState } from './interface.js';
|
|
|
504
848
|
* Public function to check the latest block number that the P2P client is synced to.
|
|
505
849
|
* @returns Block number of latest L2 Block we've synced with.
|
|
506
850
|
*/ async getSyncedLatestBlockNum() {
|
|
507
|
-
|
|
851
|
+
const tips = await this.l2Tips.getL2Tips();
|
|
852
|
+
return tips.proposed.number;
|
|
508
853
|
}
|
|
509
854
|
/**
|
|
510
855
|
* Public function to check the latest proven block number that the P2P client is synced to.
|
|
511
856
|
* @returns Block number of latest proven L2 Block we've synced with.
|
|
512
857
|
*/ async getSyncedProvenBlockNum() {
|
|
513
|
-
|
|
858
|
+
const tips = await this.l2Tips.getL2Tips();
|
|
859
|
+
return tips.proven.block.number;
|
|
514
860
|
}
|
|
515
861
|
async getSyncedFinalizedBlockNum() {
|
|
516
|
-
|
|
862
|
+
const tips = await this.l2Tips.getL2Tips();
|
|
863
|
+
return tips.finalized.block.number;
|
|
517
864
|
}
|
|
518
865
|
/** Returns latest L2 slot for which we have seen an L2 block. */ async getSyncedLatestSlot() {
|
|
519
866
|
return await this.synchedLatestSlot.getAsync() ?? BigInt(0);
|
|
@@ -554,14 +901,8 @@ import { P2PClientState } from './interface.js';
|
|
|
554
901
|
await this.txPool.clearNonEvictableTxs();
|
|
555
902
|
await this.startCollectingMissingTxs(blocks);
|
|
556
903
|
const lastBlock = blocks.at(-1);
|
|
557
|
-
await Promise.all(blocks.map(async (block)=>this.setBlockHash({
|
|
558
|
-
number: block.number,
|
|
559
|
-
hash: await block.hash().then((h)=>h.toString())
|
|
560
|
-
})));
|
|
561
|
-
await this.synchedLatestBlockNumber.set(lastBlock.number);
|
|
562
904
|
await this.synchedLatestSlot.set(BigInt(lastBlock.header.getSlot()));
|
|
563
905
|
this.log.verbose(`Synched to latest block ${lastBlock.number}`);
|
|
564
|
-
await this.startServiceIfSynched();
|
|
565
906
|
}
|
|
566
907
|
/** Request txs for unproven blocks so the prover node has more chances to get them. */ async startCollectingMissingTxs(blocks) {
|
|
567
908
|
try {
|
|
@@ -606,10 +947,8 @@ import { P2PClientState } from './interface.js';
|
|
|
606
947
|
permanently: true
|
|
607
948
|
});
|
|
608
949
|
await this.txPool.cleanupDeletedMinedTxs(lastBlockNum);
|
|
609
|
-
await this.attestationPool.
|
|
610
|
-
await this.synchedFinalizedBlockNumber.set(lastBlockNum);
|
|
950
|
+
await this.attestationPool.deleteCheckpointAttestationsOlderThan(lastBlockSlot);
|
|
611
951
|
this.log.debug(`Synched to finalized block ${lastBlockNum} at slot ${lastBlockSlot}`);
|
|
612
|
-
await this.startServiceIfSynched();
|
|
613
952
|
}
|
|
614
953
|
/**
|
|
615
954
|
* Updates the tx pool after a chain prune.
|
|
@@ -650,16 +989,15 @@ import { P2PClientState } from './interface.js';
|
|
|
650
989
|
} else {
|
|
651
990
|
await this.txPool.markMinedAsPending(minedTxsFromReorg, latestBlock);
|
|
652
991
|
}
|
|
653
|
-
await this.synchedLatestBlockNumber.set(latestBlock);
|
|
654
|
-
// no need to update block hashes, as they will be updated as new blocks are added
|
|
655
992
|
}
|
|
656
993
|
async startServiceIfSynched() {
|
|
657
994
|
if (this.currentState !== P2PClientState.SYNCHING) {
|
|
658
995
|
return;
|
|
659
996
|
}
|
|
660
|
-
const
|
|
661
|
-
const
|
|
662
|
-
const
|
|
997
|
+
const tips = await this.l2Tips.getL2Tips();
|
|
998
|
+
const syncedFinalizedBlock = tips.finalized.block.number;
|
|
999
|
+
const syncedProvenBlock = tips.proven.block.number;
|
|
1000
|
+
const syncedLatestBlock = tips.proposed.number;
|
|
663
1001
|
if (syncedLatestBlock >= this.latestBlockNumberAtStart && syncedProvenBlock >= this.provenBlockNumberAtStart && syncedFinalizedBlock >= this.finalizedBlockNumberAtStart) {
|
|
664
1002
|
this.log.info(`Completed P2P client sync to block ${syncedLatestBlock}. Starting service.`, {
|
|
665
1003
|
syncedLatestBlock,
|
|
@@ -694,10 +1032,3 @@ import { P2PClientState } from './interface.js';
|
|
|
694
1032
|
return this.p2pService.handleAuthRequestFromPeer(authRequest, peerId);
|
|
695
1033
|
}
|
|
696
1034
|
}
|
|
697
|
-
_ts_decorate([
|
|
698
|
-
trackSpan('p2pClient.broadcastProposal', async (proposal)=>({
|
|
699
|
-
[Attributes.SLOT_NUMBER]: proposal.slotNumber,
|
|
700
|
-
[Attributes.BLOCK_ARCHIVE]: proposal.archive.toString(),
|
|
701
|
-
[Attributes.P2P_ID]: (await proposal.p2pMessageLoggingIdentifier()).toString()
|
|
702
|
-
}))
|
|
703
|
-
], P2PClient.prototype, "broadcastProposal", null);
|