Skip to content

Commit

Permalink
mempool: add nop mempool (backport cometbft#1643) (cometbft#1681)
Browse files Browse the repository at this point in the history
* 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>
(cherry picked from commit bc83503)

# Conflicts:
#	config/config.go
#	config/toml.go
#	docs/architecture/README.md
#	docs/architecture/adr-111-nop-mempool.md
#	docs/core/configuration.md
#	node/node.go
#	node/setup.go

* fix merge conflicts

* add a missing ToC line

---------

Co-authored-by: Anton Kaliaev <anton.kalyaev@gmail.com>
  • Loading branch information
mergify[bot] and melekes authored Nov 23, 2023
1 parent c89ad98 commit ba3c8d8
Show file tree
Hide file tree
Showing 11 changed files with 657 additions and 47 deletions.
17 changes: 17 additions & 0 deletions .changelog/unreleased/features/1643-nop-mempool.md
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"
```
24 changes: 24 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ const (
// Default is v0.
MempoolV0 = "v0"
MempoolV1 = "v1"

MempoolTypeFlood = "flood"
MempoolTypeNop = "nop"
)

// NOTE: Most of the structs & relevant comments + the
Expand Down Expand Up @@ -151,6 +154,9 @@ func (cfg *Config) ValidateBasic() error {
if err := cfg.Instrumentation.ValidateBasic(); err != nil {
return fmt.Errorf("error in [instrumentation] section: %w", err)
}
if !cfg.Consensus.CreateEmptyBlocks && cfg.Mempool.Type == MempoolTypeNop {
return fmt.Errorf("`nop` mempool does not support create_empty_blocks = false")
}
return nil
}

Expand Down Expand Up @@ -721,6 +727,17 @@ type MempoolConfig struct {
// 1) "v0" - (default) FIFO mempool.
// 2) "v1" - prioritized mempool (deprecated; will be removed in the next release).
Version string `mapstructure:"version"`

// 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 string `mapstructure:"type"`

// RootDir is the root directory for all data. This should be configured via
// the $CMTHOME env variable or --home cmd flag rather than overriding this
// struct field.
Expand Down Expand Up @@ -802,6 +819,7 @@ type MempoolConfig struct {
// DefaultMempoolConfig returns a default configuration for the CometBFT mempool
func DefaultMempoolConfig() *MempoolConfig {
return &MempoolConfig{
Type: MempoolTypeFlood,
Version: MempoolV0,
Recheck: true,
Broadcast: true,
Expand Down Expand Up @@ -839,6 +857,12 @@ func (cfg *MempoolConfig) WalEnabled() bool {
// ValidateBasic performs basic validation (checking param bounds, etc.) and
// returns an error if any check fails.
func (cfg *MempoolConfig) ValidateBasic() error {
switch cfg.Type {
case MempoolTypeFlood, MempoolTypeNop:
case "": // allow empty string to be backwards compatible
default:
return fmt.Errorf("unknown mempool type: %q", cfg.Type)
}
if cfg.Size < 0 {
return errors.New("size can't be negative")
}
Expand Down
8 changes: 8 additions & 0 deletions config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ func TestConfigValidateBasic(t *testing.T) {
// tamper with timeout_propose
cfg.Consensus.TimeoutPropose = -10 * time.Second
assert.Error(t, cfg.ValidateBasic())
cfg.Consensus.TimeoutPropose = 3 * time.Second

cfg.Consensus.CreateEmptyBlocks = false
cfg.Mempool.Type = MempoolTypeNop
assert.Error(t, cfg.ValidateBasic())
}

func TestTLSConfiguration(t *testing.T) {
Expand Down Expand Up @@ -121,6 +126,9 @@ func TestMempoolConfigValidateBasic(t *testing.T) {
assert.Error(t, cfg.ValidateBasic())
reflect.ValueOf(cfg).Elem().FieldByName(fieldName).SetInt(0)
}

reflect.ValueOf(cfg).Elem().FieldByName("Type").SetString("invalid")
assert.Error(t, cfg.ValidateBasic())
}

func TestStateSyncConfigValidateBasic(t *testing.T) {
Expand Down
10 changes: 10 additions & 0 deletions config/toml.go
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,16 @@ dial_timeout = "{{ .P2P.DialTimeout }}"
# 2) "v1" - prioritized mempool (deprecated; will be removed in the next release).
version = "{{ .Mempool.Version }}"
# 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 = "flood"
recheck = {{ .Mempool.Recheck }}
broadcast = {{ .Mempool.Broadcast }}
wal_dir = "{{ js .Mempool.WalPath }}"
Expand Down
1 change: 1 addition & 0 deletions docs/architecture/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ therefore they have links to it and refer to CometBFT as "Tendermint" or "Tender
- [ADR-075: RPC Event Subscription Interface](./adr-075-rpc-subscription.md)
- [ADR-079: Ed25519 Verification](./adr-079-ed25519-verification.md)
- [ADR-081: Protocol Buffers Management](./adr-081-protobuf-mgmt.md)
- [ADR-111: `nop` Mempool](./adr-111-nop-mempool.md)

### Deprecated

Expand Down
Loading

0 comments on commit ba3c8d8

Please sign in to comment.