Skip to content

Commit

Permalink
Merge branch 'master' into seedLookahead
Browse files Browse the repository at this point in the history
  • Loading branch information
rolfyone authored Mar 6, 2025
2 parents 8416bda + 9166dec commit 5addb1e
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,13 @@
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.concurrent.RejectedExecutionException;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.tuweni.bytes.Bytes32;
import tech.pegasys.teku.ethereum.events.SlotEventsChannel;
import tech.pegasys.teku.infrastructure.async.SafeFuture;
import tech.pegasys.teku.infrastructure.exceptions.ExceptionUtil;
import tech.pegasys.teku.infrastructure.logging.EventLogger;
import tech.pegasys.teku.infrastructure.subscribers.Subscribers;
import tech.pegasys.teku.infrastructure.time.TimeProvider;
Expand Down Expand Up @@ -312,15 +314,31 @@ private SafeFuture<BlockImportResult> handleBlockImport(
case DOES_NOT_DESCEND_FROM_LATEST_FINALIZED,
FAILED_STATE_TRANSITION,
FAILED_WEAK_SUBJECTIVITY_CHECKS,
DESCENDANT_OF_INVALID_BLOCK,
INTERNAL_ERROR:
DESCENDANT_OF_INVALID_BLOCK:
logFailedBlockImport(block, result.getFailureReason());
dropInvalidBlock(block, result);
break;
case INTERNAL_ERROR:
logFailedBlockImport(block, result.getFailureReason());
if (result
.getFailureCause()
.map(this::internalErrorToBeConsiderAsInvalidBlock)
.orElse(false)) {
dropInvalidBlock(block, result);
}
}
}
});
}

private boolean internalErrorToBeConsiderAsInvalidBlock(final Throwable internalError) {
if (internalError instanceof RejectedExecutionException
|| ExceptionUtil.hasCause(internalError, RejectedExecutionException.class)) {
return false;
}
return true;
}

private void logFailedBlockImport(
final SignedBeaconBlock block, final FailureReason failureReason) {
LOG.trace("Unable to import block for reason {}: {}", failureReason, block);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
import java.util.Map;
import java.util.Optional;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.RejectedExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import org.apache.tuweni.bytes.Bytes32;
Expand Down Expand Up @@ -414,6 +415,42 @@ public void onGossipedBlock_unattachedFutureBlock() {
assertThat(pendingBlocks.contains(nextNextBlock)).isTrue();
}

@Test
public void onGossipedBlock_onKnownInternalErrorsShouldNotMarkAsInvalid() {
final RecentChainData localRecentChainData = mock(RecentChainData.class);
blockManager = setupBlockManagerWithMockRecentChainData(localRecentChainData, false);

final UInt64 nextSlot = GENESIS_SLOT.plus(UInt64.ONE);
final SignedBeaconBlock nextBlock =
localChain.chainBuilder().generateBlockAtSlot(nextSlot).getBlock();
incrementSlot();

doAnswer(invocation -> SafeFuture.failedFuture(new RejectedExecutionException("full")))
.when(asyncRunner)
.runAsync((ExceptionThrowingFutureSupplier<?>) any());

assertThatBlockImport(nextBlock).isCompletedWithValueMatching(result -> !result.isSuccessful());
assertThat(invalidBlockRoots).isEmpty();
}

@Test
public void onGossipedBlock_onInternalErrorsShouldMarkAsInvalid() {
final RecentChainData localRecentChainData = mock(RecentChainData.class);
blockManager = setupBlockManagerWithMockRecentChainData(localRecentChainData, false);

final UInt64 nextSlot = GENESIS_SLOT.plus(UInt64.ONE);
final SignedBeaconBlock nextBlock =
localChain.chainBuilder().generateBlockAtSlot(nextSlot).getBlock();
incrementSlot();

doAnswer(invocation -> SafeFuture.failedFuture(new RuntimeException("unknown")))
.when(asyncRunner)
.runAsync((ExceptionThrowingFutureSupplier<?>) any());

assertThatBlockImport(nextBlock).isCompletedWithValueMatching(result -> !result.isSuccessful());
assertThat(invalidBlockRoots).containsOnlyKeys(nextBlock.getRoot());
}

@Test
public void onProposedBlock_shouldImport() {
final UInt64 nextSlot = GENESIS_SLOT.plus(UInt64.ONE);
Expand Down

0 comments on commit 5addb1e

Please sign in to comment.