Skip to content
This repository has been archived by the owner on Aug 24, 2022. It is now read-only.

Commit

Permalink
Bug fix add txs to peer priority txs (#184)
Browse files Browse the repository at this point in the history
* Bug fix add txs to peer priority txs

* Remove assert in test
  • Loading branch information
jinmannwong authored Sep 24, 2020
1 parent 2b548e0 commit 1bb94da
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 deletions.
10 changes: 4 additions & 6 deletions mempool/clist_mempool.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ type CListMempool struct {
proxyAppConn proxy.AppConnMempool

// Map of peerID to location in the linked list they have broadcast to
peerPointers map[uint16]peerPointer
peerPointers map[uint16]*peerPointer

// Track whether we're rechecking txs.
// These are not protected by a mutex and are expected to be mutated in
Expand Down Expand Up @@ -105,7 +105,7 @@ func NewCListMempool(
config: config,
proxyAppConn: proxyAppConn,
txs: clist.New(),
peerPointers: make(map[uint16]peerPointer),
peerPointers: make(map[uint16]*peerPointer),
height: height,
recheckCursor: nil,
recheckEnd: nil,
Expand Down Expand Up @@ -562,7 +562,7 @@ func (mem *CListMempool) GetNewTxs(peerID uint16, max int) (ret []*types.Tx) {
mem.updateMtx.Unlock()
return
}
mem.peerPointers[peerID] = peerPointer{mem.txs.Front(), make([]*clist.CElement, 0)}
mem.peerPointers[peerID] = &peerPointer{mem.txs.Front(), make([]*clist.CElement, 0)}
ret = append(ret, &front.Value.(*mempoolTx).tx) // corner case where we want this + next
}

Expand Down Expand Up @@ -600,9 +600,7 @@ func (mem *CListMempool) GetNewTxs(peerID uint16, max int) (ret []*types.Tx) {
// Only add/return this if the peer hasn't seen it
memTx := next.Value.(*mempoolTx)

// Priority txs are gossiped using peer pointer priority txs so we to do not include
// them here to avoid sending duplicates
if _, ok := memTx.senders.Load(peerID); !ok && !isPriority(memTx.tx) {
if _, ok := memTx.senders.Load(peerID); !ok {
ret = append(ret, &memTx.tx)
}
peerPointer.Element = next
Expand Down
4 changes: 2 additions & 2 deletions mempool/clist_mempool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,12 +97,12 @@ func checkPriorityTxs(t *testing.T, mempool Mempool, count int, peerID uint16) t
txInfo := TxInfo{SenderID: peerID}
for i := 0; i < count; i++ {
txBytes := make([]byte, 20)
txBytes = tx_extensions.PrependBytes(txBytes) // Convert to priority tx (dkg)
txs[i] = txBytes
_, err := rand.Read(txBytes)
if err != nil {
t.Error(err)
}
txBytes = tx_extensions.PrependBytes(txBytes) // Convert to priority tx (dkg)
txs[i] = txBytes

if err := mempool.CheckTx(txBytes, nil, txInfo); err != nil {
// Skip invalid txs.
Expand Down

0 comments on commit 1bb94da

Please sign in to comment.