Skip to content

Commit e576fe3

Browse files
authored
Merge pull request #540 from evoskuil/master
Change populate_with_metadata to populate_without_metadata.
2 parents b6853bd + 4f40e98 commit e576fe3

File tree

2 files changed

+18
-67
lines changed

2 files changed

+18
-67
lines changed

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

Lines changed: 13 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ bool CLASS::set(const block& block, bool strong) NOEXCEPT
133133
return !set_code(block, strong);
134134
}
135135

136-
// populate
136+
// populate (with node metadata)
137137

138138
TEMPLATE
139139
bool CLASS::populate(const input& input) const NOEXCEPT
@@ -188,98 +188,52 @@ bool CLASS::populate(const block& block) const NOEXCEPT
188188
return result;
189189
}
190190

191-
// populate_with_metadata
191+
// populate_without_metadata
192192

193193
TEMPLATE
194-
bool CLASS::populate_with_metadata(const input& input,
195-
const tx_link& link) const NOEXCEPT
194+
bool CLASS::populate_without_metadata(const input& input) const NOEXCEPT
196195
{
196+
// Null point would return nullptr and be interpreted as missing.
197197
BC_ASSERT(!input.point().is_null());
198+
198199
if (input.prevout)
199200
return true;
200201

201-
// null point returns nullptr and is therefore interpreted as missing.
202-
input.prevout = get_output(input.point());
203-
if (is_null(input.prevout))
204-
return false;
205-
206-
// tx of input point exists.
207202
const auto tx = to_tx(input.point().hash());
208-
if (tx.is_terminal())
209-
return false;
210-
211-
// tx of input point is strong.
212-
const auto block = to_block(tx);
213-
if (block.is_terminal())
214-
return false;
215-
216-
context ctx{};
217-
if (!get_context(ctx, block))
218-
return false;
219-
220-
const auto point_fk = to_point(input.point().hash());
221-
const auto point_index = input.point().index();
222-
223-
input.metadata.coinbase = is_coinbase(tx);
224-
input.metadata.spent = is_spent_prevout(point_fk, point_index, link);
225-
input.metadata.median_time_past = ctx.mtp;
226-
input.metadata.height = ctx.height;
227-
return true;
203+
input.prevout = get_output(tx, input.point().index());
204+
return !is_null(input.prevout);
228205
}
229206

230207
TEMPLATE
231-
bool CLASS::populate_with_metadata(const transaction& tx,
232-
const tx_link& link) const NOEXCEPT
208+
bool CLASS::populate_without_metadata(const transaction& tx) const NOEXCEPT
233209
{
210+
BC_ASSERT(!tx.is_coinbase());
211+
234212
auto result = true;
235213
const auto& ins = tx.inputs_ptr();
236214
std::for_each(ins->begin(), ins->end(), [&](const auto& in) NOEXCEPT
237215
{
238-
result &= populate_with_metadata(*in, link);
216+
result &= populate_without_metadata(*in);
239217
});
240218

241219
return result;
242220
}
243221

244222
TEMPLATE
245-
bool CLASS::populate_with_metadata(const transaction& tx) const NOEXCEPT
246-
{
247-
BC_ASSERT(is_coinbase(tx));
248-
249-
// A coinbase tx is allowed only one input.
250-
const auto& input = tx.inputs_ptr()->front();
251-
252-
// Find any confirmed unspent duplicates of tx (unspent_coinbase_collision).
253-
const auto ec = unspent_duplicates(tx);
254-
if (ec == error::integrity)
255-
return false;
256-
257-
// The prevout of a coinbase is null (not an output of a coinbase tx).
258-
input->metadata.coinbase = false;
259-
input->metadata.spent = (ec != error::unspent_coinbase_collision);
260-
input->metadata.median_time_past = max_uint32;
261-
input->metadata.height = zero;
262-
return true;
263-
}
264-
265-
TEMPLATE
266-
bool CLASS::populate_with_metadata(const block& block) const NOEXCEPT
223+
bool CLASS::populate_without_metadata(const block& block) const NOEXCEPT
267224
{
268225
const auto& txs = block.transactions_ptr();
269226
if (txs->empty())
270227
return false;
271228

272229
auto result = true;
273-
const auto coinbase = populate_with_metadata(txs->front());
274230
std::for_each(std::next(txs->begin()), txs->end(),
275231
[&](const auto& tx) NOEXCEPT
276232
{
277-
const auto link = to_tx(tx.get_hash());
278-
result &= !link.is_terminal();
279233
const auto& ins = tx->inputs_ptr();
280234
std::for_each(ins->begin(), ins->end(), [&](const auto& in) NOEXCEPT
281235
{
282-
result &= populate_with_metadata(*in, link);
236+
result &= populate_without_metadata(*in);
283237
});
284238
});
285239

include/bitcoin/database/query.hpp

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -332,19 +332,16 @@ class query
332332
bool set(const transaction& tx) NOEXCEPT;
333333
bool set(const block& block, bool strong) NOEXCEPT;
334334

335-
/// False implies not fully populated, input.metadata is not populated.
335+
/// False implies missing prevouts, node input.metadata is populated.
336336
bool populate(const input& input) const NOEXCEPT;
337337
bool populate(const block& block) const NOEXCEPT;
338338
bool populate(const transaction& tx) const NOEXCEPT;
339339

340340
/// For testing only.
341-
/// False implies not fully populated, input.metadata is populated.
342-
bool populate_with_metadata(const block& block) const NOEXCEPT;
343-
bool populate_with_metadata(const transaction& tx) const NOEXCEPT;
344-
bool populate_with_metadata(const transaction& tx,
345-
const tx_link& link) const NOEXCEPT;
346-
bool populate_with_metadata(const input& input,
347-
const tx_link& link) const NOEXCEPT;
341+
/// False implies missing prevouts, input.metadata is not populated.
342+
bool populate_without_metadata(const input& input) const NOEXCEPT;
343+
bool populate_without_metadata(const block& block) const NOEXCEPT;
344+
bool populate_without_metadata(const transaction& tx) const NOEXCEPT;
348345

349346
/// Archival (surrogate-keyed).
350347
/// -----------------------------------------------------------------------

0 commit comments

Comments
 (0)