Skip to content

Commit 7466b06

Browse files
authored
Merge pull request #542 from evoskuil/master
Rem set_txs_connected/set_tx_preconnected, differentiate integrity errors.
2 parents c9d990d + d7e3399 commit 7466b06

File tree

8 files changed

+69
-120
lines changed

8 files changed

+69
-120
lines changed

include/bitcoin/database/error.hpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,9 @@ enum error_t : uint8_t
8787

8888
/// validation/confirmation
8989
tx_connected,
90-
tx_preconnected,
9190
tx_disconnected,
92-
block_confirmable,
9391
block_valid,
92+
block_confirmable,
9493
block_unconfirmable,
9594
unassociated,
9695
unvalidated,

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

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -283,14 +283,18 @@ error::error_t CLASS::spent_prevout(const point_link& link, index index,
283283
// The upside is half the prevout size (read/write/page) and store increase.
284284

285285
// Iterate points by point hash (of output tx) because may be conflicts.
286-
auto point = store_.point.it(get_point_key(link));
286+
// Search key must be passed as an l-value as it is held by reference.
287+
const auto point_sk = get_point_key(link);
288+
auto point = store_.point.it(point_sk);
287289
if (!point)
288290
return error::integrity;
289291

290292
do
291293
{
292294
// Iterate all spends of the point to find double spends.
293-
auto it = store_.spend.it(table::spend::compose(point.self(), index));
295+
// Search key must be passed as an l-value as it is held by reference.
296+
const auto spend_sk = table::spend::compose(point.self(), index);
297+
auto it = store_.spend.it(spend_sk);
294298
if (!it)
295299
return error::success;
296300

@@ -494,12 +498,14 @@ spend_sets CLASS::to_spend_sets(const header_link& link) const NOEXCEPT
494498
// Coinbase tx does not spend so is not retrieved.
495499
const auto txs = to_spending_transactions(link);
496500

501+
// Empty here is normal.
497502
if (txs.empty())
498503
return {};
499504

500505
spend_sets sets{ txs.size() };
501506
const auto to_set = [this](const auto& tx) NOEXCEPT
502507
{
508+
// Empty here implies integrity fault.
503509
return to_spend_set(tx);
504510
};
505511

@@ -540,6 +546,7 @@ code CLASS::block_confirmable(const header_link& link) const NOEXCEPT
540546
if ((ec = unspent_duplicates(link, ctx)))
541547
return ec;
542548

549+
// Empty here could imply integrity fault.
543550
const auto sets = to_spend_sets(link);
544551
if (sets.empty())
545552
return ec;
@@ -753,6 +760,8 @@ bool CLASS::initialize(const block& genesis) NOEXCEPT
753760
BC_ASSERT(!is_initialized());
754761
BC_ASSERT(is_one(genesis.transactions_ptr()->size()));
755762

763+
// TODO: add genesis block neutrino head and body when neutrino is enabled.
764+
756765
// ========================================================================
757766
const auto scope = store_.get_transactor();
758767

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

Lines changed: 41 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -36,16 +36,16 @@ inline code CLASS::to_block_code(
3636
{
3737
switch (value)
3838
{
39-
// Block satisfies validation rules (prevouts unverified).
39+
// Transitional: Satisfies validation rules (prevouts unverified).
4040
case schema::block_state::valid:
4141
return error::block_valid;
42-
// Final: Block satisfies confirmation rules (prevouts).
42+
// Final: Satisfies confirmation rules (prevouts confirmable).
4343
case schema::block_state::confirmable:
4444
return error::block_confirmable;
45-
// Final: Block does not satisfy validation/confirmation rules.
45+
// Final: Does not satisfy either validation or confirmation rules.
4646
case schema::block_state::unconfirmable:
4747
return error::block_unconfirmable;
48-
// Block has no recorded state, may be under checkpoint or milestone.
48+
// Fault: Has no state, should not happen when read from store.
4949
default:
5050
return error::unknown_state;
5151
}
@@ -61,16 +61,13 @@ inline code CLASS::to_tx_code(
6161
// All states below are relevant only to the associated validation context.
6262
switch (value)
6363
{
64-
// Tx is valid in the case where standard prevouts are matched.
65-
case schema::tx_state::preconnected:
66-
return error::tx_preconnected;
67-
// Final: Tx is valid (passed check, accept, and connect).
64+
// Final: Is valid (passed check, accept, and connect).
6865
case schema::tx_state::connected:
6966
return error::tx_connected;
70-
// Final: Tx is not valid (failed check, accept, or connect).
67+
// Final: Is not valid (failed check, accept, or connect).
7168
case schema::tx_state::disconnected:
7269
return error::tx_disconnected;
73-
// Tx has no recorded state, may be under checkpoint or milestone.
70+
// Fault: Has no state, should not happen when read from store.
7471
default:
7572
return error::unknown_state;
7673
}
@@ -307,25 +304,6 @@ bool CLASS::set_block_unconfirmable(const header_link& link) NOEXCEPT
307304
// ========================================================================
308305
}
309306

310-
TEMPLATE
311-
bool CLASS::set_tx_preconnected(const tx_link& link,
312-
const context& ctx) NOEXCEPT
313-
{
314-
// ========================================================================
315-
const auto scope = store_.get_transactor();
316-
317-
// Clean single allocation failure (e.g. disk full).
318-
return store_.validated_tx.put(link, table::validated_tx::slab
319-
{
320-
{},
321-
ctx,
322-
schema::tx_state::preconnected,
323-
0, // fee
324-
0 // sigops
325-
});
326-
// ========================================================================
327-
}
328-
329307
TEMPLATE
330308
bool CLASS::set_tx_disconnected(const tx_link& link,
331309
const context& ctx) NOEXCEPT
@@ -367,40 +345,40 @@ bool CLASS::set_tx_connected(const tx_link& link, const context& ctx,
367345
// ========================================================================
368346
}
369347

370-
TEMPLATE
371-
bool CLASS::set_txs_connected(const header_link& link) NOEXCEPT
372-
{
373-
context ctx{};
374-
if (!get_context(ctx, link))
375-
return false;
376-
377-
const auto txs = to_transactions(link);
378-
if (txs.empty())
379-
return false;
380-
381-
// FOR PERFORMANCE EVALUATION ONLY.
382-
constexpr uint64_t fee = 99;
383-
constexpr size_t sigops = 42;
384-
using sigs = linkage<schema::sigops>;
385-
386-
// ========================================================================
387-
const auto scope = store_.get_transactor();
388-
389-
// Clean single allocation failure (e.g. disk full).
390-
return std_all_of(bc::seq, txs.begin(), txs.end(),
391-
[&](const tx_link& fk) NOEXCEPT
392-
{
393-
return store_.validated_tx.put(fk, table::validated_tx::slab
394-
{
395-
{},
396-
ctx,
397-
schema::tx_state::connected,
398-
fee,
399-
system::possible_narrow_cast<sigs::integer>(sigops)
400-
});
401-
});
402-
// ========================================================================
403-
}
348+
////TEMPLATE
349+
////bool CLASS::set_txs_connected(const header_link& link) NOEXCEPT
350+
////{
351+
//// context ctx{};
352+
//// if (!get_context(ctx, link))
353+
//// return false;
354+
////
355+
//// const auto txs = to_transactions(link);
356+
//// if (txs.empty())
357+
//// return false;
358+
////
359+
//// // FOR PERFORMANCE EVALUATION ONLY.
360+
//// constexpr uint64_t fee = 99;
361+
//// constexpr size_t sigops = 42;
362+
//// using sigs = linkage<schema::sigops>;
363+
////
364+
//// // ========================================================================
365+
//// const auto scope = store_.get_transactor();
366+
////
367+
//// // Clean single allocation failure (e.g. disk full).
368+
//// return std_all_of(bc::seq, txs.begin(), txs.end(),
369+
//// [&](const tx_link& fk) NOEXCEPT
370+
//// {
371+
//// return store_.validated_tx.put(fk, table::validated_tx::slab
372+
//// {
373+
//// {},
374+
//// ctx,
375+
//// schema::tx_state::connected,
376+
//// fee,
377+
//// system::possible_narrow_cast<sigs::integer>(sigops)
378+
//// });
379+
//// });
380+
//// // ========================================================================
381+
////}
404382

405383
} // namespace database
406384
} // namespace libbitcoin

include/bitcoin/database/query.hpp

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -478,10 +478,6 @@ class query
478478
bool set_block_valid(const header_link& link, uint64_t fees) NOEXCEPT;
479479
bool set_block_unconfirmable(const header_link& link) NOEXCEPT;
480480
bool set_block_confirmable(const header_link& link) NOEXCEPT;
481-
482-
// set_txs_connected is FOR PERFORMANCE EVALUATION ONLY.
483-
bool set_txs_connected(const header_link& link) NOEXCEPT;
484-
bool set_tx_preconnected(const tx_link& link, const context& ctx) NOEXCEPT;
485481
bool set_tx_disconnected(const tx_link& link, const context& ctx) NOEXCEPT;
486482
bool set_tx_connected(const tx_link& link, const context& ctx,
487483
uint64_t fee, size_t sigops) NOEXCEPT;
@@ -547,13 +543,14 @@ class query
547543
bool set_filter_head(const header_link& link,
548544
const hash_digest& head) NOEXCEPT;
549545

546+
// TODO: protected
547+
spend_set to_spend_set(const tx_link& link) const NOEXCEPT;
548+
spend_sets to_spend_sets(const header_link& link) const NOEXCEPT;
549+
550550
protected:
551551
/// Translate.
552552
/// -----------------------------------------------------------------------
553553

554-
spend_set to_spend_set(const tx_link& link) const NOEXCEPT;
555-
spend_sets to_spend_sets(const header_link& link) const NOEXCEPT;
556-
557554
uint32_t to_spend_index(const tx_link& parent_fk,
558555
const spend_link& input_fk) const NOEXCEPT;
559556
uint32_t to_output_index(const tx_link& parent_fk,

include/bitcoin/database/tables/schema.hpp

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ namespace schema
5858
constexpr auto candidate = "candidate";
5959
constexpr auto confirmed = "confirmed";
6060
constexpr auto strong_tx = "strong_tx";
61-
////constexpr auto spent_out = "spent_out";
6261
}
6362

6463
namespace caches
@@ -89,16 +88,15 @@ namespace schema
8988

9089
enum block_state : uint8_t
9190
{
92-
confirmable = 0, // final
93-
valid = 1, // transitional
94-
unconfirmable = 2 // final
91+
confirmable = 0, // final
92+
valid = 1, // transitional
93+
unconfirmable = 2 // final
9594
};
9695

9796
enum tx_state : uint8_t
9897
{
99-
connected = 0, // final
100-
preconnected = 1, // transitional
101-
disconnected = 2 // final
98+
connected = 0, // final
99+
disconnected = 1 // final
102100
};
103101

104102
/// Values.

src/error.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,9 @@ DEFINE_ERROR_T_MESSAGE_MAP(error)
7979

8080
// states
8181
{ tx_connected, "transaction connected" },
82-
{ tx_preconnected, "transaction preconnected" },
8382
{ tx_disconnected, "transaction disconnected" },
84-
{ block_confirmable, "block confirmable" },
8583
{ block_valid, "block valid" },
84+
{ block_confirmable, "block confirmable" },
8685
{ block_unconfirmable, "block unconfirmable" },
8786
{ unassociated, "unassociated" },
8887
{ unvalidated, "unvalidated" },

test/error.cpp

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -365,15 +365,6 @@ BOOST_AUTO_TEST_CASE(error_t__code__tx_connected__true_exected_message)
365365
BOOST_REQUIRE_EQUAL(ec.message(), "transaction connected");
366366
}
367367

368-
BOOST_AUTO_TEST_CASE(error_t__code__tx_preconnected__true_exected_message)
369-
{
370-
constexpr auto value = error::tx_preconnected;
371-
const auto ec = code(value);
372-
BOOST_REQUIRE(ec);
373-
BOOST_REQUIRE(ec == value);
374-
BOOST_REQUIRE_EQUAL(ec.message(), "transaction preconnected");
375-
}
376-
377368
BOOST_AUTO_TEST_CASE(error_t__code__tx_disconnected__true_exected_message)
378369
{
379370
constexpr auto value = error::tx_disconnected;
@@ -383,22 +374,22 @@ BOOST_AUTO_TEST_CASE(error_t__code__tx_disconnected__true_exected_message)
383374
BOOST_REQUIRE_EQUAL(ec.message(), "transaction disconnected");
384375
}
385376

386-
BOOST_AUTO_TEST_CASE(error_t__code__block_confirmable__true_exected_message)
377+
BOOST_AUTO_TEST_CASE(error_t__code__block_valid__true_exected_message)
387378
{
388-
constexpr auto value = error::block_confirmable;
379+
constexpr auto value = error::block_valid;
389380
const auto ec = code(value);
390381
BOOST_REQUIRE(ec);
391382
BOOST_REQUIRE(ec == value);
392-
BOOST_REQUIRE_EQUAL(ec.message(), "block confirmable");
383+
BOOST_REQUIRE_EQUAL(ec.message(), "block valid");
393384
}
394385

395-
BOOST_AUTO_TEST_CASE(error_t__code__block_valid__true_exected_message)
386+
BOOST_AUTO_TEST_CASE(error_t__code__block_confirmable__true_exected_message)
396387
{
397-
constexpr auto value = error::block_valid;
388+
constexpr auto value = error::block_confirmable;
398389
const auto ec = code(value);
399390
BOOST_REQUIRE(ec);
400391
BOOST_REQUIRE(ec == value);
401-
BOOST_REQUIRE_EQUAL(ec.message(), "block valid");
392+
BOOST_REQUIRE_EQUAL(ec.message(), "block confirmable");
402393
}
403394

404395
BOOST_AUTO_TEST_CASE(error_t__code__block_unconfirmable__true_exected_message)

test/query/validate.cpp

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -349,28 +349,6 @@ BOOST_AUTO_TEST_CASE(query_validate__get_tx_state__connected_in_context__tx_conn
349349
BOOST_REQUIRE_EQUAL(sigops, expected_sigops);
350350
}
351351

352-
BOOST_AUTO_TEST_CASE(query_validate__get_tx_state__connected_in_context__tx_preconnected)
353-
{
354-
settings settings{};
355-
settings.path = TEST_DIRECTORY;
356-
test::chunk_store store{ settings };
357-
test::query_accessor query{ store };
358-
BOOST_REQUIRE_EQUAL(store.create(events_handler), error::success);
359-
BOOST_REQUIRE(query.initialize(test::genesis));
360-
BOOST_REQUIRE(query.set(test::block1, context{}, false, false));
361-
BOOST_REQUIRE(query.set(test::block2, context{}, false, false));
362-
BOOST_REQUIRE(query.set(test::block3, context{}, false, false));
363-
364-
uint64_t fee{};
365-
size_t sigops{};
366-
constexpr context ctx{ 7, 8, 9 };
367-
BOOST_REQUIRE(query.set_tx_preconnected(3, ctx));
368-
BOOST_REQUIRE_EQUAL(query.get_tx_state(3, ctx), error::tx_preconnected);
369-
BOOST_REQUIRE_EQUAL(query.get_tx_state(fee, sigops, 3, ctx), error::tx_preconnected);
370-
BOOST_REQUIRE_EQUAL(fee, 0u);
371-
BOOST_REQUIRE_EQUAL(sigops, 0u);
372-
}
373-
374352
BOOST_AUTO_TEST_CASE(query_validate__get_tx_state__connected_in_context__tx_disconnected)
375353
{
376354
settings settings{};

0 commit comments

Comments
 (0)