Skip to content

Commit

Permalink
Add settings minimum_work and milestone, add uint256_t() to base16_hash.
Browse files Browse the repository at this point in the history
  • Loading branch information
evoskuil committed Feb 27, 2024
1 parent c7fb36a commit 2399024
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 0 deletions.
1 change: 1 addition & 0 deletions include/bitcoin/system/config/hash256.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ class BC_API hash256 final
std::string to_string() const NOEXCEPT;

operator const hash_digest&() const NOEXCEPT;
operator uint256_t() const NOEXCEPT;

friend std::istream& operator>>(std::istream& stream,
hash256& argument) THROWS;
Expand Down
6 changes: 6 additions & 0 deletions include/bitcoin/system/settings.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,12 @@ class BC_API settings

/// This cannot be reactivated in a future branch due to window expiration.
chain::checkpoint bip9_bit1_active_checkpoint{};

/// A block that is presumed to be valid but not required to be present.
chain::checkpoint milestone{};

/// The minimum work for any branch to be considered valid.
config::hash256 minimum_work{};
};

} // namespace system
Expand Down
5 changes: 5 additions & 0 deletions src/config/hash256.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,11 @@ hash256::operator const hash_digest&() const NOEXCEPT
return value_;
}

hash256::operator uint256_t() const NOEXCEPT
{
return to_uintx(value_);
}

std::istream& operator>>(std::istream& stream, hash256& argument) THROWS
{
std::string base16;
Expand Down
6 changes: 6 additions & 0 deletions src/settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,8 @@ settings::settings(chain::selection context) NOEXCEPT
{ "000000002dd5588a74784eaa7ab0507a18ad16a236e7b1ce69f00d7ddfb5d0a6", 33333 },
{ "0000000069e244f73d78e8fd29ba2fd2ed618bd6fa2ee92559f542fdb26e7c1d", 11111 }
};
milestone = { "00000000000000000001a0a448d6cf2546b06801389cc030b2b18c6491266815", 804000 };
minimum_work = base16_hash("000000000000000000000000000000000000000052b2559353df4117b7348b64");
break;
}

Expand Down Expand Up @@ -195,6 +197,8 @@ settings::settings(chain::selection context) NOEXCEPT
{
{ "000000002a936ca763904c3c35fce2f3556c559c0214345d31b1bcebf76acb70", 546 }
};
milestone = { "0000000000000093bcb68c03a9a168ae252572d348a2eaeba2cdf9231d73206f", 2500000 };
minimum_work = base16_hash("000000000000000000000000000000000000000000000b6a51f415a67c0da307");
break;
}

Expand Down Expand Up @@ -252,6 +256,8 @@ settings::settings(chain::selection context) NOEXCEPT
bip9_bit0_active_checkpoint = { "0f9188f13cb7b2c71f2a335e3a4fc328bf5beb436012afca590b1a11466e2206", 0 };
bip9_bit1_active_checkpoint = { "0f9188f13cb7b2c71f2a335e3a4fc328bf5beb436012afca590b1a11466e2206", 0 };
checkpoints = {};
milestone = { "0f9188f13cb7b2c71f2a335e3a4fc328bf5beb436012afca590b1a11466e2206", 0 };
minimum_work = base16_hash("0000000000000000000000000000000000000000000000000000000000000000");
break;
}

Expand Down
8 changes: 8 additions & 0 deletions test/settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,9 @@ BOOST_AUTO_TEST_CASE(settings__construct__mainnet_context__expected)
BOOST_REQUIRE_EQUAL(configuration.bitcoin_to_satoshi(1), 100000000u);
BOOST_REQUIRE_EQUAL(configuration.max_money(), 2099999997690000u);
BOOST_REQUIRE_EQUAL(configuration.checkpoints, checkpoints);
BOOST_REQUIRE_EQUAL(configuration.minimum_work, to_uintx(base16_hash("000000000000000000000000000000000000000052b2559353df4117b7348b64")));
const chain::checkpoint milestone("00000000000000000001a0a448d6cf2546b06801389cc030b2b18c6491266815", 804000u);
BOOST_REQUIRE_EQUAL(configuration.milestone, milestone);
}

BOOST_AUTO_TEST_CASE(settings__construct__testnet_context__expected)
Expand Down Expand Up @@ -138,6 +141,9 @@ BOOST_AUTO_TEST_CASE(settings__construct__testnet_context__expected)
BOOST_REQUIRE_EQUAL(configuration.bitcoin_to_satoshi(1), 100000000u);
BOOST_REQUIRE_EQUAL(configuration.max_money(), 2099999997690000u);
BOOST_REQUIRE_EQUAL(configuration.checkpoints, checkpoints);
BOOST_REQUIRE_EQUAL(configuration.minimum_work, to_uintx(base16_hash("000000000000000000000000000000000000000000000b6a51f415a67c0da307")));
const chain::checkpoint milestone("0000000000000093bcb68c03a9a168ae252572d348a2eaeba2cdf9231d73206f", 2500000u);
BOOST_REQUIRE_EQUAL(configuration.milestone, milestone);
}

BOOST_AUTO_TEST_CASE(settings__construct__regtest_context__expected)
Expand Down Expand Up @@ -171,6 +177,8 @@ BOOST_AUTO_TEST_CASE(settings__construct__regtest_context__expected)
BOOST_REQUIRE_EQUAL(configuration.bitcoin_to_satoshi(1), 100000000u);
BOOST_REQUIRE_EQUAL(configuration.max_money(), 1499999998350u);
BOOST_REQUIRE(configuration.checkpoints.empty());
BOOST_REQUIRE_EQUAL(configuration.minimum_work, to_uintx(base16_hash("0000000000000000000000000000000000000000000000000000000000000000")));
BOOST_REQUIRE_EQUAL(configuration.milestone, genesis);
}

// setter methods
Expand Down

0 comments on commit 2399024

Please sign in to comment.