Skip to content

Commit 31b10ba

Browse files
authored
Merge pull request #1028 from evoskuil/master
Stub in batched signatures, style.
2 parents 074d4ba + 324821c commit 31b10ba

7 files changed

Lines changed: 64 additions & 16 deletions

File tree

include/bitcoin/node/chasers/chaser_validate.hpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,11 +82,18 @@ class BCN_API chaser_validate
8282
network::threadpool validation_threadpool_;
8383

8484
// These are thread safe.
85+
std::atomic<size_t> batched_ecdsa_{};
86+
std::atomic<size_t> unbatched_ecdsa_{};
87+
std::atomic<size_t> batched_schnorr_{};
88+
std::atomic<size_t> unbatched_schnorr_{};
89+
std::atomic<size_t> batched_multisig_{};
90+
std::atomic<size_t> unbatched_multisig_{};
8591
std::atomic<size_t> backlog_{};
8692
network::asio::strand validation_strand_;
8793
const uint32_t subsidy_interval_;
8894
const uint64_t initial_subsidy_;
8995
const size_t maximum_backlog_;
96+
const bool batch_signatures_;
9097
const bool node_witness_;
9198
const bool defer_;
9299
const bool filter_;

include/bitcoin/node/estimator.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ class BCN_API estimator
3737
public:
3838
typedef std::unique_ptr<estimator> ptr;
3939
static constexpr size_t maximum_horizon = 1008;
40+
static constexpr size_t estimate_failed = max_uint64;
4041

4142
DELETE_COPY_MOVE_DESTRUCT(estimator);
4243

include/bitcoin/node/settings.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ class BCN_API settings
3939
bool thread_priority;
4040
bool memory_priority;
4141
bool allow_overlapped;
42+
bool batch_signatures;
4243
bool defer_validation;
4344
bool defer_confirmation;
4445
float allowed_deviation;

src/chasers/chaser_validate.cpp

