mirror of
https://github.com/tendermint/tendermint.git
synced 2026-01-08 22:23:11 +00:00
Mempool WAL
This commit is contained in:
@@ -84,6 +84,7 @@ func GetConfig(rootDir string) cfg.Config {
|
||||
mapConfig.SetDefault("mempool_recheck", true)
|
||||
mapConfig.SetDefault("mempool_recheck_empty", true)
|
||||
mapConfig.SetDefault("mempool_broadcast", true)
|
||||
mapConfig.SetDefault("mempool_wal", rootDir+"/data/mempool_wal")
|
||||
|
||||
return mapConfig
|
||||
}
|
||||
|
||||
@@ -97,6 +97,7 @@ func ResetConfig(localPath string) cfg.Config {
|
||||
mapConfig.SetDefault("mempool_recheck", true)
|
||||
mapConfig.SetDefault("mempool_recheck_empty", true)
|
||||
mapConfig.SetDefault("mempool_broadcast", true)
|
||||
mapConfig.SetDefault("mempool_wal", "")
|
||||
|
||||
return mapConfig
|
||||
}
|
||||
|
||||
@@ -60,6 +60,9 @@ type Mempool struct {
|
||||
// Keep a cache of already-seen txs.
|
||||
// This reduces the pressure on the proxyApp.
|
||||
cache *txCache
|
||||
|
||||
// A log of mempool txs
|
||||
wal *AutoFile
|
||||
}
|
||||
|
||||
func NewMempool(config cfg.Config, proxyAppConn proxy.AppConnMempool) *Mempool {
|
||||
@@ -75,10 +78,22 @@ func NewMempool(config cfg.Config, proxyAppConn proxy.AppConnMempool) *Mempool {
|
||||
|
||||
cache: newTxCache(cacheSize),
|
||||
}
|
||||
mempool.initWAL()
|
||||
proxyAppConn.SetResponseCallback(mempool.resCb)
|
||||
return mempool
|
||||
}
|
||||
|
||||
func (mem *Mempool) initWAL() {
|
||||
walFileName := mem.config.GetString("mempool_wal")
|
||||
if walFileName != "" {
|
||||
af, err := OpenAutoFile(walFileName)
|
||||
if err != nil {
|
||||
PanicSanity(err)
|
||||
}
|
||||
mem.wal = af
|
||||
}
|
||||
}
|
||||
|
||||
// consensus must be able to hold lock to safely update
|
||||
func (mem *Mempool) Lock() {
|
||||
mem.proxyMtx.Lock()
|
||||
@@ -138,6 +153,14 @@ func (mem *Mempool) CheckTx(tx types.Tx, cb func(*tmsp.Response)) (err error) {
|
||||
mem.cache.Push(tx)
|
||||
// END CACHE
|
||||
|
||||
// WAL
|
||||
if mem.wal != nil {
|
||||
// TODO: Notify administrators when WAL fails
|
||||
mem.wal.Write([]byte(tx))
|
||||
mem.wal.Write([]byte("\n"))
|
||||
}
|
||||
// END WAL
|
||||
|
||||
// NOTE: proxyAppConn may error if tx buffer is full
|
||||
if err = mem.proxyAppConn.Error(); err != nil {
|
||||
return err
|
||||
|
||||
Reference in New Issue
Block a user