PKI QbftContext and QbftBesuControllerBuilder update (#2604)

* Added PkiQbftContext

Signed-off-by: Lucas Saldanha <lucascrsaldanha@gmail.com>
pull/2608/head
Lucas Saldanha 3 years ago committed by GitHub
parent 46df46cf90
commit e19df06c92
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 28
      besu/src/main/java/org/hyperledger/besu/controller/QbftBesuControllerBuilder.java
  2. 1
      consensus/qbft/build.gradle
  3. 40
      consensus/qbft/src/main/java/org/hyperledger/besu/consensus/qbft/pki/PkiQbftContext.java

@ -46,6 +46,8 @@ import org.hyperledger.besu.consensus.qbft.QbftExtraDataCodec;
import org.hyperledger.besu.consensus.qbft.QbftGossip;
import org.hyperledger.besu.consensus.qbft.jsonrpc.QbftJsonRpcMethods;
import org.hyperledger.besu.consensus.qbft.payload.MessageFactory;
import org.hyperledger.besu.consensus.qbft.pki.PkiQbftContext;
import org.hyperledger.besu.consensus.qbft.pki.PkiQbftExtraDataCodec;
import org.hyperledger.besu.consensus.qbft.protocol.Istanbul100SubProtocol;
import org.hyperledger.besu.consensus.qbft.statemachine.QbftBlockHeightManagerFactory;
import org.hyperledger.besu.consensus.qbft.statemachine.QbftController;
@ -68,11 +70,13 @@ import org.hyperledger.besu.ethereum.eth.transactions.TransactionPool;
import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule;
import org.hyperledger.besu.ethereum.p2p.config.SubProtocolConfiguration;
import org.hyperledger.besu.ethereum.worldstate.WorldStateArchive;
import org.hyperledger.besu.pki.keystore.KeyStoreWrapper;
import org.hyperledger.besu.util.Subscribers;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.function.Supplier;
import java.util.stream.Collectors;
@ -86,10 +90,19 @@ public class QbftBesuControllerBuilder extends BftBesuControllerBuilder {
private BftEventQueue bftEventQueue;
private QbftConfigOptions qbftConfig;
private ValidatorPeers peers;
// TODO initialize this in BesuCommand as part of the PKI setup (will be done in a follow up PR)
private final Optional<KeyStoreWrapper> pkiKeyStore = Optional.empty();
@Override
protected Supplier<BftExtraDataCodec> bftExtraDataCodec() {
return Suppliers.memoize(QbftExtraDataCodec::new);
return Suppliers.memoize(
() -> {
if (pkiKeyStore.isPresent()) {
return new PkiQbftExtraDataCodec();
} else {
return new QbftExtraDataCodec();
}
});
}
@Override
@ -262,11 +275,16 @@ public class QbftBesuControllerBuilder extends BftBesuControllerBuilder {
final Map<Long, List<Address>> bftValidatorForkMap =
convertBftForks(configOptions.getTransitions().getQbftForks());
return new BftContext(
final ValidatorProvider validatorProvider =
BlockValidatorProvider.forkingValidatorProvider(
blockchain, epochManager, bftBlockInterface().get(), bftValidatorForkMap),
epochManager,
bftBlockInterface().get());
blockchain, epochManager, bftBlockInterface().get(), bftValidatorForkMap);
if (pkiKeyStore.isPresent()) {
return new PkiQbftContext(
validatorProvider, epochManager, bftBlockInterface().get(), pkiKeyStore.get());
} else {
return new BftContext(validatorProvider, epochManager, bftBlockInterface().get());
}
}
private Map<Long, List<Address>> convertBftForks(final List<BftFork> bftForks) {

@ -65,6 +65,7 @@ dependencies {
implementation project(':ethereum:eth')
implementation project(':ethereum:p2p')
implementation project(':ethereum:rlp')
implementation project(':pki')
implementation project(':services:kvstore')
implementation 'com.google.guava:guava'

@ -0,0 +1,40 @@
/*
* Copyright ConsenSys AG.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*
* SPDX-License-Identifier: Apache-2.0
*/
package org.hyperledger.besu.consensus.qbft.pki;
import org.hyperledger.besu.consensus.common.EpochManager;
import org.hyperledger.besu.consensus.common.bft.BftBlockInterface;
import org.hyperledger.besu.consensus.common.bft.BftContext;
import org.hyperledger.besu.consensus.common.validator.ValidatorProvider;
import org.hyperledger.besu.pki.keystore.KeyStoreWrapper;
public class PkiQbftContext extends BftContext {
private final KeyStoreWrapper keyStoreWrapper;
public PkiQbftContext(
final ValidatorProvider validatorProvider,
final EpochManager epochManager,
final BftBlockInterface blockInterface,
final KeyStoreWrapper keyStoreWrapper) {
super(validatorProvider, epochManager, blockInterface);
this.keyStoreWrapper = keyStoreWrapper;
}
public KeyStoreWrapper getKeyStoreWrapper() {
return keyStoreWrapper;
}
}
Loading…
Cancel
Save