Skip to content

nmc: P1 PC embedded template builder (re-homed btc mirror) + KATs - #213

Merged
frstrtr merged 2 commits into
masterfrom
nmc/p1-pc-template-builder
Jun 19, 2026
Merged

nmc: P1 PC embedded template builder (re-homed btc mirror) + KATs#213
frstrtr merged 2 commits into
masterfrom
nmc/p1-pc-template-builder

Conversation

@frstrtr

@frstrtr frstrtr commented Jun 19, 2026

Copy link
Copy Markdown
Owner

NMC P1 PC — embedded template builder

Re-homes src/impl/btc/coin/template_builder.hpp into namespace nmc::coin. Builds block templates natively from a validated HeaderChain + Mempool, removing the getblocktemplate RPC dependency for the embedded merge-mined Namecoin chain.

Provides (header-only): get_block_subsidy() (NMC inherits Bitcoin halving: 50 NMC, 210k interval), SHA256d compute_merkle_root(), TemplateBuilder::build_template() -> WorkData, CoinNodeInterface + EmbeddedCoinNode (HeaderChain + Mempool backed).

Scope: STRUCTURAL builder only. Merge-mining specifics (aux commitment in parent coinbase, dual-target submission) are PD, NOT here.

Tests: new nmc_template_builder_test — 10 KATs (5 merkle + 3 build + 2 sync-state), all GREEN, build + run exit 0 locally.

Fence: src/impl/nmc/ only; btc tree consumed READ-ONLY. One additive shared-file edit: .github/workflows/build.yml adds nmc_template_builder_test to the two CI test-run lists (matches DGB lane convention; required so the consensus-bearing builder actually runs in CI given #137 NOT_BUILT history).

Stacked on #210 (nmc/p1-pb-mempool). Base is the PB branch; will retarget to master once #210 lands.

I do not self-merge — operator merge card via integrator.

frstrtr added 2 commits June 19, 2026 14:10
Adds nmc::coin::Mempool — a byte-faithful mirror of src/impl/btc/coin/
mempool.hpp re-homed into namespace nmc::coin so the NMC coin tree stays
self-contained (no btc::coin symbols). Namecoin is a Bitcoin fork: same
wire format, 21M money cap, 100-block coinbase maturity (NMC_LIMITS,
instantiated locally from the public core::coin::ChainLimits; no core
edit). Feeds the P1 PC template builder next.

Coverage: +3 KATs in the existing (CI-allowlisted) nmc_auxpow_merkle_test
(add/contains/remove + dedup, feerate-ordered selection, confirmed-block
cleanup). Suite 66 -> 69 green. Fence held: src/impl/nmc/ only, no
build.yml / src/core / bitcoin_family change.

Reference: namecoin-core (Bitcoin fork) txmempool.cpp / amount.h MAX_MONEY,
consensus.h COINBASE_MATURITY.
Re-home the BTC native block-template builder into the NMC coin tree so the
embedded merge-mined Namecoin chain can build block templates (WorkData)
natively from its HeaderChain + Mempool, without the getblocktemplate RPC.

  * coin/rpc_data.hpp        -- nmc::coin::rpc::WorkData (template payload)
  * coin/template_builder.hpp -- get_block_subsidy (50 NMC, halving every
    210,000 blocks, identical to Bitcoin), compute_merkle_root (SHA256d),
    CoinNodeInterface, TemplateBuilder::build_template, EmbeddedCoinNode;
    log tags [EMB-NMC].
  * coin/header_chain.hpp    -- add get_header_by_height (parent-link walk,
    no height index), is_synced (DEFAULT_MAX_TIP_AGE gate), and the
    get_next_work_required / calculate_next_work_required retarget the
    builder needs. NMC shares Bitcoins 2016-block / 10-minute retarget.
  * coin/coin_smoke.cpp + CMakeLists -- force-compile the header-only builder.

PC is the STRUCTURAL builder only; merge-mining commitment / dual-target
(phase PD) are not implemented here.

KATs: nmc_template_builder_test (10) covers subsidy halving boundaries,
compute_merkle_root (0/1/2/odd/even leaves, independently re-derived), and
build_template on a seeded chain (tip -> WorkData; empty -> nullopt).
Suite 69 -> 79 green. Fenced to src/impl/nmc/ (plus the one build.yml
--target allowlist line). btc/core trees consumed READ-ONLY.
@frstrtr
frstrtr changed the base branch from nmc/p1-pb-mempool to master June 19, 2026 14:58
@frstrtr frstrtr closed this Jun 19, 2026
@frstrtr frstrtr reopened this Jun 19, 2026
@frstrtr
frstrtr merged commit 98a345b into master Jun 19, 2026
19 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant