Add the epoch to the HistoricalSummariesKey (#2179)

This commit is contained in:
Kim De Mey 2024-05-13 18:49:21 +02:00 committed by GitHub
parent 1b8f2b0ea5
commit 2e01878afe
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 12 additions and 8 deletions

View File

@ -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),
)

View File

@ -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:

View File

@ -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[]):