Skip to content

Commit 946ed38

Browse files
authored
Merge pull request #521 from evoskuil/master
Update to latest NuGet secp256k1 package, optimize confirm.
2 parents 281a25b + fb787da commit 946ed38

File tree

12 files changed

+102
-62
lines changed

12 files changed

+102
-62
lines changed

builds/msvc/vs2022/libbitcoin-database-test/libbitcoin-database-test.vcxproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@
141141
<Import Project="$(NuGetPackageRoot)boost_program_options-vc143.1.78.0\build\boost_program_options-vc143.targets" Condition="Exists('$(NuGetPackageRoot)boost_program_options-vc143.1.78.0\build\boost_program_options-vc143.targets')" />
142142
<Import Project="$(NuGetPackageRoot)boost_system-vc143.1.78.0\build\boost_system-vc143.targets" Condition="Exists('$(NuGetPackageRoot)boost_system-vc143.1.78.0\build\boost_system-vc143.targets')" />
143143
<Import Project="$(NuGetPackageRoot)boost_thread-vc143.1.78.0\build\boost_thread-vc143.targets" Condition="Exists('$(NuGetPackageRoot)boost_thread-vc143.1.78.0\build\boost_thread-vc143.targets')" />
144-
<Import Project="$(NuGetPackageRoot)secp256k1_vc143.0.1.0.20\build\native\secp256k1_vc143.targets" Condition="Exists('$(NuGetPackageRoot)secp256k1_vc143.0.1.0.20\build\native\secp256k1_vc143.targets')" />
144+
<Import Project="$(NuGetPackageRoot)secp256k1_vc143.0.1.0.21\build\native\secp256k1_vc143.targets" Condition="Exists('$(NuGetPackageRoot)secp256k1_vc143.0.1.0.21\build\native\secp256k1_vc143.targets')" />
145145
<Import Project="$(NuGetPackageRoot)boost_unit_test_framework-vc143.1.78.0\build\boost_unit_test_framework-vc143.targets" Condition="Exists('$(NuGetPackageRoot)boost_unit_test_framework-vc143.1.78.0\build\boost_unit_test_framework-vc143.targets')" />
146146
</ImportGroup>
147147
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
@@ -157,7 +157,7 @@
157157
<Error Condition="!Exists('$(NuGetPackageRoot)boost_program_options-vc143.1.78.0\build\boost_program_options-vc143.targets')" Text="$([System.String]::Format('$(ErrorText)', '$(NuGetPackageRoot)boost_program_options-vc143.1.78.0\build\boost_program_options-vc143.targets'))" />
158158
<Error Condition="!Exists('$(NuGetPackageRoot)boost_system-vc143.1.78.0\build\boost_system-vc143.targets')" Text="$([System.String]::Format('$(ErrorText)', '$(NuGetPackageRoot)boost_system-vc143.1.78.0\build\boost_system-vc143.targets'))" />
159159
<Error Condition="!Exists('$(NuGetPackageRoot)boost_thread-vc143.1.78.0\build\boost_thread-vc143.targets')" Text="$([System.String]::Format('$(ErrorText)', '$(NuGetPackageRoot)boost_thread-vc143.1.78.0\build\boost_thread-vc143.targets'))" />
160-
<Error Condition="!Exists('$(NuGetPackageRoot)secp256k1_vc143.0.1.0.20\build\native\secp256k1_vc143.targets')" Text="$([System.String]::Format('$(ErrorText)', '$(NuGetPackageRoot)secp256k1_vc143.0.1.0.20\build\native\secp256k1_vc143.targets'))" />
160+
<Error Condition="!Exists('$(NuGetPackageRoot)secp256k1_vc143.0.1.0.21\build\native\secp256k1_vc143.targets')" Text="$([System.String]::Format('$(ErrorText)', '$(NuGetPackageRoot)secp256k1_vc143.0.1.0.21\build\native\secp256k1_vc143.targets'))" />
161161
<Error Condition="!Exists('$(NuGetPackageRoot)boost_unit_test_framework-vc143.1.78.0\build\boost_unit_test_framework-vc143.targets')" Text="$([System.String]::Format('$(ErrorText)', '$(NuGetPackageRoot)boost_unit_test_framework-vc143.1.78.0\build\boost_unit_test_framework-vc143.targets'))" />
162162
</Target>
163163
<ItemGroup>

