Skip to content

Commit

Permalink
bug fix : tx sync was incorrectly validating transactions (#3554)
Browse files Browse the repository at this point in the history
## Summary

The TestSyncFromClient was randomly failing. This is a real issue in production code, and the fix it pretty trivial.

## Test Plan

Use existing tests to verify test.
  • Loading branch information
tsachiherman authored Feb 2, 2022
1 parent 1d41730 commit 6230dc5
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions rpcs/txSyncer.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,18 +127,31 @@ func (syncer *TxSyncer) syncFromClient(client TxSyncClient) error {
return fmt.Errorf("TxSyncer.Sync: peer '%v' error '%v'", client.Address(), err)
}

var pendingTxidMap map[transactions.Txid]struct{}
// test to see if all the transaction that we've received honor the bloom filter constraints
// that we've requested.
for _, txgroup := range txgroups {
var txnsInFilter int
for i := range txgroup {
txID := txgroup[i].ID()
if filter.Test(txID[:]) {
// we just found a transaction that shouldn't have been
// included in the response. maybe this is a false positive
// and other transactions in the group aren't included in the
// bloom filter, though.
txnsInFilter++
// having the transaction id tested here might still fall into the false-positive class, so we
// need to perform explicit check. This is not too bad since we're doing this check only on the fail
// cases.
if pendingTxidMap == nil {
// construct and initialize it.
pendingTxidMap = make(map[transactions.Txid]struct{}, len(pending))
for _, txid := range pending {
pendingTxidMap[txid] = struct{}{}
}
}
if _, has := pendingTxidMap[txID]; has {
// we just found a transaction that shouldn't have been
// included in the response. maybe this is a false positive
// and other transactions in the group aren't included in the
// bloom filter, though.
txnsInFilter++
}
}
}

Expand Down

0 comments on commit 6230dc5

Please sign in to comment.