@aztec/p2p 0.86.0 → 0.87.0

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.
Files changed (159) hide show
  1. package/dest/bootstrap/bootstrap.d.ts.map +1 -1
  2. package/dest/client/factory.d.ts +4 -1
  3. package/dest/client/factory.d.ts.map +1 -1
  4. package/dest/client/factory.js +16 -14
  5. package/dest/client/index.d.ts +1 -0
  6. package/dest/client/index.d.ts.map +1 -1
  7. package/dest/client/index.js +1 -0
  8. package/dest/client/interface.d.ts +155 -0
  9. package/dest/client/interface.d.ts.map +1 -0
  10. package/dest/client/interface.js +9 -0
  11. package/dest/client/p2p_client.d.ts +26 -164
  12. package/dest/client/p2p_client.d.ts.map +1 -1
  13. package/dest/client/p2p_client.js +185 -114
  14. package/dest/config.d.ts +5 -6
  15. package/dest/config.d.ts.map +1 -1
  16. package/dest/config.js +6 -11
  17. package/dest/enr/generate-enr.d.ts +9 -1
  18. package/dest/enr/generate-enr.d.ts.map +1 -1
  19. package/dest/enr/generate-enr.js +24 -2
  20. package/dest/index.d.ts +1 -0
  21. package/dest/index.d.ts.map +1 -1
  22. package/dest/index.js +1 -0
  23. package/dest/mem_pools/attestation_pool/attestation_pool.d.ts +2 -0
  24. package/dest/mem_pools/attestation_pool/attestation_pool.d.ts.map +1 -1
  25. package/dest/mem_pools/attestation_pool/attestation_pool_test_suite.js +4 -4
  26. package/dest/mem_pools/attestation_pool/kv_attestation_pool.d.ts +1 -0
  27. package/dest/mem_pools/attestation_pool/kv_attestation_pool.d.ts.map +1 -1
  28. package/dest/mem_pools/attestation_pool/kv_attestation_pool.js +8 -2
  29. package/dest/mem_pools/attestation_pool/memory_attestation_pool.d.ts +1 -0
  30. package/dest/mem_pools/attestation_pool/memory_attestation_pool.d.ts.map +1 -1
  31. package/dest/mem_pools/attestation_pool/memory_attestation_pool.js +5 -2
  32. package/dest/mem_pools/attestation_pool/mocks.d.ts.map +1 -1
  33. package/dest/mem_pools/attestation_pool/mocks.js +2 -2
  34. package/dest/mem_pools/tx_pool/aztec_kv_tx_pool.d.ts +4 -0
  35. package/dest/mem_pools/tx_pool/aztec_kv_tx_pool.d.ts.map +1 -1
  36. package/dest/mem_pools/tx_pool/aztec_kv_tx_pool.js +50 -14
  37. package/dest/mem_pools/tx_pool/memory_tx_pool.d.ts +3 -0
  38. package/dest/mem_pools/tx_pool/memory_tx_pool.d.ts.map +1 -1
  39. package/dest/mem_pools/tx_pool/memory_tx_pool.js +9 -0
  40. package/dest/mem_pools/tx_pool/tx_pool.d.ts +9 -0
  41. package/dest/mem_pools/tx_pool/tx_pool.d.ts.map +1 -1
  42. package/dest/mem_pools/tx_pool/tx_pool_test_suite.d.ts.map +1 -1
  43. package/dest/mem_pools/tx_pool/tx_pool_test_suite.js +13 -5
  44. package/dest/msg_validators/attestation_validator/attestation_validator.js +1 -1
  45. package/dest/msg_validators/block_proposal_validator/block_proposal_validator.js +1 -1
  46. package/dest/msg_validators/tx_validator/block_header_validator.js +1 -1
  47. package/dest/msg_validators/tx_validator/data_validator.d.ts.map +1 -1
  48. package/dest/msg_validators/tx_validator/data_validator.js +15 -14
  49. package/dest/msg_validators/tx_validator/double_spend_validator.d.ts +0 -2
  50. package/dest/msg_validators/tx_validator/double_spend_validator.d.ts.map +1 -1
  51. package/dest/msg_validators/tx_validator/double_spend_validator.js +2 -2
  52. package/dest/msg_validators/tx_validator/factory.d.ts +14 -0
  53. package/dest/msg_validators/tx_validator/factory.d.ts.map +1 -0
  54. package/dest/msg_validators/tx_validator/factory.js +62 -0
  55. package/dest/msg_validators/tx_validator/gas_validator.js +3 -3
  56. package/dest/msg_validators/tx_validator/metadata_validator.d.ts +8 -4
  57. package/dest/msg_validators/tx_validator/metadata_validator.d.ts.map +1 -1
  58. package/dest/msg_validators/tx_validator/metadata_validator.js +35 -17
  59. package/dest/msg_validators/tx_validator/phases_validator.d.ts.map +1 -1
  60. package/dest/msg_validators/tx_validator/phases_validator.js +1 -1
  61. package/dest/msg_validators/tx_validator/tx_proof_validator.js +1 -1
  62. package/dest/services/discv5/discV5_service.d.ts +2 -2
  63. package/dest/services/discv5/discV5_service.d.ts.map +1 -1
  64. package/dest/services/discv5/discV5_service.js +9 -13
  65. package/dest/services/dummy_service.d.ts +3 -3
  66. package/dest/services/dummy_service.d.ts.map +1 -1
  67. package/dest/services/dummy_service.js +6 -1
  68. package/dest/services/encoding.d.ts +1 -3
  69. package/dest/services/encoding.d.ts.map +1 -1
  70. package/dest/services/libp2p/libp2p_service.d.ts +4 -2
  71. package/dest/services/libp2p/libp2p_service.d.ts.map +1 -1
  72. package/dest/services/libp2p/libp2p_service.js +94 -88
  73. package/dest/services/peer-manager/metrics.d.ts.map +1 -1
  74. package/dest/services/peer-manager/peer_manager.d.ts +1 -1
  75. package/dest/services/peer-manager/peer_manager.d.ts.map +1 -1
  76. package/dest/services/peer-manager/peer_manager.js +11 -2
  77. package/dest/services/reqresp/connection-sampler/batch_connection_sampler.d.ts.map +1 -1
  78. package/dest/services/reqresp/connection-sampler/connection_sampler.d.ts +2 -2
  79. package/dest/services/reqresp/connection-sampler/connection_sampler.d.ts.map +1 -1
  80. package/dest/services/reqresp/connection-sampler/connection_sampler.js +41 -21
  81. package/dest/services/reqresp/interface.d.ts +1 -3
  82. package/dest/services/reqresp/interface.d.ts.map +1 -1
  83. package/dest/services/reqresp/metrics.d.ts.map +1 -1
  84. package/dest/services/reqresp/protocols/goodbye.d.ts +0 -2
  85. package/dest/services/reqresp/protocols/goodbye.d.ts.map +1 -1
  86. package/dest/services/reqresp/protocols/goodbye.js +1 -1
  87. package/dest/services/reqresp/protocols/ping.d.ts +0 -2
  88. package/dest/services/reqresp/protocols/ping.d.ts.map +1 -1
  89. package/dest/services/reqresp/protocols/status.d.ts +0 -2
  90. package/dest/services/reqresp/protocols/status.d.ts.map +1 -1
  91. package/dest/services/reqresp/rate-limiter/rate_limiter.d.ts.map +1 -1
  92. package/dest/services/reqresp/reqresp.d.ts +1 -3
  93. package/dest/services/reqresp/reqresp.d.ts.map +1 -1
  94. package/dest/services/reqresp/reqresp.js +13 -10
  95. package/dest/services/service.d.ts +4 -3
  96. package/dest/services/service.d.ts.map +1 -1
  97. package/dest/test-helpers/get-ports.d.ts.map +1 -1
  98. package/dest/test-helpers/make-test-p2p-clients.d.ts.map +1 -1
  99. package/dest/test-helpers/make-test-p2p-clients.js +2 -2
  100. package/dest/test-helpers/reqresp-nodes.d.ts.map +1 -1
  101. package/dest/test-helpers/reqresp-nodes.js +1 -1
  102. package/dest/testbench/p2p_client_testbench_worker.js +11 -6
  103. package/dest/testbench/testbench.js +1 -1
  104. package/dest/testbench/worker_client_manager.d.ts +0 -1
  105. package/dest/testbench/worker_client_manager.d.ts.map +1 -1
  106. package/dest/testbench/worker_client_manager.js +2 -2
  107. package/dest/types/index.d.ts +1 -0
  108. package/dest/types/index.d.ts.map +1 -1
  109. package/dest/types/index.js +1 -0
  110. package/dest/versioning.d.ts +2 -2
  111. package/dest/versioning.d.ts.map +1 -1
  112. package/dest/versioning.js +6 -1
  113. package/package.json +15 -15
  114. package/src/bootstrap/bootstrap.ts +1 -1
  115. package/src/client/factory.ts +38 -33
  116. package/src/client/index.ts +1 -0
  117. package/src/client/interface.ts +186 -0
  118. package/src/client/p2p_client.ts +226 -287
  119. package/src/config.ts +11 -18
  120. package/src/enr/generate-enr.ts +35 -3
  121. package/src/index.ts +1 -0
  122. package/src/mem_pools/attestation_pool/attestation_pool.ts +3 -0
  123. package/src/mem_pools/attestation_pool/attestation_pool_test_suite.ts +4 -4
  124. package/src/mem_pools/attestation_pool/kv_attestation_pool.ts +11 -4
  125. package/src/mem_pools/attestation_pool/memory_attestation_pool.ts +10 -3
  126. package/src/mem_pools/attestation_pool/mocks.ts +2 -2
  127. package/src/mem_pools/tx_pool/aztec_kv_tx_pool.ts +79 -34
  128. package/src/mem_pools/tx_pool/memory_tx_pool.ts +16 -1
  129. package/src/mem_pools/tx_pool/tx_pool.ts +12 -0
  130. package/src/mem_pools/tx_pool/tx_pool_test_suite.ts +9 -3
  131. package/src/msg_validators/attestation_validator/attestation_validator.ts +1 -1
  132. package/src/msg_validators/block_proposal_validator/block_proposal_validator.ts +1 -1
  133. package/src/msg_validators/tx_validator/block_header_validator.ts +1 -1
  134. package/src/msg_validators/tx_validator/data_validator.ts +24 -18
  135. package/src/msg_validators/tx_validator/double_spend_validator.ts +2 -2
  136. package/src/msg_validators/tx_validator/factory.ts +94 -0
  137. package/src/msg_validators/tx_validator/gas_validator.ts +3 -3
  138. package/src/msg_validators/tx_validator/metadata_validator.ts +50 -14
  139. package/src/msg_validators/tx_validator/phases_validator.ts +6 -2
  140. package/src/msg_validators/tx_validator/tx_proof_validator.ts +1 -1
  141. package/src/services/discv5/discV5_service.ts +14 -12
  142. package/src/services/dummy_service.ts +8 -2
  143. package/src/services/libp2p/libp2p_service.ts +102 -111
  144. package/src/services/peer-manager/metrics.ts +4 -1
  145. package/src/services/peer-manager/peer_manager.ts +18 -1
  146. package/src/services/reqresp/connection-sampler/batch_connection_sampler.ts +5 -1
  147. package/src/services/reqresp/connection-sampler/connection_sampler.ts +42 -19
  148. package/src/services/reqresp/metrics.ts +4 -1
  149. package/src/services/reqresp/protocols/goodbye.ts +1 -1
  150. package/src/services/reqresp/rate-limiter/rate_limiter.ts +4 -1
  151. package/src/services/reqresp/reqresp.ts +12 -12
  152. package/src/services/service.ts +7 -1
  153. package/src/test-helpers/make-test-p2p-clients.ts +2 -1
  154. package/src/test-helpers/reqresp-nodes.ts +1 -1
  155. package/src/testbench/p2p_client_testbench_worker.ts +10 -4
  156. package/src/testbench/testbench.ts +1 -1
  157. package/src/testbench/worker_client_manager.ts +2 -2
  158. package/src/types/index.ts +1 -0
  159. package/src/versioning.ts +8 -1
