@Test void shouldOnlyRemoveOperations() { BeaconBlock block1 = dataStructureUtil.randomBeaconBlock(10); BeaconBlock block2 = dataStructureUtil.randomBeaconBlock(11); UInt64 commonAncestorSlot = UInt64.valueOf(9); NavigableMap<UInt64, Bytes32> nowCanonicalBlockRoots = new TreeMap<>(); nowCanonicalBlockRoots.put(UInt64.valueOf(12), block1.hash_tree_root()); nowCanonicalBlockRoots.put(UInt64.valueOf(13), block2.hash_tree_root()); when(recentChainData.getAncestorsOnFork(commonAncestorSlot, block2.hash_tree_root())) .thenReturn(nowCanonicalBlockRoots); when(recentChainData.getAncestorsOnFork(commonAncestorSlot, Bytes32.ZERO)) .thenReturn(new TreeMap<>()); when(recentChainData.retrieveBlockByRoot(block1.hash_tree_root())) .thenReturn(SafeFuture.completedFuture(Optional.of(block1))); when(recentChainData.retrieveBlockByRoot(block2.hash_tree_root())) .thenReturn(SafeFuture.completedFuture(Optional.of(block2))); when(attestationManager.onAttestation(any())) .thenReturn(SafeFuture.completedFuture(AttestationProcessingResult.SUCCESSFUL)); operationsReOrgManager.chainHeadUpdated( UInt64.valueOf(13), block2.getState_root(), block2.hash_tree_root(), false, ReorgContext.of(Bytes32.ZERO, Bytes32.ZERO, commonAncestorSlot)); verify(recentChainData).getAncestorsOnFork(commonAncestorSlot, block2.hash_tree_root()); verify(exitOperationPool, never()).addAll(any()); verify(proposerSlashingOperationPool, never()).addAll(any()); verify(attesterSlashingOperationPool, never()).addAll(any()); verify(attestationManager, never()).onAttestation(any()); verify(proposerSlashingOperationPool).removeAll(block2.getBody().getProposer_slashings()); verify(attesterSlashingOperationPool).removeAll(block2.getBody().getAttester_slashings()); verify(exitOperationPool).removeAll(block2.getBody().getVoluntary_exits()); verify(attestationPool).removeAll(block2.getBody().getAttestations()); verify(proposerSlashingOperationPool).removeAll(block1.getBody().getProposer_slashings()); verify(attesterSlashingOperationPool).removeAll(block1.getBody().getAttester_slashings()); verify(exitOperationPool).removeAll(block1.getBody().getVoluntary_exits()); verify(attestationPool).removeAll(block1.getBody().getAttestations()); }
@Override public void chainHeadUpdated( final UInt64 slot, final Bytes32 stateRoot, final Bytes32 bestBlockRoot, final boolean epochTransition, final Optional<ReorgContext> optionalReorgContext) { optionalReorgContext.ifPresent( reorgContext -> { NavigableMap<UInt64, Bytes32> notCanonicalBlockRoots = recentChainData.getAncestorsOnFork( reorgContext.getCommonAncestorSlot(), reorgContext.getOldBestBlockRoot()); NavigableMap<UInt64, Bytes32> nowCanonicalBlockRoots = recentChainData.getAncestorsOnFork( reorgContext.getCommonAncestorSlot(), bestBlockRoot); processNonCanonicalBlockOperations(notCanonicalBlockRoots.values()); processCanonicalBlockOperations(nowCanonicalBlockRoots.values()); }); }
OperationsReOrgManager implements ChainHeadChannel { @Override public void chainHeadUpdated( final UInt64 slot, final Bytes32 stateRoot, final Bytes32 bestBlockRoot, final boolean epochTransition, final Optional<ReorgContext> optionalReorgContext) { optionalReorgContext.ifPresent( reorgContext -> { NavigableMap<UInt64, Bytes32> notCanonicalBlockRoots = recentChainData.getAncestorsOnFork( reorgContext.getCommonAncestorSlot(), reorgContext.getOldBestBlockRoot()); NavigableMap<UInt64, Bytes32> nowCanonicalBlockRoots = recentChainData.getAncestorsOnFork( reorgContext.getCommonAncestorSlot(), bestBlockRoot); processNonCanonicalBlockOperations(notCanonicalBlockRoots.values()); processCanonicalBlockOperations(nowCanonicalBlockRoots.values()); }); } }
OperationsReOrgManager implements ChainHeadChannel { @Override public void chainHeadUpdated( final UInt64 slot, final Bytes32 stateRoot, final Bytes32 bestBlockRoot, final boolean epochTransition, final Optional<ReorgContext> optionalReorgContext) { optionalReorgContext.ifPresent( reorgContext -> { NavigableMap<UInt64, Bytes32> notCanonicalBlockRoots = recentChainData.getAncestorsOnFork( reorgContext.getCommonAncestorSlot(), reorgContext.getOldBestBlockRoot()); NavigableMap<UInt64, Bytes32> nowCanonicalBlockRoots = recentChainData.getAncestorsOnFork( reorgContext.getCommonAncestorSlot(), bestBlockRoot); processNonCanonicalBlockOperations(notCanonicalBlockRoots.values()); processCanonicalBlockOperations(nowCanonicalBlockRoots.values()); }); } OperationsReOrgManager(
      OperationPool<ProposerSlashing> proposerSlashingPool,
      OperationPool<AttesterSlashing> attesterSlashingPool,
      OperationPool<SignedVoluntaryExit> exitPool,
      AggregatingAttestationPool attestationPool,
      AttestationManager attestationManager,
      RecentChainData recentChainData); }