builds/msvc/vs2022/libbitcoin-database-test/packages.config

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,6 @@
1515
<package id="boost_program_options-vc143" version="1.78.0" targetFramework="Native" />
1616
<package id="boost_system-vc143" version="1.78.0" targetFramework="Native" />
1717
<package id="boost_thread-vc143" version="1.78.0" targetFramework="Native" />
18-
<package id="secp256k1_vc143" version="0.1.0.20" targetFramework="Native" />
18+
<package id="secp256k1_vc143" version="0.1.0.21" targetFramework="Native" />
1919
<package id="boost_unit_test_framework-vc143" version="1.78.0" targetFramework="Native" />
2020
</packages>

builds/msvc/vs2022/libbitcoin-database-tools/libbitcoin-database-tools.vcxproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@
8787
<Import Project="$(NuGetPackageRoot)boost_program_options-vc143.1.78.0\build\boost_program_options-vc143.targets" Condition="Exists('$(NuGetPackageRoot)boost_program_options-vc143.1.78.0\build\boost_program_options-vc143.targets')" />
8888
<Import Project="$(NuGetPackageRoot)boost_system-vc143.1.78.0\build\boost_system-vc143.targets" Condition="Exists('$(NuGetPackageRoot)boost_system-vc143.1.78.0\build\boost_system-vc143.targets')" />
8989
<Import Project="$(NuGetPackageRoot)boost_thread-vc143.1.78.0\build\boost_thread-vc143.targets" Condition="Exists('$(NuGetPackageRoot)boost_thread-vc143.1.78.0\build\boost_thread-vc143.targets')" />
90-
<Import Project="$(NuGetPackageRoot)secp256k1_vc143.0.1.0.20\build\native\secp256k1_vc143.targets" Condition="Exists('$(NuGetPackageRoot)secp256k1_vc143.0.1.0.20\build\native\secp256k1_vc143.targets')" />
90+
<Import Project="$(NuGetPackageRoot)secp256k1_vc143.0.1.0.21\build\native\secp256k1_vc143.targets" Condition="Exists('$(NuGetPackageRoot)secp256k1_vc143.0.1.0.21\build\native\secp256k1_vc143.targets')" />
9191
</ImportGroup>
9292
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
9393
<PropertyGroup>
@@ -102,7 +102,7 @@
102102
<Error Condition="!Exists('$(NuGetPackageRoot)boost_program_options-vc143.1.78.0\build\boost_program_options-vc143.targets')" Text="$([System.String]::Format('$(ErrorText)', '$(NuGetPackageRoot)boost_program_options-vc143.1.78.0\build\boost_program_options-vc143.targets'))" />
103103
<Error Condition="!Exists('$(NuGetPackageRoot)boost_system-vc143.1.78.0\build\boost_system-vc143.targets')" Text="$([System.String]::Format('$(ErrorText)', '$(NuGetPackageRoot)boost_system-vc143.1.78.0\build\boost_system-vc143.targets'))" />
104104
<Error Condition="!Exists('$(NuGetPackageRoot)boost_thread-vc143.1.78.0\build\boost_thread-vc143.targets')" Text="$([System.String]::Format('$(ErrorText)', '$(NuGetPackageRoot)boost_thread-vc143.1.78.0\build\boost_thread-vc143.targets'))" />
105-
<Error Condition="!Exists('$(NuGetPackageRoot)secp256k1_vc143.0.1.0.20\build\native\secp256k1_vc143.targets')" Text="$([System.String]::Format('$(ErrorText)', '$(NuGetPackageRoot)secp256k1_vc143.0.1.0.20\build\native\secp256k1_vc143.targets'))" />
105+
<Error Condition="!Exists('$(NuGetPackageRoot)secp256k1_vc143.0.1.0.21\build\native\secp256k1_vc143.targets')" Text="$([System.String]::Format('$(ErrorText)', '$(NuGetPackageRoot)secp256k1_vc143.0.1.0.21\build\native\secp256k1_vc143.targets'))" />
106106
</Target>
107107
<ItemGroup>
108108
<ProjectReference Include="..\libbitcoin-database\libbitcoin-database.vcxproj">

builds/msvc/vs2022/libbitcoin-database-tools/packages.config

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,5 @@
1515
<package id="boost_program_options-vc143" version="1.78.0" targetFramework="Native" />
1616
<package id="boost_system-vc143" version="1.78.0" targetFramework="Native" />
1717
<package id="boost_thread-vc143" version="1.78.0" targetFramework="Native" />
18-
<package id="secp256k1_vc143" version="0.1.0.20" targetFramework="Native" />
18+
<package id="secp256k1_vc143" version="0.1.0.21" targetFramework="Native" />
1919
</packages>

