Skip to content
/ besu Public
forked from hyperledger/besu

Commit

Permalink
feat: add fixed basefee options (hyperledger#6562)
Browse files Browse the repository at this point in the history
* feat: add fixed basefee options

Signed-off-by: Suraneti Rodsuwan <[email protected]>

* Refactor zero base fee to be extension of fixed base fee

Signed-off-by: Matthew Whitehead <[email protected]>

* feat: use MiningParameters to fixed base fee

Signed-off-by: Suraneti Rodsuwan <[email protected]>

* feat: add mining parameters arg on protocol schedule builder

* feat: add miningParameters on gray glacier and prague

Signed-off-by: Suraneti Rodsuwan <[email protected]>

* feat: add miningParameters on gray glacier and prague

Signed-off-by: Suraneti Rodsuwan <[email protected]>

* feat: add miningParameters on paris,shanghai,future,experimental

Signed-off-by: Suraneti Rodsuwan <[email protected]>

---------

Signed-off-by: Suraneti Rodsuwan <[email protected]>
Signed-off-by: Matthew Whitehead <[email protected]>
Signed-off-by: Suraneti <[email protected]>
Co-authored-by: Matthew Whitehead <[email protected]>
Co-authored-by: Sally MacFarlane <[email protected]>
Signed-off-by: amsmota <[email protected]>
  • Loading branch information
3 people authored and amsmota committed Apr 16, 2024
1 parent 74d052b commit b161ad6
Show file tree
Hide file tree
Showing 77 changed files with 726 additions and 87 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ protected ProtocolSchedule createProtocolSchedule() {
privacyParameters,
isRevertReasonEnabled,
evmConfiguration,
miningParameters,
badBlockManager);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,7 @@ protected ProtocolSchedule createProtocolSchedule() {
isRevertReasonEnabled,
bftExtraDataCodec().get(),
evmConfiguration,
miningParameters,
badBlockManager);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ protected ProtocolSchedule createProtocolSchedule() {
privacyParameters,
isRevertReasonEnabled,
evmConfiguration,
miningParameters,
badBlockManager);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,11 @@ protected MiningCoordinator createTransitionMiningCoordinator(
@Override
protected ProtocolSchedule createProtocolSchedule() {
return MergeProtocolSchedule.create(
configOptionsSupplier.get(), privacyParameters, isRevertReasonEnabled, badBlockManager);
configOptionsSupplier.get(),
privacyParameters,
isRevertReasonEnabled,
miningParameters,
badBlockManager);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,7 @@ protected ProtocolSchedule createProtocolSchedule() {
isRevertReasonEnabled,
bftExtraDataCodec().get(),
evmConfiguration,
miningParameters,
badBlockManager);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import org.hyperledger.besu.ethereum.chain.GenesisState;
import org.hyperledger.besu.ethereum.core.BlockHeader;
import org.hyperledger.besu.ethereum.core.MilestoneStreamingProtocolSchedule;
import org.hyperledger.besu.ethereum.core.MiningParameters;
import org.hyperledger.besu.ethereum.forkid.ForkId;
import org.hyperledger.besu.ethereum.forkid.ForkIdManager;
import org.hyperledger.besu.ethereum.mainnet.DefaultProtocolSchedule;
Expand Down Expand Up @@ -188,11 +189,13 @@ private static MilestoneStreamingTransitionProtocolSchedule createSchedule(
MilestoneStreamingProtocolSchedule preMergeProtocolSchedule =
new MilestoneStreamingProtocolSchedule(
(DefaultProtocolSchedule)
MainnetProtocolSchedule.fromConfig(configOptions, new BadBlockManager()));
MainnetProtocolSchedule.fromConfig(
configOptions, MiningParameters.MINING_DISABLED, new BadBlockManager()));
MilestoneStreamingProtocolSchedule postMergeProtocolSchedule =
new MilestoneStreamingProtocolSchedule(
(DefaultProtocolSchedule)
MergeProtocolSchedule.create(configOptions, false, new BadBlockManager()));
MergeProtocolSchedule.create(
configOptions, false, MiningParameters.MINING_DISABLED, new BadBlockManager()));
final MilestoneStreamingTransitionProtocolSchedule schedule =
new MilestoneStreamingTransitionProtocolSchedule(
preMergeProtocolSchedule, postMergeProtocolSchedule);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -504,6 +504,13 @@ default boolean isConsensusMigration() {
*/
boolean isZeroBaseFee();

/**
* Force a Base Fee as Gas Price network to used with London/EIP-1559.
*
* @return true, if you want the next block to use the base fee as gas price.
*/
boolean isFixedBaseFee();

/**
* The deposit contract address that should be in the logger field in Receipt of Deposit
* transaction
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public class JsonGenesisConfigOptions implements GenesisConfigOptions {
private static final String DISCOVERY_CONFIG_KEY = "discovery";
private static final String CHECKPOINT_CONFIG_KEY = "checkpoint";
private static final String ZERO_BASE_FEE_KEY = "zerobasefee";
private static final String FIXED_BASE_FEE_KEY = "fixedbasefee";
private static final String DEPOSIT_CONTRACT_ADDRESS_KEY = "depositcontractaddress";

private final ObjectNode configRoot;
Expand Down Expand Up @@ -421,6 +422,11 @@ public boolean isZeroBaseFee() {
return getOptionalBoolean(ZERO_BASE_FEE_KEY).orElse(false);
}

@Override
public boolean isFixedBaseFee() {
return getOptionalBoolean(FIXED_BASE_FEE_KEY).orElse(false);
}

@Override
public Optional<Address> getDepositContractAddress() {
Optional<String> inputAddress = JsonUtil.getString(configRoot, DEPOSIT_CONTRACT_ADDRESS_KEY);
Expand Down Expand Up @@ -492,6 +498,10 @@ public Map<String, Object> asMap() {
builder.put("zeroBaseFee", true);
}

if (isFixedBaseFee()) {
builder.put("fixedBaseFee", true);
}

return builder.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ public class StubGenesisConfigOptions implements GenesisConfigOptions, Cloneable
private TransitionsConfigOptions transitions = TransitionsConfigOptions.DEFAULT;
private static final DiscoveryOptions DISCOVERY_OPTIONS = DiscoveryOptions.DEFAULT;
private boolean zeroBaseFee = false;
private boolean fixedBaseFee = false;

@Override
public StubGenesisConfigOptions clone() {
Expand Down Expand Up @@ -424,6 +425,11 @@ public boolean isZeroBaseFee() {
return zeroBaseFee;
}

@Override
public boolean isFixedBaseFee() {
return fixedBaseFee;
}

@Override
public List<Long> getForkBlockNumbers() {
return Collections.emptyList();
Expand Down Expand Up @@ -704,6 +710,17 @@ public StubGenesisConfigOptions zeroBaseFee(final boolean zeroBaseFee) {
return this;
}

/**
* Fixed base fee per gas stub genesis config options.
*
* @param fixedBaseFee the zero base fee override
* @return the stub genesis config options
*/
public StubGenesisConfigOptions fixedBaseFee(final boolean fixedBaseFee) {
this.fixedBaseFee = fixedBaseFee;
return this;
}

/**
* Classic fork block stub genesis config options.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,27 @@ void asMapIncludesZeroBaseFee() {
assertThat(config.asMap()).containsOnlyKeys("zeroBaseFee").containsValue(true);
}

@Test
void isFixedBaseFeeShouldDefaultToFalse() {
final GenesisConfigOptions config = GenesisConfigFile.fromConfig("{}").getConfigOptions();

assertThat(config.isFixedBaseFee()).isFalse();
}

@Test
void isFixedBaseFeeParsedCorrectly() {
final GenesisConfigOptions config = fromConfigOptions(Map.of("fixedbasefee", true));

assertThat(config.isFixedBaseFee()).isTrue();
}

@Test
void asMapIncludesFixedBaseFee() {
final GenesisConfigOptions config = fromConfigOptions(Map.of("fixedbasefee", true));

assertThat(config.asMap()).containsOnlyKeys("fixedBaseFee").containsValue(true);
}

@Test
void shouldGetDepositContractAddress() {
final GenesisConfigOptions config =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import org.hyperledger.besu.datatypes.Address;
import org.hyperledger.besu.datatypes.Wei;
import org.hyperledger.besu.ethereum.chain.BadBlockManager;
import org.hyperledger.besu.ethereum.core.MiningParameters;
import org.hyperledger.besu.ethereum.core.PrivacyParameters;
import org.hyperledger.besu.ethereum.core.Util;
import org.hyperledger.besu.ethereum.mainnet.BlockHeaderValidator;
Expand Down Expand Up @@ -58,6 +59,7 @@ public class CliqueProtocolSchedule {
* @param privacyParameters the privacy parameters
* @param isRevertReasonEnabled the is revert reason enabled
* @param evmConfiguration the evm configuration
* @param miningParameters the mining parameters
* @param badBlockManager the cache to use to keep invalid blocks
* @return the protocol schedule
*/
Expand All @@ -68,6 +70,7 @@ public static ProtocolSchedule create(
final PrivacyParameters privacyParameters,
final boolean isRevertReasonEnabled,
final EvmConfiguration evmConfiguration,
final MiningParameters miningParameters,
final BadBlockManager badBlockManager) {

final CliqueConfigOptions cliqueConfig = config.getCliqueConfigOptions();
Expand Down Expand Up @@ -103,6 +106,7 @@ public static ProtocolSchedule create(
privacyParameters,
isRevertReasonEnabled,
evmConfiguration,
miningParameters,
badBlockManager)
.createProtocolSchedule();
}
Expand All @@ -115,6 +119,7 @@ public static ProtocolSchedule create(
* @param nodeKey the node key
* @param isRevertReasonEnabled the is revert reason enabled
* @param evmConfiguration the evm configuration
* @param miningParameters the mining parameters
* @param badBlockManager the cache to use to keep invalid blocks
* @return the protocol schedule
*/
Expand All @@ -125,6 +130,7 @@ public static ProtocolSchedule create(
final NodeKey nodeKey,
final boolean isRevertReasonEnabled,
final EvmConfiguration evmConfiguration,
final MiningParameters miningParameters,
final BadBlockManager badBlockManager) {
return create(
config,
Expand All @@ -133,6 +139,7 @@ public static ProtocolSchedule create(
PrivacyParameters.DEFAULT,
isRevertReasonEnabled,
evmConfiguration,
miningParameters,
badBlockManager);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import org.hyperledger.besu.ethereum.chain.BadBlockManager;
import org.hyperledger.besu.ethereum.core.BlockHeader;
import org.hyperledger.besu.ethereum.core.BlockHeaderTestFixture;
import org.hyperledger.besu.ethereum.core.MiningParameters;
import org.hyperledger.besu.ethereum.mainnet.HeaderValidationMode;
import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule;
import org.hyperledger.besu.ethereum.mainnet.ProtocolSpec;
Expand Down Expand Up @@ -66,6 +67,7 @@ public void protocolSpecsAreCreatedAtBlockDefinedInJson() {
NODE_KEY,
false,
EvmConfiguration.DEFAULT,
MiningParameters.MINING_DISABLED,
new BadBlockManager());

final ProtocolSpec homesteadSpec = protocolSchedule.getByBlockHeader(blockHeader(1));
Expand All @@ -89,6 +91,7 @@ public void parametersAlignWithMainnetWithAdjustments() {
NODE_KEY,
false,
EvmConfiguration.DEFAULT,
MiningParameters.MINING_DISABLED,
new BadBlockManager())
.getByBlockHeader(blockHeader(0));

Expand All @@ -112,6 +115,7 @@ public void zeroEpochLengthThrowsException() {
NODE_KEY,
false,
EvmConfiguration.DEFAULT,
MiningParameters.MINING_DISABLED,
new BadBlockManager()))
.isInstanceOf(IllegalArgumentException.class)
.hasMessage("Epoch length in config must be greater than zero");
Expand All @@ -131,6 +135,7 @@ public void negativeEpochLengthThrowsException() {
NODE_KEY,
false,
EvmConfiguration.DEFAULT,
MiningParameters.MINING_DISABLED,
new BadBlockManager()))
.isInstanceOf(IllegalArgumentException.class)
.hasMessage("Epoch length in config must be greater than zero");
Expand All @@ -154,6 +159,7 @@ public void shouldValidateBaseFeeMarketTransition() {
NODE_KEY,
false,
EvmConfiguration.DEFAULT,
MiningParameters.MINING_DISABLED,
new BadBlockManager());

BlockHeader emptyFrontierParent =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ public void setup() {
proposerNodeKey,
false,
EvmConfiguration.DEFAULT,
MiningParameters.MINING_DISABLED,
new BadBlockManager());

final Address otherAddress = Util.publicKeyToAddress(otherKeyPair.getPublicKey());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ public void setup() {
proposerNodeKey,
false,
EvmConfiguration.DEFAULT,
MiningParameters.MINING_DISABLED,
new BadBlockManager());
cliqueEthContext = mock(EthContext.class, RETURNS_DEEP_STUBS);
blockHeaderBuilder = new BlockHeaderTestFixture();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import org.hyperledger.besu.consensus.common.ForksSchedule;
import org.hyperledger.besu.datatypes.Wei;
import org.hyperledger.besu.ethereum.chain.BadBlockManager;
import org.hyperledger.besu.ethereum.core.MiningParameters;
import org.hyperledger.besu.ethereum.core.PrivacyParameters;
import org.hyperledger.besu.ethereum.mainnet.BlockHeaderValidator;
import org.hyperledger.besu.ethereum.mainnet.DefaultProtocolSchedule;
Expand Down Expand Up @@ -52,6 +53,7 @@ public abstract class BaseBftProtocolScheduleBuilder {
* @param isRevertReasonEnabled the is revert reason enabled
* @param bftExtraDataCodec the bft extra data codec
* @param evmConfiguration the evm configuration
* @param miningParameters the mining parameters
* @param badBlockManager the cache to use to keep invalid blocks
* @return the protocol schedule
*/
Expand All @@ -62,6 +64,7 @@ public BftProtocolSchedule createProtocolSchedule(
final boolean isRevertReasonEnabled,
final BftExtraDataCodec bftExtraDataCodec,
final EvmConfiguration evmConfiguration,
final MiningParameters miningParameters,
final BadBlockManager badBlockManager) {
final Map<Long, Function<ProtocolSpecBuilder, ProtocolSpecBuilder>> specMap = new HashMap<>();

Expand All @@ -83,6 +86,7 @@ public BftProtocolSchedule createProtocolSchedule(
privacyParameters,
isRevertReasonEnabled,
evmConfiguration,
miningParameters,
badBlockManager)
.createProtocolSchedule();
return new BftProtocolSchedule((DefaultProtocolSchedule) protocolSchedule);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import org.hyperledger.besu.consensus.common.bft.BftProtocolSchedule;
import org.hyperledger.besu.ethereum.chain.BadBlockManager;
import org.hyperledger.besu.ethereum.core.MilestoneStreamingProtocolSchedule;
import org.hyperledger.besu.ethereum.core.MiningParameters;
import org.hyperledger.besu.ethereum.core.PrivacyParameters;
import org.hyperledger.besu.ethereum.mainnet.DefaultProtocolSchedule;
import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule;
Expand Down Expand Up @@ -175,6 +176,7 @@ private BftProtocolSchedule createProtocolSchedule(
new PrivacyParameters(),
false,
EvmConfiguration.DEFAULT,
MiningParameters.MINING_DISABLED,
new BadBlockManager());

return new BftProtocolSchedule(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import org.hyperledger.besu.ethereum.core.BlockHeader;
import org.hyperledger.besu.ethereum.core.BlockHeaderTestFixture;
import org.hyperledger.besu.ethereum.core.MilestoneStreamingProtocolSchedule;
import org.hyperledger.besu.ethereum.core.MiningParameters;
import org.hyperledger.besu.ethereum.core.PrivacyParameters;
import org.hyperledger.besu.ethereum.mainnet.BlockHeaderValidator;
import org.hyperledger.besu.ethereum.mainnet.DefaultProtocolSchedule;
Expand Down Expand Up @@ -243,6 +244,7 @@ protected BlockHeaderValidator.Builder createBlockHeaderRuleset(
false,
bftExtraDataCodec,
EvmConfiguration.DEFAULT,
MiningParameters.MINING_DISABLED,
new BadBlockManager());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,7 @@ private static ControllerAndState createControllerAndFinalState(
forksSchedule,
IBFT_EXTRA_DATA_ENCODER,
EvmConfiguration.DEFAULT,
MiningParameters.MINING_DISABLED,
new BadBlockManager());

/////////////////////////////////////////////////////////////////////////////////////
Expand Down
Loading

0 comments on commit b161ad6

Please sign in to comment.