bug: Simulation is not deterministic due to GenSignedMockTx #12373
Closed
Description
opened on Jun 28, 2022
Summary of Bug
The simulation is not deterministic because we use a standalone random generator in GenSignedMockTx
:
func GenSignedMockTx(gen client.TxConfig, msgs []sdk.Msg, feeAmt sdk.Coins, gas uint64, chainID string, accNums, accSeqs []uint64, priv ...cryptotypes.PrivKey) (sdk.Tx, error) {
sigs := make([]signing.SignatureV2, len(priv))
// create a random length memo
r := rand.New(rand.NewSource(time.Now().UnixNano()))
memo := simulation.RandStringOfLength(r, simulation.RandIntBetween(r, 0, 100))
...
}
This random generator use a different random seed from the simState.Rand
, while GenSignedMockTx
is widely used in x/{module}/operations.go
to generate sdk.Tx
.
This means even with the same random seed, the simulation could generate txs with different length of memo.
Therefore, ConsumeTxSizeGasMiddleware
could consume different gas while executing the tx, which leads to non-deterministic appHash.
Version
master@450cd7fc8708ccb0fa21f05e251d9804a2063b79
release/v0.45.x
Steps to Reproduce
- change `NumBlocks` to 1 in Makefile `test-sim-nondeterminism` section.
- make test-sim-nondeterminism.
- test failed.
For Admin Use
- Not duplicate issue
- Appropriate labels applied
- Appropriate contributors tagged
- Contributor assigned/self-assigned
Metadata
Assignees
Labels
No labels
Activity