Skip to content

Commit

Permalink
Merge pull request #521 from evoskuil/master
Browse files Browse the repository at this point in the history
Update to latest NuGet secp256k1 package, optimize confirm.
  • Loading branch information
evoskuil authored Nov 19, 2024
2 parents 281a25b + fb787da commit 946ed38
Show file tree
Hide file tree
Showing 12 changed files with 102 additions and 62 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@
<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')" />
<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')" />
<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')" />
<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')" />
<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')" />
<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')" />
</ImportGroup>
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
Expand All @@ -157,7 +157,7 @@
<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'))" />
<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'))" />
<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'))" />
<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'))" />
<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'))" />
<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'))" />
</Target>
<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@
<package id="boost_program_options-vc143" version="1.78.0" targetFramework="Native" />
<package id="boost_system-vc143" version="1.78.0" targetFramework="Native" />
<package id="boost_thread-vc143" version="1.78.0" targetFramework="Native" />
<package id="secp256k1_vc143" version="0.1.0.20" targetFramework="Native" />
<package id="secp256k1_vc143" version="0.1.0.21" targetFramework="Native" />
<package id="boost_unit_test_framework-vc143" version="1.78.0" targetFramework="Native" />
</packages>
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@
<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')" />
<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')" />
<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')" />
<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')" />
<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')" />
</ImportGroup>
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
Expand All @@ -102,7 +102,7 @@
<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'))" />
<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'))" />
<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'))" />
<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'))" />
<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'))" />
</Target>
<ItemGroup>
<ProjectReference Include="..\libbitcoin-database\libbitcoin-database.vcxproj">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@
<package id="boost_program_options-vc143" version="1.78.0" targetFramework="Native" />
<package id="boost_system-vc143" version="1.78.0" targetFramework="Native" />
<package id="boost_thread-vc143" version="1.78.0" targetFramework="Native" />
<package id="secp256k1_vc143" version="0.1.0.20" targetFramework="Native" />
<package id="secp256k1_vc143" version="0.1.0.21" targetFramework="Native" />
</packages>
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@
<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')" />
<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')" />
<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')" />
<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')" />
<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')" />
</ImportGroup>
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
Expand All @@ -196,7 +196,7 @@
<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'))" />
<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'))" />
<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'))" />
<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'))" />
<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'))" />
</Target>
<ItemGroup>
<Natvis Include="..\..\debug.natvis" />
Expand Down
2 changes: 1 addition & 1 deletion builds/msvc/vs2022/libbitcoin-database/packages.config
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@
<package id="boost_program_options-vc143" version="1.78.0" targetFramework="Native" />
<package id="boost_system-vc143" version="1.78.0" targetFramework="Native" />
<package id="boost_thread-vc143" version="1.78.0" targetFramework="Native" />
<package id="secp256k1_vc143" version="0.1.0.20" targetFramework="Native" />
<package id="secp256k1_vc143" version="0.1.0.21" targetFramework="Native" />
</packages>
49 changes: 24 additions & 25 deletions include/bitcoin/database/impl/query/confirm.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -303,20 +303,21 @@ error::error_t CLASS::unspendable_prevout(const point_link& link,
}

