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