The core issue is that the gossipsub protocol in libp2p requires at least one peer in the mesh to publish messages. When running a single node, the miner can't broadcast newly created anchors, which stalls the mining process since the miner is waiting for the next anchor to begin mining the next epoch.
Consider changing gossipsub validation to Strict and add quotas. Tune RocksDB options for throughput/durability on the VM. Add sync metrics for orphan buffer size and range request progress; bound orphan map by MAX_ORPHAN_ANCHORS.
- Epochs as time buckets:
- Fixed-length epochs (on-chain enforced duration).
- Each epoch publishes an anchor committing to exactly the coins that “won” for that epoch.
- Hard coin cap per epoch:
- Configured
max_coins_per_epochis a consensus parameter. - During an epoch, miners submit PoW coins; at finalization the protocol selects the top N coins (N = cap) by a deterministic score (e.g., smallest PoW hash as uint256). Others are orphaned.
- This enforces a predictable mint rate and fairly resolves races.
- Configured
- Coin header:
- Fields:
epoch_hash,miner_address,nonce,version,pow_params. - Salt = blake3(epoch_hash || miner_address || nonce). Consensus-fix lanes=1.
- Fields:
- PoW validity:
- Use target-based difficulty:
pow_hash <= target. Work = ⌊2^256/(target+1)⌋; enables fine-grained retarget. - Memory-hard via Argon2id with epoch-committed
mem_kib. Adjust slowly at retarget boundaries with strict integer math and caps.
- Use target-based difficulty:
- Self-contained coins via certificates:
- Define
CoinCertificate = { coin, anchor_header, merkle_proof }. - Anyone can verify a coin with just the certificate: check PoW, anchor chain-work, and inclusion proof.
- Define
- Anchor header:
epoch_num, prev_anchor_hash, merkle_root_coin_ids, target(nBits), mem_kib, max_coins_per_epoch, coin_count_selected, cumulative_work, epoch_start_time, epoch_duration, version.
- Deterministic selection:
- From all valid coin IDs observed in the epoch, select the N with the lowest PoW hash (ties broken by coin_id).
- Compute the Merkle root over the selected set (sorted leaves = blake3(coin_id)).
- Persist the selected list (or a compact commitment) so proofs can be served deterministically.
- Finality semantics:
- A coin is “confirmed” only if included in the epoch anchor’s selected set. Wallets should spend only confirmed coins.
- Reorg can invalidate inclusion; SPV spenders must reference the anchor.
- Goal: keep expected winners per epoch ≈
max_coins_per_epoch. - Mechanics:
- Difficulty (target) adjusts using LWMA/ASERT-like integer algorithm based on observed selected coin count. Clamp change per retarget to avoid oscillations.
mem_kibadjusts with wide hysteresis and strong clamps; avoid flapping. Commit both in the next epoch’s header.
- Result: network tends to produce only slightly more candidates than the cap; the “top N by quality” selection resolves contention fairly.
- Gossip topics:
- Coins (provisional), Anchors (final), Requests: latest anchor, specific epoch, coin proof.
- Strict validation and quotas:
- Strict pubsub validation; per-peer quotas (messages/second, bytes), invalid-penalty scoring, exponential bans.
- Proof service:
- Add request/response protocol to fetch a
CoinCertificatebycoin_idafter finalization.
- Add request/response protocol to fetch a
- Orphan handling:
- Buffer out-of-order anchors; process once parents arrive; cap buffers.
- Anchors-first:
- Download and verify anchor headers (PoW/chain-work); pick best chain.
- Fetch only proofs for coins you need (wallet addresses, mempool referencing inputs).
- Range sync:
- Parallel, bounded requests for epochs between local and best.
- Reorg safety:
- Maintain short reorg window; rollback inclusion-dependent state if the best chain changes.
- Spend rules:
- V2
Spendreferences a confirmed coin with an inclusion proof at spend time. - Signature: Dilithium3 over authorization bytes; ownership is defined by previous spend or genesis.
- V2
- Mempool:
- Accept only spends that spend confirmed coins and pass proof/sig/ownership checks.
- Fee optional; if you keep fee-less, rate-limit and prioritize by age/size to prevent spam.
- Column families:
anchors,coin_candidates(per-epoch, all seen),coin_selected(confirmed),proof_index(optional precomputed paths),transfer,wallet.
- Proofs:
- Store per-epoch sorted leaf array (or a succinct commitment). Generate proofs on demand; cache results.
- Reasonable RocksDB tuning:
- Drop extreme fsync settings; use batched writes + WAL with periodic fsyncs; expose DB health.
- Confirmed-only balance:
- Balance/UTXO set computed from
coin_selectedonly.
- Balance/UTXO set computed from
- Send flow:
- Only spend confirmed coins; include the coin’s anchor hash in the unsigned transfer so relays can quickly pre-check.
- Security:
- Keep XChaCha20-Poly1305 with Argon2id KDF; require non-interactive passphrase provisioning for headless nodes.
- Metrics:
- epoch height, best hash, cumulative work, target, mem_kib, buffer size, candidate_count, selected_count, Nth-winner score threshold, peer counts, proofs served, reorg depth, DB latency.
- Tracing:
- Structured logs; sampling for hot paths.
- Consensus/validation:
- Replace byte-prefix difficulty with target-based checks and cumulative work calculation.
- Commit
max_coins_per_epochandmem_kibin anchors; enforce lanes=1; remove non-consensuslanesfrom config.
- Epoch manager:
- Keep buffering coin IDs, but on tick:
- Sort by PoW hash; select top N; compute Merkle over selected; record selection; discard rest.
- Persist per-epoch sorted leaves to enable proofs; or store a compact structure to recompute.
- Keep buffering coin IDs, but on tick:
- Network:
- Tighten pubsub validation; add RPC for coin proof retrieval; rate-limit coin candidate gossip.
- Wallet:
- Only treat “selected” coins as spendable; expose confirmations tied to anchor.
- Transfers:
- Upgrade
prev_tx_hashto refer to the last transfer, enabling multi-hop chains.
- Upgrade
Why this fits unchained’s ethos
-
Epoch-first minting with hard caps: predictable issuance, fair competition via “top N wins” per epoch.
-
Independent coin verification: coin + anchor + proof yields self-contained validation.
-
PQ and memory-hardness: retained and made consensus-clear.
-
Decentralized sync: anchors-first minimizes bandwidth; proofs are fetched only when needed.
-
Defined a perfect epoch-centric design: hard per-epoch mint cap with deterministic top-N selection, anchor-committed proofs, and target-based PoW.
-
Specified concrete consensus fields/rules, selection, proofs, retargeting, and reorg handling.
-
Outlined exact module-level changes to reach this design while preserving your core principles.