Skip to content

Commit 5edee9b

Browse files
committed
Enable finalized history network to portal client
1 parent da3813d commit 5edee9b

File tree

4 files changed

+31
-1
lines changed

4 files changed

+31
-1
lines changed

portal/network/finalized_history/finalized_history_network.nim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ proc new*(
6161

6262
portalProtocol = PortalProtocol.new(
6363
baseProtocol,
64-
[byte(0x50), 0x00], # TODO: Adapt getProtocolId
64+
getProtocolId(portalNetwork, PortalSubnetwork.finalizedHistory),
6565
toContentIdHandler,
6666
createGetHandler(contentDB),
6767
createStoreHandler(contentDB, portalConfig.radiusConfig),

portal/network/portal_node.nim

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import
1717
../database/content_db,
1818
./network_metadata,
1919
./wire/[portal_stream, portal_protocol_config],
20+
./finalized_history/finalized_history_network,
2021
./beacon/[beacon_init_loader, beacon_light_client],
2122
./legacy_history/[history_network, history_content]
2223

@@ -39,6 +40,7 @@ type
3940
discovery: protocol.Protocol
4041
contentDB: ContentDB
4142
streamManager: StreamManager
43+
finalizedHistoryNetwork*: Opt[FinalizedHistoryNetwork]
4244
beaconNetwork*: Opt[BeaconNetwork]
4345
legacyHistoryNetwork*: Opt[LegacyHistoryNetwork]
4446
beaconLightClient*: Opt[LightClient]
@@ -103,6 +105,24 @@ proc new*(
103105
# Get it from binary file containing SSZ encoded accumulator
104106
loadAccumulator()
105107

108+
finalizedHistoryNetwork =
109+
if PortalSubnetwork.finalizedHistory in subnetworks:
110+
Opt.some(
111+
FinalizedHistoryNetwork.new(
112+
network,
113+
discovery,
114+
contentDB,
115+
streamManager,
116+
bootstrapRecords = bootstrapRecords,
117+
portalConfig = config.portalConfig,
118+
contentRequestRetries = config.contentRequestRetries,
119+
contentQueueWorkers = config.contentQueueWorkers,
120+
contentQueueSize = config.contentQueueSize,
121+
)
122+
)
123+
else:
124+
Opt.none(FinalizedHistoryNetwork)
125+
106126
beaconNetwork =
107127
if PortalSubnetwork.beacon in subnetworks:
108128
let
@@ -172,6 +192,7 @@ proc new*(
172192
discovery: discovery,
173193
contentDB: contentDB,
174194
streamManager: streamManager,
195+
finalizedHistoryNetwork: finalizedHistoryNetwork,
175196
beaconNetwork: beaconNetwork,
176197
legacyHistoryNetwork: legacyHistoryNetwork,
177198
beaconLightClient: beaconLightClient,
@@ -204,6 +225,8 @@ proc start*(n: PortalNode) =
204225

205226
n.discovery.start()
206227

228+
if n.finalizedHistoryNetwork.isSome():
229+
n.finalizedHistoryNetwork.value.start()
207230
if n.beaconNetwork.isSome():
208231
n.beaconNetwork.value.start()
209232
if n.legacyHistoryNetwork.isSome():
@@ -218,6 +241,8 @@ proc stop*(n: PortalNode) {.async: (raises: []).} =
218241

219242
var futures: seq[Future[void]]
220243

244+
if n.finalizedHistoryNetwork.isSome():
245+
futures.add(n.finalizedHistoryNetwork.value.stop())
221246
if n.beaconNetwork.isSome():
222247
futures.add(n.beaconNetwork.value.stop())
223248
if n.legacyHistoryNetwork.isSome():

portal/network/wire/portal_protocol.nim

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,8 @@ func getProtocolId*(
308308
case network
309309
of PortalNetwork.none, PortalNetwork.mainnet:
310310
case subnetwork
311+
of PortalSubnetwork.finalizedHistory:
312+
[portalPrefix, 0x00]
311313
of PortalSubnetwork.legacyHistory:
312314
[portalPrefix, 0x0B]
313315
of PortalSubnetwork.history:
@@ -320,6 +322,8 @@ func getProtocolId*(
320322
[portalPrefix, 0x0F]
321323
of PortalNetwork.angelfood:
322324
case subnetwork
325+
of PortalSubnetwork.finalizedHistory:
326+
[portalPrefix, 0x40]
323327
of PortalSubnetwork.legacyHistory:
324328
[portalPrefix, 0x4B]
325329
of PortalSubnetwork.history:

portal/network/wire/portal_protocol_config.nim

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ type
1717

1818
# The Portal sub-protocols
1919
PortalSubnetwork* = enum
20+
finalizedHistory
2021
history
2122
legacyHistory
2223
beacon

0 commit comments

Comments
 (0)