Skip to content

Commit 743ee9e

Browse files
authored
Expose method to get blob gas price from plugins (#8843)
Signed-off-by: Fabio Di Fabio <fabio.difabio@consensys.net>
1 parent a9957ce commit 743ee9e

File tree

8 files changed

+39
-11
lines changed

8 files changed

+39
-11
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
- Introduce the `TransactionValidatorService` to allow plugins to add custom validation rules [#8793](https://github.com/hyperledger/besu/pull/8793)
2424
- Enable parallel tx processing by default if Bonsai is used [#8668](https://github.com/hyperledger/besu/pull/8668)
2525
- Increase mainnet gas limit to 45M [#8824](https://github.com/hyperledger/besu/pull/8824)
26-
26+
- Expose a method to get blob gas price from plugins [#8843](https://github.com/hyperledger/besu/pull/8843)
2727

2828
#### Fusaka Devnet
2929
- EIP-7825 - Transaction gas limit cap [#8700](https://github.com/hyperledger/besu/pull/8700)

app/src/main/java/org/hyperledger/besu/services/BlockchainServiceImpl.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@
1414
*/
1515
package org.hyperledger.besu.services;
1616

17+
import static org.hyperledger.besu.ethereum.mainnet.feemarket.ExcessBlobGasCalculator.calculateExcessBlobGasForParent;
18+
19+
import org.hyperledger.besu.datatypes.BlobGas;
1720
import org.hyperledger.besu.datatypes.Hash;
1821
import org.hyperledger.besu.datatypes.Wei;
1922
import org.hyperledger.besu.ethereum.chain.MutableBlockchain;
@@ -120,6 +123,18 @@ public Optional<Wei> getNextBlockBaseFee() {
120123
feeMarket.targetGasUsed(chainHeadHeader)));
121124
}
122125

126+
@Override
127+
public Wei getBlobGasPrice(final BlockHeader blockHeader) {
128+
final var protocolSpec = protocolSchedule.getByBlockHeader(blockHeader);
129+
final var maybeParentHeader = blockchain.getBlockHeader(blockHeader.getParentHash());
130+
return protocolSpec
131+
.getFeeMarket()
132+
.blobGasPricePerGas(
133+
maybeParentHeader
134+
.map(parent -> calculateExcessBlobGasForParent(protocolSpec, parent))
135+
.orElse(BlobGas.ZERO));
136+
}
137+
123138
@Override
124139
public Optional<List<TransactionReceipt>> getReceiptsByBlockHash(final Hash blockHash) {
125140
return blockchain

consensus/merge/src/main/java/org/hyperledger/besu/consensus/merge/TransitionProtocolSchedule.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,8 @@ public ProtocolSchedule getPostMergeSchedule() {
8181
* @return the ProtocolSpec to be used by the provided block
8282
*/
8383
@Override
84-
public ProtocolSpec getByBlockHeader(final ProcessableBlockHeader blockHeader) {
84+
public ProtocolSpec getByBlockHeader(
85+
final org.hyperledger.besu.plugin.data.ProcessableBlockHeader blockHeader) {
8586
return this.transitionUtils.dispatchFunctionAccordingToMergeState(
8687
protocolSchedule -> protocolSchedule.getByBlockHeader(blockHeader));
8788
}

ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/DefaultProtocolSchedule.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@
1919
import org.hyperledger.besu.datatypes.HardforkId;
2020
import org.hyperledger.besu.ethereum.core.BlockHeader;
2121
import org.hyperledger.besu.ethereum.core.PermissionTransactionFilter;
22-
import org.hyperledger.besu.ethereum.core.ProcessableBlockHeader;
2322
import org.hyperledger.besu.ethereum.mainnet.ScheduledProtocolSpec.BlockNumberProtocolSpec;
2423
import org.hyperledger.besu.ethereum.mainnet.ScheduledProtocolSpec.TimestampProtocolSpec;
24+
import org.hyperledger.besu.plugin.data.ProcessableBlockHeader;
2525
import org.hyperledger.besu.plugin.services.txvalidator.TransactionValidationRule;
2626

2727
import java.math.BigInteger;

ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/ProtocolSchedule.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
import org.hyperledger.besu.ethereum.core.BlockHeader;
1919
import org.hyperledger.besu.ethereum.core.BlockHeaderBuilder;
2020
import org.hyperledger.besu.ethereum.core.PermissionTransactionFilter;
21-
import org.hyperledger.besu.ethereum.core.ProcessableBlockHeader;
21+
import org.hyperledger.besu.plugin.data.ProcessableBlockHeader;
2222
import org.hyperledger.besu.plugin.services.txvalidator.TransactionValidationRule;
2323

2424
import java.math.BigInteger;

ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/ScheduledProtocolSpec.java

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,17 @@
1414
*/
1515
package org.hyperledger.besu.ethereum.mainnet;
1616

17-
import org.hyperledger.besu.ethereum.core.ProcessableBlockHeader;
17+
import org.hyperledger.besu.plugin.data.ProcessableBlockHeader;
1818

1919
/**
2020
* Associates a {@link ProtocolSpec} with a given block number or timestamp level starting point
2121
* Knows how to query the timestamp or block number of a given block header
2222
*/
2323
public interface ScheduledProtocolSpec {
24-
boolean isOnOrAfterMilestoneBoundary(ProcessableBlockHeader header);
24+
boolean isOnOrAfterMilestoneBoundary(
25+
org.hyperledger.besu.plugin.data.ProcessableBlockHeader header);
2526

26-
boolean isOnMilestoneBoundary(ProcessableBlockHeader header);
27+
boolean isOnMilestoneBoundary(org.hyperledger.besu.plugin.data.ProcessableBlockHeader header);
2728

2829
Hardfork fork();
2930

@@ -60,12 +61,14 @@ private TimestampProtocolSpec(final long timestamp, final ProtocolSpec protocolS
6061
}
6162

6263
@Override
63-
public boolean isOnOrAfterMilestoneBoundary(final ProcessableBlockHeader header) {
64+
public boolean isOnOrAfterMilestoneBoundary(
65+
final org.hyperledger.besu.plugin.data.ProcessableBlockHeader header) {
6466
return Long.compareUnsigned(header.getTimestamp(), timestamp) >= 0;
6567
}
6668

6769
@Override
68-
public boolean isOnMilestoneBoundary(final ProcessableBlockHeader header) {
70+
public boolean isOnMilestoneBoundary(
71+
final org.hyperledger.besu.plugin.data.ProcessableBlockHeader header) {
6972
return header.getTimestamp() == timestamp;
7073
}
7174

@@ -95,7 +98,8 @@ private BlockNumberProtocolSpec(final long blockNumber, final ProtocolSpec proto
9598
}
9699

97100
@Override
98-
public boolean isOnOrAfterMilestoneBoundary(final ProcessableBlockHeader header) {
101+
public boolean isOnOrAfterMilestoneBoundary(
102+
final org.hyperledger.besu.plugin.data.ProcessableBlockHeader header) {
99103
return header.getNumber() >= blockNumber;
100104
}
101105

plugin-api/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ Calculated : ${currentHash}
7171
tasks.register('checkAPIChanges', FileStateChecker) {
7272
description = "Checks that the API for the Plugin-API project does not change without deliberate thought"
7373
files = sourceSets.main.allJava.files
74-
knownHash = '4lHVP5Gc91MkqyiTvU9HVlBZx0tOgodIdOmasEAGTtM='
74+
knownHash = '2iFZ9OBdtl1VoQLGPdqolq8zlBIkwszjin8vO4TkTqk='
7575
}
7676
check.dependsOn('checkAPIChanges')
7777

plugin-api/src/main/java/org/hyperledger/besu/plugin/services/BlockchainService.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,14 @@ public interface BlockchainService extends BesuService {
6060
*/
6161
Hash getChainHeadHash();
6262

63+
/**
64+
* Return the blob gas price for the specified block
65+
*
66+
* @param blockHeader the block header
67+
* @return the block gas price or Wei.ZERO if blobs are not yet supported for that block header
68+
*/
69+
Wei getBlobGasPrice(BlockHeader blockHeader);
70+
6371
/**
6472
* Get the receipts for a block by block hash
6573
*

0 commit comments

Comments
 (0)