Search in sources :

Example 1 with ProtoNodeData

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);
}
Also used : SpecConfigBellatrix(tech.pegasys.teku.spec.config.SpecConfigBellatrix) ProtoNodeData(tech.pegasys.teku.spec.datastructures.forkchoice.ProtoNodeData) StoreConfig(tech.pegasys.teku.storage.store.StoreConfig) BlockProvider(tech.pegasys.teku.dataproviders.lookup.BlockProvider) BeaconBlock(tech.pegasys.teku.spec.datastructures.blocks.BeaconBlock) StateAndBlockSummary(tech.pegasys.teku.spec.datastructures.blocks.StateAndBlockSummary) ReadOnlyStore(tech.pegasys.teku.spec.datastructures.forkchoice.ReadOnlyStore) Map(java.util.Map) ForkInfo(tech.pegasys.teku.spec.datastructures.state.ForkInfo) Bytes32(org.apache.tuweni.bytes.Bytes32) GenesisData(tech.pegasys.teku.spec.datastructures.genesis.GenesisData) AsyncRunner(tech.pegasys.teku.infrastructure.async.AsyncRunner) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Set(java.util.Set) NavigableMap(java.util.NavigableMap) Logger(org.apache.logging.log4j.Logger) Optional(java.util.Optional) VoteUpdateChannel(tech.pegasys.teku.storage.api.VoteUpdateChannel) MetricsSystem(org.hyperledger.besu.plugin.services.MetricsSystem) Checkpoint(tech.pegasys.teku.spec.datastructures.state.Checkpoint) Counter(org.hyperledger.besu.plugin.services.metrics.Counter) ChainHeadChannel(tech.pegasys.teku.storage.api.ChainHeadChannel) StoreUpdateHandler(tech.pegasys.teku.storage.store.UpdatableStore.StoreUpdateHandler) ReadOnlyForkChoiceStrategy(tech.pegasys.teku.spec.datastructures.forkchoice.ReadOnlyForkChoiceStrategy) UpdatableStore(tech.pegasys.teku.storage.store.UpdatableStore) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) SafeFuture(tech.pegasys.teku.infrastructure.async.SafeFuture) MinimalBeaconBlockSummary(tech.pegasys.teku.spec.datastructures.blocks.MinimalBeaconBlockSummary) Fork(tech.pegasys.teku.spec.datastructures.state.Fork) StoreBuilder(tech.pegasys.teku.storage.store.StoreBuilder) SpecVersion(tech.pegasys.teku.spec.SpecVersion) VoteUpdater(tech.pegasys.teku.spec.datastructures.forkchoice.VoteUpdater) UInt64(tech.pegasys.teku.infrastructure.unsigned.UInt64) Spec(tech.pegasys.teku.spec.Spec) SignedBeaconBlock(tech.pegasys.teku.spec.datastructures.blocks.SignedBeaconBlock) SlotAndBlockRoot(tech.pegasys.teku.spec.datastructures.blocks.SlotAndBlockRoot) BeaconStateUtil(tech.pegasys.teku.spec.logic.common.util.BeaconStateUtil) FinalizedCheckpointChannel(tech.pegasys.teku.storage.api.FinalizedCheckpointChannel) EmptyStoreResults(tech.pegasys.teku.storage.store.EmptyStoreResults) ReorgContext(tech.pegasys.teku.storage.api.ReorgContext) StorageUpdateChannel(tech.pegasys.teku.storage.api.StorageUpdateChannel) StateAndBlockSummaryProvider(tech.pegasys.teku.dataproviders.lookup.StateAndBlockSummaryProvider) StoreTransaction(tech.pegasys.teku.storage.store.UpdatableStore.StoreTransaction) ForkChoiceStrategy(tech.pegasys.teku.ethereum.forkchoice.ForkChoiceStrategy) TekuMetricCategory(tech.pegasys.teku.infrastructure.metrics.TekuMetricCategory) TreeMap(java.util.TreeMap) AnchorPoint(tech.pegasys.teku.spec.datastructures.state.AnchorPoint) Bytes4(tech.pegasys.teku.infrastructure.bytes.Bytes4) Collections(java.util.Collections) LogManager(org.apache.logging.log4j.LogManager) SpecMilestone(tech.pegasys.teku.spec.SpecMilestone) BeaconState(tech.pegasys.teku.spec.datastructures.state.beaconstate.BeaconState) ReorgContext(tech.pegasys.teku.storage.api.ReorgContext) ReadOnlyForkChoiceStrategy(tech.pegasys.teku.spec.datastructures.forkchoice.ReadOnlyForkChoiceStrategy) ProtoNodeData(tech.pegasys.teku.spec.datastructures.forkchoice.ProtoNodeData) BeaconStateUtil(tech.pegasys.teku.spec.logic.common.util.BeaconStateUtil)

Aggregations

Collections (java.util.Collections)1 Map (java.util.Map)1 NavigableMap (java.util.NavigableMap)1 Optional (java.util.Optional)1 Set (java.util.Set)1 TreeMap (java.util.TreeMap)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 LogManager (org.apache.logging.log4j.LogManager)1 Logger (org.apache.logging.log4j.Logger)1 Bytes32 (org.apache.tuweni.bytes.Bytes32)1 MetricsSystem (org.hyperledger.besu.plugin.services.MetricsSystem)1 Counter (org.hyperledger.besu.plugin.services.metrics.Counter)1 BlockProvider (tech.pegasys.teku.dataproviders.lookup.BlockProvider)1 StateAndBlockSummaryProvider (tech.pegasys.teku.dataproviders.lookup.StateAndBlockSummaryProvider)1 ForkChoiceStrategy (tech.pegasys.teku.ethereum.forkchoice.ForkChoiceStrategy)1 AsyncRunner (tech.pegasys.teku.infrastructure.async.AsyncRunner)1 SafeFuture (tech.pegasys.teku.infrastructure.async.SafeFuture)1 Bytes4 (tech.pegasys.teku.infrastructure.bytes.Bytes4)1 TekuMetricCategory (tech.pegasys.teku.infrastructure.metrics.TekuMetricCategory)1