Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove QBFT hashmode in qbft core #8351

Merged
merged 3 commits into from
Feb 27, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import org.hyperledger.besu.consensus.qbft.core.types.QbftBlock;
import org.hyperledger.besu.consensus.qbft.core.types.QbftBlockCodec;
import org.hyperledger.besu.consensus.qbft.core.types.QbftBlockInterface;
import org.hyperledger.besu.consensus.qbft.core.types.QbftHashMode;
import org.hyperledger.besu.crypto.SECPSignature;
import org.hyperledger.besu.cryptoservices.NodeKey;

Expand Down Expand Up @@ -63,7 +62,6 @@ public static QbftBlock createCommitBlockFromProposalBlock(
final QbftExtraDataCodec bftExtraDataCodec = new QbftExtraDataCodec();
final BftBlockInterface bftBlockInterface = new BftBlockInterface(bftExtraDataCodec);
final QbftBlockInterface qbftBlockInterface = new QbftBlockInterfaceAdaptor(bftBlockInterface);
return qbftBlockInterface.replaceRoundInBlock(
proposalBlock, round, QbftHashMode.COMMITTED_SEAL);
return qbftBlockInterface.replaceRoundInBlock(proposalBlock, round);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import org.hyperledger.besu.consensus.qbft.core.payload.RoundChangePayload;
import org.hyperledger.besu.consensus.qbft.core.types.QbftBlock;
import org.hyperledger.besu.consensus.qbft.core.types.QbftBlockCodec;
import org.hyperledger.besu.consensus.qbft.core.types.QbftHashMode;
import org.hyperledger.besu.ethereum.rlp.BytesValueRLPOutput;
import org.hyperledger.besu.ethereum.rlp.RLP;
import org.hyperledger.besu.ethereum.rlp.RLPInput;
Expand Down Expand Up @@ -122,7 +121,7 @@ public static RoundChange decode(final Bytes data, final QbftBlockCodec blockEnc
rlpIn.skipNext();
block = Optional.empty();
} else {
block = Optional.of(blockEncoder.readFrom(rlpIn, QbftHashMode.COMMITTED_SEAL));
block = Optional.of(blockEncoder.readFrom(rlpIn));
}

final List<SignedData<PreparePayload>> prepares =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import org.hyperledger.besu.consensus.qbft.core.messagedata.QbftV1;
import org.hyperledger.besu.consensus.qbft.core.types.QbftBlock;
import org.hyperledger.besu.consensus.qbft.core.types.QbftBlockCodec;
import org.hyperledger.besu.consensus.qbft.core.types.QbftHashMode;
import org.hyperledger.besu.ethereum.rlp.RLPInput;
import org.hyperledger.besu.ethereum.rlp.RLPOutput;

Expand Down Expand Up @@ -61,7 +60,7 @@ public static ProposalPayload readFrom(
final RLPInput rlpInput, final QbftBlockCodec blockEncoder) {
rlpInput.enterList();
final ConsensusRoundIdentifier roundIdentifier = readConsensusRound(rlpInput);
final QbftBlock proposedBlock = blockEncoder.readFrom(rlpInput, QbftHashMode.COMMITTED_SEAL);
final QbftBlock proposedBlock = blockEncoder.readFrom(rlpInput);
rlpInput.leaveList();

return new ProposalPayload(roundIdentifier, proposedBlock, blockEncoder);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
import org.hyperledger.besu.consensus.qbft.core.types.QbftBlockInterface;
import org.hyperledger.besu.consensus.qbft.core.types.QbftContext;
import org.hyperledger.besu.consensus.qbft.core.types.QbftExtraDataProvider;
import org.hyperledger.besu.consensus.qbft.core.types.QbftHashMode;
import org.hyperledger.besu.consensus.qbft.core.types.QbftMinedBlockObserver;
import org.hyperledger.besu.consensus.qbft.core.types.QbftProtocolSchedule;
import org.hyperledger.besu.crypto.SECPSignature;
Expand Down Expand Up @@ -168,9 +167,7 @@ public void startRoundWith(
protocolContext.getConsensusContext(QbftContext.class).blockInterface();
blockToPublish =
bftBlockInterface.replaceRoundInBlock(
preparedBlock,
roundState.getRoundIdentifier().getRoundNumber(),
QbftHashMode.COMMITTED_SEAL);
preparedBlock, roundState.getRoundIdentifier().getRoundNumber());
}

LOG.debug(" proposal - new/prepared block hash : {}", blockToPublish.getHash());
Expand Down Expand Up @@ -397,8 +394,7 @@ private SECPSignature createCommitSeal(final QbftBlock block) {
private QbftBlock createCommitBlock(final QbftBlock block) {
final QbftBlockInterface bftBlockInterface =
protocolContext.getConsensusContext(QbftContext.class).blockInterface();
return bftBlockInterface.replaceRoundInBlock(
block, getRoundIdentifier().getRoundNumber(), QbftHashMode.COMMITTED_SEAL);
return bftBlockInterface.replaceRoundInBlock(block, getRoundIdentifier().getRoundNumber());
}

private void notifyNewBlockListeners(final QbftBlock block) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,12 @@
/** Block encoding and decoding to and from RLP */
public interface QbftBlockCodec {
/**
* Read a block from RLP
* Read a block from RLP using the committed seal hash
*
* @param rlpInput RLP input
* @param hashMode Hash mode to ensure the block hash is calculated correctly
* @return The block
*/
QbftBlock readFrom(RLPInput rlpInput, QbftHashMode hashMode);
QbftBlock readFrom(RLPInput rlpInput);

/**
* Write a block to RLP
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@
public interface QbftBlockInterface {

/**
* Create a new block using the supplied block with round number replaced.
* Create a new block using the supplied block with round number replaced. The hash must be for
* the committed seal.
*
* @param proposalBlock the proposal block
* @param roundNumber the round number
* @param hashMode the hash mode
* @return the new qbft block with updated round number
*/
QbftBlock replaceRoundInBlock(QbftBlock proposalBlock, int roundNumber, QbftHashMode hashMode);
QbftBlock replaceRoundInBlock(QbftBlock proposalBlock, int roundNumber);
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import org.hyperledger.besu.consensus.qbft.core.messagewrappers.Proposal;
import org.hyperledger.besu.consensus.qbft.core.types.QbftBlock;
import org.hyperledger.besu.consensus.qbft.core.types.QbftBlockInterface;
import org.hyperledger.besu.consensus.qbft.core.types.QbftHashMode;
import org.hyperledger.besu.datatypes.Address;

import java.util.Collection;
Expand Down Expand Up @@ -54,8 +53,7 @@ public SubsequentMessageValidator(
final QbftBlock proposalBlock,
final QbftBlockInterface blockInterface) {
final QbftBlock commitBlock =
blockInterface.replaceRoundInBlock(
proposalBlock, targetRound.getRoundNumber(), QbftHashMode.COMMITTED_SEAL);
blockInterface.replaceRoundInBlock(proposalBlock, targetRound.getRoundNumber());
prepareValidator = new PrepareValidator(validators, targetRound, proposalBlock.getHash());
commitValidator =
new CommitValidator(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
import org.hyperledger.besu.consensus.qbft.core.types.QbftBlockInterface;
import org.hyperledger.besu.consensus.qbft.core.types.QbftBlockValidator;
import org.hyperledger.besu.consensus.qbft.core.types.QbftContext;
import org.hyperledger.besu.consensus.qbft.core.types.QbftHashMode;
import org.hyperledger.besu.consensus.qbft.core.types.QbftProtocolSchedule;
import org.hyperledger.besu.datatypes.Address;
import org.hyperledger.besu.datatypes.Hash;
Expand Down Expand Up @@ -146,8 +145,7 @@ private boolean validateProposalAndRoundChangeAreConsistent(final Proposal propo
final QbftBlockInterface bftBlockInterface =
protocolContext.getConsensusContext(QbftContext.class).blockInterface();
final QbftBlock currentBlockWithOldRound =
bftBlockInterface.replaceRoundInBlock(
proposal.getBlock(), metadata.getPreparedRound(), QbftHashMode.COMMITTED_SEAL);
bftBlockInterface.replaceRoundInBlock(proposal.getBlock(), metadata.getPreparedRound());

final Hash expectedPriorBlockHash = currentBlockWithOldRound.getHash();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.when;

import org.hyperledger.besu.consensus.common.bft.ConsensusRoundIdentifier;
Expand All @@ -29,7 +28,6 @@
import org.hyperledger.besu.consensus.qbft.core.payload.RoundChangePayload;
import org.hyperledger.besu.consensus.qbft.core.types.QbftBlock;
import org.hyperledger.besu.consensus.qbft.core.types.QbftBlockCodec;
import org.hyperledger.besu.consensus.qbft.core.types.QbftHashMode;
import org.hyperledger.besu.cryptoservices.NodeKey;
import org.hyperledger.besu.cryptoservices.NodeKeyUtils;
import org.hyperledger.besu.datatypes.Address;
Expand All @@ -51,7 +49,7 @@ public class ProposalTest {

@Test
public void canRoundTripProposalMessage() {
when(blockEncoder.readFrom(any(), eq(QbftHashMode.COMMITTED_SEAL))).thenReturn(BLOCK);
when(blockEncoder.readFrom(any())).thenReturn(BLOCK);

final NodeKey nodeKey = NodeKeyUtils.generate();
final Address addr = Util.publicKeyToAddress(nodeKey.getPublicKey());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.when;

import org.hyperledger.besu.consensus.common.bft.ConsensusRoundIdentifier;
Expand All @@ -28,7 +27,6 @@
import org.hyperledger.besu.consensus.qbft.core.payload.RoundChangePayload;
import org.hyperledger.besu.consensus.qbft.core.types.QbftBlock;
import org.hyperledger.besu.consensus.qbft.core.types.QbftBlockCodec;
import org.hyperledger.besu.consensus.qbft.core.types.QbftHashMode;
import org.hyperledger.besu.cryptoservices.NodeKey;
import org.hyperledger.besu.cryptoservices.NodeKeyUtils;
import org.hyperledger.besu.datatypes.Address;
Expand All @@ -51,7 +49,7 @@ public class RoundChangeTest {

@Test
public void canRoundTripARoundChangeMessage() {
when(blockEncoder.readFrom(any(), eq(QbftHashMode.COMMITTED_SEAL))).thenReturn(BLOCK);
when(blockEncoder.readFrom(any())).thenReturn(BLOCK);

final NodeKey nodeKey = NodeKeyUtils.generate();
final Address addr = Util.publicKeyToAddress(nodeKey.getPublicKey());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -244,8 +244,7 @@ public void doesNotStartRoundTimerOnStart() {
public void onBlockTimerExpiryRoundTimerIsStartedAndProposalMessageIsTransmitted() {
when(finalState.isLocalNodeProposerForRound(roundIdentifier)).thenReturn(true);
when(blockTimer.checkEmptyBlockExpired(any(), eq(0L))).thenReturn(true);
when(blockInterface.replaceRoundInBlock(eq(createdBlock), eq(0), any()))
.thenReturn(createdBlock);
when(blockInterface.replaceRoundInBlock(eq(createdBlock), eq(0))).thenReturn(createdBlock);

final QbftBlockHeightManager manager =
new QbftBlockHeightManager(
Expand Down Expand Up @@ -300,8 +299,7 @@ public void onBlockTimerExpiryDoNothingIfExistingRoundAlreadyStarted() {
messageValidatorFactory,
messageFactory);

when(blockInterface.replaceRoundInBlock(eq(createdBlock), eq(2), any()))
.thenReturn(createdBlock);
when(blockInterface.replaceRoundInBlock(eq(createdBlock), eq(2))).thenReturn(createdBlock);

// Force a new round to be started at new round number.
final ConsensusRoundIdentifier futureRoundIdentifier = createFrom(roundIdentifier, 0, +2);
Expand Down Expand Up @@ -377,8 +375,7 @@ public void whenSufficientRoundChangesAreReceivedAProposalMessageIsTransmitted()
when(roundChangeManager.appendRoundChangeMessage(any()))
.thenReturn(Optional.of(singletonList(roundChange)));
when(finalState.isLocalNodeProposerForRound(any())).thenReturn(true);
when(blockInterface.replaceRoundInBlock(eq(createdBlock), eq(2), any()))
.thenReturn(createdBlock);
when(blockInterface.replaceRoundInBlock(eq(createdBlock), eq(2))).thenReturn(createdBlock);

final QbftBlockHeightManager manager =
new QbftBlockHeightManager(
Expand All @@ -404,8 +401,7 @@ public void whenSufficientRoundChangesAreReceivedAProposalMessageIsTransmitted()
@Test
public void messagesForFutureRoundsAreBufferedAndUsedToPreloadNewRoundWhenItIsStarted() {
when(finalState.getQuorum()).thenReturn(1);
when(blockInterface.replaceRoundInBlock(eq(createdBlock), eq(2), any()))
.thenReturn(createdBlock);
when(blockInterface.replaceRoundInBlock(eq(createdBlock), eq(2))).thenReturn(createdBlock);
when(blockCreator.createSealedBlock(any(), any(), anyInt(), any())).thenReturn(createdBlock);
when(protocolSchedule.getByBlockHeader(any())).thenReturn(protocolSpec);
when(protocolSpec.getBlockImporter()).thenReturn(blockImporter);
Expand Down Expand Up @@ -454,8 +450,7 @@ public void messagesForCurrentRoundAreBufferedAndUsedToPreloadRoundWhenItIsStart
when(finalState.getQuorum()).thenReturn(1);
when(finalState.isLocalNodeProposerForRound(roundIdentifier)).thenReturn(true);
when(blockTimer.checkEmptyBlockExpired(any(), eq(0L))).thenReturn(true);
when(blockInterface.replaceRoundInBlock(eq(createdBlock), eq(0), any()))
.thenReturn(createdBlock);
when(blockInterface.replaceRoundInBlock(eq(createdBlock), eq(0))).thenReturn(createdBlock);
when(blockCreator.createSealedBlock(any(), any(), anyInt(), any())).thenReturn(createdBlock);
when(protocolSchedule.getByBlockHeader(any())).thenReturn(protocolSpec);
when(protocolSpec.getBlockImporter()).thenReturn(blockImporter);
Expand Down Expand Up @@ -497,9 +492,8 @@ public void messagesForCurrentRoundAreBufferedAndUsedToPreloadRoundWhenItIsStart
public void preparedCertificateIncludedInRoundChangeMessageOnRoundTimeoutExpired() {
when(finalState.isLocalNodeProposerForRound(any())).thenReturn(true);
when(blockTimer.checkEmptyBlockExpired(any(), eq(0L))).thenReturn(true);
when(blockInterface.replaceRoundInBlock(eq(createdBlock), eq(0), any()))
.thenReturn(createdBlock);
when(blockEncoder.readFrom(any(), any())).thenReturn(createdBlock);
when(blockInterface.replaceRoundInBlock(eq(createdBlock), eq(0))).thenReturn(createdBlock);
when(blockEncoder.readFrom(any())).thenReturn(createdBlock);

final QbftBlockHeightManager manager =
new QbftBlockHeightManager(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@
import org.hyperledger.besu.consensus.qbft.core.types.QbftBlockInterface;
import org.hyperledger.besu.consensus.qbft.core.types.QbftContext;
import org.hyperledger.besu.consensus.qbft.core.types.QbftExtraDataProvider;
import org.hyperledger.besu.consensus.qbft.core.types.QbftHashMode;
import org.hyperledger.besu.consensus.qbft.core.types.QbftMinedBlockObserver;
import org.hyperledger.besu.consensus.qbft.core.types.QbftProtocolSchedule;
import org.hyperledger.besu.consensus.qbft.core.types.QbftProtocolSpec;
Expand Down Expand Up @@ -190,8 +189,7 @@ public void onReceptionOfValidProposalSendsAPrepareToNetworkPeers() {
qbftExtraDataProvider,
parentHeader);

when(blockInteface.replaceRoundInBlock(eq(proposedBlock), eq(0), any()))
.thenReturn(proposedBlock);
when(blockInteface.replaceRoundInBlock(eq(proposedBlock), eq(0))).thenReturn(proposedBlock);

round.handleProposalMessage(
messageFactory.createProposal(
Expand All @@ -205,8 +203,7 @@ public void aProposalWithAnewBlockIsSentUponReceptionOfARoundChangeWithNoCertifi
final QbftBlockHeader header = new QbftBlockHeaderTestFixture().number(0).buildHeader();

final QbftBlock commitBlock = new QbftBlockTestFixture().blockHeader(header).build();
when(blockInteface.replaceRoundInBlock(proposedBlock, 0, QbftHashMode.COMMITTED_SEAL))
.thenReturn(commitBlock);
when(blockInteface.replaceRoundInBlock(proposedBlock, 0)).thenReturn(commitBlock);

final RoundState roundState = new RoundState(roundIdentifier, 2, messageValidator);
final QbftRound round =
Expand Down Expand Up @@ -240,10 +237,8 @@ public void aProposalMessageWithTheSameBlockIsSentUponReceptionOfARoundChangeWit
new QbftBlockTestFixture()
.blockHeader(new QbftBlockHeaderTestFixture().number(0).buildHeader())
.build();
when(blockInteface.replaceRoundInBlock(proposedBlock, 0, QbftHashMode.COMMITTED_SEAL))
.thenReturn(publishBlock);
when(blockInteface.replaceRoundInBlock(publishBlock, 0, QbftHashMode.COMMITTED_SEAL))
.thenReturn(commitBlock);
when(blockInteface.replaceRoundInBlock(proposedBlock, 0)).thenReturn(publishBlock);
when(blockInteface.replaceRoundInBlock(publishBlock, 0)).thenReturn(commitBlock);

final ConsensusRoundIdentifier priorRoundChange = new ConsensusRoundIdentifier(1, 0);
final RoundState roundState = new RoundState(roundIdentifier, 2, messageValidator);
Expand Down Expand Up @@ -296,8 +291,7 @@ public void creatingNewBlockFromEmptyPreparedCertificateUpdatesInternalState() {
new QbftBlockTestFixture()
.blockHeader(new QbftBlockHeaderTestFixture().number(0).buildHeader())
.build();
when(blockInteface.replaceRoundInBlock(proposedBlock, 0, QbftHashMode.COMMITTED_SEAL))
.thenReturn(commitBlock);
when(blockInteface.replaceRoundInBlock(proposedBlock, 0)).thenReturn(commitBlock);

final RoundState roundState = new RoundState(roundIdentifier, 2, messageValidator);
final QbftRound round =
Expand Down Expand Up @@ -358,8 +352,7 @@ public void blockIsOnlyImportedOnceWhenCommitsAreReceivedBeforeProposal() {
qbftExtraDataProvider,
parentHeader);

when(blockInteface.replaceRoundInBlock(proposedBlock, 0, QbftHashMode.COMMITTED_SEAL))
.thenReturn(proposedBlock);
when(blockInteface.replaceRoundInBlock(proposedBlock, 0)).thenReturn(proposedBlock);
when(blockCreator.createSealedBlock(eq(qbftExtraDataProvider), eq(proposedBlock), eq(0), any()))
.thenReturn(proposedBlock);

Expand Down Expand Up @@ -392,8 +385,7 @@ public void blockIsImportedOnlyOnceIfQuorumCommitsAreReceivedPriorToProposal() {
qbftExtraDataProvider,
parentHeader);

when(blockInteface.replaceRoundInBlock(eq(proposedBlock), eq(0), any()))
.thenReturn(proposedBlock);
when(blockInteface.replaceRoundInBlock(eq(proposedBlock), eq(0))).thenReturn(proposedBlock);
when(blockCreator.createSealedBlock(eq(qbftExtraDataProvider), eq(proposedBlock), eq(0), any()))
.thenReturn(proposedBlock);

Expand Down Expand Up @@ -430,8 +422,7 @@ public void exceptionDuringNodeKeySigningDoesNotEscape() {
qbftExtraDataProvider,
parentHeader);

when(blockInteface.replaceRoundInBlock(eq(proposedBlock), eq(0), any()))
.thenReturn(proposedBlock);
when(blockInteface.replaceRoundInBlock(eq(proposedBlock), eq(0))).thenReturn(proposedBlock);

round.handleProposalMessage(
messageFactory.createProposal(
Expand Down
Loading