Skip to content

Commit d1c9426

Browse files
authored
Merge pull request #732 from evoskuil/master
Ensure that all consensus results are system::error codes.
2 parents afbdf23 + 97a3963 commit d1c9426

4 files changed

Lines changed: 8 additions & 75 deletions

File tree

include/bitcoin/database/error.hpp

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -111,14 +111,6 @@ enum error_t : uint8_t
111111
unvalidated,
112112
bypassed,
113113

114-
/// confirmation (require not just context but prevouts and/or metadata).
115-
missing_previous_output,
116-
coinbase_maturity,
117-
unspent_coinbase_collision,
118-
relative_time_locked,
119-
unconfirmed_spend,
120-
confirmed_double_spend,
121-
122114
/// tx archive
123115
tx_empty,
124116
tx_tx_allocate,

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

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@
2525
#include <bitcoin/database/define.hpp>
2626
#include <bitcoin/database/error.hpp>
2727

28+
// Consensus error codes must be system::error category in order for the node
29+
// to properly categorize the result.
30+
2831
namespace libbitcoin {
2932
namespace database {
3033

@@ -167,7 +170,7 @@ code CLASS::unspent_duplicates(const header_link& link,
167170
// bip30: all outputs of all previous duplicate coinbases must be spent.
168171
for (const auto& cb: coinbases)
169172
if (!is_spent_coinbase(cb))
170-
return error::unspent_coinbase_collision;
173+
return system::error::unspent_coinbase_collision;
171174

172175
return error::success;
173176
}
@@ -193,7 +196,7 @@ code CLASS::unspendable(uint32_t sequence, bool coinbase,
193196
// Unassociated to block is rare, generally implies a duplicate tx.
194197
// Not strong (in any block) implies the spend is not confirmed.
195198
if (strong.is_terminal() && !is_strong(tx))
196-
return error::unconfirmed_spend;
199+
return system::error::unconfirmed_spend;
197200

198201
const auto relative = ctx.is_enabled(system::chain::flags::bip68_rule) &&
199202
transaction::is_relative_locktime_applied(coinbase, version, sequence);
@@ -207,11 +210,11 @@ code CLASS::unspendable(uint32_t sequence, bool coinbase,
207210
if (relative &&
208211
input::is_relative_locked(sequence, ctx.height, ctx.mtp,
209212
out.height, out.mtp))
210-
return error::relative_time_locked;
213+
return system::error::relative_time_locked;
211214

212215
if (coinbase &&
213216
!transaction::is_coinbase_mature(out.height, ctx.height))
214-
return error::coinbase_maturity;
217+
return system::error::coinbase_maturity;
215218
}
216219

217220
return error::success;
@@ -260,7 +263,7 @@ code CLASS::populate_prevouts(point_sets& sets, size_t points,
260263
// Is any duplicated point in the block confirmed (generally empty).
261264
for (const auto& spender: cache.conflicts)
262265
if (is_strong_tx(spender))
263-
return error::confirmed_double_spend;
266+
return system::error::confirmed_double_spend;
264267

265268
// Augment spend.points with metadata.
266269
auto it = cache.spends.begin();

src/error.cpp

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -104,14 +104,6 @@ DEFINE_ERROR_T_MESSAGE_MAP(error)
104104
{ unvalidated, "unvalidated" },
105105
{ bypassed, "bypassed" },
106106

107-
// states
108-
{ missing_previous_output, "missing previous output" },
109-
{ coinbase_maturity, "coinbase maturity" },
110-
{ unspent_coinbase_collision, "unspent coinbase collision" },
111-
{ relative_time_locked, "relative time locked" },
112-
{ unconfirmed_spend, "unconfirmed spend" },
113-
{ confirmed_double_spend, "confirmed double spend" },
114-
115107
// tx archive
116108
{ tx_empty, "tx_empty" },
117109
{ tx_tx_allocate, "tx_tx_allocate" },

test/error.cpp

Lines changed: 0 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -473,60 +473,6 @@ BOOST_AUTO_TEST_CASE(error_t__code__bypassed__true_expected_message)
473473
BOOST_REQUIRE_EQUAL(ec.message(), "bypassed");
474474
}
475475

476-
BOOST_AUTO_TEST_CASE(error_t__code__missing_previous_output__true_expected_message)
477-
{
478-
constexpr auto value = error::missing_previous_output;
479-
const auto ec = code(value);
480-
BOOST_REQUIRE(ec);
481-
BOOST_REQUIRE(ec == value);
482-
BOOST_REQUIRE_EQUAL(ec.message(), "missing previous output");
483-
}
484-
485-
BOOST_AUTO_TEST_CASE(error_t__code__coinbase_maturity__true_expected_message)
486-
{
487-
constexpr auto value = error::coinbase_maturity;
488-
const auto ec = code(value);
489-
BOOST_REQUIRE(ec);
490-
BOOST_REQUIRE(ec == value);
491-
BOOST_REQUIRE_EQUAL(ec.message(), "coinbase maturity");
492-
}
493-
494-
BOOST_AUTO_TEST_CASE(error_t__code__unspent_coinbase_collision__true_expected_message)
495-
{
496-
constexpr auto value = error::unspent_coinbase_collision;
497-
const auto ec = code(value);
498-
BOOST_REQUIRE(ec);
499-
BOOST_REQUIRE(ec == value);
500-
BOOST_REQUIRE_EQUAL(ec.message(), "unspent coinbase collision");
501-
}
502-
503-
BOOST_AUTO_TEST_CASE(error_t__code__relative_time_locked__true_expected_message)
504-
{
505-
constexpr auto value = error::relative_time_locked;
506-
const auto ec = code(value);
507-
BOOST_REQUIRE(ec);
508-
BOOST_REQUIRE(ec == value);
509-
BOOST_REQUIRE_EQUAL(ec.message(), "relative time locked");
510-
}
511-
512-
BOOST_AUTO_TEST_CASE(error_t__code__unconfirmed_spend__true_expected_message)
513-
{
514-
constexpr auto value = error::unconfirmed_spend;
515-
const auto ec = code(value);
516-
BOOST_REQUIRE(ec);
517-
BOOST_REQUIRE(ec == value);
518-
BOOST_REQUIRE_EQUAL(ec.message(), "unconfirmed spend");
519-
}
520-
521-
BOOST_AUTO_TEST_CASE(error_t__code__confirmed_double_spend__true_expected_message)
522-
{
523-
constexpr auto value = error::confirmed_double_spend;
524-
const auto ec = code(value);
525-
BOOST_REQUIRE(ec);
526-
BOOST_REQUIRE(ec == value);
527-
BOOST_REQUIRE_EQUAL(ec.message(), "confirmed double spend");
528-
}
529-
530476
// tx archive
531477

532478
BOOST_AUTO_TEST_CASE(error_t__code__tx_empty__true_expected_message)

0 commit comments

Comments
 (0)