@aztec/p2p 1.2.1 → 2.0.0-nightly.20250813
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 +5 -1
- package/dest/client/factory.d.ts.map +1 -1
- package/dest/client/factory.js +29 -12
- package/dest/client/interface.d.ts +8 -13
- package/dest/client/interface.d.ts.map +1 -1
- package/dest/client/p2p_client.d.ts +18 -22
- package/dest/client/p2p_client.d.ts.map +1 -1
- package/dest/client/p2p_client.js +86 -83
- package/dest/config.d.ts +30 -1
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +34 -1
- package/dest/index.d.ts +1 -0
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +1 -0
- package/dest/mem_pools/attestation_pool/attestation_pool.d.ts +13 -1
- 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.map +1 -1
- package/dest/mem_pools/attestation_pool/attestation_pool_test_suite.js +117 -10
- package/dest/mem_pools/attestation_pool/kv_attestation_pool.d.ts +4 -1
- package/dest/mem_pools/attestation_pool/kv_attestation_pool.d.ts.map +1 -1
- package/dest/mem_pools/attestation_pool/kv_attestation_pool.js +22 -1
- package/dest/mem_pools/attestation_pool/memory_attestation_pool.d.ts +4 -1
- package/dest/mem_pools/attestation_pool/memory_attestation_pool.d.ts.map +1 -1
- package/dest/mem_pools/attestation_pool/memory_attestation_pool.js +21 -1
- package/dest/mem_pools/attestation_pool/mocks.d.ts +1 -2
- package/dest/mem_pools/attestation_pool/mocks.d.ts.map +1 -1
- package/dest/mem_pools/attestation_pool/mocks.js +2 -10
- package/dest/mem_pools/tx_pool/aztec_kv_tx_pool.d.ts +8 -3
- 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 +64 -37
- package/dest/mem_pools/tx_pool/memory_tx_pool.d.ts +8 -3
- package/dest/mem_pools/tx_pool/memory_tx_pool.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool/memory_tx_pool.js +18 -10
- package/dest/mem_pools/tx_pool/tx_pool.d.ts +11 -2
- package/dest/mem_pools/tx_pool/tx_pool.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool/tx_pool_test_suite.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool/tx_pool_test_suite.js +73 -44
- package/dest/msg_validators/attestation_validator/attestation_validator.js +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 +2 -2
- package/dest/msg_validators/tx_validator/data_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/data_validator.js +35 -59
- package/dest/msg_validators/tx_validator/double_spend_validator.js +2 -2
- package/dest/msg_validators/tx_validator/gas_validator.js +4 -4
- package/dest/msg_validators/tx_validator/metadata_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/metadata_validator.js +21 -21
- package/dest/msg_validators/tx_validator/phases_validator.js +3 -3
- package/dest/msg_validators/tx_validator/tx_proof_validator.js +3 -3
- package/dest/services/discv5/discV5_service.d.ts.map +1 -1
- package/dest/services/discv5/discV5_service.js +4 -1
- package/dest/services/dummy_service.d.ts +13 -3
- package/dest/services/dummy_service.d.ts.map +1 -1
- package/dest/services/dummy_service.js +26 -3
- package/dest/services/index.d.ts +3 -1
- package/dest/services/index.d.ts.map +1 -1
- package/dest/services/index.js +3 -1
- package/dest/services/libp2p/libp2p_service.d.ts +13 -20
- package/dest/services/libp2p/libp2p_service.d.ts.map +1 -1
- package/dest/services/libp2p/libp2p_service.js +123 -46
- package/dest/services/peer-manager/interface.d.ts +8 -1
- package/dest/services/peer-manager/interface.d.ts.map +1 -1
- package/dest/services/peer-manager/peer_manager.d.ts +70 -3
- package/dest/services/peer-manager/peer_manager.d.ts.map +1 -1
- package/dest/services/peer-manager/peer_manager.js +369 -39
- package/dest/services/reqresp/config.d.ts +3 -3
- package/dest/services/reqresp/config.d.ts.map +1 -1
- package/dest/services/reqresp/config.js +3 -3
- package/dest/services/reqresp/connection-sampler/connection_sampler.d.ts +3 -4
- package/dest/services/reqresp/connection-sampler/connection_sampler.d.ts.map +1 -1
- package/dest/services/reqresp/connection-sampler/connection_sampler.js +35 -52
- package/dest/services/reqresp/index.d.ts +2 -1
- package/dest/services/reqresp/index.d.ts.map +1 -1
- package/dest/services/reqresp/index.js +2 -1
- package/dest/services/reqresp/interface.d.ts +61 -10
- package/dest/services/reqresp/interface.d.ts.map +1 -1
- package/dest/services/reqresp/interface.js +41 -6
- package/dest/services/reqresp/protocols/auth.d.ts +43 -0
- package/dest/services/reqresp/protocols/auth.d.ts.map +1 -0
- package/dest/services/reqresp/protocols/auth.js +71 -0
- package/dest/services/reqresp/protocols/block.d.ts +5 -0
- package/dest/services/reqresp/protocols/block.d.ts.map +1 -1
- package/dest/services/reqresp/protocols/block.js +28 -5
- package/dest/services/reqresp/protocols/block_txs/bitvector.d.ts +30 -0
- package/dest/services/reqresp/protocols/block_txs/bitvector.d.ts.map +1 -0
- package/dest/services/reqresp/protocols/block_txs/bitvector.js +75 -0
- package/dest/services/reqresp/protocols/block_txs/block_txs_handler.d.ts +11 -0
- package/dest/services/reqresp/protocols/block_txs/block_txs_handler.d.ts.map +1 -0
- package/dest/services/reqresp/protocols/block_txs/block_txs_handler.js +39 -0
- package/dest/services/reqresp/protocols/block_txs/block_txs_reqresp.d.ts +49 -0
- package/dest/services/reqresp/protocols/block_txs/block_txs_reqresp.d.ts.map +1 -0
- package/dest/services/reqresp/protocols/block_txs/block_txs_reqresp.js +75 -0
- package/dest/services/reqresp/protocols/block_txs/index.d.ts +4 -0
- package/dest/services/reqresp/protocols/block_txs/index.d.ts.map +1 -0
- package/dest/services/reqresp/protocols/block_txs/index.js +3 -0
- package/dest/services/reqresp/protocols/goodbye.js +3 -5
- package/dest/services/reqresp/protocols/index.d.ts +2 -0
- package/dest/services/reqresp/protocols/index.d.ts.map +1 -1
- package/dest/services/reqresp/protocols/index.js +2 -0
- package/dest/services/reqresp/protocols/status.d.ts +2 -0
- package/dest/services/reqresp/protocols/status.d.ts.map +1 -1
- package/dest/services/reqresp/protocols/status.js +7 -0
- package/dest/services/reqresp/protocols/tx.d.ts +12 -1
- package/dest/services/reqresp/protocols/tx.d.ts.map +1 -1
- package/dest/services/reqresp/protocols/tx.js +34 -6
- package/dest/services/reqresp/rate-limiter/rate_limits.d.ts.map +1 -1
- package/dest/services/reqresp/rate-limiter/rate_limits.js +20 -0
- package/dest/services/reqresp/reqresp.d.ts +37 -39
- package/dest/services/reqresp/reqresp.d.ts.map +1 -1
- package/dest/services/reqresp/reqresp.js +220 -220
- package/dest/services/reqresp/status.d.ts +8 -3
- package/dest/services/reqresp/status.d.ts.map +1 -1
- package/dest/services/reqresp/status.js +6 -2
- package/dest/services/service.d.ts +10 -10
- package/dest/services/service.d.ts.map +1 -1
- package/dest/services/tx_collection/config.d.ts +25 -0
- package/dest/services/tx_collection/config.d.ts.map +1 -0
- package/dest/services/tx_collection/config.js +58 -0
- package/dest/services/tx_collection/fast_tx_collection.d.ts +56 -0
- package/dest/services/tx_collection/fast_tx_collection.d.ts.map +1 -0
- package/dest/services/tx_collection/fast_tx_collection.js +295 -0
- package/dest/services/tx_collection/index.d.ts +3 -0
- package/dest/services/tx_collection/index.d.ts.map +1 -0
- package/dest/services/tx_collection/index.js +2 -0
- package/dest/services/tx_collection/instrumentation.d.ts +10 -0
- package/dest/services/tx_collection/instrumentation.d.ts.map +1 -0
- package/dest/services/tx_collection/instrumentation.js +34 -0
- package/dest/services/tx_collection/slow_tx_collection.d.ts +54 -0
- package/dest/services/tx_collection/slow_tx_collection.d.ts.map +1 -0
- package/dest/services/tx_collection/slow_tx_collection.js +176 -0
- package/dest/services/tx_collection/tx_collection.d.ts +109 -0
- package/dest/services/tx_collection/tx_collection.d.ts.map +1 -0
- package/dest/services/tx_collection/tx_collection.js +127 -0
- package/dest/services/tx_collection/tx_collection_sink.d.ts +30 -0
- package/dest/services/tx_collection/tx_collection_sink.d.ts.map +1 -0
- package/dest/services/tx_collection/tx_collection_sink.js +81 -0
- package/dest/services/tx_collection/tx_source.d.ts +18 -0
- package/dest/services/tx_collection/tx_source.d.ts.map +1 -0
- package/dest/services/tx_collection/tx_source.js +31 -0
- package/dest/services/tx_provider.d.ts +49 -0
- package/dest/services/tx_provider.d.ts.map +1 -0
- package/dest/services/tx_provider.js +206 -0
- package/dest/services/{tx_collect_instrumentation.d.ts → tx_provider_instrumentation.d.ts} +2 -2
- package/dest/services/tx_provider_instrumentation.d.ts.map +1 -0
- package/dest/services/{tx_collect_instrumentation.js → tx_provider_instrumentation.js} +5 -5
- package/dest/test-helpers/make-test-p2p-clients.d.ts.map +1 -1
- package/dest/test-helpers/make-test-p2p-clients.js +4 -3
- package/dest/test-helpers/mock-pubsub.d.ts +2 -1
- package/dest/test-helpers/mock-pubsub.d.ts.map +1 -1
- package/dest/test-helpers/mock-pubsub.js +2 -1
- package/dest/test-helpers/reqresp-nodes.d.ts.map +1 -1
- package/dest/test-helpers/reqresp-nodes.js +8 -4
- package/dest/testbench/p2p_client_testbench_worker.js +11 -5
- package/dest/util.d.ts +1 -1
- package/dest/util.d.ts.map +1 -1
- package/package.json +14 -15
- package/src/client/factory.ts +87 -12
- package/src/client/interface.ts +19 -15
- package/src/client/p2p_client.ts +108 -92
- package/src/config.ts +52 -1
- package/src/index.ts +1 -0
- package/src/mem_pools/attestation_pool/attestation_pool.ts +15 -1
- package/src/mem_pools/attestation_pool/attestation_pool_test_suite.ts +155 -4
- package/src/mem_pools/attestation_pool/kv_attestation_pool.ts +28 -1
- package/src/mem_pools/attestation_pool/memory_attestation_pool.ts +28 -2
- package/src/mem_pools/attestation_pool/mocks.ts +1 -3
- package/src/mem_pools/tx_pool/aztec_kv_tx_pool.ts +59 -41
- package/src/mem_pools/tx_pool/memory_tx_pool.ts +19 -9
- package/src/mem_pools/tx_pool/tx_pool.ts +7 -2
- package/src/mem_pools/tx_pool/tx_pool_test_suite.ts +63 -40
- package/src/msg_validators/attestation_validator/attestation_validator.ts +1 -1
- package/src/msg_validators/tx_validator/block_header_validator.ts +2 -2
- package/src/msg_validators/tx_validator/data_validator.ts +36 -27
- package/src/msg_validators/tx_validator/double_spend_validator.ts +2 -2
- package/src/msg_validators/tx_validator/gas_validator.ts +4 -4
- package/src/msg_validators/tx_validator/metadata_validator.ts +22 -28
- package/src/msg_validators/tx_validator/phases_validator.ts +2 -2
- package/src/msg_validators/tx_validator/tx_proof_validator.ts +2 -2
- package/src/services/discv5/discV5_service.ts +4 -1
- package/src/services/dummy_service.ts +44 -4
- package/src/services/index.ts +3 -1
- package/src/services/libp2p/libp2p_service.ts +147 -55
- package/src/services/peer-manager/interface.ts +10 -1
- package/src/services/peer-manager/peer_manager.ts +441 -41
- package/src/services/reqresp/config.ts +3 -3
- package/src/services/reqresp/connection-sampler/connection_sampler.ts +38 -63
- package/src/services/reqresp/index.ts +2 -0
- package/src/services/reqresp/interface.ts +63 -17
- package/src/services/reqresp/protocols/auth.ts +83 -0
- package/src/services/reqresp/protocols/block.ts +24 -3
- package/src/services/reqresp/protocols/block_txs/bitvector.ts +90 -0
- package/src/services/reqresp/protocols/block_txs/block_txs_handler.ts +53 -0
- package/src/services/reqresp/protocols/block_txs/block_txs_reqresp.ts +79 -0
- package/src/services/reqresp/protocols/block_txs/index.ts +3 -0
- package/src/services/reqresp/protocols/goodbye.ts +3 -3
- package/src/services/reqresp/protocols/index.ts +2 -0
- package/src/services/reqresp/protocols/status.ts +20 -0
- package/src/services/reqresp/protocols/tx.ts +35 -6
- package/src/services/reqresp/rate-limiter/rate_limits.ts +20 -0
- package/src/services/reqresp/reqresp.ts +294 -264
- package/src/services/reqresp/status.ts +9 -3
- package/src/services/service.ts +23 -14
- package/src/services/tx_collection/config.ts +84 -0
- package/src/services/tx_collection/fast_tx_collection.ts +338 -0
- package/src/services/tx_collection/index.ts +2 -0
- package/src/services/tx_collection/instrumentation.ts +43 -0
- package/src/services/tx_collection/slow_tx_collection.ts +232 -0
- package/src/services/tx_collection/tx_collection.ts +214 -0
- package/src/services/tx_collection/tx_collection_sink.ts +98 -0
- package/src/services/tx_collection/tx_source.ts +37 -0
- package/src/services/tx_provider.ts +215 -0
- package/src/services/{tx_collect_instrumentation.ts → tx_provider_instrumentation.ts} +5 -5
- package/src/test-helpers/make-test-p2p-clients.ts +4 -2
- package/src/test-helpers/mock-pubsub.ts +1 -0
- package/src/test-helpers/reqresp-nodes.ts +7 -1
- package/src/testbench/p2p_client_testbench_worker.ts +9 -2
- package/src/util.ts +1 -1
- package/dest/services/tx_collect_instrumentation.d.ts.map +0 -1
- package/dest/services/tx_collector.d.ts +0 -23
- package/dest/services/tx_collector.d.ts.map +0 -1
- package/dest/services/tx_collector.js +0 -95
- package/src/services/tx_collector.ts +0 -134
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"memory_tx_pool.d.ts","sourceRoot":"","sources":["../../../src/mem_pools/tx_pool/memory_tx_pool.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"memory_tx_pool.d.ts","sourceRoot":"","sources":["../../../src/mem_pools/tx_pool/memory_tx_pool.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAEjE,OAAO,EAAE,WAAW,EAAE,EAAE,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAC3D,OAAO,EAAE,KAAK,eAAe,EAAsB,MAAM,yBAAyB,CAAC;AAMnF,OAAO,KAAK,EAAE,MAAM,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;mCAKnB,UAAU,iBAAiB,CAAC,YAAY,CAAC;AAH9F;;GAEG;AACH,qBAAa,cAAe,SAAQ,mBAA4D,YAAW,MAAM;IAgB7G,OAAO,CAAC,GAAG;IAfb;;OAEG;IACH,OAAO,CAAC,GAAG,CAAkB;IAC7B,OAAO,CAAC,QAAQ,CAAsB;IACtC,OAAO,CAAC,UAAU,CAAc;IAEhC,OAAO,CAAC,OAAO,CAA0B;IAEzC;;;OAGG;gBAED,SAAS,GAAE,eAAsC,EACzC,GAAG,yCAA8B;IAS3C,OAAO,CAAC,OAAO,CAOb;IAEK,OAAO,IAAI,OAAO,CAAC,OAAO,CAAC;IAI3B,WAAW,CAAC,QAAQ,EAAE,MAAM,EAAE,EAAE,WAAW,EAAE,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC;IASxE,kBAAkB,CAAC,QAAQ,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IAkB/C,kBAAkB,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC;IAQ7C,gBAAgB,IAAI,OAAO,CAAC,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE,CAAC;IAM/C,iBAAiB,IAAI,OAAO,CAAC,MAAM,CAAC;IAIpC,WAAW,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,SAAS,GAAG,OAAO,GAAG,SAAS,CAAC;IAW5E;;;;OAIG;IACI,WAAW,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,EAAE,GAAG,SAAS,CAAC;IAK3D,YAAY,CAAC,QAAQ,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,CAAC,EAAE,GAAG,SAAS,CAAC,EAAE,CAAC;IAG7D,MAAM,CAAC,QAAQ,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,OAAO,EAAE,CAAC;IAIvC,mBAAmB,IAAI,OAAO,CAAC,EAAE,GAAG,SAAS,CAAC;IAIrD;;;;OAIG;IACI,MAAM,CAAC,GAAG,EAAE,EAAE,EAAE,EAAE,IAAI,GAAE;QAAE,MAAM,CAAC,EAAE,MAAM,CAAA;KAAO,GAAG,OAAO,CAAC,MAAM,CAAC;IA0BzE;;;;OAIG;IACI,SAAS,CAAC,QAAQ,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IAWnD;;;OAGG;IACI,SAAS,IAAI,OAAO,CAAC,EAAE,EAAE,CAAC;IAIjC;;;OAGG;IACI,cAAc,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC;IAI1C,YAAY,CAAC,OAAO,EAAE,aAAa,GAAG,IAAI;IAE1C,qBAAqB,CAAC,CAAC,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;CAGlD"}
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { createLogger } from '@aztec/foundation/log';
|
|
2
2
|
import { Tx, TxHash } from '@aztec/stdlib/tx';
|
|
3
3
|
import { getTelemetryClient } from '@aztec/telemetry-client';
|
|
4
|
+
import EventEmitter from 'node:events';
|
|
4
5
|
import { PoolInstrumentation, PoolName } from '../instrumentation.js';
|
|
5
6
|
import { getPendingTxPriority } from './priority.js';
|
|
6
7
|
/**
|
|
7
8
|
* In-memory implementation of the Transaction Pool.
|
|
8
|
-
*/ export class InMemoryTxPool {
|
|
9
|
+
*/ export class InMemoryTxPool extends EventEmitter {
|
|
9
10
|
log;
|
|
10
11
|
/**
|
|
11
12
|
* Our tx pool, stored as a Map in-memory, with K: tx hash and V: the transaction.
|
|
@@ -17,8 +18,7 @@ import { getPendingTxPriority } from './priority.js';
|
|
|
17
18
|
* Class constructor for in-memory TxPool. Initiates our transaction pool as a JS Map.
|
|
18
19
|
* @param log - A logger.
|
|
19
20
|
*/ constructor(telemetry = getTelemetryClient(), log = createLogger('p2p:tx_pool')){
|
|
20
|
-
this.log = log
|
|
21
|
-
this.countTx = ()=>{
|
|
21
|
+
super(), this.log = log, this.countTx = ()=>{
|
|
22
22
|
return Promise.resolve({
|
|
23
23
|
itemCount: {
|
|
24
24
|
mined: this.minedTxs.size,
|
|
@@ -102,23 +102,31 @@ import { getPendingTxPriority } from './priority.js';
|
|
|
102
102
|
* Adds a list of transactions to the pool. Duplicates are ignored.
|
|
103
103
|
* @param txs - An array of txs to be added to the pool.
|
|
104
104
|
* @returns Empty promise.
|
|
105
|
-
*/
|
|
106
|
-
|
|
105
|
+
*/ addTxs(txs, opts = {}) {
|
|
106
|
+
const added = [];
|
|
107
107
|
for (const tx of txs){
|
|
108
|
-
const txHash =
|
|
108
|
+
const txHash = tx.getTxHash();
|
|
109
109
|
this.log.verbose(`Adding tx ${txHash.toString()} to pool`, {
|
|
110
110
|
eventName: 'tx-added-to-pool',
|
|
111
|
-
...
|
|
111
|
+
...tx.getStats()
|
|
112
112
|
});
|
|
113
113
|
const key = txHash.toBigInt();
|
|
114
|
-
this.txs.
|
|
114
|
+
if (!this.txs.has(key)) {
|
|
115
|
+
added.push(tx);
|
|
116
|
+
this.txs.set(key, tx);
|
|
117
|
+
}
|
|
115
118
|
if (!this.minedTxs.has(key)) {
|
|
116
|
-
pending++;
|
|
117
119
|
this.metrics.recordSize(tx);
|
|
118
120
|
this.pendingTxs.add(key);
|
|
119
121
|
}
|
|
120
122
|
}
|
|
121
|
-
|
|
123
|
+
if (added.length > 0) {
|
|
124
|
+
this.emit('txs-added', {
|
|
125
|
+
...opts,
|
|
126
|
+
txs: added
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
return Promise.resolve(added.length);
|
|
122
130
|
}
|
|
123
131
|
/**
|
|
124
132
|
* Deletes transactions from the pool. Tx hashes that are not present are ignored.
|
|
@@ -1,19 +1,28 @@
|
|
|
1
|
+
import type { TypedEventEmitter } from '@aztec/foundation/types';
|
|
1
2
|
import type { BlockHeader, Tx, TxHash } from '@aztec/stdlib/tx';
|
|
2
3
|
export type TxPoolOptions = {
|
|
3
4
|
maxTxPoolSize?: number;
|
|
4
5
|
txPoolOverflowFactor?: number;
|
|
5
6
|
archivedTxLimit?: number;
|
|
6
7
|
};
|
|
8
|
+
export type TxPoolEvents = {
|
|
9
|
+
['txs-added']: (args: {
|
|
10
|
+
txs: Tx[];
|
|
11
|
+
source?: string;
|
|
12
|
+
}) => void | Promise<void>;
|
|
13
|
+
};
|
|
7
14
|
/**
|
|
8
15
|
* Interface of a transaction pool. The pool includes tx requests and is kept up-to-date by a P2P client.
|
|
9
16
|
*/
|
|
10
|
-
export interface TxPool {
|
|
17
|
+
export interface TxPool extends TypedEventEmitter<TxPoolEvents> {
|
|
11
18
|
/**
|
|
12
19
|
* Adds a list of transactions to the pool. Duplicates are ignored.
|
|
13
20
|
* @param txs - An array of txs to be added to the pool.
|
|
14
21
|
* @returns The number of txs added to the pool. Note if the transaction already exists, it will not be added again.
|
|
15
22
|
*/
|
|
16
|
-
addTxs(txs: Tx[]
|
|
23
|
+
addTxs(txs: Tx[], opts?: {
|
|
24
|
+
source?: string;
|
|
25
|
+
}): Promise<number>;
|
|
17
26
|
/**
|
|
18
27
|
* Checks if a transaction exists in the pool and returns it.
|
|
19
28
|
* @param txHash - The hash of the transaction, used as an ID.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tx_pool.d.ts","sourceRoot":"","sources":["../../../src/mem_pools/tx_pool/tx_pool.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,EAAE,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAEhE,MAAM,MAAM,aAAa,GAAG;IAC1B,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,oBAAoB,CAAC,EAAE,MAAM,CAAC;IAC9B,eAAe,CAAC,EAAE,MAAM,CAAC;CAC1B,CAAC;AAEF;;GAEG;AACH,MAAM,WAAW,
|
|
1
|
+
{"version":3,"file":"tx_pool.d.ts","sourceRoot":"","sources":["../../../src/mem_pools/tx_pool/tx_pool.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AACjE,OAAO,KAAK,EAAE,WAAW,EAAE,EAAE,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAEhE,MAAM,MAAM,aAAa,GAAG;IAC1B,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,oBAAoB,CAAC,EAAE,MAAM,CAAC;IAC9B,eAAe,CAAC,EAAE,MAAM,CAAC;CAC1B,CAAC;AAEF,MAAM,MAAM,YAAY,GAAG;IACzB,CAAC,WAAW,CAAC,EAAE,CAAC,IAAI,EAAE;QAAE,GAAG,EAAE,EAAE,EAAE,CAAC;QAAC,MAAM,CAAC,EAAE,MAAM,CAAA;KAAE,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CAC/E,CAAC;AAEF;;GAEG;AACH,MAAM,WAAW,MAAO,SAAQ,iBAAiB,CAAC,YAAY,CAAC;IAC7D;;;;OAIG;IACH,MAAM,CAAC,GAAG,EAAE,EAAE,EAAE,EAAE,IAAI,CAAC,EAAE;QAAE,MAAM,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IAE/D;;;;OAIG;IACH,WAAW,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,EAAE,GAAG,SAAS,CAAC,CAAC;IAErD;;;;OAIG;IACH,YAAY,CAAC,QAAQ,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,CAAC,EAAE,GAAG,SAAS,CAAC,EAAE,CAAC,CAAC;IAE9D;;;;OAIG;IACH,MAAM,CAAC,QAAQ,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,OAAO,EAAE,CAAC,CAAC;IAE/C;;;;OAIG;IACH,mBAAmB,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,EAAE,GAAG,SAAS,CAAC,CAAC;IAE7D;;;;OAIG;IACH,WAAW,CAAC,QAAQ,EAAE,MAAM,EAAE,EAAE,WAAW,EAAE,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAEzE;;;;OAIG;IACH,kBAAkB,CAAC,QAAQ,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAEtD;;;OAGG;IACH,SAAS,CAAC,QAAQ,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAE7C;;;OAGG;IACH,SAAS,IAAI,OAAO,CAAC,EAAE,EAAE,CAAC,CAAC;IAE3B;;;OAGG;IACH,cAAc,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC;IAEpC;;;OAGG;IACH,kBAAkB,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC;IAExC,qDAAqD;IACrD,iBAAiB,IAAI,OAAO,CAAC,MAAM,CAAC,CAAC;IAErC;;;OAGG;IACH,gBAAgB,IAAI,OAAO,CAAC,CAAC,EAAE,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,CAAC,EAAE,CAAC,CAAC;IAEjE;;;;OAIG;IACH,WAAW,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,SAAS,GAAG,OAAO,GAAG,SAAS,CAAC,CAAC;IAEtE;;;OAGG;IACH,YAAY,CAAC,MAAM,EAAE,aAAa,GAAG,IAAI,CAAC;IAE1C,yCAAyC;IACzC,OAAO,IAAI,OAAO,CAAC,OAAO,CAAC,CAAC;IAE5B;;;OAGG;IACH,qBAAqB,CAAC,QAAQ,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CAC1D"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tx_pool_test_suite.d.ts","sourceRoot":"","sources":["../../../src/mem_pools/tx_pool/tx_pool_test_suite.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAE3C;;;GAGG;AACH,wBAAgB,cAAc,CAAC,SAAS,EAAE,MAAM,MAAM,
|
|
1
|
+
{"version":3,"file":"tx_pool_test_suite.d.ts","sourceRoot":"","sources":["../../../src/mem_pools/tx_pool/tx_pool_test_suite.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAE3C;;;GAGG;AACH,wBAAgB,cAAc,CAAC,SAAS,EAAE,MAAM,MAAM,QAkMrD"}
|
|
@@ -16,32 +16,61 @@ import { BlockHeader, GlobalVariables } from '@aztec/stdlib/tx';
|
|
|
16
16
|
beforeEach(()=>{
|
|
17
17
|
pool = getTxPool();
|
|
18
18
|
});
|
|
19
|
-
|
|
19
|
+
afterEach(()=>{
|
|
20
|
+
pool.removeAllListeners('txs-added');
|
|
21
|
+
});
|
|
22
|
+
it('adds txs to the pool as pending', async ()=>{
|
|
20
23
|
const tx1 = await mockTx();
|
|
21
24
|
await pool.addTxs([
|
|
22
25
|
tx1
|
|
23
26
|
]);
|
|
24
|
-
const poolTx = await pool.getTxByHash(
|
|
25
|
-
expect(
|
|
26
|
-
await expect(pool.getTxStatus(
|
|
27
|
+
const poolTx = await pool.getTxByHash(tx1.getTxHash());
|
|
28
|
+
expect(poolTx.getTxHash()).toEqual(tx1.getTxHash());
|
|
29
|
+
await expect(pool.getTxStatus(tx1.getTxHash())).resolves.toEqual('pending');
|
|
27
30
|
await expect(pool.getPendingTxHashes()).resolves.toEqual([
|
|
28
|
-
|
|
31
|
+
tx1.getTxHash()
|
|
29
32
|
]);
|
|
30
33
|
await expect(pool.getPendingTxCount()).resolves.toEqual(1);
|
|
31
34
|
});
|
|
32
|
-
it('
|
|
35
|
+
it('emits txs-added event with new txs', async ()=>{
|
|
36
|
+
const tx1 = await mockTx(); // existing and pending
|
|
37
|
+
const tx2 = await mockTx(); // mined but not known
|
|
38
|
+
const tx3 = await mockTx(); // brand new
|
|
39
|
+
await pool.addTxs([
|
|
40
|
+
tx1
|
|
41
|
+
]);
|
|
42
|
+
await pool.markAsMined([
|
|
43
|
+
tx2.getTxHash()
|
|
44
|
+
], minedBlockHeader);
|
|
45
|
+
let txsFromEvent = undefined;
|
|
46
|
+
pool.once('txs-added', ({ txs })=>{
|
|
47
|
+
txsFromEvent = txs;
|
|
48
|
+
});
|
|
49
|
+
await pool.addTxs([
|
|
50
|
+
tx1,
|
|
51
|
+
tx2,
|
|
52
|
+
tx3
|
|
53
|
+
]);
|
|
54
|
+
expect(txsFromEvent).toBeDefined();
|
|
55
|
+
expect(txsFromEvent).toHaveLength(2);
|
|
56
|
+
expect(txsFromEvent).toEqual(expect.arrayContaining([
|
|
57
|
+
tx2,
|
|
58
|
+
tx3
|
|
59
|
+
]));
|
|
60
|
+
});
|
|
61
|
+
it('removes txs from the pool', async ()=>{
|
|
33
62
|
const tx1 = await mockTx();
|
|
34
63
|
await pool.addTxs([
|
|
35
64
|
tx1
|
|
36
65
|
]);
|
|
37
66
|
await pool.deleteTxs([
|
|
38
|
-
|
|
67
|
+
tx1.getTxHash()
|
|
39
68
|
]);
|
|
40
|
-
await expect(pool.getTxByHash(
|
|
41
|
-
await expect(pool.getTxStatus(
|
|
69
|
+
await expect(pool.getTxByHash(tx1.getTxHash())).resolves.toBeFalsy();
|
|
70
|
+
await expect(pool.getTxStatus(tx1.getTxHash())).resolves.toBeUndefined();
|
|
42
71
|
await expect(pool.getPendingTxCount()).resolves.toEqual(0);
|
|
43
72
|
});
|
|
44
|
-
it('
|
|
73
|
+
it('marks txs as mined', async ()=>{
|
|
45
74
|
const tx1 = await mockTx(1);
|
|
46
75
|
const tx2 = await mockTx(2);
|
|
47
76
|
await pool.addTxs([
|
|
@@ -49,22 +78,22 @@ import { BlockHeader, GlobalVariables } from '@aztec/stdlib/tx';
|
|
|
49
78
|
tx2
|
|
50
79
|
]);
|
|
51
80
|
await pool.markAsMined([
|
|
52
|
-
|
|
81
|
+
tx1.getTxHash()
|
|
53
82
|
], minedBlockHeader);
|
|
54
|
-
await expect(pool.getTxByHash(
|
|
55
|
-
await expect(pool.getTxStatus(
|
|
83
|
+
await expect(pool.getTxByHash(tx1.getTxHash())).resolves.toEqual(tx1);
|
|
84
|
+
await expect(pool.getTxStatus(tx1.getTxHash())).resolves.toEqual('mined');
|
|
56
85
|
await expect(pool.getMinedTxHashes()).resolves.toEqual([
|
|
57
86
|
[
|
|
58
|
-
|
|
87
|
+
tx1.getTxHash(),
|
|
59
88
|
1
|
|
60
89
|
]
|
|
61
90
|
]);
|
|
62
91
|
await expect(pool.getPendingTxHashes()).resolves.toEqual([
|
|
63
|
-
|
|
92
|
+
tx2.getTxHash()
|
|
64
93
|
]);
|
|
65
94
|
await expect(pool.getPendingTxCount()).resolves.toEqual(1);
|
|
66
95
|
});
|
|
67
|
-
it('
|
|
96
|
+
it('marks txs as pending after being mined', async ()=>{
|
|
68
97
|
const tx1 = await mockTx(1);
|
|
69
98
|
const tx2 = await mockTx(2);
|
|
70
99
|
await pool.addTxs([
|
|
@@ -72,36 +101,36 @@ import { BlockHeader, GlobalVariables } from '@aztec/stdlib/tx';
|
|
|
72
101
|
tx2
|
|
73
102
|
]);
|
|
74
103
|
await pool.markAsMined([
|
|
75
|
-
|
|
104
|
+
tx1.getTxHash()
|
|
76
105
|
], minedBlockHeader);
|
|
77
106
|
await pool.markMinedAsPending([
|
|
78
|
-
|
|
107
|
+
tx1.getTxHash()
|
|
79
108
|
]);
|
|
80
109
|
await expect(pool.getMinedTxHashes()).resolves.toEqual([]);
|
|
81
110
|
const pending = await pool.getPendingTxHashes();
|
|
82
111
|
expect(pending).toHaveLength(2);
|
|
83
112
|
expect(pending).toEqual(expect.arrayContaining([
|
|
84
|
-
|
|
85
|
-
|
|
113
|
+
tx1.getTxHash(),
|
|
114
|
+
tx2.getTxHash()
|
|
86
115
|
]));
|
|
87
116
|
await expect(pool.getPendingTxCount()).resolves.toEqual(2);
|
|
88
117
|
});
|
|
89
|
-
it('
|
|
118
|
+
it('only marks txs as pending if they are known', async ()=>{
|
|
90
119
|
const tx1 = await mockTx(1);
|
|
91
120
|
// simulate a situation where not all peers have all the txs
|
|
92
121
|
const tx2 = await mockTx(2);
|
|
93
|
-
const someTxHashThatThisPeerDidNotSee =
|
|
122
|
+
const someTxHashThatThisPeerDidNotSee = tx2.getTxHash();
|
|
94
123
|
await pool.addTxs([
|
|
95
124
|
tx1
|
|
96
125
|
]);
|
|
97
126
|
// this peer knows that tx2 was mined, but it does not have the tx object
|
|
98
127
|
await pool.markAsMined([
|
|
99
|
-
|
|
128
|
+
tx1.getTxHash(),
|
|
100
129
|
someTxHashThatThisPeerDidNotSee
|
|
101
130
|
], minedBlockHeader);
|
|
102
131
|
expect(await pool.getMinedTxHashes()).toEqual(expect.arrayContaining([
|
|
103
132
|
[
|
|
104
|
-
|
|
133
|
+
tx1.getTxHash(),
|
|
105
134
|
1
|
|
106
135
|
],
|
|
107
136
|
[
|
|
@@ -111,16 +140,16 @@ import { BlockHeader, GlobalVariables } from '@aztec/stdlib/tx';
|
|
|
111
140
|
]));
|
|
112
141
|
// reorg: both txs should now become available again
|
|
113
142
|
await pool.markMinedAsPending([
|
|
114
|
-
|
|
143
|
+
tx1.getTxHash(),
|
|
115
144
|
someTxHashThatThisPeerDidNotSee
|
|
116
145
|
]);
|
|
117
146
|
await expect(pool.getMinedTxHashes()).resolves.toEqual([]);
|
|
118
147
|
await expect(pool.getPendingTxHashes()).resolves.toEqual([
|
|
119
|
-
|
|
148
|
+
tx1.getTxHash()
|
|
120
149
|
]); // tx2 is not in the pool
|
|
121
150
|
await expect(pool.getPendingTxCount()).resolves.toEqual(1);
|
|
122
151
|
});
|
|
123
|
-
it('
|
|
152
|
+
it('returns all transactions in the pool', async ()=>{
|
|
124
153
|
const tx1 = await mockTx(1);
|
|
125
154
|
const tx2 = await mockTx(2);
|
|
126
155
|
const tx3 = await mockTx(3);
|
|
@@ -138,7 +167,7 @@ import { BlockHeader, GlobalVariables } from '@aztec/stdlib/tx';
|
|
|
138
167
|
]));
|
|
139
168
|
await expect(pool.getPendingTxCount()).resolves.toEqual(3);
|
|
140
169
|
});
|
|
141
|
-
it('
|
|
170
|
+
it('returns all txHashes in the pool', async ()=>{
|
|
142
171
|
const tx1 = await mockTx(1);
|
|
143
172
|
const tx2 = await mockTx(2);
|
|
144
173
|
const tx3 = await mockTx(3);
|
|
@@ -148,16 +177,16 @@ import { BlockHeader, GlobalVariables } from '@aztec/stdlib/tx';
|
|
|
148
177
|
tx3
|
|
149
178
|
]);
|
|
150
179
|
const poolTxHashes = await pool.getAllTxHashes();
|
|
151
|
-
const expectedHashes =
|
|
180
|
+
const expectedHashes = [
|
|
152
181
|
tx1,
|
|
153
182
|
tx2,
|
|
154
183
|
tx3
|
|
155
|
-
].map((tx)=>tx.getTxHash())
|
|
184
|
+
].map((tx)=>tx.getTxHash());
|
|
156
185
|
expect(poolTxHashes).toHaveLength(3);
|
|
157
186
|
expect(poolTxHashes).toEqual(expect.arrayContaining(expectedHashes));
|
|
158
187
|
await expect(pool.getPendingTxCount()).resolves.toEqual(3);
|
|
159
188
|
});
|
|
160
|
-
it('
|
|
189
|
+
it('returns txs by their hash', async ()=>{
|
|
161
190
|
const tx1 = await mockTx(1);
|
|
162
191
|
const tx2 = await mockTx(2);
|
|
163
192
|
const tx3 = await mockTx(3);
|
|
@@ -167,8 +196,8 @@ import { BlockHeader, GlobalVariables } from '@aztec/stdlib/tx';
|
|
|
167
196
|
tx3
|
|
168
197
|
]);
|
|
169
198
|
const requestedTxs = await pool.getTxsByHash([
|
|
170
|
-
|
|
171
|
-
|
|
199
|
+
tx1.getTxHash(),
|
|
200
|
+
tx3.getTxHash()
|
|
172
201
|
]);
|
|
173
202
|
expect(requestedTxs).toHaveLength(2);
|
|
174
203
|
expect(requestedTxs).toEqual(expect.arrayContaining([
|
|
@@ -176,18 +205,18 @@ import { BlockHeader, GlobalVariables } from '@aztec/stdlib/tx';
|
|
|
176
205
|
tx3
|
|
177
206
|
]));
|
|
178
207
|
});
|
|
179
|
-
it('
|
|
208
|
+
it('returns a large number of transactions by their hash', async ()=>{
|
|
180
209
|
const numTxs = 1000;
|
|
181
210
|
const txs = await Promise.all(Array.from({
|
|
182
211
|
length: numTxs
|
|
183
212
|
}, (_, i)=>mockTx(i)));
|
|
184
|
-
const hashes =
|
|
213
|
+
const hashes = txs.map((tx)=>tx.getTxHash());
|
|
185
214
|
await pool.addTxs(txs);
|
|
186
215
|
const requestedTxs = await pool.getTxsByHash(hashes);
|
|
187
216
|
expect(requestedTxs).toHaveLength(numTxs);
|
|
188
217
|
expect(requestedTxs).toEqual(expect.arrayContaining(txs));
|
|
189
218
|
});
|
|
190
|
-
it('
|
|
219
|
+
it('returns whether or not txs exist', async ()=>{
|
|
191
220
|
const tx1 = await mockTx(1);
|
|
192
221
|
const tx2 = await mockTx(2);
|
|
193
222
|
const tx3 = await mockTx(3);
|
|
@@ -199,11 +228,11 @@ import { BlockHeader, GlobalVariables } from '@aztec/stdlib/tx';
|
|
|
199
228
|
const tx4 = await mockTx(4);
|
|
200
229
|
const tx5 = await mockTx(5);
|
|
201
230
|
const availability = await pool.hasTxs([
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
231
|
+
tx1.getTxHash(),
|
|
232
|
+
tx2.getTxHash(),
|
|
233
|
+
tx3.getTxHash(),
|
|
234
|
+
tx4.getTxHash(),
|
|
235
|
+
tx5.getTxHash()
|
|
207
236
|
]);
|
|
208
237
|
expect(availability).toHaveLength(5);
|
|
209
238
|
expect(availability).toEqual(expect.arrayContaining([
|
|
@@ -214,7 +243,7 @@ import { BlockHeader, GlobalVariables } from '@aztec/stdlib/tx';
|
|
|
214
243
|
false
|
|
215
244
|
]));
|
|
216
245
|
});
|
|
217
|
-
it('
|
|
246
|
+
it('returns pending tx hashes sorted by priority', async ()=>{
|
|
218
247
|
const withPriorityFee = (tx, fee)=>{
|
|
219
248
|
unfreeze(tx.data.constants.txContext.gasSettings).maxPriorityFeesPerGas = new GasFees(fee, fee);
|
|
220
249
|
return tx;
|
|
@@ -231,11 +260,11 @@ import { BlockHeader, GlobalVariables } from '@aztec/stdlib/tx';
|
|
|
231
260
|
]);
|
|
232
261
|
const poolTxHashes = await pool.getPendingTxHashes();
|
|
233
262
|
expect(poolTxHashes).toHaveLength(4);
|
|
234
|
-
expect(poolTxHashes).toEqual(
|
|
263
|
+
expect(poolTxHashes).toEqual([
|
|
235
264
|
tx4,
|
|
236
265
|
tx1,
|
|
237
266
|
tx3,
|
|
238
267
|
tx2
|
|
239
|
-
].map((tx)=>tx.getTxHash()))
|
|
268
|
+
].map((tx)=>tx.getTxHash()));
|
|
240
269
|
});
|
|
241
270
|
}
|
|
@@ -13,7 +13,7 @@ export class AttestationValidator {
|
|
|
13
13
|
return PeerErrorSeverity.HighToleranceError;
|
|
14
14
|
}
|
|
15
15
|
const attester = message.getSender();
|
|
16
|
-
if (!await this.epochCache.isInCommittee(attester)) {
|
|
16
|
+
if (!await this.epochCache.isInCommittee(slotNumberBigInt, attester)) {
|
|
17
17
|
return PeerErrorSeverity.HighToleranceError;
|
|
18
18
|
}
|
|
19
19
|
return undefined;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"block_header_validator.d.ts","sourceRoot":"","sources":["../../../src/msg_validators/tx_validator/block_header_validator.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,0BAA0B,CAAC;AAEnD,OAAO,EAAE,KAAK,KAAK,
|
|
1
|
+
{"version":3,"file":"block_header_validator.d.ts","sourceRoot":"","sources":["../../../src/msg_validators/tx_validator/block_header_validator.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,0BAA0B,CAAC;AAEnD,OAAO,EAAE,KAAK,KAAK,EAAyB,KAAK,kBAAkB,EAAE,KAAK,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAEhH,MAAM,WAAW,aAAa;IAC5B,iBAAiB,EAAE,CAAC,QAAQ,EAAE,EAAE,EAAE,KAAK,OAAO,CAAC,CAAC,MAAM,GAAG,SAAS,CAAC,EAAE,CAAC,CAAC;CACxE;AAED,qBAAa,sBAAsB,CAAC,CAAC,SAAS,KAAK,CAAE,YAAW,WAAW,CAAC,CAAC,CAAC;;gBAIhE,aAAa,EAAE,aAAa;IAIlC,UAAU,CAAC,EAAE,EAAE,CAAC,GAAG,OAAO,CAAC,kBAAkB,CAAC;CAQrD"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { createLogger } from '@aztec/foundation/log';
|
|
2
|
-
import { TX_ERROR_BLOCK_HEADER
|
|
2
|
+
import { TX_ERROR_BLOCK_HEADER } from '@aztec/stdlib/tx';
|
|
3
3
|
export class BlockHeaderTxValidator {
|
|
4
4
|
#log = createLogger('p2p:tx_validator:tx_block_header');
|
|
5
5
|
#archiveSource;
|
|
@@ -11,7 +11,7 @@ export class BlockHeaderTxValidator {
|
|
|
11
11
|
await tx.data.constants.historicalHeader.hash()
|
|
12
12
|
]);
|
|
13
13
|
if (index === undefined) {
|
|
14
|
-
this.#log.verbose(`Rejecting tx ${
|
|
14
|
+
this.#log.verbose(`Rejecting tx ${'txHash' in tx ? tx.txHash : tx.hash} for referencing an unknown block header`);
|
|
15
15
|
return {
|
|
16
16
|
result: 'invalid',
|
|
17
17
|
reason: [
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"data_validator.d.ts","sourceRoot":"","sources":["../../../src/msg_validators/tx_validator/data_validator.ts"],"names":[],"mappings":"AAGA,OAAO,
|
|
1
|
+
{"version":3,"file":"data_validator.d.ts","sourceRoot":"","sources":["../../../src/msg_validators/tx_validator/data_validator.ts"],"names":[],"mappings":"AAGA,OAAO,EASL,EAAE,EACF,KAAK,kBAAkB,EACvB,KAAK,WAAW,EACjB,MAAM,kBAAkB,CAAC;AAE1B,qBAAa,eAAgB,YAAW,WAAW,CAAC,EAAE,CAAC;;IAG/C,UAAU,CAAC,EAAE,EAAE,EAAE,GAAG,OAAO,CAAC,kBAAkB,CAAC;CAiGtD"}
|
|
@@ -1,34 +1,39 @@
|
|
|
1
1
|
import { MAX_FR_CALLDATA_TO_ALL_ENQUEUED_CALLS } from '@aztec/constants';
|
|
2
2
|
import { createLogger } from '@aztec/foundation/log';
|
|
3
3
|
import { computeCalldataHash } from '@aztec/stdlib/hash';
|
|
4
|
-
import { TX_ERROR_CALLDATA_COUNT_MISMATCH, TX_ERROR_CALLDATA_COUNT_TOO_LARGE, TX_ERROR_CONTRACT_CLASS_LOGS, TX_ERROR_CONTRACT_CLASS_LOG_COUNT, TX_ERROR_CONTRACT_CLASS_LOG_LENGTH, TX_ERROR_CONTRACT_CLASS_LOG_SORTING, TX_ERROR_INCORRECT_CALLDATA, Tx } from '@aztec/stdlib/tx';
|
|
4
|
+
import { TX_ERROR_CALLDATA_COUNT_MISMATCH, TX_ERROR_CALLDATA_COUNT_TOO_LARGE, TX_ERROR_CONTRACT_CLASS_LOGS, TX_ERROR_CONTRACT_CLASS_LOG_COUNT, TX_ERROR_CONTRACT_CLASS_LOG_LENGTH, TX_ERROR_CONTRACT_CLASS_LOG_SORTING, TX_ERROR_INCORRECT_CALLDATA, TX_ERROR_INCORRECT_HASH, Tx } from '@aztec/stdlib/tx';
|
|
5
5
|
export class DataTxValidator {
|
|
6
6
|
#log = createLogger('p2p:tx_validator:tx_data');
|
|
7
7
|
async validateTx(tx) {
|
|
8
|
-
const
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
const reason = await this.#hasCorrectHash(tx) ?? await this.#hasCorrectCalldata(tx) ?? await this.#hasCorrectContractClassLogs(tx);
|
|
9
|
+
return reason ? {
|
|
10
|
+
result: 'invalid',
|
|
11
|
+
reason: [
|
|
12
|
+
reason
|
|
13
|
+
]
|
|
14
|
+
} : {
|
|
15
|
+
result: 'valid'
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
async #hasCorrectHash(tx) {
|
|
19
|
+
const expected = await Tx.computeTxHash(tx);
|
|
20
|
+
if (!tx.getTxHash().equals(expected)) {
|
|
21
|
+
const reason = TX_ERROR_INCORRECT_HASH;
|
|
22
|
+
this.#log.verbose(`Rejecting tx ${tx.getTxHash().toString()}. Reason: ${reason}. Expected hash ${expected.toString()}. Got ${tx.getTxHash().toString()}.`);
|
|
23
|
+
return reason;
|
|
24
|
+
}
|
|
25
|
+
return undefined;
|
|
11
26
|
}
|
|
12
27
|
async #hasCorrectCalldata(tx) {
|
|
13
28
|
if (tx.publicFunctionCalldata.length !== tx.numberOfPublicCalls()) {
|
|
14
29
|
const reason = TX_ERROR_CALLDATA_COUNT_MISMATCH;
|
|
15
|
-
this.#log.verbose(`Rejecting tx ${
|
|
16
|
-
return
|
|
17
|
-
result: 'invalid',
|
|
18
|
-
reason: [
|
|
19
|
-
reason
|
|
20
|
-
]
|
|
21
|
-
};
|
|
30
|
+
this.#log.verbose(`Rejecting tx ${tx.getTxHash().toString()}. Reason: ${reason}. Expected ${tx.numberOfPublicCalls()}. Got ${tx.publicFunctionCalldata.length}.`);
|
|
31
|
+
return reason;
|
|
22
32
|
}
|
|
23
33
|
if (tx.getTotalPublicCalldataCount() > MAX_FR_CALLDATA_TO_ALL_ENQUEUED_CALLS) {
|
|
24
34
|
const reason = TX_ERROR_CALLDATA_COUNT_TOO_LARGE;
|
|
25
|
-
this.#log.verbose(`Rejecting tx ${
|
|
26
|
-
return
|
|
27
|
-
result: 'invalid',
|
|
28
|
-
reason: [
|
|
29
|
-
reason
|
|
30
|
-
]
|
|
31
|
-
};
|
|
35
|
+
this.#log.verbose(`Rejecting tx ${tx.getTxHash().toString()}. Reason: ${reason}. Expected no greater than ${MAX_FR_CALLDATA_TO_ALL_ENQUEUED_CALLS} fields. Got ${tx.getTotalPublicCalldataCount()}.`);
|
|
36
|
+
return reason;
|
|
32
37
|
}
|
|
33
38
|
const callRequests = tx.getPublicCallRequestsWithCalldata();
|
|
34
39
|
for(let i = 0; i < callRequests.length; i++){
|
|
@@ -36,29 +41,17 @@ export class DataTxValidator {
|
|
|
36
41
|
const hash = await computeCalldataHash(calldata);
|
|
37
42
|
if (!hash.equals(request.calldataHash)) {
|
|
38
43
|
const reason = TX_ERROR_INCORRECT_CALLDATA;
|
|
39
|
-
this.#log.verbose(`Rejecting tx ${
|
|
40
|
-
return
|
|
41
|
-
result: 'invalid',
|
|
42
|
-
reason: [
|
|
43
|
-
reason
|
|
44
|
-
]
|
|
45
|
-
};
|
|
44
|
+
this.#log.verbose(`Rejecting tx ${tx.getTxHash().toString()}. Reason: ${reason}. Call request index: ${i}.`);
|
|
45
|
+
return reason;
|
|
46
46
|
}
|
|
47
47
|
}
|
|
48
|
-
return
|
|
49
|
-
result: 'valid'
|
|
50
|
-
};
|
|
48
|
+
return undefined;
|
|
51
49
|
}
|
|
52
50
|
async #hasCorrectContractClassLogs(tx) {
|
|
53
51
|
const contractClassLogsHashes = tx.data.getNonEmptyContractClassLogsHashes();
|
|
54
52
|
if (contractClassLogsHashes.length !== tx.contractClassLogFields.length) {
|
|
55
|
-
this.#log.verbose(`Rejecting tx ${
|
|
56
|
-
return
|
|
57
|
-
result: 'invalid',
|
|
58
|
-
reason: [
|
|
59
|
-
TX_ERROR_CONTRACT_CLASS_LOG_COUNT
|
|
60
|
-
]
|
|
61
|
-
};
|
|
53
|
+
this.#log.verbose(`Rejecting tx ${tx.getTxHash().toString()} because of mismatched number of contract class logs. Expected ${contractClassLogsHashes.length}. Got ${tx.contractClassLogFields.length}.`);
|
|
54
|
+
return TX_ERROR_CONTRACT_CLASS_LOG_COUNT;
|
|
62
55
|
}
|
|
63
56
|
const expectedHashes = await Promise.all(tx.contractClassLogFields.map((l)=>l.hash()));
|
|
64
57
|
for (const [i, logHash] of contractClassLogsHashes.entries()){
|
|
@@ -66,36 +59,19 @@ export class DataTxValidator {
|
|
|
66
59
|
if (!logHash.value.equals(hash)) {
|
|
67
60
|
if (expectedHashes.some((h)=>logHash.value.equals(h))) {
|
|
68
61
|
const matchingLogIndex = expectedHashes.findIndex((l)=>logHash.value.equals(l));
|
|
69
|
-
this.#log.verbose(`Rejecting tx ${
|
|
70
|
-
return
|
|
71
|
-
result: 'invalid',
|
|
72
|
-
reason: [
|
|
73
|
-
TX_ERROR_CONTRACT_CLASS_LOG_SORTING
|
|
74
|
-
]
|
|
75
|
-
};
|
|
62
|
+
this.#log.verbose(`Rejecting tx ${tx.getTxHash().toString()} because of mismatched contract class logs indices. Expected ${i} from the kernel's log hashes. Got ${matchingLogIndex} in the tx.`);
|
|
63
|
+
return TX_ERROR_CONTRACT_CLASS_LOG_SORTING;
|
|
76
64
|
} else {
|
|
77
|
-
this.#log.verbose(`Rejecting tx ${
|
|
78
|
-
return
|
|
79
|
-
result: 'invalid',
|
|
80
|
-
reason: [
|
|
81
|
-
TX_ERROR_CONTRACT_CLASS_LOGS
|
|
82
|
-
]
|
|
83
|
-
};
|
|
65
|
+
this.#log.verbose(`Rejecting tx ${tx.getTxHash().toString()} because of mismatched contract class logs. Expected hash ${logHash.value} from the kernels. Got ${hash} in the tx.`);
|
|
66
|
+
return TX_ERROR_CONTRACT_CLASS_LOGS;
|
|
84
67
|
}
|
|
85
68
|
}
|
|
86
69
|
const expectedMinLength = 1 + tx.contractClassLogFields[i].fields.findLastIndex((f)=>!f.isZero());
|
|
87
70
|
if (logHash.logHash.length < expectedMinLength) {
|
|
88
|
-
this.#log.verbose(`Rejecting tx ${
|
|
89
|
-
return
|
|
90
|
-
result: 'invalid',
|
|
91
|
-
reason: [
|
|
92
|
-
TX_ERROR_CONTRACT_CLASS_LOG_LENGTH
|
|
93
|
-
]
|
|
94
|
-
};
|
|
71
|
+
this.#log.verbose(`Rejecting tx ${tx.getTxHash().toString()} because of incorrect contract class log length. Expected the length to be at least ${expectedMinLength}. Got ${logHash.logHash.length}.`);
|
|
72
|
+
return TX_ERROR_CONTRACT_CLASS_LOG_LENGTH;
|
|
95
73
|
}
|
|
96
74
|
}
|
|
97
|
-
return
|
|
98
|
-
result: 'valid'
|
|
99
|
-
};
|
|
75
|
+
return undefined;
|
|
100
76
|
}
|
|
101
77
|
}
|
|
@@ -11,7 +11,7 @@ export class DoubleSpendTxValidator {
|
|
|
11
11
|
// Ditch this tx if it has repeated nullifiers
|
|
12
12
|
const uniqueNullifiers = new Set(nullifiers);
|
|
13
13
|
if (uniqueNullifiers.size !== nullifiers.length) {
|
|
14
|
-
this.#log.verbose(`Rejecting tx ${
|
|
14
|
+
this.#log.verbose(`Rejecting tx ${'txHash' in tx ? tx.txHash : tx.hash} for emitting duplicate nullifiers`);
|
|
15
15
|
return {
|
|
16
16
|
result: 'invalid',
|
|
17
17
|
reason: [
|
|
@@ -20,7 +20,7 @@ export class DoubleSpendTxValidator {
|
|
|
20
20
|
};
|
|
21
21
|
}
|
|
22
22
|
if ((await this.#nullifierSource.nullifiersExist(nullifiers.map((n)=>n.toBuffer()))).some(Boolean)) {
|
|
23
|
-
this.#log.verbose(`Rejecting tx ${
|
|
23
|
+
this.#log.verbose(`Rejecting tx ${'txHash' in tx ? tx.txHash : tx.hash} for repeating a nullifier`);
|
|
24
24
|
return {
|
|
25
25
|
result: 'invalid',
|
|
26
26
|
reason: [
|
|
@@ -20,7 +20,7 @@ export class GasTxValidator {
|
|
|
20
20
|
if (gasLimitValidation.result === 'invalid') {
|
|
21
21
|
return Promise.resolve(gasLimitValidation);
|
|
22
22
|
}
|
|
23
|
-
if (
|
|
23
|
+
if (this.#shouldSkip(tx)) {
|
|
24
24
|
return Promise.resolve({
|
|
25
25
|
result: 'skipped',
|
|
26
26
|
reason: [
|
|
@@ -28,20 +28,20 @@ export class GasTxValidator {
|
|
|
28
28
|
]
|
|
29
29
|
});
|
|
30
30
|
}
|
|
31
|
-
return this.validateTxFee(tx);
|
|
31
|
+
return await this.validateTxFee(tx);
|
|
32
32
|
}
|
|
33
33
|
/**
|
|
34
34
|
* Check whether the tx's max fees are valid for the current block, and skip if not.
|
|
35
35
|
* We skip instead of invalidating since the tx may become eligible later.
|
|
36
36
|
* Note that circuits check max fees even if fee payer is unset, so we
|
|
37
37
|
* keep this validation even if the tx does not pay fees.
|
|
38
|
-
*/
|
|
38
|
+
*/ #shouldSkip(tx) {
|
|
39
39
|
const gasSettings = tx.data.constants.txContext.gasSettings;
|
|
40
40
|
// Skip the tx if its max fees are not enough for the current block's gas fees.
|
|
41
41
|
const maxFeesPerGas = gasSettings.maxFeesPerGas;
|
|
42
42
|
const notEnoughMaxFees = maxFeesPerGas.feePerDaGas < this.#gasFees.feePerDaGas || maxFeesPerGas.feePerL2Gas < this.#gasFees.feePerL2Gas;
|
|
43
43
|
if (notEnoughMaxFees) {
|
|
44
|
-
this.#log.verbose(`Skipping transaction ${
|
|
44
|
+
this.#log.verbose(`Skipping transaction ${tx.getTxHash().toString()} due to insufficient fee per gas`, {
|
|
45
45
|
txMaxFeesPerGas: maxFeesPerGas.toInspect(),
|
|
46
46
|
currentGasFees: this.#gasFees.toInspect()
|
|
47
47
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"metadata_validator.d.ts","sourceRoot":"","sources":["../../../src/msg_validators/tx_validator/metadata_validator.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,0BAA0B,CAAC;AAEnD,OAAO,EACL,KAAK,KAAK,
|
|
1
|
+
{"version":3,"file":"metadata_validator.d.ts","sourceRoot":"","sources":["../../../src/msg_validators/tx_validator/metadata_validator.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,0BAA0B,CAAC;AAEnD,OAAO,EACL,KAAK,KAAK,EAMV,KAAK,kBAAkB,EACvB,KAAK,WAAW,EAEjB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAElD,qBAAa,mBAAmB,CAAC,CAAC,SAAS,KAAK,CAAE,YAAW,WAAW,CAAC,CAAC,CAAC;;IAIvE,OAAO,CAAC,MAAM;gBAAN,MAAM,EAAE;QACd,SAAS,EAAE,EAAE,CAAC;QACd,aAAa,EAAE,EAAE,CAAC;QAGlB,SAAS,EAAE,MAAM,CAAC;QAElB,WAAW,EAAE,MAAM,CAAC;QACpB,UAAU,EAAE,EAAE,CAAC;QACf,wBAAwB,EAAE,EAAE,CAAC;KAC9B;IAGH,UAAU,CAAC,EAAE,EAAE,CAAC,GAAG,OAAO,CAAC,kBAAkB,CAAC;CAsF/C"}
|