Fix mempool issue

This commit is contained in:
Aditya Kulkarni 2022-04-07 10:20:01 -05:00
parent c1bab818a6
commit e146dbf5c2
2 changed files with 22 additions and 2 deletions

View File

@ -63,7 +63,7 @@ func refreshMempoolTxns() error {
// Set refreshing to 0 when we exit
defer func() {
refreshing = 0
atomic.StoreInt32(&refreshing, 0)
}()
// Check if the blockchain has changed, and if it has, then clear everything

View File

@ -201,6 +201,8 @@ func (s *lwdStreamer) GetTaddressTxids(addressBlockFilter *walletrpc.Transparent
timeout, cancel := context.WithTimeout(resp.Context(), 30*time.Second)
defer cancel()
var prevHeight = 0
txCache := make([]*walletrpc.RawTransaction, 0)
for _, txidstr := range txids {
txid, _ := hex.DecodeString(txidstr)
// Txid is read as a string, which is in big-endian order. But when converting
@ -209,7 +211,25 @@ func (s *lwdStreamer) GetTaddressTxids(addressBlockFilter *walletrpc.Transparent
if err != nil {
return err
}
if err = resp.Send(tx); err != nil {
if tx.Height > uint64(prevHeight) {
for _, txi := range txCache {
if err = resp.Send(txi); err != nil {
return err
}
}
txCache = make([]*walletrpc.RawTransaction, 0)
prevHeight = int(tx.Height)
}
if tx.Height == uint64(prevHeight) {
txCache = append(txCache, tx)
}
}
for _, txi := range txCache {
if err = resp.Send(txi); err != nil {
return err
}
}