use of tech.pegasys.teku.spec.datastructures.forkchoice.ProtoNodeData in project teku by ConsenSys.
the class RecentChainData method updateHead.
// NETWORKING RELATED INFORMATION METHODS:
/**
* Set the block that is the current chain head according to fork-choice processing.
*
* @param root The new head block root
* @param currentSlot The current slot - the slot at which the new head was selected
*/
public void updateHead(Bytes32 root, UInt64 currentSlot) {
synchronized (this) {
if (chainHead.map(head -> head.getRoot().equals(root)).orElse(false)) {
LOG.trace("Skipping head update because new head is same as previous head");
return;
}
final Optional<ChainHead> originalChainHead = chainHead;
final ReadOnlyForkChoiceStrategy forkChoiceStrategy = store.getForkChoiceStrategy();
final Optional<ProtoNodeData> maybeBlockData = forkChoiceStrategy.getBlockData(root);
if (maybeBlockData.isEmpty()) {
LOG.error("Unable to update head block as of slot {}. Unknown block: {}", currentSlot, root);
return;
}
final ChainHead newChainHead = createNewChainHead(root, currentSlot, maybeBlockData.get());
this.chainHead = Optional.of(newChainHead);
final Optional<ReorgContext> optionalReorgContext = computeReorgContext(forkChoiceStrategy, originalChainHead, newChainHead);
final boolean epochTransition = originalChainHead.map(previousChainHead -> spec.computeEpochAtSlot(previousChainHead.getSlot()).isLessThan(spec.computeEpochAtSlot(newChainHead.getSlot()))).orElse(false);
final BeaconStateUtil beaconStateUtil = spec.atSlot(newChainHead.getSlot()).getBeaconStateUtil();
chainHeadChannel.chainHeadUpdated(newChainHead.getSlot(), newChainHead.getStateRoot(), newChainHead.getRoot(), epochTransition, newChainHead.isOptimistic(), // block and will remain consistent.
beaconStateUtil.getPreviousDutyDependentRoot(forkChoiceStrategy, newChainHead).orElseGet(this::getFinalizedBlockParentRoot), beaconStateUtil.getCurrentDutyDependentRoot(forkChoiceStrategy, newChainHead).orElseGet(this::getFinalizedBlockParentRoot), optionalReorgContext);
}
bestBlockInitialized.complete(null);
}
Aggregations