diff --git a/beacon/validator/src/main/java/tech/pegasys/teku/validator/coordinator/ExecutionPayloadHeaderFactory.java b/beacon/validator/src/main/java/tech/pegasys/teku/validator/coordinator/ExecutionPayloadHeaderFactory.java index 0b711366219..2a9a4df04f2 100644 --- a/beacon/validator/src/main/java/tech/pegasys/teku/validator/coordinator/ExecutionPayloadHeaderFactory.java +++ b/beacon/validator/src/main/java/tech/pegasys/teku/validator/coordinator/ExecutionPayloadHeaderFactory.java @@ -13,6 +13,8 @@ package tech.pegasys.teku.validator.coordinator; +import static tech.pegasys.teku.infrastructure.logging.Converter.weiToGwei; + import java.util.Optional; import org.apache.tuweni.bytes.Bytes32; import tech.pegasys.teku.bls.BLSPublicKey; @@ -110,6 +112,7 @@ private ExecutionPayloadHeader createLocalBid( schemaDefinitions .getBlobKzgCommitmentsSchema() .createFromBlobsBundle(getPayloadResponse.getBlobsBundle().orElseThrow()); + // convert Wei to Gwei return schemaDefinitions .getExecutionPayloadHeaderSchema() .createExecutionPayloadHeader( @@ -121,9 +124,7 @@ private ExecutionPayloadHeader createLocalBid( .gasLimit(getPayloadResponse.getExecutionPayload().getGasLimit()) .builderIndex(() -> builderIndex) .slot(() -> slot) - .value( - () -> - UInt64.valueOf(getPayloadResponse.getExecutionPayloadValue().toLong())) + .value(() -> weiToGwei(getPayloadResponse.getExecutionPayloadValue())) .blobKzgCommitmentsRoot(blobKzgCommitments::hashTreeRoot)); } } diff --git a/beacon/validator/src/main/java/tech/pegasys/teku/validator/coordinator/duties/AttesterDutiesGenerator.java b/beacon/validator/src/main/java/tech/pegasys/teku/validator/coordinator/duties/AttesterDutiesGenerator.java index 2045ecf8466..b7badf0b660 100644 --- a/beacon/validator/src/main/java/tech/pegasys/teku/validator/coordinator/duties/AttesterDutiesGenerator.java +++ b/beacon/validator/src/main/java/tech/pegasys/teku/validator/coordinator/duties/AttesterDutiesGenerator.java @@ -106,7 +106,7 @@ private List createPayloadAttesterDuties( final List payloadAttesterDutyList = new ArrayList<>(); final Int2ObjectMap validatorIndexToCommitteeAssignmentMap = - spec.getValidatorIndexToPctAssignmentMap(state, epoch); + spec.getValidatorIndexToPtcAssignmentMap(state, epoch); for (final int validatorIndex : validatorIndices) { final UInt64 slot = validatorIndexToCommitteeAssignmentMap.get(validatorIndex); if (slot != null) { diff --git a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/Spec.java b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/Spec.java index a129a9c531d..b6e34a7b758 100644 --- a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/Spec.java +++ b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/Spec.java @@ -933,9 +933,9 @@ public Int2ObjectMap getValidatorIndexToCommitteeAssignment .getValidatorIndexToCommitteeAssignmentMap(state, epoch); } - public Int2ObjectMap getValidatorIndexToPctAssignmentMap( + public Int2ObjectMap getValidatorIndexToPtcAssignmentMap( final BeaconState state, final UInt64 epoch) { - return atEpoch(epoch).getValidatorsUtil().getValidatorIndexToPctAssignmentMap(state, epoch); + return atEpoch(epoch).getValidatorsUtil().getValidatorIndexToPtcAssignmentMap(state, epoch); } // Attestation helpers diff --git a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/logic/common/util/ValidatorsUtil.java b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/logic/common/util/ValidatorsUtil.java index c8226b57d71..236aed4c473 100644 --- a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/logic/common/util/ValidatorsUtil.java +++ b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/logic/common/util/ValidatorsUtil.java @@ -127,7 +127,7 @@ public Optional getPtcAssignment( return Optional.empty(); } - public Int2ObjectMap getValidatorIndexToPctAssignmentMap( + public Int2ObjectMap getValidatorIndexToPtcAssignmentMap( final BeaconState state, final UInt64 epoch) { final Int2ObjectMap assignmentMap = new Int2ObjectArrayMap<>(); diff --git a/ethereum/statetransition/src/main/java/tech/pegasys/teku/statetransition/execution/ExecutionPayloadHeaderPool.java b/ethereum/statetransition/src/main/java/tech/pegasys/teku/statetransition/execution/ExecutionPayloadHeaderPool.java index 705aaae157b..b4534fabcb5 100644 --- a/ethereum/statetransition/src/main/java/tech/pegasys/teku/statetransition/execution/ExecutionPayloadHeaderPool.java +++ b/ethereum/statetransition/src/main/java/tech/pegasys/teku/statetransition/execution/ExecutionPayloadHeaderPool.java @@ -16,6 +16,8 @@ import java.util.List; import java.util.Optional; import java.util.Set; +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; @@ -25,12 +27,14 @@ import tech.pegasys.teku.spec.datastructures.execution.SignedExecutionPayloadHeader; import tech.pegasys.teku.spec.datastructures.execution.versions.eip7732.ExecutionPayloadHeaderEip7732; import tech.pegasys.teku.spec.datastructures.state.beaconstate.BeaconState; +import tech.pegasys.teku.spec.logic.common.operations.validation.OperationInvalidReason; import tech.pegasys.teku.statetransition.OperationAddedSubscriber; import tech.pegasys.teku.statetransition.validation.InternalValidationResult; import tech.pegasys.teku.statetransition.validation.OperationValidator; import tech.pegasys.teku.statetransition.validation.ValidationResultCode; public class ExecutionPayloadHeaderPool implements SlotEventsChannel { + private static final Logger LOG = LogManager.getLogger(); // builders can broadcast a bid for only the current or the next slot, so no need to keep bids for // a long time in the pool @@ -77,10 +81,14 @@ public Optional selectBidForBlock( }) .toList(); for (SignedExecutionPayloadHeader bid : applicableBids) { - if (operationValidator.validateForBlockInclusion(stateAtBlockSlot, bid).isEmpty()) { + final Optional blockInclusionValidation = + operationValidator.validateForBlockInclusion(stateAtBlockSlot, bid); + if (blockInclusionValidation.isEmpty()) { return Optional.of(bid); } else { - // The item is no longer valid to be included in a block so remove it from the pool. + LOG.warn( + "Bid is not valid to be included in a block: {}. Removing it from the pool.", + blockInclusionValidation.get().describe()); remove(bid); } } diff --git a/ethereum/statetransition/src/main/java/tech/pegasys/teku/statetransition/validation/ExecutionPayloadHeaderValidator.java b/ethereum/statetransition/src/main/java/tech/pegasys/teku/statetransition/validation/ExecutionPayloadHeaderValidator.java index c82102e5330..70f52de84b8 100644 --- a/ethereum/statetransition/src/main/java/tech/pegasys/teku/statetransition/validation/ExecutionPayloadHeaderValidator.java +++ b/ethereum/statetransition/src/main/java/tech/pegasys/teku/statetransition/validation/ExecutionPayloadHeaderValidator.java @@ -133,7 +133,7 @@ public SafeFuture validateForGossip( final Optional parentBlockHash = recentChainData.getExecutionBlockHashForBlockRoot(header.getParentBlockRoot()); if (parentBlockHash.isEmpty() - || header.getParentBlockHash().equals(parentBlockHash.get())) { + || !header.getParentBlockHash().equals(parentBlockHash.get())) { return InternalValidationResult.IGNORE; } /* diff --git a/infrastructure/logging/src/main/java/tech/pegasys/teku/infrastructure/logging/Converter.java b/infrastructure/logging/src/main/java/tech/pegasys/teku/infrastructure/logging/Converter.java index 8b71a4b94d1..ded65f7b580 100644 --- a/infrastructure/logging/src/main/java/tech/pegasys/teku/infrastructure/logging/Converter.java +++ b/infrastructure/logging/src/main/java/tech/pegasys/teku/infrastructure/logging/Converter.java @@ -14,9 +14,12 @@ package tech.pegasys.teku.infrastructure.logging; import java.math.BigDecimal; +import java.math.BigInteger; import java.math.RoundingMode; import org.apache.tuweni.units.bigints.UInt256; import org.web3j.utils.Convert; +import org.web3j.utils.Convert.Unit; +import tech.pegasys.teku.infrastructure.unsigned.UInt64; public class Converter { @@ -28,8 +31,19 @@ public static String weiToEth(final UInt256 wei) { } public static String gweiToEth(final UInt256 gwei) { - return new BigDecimal(gwei.toBigInteger()) - .divide(gweiToEthFactor, 6, RoundingMode.HALF_UP) - .toString(); + return gweiToEth(new BigDecimal(gwei.toBigInteger())); + } + + public static String gweiToEth(final UInt64 gwei) { + return gweiToEth(new BigDecimal(gwei.bigIntegerValue())); + } + + public static UInt64 weiToGwei(final UInt256 wei) { + final BigInteger gwei = Convert.fromWei(wei.toDecimalString(), Unit.GWEI).toBigInteger(); + return UInt64.valueOf(gwei); + } + + private static String gweiToEth(final BigDecimal gwei) { + return gwei.divide(gweiToEthFactor, 6, RoundingMode.HALF_UP).toString(); } } diff --git a/infrastructure/logging/src/main/java/tech/pegasys/teku/infrastructure/logging/ValidatorLogger.java b/infrastructure/logging/src/main/java/tech/pegasys/teku/infrastructure/logging/ValidatorLogger.java index 684f7bd9f31..924545e528c 100644 --- a/infrastructure/logging/src/main/java/tech/pegasys/teku/infrastructure/logging/ValidatorLogger.java +++ b/infrastructure/logging/src/main/java/tech/pegasys/teku/infrastructure/logging/ValidatorLogger.java @@ -170,12 +170,16 @@ private String formatBlockRoots(final Set blockRoots) { return blockRoots.stream().map(LogFormatter::formatHashRoot).collect(Collectors.joining(", ")); } - public void logPublishedBid(final UInt64 slot, final UInt64 builderIndex, final String ethValue) { + public void logPublishedBid( + final UInt64 slot, + final UInt64 builderIndex, + final Bytes32 parentBlockRoot, + final String ethValue) { log.info( ColorConsolePrinter.print( String.format( - "%sPublished bid Slot: %s, Builder: %s, Value: %s ETH", - PREFIX, slot, builderIndex, ethValue), + "%sPublished bid Slot: %s, Builder: %s, Parent Block Root: %s, Value: %s ETH", + PREFIX, slot, builderIndex, parentBlockRoot, ethValue), Color.CYAN)); } diff --git a/infrastructure/logging/src/test/java/tech/pegasys/teku/infrastructure/logging/ConverterTest.java b/infrastructure/logging/src/test/java/tech/pegasys/teku/infrastructure/logging/ConverterTest.java index aada49e6276..ca1d89e2d0d 100644 --- a/infrastructure/logging/src/test/java/tech/pegasys/teku/infrastructure/logging/ConverterTest.java +++ b/infrastructure/logging/src/test/java/tech/pegasys/teku/infrastructure/logging/ConverterTest.java @@ -20,21 +20,37 @@ import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.Arguments; import org.junit.jupiter.params.provider.MethodSource; +import tech.pegasys.teku.infrastructure.unsigned.UInt64; class ConverterTest { @ParameterizedTest - @MethodSource("getUInt256Values") - void test(final UInt256 wei, final String expected) { + @MethodSource("getWeiToEthArguments") + void testWeiToEth(final UInt256 wei, final String expected) { String output = Converter.weiToEth(wei); assertThat(output).isEqualTo(expected); } - private static Stream getUInt256Values() { + @ParameterizedTest + @MethodSource("getWeiToGweiArguments") + void testWeiToGwei(final UInt256 wei, final UInt64 expected) { + UInt64 output = Converter.weiToGwei(wei); + assertThat(output).isEqualTo(expected); + } + + private static Stream getWeiToEthArguments() { return Stream.of( Arguments.of(UInt256.valueOf(1), "0.000000"), Arguments.of(UInt256.valueOf(1000), "0.000000"), Arguments.of(UInt256.valueOf(3401220000000000L), "0.003401"), Arguments.of(UInt256.valueOf(889999203452340000L), "0.889999")); } + + private static Stream getWeiToGweiArguments() { + return Stream.of( + Arguments.of(UInt256.valueOf(1), UInt64.valueOf(0)), + Arguments.of(UInt256.valueOf(1000), UInt64.valueOf(0)), + Arguments.of(UInt256.valueOf(3401220000000000L), UInt64.valueOf(3401220)), + Arguments.of(UInt256.valueOf(889999203452340000L), UInt64.valueOf(889999203))); + } } diff --git a/validator/client/src/main/java/tech/pegasys/teku/validator/client/duties/BlockProductionDuty.java b/validator/client/src/main/java/tech/pegasys/teku/validator/client/duties/BlockProductionDuty.java index d013a7e7e4d..5158eac7532 100644 --- a/validator/client/src/main/java/tech/pegasys/teku/validator/client/duties/BlockProductionDuty.java +++ b/validator/client/src/main/java/tech/pegasys/teku/validator/client/duties/BlockProductionDuty.java @@ -24,7 +24,6 @@ import java.util.Optional; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; -import org.apache.tuweni.units.bigints.UInt256; import tech.pegasys.teku.bls.BLSSignature; import tech.pegasys.teku.infrastructure.async.SafeFuture; import tech.pegasys.teku.infrastructure.metrics.Validator.DutyType; @@ -161,7 +160,8 @@ private SafeFuture processExecutionPayloadHeader( VALIDATOR_LOGGER.logPublishedBid( bid.getSlot(), bid.getBuilderIndex(), - gweiToEth(UInt256.valueOf(bid.getValue().longValue()))); + bid.getParentBlockRoot(), + gweiToEth(bid.getValue())); }); }