Skip to content

Commit

Permalink
Merge pull request #420 from evoskuil/master
Browse files Browse the repository at this point in the history
set_link(point_hash) must be protected and not use transactor.
  • Loading branch information
evoskuil authored Mar 16, 2024
2 parents 13bb08a + 10d4373 commit 659dd0e
Show file tree
Hide file tree
Showing 7 changed files with 164 additions and 154 deletions.
3 changes: 0 additions & 3 deletions include/bitcoin/database/boost.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,12 @@
#include <windows.h>
#endif
#include <filesystem>
#include <boost/chrono.hpp>
#include <boost/interprocess/detail/os_file_functions.hpp>
#include <boost/multi_index_container.hpp>
#include <boost/multi_index/hashed_index.hpp>
#include <boost/multi_index/key.hpp>
#include <boost/multi_index/key_extractors.hpp>
#include <boost/multi_index/ordered_index.hpp>
#include <boost/thread/locks.hpp>
#include <boost/thread/shared_mutex.hpp>
#include <bitcoin/system.hpp>

namespace libbitcoin {
Expand Down
46 changes: 23 additions & 23 deletions include/bitcoin/database/impl/query/archive.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -491,6 +491,28 @@ typename CLASS::inputs_ptr CLASS::get_spenders(const tx_link& link,
return get_spenders(to_output(link, output_index));
}

TEMPLATE
inline point_link CLASS::set_link_(const hash_digest& point_hash) NOEXCEPT
{
if (point_hash == system::null_hash)
return {};

// Reuse if archived (always - this is a compression, not a guard).
auto point_fk = to_point(point_hash);
if (!point_fk.is_terminal())
return point_fk;

// This write is NOT transacted as it is only called from set_link(tx)
// ========================================================================

const table::point::record empty{};
if (!store_.point.put_link(point_fk, point_hash, empty))
return {};

return point_fk;
// ========================================================================
}

TEMPLATE
tx_link CLASS::set_link(const transaction& tx) NOEXCEPT
{
Expand Down Expand Up @@ -543,7 +565,7 @@ tx_link CLASS::set_link(const transaction& tx) NOEXCEPT

// Create point and accumulate spend keys.
const auto& prevout = in->point();
spends.push_back(table::spend::compose(set_link(prevout.hash()),
spends.push_back(table::spend::compose(set_link_(prevout.hash()),
prevout.index()));

// Write spend record.
Expand Down Expand Up @@ -612,28 +634,6 @@ tx_link CLASS::set_link(const transaction& tx) NOEXCEPT
// ========================================================================
}

TEMPLATE
inline point_link CLASS::set_link(const hash_digest& point_hash) NOEXCEPT
{
if (point_hash == system::null_hash)
return {};

// Reuse if archived (always - this is a compression, not a guard).
auto point_fk = to_point(point_hash);
if (!point_fk.is_terminal())
return point_fk;

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

const table::point::record empty{};
if (!store_.point.put_link(point_fk, point_hash, empty))
return {};

return point_fk;
// ========================================================================
}

TEMPLATE
header_link CLASS::set_link(const block& block,
const chain_context& ctx) NOEXCEPT
Expand Down
Loading

0 comments on commit 659dd0e

Please sign in to comment.