Search in sources :

Example 1 with BlockInterface

use of org.hyperledger.besu.consensus.common.BlockInterface in project besu by hyperledger.

the class CliqueQueryPluginServiceFactory method appendPluginServices.

@Override
public void appendPluginServices(final BesuPluginContextImpl besuContext) {
    final BlockInterface blockInterface = new CliqueBlockInterface();
    final PoaQueryServiceImpl service = new PoaQueryServiceImpl(blockInterface, blockchain, nodeKey);
    besuContext.addService(PoaQueryService.class, service);
    besuContext.addService(PoAMetricsService.class, service);
}
Also used : PoaQueryServiceImpl(org.hyperledger.besu.consensus.common.PoaQueryServiceImpl) CliqueBlockInterface(org.hyperledger.besu.consensus.clique.CliqueBlockInterface) CliqueBlockInterface(org.hyperledger.besu.consensus.clique.CliqueBlockInterface) BlockInterface(org.hyperledger.besu.consensus.common.BlockInterface)

Example 2 with BlockInterface

use of org.hyperledger.besu.consensus.common.BlockInterface in project besu by hyperledger.

the class ProposeTest method setup.

@Before
public void setup() {
    final Blockchain blockchain = mock(Blockchain.class);
    final EpochManager epochManager = mock(EpochManager.class);
    final BlockInterface blockInterface = mock(BlockInterface.class);
    validatorProvider = BlockValidatorProvider.nonForkingValidatorProvider(blockchain, epochManager, blockInterface);
}
Also used : Blockchain(org.hyperledger.besu.ethereum.chain.Blockchain) BlockInterface(org.hyperledger.besu.consensus.common.BlockInterface) EpochManager(org.hyperledger.besu.consensus.common.EpochManager) Before(org.junit.Before)

Example 3 with BlockInterface

use of org.hyperledger.besu.consensus.common.BlockInterface in project besu by hyperledger.

the class CliqueBlockChoiceTests method setup.

@Before
public void setup() {
    keyPairs = IntStream.range(0, 8).mapToObj(i -> SignatureAlgorithmFactory.getInstance().generateKeyPair()).sorted(Comparator.comparing(kp -> publicKeyToAddress(kp.getPublicKey()))).collect(Collectors.toList());
    addresses = keyPairs.stream().map(kp -> publicKeyToAddress(kp.getPublicKey())).collect(Collectors.toList());
    headerBuilder = new BlockHeaderTestFixture();
    final Block genesisBlock = createEmptyBlock(keyPairs.get(0));
    blockchain = createInMemoryBlockchain(genesisBlock, new CliqueBlockHeaderFunctions());
    final EpochManager epochManager = new EpochManager(30_000);
    final BlockInterface blockInterface = new CliqueBlockInterface();
    cliqueContext = new CliqueContext(BlockValidatorProvider.nonForkingValidatorProvider(blockchain, epochManager, blockInterface), epochManager, blockInterface);
    installCliqueBlockChoiceRule(blockchain, cliqueContext);
    for (int i = 1; i < keyPairs.size(); i++) {
        headerBuilder.number(i);
        headerBuilder.parentHash(blockchain.getChainHeadHash());
        blockchain.appendBlock(createEmptyBlock(keyPairs.get(i)), List.of());
    }
}
Also used : IntStream(java.util.stream.IntStream) EpochManager(org.hyperledger.besu.consensus.common.EpochManager) Difficulty(org.hyperledger.besu.ethereum.core.Difficulty) CliqueHelpers.distanceFromInTurn(org.hyperledger.besu.consensus.clique.CliqueHelpers.distanceFromInTurn) BlockHeader(org.hyperledger.besu.ethereum.core.BlockHeader) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) BlockInterface(org.hyperledger.besu.consensus.common.BlockInterface) Test(org.junit.Test) SignatureAlgorithmFactory(org.hyperledger.besu.crypto.SignatureAlgorithmFactory) BlockValidatorProvider(org.hyperledger.besu.consensus.common.validator.blockbased.BlockValidatorProvider) Address(org.hyperledger.besu.datatypes.Address) BlockHeaderTestFixture(org.hyperledger.besu.ethereum.core.BlockHeaderTestFixture) Collectors(java.util.stream.Collectors) CliqueHelpers.installCliqueBlockChoiceRule(org.hyperledger.besu.consensus.clique.CliqueHelpers.installCliqueBlockChoiceRule) InMemoryKeyValueStorageProvider.createInMemoryBlockchain(org.hyperledger.besu.ethereum.core.InMemoryKeyValueStorageProvider.createInMemoryBlockchain) List(java.util.List) Lists(com.google.common.collect.Lists) Util.publicKeyToAddress(org.hyperledger.besu.ethereum.core.Util.publicKeyToAddress) KeyPair(org.hyperledger.besu.crypto.KeyPair) BlockBody(org.hyperledger.besu.ethereum.core.BlockBody) Block(org.hyperledger.besu.ethereum.core.Block) MutableBlockchain(org.hyperledger.besu.ethereum.chain.MutableBlockchain) Comparator(java.util.Comparator) Before(org.junit.Before) BlockHeaderTestFixture(org.hyperledger.besu.ethereum.core.BlockHeaderTestFixture) Block(org.hyperledger.besu.ethereum.core.Block) BlockInterface(org.hyperledger.besu.consensus.common.BlockInterface) EpochManager(org.hyperledger.besu.consensus.common.EpochManager) Before(org.junit.Before)

