Skip to content

Commit

Permalink
fix: stmgr: make the tipset and height agree when estimating gas
Browse files Browse the repository at this point in the history
Specifically re-execute all messages in the current tipset, tacking the new
message onto the end. That way, the epoch is the epoch of the current tipset.

We could try to "make" a fake block and use that, but that's unlikely to
work well.
  • Loading branch information
Stebalien committed Feb 8, 2023
1 parent da2bb41 commit c0f83f2
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 18 deletions.
28 changes: 11 additions & 17 deletions chain/stmgr/call.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,22 +107,16 @@ func (sm *StateManager) callInternal(ctx context.Context, msg *types.Message, pr
}
}

var vmHeight abi.ChainEpoch
if checkGas {
// Since we're simulating a future message, pretend we're applying it in the "next" tipset
vmHeight = ts.Height() + 1
if stateCid == cid.Undef {
stateCid, _, err = sm.TipSetState(ctx, ts)
if err != nil {
return nil, xerrors.Errorf("computing tipset state: %w", err)
}
}
} else {
// If we're not checking gas, we don't want to have to execute the tipset like above. This saves a lot of computation time
vmHeight = pts.Height() + 1
if stateCid == cid.Undef {
stateCid = ts.ParentState()
// Unless executing on a specific state cid, apply all the messages from the current tipset
// first. Unfortunately, we can't just execute the tipset, because that will run cron. We
// don't want to apply miner messages after cron runs in a given epoch.
if stateCid == cid.Undef {
stateCid = ts.ParentState()
tsMsgs, err := sm.cs.MessagesForTipset(ctx, ts)
if err != nil {
return nil, xerrors.Errorf("failed to lookup messages for parent tipset: %w", err)
}
priorMsgs = append(tsMsgs, priorMsgs...)
}

// Technically, the tipset we're passing in here should be ts+1, but that may not exist.
Expand All @@ -142,14 +136,14 @@ func (sm *StateManager) callInternal(ctx context.Context, msg *types.Message, pr
buffStore := blockstore.NewTieredBstore(sm.cs.StateBlockstore(), blockstore.NewMemorySync())
vmopt := &vm.VMOpts{
StateBase: stateCid,
Epoch: vmHeight,
Epoch: ts.Height(),
Timestamp: ts.MinTimestamp(),
Rand: rand.NewStateRand(sm.cs, ts.Cids(), sm.beacon, nvGetter),
Bstore: buffStore,
Actors: sm.tsExec.NewActorRegistry(),
Syscalls: sm.Syscalls,
CircSupplyCalc: sm.GetVMCirculatingSupply,
NetworkVersion: nvGetter(ctx, vmHeight),
NetworkVersion: nvGetter(ctx, ts.Height()),
BaseFee: ts.Blocks()[0].ParentBaseFee,
LookbackState: LookbackStateGetterForTipset(sm, ts),
TipSetGetter: TipSetGetterForTipset(sm.cs, ts),
Expand Down
2 changes: 1 addition & 1 deletion itests/wdpost_dispute_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ func TestWindowPostDispute(t *testing.T) {
//stm: @CHAIN_STATE_MINER_CALCULATE_DEADLINE_001
di, err = client.StateMinerProvingDeadline(ctx, evilMinerAddr, types.EmptyTSK)
require.NoError(t, err)
if di.Index == evilSectorLoc.Deadline && di.CurrentEpoch-di.PeriodStart > 1 {
if di.Index == evilSectorLoc.Deadline && di.CurrentEpoch-di.PeriodStart > 2 {
break
}
build.Clock.Sleep(blocktime)
Expand Down

0 comments on commit c0f83f2

Please sign in to comment.