Skip to content

Commit

Permalink
Fix filtering of the lock votes for SPV nodes. (#2468)
Browse files Browse the repository at this point in the history
* check request is not empty to use it for filtering

* Filter vote INVs by tx hash

* fix lock requests filtering

* Apply suggestions from code review

Co-Authored-By: gladcow <[email protected]>
  • Loading branch information
gladcow authored and codablock committed Nov 23, 2018
1 parent d40a5ce commit a57e9de
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/instantx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1156,10 +1156,10 @@ void CTxLockVote::Relay(CConnman& connman) const
{
CInv inv(MSG_TXLOCK_VOTE, GetHash());
CTxLockRequest request;
if (instantsend.GetTxLockRequest(txHash, request)) {
if (instantsend.GetTxLockRequest(txHash, request) && request) {
connman.RelayInvFiltered(inv, *request.tx);
} else {
connman.RelayInv(inv);
connman.RelayInvFiltered(inv, txHash);
}
}

Expand Down
21 changes: 21 additions & 0 deletions src/net.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2629,6 +2629,14 @@ void CConnman::RelayTransaction(const CTransaction& tx)
LOCK(cs_vNodes);
BOOST_FOREACH(CNode* pnode, vNodes)
{
if (nInv == MSG_TXLOCK_REQUEST) {
// Additional filtering for lock requests.
// Make it here because lock request processing
// differs from simple tx processing in PushInventory
// and tx info will not be available there.
LOCK(pnode->cs_filter);
if(pnode->pfilter && !pnode->pfilter->IsRelevantAndUpdate(tx)) continue;
}
pnode->PushInventory(inv);
}
}
Expand All @@ -2655,6 +2663,19 @@ void CConnman::RelayInvFiltered(CInv &inv, const CTransaction& relatedTx, const
}
}

void CConnman::RelayInvFiltered(CInv &inv, const uint256& relatedTxHash, const int minProtoVersion)
{
LOCK(cs_vNodes);
for (const auto& pnode : vNodes) {
if(pnode->nVersion < minProtoVersion) continue;
{
LOCK(pnode->cs_filter);
if(pnode->pfilter && !pnode->pfilter->contains(relatedTxHash)) continue;
}
pnode->PushInventory(inv);
}
}

void CConnman::RemoveAskFor(const uint256& hash)
{
mapAlreadyAskedFor.erase(hash);
Expand Down
2 changes: 2 additions & 0 deletions src/net.h
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,8 @@ class CConnman
void RelayTransaction(const CTransaction& tx, const CDataStream& ss);
void RelayInv(CInv &inv, const int minProtoVersion = MIN_PEER_PROTO_VERSION);
void RelayInvFiltered(CInv &inv, const CTransaction &relatedTx, const int minProtoVersion = MIN_PEER_PROTO_VERSION);
// This overload will not update node filters, so use it only for the cases when other messages will update related transaction data in filters
void RelayInvFiltered(CInv &inv, const uint256 &relatedTxHash, const int minProtoVersion = MIN_PEER_PROTO_VERSION);
void RemoveAskFor(const uint256& hash);

// Addrman functions
Expand Down

0 comments on commit a57e9de

Please sign in to comment.