Repository navigation
feat: AuxPoW merge-mining (v30.4.0, activates at height 80000) - #3
Conversation
…ow + check()
Foundation for merge-mining (Namecoin/Dogecoin-compatible), targeting fork
height 80000 as v30.4.0. NOT yet wired into the block/validation/RPC paths.
- primitives/pureheader.{h,cpp}: CPureBlockHeader (the 80-byte PoW-committed
header) + version helpers (chain id in bits 16..31, AuxPoW flag bit 8).
- auxpow.{h,cpp}: CAuxPow (parent coinbase + merkle branches + parent header),
the wire format, CAuxPow::check() (coinbase-merkle + chain-merkle + the
merged-mining magic scan + size/nonce index), CheckMerkleBranch helper.
Remaining: CBlockHeader refactor to derive CPureBlockHeader + carry auxpow,
pow.cpp CheckProofOfWork(header) integration, chainparams aux params,
ContextualCheckBlockHeader version enforcement, getauxblock/submitauxblock RPC,
auxpow_tests, CMakeLists. Gated behind those tests + live merge-mine interop
testing with Andy before the 80000 activation.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Hi9Fj21YnCdsu73fPDkw6o
…core builds) - CBlockHeader now derives CPureBlockHeader and carries an optional CAuxPow, serialised after the pure header iff the version has the AuxPoW flag. - pow: CheckProofOfWork(header) resolves AuxPoW — the parent-chain block must meet our nBits and commit this block's hash; else normal PoW. Call sites in CheckBlockHeader + HasValidProofOfWork updated. - validation: ContextualCheckBlockHeader rejects AuxPoW before nAuxpowStartHeight and enforces the chain id from the fork onward. - chainparams: mainnet AuxPoW fork at 80000, chain id 0x0062; regtest fork at 1, non-strict chain id for round-trip tests. consensus/params.h gains nAuxpowChainId / nAuxpowStartHeight / fStrictChainId. - CMake: auxpow.cpp + primitives/pureheader.cpp in perbug_consensus. perbugd builds + links + runs with this. Remaining: createauxblock/submitauxblock RPC + getblocktemplate chain-id, auxpow_tests, regtest merge-mine round-trip. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Hi9Fj21YnCdsu73fPDkw6o
…erified) CreateAuxPow builds a minimal valid merge-mining proof (single-slot chain tree, single-tx parent) for tests + the regtest round-trip. auxpow_tests exercises CAuxPow::check(): a valid proof is accepted; a wrong aux hash, a stripped coinbase commitment, a corrupted parent merkle root, and a coinbase not at index 0 are all rejected. Plus a CheckMerkleBranch identity check. All green. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Hi9Fj21YnCdsu73fPDkw6o
…bmitauxblock RPC - node/miner.cpp: from nAuxpowStartHeight every template carries our chain id in the version (SetBaseVersion), so even non-merge-mined blocks from the existing pool validate post-fork. - rpc/mining.cpp: createauxblock returns the hash to commit in the parent coinbase (+ chain id, bits, target); submitauxblock takes that hash + the serialised AuxPoW, attaches it, and submits via ProcessNewBlock. A small template cache maps the committed hash back to the block. perbugd + perbug-cli build clean; both commands register. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Hi9Fj21YnCdsu73fPDkw6o
… round-trip passes - createauxblock: getBlock() leaves hashMerkleRoot unfinalised, so the submitted block was rejected bad-txnmrklroot; recompute BlockMerkleRoot before caching + hashing the template. - contrib/auxpow/auxpow_roundtrip.py: a standalone regtest pool simulator — createauxblock -> build a valid AuxPoW (parent coinbase committing the aux hash, solved to target) -> submitauxblock. Verified live: block accepted, chain 20 -> 21. - Dropped the unit submit test (TestChain100Setup's mock clock vs Perbug's 150s spacing trips the future-time check inside BlockAssembler); the live round-trip covers that path instead. check()/merkle unit tests remain. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Hi9Fj21YnCdsu73fPDkw6o
|
Bug report (issues are disabled on this repo, so posting here on the change that added merge-mining) v30.4.2: merge-mined blocks break restart, wallet rescan, and header serving (assert auxpow != nullptr)Thanks for adding merge-mining. Running v30.4.2 (tag at 77ea9a5, built from source on Linux x86_64), we hit two problems once the chain is past the AuxPoW activation height (80,000). Both look like they would affect any node that restarts, including pool and explorer nodes. 1. Restart fails, and rescans skip every merge-mined blockSteps: sync a fresh node past 80,000, stop it cleanly, start it again. Result: start-up aborts with Cause (as far as we can tell):
For an AuxPoW block that hash never meets the target (the work is in the parent block), so both checks fail. Local fix we tested (doesn't change which blocks are accepted): skip the hash-only check for blocks with the AuxPoW version flag when loading the index, and use the header overload, which resolves the AuxPoW, in --- a/src/node/blockstorage.cpp
+++ b/src/node/blockstorage.cpp
@@ -134,7 +134,8 @@ bool BlockTreeDB::LoadBlockIndexGuts(...)
- if (!CheckProofOfWork(pindexNew->GetBlockHash(), pindexNew->nBits, consensusParams)) {
+ if (!(pindexNew->nVersion & CPureBlockHeader::VERSION_AUXPOW) &&
+ !CheckProofOfWork(pindexNew->GetBlockHash(), pindexNew->nBits, consensusParams)) {
@@ -1017,8 +1018,8 @@ bool BlockManager::ReadBlock(...)
- if (!CheckProofOfWork(block_hash, block.nBits, GetConsensus())) {
+ if (!CheckProofOfWork(static_cast<const CBlockHeader&>(block), GetConsensus())) {With this, the node restarts cleanly and loads its index. 2. Node aborts on
|
|
Both confirmed, both fixed, shipped in v30.4.3. Thank you — the diagnosis was correct on both counts and detailed enough to patch from directly. Two things worth adding to your report. This was already happening in production, not just theoretically. Our own mainnet node had been crash-looping on exactly this, 20,034 restarts, on exactly the error you predicted: 80,011 is the first merge-mined block after activation. It took the block explorer's sync down with it. Your line about nodes that have run nonstop "probably haven't seen either problem yet, but will after their next restart" was exactly right, and for us that restart had already happened. Your second problem had already been patched by @colneech-dev in #4, opened three days before your report and covering all five affected call sites including the ones you flagged as unpatched. That PR sat unreviewed because GitHub gates workflow runs for first-time contributors and nobody approved it. That is on us, not on either of you. What shipped
For the header path, a new UpgradingNo reindex is needed. It is a code-only fix; existing datadirs load as they are. The Verified on live mainnet against a datadir that had been accumulating merge-mined blocks since the fork: loads its index, reaches the tip, stays up with peers connected with zero assert hits, Upgrade urgency is high for anyone on v30.4.x. A node that has not restarted since before block 80,000 has not hit this yet but will the moment it stops — including after a crash or a reboot. You offered to test a fixed release: that would be genuinely useful, particularly the headers path under real peer traffic, which is the part we have exercised least. |
Adds Namecoin/Dogecoin-style AuxPoW merge-mining so large SHA-256 pools can keep Perbug alive at no cost to their miners (Andy's suggestion #2). Activates at height 80,000 (chain id
0x0062); before that nothing changes.What's in it
primitives/pureheader.*) + the version/chain-ID/aux-flag scheme.CAuxPow(auxpow.*): parent coinbase + merkle branches + parent header, the wire format, andcheck()— merkle-branch verification + merged-mining magic scan + size/nonce index.CBlockHeadernow derivesCPureBlockHeaderand carries an optional auxpow (serialised after the pure header iff the aux flag is set).CheckProofOfWork(header)resolves AuxPoW (parent-chain PoW + commitment); else normal PoW.createauxblock/submitauxblock.0x0062; regtest fork 1 + non-strict for tests.Verification
auxpow_testsunit tests: valid proof accepted; wrong hash, stripped commitment, bad merkle root, coinbase-not-at-0 all rejected.0x00620004, validation accepts them,createauxblockreturns a valid template.contrib/auxpow/auxpow_roundtrip.py): createauxblock → build a real AuxPoW → submitauxblock → block accepted, chain extends. ✅Before activation
HARD FORK: all nodes/pools must run v30.4.0 before 80,000. Authoritative wire-format check = a live merge-mine test against Andy's real SHA-256 pool (planned). Also carries the LWMA fixes already on master.