Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
mmsqe committed Dec 11, 2024
1 parent 7cd0207 commit bdd2a71
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 58 deletions.
58 changes: 1 addition & 57 deletions baseapp/txexecutor.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,65 +87,9 @@ func DefaultTxExecutor(_ context.Context,
return nil, nil
}

func DefaultSTMTxExecutor(
stores []types.StoreKey,
workers int,
txDecoder sdk.TxDecoder,
) TxExecutor {
index := make(map[types.StoreKey]int, len(stores))
for i, k := range stores {
index[k] = i
}
return func(
ctx context.Context,
txs [][]byte,
ms types.MultiStore,
deliverTxWithMultiStore func(int, sdk.Tx, types.MultiStore, map[string]any) *abci.ExecTxResult,
patcher TxResponsePatcher,
) ([]*abci.ExecTxResult, error) {
blockSize := len(txs)
if blockSize == 0 {
return nil, nil
}
results := make([]*abci.ExecTxResult, blockSize)
incarnationCache := make([]atomic.Pointer[map[string]any], blockSize)
for i := 0; i < blockSize; i++ {
m := make(map[string]any)
incarnationCache[i].Store(&m)
}

if err := blockstm.ExecuteBlock(
ctx,
blockSize,
index,
stmMultiStoreWrapper{ms},
workers,
func(txn blockstm.TxnIndex, ms blockstm.MultiStore) {
var cache map[string]any
// only one of the concurrent incarnations gets the cache if there are any, otherwise execute without
// cache, concurrent incarnations should be rare.
v := incarnationCache[txn].Swap(nil)
if v != nil {
cache = *v
}
results[txn] = deliverTxWithMultiStore(int(txn), nil, msWrapper{ms}, cache)

if v != nil {
incarnationCache[txn].Store(v)
}
},
); err != nil {
return nil, err
}

return patcher.Patch(results), nil
}
}

func STMTxExecutor(
stores []types.StoreKey,
workers int,
estimate bool,
txDecoder sdk.TxDecoder,
preEstimates func(txs [][]byte, workers int, txDecoder sdk.TxDecoder, ms types.MultiStore) ([]sdk.Tx, []blockstm.MultiLocations),
) TxExecutor {
Expand Down Expand Up @@ -175,7 +119,7 @@ func STMTxExecutor(
estimates []blockstm.MultiLocations
memTxs []sdk.Tx
)
if estimate {
if preEstimates != nil {
// pre-estimation
memTxs, estimates = preEstimates(txs, workers, txDecoder, ms)
}
Expand Down
2 changes: 1 addition & 1 deletion server/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ func (c Config) ValidateBasic() error {
"cannot enable state sync snapshots with '%s' pruning setting", pruningtypes.PruningOptionEverything,
)
}
var blockExecutors = []string{BlockExecutorSequential, BlockExecutorBlockSTM}
blockExecutors := []string{BlockExecutorSequential, BlockExecutorBlockSTM}
if c.BlockSTM.Executor != "" && !strings.StringInSlice(c.BlockSTM.Executor, blockExecutors) {
return fmt.Errorf("invalid block executor type %s, available types: %v", c.BlockSTM.Executor, blockExecutors)
}
Expand Down

0 comments on commit bdd2a71

Please sign in to comment.