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);
}
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);
}
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);
}
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;
}
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);
}
Aggregations