diff --git a/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/node/configuration/BesuNodeConfigurationBuilder.java b/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/node/configuration/BesuNodeConfigurationBuilder.java index 287f4fe6cfe9..6e925f6a2c7d 100644 --- a/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/node/configuration/BesuNodeConfigurationBuilder.java +++ b/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/node/configuration/BesuNodeConfigurationBuilder.java @@ -30,6 +30,7 @@ import org.hyperledger.besu.ethereum.api.tls.FileBasedPasswordProvider; import org.hyperledger.besu.ethereum.core.AddressHelpers; import org.hyperledger.besu.ethereum.core.ImmutableMiningParameters; +import org.hyperledger.besu.ethereum.core.ImmutableMiningParameters.UpdatableInitValues; import org.hyperledger.besu.ethereum.core.MiningParameters; import org.hyperledger.besu.ethereum.core.PrivacyParameters; import org.hyperledger.besu.ethereum.p2p.config.NetworkingConfiguration; @@ -56,7 +57,10 @@ public class BesuNodeConfigurationBuilder { private String name; private Optional dataPath = Optional.empty(); private MiningParameters miningParameters = - ImmutableMiningParameters.builder().coinbase(AddressHelpers.ofValue(1)).build(); + ImmutableMiningParameters.builder() + .updatableInitValues( + UpdatableInitValues.builder().coinbase(AddressHelpers.ofValue(1)).build()) + .build(); private JsonRpcConfiguration jsonRpcConfiguration = JsonRpcConfiguration.createDefault(); private JsonRpcConfiguration engineRpcConfiguration = JsonRpcConfiguration.createEngineDefault(); diff --git a/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/node/configuration/BesuNodeFactory.java b/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/node/configuration/BesuNodeFactory.java index fc61b998a50e..7960fd464377 100644 --- a/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/node/configuration/BesuNodeFactory.java +++ b/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/node/configuration/BesuNodeFactory.java @@ -310,8 +310,8 @@ public BesuNode createNodeWithMultiTenantedPrivacy( UpdatableInitValues.builder() .isMiningEnabled(true) .minTransactionGasPrice(Wei.ZERO) + .coinbase(AddressHelpers.ofValue(1)) .build()) - .coinbase(AddressHelpers.ofValue(1)) .build(); return create( diff --git a/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/bft/BftMiningAcceptanceTest.java b/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/bft/BftMiningAcceptanceTest.java index b4732cc7113d..8093661ebeb5 100644 --- a/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/bft/BftMiningAcceptanceTest.java +++ b/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/bft/BftMiningAcceptanceTest.java @@ -66,8 +66,8 @@ public void shouldMineOnSingleNodeWithFreeGas_Berlin() throws Exception { UpdatableInitValues.builder() .isMiningEnabled(true) .minTransactionGasPrice(Wei.ZERO) + .coinbase(AddressHelpers.ofValue(1)) .build()) - .coinbase(AddressHelpers.ofValue(1)) .build(); minerNode.setMiningParameters(zeroGasMiningParams); diff --git a/besu/src/main/java/org/hyperledger/besu/cli/options/stable/MiningOptions.java b/besu/src/main/java/org/hyperledger/besu/cli/options/stable/MiningOptions.java index b1b87321af50..29733ed0b897 100644 --- a/besu/src/main/java/org/hyperledger/besu/cli/options/stable/MiningOptions.java +++ b/besu/src/main/java/org/hyperledger/besu/cli/options/stable/MiningOptions.java @@ -30,6 +30,7 @@ import org.hyperledger.besu.datatypes.Address; import org.hyperledger.besu.datatypes.Wei; import org.hyperledger.besu.ethereum.core.ImmutableMiningParameters; +import org.hyperledger.besu.ethereum.core.ImmutableMiningParameters.UpdatableInitValues; import org.hyperledger.besu.ethereum.core.MiningParameters; import java.util.List; @@ -262,7 +263,7 @@ static MiningOptions fromConfig(final MiningParameters miningParameters) { @Override public MiningParameters toDomainObject() { final var updatableInitValuesBuilder = - ImmutableMiningParameters.UpdatableInitValues.builder() + UpdatableInitValues.builder() .isMiningEnabled(isMiningEnabled) .extraData(extraData) .minTransactionGasPrice(minTransactionGasPrice) @@ -271,6 +272,9 @@ public MiningParameters toDomainObject() { if (targetGasLimit != null) { updatableInitValuesBuilder.targetGasLimit(targetGasLimit); } + if (coinbase != null) { + updatableInitValuesBuilder.coinbase(coinbase); + } final var miningParametersBuilder = ImmutableMiningParameters.builder() @@ -290,10 +294,6 @@ public MiningParameters toDomainObject() { unstableOptions.posBlockCreationRepetitionMinDuration) .build()); - if (coinbase != null) { - miningParametersBuilder.coinbase(coinbase); - } - return miningParametersBuilder.build(); } diff --git a/besu/src/main/java/org/hyperledger/besu/cli/subcommands/blocks/BlocksSubCommand.java b/besu/src/main/java/org/hyperledger/besu/cli/subcommands/blocks/BlocksSubCommand.java index c8579c2263fd..3242ce9799ae 100644 --- a/besu/src/main/java/org/hyperledger/besu/cli/subcommands/blocks/BlocksSubCommand.java +++ b/besu/src/main/java/org/hyperledger/besu/cli/subcommands/blocks/BlocksSubCommand.java @@ -275,8 +275,8 @@ private MiningParameters getMiningParameters() { .nonceGenerator(new IncrementingNonceGenerator(0)) .extraData(extraData) .minTransactionGasPrice(minTransactionGasPrice) + .coinbase(coinbase) .build()) - .coinbase(coinbase) .build(); } diff --git a/besu/src/main/java/org/hyperledger/besu/controller/IbftBesuControllerBuilder.java b/besu/src/main/java/org/hyperledger/besu/controller/IbftBesuControllerBuilder.java index 40765769e6ea..1f9fd70f7458 100644 --- a/besu/src/main/java/org/hyperledger/besu/controller/IbftBesuControllerBuilder.java +++ b/besu/src/main/java/org/hyperledger/besu/controller/IbftBesuControllerBuilder.java @@ -145,6 +145,7 @@ protected MiningCoordinator createMiningCoordinator( final Address localAddress = Util.publicKeyToAddress(nodeKey.getPublicKey()); final BftProtocolSchedule bftProtocolSchedule = (BftProtocolSchedule) protocolSchedule; + miningParameters.setCoinbase(localAddress); final BftBlockCreatorFactory blockCreatorFactory = new BftBlockCreatorFactory<>( transactionPool, diff --git a/besu/src/test/java/org/hyperledger/besu/cli/BesuCommandTest.java b/besu/src/test/java/org/hyperledger/besu/cli/BesuCommandTest.java index 013da67e8c2d..8f2124ddfa96 100644 --- a/besu/src/test/java/org/hyperledger/besu/cli/BesuCommandTest.java +++ b/besu/src/test/java/org/hyperledger/besu/cli/BesuCommandTest.java @@ -71,6 +71,7 @@ import org.hyperledger.besu.ethereum.api.jsonrpc.websocket.WebSocketConfiguration; import org.hyperledger.besu.ethereum.api.tls.TlsConfiguration; import org.hyperledger.besu.ethereum.core.ImmutableMiningParameters; +import org.hyperledger.besu.ethereum.core.ImmutableMiningParameters.UpdatableInitValues; import org.hyperledger.besu.ethereum.core.MiningParameters; import org.hyperledger.besu.ethereum.core.PrivacyParameters; import org.hyperledger.besu.ethereum.eth.sync.SyncMode; @@ -902,7 +903,10 @@ public void envVariableOverridesValueFromConfigFile() { verify(mockControllerBuilder) .miningParameters( ImmutableMiningParameters.builder() - .coinbase(Address.fromHexString(expectedCoinbase)) + .updatableInitValues( + UpdatableInitValues.builder() + .coinbase(Address.fromHexString(expectedCoinbase)) + .build()) .build()); } @@ -916,7 +920,10 @@ public void cliOptionOverridesEnvVariableAndConfig() { verify(mockControllerBuilder) .miningParameters( ImmutableMiningParameters.builder() - .coinbase(Address.fromHexString(expectedCoinbase)) + .updatableInitValues( + UpdatableInitValues.builder() + .coinbase(Address.fromHexString(expectedCoinbase)) + .build()) .build()); } diff --git a/besu/src/test/java/org/hyperledger/besu/cli/options/stable/MiningOptionsTest.java b/besu/src/test/java/org/hyperledger/besu/cli/options/stable/MiningOptionsTest.java index 5fe050067adb..95a83e7ce871 100644 --- a/besu/src/test/java/org/hyperledger/besu/cli/options/stable/MiningOptionsTest.java +++ b/besu/src/test/java/org/hyperledger/besu/cli/options/stable/MiningOptionsTest.java @@ -322,8 +322,8 @@ protected MiningParameters createCustomizedDomainObject() { .isMiningEnabled(true) .extraData(Bytes.fromHexString("0xabc321")) .minBlockOccupancyRatio(0.5) + .coinbase(Address.ZERO) .build()) - .coinbase(Address.ZERO) .isStratumMiningEnabled(true) .unstable(Unstable.builder().posBlockCreationMaxTime(1000).build()) .build(); diff --git a/consensus/clique/src/main/java/org/hyperledger/besu/consensus/clique/blockcreation/CliqueBlockCreator.java b/consensus/clique/src/main/java/org/hyperledger/besu/consensus/clique/blockcreation/CliqueBlockCreator.java index 1f4206b7ec86..d991fb9db4c2 100644 --- a/consensus/clique/src/main/java/org/hyperledger/besu/consensus/clique/blockcreation/CliqueBlockCreator.java +++ b/consensus/clique/src/main/java/org/hyperledger/besu/consensus/clique/blockcreation/CliqueBlockCreator.java @@ -23,7 +23,6 @@ import org.hyperledger.besu.consensus.common.EpochManager; import org.hyperledger.besu.consensus.common.validator.ValidatorVote; import org.hyperledger.besu.cryptoservices.NodeKey; -import org.hyperledger.besu.datatypes.Address; import org.hyperledger.besu.datatypes.Hash; import org.hyperledger.besu.ethereum.ProtocolContext; import org.hyperledger.besu.ethereum.blockcreation.AbstractBlockCreator; @@ -49,7 +48,6 @@ public class CliqueBlockCreator extends AbstractBlockCreator { * Instantiates a new Clique block creator. * * @param miningParameters the mining parameters - * @param coinbase the coinbase * @param extraDataCalculator the extra data calculator * @param transactionPool the pending transactions * @param protocolContext the protocol context @@ -60,7 +58,6 @@ public class CliqueBlockCreator extends AbstractBlockCreator { */ public CliqueBlockCreator( final MiningParameters miningParameters, - final Address coinbase, final ExtraDataCalculator extraDataCalculator, final TransactionPool transactionPool, final ProtocolContext protocolContext, @@ -70,7 +67,6 @@ public CliqueBlockCreator( final EpochManager epochManager) { super( miningParameters, - coinbase, __ -> Util.publicKeyToAddress(nodeKey.getPublicKey()), extraDataCalculator, transactionPool, diff --git a/consensus/clique/src/main/java/org/hyperledger/besu/consensus/clique/blockcreation/CliqueMinerExecutor.java b/consensus/clique/src/main/java/org/hyperledger/besu/consensus/clique/blockcreation/CliqueMinerExecutor.java index ac06e776e448..81b754b267c6 100644 --- a/consensus/clique/src/main/java/org/hyperledger/besu/consensus/clique/blockcreation/CliqueMinerExecutor.java +++ b/consensus/clique/src/main/java/org/hyperledger/besu/consensus/clique/blockcreation/CliqueMinerExecutor.java @@ -71,6 +71,7 @@ public CliqueMinerExecutor( this.nodeKey = nodeKey; this.localAddress = Util.publicKeyToAddress(nodeKey.getPublicKey()); this.epochManager = epochManager; + miningParams.setCoinbase(localAddress); } @Override @@ -82,7 +83,6 @@ public CliqueBlockMiner createMiner( (header) -> new CliqueBlockCreator( miningParameters, - localAddress, // TOOD(tmm): This can be removed (used for voting not coinbase). this::calculateExtraData, transactionPool, protocolContext, @@ -103,7 +103,7 @@ public CliqueBlockMiner createMiner( @Override public Optional
getCoinbase() { - return Optional.of(localAddress); + return miningParameters.getCoinbase(); } /** diff --git a/consensus/clique/src/test/java/org/hyperledger/besu/consensus/clique/blockcreation/CliqueBlockCreatorTest.java b/consensus/clique/src/test/java/org/hyperledger/besu/consensus/clique/blockcreation/CliqueBlockCreatorTest.java index 787eff3bda61..208d5ac64b5a 100644 --- a/consensus/clique/src/test/java/org/hyperledger/besu/consensus/clique/blockcreation/CliqueBlockCreatorTest.java +++ b/consensus/clique/src/test/java/org/hyperledger/besu/consensus/clique/blockcreation/CliqueBlockCreatorTest.java @@ -141,7 +141,6 @@ public void proposerAddressCanBeExtractFromAConstructedBlock() { final CliqueBlockCreator blockCreator = new CliqueBlockCreator( miningParameters, - coinbase, parent -> extraData, createTransactionPool(), protocolContext, @@ -170,7 +169,6 @@ public void insertsValidVoteIntoConstructedBlock() { final CliqueBlockCreator blockCreator = new CliqueBlockCreator( miningParameters, - coinbase, parent -> extraData, createTransactionPool(), protocolContext, @@ -204,7 +202,6 @@ public void insertsNoVoteWhenAtEpoch() { final CliqueBlockCreator blockCreator = new CliqueBlockCreator( miningParameters, - coinbase, parent -> extraData, createTransactionPool(), protocolContext, @@ -252,8 +249,8 @@ private static MiningParameters createMiningParameters( .extraData(extraData) .targetGasLimit(10_000_000L) .minTransactionGasPrice(Wei.ZERO) + .coinbase(coinbase) .build()) - .coinbase(coinbase) .build(); return miningParameters; } diff --git a/consensus/clique/src/test/java/org/hyperledger/besu/consensus/clique/blockcreation/CliqueMinerExecutorTest.java b/consensus/clique/src/test/java/org/hyperledger/besu/consensus/clique/blockcreation/CliqueMinerExecutorTest.java index 6bd197cd9088..a538a491b678 100644 --- a/consensus/clique/src/test/java/org/hyperledger/besu/consensus/clique/blockcreation/CliqueMinerExecutorTest.java +++ b/consensus/clique/src/test/java/org/hyperledger/besu/consensus/clique/blockcreation/CliqueMinerExecutorTest.java @@ -240,8 +240,8 @@ private static MiningParameters createMiningParameters(final Bytes vanityData) { UpdatableInitValues.builder() .extraData(vanityData) .minTransactionGasPrice(Wei.ZERO) + .coinbase(AddressHelpers.ofValue(1)) .build()) - .coinbase(AddressHelpers.ofValue(1)) .build(); } } diff --git a/consensus/common/src/main/java/org/hyperledger/besu/consensus/common/bft/blockcreation/BftBlockCreator.java b/consensus/common/src/main/java/org/hyperledger/besu/consensus/common/bft/blockcreation/BftBlockCreator.java index 692d64e79884..47bf915a142a 100644 --- a/consensus/common/src/main/java/org/hyperledger/besu/consensus/common/bft/blockcreation/BftBlockCreator.java +++ b/consensus/common/src/main/java/org/hyperledger/besu/consensus/common/bft/blockcreation/BftBlockCreator.java @@ -63,7 +63,6 @@ public BftBlockCreator( final BftExtraDataCodec bftExtraDataCodec) { super( miningParameters, - localAddress, miningBeneficiaryCalculator(localAddress, forksSchedule), extraDataCalculator, transactionPool, diff --git a/consensus/ibft/src/integration-test/java/org/hyperledger/besu/consensus/ibft/support/TestContextBuilder.java b/consensus/ibft/src/integration-test/java/org/hyperledger/besu/consensus/ibft/support/TestContextBuilder.java index 88eba5b89304..41fbbbe1940f 100644 --- a/consensus/ibft/src/integration-test/java/org/hyperledger/besu/consensus/ibft/support/TestContextBuilder.java +++ b/consensus/ibft/src/integration-test/java/org/hyperledger/besu/consensus/ibft/support/TestContextBuilder.java @@ -312,8 +312,8 @@ private static ControllerAndState createControllerAndFinalState( .isMiningEnabled(true) .minTransactionGasPrice(Wei.ZERO) .extraData(Bytes.wrap("Ibft Int tests".getBytes(UTF_8))) + .coinbase(AddressHelpers.ofValue(1)) .build()) - .coinbase(AddressHelpers.ofValue(1)) .build(); final StubGenesisConfigOptions genesisConfigOptions = new StubGenesisConfigOptions(); diff --git a/consensus/ibft/src/test/java/org/hyperledger/besu/consensus/ibft/blockcreation/BftBlockCreatorTest.java b/consensus/ibft/src/test/java/org/hyperledger/besu/consensus/ibft/blockcreation/BftBlockCreatorTest.java index 14c1eddc70fb..afd967a2caf9 100644 --- a/consensus/ibft/src/test/java/org/hyperledger/besu/consensus/ibft/blockcreation/BftBlockCreatorTest.java +++ b/consensus/ibft/src/test/java/org/hyperledger/besu/consensus/ibft/blockcreation/BftBlockCreatorTest.java @@ -165,8 +165,8 @@ public BlockHeaderValidator.Builder createBlockHeaderRuleset( 0, initialValidatorList))) .minTransactionGasPrice(Wei.ZERO) + .coinbase(AddressHelpers.ofValue(1)) .build()) - .coinbase(AddressHelpers.ofValue(1)) .build(); final BftBlockCreator blockCreator = diff --git a/consensus/merge/src/main/java/org/hyperledger/besu/consensus/merge/blockcreation/MergeBlockCreator.java b/consensus/merge/src/main/java/org/hyperledger/besu/consensus/merge/blockcreation/MergeBlockCreator.java index 294e09435989..b81a941816ae 100644 --- a/consensus/merge/src/main/java/org/hyperledger/besu/consensus/merge/blockcreation/MergeBlockCreator.java +++ b/consensus/merge/src/main/java/org/hyperledger/besu/consensus/merge/blockcreation/MergeBlockCreator.java @@ -44,7 +44,6 @@ class MergeBlockCreator extends AbstractBlockCreator { * @param transactionPool the pending transactions * @param protocolContext the protocol context * @param protocolSchedule the protocol schedule - * @param miningBeneficiary the mining beneficiary * @param parentHeader the parent header */ public MergeBlockCreator( @@ -53,13 +52,11 @@ public MergeBlockCreator( final TransactionPool transactionPool, final ProtocolContext protocolContext, final ProtocolSchedule protocolSchedule, - final Address miningBeneficiary, final BlockHeader parentHeader, final Optional
depositContractAddress) { super( miningParameters, - miningBeneficiary, - __ -> miningBeneficiary, + __ -> miningParameters.getCoinbase().orElseThrow(), extraDataCalculator, transactionPool, protocolContext, diff --git a/consensus/merge/src/main/java/org/hyperledger/besu/consensus/merge/blockcreation/MergeCoordinator.java b/consensus/merge/src/main/java/org/hyperledger/besu/consensus/merge/blockcreation/MergeCoordinator.java index 308fd9b4aba3..b83e607ef4bb 100644 --- a/consensus/merge/src/main/java/org/hyperledger/besu/consensus/merge/blockcreation/MergeCoordinator.java +++ b/consensus/merge/src/main/java/org/hyperledger/besu/consensus/merge/blockcreation/MergeCoordinator.java @@ -118,6 +118,9 @@ public MergeCoordinator( this.mergeContext = protocolContext.getConsensusContext(MergeContext.class); this.backwardSyncContext = backwardSyncContext; + if (miningParams.getCoinbase().isEmpty()) { + miningParams.setCoinbase(Address.ZERO); + } if (miningParams.getTargetGasLimit().isEmpty()) { miningParams.setTargetGasLimit(30000000L); } @@ -133,7 +136,6 @@ public MergeCoordinator( transactionPool, protocolContext, protocolSchedule, - address.or(miningParameters::getCoinbase).orElse(Address.ZERO), parentHeader, depositContractAddress); diff --git a/consensus/merge/src/test/java/org/hyperledger/besu/consensus/merge/blockcreation/MergeCoordinatorTest.java b/consensus/merge/src/test/java/org/hyperledger/besu/consensus/merge/blockcreation/MergeCoordinatorTest.java index 28fe40d5d708..3eeb87539bdd 100644 --- a/consensus/merge/src/test/java/org/hyperledger/besu/consensus/merge/blockcreation/MergeCoordinatorTest.java +++ b/consensus/merge/src/test/java/org/hyperledger/besu/consensus/merge/blockcreation/MergeCoordinatorTest.java @@ -57,6 +57,7 @@ import org.hyperledger.besu.ethereum.core.BlockHeaderTestFixture; import org.hyperledger.besu.ethereum.core.Difficulty; import org.hyperledger.besu.ethereum.core.ImmutableMiningParameters; +import org.hyperledger.besu.ethereum.core.ImmutableMiningParameters.Unstable; import org.hyperledger.besu.ethereum.core.ImmutableMiningParameters.UpdatableInitValues; import org.hyperledger.besu.ethereum.core.MiningParameters; import org.hyperledger.besu.ethereum.core.TransactionTestFixture; @@ -134,9 +135,9 @@ public class MergeCoordinatorTest implements MergeGenesisConfigHelper { MiningParameters miningParameters = ImmutableMiningParameters.builder() - .coinbase(coinbase) + .updatableInitValues(UpdatableInitValues.builder().coinbase(coinbase).build()) .unstable( - ImmutableMiningParameters.Unstable.builder() + Unstable.builder() .posBlockCreationRepetitionMinDuration(REPETITION_MIN_DURATION) .build()) .build(); @@ -285,7 +286,6 @@ public void exceptionDuringBuildingBlockShouldNotBeInvalid() transactionPool, protocolContext, protocolSchedule, - address.or(miningParameters::getCoinbase).orElse(Address.ZERO), parentHeader, Optional.empty())); @@ -551,8 +551,7 @@ public void shouldStopRetryBlockCreationIfTimeExpired() throws InterruptedExcept miningParameters = ImmutableMiningParameters.builder() .from(miningParameters) - .unstable( - ImmutableMiningParameters.Unstable.builder().posBlockCreationMaxTime(100).build()) + .unstable(Unstable.builder().posBlockCreationMaxTime(100).build()) .build(); doAnswer( invocation -> { diff --git a/consensus/merge/src/test/java/org/hyperledger/besu/consensus/merge/blockcreation/MergeReorgTest.java b/consensus/merge/src/test/java/org/hyperledger/besu/consensus/merge/blockcreation/MergeReorgTest.java index 4c9712c9b474..75de7e190d35 100644 --- a/consensus/merge/src/test/java/org/hyperledger/besu/consensus/merge/blockcreation/MergeReorgTest.java +++ b/consensus/merge/src/test/java/org/hyperledger/besu/consensus/merge/blockcreation/MergeReorgTest.java @@ -34,6 +34,7 @@ import org.hyperledger.besu.ethereum.core.BlockHeaderTestFixture; import org.hyperledger.besu.ethereum.core.Difficulty; import org.hyperledger.besu.ethereum.core.ImmutableMiningParameters; +import org.hyperledger.besu.ethereum.core.ImmutableMiningParameters.UpdatableInitValues; import org.hyperledger.besu.ethereum.eth.sync.backwardsync.BackwardSyncContext; import org.hyperledger.besu.ethereum.eth.transactions.TransactionPool; import org.hyperledger.besu.ethereum.mainnet.BlockHeaderValidator; @@ -93,7 +94,9 @@ public void setUp() { mockProtocolSchedule, CompletableFuture::runAsync, mockTransactionPool, - ImmutableMiningParameters.builder().coinbase(coinbase).build(), + ImmutableMiningParameters.builder() + .updatableInitValues(UpdatableInitValues.builder().coinbase(coinbase).build()) + .build(), mock(BackwardSyncContext.class), Optional.empty()); mergeContext.setIsPostMerge(genesisState.getBlock().getHeader().getDifficulty()); diff --git a/consensus/qbft/src/integration-test/java/org/hyperledger/besu/consensus/qbft/support/TestContextBuilder.java b/consensus/qbft/src/integration-test/java/org/hyperledger/besu/consensus/qbft/support/TestContextBuilder.java index afbc27426372..c1a05a9709e7 100644 --- a/consensus/qbft/src/integration-test/java/org/hyperledger/besu/consensus/qbft/support/TestContextBuilder.java +++ b/consensus/qbft/src/integration-test/java/org/hyperledger/besu/consensus/qbft/support/TestContextBuilder.java @@ -372,8 +372,8 @@ private static ControllerAndState createControllerAndFinalState( .isMiningEnabled(true) .minTransactionGasPrice(Wei.ZERO) .extraData(Bytes.wrap("Qbft Int tests".getBytes(UTF_8))) + .coinbase(AddressHelpers.ofValue(1)) .build()) - .coinbase(AddressHelpers.ofValue(1)) .build(); final StubGenesisConfigOptions genesisConfigOptions = new StubGenesisConfigOptions(); diff --git a/ethereum/blockcreation/src/main/java/org/hyperledger/besu/ethereum/blockcreation/AbstractBlockCreator.java b/ethereum/blockcreation/src/main/java/org/hyperledger/besu/ethereum/blockcreation/AbstractBlockCreator.java index 060771b7ca62..a8bb17e93cdc 100644 --- a/ethereum/blockcreation/src/main/java/org/hyperledger/besu/ethereum/blockcreation/AbstractBlockCreator.java +++ b/ethereum/blockcreation/src/main/java/org/hyperledger/besu/ethereum/blockcreation/AbstractBlockCreator.java @@ -79,7 +79,6 @@ public interface ExtraDataCalculator { private static final Logger LOG = LoggerFactory.getLogger(AbstractBlockCreator.class); - protected final Address coinbase; private final MiningBeneficiaryCalculator miningBeneficiaryCalculator; private final ExtraDataCalculator extraDataCalculator; private final TransactionPool transactionPool; @@ -94,7 +93,6 @@ public interface ExtraDataCalculator { protected AbstractBlockCreator( final MiningParameters miningParameters, - final Address coinbase, final MiningBeneficiaryCalculator miningBeneficiaryCalculator, final ExtraDataCalculator extraDataCalculator, final TransactionPool transactionPool, @@ -103,7 +101,6 @@ protected AbstractBlockCreator( final BlockHeader parentHeader, final Optional
depositContractAddress) { this.miningParameters = miningParameters; - this.coinbase = coinbase; this.miningBeneficiaryCalculator = miningBeneficiaryCalculator; this.extraDataCalculator = extraDataCalculator; this.transactionPool = transactionPool; @@ -411,7 +408,7 @@ private ProcessableBlockHeader createPendingBlockHeader( final Bytes32 parentBeaconBlockRoot = maybeParentBeaconBlockRoot.orElse(null); return BlockHeaderBuilder.create() .parentHash(parentHeader.getHash()) - .coinbase(coinbase) + .coinbase(miningParameters.getCoinbase().orElseThrow()) .difficulty(Difficulty.of(difficulty)) .number(newBlockNumber) .gasLimit(gasLimit) diff --git a/ethereum/blockcreation/src/main/java/org/hyperledger/besu/ethereum/blockcreation/PoWBlockCreator.java b/ethereum/blockcreation/src/main/java/org/hyperledger/besu/ethereum/blockcreation/PoWBlockCreator.java index 032ad0b8fed5..66c57379ccba 100644 --- a/ethereum/blockcreation/src/main/java/org/hyperledger/besu/ethereum/blockcreation/PoWBlockCreator.java +++ b/ethereum/blockcreation/src/main/java/org/hyperledger/besu/ethereum/blockcreation/PoWBlockCreator.java @@ -14,7 +14,6 @@ */ package org.hyperledger.besu.ethereum.blockcreation; -import org.hyperledger.besu.datatypes.Address; import org.hyperledger.besu.ethereum.ProtocolContext; import org.hyperledger.besu.ethereum.core.BlockHeader; import org.hyperledger.besu.ethereum.core.BlockHeaderBuilder; @@ -40,7 +39,6 @@ public class PoWBlockCreator extends AbstractBlockCreator { public PoWBlockCreator( final MiningParameters miningParameters, - final Address coinbase, final ExtraDataCalculator extraDataCalculator, final TransactionPool transactionPool, final ProtocolContext protocolContext, @@ -49,8 +47,7 @@ public PoWBlockCreator( final BlockHeader parentHeader) { super( miningParameters, - coinbase, - __ -> coinbase, + __ -> miningParameters.getCoinbase().orElseThrow(), extraDataCalculator, transactionPool, protocolContext, diff --git a/ethereum/blockcreation/src/main/java/org/hyperledger/besu/ethereum/blockcreation/PoWMinerExecutor.java b/ethereum/blockcreation/src/main/java/org/hyperledger/besu/ethereum/blockcreation/PoWMinerExecutor.java index f10fe3d77715..cd44318e960e 100644 --- a/ethereum/blockcreation/src/main/java/org/hyperledger/besu/ethereum/blockcreation/PoWMinerExecutor.java +++ b/ethereum/blockcreation/src/main/java/org/hyperledger/besu/ethereum/blockcreation/PoWMinerExecutor.java @@ -32,7 +32,6 @@ public class PoWMinerExecutor extends AbstractMinerExecutor { - protected volatile Optional
coinbase; protected boolean stratumMiningEnabled; protected final EpochCalculator epochCalculator; @@ -44,7 +43,6 @@ public PoWMinerExecutor( final AbstractBlockScheduler blockScheduler, final EpochCalculator epochCalculator) { super(protocolContext, protocolSchedule, transactionPool, miningParams, blockScheduler); - this.coinbase = miningParams.getCoinbase(); if (miningParams.getNonceGenerator().isEmpty()) { miningParams.setNonceGenerator(new RandomNonceGenerator()); } @@ -56,7 +54,7 @@ public Optional startAsyncMining( final Subscribers observers, final Subscribers ethHashObservers, final BlockHeader parentHeader) { - if (coinbase.isEmpty()) { + if (miningParameters.getCoinbase().isEmpty()) { throw new CoinbaseNotSetException("Unable to start mining without a coinbase."); } return super.startAsyncMining(observers, ethHashObservers, parentHeader); @@ -82,7 +80,6 @@ public PoWBlockMiner createMiner( (header) -> new PoWBlockCreator( miningParameters, - coinbase.orElse(Address.ZERO), parent -> miningParameters.getExtraData(), transactionPool, protocolContext, @@ -98,7 +95,7 @@ public void setCoinbase(final Address coinbase) { if (coinbase == null) { throw new IllegalArgumentException("Coinbase cannot be unset."); } else { - this.coinbase = Optional.of(Address.wrap(coinbase.copy())); + miningParameters.setCoinbase(Address.wrap(coinbase.copy())); } } @@ -108,7 +105,7 @@ void setStratumMiningEnabled(final boolean stratumMiningEnabled) { @Override public Optional
getCoinbase() { - return coinbase; + return miningParameters.getCoinbase(); } public EpochCalculator getEpochCalculator() { diff --git a/ethereum/blockcreation/src/test/java/org/hyperledger/besu/ethereum/blockcreation/AbstractBlockCreatorTest.java b/ethereum/blockcreation/src/test/java/org/hyperledger/besu/ethereum/blockcreation/AbstractBlockCreatorTest.java index 8a2e91f664f9..3ed629cb9354 100644 --- a/ethereum/blockcreation/src/test/java/org/hyperledger/besu/ethereum/blockcreation/AbstractBlockCreatorTest.java +++ b/ethereum/blockcreation/src/test/java/org/hyperledger/besu/ethereum/blockcreation/AbstractBlockCreatorTest.java @@ -392,13 +392,12 @@ private AbstractBlockCreator createBlockCreator( .extraData(Bytes.fromHexString("deadbeef")) .minTransactionGasPrice(Wei.ONE) .minBlockOccupancyRatio(0d) + .coinbase(Address.ZERO) .build()) - .coinbase(Address.ZERO) .build(); return new TestBlockCreator( miningParameters, - Address.ZERO, __ -> Address.ZERO, __ -> Bytes.fromHexString("deadbeef"), transactionPool, @@ -412,7 +411,6 @@ static class TestBlockCreator extends AbstractBlockCreator { protected TestBlockCreator( final MiningParameters miningParameters, - final Address coinbase, final MiningBeneficiaryCalculator miningBeneficiaryCalculator, final ExtraDataCalculator extraDataCalculator, final TransactionPool transactionPool, @@ -422,7 +420,6 @@ protected TestBlockCreator( final Optional
depositContractAddress) { super( miningParameters, - coinbase, miningBeneficiaryCalculator, extraDataCalculator, transactionPool, diff --git a/ethereum/blockcreation/src/test/java/org/hyperledger/besu/ethereum/blockcreation/PoWBlockCreatorTest.java b/ethereum/blockcreation/src/test/java/org/hyperledger/besu/ethereum/blockcreation/PoWBlockCreatorTest.java index 2d428dcc054f..cddb0073f8dc 100644 --- a/ethereum/blockcreation/src/test/java/org/hyperledger/besu/ethereum/blockcreation/PoWBlockCreatorTest.java +++ b/ethereum/blockcreation/src/test/java/org/hyperledger/besu/ethereum/blockcreation/PoWBlockCreatorTest.java @@ -94,8 +94,7 @@ void createMainnetBlock1() throws IOException { .createProtocolSchedule()) .build(); - final MiningParameters miningParameters = - createMiningParameters(Lists.newArrayList(BLOCK_1_NONCE)); + final MiningParameters miningParameters = createMiningParameters(); final PoWSolver solver = new PoWSolver( @@ -110,7 +109,6 @@ void createMainnetBlock1() throws IOException { final PoWBlockCreator blockCreator = new PoWBlockCreator( miningParameters, - BLOCK_1_COINBASE, parent -> BLOCK_1_EXTRA_DATA, transactionPool, executionContextTestFixture.getProtocolContext(), @@ -149,8 +147,7 @@ void createMainnetBlock1_fixedDifficulty1() { .createProtocolSchedule()) .build(); - final MiningParameters miningParameters = - createMiningParameters(Lists.newArrayList(BLOCK_1_NONCE)); + final MiningParameters miningParameters = createMiningParameters(); final PoWSolver solver = new PoWSolver( @@ -165,7 +162,6 @@ void createMainnetBlock1_fixedDifficulty1() { final PoWBlockCreator blockCreator = new PoWBlockCreator( miningParameters, - BLOCK_1_COINBASE, parent -> BLOCK_1_EXTRA_DATA, transactionPool, executionContextTestFixture.getProtocolContext(), @@ -195,8 +191,7 @@ void rewardBeneficiary_zeroReward_skipZeroRewardsFalse() { final ExecutionContextTestFixture executionContextTestFixture = ExecutionContextTestFixture.builder().protocolSchedule(protocolSchedule).build(); - final MiningParameters miningParameters = - createMiningParameters(Lists.newArrayList(BLOCK_1_NONCE)); + final MiningParameters miningParameters = createMiningParameters(); final PoWSolver solver = new PoWSolver( @@ -211,7 +206,6 @@ void rewardBeneficiary_zeroReward_skipZeroRewardsFalse() { final PoWBlockCreator blockCreator = new PoWBlockCreator( miningParameters, - BLOCK_1_COINBASE, parent -> BLOCK_1_EXTRA_DATA, transactionPool, executionContextTestFixture.getProtocolContext(), @@ -263,8 +257,7 @@ void rewardBeneficiary_zeroReward_skipZeroRewardsTrue() { final ExecutionContextTestFixture executionContextTestFixture = ExecutionContextTestFixture.builder().protocolSchedule(protocolSchedule).build(); - final MiningParameters miningParameters = - createMiningParameters(Lists.newArrayList(BLOCK_1_NONCE)); + final MiningParameters miningParameters = createMiningParameters(); final PoWSolver solver = new PoWSolver( @@ -279,7 +272,6 @@ void rewardBeneficiary_zeroReward_skipZeroRewardsTrue() { final PoWBlockCreator blockCreator = new PoWBlockCreator( miningParameters, - BLOCK_1_COINBASE, parent -> BLOCK_1_EXTRA_DATA, transactionPool, executionContextTestFixture.getProtocolContext(), @@ -344,15 +336,15 @@ private TransactionPool createTransactionPool( return transactionPool; } - private MiningParameters createMiningParameters(final Iterable nonceList) { + private MiningParameters createMiningParameters() { return ImmutableMiningParameters.builder() .updatableInitValues( ImmutableMiningParameters.UpdatableInitValues.builder() - .nonceGenerator(nonceList) + .nonceGenerator(Lists.newArrayList(BLOCK_1_NONCE)) .extraData(BLOCK_1_EXTRA_DATA) .minTransactionGasPrice(Wei.ONE) + .coinbase(BLOCK_1_COINBASE) .build()) - .coinbase(BLOCK_1_COINBASE) .build(); } } diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/MiningParameters.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/MiningParameters.java index 298dc87d5738..ea14d863839d 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/MiningParameters.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/MiningParameters.java @@ -40,8 +40,6 @@ public static final MiningParameters newDefault() { return ImmutableMiningParameters.builder().build(); } - public abstract Optional
getCoinbase(); - public boolean isMiningEnabled() { return getUpdatableRuntimeValues().miningEnabled; } @@ -69,6 +67,15 @@ public MiningParameters setMinTransactionGasPrice(final Wei minTransactionGasPri return this; } + public Optional
getCoinbase() { + return getUpdatableRuntimeValues().coinbase; + } + + public MiningParameters setCoinbase(final Address coinbase) { + getUpdatableRuntimeValues().coinbase = Optional.of(coinbase); + return this; + } + public OptionalLong getTargetGasLimit() { return getUpdatableRuntimeValues().targetGasLimit; } @@ -154,6 +161,8 @@ default double getMinBlockOccupancyRatio() { return DEFAULT_MIN_BLOCK_OCCUPANCY_RATIO; } + Optional
getCoinbase(); + OptionalLong getTargetGasLimit(); Optional> nonceGenerator(); @@ -164,6 +173,7 @@ static class UpdatableRuntimeValues { private volatile Bytes extraData; private volatile Wei minTransactionGasPrice; private volatile double minBlockOccupancyRatio; + private volatile Optional
coinbase; private volatile OptionalLong targetGasLimit; private volatile Optional> nonceGenerator; @@ -172,6 +182,7 @@ private UpdatableRuntimeValues(final UpdatableInitValues initValues) { extraData = initValues.getExtraData(); minTransactionGasPrice = initValues.getMinTransactionGasPrice(); minBlockOccupancyRatio = initValues.getMinBlockOccupancyRatio(); + coinbase = initValues.getCoinbase(); targetGasLimit = initValues.getTargetGasLimit(); nonceGenerator = initValues.nonceGenerator(); } @@ -185,6 +196,7 @@ public boolean equals(final Object o) { && Double.compare(minBlockOccupancyRatio, that.minBlockOccupancyRatio) == 0 && Objects.equals(extraData, that.extraData) && Objects.equals(minTransactionGasPrice, that.minTransactionGasPrice) + && Objects.equals(coinbase, that.coinbase) && Objects.equals(targetGasLimit, that.targetGasLimit) && Objects.equals(nonceGenerator, that.nonceGenerator); } @@ -196,6 +208,7 @@ public int hashCode() { extraData, minTransactionGasPrice, minBlockOccupancyRatio, + coinbase, targetGasLimit, nonceGenerator); } @@ -211,6 +224,8 @@ public String toString() { + minTransactionGasPrice + ", minBlockOccupancyRatio=" + minBlockOccupancyRatio + + ", coinbase=" + + coinbase + ", targetGasLimit=" + targetGasLimit + ", nonceGenerator=" diff --git a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/bonsai/AbstractIsolationTests.java b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/bonsai/AbstractIsolationTests.java index a51846b528e2..0d30843cb388 100644 --- a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/bonsai/AbstractIsolationTests.java +++ b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/bonsai/AbstractIsolationTests.java @@ -207,7 +207,6 @@ public int getDatabaseVersion() { static class TestBlockCreator extends AbstractBlockCreator { private TestBlockCreator( final MiningParameters miningParameters, - final Address coinbase, final MiningBeneficiaryCalculator miningBeneficiaryCalculator, final ExtraDataCalculator extraDataCalculator, final TransactionPool transactionPool, @@ -216,7 +215,6 @@ private TestBlockCreator( final BlockHeader parentHeader) { super( miningParameters, - coinbase, miningBeneficiaryCalculator, extraDataCalculator, transactionPool, @@ -240,13 +238,12 @@ static TestBlockCreator forHeader( .targetGasLimit(30_000_000L) .minTransactionGasPrice(Wei.ONE) .minBlockOccupancyRatio(0d) + .coinbase(Address.ZERO) .build()) - .coinbase(Address.ZERO) .build(); return new TestBlockCreator( miningParameters, - Address.ZERO, __ -> Address.ZERO, __ -> Bytes.fromHexString("deadbeef"), transactionPool, diff --git a/ethereum/retesteth/src/main/java/org/hyperledger/besu/ethereum/retesteth/RetestethContext.java b/ethereum/retesteth/src/main/java/org/hyperledger/besu/ethereum/retesteth/RetestethContext.java index 706120b1bfc5..2327bfaae077 100644 --- a/ethereum/retesteth/src/main/java/org/hyperledger/besu/ethereum/retesteth/RetestethContext.java +++ b/ethereum/retesteth/src/main/java/org/hyperledger/besu/ethereum/retesteth/RetestethContext.java @@ -32,6 +32,8 @@ import org.hyperledger.besu.ethereum.core.BlockHeader; import org.hyperledger.besu.ethereum.core.BlockHeaderFunctions; import org.hyperledger.besu.ethereum.core.ImmutableMiningParameters; +import org.hyperledger.besu.ethereum.core.ImmutableMiningParameters.Unstable; +import org.hyperledger.besu.ethereum.core.ImmutableMiningParameters.UpdatableInitValues; import org.hyperledger.besu.ethereum.core.MiningParameters; import org.hyperledger.besu.ethereum.core.MutableWorldState; import org.hyperledger.besu.ethereum.eth.EthProtocolConfiguration; @@ -99,7 +101,7 @@ public class RetestethContext { private HeaderValidationMode headerValidationMode; private BlockReplay blockReplay; private RetestethClock retestethClock; - + private MiningParameters miningParameters; private TransactionPool transactionPool; private EthScheduler ethScheduler; private PoWSolver poWSolver; @@ -180,13 +182,17 @@ private boolean buildContext( ? HeaderValidationMode.LIGHT : HeaderValidationMode.FULL; - final MiningParameters miningParameters = + miningParameters = ImmutableMiningParameters.builder() - .unstable( - ImmutableMiningParameters.Unstable.builder() - .powJobTimeToLive(1000) - .maxOmmerDepth(8) + .updatableInitValues( + UpdatableInitValues.builder() + .coinbase(coinbase) + .extraData(extraData) + .targetGasLimit(blockchain.getChainHeadHeader().getGasLimit()) + .minBlockOccupancyRatio(0.0) + .minTransactionGasPrice(Wei.ZERO) .build()) + .unstable(Unstable.builder().powJobTimeToLive(1000).maxOmmerDepth(8).build()) .build(); miningParameters.setMinTransactionGasPrice(Wei.ZERO); poWSolver = @@ -311,12 +317,8 @@ public TransactionPool getTransactionPool() { return transactionPool; } - public Address getCoinbase() { - return coinbase; - } - - public Bytes getExtraData() { - return extraData; + public MiningParameters getMiningParameters() { + return miningParameters; } public MutableBlockchain getBlockchain() { diff --git a/ethereum/retesteth/src/main/java/org/hyperledger/besu/ethereum/retesteth/methods/TestMineBlocks.java b/ethereum/retesteth/src/main/java/org/hyperledger/besu/ethereum/retesteth/methods/TestMineBlocks.java index 4b6b868383dc..6c3fddae1c7b 100644 --- a/ethereum/retesteth/src/main/java/org/hyperledger/besu/ethereum/retesteth/methods/TestMineBlocks.java +++ b/ethereum/retesteth/src/main/java/org/hyperledger/besu/ethereum/retesteth/methods/TestMineBlocks.java @@ -14,7 +14,6 @@ */ package org.hyperledger.besu.ethereum.retesteth.methods; -import org.hyperledger.besu.datatypes.Wei; import org.hyperledger.besu.ethereum.ProtocolContext; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequestContext; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.JsonRpcMethod; @@ -24,7 +23,6 @@ import org.hyperledger.besu.ethereum.chain.MutableBlockchain; import org.hyperledger.besu.ethereum.core.Block; import org.hyperledger.besu.ethereum.core.BlockImporter; -import org.hyperledger.besu.ethereum.core.ImmutableMiningParameters; import org.hyperledger.besu.ethereum.core.MiningParameters; import org.hyperledger.besu.ethereum.mainnet.BlockImportResult; import org.hyperledger.besu.ethereum.mainnet.HeaderValidationMode; @@ -62,20 +60,11 @@ private boolean mineNewBlock() { final ProtocolContext protocolContext = context.getProtocolContext(); final MutableBlockchain blockchain = context.getBlockchain(); final HeaderValidationMode headerValidationMode = context.getHeaderValidationMode(); - final MiningParameters miningParameters = - ImmutableMiningParameters.builder() - .updatableInitValues( - ImmutableMiningParameters.UpdatableInitValues.builder() - .targetGasLimit(blockchain.getChainHeadHeader().getGasLimit()) - .minBlockOccupancyRatio(0.0) - .minTransactionGasPrice(Wei.ZERO) - .build()) - .build(); + final MiningParameters miningParameters = context.getMiningParameters(); final PoWBlockCreator blockCreator = new PoWBlockCreator( miningParameters, - context.getCoinbase(), - header -> context.getExtraData(), + header -> miningParameters.getExtraData(), context.getTransactionPool(), protocolContext, protocolSchedule,