Address review comments
This commit is contained in:
parent
63d2e56255
commit
deaddc1fc0
|
@ -98,6 +98,9 @@ type
|
||||||
## Directed acyclic graph of blocks pointing back to a finalized block on the chain we're
|
## Directed acyclic graph of blocks pointing back to a finalized block on the chain we're
|
||||||
## interested in - we call that block the tail
|
## interested in - we call that block the tail
|
||||||
|
|
||||||
|
genesis*: BlockRef ##\
|
||||||
|
## The genesis block of the network
|
||||||
|
|
||||||
tail*: BlockRef ##\
|
tail*: BlockRef ##\
|
||||||
## The earliest finalized block we know about
|
## The earliest finalized block we know about
|
||||||
|
|
||||||
|
|
|
@ -300,10 +300,22 @@ proc init*(T: type ChainDAGRef,
|
||||||
tailRef = BlockRef.init(tailRoot, tailBlock.message)
|
tailRef = BlockRef.init(tailRoot, tailBlock.message)
|
||||||
headRoot = headBlockRoot.get()
|
headRoot = headBlockRoot.get()
|
||||||
|
|
||||||
|
let genesisRef = if tailBlock.message.slot == GENESIS_SLOT:
|
||||||
|
tailRef
|
||||||
|
else:
|
||||||
|
let
|
||||||
|
genesisBlockRoot = db.getGenesisBlockRoot()
|
||||||
|
genesisBlock = db.getBlock(genesisBlockRoot).expect(
|
||||||
|
"preInit should have initialized the database with a genesis block")
|
||||||
|
BlockRef.init(genesisBlockRoot, genesisBlock.message)
|
||||||
|
|
||||||
var
|
var
|
||||||
blocks = {tailRef.root: tailRef}.toTable()
|
blocks = {tailRef.root: tailRef}.toTable()
|
||||||
headRef: BlockRef
|
headRef: BlockRef
|
||||||
|
|
||||||
|
if genesisRef != tailRef:
|
||||||
|
blocks[genesisRef.root] = genesisRef
|
||||||
|
|
||||||
if headRoot != tailRoot:
|
if headRoot != tailRoot:
|
||||||
var curRef: BlockRef
|
var curRef: BlockRef
|
||||||
|
|
||||||
|
@ -363,6 +375,7 @@ proc init*(T: type ChainDAGRef,
|
||||||
blocks: blocks,
|
blocks: blocks,
|
||||||
tail: tailRef,
|
tail: tailRef,
|
||||||
head: headRef,
|
head: headRef,
|
||||||
|
genesis: genesisRef,
|
||||||
db: db,
|
db: db,
|
||||||
heads: @[headRef],
|
heads: @[headRef],
|
||||||
headState: tmpState[],
|
headState: tmpState[],
|
||||||
|
@ -892,13 +905,7 @@ proc setTailState*(dag: ChainDAGRef,
|
||||||
discard
|
discard
|
||||||
|
|
||||||
proc getGenesisBlockData*(dag: ChainDAGRef): BlockData =
|
proc getGenesisBlockData*(dag: ChainDAGRef): BlockData =
|
||||||
let
|
dag.get(dag.genesis)
|
||||||
genesisBlockRoot = dag.db.getGenesisBlockRoot()
|
|
||||||
# The database should be seeded with the genesis block root by `preInit`:
|
|
||||||
genesisBlock = dag.db.getBlock(genesisBlockRoot).get()
|
|
||||||
|
|
||||||
BlockData(data: genesisBlock,
|
|
||||||
refs: BlockRef(root: genesisBlockRoot, slot: GENESIS_SLOT))
|
|
||||||
|
|
||||||
proc getGenesisBlockSlot*(dag: ChainDAGRef): BlockSlot =
|
proc getGenesisBlockSlot*(dag: ChainDAGRef): BlockSlot =
|
||||||
let blockData = dag.getGenesisBlockData()
|
let blockData = dag.getGenesisBlockData()
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
{.push raises: [Defect].}
|
{.push raises: [Defect].}
|
||||||
|
|
||||||
import
|
import
|
||||||
os, options, unicode,
|
strutils, os, options, unicode,
|
||||||
chronicles, chronicles/options as chroniclesOptions,
|
chronicles, chronicles/options as chroniclesOptions,
|
||||||
confutils, confutils/defs, confutils/std/net, stew/shims/net as stewNet,
|
confutils, confutils/defs, confutils/std/net, stew/shims/net as stewNet,
|
||||||
stew/io2, unicodedb/properties, normalize,
|
stew/io2, unicodedb/properties, normalize,
|
||||||
json_serialization, web3/[ethtypes, confutils_defs],
|
json_serialization, web3/[ethtypes, confutils_defs],
|
||||||
spec/[crypto, keystore, digest, datatypes, network, weak_subjectivity],
|
spec/[crypto, keystore, digest, datatypes, network],
|
||||||
network_metadata
|
network_metadata
|
||||||
|
|
||||||
export
|
export
|
||||||
|
@ -144,7 +144,7 @@ type
|
||||||
|
|
||||||
weakSubjectivityCheckpoint* {.
|
weakSubjectivityCheckpoint* {.
|
||||||
desc: "Weak subjectivity checkpoint in the format block_root:epoch_number"
|
desc: "Weak subjectivity checkpoint in the format block_root:epoch_number"
|
||||||
name: "weak-subjectivity-checkpoint" }: Option[WeakSubjectivityCheckpoint]
|
name: "weak-subjectivity-checkpoint" }: Option[Checkpoint]
|
||||||
|
|
||||||
finalizedCheckpointState* {.
|
finalizedCheckpointState* {.
|
||||||
desc: "SSZ file specifying a recent finalized state"
|
desc: "SSZ file specifying a recent finalized state"
|
||||||
|
@ -463,11 +463,16 @@ func parseCmdArg*(T: type GraffitiBytes, input: TaintedString): T
|
||||||
func completeCmdArg*(T: type GraffitiBytes, input: TaintedString): seq[string] =
|
func completeCmdArg*(T: type GraffitiBytes, input: TaintedString): seq[string] =
|
||||||
return @[]
|
return @[]
|
||||||
|
|
||||||
func parseCmdArg*(T: type WeakSubjectivityCheckpoint, input: TaintedString): T
|
func parseCmdArg*(T: type Checkpoint, input: TaintedString): T
|
||||||
{.raises: [ValueError, Defect].} =
|
{.raises: [ValueError, Defect].} =
|
||||||
init(T, input)
|
let sepIdx = find(input.string, ':')
|
||||||
|
if sepIdx == -1:
|
||||||
|
raise newException(ValueError,
|
||||||
|
"The weak subjectivity checkpoint must be provided in the `block_root:epoch_number` format")
|
||||||
|
T(root: Eth2Digest.fromHex(input[0 ..< sepIdx]),
|
||||||
|
epoch: parseBiggestUInt(input[sepIdx .. ^1]).Epoch)
|
||||||
|
|
||||||
func completeCmdArg*(T: type WeakSubjectivityCheckpoint, input: TaintedString): seq[string] =
|
func completeCmdArg*(T: type Checkpoint, input: TaintedString): seq[string] =
|
||||||
return @[]
|
return @[]
|
||||||
|
|
||||||
proc isPrintable(rune: Rune): bool =
|
proc isPrintable(rune: Rune): bool =
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
import
|
import
|
||||||
strutils,
|
|
||||||
datatypes, digest, helpers
|
datatypes, digest, helpers
|
||||||
|
|
||||||
{.push raises: [Defect].}
|
{.push raises: [Defect].}
|
||||||
|
@ -7,20 +6,6 @@ import
|
||||||
const
|
const
|
||||||
SAFETY_DECAY* = 10'u64
|
SAFETY_DECAY* = 10'u64
|
||||||
|
|
||||||
type
|
|
||||||
WeakSubjectivityCheckpoint* = object
|
|
||||||
root*: Eth2Digest
|
|
||||||
epoch*: Epoch
|
|
||||||
|
|
||||||
func init*(T: type WeakSubjectivityCheckpoint, str: TaintedString): T
|
|
||||||
{.raises: [ValueError, Defect].} =
|
|
||||||
let sepIdx = find(str.string, ':')
|
|
||||||
if sepIdx == -1:
|
|
||||||
raise newException(ValueError,
|
|
||||||
"The weak subjectivity checkpoint must be provided in the `block_root:epoch_number` format")
|
|
||||||
T(root: Eth2Digest.fromHex(str[0 ..< sepIdx]),
|
|
||||||
epoch: parseBiggestUInt(str[sepIdx .. ^1]).Epoch)
|
|
||||||
|
|
||||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.12.3/specs/phase0/weak-subjectivity.md#calculating-the-weak-subjectivity-period
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.12.3/specs/phase0/weak-subjectivity.md#calculating-the-weak-subjectivity-period
|
||||||
func compute_weak_subjectivity_period*(state: BeaconState): uint64 =
|
func compute_weak_subjectivity_period*(state: BeaconState): uint64 =
|
||||||
var weak_subjectivity_period = MIN_VALIDATOR_WITHDRAWABILITY_DELAY
|
var weak_subjectivity_period = MIN_VALIDATOR_WITHDRAWABILITY_DELAY
|
||||||
|
@ -34,7 +19,7 @@ func compute_weak_subjectivity_period*(state: BeaconState): uint64 =
|
||||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.12.3/specs/phase0/weak-subjectivity.md#checking-for-stale-weak-subjectivity-checkpoint
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.12.3/specs/phase0/weak-subjectivity.md#checking-for-stale-weak-subjectivity-checkpoint
|
||||||
func is_within_weak_subjectivity_period*(current_slot: Slot,
|
func is_within_weak_subjectivity_period*(current_slot: Slot,
|
||||||
ws_state: BeaconState,
|
ws_state: BeaconState,
|
||||||
ws_checkpoint: WeakSubjectivityCheckpoint): bool =
|
ws_checkpoint: Checkpoint): bool =
|
||||||
# Clients may choose to validate the input state against the input Weak Subjectivity Checkpoint
|
# Clients may choose to validate the input state against the input Weak Subjectivity Checkpoint
|
||||||
doAssert ws_state.latest_block_header.state_root == ws_checkpoint.root
|
doAssert ws_state.latest_block_header.state_root == ws_checkpoint.root
|
||||||
doAssert compute_epoch_at_slot(ws_state.slot) == ws_checkpoint.epoch
|
doAssert compute_epoch_at_slot(ws_state.slot) == ws_checkpoint.epoch
|
||||||
|
|
Loading…
Reference in New Issue