forked from cometbft/cometbft
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
mempool: add
nop
mempool (cometbft#1643)
* add `nop` mempool See [ADR-111](cometbft#1585) * implement NopMempool and NopMempoolReactor modify node.go logic I had to add NopMempoolReactor to pass it to RPC in order not to change it. * check config instead of asserting for nil * start writing docs * add changelog * move changelog * expand docs * remove unused func arguments * add simple test * make linter happy again * doc fixes Co-authored-by: Sergio Mena <sergio@informal.systems> * rename mempoolReactor to waitSyncP2PReactor * improve changelog message * allow empty string for backwards compatibility cometbft#1643 (comment) * make ErrNotAllowed private * mention `create_empty_blocks` in toml https://github.com/cometbft/cometbft/pull/1643/files#r1400434715 * return nil instead of closed channel https://github.com/cometbft/cometbft/pull/1643/files#r1400252575 The reader will block forever, which is exactly what we need. * grammar fixes Co-authored-by: lasaro <lasaro@informal.systems> * update changelog entry * adapt ADR to implementation * remove old ToC entry --------- Co-authored-by: Andy Nogueira <me@andynogueira.dev> Co-authored-by: Sergio Mena <sergio@informal.systems> Co-authored-by: lasaro <lasaro@informal.systems>
- Loading branch information
1 parent
6302491
commit bc83503
Showing
12 changed files
with
326 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
- `[mempool]` Add `nop` mempool ([\#1643](https://github.com/cometbft/cometbft/pull/1643)) | ||
|
||
If you want to use it, change mempool's `type` to `nop`: | ||
|
||
```toml | ||
[mempool] | ||
|
||
# The type of mempool for this node to use. | ||
# | ||
# Possible types: | ||
# - "flood" : concurrent linked list mempool with flooding gossip protocol | ||
# (default) | ||
# - "nop" : nop-mempool (short for no operation; the ABCI app is responsible | ||
# for storing, disseminating and proposing txs). "create_empty_blocks=false" | ||
# is not supported. | ||
type = "nop" | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
package mempool | ||
|
||
import ( | ||
"errors" | ||
|
||
abcicli "github.com/cometbft/cometbft/abci/client" | ||
abci "github.com/cometbft/cometbft/abci/types" | ||
"github.com/cometbft/cometbft/internal/service" | ||
"github.com/cometbft/cometbft/p2p" | ||
"github.com/cometbft/cometbft/types" | ||
) | ||
|
||
// NopMempool is a mempool that does nothing. | ||
// | ||
// The ABCI app is responsible for storing, disseminating, and proposing transactions. | ||
// See [ADR-111](../docs/architecture/adr-111-nop-mempool.md). | ||
type NopMempool struct{} | ||
|
||
// errNotAllowed indicates that the operation is not allowed with `nop` mempool. | ||
var errNotAllowed = errors.New("not allowed with `nop` mempool") | ||
|
||
var _ Mempool = &NopMempool{} | ||
|
||
// CheckTx always returns an error. | ||
func (*NopMempool) CheckTx(types.Tx) (*abcicli.ReqRes, error) { | ||
return nil, errNotAllowed | ||
} | ||
|
||
// RemoveTxByKey always returns an error. | ||
func (*NopMempool) RemoveTxByKey(types.TxKey) error { return errNotAllowed } | ||
|
||
// ReapMaxBytesMaxGas always returns nil. | ||
func (*NopMempool) ReapMaxBytesMaxGas(int64, int64) types.Txs { return nil } | ||
|
||
// ReapMaxTxs always returns nil. | ||
func (*NopMempool) ReapMaxTxs(int) types.Txs { return nil } | ||
|
||
// Lock does nothing. | ||
func (*NopMempool) Lock() {} | ||
|
||
// Unlock does nothing. | ||
func (*NopMempool) Unlock() {} | ||
|
||
// Update does nothing. | ||
func (*NopMempool) Update( | ||
int64, | ||
types.Txs, | ||
[]*abci.ExecTxResult, | ||
PreCheckFunc, | ||
PostCheckFunc, | ||
) error { | ||
return nil | ||
} | ||
|
||
// FlushAppConn does nothing. | ||
func (*NopMempool) FlushAppConn() error { return nil } | ||
|
||
// Flush does nothing. | ||
func (*NopMempool) Flush() {} | ||
|
||
// TxsAvailable always returns nil. | ||
func (*NopMempool) TxsAvailable() <-chan struct{} { | ||
return nil | ||
} | ||
|
||
// EnableTxsAvailable does nothing. | ||
func (*NopMempool) EnableTxsAvailable() {} | ||
|
||
// SetTxRemovedCallback does nothing. | ||
func (*NopMempool) SetTxRemovedCallback(func(txKey types.TxKey)) {} | ||
|
||
// Size always returns 0. | ||
func (*NopMempool) Size() int { return 0 } | ||
|
||
// SizeBytes always returns 0. | ||
func (*NopMempool) SizeBytes() int64 { return 0 } | ||
|
||
// NopMempoolReactor is a mempool reactor that does nothing. | ||
type NopMempoolReactor struct { | ||
service.BaseService | ||
} | ||
|
||
// NewNopMempoolReactor returns a new `nop` reactor. | ||
// | ||
// To be used only in RPC. | ||
func NewNopMempoolReactor() *NopMempoolReactor { | ||
return &NopMempoolReactor{*service.NewBaseService(nil, "NopMempoolReactor", nil)} | ||
} | ||
|
||
var _ p2p.Reactor = &NopMempoolReactor{} | ||
|
||
// WaitSync always returns false. | ||
func (*NopMempoolReactor) WaitSync() bool { return false } | ||
|
||
// GetChannels always returns nil. | ||
func (*NopMempoolReactor) GetChannels() []*p2p.ChannelDescriptor { return nil } | ||
|
||
// AddPeer does nothing. | ||
func (*NopMempoolReactor) AddPeer(p2p.Peer) {} | ||
|
||
// InitPeer always returns nil. | ||
func (*NopMempoolReactor) InitPeer(p2p.Peer) p2p.Peer { return nil } | ||
|
||
// RemovePeer does nothing. | ||
func (*NopMempoolReactor) RemovePeer(p2p.Peer, interface{}) {} | ||
|
||
// Receive does nothing. | ||
func (*NopMempoolReactor) Receive(p2p.Envelope) {} | ||
|
||
// SetSwitch does nothing. | ||
func (*NopMempoolReactor) SetSwitch(*p2p.Switch) {} |
Oops, something went wrong.