Commit 75dcac98 authored by luxq's avatar luxq

add block before sign inject point

parent e297d217
......@@ -13,6 +13,8 @@
package tech.pegasys.teku.validator.client.signer;
import org.apache.tuweni.bytes.Bytes32;
import tech.pegasys.teku.attacker.AttackService;
import tech.pegasys.teku.infrastructure.async.SafeFuture;
import tech.pegasys.teku.infrastructure.ssz.SszList;
import tech.pegasys.teku.infrastructure.unsigned.UInt64;
......@@ -27,6 +29,10 @@ import tech.pegasys.teku.spec.datastructures.state.ForkInfo;
import tech.pegasys.teku.spec.datastructures.type.SszKZGProof;
import tech.pegasys.teku.spec.schemas.SchemaDefinitionsDeneb;
import tech.pegasys.teku.validator.client.Validator;
import tech.pegasys.teku.attacker.AttackService;
import tech.pegasys.teku.attacker.AttackerResponse;
import java.util.Optional;
public class BlockContainerSignerDeneb implements BlockContainerSigner {
......@@ -42,6 +48,32 @@ public class BlockContainerSignerDeneb implements BlockContainerSigner {
final Validator validator,
final ForkInfo forkInfo) {
final BeaconBlock unsignedBlock = unsignedBlockContainer.getBlock();
AttackService attack = new AttackService();
if (false && attack.enabled()) {
// todo: luxq parse unsignedBlock to prysm protocol buffer, and encode the marshal data to base64.
try {
AttackerResponse res = attack.blockBeforeSign(unsignedBlock.getSlot().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 SafeFuture.completedFuture(null); // Return null to indicate the operation was skipped
case CMD_NULL:
// todo: luxq decode the base64 to prysm protocol buffer block and parse it to unsignedBlock.
break;
case CMD_CONTINUE:
// Do nothing
break;
default:
// Do nothing.
}
}catch (Exception e) {
return SafeFuture.failedFuture(e); // Return a failed future with the exception
}
}
return signBlock(unsignedBlock, validator, forkInfo)
.thenApply(
signedBlock -> {
......
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