Browse Source

wip wip

pull/8062/head
tycho garen 3 years ago
parent
commit
88a63cbad7
3 changed files with 24 additions and 18 deletions
  1. +3
    -4
      internal/state/execution.go
  2. +21
    -11
      internal/state/tx_filter.go
  3. +0
    -3
      node/node_test.go

+ 3
- 4
internal/state/execution.go View File

@ -253,7 +253,7 @@ func (blockExec *BlockExecutor) ApplyBlock(
} }
// Lock mempool, commit app state, update mempoool. // Lock mempool, commit app state, update mempoool.
appHash, retainHeight, err := blockExec.Commit(ctx, state, block, abciResponses.FinalizeBlock.Txs)
appHash, retainHeight, err := blockExec.Commit(ctx, block, abciResponses.FinalizeBlock.Txs)
if err != nil { if err != nil {
return state, fmt.Errorf("commit failed for application: %w", err) return state, fmt.Errorf("commit failed for application: %w", err)
} }
@ -324,7 +324,6 @@ func (blockExec *BlockExecutor) VerifyVoteExtension(ctx context.Context, vote *t
// state before new txs are run in the mempool, lest they be invalid. // state before new txs are run in the mempool, lest they be invalid.
func (blockExec *BlockExecutor) Commit( func (blockExec *BlockExecutor) Commit(
ctx context.Context, ctx context.Context,
state State,
block *types.Block, block *types.Block,
deliverTxResponses []*abci.ResponseDeliverTx, deliverTxResponses []*abci.ResponseDeliverTx,
) ([]byte, int64, error) { ) ([]byte, int64, error) {
@ -360,8 +359,8 @@ func (blockExec *BlockExecutor) Commit(
block.Height, block.Height,
block.Txs, block.Txs,
deliverTxResponses, deliverTxResponses,
TxPreCheck(state),
TxPostCheck(state),
TxPreCheck(blockExec.store),
TxPostCheck(blockExec.store),
) )
return res.Data, res.RetainHeight, err return res.Data, res.RetainHeight, err


+ 21
- 11
internal/state/tx_filter.go View File

@ -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
} }


+ 0
- 3
node/node_test.go View File

@ -292,7 +292,6 @@ func TestCreateProposalBlock(t *testing.T) {
logger.With("module", "mempool"), logger.With("module", "mempool"),
cfg.Mempool, cfg.Mempool,
proxyApp.Mempool(), proxyApp.Mempool(),
state.LastBlockHeight,
) )
// Make EvidencePool // Make EvidencePool
@ -392,7 +391,6 @@ func TestMaxTxsProposalBlockSize(t *testing.T) {
logger.With("module", "mempool"), logger.With("module", "mempool"),
cfg.Mempool, cfg.Mempool,
proxyApp.Mempool(), proxyApp.Mempool(),
state.LastBlockHeight,
) )
// fill the mempool with one txs just below the maximum size // fill the mempool with one txs just below the maximum size
@ -457,7 +455,6 @@ func TestMaxProposalBlockSize(t *testing.T) {
logger.With("module", "mempool"), logger.With("module", "mempool"),
cfg.Mempool, cfg.Mempool,
proxyApp.Mempool(), proxyApp.Mempool(),
state.LastBlockHeight,
) )
// fill the mempool with one txs just below the maximum size // fill the mempool with one txs just below the maximum size


Loading…
Cancel
Save