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

Simulation: Proper Operation (Message) Execution #4935

Closed
4 tasks
alexanderbez opened this issue Aug 21, 2019 · 4 comments · Fixed by #4946
Closed
4 tasks

Simulation: Proper Operation (Message) Execution #4935

alexanderbez opened this issue Aug 21, 2019 · 4 comments · Fixed by #4946

Comments

@alexanderbez
Copy link
Contributor

alexanderbez commented Aug 21, 2019

Problem

The BaseApp mechanics are vital to transaction execution and understanding state transitions in the state machine of an application.

The simulation test suite operates fundamentally by generating a series of "operations" (messages in a tx) per block and executes them via a "block simulator". These operations are defined on a per-module basis.

However, and I'm not sure if this was intended when simulation was first implemented, (cc @cwgoes ) but some of these operations bypass the BaseApp entirely. In other words, they generate a sdk.Msg, create a cached Context and execute the respective module's handler...essentially mimicking BaseApp to a degree.

e.g.

// x/staking/simulation/operations/msgs.go

msg := staking.NewMsgBeginRedelegate(
	delegatorAddress, srcValidatorAddress, destValidatorAddress, sdk.NewCoin(denom, amount),
)
if msg.ValidateBasic() != nil {
	return simulation.NoOpMsg(staking.ModuleName), nil, fmt.Errorf("expected msg to pass ValidateBasic: %s", msg.GetSignBytes())
}

ctx, write := ctx.CacheContext()
ok := handler(ctx, msg).IsOK()
if ok {
	write()
}

opMsg = simulation.NewOperationMsg(msg, ok, "")
return opMsg, nil, nil

To my understanding, this can be dangerous as we're not testing the true state machine execution paths. e.g. I spent a few hours debugging why some of my changes to BaseApp weren't getting reflected in simulation and as a result were failing.

Proposal

Module operation generators should instead create a tx with the message and rely on the BaseApp that's already provided to them:

e.g.

res := app.Deliver(tx)
if !res.IsOK() {
	// ...
}

// ...

For Admin Use

  • Not duplicate issue
  • Appropriate labels applied
  • Appropriate contributors tagged
  • Contributor assigned/self-assigned
@alexanderbez
Copy link
Contributor Author

If there was a reason we intentionally did this, please lmk @cwgoes 👍

@cwgoes
Copy link
Contributor

cwgoes commented Aug 21, 2019

As far as I can recall, this happened because we originally tried to have both module-specific simulations and whole-app simulations, and we wanted to share code between them.

If the former is no longer necessary switching to the app logic directly seems fine to me.

@alexanderbez
Copy link
Contributor Author

Thanks for confirming @cwgoes!

@jackzampolin
Copy link
Member

Module specific simulations would be a really nice feature.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants