Make BftBlockInterface#replaceRoundInBlock non-static (#2067)

* Make BftBlockInterface#replaceRoundInBlock non-static

Signed-off-by: Lucas Saldanha <lucascrsaldanha@gmail.com>
pull/2074/head
Lucas Saldanha 4 years ago committed by GitHub
parent 17cf72b916
commit 3ce42a3731
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      consensus/common/src/main/java/org/hyperledger/besu/consensus/common/bft/BftBlockInterface.java
  2. 6
      consensus/ibft/src/main/java/org/hyperledger/besu/consensus/ibft/statemachine/IbftRound.java
  3. 6
      consensus/ibft/src/main/java/org/hyperledger/besu/consensus/ibft/validation/MessageValidatorFactory.java
  4. 7
      consensus/ibft/src/main/java/org/hyperledger/besu/consensus/ibft/validation/RoundChangeCertificateValidator.java
  5. 2
      consensus/ibft/src/test/java/org/hyperledger/besu/consensus/ibft/validation/ProposalBlockConsistencyValidatorTest.java
  6. 5
      consensus/ibft/src/test/java/org/hyperledger/besu/consensus/ibft/validation/RoundChangeCertificateValidatorTest.java
  7. 5
      consensus/qbft/src/main/java/org/hyperledger/besu/consensus/qbft/statemachine/QbftRound.java
  8. 5
      consensus/qbft/src/main/java/org/hyperledger/besu/consensus/qbft/validation/ProposalValidator.java

