0.7.0 updates including semantic changes (#285)
* update get_previous_epoch(...) * update BeaconBlock to 0.7.0 by renaming previous_block_root field to parent_root
This commit is contained in:
parent
e2496567b3
commit
2a6e64d3f9
|
@ -138,4 +138,4 @@ iterator getAncestors*(db: BeaconChainDB, root: Eth2Digest):
|
|||
while (let blck = db.getBlock(root); blck.isSome()):
|
||||
yield (root, blck.get())
|
||||
|
||||
root = blck.get().previous_block_root
|
||||
root = blck.get().parent_root
|
||||
|
|
|
@ -363,7 +363,7 @@ proc proposeBlock(node: BeaconNode,
|
|||
var
|
||||
newBlock = BeaconBlock(
|
||||
slot: slot,
|
||||
previous_block_root: head.root,
|
||||
parent_root: head.root,
|
||||
body: blockBody,
|
||||
signature: ValidatorSig(), # we need the rest of the block first!
|
||||
)
|
||||
|
|
|
@ -167,7 +167,7 @@ proc addResolvedBlock(
|
|||
|
||||
var foundHead: Option[Head]
|
||||
for head in pool.heads.mitems():
|
||||
if head.blck.root == blck.previous_block_root:
|
||||
if head.blck.root == blck.parent_root:
|
||||
if head.justified.slot != justifiedSlot:
|
||||
head.justified = blockRef.findAncestorBySlot(justifiedSlot)
|
||||
|
||||
|
@ -227,7 +227,7 @@ proc add*(
|
|||
|
||||
return
|
||||
|
||||
let parent = pool.blocks.getOrDefault(blck.previous_block_root)
|
||||
let parent = pool.blocks.getOrDefault(blck.parent_root)
|
||||
|
||||
if parent != nil:
|
||||
# The block might have been in either of these - we don't want any more
|
||||
|
@ -258,8 +258,8 @@ proc add*(
|
|||
# think are useful - but, it would also risk filling the database with
|
||||
# junk that's not part of the block graph
|
||||
|
||||
if blck.previous_block_root in pool.missing or
|
||||
blck.previous_block_root in pool.pending:
|
||||
if blck.parent_root in pool.missing or
|
||||
blck.parent_root in pool.pending:
|
||||
return
|
||||
|
||||
# This is an unresolved block - put its parent on the missing list for now...
|
||||
|
@ -280,7 +280,7 @@ proc add*(
|
|||
|
||||
let parentSlot = blck.slot - 1
|
||||
|
||||
pool.missing[blck.previous_block_root] = MissingBlock(
|
||||
pool.missing[blck.parent_root] = MissingBlock(
|
||||
slots:
|
||||
# The block is at least two slots ahead - try to grab whole history
|
||||
if parentSlot > pool.head.blck.slot:
|
||||
|
|
|
@ -183,7 +183,7 @@ func get_temporary_block_header(blck: BeaconBlock): BeaconBlockHeader =
|
|||
## to ``ZERO_HASH``.
|
||||
BeaconBlockHeader(
|
||||
slot: blck.slot,
|
||||
previous_block_root: blck.previous_block_root,
|
||||
previous_block_root: blck.parent_root,
|
||||
state_root: ZERO_HASH,
|
||||
block_body_root: hash_tree_root(blck.body),
|
||||
# signing_root(block) is used for block id purposes so signature is a stub
|
||||
|
|
|
@ -198,7 +198,7 @@ type
|
|||
signature*: ValidatorSig ##\
|
||||
## Sender signature
|
||||
|
||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.6.3/specs/core/0_beacon-chain.md#beaconblock
|
||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.7.0/specs/core/0_beacon-chain.md#beaconblock
|
||||
BeaconBlock* = object
|
||||
## For each slot, a proposer is chosen from the validator pool to propose
|
||||
## a new block. Once the block as been proposed, it is transmitted to
|
||||
|
@ -208,8 +208,8 @@ type
|
|||
|
||||
slot*: Slot
|
||||
|
||||
previous_block_root*: Eth2Digest ##\
|
||||
##\ Root hash of the previous block
|
||||
parent_root*: Eth2Digest ##\
|
||||
## Root hash of the previous block
|
||||
|
||||
state_root*: Eth2Digest ##\
|
||||
## The state root, _after_ this block has been processed
|
||||
|
@ -436,7 +436,7 @@ func humaneEpochNum*(e: Epoch): uint64 =
|
|||
e - GENESIS_EPOCH
|
||||
|
||||
func shortLog*(v: BeaconBlock): tuple[
|
||||
slot: uint64, previous_block_root: string, state_root: string,
|
||||
slot: uint64, parent_root: string, state_root: string,
|
||||
#[ eth1_data ]#
|
||||
proposer_slashings_len: int, attester_slashings_len: int,
|
||||
attestations_len: int,
|
||||
|
@ -445,7 +445,7 @@ func shortLog*(v: BeaconBlock): tuple[
|
|||
transfers_len: int,
|
||||
signature: string
|
||||
] = (
|
||||
humaneSlotNum(v.slot), shortLog(v.previous_block_root),
|
||||
humaneSlotNum(v.slot), shortLog(v.parent_root),
|
||||
shortLog(v.state_root), v.body.proposer_slashings.len(),
|
||||
v.body.attester_slashings.len(), v.body.attestations.len(),
|
||||
v.body.deposits.len(), v.body.voluntary_exits.len(), v.body.transfers.len(),
|
||||
|
|
|
@ -118,15 +118,15 @@ func get_shuffled_index(index: ValidatorIndex, index_count: uint64, seed: Eth2Di
|
|||
if bit != 0:
|
||||
result = flip
|
||||
|
||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.6.3/specs/core/0_beacon-chain.md#get_previous_epoch
|
||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.7.0/specs/core/0_beacon-chain.md#get_previous_epoch
|
||||
func get_previous_epoch*(state: BeaconState): Epoch =
|
||||
## Return the previous epoch of the given ``state``.
|
||||
## Return the current epoch if it's genesis epoch.
|
||||
let current_epoch = get_current_epoch(state)
|
||||
if current_epoch > GENESIS_EPOCH:
|
||||
current_epoch - 1
|
||||
else:
|
||||
if current_epoch == GENESIS_EPOCH:
|
||||
current_epoch
|
||||
else:
|
||||
current_epoch - 1
|
||||
|
||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.7.0/specs/core/0_beacon-chain.md#get_shard_delta
|
||||
func get_shard_delta*(state: BeaconState, epoch: Epoch): uint64 =
|
||||
|
|
|
@ -46,7 +46,7 @@ proc processBlockHeader(
|
|||
return false
|
||||
|
||||
# Verify that the parent matches
|
||||
if skipValidation notin flags and not (blck.previous_block_root ==
|
||||
if skipValidation notin flags and not (blck.parent_root ==
|
||||
signing_root(state.latest_block_header)):
|
||||
notice "Block header: previous block root mismatch",
|
||||
latest_block_header = state.latest_block_header,
|
||||
|
@ -57,7 +57,7 @@ proc processBlockHeader(
|
|||
# Save current block as the new latest block
|
||||
state.latest_block_header = BeaconBlockHeader(
|
||||
slot: blck.slot,
|
||||
previous_block_root: blck.previous_block_root,
|
||||
previous_block_root: blck.parent_root,
|
||||
block_body_root: hash_tree_root(blck.body),
|
||||
)
|
||||
|
||||
|
|
|
@ -31,7 +31,7 @@ const
|
|||
func toHeader(b: BeaconBlock): BeaconBlockHeader =
|
||||
BeaconBlockHeader(
|
||||
slot: b.slot,
|
||||
previous_block_root: b.previous_block_root,
|
||||
previous_block_root: b.parent_root,
|
||||
state_root: b.state_root,
|
||||
block_body_root: hash_tree_root(b.body),
|
||||
signature: b.signature
|
||||
|
@ -40,7 +40,7 @@ func toHeader(b: BeaconBlock): BeaconBlockHeader =
|
|||
proc fromHeaderAndBody(b: var BeaconBlock, h: BeaconBlockHeader, body: BeaconBlockBody) =
|
||||
doAssert(hash_tree_root(body) == h.block_body_root)
|
||||
b.slot = h.slot
|
||||
b.previous_block_root = h.previous_block_root
|
||||
b.parent_root = h.previous_block_root
|
||||
b.state_root = h.state_root
|
||||
b.body = body
|
||||
b.signature = h.signature
|
||||
|
@ -225,12 +225,12 @@ p2pProtocol BeaconSync(version = 1,
|
|||
if resp.len >= MaxAncestorBlocksResponse:
|
||||
break
|
||||
|
||||
if blck.get().previous_block_root in neededRoots:
|
||||
if blck.get().parent_root in neededRoots:
|
||||
# Don't send duplicate blocks, if neededRoots has roots that are
|
||||
# in the same chain
|
||||
break
|
||||
|
||||
if (blck = db.getBlock(blck.get().previous_block_root);
|
||||
if (blck = db.getBlock(blck.get().parent_root);
|
||||
blck.isNone() or blck.get().slot < firstSlot):
|
||||
break
|
||||
|
||||
|
|
|
@ -65,9 +65,9 @@ suite "Beacon chain DB" & preset():
|
|||
let
|
||||
a0 = BeaconBlock(slot: GENESIS_SLOT + 0)
|
||||
a0r = signing_root(a0)
|
||||
a1 = BeaconBlock(slot: GENESIS_SLOT + 1, previous_block_root: a0r)
|
||||
a1 = BeaconBlock(slot: GENESIS_SLOT + 1, parent_root: a0r)
|
||||
a1r = signing_root(a1)
|
||||
a2 = BeaconBlock(slot: GENESIS_SLOT + 2, previous_block_root: a1r)
|
||||
a2 = BeaconBlock(slot: GENESIS_SLOT + 2, parent_root: a1r)
|
||||
a2r = signing_root(a2)
|
||||
|
||||
doAssert toSeq(db.getAncestors(a0r)) == []
|
||||
|
|
|
@ -96,7 +96,7 @@ proc addBlock*(
|
|||
# would look with the new block applied.
|
||||
new_block = BeaconBlock(
|
||||
slot: state.slot + 1,
|
||||
previous_block_root: previous_block_root,
|
||||
parent_root: previous_block_root,
|
||||
state_root: Eth2Digest(), # we need the new state first
|
||||
body: new_body,
|
||||
signature: ValidatorSig(), # we need the rest of the block first!
|
||||
|
|
Loading…
Reference in New Issue