Search in sources :

Example 1 with ReorgContext

use of tech.pegasys.teku.storage.api.ReorgContext in project teku by ConsenSys.

the class CoalescingChainHeadChannelTest method shouldNotBeSyncingInitially.

@Test
void shouldNotBeSyncingInitially() {
    final UInt64 slot = dataStructureUtil.randomUInt64();
    final Bytes32 stateRoot = dataStructureUtil.randomBytes32();
    final Bytes32 bestBlockRoot = dataStructureUtil.randomBytes32();
    final boolean epochTransition = true;
    final boolean executionOptimistic = false;
    final Bytes32 previousDutyDependentRoot = dataStructureUtil.randomBytes32();
    final Bytes32 currentDutyDependentRoot = dataStructureUtil.randomBytes32();
    final Optional<ReorgContext> reorgContext = Optional.empty();
    channel.chainHeadUpdated(slot, stateRoot, bestBlockRoot, epochTransition, executionOptimistic, previousDutyDependentRoot, currentDutyDependentRoot, reorgContext);
    verify(delegate).chainHeadUpdated(slot, stateRoot, bestBlockRoot, epochTransition, executionOptimistic, previousDutyDependentRoot, currentDutyDependentRoot, reorgContext);
}
Also used : ReorgContext(tech.pegasys.teku.storage.api.ReorgContext) UInt64(tech.pegasys.teku.infrastructure.unsigned.UInt64) Bytes32(org.apache.tuweni.bytes.Bytes32) Test(org.junit.jupiter.api.Test)

Example 2 with ReorgContext

use of tech.pegasys.teku.storage.api.ReorgContext in project teku by ConsenSys.

the class CoalescingChainHeadChannelTest method shouldDelegateEventImmediatelyWhenNotSyncing.

@Test
void shouldDelegateEventImmediatelyWhenNotSyncing() {
    final UInt64 slot = dataStructureUtil.randomUInt64();
    final Bytes32 stateRoot = dataStructureUtil.randomBytes32();
    final Bytes32 bestBlockRoot = dataStructureUtil.randomBytes32();
    final boolean epochTransition = true;
    final boolean executionOptimistic = true;
    final Bytes32 previousDutyDependentRoot = dataStructureUtil.randomBytes32();
    final Bytes32 currentDutyDependentRoot = dataStructureUtil.randomBytes32();
    final Optional<ReorgContext> reorgContext = Optional.empty();
    channel.onSyncingChange(false);
    channel.chainHeadUpdated(slot, stateRoot, bestBlockRoot, epochTransition, executionOptimistic, previousDutyDependentRoot, currentDutyDependentRoot, reorgContext);
    verify(delegate).chainHeadUpdated(slot, stateRoot, bestBlockRoot, epochTransition, executionOptimistic, previousDutyDependentRoot, currentDutyDependentRoot, reorgContext);
}
Also used : ReorgContext(tech.pegasys.teku.storage.api.ReorgContext) UInt64(tech.pegasys.teku.infrastructure.unsigned.UInt64) Bytes32(org.apache.tuweni.bytes.Bytes32) Test(org.junit.jupiter.api.Test)

Example 3 with ReorgContext

use of tech.pegasys.teku.storage.api.ReorgContext in project teku by ConsenSys.

the class CoalescingChainHeadChannelTest method shouldNotifyReorg.

@Test
void shouldNotifyReorg() {
    final UInt64 slot = dataStructureUtil.randomUInt64();
    final Bytes32 stateRoot = dataStructureUtil.randomBytes32();
    final Bytes32 bestBlockRoot = dataStructureUtil.randomBytes32();
    final boolean epochTransition = true;
    final boolean executionOptimistic = true;
    final Bytes32 previousDutyDependentRoot = dataStructureUtil.randomBytes32();
    final Bytes32 currentDutyDependentRoot = dataStructureUtil.randomBytes32();
    final Bytes32 oldBestBlockRoot = dataStructureUtil.randomBytes32();
    final UInt64 oldBestBlockSlot = dataStructureUtil.randomUInt64();
    final Bytes32 oldBestStateRoot = dataStructureUtil.randomBytes32();
    final UInt64 commonAncestorSlot = dataStructureUtil.randomUInt64();
    final Bytes32 commonAncestorRoot = dataStructureUtil.randomBytes32();
    final Optional<ReorgContext> reorgContext = Optional.of(new ReorgContext(oldBestBlockRoot, oldBestBlockSlot, oldBestStateRoot, commonAncestorSlot, commonAncestorRoot));
    channel.onSyncingChange(false);
    channel.chainHeadUpdated(slot, stateRoot, bestBlockRoot, epochTransition, executionOptimistic, previousDutyDependentRoot, currentDutyDependentRoot, reorgContext);
    verify(eventLogger, times(1)).reorgEvent(oldBestBlockRoot, oldBestBlockSlot, bestBlockRoot, slot, commonAncestorRoot, commonAncestorSlot);
}
Also used : ReorgContext(tech.pegasys.teku.storage.api.ReorgContext) UInt64(tech.pegasys.teku.infrastructure.unsigned.UInt64) Bytes32(org.apache.tuweni.bytes.Bytes32) Test(org.junit.jupiter.api.Test)

