use `assign` for forky state assignment (#6055)

This commit is contained in:
Jacek Sieka 2024-03-19 09:50:25 +01:00 committed by GitHub
parent d4d27164f9
commit ed1ef19bf4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 8 additions and 11 deletions

View File

@ -800,18 +800,15 @@ template withEpochInfo*(
template info: untyped {.inject.} = x.altairData
body
{.push warning[ProveField]:off.}
func assign*(tgt: var ForkedHashedBeaconState, src: ForkedHashedBeaconState) =
if tgt.kind == src.kind:
withState(tgt):
template forkyTgt: untyped = forkyState
template forkySrc: untyped = src.forky(consensusFork)
assign(forkyTgt, forkySrc)
else:
# Ensure case object and discriminator get updated simultaneously, even
# with nimOldCaseObjects. This is infrequent.
tgt = src
{.pop.}
if tgt.kind != src.kind:
# Avoid temporary with ref
tgt = (ref ForkedHashedBeaconState)(kind: src.kind)[]
withState(tgt):
template forkyTgt: untyped = forkyState
template forkySrc: untyped = src.forky(consensusFork)
assign(forkyTgt, forkySrc)
template getStateField*(x: ForkedHashedBeaconState, y: untyped): untyped =
# The use of `unsafeAddr` avoids excessive copying in certain situations, e.g.,