diff --git a/beacon_chain/beacon_chain_db.nim b/beacon_chain/beacon_chain_db.nim index 3988ea013..3947d7ebd 100644 --- a/beacon_chain/beacon_chain_db.nim +++ b/beacon_chain/beacon_chain_db.nim @@ -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 diff --git a/beacon_chain/beacon_node.nim b/beacon_chain/beacon_node.nim index dcf8778ad..3f61c53f2 100644 --- a/beacon_chain/beacon_node.nim +++ b/beacon_chain/beacon_node.nim @@ -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! ) diff --git a/beacon_chain/block_pool.nim b/beacon_chain/block_pool.nim index be5d9fcf0..d70aba1c3 100644 --- a/beacon_chain/block_pool.nim +++ b/beacon_chain/block_pool.nim @@ -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: diff --git a/beacon_chain/spec/beaconstate.nim b/beacon_chain/spec/beaconstate.nim index b46aa988f..54e01573c 100644 --- a/beacon_chain/spec/beaconstate.nim +++ b/beacon_chain/spec/beaconstate.nim @@ -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 diff --git a/beacon_chain/spec/datatypes.nim b/beacon_chain/spec/datatypes.nim index 82677d7a1..205f4db82 100644 --- a/beacon_chain/spec/datatypes.nim +++ b/beacon_chain/spec/datatypes.nim @@ -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(), diff --git a/beacon_chain/spec/validator.nim b/beacon_chain/spec/validator.nim index 6102255e4..b78f5da68 100644 --- a/beacon_chain/spec/validator.nim +++ b/beacon_chain/spec/validator.nim @@ -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 = diff --git a/beacon_chain/state_transition.nim b/beacon_chain/state_transition.nim index 33e3ef6da..161e71efe 100644 --- a/beacon_chain/state_transition.nim +++ b/beacon_chain/state_transition.nim @@ -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), ) diff --git a/beacon_chain/sync_protocol.nim b/beacon_chain/sync_protocol.nim index 3688e68ab..400801df2 100644 --- a/beacon_chain/sync_protocol.nim +++ b/beacon_chain/sync_protocol.nim @@ -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 diff --git a/tests/test_beacon_chain_db.nim b/tests/test_beacon_chain_db.nim index 8eb8ec6dd..183eb61d0 100644 --- a/tests/test_beacon_chain_db.nim +++ b/tests/test_beacon_chain_db.nim @@ -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)) == [] diff --git a/tests/testutil.nim b/tests/testutil.nim index a431f901c..465008fce 100644 --- a/tests/testutil.nim +++ b/tests/testutil.nim @@ -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!