Skip to content

Commit f65372b

Browse files
committed
Implement set_filter_head(link).
1 parent f526dcc commit f65372b

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed

include/bitcoin/database/impl/query/optional.ipp

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -198,13 +198,38 @@ bool CLASS::get_filter_head(hash_digest& out,
198198
return true;
199199
}
200200

201+
TEMPLATE
202+
bool CLASS::set_filter_head(const header_link& link) NOEXCEPT
203+
{
204+
if (!neutrino_enabled())
205+
return true;
206+
207+
// The filter body must have been previously stored under the block link.
208+
filter bytes{};
209+
if (!get_filter_body(bytes, link))
210+
return false;
211+
212+
// If genesis then previous is null_hash otherwise get by confirmed height.
213+
hash_digest previous{};
214+
const auto height = get_height(link);
215+
if (!is_zero(height))
216+
if (!get_filter_head(previous, to_confirmed(sub1(height))))
217+
return false;
218+
219+
// Use the previous head and current body to compute the current head.
220+
return set_filter_head(link,
221+
system::neutrino::compute_filter_header(previous, bytes));
222+
}
223+
201224
TEMPLATE
202225
bool CLASS::set_filter_body(const header_link& link,
203226
const block& block) NOEXCEPT
204227
{
205-
filter bytes{};
228+
if (!neutrino_enabled())
229+
return true;
206230

207-
// compute_filter is only false if prevouts are missing.
231+
// Compute the current filter from the block and store under the link.
232+
filter bytes{};
208233
return system::neutrino::compute_filter(bytes, block) &&
209234
set_filter_body(link, bytes);
210235
}

include/bitcoin/database/query.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -543,6 +543,7 @@ class query
543543
bool get_filter_head(hash_digest& out, const header_link& link) const NOEXCEPT;
544544
bool set_filter_body(const header_link& link, const block& block) NOEXCEPT;
545545
bool set_filter_body(const header_link& link, const filter& body) NOEXCEPT;
546+
bool set_filter_head(const header_link& link) NOEXCEPT;
546547
bool set_filter_head(const header_link& link,
547548
const hash_digest& head) NOEXCEPT;
548549

0 commit comments

Comments
 (0)