Commit fd8f99c
authored
bch(m4): ABLA replay + dynamic per-tip template size budget (M4 anchor) (#120)
* bch(m3): ASERT (aserti3-2d) DAA — 1:1 BCHN pow.cpp port
Net-new BCH-specific validation slice (M1 §4.3, no btc/ analogue).
CalculateASERT + GetNextASERTWorkRequired ported byte-exact from BCHN
src/pow.cpp; anchors from chainparams.cpp (main/testnet3/testnet4).
Governs SPV header-accept target only — PoW hash stays SHA256d, zero
share-format / p2pool-merged-v36 surface change. Syntax-clean -std=c++20.
* bch(m3): header-chain validation wired to ASERT DAA (M3 slice 18b)
Port src/impl/btc/coin/header_chain.hpp to BCH: same store/sync/persistence
and SHA256d PoW, with the one BCH divergence being difficulty. Replaces
Bitcoin's 2016-block 2-week retarget with ASERT (aserti3-2d) by wiring
validate_difficulty()/get_next_work_required() to asert.hpp (slice 18a).
- BCHChainParams carries the ASERTParams anchor (asert.hpp) instead of a
(timespan, spacing, interval) tuple; pow_limit/allow_min_difficulty mirror
the anchor. mainnet/testnet3 genesis shared with Bitcoin (pre-fork); BCH
testnet4 genesis flagged TODO-verify against VM300 bchn-bch chainparams.
- validate_difficulty drops the ancestor-walk lookback (ASERT is anchor-
absolute): trusts pre-anchor history and synthetic checkpoint seeds, else
asserts header.nBits == get_next_work_required_asert(tip,...).
- No p2pool-merged-v36 surface: ASERT governs header accept only, not the
PoW hash or share format.
Single-coin, src-only (no impl_bch CMake registration). Syntax-clean
-std=c++20. Push held pending PR #106 ratification.
* bch: add coinbase/template commitment construction + validation
Standalone-parent commitment layout (BTC minus AuxPoW segment):
[BIP34 height][/c2pool/][state_root 32B][TheMetadata]. BIP34 enforced
per BCHN ContextualCheckBlock; no witness commitment (SegWit struck);
CTOR handled separately by template tx sort; CashTokens transparent.
Source-only header; shared by M4 GBT builder and the share validator.
* bch(m4): template builder body — GBT assembly + CTOR + ASERT (M4 slice 1)
Flesh out bch::coin::TemplateBuilder (was an M4 TODO stub) into a working
GBT assembler from HeaderChain + Mempool, mirroring the BTC builder with the
BCH consensus divergences:
* SHA256d merkle root + 50-BCH/210k-halving subsidy (== BTC curve).
* Next-block bits from the ASERT (aserti3-2d) DAA, not a 2016-block
retarget; falls back to tip bits / pow_limit below the ASERT anchor.
* CTOR (CHIP-2018-11): block body re-sorted to ascending txid after fee
selection, coinbase excluded.
* No SegWit: single canonical tx serialization, hash == txid, empty
segwit-free rules array. CashTokens carried transparently in tx bytes.
* EmbeddedCoinNode wired to build_template() for getwork().
Coinbase tx (and its s19 commitment) is still assembled downstream, as on
BTC; binding ../coinbase_commitment.hpp into the coinbase builder is the
next M4 slice. ABLA dynamic block-size and the rules array are pinned to
pre-ABLA 32 MB EB / empty here pending verification vs VM300 bchn-bch GBT
and the p2pool-merged-v36 python reference.
Source-only, -fsyntax-only clean. No impl_bch CMake registration (does not
race ci-steward); bch lane stays skip-green.
* bch(m4): ABLA block-size limit (CHIP-2023-01) + template size-budget sourcing
Add abla.hpp -- a 1:1 fixed-point port of BCHN consensus/abla.{h,cpp}
(pinned at v29.0.0): Config (MakeDefault/SetMax) + State (NextBlockState,
GetBlockSizeLimit). Mainnet grows; testnets fixed at 32 MB.
Route the template builder block-size byte budget through abla at the
activation/floor limit (32 MB) instead of a static constant. The floor is a
safe LOCAL build cap -- ABLA only ever raises it, so a template built to the
floor can never exceed the live consensus limit. Per-tip ABLA state replay
through the header chain (dynamic limit) is the next size-slice.
No p2pool-merged-v36 surface: ABLA governs only the block-size limit, not
PoW hash, share format, coinbase commitment, or PPLNS math.
Roundtrip exec: floor==32MB both nets; mainnet->41.3MB after 5000 full
blocks; testnet fixed. abla.hpp + template_builder.hpp -fsyntax-only OK.
* bch(m4): ABLA replay primitive + dynamic per-tip template size budget
Add abla::replay() -- replay ABLA State forward from a known-good anchor
over a contiguous run of full-block sizes (1:1 BCHN State::NextBlockState
loop). Wire TemplateBuilder::build_template to consume an optional caller-
supplied per-tip ABLA State, using its GetBlockSizeLimit() as the dynamic
block-size budget; absent it, fall back to the activation/floor limit
(unchanged, always-safe LOCAL build cap).
The per-block-size feed that drives replay is a full-block/embedded-daemon
concern (M5+): the headers-only SPV header_chain structurally does not carry
block sizes, so the dynamic limit is re-homed there rather than forced into
the header chain. Build budget only -- zero p2pool-merged-v36 surface
(no PoW hash, share format, coinbase commitment, or PPLNS touched).
Validated: mainnet replay 5000x32MB grows 32->39.48MB (bounded by
MAX_CONSENSUS_BLOCK_SIZE); testnet fixedSize stays 32MB; empty replay = anchor.
---------
Co-authored-by: frstrtr <frstrtr@users.noreply.github.com>1 parent 152ef20 commit fd8f99c
5 files changed
Lines changed: 2039 additions & 26 deletions
File tree
- src/impl/bch
- coin
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
0 commit comments