diff --git a/besu/src/test/java/org/hyperledger/besu/cli/TxPoolOptionsTest.java b/besu/src/test/java/org/hyperledger/besu/cli/TxPoolOptionsTest.java index 8389ab5bae8..a5ca07484a0 100644 --- a/besu/src/test/java/org/hyperledger/besu/cli/TxPoolOptionsTest.java +++ b/besu/src/test/java/org/hyperledger/besu/cli/TxPoolOptionsTest.java @@ -30,7 +30,6 @@ import java.nio.file.Files; import java.nio.file.Path; -import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; public class TxPoolOptionsTest extends CommandTestAbstract { @@ -98,7 +97,6 @@ public void txpoolSaveFileAbsolutePathOutsideDataPath() throws IOException { } @Test - @Disabled // Failing in CI, but not locally public void txpoolForcePriceBumpToZeroWhenZeroBaseFeeMarket() throws IOException { final Path genesisFile = createFakeGenesisFile(GENESIS_WITH_ZERO_BASE_FEE_MARKET); parseCommand("--genesis-file", genesisFile.toString()); diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/chain/DefaultBlockchain.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/chain/DefaultBlockchain.java index 1b210490740..b2b4e6abfc8 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/chain/DefaultBlockchain.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/chain/DefaultBlockchain.java @@ -116,6 +116,37 @@ private DefaultBlockchain( chainHeadTransactionCount = chainHeadBody.getTransactions().size(); chainHeadOmmerCount = chainHeadBody.getOmmers().size(); + this.reorgLoggingThreshold = reorgLoggingThreshold; + this.blockChoiceRule = heaviestChainBlockChoiceRule; + this.numberOfBlocksToCache = numberOfBlocksToCache; + + if (numberOfBlocksToCache != 0) { + blockHeadersCache = + Optional.of( + CacheBuilder.newBuilder().recordStats().maximumSize(numberOfBlocksToCache).build()); + blockBodiesCache = + Optional.of( + CacheBuilder.newBuilder().recordStats().maximumSize(numberOfBlocksToCache).build()); + transactionReceiptsCache = + Optional.of( + CacheBuilder.newBuilder().recordStats().maximumSize(numberOfBlocksToCache).build()); + totalDifficultyCache = + Optional.of( + CacheBuilder.newBuilder().recordStats().maximumSize(numberOfBlocksToCache).build()); + CacheMetricsCollector cacheMetrics = new CacheMetricsCollector(); + cacheMetrics.addCache("blockHeaders", blockHeadersCache.get()); + cacheMetrics.addCache("blockBodies", blockBodiesCache.get()); + cacheMetrics.addCache("transactionReceipts", transactionReceiptsCache.get()); + cacheMetrics.addCache("totalDifficulty", totalDifficultyCache.get()); + if (metricsSystem instanceof PrometheusMetricsSystem prometheusMetricsSystem) + prometheusMetricsSystem.addCollector(BesuMetricCategory.BLOCKCHAIN, () -> cacheMetrics); + } else { + blockHeadersCache = Optional.empty(); + blockBodiesCache = Optional.empty(); + transactionReceiptsCache = Optional.empty(); + totalDifficultyCache = Optional.empty(); + } + metricsSystem.createLongGauge( BesuMetricCategory.ETHEREUM, "blockchain_height", @@ -179,37 +210,6 @@ private DefaultBlockchain( "chain_head_ommer_count", "Number of ommers in the current chain head block", () -> chainHeadOmmerCount); - - this.reorgLoggingThreshold = reorgLoggingThreshold; - this.blockChoiceRule = heaviestChainBlockChoiceRule; - this.numberOfBlocksToCache = numberOfBlocksToCache; - - if (numberOfBlocksToCache != 0) { - blockHeadersCache = - Optional.of( - CacheBuilder.newBuilder().recordStats().maximumSize(numberOfBlocksToCache).build()); - blockBodiesCache = - Optional.of( - CacheBuilder.newBuilder().recordStats().maximumSize(numberOfBlocksToCache).build()); - transactionReceiptsCache = - Optional.of( - CacheBuilder.newBuilder().recordStats().maximumSize(numberOfBlocksToCache).build()); - totalDifficultyCache = - Optional.of( - CacheBuilder.newBuilder().recordStats().maximumSize(numberOfBlocksToCache).build()); - CacheMetricsCollector cacheMetrics = new CacheMetricsCollector(); - cacheMetrics.addCache("blockHeaders", blockHeadersCache.get()); - cacheMetrics.addCache("blockBodies", blockBodiesCache.get()); - cacheMetrics.addCache("transactionReceipts", transactionReceiptsCache.get()); - cacheMetrics.addCache("totalDifficulty", totalDifficultyCache.get()); - if (metricsSystem instanceof PrometheusMetricsSystem prometheusMetricsSystem) - prometheusMetricsSystem.addCollector(BesuMetricCategory.BLOCKCHAIN, () -> cacheMetrics); - } else { - blockHeadersCache = Optional.empty(); - blockBodiesCache = Optional.empty(); - transactionReceiptsCache = Optional.empty(); - totalDifficultyCache = Optional.empty(); - } } public static MutableBlockchain createMutable( diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/MainnetTransactionValidator.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/MainnetTransactionValidator.java index b5fbf7340b2..e67ccbb4c62 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/MainnetTransactionValidator.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/MainnetTransactionValidator.java @@ -132,42 +132,59 @@ public ValidationResult validate( } if (transactionType == TransactionType.DELEGATE_CODE) { - if (isDelegateCodeEmpty(transaction)) { - return ValidationResult.invalid( - TransactionInvalidReason.EMPTY_CODE_DELEGATION, - "transaction code delegation transactions must have a non-empty code delegation list"); + ValidationResult codeDelegationValidation = + validateCodeDelegation(transaction); + if (!codeDelegationValidation.isValid()) { + return codeDelegationValidation; } + } + + return validateCostAndFee(transaction, baseFee, blobFee, transactionValidationParams); + } - final BigInteger halfCurveOrder = SignatureAlgorithmFactory.getInstance().getHalfCurveOrder(); - final Optional> validationResult = - transaction - .getCodeDelegationList() - .map( - codeDelegations -> { - for (CodeDelegation codeDelegation : codeDelegations) { - if (codeDelegation.signature().getS().compareTo(halfCurveOrder) > 0) { - return ValidationResult.invalid( - TransactionInvalidReason.INVALID_SIGNATURE, - "Invalid signature for code delegation. S value must be less or equal than the half curve order."); - } - - if (codeDelegation.signature().getRecId() != 0 - && codeDelegation.signature().getRecId() != 1) { - return ValidationResult.invalid( - TransactionInvalidReason.INVALID_SIGNATURE, - "Invalid signature for code delegation. RecId value must be 0 or 1."); - } + private static ValidationResult validateCodeDelegation( + final Transaction transaction) { + if (isDelegateCodeEmpty(transaction)) { + return ValidationResult.invalid( + TransactionInvalidReason.EMPTY_CODE_DELEGATION, + "transaction code delegation transactions must have a non-empty code delegation list"); + } + + if (transaction.getTo().isEmpty()) { + return ValidationResult.invalid( + TransactionInvalidReason.INVALID_TRANSACTION_FORMAT, + "transaction code delegation transactions must have a to address"); + } + + final BigInteger halfCurveOrder = SignatureAlgorithmFactory.getInstance().getHalfCurveOrder(); + final Optional> validationResult = + transaction + .getCodeDelegationList() + .map( + codeDelegations -> { + for (CodeDelegation codeDelegation : codeDelegations) { + if (codeDelegation.signature().getS().compareTo(halfCurveOrder) > 0) { + return ValidationResult.invalid( + TransactionInvalidReason.INVALID_SIGNATURE, + "Invalid signature for code delegation. S value must be less or equal than the half curve order."); } - return ValidationResult.valid(); - }); + if (codeDelegation.signature().getRecId() != 0 + && codeDelegation.signature().getRecId() != 1) { + return ValidationResult.invalid( + TransactionInvalidReason.INVALID_SIGNATURE, + "Invalid signature for code delegation. RecId value must be 0 or 1."); + } + } - if (validationResult.isPresent() && !validationResult.get().isValid()) { - return validationResult.get(); - } + return ValidationResult.valid(); + }); + + if (validationResult.isPresent() && !validationResult.get().isValid()) { + return validationResult.get(); } - return validateCostAndFee(transaction, baseFee, blobFee, transactionValidationParams); + return ValidationResult.valid(); } private static boolean isDelegateCodeEmpty(final Transaction transaction) {