@aztec/p2p 0.87.6 → 0.87.8
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 +1 -1
- package/dest/client/interface.d.ts.map +1 -1
- package/dest/client/p2p_client.d.ts +2 -2
- package/dest/client/p2p_client.d.ts.map +1 -1
- package/dest/client/p2p_client.js +3 -3
- 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 +0 -9
- package/dest/mem_pools/attestation_pool/kv_attestation_pool.d.ts +1 -0
- package/dest/mem_pools/attestation_pool/kv_attestation_pool.d.ts.map +1 -1
- package/dest/mem_pools/attestation_pool/kv_attestation_pool.js +13 -8
- package/dest/mem_pools/attestation_pool/memory_attestation_pool.d.ts +1 -0
- package/dest/mem_pools/attestation_pool/memory_attestation_pool.d.ts.map +1 -1
- package/dest/mem_pools/attestation_pool/memory_attestation_pool.js +7 -6
- package/dest/mem_pools/instrumentation.d.ts +7 -11
- package/dest/mem_pools/instrumentation.d.ts.map +1 -1
- package/dest/mem_pools/instrumentation.js +25 -37
- package/dest/mem_pools/tx_pool/aztec_kv_tx_pool.d.ts +2 -1
- 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 +22 -38
- package/dest/mem_pools/tx_pool/memory_tx_pool.d.ts +1 -0
- package/dest/mem_pools/tx_pool/memory_tx_pool.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool/memory_tx_pool.js +13 -21
- package/dest/services/encoding.d.ts +2 -0
- package/dest/services/encoding.d.ts.map +1 -1
- package/dest/services/encoding.js +9 -1
- package/dest/services/libp2p/instrumentation.d.ts +11 -0
- package/dest/services/libp2p/instrumentation.d.ts.map +1 -0
- package/dest/services/libp2p/instrumentation.js +29 -0
- package/dest/services/libp2p/libp2p_service.d.ts +3 -2
- package/dest/services/libp2p/libp2p_service.d.ts.map +1 -1
- package/dest/services/libp2p/libp2p_service.js +30 -17
- 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 +9 -5
- package/dest/services/tx_collect_instrumentation.d.ts +13 -0
- package/dest/services/tx_collect_instrumentation.d.ts.map +1 -0
- package/dest/services/tx_collect_instrumentation.js +34 -0
- package/dest/services/tx_collector.d.ts +6 -2
- package/dest/services/tx_collector.d.ts.map +1 -1
- package/dest/services/tx_collector.js +65 -50
- package/dest/test-helpers/reqresp-nodes.d.ts +2 -0
- package/dest/test-helpers/reqresp-nodes.d.ts.map +1 -1
- package/dest/test-helpers/reqresp-nodes.js +6 -0
- package/package.json +12 -12
- package/src/client/interface.ts +1 -1
- package/src/client/p2p_client.ts +3 -3
- package/src/mem_pools/attestation_pool/attestation_pool_test_suite.ts +0 -14
- package/src/mem_pools/attestation_pool/kv_attestation_pool.ts +17 -12
- package/src/mem_pools/attestation_pool/memory_attestation_pool.ts +8 -7
- package/src/mem_pools/instrumentation.ts +32 -46
- package/src/mem_pools/tx_pool/aztec_kv_tx_pool.ts +23 -58
- package/src/mem_pools/tx_pool/memory_tx_pool.ts +14 -26
- package/src/services/encoding.ts +9 -1
- package/src/services/libp2p/instrumentation.ts +39 -0
- package/src/services/libp2p/libp2p_service.ts +41 -15
- package/src/services/reqresp/reqresp.ts +6 -6
- package/src/services/tx_collect_instrumentation.ts +44 -0
- package/src/services/tx_collector.ts +93 -67
- package/src/test-helpers/reqresp-nodes.ts +6 -0
|
@@ -18,6 +18,7 @@ export declare class InMemoryTxPool implements TxPool {
|
|
|
18
18
|
* @param log - A logger.
|
|
19
19
|
*/
|
|
20
20
|
constructor(telemetry?: TelemetryClient, log?: import("@aztec/foundation/log").Logger);
|
|
21
|
+
private countTx;
|
|
21
22
|
isEmpty(): Promise<boolean>;
|
|
22
23
|
markAsMined(txHashes: TxHash[], blockNumber: number): Promise<void>;
|
|
23
24
|
markMinedAsPending(txHashes: TxHash[]): Promise<void>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"memory_tx_pool.d.ts","sourceRoot":"","sources":["../../../src/mem_pools/tx_pool/memory_tx_pool.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,EAAE,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,KAAK,eAAe,EAAsB,MAAM,yBAAyB,CAAC;AAInF,OAAO,KAAK,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAE1D;;GAEG;AACH,qBAAa,cAAe,YAAW,MAAM;IAgBzC,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;
|
|
1
|
+
{"version":3,"file":"memory_tx_pool.d.ts","sourceRoot":"","sources":["../../../src/mem_pools/tx_pool/memory_tx_pool.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,EAAE,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,KAAK,eAAe,EAAsB,MAAM,yBAAyB,CAAC;AAInF,OAAO,KAAK,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAE1D;;GAEG;AACH,qBAAa,cAAe,YAAW,MAAM;IAgBzC,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;IAQ3C,OAAO,CAAC,OAAO,CA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O,CAAC,IAAI,CAAC;CAGlD"}
|
|
@@ -18,11 +18,20 @@ import { getPendingTxPriority } from './priority.js';
|
|
|
18
18
|
* @param log - A logger.
|
|
19
19
|
*/ constructor(telemetry = getTelemetryClient(), log = createLogger('p2p:tx_pool')){
|
|
20
20
|
this.log = log;
|
|
21
|
+
this.countTx = ()=>{
|
|
22
|
+
return Promise.resolve({
|
|
23
|
+
itemCount: {
|
|
24
|
+
mined: this.minedTxs.size,
|
|
25
|
+
pending: this.pendingTxs.size
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
};
|
|
21
29
|
this.txs = new Map();
|
|
22
30
|
this.minedTxs = new Map();
|
|
23
31
|
this.pendingTxs = new Set();
|
|
24
|
-
this.metrics = new PoolInstrumentation(telemetry, PoolName.TX_POOL);
|
|
32
|
+
this.metrics = new PoolInstrumentation(telemetry, PoolName.TX_POOL, this.countTx);
|
|
25
33
|
}
|
|
34
|
+
countTx;
|
|
26
35
|
isEmpty() {
|
|
27
36
|
return Promise.resolve(this.txs.size === 0);
|
|
28
37
|
}
|
|
@@ -32,8 +41,6 @@ import { getPendingTxPriority } from './priority.js';
|
|
|
32
41
|
this.minedTxs.set(key, blockNumber);
|
|
33
42
|
this.pendingTxs.delete(key);
|
|
34
43
|
}
|
|
35
|
-
this.metrics.recordRemovedObjects(txHashes.length, 'pending');
|
|
36
|
-
this.metrics.recordAddedObjects(txHashes.length, 'mined');
|
|
37
44
|
return Promise.resolve();
|
|
38
45
|
}
|
|
39
46
|
markMinedAsPending(txHashes) {
|
|
@@ -41,20 +48,13 @@ import { getPendingTxPriority } from './priority.js';
|
|
|
41
48
|
return Promise.resolve();
|
|
42
49
|
}
|
|
43
50
|
const keys = txHashes.map((x)=>x.toBigInt());
|
|
44
|
-
let deleted = 0;
|
|
45
|
-
let added = 0;
|
|
46
51
|
for (const key of keys){
|
|
47
|
-
|
|
48
|
-
deleted++;
|
|
49
|
-
}
|
|
52
|
+
this.minedTxs.delete(key);
|
|
50
53
|
// only add back to the pending set if we have the tx object
|
|
51
54
|
if (this.txs.has(key)) {
|
|
52
|
-
added++;
|
|
53
55
|
this.pendingTxs.add(key);
|
|
54
56
|
}
|
|
55
57
|
}
|
|
56
|
-
this.metrics.recordRemovedObjects(deleted, 'mined');
|
|
57
|
-
this.metrics.recordAddedObjects(added, 'pending');
|
|
58
58
|
return Promise.resolve();
|
|
59
59
|
}
|
|
60
60
|
async getPendingTxHashes() {
|
|
@@ -103,7 +103,6 @@ import { getPendingTxPriority } from './priority.js';
|
|
|
103
103
|
* @param txs - An array of txs to be added to the pool.
|
|
104
104
|
* @returns Empty promise.
|
|
105
105
|
*/ async addTxs(txs) {
|
|
106
|
-
let pending = 0;
|
|
107
106
|
for (const tx of txs){
|
|
108
107
|
const txHash = await tx.getTxHash();
|
|
109
108
|
this.log.verbose(`Adding tx ${txHash.toString()} to pool`, {
|
|
@@ -113,29 +112,22 @@ import { getPendingTxPriority } from './priority.js';
|
|
|
113
112
|
const key = txHash.toBigInt();
|
|
114
113
|
this.txs.set(key, tx);
|
|
115
114
|
if (!this.minedTxs.has(key)) {
|
|
116
|
-
pending++;
|
|
117
115
|
this.metrics.recordSize(tx);
|
|
118
116
|
this.pendingTxs.add(key);
|
|
119
117
|
}
|
|
120
118
|
}
|
|
121
|
-
this.metrics.recordAddedObjects(pending, 'pending');
|
|
122
|
-
return;
|
|
123
119
|
}
|
|
124
120
|
/**
|
|
125
121
|
* Deletes transactions from the pool. Tx hashes that are not present are ignored.
|
|
126
122
|
* @param txHashes - An array of tx hashes to be removed from the tx pool.
|
|
127
123
|
* @returns The number of transactions that was deleted from the pool.
|
|
128
124
|
*/ deleteTxs(txHashes) {
|
|
129
|
-
let deletedMined = 0;
|
|
130
|
-
let deletedPending = 0;
|
|
131
125
|
for (const txHash of txHashes){
|
|
132
126
|
const key = txHash.toBigInt();
|
|
133
127
|
this.txs.delete(key);
|
|
134
|
-
|
|
135
|
-
|
|
128
|
+
this.pendingTxs.delete(key);
|
|
129
|
+
this.minedTxs.delete(key);
|
|
136
130
|
}
|
|
137
|
-
this.metrics.recordRemovedObjects(deletedPending, 'pending');
|
|
138
|
-
this.metrics.recordRemovedObjects(deletedMined, 'mined');
|
|
139
131
|
return Promise.resolve();
|
|
140
132
|
}
|
|
141
133
|
/**
|
|
@@ -25,5 +25,7 @@ export declare class SnappyTransform implements DataTransform {
|
|
|
25
25
|
inboundTransformNoTopic(data: Buffer): Buffer;
|
|
26
26
|
outboundTransform(_topicStr: string, data: Uint8Array): Uint8Array;
|
|
27
27
|
outboundTransformNoTopic(data: Buffer): Buffer;
|
|
28
|
+
outboundTransformAsync(data: Buffer): Promise<Buffer>;
|
|
29
|
+
inboundTransformAsync(data: Buffer): Promise<Buffer>;
|
|
28
30
|
}
|
|
29
31
|
//# sourceMappingURL=encoding.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"encoding.d.ts","sourceRoot":"","sources":["../../src/services/encoding.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,qCAAqC,CAAC;AAC/D,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,mCAAmC,CAAC;AACvE,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAajD;;;GAGG;AACH,wBAAgB,WAAW,CAAC,MAAM,EAAE,GAAG,CAAC,OAAO,GAAG,MAAM,CAKvD;AAED,wBAAgB,YAAY,CAAC,KAAK,EAAE,UAAU,GAAG,MAAM,CAItD;AAED;;;;;;;;GAQG;AACH,wBAAgB,UAAU,CAAC,OAAO,EAAE,OAAO,uBAK1C;AAED;;GAEG;AACH,qBAAa,eAAgB,YAAW,aAAa;IAEnD,gBAAgB,CAAC,SAAS,EAAE,MAAM,EAAE,IAAI,EAAE,UAAU,GAAG,UAAU;IAI1D,uBAAuB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM;IAQpD,iBAAiB,CAAC,SAAS,EAAE,MAAM,EAAE,IAAI,EAAE,UAAU,GAAG,UAAU;IAI3D,wBAAwB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM;
|
|
1
|
+
{"version":3,"file":"encoding.d.ts","sourceRoot":"","sources":["../../src/services/encoding.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,qCAAqC,CAAC;AAC/D,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,mCAAmC,CAAC;AACvE,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAajD;;;GAGG;AACH,wBAAgB,WAAW,CAAC,MAAM,EAAE,GAAG,CAAC,OAAO,GAAG,MAAM,CAKvD;AAED,wBAAgB,YAAY,CAAC,KAAK,EAAE,UAAU,GAAG,MAAM,CAItD;AAED;;;;;;;;GAQG;AACH,wBAAgB,UAAU,CAAC,OAAO,EAAE,OAAO,uBAK1C;AAED;;GAEG;AACH,qBAAa,eAAgB,YAAW,aAAa;IAEnD,gBAAgB,CAAC,SAAS,EAAE,MAAM,EAAE,IAAI,EAAE,UAAU,GAAG,UAAU;IAI1D,uBAAuB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM;IAQpD,iBAAiB,CAAC,SAAS,EAAE,MAAM,EAAE,IAAI,EAAE,UAAU,GAAG,UAAU;IAI3D,wBAAwB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM;IAO9C,sBAAsB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAIrD,qBAAqB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;CAG5D"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// Taken from lodestar: https://github.com/ChainSafe/lodestar
|
|
2
2
|
import { sha256 } from '@aztec/foundation/crypto';
|
|
3
|
-
import { compressSync, uncompressSync } from 'snappy';
|
|
3
|
+
import { compress, compressSync, uncompress, uncompressSync } from 'snappy';
|
|
4
4
|
import xxhashFactory from 'xxhash-wasm';
|
|
5
5
|
// Load WASM
|
|
6
6
|
const xxhash = await xxhashFactory();
|
|
@@ -63,4 +63,12 @@ export function msgIdToStrFn(msgId) {
|
|
|
63
63
|
}
|
|
64
64
|
return Buffer.from(compressSync(data));
|
|
65
65
|
}
|
|
66
|
+
outboundTransformAsync(data) {
|
|
67
|
+
return compress(data);
|
|
68
|
+
}
|
|
69
|
+
inboundTransformAsync(data) {
|
|
70
|
+
return uncompress(data, {
|
|
71
|
+
asBuffer: true
|
|
72
|
+
});
|
|
73
|
+
}
|
|
66
74
|
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { Timer } from '@aztec/foundation/timer';
|
|
2
|
+
import type { TopicType } from '@aztec/stdlib/p2p';
|
|
3
|
+
import { type TelemetryClient } from '@aztec/telemetry-client';
|
|
4
|
+
export declare class P2PInstrumentation {
|
|
5
|
+
private messageValidationDuration;
|
|
6
|
+
private messagePrevalidationCount;
|
|
7
|
+
constructor(client: TelemetryClient, name: string);
|
|
8
|
+
recordMessageValidation(topicName: TopicType, timerOrMs: Timer | number): void;
|
|
9
|
+
incMessagePrevalidationStatus(passed: boolean, topicName: TopicType | undefined): void;
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=instrumentation.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"instrumentation.d.ts","sourceRoot":"","sources":["../../../src/services/libp2p/instrumentation.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,yBAAyB,CAAC;AACrD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AACnD,OAAO,EAIL,KAAK,eAAe,EAGrB,MAAM,yBAAyB,CAAC;AAEjC,qBAAa,kBAAkB;IAC7B,OAAO,CAAC,yBAAyB,CAAY;IAC7C,OAAO,CAAC,yBAAyB,CAAgB;gBAErC,MAAM,EAAE,eAAe,EAAE,IAAI,EAAE,MAAM;IAe1C,uBAAuB,CAAC,SAAS,EAAE,SAAS,EAAE,SAAS,EAAE,KAAK,GAAG,MAAM;IAKvE,6BAA6B,CAAC,MAAM,EAAE,OAAO,EAAE,SAAS,EAAE,SAAS,GAAG,SAAS;CAGvF"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { Attributes, Metrics, ValueType } from '@aztec/telemetry-client';
|
|
2
|
+
export class P2PInstrumentation {
|
|
3
|
+
messageValidationDuration;
|
|
4
|
+
messagePrevalidationCount;
|
|
5
|
+
constructor(client, name){
|
|
6
|
+
const meter = client.getMeter(name);
|
|
7
|
+
this.messageValidationDuration = meter.createHistogram(Metrics.P2P_GOSSIP_MESSAGE_VALIDATION_DURATION, {
|
|
8
|
+
unit: 'ms',
|
|
9
|
+
description: 'How long validating a gossiped message takes',
|
|
10
|
+
valueType: ValueType.INT
|
|
11
|
+
});
|
|
12
|
+
this.messagePrevalidationCount = meter.createUpDownCounter(Metrics.P2P_GOSSIP_MESSAGE_PREVALIDATION_COUNT, {
|
|
13
|
+
description: 'How many message pass/fail prevalidation',
|
|
14
|
+
valueType: ValueType.INT
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
recordMessageValidation(topicName, timerOrMs) {
|
|
18
|
+
const ms = typeof timerOrMs === 'number' ? timerOrMs : timerOrMs.ms();
|
|
19
|
+
this.messageValidationDuration.record(Math.ceil(ms), {
|
|
20
|
+
[Attributes.TOPIC_NAME]: topicName
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
incMessagePrevalidationStatus(passed, topicName) {
|
|
24
|
+
this.messagePrevalidationCount.add(1, {
|
|
25
|
+
[Attributes.TOPIC_NAME]: topicName,
|
|
26
|
+
[Attributes.OK]: passed
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
}
|
|
@@ -3,7 +3,7 @@ import type { AztecAsyncKVStore } from '@aztec/kv-store';
|
|
|
3
3
|
import type { L2BlockSource } from '@aztec/stdlib/block';
|
|
4
4
|
import type { ContractDataSource } from '@aztec/stdlib/contract';
|
|
5
5
|
import type { ClientProtocolCircuitVerifier, PeerInfo, WorldStateSynchronizer } from '@aztec/stdlib/interfaces/server';
|
|
6
|
-
import { BlockAttestation, BlockProposal, type Gossipable, P2PClientType } from '@aztec/stdlib/p2p';
|
|
6
|
+
import { BlockAttestation, BlockProposal, type Gossipable, P2PClientType, TopicType } from '@aztec/stdlib/p2p';
|
|
7
7
|
import { Tx } from '@aztec/stdlib/tx';
|
|
8
8
|
import { type TelemetryClient, WithTracer } from '@aztec/telemetry-client';
|
|
9
9
|
import type { ENR } from '@chainsafe/enr';
|
|
@@ -46,6 +46,7 @@ export declare class LibP2PService<T extends P2PClientType = P2PClientType.Full>
|
|
|
46
46
|
*/
|
|
47
47
|
private blockReceivedCallback;
|
|
48
48
|
private gossipSubEventHandler;
|
|
49
|
+
private instrumentation;
|
|
49
50
|
constructor(clientType: T, config: P2PConfig, node: PubSubLibp2p, peerDiscoveryService: PeerDiscoveryService, mempools: MemPools<T>, archiver: L2BlockSource & ContractDataSource, epochCache: EpochCacheInterface, proofVerifier: ClientProtocolCircuitVerifier, worldStateSynchronizer: WorldStateSynchronizer, telemetry: TelemetryClient, logger?: import("@aztec/foundation/log").Logger);
|
|
50
51
|
/**
|
|
51
52
|
* Creates an instance of the LibP2P service.
|
|
@@ -112,7 +113,7 @@ export declare class LibP2PService<T extends P2PClientType = P2PClientType.Full>
|
|
|
112
113
|
protected validateReceivedMessage<T>(validationFunc: () => Promise<{
|
|
113
114
|
result: boolean;
|
|
114
115
|
obj: T;
|
|
115
|
-
}>, msgId: string, source: PeerId): Promise<{
|
|
116
|
+
}>, msgId: string, source: PeerId, topicType: TopicType): Promise<{
|
|
116
117
|
result: boolean;
|
|
117
118
|
obj: T | undefined;
|
|
118
119
|
}>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"libp2p_service.d.ts","sourceRoot":"","sources":["../../../src/services/libp2p/libp2p_service.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAm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AO,CAAC;IAWnF,YAAY,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM;YAI7B,WAAW;YAcX,UAAU;CAYzB"}
|
|
@@ -7,6 +7,7 @@ function _ts_decorate(decorators, target, key, desc) {
|
|
|
7
7
|
import { createLibp2pComponentLogger, createLogger } from '@aztec/foundation/log';
|
|
8
8
|
import { SerialQueue } from '@aztec/foundation/queue';
|
|
9
9
|
import { RunningPromise } from '@aztec/foundation/running-promise';
|
|
10
|
+
import { Timer } from '@aztec/foundation/timer';
|
|
10
11
|
import { protocolContractTreeRoot } from '@aztec/protocol-contracts';
|
|
11
12
|
import { GasFees } from '@aztec/stdlib/gas';
|
|
12
13
|
import { BlockAttestation, BlockProposal, P2PClientType, P2PMessage, PeerErrorSeverity, TopicType, createTopicString, getTopicTypeForClientType, metricsTopicStrToLabels } from '@aztec/stdlib/p2p';
|
|
@@ -43,6 +44,7 @@ import { DEFAULT_SUB_PROTOCOL_VALIDATORS, ReqRespSubProtocol } from '../reqresp/
|
|
|
43
44
|
import { reqGoodbyeHandler } from '../reqresp/protocols/goodbye.js';
|
|
44
45
|
import { pingHandler, reqRespBlockHandler, reqRespTxHandler, statusHandler } from '../reqresp/protocols/index.js';
|
|
45
46
|
import { ReqResp } from '../reqresp/reqresp.js';
|
|
47
|
+
import { P2PInstrumentation } from './instrumentation.js';
|
|
46
48
|
/**
|
|
47
49
|
* Lib P2P implementation of the P2PService interface.
|
|
48
50
|
*/ export class LibP2PService extends WithTracer {
|
|
@@ -75,8 +77,10 @@ import { ReqResp } from '../reqresp/reqresp.js';
|
|
|
75
77
|
* @returns The attestation for the block, if any.
|
|
76
78
|
*/ blockReceivedCallback;
|
|
77
79
|
gossipSubEventHandler;
|
|
80
|
+
instrumentation;
|
|
78
81
|
constructor(clientType, config, node, peerDiscoveryService, mempools, archiver, epochCache, proofVerifier, worldStateSynchronizer, telemetry, logger = createLogger('p2p:libp2p_service')){
|
|
79
82
|
super(telemetry, 'LibP2PService'), this.clientType = clientType, this.config = config, this.node = node, this.peerDiscoveryService = peerDiscoveryService, this.mempools = mempools, this.archiver = archiver, this.proofVerifier = proofVerifier, this.worldStateSynchronizer = worldStateSynchronizer, this.logger = logger, this.jobQueue = new SerialQueue(), this.msgIdSeenValidators = {}, this.protocolVersion = '', this.topicStrings = {}, this.trustedPeersIds = [];
|
|
83
|
+
this.instrumentation = new P2PInstrumentation(telemetry, 'LibP2PService');
|
|
80
84
|
this.msgIdSeenValidators[TopicType.tx] = new MessageSeenValidator(config.seenMessageCacheSize);
|
|
81
85
|
this.msgIdSeenValidators[TopicType.block_proposal] = new MessageSeenValidator(config.seenMessageCacheSize);
|
|
82
86
|
this.msgIdSeenValidators[TopicType.block_attestation] = new MessageSeenValidator(config.seenMessageCacheSize);
|
|
@@ -366,23 +370,28 @@ import { ReqResp } from '../reqresp/reqresp.js';
|
|
|
366
370
|
return result.recipients.length;
|
|
367
371
|
}
|
|
368
372
|
preValidateReceivedMessage(msg, msgId, source) {
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
373
|
+
let topicType;
|
|
374
|
+
switch(msg.topic){
|
|
375
|
+
case this.topicStrings[TopicType.tx]:
|
|
376
|
+
topicType = TopicType.tx;
|
|
377
|
+
break;
|
|
378
|
+
case this.topicStrings[TopicType.block_attestation]:
|
|
379
|
+
topicType = TopicType.block_attestation;
|
|
380
|
+
break;
|
|
381
|
+
case this.topicStrings[TopicType.block_proposal]:
|
|
382
|
+
topicType = TopicType.block_proposal;
|
|
383
|
+
break;
|
|
384
|
+
default:
|
|
385
|
+
this.logger.error(`Received message on unknown topic: ${msg.topic}`);
|
|
386
|
+
break;
|
|
387
|
+
}
|
|
388
|
+
const validator = topicType ? this.msgIdSeenValidators[topicType] : undefined;
|
|
382
389
|
if (!validator || !validator.addMessage(msgId)) {
|
|
390
|
+
this.instrumentation.incMessagePrevalidationStatus(false, topicType);
|
|
383
391
|
this.node.services.pubsub.reportMessageValidationResult(msgId, source.toString(), TopicValidatorResult.Ignore);
|
|
384
392
|
return false;
|
|
385
393
|
}
|
|
394
|
+
this.instrumentation.incMessagePrevalidationStatus(true, topicType);
|
|
386
395
|
return true;
|
|
387
396
|
}
|
|
388
397
|
/**
|
|
@@ -412,16 +421,20 @@ import { ReqResp } from '../reqresp/reqresp.js';
|
|
|
412
421
|
}
|
|
413
422
|
return;
|
|
414
423
|
}
|
|
415
|
-
async validateReceivedMessage(validationFunc, msgId, source) {
|
|
424
|
+
async validateReceivedMessage(validationFunc, msgId, source, topicType) {
|
|
416
425
|
let resultAndObj = {
|
|
417
426
|
result: false,
|
|
418
427
|
obj: undefined
|
|
419
428
|
};
|
|
429
|
+
const timer = new Timer();
|
|
420
430
|
try {
|
|
421
431
|
resultAndObj = await validationFunc();
|
|
422
432
|
} catch (err) {
|
|
423
433
|
this.logger.error(`Error deserialising and validating message `, err);
|
|
424
434
|
}
|
|
435
|
+
if (resultAndObj.result) {
|
|
436
|
+
this.instrumentation.recordMessageValidation(topicType, timer);
|
|
437
|
+
}
|
|
425
438
|
this.node.services.pubsub.reportMessageValidationResult(msgId, source.toString(), resultAndObj.result && resultAndObj.obj ? TopicValidatorResult.Accept : TopicValidatorResult.Reject);
|
|
426
439
|
return resultAndObj;
|
|
427
440
|
}
|
|
@@ -434,7 +447,7 @@ import { ReqResp } from '../reqresp/reqresp.js';
|
|
|
434
447
|
obj: tx
|
|
435
448
|
};
|
|
436
449
|
};
|
|
437
|
-
const { result, obj: tx } = await this.validateReceivedMessage(validationFunc, msgId, source);
|
|
450
|
+
const { result, obj: tx } = await this.validateReceivedMessage(validationFunc, msgId, source, TopicType.tx);
|
|
438
451
|
if (!result || !tx) {
|
|
439
452
|
return;
|
|
440
453
|
}
|
|
@@ -463,7 +476,7 @@ import { ReqResp } from '../reqresp/reqresp.js';
|
|
|
463
476
|
obj: attestation
|
|
464
477
|
};
|
|
465
478
|
};
|
|
466
|
-
const { result, obj: attestation } = await this.validateReceivedMessage(validationFunc, msgId, source);
|
|
479
|
+
const { result, obj: attestation } = await this.validateReceivedMessage(validationFunc, msgId, source, TopicType.block_attestation);
|
|
467
480
|
if (!result || !attestation) {
|
|
468
481
|
return;
|
|
469
482
|
}
|
|
@@ -490,7 +503,7 @@ import { ReqResp } from '../reqresp/reqresp.js';
|
|
|
490
503
|
obj: block
|
|
491
504
|
};
|
|
492
505
|
};
|
|
493
|
-
const { result, obj: block } = await this.validateReceivedMessage(validationFunc, msgId, source);
|
|
506
|
+
const { result, obj: block } = await this.validateReceivedMessage(validationFunc, msgId, source, TopicType.block_proposal);
|
|
494
507
|
if (!result || !block) {
|
|
495
508
|
return;
|
|
496
509
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type Logger } from '@aztec/foundation/log';
|
|
2
2
|
import { type TelemetryClient } from '@aztec/telemetry-client';
|
|
3
|
-
import type
|
|
3
|
+
import { type PeerId } from '@libp2p/interface';
|
|
4
4
|
import type { Libp2p } from 'libp2p';
|
|
5
5
|
import type { PeerScoring } from '../peer-manager/peer_scoring.js';
|
|
6
6
|
import type { P2PReqRespConfig } from './config.js';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"reqresp.d.ts","sourceRoot":"","sources":["../../../src/services/reqresp/reqresp.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,MAAM,EAAgB,MAAM,uBAAuB,CAAC;AAGlE,OAAO,EAAc,KAAK,eAAe,EAAiC,MAAM,yBAAyB,CAAC;AAE1G,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"reqresp.d.ts","sourceRoot":"","sources":["../../../src/services/reqresp/reqresp.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,MAAM,EAAgB,MAAM,uBAAuB,CAAC;AAGlE,OAAO,EAAc,KAAK,eAAe,EAAiC,MAAM,yBAAy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CAAC,WAAW,CAAC,CAAC,SAAS,CAAC,CAAC,GAC5D,OAAO,CAAC,YAAY,CAAC,cAAc,CAAC,WAAW,CAAC,CAAC,UAAU,CAAC,CAAC,GAAG,SAAS,CAAC;IA8D7E;;;;;;;;;;;;;;;;;;;;;OAqBG;IAQG,gBAAgB,CAAC,WAAW,SAAS,kBAAkB,EAC3D,WAAW,EAAE,WAAW,EACxB,QAAQ,EAAE,YAAY,CAAC,cAAc,CAAC,WAAW,CAAC,CAAC,SAAS,CAAC,CAAC,EAAE,EAChE,UAAU,EAAE,MAAM,GAAG,SAAS,EAC9B,SAAS,SAAQ,EACjB,QAAQ,SAA+C,EACvD,gBAAgB,SAAI,GACnB,OAAO,CAAC,CAAC,YAAY,CAAC,cAAc,CAAC,WAAW,CAAC,CAAC,UAAU,CAAC,CAAC,GAAG,SAAS,CAAC,EAAE,CAAC;IA4IjF;;;;;;;;;;;;;;;;;;;;;;;OAuBG;IAKU,iBAAiB,CAC5B,MAAM,EAAE,MAAM,EACd,WAAW,EAAE,kBAAkB,EAC/B,OAAO,EAAE,MAAM,EACf,WAAW,CAAC,EAAE,MAAM,GACnB,OAAO,CAAC,eAAe,CAAC;IAsC3B;;;;;;;;;OASG;IACH,OAAO,CAAC,mBAAmB;IAO3B;;OAEG;IACH,OAAO,CAAC,eAAe;IAoDvB;;;;;;OAMG;YACW,WAAW;IAoCzB;;;;;;;;;;;;;;;OAeG;YAKW,aAAa;YA0EZ,cAAc;CAI9B"}
|
|
@@ -10,6 +10,7 @@ import { createLogger } from '@aztec/foundation/log';
|
|
|
10
10
|
import { executeTimeout } from '@aztec/foundation/timer';
|
|
11
11
|
import { PeerErrorSeverity } from '@aztec/stdlib/p2p';
|
|
12
12
|
import { Attributes, getTelemetryClient, trackSpan } from '@aztec/telemetry-client';
|
|
13
|
+
import { CodeError } from '@libp2p/interface';
|
|
13
14
|
import { pipe } from 'it-pipe';
|
|
14
15
|
import { CollectiveReqRespTimeoutError, IndividualReqRespTimeoutError, InvalidResponseError } from '../../errors/reqresp.error.js';
|
|
15
16
|
import { SnappyTransform } from '../encoding.js';
|
|
@@ -406,7 +407,7 @@ import { ReqRespStatus, ReqRespStatusError, parseStatusChunk, prettyPrintReqResp
|
|
|
406
407
|
}
|
|
407
408
|
// Timeout errors are punished with high tolerance, they can be due to a geogrpahically far away peer or an
|
|
408
409
|
// overloaded peer
|
|
409
|
-
if (e instanceof IndividualReqRespTimeoutError) {
|
|
410
|
+
if (e instanceof IndividualReqRespTimeoutError || e instanceof CodeError && e.code === 'ERR_TIMEOUT') {
|
|
410
411
|
this.logger.debug(`Timeout error: ${e.message} | peerId: ${peerId.toString()} | subProtocol: ${subProtocol}`, logTags);
|
|
411
412
|
return PeerErrorSeverity.HighToleranceError;
|
|
412
413
|
}
|
|
@@ -433,7 +434,7 @@ import { ReqRespStatus, ReqRespStatusError, parseStatusChunk, prettyPrintReqResp
|
|
|
433
434
|
}
|
|
434
435
|
}
|
|
435
436
|
const messageData = Buffer.concat(chunks);
|
|
436
|
-
const message = this.snappyTransform.
|
|
437
|
+
const message = await this.snappyTransform.inboundTransformAsync(messageData);
|
|
437
438
|
return {
|
|
438
439
|
status: statusBuffer ?? ReqRespStatus.UNKNOWN,
|
|
439
440
|
data: message
|
|
@@ -491,11 +492,14 @@ import { ReqRespStatus, ReqRespStatusError, parseStatusChunk, prettyPrintReqResp
|
|
|
491
492
|
ReqRespStatus.SUCCESS
|
|
492
493
|
]);
|
|
493
494
|
yield new Uint8Array(successChunk);
|
|
494
|
-
yield new Uint8Array(transform.
|
|
495
|
+
yield new Uint8Array(await transform.outboundTransformAsync(response));
|
|
495
496
|
}
|
|
496
497
|
}, stream);
|
|
497
498
|
} catch (e) {
|
|
498
|
-
this.logger.warn(
|
|
499
|
+
this.logger.warn(`Reqresp Response error: ${e?.name} ${e?.code} ${e?.message}`, {
|
|
500
|
+
err: e,
|
|
501
|
+
protocol
|
|
502
|
+
});
|
|
499
503
|
this.metrics.recordResponseError(protocol);
|
|
500
504
|
// If we receive a known error, we use the error status in the response chunk, otherwise we categorize as unknown
|
|
501
505
|
let errorStatus = ReqRespStatus.UNKNOWN;
|
|
@@ -509,7 +513,7 @@ import { ReqRespStatus, ReqRespStatusError, parseStatusChunk, prettyPrintReqResp
|
|
|
509
513
|
yield* sendErrorChunk;
|
|
510
514
|
}, stream);
|
|
511
515
|
} else {
|
|
512
|
-
this.logger.
|
|
516
|
+
this.logger.trace('Stream already closed, not sending error response', {
|
|
513
517
|
protocol,
|
|
514
518
|
err: e,
|
|
515
519
|
errorStatus
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { type TelemetryClient } from '@aztec/telemetry-client';
|
|
2
|
+
export declare class TxCollectorInstrumentation {
|
|
3
|
+
private txFromProposalCount;
|
|
4
|
+
private txFromMempoolCount;
|
|
5
|
+
private txFromP2PCount;
|
|
6
|
+
private missingTxsCount;
|
|
7
|
+
constructor(client: TelemetryClient, name: string);
|
|
8
|
+
incTxsFromProposals(count: number): void;
|
|
9
|
+
incTxsFromMempool(count: number): void;
|
|
10
|
+
incTxsFromP2P(count: number): void;
|
|
11
|
+
incMissingTxs(count: number): void;
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=tx_collect_instrumentation.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tx_collect_instrumentation.d.ts","sourceRoot":"","sources":["../../src/services/tx_collect_instrumentation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAW,KAAK,eAAe,EAAsB,MAAM,yBAAyB,CAAC;AAE5F,qBAAa,0BAA0B;IACrC,OAAO,CAAC,mBAAmB,CAAgB;IAC3C,OAAO,CAAC,kBAAkB,CAAgB;IAC1C,OAAO,CAAC,cAAc,CAAgB;IACtC,OAAO,CAAC,eAAe,CAAgB;gBAE3B,MAAM,EAAE,eAAe,EAAE,IAAI,EAAE,MAAM;IAoBjD,mBAAmB,CAAC,KAAK,EAAE,MAAM;IAIjC,iBAAiB,CAAC,KAAK,EAAE,MAAM;IAI/B,aAAa,CAAC,KAAK,EAAE,MAAM;IAI3B,aAAa,CAAC,KAAK,EAAE,MAAM;CAG5B"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { Metrics } from '@aztec/telemetry-client';
|
|
2
|
+
export class TxCollectorInstrumentation {
|
|
3
|
+
txFromProposalCount;
|
|
4
|
+
txFromMempoolCount;
|
|
5
|
+
txFromP2PCount;
|
|
6
|
+
missingTxsCount;
|
|
7
|
+
constructor(client, name){
|
|
8
|
+
const meter = client.getMeter(name);
|
|
9
|
+
this.txFromProposalCount = meter.createUpDownCounter(Metrics.TX_COLLECTOR_TXS_FROM_PROPOSALS_COUNT, {
|
|
10
|
+
description: 'The number of txs taken from block proposals'
|
|
11
|
+
});
|
|
12
|
+
this.txFromMempoolCount = meter.createUpDownCounter(Metrics.TX_COLLECTOR_TXS_FROM_MEMPOOL_COUNT, {
|
|
13
|
+
description: 'The number of txs taken from the local mempool'
|
|
14
|
+
});
|
|
15
|
+
this.txFromP2PCount = meter.createUpDownCounter(Metrics.TX_COLLECTOR_TXS_FROM_P2P_COUNT, {
|
|
16
|
+
description: 'The number of txs taken from the p2p network'
|
|
17
|
+
});
|
|
18
|
+
this.missingTxsCount = meter.createUpDownCounter(Metrics.TX_COLLECTOR_MISSING_TXS_COUNT, {
|
|
19
|
+
description: 'The number of txs not found anywhere'
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
incTxsFromProposals(count) {
|
|
23
|
+
this.txFromProposalCount.add(count);
|
|
24
|
+
}
|
|
25
|
+
incTxsFromMempool(count) {
|
|
26
|
+
this.txFromMempoolCount.add(count);
|
|
27
|
+
}
|
|
28
|
+
incTxsFromP2P(count) {
|
|
29
|
+
this.txFromP2PCount.add(count);
|
|
30
|
+
}
|
|
31
|
+
incMissingTxs(count) {
|
|
32
|
+
this.missingTxsCount.add(count);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
@@ -1,12 +1,16 @@
|
|
|
1
1
|
import { type Logger } from '@aztec/foundation/log';
|
|
2
2
|
import type { BlockProposal } from '@aztec/stdlib/p2p';
|
|
3
3
|
import type { Tx, TxHash } from '@aztec/stdlib/tx';
|
|
4
|
+
import { type TelemetryClient } from '@aztec/telemetry-client';
|
|
5
|
+
import type { PeerId } from '@libp2p/interface';
|
|
4
6
|
import type { P2PClient } from '../client/p2p_client.js';
|
|
5
7
|
export declare class TxCollector {
|
|
6
8
|
private p2pClient;
|
|
7
9
|
private log;
|
|
8
|
-
|
|
9
|
-
|
|
10
|
+
private instrumentation;
|
|
11
|
+
constructor(p2pClient: Pick<P2PClient, 'getTxsByHashFromPool' | 'hasTxsInPool' | 'getTxsByHash' | 'validate' | 'requestTxsByHash' | 'addTxsToPool'>, log?: Logger, client?: TelemetryClient);
|
|
12
|
+
private collectFromProposal;
|
|
13
|
+
collectForBlockProposal(proposal: BlockProposal, peerWhoSentTheProposal: PeerId | undefined): Promise<{
|
|
10
14
|
txs: Tx[];
|
|
11
15
|
missing?: TxHash[];
|
|
12
16
|
}>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tx_collector.d.ts","sourceRoot":"","sources":["../../src/services/tx_collector.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,MAAM,EAAgB,MAAM,uBAAuB,CAAC;AAClE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AACvD,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"tx_collector.d.ts","sourceRoot":"","sources":["../../src/services/tx_collector.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,MAAM,EAAgB,MAAM,uBAAuB,CAAC;AAClE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AACvD,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AACnD,OAAO,EAAE,KAAK,eAAe,EAAsB,MAAM,yBAAyB,CAAC;AAEnF,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAEhD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AAGzD,qBAAa,WAAW;IAIpB,OAAO,CAAC,SAAS;IAIjB,OAAO,CAAC,GAAG;IAPb,OAAO,CAAC,eAAe,CAA6B;gBAG1C,SAAS,EAAE,IAAI,CACrB,SAAS,EACT,sBAAsB,GAAG,cAAc,GAAG,cAAc,GAAG,UAAU,GAAG,kBAAkB,GAAG,cAAc,CAC5G,EACO,GAAG,GAAE,MAAyC,EACtD,MAAM,GAAE,eAAsC;YAMlC,mBAAmB;IAmD3B,uBAAuB,CAC3B,QAAQ,EAAE,aAAa,EACvB,sBAAsB,EAAE,MAAM,GAAG,SAAS,GACzC,OAAO,CAAC;QAAE,GAAG,EAAE,EAAE,EAAE,CAAC;QAAC,OAAO,CAAC,EAAE,MAAM,EAAE,CAAA;KAAE,CAAC;CA2C9C"}
|