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: Make a simulation context struct #9443

Closed
4 tasks
ValarDragon opened this issue Jun 2, 2021 · 2 comments
Closed
4 tasks

Simulation: Make a simulation context struct #9443

ValarDragon opened this issue Jun 2, 2021 · 2 comments

Comments

@ValarDragon
Copy link
Contributor

ValarDragon commented Jun 2, 2021

Summary

Many of the parameters to functions within simulation could be neatly packaged into a single simulation context struct.

I propose making a simulation Context struct as follows:

struct SimulationContext {
  R *rand.Rand,
  SdkCtx sdk.Context,
  App *baseapp.BaseApp,
  Accs []simtypes.Account, 
  sender simtypes.Account,
}

This would allow removing many function arguments from operations.

SimulationContext should then have a method called GetSender() which then chooses a sender for the tx, and caches it internally to make repeated calls within an operation return the same address.

This allows for deduplicating the simAccount, _ := simtypes.RandomAcc(r, accs) in ~every simulated operation.

The Operation type would then simplify from

type Operation func(r *rand.Rand, app *baseapp.BaseApp,
	ctx sdk.Context, accounts []Account, chainID string) (
	OperationMsg OperationMsg, futureOps []FutureOperation, err error)

to

type Operation func(ctx SimulationContext) (
	OperationMsg OperationMsg, futureOps []FutureOperation, err error)

Similarly

type ContentSimulatorFn func(r *rand.Rand, ctx sdk.Context, accs []Account) Content

simplifies to

type ContentSimulatorFn func(ctx SimulationContext) Content

Problem Definition

Help mitigate Simulation code bloat, and improve readability


For Admin Use

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

Why is there a github-actions bot that automatically closes this issue?

@ValarDragon ValarDragon reopened this Jul 25, 2021
@tac0turtle
Copy link
Member

there was an update to the action and now its acting on issues while previously it wasnt.

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

No branches or pull requests

2 participants