@aztec/p2p 0.0.1-commit.43597cc1 → 0.0.1-commit.4ad48494d
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/factory.d.ts +3 -3
- package/dest/client/factory.d.ts.map +1 -1
- package/dest/client/factory.js +42 -8
- package/dest/client/interface.d.ts +30 -15
- package/dest/client/interface.d.ts.map +1 -1
- package/dest/client/p2p_client.d.ts +33 -35
- package/dest/client/p2p_client.d.ts.map +1 -1
- package/dest/client/p2p_client.js +107 -137
- package/dest/config.d.ts +19 -2
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +14 -0
- package/dest/index.d.ts +2 -1
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +1 -0
- package/dest/mem_pools/attestation_pool/attestation_pool.d.ts +21 -12
- package/dest/mem_pools/attestation_pool/attestation_pool.d.ts.map +1 -1
- package/dest/mem_pools/attestation_pool/attestation_pool.js +67 -37
- 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 +53 -53
- package/dest/mem_pools/attestation_pool/index.d.ts +2 -2
- package/dest/mem_pools/attestation_pool/index.d.ts.map +1 -1
- package/dest/mem_pools/attestation_pool/index.js +1 -1
- package/dest/mem_pools/index.d.ts +2 -1
- package/dest/mem_pools/index.d.ts.map +1 -1
- package/dest/mem_pools/interface.d.ts +3 -3
- package/dest/mem_pools/interface.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool_v2/deleted_pool.d.ts +102 -0
- package/dest/mem_pools/tx_pool_v2/deleted_pool.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool_v2/deleted_pool.js +242 -0
- package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_eviction_rule.d.ts +1 -1
- package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_eviction_rule.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_eviction_rule.js +3 -0
- package/dest/mem_pools/tx_pool_v2/eviction/invalid_txs_after_mining_rule.js +3 -1
- package/dest/mem_pools/tx_pool_v2/eviction/invalid_txs_after_reorg_rule.js +3 -1
- package/dest/mem_pools/tx_pool_v2/eviction/low_priority_eviction_rule.d.ts +1 -1
- package/dest/mem_pools/tx_pool_v2/eviction/low_priority_eviction_rule.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool_v2/eviction/low_priority_eviction_rule.js +3 -1
- package/dest/mem_pools/tx_pool_v2/index.d.ts +2 -1
- package/dest/mem_pools/tx_pool_v2/index.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool_v2/index.js +1 -0
- package/dest/mem_pools/tx_pool_v2/interfaces.d.ts +7 -3
- package/dest/mem_pools/tx_pool_v2/interfaces.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool_v2/interfaces.js +2 -1
- package/dest/mem_pools/tx_pool_v2/tx_metadata.d.ts +27 -3
- package/dest/mem_pools/tx_pool_v2/tx_metadata.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool_v2/tx_metadata.js +37 -4
- package/dest/mem_pools/tx_pool_v2/tx_pool_indices.d.ts +8 -2
- package/dest/mem_pools/tx_pool_v2/tx_pool_indices.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool_v2/tx_pool_indices.js +15 -2
- package/dest/mem_pools/tx_pool_v2/tx_pool_v2.d.ts +4 -2
- package/dest/mem_pools/tx_pool_v2/tx_pool_v2.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool_v2/tx_pool_v2.js +6 -2
- package/dest/mem_pools/tx_pool_v2/tx_pool_v2_impl.d.ts +4 -2
- package/dest/mem_pools/tx_pool_v2/tx_pool_v2_impl.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool_v2/tx_pool_v2_impl.js +110 -78
- package/dest/msg_validators/tx_validator/aggregate_tx_validator.d.ts +3 -3
- package/dest/msg_validators/tx_validator/aggregate_tx_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/block_header_validator.d.ts +16 -3
- 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/double_spend_validator.d.ts +13 -3
- package/dest/msg_validators/tx_validator/double_spend_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/double_spend_validator.js +4 -4
- package/dest/msg_validators/tx_validator/timestamp_validator.d.ts +20 -4
- package/dest/msg_validators/tx_validator/timestamp_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/timestamp_validator.js +2 -2
- 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 +2 -2
- package/dest/services/encoding.d.ts.map +1 -1
- package/dest/services/encoding.js +2 -2
- package/dest/services/libp2p/libp2p_service.d.ts +11 -3
- package/dest/services/libp2p/libp2p_service.d.ts.map +1 -1
- package/dest/services/libp2p/libp2p_service.js +71 -35
- package/dest/services/reqresp/interface.d.ts +10 -1
- package/dest/services/reqresp/interface.d.ts.map +1 -1
- package/dest/services/reqresp/interface.js +15 -1
- package/dest/services/reqresp/protocols/block_txs/block_txs_handler.d.ts +3 -3
- package/dest/services/reqresp/protocols/block_txs/block_txs_handler.d.ts.map +1 -1
- package/dest/services/reqresp/protocols/block_txs/block_txs_reqresp.d.ts +7 -1
- package/dest/services/reqresp/protocols/block_txs/block_txs_reqresp.d.ts.map +1 -1
- package/dest/services/reqresp/protocols/block_txs/block_txs_reqresp.js +15 -0
- package/dest/services/reqresp/protocols/tx.d.ts +7 -1
- package/dest/services/reqresp/protocols/tx.d.ts.map +1 -1
- package/dest/services/reqresp/protocols/tx.js +20 -0
- package/dest/services/reqresp/reqresp.d.ts +1 -1
- package/dest/services/reqresp/reqresp.d.ts.map +1 -1
- package/dest/services/reqresp/reqresp.js +11 -4
- package/dest/services/service.d.ts +18 -1
- package/dest/services/service.d.ts.map +1 -1
- package/dest/services/tx_collection/config.d.ts +19 -1
- package/dest/services/tx_collection/config.d.ts.map +1 -1
- package/dest/services/tx_collection/config.js +46 -0
- package/dest/services/tx_collection/fast_tx_collection.d.ts +3 -1
- package/dest/services/tx_collection/fast_tx_collection.d.ts.map +1 -1
- package/dest/services/tx_collection/fast_tx_collection.js +17 -3
- package/dest/services/tx_collection/file_store_tx_collection.d.ts +53 -0
- package/dest/services/tx_collection/file_store_tx_collection.d.ts.map +1 -0
- package/dest/services/tx_collection/file_store_tx_collection.js +165 -0
- package/dest/services/tx_collection/file_store_tx_source.d.ts +28 -0
- package/dest/services/tx_collection/file_store_tx_source.d.ts.map +1 -0
- package/dest/services/tx_collection/file_store_tx_source.js +59 -0
- package/dest/services/tx_collection/index.d.ts +2 -1
- package/dest/services/tx_collection/index.d.ts.map +1 -1
- package/dest/services/tx_collection/index.js +1 -0
- package/dest/services/tx_collection/slow_tx_collection.d.ts +6 -2
- package/dest/services/tx_collection/slow_tx_collection.d.ts.map +1 -1
- package/dest/services/tx_collection/slow_tx_collection.js +55 -23
- package/dest/services/tx_collection/tx_collection.d.ts +19 -7
- package/dest/services/tx_collection/tx_collection.d.ts.map +1 -1
- package/dest/services/tx_collection/tx_collection.js +75 -3
- package/dest/services/tx_collection/tx_collection_sink.d.ts +15 -6
- package/dest/services/tx_collection/tx_collection_sink.d.ts.map +1 -1
- package/dest/services/tx_collection/tx_collection_sink.js +13 -7
- package/dest/services/tx_file_store/config.d.ts +1 -3
- package/dest/services/tx_file_store/config.d.ts.map +1 -1
- package/dest/services/tx_file_store/config.js +0 -4
- package/dest/services/tx_file_store/tx_file_store.d.ts +4 -3
- package/dest/services/tx_file_store/tx_file_store.d.ts.map +1 -1
- package/dest/services/tx_file_store/tx_file_store.js +8 -5
- package/dest/services/tx_provider.d.ts +3 -3
- package/dest/services/tx_provider.d.ts.map +1 -1
- package/dest/services/tx_provider.js +5 -4
- package/dest/test-helpers/make-test-p2p-clients.d.ts +3 -3
- package/dest/test-helpers/make-test-p2p-clients.d.ts.map +1 -1
- package/dest/test-helpers/mock-pubsub.d.ts +27 -1
- package/dest/test-helpers/mock-pubsub.d.ts.map +1 -1
- package/dest/test-helpers/mock-pubsub.js +97 -2
- package/dest/test-helpers/testbench-utils.d.ts +32 -24
- package/dest/test-helpers/testbench-utils.d.ts.map +1 -1
- package/dest/test-helpers/testbench-utils.js +93 -35
- package/dest/testbench/p2p_client_testbench_worker.js +1 -1
- package/package.json +14 -14
- package/src/client/factory.ts +78 -9
- package/src/client/interface.ts +32 -13
- package/src/client/p2p_client.ts +135 -157
- package/src/config.ts +24 -0
- package/src/index.ts +1 -0
- package/src/mem_pools/attestation_pool/attestation_pool.ts +95 -44
- package/src/mem_pools/attestation_pool/attestation_pool_test_suite.ts +57 -53
- package/src/mem_pools/attestation_pool/index.ts +3 -3
- package/src/mem_pools/index.ts +3 -0
- package/src/mem_pools/interface.ts +2 -2
- package/src/mem_pools/tx_pool_v2/README.md +75 -9
- package/src/mem_pools/tx_pool_v2/deleted_pool.ts +310 -0
- package/src/mem_pools/tx_pool_v2/eviction/fee_payer_balance_eviction_rule.ts +3 -0
- package/src/mem_pools/tx_pool_v2/eviction/invalid_txs_after_mining_rule.ts +1 -1
- package/src/mem_pools/tx_pool_v2/eviction/invalid_txs_after_reorg_rule.ts +1 -1
- package/src/mem_pools/tx_pool_v2/eviction/low_priority_eviction_rule.ts +3 -1
- package/src/mem_pools/tx_pool_v2/index.ts +1 -0
- package/src/mem_pools/tx_pool_v2/interfaces.ts +8 -2
- package/src/mem_pools/tx_pool_v2/tx_metadata.ts +55 -5
- package/src/mem_pools/tx_pool_v2/tx_pool_indices.ts +18 -2
- package/src/mem_pools/tx_pool_v2/tx_pool_v2.ts +7 -1
- package/src/mem_pools/tx_pool_v2/tx_pool_v2_impl.ts +122 -80
- package/src/msg_validators/tx_validator/aggregate_tx_validator.ts +2 -2
- package/src/msg_validators/tx_validator/block_header_validator.ts +15 -3
- package/src/msg_validators/tx_validator/double_spend_validator.ts +11 -6
- package/src/msg_validators/tx_validator/timestamp_validator.ts +19 -14
- package/src/services/dummy_service.ts +6 -0
- package/src/services/encoding.ts +2 -2
- package/src/services/libp2p/libp2p_service.ts +70 -37
- package/src/services/reqresp/interface.ts +26 -1
- package/src/services/reqresp/protocols/block_txs/block_txs_handler.ts +2 -2
- package/src/services/reqresp/protocols/block_txs/block_txs_reqresp.ts +17 -0
- package/src/services/reqresp/protocols/tx.ts +22 -0
- package/src/services/reqresp/reqresp.ts +13 -3
- package/src/services/service.ts +20 -0
- package/src/services/tx_collection/config.ts +68 -0
- package/src/services/tx_collection/fast_tx_collection.ts +14 -2
- package/src/services/tx_collection/file_store_tx_collection.ts +198 -0
- package/src/services/tx_collection/file_store_tx_source.ts +73 -0
- package/src/services/tx_collection/index.ts +1 -0
- package/src/services/tx_collection/slow_tx_collection.ts +64 -30
- package/src/services/tx_collection/tx_collection.ts +109 -13
- package/src/services/tx_collection/tx_collection_sink.ts +17 -7
- package/src/services/tx_file_store/config.ts +0 -6
- package/src/services/tx_file_store/tx_file_store.ts +9 -7
- package/src/services/tx_provider.ts +8 -7
- package/src/test-helpers/make-test-p2p-clients.ts +3 -3
- package/src/test-helpers/mock-pubsub.ts +133 -3
- package/src/test-helpers/testbench-utils.ts +108 -40
- package/src/testbench/p2p_client_testbench_worker.ts +1 -1
|
@@ -5,6 +5,7 @@ import { RateLimitStatus } from '../services/reqresp/rate-limiter/rate_limiter.j
|
|
|
5
5
|
/**
|
|
6
6
|
* In-memory TxPool implementation for testing.
|
|
7
7
|
* Provides basic tx storage without persistence.
|
|
8
|
+
* Implements TxPoolV2 interface with stub implementations for testing.
|
|
8
9
|
*/ export class InMemoryTxPool extends EventEmitter {
|
|
9
10
|
txsByHash = new Map();
|
|
10
11
|
logger = null;
|
|
@@ -33,14 +34,15 @@ import { RateLimitStatus } from '../services/reqresp/rate-limiter/rate_limiter.j
|
|
|
33
34
|
this.txsByHash.clear();
|
|
34
35
|
this.removeAllListeners();
|
|
35
36
|
}
|
|
36
|
-
|
|
37
|
+
// === Core Operations (TxPoolV2) ===
|
|
38
|
+
addPendingTxs(txs, opts) {
|
|
39
|
+
const accepted = [];
|
|
37
40
|
const newTxs = [];
|
|
38
|
-
let added = 0;
|
|
39
41
|
for (const tx of txs){
|
|
40
42
|
const key = tx.getTxHash().toString();
|
|
41
43
|
if (!this.txsByHash.has(key)) {
|
|
42
44
|
newTxs.push(tx);
|
|
43
|
-
|
|
45
|
+
accepted.push(tx.getTxHash());
|
|
44
46
|
}
|
|
45
47
|
this.txsByHash.set(key, tx);
|
|
46
48
|
}
|
|
@@ -50,8 +52,68 @@ import { RateLimitStatus } from '../services/reqresp/rate-limiter/rate_limiter.j
|
|
|
50
52
|
source: opts?.source
|
|
51
53
|
});
|
|
52
54
|
}
|
|
53
|
-
return Promise.resolve(
|
|
55
|
+
return Promise.resolve({
|
|
56
|
+
accepted,
|
|
57
|
+
ignored: [],
|
|
58
|
+
rejected: []
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
canAddPendingTx(tx) {
|
|
62
|
+
const key = tx.getTxHash().toString();
|
|
63
|
+
if (this.txsByHash.has(key)) {
|
|
64
|
+
return Promise.resolve('ignored');
|
|
65
|
+
}
|
|
66
|
+
return Promise.resolve('accepted');
|
|
67
|
+
}
|
|
68
|
+
addProtectedTxs(txs, _block, opts) {
|
|
69
|
+
for (const tx of txs){
|
|
70
|
+
const key = tx.getTxHash().toString();
|
|
71
|
+
this.txsByHash.set(key, tx);
|
|
72
|
+
}
|
|
73
|
+
if (txs.length > 0) {
|
|
74
|
+
this.emit('txs-added', {
|
|
75
|
+
txs,
|
|
76
|
+
source: opts?.source
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
return Promise.resolve();
|
|
80
|
+
}
|
|
81
|
+
protectTxs(txHashes, _block) {
|
|
82
|
+
const notFound = [];
|
|
83
|
+
for (const txHash of txHashes){
|
|
84
|
+
if (!this.txsByHash.has(txHash.toString())) {
|
|
85
|
+
notFound.push(txHash);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
return Promise.resolve(notFound);
|
|
89
|
+
}
|
|
90
|
+
addMinedTxs(txs, _block, _opts) {
|
|
91
|
+
for (const tx of txs){
|
|
92
|
+
const key = tx.getTxHash().toString();
|
|
93
|
+
this.txsByHash.set(key, tx);
|
|
94
|
+
}
|
|
95
|
+
return Promise.resolve();
|
|
96
|
+
}
|
|
97
|
+
// === State Transition Handlers (TxPoolV2) ===
|
|
98
|
+
handleMinedBlock(_block) {
|
|
99
|
+
return Promise.resolve();
|
|
100
|
+
}
|
|
101
|
+
prepareForSlot(_slotNumber) {
|
|
102
|
+
return Promise.resolve();
|
|
103
|
+
}
|
|
104
|
+
handlePrunedBlocks(_latestBlock) {
|
|
105
|
+
return Promise.resolve();
|
|
54
106
|
}
|
|
107
|
+
handleFailedExecution(txHashes) {
|
|
108
|
+
for (const txHash of txHashes){
|
|
109
|
+
this.txsByHash.delete(txHash.toString());
|
|
110
|
+
}
|
|
111
|
+
return Promise.resolve();
|
|
112
|
+
}
|
|
113
|
+
handleFinalizedBlock(_block) {
|
|
114
|
+
return Promise.resolve();
|
|
115
|
+
}
|
|
116
|
+
// === Query Operations (TxPoolV2) ===
|
|
55
117
|
getTxByHash(hash) {
|
|
56
118
|
return Promise.resolve(this.txsByHash.get(hash.toString()));
|
|
57
119
|
}
|
|
@@ -64,52 +126,45 @@ import { RateLimitStatus } from '../services/reqresp/rate-limiter/rate_limiter.j
|
|
|
64
126
|
hasTxs(hashes) {
|
|
65
127
|
return Promise.resolve(hashes.map((h)=>this.txsByHash.has(h.toString())));
|
|
66
128
|
}
|
|
67
|
-
hasTx(hash) {
|
|
68
|
-
return Promise.resolve(this.txsByHash.has(hash.toString()));
|
|
69
|
-
}
|
|
70
129
|
getArchivedTxByHash(_hash) {
|
|
71
130
|
return Promise.resolve(undefined);
|
|
72
131
|
}
|
|
73
|
-
async markAsMined(_txHashes, _blockHeader) {}
|
|
74
|
-
async markMinedAsPending(_txHashes, _latestBlock) {}
|
|
75
|
-
deleteTxs(txHashes, _opts) {
|
|
76
|
-
for (const txHash of txHashes){
|
|
77
|
-
this.txsByHash.delete(txHash.toString());
|
|
78
|
-
}
|
|
79
|
-
return Promise.resolve();
|
|
80
|
-
}
|
|
81
|
-
getAllTxs() {
|
|
82
|
-
return Promise.resolve([
|
|
83
|
-
...this.txsByHash.values()
|
|
84
|
-
]);
|
|
85
|
-
}
|
|
86
|
-
getAllTxHashes() {
|
|
87
|
-
return Promise.resolve([
|
|
88
|
-
...this.txsByHash.keys()
|
|
89
|
-
].map((key)=>TxHash.fromString(key)));
|
|
90
|
-
}
|
|
91
132
|
getPendingTxHashes() {
|
|
92
133
|
return Promise.resolve([
|
|
93
134
|
...this.txsByHash.keys()
|
|
94
135
|
].map((key)=>TxHash.fromString(key)));
|
|
95
136
|
}
|
|
137
|
+
getEligiblePendingTxHashes() {
|
|
138
|
+
return this.getPendingTxHashes();
|
|
139
|
+
}
|
|
96
140
|
getPendingTxCount() {
|
|
97
141
|
return Promise.resolve(this.txsByHash.size);
|
|
98
142
|
}
|
|
99
143
|
getMinedTxHashes() {
|
|
100
144
|
return Promise.resolve([]);
|
|
101
145
|
}
|
|
146
|
+
getMinedTxCount() {
|
|
147
|
+
return Promise.resolve(0);
|
|
148
|
+
}
|
|
102
149
|
getTxStatus(hash) {
|
|
103
150
|
return Promise.resolve(this.txsByHash.has(hash.toString()) ? 'pending' : undefined);
|
|
104
151
|
}
|
|
105
|
-
updateConfig(_config) {}
|
|
106
152
|
isEmpty() {
|
|
107
153
|
return Promise.resolve(this.txsByHash.size === 0);
|
|
108
154
|
}
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
155
|
+
getLowestPriorityPending(_limit) {
|
|
156
|
+
return Promise.resolve([]);
|
|
157
|
+
}
|
|
158
|
+
// === Configuration (TxPoolV2) ===
|
|
159
|
+
updateConfig(_config) {
|
|
160
|
+
return Promise.resolve();
|
|
161
|
+
}
|
|
162
|
+
// === Lifecycle (TxPoolV2) ===
|
|
163
|
+
start() {
|
|
164
|
+
return Promise.resolve();
|
|
165
|
+
}
|
|
166
|
+
stop() {
|
|
167
|
+
return Promise.resolve();
|
|
113
168
|
}
|
|
114
169
|
}
|
|
115
170
|
/**
|
|
@@ -124,14 +179,14 @@ import { RateLimitStatus } from '../services/reqresp/rate-limiter/rate_limiter.j
|
|
|
124
179
|
return Promise.resolve({
|
|
125
180
|
added: false,
|
|
126
181
|
alreadyExists: true,
|
|
127
|
-
|
|
182
|
+
count: 1
|
|
128
183
|
});
|
|
129
184
|
}
|
|
130
185
|
this.proposals.set(id, blockProposal);
|
|
131
186
|
return Promise.resolve({
|
|
132
187
|
added: true,
|
|
133
188
|
alreadyExists: false,
|
|
134
|
-
|
|
189
|
+
count: 1
|
|
135
190
|
});
|
|
136
191
|
}
|
|
137
192
|
getBlockProposal(id) {
|
|
@@ -141,7 +196,7 @@ import { RateLimitStatus } from '../services/reqresp/rate-limiter/rate_limiter.j
|
|
|
141
196
|
return Promise.resolve({
|
|
142
197
|
added: true,
|
|
143
198
|
alreadyExists: false,
|
|
144
|
-
|
|
199
|
+
count: 1
|
|
145
200
|
});
|
|
146
201
|
}
|
|
147
202
|
getCheckpointProposal(_id) {
|
|
@@ -155,13 +210,16 @@ import { RateLimitStatus } from '../services/reqresp/rate-limiter/rate_limiter.j
|
|
|
155
210
|
getCheckpointAttestationsForSlotAndProposal(_slot, _proposalId) {
|
|
156
211
|
return Promise.resolve([]);
|
|
157
212
|
}
|
|
158
|
-
tryAddCheckpointAttestation(_attestation
|
|
213
|
+
tryAddCheckpointAttestation(_attestation) {
|
|
159
214
|
return Promise.resolve({
|
|
160
215
|
added: true,
|
|
161
216
|
alreadyExists: false,
|
|
162
|
-
|
|
217
|
+
count: 1
|
|
163
218
|
});
|
|
164
219
|
}
|
|
220
|
+
hasBlockProposalsForSlot(_slot) {
|
|
221
|
+
return Promise.resolve(false);
|
|
222
|
+
}
|
|
165
223
|
isEmpty() {
|
|
166
224
|
return Promise.resolve(this.proposals.size === 0);
|
|
167
225
|
}
|
|
@@ -49,7 +49,7 @@ class TestLibP2PService extends LibP2PService {
|
|
|
49
49
|
const txHash = tx.getTxHash();
|
|
50
50
|
const txHashString = txHash.toString();
|
|
51
51
|
this.logger.verbose(`Received tx ${txHashString} from external peer ${source.toString()}.`);
|
|
52
|
-
await this.mempools.txPool.
|
|
52
|
+
await this.mempools.txPool.addPendingTxs([
|
|
53
53
|
tx
|
|
54
54
|
]);
|
|
55
55
|
} else {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aztec/p2p",
|
|
3
|
-
"version": "0.0.1-commit.
|
|
3
|
+
"version": "0.0.1-commit.4ad48494d",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": "./dest/index.js",
|
|
@@ -67,17 +67,17 @@
|
|
|
67
67
|
]
|
|
68
68
|
},
|
|
69
69
|
"dependencies": {
|
|
70
|
-
"@aztec/constants": "0.0.1-commit.
|
|
71
|
-
"@aztec/epoch-cache": "0.0.1-commit.
|
|
72
|
-
"@aztec/ethereum": "0.0.1-commit.
|
|
73
|
-
"@aztec/foundation": "0.0.1-commit.
|
|
74
|
-
"@aztec/kv-store": "0.0.1-commit.
|
|
75
|
-
"@aztec/noir-contracts.js": "0.0.1-commit.
|
|
76
|
-
"@aztec/noir-protocol-circuits-types": "0.0.1-commit.
|
|
77
|
-
"@aztec/protocol-contracts": "0.0.1-commit.
|
|
78
|
-
"@aztec/simulator": "0.0.1-commit.
|
|
79
|
-
"@aztec/stdlib": "0.0.1-commit.
|
|
80
|
-
"@aztec/telemetry-client": "0.0.1-commit.
|
|
70
|
+
"@aztec/constants": "0.0.1-commit.4ad48494d",
|
|
71
|
+
"@aztec/epoch-cache": "0.0.1-commit.4ad48494d",
|
|
72
|
+
"@aztec/ethereum": "0.0.1-commit.4ad48494d",
|
|
73
|
+
"@aztec/foundation": "0.0.1-commit.4ad48494d",
|
|
74
|
+
"@aztec/kv-store": "0.0.1-commit.4ad48494d",
|
|
75
|
+
"@aztec/noir-contracts.js": "0.0.1-commit.4ad48494d",
|
|
76
|
+
"@aztec/noir-protocol-circuits-types": "0.0.1-commit.4ad48494d",
|
|
77
|
+
"@aztec/protocol-contracts": "0.0.1-commit.4ad48494d",
|
|
78
|
+
"@aztec/simulator": "0.0.1-commit.4ad48494d",
|
|
79
|
+
"@aztec/stdlib": "0.0.1-commit.4ad48494d",
|
|
80
|
+
"@aztec/telemetry-client": "0.0.1-commit.4ad48494d",
|
|
81
81
|
"@chainsafe/libp2p-gossipsub": "13.0.0",
|
|
82
82
|
"@chainsafe/libp2p-noise": "^15.0.0",
|
|
83
83
|
"@chainsafe/libp2p-yamux": "^6.0.2",
|
|
@@ -104,8 +104,8 @@
|
|
|
104
104
|
"xxhash-wasm": "^1.1.0"
|
|
105
105
|
},
|
|
106
106
|
"devDependencies": {
|
|
107
|
-
"@aztec/archiver": "0.0.1-commit.
|
|
108
|
-
"@aztec/world-state": "0.0.1-commit.
|
|
107
|
+
"@aztec/archiver": "0.0.1-commit.4ad48494d",
|
|
108
|
+
"@aztec/world-state": "0.0.1-commit.4ad48494d",
|
|
109
109
|
"@jest/globals": "^30.0.0",
|
|
110
110
|
"@types/jest": "^30.0.0",
|
|
111
111
|
"@types/node": "^22.15.17",
|
package/src/client/factory.ts
CHANGED
|
@@ -4,27 +4,34 @@ import { DateProvider } from '@aztec/foundation/timer';
|
|
|
4
4
|
import type { AztecAsyncKVStore } from '@aztec/kv-store';
|
|
5
5
|
import type { DataStoreConfig } from '@aztec/kv-store/config';
|
|
6
6
|
import { AztecLMDBStoreV2, createStore } from '@aztec/kv-store/lmdb-v2';
|
|
7
|
-
import type { L2BlockSource } from '@aztec/stdlib/block';
|
|
7
|
+
import type { BlockHash, L2BlockSource } from '@aztec/stdlib/block';
|
|
8
8
|
import type { ChainConfig } from '@aztec/stdlib/config';
|
|
9
9
|
import type { ContractDataSource } from '@aztec/stdlib/contract';
|
|
10
10
|
import type { ClientProtocolCircuitVerifier, WorldStateSynchronizer } from '@aztec/stdlib/interfaces/server';
|
|
11
11
|
import { P2PClientType } from '@aztec/stdlib/p2p';
|
|
12
|
+
import { MerkleTreeId } from '@aztec/stdlib/trees';
|
|
12
13
|
import { type TelemetryClient, getTelemetryClient } from '@aztec/telemetry-client';
|
|
13
14
|
|
|
14
15
|
import { P2PClient } from '../client/p2p_client.js';
|
|
15
16
|
import type { P2PConfig } from '../config.js';
|
|
16
17
|
import { AttestationPool, type AttestationPoolApi } from '../mem_pools/attestation_pool/attestation_pool.js';
|
|
17
18
|
import type { MemPools } from '../mem_pools/interface.js';
|
|
18
|
-
import {
|
|
19
|
+
import type { TxPoolV2 } from '../mem_pools/tx_pool_v2/interfaces.js';
|
|
20
|
+
import type { TxMetaData } from '../mem_pools/tx_pool_v2/tx_metadata.js';
|
|
21
|
+
import { AztecKVTxPoolV2 } from '../mem_pools/tx_pool_v2/tx_pool_v2.js';
|
|
22
|
+
import { AggregateTxValidator } from '../msg_validators/tx_validator/aggregate_tx_validator.js';
|
|
23
|
+
import { BlockHeaderTxValidator } from '../msg_validators/tx_validator/block_header_validator.js';
|
|
24
|
+
import { DoubleSpendTxValidator } from '../msg_validators/tx_validator/double_spend_validator.js';
|
|
19
25
|
import { DummyP2PService } from '../services/dummy_service.js';
|
|
20
26
|
import { LibP2PService } from '../services/index.js';
|
|
27
|
+
import { createFileStoreTxSources } from '../services/tx_collection/file_store_tx_source.js';
|
|
21
28
|
import { TxCollection } from '../services/tx_collection/tx_collection.js';
|
|
22
29
|
import { type TxSource, createNodeRpcTxSources } from '../services/tx_collection/tx_source.js';
|
|
23
30
|
import { TxFileStore } from '../services/tx_file_store/tx_file_store.js';
|
|
24
31
|
import { configureP2PClientAddresses, createLibP2PPeerIdFromPrivateKey, getPeerIdPrivateKey } from '../util.js';
|
|
25
32
|
|
|
26
33
|
export type P2PClientDeps<T extends P2PClientType> = {
|
|
27
|
-
txPool?:
|
|
34
|
+
txPool?: TxPoolV2;
|
|
28
35
|
store?: AztecAsyncKVStore;
|
|
29
36
|
attestationPool?: AttestationPoolApi;
|
|
30
37
|
logger?: Logger;
|
|
@@ -69,13 +76,56 @@ export async function createP2PClient<T extends P2PClientType>(
|
|
|
69
76
|
const attestationStore = await createStore(P2P_ATTESTATION_STORE_NAME, 1, config, bindings);
|
|
70
77
|
const l1Constants = await archiver.getL1Constants();
|
|
71
78
|
|
|
72
|
-
const
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
79
|
+
const rollupAddress = inputConfig.l1Contracts.rollupAddress.toString().toLowerCase().replace(/^0x/, '');
|
|
80
|
+
const txFileStoreBasePath = `aztec-${inputConfig.l1ChainId}-${inputConfig.rollupVersion}-0x${rollupAddress}`;
|
|
81
|
+
|
|
82
|
+
/** Validator factory for pool re-validation (double-spend + block header only). */
|
|
83
|
+
const createPoolTxValidator = async () => {
|
|
84
|
+
await worldStateSynchronizer.syncImmediate();
|
|
85
|
+
return new AggregateTxValidator<TxMetaData>(
|
|
86
|
+
new DoubleSpendTxValidator<TxMetaData>(
|
|
87
|
+
{
|
|
88
|
+
nullifiersExist: async (nullifiers: Buffer[]) => {
|
|
89
|
+
const merkleTree = worldStateSynchronizer.getCommitted();
|
|
90
|
+
const indices = await merkleTree.findLeafIndices(MerkleTreeId.NULLIFIER_TREE, nullifiers);
|
|
91
|
+
return indices.map(index => index !== undefined);
|
|
92
|
+
},
|
|
93
|
+
},
|
|
94
|
+
bindings,
|
|
95
|
+
),
|
|
96
|
+
new BlockHeaderTxValidator<TxMetaData>(
|
|
97
|
+
{
|
|
98
|
+
getArchiveIndices: (archives: BlockHash[]) => {
|
|
99
|
+
const merkleTree = worldStateSynchronizer.getCommitted();
|
|
100
|
+
return merkleTree.findLeafIndices(MerkleTreeId.ARCHIVE, archives);
|
|
101
|
+
},
|
|
102
|
+
},
|
|
103
|
+
bindings,
|
|
104
|
+
),
|
|
105
|
+
);
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
const txPool =
|
|
109
|
+
deps.txPool ??
|
|
110
|
+
new AztecKVTxPoolV2(
|
|
111
|
+
store,
|
|
112
|
+
archive,
|
|
113
|
+
{
|
|
114
|
+
l2BlockSource: archiver,
|
|
115
|
+
worldStateSynchronizer,
|
|
116
|
+
createTxValidator: createPoolTxValidator,
|
|
117
|
+
},
|
|
118
|
+
telemetry,
|
|
119
|
+
{
|
|
76
120
|
maxPendingTxCount: config.maxPendingTxCount,
|
|
77
121
|
archivedTxLimit: config.archivedTxLimit,
|
|
78
|
-
|
|
122
|
+
minTxPoolAgeMs: config.minTxPoolAgeMs,
|
|
123
|
+
},
|
|
124
|
+
dateProvider,
|
|
125
|
+
);
|
|
126
|
+
|
|
127
|
+
const mempools: MemPools = {
|
|
128
|
+
txPool,
|
|
79
129
|
attestationPool: deps.attestationPool ?? new AttestationPool(attestationStore, telemetry),
|
|
80
130
|
};
|
|
81
131
|
|
|
@@ -105,18 +155,36 @@ export async function createP2PClient<T extends P2PClientType>(
|
|
|
105
155
|
});
|
|
106
156
|
}
|
|
107
157
|
|
|
158
|
+
const fileStoreSources = await createFileStoreTxSources(
|
|
159
|
+
config.txCollectionFileStoreUrls,
|
|
160
|
+
txFileStoreBasePath,
|
|
161
|
+
logger.createChild('file-store-tx-source'),
|
|
162
|
+
);
|
|
163
|
+
if (fileStoreSources.length > 0) {
|
|
164
|
+
logger.info(`Using ${fileStoreSources.length} file store sources for tx collection.`, {
|
|
165
|
+
stores: fileStoreSources.map(s => s.getInfo()),
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
|
|
108
169
|
const txCollection = new TxCollection(
|
|
109
170
|
p2pService.getBatchTxRequesterService(),
|
|
110
171
|
nodeSources,
|
|
111
172
|
l1Constants,
|
|
112
173
|
mempools.txPool,
|
|
113
174
|
config,
|
|
175
|
+
fileStoreSources,
|
|
114
176
|
dateProvider,
|
|
115
177
|
telemetry,
|
|
116
178
|
logger.createChild('tx-collection'),
|
|
117
179
|
);
|
|
118
180
|
|
|
119
|
-
const txFileStore = await TxFileStore.create(
|
|
181
|
+
const txFileStore = await TxFileStore.create(
|
|
182
|
+
mempools.txPool,
|
|
183
|
+
config,
|
|
184
|
+
txFileStoreBasePath,
|
|
185
|
+
logger.createChild('tx-file-store'),
|
|
186
|
+
telemetry,
|
|
187
|
+
);
|
|
120
188
|
|
|
121
189
|
return new P2PClient(
|
|
122
190
|
clientType,
|
|
@@ -126,6 +194,7 @@ export async function createP2PClient<T extends P2PClientType>(
|
|
|
126
194
|
p2pService,
|
|
127
195
|
txCollection,
|
|
128
196
|
txFileStore,
|
|
197
|
+
epochCache,
|
|
129
198
|
config,
|
|
130
199
|
dateProvider,
|
|
131
200
|
telemetry,
|
package/src/client/interface.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
+
import type { SlotNumber } from '@aztec/foundation/branded-types';
|
|
1
2
|
import type { EthAddress, L2BlockId } from '@aztec/stdlib/block';
|
|
2
3
|
import type { P2PApiFull } from '@aztec/stdlib/interfaces/server';
|
|
3
4
|
import type { BlockProposal, CheckpointAttestation, CheckpointProposal, P2PClientType } from '@aztec/stdlib/p2p';
|
|
4
|
-
import type { Tx, TxHash } from '@aztec/stdlib/tx';
|
|
5
|
+
import type { BlockHeader, Tx, TxHash } from '@aztec/stdlib/tx';
|
|
5
6
|
|
|
6
7
|
import type { PeerId } from '@libp2p/interface';
|
|
7
8
|
import type { ENR } from '@nethermindeth/enr';
|
|
@@ -14,6 +15,7 @@ import type {
|
|
|
14
15
|
ReqRespSubProtocolValidators,
|
|
15
16
|
} from '../services/reqresp/interface.js';
|
|
16
17
|
import type {
|
|
18
|
+
DuplicateAttestationInfo,
|
|
17
19
|
DuplicateProposalInfo,
|
|
18
20
|
P2PBlockReceivedCallback,
|
|
19
21
|
P2PCheckpointReceivedCallback,
|
|
@@ -91,12 +93,13 @@ export type P2P<T extends P2PClientType = P2PClientType.Full> = P2PApiFull<T> &
|
|
|
91
93
|
registerDuplicateProposalCallback(callback: (info: DuplicateProposalInfo) => void): void;
|
|
92
94
|
|
|
93
95
|
/**
|
|
94
|
-
*
|
|
95
|
-
*
|
|
96
|
-
*
|
|
97
|
-
*
|
|
96
|
+
* Registers a callback invoked when a duplicate attestation is detected (equivocation).
|
|
97
|
+
* A validator signing attestations for different proposals at the same slot.
|
|
98
|
+
* The callback is triggered on the first duplicate (when count goes from 1 to 2).
|
|
99
|
+
*
|
|
100
|
+
* @param callback - Function called with info about the duplicate attestation
|
|
98
101
|
*/
|
|
99
|
-
|
|
102
|
+
registerDuplicateAttestationCallback(callback: (info: DuplicateAttestationInfo) => void): void;
|
|
100
103
|
|
|
101
104
|
/**
|
|
102
105
|
* Verifies the 'tx' and, if valid, adds it to local tx pool and forwards it to other peers.
|
|
@@ -112,11 +115,10 @@ export type P2P<T extends P2PClientType = P2PClientType.Full> = P2PApiFull<T> &
|
|
|
112
115
|
addTxsToPool(txs: Tx[]): Promise<number>;
|
|
113
116
|
|
|
114
117
|
/**
|
|
115
|
-
*
|
|
116
|
-
*
|
|
117
|
-
* @param txHashes - Hashes to check.
|
|
118
|
+
* Handles failed transaction execution by removing txs from the pool.
|
|
119
|
+
* @param txHashes - Hashes of the transactions that failed execution.
|
|
118
120
|
**/
|
|
119
|
-
|
|
121
|
+
handleFailedExecution(txHashes: TxHash[]): Promise<void>;
|
|
120
122
|
|
|
121
123
|
/**
|
|
122
124
|
* Returns a transaction in the transaction pool by its hash.
|
|
@@ -164,14 +166,28 @@ export type P2P<T extends P2PClientType = P2PClientType.Full> = P2PApiFull<T> &
|
|
|
164
166
|
/** Returns an iterator over pending txs on the mempool. */
|
|
165
167
|
iteratePendingTxs(): AsyncIterableIterator<Tx>;
|
|
166
168
|
|
|
169
|
+
/** Returns an iterator over pending txs that have been in the pool long enough to be eligible for block building. */
|
|
170
|
+
iterateEligiblePendingTxs(): AsyncIterableIterator<Tx>;
|
|
171
|
+
|
|
167
172
|
/** Returns the number of pending txs in the mempool. */
|
|
168
173
|
getPendingTxCount(): Promise<number>;
|
|
169
174
|
|
|
170
175
|
/**
|
|
171
|
-
*
|
|
172
|
-
*
|
|
176
|
+
* Protects existing transactions by hash for a given slot.
|
|
177
|
+
* Returns hashes of transactions that weren't found in the pool.
|
|
178
|
+
* @param txHashes - Hashes of the transactions to protect.
|
|
179
|
+
* @param blockHeader - The block header providing slot context.
|
|
180
|
+
* @returns Hashes of transactions not found in the pool.
|
|
173
181
|
*/
|
|
174
|
-
|
|
182
|
+
protectTxs(txHashes: TxHash[], blockHeader: BlockHeader): Promise<TxHash[]>;
|
|
183
|
+
|
|
184
|
+
/**
|
|
185
|
+
* Prepares the pool for a new slot.
|
|
186
|
+
* Unprotects transactions from earlier slots and validates them before
|
|
187
|
+
* returning to pending state.
|
|
188
|
+
* @param slotNumber - The slot number to prepare for
|
|
189
|
+
*/
|
|
190
|
+
prepareForSlot(slotNumber: SlotNumber): Promise<void>;
|
|
175
191
|
|
|
176
192
|
/**
|
|
177
193
|
* Starts the p2p client.
|
|
@@ -220,6 +236,9 @@ export type P2P<T extends P2PClientType = P2PClientType.Full> = P2PApiFull<T> &
|
|
|
220
236
|
|
|
221
237
|
handleAuthRequestFromPeer(authRequest: AuthRequest, peerId: PeerId): Promise<StatusMessage>;
|
|
222
238
|
|
|
239
|
+
/** Checks if any block proposals exist for the given slot. */
|
|
240
|
+
hasBlockProposalsForSlot(slot: SlotNumber): Promise<boolean>;
|
|
241
|
+
|
|
223
242
|
/** If node running this P2P stack is validator, passes in validator address to P2P layer */
|
|
224
243
|
registerThisValidatorAddresses(address: EthAddress[]): void;
|
|
225
244
|
};
|