|
@ -22,15 +22,23 @@ func cachingStateFetcher(store Store) func() (State, error) { |
|
|
mutex.Lock() |
|
|
mutex.Lock() |
|
|
defer mutex.Unlock() |
|
|
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) |
|
|
|
|
|
|
|
|
if time.Since(last) < ttl && cache.ChainID != "" { |
|
|
|
|
|
return cache, nil |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
cache, err = store.Load() |
|
|
|
|
|
if err != nil { |
|
|
|
|
|
return State{}, err |
|
|
|
|
|
} |
|
|
|
|
|
last = time.Now() |
|
|
|
|
|
// at least 100ms but maybe as much as that+
|
|
|
|
|
|
// a block interval. This might end up being
|
|
|
|
|
|
// too much, but it replaces a mechanism that
|
|
|
|
|
|
// cached these values for the entire runtime
|
|
|
|
|
|
// of the process
|
|
|
|
|
|
ttl = (100 * time.Millisecond) + cache.LastBlockTime.Sub(last) |
|
|
|
|
|
|
|
|
|
|
|
return cache, nil |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
@ -38,9 +46,10 @@ func cachingStateFetcher(store Store) func() (State, error) { |
|
|
// TxPreCheck returns a function to filter transactions before processing.
|
|
|
// TxPreCheck returns a function to filter transactions before processing.
|
|
|
// The function limits the size of a transaction to the block's maximum data size.
|
|
|
// The function limits the size of a transaction to the block's maximum data size.
|
|
|
func TxPreCheck(store Store) mempool.PreCheckFunc { |
|
|
func TxPreCheck(store Store) mempool.PreCheckFunc { |
|
|
|
|
|
fetch := cachingStateFetcher(store) |
|
|
|
|
|
|
|
|
return func(tx types.Tx) error { |
|
|
return func(tx types.Tx) error { |
|
|
// TODO: this should probably be cached at some level.
|
|
|
|
|
|
state, err := store.Load() |
|
|
|
|
|
|
|
|
state, err := fetch() |
|
|
if err != nil { |
|
|
if err != nil { |
|
|
return err |
|
|
return err |
|
|
} |
|
|
} |
|
@ -55,9 +64,10 @@ func TxPreCheck(store Store) mempool.PreCheckFunc { |
|
|
// TxPostCheck returns a function to filter transactions after processing.
|
|
|
// 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.
|
|
|
// The function limits the gas wanted by a transaction to the block's maximum total gas.
|
|
|
func TxPostCheck(store Store) mempool.PostCheckFunc { |
|
|
func TxPostCheck(store Store) mempool.PostCheckFunc { |
|
|
|
|
|
fetch := cachingStateFetcher(store) |
|
|
|
|
|
|
|
|
return func(tx types.Tx, resp *abci.ResponseCheckTx) error { |
|
|
return func(tx types.Tx, resp *abci.ResponseCheckTx) error { |
|
|
// TODO: this should probably be cached at some level.
|
|
|
|
|
|
state, err := store.Load() |
|
|
|
|
|
|
|
|
state, err := fetch() |
|
|
if err != nil { |
|
|
if err != nil { |
|
|
return err |
|
|
return err |
|
|
} |
|
|
} |
|
|