Search in sources :

Example 1 with BlockValidator

use of org.hyperledger.besu.ethereum.BlockValidator in project besu by hyperledger.

the class MessageValidatorFactory method createMessageValidator.

public MessageValidator createMessageValidator(final ConsensusRoundIdentifier roundIdentifier, final BlockHeader parentHeader) {
    final Collection<Address> validatorsForHeight = getValidatorsAfterBlock(parentHeader);
    final BlockValidator blockValidator = protocolSchedule.getByBlockNumber(roundIdentifier.getSequenceNumber()).getBlockValidator();
    final ProposalValidator proposalValidator = new ProposalValidator(blockValidator, protocolContext, BftHelpers.calculateRequiredValidatorQuorum(validatorsForHeight.size()), validatorsForHeight, roundIdentifier, proposerSelector.selectProposerForRound(roundIdentifier), bftExtraDataCodec);
    final BftBlockInterface blockInterface = protocolContext.getConsensusContext(BftContext.class).getBlockInterface();
    return new MessageValidator(block -> new SubsequentMessageValidator(validatorsForHeight, roundIdentifier, block, blockInterface, bftExtraDataCodec), proposalValidator);
}
Also used : BftBlockInterface(org.hyperledger.besu.consensus.common.bft.BftBlockInterface) Address(org.hyperledger.besu.datatypes.Address) BftContext(org.hyperledger.besu.consensus.common.bft.BftContext) SubsequentMessageValidator(org.hyperledger.besu.consensus.qbft.validation.MessageValidator.SubsequentMessageValidator) BlockValidator(org.hyperledger.besu.ethereum.BlockValidator) SubsequentMessageValidator(org.hyperledger.besu.consensus.qbft.validation.MessageValidator.SubsequentMessageValidator)

Example 2 with BlockValidator

use of org.hyperledger.besu.ethereum.BlockValidator in project besu by hyperledger.

the class MessageValidatorFactory method createRoundChangeMessageValidator.

public RoundChangeMessageValidator createRoundChangeMessageValidator(final long chainHeight, final BlockHeader parentHeader) {
    final Collection<Address> validatorsForHeight = getValidatorsAfterBlock(parentHeader);
    final RoundChangePayloadValidator roundChangePayloadValidator = new RoundChangePayloadValidator(validatorsForHeight, chainHeight);
    final BlockValidator blockValidator = protocolSchedule.getByBlockNumber(chainHeight).getBlockValidator();
    return new RoundChangeMessageValidator(roundChangePayloadValidator, BftHelpers.calculateRequiredValidatorQuorum(validatorsForHeight.size()), chainHeight, validatorsForHeight, blockValidator, protocolContext);
}
Also used : Address(org.hyperledger.besu.datatypes.Address) BlockValidator(org.hyperledger.besu.ethereum.BlockValidator)

Example 3 with BlockValidator

use of org.hyperledger.besu.ethereum.BlockValidator in project besu by hyperledger.

the class RoundChangeManagerTest method setup.

