mirror of
https://github.com/status-im/nimbus-eth2.git
synced 2025-02-27 13:40:43 +00:00
req/resp status message requires zero hash for genesis finalized epoch (#6053)
This commit is contained in:
parent
513ccc1e0d
commit
55ba43592b
@ -58,6 +58,7 @@ func forkDigestAtEpoch(state: PeerSyncNetworkState,
|
|||||||
epoch: Epoch): ForkDigest =
|
epoch: Epoch): ForkDigest =
|
||||||
state.forkDigests[].atEpoch(epoch, state.cfg)
|
state.forkDigests[].atEpoch(epoch, state.cfg)
|
||||||
|
|
||||||
|
# https://github.com/ethereum/consensus-specs/blob/v1.4.0-beta.7/specs/phase0/p2p-interface.md#status
|
||||||
proc getCurrentStatus(state: PeerSyncNetworkState): StatusMsg =
|
proc getCurrentStatus(state: PeerSyncNetworkState): StatusMsg =
|
||||||
let
|
let
|
||||||
dag = state.dag
|
dag = state.dag
|
||||||
@ -66,14 +67,22 @@ proc getCurrentStatus(state: PeerSyncNetworkState): StatusMsg =
|
|||||||
if dag != nil:
|
if dag != nil:
|
||||||
StatusMsg(
|
StatusMsg(
|
||||||
forkDigest: state.forkDigestAtEpoch(wallSlot.epoch),
|
forkDigest: state.forkDigestAtEpoch(wallSlot.epoch),
|
||||||
finalizedRoot: dag.finalizedHead.blck.root,
|
finalizedRoot:
|
||||||
|
(if dag.finalizedHead.slot.epoch != GENESIS_EPOCH:
|
||||||
|
dag.finalizedHead.blck.root
|
||||||
|
else:
|
||||||
|
# this defaults to `Root(b'\x00' * 32)` for the genesis finalized
|
||||||
|
# checkpoint
|
||||||
|
ZERO_HASH),
|
||||||
finalizedEpoch: dag.finalizedHead.slot.epoch,
|
finalizedEpoch: dag.finalizedHead.slot.epoch,
|
||||||
headRoot: dag.head.root,
|
headRoot: dag.head.root,
|
||||||
headSlot: dag.head.slot)
|
headSlot: dag.head.slot)
|
||||||
else:
|
else:
|
||||||
StatusMsg(
|
StatusMsg(
|
||||||
forkDigest: state.forkDigestAtEpoch(wallSlot.epoch),
|
forkDigest: state.forkDigestAtEpoch(wallSlot.epoch),
|
||||||
finalizedRoot: state.genesisBlockRoot,
|
# this defaults to `Root(b'\x00' * 32)` for the genesis finalized
|
||||||
|
# checkpoint
|
||||||
|
finalizedRoot: ZERO_HASH,
|
||||||
finalizedEpoch: GENESIS_EPOCH,
|
finalizedEpoch: GENESIS_EPOCH,
|
||||||
headRoot: state.genesisBlockRoot,
|
headRoot: state.genesisBlockRoot,
|
||||||
headSlot: GENESIS_SLOT)
|
headSlot: GENESIS_SLOT)
|
||||||
@ -94,6 +103,7 @@ proc checkStatusMsg(state: PeerSyncNetworkState, status: StatusMsg):
|
|||||||
if state.forkDigestAtEpoch(wallSlot.epoch) != status.forkDigest:
|
if state.forkDigestAtEpoch(wallSlot.epoch) != status.forkDigest:
|
||||||
return err("fork digests differ")
|
return err("fork digests differ")
|
||||||
|
|
||||||
|
# https://github.com/ethereum/consensus-specs/blob/v1.4.0-beta.7/specs/phase0/p2p-interface.md#status
|
||||||
if dag != nil:
|
if dag != nil:
|
||||||
if status.finalizedEpoch <= dag.finalizedHead.slot.epoch:
|
if status.finalizedEpoch <= dag.finalizedHead.slot.epoch:
|
||||||
let blockId = dag.getBlockIdAtSlot(status.finalizedEpoch.start_slot())
|
let blockId = dag.getBlockIdAtSlot(status.finalizedEpoch.start_slot())
|
||||||
@ -103,7 +113,10 @@ proc checkStatusMsg(state: PeerSyncNetworkState, status: StatusMsg):
|
|||||||
return err("peer following different finality")
|
return err("peer following different finality")
|
||||||
else:
|
else:
|
||||||
if status.finalizedEpoch == GENESIS_EPOCH:
|
if status.finalizedEpoch == GENESIS_EPOCH:
|
||||||
if status.finalizedRoot != state.genesisBlockRoot:
|
# "this defaults to `Root(b'\x00' * 32)` for the genesis finalized checkpoint"
|
||||||
|
# keep compatibility with Lighthouse and other Nimbus for a while, which
|
||||||
|
# apparently don't use spec ZERO_HASH as of this writing
|
||||||
|
if not (status.finalizedRoot in [state.genesisBlockRoot, ZERO_HASH]):
|
||||||
return err("peer following different finality")
|
return err("peer following different finality")
|
||||||
|
|
||||||
ok()
|
ok()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user