Skip to content

Commit 223121f

Browse files
authored
Merge pull request #719 from evoskuil/master
Refactor, style, comments, fixes.
2 parents 7711cc5 + a3fe49a commit 223121f

File tree

7 files changed

+125
-72
lines changed

7 files changed

+125
-72
lines changed

console/executor_store.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,7 @@ bool executor::hot_backup_store(bool details)
236236
full_node::store::tables.at(table));
237237
}))
238238
{
239+
// system::error::not_a_stream when disk is full.
239240
logger(format(BN_NODE_BACKUP_FAIL) % ec.message());
240241
return false;
241242
}
@@ -258,6 +259,7 @@ bool executor::cold_backup_store(bool details)
258259
full_node::store::tables.at(table));
259260
}))
260261
{
262+
// system::error::not_a_stream when disk is full.
261263
logger(format(BN_NODE_BACKUP_FAIL) % ec.message());
262264
return false;
263265
}

console/executor_test_reader.cpp

Lines changed: 69 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ using namespace std::chrono;
4141
using namespace std::placeholders;
4242

4343
// arbitrary testing (const).
44+
4445
void executor::read_test(bool dump) const
4546
{
4647
using namespace database;
@@ -809,18 +810,29 @@ void executor::read_test(bool dump) const
809810
logger(format("STOP (%1% secs)") % span.count());
810811
}
811812

812-
813813
// TODO: create a block/tx dumper.
814814
void executor::read_test(bool) const
815815
{
816-
constexpr auto hash511280 = base16_hash(
817-
"00000000000000000030b12ee5a31aaf553f49cdafa52698f70f0f0706f46d3d");
818-
816+
constexpr auto link = 600'000_size;
819817
const auto start = logger::now();
820-
const auto link = query_.to_header(hash511280);
821-
if (link.is_terminal())
818+
819+
const auto height = query_.get_height(link);
820+
if (height.is_terminal())
821+
{
822+
logger("height.is_terminal()");
823+
return;
824+
}
825+
826+
if (height != link)
827+
{
828+
logger("height != link");
829+
return;
830+
}
831+
832+
code ec{};
833+
if ((ec = query_.block_confirmable(link)))
822834
{
823-
logger("link.is_terminal()");
835+
logger(format("query_.block_confirmable: %1%") % ec.message());
824836
return;
825837
}
826838

@@ -855,24 +867,36 @@ void executor::read_test(bool) const
855867
state.timestamp = block->header().timestamp();
856868
state.minimum_block_version = 0;
857869
state.work_required = 0;
870+
871+
if (!block->populate(state))
872+
{
873+
logger("!block->populate(state)");
874+
return;
875+
}
876+
858877
if (!query_.populate(*block))
859878
{
860879
logger("!query_.populate(*block)");
861880
return;
862881
}
863882

864-
code ec{};
865883
if ((ec = block->check()))
866884
{
867-
logger(format("Block check: %1%") % ec.message());
885+
logger(format("Block check(): %1%") % ec.message());
886+
return;
887+
}
888+
889+
if ((ec = block->check(state)))
890+
{
891+
logger(format("Block check(state): %1%") % ec.message());
868892
return;
869893
}
870894

871-
const auto& coin = metadata_.configured.bitcoin;
872-
if ((ec = block->accept(state, coin.subsidy_interval_blocks,
873-
coin.initial_subsidy())))
895+
if ((ec = block->accept(state,
896+
metadata_.configured.bitcoin.subsidy_interval_blocks,
897+
metadata_.configured.bitcoin.initial_subsidy())))
874898
{
875-
logger(format("Block accept: %1%") % ec.message());
899+
logger(format("Block accept(state): %1%") % ec.message());
876900
return;
877901
}
878902

@@ -882,8 +906,39 @@ void executor::read_test(bool) const
882906
return;
883907
}
884908

