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
4 changes: 4 additions & 0 deletions include/bitcoin/database/impl/query/confirm.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -710,6 +710,10 @@ bool CLASS::set_unstrong(const header_link& link) NOEXCEPT
TEMPLATE
bool CLASS::set_prevouts(size_t height, const block& block) NOEXCEPT
{
// Empty or coinbase only implies no spends.
if (block.transactions() <= one)
return true;

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

Expand Down
35 changes: 14 additions & 21 deletions include/bitcoin/database/tables/caches/prevout.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,31 +103,24 @@ struct prevout
inline bool to_data(finalizer& sink) const NOEXCEPT
{
const auto txs = *block.transactions_ptr();
if (txs.size() <= one)
{
// Empty or coinbase only implies no spends.
sink.invalidate();
}
else
{
const auto write_spend = [&](const auto& in) NOEXCEPT
{
// Sets terminal sentinel for block-internal spends.
const auto value = in->metadata.inside ? tx::terminal :
merge(in->metadata.coinbase, in->metadata.parent);
BC_ASSERT_MSG(txs.size() > one, "empty block");

sink.write_little_endian<tx::integer, tx::size>(value);
};
const auto write_spend = [&](const auto& in) NOEXCEPT
{
// Sets terminal sentinel for block-internal spends.
const auto value = in->metadata.inside ? tx::terminal :
merge(in->metadata.coinbase, in->metadata.parent);

const auto write_tx = [&](const auto& tx) NOEXCEPT
{
const auto& ins = tx->inputs_ptr();
return std::for_each(ins->begin(), ins->end(), write_spend);
};
sink.write_little_endian<tx::integer, tx::size>(value);
};

std::for_each(std::next(txs.begin()), txs.end(), write_tx);
}
const auto write_tx = [&](const auto& tx) NOEXCEPT
{
const auto& ins = tx->inputs_ptr();
return std::for_each(ins->begin(), ins->end(), write_spend);
};

std::for_each(std::next(txs.begin()), txs.end(), write_tx);
BC_ASSERT(!sink || (sink.get_write_position() == count() * minrow));
return sink;
}
Expand Down
23 changes: 12 additions & 11 deletions test/tables/caches/prevout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -264,17 +264,18 @@ BOOST_AUTO_TEST_CASE(prevout__put__merged_values__expected)

// record_put_ref

BOOST_AUTO_TEST_CASE(prevout__record_put_ref__empty_block__false)
{
test::chunk_storage head_store{};
test::chunk_storage body_store{};
table::prevout instance{ head_store, body_store, 5 };
BOOST_REQUIRE(instance.create());

const auto genesis = system::settings(selection::mainnet).genesis_block;
const auto record = table::prevout::record_put_ref{ {}, genesis };
BOOST_REQUIRE(!instance.put(4, record));
}
// Empty block is now guarded at the query level (set_prevouts(...)).
////BOOST_AUTO_TEST_CASE(prevout__record_put_ref__empty_block__false)
////{
//// test::chunk_storage head_store{};
//// test::chunk_storage body_store{};
//// table::prevout instance{ head_store, body_store, 5 };
//// BOOST_REQUIRE(instance.create());
////
//// const auto genesis = system::settings(selection::mainnet).genesis_block;
//// const auto record = table::prevout::record_put_ref{ {}, genesis };
//// BOOST_REQUIRE(!instance.put(4, record));
////}

BOOST_AUTO_TEST_CASE(prevout__put_ref__get_non_empty_block_with_default_metadata__inside_spend_terminals)
{
Expand Down
Loading