mirror of
https://github.com/status-im/nimbus-eth1.git
synced 2025-01-13 05:44:40 +00:00
Remove direct local content lookup from PortalRpcClient. (#2857)
This commit is contained in:
parent
508ce79cdd
commit
4b63cdeaac
@ -48,15 +48,6 @@ func toPortalRpcError(e: ref CatchableError): PortalRpcError =
|
||||
else:
|
||||
raiseAssert(e.msg)
|
||||
|
||||
proc portal_historyLocalContent(
|
||||
client: PortalRpcClient, contentKey: string
|
||||
): Future[Result[string, PortalRpcError]] {.async: (raises: []).} =
|
||||
try:
|
||||
let content = await RpcClient(client).portal_historyLocalContent(contentKey)
|
||||
ok(content)
|
||||
except CatchableError as e:
|
||||
err(e.toPortalRpcError())
|
||||
|
||||
proc portal_historyGetContent(
|
||||
client: PortalRpcClient, contentKey: string
|
||||
): Future[Result[string, PortalRpcError]] {.async: (raises: []).} =
|
||||
@ -78,17 +69,6 @@ template valueOrErr[T](res: Result[T, string], error: PortalRpcError): auto =
|
||||
else:
|
||||
err(error)
|
||||
|
||||
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.portal_historyLocalContent(contentKey)).valueOr:
|
||||
if error == ContentNotFound:
|
||||
?await client.portal_historyGetContent(contentKey)
|
||||
else:
|
||||
return err(error)
|
||||
ok(content)
|
||||
|
||||
proc historyGetBlockHeader*(
|
||||
client: PortalRpcClient, blockHash: Hash32, validateContent = true
|
||||
): Future[Result[Header, PortalRpcError]] {.async: (raises: []).} =
|
||||
@ -104,7 +84,7 @@ proc historyGetBlockHeader*(
|
||||
|
||||
let
|
||||
contentKey = blockHeaderContentKey(blockHash).encode().asSeq().to0xHex()
|
||||
content = ?await client.historyGetContent(contentKey)
|
||||
content = ?await client.portal_historyGetContent(contentKey)
|
||||
headerWithProof = decodeSsz(content.toBytes(), BlockHeaderWithProof).valueOr:
|
||||
return err(InvalidContentValue)
|
||||
headerBytes = headerWithProof.header.asSeq()
|
||||
@ -124,7 +104,7 @@ proc historyGetBlockBody*(
|
||||
|
||||
let
|
||||
contentKey = blockBodyContentKey(blockHash).encode().asSeq().to0xHex()
|
||||
content = ?await client.historyGetContent(contentKey)
|
||||
content = ?await client.portal_historyGetContent(contentKey)
|
||||
|
||||
if validateContent:
|
||||
let blockHeader = ?await client.historyGetBlockHeader(blockHash)
|
||||
@ -144,7 +124,7 @@ proc historyGetReceipts*(
|
||||
|
||||
let
|
||||
contentKey = receiptsContentKey(blockHash).encode().asSeq().to0xHex()
|
||||
content = ?await client.historyGetContent(contentKey)
|
||||
content = ?await client.portal_historyGetContent(contentKey)
|
||||
|
||||
if validateContent:
|
||||
let blockHeader = ?await client.historyGetBlockHeader(blockHash)
|
||||
|
@ -81,9 +81,13 @@ proc installPortalHistoryApiHandlers*(rpcServer: RpcServer, p: PortalProtocol) =
|
||||
key = ContentKeyByteList.init(hexToSeqByte(contentKey))
|
||||
contentId = p.toContentId(key).valueOr:
|
||||
raise invalidKeyErr()
|
||||
maybeContent = p.getLocalContent(key, contentId)
|
||||
|
||||
contentResult = (await p.contentLookup(key, contentId)).valueOr:
|
||||
raise contentNotFoundErr()
|
||||
if maybeContent.isSome():
|
||||
return ContentInfo(content: maybeContent.get().to0xHex(), utpTransfer: false)
|
||||
|
||||
let contentResult = (await p.contentLookup(key, contentId)).valueOr:
|
||||
raise contentNotFoundErr()
|
||||
|
||||
return ContentInfo(
|
||||
content: contentResult.content.to0xHex(), utpTransfer: contentResult.utpTransfer
|
||||
@ -96,8 +100,12 @@ proc installPortalHistoryApiHandlers*(rpcServer: RpcServer, p: PortalProtocol) =
|
||||
key = ContentKeyByteList.init(hexToSeqByte(contentKey))
|
||||
contentId = p.toContentId(key).valueOr:
|
||||
raise invalidKeyErr()
|
||||
maybeContent = p.getLocalContent(key, contentId)
|
||||
|
||||
res = await p.traceContentLookup(key, contentId)
|
||||
if maybeContent.isSome():
|
||||
return TraceContentLookupResult(content: maybeContent, utpTransfer: false)
|
||||
|
||||
let res = await p.traceContentLookup(key, contentId)
|
||||
|
||||
# TODO: Might want to restructure the lookup result here. Potentially doing
|
||||
# the json conversion in this module.
|
||||
|
Loading…
x
Reference in New Issue
Block a user