[Cleanup] Remove Gas Budget Calculator (#2363)

Since there are no separate gas budgets for eip-1559 and non-eip-1559 txs,
we can return to the simpler method of just comparing against the gas limit.

This is a non-functional change.

Signed-off-by: Ratan Rai Sur <ratan.r.sur@gmail.com>
pull/2392/head
Ratan (Rai) Sur 4 years ago committed by GitHub
parent 51287459ab
commit de6c10d17f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 3
      ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetTransactionReceiptTest.java
  2. 2
      ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/results/tracing/flat/RewardTraceGeneratorTest.java
  3. 11
      ethereum/blockcreation/src/main/java/org/hyperledger/besu/ethereum/blockcreation/AbstractBlockCreator.java
  4. 30
      ethereum/blockcreation/src/main/java/org/hyperledger/besu/ethereum/blockcreation/BlockTransactionSelector.java
  5. 51
      ethereum/blockcreation/src/test/java/org/hyperledger/besu/ethereum/blockcreation/BlockTransactionSelectorTest.java
  6. 45
      ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/fees/TransactionGasBudgetCalculator.java
  7. 3
      ethereum/core/src/main/java/org/hyperledger/besu/ethereum/goquorum/GoQuorumBlockProcessor.java
  8. 10
      ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/AbstractBlockProcessor.java
  9. 4
      ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/ClassicBlockProcessor.java
  10. 1
      ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/ClassicProtocolSpecs.java
  11. 5
      ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/MainnetBlockProcessor.java
  12. 2
      ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/MainnetProtocolSpecs.java
  13. 15
      ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/ProtocolSpec.java
  14. 12
      ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/ProtocolSpecBuilder.java
  15. 97
      ethereum/core/src/test/java/org/hyperledger/besu/ethereum/core/fees/TransactionGasBudgetCalculatorTest.java
  16. 4
      ethereum/core/src/test/java/org/hyperledger/besu/ethereum/goquorum/GoQuorumBlockProcessorTest.java
  17. 3
      ethereum/core/src/test/java/org/hyperledger/besu/ethereum/mainnet/MainnetBlockProcessorTest.java
  18. 3
      ethereum/retesteth/src/main/java/org/hyperledger/besu/ethereum/retesteth/NoRewardProtocolScheduleWrapper.java

@ -33,7 +33,6 @@ import org.hyperledger.besu.ethereum.core.Hash;
import org.hyperledger.besu.ethereum.core.Transaction;
import org.hyperledger.besu.ethereum.core.TransactionReceipt;
import org.hyperledger.besu.ethereum.core.Wei;
import org.hyperledger.besu.ethereum.core.fees.TransactionGasBudgetCalculator;
import org.hyperledger.besu.ethereum.core.fees.TransactionPriceCalculator;
import org.hyperledger.besu.ethereum.mainnet.PoWHasher;
import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule;
@ -105,7 +104,6 @@ public class EthGetTransactionReceiptTest {
null,
TransactionPriceCalculator.frontier(),
Optional.empty(),
TransactionGasBudgetCalculator.frontier(),
null,
Optional.of(PoWHasher.ETHASH_LIGHT));
private final ProtocolSpec statusTransactionTypeSpec =
@ -131,7 +129,6 @@ public class EthGetTransactionReceiptTest {
null,
TransactionPriceCalculator.frontier(),
Optional.empty(),
TransactionGasBudgetCalculator.frontier(),
null,
Optional.of(PoWHasher.ETHASH_LIGHT));

@ -25,7 +25,6 @@ import org.hyperledger.besu.ethereum.core.BlockBody;
import org.hyperledger.besu.ethereum.core.BlockDataGenerator;
import org.hyperledger.besu.ethereum.core.BlockHeader;
import org.hyperledger.besu.ethereum.core.Wei;
import org.hyperledger.besu.ethereum.core.fees.TransactionGasBudgetCalculator;
import org.hyperledger.besu.ethereum.mainnet.AbstractBlockProcessor;
import org.hyperledger.besu.ethereum.mainnet.ClassicBlockProcessor;
import org.hyperledger.besu.ethereum.mainnet.MainnetBlockProcessor;
@ -93,7 +92,6 @@ public class RewardTraceGeneratorTest {
blockReward,
BlockHeader::getCoinbase,
true,
TransactionGasBudgetCalculator.frontier(),
Optional.empty());
when(protocolSpec.getBlockProcessor()).thenReturn(blockProcessor);

@ -219,17 +219,12 @@ public abstract class AbstractBlockCreator implements AsyncBlockCreator {
minBlockOccupancyRatio,
isCancelled::get,
miningBeneficiary,
protocolSpec.getTransactionPriceCalculator(),
protocolSpec.getGasBudgetCalculator());
protocolSpec.getTransactionPriceCalculator());
if (transactions.isPresent()) {
return selector.evaluateTransactions(
processableBlockHeader.getNumber(),
processableBlockHeader.getGasLimit(),
transactions.get());
return selector.evaluateTransactions(transactions.get());
} else {
return selector.buildTransactionListForBlock(
processableBlockHeader.getNumber(), processableBlockHeader.getGasLimit());
return selector.buildTransactionListForBlock();
}
}

