cosmos / cosmos-sdk

:chains: A Framework for Building High Value Public Blockchains :sparkles:
https://cosmos.network/
Apache License 2.0
6.22k stars 3.59k forks source link

Enblocker tx activity's balance incorrect when querying. #12244

Closed yj0x0x closed 2 years ago

yj0x0x commented 2 years ago

Summary of Bug

Already published issue on gaia repo : https://github.com/cosmos/gaia/issues/1518

Already published issue on the liquidity repo : https://github.com/Gravity-Devs/liquidity/issues/17

TL DR ; Rosetta API got the enblocker hash block height 8695158. Tx hash is the 002D9BEECFD46E4B35339D47166B7D0CE6F357DFA54AF3EBD1854ACC33A4D4CFB0.

But when I seen the operations , account cosmos1tx68a8k9yz54z06qfve9l2zxvgsz4ka3hr8962 spent uatom without balance.

Version

Gaia v6.0.4 Cosmos sdk version 0.44.6 Liquidity version : 1.4.6

Steps to Reproduce

Query to the cosmos node which turn on the Rosetta API.

curl -X POST  -H "Content-type: application/json" http://localhost:8080/block -d '{"network_identifier": {"blockchain": "app","network": "network"},"block_identifier": {"index": 8695158}}'

then searched tx 002D9BEECFD46E4B35339D47166B7D0CE6F357DFA54AF3EBD1854ACC33A4D4CFB0. As a result you can see the below operation.

                {
                        "operation_identifier": {
                            "index": 2
                        },
                        "type": "coin_spent",
                        "status": "Success",
                        "account": {
                            "address": "cosmos1tx68a8k9yz54z06qfve9l2zxvgsz4ka3hr8962"
                        },
                        "amount": {
                            "value": "-24770",
                            "currency": {
                                "symbol": "uatom",
                                "decimals": 0
                            }
                        }
                    },

Also can check account cosmos1tx68a8k9yz54z06qfve9l2zxvgsz4ka3hr8962 balance through rest api like below.

curl -X GET -H "Content-Type: application/json" -H "x-cosmos-block-height: 8695158" http://localhost:1317/cosmos/bank/v1beta1/balances/cosmos1tx68a8k9yz54z06qfve9l2zxvgsz4ka3hr8962

 result ; 

 {
    "balances": [],
    "pagination": {
        "next_key": null,
        "total": "0"
    }
}

 curl -X GET -H "Content-Type: application/json" -H "x-cosmos-block-height: 8695157" http://localhost:1317/cosmos/bank/v1beta1/balances/cosmos1tx68a8k9yz54z06qfve9l2zxvgsz4ka3hr8962

 {
    "balances": [],
    "pagination": {
        "next_key": null,
        "total": "0"
    }
}

For Admin Use

alexanderbez commented 2 years ago

Are you saying for tx 002D9BEECFD46E4B35339D47166B7D0CE6F357DFA54AF3EBD1854ACC33A4D4CFB0, account cosmos1tx68a8k9yz54z06qfve9l2zxvgsz4ka3hr8962 spent coins but prior to that tx, the account never had any balance?

yj0x0x commented 2 years ago

yes.

alexanderbez commented 2 years ago

Ok, so

  1. 2D9BEECFD46E4B35339D47166B7D0CE6F357DFA54AF3EBD1854ACC33A4D4CFB0 is the block hash, not a tx hash.
  2. It looks like that account only tried a few (failed) txs: https://www.mintscan.io/cosmos/account/cosmos1tx68a8k9yz54z06qfve9l2zxvgsz4ka3hr8962

Can you please post the tx hash in question?

yj0x0x commented 2 years ago

OK. I will let you know more precise explain about this ASAP.

yj0x0x commented 2 years ago

@alexanderbez Hello.

First of all, Let's see the return format of the Rosetta API. below are source code.

// In rosetta all state transitions must be represented as transactions
// since in tendermint begin block and end block are state transitions
// which are not represented as transactions we mock only the balance changes
// happening at those levels as transactions. (check BeginBlockTxHash for more info)
const (
    DeliverTxSize       = sha256.Size
    BeginEndBlockTxSize = DeliverTxSize + 1
    EndBlockHashStart   = 0x0
    BeginBlockHashStart = 0x1
)

ref : https://github.com/cosmos/cosmos-sdk/blob/9fd866e3820b3510010ae172b682d71594cd8c14/server/rosetta/types.go#L15-L24

So Transaction hash that I mentioned, 002D9BEECFD46E4B35339D47166B7D0CE6F357DFA54AF3EBD1854ACC33A4D4CFB0 is the end blocker hash.

