Skip to content

Commit

Permalink
fix: stmgr: only apply tipset messages for CallWithGas
Browse files Browse the repository at this point in the history
  • Loading branch information
Stebalien committed Feb 10, 2023
1 parent 80ff4bd commit 72946f5
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions chain/stmgr/call.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,12 @@ func (sm *StateManager) Call(ctx context.Context, msg *types.Message, ts *types.
msg.Value = types.NewInt(0)
}

return sm.callInternal(ctx, msg, nil, ts, cid.Undef, sm.GetNetworkVersion, false)
return sm.callInternal(ctx, msg, nil, ts, cid.Undef, sm.GetNetworkVersion, false, false)
}

// CallWithGas calculates the state for a given tipset, and then applies the given message on top of that state.
func (sm *StateManager) CallWithGas(ctx context.Context, msg *types.Message, priorMsgs []types.ChainMsg, ts *types.TipSet) (*api.InvocResult, error) {
return sm.callInternal(ctx, msg, priorMsgs, ts, cid.Undef, sm.GetNetworkVersion, true)
return sm.callInternal(ctx, msg, priorMsgs, ts, cid.Undef, sm.GetNetworkVersion, true, true)
}

// CallAtStateAndVersion allows you to specify a message to execute on the given stateCid and network version.
Expand All @@ -61,13 +61,13 @@ func (sm *StateManager) CallAtStateAndVersion(ctx context.Context, msg *types.Me
return v
}

return sm.callInternal(ctx, msg, nil, nil, stateCid, nvGetter, true)
return sm.callInternal(ctx, msg, nil, nil, stateCid, nvGetter, true, false)
}

// - If no tipset is specified, the first tipset without an expensive migration or one in its parent is used.
// - If executing a message at a given tipset or its parent would trigger an expensive migration, the call will
// fail with ErrExpensiveFork.
func (sm *StateManager) callInternal(ctx context.Context, msg *types.Message, priorMsgs []types.ChainMsg, ts *types.TipSet, stateCid cid.Cid, nvGetter rand.NetworkVersionGetter, checkGas bool) (*api.InvocResult, error) {
func (sm *StateManager) callInternal(ctx context.Context, msg *types.Message, priorMsgs []types.ChainMsg, ts *types.TipSet, stateCid cid.Cid, nvGetter rand.NetworkVersionGetter, checkGas, applyTsMessages bool) (*api.InvocResult, error) {
ctx, span := trace.StartSpan(ctx, "statemanager.callInternal")
defer span.End()

Expand Down Expand Up @@ -112,6 +112,8 @@ func (sm *StateManager) callInternal(ctx context.Context, msg *types.Message, pr
// don't want to apply miner messages after cron runs in a given epoch.
if stateCid == cid.Undef {
stateCid = ts.ParentState()
}
if applyTsMessages {
tsMsgs, err := sm.cs.MessagesForTipset(ctx, ts)
if err != nil {
return nil, xerrors.Errorf("failed to lookup messages for parent tipset: %w", err)
Expand Down

0 comments on commit 72946f5

Please sign in to comment.