Skip to content

Commit a707743

Browse files
committed
build silent payment index during validation
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.
1 parent e402d72 commit a707743

10 files changed

Lines changed: 50 additions & 7 deletions

File tree

data/bn.cfg

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,14 @@ filter_tx_buckets = <value>
7373
filter_tx_rate = <value>
7474
# The minimum allocation of the filter_tx table body, defaults to '1'.
7575
filter_tx_size = <value>
76+
# The number of buckets in the silent table head, defaults to '0' (0 disables).
77+
silent_buckets = <value>
78+
# The percentage expansion of the silent table body, defaults to '5'.
79+
silent_rate = <value>
80+
# The minimum allocation of the silent table body, defaults to '1'.
81+
silent_size = <value>
82+
# The first height indexed by the silent table, defaults to the bip341 activation height.
83+
silent_start_height = <value>
7684
# The number of buckets in the header table head, defaults to '386364'.
7785
header_buckets = <value>
7886
# The percentage expansion of the header table body, defaults to '5'.

include/bitcoin/node/chase.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,10 @@ enum class chase
145145
/// Issued by 'confirm' and handled by 'transaction'.
146146
reorganized,
147147

148+
/// Silent payment prevout summaries indexed for confirmed block (header_t).
149+
/// Issued by 'confirm' and handled by protocol subscribers.
150+
silent_indexed,
151+
148152
/// Mining.
149153
/// -----------------------------------------------------------------------
150154

include/bitcoin/node/chasers/chaser_validate.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ class BCN_API chaser_validate
9090
const bool node_witness_;
9191
const bool defer_;
9292
const bool filter_;
93+
const bool silent_;
9394
};
9495

9596
} // namespace node

include/bitcoin/node/error.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ enum error_t : uint8_t
9191
validate6,
9292
validate7,
9393
validate8,
94+
validate9,
9495
confirm1,
9596
confirm2,
9697
confirm3,

src/chasers/chaser_confirm.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -388,6 +388,11 @@ bool chaser_confirm::set_organized(const header_link& link,
388388
}
389389
#endif // !NDEBUG
390390

391+
const auto silent = query.silent_enabled() &&
392+
confirmed_height >= query.silent_start_height();
393+
if (silent && !query.is_silent_indexed(link))
394+
return false;
395+
391396
// Checkpointed blocks are set strong by archiver.
392397
if (!query.push_confirmed(link, !is_under_checkpoint(confirmed_height)))
393398
return false;
@@ -396,6 +401,9 @@ bool chaser_confirm::set_organized(const header_link& link,
396401
fire(events::block_organized, confirmed_height);
397402
LOGV("Block organized: " << confirmed_height);
398403

404+
if (silent)
405+
notify(error::success, chase::silent_indexed, link);
406+
399407
announce(link, confirmed_height);
400408
return true;
401409
}

src/chasers/chaser_validate.cpp

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,11 @@ chaser_validate::chaser_validate(full_node& node) NOEXCEPT
4545
maximum_backlog_(node.node_settings().maximum_concurrency_()),
4646
node_witness_(node.network_settings().witness_node()),
4747
defer_(node.node_settings().defer_validation),
48-
filter_(!defer_ && node.archive().filter_enabled())
48+
filter_(!defer_ && node.archive().filter_enabled()),
49+
silent_(!defer_ && node.network_settings().witness_node() &&
50+
node.node_settings().headers_first &&
51+
node.system_settings().forks.bip341 &&
52+
node.archive().silent_enabled())
4953
{
5054
}
5155

@@ -160,13 +164,14 @@ void chaser_validate::do_bumped(height_t height) NOEXCEPT
160164

161165
const auto bypass = defer_ || is_under_checkpoint(height) ||
162166
query.is_milestone(link);
167+
const auto silent = silent_ && height >= query.silent_start_height();
163168

164169
switch (ec.value())
165170
{
166171
case database::error::unvalidated:
167172
case database::error::unknown_state:
168173
{
169-
if (!bypass || filter_)
174+
if (!bypass || filter_ || silent)
170175
post_block(link, bypass);
171176
else
172177
complete_block(error::success, link, height, true);
@@ -175,7 +180,11 @@ void chaser_validate::do_bumped(height_t height) NOEXCEPT
175180
case database::error::block_valid:
176181
case database::error::block_confirmable:
177182
{
178-
complete_block(error::success, link, height, true);
183+
if (silent && !query.is_silent_indexed(link))
184+
post_block(link, true);
185+
else
186+
complete_block(error::success, link, height, true);
187+
179188
break;
180189
}
181190
case database::error::block_unconfirmable:
@@ -254,7 +263,7 @@ code chaser_validate::populate(bool bypass, const chain::block& block,
254263

255264
if (bypass)
256265
{
257-
// Populating for filters only (no validation metadata required).
266+
// Populating optional indexes only (no validation metadata required).
258267
block.populate(ctx);
259268
if (!query.populate_without_metadata(block))
260269
return system::error::missing_previous_output;
@@ -306,7 +315,10 @@ code chaser_validate::validate(bool bypass, const chain::block& block,
306315
if (!query.set_filter_body(link, block))
307316
return error::validate7;
308317

309-
// Valid must be set after set_prevouts and set_filter_body.
318+
if (silent_ && !query.set_silent(link, block))
319+
return error::validate9;
320+
321+
// Valid must be set after optional block indexes.
310322
if (!bypass && !query.set_block_valid(link))
311323
return error::validate8;
312324

@@ -334,7 +346,6 @@ void chaser_validate::complete_block(const code& ec, const header_link& link,
334346
return;
335347
}
336348

337-
// VALID BLOCK
338349
// Under deferral there is no state change, but downloads will stall unless
339350
// the window is closed out, so notify the check chaser of the increment.
340351
notify(ec, chase::valid, possible_wide_cast<height_t>(height));

src/configuration.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ configuration::configuration(system::chain::selection context) NOEXCEPT
3131
network(context),
3232
node(context)
3333
{
34+
database.silent_start_height = bitcoin.bip9_bit2_active_checkpoint.height();
3435
}
3536

3637
} // namespace node

src/error.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ DEFINE_ERROR_T_MESSAGE_MAP(error)
8181
{ validate6, "validate6" },
8282
{ validate7, "validate7" },
8383
{ validate8, "validate8" },
84+
{ validate9, "validate9" },
8485
{ confirm1, "confirm1" },
8586
{ confirm2, "confirm2" },
8687
{ confirm3, "confirm3" },

test/configuration.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,12 @@ BOOST_AUTO_TEST_CASE(configuration__construct1__none_context__expected)
3333
BOOST_REQUIRE_EQUAL(instance.bitcoin.first_version, 1_u32);
3434
}
3535

36+
BOOST_AUTO_TEST_CASE(configuration__construct1__mainnet_silent_start__expected)
37+
{
38+
const node::configuration instance(chain::selection::mainnet);
39+
const auto height = instance.bitcoin.bip9_bit2_active_checkpoint.height();
40+
41+
BOOST_REQUIRE_EQUAL(instance.database.silent_start_height, height);
42+
}
43+
3644
BOOST_AUTO_TEST_SUITE_END()

test/error.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ BOOST_AUTO_TEST_CASE(error_t__code__organize1__true_expected_message)
232232
BOOST_REQUIRE_EQUAL(ec.message(), "organize1");
233233
}
234234

235-
// TODO: validate2-validate6
235+
// TODO: validate2-validate9
236236
BOOST_AUTO_TEST_CASE(error_t__code__validate1__true_expected_message)
237237
{
238238
constexpr auto value = error::validate1;

0 commit comments

Comments
 (0)