diff options
author | Tsachi Herman <tsachi.herman@algorand.com> | 2022-02-02 13:30:58 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-02-02 13:30:58 -0500 |
commit | 6230dc55c78918a2d4685a4b1e6ca78fdc35888b (patch) | |
tree | 166b4b767a68ac7b3481de7c21e43352434b7852 | |
parent | 1d417308820fc102a744c934adf5862a91e577c1 (diff) |
bug fix : tx sync was incorrectly validating transactions (#3554)
## 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.
-rw-r--r-- | rpcs/txSyncer.go | 23 |
1 files changed, 18 insertions, 5 deletions
diff --git a/rpcs/txSyncer.go b/rpcs/txSyncer.go index 34d054d40..cbeeb27fc 100644 --- a/rpcs/txSyncer.go +++ b/rpcs/txSyncer.go @@ -127,6 +127,7 @@ 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 { @@ -134,11 +135,23 @@ func (syncer *TxSyncer) syncFromClient(client TxSyncClient) error { 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++ + } } } |