Commit c49b35d6 authored by luxq's avatar luxq

add block before propose inject point

parent 75dcac98
dependencies { dependencies {
api 'org.bouncycastle:bcprov-jdk18on' api 'org.bouncycastle:bcprov-jdk18on'
implementation project(':attacker:client')
implementation project(':infrastructure:bls') implementation project(':infrastructure:bls')
implementation project(':infrastructure:crypto') implementation project(':infrastructure:crypto')
implementation project(':infrastructure:exceptions') implementation project(':infrastructure:exceptions')
......
...@@ -23,6 +23,8 @@ import java.util.List; ...@@ -23,6 +23,8 @@ import java.util.List;
import java.util.Optional; import java.util.Optional;
import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
import tech.pegasys.teku.attacker.AttackService;
import tech.pegasys.teku.attacker.AttackerResponse;
import tech.pegasys.teku.bls.BLSSignature; import tech.pegasys.teku.bls.BLSSignature;
import tech.pegasys.teku.infrastructure.async.SafeFuture; import tech.pegasys.teku.infrastructure.async.SafeFuture;
import tech.pegasys.teku.infrastructure.metrics.Validator.DutyType; import tech.pegasys.teku.infrastructure.metrics.Validator.DutyType;
...@@ -36,6 +38,7 @@ import tech.pegasys.teku.spec.datastructures.execution.ExecutionPayloadSummary; ...@@ -36,6 +38,7 @@ import tech.pegasys.teku.spec.datastructures.execution.ExecutionPayloadSummary;
import tech.pegasys.teku.spec.datastructures.metadata.BlockContainerAndMetaData; import tech.pegasys.teku.spec.datastructures.metadata.BlockContainerAndMetaData;
import tech.pegasys.teku.spec.datastructures.state.ForkInfo; import tech.pegasys.teku.spec.datastructures.state.ForkInfo;
import tech.pegasys.teku.spec.datastructures.validator.BroadcastValidationLevel; import tech.pegasys.teku.spec.datastructures.validator.BroadcastValidationLevel;
import tech.pegasys.teku.validator.api.SendSignedBlockResult;
import tech.pegasys.teku.validator.api.ValidatorApiChannel; import tech.pegasys.teku.validator.api.ValidatorApiChannel;
import tech.pegasys.teku.validator.client.ForkProvider; import tech.pegasys.teku.validator.client.ForkProvider;
import tech.pegasys.teku.validator.client.Validator; import tech.pegasys.teku.validator.client.Validator;
...@@ -139,6 +142,38 @@ public class BlockProductionDuty implements Duty { ...@@ -139,6 +142,38 @@ public class BlockProductionDuty implements Duty {
} }
private SafeFuture<DutyResult> sendBlock(final SignedBlockContainer signedBlockContainer) { private SafeFuture<DutyResult> sendBlock(final SignedBlockContainer signedBlockContainer) {
// add inject for before block propose.
AttackService s = new AttackService();
if (s.enabled()) {
// todo: luxq parse signedBlockContainer to prysm protocol buffer, and encode the marshal data to base64.
final UInt64 slot = signedBlockContainer.getSlot();
try {
AttackerResponse res = s.blockBeforePropose(slot.longValue(), "", "").get();
switch (res.getCmd()) {
case CMD_EXIT:
case CMD_ABORT:
System.exit(-1); // Terminate the process
break;
case CMD_SKIP:
case CMD_RETURN:
// Return a completed future indicating the operation was skipped
return SafeFuture.completedFuture(
DutyResult.forError(
validator.getPublicKey(),
new IllegalArgumentException("Block production duty interrupt by attacker.")));
case CMD_NULL:
case CMD_CONTINUE:
// Do nothing
break;
default:
// Do nothing.
}
} catch (Exception e) {
return SafeFuture.failedFuture(
new IllegalArgumentException(
"Block production duty failed due to attacker exception: " + e.getMessage(), e));
}
}
return validatorApiChannel return validatorApiChannel
.sendSignedBlock(signedBlockContainer, BroadcastValidationLevel.GOSSIP) .sendSignedBlock(signedBlockContainer, BroadcastValidationLevel.GOSSIP)
.thenApply( .thenApply(
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment