Skip to content

Commit

Permalink
core: add Holesky config (#1796)
Browse files Browse the repository at this point in the history
  • Loading branch information
yperbasis committed Feb 5, 2024
1 parent 60f421a commit 4fb3872
Show file tree
Hide file tree
Showing 14 changed files with 3,619 additions and 29 deletions.
28 changes: 25 additions & 3 deletions silkworm/core/chain/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ nlohmann::json ChainConfig::to_json() const noexcept {
nlohmann::json empty_object(nlohmann::json::value_t::object);
std::visit(
Overloaded{
[&](const protocol::EthashConfig& x) { if (x.validate_seal) ret.emplace("ethash", empty_object); },
[&](const protocol::NoPreMergeConfig&) {},
[&](const protocol::EthashConfig& x) { ret.emplace("ethash", x.to_json()); },
[&](const protocol::CliqueConfig&) { ret.emplace("clique", empty_object); },
[&](const protocol::BorConfig& x) { ret.emplace("bor", x.to_json()); },
},
Expand Down Expand Up @@ -104,7 +105,11 @@ std::optional<ChainConfig> ChainConfig::from_json(const nlohmann::json& json) no
config.chain_id = json["chainId"].get<uint64_t>();

if (json.contains("ethash")) {
config.rule_set_config = protocol::EthashConfig{};
std::optional<protocol::EthashConfig> ethash_config{protocol::EthashConfig::from_json(json["ethash"])};
if (!ethash_config) {
return std::nullopt;
}
config.rule_set_config = *ethash_config;
} else if (json.contains("clique")) {
config.rule_set_config = protocol::CliqueConfig{};
} else if (json.contains("bor")) {
Expand All @@ -114,7 +119,7 @@ std::optional<ChainConfig> ChainConfig::from_json(const nlohmann::json& json) no
}
config.rule_set_config = *bor_config;
} else {
config.rule_set_config = protocol::EthashConfig{.validate_seal = false};
config.rule_set_config = protocol::NoPreMergeConfig{};
}

read_json_config_member(json, "homesteadBlock", config.homestead_block);
Expand Down Expand Up @@ -279,6 +284,23 @@ SILKWORM_CONSTINIT const ChainConfig kGoerliConfig{
.rule_set_config = protocol::CliqueConfig{},
};

SILKWORM_CONSTINIT const ChainConfig kHoleskyConfig{
.chain_id = 17000,
.homestead_block = 0,
.tangerine_whistle_block = 0,
.spurious_dragon_block = 0,
.byzantium_block = 0,
.constantinople_block = 0,
.petersburg_block = 0,
.istanbul_block = 0,
.berlin_block = 0,
.london_block = 0,
.terminal_total_difficulty = 0,
.shanghai_time = 1696000704,
.cancun_time = 1707305664,
.rule_set_config = protocol::NoPreMergeConfig{},
};

SILKWORM_CONSTINIT const ChainConfig kSepoliaConfig{
.chain_id = 11155111,
.homestead_block = 0,
Expand Down
18 changes: 11 additions & 7 deletions silkworm/core/chain/config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,15 @@
#include <silkworm/core/common/small_map.hpp>
#include <silkworm/core/common/util.hpp>
#include <silkworm/core/protocol/bor_config.hpp>
#include <silkworm/core/protocol/ethash_config.hpp>

namespace silkworm {

namespace protocol {

//! \see EthashRuleSet
struct EthashConfig {
bool validate_seal{true};

bool operator==(const EthashConfig&) const = default;
// Already merged at genesis
struct NoPreMergeConfig {
bool operator==(const NoPreMergeConfig&) const = default;
};

//! \see CliqueRuleSet
Expand All @@ -50,7 +49,7 @@ namespace protocol {
};

//! \see IRuleSet
using RuleSetConfig = std::variant<EthashConfig, CliqueConfig, BorConfig>;
using PreMergeRuleSetConfig = std::variant<NoPreMergeConfig, EthashConfig, CliqueConfig, BorConfig>;

} // namespace protocol

Expand Down Expand Up @@ -93,7 +92,7 @@ struct ChainConfig {
std::optional<BlockTime> cancun_time{std::nullopt};

//! \brief Returns the config of the (pre-Merge) protocol rule set
protocol::RuleSetConfig rule_set_config{protocol::EthashConfig{.validate_seal = false}};
protocol::PreMergeRuleSetConfig rule_set_config{protocol::NoPreMergeConfig{}};

// The Shanghai hard fork has withdrawals, but Agra does not
[[nodiscard]] bool withdrawals_activated(uint64_t block_time) const noexcept;
Expand Down Expand Up @@ -142,6 +141,9 @@ SILKWORM_CONSTINIT extern const ChainConfig kMainnetConfig;
inline constexpr evmc::bytes32 kGoerliGenesisHash{0xbf7e331f7f7c1dd2e05159666b3bf8bc7a8a3a9eb1d518969eab529dd9b88c1a_bytes32};
SILKWORM_CONSTINIT extern const ChainConfig kGoerliConfig;

inline constexpr evmc::bytes32 kHoleskyGenesisHash{0xb5f7f912443c940f21fd611f12828d75b534364ed9e95ca4e307729a4661bde4_bytes32};
SILKWORM_CONSTINIT extern const ChainConfig kHoleskyConfig;

inline constexpr evmc::bytes32 kSepoliaGenesisHash{0x25a5cc106eea7138acab33231d7160d69cb777ee0c2c553fcddf5138993e6dd9_bytes32};
SILKWORM_CONSTINIT extern const ChainConfig kSepoliaConfig;

Expand All @@ -155,6 +157,7 @@ SILKWORM_CONSTINIT extern const ChainConfig kMumbaiConfig;
inline constexpr SmallMap<std::string_view, ChainId> kKnownChainNameToId{
{"mainnet"sv, 1},
{"goerli"sv, 5},
{"holesky"sv, 17000},
{"sepolia"sv, 11155111},
{"polygon"sv, 137},
{"mumbai"sv, 80001},
Expand All @@ -164,6 +167,7 @@ inline constexpr SmallMap<std::string_view, ChainId> kKnownChainNameToId{
inline constexpr SmallMap<ChainId, const ChainConfig*> kKnownChainConfigs{
{*kKnownChainNameToId.find("mainnet"sv), &kMainnetConfig},
{*kKnownChainNameToId.find("goerli"sv), &kGoerliConfig},
{*kKnownChainNameToId.find("holesky"sv), &kHoleskyConfig},
{*kKnownChainNameToId.find("sepolia"sv), &kSepoliaConfig},
{*kKnownChainNameToId.find("polygon"sv), &kPolygonConfig},
{*kKnownChainNameToId.find("mumbai"sv), &kMumbaiConfig},
Expand Down
3 changes: 3 additions & 0 deletions silkworm/core/chain/genesis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

#include <silkworm/core/chain/config.hpp>
#include <silkworm/core/chain/genesis_goerli.hpp>
#include <silkworm/core/chain/genesis_holesky.hpp>
#include <silkworm/core/chain/genesis_mainnet.hpp>
#include <silkworm/core/chain/genesis_mumbai.hpp>
#include <silkworm/core/chain/genesis_polygon.hpp>
Expand All @@ -39,6 +40,8 @@ std::string_view read_genesis_data(ChainId chain_id) {
return genesis_mainnet_json;
case *kKnownChainNameToId.find("goerli"sv):
return genesis_goerli_json;
case *kKnownChainNameToId.find("holesky"sv):
return genesis_holesky_json;
case *kKnownChainNameToId.find("sepolia"sv):
return genesis_sepolia_json;
case *kKnownChainNameToId.find("polygon"sv):
Expand Down
Loading

0 comments on commit 4fb3872

Please sign in to comment.