github.com/KYVENetwork/cometbft/v38@v38.0.3/mempool/mempoolTx.go (about)

     1  package mempool
     2  
     3  import (
     4  	"sync"
     5  	"sync/atomic"
     6  
     7  	"github.com/KYVENetwork/cometbft/v38/types"
     8  )
     9  
    10  // mempoolTx is an entry in the mempool
    11  type mempoolTx struct {
    12  	height    int64    // height that this tx had been validated in
    13  	gasWanted int64    // amount of gas this tx states it will require
    14  	tx        types.Tx // validated by the application
    15  
    16  	// ids of peers who've sent us this tx (as a map for quick lookups).
    17  	// senders: PeerID -> bool
    18  	senders sync.Map
    19  }
    20  
    21  // Height returns the height for this transaction
    22  func (memTx *mempoolTx) Height() int64 {
    23  	return atomic.LoadInt64(&memTx.height)
    24  }
    25  
    26  func (memTx *mempoolTx) isSender(peerID uint16) bool {
    27  	_, ok := memTx.senders.Load(peerID)
    28  	return ok
    29  }
    30  
    31  func (memTx *mempoolTx) addSender(senderID uint16) bool {
    32  	_, added := memTx.senders.LoadOrStore(senderID, true)
    33  	return added
    34  }