From 3c93e8cdb4e23e0d02399bb1d389ad4d20a6aba1 Mon Sep 17 00:00:00 2001 From: evoskuil Date: Thu, 31 Oct 2024 00:10:16 -0400 Subject: [PATCH 1/5] Avoid assigning shared ptr dereference to reference. --- .../bitcoin/database/impl/query/archive.ipp | 62 +++++++++---------- test/query/archive.cpp | 42 ++++++------- test/tables/caches/buffer.cpp | 4 +- 3 files changed, 54 insertions(+), 54 deletions(-) diff --git a/include/bitcoin/database/impl/query/archive.ipp b/include/bitcoin/database/impl/query/archive.ipp index 17c706e2..b8da31e1 100644 --- a/include/bitcoin/database/impl/query/archive.ipp +++ b/include/bitcoin/database/impl/query/archive.ipp @@ -154,8 +154,8 @@ bool CLASS::populate(const transaction& tx) const NOEXCEPT BC_ASSERT(!tx.is_coinbase()); auto result = true; - const auto& ins = *tx.inputs_ptr(); - std::for_each(ins.begin(), ins.end(), [&](const auto& in) NOEXCEPT + const auto& ins = tx.inputs_ptr(); + std::for_each(ins->begin(), ins->end(), [&](const auto& in) NOEXCEPT { result &= populate(*in); }); @@ -166,16 +166,16 @@ bool CLASS::populate(const transaction& tx) const NOEXCEPT TEMPLATE bool CLASS::populate(const block& block) const NOEXCEPT { - const auto& txs = *block.transactions_ptr(); - if (txs.empty()) + const auto& txs = block.transactions_ptr(); + if (txs->empty()) return false; auto result = true; - std::for_each(std::next(txs.begin()), txs.end(), + std::for_each(std::next(txs->begin()), txs->end(), [&](const auto& tx) NOEXCEPT { - const auto& ins = *tx->inputs_ptr(); - std::for_each(ins.begin(), ins.end(), [&](const auto& in) NOEXCEPT + const auto& ins = tx->inputs_ptr(); + std::for_each(ins->begin(), ins->end(), [&](const auto& in) NOEXCEPT { result &= populate(*in); }); @@ -225,8 +225,8 @@ bool CLASS::populate_with_metadata(const transaction& tx, const tx_link& link) const NOEXCEPT { auto result = true; - const auto& ins = *tx.inputs_ptr(); - std::for_each(ins.begin(), ins.end(), [&](const auto& in) NOEXCEPT + const auto& ins = tx.inputs_ptr(); + std::for_each(ins->begin(), ins->end(), [&](const auto& in) NOEXCEPT { result &= populate_with_metadata(*in, link); }); @@ -240,7 +240,7 @@ bool CLASS::populate_with_metadata(const transaction& tx) const NOEXCEPT BC_ASSERT(is_coinbase(tx)); // A coinbase tx is allowed only one input. - const auto& input = *tx.inputs_ptr()->front(); + const auto& input = tx.inputs_ptr()->front(); // Find any confirmed unspent duplicates of tx (unspent_coinbase_collision). const auto ec = unspent_duplicates(tx); @@ -248,29 +248,29 @@ bool CLASS::populate_with_metadata(const transaction& tx) const NOEXCEPT return false; // The prevout of a coinbase is null (not an output of a coinbase tx). - input.metadata.coinbase = false; - input.metadata.spent = (ec != error::unspent_coinbase_collision); - input.metadata.median_time_past = max_uint32; - input.metadata.height = zero; + input->metadata.coinbase = false; + input->metadata.spent = (ec != error::unspent_coinbase_collision); + input->metadata.median_time_past = max_uint32; + input->metadata.height = zero; return true; } TEMPLATE bool CLASS::populate_with_metadata(const block& block) const NOEXCEPT { - const auto& txs = *block.transactions_ptr(); - if (txs.empty()) + const auto& txs = block.transactions_ptr(); + if (txs->empty()) return false; auto result = true; - const auto coinbase = populate_with_metadata(txs.front()); - std::for_each(std::next(txs.begin()), txs.end(), + const auto coinbase = populate_with_metadata(txs->front()); + std::for_each(std::next(txs->begin()), txs->end(), [&](const auto& tx) NOEXCEPT { const auto link = to_tx(tx.get_hash()); result &= !link.is_terminal(); - const auto& ins = *tx->inputs_ptr(); - std::for_each(ins.begin(), ins.end(), [&](const auto& in) NOEXCEPT + const auto& ins = tx->inputs_ptr(); + std::for_each(ins->begin(), ins->end(), [&](const auto& in) NOEXCEPT { result &= populate_with_metadata(*in, link); }); @@ -743,15 +743,15 @@ code CLASS::set_code(tx_link& out_fk, const transaction& tx) NOEXCEPT const auto& key = tx.get_hash(false); // Declare puts record. - const auto& ins = *tx.inputs_ptr(); - const auto& outs = *tx.outputs_ptr(); + const auto& ins = tx.inputs_ptr(); + const auto& outs = tx.outputs_ptr(); table::puts::slab puts{}; - puts.spend_fks.reserve(ins.size()); - puts.out_fks.reserve(outs.size()); + puts.spend_fks.reserve(ins->size()); + puts.out_fks.reserve(outs->size()); // Declare spends buffer. std_vector spends{}; - spends.reserve(ins.size()); + spends.reserve(ins->size()); // TODO: eliminate shared memory pointer reallocations. // ======================================================================== @@ -765,13 +765,13 @@ code CLASS::set_code(tx_link& out_fk, const transaction& tx) NOEXCEPT // Allocate spend records. // Clean single allocation failure (e.g. disk full). - const auto count = possible_narrow_cast(ins.size()); + const auto count = possible_narrow_cast(ins->size()); auto spend_fk = store_.spend.allocate(count); if (spend_fk.is_terminal()) return error::tx_spend_allocate; // Commit input records (spend records not indexed). - for (const auto& in: ins) + for (const auto& in: *ins) { // Commit input record. // Safe allocation failure, blob linked by unindexed spend. @@ -833,7 +833,7 @@ code CLASS::set_code(tx_link& out_fk, const transaction& tx) NOEXCEPT } // Commit output records. - for (const auto& out: outs) + for (const auto& out: *outs) { // Safe allocation failure, blob unlinked. output_link output_fk{}; @@ -864,8 +864,8 @@ code CLASS::set_code(tx_link& out_fk, const transaction& tx) NOEXCEPT { {}, tx, - system::possible_narrow_cast(ins.size()), - system::possible_narrow_cast(outs.size()), + system::possible_narrow_cast(ins->size()), + system::possible_narrow_cast(outs->size()), puts_fk })) { @@ -888,7 +888,7 @@ code CLASS::set_code(tx_link& out_fk, const transaction& tx) NOEXCEPT if (address_enabled()) { auto output_fk = puts.out_fks.begin(); - for (const auto& out: outs) + for (const auto& out: *outs) { // Safe allocation failure, unindexed tx outputs linked by address, // others unlinked. A replay of committed addresses without indexed diff --git a/test/query/archive.cpp b/test/query/archive.cpp index 64b54a80..911a3b3f 100644 --- a/test/query/archive.cpp +++ b/test/query/archive.cpp @@ -1273,9 +1273,9 @@ BOOST_AUTO_TEST_CASE(query_archive__get_input__genesis__expected) BOOST_REQUIRE(query.set(test::genesis, test::context, false, false)); const auto tx = test::genesis.transactions_ptr()->front(); - const auto& input = *tx->inputs_ptr()->front(); - BOOST_REQUIRE(input == *query.get_input(query.to_tx(tx->hash(false)), 0u)); - BOOST_REQUIRE(input == *query.get_input(0)); + const auto input = tx->inputs_ptr()->front(); + BOOST_REQUIRE(*input == *query.get_input(query.to_tx(tx->hash(false)), 0u)); + BOOST_REQUIRE(*input == *query.get_input(0)); } BOOST_AUTO_TEST_CASE(query_archive__get_inputs__tx_not_found__nullptr) @@ -1328,10 +1328,10 @@ BOOST_AUTO_TEST_CASE(query_archive__get_output__genesis__expected) BOOST_REQUIRE(query.set(test::genesis, test::context, false, false)); const auto tx = test::genesis.transactions_ptr()->front(); - const auto& output1 = *tx->outputs_ptr()->front(); - BOOST_REQUIRE(output1 == *query.get_output(query.to_tx(tx->hash(false)), 0u)); - BOOST_REQUIRE(output1 == *query.get_output({ tx->hash(false), 0u })); - BOOST_REQUIRE(output1 == *query.get_output(0)); + const auto output1 = tx->outputs_ptr()->front(); + BOOST_REQUIRE(*output1 == *query.get_output(query.to_tx(tx->hash(false)), 0u)); + BOOST_REQUIRE(*output1 == *query.get_output({ tx->hash(false), 0u })); + BOOST_REQUIRE(*output1 == *query.get_output(0)); } BOOST_AUTO_TEST_CASE(query_archive__get_outputs__tx_not_found__nullptr) @@ -1473,11 +1473,11 @@ BOOST_AUTO_TEST_CASE(query_archive__get_spenders__unspent_or_not_found__expected //// BOOST_REQUIRE_EQUAL(query.get_spenders(1, 2)->size(), 0u); //// //// // Match the two spenders. -//// const auto& block_inputs = *test::block2a.transactions_ptr()->front()->inputs_ptr(); -//// BOOST_REQUIRE(*query.get_spenders(query.to_output(1, 0))->front() == *block_inputs.front()); -//// BOOST_REQUIRE(*query.get_spenders(query.to_output(1, 1))->front() == *block_inputs.back()); -//// BOOST_REQUIRE(*query.get_spenders(1, 0)->front() == *block_inputs.front()); -//// BOOST_REQUIRE(*query.get_spenders(1, 1)->front() == *block_inputs.back()); +//// const auto block_inputs = test::block2a.transactions_ptr()->front()->inputs_ptr(); +//// BOOST_REQUIRE(*query.get_spenders(query.to_output(1, 0))->front() == *(*block_inputs).front()); +//// BOOST_REQUIRE(*query.get_spenders(query.to_output(1, 1))->front() == *(*block_inputs).back()); +//// BOOST_REQUIRE(*query.get_spenders(1, 0)->front() == *(*block_inputs).front()); +//// BOOST_REQUIRE(*query.get_spenders(1, 1)->front() == *(*block_inputs).back()); //// //// // Each of the two outputs of block1a spent twice (two unconfirmed double spends). //// BOOST_REQUIRE(query.set(test::tx4)); @@ -1489,15 +1489,15 @@ BOOST_AUTO_TEST_CASE(query_archive__get_spenders__unspent_or_not_found__expected //// BOOST_REQUIRE_EQUAL(query.get_spenders(1, 2)->size(), 0u); //// //// // Match the four spenders. -//// const auto& tx_inputs = *test::tx4.inputs_ptr(); -//// BOOST_REQUIRE(*query.get_spenders(query.to_output(1, 0))->front() == *tx_inputs.front()); -//// BOOST_REQUIRE(*query.get_spenders(query.to_output(1, 1))->front() == *tx_inputs.back()); -//// BOOST_REQUIRE(*query.get_spenders(query.to_output(1, 0))->back() == *block_inputs.front()); -//// BOOST_REQUIRE(*query.get_spenders(query.to_output(1, 1))->back() == *block_inputs.back()); -//// BOOST_REQUIRE(*query.get_spenders(1, 0)->front() == *tx_inputs.front()); -//// BOOST_REQUIRE(*query.get_spenders(1, 1)->front() == *tx_inputs.back()); -//// BOOST_REQUIRE(*query.get_spenders(1, 0)->back() == *block_inputs.front()); -//// BOOST_REQUIRE(*query.get_spenders(1, 1)->back() == *block_inputs.back()); +//// const auto tx_inputs = test::tx4.inputs_ptr(); +//// BOOST_REQUIRE(*query.get_spenders(query.to_output(1, 0))->front() == *(*tx_inputs).front()); +//// BOOST_REQUIRE(*query.get_spenders(query.to_output(1, 1))->front() == *(*tx_inputs).back()); +//// BOOST_REQUIRE(*query.get_spenders(query.to_output(1, 0))->back() == *(*block_inputs).front()); +//// BOOST_REQUIRE(*query.get_spenders(query.to_output(1, 1))->back() == *(*block_inputs).back()); +//// BOOST_REQUIRE(*query.get_spenders(1, 0)->front() == *(*tx_inputs).front()); +//// BOOST_REQUIRE(*query.get_spenders(1, 1)->front() == *(*tx_inputs).back()); +//// BOOST_REQUIRE(*query.get_spenders(1, 0)->back() == *(*block_inputs).front()); +//// BOOST_REQUIRE(*query.get_spenders(1, 1)->back() == *(*block_inputs).back()); ////} BOOST_AUTO_TEST_CASE(query_archive__get_value__genesis__expected) diff --git a/test/tables/caches/buffer.cpp b/test/tables/caches/buffer.cpp index 04094491..a67a5d1e 100644 --- a/test/tables/caches/buffer.cpp +++ b/test/tables/caches/buffer.cpp @@ -24,11 +24,11 @@ ////using namespace system; ////const chain::transaction empty{}; ////const auto genesis = system::settings{ system::chain::selection::mainnet }.genesis_block; -////const auto& genesis_tx = *genesis.transactions_ptr()->front(); +////const auto genesis_tx = genesis.transactions_ptr()->front(); ////const table::buffer::key key1{ 0x01, 0x02, 0x03, 0x04 }; ////const table::buffer::key key2{ 0xa1, 0xa2, 0xa3, 0xa4 }; ////const table::buffer::slab slab1{ {}, empty }; -////const table::buffer::slab slab2{ {}, genesis_tx }; +////const table::buffer::slab slab2{ {}, *genesis_tx }; ////const data_chunk expected_head = base16_chunk ////( //// "0000000000" From 4d6e9073add3330dcdfa9e01ea2e1a3ab1ca5f88 Mon Sep 17 00:00:00 2001 From: evoskuil Date: Mon, 28 Oct 2024 21:32:19 -0400 Subject: [PATCH 2/5] git.ignore /build directory. --- .gitignore | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/.gitignore b/.gitignore index 0f0459c4..334e771f 100644 --- a/.gitignore +++ b/.gitignore @@ -8,7 +8,9 @@ Makefile Makefile.in libbitcoin-database.pc +bin obj +build .*.swp *~ /*.kdev4 @@ -25,9 +27,5 @@ obj /libtool .dirstamp -/tools/initchain/initchain - -/bin -/obj *.vsidx *.lock From 1d28c32e30e59a9c9d22ba3d67d699319f258c66 Mon Sep 17 00:00:00 2001 From: evoskuil Date: Mon, 28 Oct 2024 21:33:21 -0400 Subject: [PATCH 3/5] Initial tasks.json and launch.json (presets). --- .vscode/launch.json | 32 ++++++++++++++++++++++++++++++++ .vscode/tasks.json | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 65 insertions(+) create mode 100644 .vscode/launch.json create mode 100644 .vscode/tasks.json diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 00000000..8332a762 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,32 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "name": "(gdb) Launch", + "type": "cppdbg", + "request": "launch", + "program": "${workspaceFolder}/obj/nix-gnu-debug-static/libbitcoin-database-test", + "args": [], + "stopAtEntry": false, + "cwd": "${workspaceFolder}/obj/nix-gnu-debug-static", + "environment": [], + "externalConsole": false, + "MIMode": "gdb", + "setupCommands": [ + { + "description": "Enable pretty-printing for gdb", + "text": "-enable-pretty-printing", + "ignoreFailures": true + }, + { + "description": "Set Disassembly Flavor to Intel", + "text": "-gdb-set disassembly-flavor intel", + "ignoreFailures": true + } + ] + } + ] +} \ No newline at end of file diff --git a/.vscode/tasks.json b/.vscode/tasks.json new file mode 100644 index 00000000..d2cd6a6b --- /dev/null +++ b/.vscode/tasks.json @@ -0,0 +1,33 @@ +{ + "version": "2.0.0", + "tasks": [ + { + "type": "cmake", + "label": "CMake: build", + "command": "build", + "targets": [ + "all" + ], + "preset": "${command:cmake.activeBuildPresetName}", + "group": "build", + "problemMatcher": [], + "detail": "CMake template build task" + }, + { + "type": "cmake", + "label": "CMake: clean", + "command": "clean", + "preset": "${command:cmake.activeBuildPresetName}", + "problemMatcher": [], + "detail": "CMake template clean task" + }, + { + "type": "cmake", + "label": "CMake: install", + "command": "install", + "preset": "${command:cmake.activeBuildPresetName}", + "problemMatcher": [], + "detail": "CMake template install task" + } + ] +} \ No newline at end of file From 8d2d6f8c6827e5ebec05077f44259c9bac7cad44 Mon Sep 17 00:00:00 2001 From: evoskuil Date: Mon, 28 Oct 2024 21:32:35 -0400 Subject: [PATCH 4/5] Update presets relative path. --- builds/cmake/CMakePresets.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/builds/cmake/CMakePresets.json b/builds/cmake/CMakePresets.json index 1cd9a27d..30de2c4e 100644 --- a/builds/cmake/CMakePresets.json +++ b/builds/cmake/CMakePresets.json @@ -5,7 +5,7 @@ "name": "nix-base", "description": "Factored base settings for non-windows *nix based platforms.", "hidden": true, - "installDir": "${sourceParentDir}/../../prefix/${presetName}", + "installDir": "${sourceParentDir}/../../../prefix/${presetName}", "binaryDir": "${sourceParentDir}/../obj/${presetName}", "condition": { "type": "inList", @@ -18,11 +18,11 @@ "cacheVariables": { "CMAKE_PREFIX_PATH": { "type": "PATH", - "value": "${sourceParentDir}/../../prefix/${presetName}" + "value": "${sourceParentDir}/../../../prefix/${presetName}" }, "CMAKE_LIBRARY_PATH": { "type": "PATH", - "value": "${sourceParentDir}/../../prefix/${presetName}/lib:$env{CMAKE_LIBRARY_PATH}" + "value": "${sourceParentDir}/../../../prefix/${presetName}/lib:$env{CMAKE_LIBRARY_PATH}" } } }, From 88c036ce8fbc3ea5f0db2088ae30c17df9edf69a Mon Sep 17 00:00:00 2001 From: evoskuil Date: Thu, 31 Oct 2024 12:45:05 -0400 Subject: [PATCH 5/5] Fix vscode workspace file from rebase. --- builds/vscode/database.code-workspace | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/builds/vscode/database.code-workspace b/builds/vscode/database.code-workspace index d0c9472b..58511205 100644 --- a/builds/vscode/database.code-workspace +++ b/builds/vscode/database.code-workspace @@ -1,8 +1,11 @@ { - "folders": [ - { - "path": "../../../libbitcoin-database" - } - ], - "settings": {} + "folders": [ + { + "path": "../../../libbitcoin-system" + }, + { + "path": "../../../libbitcoin-database" + } + ], + "settings": {} }