fix countdown over time period (#4449)

*sigh*

fixes:
```
Error: unhandled exception:
beacon_chain/beacon_chain_db_light_client.nim(214, 12)
`period.isSupportedBySQLite`  [AssertionDefect]
```
This commit is contained in:
Jacek Sieka 2022-12-30 21:36:31 +01:00 committed by GitHub
parent 75c7195bfd
commit d854317646
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 0 deletions

View File

@ -66,6 +66,11 @@ template ethTimeUnit*(typ: type) {.dirty.} =
proc `div`*(x: uint64, y: typ): uint64 {.borrow, noSideEffect.}
proc `-`*(x: typ, y: typ): uint64 {.borrow, noSideEffect.}
iterator countdown*(a, b: typ, step: Positive = 1): typ =
# otherwise we use the signed version that breaks at the boundary
for i in countdown(distinctBase(a), distinctBase(b), step):
yield typ(i)
proc `*`*(x: typ, y: uint64): uint64 {.borrow, noSideEffect.}
proc `+=`*(x: var typ, y: typ) {.borrow, noSideEffect.}

View File

@ -47,3 +47,10 @@ suite "Beacon time":
Epoch(5).sync_committee_period
SyncCommitteePeriod(5).start_slot.sync_committee_period ==
SyncCommitteePeriod(5)
block:
var counts = 0
for i in countdown(SyncCommitteePeriod(1), SyncCommitteePeriod(0)):
counts += 1
check:
counts == 2