From 8a12297d507b09df610334eb867a53afa775c658 Mon Sep 17 00:00:00 2001 From: Eric Voskuil Date: Tue, 24 Nov 2026 10:35:34 -0500 Subject: [PATCH 1/2] Write a changed pool row at the frontier, as a body row is not rewritten. --- .../database/impl/query/pool/pool_suffice.ipp | 78 ++++++----- .../database/impl/query/pool/pool_writer.ipp | 112 ++++++++++------ include/bitcoin/database/query.hpp | 20 ++- test/query/pool/pool_suffice.cpp | 124 ++++++++++++++++++ 4 files changed, 257 insertions(+), 77 deletions(-) diff --git a/include/bitcoin/database/impl/query/pool/pool_suffice.ipp b/include/bitcoin/database/impl/query/pool/pool_suffice.ipp index c01b21d6c..9f326d4bc 100644 --- a/include/bitcoin/database/impl/query/pool/pool_suffice.ipp +++ b/include/bitcoin/database/impl/query/pool/pool_suffice.ipp @@ -97,33 +97,43 @@ code CLASS::get_pool_unvalidated(tx_links& out) const NOEXCEPT return error::success; } -// The sigops of a tx are counted under the flags of its context. TEMPLATE bool CLASS::set_pooled_context(const tx_link& link, const context& ctx, size_t sigops) NOEXCEPT { - using scalar = table::pool_scalar; + return set_pooled_contexts({ link.value }, { sigops }, ctx); +} + +// The sigops of a tx are counted under the flags of its context. +TEMPLATE +bool CLASS::set_pooled_contexts(const tx_links& links, + const std::vector& sigops, const context& ctx) NOEXCEPT +{ if (!store_.pool.enabled()) return true; + if (links.size() != sigops.size()) + return false; + + std::unordered_map counts{}; + counts.reserve(links.size()); + for (size_t index{}; index < links.size(); ++index) + counts.emplace(links.at(index), sigops.at(index)); + // ======================================================================== const auto scope = get_transactor(); - auto& vtx = store_.pool; - const auto fk = vtx.first(link); - if (fk.is_terminal()) - return false; - - table::pool_total total{}; - auto guard = vtx.get_memory(); - if (!guard || !vtx.totals.get(fk, total)) - return false; + tx_links purged{}; + return set_pool_purged(purged, links, true) && set_pool_repooled(purged, + [&](context& stored, size_t& count, const tx_link& link) NOEXCEPT + { + const auto it = counts.find(link.value); + if (it == counts.end()) + return; - total.sigops = system::possible_narrow_cast(sigops); - return vtx.totals.put(fk, total) && - vtx.flags.put(fk, scalar{ {}, ctx.flags }) && - vtx.heights.put(fk, scalar{ {}, ctx.height }) && - vtx.medians.put(fk, scalar{ {}, ctx.mtp }); + stored = ctx; + count = it->second; + }); // ======================================================================== } @@ -134,15 +144,12 @@ TEMPLATE bool CLASS::set_pool_unvalidated(size_t& out, const header_link& link) NOEXCEPT { - using scalar = table::pool_scalar; out = zero; if (!store_.pool.enabled()) return true; - // ======================================================================== - const auto scope = get_transactor(); - - decltype(store_.pool.get_memory()) guard{}; + tx_links spenders{}; + std::unordered_set unique{}; for (const auto fk: to_transactions(link)) { const tx_link tx{ fk }; @@ -151,23 +158,26 @@ bool CLASS::set_pool_unvalidated(size_t& out, { for (const auto& in: to_spenders(tx, index)) { - const auto row = store_.pool.first(to_input_tx(in)); - if (row.is_terminal()) - continue; - - if (!guard) - guard = store_.pool.get_memory(); - - if (!guard || !store_.pool.heights.put(row, - scalar{ {}, unvalidated_height })) - return false; - - ++out; + const auto spender = to_input_tx(in); + if (!store_.pool.first(spender).is_terminal() && + unique.insert(spender.value).second) + spenders.push_back(spender.value); } } } - return store_.set_pool_top(to_parent(link)); + out = spenders.size(); + + // ======================================================================== + const auto scope = get_transactor(); + + tx_links purged{}; + return set_pool_purged(purged, spenders, true) && set_pool_repooled(purged, + [&](context& stored, size_t&, const tx_link& spender) NOEXCEPT + { + if (unique.contains(spender.value)) + stored.height = unvalidated_height; + }) && store_.set_pool_top(to_parent(link)); // ======================================================================== } diff --git a/include/bitcoin/database/impl/query/pool/pool_writer.ipp b/include/bitcoin/database/impl/query/pool/pool_writer.ipp index 1d12b12f5..4073c7ccd 100644 --- a/include/bitcoin/database/impl/query/pool/pool_writer.ipp +++ b/include/bitcoin/database/impl/query/pool/pool_writer.ipp @@ -61,16 +61,20 @@ bool CLASS::set_pooled(size_t& repooled, const tx_link& link, if (!store_.pool.enabled()) return true; + // ======================================================================== + const auto scope = get_transactor(); + if (!set_pool_row(link, tx, ctx, time, sigops)) return false; tx_links purged{}; - if (archived && (!set_pool_purged(purged, link) || - !set_pool_repooled(purged))) + if (archived && (!set_pool_purged(purged, { link.value }, false) || + !set_pool_repooled(purged, {}))) return false; repooled = purged.size(); return true; + // ======================================================================== } // protected @@ -122,9 +126,6 @@ bool CLASS::set_pool_row(const tx_link& link, const transaction& tx, const auto hash = tx.get_hash(true); const auto words = from_little_endians(array_cast(hash)); - // ======================================================================== - const auto scope = get_transactor(); - // Clean single allocation failure (e.g. disk full). table::spends::link first{}; const table::spends::put_refs spent{ {}, prevouts }; @@ -192,12 +193,13 @@ bool CLASS::set_pool_row(const tx_link& link, const transaction& tx, system::pool::label(columns); return true; - // ======================================================================== } // protected +// Row purged or confirmed is passed over, with its spenders. TEMPLATE -bool CLASS::set_pool_purged(tx_links& out, const tx_link& link) NOEXCEPT +bool CLASS::set_pool_purged(tx_links& out, const tx_links& links, + bool inclusive) NOEXCEPT { using namespace system; using algorithm = system::pool::algorithm; @@ -205,11 +207,38 @@ bool CLASS::set_pool_purged(tx_links& out, const tx_link& link) NOEXCEPT using integer = pool_link::integer; auto& cells = store_.pool_index.cells; std::vector> found{}; - tx_links pending{ link.value }; + tx_links pending{}; out.clear(); - // ======================================================================== - const auto scope = get_transactor(); + const auto purge = [&](const tx_link& tx, const pool_link& row) NOEXCEPT + { + const auto cell = cells.at(row.value); + const auto purged = algorithm::is_absent(cell) && + is_nonzero(bit_and(cell, algorithm::purged)); + if (purged || algorithm::is_boundary(cell)) + return true; + + const auto next = algorithm::raised(cell, algorithm::purged); + if (!cells.set(row.value, row_cell{ {}, next })) + return false; + + found.emplace_back(row.value, tx); + pending.push_back(tx.value); + return true; + }; + + for (const tx_link link: links) + { + if (!inclusive) + { + pending.push_back(link.value); + continue; + } + + const auto row = store_.pool.first(link); + if (row.is_terminal() || !purge(link, row)) + return false; + } while (!pending.empty()) { @@ -222,21 +251,8 @@ bool CLASS::set_pool_purged(tx_links& out, const tx_link& link) NOEXCEPT { const auto child = to_input_tx(in); const auto row = store_.pool.first(child); - if (row.is_terminal()) - continue; - - const auto cell = cells.at(row.value); - const auto purged = algorithm::is_absent(cell) && - is_nonzero(bit_and(cell, algorithm::purged)); - if (purged || algorithm::is_boundary(cell)) - continue; - - const auto next = algorithm::raised(cell, algorithm::purged); - if (!cells.set(row.value, row_cell{ {}, next })) + if (!row.is_terminal() && !purge(child, row)) return false; - - found.emplace_back(row.value, child); - pending.push_back(child.value); } } } @@ -255,33 +271,51 @@ bool CLASS::set_pool_purged(tx_links& out, const tx_link& link) NOEXCEPT system::pool::label(columns); return true; - // ======================================================================== } // protected TEMPLATE -bool CLASS::set_pool_repooled(const tx_links& purged) NOEXCEPT +bool CLASS::get_pool_stored(context& ctx, uint32_t& time, size_t& sigops, + const tx_link& link) const NOEXCEPT +{ + table::pool::record record{}; + table::pool_total total{}; + table::pool_scalar flags{}, height{}, median{}; + const auto row = store_.pool.first(link); + if (!store_.pool.get(row, record) || + !store_.pool.totals.get(row, total) || + !store_.pool.flags.get(row, flags) || + !store_.pool.heights.get(row, height) || + !store_.pool.medians.get(row, median)) + return false; + + ctx = { flags.value, height.value, median.value }; + time = record.time; + sigops = total.sigops; + return true; +} + +// protected +TEMPLATE +bool CLASS::set_pool_repooled(const tx_links& purged, + const pool_amender& amend) NOEXCEPT { - for (const auto value: purged) + for (const tx_link link: purged) { - const tx_link link{ value }; - table::pool::record record{}; - table::pool_total total{}; - table::pool_scalar flags{}, height{}, median{}; - const auto row = store_.pool.first(link); - if (!store_.pool.get(row, record) || - !store_.pool.totals.get(row, total) || - !store_.pool.flags.get(row, flags) || - !store_.pool.heights.get(row, height) || - !store_.pool.medians.get(row, median)) + context ctx{}; + uint32_t time{}; + size_t sigops{}; + if (!get_pool_stored(ctx, time, sigops, link)) return false; const auto tx = get_transaction(link, true); if (!tx || !populate_with_metadata(*tx, true, true)) return false; - const context ctx{ flags.value, height.value, median.value }; - if (!set_pool_row(link, *tx, ctx, record.time, total.sigops)) + if (amend) + amend(ctx, sigops, link); + + if (!set_pool_row(link, *tx, ctx, time, sigops)) return false; } diff --git a/include/bitcoin/database/query.hpp b/include/bitcoin/database/query.hpp index 28f6e6c2c..68caa1192 100644 --- a/include/bitcoin/database/query.hpp +++ b/include/bitcoin/database/query.hpp @@ -814,6 +814,10 @@ class query bool set_pooled_context(const tx_link& link, const context& ctx, size_t sigops) NOEXCEPT; + /// Set context of pooled txs with sigops of each, as validated under it. + bool set_pooled_contexts(const tx_links& links, + const std::vector& sigops, const context& ctx) NOEXCEPT; + /// Set pooled spenders of block's txs not validated, parent pool top. bool set_pool_unvalidated(size_t& out, const header_link& link) NOEXCEPT; @@ -1285,11 +1289,19 @@ class query bool set_pool_row(const tx_link& link, const transaction& tx, const context& ctx, uint32_t time, size_t sigops) NOEXCEPT; - /// Purge pooled spenders of tx and theirs, ascending by row. - bool set_pool_purged(tx_links& out, const tx_link& link) NOEXCEPT; + /// Purge pooled spenders of txs and theirs, and txs if inclusive, by row. + bool set_pool_purged(tx_links& out, const tx_links& links, + bool inclusive) NOEXCEPT; + + /// Context, time and sigops stored for pooled tx. + bool get_pool_stored(context& ctx, uint32_t& time, size_t& sigops, + const tx_link& link) const NOEXCEPT; - /// Pool again each purged tx, in order, under its stored context. - bool set_pool_repooled(const tx_links& purged) NOEXCEPT; + /// Pool again each purged tx, in order, stored context and sigops amended. + using pool_amender = std::function; + bool set_pool_repooled(const tx_links& purged, + const pool_amender& amend) NOEXCEPT; /// Input of a pooled spender of point below bound, and if confirmed spent. bool get_pooled_spender(system::pool::algorithm::link_t& out, diff --git a/test/query/pool/pool_suffice.cpp b/test/query/pool/pool_suffice.cpp index 320ea61dc..aa41baf05 100644 --- a/test/query/pool/pool_suffice.cpp +++ b/test/query/pool/pool_suffice.cpp @@ -380,6 +380,44 @@ BC_AUTO_TEST_CASE(query_pool__set_pool_unvalidated__revalidated__present_after_s BC_REQUIRE(system::pool::algorithm::is_present(pool_cell(query, store, tx))); } +BC_AUTO_TEST_CASE(query_pool__set_pool_unvalidated__spender_and_child__written_at_frontier_in_order) +{ + settings settings{ test::database_settings() }; + settings.path = TEST_DIRECTORY; + test::chunk_store store{ settings }; + test::query_accessor query{ store }; + BC_REQUIRE(!store.create(test::events_handler)); + BC_REQUIRE(query.initialize(test::genesis)); + + store.set_pooling(); + const auto parent = to_spend(genesis_coinbase(), 4'999'999'000); + const auto child = to_spend(parent.hash(false), 4'999'998'000); + const auto pooled = pool_populated(query, parent) && pool_populated(query, child); + const auto parent_link = query.to_tx(parent.hash(false)); + const auto child_link = query.to_tx(child.hash(false)); + size_t marked{}; + const auto unvalidated = query.set_pool_unvalidated(marked, query.to_header(test::genesis.hash())); + const auto parent_row = store.pool.first(parent_link); + const auto child_row = store.pool.first(child_link); + const auto parent_cell = store.pool_index.cells.at(0u); + const auto child_cell = store.pool_index.cells.at(1u); + table::pool_scalar parent_height{}; + table::pool_scalar child_height{}; + const auto read = store.pool.heights.get(parent_row, parent_height) && store.pool.heights.get(child_row, child_height); + + BC_REQUIRE(pooled); + BC_REQUIRE(unvalidated); + BC_REQUIRE_EQUAL(marked, 1u); + BC_REQUIRE_EQUAL(parent_row.value, 2u); + BC_REQUIRE_EQUAL(child_row.value, 3u); + BC_REQUIRE_EQUAL(store.pool.count().value, 4u); + BC_REQUIRE(is_nonzero(system::bit_and(parent_cell, system::pool::algorithm::purged))); + BC_REQUIRE(is_nonzero(system::bit_and(child_cell, system::pool::algorithm::purged))); + BC_REQUIRE(read); + BC_REQUIRE_EQUAL(parent_height.value, max_uint32); + BC_REQUIRE_EQUAL(child_height.value, 8u); +} + BC_AUTO_TEST_CASE(query_pool__set_pool_unvalidated__no_pooled_spender__true_none) { settings settings{ test::database_settings() }; @@ -456,6 +494,92 @@ BC_AUTO_TEST_CASE(query_pool__set_pooled_context__sigops__stored_with_fee_and_si BC_REQUIRE_EQUAL(after.sigops, 42u); } +BC_AUTO_TEST_CASE(query_pool__set_pooled_context__pooled__written_at_frontier_and_prior_row_purged) +{ + settings settings{ test::database_settings() }; + settings.path = TEST_DIRECTORY; + test::chunk_store store{ settings }; + test::query_accessor query{ store }; + BC_REQUIRE(!store.create(test::events_handler)); + BC_REQUIRE(query.initialize(test::genesis)); + + store.set_pooling(); + const auto tx = to_spend(genesis_coinbase(), 4'999'999'000); + const auto pooled = pool_populated(query, tx); + const auto link = query.to_tx(tx.hash(false)); + const auto before = store.pool.first(link); + const auto set = query.set_pooled_context(link, context{ bip113 | flags::bip16_rule, 8, 9 }, 0); + const auto after = store.pool.first(link); + const auto cell = store.pool_index.cells.at(before.value); + table::pool_scalar flags{}; + const auto read = store.pool.flags.get(after, flags); + + BC_REQUIRE(pooled); + BC_REQUIRE(set); + BC_REQUIRE_EQUAL(before.value, 0u); + BC_REQUIRE_EQUAL(after.value, 1u); + BC_REQUIRE_EQUAL(store.pool.count().value, 2u); + BC_REQUIRE(system::pool::algorithm::is_absent(cell)); + BC_REQUIRE(is_nonzero(system::bit_and(cell, system::pool::algorithm::purged))); + BC_REQUIRE(read); + BC_REQUIRE_EQUAL(flags.value, bip113 | flags::bip16_rule); +} + +BC_AUTO_TEST_CASE(query_pool__set_pooled_contexts__parent_of_pooled_child__child_written_after_under_stored_context) +{ + settings settings{ test::database_settings() }; + settings.path = TEST_DIRECTORY; + test::chunk_store store{ settings }; + test::query_accessor query{ store }; + BC_REQUIRE(!store.create(test::events_handler)); + BC_REQUIRE(query.initialize(test::genesis)); + + store.set_pooling(); + const context more{ bip113 | flags::bip16_rule, 8, 9 }; + const auto parent = to_spend(genesis_coinbase(), 4'999'999'000); + const auto child = to_spend(parent.hash(false), 4'999'998'000); + const auto pooled = pool_populated(query, parent) && pool_populated(query, child); + const auto parent_link = query.to_tx(parent.hash(false)); + const auto child_link = query.to_tx(child.hash(false)); + const auto set = query.set_pooled_contexts({ parent_link.value }, { 7 }, more); + const auto parent_row = store.pool.first(parent_link); + const auto child_row = store.pool.first(child_link); + table::pool_scalar parent_flags{}; + table::pool_scalar child_flags{}; + table::pool_total parent_total{}; + const auto read = store.pool.flags.get(parent_row, parent_flags) && store.pool.flags.get(child_row, child_flags) && store.pool.totals.get(parent_row, parent_total); + + BC_REQUIRE(pooled); + BC_REQUIRE(set); + BC_REQUIRE_EQUAL(parent_row.value, 2u); + BC_REQUIRE_EQUAL(child_row.value, 3u); + BC_REQUIRE_EQUAL(store.pool.count().value, 4u); + BC_REQUIRE(is_nonzero(system::bit_and(store.pool_index.cells.at(0u), system::pool::algorithm::purged))); + BC_REQUIRE(is_nonzero(system::bit_and(store.pool_index.cells.at(1u), system::pool::algorithm::purged))); + BC_REQUIRE(read); + BC_REQUIRE_EQUAL(parent_flags.value, bip113 | flags::bip16_rule); + BC_REQUIRE_EQUAL(child_flags.value, bip113); + BC_REQUIRE_EQUAL(parent_total.sigops, 7u); +} + +BC_AUTO_TEST_CASE(query_pool__set_pooled_contexts__sizes_differ__false) +{ + settings settings{ test::database_settings() }; + settings.path = TEST_DIRECTORY; + test::chunk_store store{ settings }; + test::query_accessor query{ store }; + BC_REQUIRE(!store.create(test::events_handler)); + BC_REQUIRE(query.initialize(test::genesis)); + + store.set_pooling(); + const auto tx = to_spend(genesis_coinbase(), 4'999'999'000); + const auto pooled = pool_populated(query, tx); + + BC_REQUIRE(pooled); + BC_REQUIRE(!query.set_pooled_contexts({ query.to_tx(tx.hash(false)).value }, {}, context{ bip113, 8, 9 })); + BC_REQUIRE_EQUAL(store.pool.count().value, 1u); +} + BC_AUTO_TEST_CASE(query_pool__set_pooled_context__not_pooled__false) { settings settings{ test::database_settings() }; From 52d9aab529f2e872da7cf7ed69c06788d585e70b Mon Sep 17 00:00:00 2001 From: Eric Voskuil Date: Tue, 24 Nov 2026 10:59:55 -0500 Subject: [PATCH 2/2] Regenerate artifacts. --- .github/workflows/ci-expanded.yml | 77 +++++++++++++++++++++++++++++++ .github/workflows/ci.yml | 69 +++++++++++++++++++++++++++ builds/gnu/install-gnu.sh | 37 +++++++++++++++ 3 files changed, 183 insertions(+) diff --git a/.github/workflows/ci-expanded.yml b/.github/workflows/ci-expanded.yml index 6f13fb307..3d3bbad21 100644 --- a/.github/workflows/ci-expanded.yml +++ b/.github/workflows/ci-expanded.yml @@ -567,6 +567,14 @@ jobs: ./emulation fi + - name: Register warning matcher + shell: bash + run: | + cat > "$RUNNER_TEMP/warning-matcher.json" << 'EOF' + {"problemMatcher":[{"owner":"gcc-warning","severity":"warning","pattern":[{"regexp":"^([^\\s:(][^:(]*):(\\d+):(\\d+):\\s+warning:\\s+(.*?)(?:\\s+\\[(-W[^\\]]+)\\])?$","file":1,"line":2,"column":3,"message":4,"code":5}]},{"owner":"msvc-warning","severity":"warning","pattern":[{"regexp":"^\\s*(?:\\d+>)?([^\\s(][^(]*)\\((\\d+)(?:,(\\d+))?\\)\\s*:\\s+warning\\s+(C\\d+)\\s*:\\s*(.*?)(?:\\s+\\[[^\\]]+\\])?$","file":1,"line":2,"column":3,"code":4,"message":5}]},{"owner":"clang-cl-warning","severity":"warning","pattern":[{"regexp":"^\\s*(?:\\d+>)?([^\\s(][^(]*)\\((\\d+)(?:,(\\d+))?\\)\\s*:\\s+warning:\\s+(.*?)(?:\\s+\\[(-W[^\\]]+)\\])?$","file":1,"line":2,"column":3,"message":4,"code":5}]}]} + EOF + echo "::add-matcher::$RUNNER_TEMP/warning-matcher.json" + - name: Execute installation shell: bash working-directory: 'libbitcoin-database' @@ -729,6 +737,14 @@ jobs: echo "LDFLAGS=-Wl,-rpath,${{ github.workspace }}/prefix/lib" >> $GITHUB_ENV fi + - name: Register warning matcher + shell: bash + run: | + cat > "$RUNNER_TEMP/warning-matcher.json" << 'EOF' + {"problemMatcher":[{"owner":"gcc-warning","severity":"warning","pattern":[{"regexp":"^([^\\s:(][^:(]*):(\\d+):(\\d+):\\s+warning:\\s+(.*?)(?:\\s+\\[(-W[^\\]]+)\\])?$","file":1,"line":2,"column":3,"message":4,"code":5}]},{"owner":"msvc-warning","severity":"warning","pattern":[{"regexp":"^\\s*(?:\\d+>)?([^\\s(][^(]*)\\((\\d+)(?:,(\\d+))?\\)\\s*:\\s+warning\\s+(C\\d+)\\s*:\\s*(.*?)(?:\\s+\\[[^\\]]+\\])?$","file":1,"line":2,"column":3,"code":4,"message":5}]},{"owner":"clang-cl-warning","severity":"warning","pattern":[{"regexp":"^\\s*(?:\\d+>)?([^\\s(][^(]*)\\((\\d+)(?:,(\\d+))?\\)\\s*:\\s+warning:\\s+(.*?)(?:\\s+\\[(-W[^\\]]+)\\])?$","file":1,"line":2,"column":3,"message":4,"code":5}]}]} + EOF + echo "::add-matcher::$RUNNER_TEMP/warning-matcher.json" + - name: Execute installation shell: bash working-directory: 'libbitcoin-database' @@ -1228,6 +1244,14 @@ jobs: chmod -R u+rwX /tmp/sysroot find /tmp/sysroot -name '*.la' -delete + - name: Register warning matcher + shell: bash + run: | + cat > "$RUNNER_TEMP/warning-matcher.json" << 'EOF' + {"problemMatcher":[{"owner":"gcc-warning","severity":"warning","pattern":[{"regexp":"^([^\\s:(][^:(]*):(\\d+):(\\d+):\\s+warning:\\s+(.*?)(?:\\s+\\[(-W[^\\]]+)\\])?$","file":1,"line":2,"column":3,"message":4,"code":5}]},{"owner":"msvc-warning","severity":"warning","pattern":[{"regexp":"^\\s*(?:\\d+>)?([^\\s(][^(]*)\\((\\d+)(?:,(\\d+))?\\)\\s*:\\s+warning\\s+(C\\d+)\\s*:\\s*(.*?)(?:\\s+\\[[^\\]]+\\])?$","file":1,"line":2,"column":3,"code":4,"message":5}]},{"owner":"clang-cl-warning","severity":"warning","pattern":[{"regexp":"^\\s*(?:\\d+>)?([^\\s(][^(]*)\\((\\d+)(?:,(\\d+))?\\)\\s*:\\s+warning:\\s+(.*?)(?:\\s+\\[(-W[^\\]]+)\\])?$","file":1,"line":2,"column":3,"message":4,"code":5}]}]} + EOF + echo "::add-matcher::$RUNNER_TEMP/warning-matcher.json" + - name: Execute installation shell: bash working-directory: 'libbitcoin-database' @@ -1650,6 +1674,14 @@ jobs: echo "LDFLAGS=-Wl,-rpath,${{ github.workspace }}/prefix/lib" >> $GITHUB_ENV fi + - name: Register warning matcher + shell: bash + run: | + cat > "$RUNNER_TEMP/warning-matcher.json" << 'EOF' + {"problemMatcher":[{"owner":"gcc-warning","severity":"warning","pattern":[{"regexp":"^([^\\s:(][^:(]*):(\\d+):(\\d+):\\s+warning:\\s+(.*?)(?:\\s+\\[(-W[^\\]]+)\\])?$","file":1,"line":2,"column":3,"message":4,"code":5}]},{"owner":"msvc-warning","severity":"warning","pattern":[{"regexp":"^\\s*(?:\\d+>)?([^\\s(][^(]*)\\((\\d+)(?:,(\\d+))?\\)\\s*:\\s+warning\\s+(C\\d+)\\s*:\\s*(.*?)(?:\\s+\\[[^\\]]+\\])?$","file":1,"line":2,"column":3,"code":4,"message":5}]},{"owner":"clang-cl-warning","severity":"warning","pattern":[{"regexp":"^\\s*(?:\\d+>)?([^\\s(][^(]*)\\((\\d+)(?:,(\\d+))?\\)\\s*:\\s+warning:\\s+(.*?)(?:\\s+\\[(-W[^\\]]+)\\])?$","file":1,"line":2,"column":3,"message":4,"code":5}]}]} + EOF + echo "::add-matcher::$RUNNER_TEMP/warning-matcher.json" + - name: Execute installation shell: bash working-directory: 'libbitcoin-database' @@ -1851,6 +1883,14 @@ jobs: persist-credentials: false repository: ${{ github.repository }} + - name: Register warning matcher + shell: bash + run: | + cat > "$RUNNER_TEMP/warning-matcher.json" << 'EOF' + {"problemMatcher":[{"owner":"gcc-warning","severity":"warning","pattern":[{"regexp":"^([^\\s:(][^:(]*):(\\d+):(\\d+):\\s+warning:\\s+(.*?)(?:\\s+\\[(-W[^\\]]+)\\])?$","file":1,"line":2,"column":3,"message":4,"code":5}]},{"owner":"msvc-warning","severity":"warning","pattern":[{"regexp":"^\\s*(?:\\d+>)?([^\\s(][^(]*)\\((\\d+)(?:,(\\d+))?\\)\\s*:\\s+warning\\s+(C\\d+)\\s*:\\s*(.*?)(?:\\s+\\[[^\\]]+\\])?$","file":1,"line":2,"column":3,"code":4,"message":5}]},{"owner":"clang-cl-warning","severity":"warning","pattern":[{"regexp":"^\\s*(?:\\d+>)?([^\\s(][^(]*)\\((\\d+)(?:,(\\d+))?\\)\\s*:\\s+warning:\\s+(.*?)(?:\\s+\\[(-W[^\\]]+)\\])?$","file":1,"line":2,"column":3,"message":4,"code":5}]}]} + EOF + echo "::add-matcher::$RUNNER_TEMP/warning-matcher.json" + - name: Force clean nuget package repository shell: cmd working-directory: 'libbitcoin-database' @@ -1891,3 +1931,40 @@ jobs: exit $ERR; } Write-Host "Test execution complete." -ForegroundColor Green; + + warnings: + needs: [ gnu, musl, cmake, presets, msvc ] + if: ${{ !cancelled() && (github.event_name != 'pull_request' || github.event.action != 'closed') }} + continue-on-error: true + runs-on: ubuntu-latest + + permissions: + actions: read + checks: read + + steps: + - name: Count compiler warnings + id: count + shell: bash + env: + GH_TOKEN: ${{ github.token }} + run: | + SUITE=$(gh api "repos/${{ github.repository }}/actions/runs/${{ github.run_id }}" --jq .check_suite_id) + RUNS=$(gh api --paginate "repos/${{ github.repository }}/check-suites/${SUITE}/check-runs?per_page=100" --jq '.check_runs[] | select(.output.annotations_count > 0) | .id') + COUNT=0 + for RUN in ${RUNS}; do + FOUND=$(gh api --paginate "repos/${{ github.repository }}/check-runs/${RUN}/annotations?per_page=100" --jq '[.[] | select(.annotation_level == "warning" and .path != ".github")] | length' | awk '{ sum += $1 } END { print sum + 0 }') + COUNT=$((COUNT + FOUND)) + done + echo "Compiler warnings: ${COUNT}" | tee -a "$GITHUB_STEP_SUMMARY" + mkdir -p warnings + echo "${COUNT}" > warnings/count + echo "count=${COUNT}" >> "$GITHUB_OUTPUT" + + - name: Upload warning count + if: steps.count.outputs.count != '0' + uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1 + with: + name: warnings-${{ steps.count.outputs.count }} + path: warnings/count + retention-days: 90 diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f75c1f348..762c86dbe 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -299,6 +299,14 @@ jobs: ./emulation fi + - name: Register warning matcher + shell: bash + run: | + cat > "$RUNNER_TEMP/warning-matcher.json" << 'EOF' + {"problemMatcher":[{"owner":"gcc-warning","severity":"warning","pattern":[{"regexp":"^([^\\s:(][^:(]*):(\\d+):(\\d+):\\s+warning:\\s+(.*?)(?:\\s+\\[(-W[^\\]]+)\\])?$","file":1,"line":2,"column":3,"message":4,"code":5}]},{"owner":"msvc-warning","severity":"warning","pattern":[{"regexp":"^\\s*(?:\\d+>)?([^\\s(][^(]*)\\((\\d+)(?:,(\\d+))?\\)\\s*:\\s+warning\\s+(C\\d+)\\s*:\\s*(.*?)(?:\\s+\\[[^\\]]+\\])?$","file":1,"line":2,"column":3,"code":4,"message":5}]},{"owner":"clang-cl-warning","severity":"warning","pattern":[{"regexp":"^\\s*(?:\\d+>)?([^\\s(][^(]*)\\((\\d+)(?:,(\\d+))?\\)\\s*:\\s+warning:\\s+(.*?)(?:\\s+\\[(-W[^\\]]+)\\])?$","file":1,"line":2,"column":3,"message":4,"code":5}]}]} + EOF + echo "::add-matcher::$RUNNER_TEMP/warning-matcher.json" + - name: Execute installation shell: bash working-directory: 'libbitcoin-database' @@ -505,6 +513,14 @@ jobs: echo "LDFLAGS=-Wl,-rpath,${{ github.workspace }}/prefix/lib" >> $GITHUB_ENV fi + - name: Register warning matcher + shell: bash + run: | + cat > "$RUNNER_TEMP/warning-matcher.json" << 'EOF' + {"problemMatcher":[{"owner":"gcc-warning","severity":"warning","pattern":[{"regexp":"^([^\\s:(][^:(]*):(\\d+):(\\d+):\\s+warning:\\s+(.*?)(?:\\s+\\[(-W[^\\]]+)\\])?$","file":1,"line":2,"column":3,"message":4,"code":5}]},{"owner":"msvc-warning","severity":"warning","pattern":[{"regexp":"^\\s*(?:\\d+>)?([^\\s(][^(]*)\\((\\d+)(?:,(\\d+))?\\)\\s*:\\s+warning\\s+(C\\d+)\\s*:\\s*(.*?)(?:\\s+\\[[^\\]]+\\])?$","file":1,"line":2,"column":3,"code":4,"message":5}]},{"owner":"clang-cl-warning","severity":"warning","pattern":[{"regexp":"^\\s*(?:\\d+>)?([^\\s(][^(]*)\\((\\d+)(?:,(\\d+))?\\)\\s*:\\s+warning:\\s+(.*?)(?:\\s+\\[(-W[^\\]]+)\\])?$","file":1,"line":2,"column":3,"message":4,"code":5}]}]} + EOF + echo "::add-matcher::$RUNNER_TEMP/warning-matcher.json" + - name: Execute installation shell: bash working-directory: 'libbitcoin-database' @@ -715,6 +731,14 @@ jobs: echo "LDFLAGS=-Wl,-rpath,${{ github.workspace }}/prefix/lib" >> $GITHUB_ENV fi + - name: Register warning matcher + shell: bash + run: | + cat > "$RUNNER_TEMP/warning-matcher.json" << 'EOF' + {"problemMatcher":[{"owner":"gcc-warning","severity":"warning","pattern":[{"regexp":"^([^\\s:(][^:(]*):(\\d+):(\\d+):\\s+warning:\\s+(.*?)(?:\\s+\\[(-W[^\\]]+)\\])?$","file":1,"line":2,"column":3,"message":4,"code":5}]},{"owner":"msvc-warning","severity":"warning","pattern":[{"regexp":"^\\s*(?:\\d+>)?([^\\s(][^(]*)\\((\\d+)(?:,(\\d+))?\\)\\s*:\\s+warning\\s+(C\\d+)\\s*:\\s*(.*?)(?:\\s+\\[[^\\]]+\\])?$","file":1,"line":2,"column":3,"code":4,"message":5}]},{"owner":"clang-cl-warning","severity":"warning","pattern":[{"regexp":"^\\s*(?:\\d+>)?([^\\s(][^(]*)\\((\\d+)(?:,(\\d+))?\\)\\s*:\\s+warning:\\s+(.*?)(?:\\s+\\[(-W[^\\]]+)\\])?$","file":1,"line":2,"column":3,"message":4,"code":5}]}]} + EOF + echo "::add-matcher::$RUNNER_TEMP/warning-matcher.json" + - name: Execute installation shell: bash working-directory: 'libbitcoin-database' @@ -867,6 +891,14 @@ jobs: persist-credentials: false repository: ${{ github.repository }} + - name: Register warning matcher + shell: bash + run: | + cat > "$RUNNER_TEMP/warning-matcher.json" << 'EOF' + {"problemMatcher":[{"owner":"gcc-warning","severity":"warning","pattern":[{"regexp":"^([^\\s:(][^:(]*):(\\d+):(\\d+):\\s+warning:\\s+(.*?)(?:\\s+\\[(-W[^\\]]+)\\])?$","file":1,"line":2,"column":3,"message":4,"code":5}]},{"owner":"msvc-warning","severity":"warning","pattern":[{"regexp":"^\\s*(?:\\d+>)?([^\\s(][^(]*)\\((\\d+)(?:,(\\d+))?\\)\\s*:\\s+warning\\s+(C\\d+)\\s*:\\s*(.*?)(?:\\s+\\[[^\\]]+\\])?$","file":1,"line":2,"column":3,"code":4,"message":5}]},{"owner":"clang-cl-warning","severity":"warning","pattern":[{"regexp":"^\\s*(?:\\d+>)?([^\\s(][^(]*)\\((\\d+)(?:,(\\d+))?\\)\\s*:\\s+warning:\\s+(.*?)(?:\\s+\\[(-W[^\\]]+)\\])?$","file":1,"line":2,"column":3,"message":4,"code":5}]}]} + EOF + echo "::add-matcher::$RUNNER_TEMP/warning-matcher.json" + - name: Force clean nuget package repository shell: cmd working-directory: 'libbitcoin-database' @@ -907,3 +939,40 @@ jobs: exit $ERR; } Write-Host "Test execution complete." -ForegroundColor Green; + + warnings: + needs: [ gnu, cmake, presets, msvc ] + if: ${{ !cancelled() && (github.event_name != 'pull_request' || github.event.action != 'closed') }} + continue-on-error: true + runs-on: ubuntu-latest + + permissions: + actions: read + checks: read + + steps: + - name: Count compiler warnings + id: count + shell: bash + env: + GH_TOKEN: ${{ github.token }} + run: | + SUITE=$(gh api "repos/${{ github.repository }}/actions/runs/${{ github.run_id }}" --jq .check_suite_id) + RUNS=$(gh api --paginate "repos/${{ github.repository }}/check-suites/${SUITE}/check-runs?per_page=100" --jq '.check_runs[] | select(.output.annotations_count > 0) | .id') + COUNT=0 + for RUN in ${RUNS}; do + FOUND=$(gh api --paginate "repos/${{ github.repository }}/check-runs/${RUN}/annotations?per_page=100" --jq '[.[] | select(.annotation_level == "warning" and .path != ".github")] | length' | awk '{ sum += $1 } END { print sum + 0 }') + COUNT=$((COUNT + FOUND)) + done + echo "Compiler warnings: ${COUNT}" | tee -a "$GITHUB_STEP_SUMMARY" + mkdir -p warnings + echo "${COUNT}" > warnings/count + echo "count=${COUNT}" >> "$GITHUB_OUTPUT" + + - name: Upload warning count + if: steps.count.outputs.count != '0' + uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1 + with: + name: warnings-${{ steps.count.outputs.count }} + path: warnings/count + retention-days: 90 diff --git a/builds/gnu/install-gnu.sh b/builds/gnu/install-gnu.sh index 6577f70ce..ac730435c 100755 --- a/builds/gnu/install-gnu.sh +++ b/builds/gnu/install-gnu.sh @@ -30,6 +30,8 @@ # --build-skip-tests Skip test compilation and execution. # --build-skip-test-run Compile tests without executing them. # --build-valgrind= Also run the tests matching the filter under valgrind. +# --build-web Also test, regenerate and compare the embedded web pages. +# --build-smoke Also sync each network and smoke test the nodes. # --build-parallel= Number of jobs to run simultaneously. # Default: supported platforms use nproc/sysctl # --build-use-local-src Use existing sources in relevant paths. @@ -148,6 +150,8 @@ main() (--build-skip-tests) BUILD_SKIP_TESTS="yes";; (--build-skip-test-run) BUILD_SKIP_TEST_RUN="yes";; (--build-valgrind=*) BUILD_VALGRIND="${OPTION#*=}";; + (--build-web) BUILD_WEB="yes";; + (--build-smoke) BUILD_SMOKE="yes";; (--build-parallel=*) PARALLEL="${OPTION#*=}";; (--build-use-local-src) BUILD_USE_LOCAL_SRC="yes";; (--prefix=*) PREFIX="${OPTION#*=}";; @@ -172,6 +176,8 @@ main() remove_configure_option "--build-skip-tests" remove_configure_option "--build-skip-test-run" remove_configure_option "--build-valgrind=*" + remove_configure_option "--build-web" + remove_configure_option "--build-smoke" remove_configure_option "--build-parallel=*" remove_configure_option "--build-use-local-src" remove_configure_option "--prefix=*" @@ -999,6 +1005,33 @@ test_gnu() fi fi + if [[ "${BUILD_WEB}" == "yes" && "${BUILD_SKIP_TEST_RUN}" != "yes" && "${PROJECT}" == "libbitcoin-database" ]]; then + msg "Testing ${PROJECT} embedded web pages" + push_directory "${BUILD_SRC_DIR}/${PROJECT}" + python3 tools/generate_embedded_pages.py && git diff --exit-code -- console/embedded + + RESULT=$? + pop_directory + if [[ ${RESULT} -ne 0 ]]; then + msg_error "Embedded web pages failed tests or differ from those committed." + exit ${RESULT} + fi + fi + + if [[ "${BUILD_SMOKE}" == "yes" && "${BUILD_SKIP_TEST_RUN}" != "yes" && "${PROJECT}" == "libbitcoin-database" ]]; then + msg "Smoke testing ${PROJECT} nodes" + local BS="$(pwd)/console/bs" + push_directory "${BUILD_SRC_DIR}/${PROJECT}" + python3 tools/sync_networks.py "${BS}" + + RESULT=$? + pop_directory + if [[ ${RESULT} -ne 0 ]]; then + msg_error "Encountered node smoke test failure, please see report above." + exit ${RESULT} + fi + fi + enable_exit_on_error pop_directory # BUILD_OBJ_DIR @@ -1025,6 +1058,8 @@ display_build_variables() msg "BUILD_SKIP_TESTS : ${BUILD_SKIP_TESTS}" msg "BUILD_SKIP_TEST_RUN : ${BUILD_SKIP_TEST_RUN}" msg "BUILD_VALGRIND : ${BUILD_VALGRIND}" + msg "BUILD_WEB : ${BUILD_WEB}" + msg "BUILD_SMOKE : ${BUILD_SMOKE}" msg "PARALLEL : ${PARALLEL}" msg "PREFIX : ${PREFIX}" msg "DISPLAY_VERBOSE : ${DISPLAY_VERBOSE}" @@ -1093,6 +1128,8 @@ help() msg "--build-skip-tests Skip test compilation and execution." msg "--build-skip-test-run Compile tests without executing them." msg "--build-valgrind= Also run the tests matching the filter under valgrind." + msg "--build-web Also test, regenerate and compare the embedded web pages." + msg "--build-smoke Also sync each network and smoke test the nodes." msg "--build-parallel= Number of jobs to run simultaneously." msg " Default: supported platforms use nproc/sysctl" msg "--build-use-local-src Use existing sources in relevant paths."