Example 4 with BlockInterface

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

use of org.hyperledger.besu.consensus.common.BlockInterface in project besu by hyperledger.

the class IbftJsonRpcMethods method create.

@Override
protected Map<String, JsonRpcMethod> create() {
    final MutableBlockchain blockchain = context.getBlockchain();
    final BlockchainQueries blockchainQueries = new BlockchainQueries(blockchain, context.getWorldStateArchive());
    final BftContext bftContext = context.getConsensusContext(BftContext.class);
    final BlockInterface blockInterface = bftContext.getBlockInterface();
    final ValidatorProvider validatorProvider = context.getConsensusContext(BftContext.class).getValidatorProvider();
    // Must create our own voteTallyCache as using this would pollute the main voteTallyCache
    final ValidatorProvider readOnlyValidatorProvider = createValidatorProvider(context, blockchain);
    return mapOf(new IbftProposeValidatorVote(validatorProvider), new IbftGetValidatorsByBlockNumber(blockchainQueries, blockInterface), new IbftDiscardValidatorVote(validatorProvider), new IbftGetValidatorsByBlockHash(blockchain, blockInterface), new IbftGetSignerMetrics(readOnlyValidatorProvider, blockInterface, blockchainQueries), new IbftGetPendingVotes(validatorProvider));
}
Also used : IbftGetPendingVotes(org.hyperledger.besu.consensus.ibft.jsonrpc.methods.IbftGetPendingVotes) IbftGetValidatorsByBlockHash(org.hyperledger.besu.consensus.ibft.jsonrpc.methods.IbftGetValidatorsByBlockHash) BftContext(org.hyperledger.besu.consensus.common.bft.BftContext) IbftGetValidatorsByBlockNumber(org.hyperledger.besu.consensus.ibft.jsonrpc.methods.IbftGetValidatorsByBlockNumber) IbftGetSignerMetrics(org.hyperledger.besu.consensus.ibft.jsonrpc.methods.IbftGetSignerMetrics) BlockchainQueries(org.hyperledger.besu.ethereum.api.query.BlockchainQueries) IbftProposeValidatorVote(org.hyperledger.besu.consensus.ibft.jsonrpc.methods.IbftProposeValidatorVote) IbftDiscardValidatorVote(org.hyperledger.besu.consensus.ibft.jsonrpc.methods.IbftDiscardValidatorVote) MutableBlockchain(org.hyperledger.besu.ethereum.chain.MutableBlockchain) BlockInterface(org.hyperledger.besu.consensus.common.BlockInterface) BftBlockInterface(org.hyperledger.besu.consensus.common.bft.BftBlockInterface) BlockValidatorProvider(org.hyperledger.besu.consensus.common.validator.blockbased.BlockValidatorProvider) ValidatorProvider(org.hyperledger.besu.consensus.common.validator.ValidatorProvider)

Aggregations

BlockInterface (org.hyperledger.besu.consensus.common.BlockInterface)6 EpochManager (org.hyperledger.besu.consensus.common.EpochManager)3 Before (org.junit.Before)3 BftContext (org.hyperledger.besu.consensus.common.bft.BftContext)2 ValidatorProvider (org.hyperledger.besu.consensus.common.validator.ValidatorProvider)2 BlockValidatorProvider (org.hyperledger.besu.consensus.common.validator.blockbased.BlockValidatorProvider)2 BlockchainQueries (org.hyperledger.besu.ethereum.api.query.BlockchainQueries)2 Blockchain (org.hyperledger.besu.ethereum.chain.Blockchain)2 MutableBlockchain (org.hyperledger.besu.ethereum.chain.MutableBlockchain)2 Lists (com.google.common.collect.Lists)1 Comparator (java.util.Comparator)1 List (java.util.List)1 Collectors (java.util.stream.Collectors)1 IntStream (java.util.stream.IntStream)1 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)1 CliqueBlockInterface (org.hyperledger.besu.consensus.clique.CliqueBlockInterface)1 CliqueHelpers.distanceFromInTurn (org.hyperledger.besu.consensus.clique.CliqueHelpers.distanceFromInTurn)1 CliqueHelpers.installCliqueBlockChoiceRule (org.hyperledger.besu.consensus.clique.CliqueHelpers.installCliqueBlockChoiceRule)1 PoaQueryServiceImpl (org.hyperledger.besu.consensus.common.PoaQueryServiceImpl)1 BftBlockInterface (org.hyperledger.besu.consensus.common.bft.BftBlockInterface)1