github.com/badrootd/nibiru-cometbft@v0.37.5-0.20240307173500-2a75559eee9b/mempool/v1/tx.go (about) 1 // Deprecated: Priority mempool will be removed in the next major release. 2 package v1 3 4 import ( 5 "sync" 6 "time" 7 8 "github.com/badrootd/nibiru-cometbft/types" 9 ) 10 11 // WrappedTx defines a wrapper around a raw transaction with additional metadata 12 // that is used for indexing. 13 type WrappedTx struct { 14 tx types.Tx // the original transaction data 15 hash types.TxKey // the transaction hash 16 height int64 // height when this transaction was initially checked (for expiry) 17 timestamp time.Time // time when transaction was entered (for TTL) 18 19 mtx sync.Mutex 20 gasWanted int64 // app: gas required to execute this transaction 21 priority int64 // app: priority value for this transaction 22 sender string // app: assigned sender label 23 peers map[uint16]bool // peer IDs who have sent us this transaction 24 } 25 26 // Size reports the size of the raw transaction in bytes. 27 func (w *WrappedTx) Size() int64 { return int64(len(w.tx)) } 28 29 // SetPeer adds the specified peer ID as a sender of w. 30 func (w *WrappedTx) SetPeer(id uint16) { 31 w.mtx.Lock() 32 defer w.mtx.Unlock() 33 if w.peers == nil { 34 w.peers = map[uint16]bool{id: true} 35 } else { 36 w.peers[id] = true 37 } 38 } 39 40 // HasPeer reports whether the specified peer ID is a sender of w. 41 func (w *WrappedTx) HasPeer(id uint16) bool { 42 w.mtx.Lock() 43 defer w.mtx.Unlock() 44 _, ok := w.peers[id] 45 return ok 46 } 47 48 // SetGasWanted sets the application-assigned gas requirement of w. 49 func (w *WrappedTx) SetGasWanted(gas int64) { 50 w.mtx.Lock() 51 defer w.mtx.Unlock() 52 w.gasWanted = gas 53 } 54 55 // GasWanted reports the application-assigned gas requirement of w. 56 func (w *WrappedTx) GasWanted() int64 { 57 w.mtx.Lock() 58 defer w.mtx.Unlock() 59 return w.gasWanted 60 } 61 62 // SetSender sets the application-assigned sender of w. 63 func (w *WrappedTx) SetSender(sender string) { 64 w.mtx.Lock() 65 defer w.mtx.Unlock() 66 w.sender = sender 67 } 68 69 // Sender reports the application-assigned sender of w. 70 func (w *WrappedTx) Sender() string { 71 w.mtx.Lock() 72 defer w.mtx.Unlock() 73 return w.sender 74 } 75 76 // SetPriority sets the application-assigned priority of w. 77 func (w *WrappedTx) SetPriority(p int64) { 78 w.mtx.Lock() 79 defer w.mtx.Unlock() 80 w.priority = p 81 } 82 83 // Priority reports the application-assigned priority of w. 84 func (w *WrappedTx) Priority() int64 { 85 w.mtx.Lock() 86 defer w.mtx.Unlock() 87 return w.priority 88 }