Skip to content

Commit edc12f0

Browse files
authored
Merge pull request #1897 from evoskuil/master
Update stub silent payment batch for SoA table, add CPU stub.
2 parents f16d93a + 2e2e144 commit edc12f0

2 files changed

Lines changed: 48 additions & 16 deletions

File tree

include/bitcoin/system/crypto/secp256k1_batch.hpp

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,6 @@ namespace batched {
3535
using link = data_array<3>;
3636
using link_t = unsigned_type<sizeof(link)>;
3737
using links_t = std::vector<link_t>;
38-
using tx_link = data_array<4>;
39-
using tx_link_t = unsigned_type<sizeof(tx_link)>;
40-
using tx_links_t = std::vector<tx_link_t>;
4138
} // namespace batched
4239

4340
namespace ecdsa {
@@ -106,16 +103,23 @@ namespace silent
106103
/// Span matches serialized buffer.
107104
struct BC_API batch
108105
{
109-
using span = std::span<const batch>;
110-
using prefix_bytes = data_array<sizeof(uint64_t)>;
111-
using handler = std::function<void(const code&, batched::tx_link_t)>;
106+
using prefix = data_array<8>;
107+
using tx_link = data_array<4>;
108+
using tx_link_t = unsigned_type<sizeof(tx_link)>;
109+
////using tx_links_t = std::vector<tx_link_t>;
110+
using handler = std::function<void(const code&, tx_link_t)>;
111+
112+
std::span<const prefix> prefixes;
113+
std::span<const ec_compressed> compresseds;
114+
std::span<const tx_link> correlates;
112115

113-
prefix_bytes prefix;
114-
ec_compressed compressed;
115-
batched::tx_link link;
116+
static void scan(const stopper& cancel, const batch& batch,
117+
const ec_secret& scan_key, const handler& callback,
118+
bool turbo) NOEXCEPT;
116119

117-
static void scan(const stopper& cancel, const span& batch,
118-
const ec_secret& scan_key, const handler& callback) NOEXCEPT;
120+
protected:
121+
static bool get_match(tx_link_t& out, const batch& batch,
122+
size_t row, const ec_secret& scan_key) NOEXCEPT;
119123
};
120124

121125
} // namespace silent

src/crypto/secp256k1/batch.cpp

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,16 @@ links_t schnorr::batch::get_failures(const stopper& cancel,
292292
return fails;
293293
}
294294

295+
// get_match (silent)
296+
// ----------------------------------------------------------------------------
297+
298+
bool silent::batch::get_match(tx_link_t& , const batch& , size_t ,
299+
const ec_secret& ) NOEXCEPT
300+
{
301+
// TODO: implement.
302+
return false;
303+
}
304+
295305
// evaluate
296306
// ----------------------------------------------------------------------------
297307
// static/protected
@@ -347,7 +357,7 @@ links_t schnorr::batch::verify(const stopper& cancel,
347357

348358
#if defined(HAVE_ULTRAFAST)
349359

350-
void silent::batch::scan(const stopper& , const span& ,
360+
void silent::batch::scan(const stopper& , const batch& ,
351361
const ec_secret& , const handler& ) NOEXCEPT
352362
{
353363
// TODO: iterate over chunked subsets or entire set.
@@ -356,11 +366,29 @@ void silent::batch::scan(const stopper& , const span& ,
356366

357367
#else
358368

359-
void silent::batch::scan(const stopper& , const span& ,
360-
const ec_secret& , const handler& ) NOEXCEPT
369+
void silent::batch::scan(const stopper& cancel, const batch& batch,
370+
const ec_secret& scan_key, const handler& callback, bool turbo) NOEXCEPT
361371
{
362-
// TODO: iterate results set in cancellable parallel loop over full space.
363-
// TODO: correlate matches to tx link and invoke callback.
372+
const auto policy = poolstl::execution::par_if(turbo);
373+
374+
// Three spans are corresponding arrays of equal length.
375+
const auto count = batch.correlates.size();
376+
BC_ASSERT(batch.prefixes.size() == count);
377+
BC_ASSERT(batch.compresseds.size() == count);
378+
379+
std::vector<size_t> it(count);
380+
std::iota(it.begin(), it.end(), zero);
381+
382+
// Return from scan with !cancel implies complete.
383+
std::for_each(policy, it.cbegin(), it.cend(), [&](size_t row) NOEXCEPT
384+
{
385+
if (cancel)
386+
return;
387+
388+
tx_link_t tx{};
389+
if (get_match(tx, batch, row, scan_key))
390+
callback({}, tx);
391+
});
364392
}
365393

366394
#endif

0 commit comments

Comments
 (0)