Skip to content
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
16 changes: 10 additions & 6 deletions include/bitcoin/database/impl/query/signatures.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -26,25 +26,29 @@ namespace libbitcoin {
namespace database {

TEMPLATE
bool CLASS::verify_ecdsa_signatures(header_links& links) NOEXCEPT
bool CLASS::verify_ecdsa_signatures(const stopper& cancel,
header_links& links) NOEXCEPT
{
// False return only implies canceled.
using batch = system::ecdsa::batch;
const auto count = store_.ecdsa.count().value;
const auto ptr = store_.ecdsa.get_memory();
const auto rows = system::pointer_cast<const batch>(ptr->data());
links = batch::verify({ rows, count }, store_.turbo());
return true;
links = batch::verify(cancel, { rows, count });
return !cancel;
}

TEMPLATE
bool CLASS::verify_schnorr_signatures(header_links& links) NOEXCEPT
bool CLASS::verify_schnorr_signatures(const stopper& cancel,
header_links& links) NOEXCEPT
{
// False return only implies canceled.
using batch = system::schnorr::batch;
const auto count = store_.schnorr.count().value;
const auto ptr = store_.schnorr.get_memory();
const auto rows = system::pointer_cast<const batch>(ptr->data());
links = batch::verify({ rows, count }, store_.turbo());
return true;
links = batch::verify(cancel, { rows, count });
return !cancel;
}

// setters
Expand Down
4 changes: 2 additions & 2 deletions include/bitcoin/database/query.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -585,8 +585,8 @@ class query
/// Signature verification.
bool purge_ecdsa_signatures() NOEXCEPT;
bool purge_schnorr_signatures() NOEXCEPT;
bool verify_ecdsa_signatures(header_links&) NOEXCEPT;
bool verify_schnorr_signatures(header_links&) NOEXCEPT;
bool verify_ecdsa_signatures(const stopper& cancel,header_links&) NOEXCEPT;
bool verify_schnorr_signatures(const stopper& cancel, header_links&) NOEXCEPT;

/// Confirmation.
/// -----------------------------------------------------------------------
Expand Down
1 change: 0 additions & 1 deletion include/bitcoin/database/types/type.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ using index = table::transaction::ix::integer;
/// Common std aliases.
/// ---------------------------------------------------------------------------

using stopper = std::atomic_bool;
using hash_option = std::optional<hash_digest>;

/// Common system aliases.
Expand Down
16 changes: 8 additions & 8 deletions test/query/signatures.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ BOOST_AUTO_TEST_CASE(query__verify_ecdsa_signatures__empty__empty)

header_links links{};
BOOST_REQUIRE_EQUAL(query.ecdsa_records(), 0u);
BOOST_REQUIRE(query.verify_ecdsa_signatures(links));
BOOST_REQUIRE(query.verify_ecdsa_signatures({}, links));
BOOST_REQUIRE(links.empty());
}

Expand All @@ -58,7 +58,7 @@ BOOST_AUTO_TEST_CASE(query__verify_ecdsa_signatures__one_valid__empty)

header_links links{};
BOOST_REQUIRE_EQUAL(query.ecdsa_records(), 1u);
BOOST_REQUIRE(query.verify_ecdsa_signatures(links));
BOOST_REQUIRE(query.verify_ecdsa_signatures({}, links));
BOOST_REQUIRE(links.empty());
}

Expand All @@ -72,7 +72,7 @@ BOOST_AUTO_TEST_CASE(query__verify_ecdsa_signatures__one_invalid__expected_link)

header_links links{};
BOOST_REQUIRE_EQUAL(query.ecdsa_records(), 1u);
BOOST_REQUIRE(query.verify_ecdsa_signatures(links));
BOOST_REQUIRE(query.verify_ecdsa_signatures({}, links));
BOOST_REQUIRE_EQUAL(links.size(), 1u);
BOOST_REQUIRE_EQUAL(links.front(), expected);
}
Expand All @@ -95,7 +95,7 @@ BOOST_AUTO_TEST_CASE(query__verify_ecdsa_signatures__various__expected_links)

header_links links{};
BOOST_REQUIRE_EQUAL(query.ecdsa_records(), 8u);
BOOST_REQUIRE(query.verify_ecdsa_signatures(links));
BOOST_REQUIRE(query.verify_ecdsa_signatures({}, links));
BOOST_REQUIRE_EQUAL(links.size(), 2u);

// Order is not guaranteed.
Expand Down Expand Up @@ -123,7 +123,7 @@ BOOST_AUTO_TEST_CASE(query__verify_schnorr_signatures__empty__empty)

header_links links{};
BOOST_REQUIRE_EQUAL(query.schnorr_records(), 0u);
BOOST_REQUIRE(query.verify_schnorr_signatures(links));
BOOST_REQUIRE(query.verify_schnorr_signatures({}, links));
BOOST_REQUIRE(links.empty());
}

Expand All @@ -136,7 +136,7 @@ BOOST_AUTO_TEST_CASE(query__verify_schnorr_signatures__one_valid__empty)

header_links links{};
BOOST_REQUIRE_EQUAL(query.schnorr_records(), 1u);
BOOST_REQUIRE(query.verify_schnorr_signatures(links));
BOOST_REQUIRE(query.verify_schnorr_signatures({}, links));
BOOST_REQUIRE(links.empty());
}

Expand All @@ -150,7 +150,7 @@ BOOST_AUTO_TEST_CASE(query__verify_schnorr_signatures__one_invalid__expected_lin

header_links links{};
BOOST_REQUIRE_EQUAL(query.schnorr_records(), 1u);
BOOST_REQUIRE(query.verify_schnorr_signatures(links));
BOOST_REQUIRE(query.verify_schnorr_signatures({}, links));
BOOST_REQUIRE_EQUAL(links.size(), 1u);
BOOST_REQUIRE_EQUAL(links.front(), expected);
}
Expand All @@ -173,7 +173,7 @@ BOOST_AUTO_TEST_CASE(query__verify_schnorr_signatures__various__expected_links)

header_links links{};
BOOST_REQUIRE_EQUAL(query.schnorr_records(), 8u);
BOOST_REQUIRE(query.verify_schnorr_signatures(links));
BOOST_REQUIRE(query.verify_schnorr_signatures({}, links));
BOOST_REQUIRE_EQUAL(links.size(), 2u);

// Order is not guaranteed.
Expand Down
Loading