Skip to content

Commit e91b3b2

Browse files
committed
s/DumpCache/FlushAllBlocks option
1 parent d830e23 commit e91b3b2

File tree

8 files changed

+86
-27
lines changed

8 files changed

+86
-27
lines changed

api/api_full.go

Lines changed: 67 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88

99
blocks "github.com/ipfs/go-block-format"
1010
"github.com/ipfs/go-cid"
11+
"golang.org/x/xerrors"
1112

1213
"github.com/filecoin-project/go-address"
1314
"github.com/filecoin-project/go-bitfield"
@@ -385,7 +386,7 @@ type FullNode interface {
385386
// StateCall applies the message to the tipset's parent state. The
386387
// message is not applied on-top-of the messages in the passed-in
387388
// tipset.
388-
StateCall(context.Context, *types.Message, types.TipSetKey) (*InvocResult, error) //perm:read
389+
StateCall(ctx context.Context, p StateCallParams) (*InvocResult, error) //perm:read
389390
// StateReplay replays a given message, assuming it was included in a block in the specified tipset.
390391
//
391392
// If a tipset key is provided, and a replacing message is not found on chain,
@@ -1270,7 +1271,12 @@ type InvocResult struct {
12701271
ExecutionTrace types.ExecutionTrace
12711272
Error string
12721273
Duration time.Duration
1273-
CachedBlocks []Block `json:",omitempty"`
1274+
Blocks *InvocBlocks `json:",omitempty"`
1275+
}
1276+
1277+
type InvocBlocks struct {
1278+
Root cid.Cid
1279+
Blocks []Block
12741280
}
12751281

12761282
type Block struct {
@@ -1475,3 +1481,62 @@ type EthTxReceipt struct {
14751481
Logs []ethtypes.EthLog `json:"logs"`
14761482
Type ethtypes.EthUint64 `json:"type"`
14771483
}
1484+
1485+
type StateCallParams struct {
1486+
Message *types.Message `json:"message"`
1487+
TipSetKey types.TipSetKey `json:"tipsetKey"`
1488+
IncludeBlocks bool `json:"includeBlocks,omitempty"`
1489+
}
1490+
1491+
func (e *StateCallParams) ToArg() jsonrpc.RawParams {
1492+
b, err := json.Marshal(e)
1493+
if err != nil {
1494+
return nil
1495+
}
1496+
return jsonrpc.RawParams(b)
1497+
}
1498+
1499+
func (e *StateCallParams) UnmarshalJSON(b []byte) error {
1500+
if len(b) == 0 {
1501+
return xerrors.New("empty input")
1502+
}
1503+
1504+
// If input is an object, decode it directly into a temporary struct
1505+
if b[0] == '{' {
1506+
type stateCallParamsAlias StateCallParams
1507+
var alias stateCallParamsAlias
1508+
if err := json.Unmarshal(b, &alias); err != nil {
1509+
return err
1510+
}
1511+
*e = StateCallParams(alias)
1512+
return nil
1513+
}
1514+
1515+
// If input is an array, expect exactly two elements: Message and TipSetKey
1516+
if b[0] == '[' {
1517+
var params []json.RawMessage
1518+
if err := json.Unmarshal(b, &params); err != nil {
1519+
return err
1520+
}
1521+
if len(params) != 2 {
1522+
return xerrors.Errorf("expected two parameters, got %d", len(params))
1523+
}
1524+
if err := json.Unmarshal(params[0], &e.Message); err != nil {
1525+
return xerrors.Errorf("failed to unmarshal message: %w", err)
1526+
}
1527+
if err := json.Unmarshal(params[1], &e.TipSetKey); err != nil {
1528+
return xerrors.Errorf("failed to unmarshal tipset key: %w", err)
1529+
}
1530+
return nil
1531+
}
1532+
1533+
return xerrors.Errorf("unexpected JSON input: expected object or array, got %q", string(b[0]))
1534+
}
1535+
1536+
func (e *StateCallParams) MarshalJSON() ([]byte, error) {
1537+
return json.Marshal(map[string]interface{}{
1538+
"message": e.Message,
1539+
"tipsetKey": e.TipSetKey,
1540+
"includeBlocks": e.IncludeBlocks,
1541+
})
1542+
}

chain/consensus/compute_state.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,10 +245,12 @@ func (t *TipSetExecutor) ApplyBlocks(
245245
if err := em.MessageApplied(ctx, ts, cm.Cid(), m, r, false); err != nil {
246246
log.Debugw("ApplyBlocks ExecMonitor#MessageApplied callback failed", "error", err)
247247
if cacheStore != nil {
248+
/* TODO:
248249
log.Debug("Dumping vm cache blocks to provided cacheStore")
249250
if err := vmi.DumpCache(cacheStore); err != nil {
250251
return cid.Undef, cid.Undef, xerrors.Errorf("dumping vm cache: %w", err)
251252
}
253+
*/
252254
}
253255
return cid.Undef, cid.Undef, err
254256
}
@@ -307,10 +309,12 @@ func (t *TipSetExecutor) ApplyBlocks(
307309
}
308310

309311
if cacheStore != nil {
312+
/* TODO:
310313
log.Debug("Dumping vm cache blocks to provided cacheStore")
311314
if err := vmi.DumpCache(cacheStore); err != nil {
312315
return cid.Undef, cid.Undef, xerrors.Errorf("dumping vm cache: %w", err)
313316
}
317+
*/
314318
}
315319

316320
st, err := vmi.Flush(ctx)

chain/stmgr/call.go

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,15 @@ var ErrExpensiveFork = errors.New("refusing explicit call due to state fork at e
3838
// Call applies the given message to the given tipset's parent state, at the epoch following the
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.
41-
func (sm *StateManager) Call(ctx context.Context, msg *types.Message, ts *types.TipSet) (*api.InvocResult, error) {
41+
func (sm *StateManager) Call(ctx context.Context, msg *types.Message, ts *types.TipSet, flushAllBlocks bool) (*api.InvocResult, error) {
4242
buffStore := blockstore.NewTieredBstore(sm.cs.StateBlockstore(), blockstore.NewMemorySync())
43-
return sm.CallWithStore(ctx, msg, ts, buffStore)
43+
return sm.CallWithStore(ctx, msg, ts, buffStore, flushAllBlocks)
4444
}
4545

4646
// CallWithStore applies the given message to the given tipset's parent state, at the epoch following the
4747
// tipset's parent. In the presence of null blocks, the height at which the message is invoked may
4848
// 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) {
49+
func (sm *StateManager) CallWithStore(ctx context.Context, msg *types.Message, ts *types.TipSet, bstore blockstore.Blockstore, flushAllBlocks bool) (*api.InvocResult, error) {
5050
// Copy the message as we modify it below.
5151
msgCopy := *msg
5252
msg = &msgCopy
@@ -63,13 +63,13 @@ func (sm *StateManager) CallWithStore(ctx context.Context, msg *types.Message, t
6363
if msg.Value == types.EmptyInt {
6464
msg.Value = types.NewInt(0)
6565
}
66-
return sm.callInternal(ctx, msg, nil, ts, cid.Undef, sm.GetNetworkVersion, false, execSameSenderMessages, bstore)
66+
return sm.callInternal(ctx, msg, nil, ts, cid.Undef, sm.GetNetworkVersion, false, execSameSenderMessages, bstore, flushAllBlocks)
6767
}
6868

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

7575
// CallWithGas calculates the state for a given tipset, and then applies the given message on top of that state.
@@ -81,7 +81,7 @@ func (sm *StateManager) CallWithGas(ctx context.Context, msg *types.Message, pri
8181
strategy = execSameSenderMessages
8282
}
8383
buffStore := blockstore.NewTieredBstore(sm.cs.StateBlockstore(), blockstore.NewMemorySync())
84-
return sm.callInternal(ctx, msg, priorMsgs, ts, cid.Undef, sm.GetNetworkVersion, true, strategy, buffStore)
84+
return sm.callInternal(ctx, msg, priorMsgs, ts, cid.Undef, sm.GetNetworkVersion, true, strategy, buffStore, false)
8585
}
8686

8787
// CallAtStateAndVersion allows you to specify a message to execute on the given stateCid and network version.
@@ -93,7 +93,7 @@ func (sm *StateManager) CallAtStateAndVersion(ctx context.Context, msg *types.Me
9393
return v
9494
}
9595
buffStore := blockstore.NewTieredBstore(sm.cs.StateBlockstore(), blockstore.NewMemorySync())
96-
return sm.callInternal(ctx, msg, nil, nil, stateCid, nvGetter, true, execSameSenderMessages, buffStore)
96+
return sm.callInternal(ctx, msg, nil, nil, stateCid, nvGetter, true, execSameSenderMessages, buffStore, false)
9797
}
9898

9999
// - If no tipset is specified, the first tipset without an expensive migration or one in its parent is used.
@@ -109,6 +109,7 @@ func (sm *StateManager) callInternal(
109109
checkGas bool,
110110
strategy execMessageStrategy,
111111
bstore blockstore.Blockstore,
112+
flushAllBlocks bool,
112113
) (*api.InvocResult, error) {
113114
ctx, span := trace.StartSpan(ctx, "statemanager.callInternal")
114115
defer span.End()
@@ -183,6 +184,7 @@ func (sm *StateManager) callInternal(
183184
LookbackState: LookbackStateGetterForTipset(sm, ts),
184185
TipSetGetter: TipSetGetterForTipset(sm.cs, ts),
185186
Tracing: true,
187+
FlushAllBlocks: flushAllBlocks,
186188
}
187189
vmi, err := sm.newVM(ctx, vmopt)
188190
if err != nil {

chain/vm/execution.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import (
1010
"go.opencensus.io/stats"
1111
"go.opencensus.io/tag"
1212

13-
"github.com/filecoin-project/lotus/blockstore"
1413
"github.com/filecoin-project/lotus/chain/types"
1514
"github.com/filecoin-project/lotus/metrics"
1615
)
@@ -59,10 +58,6 @@ func (e *vmExecutor) Flush(ctx context.Context) (cid.Cid, error) {
5958
return e.vmi.Flush(ctx)
6059
}
6160

62-
func (e *vmExecutor) DumpCache(bs blockstore.Blockstore) error {
63-
return e.vmi.DumpCache(bs)
64-
}
65-
6661
type executionToken struct {
6762
lane ExecutionLane
6863
reserved int

chain/vm/fvm.go

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -538,10 +538,6 @@ func (vm *FVM) Flush(ctx context.Context) (cid.Cid, error) {
538538
return vm.fvm.Flush()
539539
}
540540

541-
func (vm *FVM) DumpCache(cacheStore blockstore.Blockstore) error {
542-
return vm.fvm.DumpCache(cacheStore)
543-
}
544-
545541
type dualExecutionFVM struct {
546542
main *FVM
547543
debug *FVM
@@ -612,10 +608,6 @@ func (vm *dualExecutionFVM) Flush(ctx context.Context) (cid.Cid, error) {
612608
return vm.main.Flush(ctx)
613609
}
614610

615-
func (vm *dualExecutionFVM) DumpCache(cacheStore blockstore.Blockstore) error {
616-
return vm.main.DumpCache(cacheStore)
617-
}
618-
619611
// Passing this as a pointer of structs has proven to be an enormous PiTA; hence this code.
620612
type xRedirect struct{ from, to cid.Cid }
621613
type xMapping struct{ redirects []xRedirect }

chain/vm/vm.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,11 @@ type VMOpts struct {
249249
LookbackState LookbackStateGetter
250250
TipSetGetter TipSetGetter
251251
Tracing bool
252+
// FlushAllBlocks is used to control whether the VM should flush all blocks
253+
// created during execution to the blockstore. This is used for testing
254+
// purposes, where we want to inspect all blocks created during execution, not
255+
// just those connected to the final state root.
256+
FlushAllBlocks bool
252257
// ReturnEvents decodes and returns emitted events.
253258
ReturnEvents bool
254259
// ExecutionLane specifies the execution priority of the created vm

chain/vm/vmi.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import (
99

1010
"github.com/filecoin-project/go-state-types/network"
1111

12-
bstore "github.com/filecoin-project/lotus/blockstore"
1312
"github.com/filecoin-project/lotus/chain/types"
1413
)
1514

@@ -36,9 +35,6 @@ type Interface interface {
3635
ApplyImplicitMessage(ctx context.Context, msg *types.Message) (*ApplyRet, error)
3736
// Flush all buffered objects into the state store provided to the VM at construction.
3837
Flush(ctx context.Context) (cid.Cid, error)
39-
// Dump the contents of the caching blockstore to the provided blockstore. This will include the
40-
// final state tree as well as any intermediate objects created during messagae execution.
41-
DumpCache(bs bstore.Blockstore) error
4238
}
4339

4440
// WARNING: You will not affect your node's execution by misusing this feature, but you will confuse yourself thoroughly!

0 commit comments

Comments
 (0)