Search in sources :

Example 1 with CliqueContext

use of org.hyperledger.besu.consensus.clique.CliqueContext in project besu by hyperledger.

the class CliqueBesuControllerBuilder method createConsensusContext.

@Override
protected CliqueContext createConsensusContext(final Blockchain blockchain, final WorldStateArchive worldStateArchive, final ProtocolSchedule protocolSchedule) {
    final CliqueContext cliqueContext = new CliqueContext(BlockValidatorProvider.nonForkingValidatorProvider(blockchain, epochManager, blockInterface), epochManager, blockInterface);
    installCliqueBlockChoiceRule(blockchain, cliqueContext);
    return cliqueContext;
}
Also used : CliqueContext(org.hyperledger.besu.consensus.clique.CliqueContext)

Example 2 with CliqueContext

use of org.hyperledger.besu.consensus.clique.CliqueContext in project besu by hyperledger.

the class CliqueMinerExecutorTest method setup.

@Before
public void setup() {
    localAddress = Util.publicKeyToAddress(proposerNodeKey.getPublicKey());
    validatorList.add(localAddress);
    validatorList.add(AddressHelpers.calculateAddressWithRespectTo(localAddress, 1));
    validatorList.add(AddressHelpers.calculateAddressWithRespectTo(localAddress, 2));
    validatorList.add(AddressHelpers.calculateAddressWithRespectTo(localAddress, 3));
    final ValidatorProvider validatorProvider = mock(ValidatorProvider.class);
    when(validatorProvider.getValidatorsAfterBlock(any())).thenReturn(validatorList);
    final CliqueContext cliqueContext = new CliqueContext(validatorProvider, null, blockInterface);
    cliqueProtocolContext = new ProtocolContext(null, null, cliqueContext);
    blockHeaderBuilder = new BlockHeaderTestFixture();
}
Also used : BlockHeaderTestFixture(org.hyperledger.besu.ethereum.core.BlockHeaderTestFixture) ProtocolContext(org.hyperledger.besu.ethereum.ProtocolContext) ValidatorProvider(org.hyperledger.besu.consensus.common.validator.ValidatorProvider) CliqueContext(org.hyperledger.besu.consensus.clique.CliqueContext) Before(org.junit.Before)

Example 3 with CliqueContext

use of org.hyperledger.besu.consensus.clique.CliqueContext in project besu by hyperledger.

the class CliqueBlockCreator method determineCliqueVote.

private Optional<ValidatorVote> determineCliqueVote(final SealableBlockHeader sealableBlockHeader) {
    if (epochManager.isEpochBlock(sealableBlockHeader.getNumber())) {
        return Optional.empty();
    } else {
        final CliqueContext cliqueContext = protocolContext.getConsensusContext(CliqueContext.class);
        checkState(cliqueContext.getValidatorProvider().getVoteProviderAtHead().isPresent(), "Clique requires a vote provider");
        return cliqueContext.getValidatorProvider().getVoteProviderAtHead().get().getVoteAfterBlock(parentHeader, Util.publicKeyToAddress(nodeKey.getPublicKey()));
    }
}
Also used : CliqueContext(org.hyperledger.besu.consensus.clique.CliqueContext)

Example 4 with CliqueContext

use of org.hyperledger.besu.consensus.clique.CliqueContext 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 5 with CliqueContext

use of org.hyperledger.besu.consensus.clique.CliqueContext in project besu by hyperledger.

the class CliqueMiningCoordinatorTest method setup.

@Before
public void setup() {
    headerTestFixture.number(1);
    // not normally signed but ok
    Block genesisBlock = createEmptyBlock(0, Hash.ZERO, proposerKeys);
    blockChain = createInMemoryBlockchain(genesisBlock);
    when(validatorProvider.getValidatorsAfterBlock(any())).thenReturn(validators);
    final CliqueContext cliqueContext = new CliqueContext(validatorProvider, null, blockInterface);
    when(protocolContext.getConsensusContext(CliqueContext.class)).thenReturn(cliqueContext);
    when(protocolContext.getBlockchain()).thenReturn(blockChain);
    when(minerExecutor.startAsyncMining(any(), any(), any())).thenReturn(Optional.of(blockMiner));
    when(syncState.isInSync()).thenReturn(true);
    miningTracker = new CliqueMiningTracker(proposerAddress, protocolContext);
}
Also used : Block(org.hyperledger.besu.ethereum.core.Block) CliqueMiningTracker(org.hyperledger.besu.consensus.clique.CliqueMiningTracker) CliqueContext(org.hyperledger.besu.consensus.clique.CliqueContext) Before(org.junit.Before)

Aggregations

CliqueContext (org.hyperledger.besu.consensus.clique.CliqueContext)7 Before (org.junit.Before)5 ValidatorProvider (org.hyperledger.besu.consensus.common.validator.ValidatorProvider)4 ProtocolContext (org.hyperledger.besu.ethereum.ProtocolContext)4 BlockHeaderTestFixture (org.hyperledger.besu.ethereum.core.BlockHeaderTestFixture)3 Address (org.hyperledger.besu.datatypes.Address)2 Block (org.hyperledger.besu.ethereum.core.Block)2 CliqueMiningTracker (org.hyperledger.besu.consensus.clique.CliqueMiningTracker)1 EpochManager (org.hyperledger.besu.consensus.common.EpochManager)1 VoteProvider (org.hyperledger.besu.consensus.common.validator.VoteProvider)1 BlockBody (org.hyperledger.besu.ethereum.core.BlockBody)1