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