909+
logger(format("segregated [%1%]") % to_int(block->is_segregated()));
910+
logger(format("segregated count [%1%]") % block->segregated());
911+
885912
const auto span = duration_cast<milliseconds>(logger::now() - start);
886-
logger(format("Validated block 511280 in %1% msec.") % span.count());
913+
logger(format("Validated block [%1%] in %2% msec.") % link % span.count());
914+
915+
////constexpr auto tx_hash = base16_hash(
916+
//// "eb2179db6c40bceb02cebcc5c99cf783ed6385b00767c7a5419fe530eaba8bff");
917+
////const auto tx_link = query_.to_tx(tx_hash);
918+
////const auto tx = query_.get_transaction(tx_link);
919+
////const auto result = query_.populate(*tx);
920+
////const auto size = tx->serialized_size(false);
921+
////const auto weight = tx->serialized_size(true);
922+
////const auto version = tx->version();
923+
////const auto locktime = tx->locktime();
924+
////const auto fee = tx->fee();
925+
////const auto sequence = tx->inputs_ptr()->at(0)->sequence();
926+
////const auto& in = tx->inputs_ptr()->at(0)->script();
927+
////const auto& out = tx->inputs_ptr()->at(0)->prevout->script();
928+
////const auto connect = tx->connect(state);
929+
930+
////logger(format("tx_hash [%1%]") % encode_hash(tx_hash));
931+
////logger(format("tx_link [%1%]") % tx_link.value);
932+
////logger(format("result [%1%]") % to_int(result));
933+
////logger(format("size [%1%]") % size);
934+
////logger(format("weight [%1%]") % weight);
935+
////logger(format("version [%1%]") % version);
936+
////logger(format("locktime [%1%]") % locktime);
937+
////logger(format("fee [%1%]") % fee);
938+
////logger(format("sequence [%1%]") % sequence);
939+
////logger(format("in [%1%]") % in.to_string(chain::flags::no_rules));
940+
////logger(format("out [%1%]") % out.to_string(chain::flags::no_rules));
941+
////logger(format("connect [%1%]") % connect.message());
887942
}
888943

889944
#endif // UNDEFINED

include/bitcoin/node/error.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@ enum error_t : uint8_t
8383
validate5,
8484
validate6,
8585
validate7,
86+
validate8,
87+
validate9,
8688
confirm1,
8789
confirm2,
8890
confirm3,

src/chasers/chaser_confirm.cpp

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -156,10 +156,14 @@ void chaser_confirm::do_regressed(height_t branch_point) NOEXCEPT
156156

157157
for (auto height = position(); height > branch_point; --height)
158158
{
159-
if (!query.set_unstrong(query.to_candidate(height)))
159+
const auto link = query.to_candidate(height);
160+
if (!query.set_unstrong(link))
160161
{
161-
fault(error::confirm1);
162-
return;
162+
if (query.get_block_state(link) != database::error::unassociated)
163+
{
164+
fault(error::confirm1);
165+
return;
166+
}
163167
}
164168
}
165169

@@ -215,22 +219,23 @@ void chaser_confirm::do_bump(height_t) NOEXCEPT
215219
// Confirmation query.
216220
if ((ec = query.block_confirmable(link)))
217221
{
218-
if (ec == database::error::integrity)
222+
if (database::error::error_category::contains(ec))
219223
{
220-
fault(error::confirm2);
224+
LOGR("Confirm fault [" << height << "] " << ec.message());
225+
fault(ec);
221226
return;
222227
}
223228

224229
// Unset from set before if not using prevout table.
225230
if (!prevout_ && !query.set_unstrong(link))
226231
{
227-
fault(error::confirm5);
232+
fault(error::confirm3);
228233
return;
229234
}
230235

231236
if (!query.set_block_unconfirmable(link))
232237
{
233-
fault(error::confirm3);
238+
fault(error::confirm4);
234239
return;
235240
}
236241

@@ -242,14 +247,14 @@ void chaser_confirm::do_bump(height_t) NOEXCEPT
242247

243248
if (!query.set_block_confirmable(link))
244249
{
245-
fault(error::confirm3);
250+
fault(error::confirm5);
246251
return;
247252
}
248253

249254
// Set after if using prevout table.
250255
if (prevout_ && !query.set_strong(link))
251256
{
252-
fault(error::confirm4);
257+
fault(error::confirm6);
253258
return;
254259
}
255260
}
@@ -258,32 +263,29 @@ void chaser_confirm::do_bump(height_t) NOEXCEPT
258263
// Set in either case.
259264
if (!query.set_strong(link))
260265
{
261-
fault(error::confirm5);
266+
fault(error::confirm7);
262267
return;
263268
}
264269
}
265-
else
270+
else if (ec == database::error::block_unconfirmable)
271+
{
272+
return;
273+
}
274+
else //// if (ec == database::error::unknown_state)
266275
{
267-
// With or without an error code, shouldn't be here.
268-
// database::error::unassociated [wait state ]
269-
// database::error::unvalidated [wait state ]
270-
// database::error::block_valid [canonical state ]
271-
// database::error::block_confirmable [resurrected state]
272-
// database::error::block_unconfirmable [shouldn't be here]
273-
// database::error::unknown_state [shouldn't be here]
274-
fault(error::confirm6);
276+
fault(error::confirm8);
275277
return;
276278
}
277279

