Add the epoch to the HistoricalSummariesKey (#2179)
This commit is contained in:
parent
1b8f2b0ea5
commit
2e01878afe
|
@ -60,7 +60,8 @@ type
|
||||||
LightClientOptimisticUpdateKey* = object
|
LightClientOptimisticUpdateKey* = object
|
||||||
optimisticSlot*: uint64 ## signature_slot of the update
|
optimisticSlot*: uint64 ## signature_slot of the update
|
||||||
|
|
||||||
HistoricalSummariesKey* = uint8
|
HistoricalSummariesKey* = object
|
||||||
|
epoch*: uint64
|
||||||
|
|
||||||
ContentKey* = object
|
ContentKey* = object
|
||||||
case contentType*: ContentType
|
case contentType*: ContentType
|
||||||
|
@ -252,5 +253,8 @@ func optimisticUpdateContentKey*(optimisticSlot: uint64): ContentKey =
|
||||||
LightClientOptimisticUpdateKey(optimisticSlot: optimisticSlot),
|
LightClientOptimisticUpdateKey(optimisticSlot: optimisticSlot),
|
||||||
)
|
)
|
||||||
|
|
||||||
func historicalSummariesContentKey*(): ContentKey =
|
func historicalSummariesContentKey*(epoch: uint64): ContentKey =
|
||||||
ContentKey(contentType: historicalSummaries, historicalSummariesKey: 0)
|
ContentKey(
|
||||||
|
contentType: historicalSummaries,
|
||||||
|
historicalSummariesKey: HistoricalSummariesKey(epoch: epoch),
|
||||||
|
)
|
||||||
|
|
|
@ -160,11 +160,11 @@ proc getLightClientOptimisticUpdate*(
|
||||||
return Opt.some(decodingResult.value())
|
return Opt.some(decodingResult.value())
|
||||||
|
|
||||||
proc getHistoricalSummaries*(
|
proc getHistoricalSummaries*(
|
||||||
n: BeaconNetwork
|
n: BeaconNetwork, epoch: uint64
|
||||||
): Future[results.Opt[HistoricalSummaries]] {.async.} =
|
): Future[results.Opt[HistoricalSummaries]] {.async.} =
|
||||||
# Note: when taken from the db, it does not need to verify the proof.
|
# Note: when taken from the db, it does not need to verify the proof.
|
||||||
let
|
let
|
||||||
contentKey = historicalSummariesContentKey()
|
contentKey = historicalSummariesContentKey(epoch)
|
||||||
content = ?await n.getContent(contentKey)
|
content = ?await n.getContent(contentKey)
|
||||||
|
|
||||||
summariesWithProof = decodeSsz(content, HistoricalSummariesWithProof).valueOr:
|
summariesWithProof = decodeSsz(content, HistoricalSummariesWithProof).valueOr:
|
||||||
|
|
|
@ -238,13 +238,13 @@ procSuite "Beacon Content Network":
|
||||||
(await lcNode2.portalProtocol().ping(lcNode1.localNode())).isOk()
|
(await lcNode2.portalProtocol().ping(lcNode1.localNode())).isOk()
|
||||||
|
|
||||||
let
|
let
|
||||||
contentKeyEncoded = historicalSummariesContentKey().encode()
|
contentKeyEncoded = historicalSummariesContentKey(0).encode()
|
||||||
contentId = toContentId(contentKeyEncoded)
|
contentId = toContentId(contentKeyEncoded)
|
||||||
|
|
||||||
lcNode2.portalProtocol().storeContent(contentKeyEncoded, contentId, content)
|
lcNode2.portalProtocol().storeContent(contentKeyEncoded, contentId, content)
|
||||||
|
|
||||||
block:
|
block:
|
||||||
let res = await lcNode1.beaconNetwork.getHistoricalSummaries()
|
let res = await lcNode1.beaconNetwork.getHistoricalSummaries(0)
|
||||||
# Should fail as it cannot validate
|
# Should fail as it cannot validate
|
||||||
check res.isErr()
|
check res.isErr()
|
||||||
|
|
||||||
|
@ -269,7 +269,7 @@ procSuite "Beacon Content Network":
|
||||||
lcNode1.portalProtocol().storeContent(contentKeyEncoded, contentId, content)
|
lcNode1.portalProtocol().storeContent(contentKeyEncoded, contentId, content)
|
||||||
|
|
||||||
block:
|
block:
|
||||||
let res = await lcNode1.beaconNetwork.getHistoricalSummaries()
|
let res = await lcNode1.beaconNetwork.getHistoricalSummaries(0)
|
||||||
check:
|
check:
|
||||||
res.isOk()
|
res.isOk()
|
||||||
withState(state[]):
|
withState(state[]):
|
||||||
|
|
Loading…
Reference in New Issue