对 Parallax 难度调整历史的精确梳理——从创世开始的 BTC 风格 DAA、在区块 17,560 处启用的 ASERT 升级(PIP-0002),以及基于累积工作量的 Nakamoto 分叉选择规则。
| 参数 | 符号 | 数值 | 说明 |
|---|---|---|---|
| 目标出块间隔 | τ | 600 秒 | 类似 Bitcoin 的目标 |
| 未来时间漂移上限 | — | 300 秒 | 5 分钟 |
| MTP 采样数 | — | 11 区块 | 最近 11 个时间戳的中位数 |
| 难度算法历史 | — | BTC 风格 DAA → ASERT | 创世至 17,559 区块采用 BTC 风格的 2016 区块窗口;区块 ≥ 17,560 改用 ASERT(aserti3-2d,PIP-0002)。 |
// Given difficulty D (big integer)
TWO256M1 = (1n << 256n) - 1n
target = TWO256M1 / D
valid = BigIntFromBytes(result) <= target
// Difficulty selection by era
CalcDifficulty(config, anchor, parent, header):
if height(header) < 17560:
// BTC-style DAA: 2016-block window with epoch anchors
return CalcNakamotoDifficulty(config, parent)
else:
// ASERT: per-block retarget relative to fixed anchor
return CalcAsertDifficulty(config, anchor, parent, header)
// ASERT core idea (fixed-point, aserti3-2d)
CalcAsertDifficulty(config, anchor, parent, header):
Δh = height(header) - anchor.height
Δt = header.Time - anchor.parentTime // seconds
// τ = 600 s target, T_half = 172800 s (2 days)
e = ((Δt - Δh * τ) * RADIX) / T_half // fixed-point exponent
target = anchor.target * 2^e // via cubic approximation in integer math
target = clamp(target, 1, maxTarget)
return DifficultyFromTarget(target)
MTP(n):
ts = timestamps(n, upTo=11) // back from n inclusive
sort(ts)
return ts[len(ts)//2]
Work(block):
target = TWO256M1 / Difficulty(block)
// Use an approximation that preserves ordering; e.g.,
return TWO256M1 / (target + 1)
SelectBest(tips):
return argmax(tips, ChainWork[tip])
OnNewTip(candidate):
if ChainWork[candidate] > ChainWork[currentTip]:
currentTip = candidate
ReorgTo(candidate)
ValidHeader(h, parent):
require(len(h.Extra) <= MaximumExtraDataSize)
require(h.Time <= now() + 300)
require(h.Time > MTP(parent))
require(h.Difficulty > 0)
// difficulty rules depend on height:
// < 17560: BTC-style DAA epoch invariants
// ≥ 17560: ASERT anchor-based invariants
// PoW: MixDigest match & XHash(h) <= targetFrom(D)
区块头会依次通过 Extra 大小、时间(MTP 与未来漂移)、所处时代对应的难度规则(早期采用 BTC 风格 DAA,区块高度 ≥ 17,560 改用 ASERT)、Gas 上限/EIP、高度递增以及 PoW seal 等校验。有效区块会扩展 ChainWork,最重的链尾即为规范链。