Skip to content

Commit

Permalink
Merge branch 'main' into zkbesu
Browse files Browse the repository at this point in the history
  • Loading branch information
fab-10 committed Sep 10, 2024
2 parents 9fe8547 + 500a98b commit 6f74319
Show file tree
Hide file tree
Showing 39 changed files with 379 additions and 217 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
- Correctly drops messages that exceeds local message size limit [#5455](https://github.com/hyperledger/besu/pull/7507)
- **DebugMetrics**: Fixed a `ClassCastException` occurring in `DebugMetrics` when handling nested metric structures. Previously, `Double` values within these structures were incorrectly cast to `Map` objects, leading to errors. This update allows for proper handling of both direct values and nested structures at the same level. Issue# [#7383](https://github.com/hyperledger/besu/pull/7383)
- `evmtool` was not respecting the `--genesis` setting, resulting in unexpected trace results. [#7433](https://github.com/hyperledger/besu/pull/7433)
- The genesis config override `contractSizeLimit`q was not wired into code size limits [#7557](https://github.com/hyperledger/besu/pull/7557)
- The genesis config override `contractSizeLimit` was not wired into code size limits [#7557](https://github.com/hyperledger/besu/pull/7557)
- Fix incorrect key filtering in LayeredKeyValueStorage stream [#7535](https://github.com/hyperledger/besu/pull/7557)

## 24.8.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,29 +175,61 @@ public void shouldCheckNonceAfterNonceIncreaseOfSender() throws IOException {
besuNode.execute(ethTransactions.sendRawTransaction(tx.encoded().toHexString()));
testHelper.buildNewBlock();

Optional<TransactionReceipt> maybeTransactionReceipt =
final Optional<TransactionReceipt> maybeFirstTransactionReceipt =
besuNode.execute(ethTransactions.getTransactionReceipt(txHash));
assertThat(maybeTransactionReceipt).isPresent();
assertThat(maybeFirstTransactionReceipt).isPresent();

final String gasPriceWithout0x =
maybeTransactionReceipt.get().getEffectiveGasPrice().substring(2);
maybeFirstTransactionReceipt.get().getEffectiveGasPrice().substring(2);
final BigInteger gasPrice = new BigInteger(gasPriceWithout0x, 16);
final BigInteger txCost = maybeTransactionReceipt.get().getGasUsed().multiply(gasPrice);
final BigInteger txCost = maybeFirstTransactionReceipt.get().getGasUsed().multiply(gasPrice);

final BigInteger authorizerBalance = besuNode.execute(ethTransactions.getBalance(authorizer));
final BigInteger authorizerBalanceAfterFirstTx =
besuNode.execute(ethTransactions.getBalance(authorizer));

// The remaining balance of the authorizer should the gas limit multiplied by the gas price
// minus the transaction cost.
// The following executes this calculation in reverse.
assertThat(GAS_LIMIT).isEqualTo(authorizerBalance.add(txCost).divide(gasPrice).longValue());
assertThat(GAS_LIMIT)
.isEqualTo(authorizerBalanceAfterFirstTx.add(txCost).divide(gasPrice).longValue());

// The other accounts balance should be the initial 9000 ETH balance from the authorizer minus
// the remaining balance of the authorizer and minus the transaction cost
cluster.verify(
otherAccount.balanceEquals(
Amount.wei(
new BigInteger("90000000000000000000000")
.subtract(authorizerBalance)
.subtract(txCost))));
final BigInteger otherAccountBalanceAfterFirstTx =
new BigInteger("90000000000000000000000")
.subtract(authorizerBalanceAfterFirstTx)
.subtract(txCost);

cluster.verify(otherAccount.balanceEquals(Amount.wei(otherAccountBalanceAfterFirstTx)));

final Transaction txSendEthToOtherAccount =
Transaction.builder()
.type(TransactionType.EIP1559)
.chainId(BigInteger.valueOf(20211))
.nonce(2)
.maxPriorityFeePerGas(Wei.of(10))
.maxFeePerGas(Wei.of(100))
.gasLimit(21000)
.to(Address.fromHexStringStrict(otherAccount.getAddress()))
.value(Wei.ONE)
.payload(Bytes.EMPTY)
.signAndBuild(
secp256k1.createKeyPair(
secp256k1.createPrivateKey(AUTHORIZER_PRIVATE_KEY.toUnsignedBigInteger())));

final String txSendEthToOtherAccountHash =
besuNode.execute(
ethTransactions.sendRawTransaction(txSendEthToOtherAccount.encoded().toHexString()));
testHelper.buildNewBlock();

final Optional<TransactionReceipt> maybeSecondTransactionReceipt =
besuNode.execute(ethTransactions.getTransactionReceipt(txSendEthToOtherAccountHash));
assertThat(maybeSecondTransactionReceipt).isPresent();

// the balance of the other account should be the previous balance plus the value of the 1 Wei
final BigInteger otherAccountBalanceAfterSecondTx =
besuNode.execute(ethTransactions.getBalance(otherAccount));
assertThat(otherAccountBalanceAfterFirstTx.add(BigInteger.ONE))
.isEqualTo(otherAccountBalanceAfterSecondTx);
}
}
2 changes: 1 addition & 1 deletion besu/src/main/java/org/hyperledger/besu/RunnerBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -805,7 +805,7 @@ public Runner build() {
if (miningParameters.isStratumMiningEnabled()) {
if (!(miningCoordinator instanceof PoWMiningCoordinator powMiningCoordinator)) {
throw new IllegalArgumentException(
"Stratum server requires an PoWMiningCoordinator not "
"Stratum mining requires the network option(--network) to be set to CLASSIC. Stratum server requires a PoWMiningCoordinator not "
+ ((miningCoordinator == null) ? "null" : miningCoordinator.getClass().getName()));
}
stratumServer =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,10 @@ public class MiningOptions implements CLIOptions<MiningParameters> {

@Option(
names = {"--miner-stratum-enabled"},
description = "Set if node will perform Stratum mining (default: ${DEFAULT-VALUE})")
description =
"Set if node will perform Stratum mining (default: ${DEFAULT-VALUE})."
+ " Compatible with Proof of Work (PoW) only."
+ " Requires the network option (--network) to be set to CLASSIC.")
private Boolean iStratumMiningEnabled = false;

@Option(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ public class CliqueBlockCreator extends AbstractBlockCreator {
* @param protocolContext the protocol context
* @param protocolSchedule the protocol schedule
* @param nodeKey the node key
* @param parentHeader the parent header
* @param epochManager the epoch manager
* @param ethScheduler the scheduler for asynchronous block creation tasks
*/
Expand All @@ -65,7 +64,6 @@ public CliqueBlockCreator(
final ProtocolContext protocolContext,
final ProtocolSchedule protocolSchedule,
final NodeKey nodeKey,
final BlockHeader parentHeader,
final EpochManager epochManager,
final EthScheduler ethScheduler) {
super(
Expand All @@ -75,7 +73,6 @@ public CliqueBlockCreator(
transactionPool,
protocolContext,
protocolSchedule,
parentHeader,
ethScheduler);
this.nodeKey = nodeKey;
this.epochManager = epochManager;
Expand Down Expand Up @@ -112,6 +109,8 @@ protected BlockHeader createFinalBlockHeader(final SealableBlockHeader sealableB

private Optional<ValidatorVote> determineCliqueVote(
final SealableBlockHeader sealableBlockHeader) {
BlockHeader parentHeader =
protocolContext.getBlockchain().getBlockHeader(sealableBlockHeader.getParentHash()).get();
if (epochManager.isEpochBlock(sealableBlockHeader.getNumber())) {
return Optional.empty();
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@ public CliqueBlockMiner createMiner(
protocolContext,
protocolSchedule,
nodeKey,
header,
epochManager,
ethScheduler);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,11 +156,11 @@ public void proposerAddressCanBeExtractFromAConstructedBlock() {
protocolContext,
protocolSchedule,
proposerNodeKey,
blockchain.getChainHeadHeader(),
epochManager,
ethScheduler);

final Block createdBlock = blockCreator.createBlock(5L).getBlock();
final Block createdBlock =
blockCreator.createBlock(5L, blockchain.getChainHeadHeader()).getBlock();

assertThat(CliqueHelpers.getProposerOfBlock(createdBlock.getHeader()))
.isEqualTo(proposerAddress);
Expand All @@ -185,11 +185,11 @@ public void insertsValidVoteIntoConstructedBlock() {
protocolContext,
protocolSchedule,
proposerNodeKey,
blockchain.getChainHeadHeader(),
epochManager,
ethScheduler);

final Block createdBlock = blockCreator.createBlock(0L).getBlock();
final Block createdBlock =
blockCreator.createBlock(0L, blockchain.getChainHeadHeader()).getBlock();
assertThat(createdBlock.getHeader().getNonce()).isEqualTo(CliqueBlockInterface.ADD_NONCE);
assertThat(createdBlock.getHeader().getCoinbase()).isEqualTo(a1);
}
Expand Down Expand Up @@ -219,11 +219,11 @@ public void insertsNoVoteWhenAtEpoch() {
protocolContext,
protocolSchedule,
proposerNodeKey,
blockchain.getChainHeadHeader(),
epochManager,
ethScheduler);

final Block createdBlock = blockCreator.createBlock(0L).getBlock();
final Block createdBlock =
blockCreator.createBlock(0L, blockchain.getChainHeadHeader()).getBlock();
assertThat(createdBlock.getHeader().getNonce()).isEqualTo(CliqueBlockInterface.DROP_NONCE);
assertThat(createdBlock.getHeader().getCoinbase()).isEqualTo(Address.fromHexString("0"));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ void doesNotMineBlockIfNoTransactionsWhenEmptyBlocksNotAllowed() throws Interrup
final CliqueBlockCreator blockCreator = mock(CliqueBlockCreator.class);
final Function<BlockHeader, CliqueBlockCreator> blockCreatorSupplier =
(parentHeader) -> blockCreator;
when(blockCreator.createBlock(anyLong()))
when(blockCreator.createBlock(anyLong(), any()))
.thenReturn(
new BlockCreator.BlockCreationResult(
blockToCreate, new TransactionSelectionResults(), new BlockCreationTiming()));
Expand Down Expand Up @@ -147,7 +147,7 @@ void minesBlockIfHasTransactionsWhenEmptyBlocksNotAllowed() throws InterruptedEx
final CliqueBlockCreator blockCreator = mock(CliqueBlockCreator.class);
final Function<BlockHeader, CliqueBlockCreator> blockCreatorSupplier =
(parentHeader) -> blockCreator;
when(blockCreator.createBlock(anyLong()))
when(blockCreator.createBlock(anyLong(), any()))
.thenReturn(
new BlockCreator.BlockCreationResult(
blockToCreate, new TransactionSelectionResults(), new BlockCreationTiming()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ public class BftBlockCreator extends AbstractBlockCreator {
* @param transactionPool the pending transactions
* @param protocolContext the protocol context
* @param protocolSchedule the protocol schedule
* @param parentHeader the parent header
* @param bftExtraDataCodec the bft extra data codec
* @param ethScheduler the scheduler for asynchronous block creation tasks
*/
Expand All @@ -65,7 +64,6 @@ public BftBlockCreator(
final TransactionPool transactionPool,
final ProtocolContext protocolContext,
final ProtocolSchedule protocolSchedule,
final BlockHeader parentHeader,
final BftExtraDataCodec bftExtraDataCodec,
final EthScheduler ethScheduler) {
super(
Expand All @@ -75,21 +73,20 @@ public BftBlockCreator(
transactionPool,
protocolContext,
protocolSchedule,
parentHeader,
ethScheduler);
this.bftExtraDataCodec = bftExtraDataCodec;
}

@Override
public BlockCreationResult createBlock(final long timestamp) {
public BlockCreationResult createBlock(final long timestamp, final BlockHeader parentHeader) {
ProtocolSpec protocolSpec =
((BftProtocolSchedule) protocolSchedule)
.getByBlockNumberOrTimestamp(parentHeader.getNumber() + 1, timestamp);

if (protocolSpec.getWithdrawalsValidator() instanceof WithdrawalsValidator.AllowedWithdrawals) {
return createEmptyWithdrawalsBlock(timestamp);
return createEmptyWithdrawalsBlock(timestamp, parentHeader);
} else {
return createBlock(Optional.empty(), Optional.empty(), timestamp);
return createBlock(Optional.empty(), Optional.empty(), timestamp, parentHeader);
}
}

Expand All @@ -100,9 +97,14 @@ private static MiningBeneficiaryCalculator miningBeneficiaryCalculator(
}

@Override
public BlockCreationResult createEmptyWithdrawalsBlock(final long timestamp) {
public BlockCreationResult createEmptyWithdrawalsBlock(
final long timestamp, final BlockHeader parentHeader) {
return createBlock(
Optional.empty(), Optional.empty(), Optional.of(Collections.emptyList()), timestamp);
Optional.empty(),
Optional.empty(),
Optional.of(Collections.emptyList()),
timestamp,
parentHeader);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,10 @@ public BftBlockCreatorFactory(
/**
* Create block creator.
*
* @param parentHeader the parent header
* @param round the round
* @return the block creator
*/
public BlockCreator create(final BlockHeader parentHeader, final int round) {
public BlockCreator create(final int round) {
return new BftBlockCreator(
miningParameters,
forksSchedule,
Expand All @@ -119,7 +118,6 @@ public BlockCreator create(final BlockHeader parentHeader, final int round) {
transactionPool,
protocolContext,
protocolSchedule,
parentHeader,
bftExtraDataCodec,
ethScheduler);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,8 @@ public Block createBlockForProposal(
final BlockHeader parent, final int round, final long timestamp) {
return finalState
.getBlockCreatorFactory()
.create(parent, round)
.createBlock(timestamp)
.create(round)
.createBlock(timestamp, parent)
.getBlock();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ public class IbftRoundIntegrationTest {
private MessageFactory throwingMessageFactory;
private IbftMessageTransmitter transmitter;
@Mock private StubValidatorMulticaster multicaster;
@Mock BlockHeader parentHeader;

private Block proposedBlock;

Expand Down Expand Up @@ -145,7 +146,8 @@ public void signingFailsOnReceiptOfProposalUpdatesRoundButTransmitsNothing() {
throwingMessageFactory,
transmitter,
roundTimer,
bftExtraDataEncoder);
bftExtraDataEncoder,
parentHeader);

round.handleProposalMessage(
peerMessageFactory.createProposal(roundIdentifier, proposedBlock, Optional.empty()));
Expand All @@ -172,7 +174,8 @@ public void failuresToSignStillAllowBlockToBeImported() {
throwingMessageFactory,
transmitter,
roundTimer,
bftExtraDataEncoder);
bftExtraDataEncoder,
parentHeader);

// inject a block first, then a prepare on it.
round.handleProposalMessage(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ public class IbftRound {
private final MessageFactory messageFactory; // used only to create stored local msgs
private final IbftMessageTransmitter transmitter;
private final BftExtraDataCodec bftExtraDataCodec;
private final BlockHeader parentHeader;

/**
* Instantiates a new Ibft round.
Expand All @@ -80,6 +81,7 @@ public class IbftRound {
* @param transmitter the transmitter
* @param roundTimer the round timer
* @param bftExtraDataCodec the bft extra data codec
* @param parentHeader the parent header
*/
public IbftRound(
final RoundState roundState,
Expand All @@ -91,7 +93,8 @@ public IbftRound(
final MessageFactory messageFactory,
final IbftMessageTransmitter transmitter,
final RoundTimer roundTimer,
final BftExtraDataCodec bftExtraDataCodec) {
final BftExtraDataCodec bftExtraDataCodec,
final BlockHeader parentHeader) {
this.roundState = roundState;
this.blockCreator = blockCreator;
this.protocolContext = protocolContext;
Expand All @@ -101,6 +104,7 @@ public IbftRound(
this.messageFactory = messageFactory;
this.transmitter = transmitter;
this.bftExtraDataCodec = bftExtraDataCodec;
this.parentHeader = parentHeader;
roundTimer.startTimer(getRoundIdentifier());
}

Expand All @@ -119,7 +123,8 @@ public ConsensusRoundIdentifier getRoundIdentifier() {
* @param headerTimeStampSeconds the header time stamp seconds
*/
public void createAndSendProposalMessage(final long headerTimeStampSeconds) {
final Block block = blockCreator.createBlock(headerTimeStampSeconds).getBlock();
final Block block =
blockCreator.createBlock(headerTimeStampSeconds, this.parentHeader).getBlock();
final BftExtraData extraData = bftExtraDataCodec.decode(block.getHeader());
LOG.debug("Creating proposed block. round={}", roundState.getRoundIdentifier());
LOG.trace(
Expand All @@ -142,7 +147,7 @@ public void startRoundWith(
final Block blockToPublish;
if (!bestBlockFromRoundChange.isPresent()) {
LOG.debug("Sending proposal with new block. round={}", roundState.getRoundIdentifier());
blockToPublish = blockCreator.createBlock(headerTimestamp).getBlock();
blockToPublish = blockCreator.createBlock(headerTimestamp, this.parentHeader).getBlock();
} else {
LOG.debug(
"Sending proposal from PreparedCertificate. round={}", roundState.getRoundIdentifier());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public IbftRound createNewRound(final BlockHeader parentHeader, final int round)
public IbftRound createNewRoundWithState(
final BlockHeader parentHeader, final RoundState roundState) {
final BlockCreator blockCreator =
blockCreatorFactory.create(parentHeader, roundState.getRoundIdentifier().getRoundNumber());
blockCreatorFactory.create(roundState.getRoundIdentifier().getRoundNumber());

final IbftMessageTransmitter messageTransmitter =
new IbftMessageTransmitter(messageFactory, finalState.getValidatorMulticaster());
Expand All @@ -115,6 +115,7 @@ public IbftRound createNewRoundWithState(
messageFactory,
messageTransmitter,
finalState.getRoundTimer(),
bftExtraDataCodec);
bftExtraDataCodec,
parentHeader);
}
}
Loading

0 comments on commit 6f74319

Please sign in to comment.