Skip to content

build silent payment index during validation#1027

Open
josibake wants to merge 1 commit into
libbitcoin:masterfrom
josibake:build-silent-payment-index
Open

build silent payment index during validation#1027
josibake wants to merge 1 commit into
libbitcoin:masterfrom
josibake:build-silent-payment-index

Conversation

@josibake
Copy link
Copy Markdown
Contributor

@josibake josibake commented Jun 3, 2026

Adds in the silent payments index. Tried to model this off the filter index, as closely as possible.

Depends on:

build the optional silent payment index from the validation workflow
using the existing validation threadpool and optional-index pattern.

blocks at or above silent_start_height are populated with prevouts
even when validation is bypassed, then set_silent() is called before
valid state advances.

confirmation emits silent_indexed only after the configured row exists.
Comment thread data/bn.cfg
# The minimum allocation of the silent table body, defaults to '1'.
silent_size = <value>
# The first height indexed by the silent table, defaults to the bip341 activation height.
silent_start_height = <value>
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This belongs somewhere else, application logic. Since it's node-written prob just node. Also we use the term threshold for a minimum in a few places.

[node]
# The minimum height indexed for silent payments, defaults to the bip341 activation height.
silent_index_threshold = 42

Though we should consider relationship to address indexing. We don't currently provide a threshold for that. Since that's written directly off of tx archive, it would require store config. That might drive this back into store config as well.

Don't forget to add to server parse once merged here.

LOGV("Block organized: " << confirmed_height);

if (silent)
notify(error::success, chase::silent_indexed, link);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would drop this chaser event. The same can be accomplished by subscribing to block/tx and filtering on feature enabled, which cuts event traffic in half. This is the approach with address and filter as well, so the event count could start becoming a performance and complexity issue at some point.

filter_(!defer_ && node.archive().filter_enabled())
filter_(!defer_ && node.archive().filter_enabled()),
silent_(!defer_ && node.network_settings().witness_node() &&
node.node_settings().headers_first &&
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why headers first?

node_witness_(node.network_settings().witness_node()),
defer_(node.node_settings().defer_validation),
filter_(!defer_ && node.archive().filter_enabled())
filter_(!defer_ && node.archive().filter_enabled()),
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that defer_ is an diagnostic tool.

silent_(!defer_ && node.network_settings().witness_node() &&
node.node_settings().headers_first &&
node.system_settings().forks.bip341 &&
node.archive().silent_enabled())
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's a lot going on here. Prob best to just set this to node.archive().silent_enabled()) and deal with the rest further down.


const auto bypass = defer_ || is_under_checkpoint(height) ||
query.is_milestone(link);
const auto silent = silent_ && height >= query.silent_start_height();
Copy link
Copy Markdown
Member

@evoskuil evoskuil Jun 3, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should make this a (efficient) query, similar to is_milestone(link). It can determine from the store if taproot is active at the block (from ctx.flags), if silent is active (based on the link's height, assuming store config), and if block is a witnessed block (from block sizes). Also should be moved into the case where it's used, since it won't be universal and has a cost.

return error::validate7;

// Valid must be set after set_prevouts and set_filter_body.
if (silent_ && !query.set_silent(link, block))
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can avoid the silent_ condition and just call the query, same as filter. The query can internally determine relevance using the same (efficient) checks noted above. Getting header metadata is almost as cheap as reading a local var. The heights are the most expensive, because that's a txs hashmap search, but still cheap.

Comment thread src/configuration.cpp
network(context),
node(context)
{
database.silent_start_height = bitcoin.bip9_bit2_active_checkpoint.height();
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This belongs in the settings class that defines the property. The choice of value can be determined explicitly from the chain selection context above in that case, or any other value, such as the height at which the feature became usable or BIPped.

{
complete_block(error::success, link, height, true);
if (silent && !query.is_silent_indexed(link))
post_block(link, true);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be removed. The valid (or valid and confirmable) state implies this has already been done.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants