diff --git a/fluffy/rpc/portal_rpc_client.nim b/fluffy/rpc/portal_rpc_client.nim index 64a431163..a33d0836d 100644 --- a/fluffy/rpc/portal_rpc_client.nim +++ b/fluffy/rpc/portal_rpc_client.nim @@ -48,7 +48,7 @@ func toPortalRpcError(e: ref CatchableError): PortalRpcError = else: raiseAssert(e.msg) -proc historyLocalContent( +proc portal_historyLocalContent( client: PortalRpcClient, contentKey: string ): Future[Result[string, PortalRpcError]] {.async: (raises: []).} = try: @@ -57,12 +57,11 @@ proc historyLocalContent( except CatchableError as e: err(e.toPortalRpcError()) -proc historyRecursiveFindContent( +proc portal_historyGetContent( client: PortalRpcClient, contentKey: string ): Future[Result[string, PortalRpcError]] {.async: (raises: []).} = try: - let contentInfo = - await RpcClient(client).portal_historyRecursiveFindContent(contentKey) + let contentInfo = await RpcClient(client).portal_historyGetContent(contentKey) ok(contentInfo.content) except CatchableError as e: err(e.toPortalRpcError()) @@ -83,9 +82,9 @@ proc historyGetContent( client: PortalRpcClient, contentKey: string ): Future[Result[string, PortalRpcError]] {.async: (raises: []).} = # Look up the content from the local db before trying to get it from the network - let content = (await client.historyLocalContent(contentKey)).valueOr: + let content = (await client.portal_historyLocalContent(contentKey)).valueOr: if error == ContentNotFound: - ?await client.historyRecursiveFindContent(contentKey) + ?await client.portal_historyGetContent(contentKey) else: return err(error) ok(content) diff --git a/fluffy/rpc/rpc_calls/rpc_portal_calls.nim b/fluffy/rpc/rpc_calls/rpc_portal_calls.nim index 6eb4b8142..0869aa0b9 100644 --- a/fluffy/rpc/rpc_calls/rpc_portal_calls.nim +++ b/fluffy/rpc/rpc_calls/rpc_portal_calls.nim @@ -25,7 +25,7 @@ createRpcSigsFromNim(RpcClient): proc portal_stateFindContent(enr: Record, contentKey: string): JsonNode proc portal_stateOffer(enr: Record, contentKey: string, contentValue: string): string proc portal_stateRecursiveFindNodes(nodeId: NodeId): seq[Record] - proc portal_stateRecursiveFindContent(contentKey: string): ContentInfo + proc portal_stateGetContent(contentKey: string): ContentInfo proc portal_stateStore(contentKey: string, contentValue: string): bool proc portal_stateLocalContent(contentKey: string): string proc portal_stateGossip(contentKey: string, contentValue: string): int @@ -46,7 +46,7 @@ createRpcSigsFromNim(RpcClient): ): string proc portal_historyRecursiveFindNodes(nodeId: NodeId): seq[Record] - proc portal_historyRecursiveFindContent(contentKey: string): ContentInfo + proc portal_historyGetContent(contentKey: string): ContentInfo proc portal_historyStore(contentKey: string, contentValue: string): bool proc portal_historyLocalContent(contentKey: string): string proc portal_historyGossip(contentKey: string, contentValue: string): int @@ -64,7 +64,7 @@ createRpcSigsFromNim(RpcClient): proc portal_beaconFindContent(enr: Record, contentKey: string): JsonNode proc portal_beaconOffer(enr: Record, contentKey: string, contentValue: string): string proc portal_beaconRecursiveFindNodes(nodeId: NodeId): seq[Record] - proc portal_beaconRecursiveFindContent(contentKey: string): ContentInfo + proc portal_beaconGetContent(contentKey: string): ContentInfo proc portal_beaconStore(contentKey: string, contentValue: string): bool proc portal_beaconLocalContent(contentKey: string): string proc portal_beaconGossip(contentKey: string, contentValue: string): int diff --git a/fluffy/rpc/rpc_portal_beacon_api.nim b/fluffy/rpc/rpc_portal_beacon_api.nim index ddcf9c988..891fa1079 100644 --- a/fluffy/rpc/rpc_portal_beacon_api.nim +++ b/fluffy/rpc/rpc_portal_beacon_api.nim @@ -76,9 +76,7 @@ proc installPortalBeaconApiHandlers*(rpcServer: RpcServer, p: PortalProtocol) = SSZ.encode(offerResult).to0xHex() - rpcServer.rpc("portal_beaconRecursiveFindContent") do( - contentKey: string - ) -> ContentInfo: + rpcServer.rpc("portal_beaconGetContent") do(contentKey: string) -> ContentInfo: let key = ContentKeyByteList.init(hexToSeqByte(contentKey)) contentId = p.toContentId(key).valueOr: @@ -91,7 +89,7 @@ proc installPortalBeaconApiHandlers*(rpcServer: RpcServer, p: PortalProtocol) = content: contentResult.content.to0xHex(), utpTransfer: contentResult.utpTransfer ) - rpcServer.rpc("portal_beaconTraceRecursiveFindContent") do( + rpcServer.rpc("portal_beaconTraceGetContent") do( contentKey: string ) -> TraceContentLookupResult: let diff --git a/fluffy/rpc/rpc_portal_history_api.nim b/fluffy/rpc/rpc_portal_history_api.nim index 6d057996a..b74f08bed 100644 --- a/fluffy/rpc/rpc_portal_history_api.nim +++ b/fluffy/rpc/rpc_portal_history_api.nim @@ -76,9 +76,7 @@ proc installPortalHistoryApiHandlers*(rpcServer: RpcServer, p: PortalProtocol) = SSZ.encode(offerResult).to0xHex() - rpcServer.rpc("portal_historyRecursiveFindContent") do( - contentKey: string - ) -> ContentInfo: + rpcServer.rpc("portal_historyGetContent") do(contentKey: string) -> ContentInfo: let key = ContentKeyByteList.init(hexToSeqByte(contentKey)) contentId = p.toContentId(key).valueOr: @@ -91,7 +89,7 @@ proc installPortalHistoryApiHandlers*(rpcServer: RpcServer, p: PortalProtocol) = content: contentResult.content.to0xHex(), utpTransfer: contentResult.utpTransfer ) - rpcServer.rpc("portal_historyTraceRecursiveFindContent") do( + rpcServer.rpc("portal_historyTraceGetContent") do( contentKey: string ) -> TraceContentLookupResult: let diff --git a/fluffy/rpc/rpc_portal_state_api.nim b/fluffy/rpc/rpc_portal_state_api.nim index 8aa67e6f5..a1d163ddb 100644 --- a/fluffy/rpc/rpc_portal_state_api.nim +++ b/fluffy/rpc/rpc_portal_state_api.nim @@ -83,9 +83,7 @@ proc installPortalStateApiHandlers*(rpcServer: RpcServer, p: PortalProtocol) = SSZ.encode(offerResult).to0xHex() - rpcServer.rpc("portal_stateRecursiveFindContent") do( - contentKey: string - ) -> ContentInfo: + rpcServer.rpc("portal_stateGetContent") do(contentKey: string) -> ContentInfo: let keyBytes = ContentKeyByteList.init(hexToSeqByte(contentKey)) (key, contentId) = validateGetContentKey(keyBytes).valueOr: @@ -105,7 +103,7 @@ proc installPortalStateApiHandlers*(rpcServer: RpcServer, p: PortalProtocol) = ContentInfo(content: contentValue.to0xHex(), utpTransfer: foundContent.utpTransfer) - rpcServer.rpc("portal_stateTraceRecursiveFindContent") do( + rpcServer.rpc("portal_stateTraceGetContent") do( contentKey: string ) -> TraceContentLookupResult: let diff --git a/fluffy/tests/rpc_tests/test_portal_rpc_client.nim b/fluffy/tests/rpc_tests/test_portal_rpc_client.nim index 9553cf21a..756aedc5d 100644 --- a/fluffy/tests/rpc_tests/test_portal_rpc_client.nim +++ b/fluffy/tests/rpc_tests/test_portal_rpc_client.nim @@ -87,7 +87,8 @@ proc store*(hn: HistoryNode, blockHash: Hash32, receipts: seq[Receipt]) = hn.portalProtocol().storeContent(contentKeyBytes, contentId, receipts.encode()) type TestCase = ref object - historyNode: HistoryNode + historyNode1: HistoryNode + historyNode2: HistoryNode server: RpcHttpServer client: PortalRpcClient @@ -97,19 +98,28 @@ proc setupTest(rng: ref HmacDrbgContext): Future[TestCase] {.async.} = localSrvPort = 0 # let the OS choose a port ta = initTAddress(localSrvAddress, localSrvPort) client = newRpcHttpClient() - historyNode = newHistoryNode(rng, 20333) + historyNode1 = newHistoryNode(rng, 20333) + historyNode2 = newHistoryNode(rng, 20334) + + historyNode1.start() + historyNode2.start() + + check: + historyNode1.portalProtocol().addNode(historyNode2.localNode()) == Added + historyNode2.portalProtocol().addNode(historyNode1.localNode()) == Added let rpcHttpServer = RpcHttpServer.new() rpcHttpServer.addHttpServer(ta, maxRequestBodySize = 4 * 1_048_576) rpcHttpServer.installPortalHistoryApiHandlers( - historyNode.historyNetwork.portalProtocol + historyNode1.historyNetwork.portalProtocol ) rpcHttpServer.start() await client.connect(localSrvAddress, rpcHttpServer.localAddress[0].port, false) return TestCase( - historyNode: historyNode, + historyNode1: historyNode1, + historyNode2: historyNode2, server: rpcHttpServer, client: PortalRpcClient.init(client), ) @@ -117,7 +127,8 @@ proc setupTest(rng: ref HmacDrbgContext): Future[TestCase] {.async.} = proc stop(testCase: TestCase) {.async.} = await testCase.server.stop() await testCase.server.closeWait() - await testCase.historyNode.stop() + await testCase.historyNode1.stop() + await testCase.historyNode2.stop() procSuite "Portal RPC Client": let rng = newRng() @@ -138,7 +149,7 @@ procSuite "Portal RPC Client": # Test content found block: - tc.historyNode.store(blockHash, blockHeader) + tc.historyNode2.store(blockHash, blockHeader) let blockHeaderRes = await tc.client.historyGetBlockHeader(blockHash, validateContent = true) @@ -148,7 +159,7 @@ procSuite "Portal RPC Client": # Test content validation failed block: - tc.historyNode.store(blockHash, Header()) # bad header + tc.historyNode1.store(blockHash, Header()) # bad header let blockHeaderRes = await tc.client.historyGetBlockHeader(blockHash, validateContent = true) @@ -172,10 +183,10 @@ procSuite "Portal RPC Client": blockHeaderRes.isErr() blockHeaderRes.error() == ContentNotFound - tc.historyNode.store(blockHash, blockHeader) - # Test content found block: + tc.historyNode1.store(blockHash, blockHeader) + let blockHeaderRes = await tc.client.historyGetBlockHeader(blockHash, validateContent = false) check: @@ -201,8 +212,8 @@ procSuite "Portal RPC Client": # Test content validation failed block: - tc.historyNode.store(blockHash, blockHeader) - tc.historyNode.store(blockHash, blockBody) + tc.historyNode1.store(blockHash, blockHeader) + tc.historyNode1.store(blockHash, blockBody) let blockBodyRes = await tc.client.historyGetBlockBody(blockHash, validateContent = true) @@ -229,8 +240,8 @@ procSuite "Portal RPC Client": # Test content found block: - tc.historyNode.store(blockHash, blockHeader) - tc.historyNode.store(blockHash, blockBody) + tc.historyNode1.store(blockHash, blockHeader) + tc.historyNode1.store(blockHash, blockBody) let blockBodyRes = await tc.client.historyGetBlockBody(blockHash, validateContent = false) @@ -257,8 +268,8 @@ procSuite "Portal RPC Client": # Test content validation failed block: - tc.historyNode.store(blockHash, blockHeader) - tc.historyNode.store(blockHash, receipts) + tc.historyNode1.store(blockHash, blockHeader) + tc.historyNode1.store(blockHash, receipts) let receiptsRes = await tc.client.historyGetReceipts(blockHash, validateContent = true) @@ -285,8 +296,8 @@ procSuite "Portal RPC Client": # Test content found block: - tc.historyNode.store(blockHash, blockHeader) - tc.historyNode.store(blockHash, receipts) + tc.historyNode1.store(blockHash, blockHeader) + tc.historyNode1.store(blockHash, receipts) let receiptsRes = await tc.client.historyGetReceipts(blockHash, validateContent = false) diff --git a/fluffy/tools/portal_bridge/portal_bridge_history.nim b/fluffy/tools/portal_bridge/portal_bridge_history.nim index 0473a7db2..60bdc7e12 100644 --- a/fluffy/tools/portal_bridge/portal_bridge_history.nim +++ b/fluffy/tools/portal_bridge/portal_bridge_history.nim @@ -422,7 +422,7 @@ proc runBackfillLoopAuditMode( contentHex = try: ( - await portalClient.portal_historyRecursiveFindContent( + await portalClient.portal_historyGetContent( contentKey.encode.asSeq().toHex() ) ).content @@ -454,7 +454,7 @@ proc runBackfillLoopAuditMode( contentHex = try: ( - await portalClient.portal_historyRecursiveFindContent( + await portalClient.portal_historyGetContent( contentKey.encode.asSeq().toHex() ) ).content @@ -482,7 +482,7 @@ proc runBackfillLoopAuditMode( contentHex = try: ( - await portalClient.portal_historyRecursiveFindContent( + await portalClient.portal_historyGetContent( contentKey.encode.asSeq().toHex() ) ).content diff --git a/fluffy/tools/portal_bridge/portal_bridge_state.nim b/fluffy/tools/portal_bridge/portal_bridge_state.nim index 336f2628d..e50e3f9c0 100644 --- a/fluffy/tools/portal_bridge/portal_bridge_state.nim +++ b/fluffy/tools/portal_bridge/portal_bridge_state.nim @@ -329,8 +329,7 @@ proc runBackfillGossipBlockOffersLoop( await sleepAsync(100.milliseconds) # wait for the peers to be updated for k, _ in offersMap: try: - let contentInfo = - await portalClient.portal_stateRecursiveFindContent(k.to0xHex()) + let contentInfo = await portalClient.portal_stateGetContent(k.to0xHex()) if contentInfo.content.len() == 0: error "Found empty contentValue", workerId retryGossip = true