use safer case object transitions (#4379)

This commit is contained in:
tersec 2022-12-01 12:36:44 +00:00 committed by GitHub
parent 7c783644a2
commit c0cacd2561
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 6 additions and 2 deletions

View File

@ -438,14 +438,18 @@ template withEpochInfo*(x: ForkedEpochInfo, body: untyped): untyped =
template withEpochInfo*(
state: phase0.BeaconState, x: var ForkedEpochInfo, body: untyped): untyped =
x.kind = EpochInfoFork.Phase0
if x.kind != EpochInfoFork.Phase0:
# Rare, should never happen even, so efficiency a non-issue
x = ForkedEpochInfo(kind: EpochInfoFork.Phase0)
template info: untyped {.inject.} = x.phase0Data
body
template withEpochInfo*(
state: altair.BeaconState | bellatrix.BeaconState | capella.BeaconState,
x: var ForkedEpochInfo, body: untyped): untyped =
x.kind = EpochInfoFork.Altair
if x.kind != EpochInfoFork.Altair:
# Rare, so efficiency not critical
x = ForkedEpochInfo(kind: EpochInfoFork.Altair)
template info: untyped {.inject.} = x.altairData
body