mirror of https://github.com/hyperledger/besu
iterative merge: Initial plumbing for merge subproject (#2968)
Signed-off-by: garyschulte <garyschulte@gmail.com>pull/2979/head
parent
1959043af8
commit
65cb5f6a9c
@ -0,0 +1,57 @@ |
||||
/* |
||||
* 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.cli.options.unstable; |
||||
|
||||
import static org.hyperledger.besu.config.experimental.MergeOptions.setMergeEnabled; |
||||
|
||||
import java.util.Stack; |
||||
|
||||
import net.consensys.quorum.mainnet.launcher.options.Options; |
||||
import picocli.CommandLine; |
||||
import picocli.CommandLine.Option; |
||||
|
||||
/** Unstable support for eth1/2 merge */ |
||||
public class MergeOptions implements Options { |
||||
// To make it easier for tests to reset the value to default
|
||||
public static final boolean MERGE_ENABLED_DEFAULT_VALUE = false; |
||||
|
||||
@Option( |
||||
hidden = true, |
||||
names = {"--Xmerge-support"}, |
||||
description = "Enable experimental support for eth1/eth2 merge (default: ${DEFAULT-VALUE})", |
||||
arity = "1", |
||||
parameterConsumer = MergeConfigConsumer.class) |
||||
@SuppressWarnings({"FieldCanBeFinal"}) |
||||
private static boolean mergeEnabled = MERGE_ENABLED_DEFAULT_VALUE; |
||||
|
||||
public static MergeOptions create() { |
||||
return new MergeOptions(); |
||||
} |
||||
|
||||
public Boolean isMergeEnabled() { |
||||
return mergeEnabled; |
||||
} |
||||
|
||||
@SuppressWarnings({"JdkObsolete"}) |
||||
static class MergeConfigConsumer implements CommandLine.IParameterConsumer { |
||||
@Override |
||||
public void consumeParameters( |
||||
final Stack<String> args, |
||||
final CommandLine.Model.ArgSpec argSpec, |
||||
final CommandLine.Model.CommandSpec commandSpec) { |
||||
setMergeEnabled(Boolean.parseBoolean(args.pop())); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,60 @@ |
||||
/* |
||||
* 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.cli.options.unstable; |
||||
|
||||
import static org.assertj.core.api.AssertionsForClassTypes.assertThat; |
||||
import static org.assertj.core.api.AssertionsForClassTypes.assertThatThrownBy; |
||||
|
||||
import java.util.Stack; |
||||
import java.util.concurrent.atomic.AtomicBoolean; |
||||
|
||||
import org.junit.FixMethodOrder; |
||||
import org.junit.Test; |
||||
import org.junit.runners.MethodSorters; |
||||
|
||||
@SuppressWarnings({"JdkObsolete"}) |
||||
@FixMethodOrder(MethodSorters.NAME_ASCENDING) |
||||
public class MergeOptionsTest { |
||||
|
||||
@Test |
||||
public void shouldBeDisabledByDefault() { |
||||
// disabledByDefault
|
||||
assertThat(MergeOptions.create().isMergeEnabled()).isFalse(); |
||||
} |
||||
|
||||
@Test |
||||
public void shouldBeEnabledFromCliConsumer() { |
||||
// enable
|
||||
var mockStack = new Stack<String>(); |
||||
mockStack.push("true"); |
||||
new MergeOptions.MergeConfigConsumer().consumeParameters(mockStack, null, null); |
||||
|
||||
assertThat(org.hyperledger.besu.config.experimental.MergeOptions.isMergeEnabled()).isTrue(); |
||||
} |
||||
|
||||
@Test |
||||
public void shouldDoWithMergeEnabled() { |
||||
final AtomicBoolean check = new AtomicBoolean(false); |
||||
org.hyperledger.besu.config.experimental.MergeOptions.doIfMergeEnabled((() -> check.set(true))); |
||||
assertThat(check.get()).isTrue(); |
||||
} |
||||
|
||||
@Test |
||||
public void shouldThrowOnReconfigure() { |
||||
assertThatThrownBy( |
||||
() -> org.hyperledger.besu.config.experimental.MergeOptions.setMergeEnabled(false)) |
||||
.isInstanceOf(RuntimeException.class); |
||||
} |
||||
} |
@ -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.config.experimental; |
||||
|
||||
import java.util.Optional; |
||||
|
||||
/** For now there is a static config that is driven by a command line option. */ |
||||
public class MergeOptions { |
||||
private static Optional<Boolean> mergeEnabled = Optional.empty(); |
||||
|
||||
public static void setMergeEnabled(final boolean bool) { |
||||
if (!mergeEnabled.isPresent()) { |
||||
mergeEnabled = Optional.of(bool); |
||||
} else if (mergeEnabled.get() != bool) { |
||||
throw new RuntimeException("Refusing to re-configure already configured merge feature"); |
||||
} |
||||
} |
||||
|
||||
public static boolean isMergeEnabled() { |
||||
return mergeEnabled.orElse(false); |
||||
} |
||||
|
||||
public static void doIfMergeEnabled(final Runnable mergeDo) { |
||||
if (isMergeEnabled()) { |
||||
mergeDo.run(); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,48 @@ |
||||
/* |
||||
* 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 |
||||
*/ |
||||
|
||||
apply plugin: 'java-library' |
||||
|
||||
jar { |
||||
archiveBaseName = 'besu-merge' |
||||
manifest { |
||||
attributes( |
||||
'Specification-Title': archiveBaseName, |
||||
'Specification-Version': project.version, |
||||
'Implementation-Title': archiveBaseName, |
||||
'Implementation-Version': calculateVersion() |
||||
) |
||||
} |
||||
} |
||||
|
||||
repositories { mavenCentral() } |
||||
|
||||
dependencies { |
||||
implementation project(':config') |
||||
implementation project(':datatypes') |
||||
implementation project(':ethereum:blockcreation') |
||||
implementation project(':ethereum:core') |
||||
implementation project(':ethereum:eth') |
||||
implementation project(':evm') |
||||
implementation project(':util') |
||||
|
||||
implementation 'com.google.guava:guava' |
||||
implementation 'io.vertx:vertx-core' |
||||
implementation 'org.apache.tuweni:tuweni-bytes' |
||||
implementation 'org.apache.tuweni:tuweni-units' |
||||
|
||||
testImplementation 'junit:junit' |
||||
testImplementation 'org.assertj:assertj-core' |
||||
} |
@ -0,0 +1,19 @@ |
||||
/* |
||||
* 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.merge.blockcreation; |
||||
|
||||
import org.hyperledger.besu.ethereum.blockcreation.MiningCoordinator; |
||||
|
||||
public interface MergeMiningCoordinator extends MiningCoordinator {} |
Loading…
Reference in new issue