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

Support simulations #10

Closed
larry0x opened this issue Jun 21, 2023 · 2 comments · Fixed by #15
Closed

Support simulations #10

larry0x opened this issue Jun 21, 2023 · 2 comments · Fixed by #15

Comments

@larry0x
Copy link
Owner

larry0x commented Jun 21, 2023

Currently the Ante/PostHandler don't support simulations, meaning we can't estimate gas if a tx is initiated by an AbstractAccount. We should implement proper simulation.

NOTE: we have to register relevant types in legacy amino codec, because a certain sdk AnteHandler involved in the simulation still uses amino: https://github.com/cosmos/cosmos-sdk/blob/v0.47.2/x/auth/ante/basic.go#L124-L130

Additionally, we need a custom authcmd.GetSimulationCmd method (see: cosmos/cosmos-sdk#16887)

@larry0x
Copy link
Owner Author

larry0x commented Jul 7, 2023

A few possible designs to the sudo API:

Design 1

Introduce two new methods: BeforeTxSim and AfterTxSim

enum SudoMsg {
    BeforeTx {
        msgs: Vec<Any>,
        tx_bytes: Binary,
        credential: Binary,
    },
    BeforeTxSim {
        msgs: Vec<Any>,
        tx_bytes: Binary,
        // the credential isn't provided in simulation mode
    },
    AfterTx {},
    AfterTxSim {},
}

Design 2

Make credential optional (None in simulation mode), and add a new simulation field indicating whether it's simulation mode:

enum SudoMsg {
    BeforeTx {
        msgs: Vec<Any>,
        tx_bytes: Binary,
        // None if the tx is being run in the simulation mode
        credential: Option<Binary>,
        // whether the tx is being run in the simulation mode
        simulation: bool,
    },
    AfterTx {
        simulation: bool,
    },
}

Design 3

Define a new Credential type as follows:

enum Credential {
    Bytes(Binary),
    Simulation,
}

enum SudoMsg {
    BeforeTx {
        msgs: Vec<Any>,
        tx_bytes: Binary,
        credential: Credential,
    },
    AfterTx {
        simulation: bool,
    },
}

@larry0x
Copy link
Owner Author

larry0x commented Jul 7, 2023

going with option 2

option 2 seems the best considering that we can allow the credential to be None even if not in simulation mode:

larry_0x, [8 Jul 2023 at 01:14:58]:
we can imagine uses cases where an account may not need a credential. for example, an account that anyone can use to send a tx, but only once an hour. something like this
some interesting game mechanics can perhaps be built this way

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

Successfully merging a pull request may close this issue.

1 participant