diff options
author | Pieter Wuille <pieter.wuille@gmail.com> | 2013-07-20 14:34:16 +0200 |
---|---|---|
committer | Pieter Wuille <pieter.wuille@gmail.com> | 2013-10-15 22:34:20 +0200 |
commit | 6055b9101bc91647fb80c7ed86fcff90e3e6dedf (patch) | |
tree | b77370a39843e583cbfe513e196883a1df9b5e3f | |
parent | 38d15d8b427904a936a4fb4b8ac390bd637e1638 (diff) |
Allow SendMessages to run partially without cs_main
SendMessages() tries to acquire a cs_main lock now, but this isn't nessecary
for much of its functionality. Move those parts out of the locked section,
so they can always be performed, and we hold cs_main for a shorter time.
-rw-r--r-- | src/main.cpp | 34 |
1 files changed, 18 insertions, 16 deletions
diff --git a/src/main.cpp b/src/main.cpp index 477bc74fae..0c31655fe9 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -4134,8 +4134,7 @@ bool ProcessMessages(CNode* pfrom) bool SendMessages(CNode* pto, bool fSendTrickle) { - TRY_LOCK(cs_main, lockMain); - if (lockMain) { + { // Don't send anything until we get their version message if (pto->nVersion == 0) return true; @@ -4170,20 +4169,6 @@ bool SendMessages(CNode* pto, bool fSendTrickle) } } - // Start block sync - if (pto->fStartSync && !fImporting && !fReindex) { - pto->fStartSync = false; - PushGetBlocks(pto, chainActive.Tip(), uint256(0)); - } - - // Resend wallet transactions that haven't gotten in a block yet - // Except during reindex, importing and IBD, when old wallet - // transactions become unconfirmed and spams other nodes. - if (!fReindex && !fImporting && !IsInitialBlockDownload()) - { - ResendWalletTransactions(); - } - // Address refresh broadcast static int64 nLastRebroadcast; if (!IsInitialBlockDownload() && (GetTime() - nLastRebroadcast > 24 * 60 * 60)) @@ -4234,6 +4219,23 @@ bool SendMessages(CNode* pto, bool fSendTrickle) pto->PushMessage("addr", vAddr); } + TRY_LOCK(cs_main, lockMain); + if (!lockMain) + return true; + + // Start block sync + if (pto->fStartSync && !fImporting && !fReindex) { + pto->fStartSync = false; + PushGetBlocks(pto, chainActive.Tip(), uint256(0)); + } + + // Resend wallet transactions that haven't gotten in a block yet + // Except during reindex, importing and IBD, when old wallet + // transactions become unconfirmed and spams other nodes. + if (!fReindex && !fImporting && !IsInitialBlockDownload()) + { + ResendWalletTransactions(); + } // // Message: inventory |