cosmos / cosmos-sdk

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

send multiple msgs in one block for one account #5595

Closed Xuefeng-Zhu closed 4 years ago

Xuefeng-Zhu commented 4 years ago

I have the use case that one account needs to sends multiple msgs in one block. Currently, If one account sends the msgs in separate transactions, they will result in errors because of account seqNum. However, when I include all msgs in one transaction, if one msg results in an error, the whole transaction will fail. I wonder if there is a way to send multiple msgs in one block for one account

alexanderbez commented 4 years ago

However, when I include all msgs in one transaction, if one msg results in an error, the whole transaction will fail.

Currently, this is the only way. Your best bet is to make sure all messages in the tx are valid. We're potentially looking into ways of allowing multiple txs sequentially, but it's not a priority atm.

Xuefeng-Zhu commented 4 years ago

@alexanderbez Thank you for the response. I wonder if there is a way to do the precommit check like ethereum?

alexanderbez commented 4 years ago

Maybe you can try the --dry-run option first before broadcasting?

Xuefeng-Zhu commented 4 years ago

@alexanderbez Thank you for the quick response.

So if I do it in code

    cliCtx := client.
        NewCLIContext().
        WithCodec(cdc).
        WithFromAddress(key.GetAddress()).
        WithFromName(key.GetName()).
        WithNodeURI(nodeURI).
        WithTrustNode(true).
        WithBroadcastMode(flags.BroadcastSync).
                 WithSimulate(true)

         cliCtx.BroadcastTx(txBytes)        

The transaction will only run locally instead of broadcasting to the network?

Xuefeng-Zhu commented 4 years ago

It seems that dry run will only estimate the gas whenever the msg will succeed or not.

alexanderbez commented 4 years ago

You'd have to run simulation, yes. That should let you know that CheckTx passes.

Xuefeng-Zhu commented 4 years ago

@alexanderbez Is there sample code to do it? I used CompleteAndBroadcastTxCLI from https://github.com/cosmos/cosmos-sdk/blob/master/x/auth/client/tx.go#L48, but it will not return err when the tx fails

ahmedaly113 commented 4 years ago

which cosmos sdk version was used here?

ahmedaly113 commented 4 years ago

Sending multiple transactions in v0.35.0 was working by using offline signer but it's not working on v0.38.3. Please share what's happening if someone experience similar issue.

github-actions[bot] commented 4 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.