Skip to content

Commit d830e23

Browse files
committed
feat(stmgr): CallWithStore to collect new post-Call state
1 parent 75bcc6e commit d830e23

File tree

1 file changed

+28
-11
lines changed

1 file changed

+28
-11
lines changed

chain/stmgr/call.go

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,14 @@ var ErrExpensiveFork = errors.New("refusing explicit call due to state fork at e
3939
// tipset's parent. In the presence of null blocks, the height at which the message is invoked may
4040
// be less than the specified tipset.
4141
func (sm *StateManager) Call(ctx context.Context, msg *types.Message, ts *types.TipSet) (*api.InvocResult, error) {
42+
buffStore := blockstore.NewTieredBstore(sm.cs.StateBlockstore(), blockstore.NewMemorySync())
43+
return sm.CallWithStore(ctx, msg, ts, buffStore)
44+
}
45+
46+
// CallWithStore applies the given message to the given tipset's parent state, at the epoch following the
47+
// tipset's parent. In the presence of null blocks, the height at which the message is invoked may
48+
// be less than the specified tipset.
49+
func (sm *StateManager) CallWithStore(ctx context.Context, msg *types.Message, ts *types.TipSet, bstore blockstore.Blockstore) (*api.InvocResult, error) {
4250
// Copy the message as we modify it below.
4351
msgCopy := *msg
4452
msg = &msgCopy
@@ -55,13 +63,13 @@ func (sm *StateManager) Call(ctx context.Context, msg *types.Message, ts *types.
5563
if msg.Value == types.EmptyInt {
5664
msg.Value = types.NewInt(0)
5765
}
58-
59-
return sm.callInternal(ctx, msg, nil, ts, cid.Undef, sm.GetNetworkVersion, false, execSameSenderMessages)
66+
return sm.callInternal(ctx, msg, nil, ts, cid.Undef, sm.GetNetworkVersion, false, execSameSenderMessages, bstore)
6067
}
6168

6269
// ApplyOnStateWithGas applies the given message on top of the given state root with gas tracing enabled
6370
func (sm *StateManager) ApplyOnStateWithGas(ctx context.Context, stateCid cid.Cid, msg *types.Message, ts *types.TipSet) (*api.InvocResult, error) {
64-
return sm.callInternal(ctx, msg, nil, ts, stateCid, sm.GetNetworkVersion, true, execNoMessages)
71+
buffStore := blockstore.NewTieredBstore(sm.cs.StateBlockstore(), blockstore.NewMemorySync())
72+
return sm.callInternal(ctx, msg, nil, ts, stateCid, sm.GetNetworkVersion, true, execNoMessages, buffStore)
6573
}
6674

6775
// CallWithGas calculates the state for a given tipset, and then applies the given message on top of that state.
@@ -72,8 +80,8 @@ func (sm *StateManager) CallWithGas(ctx context.Context, msg *types.Message, pri
7280
} else {
7381
strategy = execSameSenderMessages
7482
}
75-
76-
return sm.callInternal(ctx, msg, priorMsgs, ts, cid.Undef, sm.GetNetworkVersion, true, strategy)
83+
buffStore := blockstore.NewTieredBstore(sm.cs.StateBlockstore(), blockstore.NewMemorySync())
84+
return sm.callInternal(ctx, msg, priorMsgs, ts, cid.Undef, sm.GetNetworkVersion, true, strategy, buffStore)
7785
}
7886

7987
// CallAtStateAndVersion allows you to specify a message to execute on the given stateCid and network version.
@@ -84,14 +92,24 @@ func (sm *StateManager) CallAtStateAndVersion(ctx context.Context, msg *types.Me
8492
nvGetter := func(context.Context, abi.ChainEpoch) network.Version {
8593
return v
8694
}
87-
return sm.callInternal(ctx, msg, nil, nil, stateCid, nvGetter, true, execSameSenderMessages)
95+
buffStore := blockstore.NewTieredBstore(sm.cs.StateBlockstore(), blockstore.NewMemorySync())
96+
return sm.callInternal(ctx, msg, nil, nil, stateCid, nvGetter, true, execSameSenderMessages, buffStore)
8897
}
8998

9099
// - If no tipset is specified, the first tipset without an expensive migration or one in its parent is used.
91100
// - If executing a message at a given tipset or its parent would trigger an expensive migration, the call will
92101
// fail with ErrExpensiveFork.
93-
func (sm *StateManager) callInternal(ctx context.Context, msg *types.Message, priorMsgs []types.ChainMsg, ts *types.TipSet, stateCid cid.Cid,
94-
nvGetter rand.NetworkVersionGetter, checkGas bool, strategy execMessageStrategy) (*api.InvocResult, error) {
102+
func (sm *StateManager) callInternal(
103+
ctx context.Context,
104+
msg *types.Message,
105+
priorMsgs []types.ChainMsg,
106+
ts *types.TipSet,
107+
stateCid cid.Cid,
108+
nvGetter rand.NetworkVersionGetter,
109+
checkGas bool,
110+
strategy execMessageStrategy,
111+
bstore blockstore.Blockstore,
112+
) (*api.InvocResult, error) {
95113
ctx, span := trace.StartSpan(ctx, "statemanager.callInternal")
96114
defer span.End()
97115

@@ -151,13 +169,12 @@ func (sm *StateManager) callInternal(ctx context.Context, msg *types.Message, pr
151169
)
152170
}
153171

154-
buffStore := blockstore.NewTieredBstore(sm.cs.StateBlockstore(), blockstore.NewMemorySync())
155172
vmopt := &vm.VMOpts{
156173
StateBase: stateCid,
157174
Epoch: ts.Height(),
158175
Timestamp: ts.MinTimestamp(),
159176
Rand: rand.NewStateRand(sm.cs, ts.Cids(), sm.beacon, nvGetter),
160-
Bstore: buffStore,
177+
Bstore: bstore,
161178
Actors: sm.tsExec.NewActorRegistry(),
162179
Syscalls: sm.Syscalls,
163180
CircSupplyCalc: sm.GetVMCirculatingSupply,
@@ -207,7 +224,7 @@ func (sm *StateManager) callInternal(ctx context.Context, msg *types.Message, pr
207224
}
208225
}
209226

210-
stTree, err := state.LoadStateTree(cbor.NewCborStore(buffStore), stateCid)
227+
stTree, err := state.LoadStateTree(cbor.NewCborStore(bstore), stateCid)
211228
if err != nil {
212229
return nil, xerrors.Errorf("loading state tree: %w", err)
213230
}

0 commit comments

Comments
 (0)