From 7477d839cd32d5309114d222a2cf9ea2216ff925 Mon Sep 17 00:00:00 2001 From: UdjinM6 Date: Mon, 12 Jun 2023 10:57:49 +0300 Subject: [PATCH] Merge pull request #5425 from UdjinM6/multi_fixes fix: Various small fixes --- src/bip39.cpp | 4 ++-- src/bip39.h | 2 +- src/evo/specialtx.cpp | 2 +- src/init.cpp | 4 ++-- src/llmq/utils.cpp | 2 +- src/pow.cpp | 4 ++++ src/qt/bitcoingui.cpp | 2 +- src/qt/optionsdialog.cpp | 13 ++++++++----- src/qt/optionsdialog.h | 1 + src/qt/sendcoinsdialog.cpp | 1 + src/test/evo_utils_tests.cpp | 6 +++--- src/unordered_lru_cache.h | 2 +- src/wallet/walletdb.cpp | 4 +++- 13 files changed, 29 insertions(+), 18 deletions(-) diff --git a/src/bip39.cpp b/src/bip39.cpp index 2134f98dec..61c19bdbd6 100644 --- a/src/bip39.cpp +++ b/src/bip39.cpp @@ -147,11 +147,11 @@ bool CMnemonic::Check(SecureString mnemonic) return fResult; } -// passphrase must be at most 256 characters or code may crash +// passphrase must be at most 256 characters otherwise it would be truncated void CMnemonic::ToSeed(SecureString mnemonic, SecureString passphrase, SecureVector& seedRet) { SecureString ssSalt = SecureString("mnemonic") + passphrase; - SecureVector vchSalt(ssSalt.begin(), ssSalt.end()); + SecureVector vchSalt(ssSalt.begin(), ssSalt.begin() + strnlen(ssSalt.data(), 256)); seedRet.resize(64); PKCS5_PBKDF2_HMAC_SHA512(mnemonic.c_str(), mnemonic.size(), vchSalt.data(), vchSalt.size(), 2048, 64, seedRet.data()); } diff --git a/src/bip39.h b/src/bip39.h index 9c6426b244..30f3a6880e 100644 --- a/src/bip39.h +++ b/src/bip39.h @@ -32,7 +32,7 @@ public: static SecureString Generate(int strength); // strength in bits static SecureString FromData(const SecureVector& data, int len); static bool Check(SecureString mnemonic); - // passphrase must be at most 256 characters or code may crash + // passphrase must be at most 256 characters otherwise it would be truncated static void ToSeed(SecureString mnemonic, SecureString passphrase, SecureVector& seedRet); }; diff --git a/src/evo/specialtx.cpp b/src/evo/specialtx.cpp index 4dd9c0203c..6a1820dd9e 100644 --- a/src/evo/specialtx.cpp +++ b/src/evo/specialtx.cpp @@ -9,7 +9,7 @@ uint256 CalcTxInputsHash(const CTransaction& tx) { - CHashWriter hw(CLIENT_VERSION, SER_GETHASH); + CHashWriter hw(SER_GETHASH, CLIENT_VERSION); for (const auto& in : tx.vin) { hw << in.prevout; } diff --git a/src/init.cpp b/src/init.cpp index e391bb4efc..026fcc9e10 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -734,14 +734,14 @@ void SetupServerArgs(NodeContext& node) argsman.AddArg("-pushversion", "Protocol version to report to other nodes", ArgsManager::ALLOW_ANY, OptionsCategory::DEBUG_TEST); argsman.AddArg("-shrinkdebugfile", "Shrink debug.log file on client startup (default: 1 when no -debug)", ArgsManager::ALLOW_ANY, OptionsCategory::DEBUG_TEST); argsman.AddArg("-sporkaddr=", "Override spork address. Only useful for regtest and devnet. Using this on mainnet or testnet will ban you.", ArgsManager::ALLOW_ANY, OptionsCategory::DEBUG_TEST); - argsman.AddArg("-sporkkey=", "Set the private key to be used for signing spork messages.", ArgsManager::ALLOW_ANY, OptionsCategory::DEBUG_TEST); + argsman.AddArg("-sporkkey=", "Set the private key to be used for signing spork messages.", ArgsManager::ALLOW_ANY | ArgsManager::SENSITIVE, OptionsCategory::DEBUG_TEST); argsman.AddArg("-uacomment=", "Append comment to the user agent string", ArgsManager::ALLOW_ANY, OptionsCategory::DEBUG_TEST); SetupChainParamsBaseOptions(argsman); argsman.AddArg("-llmq-data-recovery=", strprintf("Enable automated quorum data recovery (default: %u)", llmq::DEFAULT_ENABLE_QUORUM_DATA_RECOVERY), ArgsManager::ALLOW_ANY, OptionsCategory::MASTERNODE); argsman.AddArg("-llmq-qvvec-sync=:", strprintf("Defines from which LLMQ type the masternode should sync quorum verification vectors. Can be used multiple times with different LLMQ types. : %d (sync always from all quorums of the type defined by ), %d (sync from all quorums of the type defined by if a member of any of the quorums)", (int32_t)llmq::QvvecSyncMode::Always, (int32_t)llmq::QvvecSyncMode::OnlyIfTypeMember), ArgsManager::ALLOW_ANY, OptionsCategory::MASTERNODE); - argsman.AddArg("-masternodeblsprivkey=", "Set the masternode BLS private key and enable the client to act as a masternode", ArgsManager::ALLOW_ANY, OptionsCategory::MASTERNODE); + argsman.AddArg("-masternodeblsprivkey=", "Set the masternode BLS private key and enable the client to act as a masternode", ArgsManager::ALLOW_ANY | ArgsManager::SENSITIVE, OptionsCategory::MASTERNODE); argsman.AddArg("-platform-user=", "Set the username for the \"platform user\", a restricted user intended to be used by Dash Platform, to the specified username.", ArgsManager::ALLOW_ANY, OptionsCategory::MASTERNODE); argsman.AddArg("-acceptnonstdtxn", strprintf("Relay and mine \"non-standard\" transactions (%sdefault: %u)", "testnet/regtest only; ", !testnetChainParams->RequireStandard()), ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::NODE_RELAY); diff --git a/src/llmq/utils.cpp b/src/llmq/utils.cpp index ce0fba766c..0d43c311d4 100644 --- a/src/llmq/utils.cpp +++ b/src/llmq/utils.cpp @@ -573,7 +573,7 @@ uint256 BuildCommitmentHash(Consensus::LLMQType llmqType, const uint256& blockHa const std::vector& validMembers, const CBLSPublicKey& pubKey, const uint256& vvecHash) { - CHashWriter hw(SER_NETWORK, 0); + CHashWriter hw(SER_GETHASH, 0); hw << llmqType; hw << blockHash; hw << DYNBITSET(validMembers); diff --git a/src/pow.cpp b/src/pow.cpp index 9135ebb42a..ed014aeba7 100644 --- a/src/pow.cpp +++ b/src/pow.cpp @@ -181,6 +181,10 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead // Note: GetNextWorkRequiredBTC has it's own special difficulty rule, // so we only apply this to post-BTC algos. + if (params.fPowNoRetargeting) { + return bnPowLimit.GetCompact(); + } + if (params.fPowAllowMinDifficultyBlocks) { // recent block is more than 2 hours old if (pblock->GetBlockTime() > pindexLast->GetBlockTime() + 2 * 60 * 60) { diff --git a/src/qt/bitcoingui.cpp b/src/qt/bitcoingui.cpp index 9851801a9f..4b244637f0 100644 --- a/src/qt/bitcoingui.cpp +++ b/src/qt/bitcoingui.cpp @@ -460,7 +460,7 @@ void BitcoinGUI::createActions() // Jump directly to tabs in RPC-console connect(openInfoAction, &QAction::triggered, this, &BitcoinGUI::showInfo); - connect(openRPCConsoleAction, &QAction::triggered, this, &BitcoinGUI::showDebugWindow); + connect(openRPCConsoleAction, &QAction::triggered, this, &BitcoinGUI::showConsole); connect(openGraphAction, &QAction::triggered, this, &BitcoinGUI::showGraph); connect(openPeersAction, &QAction::triggered, this, &BitcoinGUI::showPeers); connect(openRepairAction, &QAction::triggered, this, &BitcoinGUI::showRepair); diff --git a/src/qt/optionsdialog.cpp b/src/qt/optionsdialog.cpp index 440685835b..586a7aae74 100644 --- a/src/qt/optionsdialog.cpp +++ b/src/qt/optionsdialog.cpp @@ -38,7 +38,8 @@ OptionsDialog::OptionsDialog(QWidget *parent, bool enableWallet) : ui(new Ui::OptionsDialog), model(nullptr), mapper(nullptr), - pageButtons(nullptr) + pageButtons(nullptr), + m_enable_wallet(enableWallet) { ui->setupUi(this); @@ -108,7 +109,7 @@ OptionsDialog::OptionsDialog(QWidget *parent, bool enableWallet) : pageButtons = new QButtonGroup(this); pageButtons->addButton(ui->btnMain, pageButtons->buttons().size()); /* Remove Wallet/CoinJoin tabs and 3rd party-URL textbox in case of -disablewallet */ - if (!enableWallet) { + if (!m_enable_wallet) { ui->stackedWidgetOptions->removeWidget(ui->pageWallet); ui->btnWallet->hide(); ui->stackedWidgetOptions->removeWidget(ui->pageCoinJoin); @@ -396,9 +397,11 @@ void OptionsDialog::on_okButton_clicked() mapper->submit(); appearance->accept(); #ifdef ENABLE_WALLET - for (auto& wallet : model->node().walletClient().getWallets()) { - wallet->coinJoin().resetCachedBlocks(); - wallet->markDirty(); + if (m_enable_wallet) { + for (auto& wallet : model->node().walletClient().getWallets()) { + wallet->coinJoin().resetCachedBlocks(); + wallet->markDirty(); + } } #endif // ENABLE_WALLET accept(); diff --git a/src/qt/optionsdialog.h b/src/qt/optionsdialog.h index 56042bbadc..3eceb2f0f1 100644 --- a/src/qt/optionsdialog.h +++ b/src/qt/optionsdialog.h @@ -89,6 +89,7 @@ private: QString previousTheme; AppearanceWidget* appearance; bool fCoinJoinEnabledPrev{false}; + bool m_enable_wallet{false}; void showEvent(QShowEvent* event) override; }; diff --git a/src/qt/sendcoinsdialog.cpp b/src/qt/sendcoinsdialog.cpp index 6e07593fb4..986a30061f 100644 --- a/src/qt/sendcoinsdialog.cpp +++ b/src/qt/sendcoinsdialog.cpp @@ -86,6 +86,7 @@ SendCoinsDialog::SendCoinsDialog(bool _fCoinJoin, QWidget* parent) : GUIUtil::setFont({ui->labelCoinControlFeatures }, GUIUtil::FontWeight::Bold, 16); + ui->checkBoxCoinControlChange->setEnabled(!_fCoinJoin); GUIUtil::setupAddressWidget(ui->lineEditCoinControlChange, this); addEntry(); diff --git a/src/test/evo_utils_tests.cpp b/src/test/evo_utils_tests.cpp index 42b0001642..5ff3c196a6 100644 --- a/src/test/evo_utils_tests.cpp +++ b/src/test/evo_utils_tests.cpp @@ -29,14 +29,14 @@ void Test(llmq::CQuorumManager& qman) BOOST_CHECK_EQUAL(IsQuorumTypeEnabledInternal(consensus_params.llmqTypeDIP0024InstantSend, qman, nullptr, true, false), true); BOOST_CHECK_EQUAL(IsQuorumTypeEnabledInternal(consensus_params.llmqTypeDIP0024InstantSend, qman, nullptr, true, true), true); BOOST_CHECK_EQUAL(IsQuorumTypeEnabledInternal(consensus_params.llmqTypeChainLocks, qman, nullptr, false, false), true); - BOOST_CHECK_EQUAL(IsQuorumTypeEnabledInternal(consensus_params.llmqTypeChainLocks, qman, nullptr, false, false), true); BOOST_CHECK_EQUAL(IsQuorumTypeEnabledInternal(consensus_params.llmqTypeChainLocks, qman, nullptr, true, false), true); + BOOST_CHECK_EQUAL(IsQuorumTypeEnabledInternal(consensus_params.llmqTypeChainLocks, qman, nullptr, true, true), true); + BOOST_CHECK_EQUAL(IsQuorumTypeEnabledInternal(consensus_params.llmqTypePlatform, qman, nullptr, false, false), Params().IsTestChain()); BOOST_CHECK_EQUAL(IsQuorumTypeEnabledInternal(consensus_params.llmqTypePlatform, qman, nullptr, true, false), Params().IsTestChain()); BOOST_CHECK_EQUAL(IsQuorumTypeEnabledInternal(consensus_params.llmqTypePlatform, qman, nullptr, true, true), Params().IsTestChain()); - BOOST_CHECK_EQUAL(IsQuorumTypeEnabledInternal(consensus_params.llmqTypePlatform, qman, nullptr, true, true), Params().IsTestChain()); + BOOST_CHECK_EQUAL(IsQuorumTypeEnabledInternal(consensus_params.llmqTypeMnhf, qman, nullptr, false, false), true); BOOST_CHECK_EQUAL(IsQuorumTypeEnabledInternal(consensus_params.llmqTypeMnhf, qman, nullptr, true, false), true); BOOST_CHECK_EQUAL(IsQuorumTypeEnabledInternal(consensus_params.llmqTypeMnhf, qman, nullptr, true, true), true); - BOOST_CHECK_EQUAL(IsQuorumTypeEnabledInternal(consensus_params.llmqTypeMnhf, qman, nullptr, true, true), true); } BOOST_FIXTURE_TEST_CASE(utils_IsQuorumTypeEnabled_tests_regtest, RegTestingSetup) diff --git a/src/unordered_lru_cache.h b/src/unordered_lru_cache.h index 8a364b8547..7208737dde 100644 --- a/src/unordered_lru_cache.h +++ b/src/unordered_lru_cache.h @@ -36,7 +36,6 @@ public: template void _emplace(const Key& key, Value2&& v) { - truncate_if_needed(); auto it = cacheMap.find(key); if (it == cacheMap.end()) { cacheMap.emplace(key, std::make_pair(std::forward(v), accessCounter++)); @@ -44,6 +43,7 @@ public: it->second.first = std::forward(v); it->second.second = accessCounter++; } + truncate_if_needed(); } void emplace(const Key& key, Value&& v) diff --git a/src/wallet/walletdb.cpp b/src/wallet/walletdb.cpp index fcddef2ddb..677129d3c0 100644 --- a/src/wallet/walletdb.cpp +++ b/src/wallet/walletdb.cpp @@ -486,7 +486,9 @@ ReadKeyValue(CWallet* pwallet, CDataStream& ssKey, CDataStream& ssValue, strErr = "Found unsupported 'wkey' record, try loading with version 0.17"; return false; } else if (strType != DBKeys::BESTBLOCK && strType != DBKeys::BESTBLOCK_NOMERKLE && - strType != DBKeys::MINVERSION && strType != DBKeys::ACENTRY && strType != DBKeys::VERSION) { + strType != DBKeys::MINVERSION && strType != DBKeys::ACENTRY && + strType != DBKeys::VERSION && + strType != DBKeys::PRIVATESEND_SALT && strType != DBKeys::COINJOIN_SALT) { wss.m_unknown_records++; } } catch (const std::exception& e) {