builds/msvc/vs2022/libbitcoin-database/libbitcoin-database.vcxproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@
181181
<Import Project="$(NuGetPackageRoot)boost_program_options-vc143.1.78.0\build\boost_program_options-vc143.targets" Condition="Exists('$(NuGetPackageRoot)boost_program_options-vc143.1.78.0\build\boost_program_options-vc143.targets')" />
182182
<Import Project="$(NuGetPackageRoot)boost_system-vc143.1.78.0\build\boost_system-vc143.targets" Condition="Exists('$(NuGetPackageRoot)boost_system-vc143.1.78.0\build\boost_system-vc143.targets')" />
183183
<Import Project="$(NuGetPackageRoot)boost_thread-vc143.1.78.0\build\boost_thread-vc143.targets" Condition="Exists('$(NuGetPackageRoot)boost_thread-vc143.1.78.0\build\boost_thread-vc143.targets')" />
184-
<Import Project="$(NuGetPackageRoot)secp256k1_vc143.0.1.0.20\build\native\secp256k1_vc143.targets" Condition="Exists('$(NuGetPackageRoot)secp256k1_vc143.0.1.0.20\build\native\secp256k1_vc143.targets')" />
184+
<Import Project="$(NuGetPackageRoot)secp256k1_vc143.0.1.0.21\build\native\secp256k1_vc143.targets" Condition="Exists('$(NuGetPackageRoot)secp256k1_vc143.0.1.0.21\build\native\secp256k1_vc143.targets')" />
185185
</ImportGroup>
186186
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
187187
<PropertyGroup>
@@ -196,7 +196,7 @@
196196
<Error Condition="!Exists('$(NuGetPackageRoot)boost_program_options-vc143.1.78.0\build\boost_program_options-vc143.targets')" Text="$([System.String]::Format('$(ErrorText)', '$(NuGetPackageRoot)boost_program_options-vc143.1.78.0\build\boost_program_options-vc143.targets'))" />
197197
<Error Condition="!Exists('$(NuGetPackageRoot)boost_system-vc143.1.78.0\build\boost_system-vc143.targets')" Text="$([System.String]::Format('$(ErrorText)', '$(NuGetPackageRoot)boost_system-vc143.1.78.0\build\boost_system-vc143.targets'))" />
198198
<Error Condition="!Exists('$(NuGetPackageRoot)boost_thread-vc143.1.78.0\build\boost_thread-vc143.targets')" Text="$([System.String]::Format('$(ErrorText)', '$(NuGetPackageRoot)boost_thread-vc143.1.78.0\build\boost_thread-vc143.targets'))" />
199-
<Error Condition="!Exists('$(NuGetPackageRoot)secp256k1_vc143.0.1.0.20\build\native\secp256k1_vc143.targets')" Text="$([System.String]::Format('$(ErrorText)', '$(NuGetPackageRoot)secp256k1_vc143.0.1.0.20\build\native\secp256k1_vc143.targets'))" />
199+
<Error Condition="!Exists('$(NuGetPackageRoot)secp256k1_vc143.0.1.0.21\build\native\secp256k1_vc143.targets')" Text="$([System.String]::Format('$(ErrorText)', '$(NuGetPackageRoot)secp256k1_vc143.0.1.0.21\build\native\secp256k1_vc143.targets'))" />
200200
</Target>
201201
<ItemGroup>
202202
<Natvis Include="..\..\debug.natvis" />

builds/msvc/vs2022/libbitcoin-database/packages.config

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,5 @@
1515
<package id="boost_program_options-vc143" version="1.78.0" targetFramework="Native" />
1616
<package id="boost_system-vc143" version="1.78.0" targetFramework="Native" />
1717
<package id="boost_thread-vc143" version="1.78.0" targetFramework="Native" />
18-
<package id="secp256k1_vc143" version="0.1.0.20" targetFramework="Native" />
18+
<package id="secp256k1_vc143" version="0.1.0.21" targetFramework="Native" />
1919
</packages>

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

Lines changed: 24 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -303,20 +303,21 @@ error::error_t CLASS::unspendable_prevout(const point_link& link,
303303
}
304304

