Skip to content

Commit c714fa8

Browse files
authored
Fluffy: Rename portal_*Gossip JSON-RPC endpoints to be in line with updated portal spec (#2970)
* Revert previous change in PortalStream. Allow zero as a valid connectionId if randomly generated. * Rename portal_*Gossip JSON-RPC endpoints to portal_*PutContent to be in line with updated portal spec.
1 parent 487743f commit c714fa8

File tree

8 files changed

+16
-15
lines changed

8 files changed

+16
-15
lines changed

fluffy/network/wire/portal_stream.nim

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -190,8 +190,7 @@ proc addContentOffer*(
190190
var id = ConnectionId.fromBytesBE(connectionId)
191191

192192
# Generate a new id if already existing to avoid using a duplicate
193-
# or if we happen to get an id of zero from the generator
194-
if id == 0 or stream.contentOffers.contains(id):
193+
if stream.contentOffers.contains(id):
195194
stream.rng[].generate(connectionId)
196195
id = ConnectionId.fromBytesBE(connectionId)
197196

@@ -219,8 +218,7 @@ proc addContentRequest*(
219218
var id = ConnectionId.fromBytesBE(connectionId)
220219

221220
# Generate a new id if already existing to avoid using a duplicate
222-
# or if we happen to get an id of zero from the generator
223-
if id == 0 or stream.contentRequests.contains(id):
221+
if stream.contentRequests.contains(id):
224222
stream.rng[].generate(connectionId)
225223
id = ConnectionId.fromBytesBE(connectionId)
226224

fluffy/rpc/rpc_calls/rpc_portal_calls.nim

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ createRpcSigsFromNim(RpcClient):
2828
proc portal_stateGetContent(contentKey: string): ContentInfo
2929
proc portal_stateStore(contentKey: string, contentValue: string): bool
3030
proc portal_stateLocalContent(contentKey: string): string
31-
proc portal_stateGossip(contentKey: string, contentValue: string): int
31+
proc portal_statePutContent(contentKey: string, contentValue: string): int
3232

3333
## Portal History Network json-rpc calls
3434
proc portal_historyNodeInfo(): NodeInfo
@@ -49,7 +49,7 @@ createRpcSigsFromNim(RpcClient):
4949
proc portal_historyGetContent(contentKey: string): ContentInfo
5050
proc portal_historyStore(contentKey: string, contentValue: string): bool
5151
proc portal_historyLocalContent(contentKey: string): string
52-
proc portal_historyGossip(contentKey: string, contentValue: string): int
52+
proc portal_historyPutContent(contentKey: string, contentValue: string): int
5353

5454
## Portal Beacon Light Client Network json-rpc calls
5555
proc portal_beaconNodeInfo(): NodeInfo
@@ -67,5 +67,5 @@ createRpcSigsFromNim(RpcClient):
6767
proc portal_beaconGetContent(contentKey: string): ContentInfo
6868
proc portal_beaconStore(contentKey: string, contentValue: string): bool
6969
proc portal_beaconLocalContent(contentKey: string): string
70-
proc portal_beaconGossip(contentKey: string, contentValue: string): int
70+
proc portal_beaconPutContent(contentKey: string, contentValue: string): int
7171
proc portal_beaconRandomGossip(contentKey: string, contentValue: string): int

fluffy/rpc/rpc_portal_beacon_api.nim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ proc installPortalBeaconApiHandlers*(rpcServer: RpcServer, p: PortalProtocol) =
129129

130130
return contentResult.to0xHex()
131131

132-
rpcServer.rpc("portal_beaconGossip") do(
132+
rpcServer.rpc("portal_beaconPutContent") do(
133133
contentKey: string, contentValue: string
134134
) -> int:
135135
let

fluffy/rpc/rpc_portal_history_api.nim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ proc installPortalHistoryApiHandlers*(rpcServer: RpcServer, p: PortalProtocol) =
137137

138138
return contentResult.to0xHex()
139139

140-
rpcServer.rpc("portal_historyGossip") do(
140+
rpcServer.rpc("portal_historyPutContent") do(
141141
contentKey: string, contentValue: string
142142
) -> int:
143143
let

fluffy/rpc/rpc_portal_state_api.nim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ proc installPortalStateApiHandlers*(rpcServer: RpcServer, p: PortalProtocol) =
150150

151151
contentResult.to0xHex()
152152

153-
rpcServer.rpc("portal_stateGossip") do(contentKey: string, content: string) -> int:
153+
rpcServer.rpc("portal_statePutContent") do(contentKey: string, content: string) -> int:
154154
let
155155
keyBytes = ContentKeyByteList.init(hexToSeqByte(contentKey))
156156
(key, contentId) = validateGetContentKey(keyBytes).valueOr:

fluffy/scripts/test_portal_testnet.nim

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,9 @@ procSuite "Portal testnet tests":
264264
# require them for validation.
265265
for (contentKey, contentValue) in blockHeadersWithProof:
266266
discard (
267-
await clients[0].portal_historyGossip(contentKey.toHex(), contentValue.toHex())
267+
await clients[0].portal_historyPutContent(
268+
contentKey.toHex(), contentValue.toHex()
269+
)
268270
)
269271

270272
# TODO: Fix iteration order: Because the blockData gets parsed into a
@@ -291,7 +293,7 @@ procSuite "Portal testnet tests":
291293
contentKey = history_content.encode(value[0]).asSeq().toHex()
292294
contentValue = value[1].toHex()
293295

294-
discard (await clients[0].portal_historyGossip(contentKey, contentValue))
296+
discard (await clients[0].portal_historyPutContent(contentKey, contentValue))
295297

296298
await clients[0].close()
297299

fluffy/tools/portal_bridge/portal_bridge_history.nim

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -516,15 +516,15 @@ proc runHistory*(config: PortalBridgeConf) =
516516
contentValueHex = contentValue.toHex()
517517

518518
try:
519-
let peers = await bridge.portalClient.portal_historyGossip(
519+
let peers = await bridge.portalClient.portal_historyPutContent(
520520
contentKeyHex, contentValueHex
521521
)
522522
debug "Content gossiped", peers, contentKey = contentKeyHex
523523
except CancelledError as e:
524524
trace "Cancelled gossipWorker"
525525
raise e
526526
except CatchableError as e:
527-
error "JSON-RPC portal_historyGossip failed",
527+
error "JSON-RPC portal_historyPutContent failed",
528528
error = $e.msg, contentKey = contentKeyHex
529529
except CancelledError:
530530
trace "gossipWorker canceled"

fluffy/tools/portal_bridge/portal_bridge_state.nim

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,8 @@ proc runBackfillGossipBlockOffersLoop(
333333

334334
if gossipContent:
335335
try:
336-
let numPeers = await portalClient.portal_stateGossip(k.to0xHex(), v.to0xHex())
336+
let numPeers =
337+
await portalClient.portal_statePutContent(k.to0xHex(), v.to0xHex())
337338
if numPeers > 0:
338339
debug "Offer successfully gossipped to peers: ", numPeers, workerId
339340
elif numPeers == 0:

0 commit comments

Comments
 (0)