Skip to content

Commit

Permalink
Be explicit about mempool peer IDs
Browse files Browse the repository at this point in the history
  • Loading branch information
zivkovicmilos committed Jan 7, 2025
1 parent 5702e74 commit a2c11a0
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions tm2/pkg/bft/mempool/reactor.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ type mempoolIDs struct {
mtx sync.RWMutex
peerMap map[p2pTypes.ID]uint16
nextID uint16 // assumes that a node will never have over 65536 active peers
activeIDs map[uint16]struct{} // used to check if a given peerID key is used, the value doesn't matter
activeIDs map[uint16]struct{} // used to check if a given mempoolID key is used, the value doesn't matter
}

// Reserve searches for the next unused ID and assigns it to the
Expand All @@ -51,14 +51,14 @@ func (ids *mempoolIDs) ReserveForPeer(id p2pTypes.ID) {
ids.mtx.Lock()
defer ids.mtx.Unlock()

curID := ids.nextPeerID()
curID := ids.nextMempoolPeerID()
ids.peerMap[id] = curID
ids.activeIDs[curID] = struct{}{}
}

// nextPeerID returns the next unused peer ID to use.
// nextMempoolPeerID returns the next unused peer ID to use.
// This assumes that ids's mutex is already locked.
func (ids *mempoolIDs) nextPeerID() uint16 {
func (ids *mempoolIDs) nextMempoolPeerID() uint16 {
if len(ids.activeIDs) == maxActiveIDs {
panic(fmt.Sprintf("node has maximum %d active IDs and wanted to get one more", maxActiveIDs))
}
Expand Down Expand Up @@ -163,8 +163,8 @@ func (memR *Reactor) Receive(chID byte, src p2p.PeerConn, msgBytes []byte) {

switch msg := msg.(type) {
case *TxMessage:
peerID := memR.ids.GetForPeer(src.ID())
err := memR.mempool.CheckTxWithInfo(msg.Tx, nil, TxInfo{SenderID: peerID})
mempoolID := memR.ids.GetForPeer(src.ID())
err := memR.mempool.CheckTxWithInfo(msg.Tx, nil, TxInfo{SenderID: mempoolID})
if err != nil {
memR.Logger.Info("Could not check tx", "tx", txID(msg.Tx), "err", err)
}
Expand All @@ -185,7 +185,7 @@ func (memR *Reactor) broadcastTxRoutine(peer p2p.PeerConn) {
return
}

peerID := memR.ids.GetForPeer(peer.ID())
mempoolID := memR.ids.GetForPeer(peer.ID())
var next *clist.CElement
for {
// In case of both next.NextWaitChan() and peer.Quit() are variable at the same time
Expand Down Expand Up @@ -227,7 +227,7 @@ func (memR *Reactor) broadcastTxRoutine(peer p2p.PeerConn) {
}

// ensure peer hasn't already sent us this tx
if _, ok := memTx.senders.Load(peerID); !ok {
if _, ok := memTx.senders.Load(mempoolID); !ok {
// send memTx
msg := &TxMessage{Tx: memTx.tx}
success := peer.Send(MempoolChannel, amino.MustMarshalAny(msg))
Expand Down

0 comments on commit a2c11a0

Please sign in to comment.