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

Fail to decode raw Pay For Data Tx #1265

Closed
4 tasks
xiaying-peng opened this issue Jan 19, 2023 · 9 comments
Closed
4 tasks

Fail to decode raw Pay For Data Tx #1265

xiaying-peng opened this issue Jan 19, 2023 · 9 comments
Labels
bug Something isn't working

Comments

@xiaying-peng
Copy link

xiaying-peng commented Jan 19, 2023

Summary of Bug

Unable to decode Pay For Data transaction using the standard CosmosSDK way

Version

29b84d8

Steps to Reproduce

I tried using the following code to decode the tx:

encCfg := encoding.MakeConfig(app.ModuleEncodingRegisters...) 
for _, rawTx := range b.Data.Txs { 
    sdkTx, err := encCfg.TxConfig.TxDecoder()(rawTx) 
    if err != nil { return err }

but got error:

expected 2 wire type, got 0: tx parse error [celestiaorg/[email protected]/x/auth/tx/decoder.go:21]

Example: https://rpc-mocha.pops.one/block?height=199687

"data": {
        "txs": [
          "CiBsaebmNmMGH/oqyFSQKZE31Qa8+cuzpP3+jxDuGPPS3hKqAgp8CnoKFi9wYXltZW50Lk1zZ1BheUZvckRhdGESYAovY2VsZXN0aWExcmE3dTN1NjI0NXQ2Mzl1ejUzc3RodWZya3J2dDlyMnlqbW5qY3cSCG9dtlaZ+E6HGJQDIiBjeUD36dUpKiBzyDqhOdjhKdL1mt02UpA0+e2nagKAChJoClEKRgofL2Nvc21vcy5jcnlwdG8uc2VjcDI1NmsxLlB1YktleRIjCiEDI+p1TghEsBXS24cHxNIV7kJBx0FCqj2neR2Kc1ziMCMSBAoCCAEYklgSEwoMCgR1dGlhEgQ2MDAwEICb7gIaQDt5laDXsx0TdSb8gSf49ujTRDktrysSeGelAw/l+q2nU1GToXE9O/y2o4rfQ17yryuFJ/VyML/yTVizAKnHRsMYAg==",
          "CiCGJ5oCbc9K8gUlhAlJjA39v5Y3nsGv57/q+qgjCU3XUhKpAgp8CnoKFi9wYXltZW50Lk1zZ1BheUZvckRhdGESYAovY2VsZXN0aWExcHlqNnlzdzI3bTJ1NGE3NDRtaHJuOXU5cWg2Y2E5ZDI4eWVwaG4SCPwuN2oIl+o/GJQDIiBlfXOx5XDFwCKWqylinahhcxN5W4W1XVON49G3lG86URJnClAKRgofL2Nvc21vcy5jcnlwdG8uc2VjcDI1NmsxLlB1YktleRIjCiEDCqv9ioKle4mSUz1R/cw/P0pcpYEMFpRZKnUT/XI9+QQSBAoCCAEYMhITCgwKBHV0aWESBDYwMDAQgJvuAhpAwI4LcqPuXHciSSQNMDh3k/2Bm76FqJLujQ+rtYW99DMk/OF30yvrnsA7AnQo4DfGq7jRKvnLMAtp8GYlEEIjVBgD"
        ],

For Admin Use

  • Not duplicate issue
  • Appropriate labels applied
  • Appropriate contributors tagged
  • Contributor assigned/self-assigned
@xiaying-peng xiaying-peng added the bug Something isn't working label Jan 19, 2023
@xiaying-peng xiaying-peng changed the title Fail to decode raw Tx Fail to decode raw Pay For Data Tx Jan 19, 2023
@xiaying-peng
Copy link
Author

cc @rootulp Any quick suggestions?

@evan-forbes
Copy link
Member

@xiaying-peng apologies for not documenting this well enough, this is something that we are working on in #1257.

The transactions that contain MsgPayForBlobs are wrapped with some important metadata. To get rid of this data, we use this

func IndexWrapperDecoder(dec sdk.TxDecoder) sdk.TxDecoder {

so

encCfg := encoding.MakeConfig(app.ModuleEncodingRegisters...) 
for _, rawTx := range b.Data.Txs { 
    sdkTx, err := encoding.IndexWrapperDecoder(encCfg.TxConfig.TxDecoder())(rawTx) 

@evan-forbes
Copy link
Member

also kinda related to #485

@xiaying-peng
Copy link
Author

Hi @evan-forbes , I tried the same code, but still same error:

        encCfg := encoding.MakeConfig(app.ModuleEncodingRegisters...) 
	dec := encoding.IndexWrapperDecoder(encCfg.TxConfig.TxDecoder())
	tx, err := dec(rawTx)
	if err != nil {
		fmt.Println(err)
		return nil, nil
	}

@xiaying-peng
Copy link
Author

The reason I want to decode the tx because I want to get FeePayer and Fee for a given tx.
However, I found txs_results's events contain the fee as coin_receive, and coin_spent events.
Example here:

"txs_results": [
      {
        "code": 0,
        "data": "EiAKHi9wYXltZW50Lk1zZ1BheUZvckRhdGFSZXNwb25zZQ==",
        "log": "[{\"msg_index\":0,\"events\":[{\"type\":\"message\",\"attributes\":[{\"key\":\"action\",\"value\":\"/payment.MsgPayForData\"}]},{\"type\":\"payfordata\",\"attributes\":[{\"key\":\"signer\",\"value\":\"celestia1vdjkcetnw35kzvtjvymh2vm4xcergdt5xcenjat6x5ehxargw4n8y6mjwe6rju3j094x6mn2vdms9mxgrp\"},{\"key\":\"size\",\"value\":\"404\"}]}]}]",
        "info": "",
        "gas_wanted": "6000000",
        "gas_used": "61894",
        "events": [
          {
            "type": "coin_spent",
            "attributes": [
              {
                "key": "c3BlbmRlcg==",
                "value": "Y2VsZXN0aWExcmE3dTN1NjI0NXQ2Mzl1ejUzc3RodWZya3J2dDlyMnlqbW5qY3c=",
                "index": true
              },
              {
                "key": "YW1vdW50",
                "value": "NjAwMHV0aWE=",
                "index": true
              }
            ]
          },
          {
            "type": "coin_received",
            "attributes": [
              {
                "key": "cmVjZWl2ZXI=",
                "value": "Y2VsZXN0aWExN3hwZnZha20yYW1nOTYyeWxzNmY4NHoza2VsbDhjNWxwbmpzM3M=",
                "index": true
              },
              {
                "key": "YW1vdW50",
                "value": "NjAwMHV0aWE=",
                "index": true
              }
            ]
          },

This is a little bit different than other Cosmos based chains, since other Chain's events does not contain Fee debit and credit.

@evan-forbes
Copy link
Member

evan-forbes commented Jan 20, 2023

mocha is using v0.11.1, so we can't actually use the version listed in the issue. That is likely the case, but I'll check myself in a second

@evan-forbes
Copy link
Member

Yeah, using v0.11.1, this test works as expected

func TestExample(t *testing.T) {
	txs := []string{
		"CiBsaebmNmMGH/oqyFSQKZE31Qa8+cuzpP3+jxDuGPPS3hKqAgp8CnoKFi9wYXltZW50Lk1zZ1BheUZvckRhdGESYAovY2VsZXN0aWExcmE3dTN1NjI0NXQ2Mzl1ejUzc3RodWZya3J2dDlyMnlqbW5qY3cSCG9dtlaZ+E6HGJQDIiBjeUD36dUpKiBzyDqhOdjhKdL1mt02UpA0+e2nagKAChJoClEKRgofL2Nvc21vcy5jcnlwdG8uc2VjcDI1NmsxLlB1YktleRIjCiEDI+p1TghEsBXS24cHxNIV7kJBx0FCqj2neR2Kc1ziMCMSBAoCCAEYklgSEwoMCgR1dGlhEgQ2MDAwEICb7gIaQDt5laDXsx0TdSb8gSf49ujTRDktrysSeGelAw/l+q2nU1GToXE9O/y2o4rfQ17yryuFJ/VyML/yTVizAKnHRsMYAg==",
		"CiCGJ5oCbc9K8gUlhAlJjA39v5Y3nsGv57/q+qgjCU3XUhKpAgp8CnoKFi9wYXltZW50Lk1zZ1BheUZvckRhdGESYAovY2VsZXN0aWExcHlqNnlzdzI3bTJ1NGE3NDRtaHJuOXU5cWg2Y2E5ZDI4eWVwaG4SCPwuN2oIl+o/GJQDIiBlfXOx5XDFwCKWqylinahhcxN5W4W1XVON49G3lG86URJnClAKRgofL2Nvc21vcy5jcnlwdG8uc2VjcDI1NmsxLlB1YktleRIjCiEDCqv9ioKle4mSUz1R/cw/P0pcpYEMFpRZKnUT/XI9+QQSBAoCCAEYMhITCgwKBHV0aWESBDYwMDAQgJvuAhpAwI4LcqPuXHciSSQNMDh3k/2Bm76FqJLujQ+rtYW99DMk/OF30yvrnsA7AnQo4DfGq7jRKvnLMAtp8GYlEEIjVBgD",
	}
	encCfg := encoding.MakeConfig(app.ModuleEncodingRegisters...)
	for _, tx := range txs {
		rawTx, err := base64.StdEncoding.DecodeString(tx)
		require.NoError(t, err)
		sdkTx, err := encoding.MalleatedTxDecoder(encCfg.TxConfig.TxDecoder())(rawTx)
		require.NoError(t, err)
		for _, msg := range sdkTx.GetMsgs() {
			fmt.Println(sdk.MsgTypeURL(msg))
		}
	}
}

@evan-forbes
Copy link
Member

@xiaying-peng please close this issue after confirming 🙂

sorry I didn't notice the version at first glance!

@xiaying-peng
Copy link
Author

Ah, Thank you! It works!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants