Use protocol schedule to determine mining beneficiary (#8387)

* Use protocol schedule to determine mining beneficiary

Signed-off-by: Matthew Whitehead <matthew.whitehead@kaleido.io>

* Add entry to changelog

Signed-off-by: Matthew Whitehead <matthew.whitehead@kaleido.io>

* Update isolation test

Signed-off-by: Matthew Whitehead <matthew.whitehead@kaleido.io>

* Fix for zero addresses

Signed-off-by: Matthew Whitehead <matthew.whitehead@kaleido.io>

* Test compile fix

Signed-off-by: Matthew Whitehead <matthew.whitehead@kaleido.io>

* Use next header, not current header

Signed-off-by: Matthew Whitehead <matthew1001@gmail.com>

---------

Signed-off-by: Matthew Whitehead <matthew.whitehead@kaleido.io>
Signed-off-by: Matthew Whitehead <matthew1001@gmail.com>
Signed-off-by: Matt Whitehead <matthew.whitehead@kaleido.io>
This commit is contained in:
Matt Whitehead
2025-03-14 10:10:41 +00:00
committed by GitHub
parent b7a0b91f84
commit a190be3f3c
8 changed files with 22 additions and 11 deletions

View File

@@ -50,6 +50,7 @@
- Add missing RPC method `debug_accountRange` to `RpcMethod.java` so this method can be used with `--rpc-http-api-method-no-auth` [#8153](https://github.com/hyperledger/besu/issues/8153)
- Add a fallback pivot strategy when the safe block does not change for a long time, to make possible to complete the initial sync in case the chain is not finalizing [#8395](https://github.com/hyperledger/besu/pull/8395)
- Fix issue with new QBFT/IBFT blocks being produced under certain circumstances. [#8308](https://github.com/hyperledger/besu/issues/8308)
- Fix QBFT and IBFT transitions that change the mining beneficiary [#8387](https://github.com/hyperledger/besu/issues/8387)
## 25.2.2 hotfix
- Pectra - Sepolia: Fix for deposit contract log decoding [#8383](https://github.com/hyperledger/besu/pull/8383)

View File

@@ -68,7 +68,7 @@ public class CliqueBlockCreator extends AbstractBlockCreator {
final EthScheduler ethScheduler) {
super(
miningConfiguration,
__ -> Util.publicKeyToAddress(nodeKey.getPublicKey()),
(__, ___) -> Util.publicKeyToAddress(nodeKey.getPublicKey()),
extraDataCalculator,
transactionPool,
protocolContext,

View File

@@ -68,7 +68,7 @@ public class BftBlockCreator extends AbstractBlockCreator {
final EthScheduler ethScheduler) {
super(
miningConfiguration.setCoinbase(localAddress),
miningBeneficiaryCalculator(localAddress, forksSchedule),
miningBeneficiaryCalculator(localAddress, protocolSchedule),
extraDataCalculator,
transactionPool,
protocolContext,
@@ -91,9 +91,19 @@ public class BftBlockCreator extends AbstractBlockCreator {
}
private static MiningBeneficiaryCalculator miningBeneficiaryCalculator(
final Address localAddress, final ForksSchedule<? extends BftConfigOptions> forksSchedule) {
return blockNum ->
forksSchedule.getFork(blockNum).getValue().getMiningBeneficiary().orElse(localAddress);
final Address localAddress, final ProtocolSchedule protocolSchedule) {
return (blockTimestamp, pendingHeader) -> {
BlockHeader newBlockHeader =
BlockHeaderBuilder.createDefault()
.coinbase(pendingHeader.getCoinbase())
.buildBlockHeader();
ProtocolSpec protocolSpec =
((BftProtocolSchedule) protocolSchedule)
.getByBlockNumberOrTimestamp(pendingHeader.getNumber(), blockTimestamp);
Address beneficiaryAddress =
protocolSpec.getMiningBeneficiaryCalculator().calculateBeneficiary(newBlockHeader);
return !beneficiaryAddress.isZero() ? beneficiaryAddress : localAddress;
};
}
@Override

View File

@@ -56,7 +56,7 @@ class MergeBlockCreator extends AbstractBlockCreator {
final EthScheduler ethScheduler) {
super(
miningConfiguration,
__ -> miningConfiguration.getCoinbase().orElseThrow(),
(__, ___) -> miningConfiguration.getCoinbase().orElseThrow(),
extraDataCalculator,
transactionPool,
protocolContext,

View File

@@ -205,7 +205,7 @@ public abstract class AbstractBlockCreator implements AsyncBlockCreator {
.buildProcessableBlockHeader();
final Address miningBeneficiary =
miningBeneficiaryCalculator.getMiningBeneficiary(processableBlockHeader.getNumber());
miningBeneficiaryCalculator.getMiningBeneficiary(timestamp, processableBlockHeader);
throwIfStopped();
@@ -495,6 +495,6 @@ public abstract class AbstractBlockCreator implements AsyncBlockCreator {
@FunctionalInterface
protected interface MiningBeneficiaryCalculator {
Address getMiningBeneficiary(long blockNumber);
Address getMiningBeneficiary(long blockTimestamp, ProcessableBlockHeader parentHeader);
}
}

View File

@@ -48,7 +48,7 @@ public class PoWBlockCreator extends AbstractBlockCreator {
final EthScheduler ethScheduler) {
super(
miningConfiguration,
__ -> miningConfiguration.getCoinbase().orElseThrow(),
(__, ___) -> miningConfiguration.getCoinbase().orElseThrow(),
extraDataCalculator,
transactionPool,
protocolContext,

View File

@@ -359,7 +359,7 @@ abstract class AbstractBlockCreatorTest {
return new CreateOn(
new TestBlockCreator(
miningConfiguration,
__ -> Address.ZERO,
(__, ___) -> Address.ZERO,
__ -> Bytes.fromHexString("deadbeef"),
transactionPool,
executionContextTestFixture.getProtocolContext(),

View File

@@ -306,7 +306,7 @@ public abstract class AbstractIsolationTests {
return new TestBlockCreator(
miningConfiguration,
__ -> Address.ZERO,
(__, ___) -> Address.ZERO,
__ -> Bytes.fromHexString("deadbeef"),
transactionPool,
protocolContext,