Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Print warning for deprecated testnets #4173

Merged
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

### Additions and Improvements
- Engine API: Change expiration time for JWT tokens to 60s [#4168](https://github.com/hyperledger/besu/pull/4168)
- Deprecation warning for Ropsten, Rinkeby, Kiln [#4173](https://github.com/hyperledger/besu/pull/4173)

### Bug Fixes

Expand Down
1 change: 1 addition & 0 deletions besu/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ dependencies {
implementation 'info.picocli:picocli'
implementation 'io.vertx:vertx-core'
implementation 'io.vertx:vertx-web'
implementation 'org.apache.commons:commons-lang3'
implementation 'org.apache.logging.log4j:log4j-core'
implementation 'org.apache.tuweni:tuweni-bytes'
implementation 'org.apache.tuweni:tuweni-config'
Expand Down
3 changes: 3 additions & 0 deletions besu/src/main/java/org/hyperledger/besu/cli/BesuCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -1393,6 +1393,9 @@ public void parse(

@Override
public void run() {
if (network != null && network.isDeprecated()) {
logger.warn(NetworkDeprecationMessage.generate(network));
}

try {
configureLogging(true);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/*
* 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.cli;

import org.hyperledger.besu.cli.config.NetworkName;

import org.apache.commons.lang3.StringUtils;

public class NetworkDeprecationMessage {
private static final int MAX_LINE_LENGTH = 80;

public static String generate(final NetworkName network) {
if (network.getDeprecationDate().isEmpty()) {
throw new AssertionError("Deprecation date is not set. Cannot print a deprecation message");
}

final StringBuilder messageBuilder = new StringBuilder("\n");
messageBuilder
.append("#".repeat(MAX_LINE_LENGTH))
.append(emptyLine())
.append(
String.format(
"#%s#",
StringUtils.center(
deprecationDetails(
network.humanReadableNetworkName(), network.getDeprecationDate().get()),
MAX_LINE_LENGTH - 2)))
.append(emptyLine())
.append(
String.format(
"#%s#\n", StringUtils.center("For more details please go to", MAX_LINE_LENGTH - 2)))
.append(
String.format(
"#%s#",
StringUtils.center(
"https://blog.ethereum.org/2022/06/21/testnet-deprecation/",
MAX_LINE_LENGTH - 2)))
.append(emptyLine())
.append("#".repeat(MAX_LINE_LENGTH));

return messageBuilder.toString();
}

private static String deprecationDetails(final String networkName, final String deprecationDate) {
return networkName + " is deprecated and will be shutdown " + deprecationDate;
}

private static String emptyLine() {
return String.format("\n#%s#\n", StringUtils.center("", MAX_LINE_LENGTH - 2));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
package org.hyperledger.besu.cli.config;

import java.math.BigInteger;
import java.util.Optional;

import org.apache.commons.lang3.StringUtils;

public enum NetworkName {
MAINNET("/mainnet.json", BigInteger.valueOf(1)),
Expand All @@ -33,17 +36,31 @@ public enum NetworkName {
private final String genesisFile;
private final BigInteger networkId;
private final boolean canFastSync;
private final String deprecationDate;

NetworkName(final String genesisFile, final BigInteger networkId) {
this.genesisFile = genesisFile;
this.networkId = networkId;
this.canFastSync = true;
this(genesisFile, networkId, true);
}

NetworkName(final String genesisFile, final BigInteger networkId, final boolean canFastSync) {
this.genesisFile = genesisFile;
this.networkId = networkId;
this.canFastSync = canFastSync;

// https://blog.ethereum.org/2022/06/21/testnet-deprecation/
switch (networkId.intValue()) {
case 3:
deprecationDate = "in Q4 2022";
break;
case 4:
deprecationDate = "in Q2/Q3 2023";
break;
case 1337802:
deprecationDate = "after the Mainnet Merge";
break;
default:
deprecationDate = null;
}
}

public String getGenesisFile() {
Expand All @@ -57,4 +74,17 @@ public BigInteger getNetworkId() {
public boolean canFastSync() {
return canFastSync;
}

public String humanReadableNetworkName() {
return StringUtils.capitalize(
StringUtils.substringAfter(StringUtils.substringBefore(genesisFile, ".json"), "/"));
}

public boolean isDeprecated() {
return deprecationDate != null;
}

public Optional<String> getDeprecationDate() {
return Optional.ofNullable(deprecationDate);
}
}
54 changes: 51 additions & 3 deletions besu/src/test/java/org/hyperledger/besu/cli/BesuCommandTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,13 @@
import static org.hyperledger.besu.cli.config.NetworkName.CLASSIC;
import static org.hyperledger.besu.cli.config.NetworkName.DEV;
import static org.hyperledger.besu.cli.config.NetworkName.GOERLI;
import static org.hyperledger.besu.cli.config.NetworkName.KILN;
import static org.hyperledger.besu.cli.config.NetworkName.KOTTI;
import static org.hyperledger.besu.cli.config.NetworkName.MAINNET;
import static org.hyperledger.besu.cli.config.NetworkName.MORDOR;
import static org.hyperledger.besu.cli.config.NetworkName.RINKEBY;
import static org.hyperledger.besu.cli.config.NetworkName.ROPSTEN;
import static org.hyperledger.besu.cli.config.NetworkName.SEPOLIA;
import static org.hyperledger.besu.cli.util.CommandLineUtils.DEPENDENCY_WARNING_MSG;
import static org.hyperledger.besu.cli.util.CommandLineUtils.DEPRECATED_AND_USELESS_WARNING_MSG;
import static org.hyperledger.besu.cli.util.CommandLineUtils.DEPRECATION_WARNING_MSG;
Expand All @@ -44,11 +46,13 @@
import static org.hyperledger.besu.nat.kubernetes.KubernetesNatManager.DEFAULT_BESU_SERVICE_NAME_FILTER;
import static org.junit.Assume.assumeThat;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.contains;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.ArgumentMatchers.isNotNull;
import static org.mockito.Mockito.atLeast;
import static org.mockito.Mockito.atMost;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoInteractions;
Expand Down Expand Up @@ -996,6 +1000,8 @@ public void testGenesisPathMainnetEthConfig() throws Exception {
assertThat(config.getBootNodes()).isEqualTo(MAINNET_BOOTSTRAP_NODES);
assertThat(config.getDnsDiscoveryUrl()).isEqualTo(MAINNET_DISCOVERY_URL);
assertThat(config.getNetworkId()).isEqualTo(BigInteger.valueOf(1));

verify(mockLogger, never()).warn(contains("Mainnet is deprecated and will be shutdown"));
}

@Test
Expand Down Expand Up @@ -3829,7 +3835,7 @@ public void devModeOptionMustBeUsed() throws Exception {
}

@Test
public void rinkebyValuesAreUsed() throws Exception {
public void rinkebyValuesAreUsed() {
parseCommand("--network", "rinkeby");

final ArgumentCaptor<EthNetworkConfig> networkArg =
Expand All @@ -3842,10 +3848,12 @@ public void rinkebyValuesAreUsed() throws Exception {

assertThat(commandOutput.toString(UTF_8)).isEmpty();
assertThat(commandErrorOutput.toString(UTF_8)).isEmpty();

verify(mockLogger, times(1)).warn(contains("Rinkeby is deprecated and will be shutdown"));
}

@Test
public void ropstenValuesAreUsed() throws Exception {
public void ropstenValuesAreUsed() {
parseCommand("--network", "ropsten");

final ArgumentCaptor<EthNetworkConfig> networkArg =
Expand All @@ -3858,10 +3866,30 @@ public void ropstenValuesAreUsed() throws Exception {

assertThat(commandOutput.toString(UTF_8)).isEmpty();
assertThat(commandErrorOutput.toString(UTF_8)).isEmpty();

verify(mockLogger, times(1)).warn(contains("Ropsten is deprecated and will be shutdown"));
}

@Test
public void kilnValuesAreUsed() {
parseCommand("--network", "kiln");

final ArgumentCaptor<EthNetworkConfig> networkArg =
ArgumentCaptor.forClass(EthNetworkConfig.class);

verify(mockControllerBuilderFactory).fromEthNetworkConfig(networkArg.capture(), any());
verify(mockControllerBuilder).build();

assertThat(networkArg.getValue()).isEqualTo(EthNetworkConfig.getNetworkConfig(KILN));

assertThat(commandOutput.toString(UTF_8)).isEmpty();
assertThat(commandErrorOutput.toString(UTF_8)).isEmpty();

verify(mockLogger, times(1)).warn(contains("Kiln is deprecated and will be shutdown"));
}

@Test
public void goerliValuesAreUsed() throws Exception {
public void goerliValuesAreUsed() {
parseCommand("--network", "goerli");

final ArgumentCaptor<EthNetworkConfig> networkArg =
Expand All @@ -3874,6 +3902,26 @@ public void goerliValuesAreUsed() throws Exception {

assertThat(commandOutput.toString(UTF_8)).isEmpty();
assertThat(commandErrorOutput.toString(UTF_8)).isEmpty();

verify(mockLogger, never()).warn(contains("Goerli is deprecated and will be shutdown"));
}

@Test
public void sepoliaValuesAreUsed() {
parseCommand("--network", "sepolia");

final ArgumentCaptor<EthNetworkConfig> networkArg =
ArgumentCaptor.forClass(EthNetworkConfig.class);

verify(mockControllerBuilderFactory).fromEthNetworkConfig(networkArg.capture(), any());
verify(mockControllerBuilder).build();

assertThat(networkArg.getValue()).isEqualTo(EthNetworkConfig.getNetworkConfig(SEPOLIA));

assertThat(commandOutput.toString(UTF_8)).isEmpty();
assertThat(commandErrorOutput.toString(UTF_8)).isEmpty();

verify(mockLogger, never()).warn(contains("Sepolia is deprecated and will be shutdown"));
}

@Test
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.cli;

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;

import org.hyperledger.besu.cli.config.NetworkName;

import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.EnumSource;

class NetworkDeprecationMessageTest {

@ParameterizedTest
@EnumSource(
value = NetworkName.class,
names = {"RINKEBY", "ROPSTEN", "KILN"})
void shouldGenerateDeprecationMessageForDeprecatedNetworks(final NetworkName network) {
assertThat(NetworkDeprecationMessage.generate(network))
.contains(network.humanReadableNetworkName() + " is deprecated and will be shutdown");
}

@ParameterizedTest
@EnumSource(
value = NetworkName.class,
names = {"RINKEBY", "ROPSTEN", "KILN"},
daniellehrner marked this conversation as resolved.
Show resolved Hide resolved
mode = EnumSource.Mode.EXCLUDE)
void shouldThrowErrorForNonDeprecatedNetworks(final NetworkName network) {
assertThatThrownBy(() -> NetworkDeprecationMessage.generate(network))
.isInstanceOf(AssertionError.class);
}
}
1 change: 1 addition & 0 deletions gradle/versions.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ dependencyManagement {
dependency 'net.java.dev.jna:jna:5.11.0'

dependency 'org.apache.commons:commons-compress:1.21'
dependency 'org.apache.commons:commons-lang3:3.12.0'
dependency 'org.apache.commons:commons-text:1.9'

dependency 'org.apache.logging.log4j:log4j-api:2.17.2'
Expand Down