Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions include/bitcoin/database/error.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ enum error_t : uint8_t
copy_directory,

/// store
not_coalesced,
missing_snapshot,
unloaded_file,

Expand Down
27 changes: 23 additions & 4 deletions include/bitcoin/database/impl/query/consensus.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,14 @@ error::error_t CLASS::unspendable(uint32_t sequence, bool coinbase,
TEMPLATE
bool CLASS::is_prevouts_cached(const header_link& link) const NOEXCEPT
{
return store_.prevout.exists(to_prevout(link));
const auto prevout = to_prevout(link);

// Transactor required for prevout read because of pruning.
// ========================================================================
const auto scope = store_.get_transactor();

return store_.prevout.exists(prevout);
// ========================================================================
}

TEMPLATE
Expand All @@ -235,8 +242,18 @@ code CLASS::populate_prevouts(point_sets& sets, size_t points,
// An empty block will fail here as no prevout element is populated.
table::prevout::slab_get cache{};
cache.spends.resize(points);
if (!store_.prevout.at(to_prevout(link), cache))
return error::integrity5;
const auto prevout = to_prevout(link);

// Transactor required for prevout read because of pruning.
// ========================================================================
{
const auto scope = store_.get_transactor();

if (!store_.prevout.at(prevout, cache))
return error::integrity5;

}
// ========================================================================

// Is any duplicated point in the block confirmed (generally empty).
for (const auto& spender: cache.conflicts)
Expand Down Expand Up @@ -494,12 +511,14 @@ bool CLASS::set_prevouts(const header_link& link, const block& block) NOEXCEPT
if (!get_doubles(doubles, block))
return false;

const auto prevout = to_prevout(link);

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

// Clean single allocation failure (e.g. disk full).
const table::prevout::slab_put_ref prevouts{ {}, doubles, block };
return store_.prevout.put(to_prevout(link), prevouts);
return store_.prevout.put(prevout, prevouts);
// ========================================================================
}

Expand Down
6 changes: 6 additions & 0 deletions include/bitcoin/database/impl/store.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,8 @@ code CLASS::open(const event_handler& handler) NOEXCEPT
TEMPLATE
code CLASS::prune(const event_handler& handler) NOEXCEPT
{
// Transactor lock generally only covers writes, but in this case prevout
// reads must also be guarded since the body shrinks and head is cleared.
while (!transactor_mutex_.try_lock_for(std::chrono::seconds(1)))
{
handler(event_t::wait_lock, table_t::store);
Expand Down Expand Up @@ -467,6 +469,10 @@ code CLASS::prune(const event_handler& handler) NOEXCEPT
// map body, making table usable again.
load(ec, prevout_body_, table_t::prevout_body);
}
else
{
ec = error::not_coalesced;
}

transactor_mutex_.unlock();
return ec;
Expand Down
2 changes: 2 additions & 0 deletions src/error.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,10 @@ DEFINE_ERROR_T_MESSAGE_MAP(error)
{ missing_directory, "missing directory failure" },
{ clear_directory, "clear directory failure" },
{ rename_directory, "rename directory failure" },
{ copy_directory, "copy directory failure" },

// store
{ not_coalesced, "not coalesced" },
{ missing_snapshot, "missing snapshot" },
{ unloaded_file, "file not loaded" },

Expand Down
18 changes: 18 additions & 0 deletions test/error.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,24 @@ BOOST_AUTO_TEST_CASE(error_t__code__rename_directory__true_exected_message)
BOOST_REQUIRE_EQUAL(ec.message(), "rename directory failure");
}

BOOST_AUTO_TEST_CASE(error_t__code__copy_directory__true_exected_message)
{
constexpr auto value = error::copy_directory;
const auto ec = code(value);
BOOST_REQUIRE(ec);
BOOST_REQUIRE(ec == value);
BOOST_REQUIRE_EQUAL(ec.message(), "copy directory failure");
}

BOOST_AUTO_TEST_CASE(error_t__code__not_coalesced__true_exected_message)
{
constexpr auto value = error::not_coalesced;
const auto ec = code(value);
BOOST_REQUIRE(ec);
BOOST_REQUIRE(ec == value);
BOOST_REQUIRE_EQUAL(ec.message(), "not coalesced");
}

BOOST_AUTO_TEST_CASE(error_t__code__missing_snapshot__true_exected_message)
{
constexpr auto value = error::missing_snapshot;
Expand Down
Loading