TEMPLATE
code CLASS::unspent_duplicates(const tx_link& coinbase,
code CLASS::unspent_duplicates(const header_link& link,
const context& ctx) const NOEXCEPT
{
if (!ctx.is_enabled(system::chain::flags::bip30_rule))
return error::success;

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

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

if (coinbases.empty())
return error::integrity;

// bip30: all (but self) must be confirmed spent or dup invalid (cb only).
size_t unspent{};
for (const auto& tx: coinbases)
Expand All @@ -327,6 +328,8 @@ code CLASS::unspent_duplicates(const tx_link& coinbase,
return is_zero(unspent) ? error::integrity : error::success;
}

#if defined(UNDEFINED)

// protected
TEMPLATE
spend_sets CLASS::to_spend_sets(const header_link& link) const NOEXCEPT
Expand Down Expand Up @@ -407,31 +410,27 @@ code CLASS::block_confirmable(const header_link& link) const NOEXCEPT
return ec;
}

#if defined(UNDEFINED)
#endif


// protected
TEMPLATE
spend_sets CLASS::to_spend_sets(const header_link& link) const NOEXCEPT
{
const auto txs = to_transactions(link);
// Coinbase tx does not spend.
const auto txs = to_spending_transactions(link);

if (txs.empty())
return {};

// Coinbase optimization.
spend_sets out{ txs.size() };
out.front().tx = txs.front();
if (is_one(out.size()))
return out;

const auto non_coinbase = std::next(txs.begin());
const auto to_set = [this](const auto& tx) NOEXCEPT
{
return to_spend_set(tx);
};

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

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

// C++17 incomplete on GCC/CLang, so presently parallel only on MSVC++.
const auto sets = to_spend_sets(link);
if (sets.empty())
return error::integrity;

code ec{};
if ((ec = unspent_duplicates(sets.front().tx, ctx)))
if ((ec = unspent_duplicates(link, ctx)))
return ec;

const auto non_coinbase = std::next(sets.begin());
const auto sets = to_spend_sets(link);
if (sets.empty())
return ec;

std::atomic<error::error_t> fault{ error::success };

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

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

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

return ec;
}

#if defined(UNDEFINED)

// split(1) 446 secs for 400k-410k
TEMPLATE
code CLASS::block_confirmable(const header_link& link) const NOEXCEPT
Expand Down Expand Up @@ -620,7 +619,7 @@ TEMPLATE
bool CLASS::initialize(const block& genesis) NOEXCEPT
{
BC_ASSERT(!is_initialized());
BC_ASSERT(genesis.transactions_ptr()->size() == one);
BC_ASSERT(is_one(genesis.transactions_ptr()->size()));

// ========================================================================
const auto scope = store_.get_transactor();
Expand Down
13 changes: 11 additions & 2 deletions include/bitcoin/database/impl/query/translate.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -479,13 +479,12 @@ spend_set CLASS::to_spend_set(const tx_link& link) const NOEXCEPT

spend_set set{ link, tx.version, {} };
set.spends.reserve(tx.ins_count);

// This is not concurrent because to_spend_sets is (by tx).
table::spend::get_prevout_sequence get{};

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

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

TEMPLATE
tx_links CLASS::to_spending_transactions(const header_link& link) const NOEXCEPT
{
table::txs::get_spending_txs txs{};
if (!store_.txs.find(link, txs))
return {};

return std::move(txs.tx_fks);
}

TEMPLATE
tx_link CLASS::to_coinbase(const header_link& link) const NOEXCEPT
{
Expand Down
5 changes: 3 additions & 2 deletions include/bitcoin/database/query.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,7 @@ class query
/// block to txs/puts (forward navigation)
tx_link to_coinbase(const header_link& link) const NOEXCEPT;
tx_links to_transactions(const header_link& link) const NOEXCEPT;
tx_links to_spending_transactions(const header_link& link) const NOEXCEPT;
output_links to_block_outputs(const header_link& link) const NOEXCEPT;
spend_links to_block_spends(const header_link& link) const NOEXCEPT;

Expand Down Expand Up @@ -497,8 +498,8 @@ class query
bool set_strong(const header_link& link) NOEXCEPT;
bool set_unstrong(const header_link& link) NOEXCEPT;
code block_confirmable(const header_link& link) const NOEXCEPT;
code tx_confirmable(const tx_link& link, const context& ctx) const NOEXCEPT;
code unspent_duplicates(const tx_link& coinbase,
////code tx_confirmable(const tx_link& link, const context& ctx) const NOEXCEPT;
code unspent_duplicates(const header_link& coinbase,
const context& ctx) const NOEXCEPT;

/// Height indexation.
Expand Down
23 changes: 23 additions & 0 deletions include/bitcoin/database/tables/archives/txs.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#define LIBBITCOIN_DATABASE_TABLES_ARCHIVES_TXS_HPP

#include <algorithm>
#include <iterator>
#include <bitcoin/system.hpp>
#include <bitcoin/database/define.hpp>
#include <bitcoin/database/memory/memory.hpp>
Expand Down Expand Up @@ -169,6 +170,28 @@ struct txs
keys tx_fks{};
};

struct get_spending_txs
: public schema::txs
{
inline bool from_data(reader& source) NOEXCEPT
{
const auto count = source.read_little_endian<tx::integer, schema::count_>();
if (count <= one)
return source;

tx_fks.resize(sub1(count));
source.skip_bytes(bytes::size + tx::size);
std::for_each(tx_fks.begin(), tx_fks.end(), [&](auto& fk) NOEXCEPT
{
fk = source.read_little_endian<tx::integer, tx::size>();
});

return source;
}

keys tx_fks{};
};

struct get_tx_quantity
: public schema::txs
{
Expand Down
Loading

0 comments on commit 946ed38

Please sign in to comment.