cleanup: dedup addrman Select_ table walk and pow-limit-by-algo selection
Two behavior-preserving refactors flagged by the Phase-6 hygiene scoping: * addrman: CAddrMan::Select_ contained two ~40-line copies of the same bucket-table random walk, differing only in the table (vvTried/vvNew), its bucket count, and a log label. Extract the shared loop into SelectFromTable_(vvTable, nBucketCount, tableName); Select_ now just dispatches to it. Verbatim move — clean compile proves self-containment. * pow: the "Equihash uses powLimit, everything else uses powAlternate" selection was copy-pasted as an if/else into GetNextWorkRequired, CalculateNextWorkRequired, and lwmaCalculateNextWorkRequired. Extract into PowLimitForAlgo(params). The CheckProofOfWork site (line ~892) is left as-is: it has an extra `height <= 1` genesis special-case and is NOT the same selection. On DragonX (RandomX) this always returns powAlternate, exactly as before. Validated: full build of dragonxd/cli/tx, isolated self-mine to height 336, verifychain 4 0 -> true (exercises PowLimitForAlgo on every block). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
+11
-12
@@ -97,6 +97,14 @@ bnTarget = RT_CST_RST (bnTarget, ts, cw, numerator, denominator, W, T, past);
|
||||
#define T ASSETCHAINS_BLOCKTIME
|
||||
#define K ((int64_t)1000000)
|
||||
|
||||
// The proof-of-work limit for the active algorithm: Equihash chains use params.powLimit,
|
||||
// everything else (DragonX = RandomX) uses params.powAlternate. Shared by the retarget
|
||||
// functions below, where this selection was previously copy-pasted as an if/else.
|
||||
static arith_uint256 PowLimitForAlgo(const Consensus::Params& params)
|
||||
{
|
||||
return UintToArith256(ASSETCHAINS_ALGO == ASSETCHAINS_EQUIHASH ? params.powLimit : params.powAlternate);
|
||||
}
|
||||
|
||||
arith_uint256 RT_CST_RST_outer(int32_t height,uint32_t nTime,arith_uint256 bnTarget,uint32_t *ts,arith_uint256 *ct,int32_t numerator,int32_t denominator,int32_t W,int32_t past)
|
||||
{
|
||||
int64_t outerK; int32_t cmpval; arith_uint256 mintarget = bnTarget / arith_uint256(2);
|
||||
@@ -211,10 +219,7 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead
|
||||
}
|
||||
|
||||
arith_uint256 bnLimit;
|
||||
if (ASSETCHAINS_ALGO == ASSETCHAINS_EQUIHASH)
|
||||
bnLimit = UintToArith256(params.powLimit);
|
||||
else
|
||||
bnLimit = UintToArith256(params.powAlternate);
|
||||
bnLimit = PowLimitForAlgo(params);
|
||||
unsigned int nProofOfWorkLimit = bnLimit.GetCompact();
|
||||
// Genesis block
|
||||
if (pindexLast == NULL )
|
||||
@@ -461,10 +466,7 @@ unsigned int CalculateNextWorkRequired(arith_uint256 bnAvg,
|
||||
}
|
||||
// Retarget
|
||||
arith_uint256 bnLimit;
|
||||
if (ASSETCHAINS_ALGO == ASSETCHAINS_EQUIHASH)
|
||||
bnLimit = UintToArith256(params.powLimit);
|
||||
else
|
||||
bnLimit = UintToArith256(params.powAlternate);
|
||||
bnLimit = PowLimitForAlgo(params);
|
||||
|
||||
const arith_uint256 bnPowLimit = bnLimit; //UintToArith256(params.powLimit);
|
||||
arith_uint256 bnNew {bnAvg};
|
||||
@@ -498,10 +500,7 @@ unsigned int lwmaGetNextWorkRequired(const CBlockIndex* pindexLast, const CBlock
|
||||
unsigned int lwmaCalculateNextWorkRequired(const CBlockIndex* pindexLast, const Consensus::Params& params)
|
||||
{
|
||||
arith_uint256 nextTarget {0}, sumTarget {0}, bnTmp, bnLimit;
|
||||
if (ASSETCHAINS_ALGO == ASSETCHAINS_EQUIHASH)
|
||||
bnLimit = UintToArith256(params.powLimit);
|
||||
else
|
||||
bnLimit = UintToArith256(params.powAlternate);
|
||||
bnLimit = PowLimitForAlgo(params);
|
||||
|
||||
unsigned int nProofOfWorkLimit = bnLimit.GetCompact();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user