Skip to content

Commit 53bebdd

Browse files
Merge branch 'develop' of https://github.com/dashpay/dash into develop
2 parents 6b3c4bd + c40f3db commit 53bebdd

File tree

6 files changed

+52
-53
lines changed

6 files changed

+52
-53
lines changed

src/llmq/quorums.cpp

Lines changed: 20 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,6 @@ namespace llmq
3434
static const std::string DB_QUORUM_SK_SHARE = "q_Qsk";
3535
static const std::string DB_QUORUM_QUORUM_VVEC = "q_Qqvvec";
3636

37-
RecursiveMutex cs_data_requests;
38-
static std::unordered_map<CQuorumDataRequestKey, CQuorumDataRequest, StaticSaltedHasher> mapQuorumDataRequests GUARDED_BY(cs_data_requests);
39-
40-
4137
static uint256 MakeQuorumKey(const CQuorum& q)
4238
{
4339
CHashWriter hw(SER_NETWORK, 0);
@@ -707,18 +703,9 @@ size_t CQuorumManager::GetQuorumRecoveryStartOffset(const CQuorum& quorum, gsl::
707703

708704
MessageProcessingResult CQuorumManager::ProcessMessage(CNode& pfrom, CConnman& connman, std::string_view msg_type, CDataStream& vRecv)
709705
{
710-
auto strFunc = __func__;
711-
auto errorHandler = [&](const std::string& strError, int nScore = 10) -> MessageProcessingResult {
712-
LogPrint(BCLog::LLMQ, "CQuorumManager::%s -- %s: %s, from peer=%d\n", strFunc, msg_type, strError, pfrom.GetId());
713-
if (nScore > 0) {
714-
return MisbehavingError{nScore};
715-
}
716-
return {};
717-
};
718-
719706
if (msg_type == NetMsgType::QGETDATA) {
720707
if (m_mn_activeman == nullptr || (pfrom.GetVerifiedProRegTxHash().IsNull() && !pfrom.qwatch)) {
721-
return errorHandler("Not a verified masternode or a qwatch connection");
708+
return MisbehavingError{10, "not a verified masternode or a qwatch connection"};
722709
}
723710

724711
CQuorumDataRequest request;
@@ -735,7 +722,7 @@ MessageProcessingResult CQuorumManager::ProcessMessage(CNode& pfrom, CConnman& c
735722
case (CQuorumDataRequest::Errors::QUORUM_NOT_FOUND):
736723
case (CQuorumDataRequest::Errors::MASTERNODE_IS_NO_MEMBER):
737724
case (CQuorumDataRequest::Errors::UNDEFINED):
738-
if (request_limit_exceeded) ret = errorHandler("Request limit exceeded", 25);
725+
if (request_limit_exceeded) ret = MisbehavingError{25, "request limit exceeded"};
739726
break;
740727
case (CQuorumDataRequest::Errors::QUORUM_VERIFICATION_VECTOR_MISSING):
741728
case (CQuorumDataRequest::Errors::ENCRYPTED_CONTRIBUTIONS_MISSING):
@@ -812,7 +799,7 @@ MessageProcessingResult CQuorumManager::ProcessMessage(CNode& pfrom, CConnman& c
812799

813800
if (msg_type == NetMsgType::QDATA) {
814801
if ((m_mn_activeman == nullptr && !m_quorums_watch) || pfrom.GetVerifiedProRegTxHash().IsNull()) {
815-
return errorHandler("Not a verified masternode and -watchquorums is not enabled");
802+
return MisbehavingError{10, "not a verified masternode and -watchquorums is not enabled"};
816803
}
817804

818805
CQuorumDataRequest request;
@@ -823,25 +810,28 @@ MessageProcessingResult CQuorumManager::ProcessMessage(CNode& pfrom, CConnman& c
823810
const CQuorumDataRequestKey key(pfrom.GetVerifiedProRegTxHash(), true, request.GetQuorumHash(), request.GetLLMQType());
824811
auto it = mapQuorumDataRequests.find(key);
825812
if (it == mapQuorumDataRequests.end()) {
826-
return errorHandler("Not requested");
813+
return MisbehavingError{10, "not requested"};
827814
}
828815
if (it->second.IsProcessed()) {
829-
return errorHandler("Already received");
816+
return MisbehavingError(10, "already received");
830817
}
831818
if (request != it->second) {
832-
return errorHandler("Not like requested");
819+
return MisbehavingError(10, "not like requested");
833820
}
834821
it->second.SetProcessed();
835822
}
836823

837824
if (request.GetError() != CQuorumDataRequest::Errors::NONE) {
838-
return errorHandler(strprintf("Error %d (%s)", request.GetError(), request.GetErrorString()), 0);
825+
LogPrint(BCLog::LLMQ, "CQuorumManager::%s -- %s: %s, from peer=%d\n", __func__, msg_type, strprintf("Error %d (%s)", request.GetError(), request.GetErrorString()), pfrom.GetId());
826+
return {};
839827
}
840828

841829
CQuorumPtr pQuorum;
842830
{
843831
if (LOCK(cs_map_quorums); !mapQuorumsCache[request.GetLLMQType()].get(request.GetQuorumHash(), pQuorum)) {
844-
return errorHandler("Quorum not found", 0); // Don't bump score because we asked for it
832+
// Don't bump score because we asked for it
833+
LogPrint(BCLog::LLMQ, "CQuorumManager::%s -- %s: Quorum not found, from peer=%d\n", __func__, msg_type, pfrom.GetId());
834+
return {};
845835
}
846836
}
847837

@@ -854,7 +844,7 @@ MessageProcessingResult CQuorumManager::ProcessMessage(CNode& pfrom, CConnman& c
854844
if (pQuorum->SetVerificationVector(verificationVector)) {
855845
StartCachePopulatorThread(pQuorum);
856846
} else {
857-
return errorHandler("Invalid quorum verification vector");
847+
return MisbehavingError{10, "invalid quorum verification vector"};
858848
}
859849
}
860850

@@ -863,12 +853,16 @@ MessageProcessingResult CQuorumManager::ProcessMessage(CNode& pfrom, CConnman& c
863853
assert(m_mn_activeman);
864854

865855
if (WITH_LOCK(pQuorum->cs_vvec_shShare, return pQuorum->quorumVvec->size() != size_t(pQuorum->params.threshold))) {
866-
return errorHandler("No valid quorum verification vector available", 0); // Don't bump score because we asked for it
856+
// Don't bump score because we asked for it
857+
LogPrint(BCLog::LLMQ, "CQuorumManager::%s -- %s: No valid quorum verification vector available, from peer=%d\n", __func__, msg_type, pfrom.GetId());
858+
return {};
867859
}
868860

869861
int memberIdx = pQuorum->GetMemberIndex(request.GetProTxHash());
870862
if (memberIdx == -1) {
871-
return errorHandler("Not a member of the quorum", 0); // Don't bump score because we asked for it
863+
// Don't bump score because we asked for it
864+
LogPrint(BCLog::LLMQ, "CQuorumManager::%s -- %s: Not a member of the quorum, from peer=%d\n", __func__, msg_type, pfrom.GetId());
865+
return {};
872866
}
873867

874868
std::vector<CBLSIESEncryptedObject<CBLSSecretKey>> vecEncrypted;
@@ -878,13 +872,13 @@ MessageProcessingResult CQuorumManager::ProcessMessage(CNode& pfrom, CConnman& c
878872
vecSecretKeys.resize(vecEncrypted.size());
879873
for (const auto i : irange::range(vecEncrypted.size())) {
880874
if (!m_mn_activeman->Decrypt(vecEncrypted[i], memberIdx, vecSecretKeys[i], PROTOCOL_VERSION)) {
881-
return errorHandler("Failed to decrypt");
875+
return MisbehavingError{10, "failed to decrypt"};
882876
}
883877
}
884878

885879
CBLSSecretKey secretKeyShare = blsWorker.AggregateSecretKeys(vecSecretKeys);
886880
if (!pQuorum->SetSecretKeyShare(secretKeyShare, *m_mn_activeman)) {
887-
return errorHandler("Invalid secret key share received");
881+
return MisbehavingError{10, "invalid secret key share received"};
888882
}
889883
}
890884
WITH_LOCK(cs_db, pQuorum->WriteContributions(*db));

src/llmq/quorums.h

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,10 @@ class CQuorumManager
251251
mutable Mutex cs_db;
252252
std::unique_ptr<CDBWrapper> db GUARDED_BY(cs_db){nullptr};
253253

254+
mutable Mutex cs_data_requests;
255+
mutable std::unordered_map<CQuorumDataRequestKey, CQuorumDataRequest, StaticSaltedHasher> mapQuorumDataRequests
256+
GUARDED_BY(cs_data_requests);
257+
254258
mutable Mutex cs_map_quorums;
255259
mutable std::map<Consensus::LLMQType, Uint256LruHashMap<CQuorumPtr>> mapQuorumsCache GUARDED_BY(cs_map_quorums);
256260

@@ -294,19 +298,19 @@ class CQuorumManager
294298
void Stop();
295299

296300
void TriggerQuorumDataRecoveryThreads(CConnman& connman, gsl::not_null<const CBlockIndex*> pIndex) const
297-
EXCLUSIVE_LOCKS_REQUIRED(!cs_db, !cs_scan_quorums, !cs_map_quorums);
301+
EXCLUSIVE_LOCKS_REQUIRED(!cs_db, !cs_data_requests, !cs_scan_quorums, !cs_map_quorums);
298302

299303
void UpdatedBlockTip(const CBlockIndex* pindexNew, CConnman& connman, bool fInitialDownload) const
300-
EXCLUSIVE_LOCKS_REQUIRED(!cs_db, !cs_scan_quorums, !cs_map_quorums);
304+
EXCLUSIVE_LOCKS_REQUIRED(!cs_db, !cs_data_requests, !cs_scan_quorums, !cs_map_quorums);
301305

302306
[[nodiscard]] MessageProcessingResult ProcessMessage(CNode& pfrom, CConnman& connman, std::string_view msg_type,
303307
CDataStream& vRecv)
304-
EXCLUSIVE_LOCKS_REQUIRED(!cs_map_quorums, !cs_db);
308+
EXCLUSIVE_LOCKS_REQUIRED(!cs_db, !cs_data_requests, !cs_map_quorums);
305309

306310
static bool HasQuorum(Consensus::LLMQType llmqType, const CQuorumBlockProcessor& quorum_block_processor, const uint256& quorumHash);
307311

308312
bool RequestQuorumData(CNode* pfrom, CConnman& connman, const CQuorum& quorum, uint16_t nDataMask,
309-
const uint256& proTxHash = uint256()) const;
313+
const uint256& proTxHash = uint256()) const EXCLUSIVE_LOCKS_REQUIRED(!cs_data_requests);
310314

311315
// all these methods will lock cs_main for a short period of time
312316
CQuorumCPtr GetQuorum(Consensus::LLMQType llmqType, const uint256& quorumHash) const
@@ -341,7 +345,7 @@ class CQuorumManager
341345

342346
void StartCachePopulatorThread(CQuorumCPtr pQuorum) const;
343347
void StartQuorumDataRecoveryThread(CConnman& connman, CQuorumCPtr pQuorum, gsl::not_null<const CBlockIndex*> pIndex,
344-
uint16_t nDataMask) const;
348+
uint16_t nDataMask) const EXCLUSIVE_LOCKS_REQUIRED(!cs_data_requests);
345349

346350
void StartCleanupOldQuorumDataThread(gsl::not_null<const CBlockIndex*> pIndex) const;
347351
void MigrateOldQuorumDB(CEvoDB& evoDb) const EXCLUSIVE_LOCKS_REQUIRED(!cs_db);

src/qt/optionsmodel.cpp

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -564,16 +564,22 @@ QVariant OptionsModel::data(const QModelIndex & index, int role) const
564564
case FontScale:
565565
return settings.value("fontScale");
566566
case FontWeightNormal: {
567-
QFont::Weight weight{GUIUtil::g_font_registry.GetWeightNormalDefault()};
568-
GUIUtil::weightFromArg(settings.value("fontWeightNormal").toInt(), weight);
569-
int nIndex = GUIUtil::g_font_registry.WeightToIdx(weight);
567+
int nIndex = [&]() -> int {
568+
if (QFont::Weight weight; GUIUtil::weightFromArg(settings.value("fontWeightNormal").toInt(), weight) && GUIUtil::g_font_registry.IsValidWeight(weight)) {
569+
return GUIUtil::g_font_registry.WeightToIdx(weight);
570+
}
571+
return GUIUtil::g_font_registry.WeightToIdx(GUIUtil::g_font_registry.GetWeightNormalDefault());
572+
}();
570573
assert(nIndex != -1);
571574
return nIndex;
572575
}
573576
case FontWeightBold: {
574-
QFont::Weight weight{GUIUtil::g_font_registry.GetWeightBoldDefault()};
575-
GUIUtil::weightFromArg(settings.value("fontWeightBold").toInt(), weight);
576-
int nIndex = GUIUtil::g_font_registry.WeightToIdx(weight);
577+
int nIndex = [&]() -> int {
578+
if (QFont::Weight weight; GUIUtil::weightFromArg(settings.value("fontWeightBold").toInt(), weight) && GUIUtil::g_font_registry.IsValidWeight(weight)) {
579+
return GUIUtil::g_font_registry.WeightToIdx(weight);
580+
}
581+
return GUIUtil::g_font_registry.WeightToIdx(GUIUtil::g_font_registry.GetWeightBoldDefault());
582+
}();
577583
assert(nIndex != -1);
578584
return nIndex;
579585
}

src/wallet/wallet.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3967,7 +3967,12 @@ void CWallet::SetupDescriptorScriptPubKeyMans(const SecureString& mnemonic_arg,
39673967
spk_manager->SetupDescriptor(std::move(desc));
39683968
uint256 id = spk_manager->GetID();
39693969
m_spk_managers[id] = std::move(spk_manager);
3970-
AddActiveScriptPubKeyMan(id, internal);
3970+
// Only activate BIP44 descriptors, similar to how the non-external-signer branch
3971+
// only activates certain types (External and Internal, but not CoinJoin)
3972+
std::string bip44_purpose = strprintf("/%d'/%s'", BIP32_PURPOSE_STANDARD, Params().ExtCoinType());
3973+
if (desc_str.find(bip44_purpose) != std::string::npos) {
3974+
AddActiveScriptPubKeyMan(id, internal);
3975+
}
39713976
}
39723977
}
39733978
}

test/functional/mocks/invalid_signer.py

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,19 +22,13 @@ def enumerate(args):
2222

2323
def getdescriptors(args):
2424
xpub_pkh = "xpub6CRhJvXV8x2AKWvqi1ZSMFU6cbxzQiYrv3dxSUXCawjMJ1JzpqVsveH4way1yCmJm29KzH1zrVZmVwes4Qo6oXVE1HFn4fdiKrYJngqFFc6"
25-
xpub_sh = "xpub6CoNoq3Tg4tGSpom2BSwL42gy864KHo3TXkHxLxBbhvCkgmdVXADQmiHbLZhX3Me1cYhRx7s25Lpm4LnT5zu395ANHsXB2QvT9tqJDAibTN"
26-
xpub_pkh = "xpub6DUcLgY1DfgDy2RV6q4djwwsLitaoZDumbribqrR8mP78fEtgZa1XEsqT5MWQ7gwLwKsTQPT28XLoVE5A97rDNTwMXjmzPaNijoCApCbWvp"
2725

2826
sys.stdout.write(json.dumps({
2927
"receive": [
30-
"pkh([b3c19bfc/44'/1'/" + args.account + "']" + xpub_pkh + "/0/*)#h26nxtl9",
31-
"sh(pkh([b3c19bfc/49'/1'/" + args.account + "']" + xpub_sh + "/0/*))#32ry02yp",
32-
"pkh([b3c19bfc/84'/1'/" + args.account + "']" + xpub_pkh + "/0/*)#jftn8ppv"
28+
"pkh([b3c19bfc/44'/1'/" + args.account + "']" + xpub_pkh + "/0/*)#h26nxtl9"
3329
],
3430
"internal": [
35-
"pkh([b3c19bfc/44'/1'/" + args.account + "']" + xpub_pkh + "/1/*)#x7ljm70a",
36-
"sh(pkh([b3c19bfc/49'/1'/" + args.account + "']" + xpub_sh + "/1/*))#ytdjh437",
37-
"pkh([b3c19bfc/84'/1'/" + args.account + "']" + xpub_pkh + "/1/*)#rawj6535"
31+
"pkh([b3c19bfc/44'/1'/" + args.account + "']" + xpub_pkh + "/1/*)#x7ljm70a"
3832
]
3933
}))
4034

test/functional/mocks/signer.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,10 @@ def getdescriptors(args):
2525

2626
sys.stdout.write(json.dumps({
2727
"receive": [
28-
"pkh([00000001/44'/1'/" + args.account + "']" + xpub + "/0/*)#vt6w3l3j",
29-
"sh(pkh([00000001/49'/1'/" + args.account + "']" + xpub + "/0/*))#az7uyg3n",
30-
"pkh([00000001/84'/1'/" + args.account + "']" + xpub + "/0/*)#58ssc2nq"
28+
"pkh([00000001/44'/1'/" + args.account + "']" + xpub + "/0/*)#vt6w3l3j"
3129
],
3230
"internal": [
33-
"pkh([00000001/44'/1'/" + args.account + "']" + xpub + "/1/*)#all0v2p2",
34-
"sh(pkh([00000001/49'/1'/" + args.account + "']" + xpub + "/1/*))#mpkel968",
35-
"pkh([00000001/84'/1'/" + args.account + "']" + xpub + "/1/*)#9n439lrc"
31+
"pkh([00000001/44'/1'/" + args.account + "']" + xpub + "/1/*)#all0v2p2"
3632
]
3733
}))
3834

@@ -44,7 +40,7 @@ def displayaddress(args):
4440
return sys.stdout.write(json.dumps({"error": "Unexpected fingerprint", "fingerprint": args.fingerprint}))
4541

4642
expected_desc = [
47-
"pkh([00000001/84'/1'/0'/0/0]02c97dc3f4420402e01a113984311bf4a1b8de376cac0bdcfaf1b3ac81f13433c7)#0yneg42r"
43+
"pkh([00000001/44'/1'/0'/0/0]02c97dc3f4420402e01a113984311bf4a1b8de376cac0bdcfaf1b3ac81f13433c7)#0yneg42r"
4844
]
4945
if args.desc not in expected_desc:
5046
return sys.stdout.write(json.dumps({"error": "Unexpected descriptor", "desc": args.desc}))

0 commit comments

Comments
 (0)