diff --git a/include/bitcoin/system/chain/checkpoint.hpp b/include/bitcoin/system/chain/checkpoint.hpp index 1befd7373c..ef8d4e5c18 100644 --- a/include/bitcoin/system/chain/checkpoint.hpp +++ b/include/bitcoin/system/chain/checkpoint.hpp @@ -103,8 +103,8 @@ bool operator==(const checkpoint& left, const checkpoint& right) NOEXCEPT; bool operator!=(const checkpoint& left, const checkpoint& right) NOEXCEPT; // TODO: rationalize with config. +std::istream& operator>>(std::istream& stream, checkpoint& out) THROWS; std::ostream& operator<<(std::ostream& stream, const checkpoint& in) NOEXCEPT; -std::istream& operator>>(std::istream& stream, checkpoint& out) NOEXCEPT; typedef std::vector checkpoints; diff --git a/include/bitcoin/system/error/block_error_t.hpp b/include/bitcoin/system/error/block_error_t.hpp index cb5ee603fc..59dd0607f8 100644 --- a/include/bitcoin/system/error/block_error_t.hpp +++ b/include/bitcoin/system/error/block_error_t.hpp @@ -40,7 +40,7 @@ enum block_error_t : uint8_t // TODO: order these. // accept header - checkpoints_failed, + checkpoint_conflict, invalid_block_version, timestamp_too_early, incorrect_proof_of_work, diff --git a/src/chain/block.cpp b/src/chain/block.cpp index d9a3a23da0..30ecda77bc 100644 --- a/src/chain/block.cpp +++ b/src/chain/block.cpp @@ -705,7 +705,7 @@ code block::check(const context& ctx) const NOEXCEPT return check_transactions(ctx); } -// These assume that prevout caching is completed on all inputs. +// This assumes that prevout caching is completed on all inputs. code block::accept(const context& ctx, size_t subsidy_interval, uint64_t initial_subsidy) const NOEXCEPT { @@ -722,7 +722,8 @@ code block::accept(const context& ctx, size_t subsidy_interval, return accept_transactions(ctx); } -// This assume that prevout and metadata caching are completed on all inputs. +// Node performs these checks through database query. +// This assumes that prevout and metadata caching are completed on all inputs. code block::confirm(const context& ctx) const NOEXCEPT { const auto bip30 = ctx.is_enabled(bip30_rule); diff --git a/src/chain/checkpoint.cpp b/src/chain/checkpoint.cpp index e9958dc0a3..f5c093b697 100644 --- a/src/chain/checkpoint.cpp +++ b/src/chain/checkpoint.cpp @@ -133,25 +133,24 @@ bool operator!=(const checkpoint& left, const checkpoint& right) NOEXCEPT // TODO: add from_string. // TODO: add get_line/put_line to reader and eliminate stream_result. -std::istream& operator>>(std::istream& stream, checkpoint& out) NOEXCEPT +std::istream& operator>>(std::istream& stream, checkpoint& out) THROWS { std::string value; stream >> value; hash_digest hash; size_t height(zero); - const auto tokens = split(value, ":"); - if (tokens.size() == two && - decode_hash(hash, tokens.front()) && - deserialize(height, tokens.back())) - { - out = { hash, height }; - return stream_result(stream, true); - } + // std::string avoids boolean override. + const auto tokens = split(value, std::string{ ":" }); + + if (tokens.size() != two || + !decode_hash(hash, tokens.front()) || + !deserialize(height, tokens.back())) + throw istream_exception(value); - out = {}; - return stream_result(stream, false); + out = { hash, height }; + return stream; } bool checkpoint::is_valid() const NOEXCEPT diff --git a/src/chain/transaction.cpp b/src/chain/transaction.cpp index 061030472a..820994d9c3 100644 --- a/src/chain/transaction.cpp +++ b/src/chain/transaction.cpp @@ -1267,7 +1267,7 @@ code transaction::check(const context& ctx) const NOEXCEPT } // Do NOT invoke on coinbase. -// These assume that prevout caching is completed on all inputs. +// This assumes that prevout caching is completed on all inputs. code transaction::accept(const context&) const NOEXCEPT { BC_ASSERT(!is_coinbase()); diff --git a/src/error/block_error_t.cpp b/src/error/block_error_t.cpp index 0a27da03fa..456ee9e6e5 100644 --- a/src/error/block_error_t.cpp +++ b/src/error/block_error_t.cpp @@ -34,7 +34,7 @@ DEFINE_ERROR_T_MESSAGE_MAP(block_error) { futuristic_timestamp, "timestamp too far in the future" }, // accept header - { checkpoints_failed, "block hash rejected by checkpoint" }, + { checkpoint_conflict, "block hash rejected by checkpoint" }, { invalid_block_version, "block version rejected at current height" }, { timestamp_too_early, "block timestamp is too early" }, { incorrect_proof_of_work, "proof of work does not match bits field" }, diff --git a/test/error/block_error_t.cpp b/test/error/block_error_t.cpp index b2c8da5714..e6f9fffb8f 100644 --- a/test/error/block_error_t.cpp +++ b/test/error/block_error_t.cpp @@ -53,9 +53,9 @@ BOOST_AUTO_TEST_CASE(block_error_t__code__futuristic_timestamp__true_exected_mes // accept header -BOOST_AUTO_TEST_CASE(block_error_t__code__checkpoints_failed__true_exected_message) +BOOST_AUTO_TEST_CASE(block_error_t__code__checkpoint_conflict__true_exected_message) { - constexpr auto value = error::checkpoints_failed; + constexpr auto value = error::checkpoint_conflict; const auto ec = code(value); BOOST_REQUIRE(ec); BOOST_REQUIRE(ec == value);