Search in sources :

Example 1 with BftContext

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));
}
Also used : QbftProposeValidatorVote(org.hyperledger.besu.consensus.qbft.jsonrpc.methods.QbftProposeValidatorVote) BftContext(org.hyperledger.besu.consensus.common.bft.BftContext) BlockchainQueries(org.hyperledger.besu.ethereum.api.query.BlockchainQueries) QbftGetValidatorsByBlockNumber(org.hyperledger.besu.consensus.qbft.jsonrpc.methods.QbftGetValidatorsByBlockNumber) BlockInterface(org.hyperledger.besu.consensus.common.BlockInterface) QbftGetValidatorsByBlockHash(org.hyperledger.besu.consensus.qbft.jsonrpc.methods.QbftGetValidatorsByBlockHash) QbftDiscardValidatorVote(org.hyperledger.besu.consensus.qbft.jsonrpc.methods.QbftDiscardValidatorVote) ValidatorProvider(org.hyperledger.besu.consensus.common.validator.ValidatorProvider) QbftGetSignerMetrics(org.hyperledger.besu.consensus.qbft.jsonrpc.methods.QbftGetSignerMetrics) QbftGetPendingVotes(org.hyperledger.besu.consensus.qbft.jsonrpc.methods.QbftGetPendingVotes)

Example 2 with BftContext

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();
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) IntStream(java.util.stream.IntStream) NodeKeyUtils(org.hyperledger.besu.crypto.NodeKeyUtils) Collections.emptyList(java.util.Collections.emptyList) BlockHeader(org.hyperledger.besu.ethereum.core.BlockHeader) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) Address(org.hyperledger.besu.datatypes.Address) Util(org.hyperledger.besu.ethereum.core.Util) Collectors(java.util.stream.Collectors) Collections.singletonList(java.util.Collections.singletonList) BftContext(org.hyperledger.besu.consensus.common.bft.BftContext) List(java.util.List) Lists(com.google.common.collect.Lists) BftContextBuilder.setupContextWithValidators(org.hyperledger.besu.consensus.common.bft.BftContextBuilder.setupContextWithValidators) ProtocolContext(org.hyperledger.besu.ethereum.ProtocolContext) Collections(java.util.Collections) Mockito.mock(org.mockito.Mockito.mock) NodeKey(org.hyperledger.besu.crypto.NodeKey) Hash(org.hyperledger.besu.datatypes.Hash) Address(org.hyperledger.besu.datatypes.Address) BftContext(org.hyperledger.besu.consensus.common.bft.BftContext) ProtocolContext(org.hyperledger.besu.ethereum.ProtocolContext) NodeKey(org.hyperledger.besu.crypto.NodeKey) Test(org.junit.Test)

Example 3 with BftContext

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);
}
Also used : Address(org.hyperledger.besu.datatypes.Address) BftContext(org.hyperledger.besu.consensus.common.bft.BftContext) ProtocolContext(org.hyperledger.besu.ethereum.ProtocolContext) NodeKey(org.hyperledger.besu.crypto.NodeKey)

Example 4 with BftContext

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();
}
Also used : Address(org.hyperledger.besu.datatypes.Address) BftContext(org.hyperledger.besu.consensus.common.bft.BftContext) ProtocolContext(org.hyperledger.besu.ethereum.ProtocolContext) NodeKey(org.hyperledger.besu.crypto.NodeKey) Test(org.junit.Test)

Example 5 with BftContext

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();
}
Also used : Address(org.hyperledger.besu.datatypes.Address) BftContext(org.hyperledger.besu.consensus.common.bft.BftContext) ProtocolContext(org.hyperledger.besu.ethereum.ProtocolContext) NodeKey(org.hyperledger.besu.crypto.NodeKey) Test(org.junit.Test)

Aggregations

BftContext (org.hyperledger.besu.consensus.common.bft.BftContext)16 Address (org.hyperledger.besu.datatypes.Address)9 ProtocolContext (org.hyperledger.besu.ethereum.ProtocolContext)7 NodeKey (org.hyperledger.besu.crypto.NodeKey)5 BftExtraData (org.hyperledger.besu.consensus.common.bft.BftExtraData)4 ValidatorProvider (org.hyperledger.besu.consensus.common.validator.ValidatorProvider)4 EpochManager (org.hyperledger.besu.consensus.common.EpochManager)3 BftBlockInterface (org.hyperledger.besu.consensus.common.bft.BftBlockInterface)3 Test (org.junit.Test)3 ArrayList (java.util.ArrayList)2 BftConfigOptions (org.hyperledger.besu.config.BftConfigOptions)2 BlockInterface (org.hyperledger.besu.consensus.common.BlockInterface)2 BlockValidatorProvider (org.hyperledger.besu.consensus.common.validator.blockbased.BlockValidatorProvider)2 Lists (com.google.common.collect.Lists)1 Collections (java.util.Collections)1 Collections.emptyList (java.util.Collections.emptyList)1 Collections.singletonList (java.util.Collections.singletonList)1 List (java.util.List)1 TreeSet (java.util.TreeSet)1 Collectors (java.util.stream.Collectors)1