Support simulations
Closed this issue · 2 comments
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)
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,
},
}
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