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);
}
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);
}
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);
}
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));
}
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());
}
Aggregations