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

     1  package mempool
     2  
     3  import (
     4  	"errors"
     5  
     6  	abci "github.com/KYVENetwork/cometbft/v38/abci/types"
     7  	"github.com/KYVENetwork/cometbft/v38/libs/service"
     8  	"github.com/KYVENetwork/cometbft/v38/p2p"
     9  	"github.com/KYVENetwork/cometbft/v38/types"
    10  )
    11  
    12  // NopMempool is a mempool that does nothing.
    13  //
    14  // The ABCI app is responsible for storing, disseminating, and proposing transactions.
    15  // See [ADR-111](../docs/architecture/adr-111-nop-mempool.md).
    16  type NopMempool struct{}
    17  
    18  // errNotAllowed indicates that the operation is not allowed with `nop` mempool.
    19  var errNotAllowed = errors.New("not allowed with `nop` mempool")
    20  
    21  var _ Mempool = &NopMempool{}
    22  
    23  // CheckTx always returns an error.
    24  func (*NopMempool) CheckTx(types.Tx, func(*abci.ResponseCheckTx), TxInfo) error {
    25  	return errNotAllowed
    26  }
    27  
    28  // RemoveTxByKey always returns an error.
    29  func (*NopMempool) RemoveTxByKey(types.TxKey) error { return errNotAllowed }
    30  
    31  // ReapMaxBytesMaxGas always returns nil.
    32  func (*NopMempool) ReapMaxBytesMaxGas(int64, int64) types.Txs { return nil }
    33  
    34  // ReapMaxTxs always returns nil.
    35  func (*NopMempool) ReapMaxTxs(int) types.Txs { return nil }
    36  
    37  // Lock does nothing.
    38  func (*NopMempool) Lock() {}
    39  
    40  // Unlock does nothing.
    41  func (*NopMempool) Unlock() {}
    42  
    43  // Update does nothing.
    44  func (*NopMempool) Update(
    45  	int64,
    46  	types.Txs,
    47  	[]*abci.ExecTxResult,
    48  	PreCheckFunc,
    49  	PostCheckFunc,
    50  ) error {
    51  	return nil
    52  }
    53  
    54  // FlushAppConn does nothing.
    55  func (*NopMempool) FlushAppConn() error { return nil }
    56  
    57  // Flush does nothing.
    58  func (*NopMempool) Flush() {}
    59  
    60  // TxsAvailable always returns nil.
    61  func (*NopMempool) TxsAvailable() <-chan struct{} {
    62  	return nil
    63  }
    64  
    65  // EnableTxsAvailable does nothing.
    66  func (*NopMempool) EnableTxsAvailable() {}
    67  
    68  // SetTxRemovedCallback does nothing.
    69  func (*NopMempool) SetTxRemovedCallback(func(txKey types.TxKey)) {}
    70  
    71  // Size always returns 0.
    72  func (*NopMempool) Size() int { return 0 }
    73  
    74  // SizeBytes always returns 0.
    75  func (*NopMempool) SizeBytes() int64 { return 0 }
    76  
    77  // NopMempoolReactor is a mempool reactor that does nothing.
    78  type NopMempoolReactor struct {
    79  	service.BaseService
    80  }
    81  
    82  // NewNopMempoolReactor returns a new `nop` reactor.
    83  //
    84  // To be used only in RPC.
    85  func NewNopMempoolReactor() *NopMempoolReactor {
    86  	return &NopMempoolReactor{*service.NewBaseService(nil, "NopMempoolReactor", nil)}
    87  }
    88  
    89  var _ p2p.Reactor = &NopMempoolReactor{}
    90  
    91  // GetChannels always returns nil.
    92  func (*NopMempoolReactor) GetChannels() []*p2p.ChannelDescriptor { return nil }
    93  
    94  // AddPeer does nothing.
    95  func (*NopMempoolReactor) AddPeer(p2p.Peer) {}
    96  
    97  // InitPeer always returns nil.
    98  func (*NopMempoolReactor) InitPeer(p2p.Peer) p2p.Peer { return nil }
    99  
   100  // RemovePeer does nothing.
   101  func (*NopMempoolReactor) RemovePeer(p2p.Peer, interface{}) {}
   102  
   103  // Receive does nothing.
   104  func (*NopMempoolReactor) Receive(p2p.Envelope) {}
   105  
   106  // SetSwitch does nothing.
   107  func (*NopMempoolReactor) SetSwitch(*p2p.Switch) {}