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
40 changes: 9 additions & 31 deletions include/bitcoin/database/impl/query/batch/silent.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -107,26 +107,14 @@ bool CLASS::set_silent(const header_link& link, const block& block) NOEXCEPT
return false;

const auto first = links.front();

stopper fail{};
std::vector<size_t> it(sub1(count));
std::iota(it.begin(), it.end(), one);
constexpr auto parallel = poolstl::execution::par;
constexpr auto relaxed = std::memory_order_relaxed;

// TODO: parallel may or may not be optimal.
// TODO: alternatively could accumulate block results and write once.
std::for_each(parallel, it.cbegin(), it.cend(), [&](size_t index) NOEXCEPT
for (auto index = one; index < count; ++index)
{
if (fail.load(relaxed))
return;

const auto& fk = links.at(index);
if (fk >= first && !set_silent(fk, *txs->at(index)))
fail.store(true, relaxed);
});
return !fail.load(relaxed);
return false;
}

return true;
}

TEMPLATE
Expand All @@ -143,24 +131,14 @@ bool CLASS::set_silent(const header_link& link,
return false;

const auto first = links.front();

stopper fail{};
std::vector<size_t> it(sub1(count));
std::iota(it.begin(), it.end(), one);
constexpr auto parallel = poolstl::execution::par;
constexpr auto relaxed = std::memory_order_relaxed;

std::for_each(parallel, it.cbegin(), it.cend(), [&](size_t index) NOEXCEPT
for (auto index = one; index < count; ++index)
{
if (fail.load(relaxed))
return;

const auto& fk = links.at(index);
if (fk >= first && !set_silent(fk, txs.at(index)))
fail.store(true, relaxed);
});
return false;
}

return !fail.load(relaxed);
return true;
}

// Ineligible txs have no records.
Expand Down
62 changes: 14 additions & 48 deletions include/bitcoin/database/impl/query/consensus/consensus_compact.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ bool CLASS::get_compact_matches(compact_matches& out,
using link_t = table::pool::link::integer;
static_assert(is_same_type<siphash_columns::value_type,
std::span<const lane_t>>);
constexpr auto chunk_rows = short_id_chunk_rows;
const auto ptr0 = store_.pool.id0.get_memory();
const auto ptr1 = store_.pool.id1.get_memory();
const auto ptr2 = store_.pool.id2.get_memory();
Expand All @@ -94,15 +93,13 @@ bool CLASS::get_compact_matches(compact_matches& out,
return false;

const auto rows = possible_narrow_cast<size_t>(store_.pool.count().value);
if constexpr (is_little_endian)
{
const auto bytes = rows * sizeof(lane_t);
if (is_lesser(ptr0.size(), bytes) || is_lesser(ptr1.size(), bytes) ||
is_lesser(ptr2.size(), bytes) || is_lesser(ptr3.size(), bytes))
return false;
}
const auto bytes = rows * sizeof(lane_t);
if (is_lesser(ptr0.size(), bytes) || is_lesser(ptr1.size(), bytes) ||
is_lesser(ptr2.size(), bytes) || is_lesser(ptr3.size(), bytes))
return false;

std::atomic_bool fail{};
const auto chunk_rows = std::max(short_id_minimum_rows,
ceilinged_divide(rows, two * cores()));
std::vector<compact_matches> found(ceilinged_divide(rows, chunk_rows));
std::vector<size_t> chunks(found.size());
std::iota(chunks.begin(), chunks.end(), zero);
Expand All @@ -114,47 +111,19 @@ bool CLASS::get_compact_matches(compact_matches& out,
const auto first = chunk * chunk_rows;
std::vector<short_id> ids(std::min(chunk_rows, rows - first));

if constexpr (is_little_endian)
const auto column = [&](const memory& ptr) NOEXCEPT
{
const auto column = [&](const memory& ptr) NOEXCEPT
const auto data = pointer_cast<const lane_t>(ptr.data());
return std::span<const lane_t>
{
const auto data = pointer_cast<const lane_t>(ptr.data());
return std::span<const lane_t>
{
std::next(data, first), ids.size()
};
std::next(data, first), ids.size()
};
};

siphash(ids, key, siphash_columns
{
column(ptr0), column(ptr1), column(ptr2), column(ptr3)
});
}
else
siphash(ids, key, siphash_columns
{
table::pool_word id0{}, id1{}, id2{}, id3{};
for (size_t row{}; row < ids.size(); ++row)
{
const table::pool::link link
{
possible_narrow_cast<link_t>(first + row)
};

if (!store_.pool.id0.get(ptr0, link, id0) ||
!store_.pool.id1.get(ptr1, link, id1) ||
!store_.pool.id2.get(ptr2, link, id2) ||
!store_.pool.id3.get(ptr3, link, id3))
{
fail.store(true, std::memory_order_relaxed);
return;
}

ids[row] = siphash(key, siphash_words
{
id0.word, id1.word, id2.word, id3.word
});
}
}
column(ptr0), column(ptr1), column(ptr2), column(ptr3)
});

auto& matches = found.at(chunk);
for (size_t row{}; row < ids.size(); ++row)
Expand All @@ -166,9 +135,6 @@ bool CLASS::get_compact_matches(compact_matches& out,
}
});

if (fail.load(std::memory_order_relaxed))
return false;

for (const auto& matches: found)
out.insert(out.end(), matches.cbegin(), matches.cend());

Expand Down
4 changes: 2 additions & 2 deletions include/bitcoin/database/query.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1105,8 +1105,8 @@ class query
// This value should never be read, but may be useful in debugging.
static constexpr uint32_t unspecified_timestamp = max_uint32;

// Pool rows hashed by one task of the compact block short id scan.
static constexpr size_t short_id_chunk_rows = system::power2(14u);
// Fewest pool rows hashed by one task of the compact block short id scan.
static constexpr size_t short_id_minimum_rows = system::power2(10u);

// Chain objects.
template <typename Bool>
Expand Down
Loading