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 mergeForkBlock #614

Merged
merged 10 commits into from
Mar 18, 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
4 changes: 4 additions & 0 deletions core/silkworm/chain/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ static const std::vector<std::pair<std::string, const ChainConfig*>> kKnownChain
constexpr const char* kTerminalTotalDifficulty{"terminalTotalDifficulty"};
constexpr const char* kTerminalBlockNumber{"terminalBlockNumber"};
constexpr const char* kTerminalBlockHash{"terminalBlockHash"};
constexpr const char* kMergeForkBlock{"mergeForkBlock"};

static inline void member_to_json(nlohmann::json& json, const std::string& key, const std::optional<uint64_t>& source) {
if (source.has_value()) {
Expand Down Expand Up @@ -74,6 +75,7 @@ nlohmann::json ChainConfig::to_json() const noexcept {
member_to_json(ret, "muirGlacierBlock", muir_glacier_block);
member_to_json(ret, "arrowGlacierBlock", arrow_glacier_block);
member_to_json(ret, kTerminalBlockNumber, terminal_block_number);
member_to_json(ret, kMergeForkBlock, merge_fork_block);

if (terminal_total_difficulty.has_value()) {
// TODO (Andrew) geth probably treats terminalTotalDifficulty as a JSON number
Expand Down Expand Up @@ -112,6 +114,8 @@ std::optional<ChainConfig> ChainConfig::from_json(const nlohmann::json& json) no
read_json_config_member(json, "muirGlacierBlock", config.muir_glacier_block);
read_json_config_member(json, "arrowGlacierBlock", config.arrow_glacier_block);
read_json_config_member(json, kTerminalBlockNumber, config.terminal_block_number);
read_json_config_member(json, kMergeForkBlock, config.merge_fork_block);

if (json.contains(kTerminalTotalDifficulty)) {
config.terminal_total_difficulty =
intx::from_string<intx::uint256>(json[kTerminalTotalDifficulty].get<std::string>());
Expand Down
1 change: 1 addition & 0 deletions core/silkworm/chain/config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ struct ChainConfig {
std::optional<intx::uint256> terminal_total_difficulty{std::nullopt};
std::optional<uint64_t> terminal_block_number{std::nullopt};
std::optional<evmc::bytes32> terminal_block_hash{std::nullopt};
std::optional<uint64_t> merge_fork_block{std::nullopt};
// Returns the revision level at given block number
// In other words, on behalf of Json chain config data
// returns whether specific HF have occurred
Expand Down
6 changes: 4 additions & 2 deletions core/silkworm/chain/config_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,9 @@ TEST_CASE("JSON serialization") {
"berlinBlock":0,
"londonBlock":0,
"terminalTotalDifficulty":"39387012740608862000000",
"terminalBlockNumber": 10000,
"terminalBlockHash": "0x6dc57fd586f41ee340124c3a005642af7731a9ca7a7b70d989a7e2833e4ab740"
"terminalBlockNumber":10000,
"terminalBlockHash":"0x6dc57fd586f41ee340124c3a005642af7731a9ca7a7b70d989a7e2833e4ab740",
"mergeForkBlock":10000
})");

const std::optional<ChainConfig> config2{ChainConfig::from_json(merge_test_json)};
Expand All @@ -158,6 +159,7 @@ TEST_CASE("JSON serialization") {
CHECK(config2->terminal_total_difficulty == intx::from_string<intx::uint256>("39387012740608862000000"));
CHECK(config2->terminal_block_number == 10000);
CHECK(config2->terminal_block_hash == 0x6dc57fd586f41ee340124c3a005642af7731a9ca7a7b70d989a7e2833e4ab740_bytes32);
CHECK(config2->merge_fork_block == 10000);

CHECK(config2->to_json() == merge_test_json);
}
Expand Down