From f3995fa1b7e0a65d7ea3c871f2d2352cee6f22fa Mon Sep 17 00:00:00 2001 From: Duke Date: Wed, 18 Sep 2024 18:12:01 -0400 Subject: [PATCH 1/2] Cleanup MAX_BLOCK_SIZE --- src/chainparams.cpp | 45 +++++++++++++++++++-------------------------- 1 file changed, 19 insertions(+), 26 deletions(-) diff --git a/src/chainparams.cpp b/src/chainparams.cpp index 1d70612a1..18ad10cb0 100644 --- a/src/chainparams.cpp +++ b/src/chainparams.cpp @@ -222,24 +222,6 @@ void CChainParams::SetCheckpointData(CChainParams::CCheckpointData checkpointDat CChainParams::checkpointData = checkpointData; } -/* - To change the max block size, all that needs to be updated is the #define _MAX_BLOCK_SIZE in utils.h - - However, doing that without any other changes will allow forking non-updated nodes by creating a larger block. So, make sure to height activate the new blocksize properly. - - Assuming it is 8MB, then: - #define _OLD_MAX_BLOCK_SIZE (4096 * 1024) - #define _MAX_BLOCK_SIZE (2 * 4096 * 1024) - - change the body of if: - { - if ( height < saplinght+1000000 ) // activates 8MB blocks 1 million blocks after saplinght - return(_OLD_MAX_BLOCK_SIZE); - else return(_MAX_BLOCK_SIZE); - } - -*/ - // Unused Testnet, for completeness. We make testcoins instead. class CTestNetParams : public CChainParams { public: @@ -490,16 +472,27 @@ void UpdateNetworkUpgradeParameters(Consensus::UpgradeIndex idx, int nActivation regTestParams.UpdateNetworkUpgradeParameters(idx, nActivationHeight); } +/* + To change the max block size, all that needs to be updated is the #define _MAX_BLOCK_SIZE in utils.h + + However, doing that without any other changes will allow forking non-updated nodes by creating a larger block. So, make sure to height activate the new blocksize properly. + + Assuming it is 8MB, then: + #define _OLD_MAX_BLOCK_SIZE (4096 * 1024) + #define _MAX_BLOCK_SIZE (2 * 4096 * 1024) + + change the body of MAX_BLOCK_SIZE() function to + { + if ( height < saplinght+1000000 ) // activates 8MB blocks 1 million blocks after saplinght + return(_OLD_MAX_BLOCK_SIZE); + else return(_MAX_BLOCK_SIZE); + } + +*/ + int32_t MAX_BLOCK_SIZE(int32_t height) { - // this codebase requires sapling activation at height=1 - int32_t saplinght = 1; // pCurrentParams->consensus.vUpgrades[Consensus::UPGRADE_SAPLING].nActivationHeight; - //fprintf(stderr,"MAX_BLOCK_SIZE %d vs. %d\n",height,mainParams.consensus.vUpgrades[Consensus::UPGRADE_SAPLING].nActivationHeight); - //if ( height <= 0 || (saplinght > 0 && height >= saplinght) ) - //{ - return(_MAX_BLOCK_SIZE); - //} - //else return(2000000); + return(_MAX_BLOCK_SIZE); } // Change the Hush blocktime at run-time(!) From 792fec7689d606b1bc261afd155ee1ae494a2857 Mon Sep 17 00:00:00 2001 From: Duke Date: Fri, 20 Sep 2024 13:35:38 -0400 Subject: [PATCH 2/2] Do not lock cs_main in mining code Technically we should take this lock but it has never been there before and it leads to potentially large slow downs when mining with multiple cores. We see basically the same hashrate for a single core if we have the lock or not and that makes sense, since there is only one core, there are no other mining threads that have to wait. But on one particular CPU I saw a 6% slower hashing when mining with 2 threads and 35% slower with 3 threads. This change also means debug builds will coredump if mining is enabled. --- src/miner.cpp | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/miner.cpp b/src/miner.cpp index 1bc0e984d..2b5c7c033 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -1320,8 +1320,7 @@ void static RandomXMiner() } CValidationState state; - { LOCK(cs_main); - + //{ LOCK(cs_main); if ( !TestBlockValidity(state,B, chainActive.LastTip(), true, false)) { h = UintToArith256(B.GetHash()); @@ -1332,8 +1331,7 @@ void static RandomXMiner() fprintf(stderr,"\n"); return(false); } - - } + //} SetThreadPriority(THREAD_PRIORITY_NORMAL); LogPrintf("HushRandomXMiner:\n"); LogPrintf("proof-of-work found \n hash: %s \ntarget: %s\n", B.GetHash().GetHex(), HASHTarget.GetHex()); @@ -1692,8 +1690,8 @@ void static BitcoinMiner() fprintf(stderr," mined %s block %d!\n",SMART_CHAIN_SYMBOL,Mining_height); } CValidationState state; - { LOCK(cs_main); + //{ LOCK(cs_main); if ( !TestBlockValidity(state,B, chainActive.LastTip(), true, false)) { h = UintToArith256(B.GetHash()); @@ -1704,7 +1702,7 @@ void static BitcoinMiner() return(false); } - } + //} HUSH_CHOSEN_ONE = 1; // Found a solution SetThreadPriority(THREAD_PRIORITY_NORMAL);