Skip to content

Commit

Permalink
Add config option so that pos can be used at genesis
Browse files Browse the repository at this point in the history
Signed-off-by: Jason Frame <[email protected]>
  • Loading branch information
jframe committed Jan 27, 2023
1 parent 835769d commit a373846
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -330,10 +330,16 @@ BesuControllerBuilder fromGenesisConfig(
builder = new QbftBesuControllerBuilder();
} else if (configOptions.isClique()) {
builder = new CliqueBesuControllerBuilder();
} else if (configOptions.isPos()) {
builder = new MergeBesuControllerBuilder();
} else {
throw new IllegalArgumentException("Unknown consensus mechanism defined");
}

if (configOptions.isPos()) {
return builder.genesisConfigFile(genesisConfig);
}

// wrap with TransitionBesuControllerBuilder if we have a terminal total difficulty:
if (configOptions.getTerminalTotalDifficulty().isPresent()) {
// Enable start with vanilla MergeBesuControllerBuilder for PoS checkpoint block
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,13 @@ public interface GenesisConfigOptions {
*/
boolean isClique();

/**
* Is pos boolean.
*
* @return the boolean
*/
boolean isPos();

/**
* Is consensus migration boolean.
*
Expand Down Expand Up @@ -136,6 +143,13 @@ default boolean isConsensusMigration() {
*/
EthashConfigOptions getEthashConfigOptions();

/**
* Gets pos config options.
*
* @return the pos config options
*/
PosConfigOptions getPosConfigOptions();

/**
* Gets keccak 256 config options.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
public class JsonGenesisConfigOptions implements GenesisConfigOptions {

private static final String ETHASH_CONFIG_KEY = "ethash";
private static final String POS_CONFIG_KEY = "pos";
private static final String KECCAK256_CONFIG_KEY = "keccak256";
private static final String IBFT_LEGACY_CONFIG_KEY = "ibft";
private static final String IBFT2_CONFIG_KEY = "ibft2";
Expand Down Expand Up @@ -144,6 +145,11 @@ public boolean isClique() {
return configRoot.has(CLIQUE_CONFIG_KEY);
}

@Override
public boolean isPos() {
return configRoot.has(POS_CONFIG_KEY);
}

@Override
public boolean isIbft2() {
return configRoot.has(IBFT2_CONFIG_KEY);
Expand Down Expand Up @@ -204,6 +210,13 @@ public EthashConfigOptions getEthashConfigOptions() {
.orElse(EthashConfigOptions.DEFAULT);
}

@Override
public PosConfigOptions getPosConfigOptions() {
return JsonUtil.getObjectNode(configRoot, POS_CONFIG_KEY)
.map(ignore -> new PosConfigOptions())
.orElse(PosConfigOptions.DEFAULT);
}

@Override
public Keccak256ConfigOptions getKeccak256ConfigOptions() {
return JsonUtil.getObjectNode(configRoot, KECCAK256_CONFIG_KEY)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* 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.config;

import java.util.Map;

import com.google.common.collect.ImmutableMap;

public class PosConfigOptions {
/** The constant DEFAULT. */
public static final PosConfigOptions DEFAULT = new PosConfigOptions();

/** Instantiates a new Pos config options. */
PosConfigOptions() {}

/**
* As map.
*
* @return the map
*/
Map<String, Object> asMap() {
final ImmutableMap.Builder<String, Object> builder = ImmutableMap.builder();
return builder.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,11 @@ public boolean isClique() {
return false;
}

@Override
public boolean isPos() {
return false;
}

@Override
public boolean isIbft2() {
return false;
Expand Down Expand Up @@ -146,6 +151,11 @@ public EthashConfigOptions getEthashConfigOptions() {
return EthashConfigOptions.DEFAULT;
}

@Override
public PosConfigOptions getPosConfigOptions() {
return PosConfigOptions.DEFAULT;
}

@Override
public Keccak256ConfigOptions getKeccak256ConfigOptions() {
return Keccak256ConfigOptions.DEFAULT;
Expand Down

0 comments on commit a373846

Please sign in to comment.