Skip to content

Commit

Permalink
Merge branch 'dev' into kefan/auto_snapshot
Browse files Browse the repository at this point in the history
  • Loading branch information
KamiD authored Jul 11, 2023
2 parents 0eb772b + 9483c69 commit 8518b52
Show file tree
Hide file tree
Showing 16 changed files with 155 additions and 162 deletions.
25 changes: 17 additions & 8 deletions app/app_parallel.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,15 +117,17 @@ func getTxFeeHandler() sdk.GetTxFeeHandler {

// getTxFeeAndFromHandler get tx fee and from
func getTxFeeAndFromHandler(ek appante.EVMKeeper) sdk.GetTxFeeAndFromHandler {
return func(ctx sdk.Context, tx sdk.Tx) (fee sdk.Coins, isEvm bool, isE2C bool, from string, to string, err error, supportPara bool) {
return func(ctx sdk.Context, tx sdk.Tx) (fee sdk.Coins, isEvm bool, needUpdateTXCounter bool, from string, to string, err error, supportPara bool) {
if evmTx, ok := tx.(*evmtypes.MsgEthereumTx); ok {
isEvm = true
supportPara = true
if appante.IsE2CTx(ek, &ctx, evmTx) {
isE2C = true
if tmtypes.HigherThanVenus6(ctx.BlockHeight()) {
needUpdateTXCounter = true
}
// E2C will include cosmos Msg in the Payload.
// Sometimes, this Msg do not support parallel execution.
if !isParaSupportedE2CMsg(evmTx.Data.Payload) {
if !tmtypes.HigherThanVenus6(ctx.BlockHeight()) || !isParaSupportedE2CMsg(evmTx.Data.Payload) {
supportPara = false
}
}
Expand All @@ -143,11 +145,18 @@ func getTxFeeAndFromHandler(ek appante.EVMKeeper) sdk.GetTxFeeAndFromHandler {
}
} else if feeTx, ok := tx.(authante.FeeTx); ok {
fee = feeTx.GetFee()
if stdTx, ok := tx.(*auth.StdTx); ok && len(stdTx.Msgs) == 1 { // only support one message
if msg, ok := stdTx.Msgs[0].(interface{ CalFromAndToForPara() (string, string) }); ok {
from, to = msg.CalFromAndToForPara()
if tmtypes.HigherThanVenus6(ctx.BlockHeight()) {
supportPara = true
if tx.GetType() == sdk.StdTxType {
if tmtypes.HigherThanEarth(ctx.BlockHeight()) {
needUpdateTXCounter = true
}
txMsgs := tx.GetMsgs()
// only support one message
if len(txMsgs) == 1 {
if msg, ok := txMsgs[0].(interface{ CalFromAndToForPara() (string, string) }); ok {
from, to = msg.CalFromAndToForPara()
if tmtypes.HigherThanVenus6(ctx.BlockHeight()) {
supportPara = true
}
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/client/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ func RegisterAppFlag(cmd *cobra.Command) {
cmd.Flags().String(tmdb.FlagRocksdbOpts, "", "Options of rocksdb. (block_size=4KB,block_cache=1GB,statistics=true,allow_mmap_reads=true,max_open_files=-1,unordered_write=true,pipelined_write=true)")
cmd.Flags().String(types.FlagNodeMode, "", "Node mode (rpc|val|archive) is used to manage flags")

cmd.Flags().Bool(consensus.EnablePrerunTx, true, "enable proactively runtx mode, default close")
cmd.Flags().Bool(consensus.EnablePrerunTx, true, "enable proactively runtx mode, default open")
cmd.Flags().String(automation.ConsensusRole, "", "consensus role")
cmd.Flags().String(automation.ConsensusTestcase, "", "consensus test case file")

Expand Down
2 changes: 1 addition & 1 deletion dev/vmbridge.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
res=$(exchaincli tx wasm store ./wasm/vmbridge-erc20/artifacts/cw_erc20.wasm --fees 0.01okt --from captain --gas=20000000 -b block -y)
res=$(exchaincli tx wasm store ./wasm/erc20/artifacts/cw_erc20.wasm --fees 0.01okt --from captain --gas=20000000 -b block -y)
echo "store--------------"
echo $res
code_id=$(echo "$res" | jq '.logs[0].events[1].attributes[0].value' | sed 's/\"//g')
Expand Down
28 changes: 0 additions & 28 deletions dev/wasm/erc20/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,6 @@ pub fn execute(
recipient,
amount,
} => try_send_to_erc20(deps, env,evmContract,recipient,amount,info),

ExecuteMsg::CallToEvmMsg {
evmaddr,
calldata,
value,
} => try_call_to_evm(deps, env,evmaddr,calldata,value,info),
}
}

Expand Down Expand Up @@ -160,29 +154,7 @@ fn try_mint_cw20(
.add_attribute("amount", amount.to_string()))
}

fn try_call_to_evm(
deps: DepsMut,
_env: Env,
evmaddr: String,
calldata: String,
value: Uint128,
info: MessageInfo,
) -> Result<Response<SendToEvmMsg>, ContractError> {

let submsg = SendToEvmMsg {
sender: _env.contract.address.to_string(),
evmaddr: evmaddr.to_string(),
calldata: calldata,
value: value,
};

Ok(Response::new()
.add_attribute("action", "call to evm")
.add_attribute("evmaddr", evmaddr.to_string())
.add_attribute("value", value.to_string())
.add_message(submsg)
.set_data(b"the result data"))
}

fn try_send_to_erc20(
deps: DepsMut,
Expand Down
20 changes: 0 additions & 20 deletions dev/wasm/erc20/src/msg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,6 @@ pub enum ExecuteMsg {
recipient: String,
amount: Uint128,
},
CallToEvm {
evmContract: String,
calldata: String,
value: Uint128,
}
}

#[derive(Serialize, Deserialize, Clone, PartialEq, JsonSchema, Debug)]
Expand All @@ -71,21 +66,6 @@ impl Into<CosmosMsg<SendToEvmMsg>> for SendToEvmMsg {
}
impl CustomMsg for SendToEvmMsg {}

#[derive(Serialize, Deserialize, Clone, PartialEq, JsonSchema, Debug)]
#[serde(rename_all = "snake_case")]
pub struct CallToEvmMsg {
pub sender: String,
pub evmaddr: String,
pub calldata: String,
pub value: Uint128,

}
impl Into<CosmosMsg<CallToEvmMsg>> for CallToEvmMsg {
fn into(self) -> CosmosMsg<CallToEvmMsg> {
CosmosMsg::Custom(self)
}
}
impl CustomMsg for CallToEvmMsg {}

#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
#[serde(rename_all = "snake_case")]
Expand Down
10 changes: 5 additions & 5 deletions dev/wasm/vmbridge-erc20/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,11 +157,11 @@ fn try_mint_cw20(
recipient: String,
amount: Uint128,
) -> Result<Response<CallToEvmMsg>, ContractError> {
if info.sender.to_string() != EVM_CONTRACT_ADDR.to_string() {
return Err(ContractError::ContractERC20Err {
addr:info.sender.to_string()
});
}
// if info.sender.to_string() != EVM_CONTRACT_ADDR.to_string() {
// return Err(ContractError::ContractERC20Err {
// addr:info.sender.to_string()
// });
// }
let amount_raw = amount.u128();
let recipient_address = deps.api.addr_validate(recipient.as_str())?;
let mut account_balance = read_balance(deps.storage, &recipient_address)?;
Expand Down
8 changes: 7 additions & 1 deletion libs/cosmos-sdk/baseapp/baseapp.go
Original file line number Diff line number Diff line change
Expand Up @@ -697,10 +697,16 @@ func (app *BaseApp) getContextForTx(mode runTxMode, txBytes []byte) sdk.Context
ctx.SetGasMeter(sdk.NewInfiniteGasMeter())
}
if app.parallelTxManage.isAsyncDeliverTx && mode == runTxModeDeliverInAsync {
app.parallelTxManage.txByteMpCMIndexLock.RLock()
ctx.SetParaMsg(&sdk.ParaMsg{
HaveCosmosTxInBlock: app.parallelTxManage.haveCosmosTxInBlock,
// Concurrency security issues need to be considered here,
// and there is a small probability that NeedUpdateTXCounter() will be wrong
// due to concurrent reading and writing of pm.txIndexMpUpdateTXCounter (slice),
// but such tx will be rerun, so this case can be ignored.
NeedUpdateTXCounter: app.parallelTxManage.NeedUpdateTXCounter(),
CosmosIndexInBlock: app.parallelTxManage.txByteMpCosmosIndex[string(txBytes)],
})
app.parallelTxManage.txByteMpCMIndexLock.RUnlock()
ctx.SetTxBytes(txBytes)
ctx.ResetWatcher()
}
Expand Down
Loading

0 comments on commit 8518b52

Please sign in to comment.