278280
if (!query.set_filter_head(link))
279281
{
280-
fault(error::confirm7);
282+
fault(error::confirm9);
281283
return;
282284
}
283285

284286
////if (!set_organized(link, height))
285287
////{
286-
//// fault(error::confirm8);
288+
//// fault(error::confirm10);
287289
//// return;
288290
////}
289291

src/chasers/chaser_validate.cpp

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ void chaser_validate::do_bump(height_t) NOEXCEPT
191191

192192
if (bypass && !filter_)
193193
{
194-
complete_block(error::success, link, height);
194+
complete_block(database::error::success, link, height);
195195
}
196196
else
197197
{
@@ -242,8 +242,8 @@ void chaser_validate::validate_block(const header_link& link,
242242
POST(tracked_complete_block, ec, link, ctx.height);
243243
}
244244

245-
code chaser_validate::populate(bool bypass, const system::chain::block& block,
246-
const system::chain::context& ctx) NOEXCEPT
245+
code chaser_validate::populate(bool bypass, const chain::block& block,
246+
const chain::context& ctx) NOEXCEPT
247247
{
248248
const auto& query = archive();
249249

@@ -262,12 +262,11 @@ code chaser_validate::populate(bool bypass, const system::chain::block& block,
262262
return system::error::missing_previous_output;
263263
}
264264

265-
return error::success;
265+
return system::error::success;
266266
}
267267

268-
code chaser_validate::validate(bool bypass, const system::chain::block& block,
269-
const database::header_link& link,
270-
const system::chain::context& ctx) NOEXCEPT
268+
code chaser_validate::validate(bool bypass, const chain::block& block,
269+
const database::header_link& link, const chain::context& ctx) NOEXCEPT
271270
{
272271
code ec{};
273272
if (bypass)
@@ -282,10 +281,10 @@ code chaser_validate::validate(bool bypass, const system::chain::block& block,
282281
return ec;
283282

284283
if (!query.set_prevouts(link, block))
285-
return error::validate6;
284+
return error::validate8;
286285

287286
if (!query.set_block_valid(link, block.fees()))
288-
return error::validate7;
287+
return error::validate9;
289288

290289
return ec;
291290
}
@@ -307,22 +306,16 @@ void chaser_validate::complete_block(const code& ec, const header_link& link,
307306

308307
if (ec)
309308
{
310-
// Differentiated fault codes for troubleshooting.
311-
if (ec == error::validate1 ||
312-
ec == error::validate2 ||
313-
ec == error::validate3 ||
314-
ec == error::validate4 ||
315-
ec == error::validate5 ||
316-
ec == error::validate6 ||
317-
ec == error::validate7)
309+
if (node::error::error_category::contains(ec))
318310
{
311+
LOGR("Validate fault [" << height << "] " << ec.message());
319312
fault(ec);
320313
return;
321314
}
322315

323316
notify(ec, chase::unvalid, link);
324317
fire(events::block_unconfirmable, height);
325-
LOGR("Unconfirmable block [" << height << "] " << ec.message());
318+
LOGR("Invalid block [" << height << "] " << ec.message());
326319
return;
327320
}
328321

src/error.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ DEFINE_ERROR_T_MESSAGE_MAP(error)
7373
{ validate5, "validate5" },
7474
{ validate6, "validate6" },
7575
{ validate7, "validate7" },
76+
{ validate8, "validate8" },
77+
{ validate9, "validate9" },
7678
{ confirm1, "confirm1" },
7779
{ confirm2, "confirm2" },
7880
{ confirm3, "confirm3" },

0 commit comments

Comments
 (0)