avoid `ProveField` warning in `network_metadata` (#5066)

Before assigning to `genesisData` or returning `cfg`, have to check that
metadata is not `incompatible` to avoid `ProveField` warning.
The way how we use it was already correct (`incompatible` unreachable).
Use `case` syntax to silence the warning, and add comments referring to
the existing checks that make `incompatible` unreachable.
This commit is contained in:
Etan Kissling 2023-06-16 14:15:42 +02:00 committed by GitHub
parent e9262ab6a3
commit 8eec6ab221
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 25 additions and 12 deletions

View File

@ -295,7 +295,11 @@ proc getMetadataForNetwork*(
template withGenesis(metadata, genesis: untyped): untyped = template withGenesis(metadata, genesis: untyped): untyped =
when incbinEnabled: when incbinEnabled:
var tmp = metadata var tmp = metadata
assign(tmp.genesisData, genesis.toOpenArray(0, `genesis Size` - 1)) case tmp.incompatible
of false:
assign(tmp.genesisData, genesis.toOpenArray(0, `genesis Size` - 1))
of true:
raiseAssert "Unreachable" # `loadCompileTimeNetworkMetadata`
tmp tmp
else: else:
metadata metadata
@ -343,15 +347,24 @@ proc getRuntimeConfig*(
## quite appropriate in such as low-level function. The "assume mainnet by ## quite appropriate in such as low-level function. The "assume mainnet by
## default" behavior is something that should be handled closer to the `conf` ## default" behavior is something that should be handled closer to the `conf`
## layer. ## layer.
if eth2Network.isSome: let metadata =
return getMetadataForNetwork(eth2Network.get).cfg if eth2Network.isSome:
getMetadataForNetwork(eth2Network.get)
else:
when const_preset == "mainnet":
mainnetMetadata
elif const_preset == "gnosis":
gnosisMetadata
else:
# This is a non-standard build (i.e. minimal), and the function was
# most likely executed in a test. The best we can do is return a fully
# default config:
return defaultRuntimeConfig
when const_preset == "mainnet": return
mainnetMetadata.cfg case metadata.incompatible
elif const_preset == "gnosis": of false:
gnosisMetadata.cfg metadata.cfg
else: of true:
# This is a non-standard build (i.e. minimal), and the function was most # `getMetadataForNetwork` / `loadCompileTimeNetworkMetadata`
# likely executed in a test. The best we can do is return a fully default raiseAssert "Unreachable"
# config:
defaultRuntimeConfig