mirror of
https://github.com/tendermint/tendermint.git
synced 2026-09-29 11:15:50 +00:00
Merge remote-tracking branch 'origin/master' into proxy-remove-triforcated-client
This commit is contained in:
@@ -360,8 +360,8 @@ func (blockExec *BlockExecutor) Commit(
|
||||
block.Height,
|
||||
block.Txs,
|
||||
deliverTxResponses,
|
||||
TxPreCheck(state),
|
||||
TxPostCheck(state),
|
||||
TxPreCheckForState(state),
|
||||
TxPostCheckForState(state),
|
||||
)
|
||||
|
||||
return res.Data, res.RetainHeight, err
|
||||
|
||||
+73
-10
@@ -1,22 +1,85 @@
|
||||
package state
|
||||
|
||||
import (
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
abci "github.com/tendermint/tendermint/abci/types"
|
||||
"github.com/tendermint/tendermint/internal/mempool"
|
||||
"github.com/tendermint/tendermint/types"
|
||||
)
|
||||
|
||||
// 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(),
|
||||
func cachingStateFetcher(store Store) func() (State, error) {
|
||||
const ttl = time.Second
|
||||
|
||||
var (
|
||||
last time.Time
|
||||
mutex = &sync.Mutex{}
|
||||
cache State
|
||||
err error
|
||||
)
|
||||
return mempool.PreCheckMaxBytes(maxDataBytes)
|
||||
|
||||
return func() (State, error) {
|
||||
mutex.Lock()
|
||||
defer mutex.Unlock()
|
||||
|
||||
if time.Since(last) < ttl && cache.ChainID != "" {
|
||||
return cache, nil
|
||||
}
|
||||
|
||||
cache, err = store.Load()
|
||||
if err != nil {
|
||||
return State{}, err
|
||||
}
|
||||
last = time.Now()
|
||||
|
||||
return cache, nil
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// TxPostCheck returns a function to filter transactions after processing.
|
||||
// TxPreCheckFromStore returns a function to filter transactions before processing.
|
||||
// The function limits the size of a transaction to the block's maximum data size.
|
||||
func TxPreCheckFromStore(store Store) mempool.PreCheckFunc {
|
||||
fetch := cachingStateFetcher(store)
|
||||
|
||||
return func(tx types.Tx) error {
|
||||
state, err := fetch()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return TxPreCheckForState(state)(tx)
|
||||
}
|
||||
}
|
||||
|
||||
func TxPreCheckForState(state State) mempool.PreCheckFunc {
|
||||
return func(tx types.Tx) error {
|
||||
maxDataBytes := types.MaxDataBytesNoEvidence(
|
||||
state.ConsensusParams.Block.MaxBytes,
|
||||
state.Validators.Size(),
|
||||
)
|
||||
return mempool.PreCheckMaxBytes(maxDataBytes)(tx)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// TxPostCheckFromStore 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 TxPostCheckFromStore(store Store) mempool.PostCheckFunc {
|
||||
fetch := cachingStateFetcher(store)
|
||||
|
||||
return func(tx types.Tx, resp *abci.ResponseCheckTx) error {
|
||||
state, err := fetch()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return mempool.PostCheckMaxGas(state.ConsensusParams.Block.MaxGas)(tx, resp)
|
||||
}
|
||||
}
|
||||
|
||||
func TxPostCheckForState(state State) mempool.PostCheckFunc {
|
||||
return func(tx types.Tx, resp *abci.ResponseCheckTx) error {
|
||||
return mempool.PostCheckMaxGas(state.ConsensusParams.Block.MaxGas)(tx, resp)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,7 +31,7 @@ func TestTxFilter(t *testing.T) {
|
||||
state, err := sm.MakeGenesisState(genDoc)
|
||||
require.NoError(t, err)
|
||||
|
||||
f := sm.TxPreCheck(state)
|
||||
f := sm.TxPreCheckForState(state)
|
||||
if tc.isErr {
|
||||
assert.NotNil(t, f(tc.tx), "#%v", i)
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user