And let's see the Rosetta API returns of block, 2D9BEECFD46E4B35339D47166B7D0CE6F357DFA54AF3EBD1854ACC33A4D4CFB0`

Continue...

yj0x0x commented 2 years ago

And this zip file is the original return of block 2D9BEECFD46E4B35339D471 66B7D0CE6F357DFA54AF3EBD1854ACC33A4D4CFB0 's return. Please check it.

block-8695158-rosetta-api-result.json.zip

@alexanderbez

yj0x0x commented 2 years ago

Issue is that account cosmos1tx68a8k9yz54z06qfve9l2zxvgsz4ka3hr8962 didn't have any asset on that block height, 8695158 like below.

curl -X GET -H "Content-Type: application/json" -H "x-cosmos-block-height: 8695158" http://localhost:1317/cosmos/bank/v1beta1/balances/cosmos1tx68a8k9yz54z06qfve9l2zxvgsz4ka3hr8962

 result ; 

 {
    "balances": [],
    "pagination": {
        "next_key": null,
        "total": "0"
    }
}

 curl -X GET -H "Content-Type: application/json" -H "x-cosmos-block-height: 8695157" http://localhost:1317/cosmos/bank/v1beta1/balances/cosmos1tx68a8k9yz54z06qfve9l2zxvgsz4ka3hr8962

 {
    "balances": [],
    "pagination": {
        "next_key": null,
        "total": "0"
    }
}

How this can be possible?

yj0x0x commented 2 years ago

My node setup like below.

6.0.4
Node is archive node to set up config pruning nothing.
This node sync from v4.2.1 which block height started 5200791 .
yj0x0x commented 2 years ago

@alexanderbez Hello. Have you ever checked above ??

alexanderbez commented 2 years ago

@yj0x0x I'm sorry, but the data and info you've posted has made this issue way too verbose for me to really follow effectively. I would suggest deleting the verbose comments and only posting what's needed for the relevant issue. IIRC, I just needed to know the tx hash.

yj0x0x commented 2 years ago

OK. I will remove too much info about data.

Tx hash is the 002D9BEECFD46E4B35339D47166B7D0CE6F357DFA54AF3EBD1854ACC33A4D4CFB0.

This TX is the Endblocker Transaction as I mentioned and only can get through the Rosetta API request.

If you query this transaction through CLI or /cosmos/tx/v1beta1/txs/{hash} endpoint, you won't be able to get it.

Because this transaction is the ENDBLOCKER TRANSACTION. as I mentioned.

Please check .

alexanderbez commented 2 years ago

EndBlocker execution doesn't have tx hashes. The hash you posted is a block hash, not a tx hash. In order to help, I need to know the tx hash.

yj0x0x commented 2 years ago

Then This block 2D9BEECFD46E4B35339D47166B7D0CE6F357DFA54AF3EBD1854ACC33A4D4CFB0's Endblocker execution which identified 002D9BEECFD46E4B35339D47166B7D0CE6F357DFA54AF3EBD1854ACC33A4D4CFB0. has wrong operations.

In case of this, Do I need to open another issue?

yj0x0x commented 2 years ago

Or Could you please explain to me that endblocker execution can be wrong??

alexanderbez commented 2 years ago

I'm not sure what you mean by EndBlocker execution can be wrong? What defines being "wrong" here?

See my original comment here: https://github.com/cosmos/cosmos-sdk/issues/12244#issuecomment-1155350896

I need to know what height to query this account at to see if it had funds.

yj0x0x commented 2 years ago

Hi @alexanderbez .

Here is the query that I did for checking account cosmos1tx68a8k9yz54z06qfve9l2zxvgsz4ka3hr8962 's balance.

curl -X GET -H "Content-Type: application/json" -H "x-cosmos-block-height: 8695158" http://localhost:1317/cosmos/bank/v1beta1/balances/cosmos1tx68a8k9yz54z06qfve9l2zxvgsz4ka3hr8962

 result ; 

 {
    "balances": [],
    "pagination": {
        "next_key": null,
        "total": "0"
    }
}

 curl -X GET -H "Content-Type: application/json" -H "x-cosmos-block-height: 8695157" http://localhost:1317/cosmos/bank/v1beta1/balances/cosmos1tx68a8k9yz54z06qfve9l2zxvgsz4ka3hr8962

 {
    "balances": [],
    "pagination": {
        "next_key": null,
        "total": "0"
    }
}

Why I said Endblocker execution was wronged, Cause account cosmos1tx68a8k9yz54z06qfve9l2zxvgsz4ka3hr8962 didn't have any balance at height 8695157.

