Skip to content

Commit d1b3c4d

Browse files
committedAug 9, 2024·
add more logs around the mempool
1 parent 82a8958 commit d1b3c4d

File tree

3 files changed

+16
-7
lines changed

3 files changed

+16
-7
lines changed
 

‎mempool/cat/pool.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ func (txmp *TxPool) markToBeBroadcast(key types.TxKey) {
320320
func (txmp *TxPool) TryAddNewTx(tx types.Tx, key types.TxKey, txInfo mempool.TxInfo) (*abci.ResponseCheckTx, error) {
321321
// First check any of the caches to see if we can conclude early. We may have already seen and processed
322322
// the transaction, or it may have already been committed.
323-
if wtx := txmp.store.getCommitted(key); wtx != nil {
323+
if txmp.store.hasCommitted(key) {
324324
return nil, ErrTxRecentlyCommitted
325325
}
326326

‎mempool/cat/reactor.go

+8-6
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ const (
2929

3030
// peerHeightDiff signifies the tolerance in difference in height between the peer and the height
3131
// the node received the tx
32-
peerHeightDiff = 10
32+
peerHeightDiff = 2
3333
)
3434

3535
// Reactor handles mempool tx broadcasting logic amongst peers. For the main
@@ -303,7 +303,7 @@ func (memR *Reactor) ReceiveEnvelope(e p2p.Envelope) {
303303
peerID := memR.ids.GetIDForPeer(e.Src.ID())
304304
memR.mempool.PeerHasTx(peerID, txKey)
305305
// Check if we don't already have the transaction and that it was recently rejected
306-
if memR.mempool.Has(txKey) || memR.mempool.IsRejectedTx(txKey) {
306+
if memR.mempool.Has(txKey) || memR.mempool.IsRejectedTx(txKey) || memR.mempool.store.hasCommitted(txKey) {
307307
memR.Logger.Debug("received a seen tx for a tx we already have", "txKey", txKey)
308308
return
309309
}
@@ -341,7 +341,7 @@ func (memR *Reactor) ReceiveEnvelope(e p2p.Envelope) {
341341
}
342342
if has && !memR.opts.ListenOnly {
343343
peerID := memR.ids.GetIDForPeer(e.Src.ID())
344-
memR.Logger.Debug("sending a tx in response to a want msg", "peer", peerID)
344+
memR.Logger.Info("sending a tx in response to a want msg", "peer", peerID)
345345
if p2p.SendEnvelopeShim(e.Src, p2p.Envelope{ //nolint:staticcheck
346346
ChannelID: mempool.MempoolChannel,
347347
Message: &protomem.Txs{Txs: [][]byte{tx}},
@@ -404,7 +404,9 @@ func (memR *Reactor) broadcastSeenTx(txKey types.TxKey) {
404404
continue
405405
}
406406

407-
peer.Send(MempoolStateChannel, bz) //nolint:staticcheck
407+
if peer.Send(MempoolStateChannel, bz) {
408+
memR.Logger.Info("sent seen tx to peer", "peerID", peer.ID(), "txKey", txKey)
409+
}
408410
}
409411
}
410412

@@ -450,7 +452,6 @@ func (memR *Reactor) requestTx(txKey types.TxKey, peer p2p.Peer) {
450452
// we have disconnected from the peer
451453
return
452454
}
453-
memR.Logger.Debug("requesting tx", "txKey", txKey, "peerID", peer.ID())
454455
msg := &protomem.Message{
455456
Sum: &protomem.Message_WantTx{
456457
WantTx: &protomem.WantTx{TxKey: txKey[:]},
@@ -463,10 +464,11 @@ func (memR *Reactor) requestTx(txKey types.TxKey, peer p2p.Peer) {
463464

464465
success := peer.Send(MempoolStateChannel, bz) //nolint:staticcheck
465466
if success {
467+
memR.Logger.Info("requested tx", "txKey", txKey, "peerID", peer.ID())
466468
memR.mempool.metrics.RequestedTxs.Add(1)
467469
requested := memR.requests.Add(txKey, memR.ids.GetIDForPeer(peer.ID()), memR.findNewPeerToRequestTx)
468470
if !requested {
469-
memR.Logger.Debug("have already marked a tx as requested", "txKey", txKey, "peerID", peer.ID())
471+
memR.Logger.Error("have already marked a tx as requested", "txKey", txKey, "peerID", peer.ID())
470472
}
471473
}
472474
}

‎mempool/cat/store.go

+7
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,13 @@ func (s *store) getCommitted(txKey types.TxKey) *wrappedTx {
5050
return s.committedTxs[txKey]
5151
}
5252

53+
func (s *store) hasCommitted(txKey types.TxKey) bool {
54+
s.mtx.RLock()
55+
defer s.mtx.RUnlock()
56+
_, has := s.committedTxs[txKey]
57+
return has
58+
}
59+
5360
func (s *store) has(txKey types.TxKey) bool {
5461
s.mtx.RLock()
5562
defer s.mtx.RUnlock()

0 commit comments

Comments
 (0)
Please sign in to comment.