use of org.hyperledger.besu.consensus.common.bft.BftContext in project besu by hyperledger.
the class QbftJsonRpcMethods method create.
@Override
protected Map<String, JsonRpcMethod> create() {
final BlockchainQueries blockchainQueries = new BlockchainQueries(context.getBlockchain(), context.getWorldStateArchive());
final BftContext bftContext = context.getConsensusContext(BftContext.class);
final BlockInterface blockInterface = bftContext.getBlockInterface();
final ValidatorProvider validatorProvider = bftContext.getValidatorProvider();
return mapOf(new QbftProposeValidatorVote(validatorProvider), new QbftGetValidatorsByBlockNumber(blockchainQueries, readOnlyValidatorProvider), new QbftDiscardValidatorVote(validatorProvider), new QbftGetValidatorsByBlockHash(context.getBlockchain(), readOnlyValidatorProvider), new QbftGetSignerMetrics(readOnlyValidatorProvider, blockInterface, blockchainQueries), new QbftGetPendingVotes(validatorProvider));
}
use of org.hyperledger.besu.consensus.common.bft.BftContext in project besu by hyperledger.
the class BftCommitSealsValidationRuleTest method correctlyConstructedHeaderPassesValidation.
@Test
public void correctlyConstructedHeaderPassesValidation() {
final List<NodeKey> committerNodeKeys = IntStream.range(0, 2).mapToObj(i -> NodeKeyUtils.generate()).collect(Collectors.toList());
final List<Address> committerAddresses = committerNodeKeys.stream().map(nodeKey -> Util.publicKeyToAddress(nodeKey.getPublicKey())).sorted().collect(Collectors.toList());
final BftContext bftContext = setupContextWithValidators(committerAddresses);
final ProtocolContext context = new ProtocolContext(null, null, bftContext);
when(bftContext.getBlockInterface().getCommitters(any())).thenReturn(committerAddresses);
assertThat(commitSealsValidationRule.validate(blockHeader, null, context)).isTrue();
}
use of org.hyperledger.besu.consensus.common.bft.BftContext in project besu by hyperledger.
the class BftCommitSealsValidationRuleTest method subExecution.
private boolean subExecution(final int validatorCount, final int committerCount) {
final List<Address> validators = Lists.newArrayList();
for (int i = 0; i < validatorCount; i++) {
// need -1 to account for proposer
final NodeKey committerNodeKey = NodeKeyUtils.generate();
validators.add(Address.extract(Hash.hash(committerNodeKey.getPublicKey().getEncodedBytes())));
}
Collections.sort(validators);
final BftContext bftContext = setupContextWithValidators(validators);
final ProtocolContext context = new ProtocolContext(null, null, bftContext);
when(bftContext.getBlockInterface().getCommitters(any())).thenReturn(validators.subList(0, committerCount));
return commitSealsValidationRule.validate(blockHeader, null, context);
}
use of org.hyperledger.besu.consensus.common.bft.BftContext in project besu by hyperledger.
the class BftCommitSealsValidationRuleTest method committerNotInValidatorListFailsValidation.
@Test
public void committerNotInValidatorListFailsValidation() {
final NodeKey committerNodeKey = NodeKeyUtils.generate();
final Address committerAddress = Util.publicKeyToAddress(committerNodeKey.getPublicKey());
final List<Address> validators = singletonList(committerAddress);
// Insert an extraData block with committer seals.
final NodeKey nonValidatorNodeKey = NodeKeyUtils.generate();
final BftContext bftContext = setupContextWithValidators(validators);
final ProtocolContext context = new ProtocolContext(null, null, bftContext);
when(bftContext.getBlockInterface().getCommitters(any())).thenReturn(singletonList(Util.publicKeyToAddress(nonValidatorNodeKey.getPublicKey())));
assertThat(commitSealsValidationRule.validate(blockHeader, null, context)).isFalse();
}
use of org.hyperledger.besu.consensus.common.bft.BftContext in project besu by hyperledger.
the class BftCommitSealsValidationRuleTest method insufficientCommitSealsFailsValidation.
@Test
public void insufficientCommitSealsFailsValidation() {
final NodeKey committerNodeKey = NodeKeyUtils.generate();
final Address committerAddress = Address.extract(Hash.hash(committerNodeKey.getPublicKey().getEncodedBytes()));
final List<Address> validators = singletonList(committerAddress);
final BftContext bftContext = setupContextWithValidators(validators);
final ProtocolContext context = new ProtocolContext(null, null, bftContext);
when(bftContext.getBlockInterface().getCommitters(any())).thenReturn(emptyList());
assertThat(commitSealsValidationRule.validate(blockHeader, null, context)).isFalse();
}
Aggregations