From a017e4a8179a12ab12be31d47aa5f0bc72d28692 Mon Sep 17 00:00:00 2001 From: Jacek Sieka Date: Wed, 6 Oct 2021 18:47:11 +0300 Subject: [PATCH] fix forkDigest --- beacon_chain/networking/eth2_network.nim | 4 ++-- beacon_chain/spec/forks.nim | 22 ++++++++++------------ 2 files changed, 12 insertions(+), 14 deletions(-) diff --git a/beacon_chain/networking/eth2_network.nim b/beacon_chain/networking/eth2_network.nim index 6bc511ffd..17d47640f 100644 --- a/beacon_chain/networking/eth2_network.nim +++ b/beacon_chain/networking/eth2_network.nim @@ -1857,9 +1857,9 @@ proc createEth2Node*(rng: ref BrHmacDrbgContext, # that are different from the host address (this is relevant when we # are running behind a NAT). var switch = newBeaconSwitch(config, netKeys.seckey, hostAddress, rng) - + let altairPrefix = $forkDigests.altair func msgIdProvider(m: messages.Message): seq[byte] = - let topic = getAltairTopic(m, forkDigests.altairTopicPrefix) + let topic = getAltairTopic(m, altairPrefix) try: let decoded = snappy.decode(m.data, GOSSIP_MAX_SIZE) gossipId(decoded, topic, true) diff --git a/beacon_chain/spec/forks.nim b/beacon_chain/spec/forks.nim index 6c270614e..7b63d7c5a 100644 --- a/beacon_chain/spec/forks.nim +++ b/beacon_chain/spec/forks.nim @@ -68,11 +68,10 @@ type of BeaconBlockFork.Merge: mergeBlock*: merge.TrustedSignedBeaconBlock - ForkDigests* = object + ForkDigests* {.requiresInit.} = object phase0*: ForkDigest altair*: ForkDigest - merge*: ForkDigest # TODO where does this get filled - altairTopicPrefix*: string # Used by isAltairTopic + merge*: ForkDigest ForkDigestsRef* = ref ForkDigests @@ -306,15 +305,14 @@ func get_previous_epoch*(stateData: ForkedHashedBeaconState): Epoch = func init*(T: type ForkDigests, cfg: RuntimeConfig, genesisValidatorsRoot: Eth2Digest): T = - let altairForkDigest = compute_fork_digest( - cfg.ALTAIR_FORK_VERSION, - genesisValidatorsRoot) - - T(phase0: compute_fork_digest( - cfg.GENESIS_FORK_VERSION, - genesisValidatorsRoot), - altair: altairForkDigest, - altairTopicPrefix: $altairForkDigest) + T( + phase0: + compute_fork_digest(cfg.GENESIS_FORK_VERSION, genesisValidatorsRoot), + altair: + compute_fork_digest(cfg.ALTAIR_FORK_VERSION, genesisValidatorsRoot), + merge: + compute_fork_digest(cfg.MERGE_FORK_VERSION, genesisValidatorsRoot), + ) template asSigned*(x: phase0.TrustedSignedBeaconBlock or phase0.SigVerifiedBeaconBlock): phase0.SignedBeaconBlock =