@Test void shouldRequeueAndRemoveOperations() { BeaconBlock fork1Block1 = dataStructureUtil.randomBeaconBlock(10); BeaconBlock fork1Block2 = dataStructureUtil.randomBeaconBlock(11); BeaconBlock fork2Block1 = dataStructureUtil.randomBeaconBlock(12); BeaconBlock fork2Block2 = dataStructureUtil.randomBeaconBlock(13); UInt64 commonAncestorSlot = UInt64.valueOf(9); NavigableMap<UInt64, Bytes32> nowNotCanonicalBlockRoots = new TreeMap<>(); nowNotCanonicalBlockRoots.put(UInt64.valueOf(10), fork1Block1.hash_tree_root()); nowNotCanonicalBlockRoots.put(UInt64.valueOf(11), fork1Block2.hash_tree_root()); when(recentChainData.getAncestorsOnFork(commonAncestorSlot, fork1Block2.hash_tree_root())) .thenReturn(nowNotCanonicalBlockRoots); NavigableMap<UInt64, Bytes32> nowCanonicalBlockRoots = new TreeMap<>(); nowCanonicalBlockRoots.put(UInt64.valueOf(12), fork2Block1.hash_tree_root()); nowCanonicalBlockRoots.put(UInt64.valueOf(13), fork2Block2.hash_tree_root()); when(recentChainData.getAncestorsOnFork(commonAncestorSlot, fork2Block2.hash_tree_root())) .thenReturn(nowCanonicalBlockRoots); when(recentChainData.retrieveBlockByRoot(fork1Block1.hash_tree_root())) .thenReturn(SafeFuture.completedFuture(Optional.of(fork1Block1))); when(recentChainData.retrieveBlockByRoot(fork1Block2.hash_tree_root())) .thenReturn(SafeFuture.completedFuture(Optional.of(fork1Block2))); when(recentChainData.retrieveBlockByRoot(fork2Block1.hash_tree_root())) .thenReturn(SafeFuture.completedFuture(Optional.of(fork2Block1))); when(recentChainData.retrieveBlockByRoot(fork2Block2.hash_tree_root())) .thenReturn(SafeFuture.completedFuture(Optional.of(fork2Block2))); when(attestationManager.onAttestation(any())) .thenReturn(SafeFuture.completedFuture(AttestationProcessingResult.SUCCESSFUL)); operationsReOrgManager.chainHeadUpdated( UInt64.valueOf(13), fork2Block2.getState_root(), fork2Block2.hash_tree_root(), false, ReorgContext.of( fork1Block2.hash_tree_root(), fork1Block2.getState_root(), commonAncestorSlot)); verify(recentChainData).getAncestorsOnFork(commonAncestorSlot, fork1Block2.hash_tree_root()); verify(proposerSlashingOperationPool).addAll(fork1Block1.getBody().getProposer_slashings()); verify(attesterSlashingOperationPool).addAll(fork1Block1.getBody().getAttester_slashings()); verify(exitOperationPool).addAll(fork1Block1.getBody().getVoluntary_exits()); verify(proposerSlashingOperationPool).addAll(fork1Block2.getBody().getProposer_slashings()); verify(attesterSlashingOperationPool).addAll(fork1Block2.getBody().getAttester_slashings()); verify(exitOperationPool).addAll(fork1Block2.getBody().getVoluntary_exits()); ArgumentCaptor<ValidateableAttestation> argument = ArgumentCaptor.forClass(ValidateableAttestation.class); verify(attestationManager, atLeastOnce()).onAttestation(argument.capture()); List<ValidateableAttestation> attestationList = new ArrayList<>(); attestationList.addAll( fork1Block1.getBody().getAttestations().stream() .map(ValidateableAttestation::fromAttestation) .collect(Collectors.toList())); attestationList.addAll( fork1Block2.getBody().getAttestations().stream() .map(ValidateableAttestation::fromAttestation) .collect(Collectors.toList())); assertThat(argument.getAllValues()).containsExactlyInAnyOrderElementsOf(attestationList); verify(proposerSlashingOperationPool).removeAll(fork2Block1.getBody().getProposer_slashings()); verify(attesterSlashingOperationPool).removeAll(fork2Block1.getBody().getAttester_slashings()); verify(exitOperationPool).removeAll(fork2Block1.getBody().getVoluntary_exits()); verify(attestationPool).removeAll(fork2Block1.getBody().getAttestations()); verify(proposerSlashingOperationPool).removeAll(fork2Block2.getBody().getProposer_slashings()); verify(attesterSlashingOperationPool).removeAll(fork2Block2.getBody().getAttester_slashings()); verify(exitOperationPool).removeAll(fork2Block2.getBody().getVoluntary_exits()); verify(attestationPool).removeAll(fork2Block2.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);  }