@ -70,7 +70,7 @@ public class BftBlockInterface implements BlockInterface {
return bftExtraData.getValidators();
}
public static Block replaceRoundInBlock(
public Block replaceRoundInBlock(
final Block block,
final int round,
final BlockHeaderFunctions blockHeaderFunctions,

@ -17,6 +17,7 @@ package org.hyperledger.besu.consensus.ibft.statemachine;
import org.hyperledger.besu.consensus.common.bft.BftBlockHashing;
import org.hyperledger.besu.consensus.common.bft.BftBlockHeaderFunctions;
import org.hyperledger.besu.consensus.common.bft.BftBlockInterface;
import org.hyperledger.besu.consensus.common.bft.BftContext;
import org.hyperledger.besu.consensus.common.bft.BftExtraData;
import org.hyperledger.besu.consensus.common.bft.BftExtraDataCodec;
import org.hyperledger.besu.consensus.common.bft.BftHelpers;
@ -110,8 +111,11 @@ public class IbftRound {
} else {
LOG.debug(
"Sending proposal from PreparedCertificate. round={}", roundState.getRoundIdentifier());
final BftBlockInterface bftBlockInterface =
protocolContext.getConsensusState(BftContext.class).getBlockInterface();
blockToPublish =
BftBlockInterface.replaceRoundInBlock(
bftBlockInterface.replaceRoundInBlock(
bestBlockFromRoundChange.get(),
getRoundIdentifier().getRoundNumber(),
BftBlockHeaderFunctions.forCommittedSeal(bftExtraDataCodec),

@ -69,6 +69,9 @@ public class MessageValidatorFactory {
protocolSchedule.getByBlockNumber(roundIdentifier.getSequenceNumber()).getBlockValidator();
final Collection<Address> validators = getValidatorsAfterBlock(parentHeader);
final BftBlockInterface bftBlockInterface =
protocolContext.getConsensusState(BftContext.class).getBlockInterface();
return new MessageValidator(
createSignedDataValidator(roundIdentifier, parentHeader),
new ProposalBlockConsistencyValidator(),
@ -78,7 +81,8 @@ public class MessageValidatorFactory {
validators,
(ri) -> createSignedDataValidator(ri, parentHeader),
roundIdentifier.getSequenceNumber(),
bftExtraDataCodec));
bftExtraDataCodec,
bftBlockInterface));
}
public RoundChangeMessageValidator createRoundChangeMessageValidator(

@ -40,6 +40,7 @@ public class RoundChangeCertificateValidator {
private final Collection<Address> validators;
private final MessageValidatorForHeightFactory messageValidatorFactory;
private final BftExtraDataCodec bftExtraDataCodec;
private final BftBlockInterface bftBlockInterface;
private final long quorum;
private final long chainHeight;
@ -47,12 +48,14 @@ public class RoundChangeCertificateValidator {
final Collection<Address> validators,
final MessageValidatorForHeightFactory messageValidatorFactory,
final long chainHeight,
final BftExtraDataCodec bftExtraDataCodec) {
final BftExtraDataCodec bftExtraDataCodec,
final BftBlockInterface bftBlockInterface) {
this.validators = validators;
this.messageValidatorFactory = messageValidatorFactory;
this.quorum = BftHelpers.calculateRequiredValidatorQuorum(validators.size());
this.chainHeight = chainHeight;
this.bftExtraDataCodec = bftExtraDataCodec;
this.bftBlockInterface = bftBlockInterface;
}
public boolean validateRoundChangeMessagesAndEnsureTargetRoundMatchesRoot(
@ -124,7 +127,7 @@ public class RoundChangeCertificateValidator {
// Need to check that if we substitute the LatestPrepareCert round number into the supplied
// block that we get the SAME hash as PreparedCert.
final Block currentBlockWithOldRound =
BftBlockInterface.replaceRoundInBlock(
bftBlockInterface.replaceRoundInBlock(
proposedBlock,
latestPreparedCertificate
.get()

@ -64,7 +64,7 @@ public class ProposalBlockConsistencyValidatorTest {
final IbftExtraDataCodec bftExtraDataEncoder = new IbftExtraDataCodec();
final Block misMatchedBlock =
BftBlockInterface.replaceRoundInBlock(
bftBlockInterface.replaceRoundInBlock(
block,
roundIdentifier.getRoundNumber() + 1,
BftBlockHeaderFunctions.forCommittedSeal(bftExtraDataEncoder),

@ -21,6 +21,7 @@ import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import org.hyperledger.besu.consensus.common.bft.BftBlockInterface;
import org.hyperledger.besu.consensus.common.bft.ConsensusRoundHelpers;
import org.hyperledger.besu.consensus.common.bft.ConsensusRoundIdentifier;
import org.hyperledger.besu.consensus.common.bft.ProposedBlockHelpers;
@ -63,6 +64,7 @@ public class RoundChangeCertificateValidatorTest {
mock(MessageValidatorForHeightFactory.class);
private final SignedDataValidator signedDataValidator = mock(SignedDataValidator.class);
final IbftExtraDataCodec bftExtraDataEncoder = new IbftExtraDataCodec();
final BftBlockInterface bftBlockInterface = new BftBlockInterface(bftExtraDataEncoder);
private Block proposedBlock;
@ -76,7 +78,8 @@ public class RoundChangeCertificateValidatorTest {
ProposedBlockHelpers.createProposalBlock(validators, roundIdentifier, bftExtraDataEncoder);
validator =
new RoundChangeCertificateValidator(validators, validatorFactory, 5, bftExtraDataEncoder);
new RoundChangeCertificateValidator(
validators, validatorFactory, 5, bftExtraDataEncoder, bftBlockInterface);
}
@Test

@ -19,6 +19,7 @@ import static java.util.Collections.emptyList;
import org.hyperledger.besu.consensus.common.bft.BftBlockHashing;
import org.hyperledger.besu.consensus.common.bft.BftBlockHeaderFunctions;
import org.hyperledger.besu.consensus.common.bft.BftBlockInterface;
import org.hyperledger.besu.consensus.common.bft.BftContext;
import org.hyperledger.besu.consensus.common.bft.BftExtraData;
import org.hyperledger.besu.consensus.common.bft.BftExtraDataCodec;
import org.hyperledger.besu.consensus.common.bft.BftHelpers;
@ -113,8 +114,10 @@ public class QbftRound {
} else {
LOG.debug(
"Sending proposal from PreparedCertificate. round={}", roundState.getRoundIdentifier());
final BftBlockInterface bftBlockInterface =
protocolContext.getConsensusState(BftContext.class).getBlockInterface();
blockToPublish =
BftBlockInterface.replaceRoundInBlock(
bftBlockInterface.replaceRoundInBlock(
bestPreparedCertificate.get().getBlock(),
getRoundIdentifier().getRoundNumber(),
BftBlockHeaderFunctions.forCommittedSeal(bftExtraDataCodec),

@ -19,6 +19,7 @@ import static org.hyperledger.besu.consensus.common.bft.validation.ValidationHel
import org.hyperledger.besu.consensus.common.bft.BftBlockHeaderFunctions;
import org.hyperledger.besu.consensus.common.bft.BftBlockInterface;
import org.hyperledger.besu.consensus.common.bft.BftContext;
import org.hyperledger.besu.consensus.common.bft.BftExtraDataCodec;
import org.hyperledger.besu.consensus.common.bft.ConsensusRoundIdentifier;
import org.hyperledger.besu.consensus.common.bft.payload.Payload;
@ -121,8 +122,10 @@ public class ProposalValidator {
// to create a block with the old round in it, then re-calc expected hash
// Need to check that if we substitute the LatestPrepareCert round number into the supplied
// block that we get the SAME hash as PreparedCert.
final BftBlockInterface bftBlockInterface =
protocolContext.getConsensusState(BftContext.class).getBlockInterface();
final Block currentBlockWithOldRound =
BftBlockInterface.replaceRoundInBlock(
bftBlockInterface.replaceRoundInBlock(
proposal.getBlock(),
metadata.getPreparedRound(),
BftBlockHeaderFunctions.forCommittedSeal(bftExtraDataCodec),

Loading…
Cancel
Save