305305
TEMPLATE
306-
code CLASS::unspent_duplicates(const tx_link& coinbase,
306+
code CLASS::unspent_duplicates(const header_link& link,
307307
const context& ctx) const NOEXCEPT
308308
{
309309
if (!ctx.is_enabled(system::chain::flags::bip30_rule))
310310
return error::success;
311311

312312
// This will be empty if current block is not set_strong.
313-
const auto coinbases = to_strong_txs(get_tx_key(coinbase));
314-
if (coinbases.empty())
315-
return error::integrity;
313+
const auto coinbases = to_strong_txs(get_tx_key(to_coinbase(link)));
316314

317315
if (is_one(coinbases.size()))
318316
return error::success;
319317

318+
if (coinbases.empty())
319+
return error::integrity;
320+
320321
// bip30: all (but self) must be confirmed spent or dup invalid (cb only).
321322
size_t unspent{};
322323
for (const auto& tx: coinbases)
@@ -327,6 +328,8 @@ code CLASS::unspent_duplicates(const tx_link& coinbase,
327328
return is_zero(unspent) ? error::integrity : error::success;
328329
}
329330

331+
#if defined(UNDEFINED)
332+
330333
// protected
331334
TEMPLATE
332335
spend_sets CLASS::to_spend_sets(const header_link& link) const NOEXCEPT
@@ -407,31 +410,27 @@ code CLASS::block_confirmable(const header_link& link) const NOEXCEPT
407410
return ec;
408411
}
409412

410-
#if defined(UNDEFINED)
413+
#endif
414+
411415

412416
// protected
413417
TEMPLATE
414418
spend_sets CLASS::to_spend_sets(const header_link& link) const NOEXCEPT
415419
{
416-
const auto txs = to_transactions(link);
420+
// Coinbase tx does not spend.
421+
const auto txs = to_spending_transactions(link);
422+
417423
if (txs.empty())
418424
return {};
419425

420-
// Coinbase optimization.
421426
spend_sets out{ txs.size() };
422-
out.front().tx = txs.front();
423-
if (is_one(out.size()))
424-
return out;
425-
426-
const auto non_coinbase = std::next(txs.begin());
427427
const auto to_set = [this](const auto& tx) NOEXCEPT
428428
{
429429
return to_spend_set(tx);
430430
};
431431

432432
// C++17 incomplete on GCC/CLang, so presently parallel only on MSVC++.
433-
std_transform(bc::par_unseq, std::next(txs.begin()), txs.end(),
434-
std::next(out.begin()), to_set);
433+
std_transform(bc::par_unseq, txs.begin(), txs.end(), out.begin(), to_set);
435434

436435
return out;
437436
}
@@ -444,16 +443,14 @@ code CLASS::block_confirmable(const header_link& link) const NOEXCEPT
444443
if (!get_context(ctx, link))
445444
return error::integrity;
446445

447-
// C++17 incomplete on GCC/CLang, so presently parallel only on MSVC++.
448-
const auto sets = to_spend_sets(link);
449-
if (sets.empty())
450-
return error::integrity;
451-
452446
code ec{};
453-
if ((ec = unspent_duplicates(sets.front().tx, ctx)))
447+
if ((ec = unspent_duplicates(link, ctx)))
454448
return ec;
455449

456-
const auto non_coinbase = std::next(sets.begin());
450+
const auto sets = to_spend_sets(link);
451+
if (sets.empty())
452+
return ec;
453+
457454
std::atomic<error::error_t> fault{ error::success };
458455

459456
const auto is_unspendable = [this, &ctx, &fault](const auto& set) NOEXCEPT
@@ -484,16 +481,18 @@ code CLASS::block_confirmable(const header_link& link) const NOEXCEPT
484481
};
485482

486483
// C++17 incomplete on GCC/CLang, so presently parallel only on MSVC++.
487-
if (std_any_of(bc::par_unseq, non_coinbase, sets.end(), is_unspendable))
484+
if (std_any_of(bc::par_unseq, sets.begin(), sets.end(), is_unspendable))
488485
return { fault.load() };
489486

490487
// C++17 incomplete on GCC/CLang, so presently parallel only on MSVC++.
491-
if (std_any_of(bc::par_unseq, non_coinbase, sets.end(), is_spent))
488+
if (std_any_of(bc::par_unseq, sets.begin(), sets.end(), is_spent))
492489
return { fault.load() };
493-
490+
494491
return ec;
495492
}
496493

