From dc391d9929925919da3433e9b37c9ebce23ec568 Mon Sep 17 00:00:00 2001 From: Shoham Chakraborty Date: Wed, 15 Feb 2023 11:45:27 +0800 Subject: [PATCH 1/5] Refactor txordering to use global variables --- src/init.cpp | 6 ++++++ src/miner.cpp | 8 +++----- src/miner.h | 2 ++ src/policy/fees.cpp | 5 ++--- src/rpc/mining.cpp | 4 +--- 5 files changed, 14 insertions(+), 11 deletions(-) diff --git a/src/init.cpp b/src/init.cpp index 505cbde29f..ecd73acaad 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -962,6 +962,12 @@ void InitParameterInteraction() LogPrintf("%s: parameter interaction: -masternode_operator -> setting -leveldbchecksum='true'\n", __func__); } } + + const auto timeOrdering = gArgs.GetBoolArg("-blocktimeordering", DEFAULT_FEE_ORDERING); + if (timeOrdering) + txOrdering = TxOrderings::ENTRYTIME_ORDERING; + + txOrdering = static_cast(gArgs.GetArg("-txordering", DEFAULT_AUTO_FEE_ORDERING)); } /** diff --git a/src/miner.cpp b/src/miner.cpp index 4e218ecbf2..bcefe112bc 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -218,9 +218,7 @@ std::unique_ptr BlockAssembler::CreateNewBlock(const CScript& sc UpdateTime(pblock, consensus, pindexPrev); // update time before tx packaging } - const auto txOrdering = gArgs.GetArg("-txordering", DEFAULT_AUTO_FEE_ORDERING); - bool timeOrdering = gArgs.GetBoolArg("-blocktimeordering", DEFAULT_FEE_ORDERING); - + bool timeOrdering; if (txOrdering == MIXED_ORDERING) { std::random_device rd; std::mt19937_64 gen(rd()); @@ -232,9 +230,9 @@ std::unique_ptr BlockAssembler::CreateNewBlock(const CScript& sc timeOrdering = true; } else if (txOrdering == ENTRYTIME_ORDERING) { timeOrdering = true; - } else if (gArgs.IsArgSet("-txordering") && txOrdering == FEE_ORDERING) { + } else if (txOrdering == FEE_ORDERING) { timeOrdering = false; - } // falls back to blocktimeordering arg if txordering is not set + } if (timeOrdering) { addPackageTxs(nPackagesSelected, nDescendantsUpdated, nHeight, mnview); diff --git a/src/miner.h b/src/miner.h index 9d583047e7..244153f57f 100644 --- a/src/miner.h +++ b/src/miner.h @@ -30,6 +30,8 @@ static const bool DEFAULT_GENERATE = false; static const bool DEFAULT_PRINTPRIORITY = false; +extern TxOrderings txOrdering; + struct CBlockTemplate { CBlock block; diff --git a/src/policy/fees.cpp b/src/policy/fees.cpp index 5dccc83568..37e6d88878 100644 --- a/src/policy/fees.cpp +++ b/src/policy/fees.cpp @@ -9,6 +9,7 @@ #include #include #include +#include #include #include @@ -789,9 +790,7 @@ CFeeRate CBlockPolicyEstimator::estimateSmartFee(int confTarget, FeeCalculation LOCK(m_cs_fee_estimator); // If block ordering by time is enabled return 0 to let fallback or discard fee be used. - if (gArgs.GetBoolArg("-blocktimeordering", DEFAULT_FEE_ORDERING) || - gArgs.GetArg("-txordering", DEFAULT_AUTO_FEE_ORDERING) == MIXED_ORDERING || - gArgs.GetArg("-txordering", DEFAULT_AUTO_FEE_ORDERING) == ENTRYTIME_ORDERING) { + if (txOrdering == MIXED_ORDERING || txOrdering == ENTRYTIME_ORDERING) { return 0; } diff --git a/src/rpc/mining.cpp b/src/rpc/mining.cpp index e170b6c2bb..f5531e4342 100644 --- a/src/rpc/mining.cpp +++ b/src/rpc/mining.cpp @@ -979,9 +979,7 @@ static UniValue estimatesmartfee(const JSONRPCRequest& request) CFeeRate feeRate = ::feeEstimator.estimateSmartFee(conf_target, &feeCalc, conservative); if (feeRate != CFeeRate(0)) { result.pushKV("feerate", ValueFromAmount(feeRate.GetFeePerK())); - } else if (gArgs.GetBoolArg("-blocktimeordering", DEFAULT_FEE_ORDERING) || - gArgs.GetArg("-txordering", DEFAULT_AUTO_FEE_ORDERING) == MIXED_ORDERING || - gArgs.GetArg("-txordering", DEFAULT_AUTO_FEE_ORDERING) == ENTRYTIME_ORDERING) { + } else if (txOrdering == MIXED_ORDERING || txOrdering == ENTRYTIME_ORDERING) { result.pushKV("feerate", ValueFromAmount(DEFAULT_TRANSACTION_MINFEE)); } else { errors.push_back("Insufficient data or no feerate found"); From 405f77461493e2b50ee66ff2810c40a0cd29b7f2 Mon Sep 17 00:00:00 2001 From: Shoham Chakraborty Date: Wed, 15 Feb 2023 12:08:15 +0800 Subject: [PATCH 2/5] Fix build --- src/miner.cpp | 2 +- src/rpc/mining.cpp | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/miner.cpp b/src/miner.cpp index bcefe112bc..267fd76d23 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -218,7 +218,7 @@ std::unique_ptr BlockAssembler::CreateNewBlock(const CScript& sc UpdateTime(pblock, consensus, pindexPrev); // update time before tx packaging } - bool timeOrdering; + bool timeOrdering{false}; if (txOrdering == MIXED_ORDERING) { std::random_device rd; std::mt19937_64 gen(rd()); diff --git a/src/rpc/mining.cpp b/src/rpc/mining.cpp index f5531e4342..6aafed7e44 100644 --- a/src/rpc/mining.cpp +++ b/src/rpc/mining.cpp @@ -36,6 +36,7 @@ #include #include +TxOrderings txOrdering; /** * Return average network hashes per second based on the last 'lookup' blocks, * or from the last difficulty change if 'lookup' is nonpositive. From 2490f56a6d3996328bf90b88e31187f63a203ca9 Mon Sep 17 00:00:00 2001 From: Shoham Chakraborty Date: Wed, 15 Feb 2023 12:39:35 +0800 Subject: [PATCH 3/5] Switch arg processing order --- src/init.cpp | 7 +++---- src/validation.h | 3 +-- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/src/init.cpp b/src/init.cpp index ecd73acaad..263232a66e 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -963,11 +963,10 @@ void InitParameterInteraction() } } - const auto timeOrdering = gArgs.GetBoolArg("-blocktimeordering", DEFAULT_FEE_ORDERING); - if (timeOrdering) - txOrdering = TxOrderings::ENTRYTIME_ORDERING; + txOrdering = static_cast(gArgs.GetArg("-txordering", DEFAULT_TX_ORDERING)); - txOrdering = static_cast(gArgs.GetArg("-txordering", DEFAULT_AUTO_FEE_ORDERING)); + if (gArgs.GetBoolArg("-blocktimeordering", false)) + txOrdering = TxOrderings::ENTRYTIME_ORDERING; } /** diff --git a/src/validation.h b/src/validation.h index ce914e34b4..750ea2f3fe 100644 --- a/src/validation.h +++ b/src/validation.h @@ -138,8 +138,7 @@ static const bool DEFAULT_DEXSTATS = false; /** Default for tracking amount negated by negative interest in attributes */ static const bool DEFAULT_NEGATIVE_INTEREST = false; /** Default for using TX fee ordering in blocks */ -static const bool DEFAULT_FEE_ORDERING = false; -static const TxOrderings DEFAULT_AUTO_FEE_ORDERING = FEE_ORDERING; +static const TxOrderings DEFAULT_TX_ORDERING = FEE_ORDERING; /** Maximum number of headers to announce when relaying blocks with headers message.*/ static const unsigned int MAX_BLOCKS_TO_ANNOUNCE = 8; From 3fa0666ce038a32d55ad0a747799dc0f4f2f8374 Mon Sep 17 00:00:00 2001 From: Shoham Chakraborty Date: Wed, 15 Feb 2023 12:44:01 +0800 Subject: [PATCH 4/5] Fix lint --- test/lint/lint-circular-dependencies.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/test/lint/lint-circular-dependencies.sh b/test/lint/lint-circular-dependencies.sh index cb61437fa8..312d5a8c19 100755 --- a/test/lint/lint-circular-dependencies.sh +++ b/test/lint/lint-circular-dependencies.sh @@ -63,6 +63,7 @@ EXPECTED_CIRCULAR_DEPENDENCIES=( "masternodes/mn_checks -> validation -> masternodes/mn_checks" "masternodes/mn_checks -> validation -> wallet/wallet -> masternodes/mn_checks" "masternodes/validation -> validation -> masternodes/validation" + "miner -> wallet/wallet -> policy/fees -> miner" "net_processing -> validation -> net_processing" "policy/fees -> txmempool -> policy/fees" "policy/fees -> validation -> policy/fees" From 3a43b9d6a9f01d7810c007b06ab81b85eb967eb6 Mon Sep 17 00:00:00 2001 From: Shoham Chakraborty Date: Wed, 15 Feb 2023 12:53:53 +0800 Subject: [PATCH 5/5] Fix build, deprecate blocktimeordering --- src/init.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/init.cpp b/src/init.cpp index 263232a66e..5a8ca0d537 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -512,8 +512,8 @@ void SetupServerArgs() gArgs.AddArg("-regtest-minttoken-simulate-mainnet", "Simulate mainnet for minttokens on regtest - default behavior on regtest is to allow anyone to mint mintable tokens for ease of testing", ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::OPTIONS); gArgs.AddArg("-simulatemainnet", "Configure the regtest network to mainnet target timespan and spacing ", ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::OPTIONS); gArgs.AddArg("-dexstats", strprintf("Enable storing live dex data in DB (default: %u)", DEFAULT_DEXSTATS), ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS); - gArgs.AddArg("-blocktimeordering", strprintf("Whether to order transactions by time, otherwise ordered by fee (default: %u)", DEFAULT_FEE_ORDERING), ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS); - gArgs.AddArg("-txordering", strprintf("Whether to order transactions by entry time, fee or both randomly (0: mixed, 1: fee based, 2: entry time) (default: %u)", DEFAULT_AUTO_FEE_ORDERING), ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS); + gArgs.AddArg("-blocktimeordering", strprintf("(Deprecated) Whether to order transactions by time, otherwise ordered by fee (default: %u)", false), ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS); + gArgs.AddArg("-txordering", strprintf("Whether to order transactions by entry time, fee or both randomly (0: mixed, 1: fee based, 2: entry time) (default: %u)", DEFAULT_TX_ORDERING), ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS); #ifdef USE_UPNP #if USE_UPNP gArgs.AddArg("-upnp", "Use UPnP to map the listening port (default: 1 when listening and no -proxy)", ArgsManager::ALLOW_ANY, OptionsCategory::CONNECTION);