@Before
public void setup() {
    validators.add(Util.publicKeyToAddress(proposerKey.getPublicKey()));
    validators.add(Util.publicKeyToAddress(validator1Key.getPublicKey()));
    validators.add(Util.publicKeyToAddress(validator2Key.getPublicKey()));
    final BlockValidator blockValidator = mock(BlockValidator.class);
    when(blockValidator.validateAndProcessBlock(any(), any(), any(), any())).thenReturn(new Result(new BlockProcessingOutputs(null, null)));
    final RoundChangePayloadValidator.MessageValidatorForHeightFactory messageValidatorFactory = mock(RoundChangePayloadValidator.MessageValidatorForHeightFactory.class);
    when(messageValidatorFactory.createAt(ri1)).thenAnswer(invocation -> new SignedDataValidator(validators, Util.publicKeyToAddress(proposerKey.getPublicKey()), ri1));
    when(messageValidatorFactory.createAt(ri2)).thenAnswer(invocation -> new SignedDataValidator(validators, Util.publicKeyToAddress(validator1Key.getPublicKey()), ri2));
    when(messageValidatorFactory.createAt(ri3)).thenAnswer(invocation -> new SignedDataValidator(validators, Util.publicKeyToAddress(validator2Key.getPublicKey()), ri3));
    final RoundChangeMessageValidator roundChangeMessageValidator = new RoundChangeMessageValidator(new RoundChangePayloadValidator(messageValidatorFactory, validators, BftHelpers.calculateRequiredValidatorQuorum(BftHelpers.calculateRequiredValidatorQuorum(validators.size())), 2), proposalConsistencyValidator, bftBlockInterface);
    manager = new RoundChangeManager(2, roundChangeMessageValidator);
    when(proposalConsistencyValidator.validateProposalMatchesBlock(any(), any(), any())).thenReturn(true);
}
Also used : BlockProcessingOutputs(org.hyperledger.besu.ethereum.BlockValidator.BlockProcessingOutputs) RoundChangePayloadValidator(org.hyperledger.besu.consensus.ibft.validation.RoundChangePayloadValidator) RoundChangeMessageValidator(org.hyperledger.besu.consensus.ibft.validation.RoundChangeMessageValidator) SignedDataValidator(org.hyperledger.besu.consensus.ibft.validation.SignedDataValidator) BlockValidator(org.hyperledger.besu.ethereum.BlockValidator) Result(org.hyperledger.besu.ethereum.BlockValidator.Result) Before(org.junit.Before)

Example 4 with BlockValidator

use of org.hyperledger.besu.ethereum.BlockValidator in project besu by hyperledger.

the class MessageValidatorFactory method createMessageValidator.

public MessageValidator createMessageValidator(final ConsensusRoundIdentifier roundIdentifier, final BlockHeader parentHeader) {
    final BlockValidator blockValidator = protocolSchedule.getByBlockNumber(roundIdentifier.getSequenceNumber()).getBlockValidator();
    final Collection<Address> validators = getValidatorsAfterBlock(parentHeader);
    final BftBlockInterface bftBlockInterface = protocolContext.getConsensusContext(BftContext.class).getBlockInterface();
    return new MessageValidator(createSignedDataValidator(roundIdentifier, parentHeader), new ProposalBlockConsistencyValidator(), blockValidator, protocolContext, new RoundChangeCertificateValidator(validators, (ri) -> createSignedDataValidator(ri, parentHeader), roundIdentifier.getSequenceNumber(), bftExtraDataCodec, bftBlockInterface));
}
Also used : BftBlockInterface(org.hyperledger.besu.consensus.common.bft.BftBlockInterface) ProtocolSchedule(org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule) BftContext(org.hyperledger.besu.consensus.common.bft.BftContext) ConsensusRoundIdentifier(org.hyperledger.besu.consensus.common.bft.ConsensusRoundIdentifier) ProposerSelector(org.hyperledger.besu.consensus.common.bft.blockcreation.ProposerSelector) BlockHeader(org.hyperledger.besu.ethereum.core.BlockHeader) Collection(java.util.Collection) BftBlockInterface(org.hyperledger.besu.consensus.common.bft.BftBlockInterface) ProtocolContext(org.hyperledger.besu.ethereum.ProtocolContext) BftHelpers(org.hyperledger.besu.consensus.common.bft.BftHelpers) BftExtraDataCodec(org.hyperledger.besu.consensus.common.bft.BftExtraDataCodec) Address(org.hyperledger.besu.datatypes.Address) BlockValidator(org.hyperledger.besu.ethereum.BlockValidator) Address(org.hyperledger.besu.datatypes.Address) BftContext(org.hyperledger.besu.consensus.common.bft.BftContext) BlockValidator(org.hyperledger.besu.ethereum.BlockValidator)

Example 5 with BlockValidator

use of org.hyperledger.besu.ethereum.BlockValidator in project besu by hyperledger.

the class NoRewardProtocolScheduleWrapper method getByBlockNumber.

