From a8712d75bca5ba4371f5605e31420e2d7f796c6e Mon Sep 17 00:00:00 2001 From: Fabio Di Fabio Date: Tue, 7 Jan 2025 14:45:00 +0100 Subject: [PATCH] Creating blocks before Byzantium hard fork is not supported anymore Signed-off-by: Fabio Di Fabio --- .../mainnet/AbstractBlockProcessor.java | 28 +++++++++++++- .../mainnet/MainnetProtocolSpecs.java | 38 +++++++++++++------ 2 files changed, 53 insertions(+), 13 deletions(-) diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/AbstractBlockProcessor.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/AbstractBlockProcessor.java index 993478fe50c..a2d032ac393 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/AbstractBlockProcessor.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/AbstractBlockProcessor.java @@ -52,12 +52,38 @@ public abstract class AbstractBlockProcessor implements BlockProcessor { @FunctionalInterface public interface TransactionReceiptFactory { - + /** + * Use to create a receipt for a transaction during block processing. + * + * @param transactionType the transaction type + * @param result the transaction processing result + * @param worldState the world state updated with the execution of this transaction, that is + * used to calculate the forestStateRoot if needed + * @param gasUsed the gas used by the transaction + * @return the transaction receipt + */ TransactionReceipt create( TransactionType transactionType, TransactionProcessingResult result, WorldState worldState, long gasUsed); + + /** + * Use to create a receipt for a transaction selected during block creation. Conversely to the + * other method, world state here is not required, since creating block for hard forks that + * require the calculation of the forestStateRoot is not supported anymore. + * + * @param transactionType the transaction type + * @param result the transaction processing result + * @param gasUsed the gas used by the transaction + * @return the transaction receipt + */ + default TransactionReceipt create( + final TransactionType transactionType, + final TransactionProcessingResult result, + final long gasUsed) { + return create(transactionType, result, null, gasUsed); + } } private static final Logger LOG = LoggerFactory.getLogger(AbstractBlockProcessor.class); diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/MainnetProtocolSpecs.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/MainnetProtocolSpecs.java index af71df1ab5a..36a8b3f152f 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/MainnetProtocolSpecs.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/MainnetProtocolSpecs.java @@ -34,6 +34,7 @@ import org.hyperledger.besu.ethereum.core.TransactionReceipt; import org.hyperledger.besu.ethereum.core.Withdrawal; import org.hyperledger.besu.ethereum.core.feemarket.CoinbaseFeePriceCalculator; +import org.hyperledger.besu.ethereum.mainnet.AbstractBlockProcessor.TransactionReceiptFactory; import org.hyperledger.besu.ethereum.mainnet.ProtocolSpecBuilder.BlockValidatorBuilder; import org.hyperledger.besu.ethereum.mainnet.blockhash.CancunBlockHashProcessor; import org.hyperledger.besu.ethereum.mainnet.blockhash.FrontierBlockHashProcessor; @@ -163,7 +164,7 @@ public static ProtocolSpecBuilder frontierDefinition( .ommerHeaderValidatorBuilder( feeMarket -> MainnetBlockHeaderValidator.createLegacyFeeMarketOmmerValidator()) .blockBodyValidatorBuilder(MainnetBlockBodyValidator::new) - .transactionReceiptFactory(MainnetProtocolSpecs::frontierTransactionReceiptFactory) + .transactionReceiptFactory(frontierTransactionReceiptFactory()) .blockReward(FRONTIER_BLOCK_REWARD) .skipZeroBlockRewards(false) .blockProcessorBuilder( @@ -1016,17 +1017,30 @@ static ProtocolSpecBuilder experimentalEipsDefinition( .name("ExperimentalEips"); } - private static TransactionReceipt frontierTransactionReceiptFactory( - // ignored because it's always FRONTIER - final TransactionType __, - final TransactionProcessingResult result, - final WorldState worldState, - final long gasUsed) { - return new TransactionReceipt( - worldState.frontierRootHash(), - gasUsed, - result.getLogs(), - Optional.empty()); // No revert reason in frontier + private static TransactionReceiptFactory frontierTransactionReceiptFactory() { + return new TransactionReceiptFactory() { + @Override + public TransactionReceipt create( + final TransactionType transactionType, + final TransactionProcessingResult result, + final WorldState worldState, + final long gasUsed) { + return new TransactionReceipt( + worldState.frontierRootHash(), + gasUsed, + result.getLogs(), + Optional.empty()); // No revert reason in frontier + } + + @Override + public TransactionReceipt create( + final TransactionType transactionType, + final TransactionProcessingResult result, + final long gasUsed) { + throw new UnsupportedOperationException( + "Creating blocks before Byzantium hard fork is not supported anymore"); + } + }; } private static TransactionReceipt byzantiumTransactionReceiptFactory(