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

fix(cosmos): ensure simulated transactions can't trigger SwingSet #3740

Merged
merged 1 commit into from
Aug 21, 2021

Conversation

michaelfig
Copy link
Member

@michaelfig michaelfig commented Aug 21, 2021

Closes #3739

The former pattern of vm.IsSimulation was too brittle to handle
our migration to the GRPC-based transaction handlers. Instead,
intercept the actual invocation of CallToController and prevent
it from running anything in SwingSet if in simulation mode.

Also, make sure our InfiniteGasMeter is only assigned once, so
that if we ever do Cosmos-level metering of SwingSet downcalls,
there is only one place to adjust.

@michaelfig michaelfig added the cosmic-swingset package: cosmic-swingset label Aug 21, 2021
@michaelfig michaelfig self-assigned this Aug 21, 2021
The former pattern of `vm.IsSimulation` was too brittle to handle
our migration to the GRPC-based transaction handlers.  Instead,
intercept the actual invocation of CallToController and prevent
it from running anything in SwingSet if in simulation mode.

Also, make sure our InfiniteGasMeter is only assigned once, so
that if we ever do Cosmos-level metering of SwingSet downcalls,
there is only one place to adjust.
Copy link
Member

@dckc dckc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wild.

I browsed the changes. If it's important to have this approved soon: Which are the key parts and which are just knock-on effects?

Copy link
Member

@dckc dckc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for testing it.

@michaelfig michaelfig merged commit b43df5a into master Aug 21, 2021
@michaelfig michaelfig deleted the mfig-3739-simulated-txes branch August 21, 2021 05:47
michaelfig added a commit that referenced this pull request Aug 21, 2021
fix(cosmos): ensure simulated transactions can't trigger SwingSet
@@ -23,7 +23,7 @@ func NewStorageHandler(keeper Keeper) storageHandler {
return storageHandler{keeper: keeper}
}

func (sh storageHandler) Receive(ctx *vm.ControllerContext, str string) (ret string, err error) {
func (sh storageHandler) Receive(cctx *vm.ControllerContext, str string) (ret string, err error) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've been using ctlCtx, e.g. in vbank_test.go, so we should use one of the two names consistently (I don't care which). Might save some clutter below by extracting ctx := ctlCtx.Context at the top.

callToController := func(ctx sdk.Context, str, simReturn string) (string, error) {
if vm.IsSimulation(ctx) {
// Just return the simReturn, since the message is being simulated.
return simReturn, nil
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It sure looks like simReturn is always the empty string. If so, you can avoid the extra arg to callToController and avoid a lot of changes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cosmic-swingset package: cosmic-swingset
Projects
None yet
Development

Successfully merging this pull request may close these issues.

consensus failure in testnet4.5 on RPC node peer-2 at block 9292
3 participants