Skip to content

Commit

Permalink
Merge pull request libbitcoin#1409 from evoskuil/master
Browse files Browse the repository at this point in the history
Fix checkpoint parse, comments.
  • Loading branch information
evoskuil authored Feb 24, 2024
2 parents 7e7d910 + 79a139d commit e829651
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 19 deletions.
2 changes: 1 addition & 1 deletion include/bitcoin/system/chain/checkpoint.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<checkpoint> checkpoints;

Expand Down
2 changes: 1 addition & 1 deletion include/bitcoin/system/error/block_error_t.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
5 changes: 3 additions & 2 deletions src/chain/block.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -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);
Expand Down
21 changes: 10 additions & 11 deletions src/chain/checkpoint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/chain/transaction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
2 changes: 1 addition & 1 deletion src/error/block_error_t.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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" },
Expand Down
4 changes: 2 additions & 2 deletions test/error/block_error_t.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit e829651

Please sign in to comment.