use of org.hyperledger.besu.consensus.common.validator.VoteProvider in project besu by hyperledger.
the class ForkingValidatorProviderTest method getVoteProviderAfterBlock_correctVoteProviderIsResolved.
@Test
public void getVoteProviderAfterBlock_correctVoteProviderIsResolved() {
final ForksSchedule<QbftConfigOptions> forksSchedule = new ForksSchedule<>(List.of(createBlockForkSpec(0), createBlockForkSpec(1), createContractForkSpec(2, CONTRACT_ADDRESS_1)));
final ForkingValidatorProvider validatorProvider = new ForkingValidatorProvider(blockChain, forksSchedule, blockValidatorProvider, contractValidatorProvider);
final VoteProvider voteProviderForBlockValidator = Mockito.mock(VoteProvider.class);
when(blockValidatorProvider.getVoteProviderAtHead()).thenReturn(Optional.of(voteProviderForBlockValidator));
when(contractValidatorProvider.getVoteProviderAtHead()).thenReturn(Optional.empty());
SoftAssertions.assertSoftly((softly) -> {
softly.assertThat(validatorProvider.getVoteProviderAfterBlock(genesisHeader)).contains(voteProviderForBlockValidator);
softly.assertThat(validatorProvider.getVoteProviderAfterBlock(header1)).isEmpty();
softly.assertThat(validatorProvider.getVoteProviderAfterBlock(header2)).isEmpty();
});
}
use of org.hyperledger.besu.consensus.common.validator.VoteProvider in project besu by hyperledger.
the class CliqueBlockCreatorTest method setup.
@Before
public void setup() {
protocolSchedule = CliqueProtocolSchedule.create(GenesisConfigFile.DEFAULT.getConfigOptions(), proposerNodeKey, false, EvmConfiguration.DEFAULT);
final Address otherAddress = Util.publicKeyToAddress(otherKeyPair.getPublicKey());
validatorList.add(otherAddress);
validatorProvider = mock(ValidatorProvider.class);
voteProvider = mock(VoteProvider.class);
when(validatorProvider.getVoteProviderAtHead()).thenReturn(Optional.of(voteProvider));
when(validatorProvider.getValidatorsAfterBlock(any())).thenReturn(validatorList);
final CliqueContext cliqueContext = new CliqueContext(validatorProvider, null, blockInterface);
final Block genesis = GenesisState.fromConfig(GenesisConfigFile.mainnet(), protocolSchedule).getBlock();
blockchain = createInMemoryBlockchain(genesis);
protocolContext = new ProtocolContext(blockchain, stateArchive, cliqueContext);
epochManager = new EpochManager(10);
// Add a block above the genesis
final BlockHeaderTestFixture headerTestFixture = new BlockHeaderTestFixture();
headerTestFixture.number(1).parentHash(genesis.getHeader().getHash());
final Block emptyBlock = new Block(TestHelpers.createCliqueSignedBlockHeader(headerTestFixture, otherKeyPair, validatorList), new BlockBody(Lists.newArrayList(), Lists.newArrayList()));
blockchain.appendBlock(emptyBlock, Lists.newArrayList());
}
use of org.hyperledger.besu.consensus.common.validator.VoteProvider in project besu by hyperledger.
the class BftBlockCreatorFactory method createExtraData.
public Bytes createExtraData(final int round, final BlockHeader parentHeader) {
final BftContext bftContext = protocolContext.getConsensusContext(BftContext.class);
final ValidatorProvider validatorProvider = bftContext.getValidatorProvider();
Optional<VoteProvider> voteProviderAfterBlock = validatorProvider.getVoteProviderAfterBlock(parentHeader);
checkState(voteProviderAfterBlock.isPresent(), "Bft requires a vote provider");
final Optional<ValidatorVote> proposal = voteProviderAfterBlock.get().getVoteAfterBlock(parentHeader, localAddress);
final List<Address> validators = new ArrayList<>(validatorProvider.getValidatorsAfterBlock(parentHeader));
final BftExtraData extraData = new BftExtraData(ConsensusHelpers.zeroLeftPad(vanityData, BftExtraDataCodec.EXTRA_VANITY_LENGTH), Collections.emptyList(), toVote(proposal), round, validators);
return bftExtraDataCodec.encode(extraData);
}
Aggregations