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

Add Shandong network and fork #4599

Merged
merged 9 commits into from
Nov 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
- Fields `publicKey` and `raw` removed from RPC API `Transaction` result object [#4575](https://github.com/hyperledger/besu/pull/4575)

### Additions and Improvements
- Support for ephemeral testnet Shandong. EIPs are still in flux, besu does not fully sync yet, and the network is subject to restarts. [#//FIXME](https://github.com/hyperledger/besu/pull///FIXME)

### Bug Fixes

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public enum NetworkName {
ROPSTEN("/ropsten.json", BigInteger.valueOf(3)),
SEPOLIA("/sepolia.json", BigInteger.valueOf(11155111)),
GOERLI("/goerli.json", BigInteger.valueOf(5)),
SHANDONG("/shandong.json", BigInteger.valueOf(1337903)),
KILN("/kiln.json", BigInteger.valueOf(1337802), false),
DEV("/dev.json", BigInteger.valueOf(2018), false),
CLASSIC("/classic.json", BigInteger.valueOf(1)),
Expand Down
6 changes: 6 additions & 0 deletions besu/src/test/java/org/hyperledger/besu/ForkIdsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,12 @@ public static Collection<Object[]> parameters() {
new ForkId(Bytes.ofUnsignedInt(0xb8c6299dL), 0L),
new ForkId(Bytes.ofUnsignedInt(0xb8c6299dL), 0L))
},
new Object[] {
NetworkName.SHANDONG,
List.of(
new ForkId(Bytes.ofUnsignedInt(0xc42480d3L), 0L),
new ForkId(Bytes.ofUnsignedInt(0xc42480d3L), 0L))
},
new Object[] {
NetworkName.MAINNET,
List.of(
Expand Down
40 changes: 40 additions & 0 deletions besu/src/test/java/org/hyperledger/besu/cli/BesuCommandTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
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.config.NetworkName.SHANDONG;
import static org.hyperledger.besu.cli.util.CommandLineUtils.DEPENDENCY_WARNING_MSG;
import static org.hyperledger.besu.cli.util.CommandLineUtils.DEPRECATION_WARNING_MSG;
import static org.hyperledger.besu.ethereum.api.jsonrpc.RpcApis.ENGINE;
Expand All @@ -43,6 +44,7 @@
import static org.hyperledger.besu.ethereum.p2p.config.DefaultDiscoveryConfiguration.MAINNET_DISCOVERY_URL;
import static org.hyperledger.besu.ethereum.p2p.config.DefaultDiscoveryConfiguration.RINKEBY_BOOTSTRAP_NODES;
import static org.hyperledger.besu.ethereum.p2p.config.DefaultDiscoveryConfiguration.RINKEBY_DISCOVERY_URL;
import static org.hyperledger.besu.ethereum.p2p.config.DefaultDiscoveryConfiguration.SHANDONG_BOOTSTRAP_NODES;
import static org.hyperledger.besu.ethereum.worldstate.DataStorageFormat.BONSAI;
import static org.hyperledger.besu.nat.kubernetes.KubernetesNatManager.DEFAULT_BESU_SERVICE_NAME_FILTER;
import static org.junit.Assume.assumeThat;
Expand Down Expand Up @@ -1041,6 +1043,22 @@ public void testGenesisPathRinkebyEthConfig() {
assertThat(config.getNetworkId()).isEqualTo(BigInteger.valueOf(4));
}

@Test
public void testGenesisPathShandongEthConfig() {
final ArgumentCaptor<EthNetworkConfig> networkArg =
ArgumentCaptor.forClass(EthNetworkConfig.class);

parseCommand("--network", "shandong");

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

final EthNetworkConfig config = networkArg.getValue();
assertThat(config.getBootNodes()).isEqualTo(SHANDONG_BOOTSTRAP_NODES);
assertThat(config.getDnsDiscoveryUrl()).isNull();
assertThat(config.getNetworkId()).isEqualTo(BigInteger.valueOf(1337903));
}

@Test
public void genesisAndNetworkMustNotBeUsedTogether() throws Exception {
final Path genesisFile = createFakeGenesisFile(GENESIS_VALID_JSON);
Expand Down Expand Up @@ -3976,6 +3994,24 @@ public void sepoliaValuesAreUsed() {
verify(mockLogger, never()).warn(contains("Sepolia is deprecated and will be shutdown"));
}

@Test
public void shandongValuesAreUsed() {
parseCommand("--network", "shandong");

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

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

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

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

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

@Test
public void classicValuesAreUsed() throws Exception {
parseCommand("--network", "classic");
Expand Down Expand Up @@ -4039,6 +4075,10 @@ public void ropstenValuesCanBeOverridden() throws Exception {
networkValuesCanBeOverridden("ropsten");
}

public void shandongValuesCanBeOverridden() throws Exception {
networkValuesCanBeOverridden("shandong");
}

@Test
public void devValuesCanBeOverridden() throws Exception {
networkValuesCanBeOverridden("dev");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ void shouldGenerateDeprecationMessageForDeprecatedNetworks(final NetworkName net
"MAINNET",
"SEPOLIA",
"GOERLI",
"SHANDONG",
"DEV",
"CLASSIC",
"KOTTI",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import static org.hyperledger.besu.ethereum.p2p.config.DefaultDiscoveryConfiguration.MAINNET_DISCOVERY_URL;
import static org.hyperledger.besu.ethereum.p2p.config.DefaultDiscoveryConfiguration.RINKEBY_BOOTSTRAP_NODES;
import static org.hyperledger.besu.ethereum.p2p.config.DefaultDiscoveryConfiguration.RINKEBY_DISCOVERY_URL;
import static org.hyperledger.besu.ethereum.p2p.config.DefaultDiscoveryConfiguration.SHANDONG_BOOTSTRAP_NODES;

import java.math.BigInteger;

Expand Down Expand Up @@ -56,6 +57,14 @@ public void testDefaultGoerliConfig() {
assertThat(config.getNetworkId()).isEqualTo(BigInteger.valueOf(5));
}

@Test
public void testDefaultShandongConfig() {
EthNetworkConfig config = EthNetworkConfig.getNetworkConfig(NetworkName.SHANDONG);
assertThat(config.getDnsDiscoveryUrl()).isNull();
assertThat(config.getBootNodes()).isEqualTo(SHANDONG_BOOTSTRAP_NODES);
assertThat(config.getNetworkId()).isEqualTo(BigInteger.valueOf(1337903));
}

@Test
public void testDefaultDevConfig() {
EthNetworkConfig config = EthNetworkConfig.getNetworkConfig(NetworkName.DEV);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,19 @@ public class DefaultDiscoveryConfiguration {
"enode://9246d00bc8fd1742e5ad2428b80fc4dc45d786283e05ef6edbd9002cbc335d40998444732fbe921cb88e1d2c73d1b1de53bae6a2237996e9bfe14f871baf7066@18.168.182.86:30303")
.map(EnodeURLImpl::fromString)
.collect(toList()));
public static final List<EnodeURL> SHANDONG_BOOTSTRAP_NODES =
Collections.unmodifiableList(
Stream.of(
"enode://11e43515d6258ab2bd814b25a50c911c155a46a27e9be8ce6ea68e293ec13aa4cd6740418baf9abf1e79ba9252c497d66aa4a293c94ef8168d0e7c211ef73690@46.101.126.45:30303",
"enode://95b683a66aba396551bafff688644fc6dc1bada2de78491f89b268ebdcf3d88dfc9942a9f2833ecc3887d49dfb4e96851c2f5eb0adde41847cc356f15ac4ac67@178.128.206.76:30303",
"enode://bcd3eeabca8ff3a1c3b19384e064cc79fda547939324e0699d030041a8960a1d68f1e19141d19305e79675be50434521d024352a5eae00da8ace7933abf20fdf@142.93.160.7:30303",
"enode://6a65c7e62360e1fcc98c88cf8dd8e9492d2e95372f5d7b742b73ab8f82e849bae196bd18b79bc9502b204cef7bf64b589147700368d877c32a76f9c4fd7dd941@104.248.21.4:30303",
"enode://2ae5ef4b4c338e4ee15a347aba8e60bcb451ca19d26f8d67e731bb5f2972ad6ce867ec85f9942a5efe349470106b21c49a9aeb5b00b91063e35f1c1643c0930c@104.248.251.20:30303",
"enode://85ecd8fcab723a33ee68e5f8530c9d264bd601899dc74af7f020bc2f8e0d0ad8ec5c5324364f127c77ddab607bc16e1c5fbae2c675b6d94a79a24222e7e4766e@164.92.174.56:30303",
"enode://24951d3b76f20aed18e32096941d572b98518c9e4dace6b7d0b1f34292dfc5ee7d295453b955be4d2967c6ce1948c11513cd70d76dbee8d3034ddb40d63f5517@142.93.173.170:30303",
"enode://73e2396ac78c462287edd22957096890ca1995a4995c51a1fe24accbe931209fb0fc5359fc1043a0edad3fc53ba64fba5262255c70a03e5fca86f924c261ad4f@178.128.203.243:30303")
.map(EnodeURLImpl::fromString)
.collect(toList()));
public static final List<EnodeURL> CLASSIC_BOOTSTRAP_NODES =
Collections.unmodifiableList(
Stream.of(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public class GenesisConfigFile {
public static final GenesisConfigFile DEFAULT =
new GenesisConfigFile(JsonUtil.createEmptyObjectNode());

public static final Wei BASEFEE_AT_GENESIS_DEFAULT_VALUE = Wei.of(1000000000L);
public static final Wei BASEFEE_AT_GENESIS_DEFAULT_VALUE = Wei.of(1_000_000_000L);
private final ObjectNode configRoot;

private GenesisConfigFile(final ObjectNode config) {
Expand Down Expand Up @@ -139,12 +139,17 @@ public Optional<Wei> getBaseFeePerGas() {
}

public Optional<Wei> getGenesisBaseFeePerGas() {
// if we have a base fee market at genesis, get either the configured baseFeePerGas, or the
// default
return getBaseFeePerGas()
.map(Optional::of)
.orElseGet(() -> Optional.of(BASEFEE_AT_GENESIS_DEFAULT_VALUE))
.filter(z -> 0L == getConfigOptions().getLondonBlockNumber().orElse(-1L));
if (getBaseFeePerGas().isPresent()) {
// always use specified basefee if present
return getBaseFeePerGas();
} else if (getConfigOptions().getLondonBlockNumber().orElse(-1L) == 0) {
// if not specified, and we specify london at block zero use a default fee
// this is needed for testing.
return Optional.of(BASEFEE_AT_GENESIS_DEFAULT_VALUE);
} else {
// no explicit base fee and no london block zero means no basefee at genesis
return Optional.empty();
}
}

public String getMixHash() {
Expand All @@ -170,7 +175,7 @@ private String getRequiredString(final String key) {
private String getFirstRequiredString(final String... keys) {
List<String> keysList = Arrays.asList(keys);
return keysList.stream()
.filter(key -> configRoot.has(key))
.filter(configRoot::has)
.findFirst()
.map(key -> configRoot.get(key).asText())
.orElseThrow(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ default boolean isConsensusMigration() {

OptionalLong getMergeNetSplitBlockNumber();

OptionalLong getShandongBlockNumber();

Optional<Wei> getBaseFeePerGas();

Optional<UInt256> getTerminalTotalDifficulty();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
import java.util.stream.Collectors;
import java.util.stream.Stream;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.google.common.collect.ImmutableMap;
import org.apache.tuweni.units.bigints.UInt256;
Expand Down Expand Up @@ -60,17 +59,11 @@ public static JsonGenesisConfigOptions fromJsonObject(final ObjectNode configRoo
static JsonGenesisConfigOptions fromJsonObjectWithOverrides(
final ObjectNode configRoot, final Map<String, String> configOverrides) {
final TransitionsConfigOptions transitionsConfigOptions;
try {
transitionsConfigOptions = loadTransitionsFrom(configRoot);
} catch (final JsonProcessingException e) {
throw new RuntimeException("Transitions section of genesis file failed to decode.", e);
}
transitionsConfigOptions = loadTransitionsFrom(configRoot);
return new JsonGenesisConfigOptions(configRoot, configOverrides, transitionsConfigOptions);
}

private static TransitionsConfigOptions loadTransitionsFrom(final ObjectNode parentNode)
throws JsonProcessingException {

private static TransitionsConfigOptions loadTransitionsFrom(final ObjectNode parentNode) {
final Optional<ObjectNode> transitionsNode =
JsonUtil.getObjectNode(parentNode, TRANSITIONS_CONFIG_KEY);
if (transitionsNode.isEmpty()) {
Expand Down Expand Up @@ -285,6 +278,11 @@ public OptionalLong getMergeNetSplitBlockNumber() {
return getOptionalLong("mergenetsplitblock");
}

@Override
public OptionalLong getShandongBlockNumber() {
return getOptionalLong("shandongblock");
}

@Override
public Optional<Wei> getBaseFeePerGas() {
return Optional.ofNullable(configOverrides.get("baseFeePerGas"))
Expand Down Expand Up @@ -422,21 +420,9 @@ public Map<String, Object> asMap() {

// mainnet fork blocks
getHomesteadBlockNumber().ifPresent(l -> builder.put("homesteadBlock", l));
getDaoForkBlock()
.ifPresent(
l -> {
builder.put("daoForkBlock", l);
});
getTangerineWhistleBlockNumber()
.ifPresent(
l -> {
builder.put("eip150Block", l);
});
getSpuriousDragonBlockNumber()
.ifPresent(
l -> {
builder.put("eip158Block", l);
});
getDaoForkBlock().ifPresent(l -> builder.put("daoForkBlock", l));
getTangerineWhistleBlockNumber().ifPresent(l -> builder.put("eip150Block", l));
getSpuriousDragonBlockNumber().ifPresent(l -> builder.put("eip158Block", l));
getByzantiumBlockNumber().ifPresent(l -> builder.put("byzantiumBlock", l));
getConstantinopleBlockNumber().ifPresent(l -> builder.put("constantinopleBlock", l));
getPetersburgBlockNumber().ifPresent(l -> builder.put("petersburgBlock", l));
Expand All @@ -447,6 +433,7 @@ public Map<String, Object> asMap() {
getArrowGlacierBlockNumber().ifPresent(l -> builder.put("arrowGlacierBlock", l));
getGrayGlacierBlockNumber().ifPresent(l -> builder.put("grayGlacierBlock", l));
getMergeNetSplitBlockNumber().ifPresent(l -> builder.put("mergeNetSplitBlock", l));
getShandongBlockNumber().ifPresent(l -> builder.put("shandongBlock", l));
getTerminalBlockNumber().ifPresent(l -> builder.put("terminalBlockNumber", l));
getTerminalBlockHash().ifPresent(h -> builder.put("terminalBlockHash", h.toHexString()));

Expand Down Expand Up @@ -548,7 +535,7 @@ private Optional<Hash> getOptionalHash(final String key) {
final String overrideHash = configOverrides.get(key);
return Optional.of(Hash.fromHexString(overrideHash));
} else {
return JsonUtil.getValueAsString(configRoot, key).map(s -> Hash.fromHexString(s));
return JsonUtil.getValueAsString(configRoot, key).map(Hash::fromHexString);
}
}

Expand All @@ -570,6 +557,7 @@ public List<Long> getForks() {
getArrowGlacierBlockNumber(),
getGrayGlacierBlockNumber(),
getMergeNetSplitBlockNumber(),
getShandongBlockNumber(),
getEcip1015BlockNumber(),
getDieHardBlockNumber(),
getGothamBlockNumber(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public class StubGenesisConfigOptions implements GenesisConfigOptions {
private OptionalLong arrowGlacierBlockNumber = OptionalLong.empty();
private OptionalLong grayGlacierBlockNumber = OptionalLong.empty();
private OptionalLong mergeNetSplitBlockNumber = OptionalLong.empty();
private OptionalLong shandongBlockNumber = OptionalLong.empty();
private OptionalLong terminalBlockNumber = OptionalLong.empty();
private Optional<Hash> terminalBlockHash = Optional.empty();
private Optional<UInt256> terminalTotalDifficulty = Optional.empty();
Expand All @@ -69,7 +70,7 @@ public class StubGenesisConfigOptions implements GenesisConfigOptions {
private QbftConfigOptions qbftConfigOptions = JsonQbftConfigOptions.DEFAULT;
private BftConfigOptions bftConfigOptions = JsonBftConfigOptions.DEFAULT;
private TransitionsConfigOptions transitions = TransitionsConfigOptions.DEFAULT;
private final DiscoveryOptions discoveryOptions = DiscoveryOptions.DEFAULT;
private static final DiscoveryOptions DISCOVERY_OPTIONS = DiscoveryOptions.DEFAULT;

@Override
public String getConsensusEngine() {
Expand Down Expand Up @@ -133,7 +134,7 @@ public QbftConfigOptions getQbftConfigOptions() {

@Override
public DiscoveryOptions getDiscoveryOptions() {
return discoveryOptions;
return DISCOVERY_OPTIONS;
}

@Override
Expand Down Expand Up @@ -216,6 +217,11 @@ public OptionalLong getMergeNetSplitBlockNumber() {
return mergeNetSplitBlockNumber;
}

@Override
public OptionalLong getShandongBlockNumber() {
return shandongBlockNumber;
}

@Override
public Optional<Wei> getBaseFeePerGas() {
return baseFeePerGas;
Expand Down Expand Up @@ -319,21 +325,13 @@ public Optional<BigInteger> getChainId() {
@Override
public Map<String, Object> asMap() {
final ImmutableMap.Builder<String, Object> builder = ImmutableMap.builder();
getChainId().ifPresent(chainId -> builder.put("chainId", chainId));
getChainId().ifPresent(id -> builder.put("chainId", id));

// mainnet fork blocks
getHomesteadBlockNumber().ifPresent(l -> builder.put("homesteadBlock", l));
getDaoForkBlock()
.ifPresent(
l -> {
builder.put("daoForkBlock", l);
});
getDaoForkBlock().ifPresent(l -> builder.put("daoForkBlock", l));
getTangerineWhistleBlockNumber().ifPresent(l -> builder.put("eip150Block", l));
getSpuriousDragonBlockNumber()
.ifPresent(
l -> {
builder.put("eip158Block", l);
});
getSpuriousDragonBlockNumber().ifPresent(l -> builder.put("eip158Block", l));
getByzantiumBlockNumber().ifPresent(l -> builder.put("byzantiumBlock", l));
getConstantinopleBlockNumber().ifPresent(l -> builder.put("constantinopleBlock", l));
getPetersburgBlockNumber().ifPresent(l -> builder.put("petersburgBlock", l));
Expand All @@ -344,6 +342,7 @@ public Map<String, Object> asMap() {
getArrowGlacierBlockNumber().ifPresent(l -> builder.put("arrowGlacierBlock", l));
getGrayGlacierBlockNumber().ifPresent(l -> builder.put("grayGlacierBlock", l));
getMergeNetSplitBlockNumber().ifPresent(l -> builder.put("mergeNetSplitBlock", l));
getShandongBlockNumber().ifPresent(l -> builder.put("shandongBlock", l));
getTerminalBlockNumber().ifPresent(l -> builder.put("terminalBlockNumber", l));
getTerminalBlockHash().ifPresent(h -> builder.put("terminalBlockHash", h));
// classic fork blocks
Expand Down Expand Up @@ -487,6 +486,11 @@ public StubGenesisConfigOptions mergeNetSplitBlock(final long blockNumber) {
return this;
}

public StubGenesisConfigOptions shandongBlock(final long blockNumber) {
shandongBlockNumber = OptionalLong.of(blockNumber);
return this;
}

public StubGenesisConfigOptions terminalTotalDifficulty(
final UInt256 updatedTerminalTotalDifficulty) {
terminalTotalDifficulty = Optional.of(updatedTerminalTotalDifficulty);
Expand Down
Loading