Browse Source

wip

pull/8062/head
tycho garen 3 years ago
parent
commit
c66136d5a0
5 changed files with 58 additions and 16 deletions
  1. +1
    -2
      internal/mempool/mempool.go
  2. +1
    -1
      internal/mempool/mempool_test.go
  3. +52
    -8
      internal/state/tx_filter.go
  4. +1
    -1
      node/node.go
  5. +3
    -4
      node/setup.go

+ 1
- 2
internal/mempool/mempool.go View File

@ -94,7 +94,6 @@ func NewTxMempool(
logger log.Logger,
cfg *config.MempoolConfig,
proxyAppConn proxy.AppConnMempool,
height int64,
options ...TxMempoolOption,
) *TxMempool {
@ -102,7 +101,7 @@ func NewTxMempool(
logger: logger,
config: cfg,
proxyAppConn: proxyAppConn,
height: height,
height: -1,
cache: NopTxCache{},
metrics: NopMetrics(),
txStore: NewTxStore(),


+ 1
- 1
internal/mempool/mempool_test.go View File

@ -95,7 +95,7 @@ func setup(ctx context.Context, t testing.TB, cacheSize int, options ...TxMempoo
appConnMem.Wait()
})
return NewTxMempool(logger.With("test", t.Name()), cfg.Mempool, appConnMem, 0, options...)
return NewTxMempool(logger.With("test", t.Name()), cfg.Mempool, appConnMem, options...)
}
func checkTxs(ctx context.Context, t *testing.T, txmp *TxMempool, numTxs int, peerID uint16) []testTx {


+ 52
- 8
internal/state/tx_filter.go View File

@ -1,22 +1,66 @@
package state
import (
"sync"
"time"
abci "github.com/tendermint/tendermint/abci/types"
"github.com/tendermint/tendermint/internal/mempool"
"github.com/tendermint/tendermint/types"
)
func cachingStateFetcher(store Store) func() (State, error) {
var (
last time.Time
mutex = &sync.Mutex{}
ttl time.Duration
cache State
err error
)
return func() (State, error) {
mutex.Lock()
defer mutex.Unlock()
if cache.ChainID == "" { // is nil
cache, err = store.Load()
if err != nil {
return State{}, err
}
last = time.Now()
ttl = 100*time.Millisecond + (cache.LastBlockTime.Add(last) * 2)
}
}
}
// TxPreCheck returns a function to filter transactions before processing.
// The function limits the size of a transaction to the block's maximum data size.
func TxPreCheck(state State) mempool.PreCheckFunc {
maxDataBytes := types.MaxDataBytesNoEvidence(
state.ConsensusParams.Block.MaxBytes,
state.Validators.Size(),
)
return mempool.PreCheckMaxBytes(maxDataBytes)
func TxPreCheck(store Store) mempool.PreCheckFunc {
return func(tx types.Tx) error {
// TODO: this should probably be cached at some level.
state, err := store.Load()
if err != nil {
return err
}
maxDataBytes := types.MaxDataBytesNoEvidence(
state.ConsensusParams.Block.MaxBytes,
state.Validators.Size(),
)
return mempool.PreCheckMaxBytes(maxDataBytes)(tx)
}
}
// TxPostCheck returns a function to filter transactions after processing.
// The function limits the gas wanted by a transaction to the block's maximum total gas.
func TxPostCheck(state State) mempool.PostCheckFunc {
return mempool.PostCheckMaxGas(state.ConsensusParams.Block.MaxGas)
func TxPostCheck(store Store) mempool.PostCheckFunc {
return func(tx types.Tx, resp *abci.ResponseCheckTx) error {
// TODO: this should probably be cached at some level.
state, err := store.Load()
if err != nil {
return err
}
return mempool.PostCheckMaxGas(state.ConsensusParams.Block.MaxGas)(tx, resp)
}
}

+ 1
- 1
node/node.go View File

@ -272,7 +272,7 @@ func makeNode(
}
mpReactor, mp, err := createMempoolReactor(ctx,
cfg, proxyApp, state, nodeMetrics.mempool, peerManager, router, logger,
cfg, proxyApp, stateStore, nodeMetrics.mempool, peerManager, router, logger,
)
if err != nil {
return nil, combineCloseError(err, makeCloser(closers))


+ 3
- 4
node/setup.go View File

@ -172,7 +172,7 @@ func createMempoolReactor(
ctx context.Context,
cfg *config.Config,
proxyApp proxy.AppConns,
state sm.State,
store sm.Store,
memplMetrics *mempool.Metrics,
peerManager *p2p.PeerManager,
router *p2p.Router,
@ -184,10 +184,9 @@ func createMempoolReactor(
logger,
cfg.Mempool,
proxyApp.Mempool(),
state.LastBlockHeight,
mempool.WithMetrics(memplMetrics),
mempool.WithPreCheck(sm.TxPreCheck(state)),
mempool.WithPostCheck(sm.TxPostCheck(state)),
mempool.WithPreCheck(sm.TxPreCheck(store)),
mempool.WithPostCheck(sm.TxPostCheck(store)),
)
reactor, err := mempool.NewReactor(


Loading…
Cancel
Save