@aztec/p2p 0.0.1-commit.fcb71a6 → 0.0.1-commit.fffb133c
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dest/client/interface.d.ts +18 -5
- package/dest/client/interface.d.ts.map +1 -1
- package/dest/client/p2p_client.d.ts +10 -13
- package/dest/client/p2p_client.d.ts.map +1 -1
- package/dest/client/p2p_client.js +449 -118
- package/dest/config.js +2 -2
- package/dest/mem_pools/attestation_pool/attestation_pool.d.ts +61 -42
- package/dest/mem_pools/attestation_pool/attestation_pool.d.ts.map +1 -1
- package/dest/mem_pools/attestation_pool/attestation_pool_test_suite.d.ts +1 -1
- package/dest/mem_pools/attestation_pool/attestation_pool_test_suite.d.ts.map +1 -1
- package/dest/mem_pools/attestation_pool/attestation_pool_test_suite.js +237 -263
- package/dest/mem_pools/attestation_pool/kv_attestation_pool.d.ts +21 -18
- package/dest/mem_pools/attestation_pool/kv_attestation_pool.d.ts.map +1 -1
- package/dest/mem_pools/attestation_pool/kv_attestation_pool.js +113 -108
- package/dest/mem_pools/attestation_pool/memory_attestation_pool.d.ts +17 -16
- package/dest/mem_pools/attestation_pool/memory_attestation_pool.d.ts.map +1 -1
- package/dest/mem_pools/attestation_pool/memory_attestation_pool.js +89 -128
- package/dest/mem_pools/attestation_pool/mocks.d.ts +9 -6
- package/dest/mem_pools/attestation_pool/mocks.d.ts.map +1 -1
- package/dest/mem_pools/attestation_pool/mocks.js +16 -12
- package/dest/mem_pools/instrumentation.d.ts +1 -1
- package/dest/mem_pools/instrumentation.d.ts.map +1 -1
- package/dest/mem_pools/instrumentation.js +4 -13
- package/dest/mem_pools/tx_pool/aztec_kv_tx_pool.d.ts +15 -10
- package/dest/mem_pools/tx_pool/aztec_kv_tx_pool.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool/aztec_kv_tx_pool.js +91 -50
- package/dest/mem_pools/tx_pool/eviction/eviction_manager.d.ts +19 -5
- package/dest/mem_pools/tx_pool/eviction/eviction_manager.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool/eviction/eviction_manager.js +59 -3
- package/dest/mem_pools/tx_pool/eviction/eviction_strategy.d.ts +79 -5
- package/dest/mem_pools/tx_pool/eviction/eviction_strategy.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool/eviction/eviction_strategy.js +47 -0
- package/dest/mem_pools/tx_pool/eviction/fee_payer_balance_eviction_rule.d.ts +16 -0
- package/dest/mem_pools/tx_pool/eviction/fee_payer_balance_eviction_rule.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool/eviction/fee_payer_balance_eviction_rule.js +122 -0
- package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_mining_rule.d.ts +2 -2
- package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_mining_rule.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_reorg_rule.d.ts +4 -4
- package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_reorg_rule.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_reorg_rule.js +2 -0
- package/dest/mem_pools/tx_pool/eviction/low_priority_eviction_rule.d.ts +2 -2
- package/dest/mem_pools/tx_pool/eviction/low_priority_eviction_rule.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool/eviction/nullifier_conflict_pre_add_rule.d.ts +25 -0
- package/dest/mem_pools/tx_pool/eviction/nullifier_conflict_pre_add_rule.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool/eviction/nullifier_conflict_pre_add_rule.js +57 -0
- package/dest/msg_validators/attestation_validator/attestation_validator.d.ts +4 -4
- package/dest/msg_validators/attestation_validator/attestation_validator.d.ts.map +1 -1
- package/dest/msg_validators/attestation_validator/attestation_validator.js +51 -18
- package/dest/msg_validators/attestation_validator/fisherman_attestation_validator.d.ts +5 -5
- package/dest/msg_validators/attestation_validator/fisherman_attestation_validator.d.ts.map +1 -1
- package/dest/msg_validators/attestation_validator/fisherman_attestation_validator.js +18 -14
- package/dest/msg_validators/clock_tolerance.d.ts +21 -0
- package/dest/msg_validators/clock_tolerance.d.ts.map +1 -0
- package/dest/msg_validators/clock_tolerance.js +37 -0
- package/dest/msg_validators/index.d.ts +2 -2
- package/dest/msg_validators/index.d.ts.map +1 -1
- package/dest/msg_validators/index.js +1 -1
- package/dest/msg_validators/proposal_validator/block_proposal_validator.d.ts +9 -0
- package/dest/msg_validators/proposal_validator/block_proposal_validator.d.ts.map +1 -0
- package/dest/msg_validators/proposal_validator/block_proposal_validator.js +6 -0
- package/dest/msg_validators/proposal_validator/checkpoint_proposal_validator.d.ts +9 -0
- package/dest/msg_validators/proposal_validator/checkpoint_proposal_validator.d.ts.map +1 -0
- package/dest/msg_validators/proposal_validator/checkpoint_proposal_validator.js +6 -0
- package/dest/msg_validators/proposal_validator/index.d.ts +4 -0
- package/dest/msg_validators/proposal_validator/index.d.ts.map +1 -0
- package/dest/msg_validators/proposal_validator/index.js +3 -0
- package/dest/msg_validators/proposal_validator/proposal_validator.d.ts +13 -0
- package/dest/msg_validators/proposal_validator/proposal_validator.d.ts.map +1 -0
- package/dest/msg_validators/proposal_validator/proposal_validator.js +104 -0
- package/dest/msg_validators/proposal_validator/proposal_validator_test_suite.d.ts +23 -0
- package/dest/msg_validators/proposal_validator/proposal_validator_test_suite.d.ts.map +1 -0
- package/dest/msg_validators/proposal_validator/proposal_validator_test_suite.js +212 -0
- package/dest/msg_validators/tx_validator/block_header_validator.d.ts +1 -1
- package/dest/msg_validators/tx_validator/block_header_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/block_header_validator.js +1 -1
- package/dest/msg_validators/tx_validator/data_validator.d.ts +1 -1
- package/dest/msg_validators/tx_validator/data_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/fee_payer_balance.d.ts +10 -0
- package/dest/msg_validators/tx_validator/fee_payer_balance.d.ts.map +1 -0
- package/dest/msg_validators/tx_validator/fee_payer_balance.js +20 -0
- package/dest/msg_validators/tx_validator/gas_validator.d.ts +1 -1
- package/dest/msg_validators/tx_validator/gas_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/gas_validator.js +8 -14
- package/dest/msg_validators/tx_validator/index.d.ts +2 -1
- package/dest/msg_validators/tx_validator/index.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/index.js +1 -0
- package/dest/msg_validators/tx_validator/metadata_validator.d.ts +1 -1
- package/dest/msg_validators/tx_validator/metadata_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/size_validator.d.ts +6 -0
- package/dest/msg_validators/tx_validator/size_validator.d.ts.map +1 -0
- package/dest/msg_validators/tx_validator/size_validator.js +20 -0
- package/dest/msg_validators/tx_validator/timestamp_validator.d.ts +1 -1
- package/dest/msg_validators/tx_validator/timestamp_validator.d.ts.map +1 -1
- package/dest/services/dummy_service.d.ts +6 -2
- package/dest/services/dummy_service.d.ts.map +1 -1
- package/dest/services/dummy_service.js +3 -0
- package/dest/services/encoding.d.ts +1 -1
- package/dest/services/encoding.d.ts.map +1 -1
- package/dest/services/encoding.js +6 -5
- package/dest/services/libp2p/instrumentation.d.ts +1 -1
- package/dest/services/libp2p/instrumentation.d.ts.map +1 -1
- package/dest/services/libp2p/instrumentation.js +20 -73
- package/dest/services/libp2p/libp2p_service.d.ts +28 -11
- package/dest/services/libp2p/libp2p_service.d.ts.map +1 -1
- package/dest/services/libp2p/libp2p_service.js +711 -152
- package/dest/services/peer-manager/metrics.d.ts +1 -1
- package/dest/services/peer-manager/metrics.d.ts.map +1 -1
- package/dest/services/peer-manager/metrics.js +6 -26
- package/dest/services/peer-manager/peer_manager.d.ts +2 -2
- package/dest/services/peer-manager/peer_manager.d.ts.map +1 -1
- package/dest/services/peer-manager/peer_manager.js +0 -10
- package/dest/services/peer-manager/peer_scoring.d.ts +1 -1
- package/dest/services/peer-manager/peer_scoring.d.ts.map +1 -1
- package/dest/services/peer-manager/peer_scoring.js +2 -5
- package/dest/services/reqresp/connection-sampler/connection_sampler.d.ts +1 -1
- package/dest/services/reqresp/connection-sampler/connection_sampler.d.ts.map +1 -1
- package/dest/services/reqresp/constants.d.ts +12 -0
- package/dest/services/reqresp/constants.d.ts.map +1 -0
- package/dest/services/reqresp/constants.js +7 -0
- package/dest/services/reqresp/metrics.d.ts +1 -1
- package/dest/services/reqresp/metrics.d.ts.map +1 -1
- package/dest/services/reqresp/metrics.js +5 -21
- package/dest/services/reqresp/protocols/block_txs/bitvector.d.ts +1 -1
- package/dest/services/reqresp/protocols/block_txs/bitvector.d.ts.map +1 -1
- package/dest/services/reqresp/protocols/block_txs/bitvector.js +7 -0
- package/dest/services/reqresp/protocols/status.d.ts +1 -1
- package/dest/services/reqresp/protocols/status.d.ts.map +1 -1
- package/dest/services/reqresp/protocols/status.js +4 -1
- package/dest/services/reqresp/reqresp.js +402 -24
- package/dest/services/service.d.ts +16 -3
- package/dest/services/service.d.ts.map +1 -1
- package/dest/services/tx_collection/instrumentation.d.ts +1 -1
- package/dest/services/tx_collection/instrumentation.d.ts.map +1 -1
- package/dest/services/tx_collection/instrumentation.js +4 -14
- package/dest/services/tx_collection/slow_tx_collection.d.ts +3 -3
- package/dest/services/tx_collection/slow_tx_collection.d.ts.map +1 -1
- package/dest/services/tx_collection/tx_collection.d.ts +5 -5
- package/dest/services/tx_collection/tx_collection.d.ts.map +1 -1
- package/dest/services/tx_provider.d.ts +3 -3
- package/dest/services/tx_provider.d.ts.map +1 -1
- package/dest/services/tx_provider_instrumentation.d.ts +1 -1
- package/dest/services/tx_provider_instrumentation.d.ts.map +1 -1
- package/dest/services/tx_provider_instrumentation.js +6 -19
- package/dest/testbench/p2p_client_testbench_worker.js +30 -17
- package/dest/testbench/worker_client_manager.d.ts +1 -1
- package/dest/testbench/worker_client_manager.d.ts.map +1 -1
- package/dest/testbench/worker_client_manager.js +6 -1
- package/package.json +16 -16
- package/src/client/interface.ts +19 -4
- package/src/client/p2p_client.ts +82 -132
- package/src/config.ts +2 -2
- package/src/mem_pools/attestation_pool/attestation_pool.ts +68 -41
- package/src/mem_pools/attestation_pool/attestation_pool_test_suite.ts +239 -287
- package/src/mem_pools/attestation_pool/kv_attestation_pool.ts +162 -140
- package/src/mem_pools/attestation_pool/memory_attestation_pool.ts +141 -164
- package/src/mem_pools/attestation_pool/mocks.ts +19 -13
- package/src/mem_pools/instrumentation.ts +9 -18
- package/src/mem_pools/tx_pool/README.md +28 -13
- package/src/mem_pools/tx_pool/aztec_kv_tx_pool.ts +130 -75
- package/src/mem_pools/tx_pool/eviction/eviction_manager.ts +66 -5
- package/src/mem_pools/tx_pool/eviction/eviction_strategy.ts +119 -4
- package/src/mem_pools/tx_pool/eviction/fee_payer_balance_eviction_rule.ts +162 -0
- package/src/mem_pools/tx_pool/eviction/invalid_txs_after_reorg_rule.ts +4 -2
- package/src/mem_pools/tx_pool/eviction/nullifier_conflict_pre_add_rule.ts +75 -0
- package/src/msg_validators/attestation_validator/attestation_validator.ts +36 -21
- package/src/msg_validators/attestation_validator/fisherman_attestation_validator.ts +13 -16
- package/src/msg_validators/clock_tolerance.ts +51 -0
- package/src/msg_validators/index.ts +1 -1
- package/src/msg_validators/proposal_validator/block_proposal_validator.ts +10 -0
- package/src/msg_validators/proposal_validator/checkpoint_proposal_validator.ts +13 -0
- package/src/msg_validators/proposal_validator/index.ts +3 -0
- package/src/msg_validators/proposal_validator/proposal_validator.ts +92 -0
- package/src/msg_validators/proposal_validator/proposal_validator_test_suite.ts +230 -0
- package/src/msg_validators/tx_validator/block_header_validator.ts +3 -1
- package/src/msg_validators/tx_validator/data_validator.ts +12 -4
- package/src/msg_validators/tx_validator/fee_payer_balance.ts +40 -0
- package/src/msg_validators/tx_validator/gas_validator.ts +8 -25
- package/src/msg_validators/tx_validator/index.ts +1 -0
- package/src/msg_validators/tx_validator/metadata_validator.ts +12 -4
- package/src/msg_validators/tx_validator/size_validator.ts +18 -0
- package/src/msg_validators/tx_validator/timestamp_validator.ts +3 -1
- package/src/services/dummy_service.ts +6 -0
- package/src/services/encoding.ts +5 -4
- package/src/services/libp2p/instrumentation.ts +19 -73
- package/src/services/libp2p/libp2p_service.ts +351 -115
- package/src/services/peer-manager/metrics.ts +5 -26
- package/src/services/peer-manager/peer_manager.ts +1 -2
- package/src/services/peer-manager/peer_scoring.ts +1 -5
- package/src/services/reqresp/connection-sampler/connection_sampler.ts +3 -1
- package/src/services/reqresp/constants.ts +14 -0
- package/src/services/reqresp/metrics.ts +7 -23
- package/src/services/reqresp/protocols/block_txs/bitvector.ts +9 -0
- package/src/services/reqresp/protocols/status.ts +7 -4
- package/src/services/service.ts +19 -4
- package/src/services/tx_collection/instrumentation.ts +4 -21
- package/src/services/tx_collection/slow_tx_collection.ts +2 -2
- package/src/services/tx_collection/tx_collection.ts +4 -4
- package/src/services/tx_provider.ts +2 -2
- package/src/services/tx_provider_instrumentation.ts +11 -24
- package/src/testbench/p2p_client_testbench_worker.ts +40 -21
- package/src/testbench/worker_client_manager.ts +6 -1
- package/dest/mem_pools/tx_pool/eviction/insufficient_fee_payer_balance_rule.d.ts +0 -15
- package/dest/mem_pools/tx_pool/eviction/insufficient_fee_payer_balance_rule.d.ts.map +0 -1
- package/dest/mem_pools/tx_pool/eviction/insufficient_fee_payer_balance_rule.js +0 -88
- package/dest/msg_validators/block_proposal_validator/block_proposal_validator.d.ts +0 -12
- package/dest/msg_validators/block_proposal_validator/block_proposal_validator.d.ts.map +0 -1
- package/dest/msg_validators/block_proposal_validator/block_proposal_validator.js +0 -82
- package/dest/msg_validators/block_proposal_validator/index.d.ts +0 -2
- package/dest/msg_validators/block_proposal_validator/index.d.ts.map +0 -1
- package/dest/msg_validators/block_proposal_validator/index.js +0 -1
- package/src/mem_pools/tx_pool/eviction/insufficient_fee_payer_balance_rule.ts +0 -108
- package/src/msg_validators/block_proposal_validator/block_proposal_validator.ts +0 -97
- package/src/msg_validators/block_proposal_validator/index.ts +0 -1
|
@@ -6,7 +6,6 @@ import {
|
|
|
6
6
|
type TelemetryClient,
|
|
7
7
|
type Tracer,
|
|
8
8
|
type UpDownCounter,
|
|
9
|
-
ValueType,
|
|
10
9
|
getTelemetryClient,
|
|
11
10
|
} from '@aztec/telemetry-client';
|
|
12
11
|
|
|
@@ -32,31 +31,11 @@ export class PeerManagerMetrics {
|
|
|
32
31
|
this.tracer = telemetryClient.getTracer(name);
|
|
33
32
|
|
|
34
33
|
const meter = telemetryClient.getMeter(name);
|
|
35
|
-
this.sentGoodbyes = meter.createUpDownCounter(Metrics.PEER_MANAGER_GOODBYES_SENT
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
this.receivedGoodbyes = meter.createUpDownCounter(Metrics.PEER_MANAGER_GOODBYES_RECEIVED, {
|
|
41
|
-
description: 'Number of goodbyes received from peers',
|
|
42
|
-
unit: 'peers',
|
|
43
|
-
valueType: ValueType.INT,
|
|
44
|
-
});
|
|
45
|
-
this.peerCount = meter.createGauge(Metrics.PEER_MANAGER_PEER_COUNT, {
|
|
46
|
-
description: 'Number of peers',
|
|
47
|
-
unit: 'peers',
|
|
48
|
-
valueType: ValueType.INT,
|
|
49
|
-
});
|
|
50
|
-
this.lowScoreDisconnects = meter.createUpDownCounter(Metrics.PEER_MANAGER_LOW_SCORE_DISCONNECTS, {
|
|
51
|
-
description: 'Number of peers disconnected due to low score',
|
|
52
|
-
unit: 'peers',
|
|
53
|
-
valueType: ValueType.INT,
|
|
54
|
-
});
|
|
55
|
-
this.peerConnectionDuration = meter.createHistogram(Metrics.PEER_MANAGER_PEER_CONNECTION_DURATION, {
|
|
56
|
-
description: 'Time duration between peer connection and disconnection',
|
|
57
|
-
unit: 'ms',
|
|
58
|
-
valueType: ValueType.INT,
|
|
59
|
-
});
|
|
34
|
+
this.sentGoodbyes = meter.createUpDownCounter(Metrics.PEER_MANAGER_GOODBYES_SENT);
|
|
35
|
+
this.receivedGoodbyes = meter.createUpDownCounter(Metrics.PEER_MANAGER_GOODBYES_RECEIVED);
|
|
36
|
+
this.peerCount = meter.createGauge(Metrics.PEER_MANAGER_PEER_COUNT);
|
|
37
|
+
this.lowScoreDisconnects = meter.createUpDownCounter(Metrics.PEER_MANAGER_LOW_SCORE_DISCONNECTS);
|
|
38
|
+
this.peerConnectionDuration = meter.createHistogram(Metrics.PEER_MANAGER_PEER_CONNECTION_DURATION);
|
|
60
39
|
}
|
|
61
40
|
|
|
62
41
|
public recordGoodbyeSent(reason: GoodByeReason) {
|
|
@@ -7,7 +7,7 @@ import { bufferToHex } from '@aztec/foundation/string';
|
|
|
7
7
|
import { DateProvider } from '@aztec/foundation/timer';
|
|
8
8
|
import type { PeerInfo, WorldStateSynchronizer } from '@aztec/stdlib/interfaces/server';
|
|
9
9
|
import type { PeerErrorSeverity } from '@aztec/stdlib/p2p';
|
|
10
|
-
import {
|
|
10
|
+
import type { TelemetryClient } from '@aztec/telemetry-client';
|
|
11
11
|
|
|
12
12
|
import type { Connection, PeerId } from '@libp2p/interface';
|
|
13
13
|
import { peerIdFromString } from '@libp2p/peer-id';
|
|
@@ -161,7 +161,6 @@ export class PeerManager implements PeerManagerInterface {
|
|
|
161
161
|
return this.metrics.tracer;
|
|
162
162
|
}
|
|
163
163
|
|
|
164
|
-
@trackSpan('PeerManager.heartbeat')
|
|
165
164
|
public async heartbeat() {
|
|
166
165
|
this.heartbeatCounter++;
|
|
167
166
|
this.peerScoring.decayAllScores();
|
|
@@ -6,7 +6,6 @@ import {
|
|
|
6
6
|
Metrics,
|
|
7
7
|
type TelemetryClient,
|
|
8
8
|
type UpDownCounter,
|
|
9
|
-
ValueType,
|
|
10
9
|
getTelemetryClient,
|
|
11
10
|
} from '@aztec/telemetry-client';
|
|
12
11
|
|
|
@@ -53,10 +52,7 @@ export class PeerScoring {
|
|
|
53
52
|
|
|
54
53
|
const meter = telemetry.getMeter('PeerScoring');
|
|
55
54
|
|
|
56
|
-
this.peerStateCounter = meter.createUpDownCounter(Metrics.P2P_PEER_STATE_COUNT
|
|
57
|
-
description: 'Count of peers by state (Healthy, Disconnect, Banned)',
|
|
58
|
-
valueType: ValueType.INT,
|
|
59
|
-
});
|
|
55
|
+
this.peerStateCounter = meter.createUpDownCounter(Metrics.P2P_PEER_STATE_COUNT);
|
|
60
56
|
}
|
|
61
57
|
|
|
62
58
|
public penalizePeer(peerId: PeerId, penalty: PeerErrorSeverity) {
|
|
@@ -261,7 +261,9 @@ export class ConnectionSampler {
|
|
|
261
261
|
}
|
|
262
262
|
} catch (error) {
|
|
263
263
|
this.logger.error(
|
|
264
|
-
`Error cleaning up stale connection to peer ${stream.metadata.peerId?.toString() ?? 'unknown'} stream ${
|
|
264
|
+
`Error cleaning up stale connection to peer ${stream.metadata.peerId?.toString() ?? 'unknown'} stream ${
|
|
265
|
+
stream.id
|
|
266
|
+
}`,
|
|
265
267
|
{ error },
|
|
266
268
|
);
|
|
267
269
|
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Constants for P2P message deserialization bounds checking.
|
|
3
|
+
* These constants define maximum allowed sizes during deserialization
|
|
4
|
+
* to prevent DoS attacks via maliciously crafted messages.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
/** Max transactions per block for deserialization validation (~300x default of 32) */
|
|
8
|
+
export { MAX_TXS_PER_BLOCK } from '@aztec/stdlib/deserialization';
|
|
9
|
+
|
|
10
|
+
/** Max version string length (e.g., "1.0.0-alpha.123") */
|
|
11
|
+
export const MAX_VERSION_STRING_LENGTH = 64;
|
|
12
|
+
|
|
13
|
+
/** Max block hash string length (hex: 0x + 64 chars, with generous headroom) */
|
|
14
|
+
export const MAX_BLOCK_HASH_STRING_LENGTH = 128;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// Request response metrics
|
|
2
|
-
import { Attributes, Metrics
|
|
2
|
+
import { Attributes, Metrics } from '@aztec/telemetry-client';
|
|
3
3
|
import type { TelemetryClient, Tracer, UpDownCounter } from '@aztec/telemetry-client';
|
|
4
4
|
|
|
5
5
|
export class ReqRespMetrics {
|
|
@@ -18,28 +18,12 @@ export class ReqRespMetrics {
|
|
|
18
18
|
this.tracer = telemetryClient.getTracer(name);
|
|
19
19
|
|
|
20
20
|
const meter = telemetryClient.getMeter(name);
|
|
21
|
-
this.sentRequests = meter.createUpDownCounter(Metrics.P2P_REQ_RESP_SENT_REQUESTS
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
this.
|
|
27
|
-
description: 'Number of requests received from peers',
|
|
28
|
-
unit: 'requests',
|
|
29
|
-
valueType: ValueType.INT,
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
this.failedOutboundRequests = meter.createUpDownCounter(Metrics.P2P_REQ_RESP_FAILED_OUTBOUND_REQUESTS, {
|
|
33
|
-
description: 'Number of failed outbound requests - nodes not getting valid responses',
|
|
34
|
-
unit: 'requests',
|
|
35
|
-
valueType: ValueType.INT,
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
this.failedInboundRequests = meter.createUpDownCounter(Metrics.P2P_REQ_RESP_FAILED_INBOUND_REQUESTS, {
|
|
39
|
-
description: 'Number of failed inbound requests - node failing to respond to requests',
|
|
40
|
-
unit: 'requests',
|
|
41
|
-
valueType: ValueType.INT,
|
|
42
|
-
});
|
|
21
|
+
this.sentRequests = meter.createUpDownCounter(Metrics.P2P_REQ_RESP_SENT_REQUESTS);
|
|
22
|
+
this.receivedRequests = meter.createUpDownCounter(Metrics.P2P_REQ_RESP_RECEIVED_REQUESTS);
|
|
23
|
+
|
|
24
|
+
this.failedOutboundRequests = meter.createUpDownCounter(Metrics.P2P_REQ_RESP_FAILED_OUTBOUND_REQUESTS);
|
|
25
|
+
|
|
26
|
+
this.failedInboundRequests = meter.createUpDownCounter(Metrics.P2P_REQ_RESP_FAILED_INBOUND_REQUESTS);
|
|
43
27
|
}
|
|
44
28
|
|
|
45
29
|
public recordRequestSent(protocol: string) {
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { BufferReader, serializeToBuffer } from '@aztec/foundation/serialize';
|
|
2
2
|
|
|
3
|
+
import { MAX_TXS_PER_BLOCK } from '../../constants.js';
|
|
4
|
+
|
|
3
5
|
/**
|
|
4
6
|
* BitVector helper class for representing and serializing bit vectors
|
|
5
7
|
*/
|
|
@@ -80,6 +82,13 @@ export class BitVector {
|
|
|
80
82
|
const reader = BufferReader.asReader(buffer);
|
|
81
83
|
const length = reader.readNumber();
|
|
82
84
|
|
|
85
|
+
if (length < 0) {
|
|
86
|
+
throw new Error(`BitVector length ${length} cannot be negative`);
|
|
87
|
+
}
|
|
88
|
+
if (length > MAX_TXS_PER_BLOCK) {
|
|
89
|
+
throw new Error(`BitVector length ${length} exceeds maximum ${MAX_TXS_PER_BLOCK}`);
|
|
90
|
+
}
|
|
91
|
+
|
|
83
92
|
const bitBuffer = reader.readBytes(BitVector.byteLength(length));
|
|
84
93
|
return new BitVector(bitBuffer, length);
|
|
85
94
|
}
|
|
@@ -7,6 +7,8 @@ import type { WorldStateSyncStatus, WorldStateSynchronizer } from '@aztec/stdlib
|
|
|
7
7
|
|
|
8
8
|
import type { PeerId } from '@libp2p/interface';
|
|
9
9
|
|
|
10
|
+
import { MAX_BLOCK_HASH_STRING_LENGTH, MAX_VERSION_STRING_LENGTH } from '../constants.js';
|
|
11
|
+
|
|
10
12
|
/*
|
|
11
13
|
* P2P Status Message
|
|
12
14
|
* It is used to establish Status handshake between to peers
|
|
@@ -19,9 +21,10 @@ export class StatusMessage {
|
|
|
19
21
|
readonly latestBlockNumber: BlockNumber,
|
|
20
22
|
readonly latestBlockHash: string,
|
|
21
23
|
readonly finalizedBlockNumber: BlockNumber,
|
|
24
|
+
) {
|
|
22
25
|
//TODO: add finalizedBlockHash
|
|
23
26
|
//readonly finalizedBlockHash: string,
|
|
24
|
-
|
|
27
|
+
}
|
|
25
28
|
|
|
26
29
|
/**
|
|
27
30
|
* Deserializes the StatusMessage object from a Buffer.
|
|
@@ -31,12 +34,12 @@ export class StatusMessage {
|
|
|
31
34
|
static fromBuffer(buffer: Buffer | BufferReader): StatusMessage {
|
|
32
35
|
const reader = BufferReader.asReader(buffer);
|
|
33
36
|
return new StatusMessage(
|
|
34
|
-
reader.readString(), // compressedComponentsVersion
|
|
37
|
+
reader.readString(MAX_VERSION_STRING_LENGTH), // compressedComponentsVersion
|
|
35
38
|
BlockNumber(reader.readNumber()), // latestBlockNumber
|
|
36
|
-
reader.readString(), // latestBlockHash
|
|
39
|
+
reader.readString(MAX_BLOCK_HASH_STRING_LENGTH), // latestBlockHash
|
|
37
40
|
BlockNumber(reader.readNumber()), // finalizedBlockNumber
|
|
38
41
|
//TODO: add finalizedBlockHash
|
|
39
|
-
//reader.readString(), // finalizedBlockHash
|
|
42
|
+
//reader.readString(MAX_BLOCK_HASH_STRING_LENGTH), // finalizedBlockHash
|
|
40
43
|
);
|
|
41
44
|
}
|
|
42
45
|
|
package/src/services/service.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { EthAddress } from '@aztec/foundation/eth-address';
|
|
2
2
|
import type { PeerInfo } from '@aztec/stdlib/interfaces/server';
|
|
3
|
-
import type {
|
|
3
|
+
import type { BlockProposal, CheckpointAttestation, CheckpointProposalCore, Gossipable } from '@aztec/stdlib/p2p';
|
|
4
4
|
import type { Tx } from '@aztec/stdlib/tx';
|
|
5
5
|
|
|
6
6
|
import type { PeerId } from '@libp2p/interface';
|
|
@@ -22,10 +22,23 @@ export enum PeerDiscoveryState {
|
|
|
22
22
|
STOPPED = 'stopped',
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
-
|
|
26
|
-
|
|
25
|
+
/**
|
|
26
|
+
* Callback for when a block proposal is received.
|
|
27
|
+
* Validators validate but DO NOT attest to individual blocks - attestations are only for checkpoints.
|
|
28
|
+
* @returns true if the proposal is valid, false otherwise
|
|
29
|
+
*/
|
|
30
|
+
export type P2PBlockReceivedCallback = (block: BlockProposal, sender: PeerId) => Promise<boolean>;
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Callback for when a checkpoint proposal is received.
|
|
34
|
+
* The checkpoint proposal is passed as CheckpointProposalCore (without lastBlock) since
|
|
35
|
+
* the lastBlock is extracted and stored separately as a BlockProposal, and the block
|
|
36
|
+
* callback is invoked and awaited before this checkpoint callback.
|
|
37
|
+
*/
|
|
38
|
+
export type P2PCheckpointReceivedCallback = (
|
|
39
|
+
checkpoint: CheckpointProposalCore,
|
|
27
40
|
sender: PeerId,
|
|
28
|
-
) => Promise<
|
|
41
|
+
) => Promise<CheckpointAttestation[] | undefined>;
|
|
29
42
|
|
|
30
43
|
export type AuthReceivedCallback = (peerId: PeerId, authRequest: AuthRequest) => Promise<AuthResponse | undefined>;
|
|
31
44
|
|
|
@@ -70,6 +83,8 @@ export interface P2PService {
|
|
|
70
83
|
// Leaky abstraction: fix https://github.com/AztecProtocol/aztec-packages/issues/7963
|
|
71
84
|
registerBlockReceivedCallback(callback: P2PBlockReceivedCallback): void;
|
|
72
85
|
|
|
86
|
+
registerCheckpointReceivedCallback(callback: P2PCheckpointReceivedCallback): void;
|
|
87
|
+
|
|
73
88
|
getEnr(): ENR | undefined;
|
|
74
89
|
|
|
75
90
|
getPeers(includePending?: boolean): PeerInfo[];
|
|
@@ -1,11 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
Attributes,
|
|
3
|
-
type Histogram,
|
|
4
|
-
Metrics,
|
|
5
|
-
type TelemetryClient,
|
|
6
|
-
type UpDownCounter,
|
|
7
|
-
ValueType,
|
|
8
|
-
} from '@aztec/telemetry-client';
|
|
1
|
+
import { Attributes, type Histogram, Metrics, type TelemetryClient, type UpDownCounter } from '@aztec/telemetry-client';
|
|
9
2
|
|
|
10
3
|
import type { CollectionMethod } from './tx_collection.js';
|
|
11
4
|
|
|
@@ -17,21 +10,11 @@ export class TxCollectionInstrumentation {
|
|
|
17
10
|
constructor(client: TelemetryClient, name: string) {
|
|
18
11
|
const meter = client.getMeter(name);
|
|
19
12
|
|
|
20
|
-
this.txsCollected = meter.createUpDownCounter(Metrics.TX_COLLECTOR_COUNT
|
|
21
|
-
description: 'The number of txs collected',
|
|
22
|
-
});
|
|
13
|
+
this.txsCollected = meter.createUpDownCounter(Metrics.TX_COLLECTOR_COUNT);
|
|
23
14
|
|
|
24
|
-
this.collectionDurationPerTx = meter.createHistogram(Metrics.TX_COLLECTOR_DURATION_PER_TX
|
|
25
|
-
unit: 'ms',
|
|
26
|
-
description: 'Average duration per tx of an individual tx collection request',
|
|
27
|
-
valueType: ValueType.INT,
|
|
28
|
-
});
|
|
15
|
+
this.collectionDurationPerTx = meter.createHistogram(Metrics.TX_COLLECTOR_DURATION_PER_TX);
|
|
29
16
|
|
|
30
|
-
this.collectionDurationPerRequest = meter.createHistogram(Metrics.TX_COLLECTOR_DURATION_PER_REQUEST
|
|
31
|
-
unit: 'ms',
|
|
32
|
-
description: 'Total duration of an individual tx collection request',
|
|
33
|
-
valueType: ValueType.INT,
|
|
34
|
-
});
|
|
17
|
+
this.collectionDurationPerRequest = meter.createHistogram(Metrics.TX_COLLECTOR_DURATION_PER_REQUEST);
|
|
35
18
|
}
|
|
36
19
|
|
|
37
20
|
increaseTxsFor(what: CollectionMethod, count: number, duration: number) {
|
|
@@ -4,7 +4,7 @@ import { type Logger, createLogger } from '@aztec/foundation/log';
|
|
|
4
4
|
import { boundInclusive } from '@aztec/foundation/number';
|
|
5
5
|
import { RunningPromise } from '@aztec/foundation/promise';
|
|
6
6
|
import { DateProvider } from '@aztec/foundation/timer';
|
|
7
|
-
import type {
|
|
7
|
+
import type { L2Block } from '@aztec/stdlib/block';
|
|
8
8
|
import { type L1RollupConstants, getEpochAtSlot, getTimestampRangeForEpoch } from '@aztec/stdlib/epoch-helpers';
|
|
9
9
|
import { type Tx, TxHash } from '@aztec/stdlib/tx';
|
|
10
10
|
|
|
@@ -76,7 +76,7 @@ export class SlowTxCollection {
|
|
|
76
76
|
}
|
|
77
77
|
|
|
78
78
|
/** Starts collecting the given tx hashes for the given L2Block in the slow loop */
|
|
79
|
-
public startCollecting(block:
|
|
79
|
+
public startCollecting(block: L2Block, txHashes: TxHash[]) {
|
|
80
80
|
const slot = block.header.getSlot();
|
|
81
81
|
const deadline = this.getDeadlineForSlot(slot);
|
|
82
82
|
if (+deadline < this.dateProvider.now()) {
|
|
@@ -3,7 +3,7 @@ import { compactArray } from '@aztec/foundation/collection';
|
|
|
3
3
|
import { type Logger, createLogger } from '@aztec/foundation/log';
|
|
4
4
|
import { type PromiseWithResolvers, RunningPromise } from '@aztec/foundation/promise';
|
|
5
5
|
import { DateProvider } from '@aztec/foundation/timer';
|
|
6
|
-
import type {
|
|
6
|
+
import type { L2Block, L2BlockInfo } from '@aztec/stdlib/block';
|
|
7
7
|
import type { L1RollupConstants } from '@aztec/stdlib/epoch-helpers';
|
|
8
8
|
import type { BlockProposal } from '@aztec/stdlib/p2p';
|
|
9
9
|
import { Tx, TxHash } from '@aztec/stdlib/tx';
|
|
@@ -25,7 +25,7 @@ export type CollectionMethod = 'fast-req-resp' | 'fast-node-rpc' | 'slow-req-res
|
|
|
25
25
|
export type MissingTxInfo = { blockNumber: BlockNumber; deadline: Date; readyForReqResp: boolean };
|
|
26
26
|
|
|
27
27
|
export type FastCollectionRequestInput =
|
|
28
|
-
| { type: 'block'; block:
|
|
28
|
+
| { type: 'block'; block: L2Block }
|
|
29
29
|
| { type: 'proposal'; blockProposal: BlockProposal; blockNumber: BlockNumber };
|
|
30
30
|
|
|
31
31
|
export type FastCollectionRequest = FastCollectionRequestInput & {
|
|
@@ -146,7 +146,7 @@ export class TxCollection {
|
|
|
146
146
|
}
|
|
147
147
|
|
|
148
148
|
/** Starts collecting the given tx hashes for the given L2Block in the slow loop */
|
|
149
|
-
public startCollecting(block:
|
|
149
|
+
public startCollecting(block: L2Block, txHashes: TxHash[]) {
|
|
150
150
|
return this.slowCollection.startCollecting(block, txHashes);
|
|
151
151
|
}
|
|
152
152
|
|
|
@@ -162,7 +162,7 @@ export class TxCollection {
|
|
|
162
162
|
|
|
163
163
|
/** Collects the set of txs for the given mined block as fast as possible */
|
|
164
164
|
public collectFastForBlock(
|
|
165
|
-
block:
|
|
165
|
+
block: L2Block,
|
|
166
166
|
txHashes: TxHash[] | string[],
|
|
167
167
|
opts: { deadline: Date; pinnedPeer?: PeerId },
|
|
168
168
|
) {
|
|
@@ -2,7 +2,7 @@ import { BlockNumber } from '@aztec/foundation/branded-types';
|
|
|
2
2
|
import { compactArray } from '@aztec/foundation/collection';
|
|
3
3
|
import { type Logger, createLogger } from '@aztec/foundation/log';
|
|
4
4
|
import { elapsed } from '@aztec/foundation/timer';
|
|
5
|
-
import type {
|
|
5
|
+
import type { L2Block, L2BlockInfo } from '@aztec/stdlib/block';
|
|
6
6
|
import type { ITxProvider } from '@aztec/stdlib/interfaces/server';
|
|
7
7
|
import type { BlockProposal } from '@aztec/stdlib/p2p';
|
|
8
8
|
import { Tx, TxHash } from '@aztec/stdlib/tx';
|
|
@@ -68,7 +68,7 @@ export class TxProvider implements ITxProvider {
|
|
|
68
68
|
}
|
|
69
69
|
|
|
70
70
|
/** Gathers txs from the tx pool, remote rpc nodes, and reqresp. */
|
|
71
|
-
public getTxsForBlock(block:
|
|
71
|
+
public getTxsForBlock(block: L2Block, opts: { deadline: Date }): Promise<{ txs: Tx[]; missingTxs: TxHash[] }> {
|
|
72
72
|
return this.getOrderedTxsFromAllSources(
|
|
73
73
|
{ type: 'block', block },
|
|
74
74
|
block.toBlockInfo(),
|
|
@@ -12,30 +12,17 @@ export class TxProviderInstrumentation {
|
|
|
12
12
|
constructor(client: TelemetryClient, name: string) {
|
|
13
13
|
const meter = client.getMeter(name);
|
|
14
14
|
|
|
15
|
-
this.txFromProposalCount = meter.createUpDownCounter(Metrics.TX_PROVIDER_TXS_FROM_PROPOSALS_COUNT
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
this.
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
this.
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
this.missingTxsCount = meter.createUpDownCounter(Metrics.TX_PROVIDER_MISSING_TXS_COUNT, {
|
|
28
|
-
description: 'The number of txs not found anywhere',
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
this.fractionOfTxsRequestedFromP2P = meter.createHistogram(Metrics.TX_PROVIDER_P2P_TXS_REQUESTED_FRACTION, {
|
|
32
|
-
description: 'The fraction of transaction requested from peers',
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
this.txsRequestDelay = meter.createHistogram(Metrics.TX_PROVIDER_P2P_TXS_REQUEST_DELAY, {
|
|
36
|
-
unit: 'ms',
|
|
37
|
-
description: 'The time it took to request missing transactions from p2p',
|
|
38
|
-
});
|
|
15
|
+
this.txFromProposalCount = meter.createUpDownCounter(Metrics.TX_PROVIDER_TXS_FROM_PROPOSALS_COUNT);
|
|
16
|
+
|
|
17
|
+
this.txFromMempoolCount = meter.createUpDownCounter(Metrics.TX_PROVIDER_TXS_FROM_MEMPOOL_COUNT);
|
|
18
|
+
|
|
19
|
+
this.txFromP2PCount = meter.createUpDownCounter(Metrics.TX_PROVIDER_TXS_FROM_P2P_COUNT);
|
|
20
|
+
|
|
21
|
+
this.missingTxsCount = meter.createUpDownCounter(Metrics.TX_PROVIDER_MISSING_TXS_COUNT);
|
|
22
|
+
|
|
23
|
+
this.fractionOfTxsRequestedFromP2P = meter.createHistogram(Metrics.TX_PROVIDER_P2P_TXS_REQUESTED_FRACTION);
|
|
24
|
+
|
|
25
|
+
this.txsRequestDelay = meter.createHistogram(Metrics.TX_PROVIDER_P2P_TXS_REQUEST_DELAY);
|
|
39
26
|
}
|
|
40
27
|
|
|
41
28
|
incTxsFromProposals(count: number) {
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
import { MockL2BlockSource } from '@aztec/archiver/test';
|
|
7
7
|
import type { EpochCacheInterface } from '@aztec/epoch-cache';
|
|
8
8
|
import { EpochNumber, SlotNumber } from '@aztec/foundation/branded-types';
|
|
9
|
-
import {
|
|
9
|
+
import { SecretValue } from '@aztec/foundation/config';
|
|
10
10
|
import { createLogger } from '@aztec/foundation/log';
|
|
11
11
|
import { sleep } from '@aztec/foundation/sleep';
|
|
12
12
|
import type { DataStoreConfig } from '@aztec/kv-store/config';
|
|
@@ -65,35 +65,37 @@ function mockTxPool(): TxPool {
|
|
|
65
65
|
function mockAttestationPool(): AttestationPool {
|
|
66
66
|
return {
|
|
67
67
|
isEmpty: () => Promise.resolve(false),
|
|
68
|
-
addAttestations: () => Promise.resolve(),
|
|
69
|
-
deleteAttestations: () => Promise.resolve(),
|
|
70
|
-
deleteAttestationsOlderThan: () => Promise.resolve(),
|
|
71
|
-
deleteAttestationsForSlot: () => Promise.resolve(),
|
|
72
|
-
deleteAttestationsForSlotAndProposal: () => Promise.resolve(),
|
|
73
|
-
getAttestationsForSlot: () => Promise.resolve([]),
|
|
74
|
-
getAttestationsForSlotAndProposal: () => Promise.resolve([]),
|
|
75
68
|
addBlockProposal: () => Promise.resolve(),
|
|
76
69
|
getBlockProposal: () => Promise.resolve(undefined),
|
|
77
70
|
hasBlockProposal: () => Promise.resolve(false),
|
|
78
|
-
hasAttestation: () => Promise.resolve(false),
|
|
79
71
|
canAddProposal: () => Promise.resolve(true),
|
|
80
|
-
|
|
72
|
+
// Checkpoint attestation methods
|
|
73
|
+
addCheckpointProposal: () => Promise.resolve(),
|
|
74
|
+
getCheckpointProposal: () => Promise.resolve(undefined),
|
|
75
|
+
hasCheckpointProposal: () => Promise.resolve(false),
|
|
76
|
+
addCheckpointAttestations: () => Promise.resolve(),
|
|
77
|
+
getCheckpointAttestationsForSlot: () => Promise.resolve([]),
|
|
78
|
+
getCheckpointAttestationsForSlotAndProposal: () => Promise.resolve([]),
|
|
79
|
+
deleteCheckpointAttestationsOlderThan: () => Promise.resolve(),
|
|
80
|
+
hasReachedCheckpointProposalCap: () => Promise.resolve(false),
|
|
81
|
+
hasReachedCheckpointAttestationCap: () => Promise.resolve(false),
|
|
82
|
+
canAddCheckpointProposal: () => Promise.resolve(true),
|
|
83
|
+
canAddCheckpointAttestation: () => Promise.resolve(true),
|
|
84
|
+
hasCheckpointAttestation: () => Promise.resolve(false),
|
|
81
85
|
};
|
|
82
86
|
}
|
|
83
87
|
|
|
84
88
|
function mockEpochCache(): EpochCacheInterface {
|
|
85
89
|
return {
|
|
86
|
-
getCommittee: () => Promise.resolve({ committee: [], seed: 1n, epoch: EpochNumber.ZERO }),
|
|
90
|
+
getCommittee: () => Promise.resolve({ committee: [], seed: 1n, epoch: EpochNumber.ZERO, isEscapeHatchOpen: false }),
|
|
87
91
|
getProposerIndexEncoding: () => '0x' as `0x${string}`,
|
|
88
|
-
getEpochAndSlotNow: () => ({ epoch: EpochNumber.ZERO, slot: SlotNumber.ZERO, ts: 0n }),
|
|
92
|
+
getEpochAndSlotNow: () => ({ epoch: EpochNumber.ZERO, slot: SlotNumber.ZERO, ts: 0n, nowMs: 0n }),
|
|
89
93
|
computeProposerIndex: () => 0n,
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
nextSlot: SlotNumber.ZERO,
|
|
96
|
-
}),
|
|
94
|
+
getCurrentAndNextSlot: () => ({
|
|
95
|
+
currentSlot: SlotNumber.ZERO,
|
|
96
|
+
nextSlot: SlotNumber.ZERO,
|
|
97
|
+
}),
|
|
98
|
+
getProposerAttesterAddressInSlot: () => Promise.resolve(undefined),
|
|
97
99
|
getEpochAndSlotInNextL1Slot: () => ({ epoch: EpochNumber.ZERO, slot: SlotNumber.ZERO, ts: 0n, now: 0n }),
|
|
98
100
|
isInCommittee: () => Promise.resolve(false),
|
|
99
101
|
getRegisteredValidators: () => Promise.resolve([]),
|
|
@@ -189,9 +191,25 @@ class TestLibP2PService<T extends P2PClientType = P2PClientType.Full> extends Li
|
|
|
189
191
|
|
|
190
192
|
// eslint-disable-next-line @typescript-eslint/no-misused-promises
|
|
191
193
|
process.on('message', async msg => {
|
|
192
|
-
|
|
194
|
+
// Note: peerIdPrivateKey comes as a raw string (not SecretValue) because
|
|
195
|
+
// SecretValue's private fields can't be serialized via IPC
|
|
196
|
+
const {
|
|
197
|
+
type,
|
|
198
|
+
config: rawConfig,
|
|
199
|
+
clientIndex,
|
|
200
|
+
} = msg as {
|
|
201
|
+
type: string;
|
|
202
|
+
config: Omit<P2PConfig, 'peerIdPrivateKey'> & { peerIdPrivateKey?: string };
|
|
203
|
+
clientIndex: number;
|
|
204
|
+
};
|
|
193
205
|
try {
|
|
194
206
|
if (type === 'START') {
|
|
207
|
+
// Re-wrap the peerIdPrivateKey with SecretValue
|
|
208
|
+
const config: P2PConfig = {
|
|
209
|
+
...rawConfig,
|
|
210
|
+
peerIdPrivateKey: rawConfig.peerIdPrivateKey ? new SecretValue(rawConfig.peerIdPrivateKey) : undefined,
|
|
211
|
+
} as P2PConfig;
|
|
212
|
+
|
|
195
213
|
const txPool = mockTxPool();
|
|
196
214
|
const attestationPool = mockAttestationPool();
|
|
197
215
|
const epochCache = mockEpochCache();
|
|
@@ -224,14 +242,15 @@ process.on('message', async msg => {
|
|
|
224
242
|
);
|
|
225
243
|
|
|
226
244
|
// Create test service with validation disabled
|
|
245
|
+
// Note: Parameter order must match LibP2PService constructor
|
|
227
246
|
const testService = new TestLibP2PService(
|
|
228
247
|
P2PClientType.Full,
|
|
229
248
|
config,
|
|
230
249
|
(client as any).p2pService.node,
|
|
231
250
|
(client as any).p2pService.peerDiscoveryService,
|
|
232
|
-
(client as any).p2pService.mempools,
|
|
233
251
|
(client as any).p2pService.reqresp,
|
|
234
252
|
(client as any).p2pService.peerManager,
|
|
253
|
+
(client as any).p2pService.mempools,
|
|
235
254
|
(client as any).p2pService.archiver,
|
|
236
255
|
epochCache,
|
|
237
256
|
proofVerifier,
|
|
@@ -73,7 +73,12 @@ class WorkerClientManager {
|
|
|
73
73
|
clientIndex: number,
|
|
74
74
|
): [ChildProcess, Promise<void>] {
|
|
75
75
|
const childProcess = fork(workerPath);
|
|
76
|
-
|
|
76
|
+
// Extract the raw peerIdPrivateKey value since SecretValue can't be serialized via IPC
|
|
77
|
+
const serializedConfig = {
|
|
78
|
+
...config,
|
|
79
|
+
peerIdPrivateKey: config.peerIdPrivateKey?.getValue(),
|
|
80
|
+
};
|
|
81
|
+
childProcess.send({ type: 'START', config: serializedConfig, clientIndex });
|
|
77
82
|
|
|
78
83
|
// Handle unexpected child process exit
|
|
79
84
|
childProcess.on('exit', (code, signal) => {
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import type { ReadonlyWorldStateAccess } from '@aztec/stdlib/interfaces/server';
|
|
2
|
-
import type { TxPoolOptions } from '../tx_pool.js';
|
|
3
|
-
import { type EvictionContext, type EvictionResult, type EvictionRule, type TxPoolOperations } from './eviction_strategy.js';
|
|
4
|
-
export declare class InsufficientFeePayerBalanceRule implements EvictionRule {
|
|
5
|
-
private worldState;
|
|
6
|
-
readonly name: string;
|
|
7
|
-
readonly reason: string;
|
|
8
|
-
constructor(worldState: ReadonlyWorldStateAccess);
|
|
9
|
-
private log;
|
|
10
|
-
evict(context: EvictionContext, txPool: TxPoolOperations): Promise<EvictionResult>;
|
|
11
|
-
private evictTxs;
|
|
12
|
-
private createGasTxValidator;
|
|
13
|
-
updateConfig(_config: TxPoolOptions): void;
|
|
14
|
-
}
|
|
15
|
-
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5zdWZmaWNpZW50X2ZlZV9wYXllcl9iYWxhbmNlX3J1bGUuZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uLy4uL3NyYy9tZW1fcG9vbHMvdHhfcG9vbC9ldmljdGlvbi9pbnN1ZmZpY2llbnRfZmVlX3BheWVyX2JhbGFuY2VfcnVsZS50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFHQSxPQUFPLEtBQUssRUFBRSx3QkFBd0IsRUFBRSxNQUFNLGlDQUFpQyxDQUFDO0FBS2hGLE9BQU8sS0FBSyxFQUFFLGFBQWEsRUFBRSxNQUFNLGVBQWUsQ0FBQztBQUNuRCxPQUFPLEVBQ0wsS0FBSyxlQUFlLEVBRXBCLEtBQUssY0FBYyxFQUNuQixLQUFLLFlBQVksRUFFakIsS0FBSyxnQkFBZ0IsRUFDdEIsTUFBTSx3QkFBd0IsQ0FBQztBQUVoQyxxQkFBYSwrQkFBZ0MsWUFBVyxZQUFZO0lBSS9DLE9BQU8sQ0FBQyxVQUFVO0lBSHJDLFNBQWdCLElBQUksU0FBaUM7SUFDckQsU0FBZ0IsTUFBTSxTQUE0QjtJQUVsRCxZQUEyQixVQUFVLEVBQUUsd0JBQXdCLEVBQUk7SUFFbkUsT0FBTyxDQUFDLEdBQUcsQ0FBMkU7SUFFaEYsS0FBSyxDQUFDLE9BQU8sRUFBRSxlQUFlLEVBQUUsTUFBTSxFQUFFLGdCQUFnQixHQUFHLE9BQU8sQ0FBQyxjQUFjLENBQUMsQ0FrQ3ZGO1lBRWEsUUFBUTtJQXdDdEIsT0FBTyxDQUFDLG9CQUFvQjtJQUk1QixZQUFZLENBQUMsT0FBTyxFQUFFLGFBQWEsR0FBRyxJQUFJLENBQUc7Q0FDOUMifQ==
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"insufficient_fee_payer_balance_rule.d.ts","sourceRoot":"","sources":["../../../../src/mem_pools/tx_pool/eviction/insufficient_fee_payer_balance_rule.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,iCAAiC,CAAC;AAKhF,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AACnD,OAAO,EACL,KAAK,eAAe,EAEpB,KAAK,cAAc,EACnB,KAAK,YAAY,EAEjB,KAAK,gBAAgB,EACtB,MAAM,wBAAwB,CAAC;AAEhC,qBAAa,+BAAgC,YAAW,YAAY;IAI/C,OAAO,CAAC,UAAU;IAHrC,SAAgB,IAAI,SAAiC;IACrD,SAAgB,MAAM,SAA4B;IAElD,YAA2B,UAAU,EAAE,wBAAwB,EAAI;IAEnE,OAAO,CAAC,GAAG,CAA2E;IAEhF,KAAK,CAAC,OAAO,EAAE,eAAe,EAAE,MAAM,EAAE,gBAAgB,GAAG,OAAO,CAAC,cAAc,CAAC,CAkCvF;YAEa,QAAQ;IAwCtB,OAAO,CAAC,oBAAoB;IAI5B,YAAY,CAAC,OAAO,EAAE,aAAa,GAAG,IAAI,CAAG;CAC9C"}
|
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
import { createLogger } from '@aztec/foundation/log';
|
|
2
|
-
import { ProtocolContractAddress } from '@aztec/protocol-contracts';
|
|
3
|
-
import { GasFees } from '@aztec/stdlib/gas';
|
|
4
|
-
import { DatabasePublicStateSource } from '@aztec/stdlib/trees';
|
|
5
|
-
import { GasTxValidator } from '../../../msg_validators/index.js';
|
|
6
|
-
import { EvictionEvent } from './eviction_strategy.js';
|
|
7
|
-
export class InsufficientFeePayerBalanceRule {
|
|
8
|
-
worldState;
|
|
9
|
-
name;
|
|
10
|
-
reason;
|
|
11
|
-
constructor(worldState){
|
|
12
|
-
this.worldState = worldState;
|
|
13
|
-
this.name = 'InsufficientFeePayerBalance';
|
|
14
|
-
this.reason = 'insufficient_fee_juice';
|
|
15
|
-
this.log = createLogger('p2p:mempool:tx_pool:insufficient_fee_payer_balance_rule');
|
|
16
|
-
}
|
|
17
|
-
log;
|
|
18
|
-
async evict(context, txPool) {
|
|
19
|
-
try {
|
|
20
|
-
if (context.event === EvictionEvent.CHAIN_PRUNED) {
|
|
21
|
-
const affectedTxs = await txPool.getPendingTxInfos();
|
|
22
|
-
return this.evictTxs(affectedTxs, context.blockNumber, txPool);
|
|
23
|
-
}
|
|
24
|
-
if (context.event === EvictionEvent.BLOCK_MINED) {
|
|
25
|
-
const affectedTxs = await txPool.getPendingTxsWithFeePayer(context.minedFeePayers);
|
|
26
|
-
// TODO: fix this edge-case
|
|
27
|
-
// This can lead to a race condition if we are catching up in the p2p client.
|
|
28
|
-
// Let's say we have 3 txs for the same fee payer, which get mined in blocks 1, 2, 3.
|
|
29
|
-
// Tx1 consumes fee juice, tx2 increases it, tx3 consumes it again. We see block1 with tx1 first, run this rule, and evict tx3.
|
|
30
|
-
// But tx3 was valid (due to tx2) and mined on block3. And we have just removed from the mempool a tx we needed for proving/reexec.
|
|
31
|
-
// -----
|
|
32
|
-
// Proposed fix: evict only if node is synched
|
|
33
|
-
return this.evictTxs(affectedTxs, context.block.getBlockNumber(), txPool);
|
|
34
|
-
}
|
|
35
|
-
return {
|
|
36
|
-
reason: this.reason,
|
|
37
|
-
success: true,
|
|
38
|
-
txsEvicted: []
|
|
39
|
-
};
|
|
40
|
-
} catch (err) {
|
|
41
|
-
this.log.error('Failed to evict invalid transactions after mining', {
|
|
42
|
-
err
|
|
43
|
-
});
|
|
44
|
-
return {
|
|
45
|
-
reason: this.reason,
|
|
46
|
-
success: false,
|
|
47
|
-
txsEvicted: [],
|
|
48
|
-
error: new Error('Failed to evict invalid txs after mining', {
|
|
49
|
-
cause: err
|
|
50
|
-
})
|
|
51
|
-
};
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
async evictTxs(candidateTxs, blockNumber, txPool) {
|
|
55
|
-
const txsToEvict = [];
|
|
56
|
-
const gasValidator = this.createGasTxValidator(this.worldState.getSnapshot(blockNumber));
|
|
57
|
-
for (const { txHash, isEvictable } of candidateTxs){
|
|
58
|
-
if (!isEvictable) {
|
|
59
|
-
continue;
|
|
60
|
-
}
|
|
61
|
-
const tx = await txPool.getTxByHash(txHash);
|
|
62
|
-
if (!tx) {
|
|
63
|
-
continue;
|
|
64
|
-
}
|
|
65
|
-
this.log.debug(`Validating tx balance ${txHash}`);
|
|
66
|
-
if ((await gasValidator.validateTxFee(tx)).result === 'invalid') {
|
|
67
|
-
this.log.verbose(`Evicting tx ${txHash} from pool due to an insufficient fee payer balance`);
|
|
68
|
-
txsToEvict.push(txHash);
|
|
69
|
-
continue;
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
if (txsToEvict.length > 0) {
|
|
73
|
-
await txPool.deleteTxs(txsToEvict);
|
|
74
|
-
}
|
|
75
|
-
this.log.verbose(`Evicted ${txsToEvict.length} invalid txs after block mined`, {
|
|
76
|
-
txsToEvict
|
|
77
|
-
});
|
|
78
|
-
return {
|
|
79
|
-
reason: this.reason,
|
|
80
|
-
success: true,
|
|
81
|
-
txsEvicted: txsToEvict
|
|
82
|
-
};
|
|
83
|
-
}
|
|
84
|
-
createGasTxValidator(db) {
|
|
85
|
-
return new GasTxValidator(new DatabasePublicStateSource(db), ProtocolContractAddress.FeeJuice, GasFees.empty());
|
|
86
|
-
}
|
|
87
|
-
updateConfig(_config) {}
|
|
88
|
-
}
|