@Override
public ProtocolSpec getByBlockNumber(final long number) {
    final ProtocolSpec original = delegate.getByBlockNumber(number);
    final BlockProcessor noRewardBlockProcessor = new MainnetBlockProcessor(original.getTransactionProcessor(), original.getTransactionReceiptFactory(), Wei.ZERO, original.getMiningBeneficiaryCalculator(), original.isSkipZeroBlockRewards(), Optional.empty());
    final BlockValidator noRewardBlockValidator = new MainnetBlockValidator(original.getBlockHeaderValidator(), original.getBlockBodyValidator(), noRewardBlockProcessor, original.getBadBlocksManager());
    final BlockImporter noRewardBlockImporter = new MainnetBlockImporter(noRewardBlockValidator);
    return new ProtocolSpec(original.getName(), original.getEvm(), original.getTransactionValidator(), original.getTransactionProcessor(), original.getPrivateTransactionProcessor(), original.getBlockHeaderValidator(), original.getOmmerHeaderValidator(), original.getBlockBodyValidator(), noRewardBlockProcessor, noRewardBlockImporter, noRewardBlockValidator, original.getBlockHeaderFunctions(), original.getTransactionReceiptFactory(), original.getDifficultyCalculator(), // block reward
    Wei.ZERO, original.getMiningBeneficiaryCalculator(), original.getPrecompileContractRegistry(), original.isSkipZeroBlockRewards(), original.getGasCalculator(), original.getGasLimitCalculator(), original.getFeeMarket(), original.getBadBlocksManager(), Optional.empty());
}
Also used : MainnetBlockProcessor(org.hyperledger.besu.ethereum.mainnet.MainnetBlockProcessor) MainnetBlockProcessor(org.hyperledger.besu.ethereum.mainnet.MainnetBlockProcessor) BlockProcessor(org.hyperledger.besu.ethereum.mainnet.BlockProcessor) MainnetBlockImporter(org.hyperledger.besu.ethereum.mainnet.MainnetBlockImporter) ProtocolSpec(org.hyperledger.besu.ethereum.mainnet.ProtocolSpec) MainnetBlockValidator(org.hyperledger.besu.ethereum.MainnetBlockValidator) BlockValidator(org.hyperledger.besu.ethereum.BlockValidator) MainnetBlockImporter(org.hyperledger.besu.ethereum.mainnet.MainnetBlockImporter) BlockImporter(org.hyperledger.besu.ethereum.core.BlockImporter) MainnetBlockValidator(org.hyperledger.besu.ethereum.MainnetBlockValidator)

Aggregations

BlockValidator (org.hyperledger.besu.ethereum.BlockValidator)8 Address (org.hyperledger.besu.datatypes.Address)3 Result (org.hyperledger.besu.ethereum.BlockValidator.Result)3 Before (org.junit.Before)3 BftBlockInterface (org.hyperledger.besu.consensus.common.bft.BftBlockInterface)2 BftContext (org.hyperledger.besu.consensus.common.bft.BftContext)2 Block (org.hyperledger.besu.ethereum.core.Block)2 BlockDataGenerator (org.hyperledger.besu.ethereum.core.BlockDataGenerator)2 BlockImporter (org.hyperledger.besu.ethereum.core.BlockImporter)2 TransactionReceipt (org.hyperledger.besu.ethereum.core.TransactionReceipt)2 EthContext (org.hyperledger.besu.ethereum.eth.manager.EthContext)2 EthProtocolManager (org.hyperledger.besu.ethereum.eth.manager.EthProtocolManager)2 ReferenceTestWorldState (org.hyperledger.besu.ethereum.referencetests.ReferenceTestWorldState)2 Collection (java.util.Collection)1 BftExtraDataCodec (org.hyperledger.besu.consensus.common.bft.BftExtraDataCodec)1 BftHelpers (org.hyperledger.besu.consensus.common.bft.BftHelpers)1 ConsensusRoundIdentifier (org.hyperledger.besu.consensus.common.bft.ConsensusRoundIdentifier)1 ProposerSelector (org.hyperledger.besu.consensus.common.bft.blockcreation.ProposerSelector)1 RoundChangeMessageValidator (org.hyperledger.besu.consensus.ibft.validation.RoundChangeMessageValidator)1 RoundChangePayloadValidator (org.hyperledger.besu.consensus.ibft.validation.RoundChangePayloadValidator)1