Skip to content

Commit

Permalink
fix dds wasm (#183)
Browse files Browse the repository at this point in the history
* fix dds wasm

* simulate not set WasmStoreCode

* change isDeliver to IsDeliverWithSerial

* change isDeliver to IsDeliverWithSerial

* change isDeliver to IsDeliverWithSerial

* change isDeliver to IsDeliverWithSerial

---------

Co-authored-by: KamiD <[email protected]>
  • Loading branch information
chengzhinei and KamiD authored Jun 25, 2023
1 parent 8823340 commit 0022603
Show file tree
Hide file tree
Showing 16 changed files with 65 additions and 60 deletions.
2 changes: 1 addition & 1 deletion app/innertx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func (suite *InnerTxTestSuite) SetupTest() {

suite.app = Setup(checkTx)
suite.ctx = suite.app.BaseApp.NewContext(checkTx, abci.Header{Height: 1, ChainID: chain_id, Time: time.Now().UTC()})
suite.ctx.SetDeliver()
suite.ctx.SetDeliverSerial()
suite.stateDB = evm_types.CreateEmptyCommitStateDB(suite.app.EvmKeeper.GenerateCSDBParams(), suite.ctx)
suite.codec = codec.New()

Expand Down
2 changes: 1 addition & 1 deletion libs/cosmos-sdk/baseapp/baseapp.go
Original file line number Diff line number Diff line change
Expand Up @@ -699,7 +699,7 @@ func (app *BaseApp) getContextForTx(mode runTxMode, txBytes []byte) sdk.Context
}

if mode == runTxModeDeliver {
ctx.SetDeliver()
ctx.SetDeliverSerial()
}
ctx.SetFeeSplitInfo(&sdk.FeeSplitInfo{})

Expand Down
72 changes: 36 additions & 36 deletions libs/cosmos-sdk/types/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,36 +24,36 @@ but please do not over-use it. We try to keep all data structured
and standard additions here would be better just to add to the Context struct
*/
type Context struct {
ctx context.Context
ms MultiStore
header *abci.Header
chainID string
from string
txBytes []byte
logger log.Logger
voteInfo []abci.VoteInfo
gasMeter GasMeter
blockGasMeter GasMeter
isDeliver bool
checkTx bool
recheckTx bool // if recheckTx == true, then checkTx must also be true
wrappedCheckTx bool // if wrappedCheckTx == true, then checkTx must also be true
traceTx bool // traceTx is set true for trace tx and its predesessors , traceTx was set in app.beginBlockForTrace()
traceTxLog bool // traceTxLog is used to create trace logger for evm , traceTxLog is set to true when only tracing target tx (its predesessors will set false), traceTxLog is set before runtx
traceTxConfigBytes []byte // traceTxConfigBytes is used to save traceTxConfig, passed from api to x/evm
minGasPrice DecCoins
consParams *abci.ConsensusParams
eventManager *EventManager
accountNonce uint64
trc *trace.Tracer
accountCache *AccountCache
paraMsg *ParaMsg
ctx context.Context
ms MultiStore
header *abci.Header
chainID string
from string
txBytes []byte
logger log.Logger
voteInfo []abci.VoteInfo
gasMeter GasMeter
blockGasMeter GasMeter
isDeliverWithSerial bool
checkTx bool
recheckTx bool // if recheckTx == true, then checkTx must also be true
wrappedCheckTx bool // if wrappedCheckTx == true, then checkTx must also be true
traceTx bool // traceTx is set true for trace tx and its predesessors , traceTx was set in app.beginBlockForTrace()
traceTxLog bool // traceTxLog is used to create trace logger for evm , traceTxLog is set to true when only tracing target tx (its predesessors will set false), traceTxLog is set before runtx
traceTxConfigBytes []byte // traceTxConfigBytes is used to save traceTxConfig, passed from api to x/evm
minGasPrice DecCoins
consParams *abci.ConsensusParams
eventManager *EventManager
accountNonce uint64
trc *trace.Tracer
accountCache *AccountCache
paraMsg *ParaMsg
// txCount uint32
overridesBytes []byte // overridesBytes is used to save overrides info, passed from ethCall to x/evm
watcher *TxWatcher
feesplitInfo *FeeSplitInfo
statedb vm.StateDB
outOfGas bool
overridesBytes []byte // overridesBytes is used to save overrides info, passed from ethCall to x/evm
watcher *TxWatcher
feesplitInfo *FeeSplitInfo
statedb vm.StateDB
outOfGas bool
wasmSimulateCache map[string][]byte
}

Expand Down Expand Up @@ -83,12 +83,12 @@ func (c *Context) VoteInfos() []abci.VoteInfo { return c.voteInfo }
func (c *Context) GasMeter() GasMeter { return c.gasMeter }
func (c *Context) BlockGasMeter() GasMeter { return c.blockGasMeter }

func (c *Context) IsDeliver() bool {
return c.isDeliver
func (c *Context) IsDeliverWithSerial() bool {
return c.isDeliverWithSerial
}

func (c *Context) UseParamCache() bool {
return c.isDeliver || (c.paraMsg != nil && !c.paraMsg.HaveCosmosTxInBlock) || c.checkTx
return c.isDeliverWithSerial || (c.paraMsg != nil && !c.paraMsg.HaveCosmosTxInBlock) || c.checkTx
}

func (c *Context) IsCheckTx() bool { return c.checkTx }
Expand Down Expand Up @@ -208,8 +208,8 @@ func NewContext(ms MultiStore, header abci.Header, isCheckTx bool, logger log.Lo
}
}

func (c *Context) SetDeliver() *Context {
c.isDeliver = true
func (c *Context) SetDeliverSerial() *Context {
c.isDeliverWithSerial = true
return c
}

Expand Down Expand Up @@ -318,8 +318,8 @@ func (c *Context) SetIsCheckTx(isCheckTx bool) *Context {
return c
}

func (c *Context) SetIsDeliverTx(isDeliverTx bool) *Context {
c.isDeliver = isDeliverTx
func (c *Context) SetIsDeliverTxSerial(isDeliverWithSerial bool) *Context {
c.isDeliverWithSerial = isDeliverWithSerial
return c
}

Expand Down
7 changes: 4 additions & 3 deletions libs/cosmos-sdk/x/auth/keeper/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func (ak AccountKeeper) SetAccount(ctx sdk.Context, acc exported.Account) {
storeAccKey := types.AddressStoreKey(addr)
store.Set(storeAccKey, bz)

if ctx.IsDeliver() {
if ctx.IsDeliverWithSerial() {
mpt.GAccToPrefetchChannel <- [][]byte{storeAccKey}
}

Expand Down Expand Up @@ -119,7 +119,7 @@ func (ak AccountKeeper) RemoveAccount(ctx sdk.Context, acc exported.Account) {
storeAccKey := types.AddressStoreKey(addr)
store.Delete(storeAccKey)

if ctx.IsDeliver() {
if ctx.IsDeliverWithSerial() {
mpt.GAccToPrefetchChannel <- [][]byte{storeAccKey}
}
}
Expand All @@ -141,7 +141,8 @@ func (ak AccountKeeper) IterateAccounts(ctx sdk.Context, cb func(account exporte
}

// IterateAccounts iterates over all the stored accounts and performs a callback function
// TODO by yxq: deprecated
//
// TODO by yxq: deprecated
func (ak AccountKeeper) MigrateAccounts(ctx sdk.Context, cb func(account exported.Account, key, value []byte) (stop bool)) {

store := ctx.KVStore(ak.mptKey)
Expand Down
4 changes: 2 additions & 2 deletions libs/tendermint/state/execution_dds.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,14 +194,14 @@ func (dc *DeltaContext) postApplyBlock(height int64, deltaInfo *DeltaInfo,
}

// delta producer
if dc.uploadDelta {
if dc.uploadDelta && !types.WasmStoreCode {
trace.GetElapsedInfo().AddInfo(trace.Delta, fmt.Sprintf("ratio<%.2f>", dc.hitRatio()))

wdFunc := evmWatchDataManager.CreateWatchDataGenerator()
wasmWdFunc := wasmWatchDataManager.CreateWatchDataGenerator()
go dc.uploadData(height, abciResponses, deltaMap, wdFunc, wasmWdFunc)

}
types.WasmStoreCode = false
}

func (dc *DeltaContext) uploadData(height int64, abciResponses *ABCIResponses, deltaMap interface{}, wdFunc, wasmWdFunc func() ([]byte, error)) {
Expand Down
1 change: 1 addition & 0 deletions libs/tendermint/types/deltas.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ var (
FastQuery = false
DownloadDelta = false
UploadDelta = false
WasmStoreCode = false
)

type TreeDelta struct {
Expand Down
2 changes: 1 addition & 1 deletion x/evm/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ func NewHandler(k *Keeper) sdk.Handler {
return func(ctx sdk.Context, msg sdk.Msg) (result *sdk.Result, err error) {
ctx.SetEventManager(sdk.NewEventManager())

if ctx.IsDeliver() {
if ctx.IsDeliverWithSerial() {
k.UpdatedAccount = k.UpdatedAccount[:0]
}

Expand Down
10 changes: 5 additions & 5 deletions x/evm/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func (suite *EvmTestSuite) SetupTest() {

suite.app = app.Setup(checkTx)
suite.ctx = suite.app.BaseApp.NewContext(checkTx, abci.Header{Height: 1, ChainID: chain_id, Time: time.Now().UTC()})
suite.ctx.SetDeliver()
suite.ctx.SetDeliverSerial()
suite.stateDB = types.CreateEmptyCommitStateDB(suite.app.EvmKeeper.GenerateCSDBParams(), suite.ctx)
suite.handler = evm.NewHandler(suite.app.EvmKeeper)
suite.querier = keeper.NewQuerier(*suite.app.EvmKeeper)
Expand Down Expand Up @@ -614,14 +614,14 @@ func (suite *EvmTestSuite) TestSimulateConflict() {
suite.Require().NoError(err)

suite.ctx.SetGasMeter(sdk.NewInfiniteGasMeter())
suite.ctx.SetIsCheckTx(true).SetIsDeliverTx(false)
suite.ctx.SetIsCheckTx(true).SetIsDeliverTxSerial(false)

cacheCtx, _ := suite.ctx.CacheContext()
result, err := suite.handler(cacheCtx, tx)
suite.Require().NotNil(result)
suite.Require().Nil(err)

suite.ctx.SetIsCheckTx(false).SetIsDeliverTx(true)
suite.ctx.SetIsCheckTx(false).SetIsDeliverTxSerial(true)
result, err = suite.handler(suite.ctx, tx)
suite.Require().NotNil(result)
suite.Require().Nil(err)
Expand Down Expand Up @@ -801,7 +801,7 @@ func (suite *EvmContractBlockedListTestSuite) SetupTest() {

suite.app = app.Setup(checkTx)
suite.ctx = suite.app.BaseApp.NewContext(checkTx, abci.Header{Height: 1, ChainID: "ethermint-3", Time: time.Now().UTC()})
suite.ctx.SetDeliver()
suite.ctx.SetDeliverSerial()
suite.stateDB = types.CreateEmptyCommitStateDB(suite.app.EvmKeeper.GenerateCSDBParams(), suite.ctx)
suite.handler = evm.NewHandler(suite.app.EvmKeeper)

Expand Down Expand Up @@ -1043,7 +1043,7 @@ func (suite *EvmContractBlockedListTestSuite) TestEvmParamsAndContractMethodBloc
for _, tc := range testCases {
suite.Run(tc.msg, func() {
suite.SetupTest()
suite.ctx.SetIsDeliverTx(true).SetIsCheckTx(false)
suite.ctx.SetIsDeliverTxSerial(true).SetIsCheckTx(false)

// set contract code
suite.stateDB.CreateAccount(callEthAcc)
Expand Down
4 changes: 2 additions & 2 deletions x/evm/keeper/params_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ func (suite *KeeperTestSuite) TestParams() {
suite.app.EvmKeeper.SetParams(suite.ctx, params)
newParams := suite.app.EvmKeeper.GetParams(suite.ctx)
suite.Require().Equal(newParams, params)
newParams = suite.app.EvmKeeper.GetParams(*suite.ctx.SetDeliver())
newParams = suite.app.EvmKeeper.GetParams(*suite.ctx.SetDeliverSerial())
suite.Require().Equal(newParams, params)
types.GetEvmParamsCache().UpdateParams(params, false)
newParams = suite.app.EvmKeeper.GetParams(*suite.ctx.SetDeliver())
newParams = suite.app.EvmKeeper.GetParams(*suite.ctx.SetDeliverSerial())
suite.Require().Equal(newParams, params)
}
2 changes: 1 addition & 1 deletion x/evm/types/state_transition.go
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ func (st StateTransition) TransitionDb(ctx sdk.Context, config ChainConfig) (exe
}

if !st.Simulate {
if ctx.IsDeliver() || ctx.ParaMsg() != nil {
if ctx.IsDeliverWithSerial() || ctx.ParaMsg() != nil {
csdb.Commit(true)
}
}
Expand Down
2 changes: 1 addition & 1 deletion x/evm/types/statedb_protect_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func (suite *StateDB_ProtectTestSuite) SetupTest() {

suite.app = app.Setup(checkTx)
suite.ctx = suite.app.BaseApp.NewContext(checkTx, abci.Header{Height: 1, ChainID: "ethermint-1"})
suite.ctx.SetDeliver()
suite.ctx.SetDeliverSerial()
suite.stateDB = types.CreateEmptyCommitStateDB(suite.app.EvmKeeper.GenerateCSDBParams(), suite.ctx)

privkey, err := ethsecp256k1.GenerateKey()
Expand Down
2 changes: 1 addition & 1 deletion x/evm/types/statedb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func (suite *StateDBTestSuite) SetupTest() {

suite.app = app.Setup(checkTx)
suite.ctx = suite.app.BaseApp.NewContext(checkTx, abci.Header{Height: 1, ChainID: "ethermint-1"})
suite.ctx.SetDeliver()
suite.ctx.SetDeliverSerial()
suite.stateDB = types.CreateEmptyCommitStateDB(suite.app.EvmKeeper.GenerateCSDBParams(), suite.ctx)

privkey, err := ethsecp256k1.GenerateKey()
Expand Down
2 changes: 1 addition & 1 deletion x/evm/watcher/watcher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func setupTest() *WatcherTestSt {

w.app = app.Setup(checkTx)
w.ctx = w.app.BaseApp.NewContext(checkTx, abci.Header{Height: 1, ChainID: chain_id, Time: time.Now().UTC()})
w.ctx.SetDeliver()
w.ctx.SetDeliverSerial()
w.handler = evm.NewHandler(w.app.EvmKeeper)

ethermint.SetChainId(chain_id)
Expand Down
6 changes: 3 additions & 3 deletions x/feesplit/keeper/fee_splits.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ func (k Keeper) SetFeeSplit(ctx sdk.Context, feeSplit types.FeeSplit) {
store.Set(key.Bytes(), bz)

// update cache
if ctx.IsDeliver() || ctx.ParaMsg() != nil {
if ctx.IsDeliverWithSerial() || ctx.ParaMsg() != nil {
types.GetParamsCache().UpdateFeeSplit(feeSplit.ContractAddress, feeSplit, ctx.IsCheckTx())
}
}
Expand All @@ -106,7 +106,7 @@ func (k Keeper) DeleteFeeSplit(ctx sdk.Context, feeSplit types.FeeSplit) {
store.Delete(key.Bytes())

// update cache
if ctx.IsDeliver() || ctx.ParaMsg() != nil {
if ctx.IsDeliverWithSerial() || ctx.ParaMsg() != nil {
types.GetParamsCache().DeleteFeeSplit(feeSplit.ContractAddress, ctx.IsCheckTx())
}
}
Expand Down Expand Up @@ -196,7 +196,7 @@ func (k Keeper) SetContractShare(
store.Set(contract.Bytes(), share.Bytes())

// update cache
if ctx.IsDeliver() || ctx.ParaMsg() != nil {
if ctx.IsDeliverWithSerial() || ctx.ParaMsg() != nil {
types.GetParamsCache().UpdateShare(contract, share, ctx.IsCheckTx())
}
}
Expand Down
2 changes: 1 addition & 1 deletion x/params/types/upgrade_cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func (suite *UpgradeKeeperSuite) SetupTest() {

func (suite *UpgradeKeeperSuite) Context(height int64) sdk.Context {
ctx := sdk.NewContext(suite.ms, abci.Header{Height: height}, false, suite.logger)
ctx.SetDeliver()
ctx.SetDeliverSerial()
return ctx
}

Expand Down
5 changes: 4 additions & 1 deletion x/wasm/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func NewHandler(k types.ContractOpsKeeper) sdk.Handler {
// update watcher
defer func() {
// update watchDB when delivering tx
if ctx.IsDeliver() || ctx.ParaMsg() != nil {
if ctx.IsDeliverWithSerial() || ctx.ParaMsg() != nil {
watcher.Save(err)
}

Expand All @@ -46,6 +46,9 @@ func NewHandler(k types.ContractOpsKeeper) sdk.Handler {

switch msg := msg.(type) {
case *MsgStoreCode: //nolint:typecheck
if !ctx.IsCheckTx() {
types2.WasmStoreCode = true
}
res, err = msgServer.StoreCode(sdk.WrapSDKContext(ctx), msg)
case *MsgInstantiateContract:
res, err = msgServer.InstantiateContract(sdk.WrapSDKContext(ctx), msg)
Expand Down

0 comments on commit 0022603

Please sign in to comment.