-
Notifications
You must be signed in to change notification settings - Fork 351
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
Add transaction index to Env #1077
Conversation
The problem is that I think the tx index is not exposed in Cosmos SDK. Maybe @alpe knows more, but we need to make sure it is feasible to support without forking the SDK. sigh btw, I like the idea... if it is possible. It would help differentiating between multiple tx in the same block when ordering. |
I love it! A few notes:
IMO |
Looking at https://github.com/CosmWasm/wasmd/blob/v0.18.0/proto/cosmwasm/wasm/v1/types.proto#L123-L131 and https://github.com/CosmWasm/wasmd/blob/v0.18.0/x/wasm/types/types.go#L206-L222 it seems you are right and we do not get a simple counter. |
Messages do not have to be executed as part of a transaction. They can for example be executed in BeginBlocker or EndBlocker. |
Good eye. And the use of "GasConsumed" as a monotonic counter is actually quite useful. It also works when 3 messages are called in part of the same transaction. It is actually a quite clever way to order the various calls, and I could see the usage already in eg. snapshotting for voting contracts (with only block height, this is a bit course) However, it may not provide @assafmo with what he wants to uniquely identify the transaction in the block. |
Yeah, the gas meter is nice for ordering but not helpful when used together with external tooling. E.g. it would be nice to be able to find a transation (10985258, 0) or (10985258, 3) by simply looking at a tool like this: https://www.mintscan.io/cosmos/blocks/id/10985258 |
@ethanfrey that's even better, we can distinguish between contract calls. I'm not really sure if that's necessary but it's pretty cool. |
🤔 I have not found any information about the use case this patch should handle. The "gas based position" would just be an incrementing counter with random steps. Can you not achieve the same in the contract itself with a counter per block? |
The original motivation is somewhere in a private chat, sorry. The contract should have the option of accurately describing when an event happened. A proposed solution was to expose the transaction hash. If we do that, we have to expose block hash as well for consistentcy. And we know once we expose those hashes, people use them for bad RNGs.
The contract can only know how often per block height it was called. This can solve some of the problem but makes it very hard to use in combination with other tooling. Something like the 3rd contract call on height 6484654 barely allows you to find the transaction in a explorer or other client. It also requires costy storage writes.
It would be amazing if we could implement that. |
The wasmd counter part is CosmWasm/wasmd#601. Alex says he can make it happen 🧙 |
02407fd
to
45ef88c
Compare
Please note that a simple counter that says "this is the third time the contract was called in this block" is problematic for the following reasons:
|
Also, I think you should not be concerned by misusing txhash for creating random numbers. Professional devs wouldn't do it, and if a dev is unaware of how problematic it is to get random numbers in blockchain then nothing will help them. 🤷 |
I was thinking in that direction as well alredy. However, for the sake of consistency we should either expose both block hash and tx hash or none of the two. |
Then I vote for exposing both of them. Call counter - I think it'll just be confusing and ugly in |
I was gonna say that it's useful for when the same contract gets called twice in the same TX - then you can imagine a scenario where a contract sends funds to multiple accounts in one tx from its own (or someone else's) balance. But then if all events are registered in an internal event log, even if they are all registered with the same txhash, then you can still see the order of events inside the tx just by the order in which events were registered. |
Okay, I don't think that's very interesting, but I get it. Also, you can have multiple messages in the same tx, so is the counter resets for every message? I'd argue that you have to add more context for that (E.g. |
Yeah, I agree with that. |
I am getting confused. The original discussion was about the TX index in Env. Is this still relevant or does this not work for you? A TX can have multiple messages though. |
block hash + tx hash is a different story and I think we should keep it out of here. Maybe we do it, maybe not. Let's go with tx index for now. |
Feel free to continue the block hash/tx hash discussion in #1086. |
dbceb6b
to
e42379f
Compare
This came up in chat recently. With the transaction index we have a global tx identifier
(block height, transaction index)
that avoids exposing transaction hash.Exposing block hash and transaction hash is not desired since people will use those for poor RNGs.