@@ -6,24 +6,17 @@ function _ts_decorate(decorators, target, key, desc) {
6
6
  }
7
7
  import { INITIAL_L2_BLOCK_NUM } from '@aztec/constants';
8
8
  import { createLogger } from '@aztec/foundation/log';
9
- import { BlockAttestation, ConsensusPayload } from '@aztec/stdlib/p2p';
10
9
  import { Attributes, TraceableL2BlockStream, WithTracer, getTelemetryClient, trackSpan } from '@aztec/telemetry-client';
11
10
  import { getP2PDefaultConfig } from '../config.js';
12
11
  import { ReqRespSubProtocol } from '../services/reqresp/interface.js';
13
- /**
14
- * Enum defining the possible states of the p2p client.
15
- */ export var P2PClientState = /*#__PURE__*/ function(P2PClientState) {
16
- P2PClientState[P2PClientState["IDLE"] = 0] = "IDLE";
17
- P2PClientState[P2PClientState["SYNCHING"] = 1] = "SYNCHING";
18
- P2PClientState[P2PClientState["RUNNING"] = 2] = "RUNNING";
19
- P2PClientState[P2PClientState["STOPPED"] = 3] = "STOPPED";
20
- return P2PClientState;
21
- }({});
12
+ import { P2PClientState } from './interface.js';
22
13
  /**
23
14
  * The P2P client implementation.
24
15
  */ export class P2PClient extends WithTracer {
16
+ store;
25
17
  l2BlockSource;
26
18
  p2pService;
19
+ telemetry;
27
20
  log;
28
21
  /** The JS promise that will be running to keep the client's data in sync. Can be interrupted if the client is stopped. */ runningPromise;
29
22
  currentState;
@@ -31,45 +24,40 @@ import { ReqRespSubProtocol } from '../services/reqresp/interface.js';
31
24
  syncResolve;
32
25
  latestBlockNumberAtStart;
33
26
  provenBlockNumberAtStart;
27
+ finalizedBlockNumberAtStart;
34
28
  synchedBlockHashes;
35
29
  synchedLatestBlockNumber;
36
30
  synchedProvenBlockNumber;
31
+ synchedFinalizedBlockNumber;
37
32
  synchedLatestSlot;
38
33
  txPool;
39
34
  attestationPool;
40
- /** How many slots to keep attestations for. */ keepAttestationsInPoolFor;
41
- /** How many slots to keep proven txs for. */ keepProvenTxsFor;
42
- blockStream;
43
35
  config;
36
+ blockStream;
44
37
  /**
45
38
  * In-memory P2P client constructor.
46
39
  * @param store - The client's instance of the KV store.
47
40
  * @param l2BlockSource - P2P client's source for fetching existing blocks.
48
41
  * @param txPool - The client's instance of a transaction pool. Defaults to in-memory implementation.
49
42
  * @param p2pService - The concrete instance of p2p networking to use.
50
- * @param keepProvenTxsFor - How many blocks have to pass after a block is proven before its txs are deleted (zero to delete immediately once proven).
51
43
  * @param log - A logger.
52
44
  */ constructor(_clientType, store, l2BlockSource, mempools, p2pService, config = {}, telemetry = getTelemetryClient(), log = createLogger('p2p')){
53
- super(telemetry, 'P2PClient'), this.l2BlockSource = l2BlockSource, this.p2pService = p2pService, this.log = log, this.currentState = 0, this.syncPromise = Promise.resolve(), this.syncResolve = undefined, this.latestBlockNumberAtStart = -1, this.provenBlockNumberAtStart = -1;
45
+ super(telemetry, 'P2PClient'), this.store = store, this.l2BlockSource = l2BlockSource, this.p2pService = p2pService, this.telemetry = telemetry, this.log = log, this.currentState = P2PClientState.IDLE, this.syncPromise = Promise.resolve(), this.syncResolve = undefined, this.latestBlockNumberAtStart = -1, this.provenBlockNumberAtStart = -1, this.finalizedBlockNumberAtStart = -1;
54
46
  this.config = {
55
47
  ...getP2PDefaultConfig(),
56
48
  ...config
57
49
  };
58
- const { keepProvenTxsInPoolFor, blockCheckIntervalMS, blockRequestBatchSize, keepAttestationsInPoolFor } = this.config;
59
- this.keepProvenTxsFor = keepProvenTxsInPoolFor;
60
- this.keepAttestationsInPoolFor = keepAttestationsInPoolFor;
61
- const tracer = telemetry.getTracer('P2PL2BlockStream');
62
- const logger = createLogger('p2p:l2-block-stream');
63
- this.blockStream = new TraceableL2BlockStream(l2BlockSource, this, this, tracer, 'P2PL2BlockStream', logger, {
64
- batchSize: blockRequestBatchSize,
65
- pollIntervalMS: blockCheckIntervalMS
66
- });
50
+ this.txPool = mempools.txPool;
51
+ this.attestationPool = mempools.attestationPool;
52
+ // REFACTOR: Try replacing these with an L2TipsStore
67
53
  this.synchedBlockHashes = store.openMap('p2p_pool_block_hashes');
68
54
  this.synchedLatestBlockNumber = store.openSingleton('p2p_pool_last_l2_block');
69
55
  this.synchedProvenBlockNumber = store.openSingleton('p2p_pool_last_proven_l2_block');
56
+ this.synchedFinalizedBlockNumber = store.openSingleton('p2p_pool_last_finalized_l2_block');
70
57
  this.synchedLatestSlot = store.openSingleton('p2p_pool_last_l2_slot');
71
- this.txPool = mempools.txPool;
72
- this.attestationPool = mempools.attestationPool;
58
+ }
59
+ clear() {
60
+ return this.store.clear();
73
61
  }
74
62
  isP2PClient() {
75
63
  return true;
@@ -91,21 +79,27 @@ import { ReqRespSubProtocol } from '../services/reqresp/interface.js';
91
79
  let latestBlockHash;
92
80
  const provenBlockNumber = await this.getSyncedProvenBlockNum();
93
81
  let provenBlockHash;
82
+ const finalizedBlockNumber = await this.getSyncedFinalizedBlockNum();
83
+ let finalizedBlockHash;
94
84
  if (latestBlockNumber > 0) {
95
85
  latestBlockHash = await this.synchedBlockHashes.getAsync(latestBlockNumber);
96
86
  if (typeof latestBlockHash === 'undefined') {
97
- this.log.warn(`Block hash for latest block ${latestBlockNumber} not found`);
98
- throw new Error();
87
+ throw new Error(`Block hash for latest block ${latestBlockNumber} not found in p2p client`);
99
88
  }
100
89
  }
101
90
  if (provenBlockNumber > 0) {
102
91
  provenBlockHash = await this.synchedBlockHashes.getAsync(provenBlockNumber);
103
92
  if (typeof provenBlockHash === 'undefined') {
104
- this.log.warn(`Block hash for proven block ${provenBlockNumber} not found`);
105
- throw new Error();
93
+ throw new Error(`Block hash for proven block ${provenBlockNumber} not found in p2p client`);
94
+ }
95
+ }
96
+ if (finalizedBlockNumber > 0) {
97
+ finalizedBlockHash = await this.synchedBlockHashes.getAsync(finalizedBlockNumber);
98
+ if (typeof finalizedBlockHash === 'undefined') {
99
+ throw new Error(`Block hash for finalized block ${finalizedBlockNumber} not found in p2p client`);
106
100
  }
107
101
  }
108
- return Promise.resolve({
102
+ return {
109
103
  latest: {
110
104
  hash: latestBlockHash,
111
105
  number: latestBlockNumber
@@ -115,10 +109,10 @@ import { ReqRespSubProtocol } from '../services/reqresp/interface.js';
115
109
  number: provenBlockNumber
116
110
  },
117
111
  finalized: {
118
- hash: provenBlockHash,
119
- number: provenBlockNumber
112
+ hash: finalizedBlockHash,
113
+ number: finalizedBlockNumber
120
114
  }
121
- });
115
+ };
122
116
  }
123
117
  async handleBlockStreamEvent(event) {
124
118
  this.log.debug(`Handling block stream event ${event.type}`);
@@ -127,15 +121,24 @@ import { ReqRespSubProtocol } from '../services/reqresp/interface.js';
127
121
  await this.handleLatestL2Blocks(event.blocks);
128
122
  break;
129
123
  case 'chain-finalized':
130
- break;
131
- case 'chain-proven':
132
124
  {
133
- const from = await this.getSyncedProvenBlockNum() + 1;
125
+ // TODO (alexg): I think we can prune the block hashes map here
126
+ await this.setBlockHash(event.block);
127
+ const from = await this.getSyncedFinalizedBlockNum() + 1;
134
128
  const limit = event.block.number - from + 1;
135
- await this.handleProvenL2Blocks(await this.l2BlockSource.getBlocks(from, limit));
129
+ if (limit > 0) {
130
+ await this.handleFinalizedL2Blocks(await this.l2BlockSource.getBlocks(from, limit));
131
+ }
132
+ break;
133
+ }
134
+ case 'chain-proven':
135
+ {
136
+ await this.setBlockHash(event.block);
137
+ await this.synchedProvenBlockNumber.set(event.block.number);
136
138
  break;
137
139
  }
138
140
  case 'chain-pruned':
141
+ await this.setBlockHash(event.block);
139
142
  await this.handlePruneL2Blocks(event.block.number);
140
143
  break;
141
144
  default:
@@ -145,6 +148,11 @@ import { ReqRespSubProtocol } from '../services/reqresp/interface.js';
145
148
  }
146
149
  }
