mirror of
https://github.com/status-im/nimbus-eth1.git
synced 2025-03-01 04:10:45 +00:00
Rename Fluffy rpc methods to match updated spec (#2735)
This commit is contained in:
parent
3e36f52fd7
commit
bdbea9853e
@ -48,7 +48,7 @@ func toPortalRpcError(e: ref CatchableError): PortalRpcError =
|
|||||||
else:
|
else:
|
||||||
raiseAssert(e.msg)
|
raiseAssert(e.msg)
|
||||||
|
|
||||||
proc historyLocalContent(
|
proc portal_historyLocalContent(
|
||||||
client: PortalRpcClient, contentKey: string
|
client: PortalRpcClient, contentKey: string
|
||||||
): Future[Result[string, PortalRpcError]] {.async: (raises: []).} =
|
): Future[Result[string, PortalRpcError]] {.async: (raises: []).} =
|
||||||
try:
|
try:
|
||||||
@ -57,12 +57,11 @@ proc historyLocalContent(
|
|||||||
except CatchableError as e:
|
except CatchableError as e:
|
||||||
err(e.toPortalRpcError())
|
err(e.toPortalRpcError())
|
||||||
|
|
||||||
proc historyRecursiveFindContent(
|
proc portal_historyGetContent(
|
||||||
client: PortalRpcClient, contentKey: string
|
client: PortalRpcClient, contentKey: string
|
||||||
): Future[Result[string, PortalRpcError]] {.async: (raises: []).} =
|
): Future[Result[string, PortalRpcError]] {.async: (raises: []).} =
|
||||||
try:
|
try:
|
||||||
let contentInfo =
|
let contentInfo = await RpcClient(client).portal_historyGetContent(contentKey)
|
||||||
await RpcClient(client).portal_historyRecursiveFindContent(contentKey)
|
|
||||||
ok(contentInfo.content)
|
ok(contentInfo.content)
|
||||||
except CatchableError as e:
|
except CatchableError as e:
|
||||||
err(e.toPortalRpcError())
|
err(e.toPortalRpcError())
|
||||||
@ -83,9 +82,9 @@ proc historyGetContent(
|
|||||||
client: PortalRpcClient, contentKey: string
|
client: PortalRpcClient, contentKey: string
|
||||||
): Future[Result[string, PortalRpcError]] {.async: (raises: []).} =
|
): Future[Result[string, PortalRpcError]] {.async: (raises: []).} =
|
||||||
# Look up the content from the local db before trying to get it from the network
|
# 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:
|
if error == ContentNotFound:
|
||||||
?await client.historyRecursiveFindContent(contentKey)
|
?await client.portal_historyGetContent(contentKey)
|
||||||
else:
|
else:
|
||||||
return err(error)
|
return err(error)
|
||||||
ok(content)
|
ok(content)
|
||||||
|
@ -25,7 +25,7 @@ createRpcSigsFromNim(RpcClient):
|
|||||||
proc portal_stateFindContent(enr: Record, contentKey: string): JsonNode
|
proc portal_stateFindContent(enr: Record, contentKey: string): JsonNode
|
||||||
proc portal_stateOffer(enr: Record, contentKey: string, contentValue: string): string
|
proc portal_stateOffer(enr: Record, contentKey: string, contentValue: string): string
|
||||||
proc portal_stateRecursiveFindNodes(nodeId: NodeId): seq[Record]
|
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_stateStore(contentKey: string, contentValue: string): bool
|
||||||
proc portal_stateLocalContent(contentKey: string): string
|
proc portal_stateLocalContent(contentKey: string): string
|
||||||
proc portal_stateGossip(contentKey: string, contentValue: string): int
|
proc portal_stateGossip(contentKey: string, contentValue: string): int
|
||||||
@ -46,7 +46,7 @@ createRpcSigsFromNim(RpcClient):
|
|||||||
): string
|
): string
|
||||||
|
|
||||||
proc portal_historyRecursiveFindNodes(nodeId: NodeId): seq[Record]
|
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_historyStore(contentKey: string, contentValue: string): bool
|
||||||
proc portal_historyLocalContent(contentKey: string): string
|
proc portal_historyLocalContent(contentKey: string): string
|
||||||
proc portal_historyGossip(contentKey: string, contentValue: string): int
|
proc portal_historyGossip(contentKey: string, contentValue: string): int
|
||||||
@ -64,7 +64,7 @@ createRpcSigsFromNim(RpcClient):
|
|||||||
proc portal_beaconFindContent(enr: Record, contentKey: string): JsonNode
|
proc portal_beaconFindContent(enr: Record, contentKey: string): JsonNode
|
||||||
proc portal_beaconOffer(enr: Record, contentKey: string, contentValue: string): string
|
proc portal_beaconOffer(enr: Record, contentKey: string, contentValue: string): string
|
||||||
proc portal_beaconRecursiveFindNodes(nodeId: NodeId): seq[Record]
|
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_beaconStore(contentKey: string, contentValue: string): bool
|
||||||
proc portal_beaconLocalContent(contentKey: string): string
|
proc portal_beaconLocalContent(contentKey: string): string
|
||||||
proc portal_beaconGossip(contentKey: string, contentValue: string): int
|
proc portal_beaconGossip(contentKey: string, contentValue: string): int
|
||||||
|
@ -76,9 +76,7 @@ proc installPortalBeaconApiHandlers*(rpcServer: RpcServer, p: PortalProtocol) =
|
|||||||
|
|
||||||
SSZ.encode(offerResult).to0xHex()
|
SSZ.encode(offerResult).to0xHex()
|
||||||
|
|
||||||
rpcServer.rpc("portal_beaconRecursiveFindContent") do(
|
rpcServer.rpc("portal_beaconGetContent") do(contentKey: string) -> ContentInfo:
|
||||||
contentKey: string
|
|
||||||
) -> ContentInfo:
|
|
||||||
let
|
let
|
||||||
key = ContentKeyByteList.init(hexToSeqByte(contentKey))
|
key = ContentKeyByteList.init(hexToSeqByte(contentKey))
|
||||||
contentId = p.toContentId(key).valueOr:
|
contentId = p.toContentId(key).valueOr:
|
||||||
@ -91,7 +89,7 @@ proc installPortalBeaconApiHandlers*(rpcServer: RpcServer, p: PortalProtocol) =
|
|||||||
content: contentResult.content.to0xHex(), utpTransfer: contentResult.utpTransfer
|
content: contentResult.content.to0xHex(), utpTransfer: contentResult.utpTransfer
|
||||||
)
|
)
|
||||||
|
|
||||||
rpcServer.rpc("portal_beaconTraceRecursiveFindContent") do(
|
rpcServer.rpc("portal_beaconTraceGetContent") do(
|
||||||
contentKey: string
|
contentKey: string
|
||||||
) -> TraceContentLookupResult:
|
) -> TraceContentLookupResult:
|
||||||
let
|
let
|
||||||
|
@ -76,9 +76,7 @@ proc installPortalHistoryApiHandlers*(rpcServer: RpcServer, p: PortalProtocol) =
|
|||||||
|
|
||||||
SSZ.encode(offerResult).to0xHex()
|
SSZ.encode(offerResult).to0xHex()
|
||||||
|
|
||||||
rpcServer.rpc("portal_historyRecursiveFindContent") do(
|
rpcServer.rpc("portal_historyGetContent") do(contentKey: string) -> ContentInfo:
|
||||||
contentKey: string
|
|
||||||
) -> ContentInfo:
|
|
||||||
let
|
let
|
||||||
key = ContentKeyByteList.init(hexToSeqByte(contentKey))
|
key = ContentKeyByteList.init(hexToSeqByte(contentKey))
|
||||||
contentId = p.toContentId(key).valueOr:
|
contentId = p.toContentId(key).valueOr:
|
||||||
@ -91,7 +89,7 @@ proc installPortalHistoryApiHandlers*(rpcServer: RpcServer, p: PortalProtocol) =
|
|||||||
content: contentResult.content.to0xHex(), utpTransfer: contentResult.utpTransfer
|
content: contentResult.content.to0xHex(), utpTransfer: contentResult.utpTransfer
|
||||||
)
|
)
|
||||||
|
|
||||||
rpcServer.rpc("portal_historyTraceRecursiveFindContent") do(
|
rpcServer.rpc("portal_historyTraceGetContent") do(
|
||||||
contentKey: string
|
contentKey: string
|
||||||
) -> TraceContentLookupResult:
|
) -> TraceContentLookupResult:
|
||||||
let
|
let
|
||||||
|
@ -83,9 +83,7 @@ proc installPortalStateApiHandlers*(rpcServer: RpcServer, p: PortalProtocol) =
|
|||||||
|
|
||||||
SSZ.encode(offerResult).to0xHex()
|
SSZ.encode(offerResult).to0xHex()
|
||||||
|
|
||||||
rpcServer.rpc("portal_stateRecursiveFindContent") do(
|
rpcServer.rpc("portal_stateGetContent") do(contentKey: string) -> ContentInfo:
|
||||||
contentKey: string
|
|
||||||
) -> ContentInfo:
|
|
||||||
let
|
let
|
||||||
keyBytes = ContentKeyByteList.init(hexToSeqByte(contentKey))
|
keyBytes = ContentKeyByteList.init(hexToSeqByte(contentKey))
|
||||||
(key, contentId) = validateGetContentKey(keyBytes).valueOr:
|
(key, contentId) = validateGetContentKey(keyBytes).valueOr:
|
||||||
@ -105,7 +103,7 @@ proc installPortalStateApiHandlers*(rpcServer: RpcServer, p: PortalProtocol) =
|
|||||||
|
|
||||||
ContentInfo(content: contentValue.to0xHex(), utpTransfer: foundContent.utpTransfer)
|
ContentInfo(content: contentValue.to0xHex(), utpTransfer: foundContent.utpTransfer)
|
||||||
|
|
||||||
rpcServer.rpc("portal_stateTraceRecursiveFindContent") do(
|
rpcServer.rpc("portal_stateTraceGetContent") do(
|
||||||
contentKey: string
|
contentKey: string
|
||||||
) -> TraceContentLookupResult:
|
) -> TraceContentLookupResult:
|
||||||
let
|
let
|
||||||
|
@ -87,7 +87,8 @@ proc store*(hn: HistoryNode, blockHash: Hash32, receipts: seq[Receipt]) =
|
|||||||
hn.portalProtocol().storeContent(contentKeyBytes, contentId, receipts.encode())
|
hn.portalProtocol().storeContent(contentKeyBytes, contentId, receipts.encode())
|
||||||
|
|
||||||
type TestCase = ref object
|
type TestCase = ref object
|
||||||
historyNode: HistoryNode
|
historyNode1: HistoryNode
|
||||||
|
historyNode2: HistoryNode
|
||||||
server: RpcHttpServer
|
server: RpcHttpServer
|
||||||
client: PortalRpcClient
|
client: PortalRpcClient
|
||||||
|
|
||||||
@ -97,19 +98,28 @@ proc setupTest(rng: ref HmacDrbgContext): Future[TestCase] {.async.} =
|
|||||||
localSrvPort = 0 # let the OS choose a port
|
localSrvPort = 0 # let the OS choose a port
|
||||||
ta = initTAddress(localSrvAddress, localSrvPort)
|
ta = initTAddress(localSrvAddress, localSrvPort)
|
||||||
client = newRpcHttpClient()
|
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()
|
let rpcHttpServer = RpcHttpServer.new()
|
||||||
rpcHttpServer.addHttpServer(ta, maxRequestBodySize = 4 * 1_048_576)
|
rpcHttpServer.addHttpServer(ta, maxRequestBodySize = 4 * 1_048_576)
|
||||||
rpcHttpServer.installPortalHistoryApiHandlers(
|
rpcHttpServer.installPortalHistoryApiHandlers(
|
||||||
historyNode.historyNetwork.portalProtocol
|
historyNode1.historyNetwork.portalProtocol
|
||||||
)
|
)
|
||||||
rpcHttpServer.start()
|
rpcHttpServer.start()
|
||||||
|
|
||||||
await client.connect(localSrvAddress, rpcHttpServer.localAddress[0].port, false)
|
await client.connect(localSrvAddress, rpcHttpServer.localAddress[0].port, false)
|
||||||
|
|
||||||
return TestCase(
|
return TestCase(
|
||||||
historyNode: historyNode,
|
historyNode1: historyNode1,
|
||||||
|
historyNode2: historyNode2,
|
||||||
server: rpcHttpServer,
|
server: rpcHttpServer,
|
||||||
client: PortalRpcClient.init(client),
|
client: PortalRpcClient.init(client),
|
||||||
)
|
)
|
||||||
@ -117,7 +127,8 @@ proc setupTest(rng: ref HmacDrbgContext): Future[TestCase] {.async.} =
|
|||||||
proc stop(testCase: TestCase) {.async.} =
|
proc stop(testCase: TestCase) {.async.} =
|
||||||
await testCase.server.stop()
|
await testCase.server.stop()
|
||||||
await testCase.server.closeWait()
|
await testCase.server.closeWait()
|
||||||
await testCase.historyNode.stop()
|
await testCase.historyNode1.stop()
|
||||||
|
await testCase.historyNode2.stop()
|
||||||
|
|
||||||
procSuite "Portal RPC Client":
|
procSuite "Portal RPC Client":
|
||||||
let rng = newRng()
|
let rng = newRng()
|
||||||
@ -138,7 +149,7 @@ procSuite "Portal RPC Client":
|
|||||||
|
|
||||||
# Test content found
|
# Test content found
|
||||||
block:
|
block:
|
||||||
tc.historyNode.store(blockHash, blockHeader)
|
tc.historyNode2.store(blockHash, blockHeader)
|
||||||
|
|
||||||
let blockHeaderRes =
|
let blockHeaderRes =
|
||||||
await tc.client.historyGetBlockHeader(blockHash, validateContent = true)
|
await tc.client.historyGetBlockHeader(blockHash, validateContent = true)
|
||||||
@ -148,7 +159,7 @@ procSuite "Portal RPC Client":
|
|||||||
|
|
||||||
# Test content validation failed
|
# Test content validation failed
|
||||||
block:
|
block:
|
||||||
tc.historyNode.store(blockHash, Header()) # bad header
|
tc.historyNode1.store(blockHash, Header()) # bad header
|
||||||
|
|
||||||
let blockHeaderRes =
|
let blockHeaderRes =
|
||||||
await tc.client.historyGetBlockHeader(blockHash, validateContent = true)
|
await tc.client.historyGetBlockHeader(blockHash, validateContent = true)
|
||||||
@ -172,10 +183,10 @@ procSuite "Portal RPC Client":
|
|||||||
blockHeaderRes.isErr()
|
blockHeaderRes.isErr()
|
||||||
blockHeaderRes.error() == ContentNotFound
|
blockHeaderRes.error() == ContentNotFound
|
||||||
|
|
||||||
tc.historyNode.store(blockHash, blockHeader)
|
|
||||||
|
|
||||||
# Test content found
|
# Test content found
|
||||||
block:
|
block:
|
||||||
|
tc.historyNode1.store(blockHash, blockHeader)
|
||||||
|
|
||||||
let blockHeaderRes =
|
let blockHeaderRes =
|
||||||
await tc.client.historyGetBlockHeader(blockHash, validateContent = false)
|
await tc.client.historyGetBlockHeader(blockHash, validateContent = false)
|
||||||
check:
|
check:
|
||||||
@ -201,8 +212,8 @@ procSuite "Portal RPC Client":
|
|||||||
|
|
||||||
# Test content validation failed
|
# Test content validation failed
|
||||||
block:
|
block:
|
||||||
tc.historyNode.store(blockHash, blockHeader)
|
tc.historyNode1.store(blockHash, blockHeader)
|
||||||
tc.historyNode.store(blockHash, blockBody)
|
tc.historyNode1.store(blockHash, blockBody)
|
||||||
|
|
||||||
let blockBodyRes =
|
let blockBodyRes =
|
||||||
await tc.client.historyGetBlockBody(blockHash, validateContent = true)
|
await tc.client.historyGetBlockBody(blockHash, validateContent = true)
|
||||||
@ -229,8 +240,8 @@ procSuite "Portal RPC Client":
|
|||||||
|
|
||||||
# Test content found
|
# Test content found
|
||||||
block:
|
block:
|
||||||
tc.historyNode.store(blockHash, blockHeader)
|
tc.historyNode1.store(blockHash, blockHeader)
|
||||||
tc.historyNode.store(blockHash, blockBody)
|
tc.historyNode1.store(blockHash, blockBody)
|
||||||
|
|
||||||
let blockBodyRes =
|
let blockBodyRes =
|
||||||
await tc.client.historyGetBlockBody(blockHash, validateContent = false)
|
await tc.client.historyGetBlockBody(blockHash, validateContent = false)
|
||||||
@ -257,8 +268,8 @@ procSuite "Portal RPC Client":
|
|||||||
|
|
||||||
# Test content validation failed
|
# Test content validation failed
|
||||||
block:
|
block:
|
||||||
tc.historyNode.store(blockHash, blockHeader)
|
tc.historyNode1.store(blockHash, blockHeader)
|
||||||
tc.historyNode.store(blockHash, receipts)
|
tc.historyNode1.store(blockHash, receipts)
|
||||||
|
|
||||||
let receiptsRes =
|
let receiptsRes =
|
||||||
await tc.client.historyGetReceipts(blockHash, validateContent = true)
|
await tc.client.historyGetReceipts(blockHash, validateContent = true)
|
||||||
@ -285,8 +296,8 @@ procSuite "Portal RPC Client":
|
|||||||
|
|
||||||
# Test content found
|
# Test content found
|
||||||
block:
|
block:
|
||||||
tc.historyNode.store(blockHash, blockHeader)
|
tc.historyNode1.store(blockHash, blockHeader)
|
||||||
tc.historyNode.store(blockHash, receipts)
|
tc.historyNode1.store(blockHash, receipts)
|
||||||
|
|
||||||
let receiptsRes =
|
let receiptsRes =
|
||||||
await tc.client.historyGetReceipts(blockHash, validateContent = false)
|
await tc.client.historyGetReceipts(blockHash, validateContent = false)
|
||||||
|
@ -422,7 +422,7 @@ proc runBackfillLoopAuditMode(
|
|||||||
contentHex =
|
contentHex =
|
||||||
try:
|
try:
|
||||||
(
|
(
|
||||||
await portalClient.portal_historyRecursiveFindContent(
|
await portalClient.portal_historyGetContent(
|
||||||
contentKey.encode.asSeq().toHex()
|
contentKey.encode.asSeq().toHex()
|
||||||
)
|
)
|
||||||
).content
|
).content
|
||||||
@ -454,7 +454,7 @@ proc runBackfillLoopAuditMode(
|
|||||||
contentHex =
|
contentHex =
|
||||||
try:
|
try:
|
||||||
(
|
(
|
||||||
await portalClient.portal_historyRecursiveFindContent(
|
await portalClient.portal_historyGetContent(
|
||||||
contentKey.encode.asSeq().toHex()
|
contentKey.encode.asSeq().toHex()
|
||||||
)
|
)
|
||||||
).content
|
).content
|
||||||
@ -482,7 +482,7 @@ proc runBackfillLoopAuditMode(
|
|||||||
contentHex =
|
contentHex =
|
||||||
try:
|
try:
|
||||||
(
|
(
|
||||||
await portalClient.portal_historyRecursiveFindContent(
|
await portalClient.portal_historyGetContent(
|
||||||
contentKey.encode.asSeq().toHex()
|
contentKey.encode.asSeq().toHex()
|
||||||
)
|
)
|
||||||
).content
|
).content
|
||||||
|
@ -329,8 +329,7 @@ proc runBackfillGossipBlockOffersLoop(
|
|||||||
await sleepAsync(100.milliseconds) # wait for the peers to be updated
|
await sleepAsync(100.milliseconds) # wait for the peers to be updated
|
||||||
for k, _ in offersMap:
|
for k, _ in offersMap:
|
||||||
try:
|
try:
|
||||||
let contentInfo =
|
let contentInfo = await portalClient.portal_stateGetContent(k.to0xHex())
|
||||||
await portalClient.portal_stateRecursiveFindContent(k.to0xHex())
|
|
||||||
if contentInfo.content.len() == 0:
|
if contentInfo.content.len() == 0:
|
||||||
error "Found empty contentValue", workerId
|
error "Found empty contentValue", workerId
|
||||||
retryGossip = true
|
retryGossip = true
|
||||||
|
Loading…
x
Reference in New Issue
Block a user