Skip to content

Commit

Permalink
Add QBFT support for evmtool (hyperledger#2807)
Browse files Browse the repository at this point in the history
* qbft support in evmtool

Signed-off-by: Usman Saleem <usman@usmans.info>
  • Loading branch information
usmansaleem authored and jflo committed Oct 13, 2021
1 parent fd05ee6 commit 82c8831
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,9 @@ public Map<String, Object> asMap() {
if (isIbft2()) {
builder.put("ibft2", getBftConfigOptions().asMap());
}
if (isQbft()) {
builder.put("qbft", getQbftConfigOptions().asMap());
}

if (isQuorum()) {
builder.put("isQuorum", true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,18 @@ public static ProtocolSchedule create(
return create(config, PrivacyParameters.DEFAULT, false, bftExtraDataCodec, evmConfiguration);
}

public static ProtocolSchedule create(
final GenesisConfigOptions config,
final boolean isRevertReasonEnabled,
final BftExtraDataCodec bftExtraDataCodec) {
return create(
config,
PrivacyParameters.DEFAULT,
isRevertReasonEnabled,
bftExtraDataCodec,
EvmConfiguration.DEFAULT);
}

@Override
protected Supplier<BlockHeaderValidator.Builder> createForkBlockHeaderRuleset(
final GenesisConfigOptions config, final BftFork fork) {
Expand Down
1 change: 1 addition & 0 deletions ethereum/evmtool/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ dependencies {
implementation project(':consensus:clique')
implementation project(':consensus:common')
implementation project(':consensus:ibft')
implementation project(':consensus:qbft')
implementation project(':ethereum:api')
implementation project(':ethereum:core')
implementation project(':ethereum:referencetests')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,8 @@ private static GenesisFileModule createGenesisModule(final String genesisConfig)
return new IBFTGenesisFileModule(genesisConfig);
} else if (config.containsKey("clique")) {
return new CliqueGenesisFileModule(genesisConfig);
} else if (config.containsKey("qbft")) {
return new QBFTGenesisFileModule(genesisConfig);
} else {
// default is mainnet
return new MainnetGenesisFileModule(genesisConfig);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* Copyright Hyperledger Besu Contributors.
*
* 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.evmtool;

import org.hyperledger.besu.config.GenesisConfigOptions;
import org.hyperledger.besu.consensus.common.bft.BftBlockHeaderFunctions;
import org.hyperledger.besu.consensus.qbft.QbftExtraDataCodec;
import org.hyperledger.besu.consensus.qbft.QbftProtocolSchedule;
import org.hyperledger.besu.ethereum.core.BlockHeaderFunctions;
import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule;

import javax.inject.Named;

class QBFTGenesisFileModule extends GenesisFileModule {
final QbftExtraDataCodec bftExtraDataEncoder;

QBFTGenesisFileModule(final String genesisConfig) {
super(genesisConfig);
bftExtraDataEncoder = new QbftExtraDataCodec();
}

@Override
ProtocolSchedule provideProtocolSchedule(
final GenesisConfigOptions configOptions,
@Named("RevertReasonEnabled") final boolean revertReasonEnabled) {
return QbftProtocolSchedule.create(configOptions, revertReasonEnabled, bftExtraDataEncoder);
}

@Override
BlockHeaderFunctions blockHashFunction() {
return BftBlockHeaderFunctions.forOnchainBlock(bftExtraDataEncoder);
}
}

0 comments on commit 82c8831

Please sign in to comment.