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