You have to be able to see account cosmos1tx68a8k9yz54z06qfve9l2zxvgsz4ka3hr8962 has endblocker execution activities through the below rosetta api query.

curl -X POST  -H "Content-type: application/json" http://localhost:8080/block -d '{"network_identifier": {"blockchain": "app","network": "network"},"block_identifier": {"index": 8695158}}'
alexanderbez commented 2 years ago

Ahh 8695158 is a block height prior to the last upgrade -- Theta. So querying against a current node won't return you any data. See this discussion: https://github.com/cosmos/cosmos-sdk/discussions/9740

There are archive nodes of previous versions. If you query against the v6 version, you'll find the state/balance of this account.

I know @jackzampolin has some archive nodes up and running of previous hub versions.

yj0x0x commented 2 years ago

As I mentioned here (https://github.com/cosmos/cosmos-sdk/issues/12244#issuecomment-1160520624) , Node version is 6.0.4, Which is Vega.

I had set up my node to prevent syncing progress because of want to resolve this issue.

So this query is for the in the Vega era not Theta.

alexanderbez commented 2 years ago

Do you have a node I can use?

yj0x0x commented 2 years ago

I can't open node to external. Please understand it. Cosmos team doesn't have node that test this issue?

Or you can check this result that I left. https://github.com/cosmos/cosmos-sdk/issues/12244#issuecomment-1160513475

This zip file is the rosetta api return which is block height 8695158.

alexanderbez commented 2 years ago

There really isn't a "cosmos team", we're a distributed set of entities all working towards a collective aim. There are archive nodes that exist. I will find one and query against and see what's up ;-)

yj0x0x commented 2 years ago

Thank you so much.

yj0x0x commented 2 years ago

@alexanderbez Can I ask you how is it going to check on your side?

alexanderbez commented 2 years ago

I'm sorry but I have not been able to find a Vega archive node to query against. I've asked in a few places.

yj0x0x commented 2 years ago

@alexanderbez Thank you for letting me know.

alexanderbez commented 2 years ago

I was able to query against an archival node. I do see it has no balance at 8695157 nor does it have any balance as of now. The only thing I can think of is that it received funds during EndBlock execution and later sent them.

yj0x0x commented 2 years ago

Thank you. Now we are almost same page. Thing is account cosmos1tx68a8k9yz54z06qfve9l2zxvgsz4ka3hr8962 didn't have any balance at 8695158 block height & 8695157 too.

But block height 8695158's Endblock execution has balance change activity like below.

            {
                "transaction_identifier": {
                    "hash": "002D9BEECFD46E4B35339D47166B7D0CE6F357DFA54AF3EBD1854ACC33A4D4CFB0"
                },
                "operations": [
                    {
                        "operation_identifier": {
                            "index": 0
                        },
                        "type": "coin_received",
                        "status": "Success",
                        "account": {
                            "address": "cosmos1tx68a8k9yz54z06qfve9l2zxvgsz4ka3hr8962"
                        },
                        "amount": {
                            "value": "24",
                            "currency": {
                                "symbol": "pool32DD066BE949E5FDCC7DC09EBB67C7301D0CA957C2EF56A39B37430165447DAC",
                                "decimals": 0
                            }
                        }
                    },
                    {
                        "operation_identifier": {
                            "index": 1
                        },
                        "type": "coin_spent",
                        "status": "Success",
                        "account": {
                            "address": "cosmos1tx68a8k9yz54z06qfve9l2zxvgsz4ka3hr8962"
                        },
                        "amount": {
                            "value": "-356604",
                            "currency": {
                                "symbol": "ibc/2181AAB0218EAC24BC9F86BD1364FBBFA3E6E3FCC25E88E3E68C15DC6E752D86",
                                "decimals": 0
                            }
                        }
                    },
                    {
                        "operation_identifier": {
                            "index": 2
                        },
                        "type": "coin_spent",
                        "status": "Success",
                        "account": {
                            "address": "cosmos1tx68a8k9yz54z06qfve9l2zxvgsz4ka3hr8962"
                        },
                        "amount": {
                            "value": "-24770",
                            "currency": {
                                "symbol": "uatom",
                                "decimals": 0
                            }
                        }
                    },
                    {
                        "operation_identifier": {
                            "index": 3
                        },
                        "type": "coin_spent",
                        "status": "Success",
                        "account": {
                            "address": "cosmos1tx68a8k9yz54z06qfve9l2zxvgsz4ka3hr8962"
                        },
                        "amount": {
                            "value": "-11160745",
                            "currency": {
                                "symbol": "ibc/2181AAB0218EAC24BC9F86BD1364FBBFA3E6E3FCC25E88E3E68C15DC6E752D86",
                                "decimals": 0
                            }
                        }
                    },
                    {
                        "operation_identifier": {
                            "index": 4
                        },
                        "type": "coin_spent",
                        "status": "Success",
                        "account": {
                            "address": "cosmos1tx68a8k9yz54z06qfve9l2zxvgsz4ka3hr8962"
                        },
                        "amount": {
                            "value": "-775230",
                            "currency": {
                                "symbol": "uatom",
                                "decimals": 0
                            }
                        }
                    },
                    {
                        "operation_identifier": {
                            "index": 5
                        },
                        "type": "coin_spent",
                        "status": "Success",
                        "account": {
                            "address": "cosmos1tx68a8k9yz54z06qfve9l2zxvgsz4ka3hr8962"
                        },
                        "amount": {
                            "value": "-24",
                            "currency": {
                                "symbol": "pool32DD066BE949E5FDCC7DC09EBB67C7301D0CA957C2EF56A39B37430165447DAC",
                                "decimals": 0
                            }
                        }
                    },
                    {
                        "operation_identifier": {
                            "index": 6
                        },
                        "type": "coin_received",
                        "status": "Success",
                        "account": {
                            "address": "cosmos13s0lj78gujy89vn9780gq6qn4v937ywjasyw2q"
                        },
                        "amount": {
                            "value": "356604",
                            "currency": {
                                "symbol": "ibc/2181AAB0218EAC24BC9F86BD1364FBBFA3E6E3FCC25E88E3E68C15DC6E752D86",
                                "decimals": 0
                            }
                        }
                    },
                    {
                        "operation_identifier": {
                            "index": 7
                        },
                        "type": "coin_received",
                        "status": "Success",
                        "account": {
                            "address": "cosmos13s0lj78gujy89vn9780gq6qn4v937ywjasyw2q"
                        },
                        "amount": {
                            "value": "24770",
                            "currency": {
                                "symbol": "uatom",
                                "decimals": 0
                            }
                        }
                    },
                    {
                        "operation_identifier": {
                            "index": 8
                        },
                        "type": "coin_received",
                        "status": "Success",
                        "account": {
                            "address": "cosmos1xtwsv6lff8jlmnracz0tke78xqwse22h4sez9u"
                        },
                        "amount": {
                            "value": "11160745",
                            "currency": {
                                "symbol": "ibc/2181AAB0218EAC24BC9F86BD1364FBBFA3E6E3FCC25E88E3E68C15DC6E752D86",
                                "decimals": 0
                            }
                        }
                    },
                    {
                        "operation_identifier": {
                            "index": 9
                        },
                        "type": "coin_received",
                        "status": "Success",
                        "account": {
                            "address": "cosmos1xtwsv6lff8jlmnracz0tke78xqwse22h4sez9u"
                        },
                        "amount": {
                            "value": "775230",
                            "currency": {
                                "symbol": "uatom",
                                "decimals": 0
                            }
                        }
                    },
                    {
                        "operation_identifier": {
                            "index": 10
                        },
                        "type": "coin_received",
                        "status": "Success",
                        "account": {
                            "address": "cosmos13s0lj78gujy89vn9780gq6qn4v937ywjasyw2q"
                        },
                        "amount": {
                            "value": "24",
                            "currency": {
                                "symbol": "pool32DD066BE949E5FDCC7DC09EBB67C7301D0CA957C2EF56A39B37430165447DAC",
                                "decimals": 0
                            }
                        }
                    }

Isn't it strange that account cosmos1tx68a8k9yz54z06qfve9l2zxvgsz4ka3hr8962 had balance change execution?

alexanderbez commented 2 years ago

That's because cosmos1tx68a8k9yz54z06qfve9l2zxvgsz4ka3hr8962 is a module account.

yj0x0x commented 2 years ago

What is the module account? If you don't mind, Can I ask your explanation?

yj0x0x commented 2 years ago

Or if you provided me some link about module account, would be appreciated.

alexanderbez commented 2 years ago

Look at the account https://www.mintscan.io/cosmos/account/cosmos1tx68a8k9yz54z06qfve9l2zxvgsz4ka3hr8962

You'll see there a few failed txs where someone tried to send funds to do it. You'll see cosmos1tx68a8k9yz54z06qfve9l2zxvgsz4ka3hr8962 is not allowed to receive funds: unauthorized. This means the account is a module account -- i.e. an account that's managed internally by state.

alexanderbez commented 2 years ago

There really isn't a doc on it -- they're fairly a straightforward concept:

module accounts: basically any accounts which cannot sign transactions and which are managed internally by modules