Browse Source

bound the mempool

Refs #345
pull/1585/head
Anton Kaliaev 7 years ago
parent
commit
c9001d5a11
No known key found for this signature in database GPG Key ID: 7B6881D965918214
4 changed files with 25 additions and 2 deletions
  1. +2
    -0
      config/config.go
  2. +6
    -0
      config/toml.go
  3. +6
    -0
      docs/specification/configuration.rst
  4. +11
    -2
      mempool/mempool.go

+ 2
- 0
config/config.go View File

@ -335,6 +335,7 @@ type MempoolConfig struct {
RecheckEmpty bool `mapstructure:"recheck_empty"` RecheckEmpty bool `mapstructure:"recheck_empty"`
Broadcast bool `mapstructure:"broadcast"` Broadcast bool `mapstructure:"broadcast"`
WalPath string `mapstructure:"wal_dir"` WalPath string `mapstructure:"wal_dir"`
Size int `mapstructure:"size"`
CacheSize int `mapstructure:"cache_size"` CacheSize int `mapstructure:"cache_size"`
} }
@ -345,6 +346,7 @@ func DefaultMempoolConfig() *MempoolConfig {
RecheckEmpty: true, RecheckEmpty: true,
Broadcast: true, Broadcast: true,
WalPath: filepath.Join(defaultDataDir, "mempool.wal"), WalPath: filepath.Join(defaultDataDir, "mempool.wal"),
Size: 100000,
CacheSize: 100000, CacheSize: 100000,
} }
} }


+ 6
- 0
config/toml.go View File

@ -179,6 +179,12 @@ recheck_empty = {{ .Mempool.RecheckEmpty }}
broadcast = {{ .Mempool.Broadcast }} broadcast = {{ .Mempool.Broadcast }}
wal_dir = "{{ .Mempool.WalPath }}" wal_dir = "{{ .Mempool.WalPath }}"
# size of the mempool
size = {{ .Mempool.Size }}
# size of the cache (used to filter transactions we saw earlier)
cache_size = {{ .Mempool.CacheSize }}
##### consensus configuration options ##### ##### consensus configuration options #####
[consensus] [consensus]


+ 6
- 0
docs/specification/configuration.rst View File

@ -136,6 +136,12 @@ like the file below, however, double check by inspecting the
broadcast = true broadcast = true
wal_dir = "data/mempool.wal" wal_dir = "data/mempool.wal"
# size of the mempool
size = 100000
# size of the cache (used to filter transactions we saw earlier)
cache_size = 100000
##### consensus configuration options ##### ##### consensus configuration options #####
[consensus] [consensus]


+ 11
- 2
mempool/mempool.go View File

@ -49,7 +49,13 @@ TODO: Better handle abci client errors. (make it automatically handle connection
*/ */
var ErrTxInCache = errors.New("Tx already exists in cache")
var (
// ErrTxInCache is returned to the client if we saw tx earlier
ErrTxInCache = errors.New("Tx already exists in cache")
// ErrMempoolIsFull means Tendermint & an application can't handle that much load
ErrMempoolIsFull = errors.New("Mempool is full")
)
// Mempool is an ordered in-memory pool for transactions before they are proposed in a consensus // Mempool is an ordered in-memory pool for transactions before they are proposed in a consensus
// round. Transaction validity is checked using the CheckTx abci message before the transaction is // round. Transaction validity is checked using the CheckTx abci message before the transaction is
@ -80,7 +86,6 @@ type Mempool struct {
} }
// NewMempool returns a new Mempool with the given configuration and connection to an application. // NewMempool returns a new Mempool with the given configuration and connection to an application.
// TODO: Extract logger into arguments.
func NewMempool(config *cfg.MempoolConfig, proxyAppConn proxy.AppConnMempool, height int64) *Mempool { func NewMempool(config *cfg.MempoolConfig, proxyAppConn proxy.AppConnMempool, height int64) *Mempool {
mempool := &Mempool{ mempool := &Mempool{
config: config, config: config,
@ -202,6 +207,10 @@ func (mem *Mempool) CheckTx(tx types.Tx, cb func(*abci.Response)) (err error) {
mem.proxyMtx.Lock() mem.proxyMtx.Lock()
defer mem.proxyMtx.Unlock() defer mem.proxyMtx.Unlock()
if mem.Size() >= mem.config.Size {
return ErrMempoolIsFull
}
// CACHE // CACHE
if !mem.cache.Push(tx) { if !mem.cache.Push(tx) {
return ErrTxInCache return ErrTxInCache


Loading…
Cancel
Save