2022-03-17 22:26:56 +00:00
|
|
|
# beacon_chain
|
2024-01-06 14:26:56 +00:00
|
|
|
# Copyright (c) 2022-2024 Status Research & Development GmbH
|
2022-03-17 22:26:56 +00:00
|
|
|
# Licensed and distributed under either of
|
|
|
|
# * MIT license (license terms in the root directory or at https://opensource.org/licenses/MIT).
|
|
|
|
# * Apache v2 license (license terms in the root directory or at https://www.apache.org/licenses/LICENSE-2.0).
|
|
|
|
# at your option. This file may not be copied, modified, or distributed except according to those terms.
|
|
|
|
|
2024-02-18 01:16:49 +00:00
|
|
|
{.push raises: [].}
|
2022-03-17 22:26:56 +00:00
|
|
|
{.used.}
|
|
|
|
|
|
|
|
import
|
|
|
|
# Status libraries
|
2023-06-19 22:43:50 +00:00
|
|
|
chronos,
|
2022-03-17 22:26:56 +00:00
|
|
|
# Beacon chain internals
|
|
|
|
../beacon_chain/consensus_object_pools/
|
|
|
|
[block_clearance, block_quarantine, blockchain_dag],
|
|
|
|
../beacon_chain/gossip_processing/light_client_processor,
|
|
|
|
../beacon_chain/spec/[beacon_time, light_client_sync, state_transition],
|
|
|
|
# Test utilities
|
|
|
|
./testutil, ./testdbutil
|
|
|
|
|
2024-02-09 23:46:51 +00:00
|
|
|
from ./testbcutil import addHeadBlock
|
|
|
|
|
2022-03-17 22:26:56 +00:00
|
|
|
suite "Light client processor" & preset():
|
2023-01-16 15:53:45 +00:00
|
|
|
const # Test config, should be long enough to cover interesting transitions
|
|
|
|
lowPeriod = 0.SyncCommitteePeriod
|
2024-06-22 08:19:51 +00:00
|
|
|
lastPeriodWithSupermajority = 4.SyncCommitteePeriod
|
|
|
|
highPeriod = 6.SyncCommitteePeriod
|
2022-03-17 22:26:56 +00:00
|
|
|
let
|
2023-01-16 15:53:45 +00:00
|
|
|
cfg = block: # Fork schedule so that each `LightClientDataFork` is covered
|
2024-04-03 14:43:43 +00:00
|
|
|
static: doAssert ConsensusFork.high == ConsensusFork.Electra
|
2022-03-17 22:26:56 +00:00
|
|
|
var res = defaultRuntimeConfig
|
2023-01-16 15:53:45 +00:00
|
|
|
res.ALTAIR_FORK_EPOCH = 1.Epoch
|
|
|
|
res.BELLATRIX_FORK_EPOCH = 2.Epoch
|
2023-03-11 20:11:33 +00:00
|
|
|
res.CAPELLA_FORK_EPOCH = (EPOCHS_PER_SYNC_COMMITTEE_PERIOD * 1).Epoch
|
|
|
|
res.DENEB_FORK_EPOCH = (EPOCHS_PER_SYNC_COMMITTEE_PERIOD * 2).Epoch
|
2024-06-22 08:19:51 +00:00
|
|
|
res.ELECTRA_FORK_EPOCH = (EPOCHS_PER_SYNC_COMMITTEE_PERIOD * 3).Epoch
|
2022-03-17 22:26:56 +00:00
|
|
|
res
|
|
|
|
|
|
|
|
const numValidators = SLOTS_PER_EPOCH
|
|
|
|
let
|
|
|
|
validatorMonitor = newClone(ValidatorMonitor.init())
|
|
|
|
dag = ChainDAGRef.init(
|
2023-03-11 20:11:33 +00:00
|
|
|
cfg, makeTestDB(numValidators, cfg = cfg), validatorMonitor, {},
|
2022-06-28 20:52:29 +00:00
|
|
|
lcDataConfig = LightClientDataConfig(
|
|
|
|
serve: true,
|
|
|
|
importMode: LightClientDataImportMode.OnlyNew))
|
2022-03-17 22:26:56 +00:00
|
|
|
quarantine = newClone(Quarantine.init())
|
2023-06-19 22:43:50 +00:00
|
|
|
rng = HmacDrbgContext.new()
|
2022-04-08 16:22:49 +00:00
|
|
|
taskpool = Taskpool.new()
|
2023-08-03 08:36:45 +00:00
|
|
|
var verifier =BatchVerifier.init(rng, taskpool)
|
2022-03-17 22:26:56 +00:00
|
|
|
|
|
|
|
var cache: StateCache
|
|
|
|
proc addBlocks(blocks: uint64, syncCommitteeRatio: float) =
|
2023-05-15 15:41:30 +00:00
|
|
|
for blck in makeTestBlocks(
|
|
|
|
dag.headState, cache, blocks.int, attested = true,
|
|
|
|
syncCommitteeRatio = syncCommitteeRatio, cfg = cfg):
|
2023-09-13 17:57:54 +00:00
|
|
|
let added = withBlck(blck):
|
|
|
|
const nilCallback = (consensusFork.OnBlockAddedCallback)(nil)
|
2023-09-21 10:49:14 +00:00
|
|
|
dag.addHeadBlock(verifier, forkyBlck, nilCallback)
|
2022-03-17 22:26:56 +00:00
|
|
|
doAssert added.isOk()
|
2023-03-02 16:13:35 +00:00
|
|
|
dag.updateHead(added[], quarantine[], [])
|
2022-03-17 22:26:56 +00:00
|
|
|
|
2022-05-23 12:02:54 +00:00
|
|
|
addBlocks(SLOTS_PER_EPOCH, 0.82)
|
2022-03-17 22:26:56 +00:00
|
|
|
let
|
2022-04-08 16:22:49 +00:00
|
|
|
genesis_validators_root = dag.genesis_validators_root
|
2022-03-17 22:26:56 +00:00
|
|
|
trustedBlockRoot = dag.head.root
|
2022-05-31 10:45:37 +00:00
|
|
|
proc getTrustedBlockRoot(): Option[Eth2Digest] =
|
|
|
|
some trustedBlockRoot
|
2022-03-17 22:26:56 +00:00
|
|
|
|
|
|
|
for period in lowPeriod .. highPeriod:
|
|
|
|
const numFilledEpochsPerPeriod = 3
|
|
|
|
let slot = ((period + 1).start_epoch - numFilledEpochsPerPeriod).start_slot
|
|
|
|
var info: ForkedEpochInfo
|
|
|
|
doAssert process_slots(cfg, dag.headState, slot,
|
|
|
|
cache, info, flags = {}).isOk()
|
|
|
|
let syncCommitteeRatio =
|
|
|
|
if period > lastPeriodWithSupermajority:
|
2022-05-23 12:02:54 +00:00
|
|
|
0.62
|
2022-03-17 22:26:56 +00:00
|
|
|
else:
|
2022-05-23 12:02:54 +00:00
|
|
|
0.82
|
2022-03-17 22:26:56 +00:00
|
|
|
addBlocks(numFilledEpochsPerPeriod * SLOTS_PER_EPOCH, syncCommitteeRatio)
|
|
|
|
|
2022-07-21 09:16:10 +00:00
|
|
|
for finalizationMode in LightClientFinalizationMode:
|
|
|
|
let testNameSuffix = " (" & $finalizationMode & ")" & preset()
|
|
|
|
|
|
|
|
setup:
|
|
|
|
var time = chronos.seconds(0)
|
|
|
|
proc getBeaconTime(): BeaconTime =
|
|
|
|
BeaconTime(ns_since_genesis: time.nanoseconds)
|
|
|
|
func setTimeToSlot(slot: Slot) =
|
|
|
|
time = chronos.seconds((slot * SECONDS_PER_SLOT).int64)
|
|
|
|
|
|
|
|
var numOnStoreInitializedCalls = 0
|
|
|
|
func onStoreInitialized() = inc numOnStoreInitializedCalls
|
|
|
|
|
2023-01-16 15:53:45 +00:00
|
|
|
let store = (ref ForkedLightClientStore)()
|
2022-07-21 09:16:10 +00:00
|
|
|
var
|
|
|
|
processor = LightClientProcessor.new(
|
|
|
|
false, "", "", cfg, genesis_validators_root, finalizationMode,
|
|
|
|
store, getBeaconTime, getTrustedBlockRoot, onStoreInitialized)
|
2022-11-10 17:40:27 +00:00
|
|
|
res: Result[bool, VerifierError]
|
2022-07-21 09:16:10 +00:00
|
|
|
|
|
|
|
test "Sync" & testNameSuffix:
|
2023-01-16 15:53:45 +00:00
|
|
|
var bootstrap = dag.getLightClientBootstrap(trustedBlockRoot)
|
|
|
|
check bootstrap.kind > LightClientDataFork.None
|
|
|
|
withForkyBootstrap(bootstrap):
|
|
|
|
when lcDataFork > LightClientDataFork.None:
|
|
|
|
setTimeToSlot(forkyBootstrap.header.beacon.slot)
|
2022-03-17 22:26:56 +00:00
|
|
|
res = processor[].storeObject(
|
2023-01-12 17:11:38 +00:00
|
|
|
MsgSource.gossip, getBeaconTime(), bootstrap)
|
2022-03-17 22:26:56 +00:00
|
|
|
check:
|
|
|
|
res.isOk
|
2022-07-21 09:16:10 +00:00
|
|
|
numOnStoreInitializedCalls == 1
|
2023-01-16 15:53:45 +00:00
|
|
|
store[].kind > LightClientDataFork.None
|
2022-03-17 22:26:56 +00:00
|
|
|
|
2022-07-21 09:16:10 +00:00
|
|
|
# Reduce stack size by making this a `proc`
|
|
|
|
proc applyPeriodWithSupermajority(period: SyncCommitteePeriod) =
|
|
|
|
let update = dag.getLightClientUpdateForPeriod(period)
|
2023-01-16 15:53:45 +00:00
|
|
|
check update.kind > LightClientDataFork.None
|
|
|
|
withForkyUpdate(update):
|
|
|
|
when lcDataFork > LightClientDataFork.None:
|
|
|
|
setTimeToSlot(forkyUpdate.signature_slot)
|
2022-03-17 22:26:56 +00:00
|
|
|
res = processor[].storeObject(
|
2023-01-12 17:11:38 +00:00
|
|
|
MsgSource.gossip, getBeaconTime(), update)
|
2023-01-16 15:53:45 +00:00
|
|
|
check update.kind <= store[].kind
|
|
|
|
withForkyStore(store[]):
|
|
|
|
when lcDataFork > LightClientDataFork.None:
|
|
|
|
bootstrap.migrateToDataFork(lcDataFork)
|
|
|
|
template forkyBootstrap: untyped = bootstrap.forky(lcDataFork)
|
|
|
|
let upgraded = update.migratingToDataFork(lcDataFork)
|
|
|
|
template forkyUpdate: untyped = upgraded.forky(lcDataFork)
|
|
|
|
check:
|
|
|
|
res.isOk
|
|
|
|
if forkyUpdate.finalized_header.beacon.slot >
|
|
|
|
forkyBootstrap.header.beacon.slot:
|
|
|
|
forkyStore.finalized_header == forkyUpdate.finalized_header
|
|
|
|
else:
|
|
|
|
forkyStore.finalized_header == forkyBootstrap.header
|
|
|
|
forkyStore.optimistic_header == forkyUpdate.attested_header
|
2022-03-17 22:26:56 +00:00
|
|
|
|
2022-07-21 09:16:10 +00:00
|
|
|
for period in lowPeriod .. lastPeriodWithSupermajority:
|
|
|
|
applyPeriodWithSupermajority(period)
|
|
|
|
|
|
|
|
# Reduce stack size by making this a `proc`
|
2023-01-19 22:53:37 +00:00
|
|
|
proc applyPeriodWithoutSupermajority(
|
|
|
|
period: SyncCommitteePeriod, update: ref ForkedLightClientUpdate) =
|
2022-07-21 09:16:10 +00:00
|
|
|
for i in 0 ..< 2:
|
2024-06-21 16:36:54 +00:00
|
|
|
# Reduce stack size by making this a `proc`
|
|
|
|
proc applyInitial(update: ref ForkedLightClientUpdate) =
|
|
|
|
res = processor[].storeObject(
|
|
|
|
MsgSource.gossip, getBeaconTime(), update[])
|
|
|
|
check update[].kind <= store[].kind
|
2022-07-21 09:16:10 +00:00
|
|
|
if finalizationMode == LightClientFinalizationMode.Optimistic or
|
2024-06-21 16:36:54 +00:00
|
|
|
period == lastPeriodWithSupermajority + 1:
|
|
|
|
if finalizationMode == LightClientFinalizationMode.Optimistic or
|
|
|
|
i == 0:
|
|
|
|
withForkyStore(store[]):
|
|
|
|
when lcDataFork > LightClientDataFork.None:
|
|
|
|
let upgraded = newClone(
|
|
|
|
update[].migratingToDataFork(lcDataFork))
|
|
|
|
template forkyUpdate: untyped = upgraded[].forky(lcDataFork)
|
|
|
|
check:
|
|
|
|
res.isOk
|
|
|
|
forkyStore.best_valid_update.isSome
|
|
|
|
forkyStore.best_valid_update.get.matches(forkyUpdate)
|
|
|
|
else:
|
|
|
|
withForkyStore(store[]):
|
|
|
|
when lcDataFork > LightClientDataFork.None:
|
|
|
|
let upgraded = newClone(
|
|
|
|
update[].migratingToDataFork(lcDataFork))
|
|
|
|
template forkyUpdate: untyped = upgraded[].forky(lcDataFork)
|
|
|
|
check:
|
|
|
|
res.isErr
|
|
|
|
res.error == VerifierError.Duplicate
|
|
|
|
forkyStore.best_valid_update.isSome
|
|
|
|
forkyStore.best_valid_update.get.matches(forkyUpdate)
|
2022-07-21 09:16:10 +00:00
|
|
|
else:
|
2023-01-16 15:53:45 +00:00
|
|
|
withForkyStore(store[]):
|
|
|
|
when lcDataFork > LightClientDataFork.None:
|
2023-01-18 14:32:57 +00:00
|
|
|
let upgraded = newClone(
|
|
|
|
update[].migratingToDataFork(lcDataFork))
|
|
|
|
template forkyUpdate: untyped = upgraded[].forky(lcDataFork)
|
2023-01-16 15:53:45 +00:00
|
|
|
check:
|
|
|
|
res.isErr
|
2024-06-21 16:36:54 +00:00
|
|
|
res.error == VerifierError.MissingParent
|
2023-01-16 15:53:45 +00:00
|
|
|
forkyStore.best_valid_update.isSome
|
2024-06-21 16:36:54 +00:00
|
|
|
not forkyStore.best_valid_update.get.matches(forkyUpdate)
|
|
|
|
|
|
|
|
applyInitial(update)
|
2022-07-21 09:16:10 +00:00
|
|
|
|
2023-01-19 22:53:37 +00:00
|
|
|
# Reduce stack size by making this a `proc`
|
|
|
|
proc applyDuplicate(update: ref ForkedLightClientUpdate) =
|
2022-07-21 09:16:10 +00:00
|
|
|
res = processor[].storeObject(
|
2023-01-18 14:32:57 +00:00
|
|
|
MsgSource.gossip, getBeaconTime(), update[])
|
|
|
|
check update[].kind <= store[].kind
|
2022-07-21 09:16:10 +00:00
|
|
|
if finalizationMode == LightClientFinalizationMode.Optimistic or
|
|
|
|
period == lastPeriodWithSupermajority + 1:
|
2023-01-16 15:53:45 +00:00
|
|
|
withForkyStore(store[]):
|
|
|
|
when lcDataFork > LightClientDataFork.None:
|
2023-01-18 14:32:57 +00:00
|
|
|
let upgraded = newClone(
|
|
|
|
update[].migratingToDataFork(lcDataFork))
|
|
|
|
template forkyUpdate: untyped = upgraded[].forky(lcDataFork)
|
2023-01-16 15:53:45 +00:00
|
|
|
check:
|
|
|
|
res.isErr
|
|
|
|
res.error == VerifierError.Duplicate
|
|
|
|
forkyStore.best_valid_update.isSome
|
|
|
|
forkyStore.best_valid_update.get.matches(forkyUpdate)
|
2022-07-21 09:16:10 +00:00
|
|
|
else:
|
2023-01-16 15:53:45 +00:00
|
|
|
withForkyStore(store[]):
|
|
|
|
when lcDataFork > LightClientDataFork.None:
|
2023-01-18 14:32:57 +00:00
|
|
|
let upgraded = newClone(
|
|
|
|
update[].migratingToDataFork(lcDataFork))
|
|
|
|
template forkyUpdate: untyped = upgraded[].forky(lcDataFork)
|
2023-01-16 15:53:45 +00:00
|
|
|
check:
|
|
|
|
res.isErr
|
|
|
|
res.error == VerifierError.MissingParent
|
|
|
|
forkyStore.best_valid_update.isSome
|
|
|
|
not forkyStore.best_valid_update.get.matches(forkyUpdate)
|
2022-07-21 09:16:10 +00:00
|
|
|
|
2023-01-19 22:53:37 +00:00
|
|
|
applyDuplicate(update)
|
2022-07-21 09:16:10 +00:00
|
|
|
time += chronos.minutes(15)
|
|
|
|
for _ in 0 ..< 150:
|
2023-01-19 22:53:37 +00:00
|
|
|
applyDuplicate(update)
|
2022-07-21 09:16:10 +00:00
|
|
|
time += chronos.seconds(5)
|
|
|
|
time += chronos.minutes(15)
|
2022-03-17 22:26:56 +00:00
|
|
|
|
2022-07-21 09:16:10 +00:00
|
|
|
res = processor[].storeObject(
|
2023-01-18 14:32:57 +00:00
|
|
|
MsgSource.gossip, getBeaconTime(), update[])
|
|
|
|
check update[].kind <= store[].kind
|
2022-07-21 09:16:10 +00:00
|
|
|
if finalizationMode == LightClientFinalizationMode.Optimistic:
|
2023-01-16 15:53:45 +00:00
|
|
|
withForkyStore(store[]):
|
|
|
|
when lcDataFork > LightClientDataFork.None:
|
2023-01-18 14:32:57 +00:00
|
|
|
let upgraded = newClone(
|
|
|
|
update[].migratingToDataFork(lcDataFork))
|
|
|
|
template forkyUpdate: untyped = upgraded[].forky(lcDataFork)
|
2023-01-16 15:53:45 +00:00
|
|
|
check:
|
|
|
|
res.isErr
|
|
|
|
res.error == VerifierError.Duplicate
|
|
|
|
forkyStore.best_valid_update.isNone
|
|
|
|
if forkyStore.finalized_header == forkyUpdate.attested_header:
|
|
|
|
break
|
|
|
|
check forkyStore.finalized_header ==
|
|
|
|
forkyUpdate.finalized_header
|
2022-07-21 09:16:10 +00:00
|
|
|
elif period == lastPeriodWithSupermajority + 1:
|
2023-01-16 15:53:45 +00:00
|
|
|
withForkyStore(store[]):
|
|
|
|
when lcDataFork > LightClientDataFork.None:
|
2023-01-18 14:32:57 +00:00
|
|
|
let upgraded = newClone(
|
|
|
|
update[].migratingToDataFork(lcDataFork))
|
|
|
|
template forkyUpdate: untyped = upgraded[].forky(lcDataFork)
|
2023-01-16 15:53:45 +00:00
|
|
|
check:
|
|
|
|
res.isErr
|
|
|
|
res.error == VerifierError.Duplicate
|
|
|
|
forkyStore.best_valid_update.isSome
|
|
|
|
forkyStore.best_valid_update.get.matches(forkyUpdate)
|
2022-07-21 09:16:10 +00:00
|
|
|
else:
|
2023-01-16 15:53:45 +00:00
|
|
|
withForkyStore(store[]):
|
|
|
|
when lcDataFork > LightClientDataFork.None:
|
2023-01-18 14:32:57 +00:00
|
|
|
let upgraded = newClone(
|
|
|
|
update[].migratingToDataFork(lcDataFork))
|
|
|
|
template forkyUpdate: untyped = upgraded[].forky(lcDataFork)
|
2023-01-16 15:53:45 +00:00
|
|
|
check:
|
|
|
|
res.isErr
|
|
|
|
res.error == VerifierError.MissingParent
|
|
|
|
forkyStore.best_valid_update.isSome
|
|
|
|
not forkyStore.best_valid_update.get.matches(forkyUpdate)
|
2023-01-19 22:53:37 +00:00
|
|
|
|
|
|
|
for period in lastPeriodWithSupermajority + 1 .. highPeriod:
|
|
|
|
let update = newClone(dag.getLightClientUpdateForPeriod(period))
|
|
|
|
check update[].kind > LightClientDataFork.None
|
|
|
|
withForkyUpdate(update[]):
|
|
|
|
when lcDataFork > LightClientDataFork.None:
|
|
|
|
setTimeToSlot(forkyUpdate.signature_slot)
|
|
|
|
|
|
|
|
applyPeriodWithoutSupermajority(period, update)
|
|
|
|
|
2022-07-21 09:16:10 +00:00
|
|
|
if finalizationMode == LightClientFinalizationMode.Optimistic:
|
2023-01-16 15:53:45 +00:00
|
|
|
withForkyStore(store[]):
|
|
|
|
when lcDataFork > LightClientDataFork.None:
|
2023-01-18 14:32:57 +00:00
|
|
|
let upgraded = newClone(
|
|
|
|
update[].migratingToDataFork(lcDataFork))
|
|
|
|
template forkyUpdate: untyped = upgraded[].forky(lcDataFork)
|
2023-01-16 15:53:45 +00:00
|
|
|
check forkyStore.finalized_header == forkyUpdate.attested_header
|
2022-07-21 09:16:10 +00:00
|
|
|
else:
|
2023-01-16 15:53:45 +00:00
|
|
|
withForkyStore(store[]):
|
|
|
|
when lcDataFork > LightClientDataFork.None:
|
2023-01-18 14:32:57 +00:00
|
|
|
let upgraded = newClone(
|
|
|
|
update[].migratingToDataFork(lcDataFork))
|
|
|
|
template forkyUpdate: untyped = upgraded[].forky(lcDataFork)
|
2023-01-16 15:53:45 +00:00
|
|
|
check forkyStore.finalized_header != forkyUpdate.attested_header
|
2022-07-21 09:16:10 +00:00
|
|
|
|
2023-01-16 15:53:45 +00:00
|
|
|
var oldFinalized {.noinit.}: ForkedLightClientHeader
|
|
|
|
withForkyStore(store[]):
|
|
|
|
when lcDataFork > LightClientDataFork.None:
|
2023-10-04 16:11:45 +00:00
|
|
|
oldFinalized = ForkedLightClientHeader.init(
|
|
|
|
forkyStore.finalized_header)
|
2023-01-16 15:53:45 +00:00
|
|
|
else: raiseAssert "Unreachable"
|
|
|
|
let finalityUpdate = dag.getLightClientFinalityUpdate()
|
|
|
|
check finalityUpdate.kind > LightClientDataFork.None
|
|
|
|
withForkyFinalityUpdate(finalityUpdate):
|
|
|
|
when lcDataFork > LightClientDataFork.None:
|
|
|
|
setTimeToSlot(forkyFinalityUpdate.signature_slot)
|
2022-07-21 09:16:10 +00:00
|
|
|
res = processor[].storeObject(
|
2023-01-12 17:11:38 +00:00
|
|
|
MsgSource.gossip, getBeaconTime(), finalityUpdate)
|
2023-01-16 15:53:45 +00:00
|
|
|
check finalityUpdate.kind <= store[].kind
|
2022-07-21 09:16:10 +00:00
|
|
|
if res.isOk:
|
2023-01-16 15:53:45 +00:00
|
|
|
withForkyStore(store[]):
|
|
|
|
when lcDataFork > LightClientDataFork.None:
|
|
|
|
oldFinalized.migrateToDataFork(lcDataFork)
|
|
|
|
template forkyOldFinalized: untyped = oldFinalized.forky(lcDataFork)
|
|
|
|
let upgraded = finalityUpdate.migratingToDataFork(lcDataFork)
|
|
|
|
template forkyUpdate: untyped = upgraded.forky(lcDataFork)
|
|
|
|
check:
|
|
|
|
finalizationMode == LightClientFinalizationMode.Optimistic
|
|
|
|
forkyStore.finalized_header == forkyOldFinalized
|
|
|
|
forkyStore.best_valid_update.isSome
|
|
|
|
forkyStore.best_valid_update.get.matches(forkyUpdate)
|
|
|
|
forkyStore.optimistic_header == forkyUpdate.attested_header
|
2022-07-21 09:16:10 +00:00
|
|
|
elif finalizationMode == LightClientFinalizationMode.Optimistic:
|
2022-11-10 17:40:27 +00:00
|
|
|
check res.error == VerifierError.Duplicate
|
2022-07-21 09:16:10 +00:00
|
|
|
else:
|
2022-11-10 17:40:27 +00:00
|
|
|
check res.error == VerifierError.MissingParent
|
2022-07-21 09:16:10 +00:00
|
|
|
check numOnStoreInitializedCalls == 1
|
|
|
|
|
|
|
|
test "Invalid bootstrap" & testNameSuffix:
|
|
|
|
var bootstrap = dag.getLightClientBootstrap(trustedBlockRoot)
|
2023-01-16 15:53:45 +00:00
|
|
|
check bootstrap.kind > LightClientDataFork.None
|
2023-01-12 17:11:38 +00:00
|
|
|
withForkyBootstrap(bootstrap):
|
2023-01-14 21:19:50 +00:00
|
|
|
when lcDataFork > LightClientDataFork.None:
|
2023-01-13 15:46:35 +00:00
|
|
|
forkyBootstrap.header.beacon.slot.inc()
|
2023-01-16 15:53:45 +00:00
|
|
|
setTimeToSlot(forkyBootstrap.header.beacon.slot)
|
2022-07-21 09:16:10 +00:00
|
|
|
res = processor[].storeObject(
|
2023-01-12 17:11:38 +00:00
|
|
|
MsgSource.gossip, getBeaconTime(), bootstrap)
|
2022-07-21 09:16:10 +00:00
|
|
|
check:
|
|
|
|
res.isErr
|
2022-11-10 17:40:27 +00:00
|
|
|
res.error == VerifierError.Invalid
|
2022-07-21 09:16:10 +00:00
|
|
|
numOnStoreInitializedCalls == 0
|
|
|
|
|
|
|
|
test "Duplicate bootstrap" & testNameSuffix:
|
|
|
|
let bootstrap = dag.getLightClientBootstrap(trustedBlockRoot)
|
2023-01-16 15:53:45 +00:00
|
|
|
check bootstrap.kind > LightClientDataFork.None
|
|
|
|
withForkyBootstrap(bootstrap):
|
|
|
|
when lcDataFork > LightClientDataFork.None:
|
|
|
|
setTimeToSlot(forkyBootstrap.header.beacon.slot)
|
2022-07-21 09:16:10 +00:00
|
|
|
res = processor[].storeObject(
|
2023-01-12 17:11:38 +00:00
|
|
|
MsgSource.gossip, getBeaconTime(), bootstrap)
|
2022-07-21 09:16:10 +00:00
|
|
|
check:
|
|
|
|
res.isOk
|
|
|
|
numOnStoreInitializedCalls == 1
|
|
|
|
res = processor[].storeObject(
|
2023-01-12 17:11:38 +00:00
|
|
|
MsgSource.gossip, getBeaconTime(), bootstrap)
|
2022-07-21 09:16:10 +00:00
|
|
|
check:
|
|
|
|
res.isErr
|
2022-11-10 17:40:27 +00:00
|
|
|
res.error == VerifierError.Duplicate
|
2022-07-21 09:16:10 +00:00
|
|
|
numOnStoreInitializedCalls == 1
|
|
|
|
|
|
|
|
test "Missing bootstrap (update)" & testNameSuffix:
|
|
|
|
let update = dag.getLightClientUpdateForPeriod(lowPeriod)
|
2023-01-16 15:53:45 +00:00
|
|
|
check update.kind > LightClientDataFork.None
|
|
|
|
withForkyUpdate(update):
|
|
|
|
when lcDataFork > LightClientDataFork.None:
|
|
|
|
setTimeToSlot(forkyUpdate.signature_slot)
|
2022-07-21 09:16:10 +00:00
|
|
|
res = processor[].storeObject(
|
2023-01-12 17:11:38 +00:00
|
|
|
MsgSource.gossip, getBeaconTime(), update)
|
2022-07-21 09:16:10 +00:00
|
|
|
check:
|
|
|
|
res.isErr
|
2022-11-10 17:40:27 +00:00
|
|
|
res.error == VerifierError.MissingParent
|
2022-07-21 09:16:10 +00:00
|
|
|
numOnStoreInitializedCalls == 0
|
|
|
|
|
|
|
|
test "Missing bootstrap (finality update)" & testNameSuffix:
|
|
|
|
let finalityUpdate = dag.getLightClientFinalityUpdate()
|
2023-01-16 15:53:45 +00:00
|
|
|
check finalityUpdate.kind > LightClientDataFork.None
|
|
|
|
withForkyFinalityUpdate(finalityUpdate):
|
|
|
|
when lcDataFork > LightClientDataFork.None:
|
|
|
|
setTimeToSlot(forkyFinalityUpdate.signature_slot)
|
2022-07-21 09:16:10 +00:00
|
|
|
res = processor[].storeObject(
|
2023-01-12 17:11:38 +00:00
|
|
|
MsgSource.gossip, getBeaconTime(), finalityUpdate)
|
2022-07-21 09:16:10 +00:00
|
|
|
check:
|
|
|
|
res.isErr
|
2022-11-10 17:40:27 +00:00
|
|
|
res.error == VerifierError.MissingParent
|
2022-07-21 09:16:10 +00:00
|
|
|
numOnStoreInitializedCalls == 0
|
|
|
|
|
|
|
|
test "Missing bootstrap (optimistic update)" & testNameSuffix:
|
|
|
|
let optimisticUpdate = dag.getLightClientOptimisticUpdate()
|
2023-01-16 15:53:45 +00:00
|
|
|
check optimisticUpdate.kind > LightClientDataFork.None
|
|
|
|
withForkyOptimisticUpdate(optimisticUpdate):
|
|
|
|
when lcDataFork > LightClientDataFork.None:
|
|
|
|
setTimeToSlot(forkyOptimisticUpdate.signature_slot)
|
2022-07-21 09:16:10 +00:00
|
|
|
res = processor[].storeObject(
|
2023-01-12 17:11:38 +00:00
|
|
|
MsgSource.gossip, getBeaconTime(), optimisticUpdate)
|
2022-03-17 22:26:56 +00:00
|
|
|
check:
|
2022-07-21 09:16:10 +00:00
|
|
|
res.isErr
|
2022-11-10 17:40:27 +00:00
|
|
|
res.error == VerifierError.MissingParent
|
2024-06-21 16:36:54 +00:00
|
|
|
numOnStoreInitializedCalls == 0
|