494+
#if defined(UNDEFINED)
495+
497496
// split(1) 446 secs for 400k-410k
498497
TEMPLATE
499498
code CLASS::block_confirmable(const header_link& link) const NOEXCEPT
@@ -620,7 +619,7 @@ TEMPLATE
620619
bool CLASS::initialize(const block& genesis) NOEXCEPT
621620
{
622621
BC_ASSERT(!is_initialized());
623-
BC_ASSERT(genesis.transactions_ptr()->size() == one);
622+
BC_ASSERT(is_one(genesis.transactions_ptr()->size()));
624623

625624
// ========================================================================
626625
const auto scope = store_.get_transactor();

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

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -479,13 +479,12 @@ spend_set CLASS::to_spend_set(const tx_link& link) const NOEXCEPT
479479

480480
spend_set set{ link, tx.version, {} };
481481
set.spends.reserve(tx.ins_count);
482-
483-
// This is not concurrent because to_spend_sets is (by tx).
484482
table::spend::get_prevout_sequence get{};
485483

486484
// This reduced a no-bypass 840k sync/confirmable/confirm run by 8.3%.
487485
const auto ptr = store_.spend.get_memory();
488486

487+
// This is not concurrent because to_spend_sets is (by tx).
489488
for (const auto& spend_fk: puts.spend_fks)
490489
{
491490
if (!store_.spend.get(ptr, spend_fk, get))
@@ -516,6 +515,16 @@ tx_links CLASS::to_transactions(const header_link& link) const NOEXCEPT
516515
return std::move(txs.tx_fks);
517516
}
518517

518+
TEMPLATE
519+
tx_links CLASS::to_spending_transactions(const header_link& link) const NOEXCEPT
520+
{
521+
table::txs::get_spending_txs txs{};
522+
if (!store_.txs.find(link, txs))
523+
return {};
524+
525+
return std::move(txs.tx_fks);
526+
}
527+
519528
TEMPLATE
520529
tx_link CLASS::to_coinbase(const header_link& link) const NOEXCEPT
521530
{

include/bitcoin/database/query.hpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,7 @@ class query
288288
/// block to txs/puts (forward navigation)
289289
tx_link to_coinbase(const header_link& link) const NOEXCEPT;
290290
tx_links to_transactions(const header_link& link) const NOEXCEPT;
291+
tx_links to_spending_transactions(const header_link& link) const NOEXCEPT;
291292
output_links to_block_outputs(const header_link& link) const NOEXCEPT;
292293
spend_links to_block_spends(const header_link& link) const NOEXCEPT;
293294

@@ -497,8 +498,8 @@ class query
497498
bool set_strong(const header_link& link) NOEXCEPT;
498499
bool set_unstrong(const header_link& link) NOEXCEPT;
499500
code block_confirmable(const header_link& link) const NOEXCEPT;
500-
code tx_confirmable(const tx_link& link, const context& ctx) const NOEXCEPT;
501-
code unspent_duplicates(const tx_link& coinbase,
501+
////code tx_confirmable(const tx_link& link, const context& ctx) const NOEXCEPT;
502+
code unspent_duplicates(const header_link& coinbase,
502503
const context& ctx) const NOEXCEPT;
503504

504505
/// Height indexation.

include/bitcoin/database/tables/archives/txs.hpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#define LIBBITCOIN_DATABASE_TABLES_ARCHIVES_TXS_HPP
2121

2222
#include <algorithm>
23+
#include <iterator>
2324
#include <bitcoin/system.hpp>
2425
#include <bitcoin/database/define.hpp>
2526
#include <bitcoin/database/memory/memory.hpp>
@@ -169,6 +170,28 @@ struct txs
169170
keys tx_fks{};
170171
};
171172

173+
struct get_spending_txs
174+
: public schema::txs
175+
{
176+
inline bool from_data(reader& source) NOEXCEPT
177+
{
178+
const auto count = source.read_little_endian<tx::integer, schema::count_>();
179+
if (count <= one)
180+
return source;
181+
182+
tx_fks.resize(sub1(count));
183+
source.skip_bytes(bytes::size + tx::size);
184+
std::for_each(tx_fks.begin(), tx_fks.end(), [&](auto& fk) NOEXCEPT
185+
{
186+
fk = source.read_little_endian<tx::integer, tx::size>();
187+
});
188+
189+
return source;
190+
}
191+
192+
keys tx_fks{};
193+
};
194+
172195
struct get_tx_quantity
173196
: public schema::txs
174197
{

0 commit comments

Comments
 (0)