diff --git a/console/executor.cpp b/console/executor.cpp index 78fa5f83..4c3dbbc1 100644 --- a/console/executor.cpp +++ b/console/executor.cpp @@ -736,51 +736,16 @@ void executor::scan_collisions() const spend.shrink_to_fit(); } -// arbitrary testing (const). -void executor::read_test() const -{ - logger("Wire size computation."); - const auto start = fine_clock::now(); - const auto last = metadata_.configured.node.maximum_height; - - size_t size{}; - for (auto height = zero; !cancel_ && height <= last; ++height) - { - const auto link = query_.to_candidate(height); - if (link.is_terminal()) - { - logger(format("Max candidate height is (%1%).") % sub1(height)); - return; - } - - const auto bytes = query_.get_block_size(link); - if (is_zero(bytes)) - { - logger(format("Block (%1%) is not associated.") % height); - return; - } - - size += bytes; - } - - const auto span = duration_cast(fine_clock::now() - start); - logger(format("Wire size (%1%) at (%2%) in (%3%) ms.") % - size % last % span.count()); -} - -#if defined(UNDEFINED) - -void executor::read_test() const +void executor::read_test(bool dump) const { - constexpr auto start_tx = 15'000_u32; - constexpr auto target_count = 3000_size; + constexpr auto start_tx = 1'000'000'000_u32; + constexpr auto target_count = 100_size; // Set ensures unique addresses. std::set keys{}; auto tx = start_tx; - logger(format("Getting first [%1%] output address hashes.") % - target_count); + logger(format("Getting first [%1%] output address hashes.") % target_count); auto start = fine_clock::now(); while (!cancel_ && keys.size() < target_count) @@ -803,35 +768,24 @@ void executor::read_test() const struct out { - // Address hash, output link, first spender link. hash_digest address; - uint64_t output_fk; - uint64_t spend_fk; - uint64_t input_fk; - - // Output's tx link, hash, and block position. - uint64_t tx_fk; - hash_digest tx_hash; - uint16_t tx_position; - // Output tx's block link, hash, and height. uint32_t bk_fk; - hash_digest bk_hash; uint32_t bk_height; + hash_digest bk_hash; - // Spender's tx link, hash, and block position. - uint64_t in_tx_fk; - hash_digest in_tx_hash; - uint16_t in_tx_position; + uint32_t tx_fk; + size_t tx_position; + hash_digest tx_hash; - // Spender tx's block link, hash, and height. - uint32_t in_bk_fk; - hash_digest in_bk_hash; - uint32_t in_bk_height; + uint32_t sp_tx_fk; + hash_digest sp_tx_hash; - // Spender (first input) and output. - chain::output::cptr output{}; + uint64_t input_fk; chain::input::cptr input{}; + + uint64_t output_fk; + chain::output::cptr output{}; }; std_vector outs{}; @@ -841,6 +795,7 @@ void executor::read_test() const start = fine_clock::now(); for (auto& key: keys) { + size_t found{}; auto address_it = store_.address.it(key); if (cancel_ || address_it.self().is_terminal()) return; @@ -859,213 +814,153 @@ void executor::read_test() const const auto tx_fk = output.parent_fk; const auto block_fk = query_.to_block(tx_fk); - // Output tx block has height. - database::height_link bk_height{}; - table::header::get_height bk_header{}; - if (!block_fk.is_terminal()) - { - if (!store_.header.get(block_fk, bk_header)) - return; - else - bk_height = bk_header.height; - } - - // The block is confirmed by height. - table::height::record height_record{}; - const auto confirmed = store_.confirmed.get(bk_height, - height_record) && (height_record.header_fk == block_fk); - - // unconfirmed tx: max height/pos, null hash, terminal/zero links. - if (!confirmed) - { - outs.push_back(out - { - key, - out_fk, - max_uint64, // spend_fk - max_uint64, // input_fk - - tx_fk, - null_hash, - max_uint16, // position - - block_fk, - null_hash, - max_uint32, // height - - // in_tx - max_uint64, - null_hash, - max_uint16, // position - - // in_bk_tx - max_uint32, - null_hash, - max_uint32, // height - - nullptr, //query_.get_output(out_fk), - nullptr - }); - continue; - } + table::header::get_height header{}; + if (!store_.header.get(block_fk, header)) + return; - // Get confirmed output tx block position. - auto out_position = max_uint16; table::txs::get_position txs{ {}, tx_fk }; if (!store_.txs.get(query_.to_txs(block_fk), txs)) return; - else - out_position = possible_narrow_cast(txs.position); - // Get first spender only (may or may not be confirmed). - const auto spenders = query_.to_spenders(out_fk); spend_link sp_fk{}; - if (!spenders.empty()) - sp_fk = spenders.front(); - - // Get spender input, tx, position, block, height. - auto in_position = max_uint16; input_link in_fk{}; - tx_link in_tx_fk{}; - header_link in_bk_fk{}; - height_link in_bk_height{}; + tx_link sp_tx_fk{}; - if (!sp_fk.is_terminal()) + // Get first spender only (may or may not be confirmed). + const auto spenders = query_.to_spenders(out_fk); + if (!spenders.empty()) { + sp_fk = spenders.front(); table::spend::record spend{}; if (!store_.spend.get(sp_fk, spend)) - { return; - } - else - { - in_fk = spend.input_fk; - in_tx_fk = spend.parent_fk; - } - - // Get spender tx block. - in_bk_fk = query_.to_block(in_tx_fk); - // Get in_tx position in the confirmed block. - table::txs::get_position in_txs{ {}, in_tx_fk }; - if (!in_bk_fk.is_terminal()) - { - if (!store_.txs.get(query_.to_txs(in_bk_fk), in_txs)) - return; - else - in_position = possible_narrow_cast(in_txs.position); - } - - // Get spender input tx block height. - table::header::get_height in_bk_header{}; - if (!in_bk_fk.is_terminal()) - { - if (!store_.header.get(in_bk_fk, in_bk_header)) - return; - else - in_bk_height = in_bk_header.height; - } + in_fk = spend.input_fk; + sp_tx_fk = spend.parent_fk; } - // confirmed tx has block height and tx position. + ++found; outs.push_back(out { key, - out_fk, - sp_fk, - in_fk, - - tx_fk, - query_.get_tx_key(tx_fk), - out_position, block_fk, + header.height, query_.get_header_key(block_fk), - bk_height, - in_tx_fk, - query_.get_tx_key(in_tx_fk), - in_position, + tx_fk, + txs.position, + query_.get_tx_key(tx_fk), + + sp_tx_fk, + query_.get_tx_key(sp_tx_fk), - in_bk_fk, - query_.get_header_key(in_bk_fk), - in_bk_height, + in_fk, + query_.get_input(sp_fk), - query_.get_output(out_fk), - query_.get_input(sp_fk) + out_fk, + query_.get_output(out_fk) }); } while (address_it.advance()); + + logger(format("Fetched [%1%] unique payments to address [%2%].") % + found% encode_hash(key)); } span = duration_cast(fine_clock::now() - start); logger(format("Got all [%1%] payments to [%2%] addresses in [%3%] ms.") % outs.size() % keys.size() % span.count()); + if (!dump) + return; + // Write it all... -#if !defined(UNDEFINED) logger( "output_script_hash, " - "output_fk, " - "spend_fk, " - "input_fk, " - - "ouput_tx_fk, " - "ouput_tx_hash, " - "ouput_tx_pos, " "ouput_bk_fk, " - "ouput_bk_hash, " "ouput_bk_height, " - + "ouput_bk_hash, " + + "ouput_tx_fk, " + "ouput_tx_position, " + "ouput_tx_hash, " + "input_tx_fk, " "input_tx_hash, " - "input_tx_pos, " - - "input_bk_fk, " - "input_bk_hash, " - "input_bk_height, " - - "output_script " - "input_script, " + + "output_fk, " + "output_script, " + + "input_fk, " + "input_script" ); - + for (const auto& row: outs) { if (cancel_) break; - - const auto input = !row.input ? "{unspent}" : - row.input->script().to_string(chain::flags::all_rules); - + const auto output = !row.output ? "{error}" : row.output->script().to_string(chain::flags::all_rules); + + const auto input = !row.input ? "{unspent}" : + row.input->script().to_string(chain::flags::all_rules); - logger(format("%1%, %2%, %3%, %4%, %5%, %6%, %7%, %8%, %9%, %10%, %11%, %12%, %13%, %14%, %15%, %16%, %17%, %18%") % + logger(format("%1%, %2%, %3%, %4%, %5%, %6%, %7%, %8%, %9%, %10%, %11%, %12%, %13%") % encode_hash(row.address) % - row.output_fk % - row.spend_fk% - row.input_fk% - - row.tx_fk % - encode_hash(row.tx_hash) % - row.tx_position % - + row.bk_fk % - encode_hash(row.bk_hash) % row.bk_height % - - row.in_tx_fk % - encode_hash(row.in_tx_hash) % - row.in_tx_position % - - row.in_bk_fk % - encode_hash(row.in_bk_hash) % - row.in_bk_height % - - output% + encode_hash(row.bk_hash) % + + row.tx_fk % + row.tx_position % + encode_hash(row.tx_hash) % + + row.sp_tx_fk % + encode_hash(row.sp_tx_hash) % + + row.output_fk % + output % + + row.input_fk % input); } -#endif // UNDEFINED +} + +#if defined(UNDEFINED) + +// arbitrary testing (const). +void executor::read_test() const +{ + logger("Wire size computation."); + const auto start = fine_clock::now(); + const auto last = metadata_.configured.node.maximum_height; + + size_t size{}; + for (auto height = zero; !cancel_ && height <= last; ++height) + { + const auto link = query_.to_candidate(height); + if (link.is_terminal()) + { + logger(format("Max candidate height is (%1%).") % sub1(height)); + return; + } + + const auto bytes = query_.get_block_size(link); + if (is_zero(bytes)) + { + logger(format("Block (%1%) is not associated.") % height); + return; + } + + size += bytes; + } + + const auto span = duration_cast(fine_clock::now() - start); + logger(format("Wire size (%1%) at (%2%) in (%3%) ms.") % + size % last % span.count()); } void executor::read_test() const @@ -1644,7 +1539,7 @@ void executor::read_test() const #endif // UNDEFINED // arbitrary testing (non-const). -void executor::write_test() +void executor::write_test(bool) { logger("No write test implemented."); } @@ -2217,7 +2112,7 @@ bool executor::do_read() !open_store()) return false; - read_test(); + read_test(true); return close_store(); } @@ -2229,7 +2124,7 @@ bool executor::do_write() !open_store()) return false; - write_test(); + write_test(true); return close_store(); } @@ -2327,7 +2222,7 @@ void executor::do_menu() const // [t]est void executor::do_test() const { - read_test(); + read_test(false); } // [w]ork diff --git a/console/executor.hpp b/console/executor.hpp index cd3a3262..80c7fbb7 100644 --- a/console/executor.hpp +++ b/console/executor.hpp @@ -123,8 +123,8 @@ class executor void scan_buckets() const; void scan_collisions() const; void scan_slabs() const; - void read_test() const; - void write_test(); + void read_test(bool dump) const; + void write_test(bool dump); rotator_t create_log_sink() const; system::ofstream create_event_sink() const;