forked from evmos/ethermint
-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- patch tx response to fix tx index and log index - collect tx fee to temporary module account
- Loading branch information
Showing
24 changed files
with
413 additions
and
223 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,159 @@ | ||
package app | ||
|
||
import ( | ||
"context" | ||
"io" | ||
|
||
"cosmossdk.io/store/cachekv" | ||
"cosmossdk.io/store/cachemulti" | ||
"cosmossdk.io/store/tracekv" | ||
storetypes "cosmossdk.io/store/types" | ||
abci "github.com/cometbft/cometbft/abci/types" | ||
"github.com/cosmos/cosmos-sdk/baseapp" | ||
evmtypes "github.com/evmos/ethermint/x/evm/types" | ||
block_stm "github.com/yihuang/go-block-stm" | ||
) | ||
|
||
func DefaultTxExecutor(ctx context.Context, | ||
blockSize int, | ||
ms storetypes.MultiStore, | ||
deliverTxWithMultiStore func(int, storetypes.MultiStore) *abci.ExecTxResult, | ||
) ([]*abci.ExecTxResult, error) { | ||
results := make([]*abci.ExecTxResult, blockSize) | ||
for i := 0; i < blockSize; i++ { | ||
results[i] = deliverTxWithMultiStore(i, ms) | ||
} | ||
return evmtypes.PatchTxResponses(results), nil | ||
} | ||
|
||
func STMTxExecutor(stores []storetypes.StoreKey, workers int) baseapp.TxExecutor { | ||
return func( | ||
ctx context.Context, | ||
blockSize int, | ||
ms storetypes.MultiStore, | ||
deliverTxWithMultiStore func(int, storetypes.MultiStore) *abci.ExecTxResult, | ||
) ([]*abci.ExecTxResult, error) { | ||
if blockSize == 0 { | ||
return nil, nil | ||
} | ||
results := make([]*abci.ExecTxResult, blockSize) | ||
if err := block_stm.ExecuteBlock( | ||
ctx, | ||
blockSize, | ||
stores, | ||
stmMultiStoreWrapper{ms}, | ||
workers, | ||
func(txn block_stm.TxnIndex, ms block_stm.MultiStore) { | ||
result := deliverTxWithMultiStore(int(txn), newMultiStoreWrapper(ms, stores)) | ||
results[txn] = result | ||
}, | ||
); err != nil { | ||
return nil, err | ||
} | ||
|
||
return evmtypes.PatchTxResponses(results), nil | ||
} | ||
} | ||
|
||
type storeWrapper struct { | ||
block_stm.KVStore | ||
} | ||
|
||
var ( | ||
_ storetypes.Store = storeWrapper{} | ||
_ storetypes.KVStore = storeWrapper{} | ||
) | ||
|
||
func (s storeWrapper) GetStoreType() storetypes.StoreType { | ||
return storetypes.StoreTypeIAVL | ||
} | ||
|
||
func (s storeWrapper) CacheWrap() storetypes.CacheWrap { | ||
return cachekv.NewStore(storetypes.KVStore(s)) | ||
} | ||
|
||
func (s storeWrapper) CacheWrapWithTrace(w io.Writer, tc storetypes.TraceContext) storetypes.CacheWrap { | ||
return cachekv.NewStore(tracekv.NewStore(s, w, tc)) | ||
} | ||
|
||
type msWrapper struct { | ||
block_stm.MultiStore | ||
stores []storetypes.StoreKey | ||
keysByName map[string]storetypes.StoreKey | ||
} | ||
|
||
var _ storetypes.MultiStore = msWrapper{} | ||
|
||
func newMultiStoreWrapper(ms block_stm.MultiStore, stores []storetypes.StoreKey) msWrapper { | ||
keysByName := make(map[string]storetypes.StoreKey) | ||
for _, k := range stores { | ||
keysByName[k.Name()] = k | ||
} | ||
return msWrapper{ms, stores, keysByName} | ||
} | ||
|
||
func (ms msWrapper) GetStore(key storetypes.StoreKey) storetypes.Store { | ||
return storetypes.Store(ms.GetKVStore(key)) | ||
} | ||
|
||
func (ms msWrapper) GetKVStore(key storetypes.StoreKey) storetypes.KVStore { | ||
return storeWrapper{ms.MultiStore.GetKVStore(key)} | ||
} | ||
|
||
func (ms msWrapper) CacheMultiStore() storetypes.CacheMultiStore { | ||
stores := make(map[storetypes.StoreKey]storetypes.CacheWrapper) | ||
for _, k := range ms.stores { | ||
store := ms.GetKVStore(k) | ||
stores[k] = store | ||
} | ||
return cachemulti.NewStore(nil, stores, ms.keysByName, nil, nil) | ||
} | ||
|
||
func (ms msWrapper) CacheMultiStoreWithVersion(_ int64) (storetypes.CacheMultiStore, error) { | ||
panic("cannot branch cached multi-store with a version") | ||
} | ||
|
||
// Implements CacheWrapper. | ||
func (ms msWrapper) CacheWrap() storetypes.CacheWrap { | ||
return ms.CacheMultiStore().(storetypes.CacheWrap) | ||
} | ||
|
||
// CacheWrapWithTrace implements the CacheWrapper interface. | ||
func (ms msWrapper) CacheWrapWithTrace(_ io.Writer, _ storetypes.TraceContext) storetypes.CacheWrap { | ||
return ms.CacheWrap() | ||
} | ||
|
||
// GetStoreType returns the type of the store. | ||
func (ms msWrapper) GetStoreType() storetypes.StoreType { | ||
return storetypes.StoreTypeMulti | ||
} | ||
|
||
// LatestVersion returns the branch version of the store | ||
func (ms msWrapper) LatestVersion() int64 { | ||
panic("cannot get latest version from branch cached multi-store") | ||
} | ||
|
||
// Implements interface MultiStore | ||
func (ms msWrapper) SetTracer(w io.Writer) storetypes.MultiStore { | ||
return nil | ||
} | ||
|
||
// Implements interface MultiStore | ||
func (ms msWrapper) SetTracingContext(storetypes.TraceContext) storetypes.MultiStore { | ||
return nil | ||
} | ||
|
||
// Implements interface MultiStore | ||
func (ms msWrapper) TracingEnabled() bool { | ||
return false | ||
} | ||
|
||
type stmMultiStoreWrapper struct { | ||
inner storetypes.MultiStore | ||
} | ||
|
||
var _ block_stm.MultiStore = stmMultiStoreWrapper{} | ||
|
||
func (ms stmMultiStoreWrapper) GetKVStore(key storetypes.StoreKey) block_stm.KVStore { | ||
return block_stm.KVStore(ms.inner.GetKVStore(key)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.