Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow empty maxFeePerBlobGas for eth_call #6731

Merged
merged 16 commits into from
Mar 19, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"response": {
"jsonrpc": "2.0",
"id": 4,
"error":{"code":-32603,"message":"Internal error"}
"result": "0x0000000000000000000000000000000000000000000000000000000000000001"
},
"statusCode": 200
}
Original file line number Diff line number Diff line change
Expand Up @@ -173,12 +173,13 @@ private ValidationResult<TransactionInvalidReason> validateCostAndFee(
if (maybeBlobFee.isEmpty()) {
throw new IllegalArgumentException(
"blob fee must be provided from blocks containing blobs");
// tx.getMaxFeePerBlobGas can be empty for eth_call
} else if (!transactionValidationParams.allowUnderpriced()
&& maybeBlobFee.get().compareTo(transaction.getMaxFeePerBlobGas().get()) > 0) {
return ValidationResult.invalid(
TransactionInvalidReason.BLOB_GAS_PRICE_BELOW_CURRENT_BLOB_BASE_FEE,
String.format(
"max fee per blob gas less than block blob gas fee: address %s blobGasFeeCap: %s, blobBaseFee: %s",
"tx max fee per blob gas less than block blob gas fee: address %s blobGasFeeCap: %s, blobBaseFee: %s",
transaction.getSender().toHexString(),
transaction.getMaxFeePerBlobGas().get().toHumanReadableString(),
maybeBlobFee.get().toHumanReadableString()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

import org.apache.tuweni.bytes.Bytes;

// Represents parameters for a eth_call or eth_estimateGas JSON-RPC methods.
// Represents parameters for eth_call and eth_estimateGas JSON-RPC methods.
public class CallParameter {

private final Address from;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,16 @@ public Optional<TransactionSimulatorResult> processWithWorldUpdater(
final MainnetTransactionProcessor transactionProcessor =
protocolSchedule.getByBlockHeader(blockHeaderToProcess).getTransactionProcessor();

final Optional<BlockHeader> maybeParentHeader =
blockchain.getBlockHeader(blockHeaderToProcess.getParentHash());
final Wei blobGasPrice =
protocolSpec
.getFeeMarket()
.blobGasPricePerGas(
maybeParentHeader
.map(parent -> calculateExcessBlobGasForParent(protocolSpec, parent))
.orElse(BlobGas.ZERO));

final Optional<Transaction> maybeTransaction =
buildTransaction(
callParams,
Expand All @@ -256,21 +266,12 @@ public Optional<TransactionSimulatorResult> processWithWorldUpdater(
nonce,
gasLimit,
value,
payload);
payload,
blobGasPrice);
if (maybeTransaction.isEmpty()) {
return Optional.empty();
}

final Optional<BlockHeader> maybeParentHeader =
blockchain.getBlockHeader(blockHeaderToProcess.getParentHash());
final Wei blobGasPrice =
protocolSpec
.getFeeMarket()
.blobGasPricePerGas(
maybeParentHeader
.map(parent -> calculateExcessBlobGasForParent(protocolSpec, parent))
.orElse(BlobGas.ZERO));

final Transaction transaction = maybeTransaction.get();
final TransactionProcessingResult result =
transactionProcessor.processTransaction(
Expand All @@ -286,6 +287,8 @@ public Optional<TransactionSimulatorResult> processWithWorldUpdater(
transactionValidationParams,
operationTracer,
blobGasPrice);
LOG.info("tx simulator " + transaction);
LOG.info("tx simulator " + result);
macfarla marked this conversation as resolved.
Show resolved Hide resolved

return Optional.of(new TransactionSimulatorResult(transaction, result));
}
Expand All @@ -298,7 +301,8 @@ private Optional<Transaction> buildTransaction(
final long nonce,
final long gasLimit,
final Wei value,
final Bytes payload) {
final Bytes payload,
final Wei blobGasPrice) {
final Transaction.Builder transactionBuilder =
Transaction.builder()
.nonce(nonce)
Expand All @@ -313,12 +317,11 @@ private Optional<Transaction> buildTransaction(
callParams.getAccessList().ifPresent(transactionBuilder::accessList);
// Set versioned hashes if present
callParams.getBlobVersionedHashes().ifPresent(transactionBuilder::versionedHashes);
// Set max fee per blob gas if present
callParams.getMaxFeePerBlobGas().ifPresent(transactionBuilder::maxFeePerBlobGas);

final Wei gasPrice;
final Wei maxFeePerGas;
final Wei maxPriorityFeePerGas;
final Wei maxFeePerBlobGas;
if (transactionValidationParams.isAllowExceedingBalance()) {
gasPrice = Wei.ZERO;
maxFeePerGas = Wei.ZERO;
Expand All @@ -337,6 +340,10 @@ private Optional<Transaction> buildTransaction(
}

transactionBuilder.guessType();
if (transactionBuilder.getTransactionType().supportsBlob()) {
maxFeePerBlobGas = callParams.getMaxFeePerBlobGas().orElse(blobGasPrice);
transactionBuilder.maxFeePerBlobGas(maxFeePerBlobGas);
}
if (transactionBuilder.getTransactionType().requiresChainId()) {
transactionBuilder.chainId(
protocolSchedule
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ public void shouldRejectTransactionWithMaxBlobPriorityFeeSmallerThanBlobBaseFee(
.isEqualTo(ValidationResult.invalid(BLOB_GAS_PRICE_BELOW_CURRENT_BLOB_BASE_FEE));
assertThat(validationResult.getErrorMessage())
.matches(
"max fee per blob gas less than block blob gas fee: address 0x[0-9a-f]+ blobGasFeeCap: 7 wei, blobBaseFee: 10 wei");
"tx max fee per blob gas less than block blob gas fee: address 0x[0-9a-f]+ blobGasFeeCap: 7 wei, blobBaseFee: 10 wei");
}

@Test
Expand Down
Loading