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

Events of the same type are collapsed into one event #8419

Closed
4 tasks
ethanfrey opened this issue Jan 22, 2021 · 4 comments
Closed
4 tasks

Events of the same type are collapsed into one event #8419

ethanfrey opened this issue Jan 22, 2021 · 4 comments

Comments

@ethanfrey
Copy link
Contributor

Summary of Bug

I realized how critical a functioning event system is to the future of the Cosmos, when I realized that parsing events is the only way a relayer can get the needed info to transfer packets between chains. I was wondering how robust this was, so I tested out a simpler example - x/bank send.

I created a simple "subkeys" contract in wasm and then triggered 3 bank.Send() calls in the same message. 1 sendings 4 MAYO into the contract, and then informing the contract to send 1.6666 MAYO to A and 2.33333 MAYO to B. I expected to see 3 different events, that could be easily parsed. What I got was this (look at the transfer event... it is 3 different bank sends collapsed into 1 event)

wasmd query tx 94E935BE53D65B090B1595C8DECE5363A19F85B6F770883EA96BC1A3449EC3F4 --node https://rpc.musselnet.cosmwasm.com:443 -o json | jq .logs

[
  {
    "msg_index": 0,
    "log": "",
    "events": [
      {
        "type": "message",
        "attributes": [
          {
            "key": "action",
            "value": "execute"
          },
          {
            "key": "module",
            "value": "wasm"
          },
          {
            "key": "signer",
            "value": "wasm1eldfm7jktevnscwr6prdravd8yuq7j87q6d9vx"
          },
          {
            "key": "contract_address",
            "value": "wasm178muner9x4shrdnu9xjnurlgd4qkul9t9pupcp"
          }
        ]
      },
      {
        "type": "transfer",
        "attributes": [
          {
            "key": "recipient",
            "value": "wasm178muner9x4shrdnu9xjnurlgd4qkul9t9pupcp"
          },
          {
            "key": "sender",
            "value": "wasm1eldfm7jktevnscwr6prdravd8yuq7j87q6d9vx"
          },
          {
            "key": "amount",
            "value": "4000000umayo"
          },
          {
            "key": "recipient",
            "value": "wasm1c9489dfpgpual8gwpd85xfc2tnwl6qsx8d0j80"
          },
          {
            "key": "sender",
            "value": "wasm178muner9x4shrdnu9xjnurlgd4qkul9t9pupcp"
          },
          {
            "key": "amount",
            "value": "1666666umayo"
          },
          {
            "key": "recipient",
            "value": "wasm1df43m7ag36twfxm998yakxp4dw74gvludpsxx0"
          },
          {
            "key": "sender",
            "value": "wasm178muner9x4shrdnu9xjnurlgd4qkul9t9pupcp"
          },
          {
            "key": "amount",
            "value": "2333333umayo"
          }
        ]
      },
      {
        "type": "wasm",
        "attributes": [
          {
            "key": "contract_address",
            "value": "wasm178muner9x4shrdnu9xjnurlgd4qkul9t9pupcp"
          },
          {
            "key": "action",
            "value": "execute"
          },
          {
            "key": "owner",
            "value": "wasm1eldfm7jktevnscwr6prdravd8yuq7j87q6d9vx"
          }
        ]
      }
    ]
  }
]

Version

v0.40.1

Steps to Reproduce

Note, I am not sure if the bug is in baseapp or in tendermint. When I test the handler, this returns 3 transfer events (and the wasm event).

You should probably build wasmd from here first: https://github.com/CosmWasm/wasmd/
Here is the script I used to generate the test case, but you can also just look at those logs.

# config
NODE="--node https://rpc.musselnet.cosmwasm.com:443"
TXFLAG="$NODE --chain-id musselnet-2 --gas-prices 0.01umayo --from events"

# set up account with tokens
wasmd keys add events
ADDR=$(wasmd keys show -a events)
echo $ADDR

curl --header "Content-Type: application/json" \
  --request POST \
  --data "{\"denom\":\"umayo\",\"address\":\"$ADDR\"}" \
  https://faucet.musselnet.cosmwasm.com/credit

wasmd query bank balances $ADDR $NODE

# Note, the subkeys contract is already uploaded, create one
CODE_ID=1
read -r -d '' INIT_MSG << EOM
{
    "admins": ["$ADDR"],
    "mutable": false
}
EOM

wasmd tx wasm instantiate $CODE_ID "$INIT_MSG" --label "Event Test 1" --admin $ADDR $TXFLAG --gas 200000 -y

CONTRACT=TODO-PLACE-CONTRACT-ADDRESS-OF-LAST-STEP-HERE

wasmd query wasm contract $CONTRACT $NODE
wasmd query wasm contract-state smart $CONTRACT '{"admin_list":{}}' $NODE

# now, let's send some tokens and send them out again
wasmd keys add rcpt1
RCPT1=$(wasmd keys show -a rcpt1)
wasmd keys add rcpt2
RCPT2=$(wasmd keys show -a rcpt2)

read -r -d '' EXEC_MSG << EOM
{
    "execute": {
        "msgs": [
            {
                "bank": {
                    "send": {
                        "from_address": "$CONTRACT",
                        "to_address": "$RCPT1",
                        "amount": [{
                            "denom": "umayo",
                            "amount": "1666666"
                        }]
                    }
                }
            },
            {
                "bank": {
                    "send": {
                        "from_address": "$CONTRACT",
                        "to_address": "$RCPT2",
                        "amount": [{
                            "denom": "umayo",
                            "amount": "2333333"
                        }]
                    }
                }
            }
        ]
    }
}
EOM

wasmd query bank balances $ADDR $NODE
wasmd query bank balances $CONTRACT $NODE


# we sent 1.666 and 2.333 mayo out, we need to send 4 mayo in
wasmd tx wasm execute $CONTRACT "$EXEC_MSG" --amount 4000000umayo $TXFLAG --gas 400000 -y | jq .

For Admin Use

  • Not duplicate issue
  • Appropriate labels applied
  • Appropriate contributors tagged
  • Contributor assigned/self-assigned
@ethanfrey
Copy link
Contributor Author

This demo is with wasmd, but this affects any sdk app that emits 2 events of the same type. As soon as someone decides to send to ibc packets from on user message, this will break the relayer. It will also affect native modules dispatches.

@colin-axner
Copy link
Contributor

I think this is a related issue I opened a while back. I remember there being someway to make this less painful. I tried documenting things here as well. I believe typed events should make this a lot better?

@ethanfrey
Copy link
Contributor Author

ethanfrey commented Jan 25, 2021

I don't think TypedEvents help here, they turn into normal abci.Events when hitting the Tendermint/ABCI boundary.

It seems this mangling is done in Tendermint then? With the ResultEvent:

type ResultEvent struct {
	Query  string              `json:"query"`
	Data   types.TMEventData   `json:"data"`
	Events map[string][]string `json:"events"`
}

It looks like that is the collapsing phase. I guess I need to move the issue there or commend more on your issue

@tac0turtle
Copy link
Member

this has been fixed on the Tendermint side. Once there is a new release with the new tendermint this will be solved in the sdk. Closing this issue

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

No branches or pull requests

3 participants