Search in sources :

Example 1 with VoteProvider

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();
    });
}
Also used : VoteProvider(org.hyperledger.besu.consensus.common.validator.VoteProvider) QbftConfigOptions(org.hyperledger.besu.config.QbftConfigOptions) ForksSchedule(org.hyperledger.besu.consensus.common.ForksSchedule) Test(org.junit.Test)

Example 2 with VoteProvider

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());
}
Also used : BlockHeaderTestFixture(org.hyperledger.besu.ethereum.core.BlockHeaderTestFixture) Address(org.hyperledger.besu.datatypes.Address) BlockBody(org.hyperledger.besu.ethereum.core.BlockBody) VoteProvider(org.hyperledger.besu.consensus.common.validator.VoteProvider) Block(org.hyperledger.besu.ethereum.core.Block) ProtocolContext(org.hyperledger.besu.ethereum.ProtocolContext) ValidatorProvider(org.hyperledger.besu.consensus.common.validator.ValidatorProvider) EpochManager(org.hyperledger.besu.consensus.common.EpochManager) CliqueContext(org.hyperledger.besu.consensus.clique.CliqueContext) Before(org.junit.Before)

Example 3 with VoteProvider

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);
}
Also used : BftContext(org.hyperledger.besu.consensus.common.bft.BftContext) ValidatorVote(org.hyperledger.besu.consensus.common.validator.ValidatorVote) Address(org.hyperledger.besu.datatypes.Address) VoteProvider(org.hyperledger.besu.consensus.common.validator.VoteProvider) ArrayList(java.util.ArrayList) ValidatorProvider(org.hyperledger.besu.consensus.common.validator.ValidatorProvider) BftExtraData(org.hyperledger.besu.consensus.common.bft.BftExtraData)

Aggregations

VoteProvider (org.hyperledger.besu.consensus.common.validator.VoteProvider)3 ValidatorProvider (org.hyperledger.besu.consensus.common.validator.ValidatorProvider)2 Address (org.hyperledger.besu.datatypes.Address)2 ArrayList (java.util.ArrayList)1 QbftConfigOptions (org.hyperledger.besu.config.QbftConfigOptions)1 CliqueContext (org.hyperledger.besu.consensus.clique.CliqueContext)1 EpochManager (org.hyperledger.besu.consensus.common.EpochManager)1 ForksSchedule (org.hyperledger.besu.consensus.common.ForksSchedule)1 BftContext (org.hyperledger.besu.consensus.common.bft.BftContext)1 BftExtraData (org.hyperledger.besu.consensus.common.bft.BftExtraData)1 ValidatorVote (org.hyperledger.besu.consensus.common.validator.ValidatorVote)1 ProtocolContext (org.hyperledger.besu.ethereum.ProtocolContext)1 Block (org.hyperledger.besu.ethereum.core.Block)1 BlockBody (org.hyperledger.besu.ethereum.core.BlockBody)1 BlockHeaderTestFixture (org.hyperledger.besu.ethereum.core.BlockHeaderTestFixture)1 Before (org.junit.Before)1 Test (org.junit.Test)1