Example 4 with ReorgContext

use of tech.pegasys.teku.storage.api.ReorgContext in project teku by ConsenSys.

the class RecentChainData method computeReorgContext.

private Optional<ReorgContext> computeReorgContext(final ReadOnlyForkChoiceStrategy forkChoiceStrategy, final Optional<ChainHead> originalChainHead, final ChainHead newChainHead) {
    final Optional<ReorgContext> optionalReorgContext;
    if (originalChainHead.map(head -> hasReorgedFrom(head.getRoot(), head.getSlot())).orElse(false)) {
        final ChainHead previousChainHead = originalChainHead.get();
        final SlotAndBlockRoot commonAncestorSlotAndBlockRoot = forkChoiceStrategy.findCommonAncestor(previousChainHead.getRoot(), newChainHead.getRoot()).orElseGet(() -> store.getFinalizedCheckpoint().toSlotAndBlockRoot(spec));
        reorgCounter.inc();
        optionalReorgContext = ReorgContext.of(previousChainHead.getRoot(), previousChainHead.getSlot(), previousChainHead.getStateRoot(), commonAncestorSlotAndBlockRoot.getSlot(), commonAncestorSlotAndBlockRoot.getBlockRoot());
    } else {
        optionalReorgContext = ReorgContext.empty();
    }
    return optionalReorgContext;
}
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) SlotAndBlockRoot(tech.pegasys.teku.spec.datastructures.blocks.SlotAndBlockRoot) ReorgContext(tech.pegasys.teku.storage.api.ReorgContext)

Example 5 with ReorgContext

use of tech.pegasys.teku.storage.api.ReorgContext in project teku by ConsenSys.

the class CoalescingChainHeadChannelTest method shouldNotResendPreviousCoalescedHeadEventWhenSyncingFinishesASecondTime.

@Test
void shouldNotResendPreviousCoalescedHeadEventWhenSyncingFinishesASecondTime() {
    final UInt64 slot = dataStructureUtil.randomUInt64();
    final Bytes32 stateRoot = dataStructureUtil.randomBytes32();
    final Bytes32 bestBlockRoot = dataStructureUtil.randomBytes32();
    final boolean epochTransition = true;
    final boolean executionOptimistic = true;
    final Bytes32 previousDutyDependentRoot = dataStructureUtil.randomBytes32();
    final Bytes32 currentDutyDependentRoot = dataStructureUtil.randomBytes32();
    final Optional<ReorgContext> reorgContext = Optional.empty();
    channel.onSyncingChange(true);
    channel.chainHeadUpdated(slot, stateRoot, bestBlockRoot, epochTransition, executionOptimistic, previousDutyDependentRoot, currentDutyDependentRoot, reorgContext);
    channel.onSyncingChange(false);
    verify(delegate).chainHeadUpdated(slot, stateRoot, bestBlockRoot, epochTransition, executionOptimistic, previousDutyDependentRoot, currentDutyDependentRoot, reorgContext);
    channel.onSyncingChange(true);
    channel.onSyncingChange(false);
    verifyNoMoreInteractions(delegate);
}
Also used : ReorgContext(tech.pegasys.teku.storage.api.ReorgContext) UInt64(tech.pegasys.teku.infrastructure.unsigned.UInt64) Bytes32(org.apache.tuweni.bytes.Bytes32) Test(org.junit.jupiter.api.Test)

Aggregations

Bytes32 (org.apache.tuweni.bytes.Bytes32)10 UInt64 (tech.pegasys.teku.infrastructure.unsigned.UInt64)10 ReorgContext (tech.pegasys.teku.storage.api.ReorgContext)10 Test (org.junit.jupiter.api.Test)8 Collections (java.util.Collections)2 Map (java.util.Map)2 NavigableMap (java.util.NavigableMap)2 Optional (java.util.Optional)2 Set (java.util.Set)2 TreeMap (java.util.TreeMap)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)2 LogManager (org.apache.logging.log4j.LogManager)2 Logger (org.apache.logging.log4j.Logger)2 MetricsSystem (org.hyperledger.besu.plugin.services.MetricsSystem)2 Counter (org.hyperledger.besu.plugin.services.metrics.Counter)2 BlockProvider (tech.pegasys.teku.dataproviders.lookup.BlockProvider)2 StateAndBlockSummaryProvider (tech.pegasys.teku.dataproviders.lookup.StateAndBlockSummaryProvider)2 ForkChoiceStrategy (tech.pegasys.teku.ethereum.forkchoice.ForkChoiceStrategy)2 AsyncRunner (tech.pegasys.teku.infrastructure.async.AsyncRunner)2