Skip to content

Commit 8fc12bc

Browse files
fixes
1 parent ce5601c commit 8fc12bc

File tree

2 files changed

+21
-17
lines changed

2 files changed

+21
-17
lines changed

src/instantsend/instantsend.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -984,10 +984,8 @@ std::optional<int> CInstantSendManager::GetBlockHeight(const uint256& hash) cons
984984
{
985985
{
986986
LOCK(cs_height_cache);
987-
auto it = m_cached_block_heights.find(hash);
988-
if (it != m_cached_block_heights.end()) {
989-
return it->second;
990-
}
987+
int cached_height{0};
988+
if (m_cached_block_heights.get(hash, cached_height)) return cached_height;
991989
}
992990

993991
const CBlockIndex* pindex =

src/instantsend/instantsend.h

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -123,15 +123,15 @@ class CInstantSendManager final : public instantsend::InstantSendSignerParent
123123

124124
private:
125125
instantsend::PendingState ProcessPendingInstantSendLocks()
126-
EXCLUSIVE_LOCKS_REQUIRED(!cs_nonLocked, !cs_pendingLocks, !cs_pendingRetry);
126+
EXCLUSIVE_LOCKS_REQUIRED(!cs_nonLocked, !cs_pendingLocks, !cs_pendingRetry, !cs_height_cache);
127127

128128
Uint256HashSet ProcessPendingInstantSendLocks(const Consensus::LLMQParams& llmq_params, int signOffset, bool ban,
129129
const Uint256HashMap<std::pair<NodeId, instantsend::InstantSendLockPtr>>& pend,
130130
std::vector<std::pair<NodeId, MessageProcessingResult>>& peer_activity)
131-
EXCLUSIVE_LOCKS_REQUIRED(!cs_nonLocked, !cs_pendingLocks, !cs_pendingRetry);
131+
EXCLUSIVE_LOCKS_REQUIRED(!cs_nonLocked, !cs_pendingLocks, !cs_pendingRetry, !cs_height_cache);
132132
MessageProcessingResult ProcessInstantSendLock(NodeId from, const uint256& hash,
133133
const instantsend::InstantSendLockPtr& islock)
134-
EXCLUSIVE_LOCKS_REQUIRED(!cs_nonLocked, !cs_pendingLocks, !cs_pendingRetry);
134+
EXCLUSIVE_LOCKS_REQUIRED(!cs_nonLocked, !cs_pendingLocks, !cs_pendingRetry, !cs_height_cache);
135135

136136
void AddNonLockedTx(const CTransactionRef& tx, const CBlockIndex* pindexMined)
137137
EXCLUSIVE_LOCKS_REQUIRED(!cs_nonLocked, !cs_pendingLocks, !cs_timingsTxSeen);
@@ -144,7 +144,7 @@ class CInstantSendManager final : public instantsend::InstantSendSignerParent
144144
void RemoveMempoolConflictsForLock(const uint256& hash, const instantsend::InstantSendLock& islock)
145145
EXCLUSIVE_LOCKS_REQUIRED(!cs_nonLocked, !cs_pendingRetry);
146146
void ResolveBlockConflicts(const uint256& islockHash, const instantsend::InstantSendLock& islock)
147-
EXCLUSIVE_LOCKS_REQUIRED(!cs_nonLocked, !cs_pendingLocks, !cs_pendingRetry);
147+
EXCLUSIVE_LOCKS_REQUIRED(!cs_nonLocked, !cs_pendingLocks, !cs_pendingRetry, !cs_height_cache);
148148

149149
void WorkThreadMain(PeerManager& peerman)
150150
EXCLUSIVE_LOCKS_REQUIRED(!cs_nonLocked, !cs_pendingLocks, !cs_pendingRetry);
@@ -158,14 +158,16 @@ class CInstantSendManager final : public instantsend::InstantSendSignerParent
158158
instantsend::InstantSendLockPtr GetConflictingLock(const CTransaction& tx) const override;
159159

160160
[[nodiscard]] MessageProcessingResult ProcessMessage(NodeId from, std::string_view msg_type, CDataStream& vRecv)
161-
EXCLUSIVE_LOCKS_REQUIRED(!cs_pendingLocks);
161+
EXCLUSIVE_LOCKS_REQUIRED(!cs_pendingLocks, !cs_height_cache);
162162

163163
void TransactionAddedToMempool(const CTransactionRef& tx)
164164
EXCLUSIVE_LOCKS_REQUIRED(!cs_nonLocked, !cs_pendingLocks, !cs_pendingRetry, !cs_timingsTxSeen);
165-
void TransactionRemovedFromMempool(const CTransactionRef& tx);
165+
void TransactionRemovedFromMempool(const CTransactionRef& tx)
166+
EXCLUSIVE_LOCKS_REQUIRED(!cs_height_cache);
166167
void BlockConnected(const std::shared_ptr<const CBlock>& pblock, const CBlockIndex* pindex)
167-
EXCLUSIVE_LOCKS_REQUIRED(!cs_nonLocked, !cs_pendingLocks, !cs_pendingRetry, !cs_timingsTxSeen);
168-
void BlockDisconnected(const std::shared_ptr<const CBlock>& pblock, const CBlockIndex* pindexDisconnected);
168+
EXCLUSIVE_LOCKS_REQUIRED(!cs_nonLocked, !cs_pendingLocks, !cs_pendingRetry, !cs_timingsTxSeen, !cs_height_cache);
169+
void BlockDisconnected(const std::shared_ptr<const CBlock>& pblock, const CBlockIndex* pindexDisconnected)
170+
EXCLUSIVE_LOCKS_REQUIRED(!cs_height_cache);
169171

170172
bool AlreadyHave(const CInv& inv) const EXCLUSIVE_LOCKS_REQUIRED(!cs_pendingLocks);
171173
bool GetInstantSendLockByHash(const uint256& hash, instantsend::InstantSendLock& ret) const
@@ -175,17 +177,21 @@ class CInstantSendManager final : public instantsend::InstantSendSignerParent
175177
void NotifyChainLock(const CBlockIndex* pindexChainLock)
176178
EXCLUSIVE_LOCKS_REQUIRED(!cs_nonLocked, !cs_pendingRetry);
177179
void UpdatedBlockTip(const CBlockIndex* pindexNew)
178-
EXCLUSIVE_LOCKS_REQUIRED(!cs_nonLocked, !cs_pendingRetry);
180+
EXCLUSIVE_LOCKS_REQUIRED(!cs_nonLocked, !cs_pendingRetry, !cs_height_cache);
179181

180-
void RemoveConflictingLock(const uint256& islockHash, const instantsend::InstantSendLock& islock);
182+
void RemoveConflictingLock(const uint256& islockHash, const instantsend::InstantSendLock& islock)
183+
EXCLUSIVE_LOCKS_REQUIRED(!cs_height_cache);
181184
void TryEmplacePendingLock(const uint256& hash, const NodeId id, const instantsend::InstantSendLockPtr& islock) override
182185
EXCLUSIVE_LOCKS_REQUIRED(!cs_pendingLocks);
183186

184187
size_t GetInstantSendLockCount() const;
185188

186-
void CacheBlockHeight(const uint256& hash, int height) const;
187-
std::optional<int> GetBlockHeight(const uint256& hash) const override;
188-
int GetTipHeight() const override;
189+
void CacheBlockHeight(const uint256& hash, int height) const
190+
EXCLUSIVE_LOCKS_REQUIRED(!cs_height_cache);
191+
std::optional<int> GetBlockHeight(const uint256& hash) const override
192+
EXCLUSIVE_LOCKS_REQUIRED(!cs_height_cache);
193+
int GetTipHeight() const override
194+
EXCLUSIVE_LOCKS_REQUIRED(!cs_height_cache);
189195

190196
bool IsInstantSendEnabled() const override;
191197
/**

0 commit comments

Comments
 (0)