OperationsReOrgManager implements ChainHeadChannel { @Override public void chainHeadUpdated( final UInt64 slot, final Bytes32 stateRoot, final Bytes32 bestBlockRoot, final boolean epochTransition, final Optional<ReorgContext> optionalReorgContext) { optionalReorgContext.ifPresent( reorgContext -> { NavigableMap<UInt64, Bytes32> notCanonicalBlockRoots = recentChainData.getAncestorsOnFork( reorgContext.getCommonAncestorSlot(), reorgContext.getOldBestBlockRoot()); NavigableMap<UInt64, Bytes32> nowCanonicalBlockRoots = recentChainData.getAncestorsOnFork( reorgContext.getCommonAncestorSlot(), bestBlockRoot); processNonCanonicalBlockOperations(notCanonicalBlockRoots.values()); processCanonicalBlockOperations(nowCanonicalBlockRoots.values()); }); } OperationsReOrgManager(
      OperationPool<ProposerSlashing> proposerSlashingPool,
      OperationPool<AttesterSlashing> attesterSlashingPool,
      OperationPool<SignedVoluntaryExit> exitPool,
      AggregatingAttestationPool attestationPool,
      AttestationManager attestationManager,
      RecentChainData recentChainData); @Override void chainHeadUpdated(
      final UInt64 slot,
      final Bytes32 stateRoot,
      final Bytes32 bestBlockRoot,
      final boolean epochTransition,
      final Optional<ReorgContext> optionalReorgContext); }
OperationsReOrgManager implements ChainHeadChannel { @Override public void chainHeadUpdated( final UInt64 slot, final Bytes32 stateRoot, final Bytes32 bestBlockRoot, final boolean epochTransition, final Optional<ReorgContext> optionalReorgContext) { optionalReorgContext.ifPresent( reorgContext -> { NavigableMap<UInt64, Bytes32> notCanonicalBlockRoots = recentChainData.getAncestorsOnFork( reorgContext.getCommonAncestorSlot(), reorgContext.getOldBestBlockRoot()); NavigableMap<UInt64, Bytes32> nowCanonicalBlockRoots = recentChainData.getAncestorsOnFork( reorgContext.getCommonAncestorSlot(), bestBlockRoot); processNonCanonicalBlockOperations(notCanonicalBlockRoots.values()); processCanonicalBlockOperations(nowCanonicalBlockRoots.values()); }); } OperationsReOrgManager(
      OperationPool<ProposerSlashing> proposerSlashingPool,
      OperationPool<AttesterSlashing> attesterSlashingPool,
      OperationPool<SignedVoluntaryExit> exitPool,
      AggregatingAttestationPool attestationPool,
      AttestationManager attestationManager,
      RecentChainData recentChainData); @Override void chainHeadUpdated(
      final UInt64 slot,
      final Bytes32 stateRoot,
      final Bytes32 bestBlockRoot,
      final boolean epochTransition,
      final Optional<ReorgContext> optionalReorgContext);  }