147
150
  }
151
+ async setBlockHash(block) {
152
+ if (block.hash !== undefined) {
153
+ await this.synchedBlockHashes.set(block.number, block.hash.toString());
154
+ }
155
+ }
148
156
  #assertIsReady() {
149
157
  // this.log.info('Checking if p2p client is ready, current state: ', this.currentState);
150
158
  if (!this.isReady()) {
@@ -155,35 +163,65 @@ import { ReqRespSubProtocol } from '../services/reqresp/interface.js';
155
163
  * Starts the P2P client.
156
164
  * @returns An empty promise signalling the synching process.
157
165
  */ async start() {
158
- if (this.currentState === 3) {
166
+ if (this.currentState === P2PClientState.STOPPED) {
159
167
  throw new Error('P2P client already stopped');
160
168
  }
161
- if (this.currentState !== 0) {
169
+ if (this.currentState !== P2PClientState.IDLE) {
162
170
  return this.syncPromise;
163
171
  }
164
172
  // get the current latest block numbers
165
- this.latestBlockNumberAtStart = await this.l2BlockSource.getBlockNumber();
166
- this.provenBlockNumberAtStart = await this.l2BlockSource.getProvenBlockNumber();
173
+ const latestBlockNumbers = await this.l2BlockSource.getL2Tips();
174
+ this.latestBlockNumberAtStart = latestBlockNumbers.latest.number;
175
+ this.provenBlockNumberAtStart = latestBlockNumbers.proven.number;
176
+ this.finalizedBlockNumberAtStart = latestBlockNumbers.finalized.number;
167
177
  const syncedLatestBlock = await this.getSyncedLatestBlockNum() + 1;
168
178
  const syncedProvenBlock = await this.getSyncedProvenBlockNum() + 1;
169
- // if there are blocks to be retrieved, go to a synching state
170
- if (syncedLatestBlock <= this.latestBlockNumberAtStart || syncedProvenBlock <= this.provenBlockNumberAtStart) {
171
- this.setCurrentState(1);
179
+ const syncedFinalizedBlock = await this.getSyncedFinalizedBlockNum() + 1;
180
+ if (await this.txPool.isEmpty() && (this.attestationPool === undefined || await this.attestationPool?.isEmpty())) {
181
+ // if mempools are empty, we don't care about syncing prior blocks
182
+ this.initBlockStream(this.latestBlockNumberAtStart);
183
+ this.setCurrentState(P2PClientState.RUNNING);
184
+ this.syncPromise = Promise.resolve();
185
+ await this.p2pService.start();
186
+ this.log.info(`Starting p2p client from block ${this.latestBlockNumberAtStart} with empty mempools`);
187
+ } else if (syncedLatestBlock <= this.latestBlockNumberAtStart || syncedProvenBlock <= this.provenBlockNumberAtStart || syncedFinalizedBlock <= this.finalizedBlockNumberAtStart) {
188
+ // if there are blocks to be retrieved, go to a synching state
189
+ // this gets resolved on `startServiceIfSynched`
190
+ this.initBlockStream();
191
+ this.setCurrentState(P2PClientState.SYNCHING);
172
192
  this.syncPromise = new Promise((resolve)=>{
173
193
  this.syncResolve = resolve;
174
194
  });
175
- this.log.verbose(`Starting sync from ${syncedLatestBlock} (last proven ${syncedProvenBlock})`);
195
+ this.log.info(`Initiating p2p sync from ${syncedLatestBlock}`, {
196
+ syncedLatestBlock,
197
+ syncedProvenBlock,
198
+ syncedFinalizedBlock
199
+ });
176
200
  } else {
177
201
  // if no blocks to be retrieved, go straight to running
178
- this.setCurrentState(2);
202
+ this.initBlockStream();
203
+ this.setCurrentState(P2PClientState.RUNNING);
179
204
  this.syncPromise = Promise.resolve();
180
205
  await this.p2pService.start();
181
- this.log.debug(`Block ${syncedLatestBlock} (proven ${syncedProvenBlock}) already beyond current block`);
206
+ this.log.info(`Starting P2P client synced to ${syncedLatestBlock}`, {
207
+ syncedLatestBlock,
208
+ syncedProvenBlock,
209
+ syncedFinalizedBlock
210
+ });
182
211
  }
183
212
  this.blockStream.start();
184
- this.log.verbose(`Started block downloader from block ${syncedLatestBlock}`);
185
213
  return this.syncPromise;
186
214
  }
215
+ initBlockStream(startingBlock) {
216
+ if (!this.blockStream) {
217
+ const { blockRequestBatchSize: batchSize, blockCheckIntervalMS: pollIntervalMS } = this.config;
218
+ this.blockStream = new TraceableL2BlockStream(this.l2BlockSource, this, this, this.telemetry.getTracer('P2PL2BlockStream'), 'P2PL2BlockStream', createLogger('p2p:l2-block-stream'), {
219
+ batchSize,
220
+ pollIntervalMS,
221
+ startingBlock
222
+ });
223
+ }
224
+ }
187
225
  /**
188
226
  * Allows consumers to stop the instance of the P2P client.
189
227
  * 'ready' will now return 'false' and the running promise that keeps the client synced is interrupted.
@@ -191,13 +229,14 @@ import { ReqRespSubProtocol } from '../services/reqresp/interface.js';
191
229
  this.log.debug('Stopping p2p client...');
192
230
  await this.p2pService.stop();
193
231
  this.log.debug('Stopped p2p service');
194
- await this.blockStream.stop();
232
+ await this.blockStream?.stop();
195
233
  this.log.debug('Stopped block downloader');
196
234
  await this.runningPromise;
197
- this.setCurrentState(3);
235
+ this.setCurrentState(P2PClientState.STOPPED);
198
236
  this.log.info('P2P client stopped.');
199
237
  }
200
238
  /** Triggers a sync to the archiver. Used for testing. */ async sync() {
239
+ this.initBlockStream();
201
240
  await this.blockStream.sync();
202
241
  }
203
242
  broadcastProposal(proposal) {
@@ -218,18 +257,6 @@ import { ReqRespSubProtocol } from '../services/reqresp/interface.js';
218
257
  this.p2pService.registerBlockReceivedCallback(handler);
219
258
  }
220
259
  /**
221
- * Requests the transactions with the given hashes from the network.
222
- *
223
- * If a transaction can be retrieved, it will be returned, if not an undefined
224
- * will be returned. In place.
225
- *
226
- * @param txHashes - The hashes of the transactions to request.
227
- * @returns A promise that resolves to an array of transactions or undefined.
228
- */ async requestTxs(txHashes) {
229
- const res = await this.p2pService.sendBatchRequest(ReqRespSubProtocol.TX, txHashes);
230
- return Promise.resolve(res ?? []);
231
- }
232
- /**
233
260
  * Uses the Request Response protocol to request a transaction from the network.
234
261
  *
235
262
  * If the underlying request response protocol fails, then we return undefined.
@@ -252,21 +279,25 @@ import { ReqRespSubProtocol } from '../services/reqresp/interface.js';
252
279
  /**
253
280
  * Uses the batched Request Response protocol to request a set of transactions from the network.
254
281
  */ async requestTxsByHash(txHashes) {
255
- const txs = await this.p2pService.sendBatchRequest(ReqRespSubProtocol.TX, txHashes);
282
+ const timeoutMs = 8000; // Longer timeout for now
283
+ const maxPeers = Math.min(Math.ceil(txHashes.length / 3), 10);
284
+ const maxRetryAttempts = 10; // Keep retrying within the timeout
285
+ const txs = await this.p2pService.sendBatchRequest(ReqRespSubProtocol.TX, txHashes, timeoutMs, maxPeers, maxRetryAttempts);
256
286
  // Some transactions may return undefined, so we filter them out
257
287
  const filteredTxs = txs.filter((tx)=>!!tx);
258
- await this.txPool.addTxs(filteredTxs);
288
+ if (filteredTxs.length > 0) {
289
+ await this.txPool.addTxs(filteredTxs);
290
+ }
259
291
  const txHashesStr = txHashes.map((tx)=>tx.toString()).join(', ');
260
- this.log.debug(`Received batched txs ${txHashesStr} (${txs.length} / ${txHashes.length}}) from peers`);
292
+ this.log.debug(`Requested txs ${txHashesStr} (${filteredTxs.length} / ${txHashes.length}}) from peers`);
261
293
  // We return all transactions, even the not found ones to the caller, such they can handle missing items themselves.
262
294
  return txs;
263
295
  }
264
296
  getPendingTxs() {
265
- return Promise.resolve(this.getTxs('pending'));
297
+ return this.getTxs('pending');
266
298
  }
267
- async getPendingTxCount() {
268
- const pendingTxs = await this.txPool.getPendingTxHashes();
269
- return pendingTxs.length;
299
+ getPendingTxCount() {
300
+ return this.txPool.getPendingTxCount();
270
301
  }
271
302
  async *iteratePendingTxs() {
272
303
  for (const txHash of (await this.txPool.getPendingTxHashes())){
@@ -328,7 +359,7 @@ import { ReqRespSubProtocol } from '../services/reqresp/interface.js';
328
359
  * Returns transactions in the transaction pool by hash.
329
360
  * If a transaction is not in the pool, it will be requested from the network.
330
361
  * @param txHashes - Hashes of the transactions to look for.
331
- * @returns The txs found, not necessarily on the same order as the hashes.
362
+ * @returns The txs found, or undefined if not found in the order requested.
332
363
  */ async getTxsByHash(txHashes) {
333
364
  const txs = await Promise.all(txHashes.map((txHash)=>this.txPool.getTxByHash(txHash)));
334
365
  const missingTxHashes = txs.map((tx, index)=>[
@@ -340,7 +371,25 @@ import { ReqRespSubProtocol } from '../services/reqresp/interface.js';
340
371
  }
341
372
  const missingTxs = await this.requestTxsByHash(missingTxHashes);
342
373
  const fetchedMissingTxs = missingTxs.filter((tx)=>!!tx);
343
- return txs.filter((tx)=>!!tx).concat(fetchedMissingTxs);
374
+ // TODO: optimize
375
+ // Merge the found txs in order
376
+ const mergingTxsPromises = txHashes.map(async (txHash)=>{
377
+ // Is it in the txs list from the mempool?
378
+ for (const tx of txs){
379
+ if (tx !== undefined && (await tx.getTxHash()).equals(txHash)) {
380
+ return tx;
381
+ }
382
+ }
383
+ // Is it in the fetched missing txs?
384
+ for (const tx of fetchedMissingTxs){
385
+ if (tx !== undefined && (await tx.getTxHash()).equals(txHash)) {
386
+ return tx;
387
+ }
388
+ }
389
+ // Otherwise return undefined
390
+ return undefined;
391
+ });
392
+ return await Promise.all(mergingTxsPromises);
344
393
  }
345
394
  /**
346
395
  * Returns an archived transaction in the transaction pool by its hash.
@@ -357,7 +406,7 @@ import { ReqRespSubProtocol } from '../services/reqresp/interface.js';
357
406
  await this.addTxs([
358
407
  tx
359
408
  ]);
360
- this.p2pService.propagate(tx);
409
+ await this.p2pService.propagate(tx);
361
410
  }
362
411
  /**
363
412
  * Adds transactions to the pool. Does not send to peers or validate the txs.
@@ -392,7 +441,7 @@ import { ReqRespSubProtocol } from '../services/reqresp/interface.js';
392
441
  * Public function to check if the p2p client is fully synced and ready to receive txs.
393
442
  * @returns True if the P2P client is ready to receive txs.
394
443
  */ isReady() {
395
- return this.currentState === 2;
444
+ return this.currentState === P2PClientState.RUNNING;
396
445
  }
397
446
  /**
398
447
  * Public function to check the latest block number that the P2P client is synced to.
@@ -406,6 +455,9 @@ import { ReqRespSubProtocol } from '../services/reqresp/interface.js';
406
455
  */ async getSyncedProvenBlockNum() {
407
456
  return await this.synchedProvenBlockNumber.getAsync() ?? INITIAL_L2_BLOCK_NUM - 1;
408
457
  }
458
+ async getSyncedFinalizedBlockNum() {
459
+ return await this.synchedFinalizedBlockNumber.getAsync() ?? INITIAL_L2_BLOCK_NUM - 1;
460
+ }
409
461
  /** Returns latest L2 slot for which we have seen an L2 block. */ async getSyncedLatestSlot() {
410
462
  return await this.synchedLatestSlot.getAsync() ?? BigInt(0);
411
463
  }
@@ -433,15 +485,6 @@ import { ReqRespSubProtocol } from '../services/reqresp/interface.js';
433
485
  await this.txPool.markAsMined(txHashes, block.number);
434
486
  }
435
487
  }
436
- async addAttestationsToPool(blocks) {
437
- const attestations = blocks.flatMap((block)=>{
438
- const payload = ConsensusPayload.fromBlock(block.block);
439
- return block.signatures.filter((sig)=>!sig.isEmpty).map((signature)=>new BlockAttestation(payload, signature));
440
- });
441
- await this.attestationPool?.addAttestations(attestations);
442
- const slots = blocks.map((b)=>b.block.header.getSlot()).sort((a, b)=>Number(a - b));
443
- this.log.debug(`Added ${attestations.length} attestations for slots ${slots[0]}-${slots.at(-1)} to the pool`);
444
- }
445
488
  /**
446
489
  * Deletes txs from these blocks.
447
490
  * @param blocks - A list of existing blocks with txs that the P2P client needs to ensure the tx pool is reconciled with.
@@ -462,42 +505,51 @@ import { ReqRespSubProtocol } from '../services/reqresp/interface.js';
462
505
  return Promise.resolve();
463
506
  }
464
507
  await this.markTxsAsMinedFromBlocks(blocks.map((b)=>b.block));
465
- await this.addAttestationsToPool(blocks);
508
+ void this.requestMissingTxsFromUnprovenBlocks(blocks.map((b)=>b.block));
466
509
  const lastBlock = blocks.at(-1).block;
467
- await Promise.all(blocks.map(async (block)=>this.synchedBlockHashes.set(block.block.number, (await block.block.hash()).toString())));
510
+ await Promise.all(blocks.map(async (block)=>this.setBlockHash({
511
+ number: block.block.number,
512
+ hash: await block.block.hash().then((h)=>h.toString())
513
+ })));
468
514
  await this.synchedLatestBlockNumber.set(lastBlock.number);
469
515
  await this.synchedLatestSlot.set(lastBlock.header.getSlot());
470
516
  this.log.verbose(`Synched to latest block ${lastBlock.number}`);
471
517
  await this.startServiceIfSynched();
472
518
  }
519
+ /** Request txs for unproven blocks so the prover node has more chances to get them. */ async requestMissingTxsFromUnprovenBlocks(blocks) {
520
+ try {
521
+ const provenBlockNumber = Math.max(await this.getSyncedProvenBlockNum(), this.provenBlockNumberAtStart);
522
+ const unprovenBlocks = blocks.filter((block)=>block.number > provenBlockNumber);
523
+ const txHashes = unprovenBlocks.flatMap((block)=>block.body.txEffects.map((txEffect)=>txEffect.txHash));
524
+ const missingTxHashes = await this.txPool.hasTxs(txHashes).then((availability)=>txHashes.filter((_, index)=>!availability[index]));
525
+ if (missingTxHashes.length > 0) {
526
+ this.log.verbose(`Requesting ${missingTxHashes.length} missing txs from peers for ${unprovenBlocks.length} unproven mined blocks`, {
527
+ missingTxHashes,
528
+ unprovenBlockNumbers: unprovenBlocks.map((block)=>block.number)
529
+ });
530
+ await this.requestTxsByHash(missingTxHashes);
531
+ }
532
+ } catch (err) {
533
+ this.log.error(`Error requesting missing txs from unproven blocks`, err, {
534
+ blocks: blocks.map((block)=>block.number)
535
+ });
536
+ }
537
+ }
473
538
  /**
474
- * Handles new proven blocks by deleting the txs in them, or by deleting the txs in blocks `keepProvenTxsFor` ago.
475
- * @param blocks - A list of proven L2 blocks.
539
+ * Handles new finalized blocks by deleting the txs and attestations in them.
540
+ * @param blocks - A list of finalized L2 blocks.
476
541
  * @returns Empty promise.
477
- */ async handleProvenL2Blocks(blocks) {
542
+ */ async handleFinalizedL2Blocks(blocks) {
543
+ this.log.trace(`Handling finalized blocks ${blocks.length} up to ${blocks.at(-1)?.number}`);
478
544
  if (!blocks.length) {
479
545
  return Promise.resolve();
480
546
  }
481
- const firstBlockNum = blocks[0].number;
482
547
  const lastBlockNum = blocks[blocks.length - 1].number;
483
- const lastBlockSlot = blocks[blocks.length - 1].header.globalVariables.slotNumber.toBigInt();
484
- // If keepProvenTxsFor is 0, we delete all txs from all proven blocks.
485
- if (this.keepProvenTxsFor === 0) {
486
- await this.deleteTxsFromBlocks(blocks);
487
- } else if (lastBlockNum - this.keepProvenTxsFor >= INITIAL_L2_BLOCK_NUM) {
488
- const fromBlock = Math.max(INITIAL_L2_BLOCK_NUM, firstBlockNum - this.keepProvenTxsFor);
489
- const toBlock = lastBlockNum - this.keepProvenTxsFor;
490
- const limit = toBlock - fromBlock + 1;
491
- const blocksToDeleteTxsFrom = await this.l2BlockSource.getBlocks(fromBlock, limit, true);
492
- await this.deleteTxsFromBlocks(blocksToDeleteTxsFrom);
493
- }
494
- // We delete attestations older than the last block slot minus the number of slots we want to keep in the pool.
495
- const lastBlockSlotMinusKeepAttestationsInPoolFor = lastBlockSlot - BigInt(this.keepAttestationsInPoolFor);
496
- if (lastBlockSlotMinusKeepAttestationsInPoolFor >= BigInt(INITIAL_L2_BLOCK_NUM)) {
497
- await this.attestationPool?.deleteAttestationsOlderThan(lastBlockSlotMinusKeepAttestationsInPoolFor);
498
- }
499
- await this.synchedProvenBlockNumber.set(lastBlockNum);
500
- this.log.debug(`Synched to proven block ${lastBlockNum}`);
548
+ const lastBlockSlot = blocks[blocks.length - 1].header.getSlot();
549
+ await this.deleteTxsFromBlocks(blocks);
550
+ await this.attestationPool?.deleteAttestationsOlderThan(lastBlockSlot);
551
+ await this.synchedFinalizedBlockNumber.set(lastBlockNum);
552
+ this.log.debug(`Synched to finalized block ${lastBlockNum}`);
501
553
  await this.startServiceIfSynched();
502
554
  }
503
555
  /**
@@ -506,11 +558,11 @@ import { ReqRespSubProtocol } from '../services/reqresp/interface.js';
506
558
  */ async handlePruneL2Blocks(latestBlock) {
507
559
  // NOTE: temporary fix for alphanet, deleting ALL txs that were in the epoch from the pool #13723
508
560
  // TODO: undo once fixed: #13770
509
- const txsToDelete = new Set();
561
+ const txsToDelete = new Map();
510
562
  const minedTxs = await this.txPool.getMinedTxHashes();
511
563
  for (const [txHash, blockNumber] of minedTxs){
512
564
  if (blockNumber > latestBlock) {
513
- txsToDelete.add(txHash);
565
+ txsToDelete.set(txHash.toString(), txHash);
514
566
  }
515
567
  }
516
568
  // Find transactions that reference pruned blocks in their historical header
@@ -518,12 +570,12 @@ import { ReqRespSubProtocol } from '../services/reqresp/interface.js';
518
570
  // every tx that's been generated against a block that has now been pruned is no longer valid
519
571
  if (tx.data.constants.historicalHeader.globalVariables.blockNumber.toNumber() > latestBlock) {
520
572
  const txHash = await tx.getTxHash();
521
- txsToDelete.add(txHash);
573
+ txsToDelete.set(txHash.toString(), txHash);
522
574
  }
523
575
  }
524
576
  this.log.info(`Detected chain prune. Removing invalid txs count=${txsToDelete.size} newLatestBlock=${latestBlock} previousLatestBlock=${await this.getSyncedLatestBlockNum()}`);
525
577
  // delete invalid txs (both pending and mined)
526
- await this.txPool.deleteTxs(Array.from(txsToDelete));
578
+ await this.txPool.deleteTxs(Array.from(txsToDelete.values()));
527
579
  // everything left in the mined set was built against a block on the proven chain so its still valid
528
580
  // move back to pending the txs that were reorged out of the chain
529
581
  // NOTE: we can't move _all_ txs back to pending because the tx pool could keep hold of mined txs for longer
@@ -542,9 +594,19 @@ import { ReqRespSubProtocol } from '../services/reqresp/interface.js';
542
594
  // no need to update block hashes, as they will be updated as new blocks are added
543
595
  }
544
596
  async startServiceIfSynched() {
545
- if (this.currentState === 1 && await this.getSyncedLatestBlockNum() >= this.latestBlockNumberAtStart && await this.getSyncedProvenBlockNum() >= this.provenBlockNumberAtStart) {
546
- this.log.debug(`Synched to blocks at start`);
547
- this.setCurrentState(2);
597
+ if (this.currentState !== P2PClientState.SYNCHING) {
598
+ return;
599
+ }
600
+ const syncedFinalizedBlock = await this.getSyncedFinalizedBlockNum();
601
+ const syncedProvenBlock = await this.getSyncedProvenBlockNum();
602
+ const syncedLatestBlock = await this.getSyncedLatestBlockNum();
603
+ if (syncedLatestBlock >= this.latestBlockNumberAtStart && syncedProvenBlock >= this.provenBlockNumberAtStart && syncedFinalizedBlock >= this.finalizedBlockNumberAtStart) {
604
+ this.log.info(`Completed P2P client sync to block ${syncedLatestBlock}. Starting service.`, {
605
+ syncedLatestBlock,
606
+ syncedProvenBlock,
607
+ syncedFinalizedBlock
608
+ });
609
+ this.setCurrentState(P2PClientState.RUNNING);
548
610
  if (this.syncResolve !== undefined) {
549
611
  this.syncResolve();
550
612
  await this.p2pService.start();
@@ -559,6 +621,15 @@ import { ReqRespSubProtocol } from '../services/reqresp/interface.js';
559
621
  this.currentState = newState;
560
622
  this.log.debug(`Moved from state ${P2PClientState[oldState]} to ${P2PClientState[this.currentState]}`);
561
623
  }
624
+ validate(txs) {
625
+ return this.p2pService.validate(txs);
626
+ }
627
+ /**
628
+ * Marks transactions as non-evictable in the pool.
629
+ * @param txHashes - Hashes of the transactions to mark as non-evictable.
630
+ */ markTxsAsNonEvictable(txHashes) {
631
+ return this.txPool.markTxsAsNonEvictable(txHashes);
632
+ }
562
633
  }
563
634
  _ts_decorate([
564
635
  trackSpan('p2pClient.broadcastProposal', async (proposal)=>({
package/dest/config.d.ts CHANGED
@@ -70,10 +70,6 @@ export interface P2PConfig extends P2PReqRespConfig, ChainConfig {
70
70
  * If announceUdpAddress or announceTcpAddress are not provided, query for the IP address of the machine. Default is false.
71
71
  */
72
72
  queryForIp: boolean;
73
- /** How many blocks have to pass after a block is proven before its txs are deleted (zero to delete immediately once proven) */
74
- keepProvenTxsInPoolFor: number;
75
- /** How many slots to keep attestations for. */
76
- keepAttestationsInPoolFor: number;
77
73
  /**
78
74
  * The interval of the gossipsub heartbeat to perform maintenance tasks.
79
75
  */
@@ -106,6 +102,10 @@ export interface P2PConfig extends P2PReqRespConfig, ChainConfig {
106
102
  * How many message cache windows to include when gossiping with other pears.
107
103
  */
108
104
  gossipsubMcacheGossip: number;
105
+ /**
106
+ * How long to keep message IDs in the seen cache (ms).
107
+ */
108
+ gossipsubSeenTTL: number;
109
109
  /**
110
110
  * The 'age' (in # of L2 blocks) of a processed tx after which we heavily penalize a peer for re-sending it.
111
111
  */
@@ -186,8 +186,6 @@ export declare const bootnodeConfigMappings: ConfigMappingsType<Pick<{
186
186
  bootstrapNodesAsFullPeers: unknown;
187
187
  maxPeerCount: unknown;
188
188
  queryForIp: unknown;
189
- keepProvenTxsInPoolFor: unknown;
190
- keepAttestationsInPoolFor: unknown;
191
189
  gossipsubInterval: unknown;
192
190
  gossipsubD: unknown;
193
191
  gossipsubDlo: unknown;
@@ -196,6 +194,7 @@ export declare const bootnodeConfigMappings: ConfigMappingsType<Pick<{
196
194
  gossipsubFloodPublish: unknown;
197
195
  gossipsubMcacheLength: unknown;
198
196
  gossipsubMcacheGossip: unknown;
197
+ gossipsubSeenTTL: unknown;
199
198
  doubleSpendSeverePeerPenaltyWindow: unknown;
200
199
  gossipsubTxTopicWeight: unknown;
201
200
  gossipsubTxInvalidMessageDeliveriesWeight: unknown;
@@ -1 +1 @@
1
- {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,kBAAkB,EAMxB,MAAM,0BAA0B,CAAC;AAElC,OAAO,EAAE,KAAK,eAAe,EAAsB,MAAM,wBAAwB,CAAC;AAGlF,OAAO,EAAE,KAAK,cAAc,EAAE,KAAK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ED,wBAAgB,mBAAmB,IAAI,SAAS,CAE/C;AAED;;GAEG;AACH,MAAM,MAAM,cAAc,GAAG,IAAI,CAC/B,SAAS,EACP,OAAO,GACP,SAAS,GACT,kBAAkB,GAClB,kBAAkB,GAClB,sBAAsB,GACtB,gBAAgB,GAChB,eAAe,CAClB,GACC,QAAQ,CAAC,IAAI,CAAC,SAAS,EAAE,OAAO,GAAG,SAAS,CAAC,CAAC,GAC9C,IAAI,CAAC,eAAe,EAAE,eAAe,GAAG,oBAAoB,CAAC,GAC7D,IAAI,CAAC,WAAW,EAAE,WAAW,CAAC,CAAC;AAejC,eAAO,MAAM,sBAAsB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;uLAGlC,CAAC;AAEF;;;;;;;;;;GAUG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,MAAM,GAAG,cAAc,EAAE,CAqC9D"}
package/dest/config.js CHANGED
@@ -84,16 +84,6 @@ export const p2pConfigMappings = {
84
84
  description: 'If announceUdpAddress or announceTcpAddress are not provided, query for the IP address of the machine. Default is false.',
85
85
  ...booleanConfigHelper()
86
86
  },
87
- keepProvenTxsInPoolFor: {
88
- env: 'P2P_TX_POOL_KEEP_PROVEN_FOR',
89
- description: 'How many blocks have to pass after a block is proven before its txs are deleted (zero to delete immediately once proven)',
90
- ...numberConfigHelper(0)
91
- },
92
- keepAttestationsInPoolFor: {
93
- env: 'P2P_ATTESTATION_POOL_KEEP_FOR',
94
- description: 'How many slots to keep attestations for.',
95
- ...numberConfigHelper(96)
96
- },
97
87
  gossipsubInterval: {
98
88
  env: 'P2P_GOSSIPSUB_INTERVAL_MS',
99
89
  description: 'The interval of the gossipsub heartbeat to perform maintenance tasks.',
@@ -131,9 +121,14 @@ export const p2pConfigMappings = {
131
121
  },
132
122
  gossipsubMcacheGossip: {
133
123
  env: 'P2P_GOSSIPSUB_MCACHE_GOSSIP',
134
- description: 'How many message cache windows to include when gossiping with other pears.',
124
+ description: 'How many message cache windows to include when gossiping with other peers.',
135
125
  ...numberConfigHelper(3)
136
126
  },
127
+ gossipsubSeenTTL: {
128
+ env: 'P2P_GOSSIPSUB_SEEN_TTL',
129
+ description: 'How long to keep message IDs in the seen cache.',
130
+ ...numberConfigHelper(20 * 60 * 1000)
131
+ },
137
132
  gossipsubTxTopicWeight: {
138
133
  env: 'P2P_GOSSIPSUB_TX_TOPIC_WEIGHT',
139
134
  description: 'The weight of the tx topic for the gossipsub protocol.',
@@ -1,9 +1,17 @@
1
1
  import type { LogFn } from '@aztec/foundation/log';
2
- import { SignableENR } from '@chainsafe/enr';
2
+ import { type ChainConfig } from '@aztec/stdlib/config';
3
+ import type { ComponentsVersions } from '@aztec/stdlib/versioning';
4
+ import { ENR, SignableENR } from '@chainsafe/enr';
3
5
  import type { PeerId } from '@libp2p/interface';
6
+ import { type Multiaddr } from '@multiformats/multiaddr';
7
+ export { ENR };
4
8
  export declare function createBootnodeENRandPeerId(privateKey: string, p2pIp: string, p2pBroadcastPort: number, l1ChainId: number): Promise<{
5
9
  enr: SignableENR;
6
10
  peerId: PeerId;
7
11
  }>;
12
+ export declare function createNodeENR(peerId: PeerId, multiAddrUdp: Multiaddr | undefined, multiAddrTcp: Multiaddr | undefined, chainConfig: ChainConfig, packageVersion: string): {
13
+ enr: SignableENR;
14
+ versions: ComponentsVersions;
15
+ };
8
16
  export declare function printENR(enr: string, log: LogFn): Promise<void>;
9
17
  //# sourceMappingURL=generate-enr.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"generate-enr.d.ts","sourceRoot":"","sources":["../../src/enr/generate-enr.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,uBAAuB,CAAC;AAGnD,OAAO,EAAO,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAClD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAOhD,wBAAsB,0BAA0B,CAC9C,UAAU,EAAE,MAAM,EAClB,KAAK,E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