Lines changed: 46 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ chaser_validate::chaser_validate(full_node& node) NOEXCEPT
4343
subsidy_interval_(node.system_settings().subsidy_interval_blocks),
4444
initial_subsidy_(node.system_settings().initial_subsidy()),
4545
maximum_backlog_(node.node_settings().maximum_concurrency_()),
46+
batch_signatures_(node.node_settings().batch_signatures),
4647
node_witness_(node.network_settings().witness_node()),
4748
defer_(node.node_settings().defer_validation),
4849
filter_(!defer_ && node.archive().filter_enabled())
@@ -295,8 +296,51 @@ code chaser_validate::validate(bool bypass, const chain::block& block,
295296
if ((ec = block.accept(ctx, subsidy_interval_, initial_subsidy_)))
296297
return ec;
297298

298-
if ((ec = block.connect(ctx)))
299-
return ec;
299+
if (batch_signatures_)
300+
{
301+
const chain::signatures capture
302+
{
303+
.ecdsa = [&](const hash_digest& ,
304+
const ec_compressed& , const ec_signature& ) NOEXCEPT
305+
{
306+
////query.set_signature(digest, point, sign, link);
307+
},
308+
309+
.schnorr = [&](const hash_digest& ,
310+
const ec_xonly& , const ec_signature& ) NOEXCEPT
311+
{
312+
////query.set_signature(digest, point, sign, link);
313+
},
314+
315+
.enabled = batch_signatures_
316+
};
317+
318+
if ((ec = block.connect(ctx, capture)))
319+
return ec;
320+
321+
batched_ecdsa_ += capture.batched_ecdsa;
322+
unbatched_ecdsa_ += capture.unbatched_ecdsa;
323+
batched_schnorr_ += capture.batched_schnorr;
324+
unbatched_schnorr_ += capture.unbatched_schnorr;
325+
batched_multisig_ += capture.batched_multisig;
326+
unbatched_multisig_ += capture.unbatched_multisig;
327+
{
328+
LOGV("Bypass ecdsa " << batched_ecdsa_ << " / (" << batched_ecdsa_ << " + " << unbatched_ecdsa_ << ")");
329+
}
330+
if (to_bool(batched_schnorr_.load()) || to_bool(unbatched_schnorr_.load()))
331+
{
332+
LOGV("Bypass schnorr " << batched_schnorr_ << " / (" << batched_schnorr_ << " + " << unbatched_schnorr_ << ")");
333+
}
334+
if (to_bool(batched_multisig_.load()) || to_bool(unbatched_multisig_.load()))
335+
{
336+
LOGV("Bypass multisig " << batched_multisig_ << " / (" << batched_multisig_ << " + " << unbatched_multisig_ << ")");
337+
}
338+
}
339+
else
340+
{
341+
if ((ec = block.connect(ctx)))
342+
return ec;
343+
}
300344

301345
// Prevouts optimize confirmation.
302346
if (!query.set_prevouts(link, block))

src/estimator.cpp

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -34,25 +34,21 @@ using namespace system;
3434

3535
uint64_t estimator::estimate(size_t target, mode mode) const NOEXCEPT
3636
{
37-
// max_uint64 is failure sentinel (and unachievable/invalid as a fee).
38-
auto estimate = max_uint64;
3937
constexpr size_t large = horizon::large;
4038
if (target >= large)
41-
return estimate;
39+
return estimate_failed;
4240

4341
// Valid results are effectively limited to at least 1 sat/vb.
4442
// threshold_fee is thread safe but values are affected during update.
4543
switch (mode)
4644
{
4745
case mode::basic:
4846
{
49-
estimate = compute(target, confidence::high);
50-
break;
47+
return compute(target, confidence::high);
5148
}
5249
case mode::geometric:
5350
{
54-
estimate = compute(target, confidence::high, true);
55-
break;
51+
return compute(target, confidence::high, true);
5652
}
5753
case mode::economical:
5854
{
@@ -62,8 +58,7 @@ uint64_t estimator::estimate(size_t target, mode mode) const NOEXCEPT
6258
const auto fee1 = compute(target1, confidence::low);
6359
const auto fee2 = compute(target2, confidence::mid);
6460
const auto fee3 = compute(target3, confidence::high);
65-
estimate = std::max({ fee1, fee2, fee3 });
66-
break;
61+
return std::max({ fee1, fee2, fee3 });
6762
}
6863
case mode::conservative:
6964
{
@@ -73,16 +68,14 @@ uint64_t estimator::estimate(size_t target, mode mode) const NOEXCEPT
7368
const auto fee1 = compute(target1, confidence::low);
7469
const auto fee2 = compute(target2, confidence::mid);
7570
const auto fee3 = compute(target3, confidence::high);
76-
estimate = std::max({ fee1, fee2, fee3 });
77-
break;
71+
return std::max({ fee1, fee2, fee3 });
7872
}
73+
default:
7974
case mode::unknown:
8075
{
81-
break;
76+
return estimate_failed;
8277
}
8378
}
84-
85-
return estimate;
8679
}
8780

8881
bool estimator::initialize(const std::atomic_bool& cancel, const query& query,

src/settings.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ settings::settings() NOEXCEPT
3535
memory_priority{ true },
3636
thread_priority{ true },
3737
allow_overlapped{ true },
38+
batch_signatures{ true },
3839
defer_validation{ false },
3940
defer_confirmation{ false },
4041
minimum_fee_rate{ 0.0 },

test/settings.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ BOOST_AUTO_TEST_CASE(settings__node__default_context__expected)
3535
BOOST_REQUIRE_EQUAL(node.memory_priority, true);
3636
BOOST_REQUIRE_EQUAL(node.thread_priority, true);
3737
BOOST_REQUIRE_EQUAL(node.allow_overlapped, true);
38+
BOOST_REQUIRE_EQUAL(node.batch_signatures, true);
3839
BOOST_REQUIRE_EQUAL(node.defer_validation, false);
3940
BOOST_REQUIRE_EQUAL(node.defer_confirmation, false);
4041
BOOST_REQUIRE_EQUAL(node.minimum_fee_rate, 0.0);

0 commit comments

Comments
 (0)