Skip to content

Commit 8609655

Browse files
committed
Add confirmation integrity error differentiation.
1 parent c9d990d commit 8609655

File tree

5 files changed

+21
-24
lines changed

5 files changed

+21
-24
lines changed

include/bitcoin/database/error.hpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ enum error_t : uint8_t
3737
success,
3838
unknown_state,
3939
integrity,
40+
integrity1,
41+
integrity2,
42+
integrity3,
43+
integrity4,
4044

4145
/// memory map
4246
open_open,
@@ -87,10 +91,9 @@ enum error_t : uint8_t
8791

8892
/// validation/confirmation
8993
tx_connected,
90-
tx_preconnected,
9194
tx_disconnected,
92-
block_confirmable,
9395
block_valid,
96+
block_confirmable,
9497
block_unconfirmable,
9598
unassociated,
9699
unvalidated,

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ error::error_t CLASS::spent_prevout(const point_link& link, index index,
285285
// Iterate points by point hash (of output tx) because may be conflicts.
286286
auto point = store_.point.it(get_point_key(link));
287287
if (!point)
288-
return error::integrity;
288+
return error::integrity1;
289289

290290
do
291291
{
@@ -298,7 +298,7 @@ error::error_t CLASS::spent_prevout(const point_link& link, index index,
298298
do
299299
{
300300
if (!store_.spend.get(it, spend))
301-
return error::integrity;
301+
return error::integrity2;
302302

303303
// is_strong_tx (search) only called in the case of duplicate.
304304
// Other parent tx of spend is strong (confirmed spent prevout).
@@ -359,7 +359,7 @@ error::error_t CLASS::unspendable_prevout(uint32_t sequence, bool coinbase,
359359

360360
context out{};
361361
if (!get_context(out, block))
362-
return error::integrity;
362+
return error::integrity3;
363363

364364
// All txs with same hash must be coinbase or not.
365365
if (coinbase && !transaction::is_coinbase_mature(out.height, ctx.height))
@@ -533,7 +533,7 @@ code CLASS::block_confirmable(const header_link& link) const NOEXCEPT
533533
{
534534
context ctx{};
535535
if (!get_context(ctx, link))
536-
return error::integrity;
536+
return error::integrity4;
537537

538538
// This is never invoked (bip30).
539539
code ec{};

src/error.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ DEFINE_ERROR_T_MESSAGE_MAP(error)
3030
{ success, "success" },
3131
{ unknown_state, "unknown state" },
3232
{ integrity, "store corrupted" },
33+
{ integrity1, "store corrupted1" },
34+
{ integrity2, "store corrupted2" },
35+
{ integrity3, "store corrupted3" },
36+
{ integrity4, "store corrupted4" },
3337

3438
// memory map
3539
{ open_open, "opening open file" },
@@ -79,10 +83,9 @@ DEFINE_ERROR_T_MESSAGE_MAP(error)
7983

8084
// states
8185
{ tx_connected, "transaction connected" },
82-
{ tx_preconnected, "transaction preconnected" },
8386
{ tx_disconnected, "transaction disconnected" },
84-
{ block_confirmable, "block confirmable" },
8587
{ block_valid, "block valid" },
88+
{ block_confirmable, "block confirmable" },
8689
{ block_unconfirmable, "block unconfirmable" },
8790
{ unassociated, "unassociated" },
8891
{ 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/confirm.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -469,7 +469,7 @@ BOOST_AUTO_TEST_CASE(query_confirm__block_confirmable__bad_link__integrity)
469469
BOOST_REQUIRE_EQUAL(store.create(events_handler), error::success);
470470
BOOST_REQUIRE(query.initialize(test::genesis));
471471
BOOST_REQUIRE(query.set(test::block1, context{ bip68, 1, 0 }, false, false));
472-
BOOST_REQUIRE_EQUAL(query.block_confirmable(2), error::integrity);
472+
BOOST_REQUIRE_EQUAL(query.block_confirmable(2), error::integrity4);
473473
}
474474

475475
BOOST_AUTO_TEST_CASE(query_confirm__block_confirmable__null_points__success)

0 commit comments

Comments
 (0)