@ -23,7 +23,6 @@ import org.hyperledger.besu.ethereum.core.Transaction;
import org.hyperledger.besu.ethereum.core.TransactionReceipt;
import org.hyperledger.besu.ethereum.core.Wei;
import org.hyperledger.besu.ethereum.core.WorldUpdater;
import org.hyperledger.besu.ethereum.core.fees.TransactionGasBudgetCalculator;
import org.hyperledger.besu.ethereum.core.fees.TransactionPriceCalculator;
import org.hyperledger.besu.ethereum.eth.transactions.PendingTransactions;
import org.hyperledger.besu.ethereum.eth.transactions.PendingTransactions.TransactionSelectionResult;
@ -107,7 +106,6 @@ public class BlockTransactionSelector {
private final AbstractBlockProcessor.TransactionReceiptFactory transactionReceiptFactory;
private final Address miningBeneficiary;
private final TransactionPriceCalculator transactionPriceCalculator;
private final TransactionGasBudgetCalculator transactionGasBudgetCalculator;
private final TransactionSelectionResults transactionSelectionResult =
new TransactionSelectionResults();
@ -123,8 +121,7 @@ public class BlockTransactionSelector {
final Double minBlockOccupancyRatio,
final Supplier<Boolean> isCancelled,
final Address miningBeneficiary,
final TransactionPriceCalculator transactionPriceCalculator,
final TransactionGasBudgetCalculator transactionGasBudgetCalculator) {
final TransactionPriceCalculator transactionPriceCalculator) {
this.transactionProcessor = transactionProcessor;
this.blockchain = blockchain;
this.worldState = worldState;
@ -136,7 +133,6 @@ public class BlockTransactionSelector {
this.minBlockOccupancyRatio = minBlockOccupancyRatio;
this.miningBeneficiary = miningBeneficiary;
this.transactionPriceCalculator = transactionPriceCalculator;
this.transactionGasBudgetCalculator = transactionGasBudgetCalculator;
}
/*
@ -145,24 +141,20 @@ public class BlockTransactionSelector {
If running in a thread, it can be cancelled via the isCancelled supplier (which will result
in this throwing an CancellationException).
*/
public TransactionSelectionResults buildTransactionListForBlock(
final long blockNumber, final long gasLimit) {
public TransactionSelectionResults buildTransactionListForBlock() {
pendingTransactions.selectTransactions(
pendingTransaction -> evaluateTransaction(blockNumber, gasLimit, pendingTransaction));
pendingTransaction -> evaluateTransaction(pendingTransaction));
return transactionSelectionResult;
}
/**
* Evaluate the given transactions and return the result of that evaluation.
*
* @param blockNumber The block number.
* @param gasLimit The gas limit.
* @param transactions The set of transactions to evaluate.
* @return The {@code TransactionSelectionResults} results of transaction evaluation.
*/
public TransactionSelectionResults evaluateTransactions(
final long blockNumber, final long gasLimit, final List<Transaction> transactions) {
transactions.forEach(transaction -> evaluateTransaction(blockNumber, gasLimit, transaction));
public TransactionSelectionResults evaluateTransactions(final List<Transaction> transactions) {
transactions.forEach(this::evaluateTransaction);
return transactionSelectionResult;
}
@ -175,13 +167,12 @@ public class BlockTransactionSelector {
* the space remaining in the block.
*
*/
private TransactionSelectionResult evaluateTransaction(
final long blockNumber, final long gasLimit, final Transaction transaction) {
private TransactionSelectionResult evaluateTransaction(final Transaction transaction) {
if (isCancelled.get()) {
throw new CancellationException("Cancelled during transaction selection.");
}
if (transactionTooLargeForBlock(blockNumber, gasLimit, transaction)) {
if (transactionTooLargeForBlock(transaction)) {
LOG.trace("{} too large to select for block creation", transaction);
if (blockOccupancyAboveThreshold()) {
return TransactionSelectionResult.COMPLETE_OPERATION;
@ -310,10 +301,9 @@ public class BlockTransactionSelector {
ValidationResult.valid());
}
private boolean transactionTooLargeForBlock(
final long blockNumber, final long gasLimit, final Transaction transaction) {
return !transactionGasBudgetCalculator.hasBudget(
transaction, blockNumber, gasLimit, transactionSelectionResult.cumulativeGasUsed);
private boolean transactionTooLargeForBlock(final Transaction transaction) {
return transaction.getGasLimit()
> processableBlockHeader.getGasLimit() - transactionSelectionResult.getCumulativeGasUsed();
}
private boolean blockOccupancyAboveThreshold() {

@ -40,7 +40,6 @@ import org.hyperledger.besu.ethereum.core.TransactionTestFixture;
import org.hyperledger.besu.ethereum.core.Wei;
import org.hyperledger.besu.ethereum.core.WorldState;
import org.hyperledger.besu.ethereum.core.WorldUpdater;
import org.hyperledger.besu.ethereum.core.fees.TransactionGasBudgetCalculator;
import org.hyperledger.besu.ethereum.core.fees.TransactionPriceCalculator;
import org.hyperledger.besu.ethereum.difficulty.fixed.FixedDifficultyProtocolSchedule;
import org.hyperledger.besu.ethereum.eth.transactions.PendingTransactions;
@ -133,11 +132,10 @@ public class BlockTransactionSelectorTest {
0.8,
this::isCancelled,
miningBeneficiary,
TransactionPriceCalculator.frontier(),
TransactionGasBudgetCalculator.frontier());
TransactionPriceCalculator.frontier());
final BlockTransactionSelector.TransactionSelectionResults results =
selector.buildTransactionListForBlock(blockHeader.getNumber(), blockHeader.getGasLimit());
selector.buildTransactionListForBlock();
assertThat(results.getTransactions().size()).isEqualTo(0);
assertThat(results.getReceipts().size()).isEqualTo(0);
@ -171,11 +169,10 @@ public class BlockTransactionSelectorTest {
0.8,
this::isCancelled,
miningBeneficiary,
TransactionPriceCalculator.frontier(),
TransactionGasBudgetCalculator.frontier());
TransactionPriceCalculator.frontier());
final BlockTransactionSelector.TransactionSelectionResults results =
selector.buildTransactionListForBlock(blockHeader.getNumber(), blockHeader.getGasLimit());
selector.buildTransactionListForBlock();
assertThat(results.getTransactions().size()).isEqualTo(1);
Assertions.assertThat(results.getTransactions()).contains(transaction);
@ -227,11 +224,10 @@ public class BlockTransactionSelectorTest {
0.8,
this::isCancelled,
miningBeneficiary,
TransactionPriceCalculator.frontier(),
TransactionGasBudgetCalculator.frontier());
TransactionPriceCalculator.frontier());
final BlockTransactionSelector.TransactionSelectionResults results =
selector.buildTransactionListForBlock(blockHeader.getNumber(), blockHeader.getGasLimit());
selector.buildTransactionListForBlock();
assertThat(results.getTransactions().size()).isEqualTo(4);
assertThat(results.getTransactions().contains(transactionsToInject.get(1))).isFalse();
@ -271,11 +267,10 @@ public class BlockTransactionSelectorTest {
0.8,
this::isCancelled,
miningBeneficiary,
TransactionPriceCalculator.frontier(),
TransactionGasBudgetCalculator.frontier());
TransactionPriceCalculator.frontier());
final BlockTransactionSelector.TransactionSelectionResults results =
selector.buildTransactionListForBlock(blockHeader.getNumber(), blockHeader.getGasLimit());
selector.buildTransactionListForBlock();
assertThat(results.getTransactions().size()).isEqualTo(3);
@ -306,14 +301,13 @@ public class BlockTransactionSelectorTest {
0.8,
this::isCancelled,
miningBeneficiary,
TransactionPriceCalculator.frontier(),
TransactionGasBudgetCalculator.frontier());
TransactionPriceCalculator.frontier());
final Transaction tx = createTransaction(1);
pendingTransactions.addRemoteTransaction(tx);
final BlockTransactionSelector.TransactionSelectionResults results =
selector.buildTransactionListForBlock(blockHeader.getNumber(), blockHeader.getGasLimit());
selector.buildTransactionListForBlock();
assertThat(results.getTransactions().size()).isEqualTo(0);
assertThat(pendingTransactions.size()).isEqualTo(0);
@ -336,8 +330,7 @@ public class BlockTransactionSelectorTest {
0.8,
this::isCancelled,
miningBeneficiary,
TransactionPriceCalculator.eip1559(),
TransactionGasBudgetCalculator.frontier());
TransactionPriceCalculator.eip1559());
// this should fill up all the block space
final Transaction fillingLegacyTx =
@ -376,7 +369,7 @@ public class BlockTransactionSelectorTest {
pendingTransactions.addRemoteTransaction(fillingLegacyTx);
pendingTransactions.addRemoteTransaction(extraEIP1559Tx);
final BlockTransactionSelector.TransactionSelectionResults results =
selector.buildTransactionListForBlock(blockHeader.getNumber(), blockHeader.getGasLimit());
selector.buildTransactionListForBlock();
assertThat(results.getTransactions().size()).isEqualTo(1);
}
@ -404,8 +397,7 @@ public class BlockTransactionSelectorTest {
0.8,
this::isCancelled,
miningBeneficiary,
TransactionPriceCalculator.frontier(),
TransactionGasBudgetCalculator.frontier());
TransactionPriceCalculator.frontier());
final TransactionTestFixture txTestFixture = new TransactionTestFixture();
// Add 3 transactions to the Pending Transactions, 79% of block, 100% of block and 10% of block
@ -430,7 +422,7 @@ public class BlockTransactionSelectorTest {
}
final BlockTransactionSelector.TransactionSelectionResults results =
selector.buildTransactionListForBlock(blockHeader.getNumber(), blockHeader.getGasLimit());
selector.buildTransactionListForBlock();
assertThat(results.getTransactions().size()).isEqualTo(2);
Assertions.assertThat(results.getTransactions().get(0)).isEqualTo(transactionsToInject.get(0));
@ -461,8 +453,7 @@ public class BlockTransactionSelectorTest {
0.8,
this::isCancelled,
miningBeneficiary,
TransactionPriceCalculator.frontier(),
TransactionGasBudgetCalculator.frontier());
TransactionPriceCalculator.frontier());
final TransactionTestFixture txTestFixture = new TransactionTestFixture();
// Add 4 transactions to the Pending Transactions 15% (ok), 79% (ok), 25% (too large), 10%
@ -496,7 +487,7 @@ public class BlockTransactionSelectorTest {
pendingTransactions.addRemoteTransaction(transaction4);
final BlockTransactionSelector.TransactionSelectionResults results =
selector.buildTransactionListForBlock(blockHeader.getNumber(), blockHeader.getGasLimit());
selector.buildTransactionListForBlock();
assertThat(results.getTransactions().size()).isEqualTo(2);
Assertions.assertThat(results.getTransactions().get(0)).isEqualTo(transaction1);
@ -522,8 +513,7 @@ public class BlockTransactionSelectorTest {
0.8,
this::isCancelled,
miningBeneficiary,
TransactionPriceCalculator.frontier(),
TransactionGasBudgetCalculator.frontier());
TransactionPriceCalculator.frontier());
final TransactionTestFixture txTestFixture = new TransactionTestFixture();
final Transaction validTransaction =
@ -559,7 +549,7 @@ public class BlockTransactionSelectorTest {
TransactionProcessingResult.invalid(
ValidationResult.invalid(TransactionInvalidReason.EXCEEDS_BLOCK_GAS_LIMIT)));
selector.buildTransactionListForBlock(blockHeader.getNumber(), blockHeader.getGasLimit());
selector.buildTransactionListForBlock();
Assertions.assertThat(pendingTransactions.getTransactionByHash(validTransaction.getHash()))
.isPresent();
@ -603,11 +593,10 @@ public class BlockTransactionSelectorTest {
0.8,
this::isCancelled,
miningBeneficiary,
TransactionPriceCalculator.frontier(),
TransactionGasBudgetCalculator.frontier());
TransactionPriceCalculator.frontier());
final BlockTransactionSelector.TransactionSelectionResults results =
selector.buildTransactionListForBlock(blockHeader.getNumber(), blockHeader.getGasLimit());
selector.buildTransactionListForBlock();
Assertions.assertThat(pendingTransactions.getTransactionByHash(futureTransaction.getHash()))
.isPresent();

@ -1,45 +0,0 @@
/*
* Copyright ConsenSys AG.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*
* SPDX-License-Identifier: Apache-2.0
*/
package org.hyperledger.besu.ethereum.core.fees;
import org.hyperledger.besu.ethereum.core.Transaction;
@FunctionalInterface
public interface TransactionGasBudgetCalculator {
boolean hasBudget(
final Transaction transaction,
final long blockNumber,
final long gasLimit,
final long gasUsed);
static TransactionGasBudgetCalculator frontier() {
return gasBudgetCalculator((blockNumber, gasLimit, ignored) -> gasLimit);
}
static TransactionGasBudgetCalculator gasBudgetCalculator(
final BlockGasLimitCalculator blockGasLimitCalculator) {
return (transaction, blockNumber, gasLimit, gasUsed) -> {
final long remainingGasBudget =
blockGasLimitCalculator.apply(blockNumber, gasLimit, transaction) - gasUsed;
return Long.compareUnsigned(transaction.getGasLimit(), remainingGasBudget) <= 0;
};
}
@FunctionalInterface
interface BlockGasLimitCalculator {
long apply(final long blockNumber, final long gasLimit, Transaction transaction);
}
}

@ -29,7 +29,6 @@ import org.hyperledger.besu.ethereum.core.Transaction;
import org.hyperledger.besu.ethereum.core.TransactionReceipt;
import org.hyperledger.besu.ethereum.core.Wei;
import org.hyperledger.besu.ethereum.core.WorldUpdater;
import org.hyperledger.besu.ethereum.core.fees.TransactionGasBudgetCalculator;
import org.hyperledger.besu.ethereum.mainnet.AbstractBlockProcessor;
import org.hyperledger.besu.ethereum.mainnet.MainnetBlockProcessor;
import org.hyperledger.besu.ethereum.mainnet.MainnetTransactionProcessor;
@ -65,7 +64,6 @@ public class GoQuorumBlockProcessor extends MainnetBlockProcessor {
final Wei blockReward,
final MiningBeneficiaryCalculator miningBeneficiaryCalculator,
final boolean skipZeroBlockRewards,
final TransactionGasBudgetCalculator gasBudgetCalculator,
final Optional<GoQuorumPrivacyParameters> goQuorumPrivacyParameters) {
super(
transactionProcessor,
@ -73,7 +71,6 @@ public class GoQuorumBlockProcessor extends MainnetBlockProcessor {
blockReward,
miningBeneficiaryCalculator,
skipZeroBlockRewards,
gasBudgetCalculator,
Optional.empty());
this.goQuorumEnclave = goQuorumPrivacyParameters.orElseThrow().enclave();

@ -25,7 +25,6 @@ import org.hyperledger.besu.ethereum.core.TransactionReceipt;
import org.hyperledger.besu.ethereum.core.Wei;
import org.hyperledger.besu.ethereum.core.WorldState;
import org.hyperledger.besu.ethereum.core.WorldUpdater;
import org.hyperledger.besu.ethereum.core.fees.TransactionGasBudgetCalculator;
import org.hyperledger.besu.ethereum.privacy.storage.PrivateMetadataUpdater;
import org.hyperledger.besu.ethereum.processing.TransactionProcessingResult;
import org.hyperledger.besu.ethereum.vm.BlockHashLookup;
@ -125,21 +124,17 @@ public abstract class AbstractBlockProcessor implements BlockProcessor {
protected final MiningBeneficiaryCalculator miningBeneficiaryCalculator;
protected final TransactionGasBudgetCalculator gasBudgetCalculator;
protected AbstractBlockProcessor(
final MainnetTransactionProcessor transactionProcessor,
final TransactionReceiptFactory transactionReceiptFactory,
final Wei blockReward,
final MiningBeneficiaryCalculator miningBeneficiaryCalculator,
final boolean skipZeroBlockRewards,
final TransactionGasBudgetCalculator gasBudgetCalculator) {
final boolean skipZeroBlockRewards) {
this.transactionProcessor = transactionProcessor;
this.transactionReceiptFactory = transactionReceiptFactory;
this.blockReward = blockReward;
this.miningBeneficiaryCalculator = miningBeneficiaryCalculator;
this.skipZeroBlockRewards = skipZeroBlockRewards;
this.gasBudgetCalculator = gasBudgetCalculator;
}
@Override
@ -210,9 +205,8 @@ public abstract class AbstractBlockProcessor implements BlockProcessor {
protected boolean hasAvailableBlockBudget(
final BlockHeader blockHeader, final Transaction transaction, final long currentGasUsed) {
if (!gasBudgetCalculator.hasBudget(
transaction, blockHeader.getNumber(), blockHeader.getGasLimit(), currentGasUsed)) {
final long remainingGasBudget = blockHeader.getGasLimit() - currentGasUsed;
if (Long.compareUnsigned(transaction.getGasLimit(), remainingGasBudget) > 0) {
LOG.info(
"Block processing error: transaction gas limit {} exceeds available block budget"
+ " remaining {}. Block {} Transaction {}",

@ -19,7 +19,6 @@ import org.hyperledger.besu.ethereum.core.MutableAccount;
import org.hyperledger.besu.ethereum.core.MutableWorldState;
import org.hyperledger.besu.ethereum.core.Wei;
import org.hyperledger.besu.ethereum.core.WorldUpdater;
import org.hyperledger.besu.ethereum.core.fees.TransactionGasBudgetCalculator;
import java.math.BigInteger;
import java.util.List;
@ -48,8 +47,7 @@ public class ClassicBlockProcessor extends AbstractBlockProcessor {
transactionReceiptFactory,
blockReward,
miningBeneficiaryCalculator,
skipZeroBlockRewards,
TransactionGasBudgetCalculator.frontier());
skipZeroBlockRewards);
eraLength = eraLen.orElse(DEFAULT_ERA_LENGTH);
}

@ -91,7 +91,6 @@ public class ClassicProtocolSpecs {
blockReward,
miningBeneficiaryCalculator,
skipZeroBlockRewards,
gasBudgetCalculator,
goQuorumPrivacyParameters) ->
new ClassicBlockProcessor(
transactionProcessor,

@ -21,7 +21,6 @@ import org.hyperledger.besu.ethereum.core.MutableAccount;
import org.hyperledger.besu.ethereum.core.MutableWorldState;
import org.hyperledger.besu.ethereum.core.Wei;
import org.hyperledger.besu.ethereum.core.WorldUpdater;
import org.hyperledger.besu.ethereum.core.fees.TransactionGasBudgetCalculator;
import java.util.List;
import java.util.Optional;
@ -39,15 +38,13 @@ public class MainnetBlockProcessor extends AbstractBlockProcessor {
final Wei blockReward,
final MiningBeneficiaryCalculator miningBeneficiaryCalculator,
final boolean skipZeroBlockRewards,
final TransactionGasBudgetCalculator gasBudgetCalculator,
final Optional<GoQuorumPrivacyParameters> goQuorumPrivacyParameters) {
super(
transactionProcessor,
transactionReceiptFactory,
blockReward,
miningBeneficiaryCalculator,
skipZeroBlockRewards,
gasBudgetCalculator);
skipZeroBlockRewards);
}
@Override

@ -225,7 +225,6 @@ public abstract class MainnetProtocolSpecs {
blockReward,
miningBeneficiaryCalculator,
skipZeroBlockRewards,
gasBudgetCalculator,
goQuorumPrivacyParameters) ->
new DaoBlockProcessor(
new MainnetBlockProcessor(
@ -234,7 +233,6 @@ public abstract class MainnetProtocolSpecs {
blockReward,
miningBeneficiaryCalculator,
skipZeroBlockRewards,
gasBudgetCalculator,
Optional.empty())))
.name("DaoRecoveryInit");
}

@ -20,7 +20,6 @@ import org.hyperledger.besu.ethereum.core.BlockHeaderFunctions;
import org.hyperledger.besu.ethereum.core.BlockImporter;
import org.hyperledger.besu.ethereum.core.Wei;
import org.hyperledger.besu.ethereum.core.fees.EIP1559;
import org.hyperledger.besu.ethereum.core.fees.TransactionGasBudgetCalculator;
import org.hyperledger.besu.ethereum.core.fees.TransactionPriceCalculator;
import org.hyperledger.besu.ethereum.privacy.PrivateTransactionProcessor;
import org.hyperledger.besu.ethereum.vm.EVM;
@ -72,8 +71,6 @@ public class ProtocolSpec {
private final Optional<EIP1559> eip1559;
private final TransactionGasBudgetCalculator gasBudgetCalculator;
private final BadBlockManager badBlockManager;
private final Optional<PoWHasher> powHasher;
@ -102,7 +99,6 @@ public class ProtocolSpec {
* @param gasCalculator the gas calculator to use.
* @param transactionPriceCalculator the transaction price calculator to use.
* @param eip1559 an {@link Optional} wrapping {@link EIP1559} manager class if appropriate.
* @param gasBudgetCalculator the gas budget calculator to use.
* @param badBlockManager the cache to use to keep invalid blocks
* @param powHasher the proof-of-work hasher
*/
@ -128,7 +124,6 @@ public class ProtocolSpec {
final GasCalculator gasCalculator,
final TransactionPriceCalculator transactionPriceCalculator,
final Optional<EIP1559> eip1559,
final TransactionGasBudgetCalculator gasBudgetCalculator,
final BadBlockManager badBlockManager,
final Optional<PoWHasher> powHasher) {
this.name = name;
@ -152,7 +147,6 @@ public class ProtocolSpec {
this.gasCalculator = gasCalculator;
this.transactionPriceCalculator = transactionPriceCalculator;
this.eip1559 = eip1559;
this.gasBudgetCalculator = gasBudgetCalculator;
this.badBlockManager = badBlockManager;
this.powHasher = powHasher;
}
@ -337,15 +331,6 @@ public class ProtocolSpec {
return eip1559.isPresent();
}
/**
* Returns the gas budget calculator in this specification.
*
* @return the gas budget calculator
*/
public TransactionGasBudgetCalculator getGasBudgetCalculator() {
return gasBudgetCalculator;
}
/**
* Returns the bad blocks manager
*

@ -26,7 +26,6 @@ import org.hyperledger.besu.ethereum.core.GoQuorumPrivacyParameters;
import org.hyperledger.besu.ethereum.core.PrivacyParameters;
import org.hyperledger.besu.ethereum.core.Wei;
import org.hyperledger.besu.ethereum.core.fees.EIP1559;
import org.hyperledger.besu.ethereum.core.fees.TransactionGasBudgetCalculator;
import org.hyperledger.besu.ethereum.core.fees.TransactionPriceCalculator;
import org.hyperledger.besu.ethereum.mainnet.precompiles.privacy.OnChainPrivacyPrecompiledContract;
import org.hyperledger.besu.ethereum.mainnet.precompiles.privacy.PrivacyPrecompiledContract;
@ -69,8 +68,6 @@ public class ProtocolSpecBuilder {
private TransactionPriceCalculator transactionPriceCalculator =
TransactionPriceCalculator.frontier();
private Optional<EIP1559> eip1559 = Optional.empty();
private TransactionGasBudgetCalculator gasBudgetCalculator =
TransactionGasBudgetCalculator.frontier();
private BadBlockManager badBlockManager;
private PoWHasher powHasher = PoWHasher.ETHASH_LIGHT;
@ -228,12 +225,6 @@ public class ProtocolSpecBuilder {
return this;
}
public ProtocolSpecBuilder gasBudgetCalculator(
final TransactionGasBudgetCalculator gasBudgetCalculator) {
this.gasBudgetCalculator = gasBudgetCalculator;
return this;
}
public ProtocolSpecBuilder badBlocksManager(final BadBlockManager badBlockManager) {
this.badBlockManager = badBlockManager;
return this;
@ -301,7 +292,6 @@ public class ProtocolSpecBuilder {
blockReward,
miningBeneficiaryCalculator,
skipZeroBlockRewards,
gasBudgetCalculator,
privacyParameters.getGoQuorumPrivacyParameters());
// Set private Tx Processor
PrivateTransactionProcessor privateTransactionProcessor = null;
@ -369,7 +359,6 @@ public class ProtocolSpecBuilder {
gasCalculator,
transactionPriceCalculator,
eip1559,
gasBudgetCalculator,
badBlockManager,
Optional.ofNullable(powHasher));
}
@ -402,7 +391,6 @@ public class ProtocolSpecBuilder {
Wei blockReward,
MiningBeneficiaryCalculator miningBeneficiaryCalculator,
boolean skipZeroBlockRewards,
TransactionGasBudgetCalculator gasBudgetCalculator,
Optional<GoQuorumPrivacyParameters> goQuorumPrivacyParameters);
}

@ -1,97 +0,0 @@
/*
* Copyright ConsenSys AG.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*
* SPDX-License-Identifier: Apache-2.0
*/
package org.hyperledger.besu.ethereum.core.fees;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import org.hyperledger.besu.ethereum.core.Transaction;
import org.hyperledger.besu.plugin.data.TransactionType;
import java.util.Arrays;
import java.util.Collection;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
@RunWith(Parameterized.class)
public class TransactionGasBudgetCalculatorTest {
private static final TransactionGasBudgetCalculator FRONTIER_CALCULATOR =
TransactionGasBudgetCalculator.frontier();
private final TransactionGasBudgetCalculator gasBudgetCalculator;
private final boolean isEIP1559;
private final long transactionGasLimit;
private final long blockNumber;
private final long blockHeaderGasLimit;
private final long gasUsed;
private final boolean expectedHasBudget;
public TransactionGasBudgetCalculatorTest(
final TransactionGasBudgetCalculator gasBudgetCalculator,
final boolean isEIP1559,
final long transactionGasLimit,
final long blockNumber,
final long blockHeaderGasLimit,
final long gasUsed,
final boolean expectedHasBudget) {
this.gasBudgetCalculator = gasBudgetCalculator;
this.isEIP1559 = isEIP1559;
this.transactionGasLimit = transactionGasLimit;
this.blockNumber = blockNumber;
this.blockHeaderGasLimit = blockHeaderGasLimit;
this.gasUsed = gasUsed;
this.expectedHasBudget = expectedHasBudget;
}
@Parameterized.Parameters
public static Collection<Object[]> data() {
return Arrays.asList(
new Object[][] {
{FRONTIER_CALCULATOR, false, 5L, 1L, 10L, 0L, true},
{FRONTIER_CALCULATOR, false, 11L, 1L, 10L, 0L, false},
{FRONTIER_CALCULATOR, false, 5L, 1L, 10L, 6L, false},
{FRONTIER_CALCULATOR, true, 5L, 1L, 10L, 0L, true},
{FRONTIER_CALCULATOR, true, 11L, 1L, 10L, 0L, false},
{FRONTIER_CALCULATOR, true, 5L, 1L, 10L, 6L, false},
});
}
@Test
public void assertThatCalculatorWorks() {
assertThat(
gasBudgetCalculator.hasBudget(
transaction(isEIP1559, transactionGasLimit),
blockNumber,
blockHeaderGasLimit,
gasUsed))
.isEqualTo(expectedHasBudget);
}
private Transaction transaction(final boolean isEIP1559, final long gasLimit) {
final Transaction transaction = mock(Transaction.class);
if (isEIP1559) {
when(transaction.getType()).thenReturn(TransactionType.EIP1559);
} else {
when(transaction.getType()).thenReturn(TransactionType.FRONTIER);
}
when(transaction.getGasLimit()).thenReturn(gasLimit);
return transaction;
}
}

@ -34,7 +34,6 @@ import org.hyperledger.besu.ethereum.core.Hash;
import org.hyperledger.besu.ethereum.core.MutableWorldState;
import org.hyperledger.besu.ethereum.core.Transaction;
import org.hyperledger.besu.ethereum.core.Wei;
import org.hyperledger.besu.ethereum.core.fees.TransactionGasBudgetCalculator;
import org.hyperledger.besu.ethereum.mainnet.AbstractBlockProcessor;
import org.hyperledger.besu.ethereum.mainnet.MainnetTransactionProcessor;
import org.hyperledger.besu.ethereum.referencetests.ReferenceTestBlockchain;
@ -68,7 +67,6 @@ public class GoQuorumBlockProcessorTest {
Wei.ZERO,
BlockHeader::getCoinbase,
true,
TransactionGasBudgetCalculator.frontier(),
Optional.of(goQuorumPrivacyParameters));
final MutableWorldState worldState = ReferenceTestWorldState.create(emptyMap());
@ -95,7 +93,6 @@ public class GoQuorumBlockProcessorTest {
Wei.ZERO,
BlockHeader::getCoinbase,
false,
TransactionGasBudgetCalculator.frontier(),
Optional.of(goQuorumPrivacyParameters));
final MutableWorldState worldState = ReferenceTestWorldState.create(emptyMap());
@ -122,7 +119,6 @@ public class GoQuorumBlockProcessorTest {
Wei.ZERO,
BlockHeader::getCoinbase,
false,
TransactionGasBudgetCalculator.frontier(),
Optional.of(goQuorumPrivacyParameters));
final MutableWorldState worldState = ReferenceTestWorldState.create(emptyMap());

@ -25,7 +25,6 @@ import org.hyperledger.besu.ethereum.core.BlockHeaderTestFixture;
import org.hyperledger.besu.ethereum.core.Hash;
import org.hyperledger.besu.ethereum.core.MutableWorldState;
import org.hyperledger.besu.ethereum.core.Wei;
import org.hyperledger.besu.ethereum.core.fees.TransactionGasBudgetCalculator;
import org.hyperledger.besu.ethereum.referencetests.ReferenceTestBlockchain;
import org.hyperledger.besu.ethereum.referencetests.ReferenceTestWorldState;
@ -50,7 +49,6 @@ public class MainnetBlockProcessorTest {
Wei.ZERO,
BlockHeader::getCoinbase,
true,
TransactionGasBudgetCalculator.frontier(),
Optional.empty());
final MutableWorldState worldState = ReferenceTestWorldState.create(emptyMap());
@ -77,7 +75,6 @@ public class MainnetBlockProcessorTest {
Wei.ZERO,
BlockHeader::getCoinbase,
false,
TransactionGasBudgetCalculator.frontier(),
Optional.empty());
final MutableWorldState worldState = ReferenceTestWorldState.create(emptyMap());

@ -19,7 +19,6 @@ import org.hyperledger.besu.ethereum.MainnetBlockValidator;
import org.hyperledger.besu.ethereum.core.BlockImporter;
import org.hyperledger.besu.ethereum.core.TransactionFilter;
import org.hyperledger.besu.ethereum.core.Wei;
import org.hyperledger.besu.ethereum.core.fees.TransactionGasBudgetCalculator;
import org.hyperledger.besu.ethereum.mainnet.BlockProcessor;
import org.hyperledger.besu.ethereum.mainnet.MainnetBlockImporter;
import org.hyperledger.besu.ethereum.mainnet.MainnetBlockProcessor;
@ -49,7 +48,6 @@ public class NoRewardProtocolScheduleWrapper implements ProtocolSchedule {
Wei.ZERO,
original.getMiningBeneficiaryCalculator(),
original.isSkipZeroBlockRewards(),
TransactionGasBudgetCalculator.frontier(),
Optional.empty());
final BlockValidator noRewardBlockValidator =
new MainnetBlockValidator(
@ -80,7 +78,6 @@ public class NoRewardProtocolScheduleWrapper implements ProtocolSchedule {
original.getGasCalculator(),
original.getTransactionPriceCalculator(),
original.getEip1559(),
original.getGasBudgetCalculator(),
original.getBadBlocksManager(),
Optional.empty());
}

Loading…
Cancel
Save