From 10906597d44bddfb051cacec81ce3cef260cb979 Mon Sep 17 00:00:00 2001 From: DanS Date: Wed, 4 Mar 2026 00:14:39 -0600 Subject: [PATCH] Fix DragonX P2P port, block subsidy, blocktime, and difficulty params MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - chainparams.cpp: Correct P2P port from 18030 to 21768 - hush_utils.h: Use CRC-based network magic instead of HUSH_MAGIC shortcut so new standalone binary matches existing network nodes - hush_utils.h: Remove DragonX-specific hush_block_subsidy() call, use generic ASSETCHAINS_HALVING logic consistent with mainnet - hush_utils.h: Fix P2P port override so -port flag works correctly - main.cpp: Remove blocktime halving code (150s→75s at z2zheight) that does not apply to DragonX's fixed 36s blocktime - pow.cpp: Use params.AveragingWindowTimespan() (17*36=612) instead of standalone AveragingWindowTimespan() which returns HUSH3's 17*75=1275 --- src/chainparams.cpp | 2 +- src/hush_utils.h | 24 +++++++++++++----------- src/main.cpp | 34 ++++------------------------------ src/pow.cpp | 6 +++--- 4 files changed, 21 insertions(+), 45 deletions(-) diff --git a/src/chainparams.cpp b/src/chainparams.cpp index 0d1a84092..fb87916c0 100644 --- a/src/chainparams.cpp +++ b/src/chainparams.cpp @@ -520,7 +520,7 @@ void *chainparams_commandline() { if ( SMART_CHAIN_SYMBOL[0] != 0 ) { if (strcmp(SMART_CHAIN_SYMBOL,"DRAGONX") == 0) { - ASSETCHAINS_P2PPORT = 18030; + ASSETCHAINS_P2PPORT = 21768; } if ( ASSETCHAINS_BLOCKTIME != 60 ) diff --git a/src/hush_utils.h b/src/hush_utils.h index 05f7190d8..811c42f12 100644 --- a/src/hush_utils.h +++ b/src/hush_utils.h @@ -1476,7 +1476,10 @@ uint32_t hush_smartmagic(char *symbol,uint64_t supply,uint8_t *extraptr,int32_t //TODO: why is this needed? const bool isdragonx = strncmp(symbol, "DRAGONX",7) == 0 ? true : false; if(isdragonx) { - return HUSH_MAGIC; + // Use the same CRC-based magic as all other chains so that the + // network magic bytes match between old wrapper-launched nodes + // and the new standalone binary. + return(calc_crc32(crc0,buf,len)); } else { return(calc_crc32(crc0,buf,len)); } @@ -1650,13 +1653,11 @@ uint64_t hush_sc_block_subsidy(int nHeight) if(fDebug) { fprintf(stderr,"%s: subsidy=%ld at height=%d with ASSETCHAINS_HALVING[curEra]=%lu\n",__func__,subsidy,nHeight, ASSETCHAINS_HALVING[curEra]); } - if ( ASSETCHAINS_HALVING[curEra] != 0 ) + if (ASSETCHAINS_HALVING[curEra] != 0) { - if (isdragonx) { - subsidy = hush_block_subsidy(nHeight); - if(fDebug) - fprintf(stderr,"%s: DRAGONX subsidy=%ld at height=%d\n",__func__,subsidy,nHeight); - } else if ( (numhalvings = ((nHeight - nStart) / ASSETCHAINS_HALVING[curEra])) > 0 ) { + // hush_block_subsidy() is HUSH3-specific with hardcoded reward schedule + // DragonX uses generic halving logic with ASSETCHAINS_REWARD/ASSETCHAINS_HALVING + if ( (numhalvings = ((nHeight - nStart) / ASSETCHAINS_HALVING[curEra])) > 0 ) { // The code below is not compatible with DRAGONX mainnet if ( ASSETCHAINS_DECAY[curEra] == 0 ) { subsidy >>= numhalvings; @@ -2349,13 +2350,14 @@ void hush_args(char *argv0) fprintf(stderr,"MAX_MONEY %llu %.8f\n",(long long)MAX_MONEY,(double)MAX_MONEY/SATOSHIDEN); //printf("baseid.%d MAX_MONEY.%s %.8f\n",baseid,SMART_CHAIN_SYMBOL,(double)MAX_MONEY/SATOSHIDEN); uint16_t tmpport = hush_port(SMART_CHAIN_SYMBOL,ASSETCHAINS_SUPPLY,&ASSETCHAINS_MAGIC,extraptr,extralen); + // DragonX P2P port is 21768 (RPC=21769). The HUSH_MAGIC shortcut in + // hush_smartmagic() produces 18030 which is wrong, so override here. + if(isdragonx) { + tmpport = 21768; + } if ( GetArg("-port",0) != 0 ) { ASSETCHAINS_P2PPORT = GetArg("-port",0); - if(isdragonx) { - fprintf(stderr,"set DRAGONX p2pport.%u\n",ASSETCHAINS_P2PPORT); - ASSETCHAINS_P2PPORT = 18030; - } if(fDebug) fprintf(stderr,"set p2pport.%u\n",ASSETCHAINS_P2PPORT); } else ASSETCHAINS_P2PPORT = tmpport; diff --git a/src/main.cpp b/src/main.cpp index aa2e1b767..d69a70627 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3062,15 +3062,8 @@ bool DisconnectBlock(CBlock& block, CValidationState& state, CBlockIndex* pindex // move best block pointer to prevout block view.SetBestBlock(pindex->pprev->GetBlockHash()); - // If disconnecting a block brings us back before our blocktime halving height, go back - // to our original blocktime so our DAA has the correct target for that height + // DragonX has a fixed 36s blocktime - no blocktime halving needed int nHeight = pindex->pprev->GetHeight(); - nFirstHalvingHeight = GetArg("-z2zheight",340000); - if (isdragonx && (ASSETCHAINS_BLOCKTIME != 150) && (nHeight < nFirstHalvingHeight)) { - LogPrintf("%s: Setting blocktime to 150s at height %d!\n",__func__,nHeight); - ASSETCHAINS_BLOCKTIME = 150; - hush_changeblocktime(); - } if (pfClean) { @@ -3154,11 +3147,7 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin ASSETCHAINS_PRIVATE = 1; } } - if (isdragonx && (ASSETCHAINS_BLOCKTIME != 75) && (chainActive.Height() >= nFirstHalvingHeight)) { - LogPrintf("%s: Blocktime halving to 75s at height %d!\n",__func__,pindex->GetHeight()); - ASSETCHAINS_BLOCKTIME = 75; - hush_changeblocktime(); - } + // DragonX has a fixed 36s blocktime - no blocktime halving needed bool fExpensiveChecks = true; if (fCheckpointsEnabled) { @@ -3761,14 +3750,7 @@ void static UpdateTip(CBlockIndex *pindexNew) { progress = (longestchain > 0 ) ? (double) chainActive.Height() / longestchain : 1.0; } - nFirstHalvingHeight = GetArg("-z2zheight",340000); - if(isdragonx) { - if (ASSETCHAINS_BLOCKTIME != 75 && (chainActive.Height() >= nFirstHalvingHeight)) { - LogPrintf("%s: Blocktime halving to 75s at height %d!\n",__func__,chainActive.Height()); - ASSETCHAINS_BLOCKTIME = 75; - hush_changeblocktime(); - } - } + // DragonX has a fixed 36s blocktime - no blocktime halving needed LogPrintf("%s: new best=%s height=%d log2_work=%.8g tx=%lu date=%s progress=%f cache=%.1fMiB(%utx)\n", __func__, chainActive.LastTip()->GetBlockHash().ToString(), chainActive.Height(), @@ -5113,15 +5095,7 @@ bool ContextualCheckBlockHeader(const CBlockHeader& block, CValidationState& sta // Check Proof-of-Work difficulty if (isdragonx) { - // Difficulty (nBits) relies on the current blocktime of this block - if ((ASSETCHAINS_BLOCKTIME != 75) && (nHeight >= nFirstHalvingHeight)) { - LogPrintf("%s: Blocktime halving to 75s at height %d!\n",__func__,nHeight); - ASSETCHAINS_BLOCKTIME = 75; - hush_changeblocktime(); - } - // The change of blocktime from 150s to 75s caused incorrect AWT of 34 blocks instead of 17 - // caused by the fact that Difficulty Adjustment Algorithms do not take into account blocktime - // changing at run-time, from Consensus::Params being a const struct + // DragonX has a fixed 36s blocktime - no blocktime halving needed unsigned int nNextWork = GetNextWorkRequired(pindexPrev, &block, consensusParams); if (fDebug) { diff --git a/src/pow.cpp b/src/pow.cpp index 23ebd4a61..e464a7bb7 100644 --- a/src/pow.cpp +++ b/src/pow.cpp @@ -533,9 +533,9 @@ unsigned int CalculateNextWorkRequired(arith_uint256 bnAvg, int64_t nActualTimespan = nLastBlockTime - nFirstBlockTime; LogPrint("pow", " nActualTimespan = %d before dampening\n", nActualTimespan); - bool isdragonx = strncmp(SMART_CHAIN_SYMBOL, "DRAGONX",7) == 0 ? true : false; - // If this is DRAGONX, use AWT function defined above, else use the one in params - int64_t AWT = isdragonx ? AveragingWindowTimespan() : params.AveragingWindowTimespan(); + // DragonX uses params.AveragingWindowTimespan() = nPowAveragingWindow * nPowTargetSpacing = 17 * 36 = 612 + // The standalone AveragingWindowTimespan() returns 1275 which is HUSH3-specific (17 * 75s) + int64_t AWT = params.AveragingWindowTimespan(); nActualTimespan = AWT + (nActualTimespan - AWT)/4; LogPrint("pow", " nActualTimespan = %d before bounds\n", nActualTimespan);