-
Notifications
You must be signed in to change notification settings - Fork 59
add silent payments prevout summaries table #804
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
base: master
Are you sure you want to change the base?
Changes from all commits
b51a2c9
50f998f
7b82ba1
55b595b
fcd10ab
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -117,7 +117,8 @@ header_links CLASS::get_confirmed_fork(const header_link& fork) const NOEXCEPT | |
| // node/confirmer | ||
| TEMPLATE | ||
| header_states CLASS::get_validated_fork(size_t& fork_point, | ||
| size_t top_checkpoint, bool filter) const NOEXCEPT | ||
| size_t top_checkpoint, bool filter, bool sp_prevout_summaries, | ||
| size_t sp_prevout_summaries_activation) const NOEXCEPT | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. IIUC these parameters are configuration, so shouldn't be passed here. This applies to |
||
| { | ||
| // Reservation may limit allocation to most common scenario. | ||
| header_states out{}; | ||
|
|
@@ -126,6 +127,7 @@ header_states CLASS::get_validated_fork(size_t& fork_point, | |
|
|
||
| // Disable filter constraint if filtering is disabled. | ||
| filter &= filter_enabled(); | ||
| sp_prevout_summaries &= sp_prevout_summaries_enabled(); | ||
|
|
||
| /////////////////////////////////////////////////////////////////////////// | ||
| std::shared_lock interlock{ candidate_reorganization_mutex_ }; | ||
|
|
@@ -134,7 +136,9 @@ header_states CLASS::get_validated_fork(size_t& fork_point, | |
| auto height = add1(fork_point); | ||
| auto link = to_candidate(height); | ||
| while (is_block_validated(ec, link, height, top_checkpoint) && | ||
| (!filter || is_filtered_body(link))) | ||
| (!filter || is_filtered_body(link)) && | ||
| (!sp_prevout_summaries || height < sp_prevout_summaries_activation || | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The link-based state of activation should be reduced to a config-driven method, similar to those for the other optional tables (address/filters).
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Related PRs: |
||
| is_sp_prevout_summaries_indexed(link))) | ||
| { | ||
| out.emplace_back(link, ec); | ||
| link = to_candidate(++height); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -69,12 +69,14 @@ TEMPLATE | |
| height_link CLASS::find_strong_spender_height( | ||
| const point& point) const NOEXCEPT | ||
| { | ||
| size_t out{}; | ||
| for (const auto& in: to_spenders(point)) | ||
| { | ||
| size_t out{}; | ||
| if (const auto tx = to_input_tx(in); get_tx_height(out, tx)) | ||
| break; | ||
| return { system::possible_narrow_cast<uint32_t>(out) }; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This (original code) cast is incorrect, should be: I've fixed this in an independent PR.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also, yes, needs default return for terminal value. Prefer to keep out declaration outside the loop to reduce the clutter.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Yes, please split out. |
||
| } | ||
|
|
||
| return { system::possible_narrow_cast<uint32_t>(out) }; | ||
| return {}; | ||
| } | ||
|
|
||
| // find_strong (block) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,187 @@ | ||
| /** | ||
| * Copyright (c) 2011-2026 libbitcoin developers (see AUTHORS) | ||
| * | ||
| * This file is part of libbitcoin. | ||
| * | ||
| * This program is free software: you can redistribute it and/or modify | ||
| * it under the terms of the GNU Affero General Public License as published by | ||
| * the Free Software Foundation, either version 3 of the License, or | ||
| * (at your option) any later version. | ||
| * | ||
| * This program is distributed in the hope that it will be useful, | ||
| * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| * GNU Affero General Public License for more details. | ||
| * | ||
| * You should have received a copy of the GNU Affero General Public License | ||
| * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
| */ | ||
| #ifndef LIBBITCOIN_DATABASE_QUERY_SP_PREVOUT_SUMMARIES_IPP | ||
| #define LIBBITCOIN_DATABASE_QUERY_SP_PREVOUT_SUMMARIES_IPP | ||
|
|
||
| #include <utility> | ||
| #include <bitcoin/database/define.hpp> | ||
| #include <bitcoin/system/chain/silent_payment.hpp> | ||
|
|
||
| namespace libbitcoin { | ||
| namespace database { | ||
|
|
||
| // sp_prevout_summaries | ||
| // ---------------------------------------------------------------------------- | ||
|
|
||
| TEMPLATE | ||
| bool CLASS::is_sp_prevout_summaries_indexed(const header_link& link) const | ||
| NOEXCEPT | ||
| { | ||
| const auto uncompressed = sp_prevout_summaries_uncompressed(); | ||
| table::sp_prevout_summaries::get_format summaries{ {}, uncompressed }; | ||
| return store_.sp_prevout_summaries.at(to_sp_prevout_summaries(link), | ||
| summaries); | ||
| } | ||
|
|
||
| TEMPLATE | ||
| bool CLASS::get_sp_prevout_summaries(sp_prevout_summaries& out, | ||
| const header_link& link) const NOEXCEPT | ||
| { | ||
| const auto uncompressed = sp_prevout_summaries_uncompressed(); | ||
| table::sp_prevout_summaries::get_summaries summaries{ {}, uncompressed }; | ||
| if (!store_.sp_prevout_summaries.at(to_sp_prevout_summaries(link), | ||
| summaries)) | ||
| return false; | ||
|
|
||
| out = std::move(summaries.summaries); | ||
| return true; | ||
| } | ||
|
|
||
| // node/validator | ||
| TEMPLATE | ||
| bool CLASS::set_sp_prevout_summaries(const header_link& link, | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we intend to support unconfirmed txs as well? Implies an tx override, similar to the block/tx writers. In that case the block writer just iterates over the tx writer. |
||
| const block& block) NOEXCEPT | ||
| { | ||
| using namespace system::chain; | ||
| if (!sp_prevout_summaries_enabled()) | ||
| return true; | ||
|
|
||
| const auto txs = to_transactions(link); | ||
| const auto& transactions = *block.transactions_ptr(); | ||
| if (txs.size() != transactions.size()) | ||
| return false; | ||
|
|
||
| database::sp_prevout_summaries summaries{}; | ||
| summaries.format = sp_prevout_summaries_uncompressed() ? | ||
| sp_prevout_summaries::uncompressed : sp_prevout_summaries::compressed; | ||
| summaries.records.reserve(transactions.size()); | ||
|
|
||
| for (size_t index{}; index < transactions.size(); ++index) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Generally we prefer to use iterator syntax here: This reduces the cognitive load for the reader, not having to associate the additional index var. |
||
| { | ||
| silent_payment::record record{}; | ||
| if (!silent_payment::compute_scan_record(record, *transactions[index])) | ||
| continue; | ||
|
|
||
| sp_prevout_summary entry | ||
| { | ||
| txs[index], | ||
| record.tweak_key, | ||
| {}, | ||
| std::move(record.outputs) | ||
| }; | ||
|
|
||
| if (summaries.format == sp_prevout_summaries::uncompressed && | ||
| !system::decompress(entry.tweak_point, entry.tweak_key)) | ||
| return false; | ||
|
|
||
| summaries.records.push_back(std::move(entry)); | ||
| } | ||
|
|
||
| return set_sp_prevout_summaries(link, summaries); | ||
| } | ||
|
|
||
| TEMPLATE | ||
| bool CLASS::set_sp_prevout_summaries(const header_link& link, | ||
| const sp_prevout_summaries& summaries) NOEXCEPT | ||
| { | ||
| if (!sp_prevout_summaries_enabled()) | ||
| return true; | ||
|
|
||
| const auto uncompressed = sp_prevout_summaries_uncompressed(); | ||
| if (uncompressed && summaries.format != sp_prevout_summaries::uncompressed) | ||
| { | ||
| auto copy = summaries; | ||
| copy.format = sp_prevout_summaries::uncompressed; | ||
| for (auto& record: copy.records) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ideally this should be implemented where the records are created, or by the caller, not in the table writer. The values should really just be stored everywhere as compressed. Def don't want to initially overallocate and then copy the full set. |
||
| if (!system::decompress(record.tweak_point, record.tweak_key)) | ||
| return false; | ||
|
|
||
| // ==================================================================== | ||
| const auto scope = store_.get_transactor(); | ||
|
|
||
| return store_.sp_prevout_summaries.put(to_sp_prevout_summaries(link), | ||
| table::sp_prevout_summaries::put_ref | ||
| { | ||
| {}, | ||
| true, | ||
| copy | ||
| }); | ||
| // ==================================================================== | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there a missing |
||
| } | ||
|
|
||
| // ======================================================================== | ||
| const auto scope = store_.get_transactor(); | ||
|
|
||
| // Clean single allocation failure (e.g. disk full). | ||
| return store_.sp_prevout_summaries.put(to_sp_prevout_summaries(link), | ||
| table::sp_prevout_summaries::put_ref | ||
| { | ||
| {}, | ||
| uncompressed, | ||
| summaries | ||
| }); | ||
| // ======================================================================== | ||
| } | ||
|
|
||
| TEMPLATE | ||
| bool CLASS::get_sp_prevout_summaries_tip(size_t& out) const NOEXCEPT | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Top, not tip. It's a stack, not a spear. ;). |
||
| { | ||
| const auto tip = sp_prevout_summaries_tip_.load(std::memory_order_relaxed); | ||
| if (tip == max_size_t) | ||
| return false; | ||
|
|
||
| out = tip; | ||
| return true; | ||
| } | ||
|
|
||
| TEMPLATE | ||
| void CLASS::set_sp_prevout_summaries_tip(size_t height) NOEXCEPT | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We don't do this even for the candidate and confirmed top heights. truth in once place. |
||
| { | ||
| sp_prevout_summaries_tip_.store(height, std::memory_order_relaxed); | ||
| } | ||
|
|
||
| TEMPLATE | ||
| size_t CLASS::recover_sp_prevout_summaries_tip(size_t activation) NOEXCEPT | ||
| { | ||
| const auto top = get_top_confirmed(); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Once the block is validated the entry exists. Once the block is confirmed, the full set of entries up to the confirmed top exist. |
||
| auto tip = max_size_t; | ||
|
|
||
| if (sp_prevout_summaries_enabled() && top >= activation) | ||
| { | ||
| for (auto height = activation; height <= top; ++height) | ||
| { | ||
| const auto link = to_confirmed(height); | ||
| if (link.is_terminal() || !is_sp_prevout_summaries_indexed(link)) | ||
| break; | ||
|
|
||
| tip = height; | ||
| } | ||
| } | ||
|
|
||
| if (tip == max_size_t && !is_zero(activation)) | ||
| tip = sub1(activation); | ||
|
|
||
| set_sp_prevout_summaries_tip(tip); | ||
| return tip; | ||
| } | ||
|
|
||
| } // namespace database | ||
| } // namespace libbitcoin | ||
|
|
||
| #endif | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Requires artifact regeneration.