Skip to content

Commit 95ac9a0

Browse files
authored
Merge pull request #538 from evoskuil/master
Move prevouts query empty block guard outside of transactor.
2 parents 295884d + de45d4a commit 95ac9a0

File tree

3 files changed

+30
-32
lines changed

3 files changed

+30
-32
lines changed

include/bitcoin/database/impl/query/confirm.ipp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -710,6 +710,10 @@ bool CLASS::set_unstrong(const header_link& link) NOEXCEPT
710710
TEMPLATE
711711
bool CLASS::set_prevouts(size_t height, const block& block) NOEXCEPT
712712
{
713+
// Empty or coinbase only implies no spends.
714+
if (block.transactions() <= one)
715+
return true;
716+
713717
// ========================================================================
714718
const auto scope = store_.get_transactor();
715719

include/bitcoin/database/tables/caches/prevout.hpp

Lines changed: 14 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -103,31 +103,24 @@ struct prevout
103103
inline bool to_data(finalizer& sink) const NOEXCEPT
104104
{
105105
const auto txs = *block.transactions_ptr();
106-
if (txs.size() <= one)
107-
{
108-
// Empty or coinbase only implies no spends.
109-
sink.invalidate();
110-
}
111-
else
112-
{
113-
const auto write_spend = [&](const auto& in) NOEXCEPT
114-
{
115-
// Sets terminal sentinel for block-internal spends.
116-
const auto value = in->metadata.inside ? tx::terminal :
117-
merge(in->metadata.coinbase, in->metadata.parent);
106+
BC_ASSERT_MSG(txs.size() > one, "empty block");
118107

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

122-
const auto write_tx = [&](const auto& tx) NOEXCEPT
123-
{
124-
const auto& ins = tx->inputs_ptr();
125-
return std::for_each(ins->begin(), ins->end(), write_spend);
126-
};
114+
sink.write_little_endian<tx::integer, tx::size>(value);
115+
};
127116

128-
std::for_each(std::next(txs.begin()), txs.end(), write_tx);
129-
}
117+
const auto write_tx = [&](const auto& tx) NOEXCEPT
118+
{
119+
const auto& ins = tx->inputs_ptr();
120+
return std::for_each(ins->begin(), ins->end(), write_spend);
121+
};
130122

123+
std::for_each(std::next(txs.begin()), txs.end(), write_tx);
131124
BC_ASSERT(!sink || (sink.get_write_position() == count() * minrow));
132125
return sink;
133126
}

test/tables/caches/prevout.cpp

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -264,17 +264,18 @@ BOOST_AUTO_TEST_CASE(prevout__put__merged_values__expected)
264264

265265
// record_put_ref
266266

267-
BOOST_AUTO_TEST_CASE(prevout__record_put_ref__empty_block__false)
268-
{
269-
test::chunk_storage head_store{};
270-
test::chunk_storage body_store{};
271-
table::prevout instance{ head_store, body_store, 5 };
272-
BOOST_REQUIRE(instance.create());
273-
274-
const auto genesis = system::settings(selection::mainnet).genesis_block;
275-
const auto record = table::prevout::record_put_ref{ {}, genesis };
276-
BOOST_REQUIRE(!instance.put(4, record));
277-
}
267+
// Empty block is now guarded at the query level (set_prevouts(...)).
268+
////BOOST_AUTO_TEST_CASE(prevout__record_put_ref__empty_block__false)
269+
////{
270+
//// test::chunk_storage head_store{};
271+
//// test::chunk_storage body_store{};
272+
//// table::prevout instance{ head_store, body_store, 5 };
273+
//// BOOST_REQUIRE(instance.create());
274+
////
275+
//// const auto genesis = system::settings(selection::mainnet).genesis_block;
276+
//// const auto record = table::prevout::record_put_ref{ {}, genesis };
277+
//// BOOST_REQUIRE(!instance.put(4, record));
278+
////}
278279

279280
BOOST_AUTO_TEST_CASE(prevout__put_ref__get_non_empty_block_with_default_metadata__inside_spend_terminals)
280281
{

0 commit comments

Comments
 (0)