|
65 | 65 | import org.hyperledger.besu.ethereum.core.MutableWorldState; |
66 | 66 | import org.hyperledger.besu.ethereum.core.TransactionReceipt; |
67 | 67 | import org.hyperledger.besu.ethereum.core.feemarket.CoinbaseFeePriceCalculator; |
| 68 | +import org.hyperledger.besu.ethereum.mainnet.AbstractBlockProcessor.TransactionReceiptFactory; |
68 | 69 | import org.hyperledger.besu.ethereum.mainnet.blockhash.CancunPreExecutionProcessor; |
69 | 70 | import org.hyperledger.besu.ethereum.mainnet.blockhash.FrontierPreExecutionProcessor; |
70 | 71 | import org.hyperledger.besu.ethereum.mainnet.blockhash.PraguePreExecutionProcessor; |
@@ -190,7 +191,7 @@ public static ProtocolSpecBuilder frontierDefinition( |
190 | 191 | (feeMarket, gasCalculator, gasLimitCalculator) -> |
191 | 192 | MainnetBlockHeaderValidator.createLegacyFeeMarketOmmerValidator()) |
192 | 193 | .blockBodyValidatorBuilder(MainnetBlockBodyValidator::new) |
193 | | - .transactionReceiptFactory(MainnetProtocolSpecs::frontierTransactionReceiptFactory) |
| 194 | + .transactionReceiptFactory(new FrontierTransactionReceiptFactory()) |
194 | 195 | .blockReward(FRONTIER_BLOCK_REWARD) |
195 | 196 | .skipZeroBlockRewards(false) |
196 | 197 | .blockProcessorBuilder( |
@@ -348,10 +349,7 @@ public static ProtocolSpecBuilder byzantiumDefinition( |
348 | 349 | .evmBuilder(MainnetEVMs::byzantium) |
349 | 350 | .precompileContractRegistryBuilder(MainnetPrecompiledContractRegistries::byzantium) |
350 | 351 | .difficultyCalculator(MainnetDifficultyCalculators.BYZANTIUM) |
351 | | - .transactionReceiptFactory( |
352 | | - enableRevertReason |
353 | | - ? MainnetProtocolSpecs::byzantiumTransactionReceiptFactoryWithReasonEnabled |
354 | | - : MainnetProtocolSpecs::byzantiumTransactionReceiptFactory) |
| 352 | + .transactionReceiptFactory(new ByzantiumTransactionReceiptFactory(enableRevertReason)) |
355 | 353 | .blockReward(BYZANTIUM_BLOCK_REWARD) |
356 | 354 | .hardforkId(BYZANTIUM); |
357 | 355 | } |
@@ -457,10 +455,7 @@ static ProtocolSpecBuilder berlinDefinition( |
457 | 455 | true, |
458 | 456 | chainId, |
459 | 457 | Set.of(TransactionType.FRONTIER, TransactionType.ACCESS_LIST))) |
460 | | - .transactionReceiptFactory( |
461 | | - enableRevertReason |
462 | | - ? MainnetProtocolSpecs::berlinTransactionReceiptFactoryWithReasonEnabled |
463 | | - : MainnetProtocolSpecs::berlinTransactionReceiptFactory) |
| 458 | + .transactionReceiptFactory(new BerlinTransactionReceiptFactory(enableRevertReason)) |
464 | 459 | .hardforkId(BERLIN); |
465 | 460 | } |
466 | 461 |
|
@@ -1114,63 +1109,84 @@ static ProtocolSpecBuilder experimentalEipsDefinition( |
1114 | 1109 | .hardforkId(EXPERIMENTAL_EIPS); |
1115 | 1110 | } |
1116 | 1111 |
|
1117 | | - private static TransactionReceipt frontierTransactionReceiptFactory( |
1118 | | - // ignored because it's always FRONTIER |
1119 | | - final TransactionType __, |
1120 | | - final TransactionProcessingResult result, |
1121 | | - final WorldState worldState, |
1122 | | - final long gasUsed) { |
1123 | | - return new TransactionReceipt( |
1124 | | - worldState.frontierRootHash(), |
1125 | | - gasUsed, |
1126 | | - result.getLogs(), |
1127 | | - Optional.empty()); // No revert reason in frontier |
1128 | | - } |
| 1112 | + private static class FrontierTransactionReceiptFactory implements TransactionReceiptFactory { |
1129 | 1113 |
|
1130 | | - private static TransactionReceipt byzantiumTransactionReceiptFactory( |
1131 | | - // ignored because it's always FRONTIER |
1132 | | - final TransactionType __, |
1133 | | - final TransactionProcessingResult result, |
1134 | | - final WorldState worldState, |
1135 | | - final long gasUsed) { |
1136 | | - return new TransactionReceipt( |
1137 | | - result.isSuccessful() ? 1 : 0, gasUsed, result.getLogs(), Optional.empty()); |
| 1114 | + @Override |
| 1115 | + public TransactionReceipt create( |
| 1116 | + final TransactionType transactionType, |
| 1117 | + final TransactionProcessingResult result, |
| 1118 | + final WorldState worldState, |
| 1119 | + final long gasUsed) { |
| 1120 | + return new TransactionReceipt( |
| 1121 | + worldState.frontierRootHash(), |
| 1122 | + gasUsed, |
| 1123 | + result.getLogs(), |
| 1124 | + Optional.empty()); // No revert reason in Frontier |
| 1125 | + } |
| 1126 | + |
| 1127 | + @Override |
| 1128 | + public TransactionReceipt create( |
| 1129 | + final TransactionType transactionType, |
| 1130 | + final TransactionProcessingResult result, |
| 1131 | + final long gasUsed) { |
| 1132 | + throw new UnsupportedOperationException("No stateless transaction receipt in Frontier"); |
| 1133 | + } |
1138 | 1134 | } |
1139 | 1135 |
|
1140 | | - private static TransactionReceipt byzantiumTransactionReceiptFactoryWithReasonEnabled( |
1141 | | - // ignored because it's always FRONTIER |
1142 | | - final TransactionType __, |
1143 | | - final TransactionProcessingResult result, |
1144 | | - final WorldState worldState, |
1145 | | - final long gasUsed) { |
1146 | | - return new TransactionReceipt( |
1147 | | - result.isSuccessful() ? 1 : 0, gasUsed, result.getLogs(), result.getRevertReason()); |
| 1136 | + private abstract static class PostFrontierTransactionReceiptFactory |
| 1137 | + implements TransactionReceiptFactory { |
| 1138 | + protected final boolean revertReasonEnabled; |
| 1139 | + |
| 1140 | + public PostFrontierTransactionReceiptFactory(final boolean revertReasonEnabled) { |
| 1141 | + this.revertReasonEnabled = revertReasonEnabled; |
| 1142 | + } |
| 1143 | + |
| 1144 | + @Override |
| 1145 | + public TransactionReceipt create( |
| 1146 | + final TransactionType transactionType, |
| 1147 | + final TransactionProcessingResult result, |
| 1148 | + final WorldState worldState, |
| 1149 | + final long gasUsed) { |
| 1150 | + return create(transactionType, result, gasUsed); |
| 1151 | + } |
1148 | 1152 | } |
1149 | 1153 |
|
1150 | | - static TransactionReceipt berlinTransactionReceiptFactory( |
1151 | | - final TransactionType transactionType, |
1152 | | - final TransactionProcessingResult transactionProcessingResult, |
1153 | | - final WorldState worldState, |
1154 | | - final long gasUsed) { |
1155 | | - return new TransactionReceipt( |
1156 | | - transactionType, |
1157 | | - transactionProcessingResult.isSuccessful() ? 1 : 0, |
1158 | | - gasUsed, |
1159 | | - transactionProcessingResult.getLogs(), |
1160 | | - Optional.empty()); |
| 1154 | + static class ByzantiumTransactionReceiptFactory extends PostFrontierTransactionReceiptFactory { |
| 1155 | + public ByzantiumTransactionReceiptFactory(final boolean revertReasonEnabled) { |
| 1156 | + super(revertReasonEnabled); |
| 1157 | + } |
| 1158 | + |
| 1159 | + @Override |
| 1160 | + public TransactionReceipt create( |
| 1161 | + final TransactionType transactionType, |
| 1162 | + final TransactionProcessingResult result, |
| 1163 | + final long gasUsed) { |
| 1164 | + return new TransactionReceipt( |
| 1165 | + result.isSuccessful() ? 1 : 0, |
| 1166 | + gasUsed, |
| 1167 | + result.getLogs(), |
| 1168 | + revertReasonEnabled ? result.getRevertReason() : Optional.empty()); |
| 1169 | + } |
1161 | 1170 | } |
1162 | 1171 |
|
1163 | | - static TransactionReceipt berlinTransactionReceiptFactoryWithReasonEnabled( |
1164 | | - final TransactionType transactionType, |
1165 | | - final TransactionProcessingResult transactionProcessingResult, |
1166 | | - final WorldState worldState, |
1167 | | - final long gasUsed) { |
1168 | | - return new TransactionReceipt( |
1169 | | - transactionType, |
1170 | | - transactionProcessingResult.isSuccessful() ? 1 : 0, |
1171 | | - gasUsed, |
1172 | | - transactionProcessingResult.getLogs(), |
1173 | | - transactionProcessingResult.getRevertReason()); |
| 1172 | + static class BerlinTransactionReceiptFactory extends PostFrontierTransactionReceiptFactory { |
| 1173 | + |
| 1174 | + public BerlinTransactionReceiptFactory(final boolean revertReasonEnabled) { |
| 1175 | + super(revertReasonEnabled); |
| 1176 | + } |
| 1177 | + |
| 1178 | + @Override |
| 1179 | + public TransactionReceipt create( |
| 1180 | + final TransactionType transactionType, |
| 1181 | + final TransactionProcessingResult result, |
| 1182 | + final long gasUsed) { |
| 1183 | + return new TransactionReceipt( |
| 1184 | + transactionType, |
| 1185 | + result.isSuccessful() ? 1 : 0, |
| 1186 | + gasUsed, |
| 1187 | + result.getLogs(), |
| 1188 | + revertReasonEnabled ? result.getRevertReason() : Optional.empty()); |
| 1189 | + } |
1174 | 1190 | } |
1175 | 1191 |
|
1176 | 1192 | private record DaoBlockProcessor(BlockProcessor wrapped) implements BlockProcessor { |
|
0 commit comments