Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Transaction index in Env is always None #932

Closed
ninkisa opened this issue Aug 9, 2022 · 8 comments · Fixed by #984
Closed

Transaction index in Env is always None #932

ninkisa opened this issue Aug 9, 2022 · 8 comments · Fixed by #984
Milestone

Comments

@ninkisa
Copy link

ninkisa commented Aug 9, 2022

Hi,

I am trying to get information about the current transaction from an execute message with env.transaction.index on our local chain, but it always returns None.
The custom AnteHandler is set with wasmkeeper.NewCountTXDecorator (same as here: #621 (comment)), but still env.transaction is None

Reproduced it with local wasmd node and against the Malaga testnet and the demo nameservice contract from https://github.com/InterWasm/cw-contracts
Steps to reproduce:

  • In the demo namespace conctract add to ExecuteMsg::Register action
let tx_idx = env.transaction.expect("No transaction"); 
Ok(Response::default().add_attribute("idx", tx_idx.index.to_string()))`
  • Call the demo contract with
REGISTER='{"register":{"name":"fred"}}' 
wasmd tx wasm execute $CONTRACT "$REGISTER" --amount 100umlg --from wallet $TXFLAG -y

env.transaction is None and code will panic

wasmd version 0.27.0
cosmwasm version 1.0.0

Any help will be appreciated!
Best regards,
Nina

@ninkisa ninkisa changed the title Transaction index in Env is aways None Transaction index in Env is always None Aug 9, 2022
@ethanfrey ethanfrey added this to the v0.29.0 milestone Aug 15, 2022
@ethanfrey
Copy link
Member

I have added it to the next milestone to investigate.

If you can make a (failing) Go testcase as a PR, that would raise this up in priority, but in any case, it should be in the next release

@alpe
Copy link
Contributor

alpe commented Aug 25, 2022

I can confirm this issue. When I was debugging the env is serialized into :

{
  "block": {
    "height": 61,
    "time": "1661435276327602000",
    "chain_id": "testing"
  },
  "contract": {
    "address": "wasm14hj2tavq8fpesdwxxcu44rty3hh90vhujrvcmstl4zr3txmfvw9s0phg4d"
  },
  "transaction_info": {
    "index": 0
  }
}

in the VM execute.
Also see Go env

As I understand the Rust Env type, it expects the transaction_info to be nested in a "transaction" element

@webmaster128
Copy link
Member

In the Rust type, the field is called transaction and the type is TransactionInfo. The Option is serialized as null or the object. So it should look like this:

  "transaction": {
    "index": 0
  }

or

  "transaction": null

The json:"transaction_info,omitempty" part in wasmvm seems like a bug to me.

@webmaster128
Copy link
Member

This is now tracked in CosmWasm/wasmvm#341, which is the repo that contains the bug. Feel free to close here. There issue will disapear with any wasmd containing wasmvm 1.1.0+.

@webmaster128
Copy link
Member

Patch is here: CosmWasm/wasmvm#345

@alpe
Copy link
Contributor

alpe commented Aug 31, 2022

I would keep this open if there is a chance to write an end to end test for this. Do we have an example contract already, that I can use for this to return the env data to the caller?

@webmaster128
Copy link
Member

Yeah, test contract "cyberpunk" with MirrorEnv execute and query message is there. Have a look at the Go test in the PR. You can copy it over to this repo but I don't think it would test more than what we test already.

@alpe
Copy link
Contributor

alpe commented Sep 1, 2022

The test in wasmvm is fine and covering all that is needed for an end to end scenario. Thanks! 🏄
All that is left to do is the wasmvm upgrade.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants