-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
tracers.go
57 lines (47 loc) · 1.52 KB
/
tracers.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package stmgr
import (
"context"
"github.com/ipfs/go-cid"
"github.com/filecoin-project/lotus/api"
"github.com/filecoin-project/lotus/chain/types"
"github.com/filecoin-project/lotus/chain/vm"
)
type ExecMonitor interface {
// MessageApplied is called after a message has been applied. Returning an error will halt execution of any further messages.
MessageApplied(ctx context.Context, ts *types.TipSet, mcid cid.Cid, msg *types.Message, ret *vm.ApplyRet, implicit bool) error
}
var _ ExecMonitor = (*InvocationTracer)(nil)
type InvocationTracer struct {
trace *[]*api.InvocResult
}
func (i *InvocationTracer) MessageApplied(ctx context.Context, ts *types.TipSet, mcid cid.Cid, msg *types.Message, ret *vm.ApplyRet, implicit bool) error {
ir := &api.InvocResult{
MsgCid: mcid,
Msg: msg,
MsgRct: &ret.MessageReceipt,
ExecutionTrace: ret.ExecutionTrace,
Duration: ret.Duration,
}
if ret.ActorErr != nil {
ir.Error = ret.ActorErr.Error()
}
if ret.GasCosts != nil {
ir.GasCost = MakeMsgGasCost(msg, ret)
}
*i.trace = append(*i.trace, ir)
return nil
}
var _ ExecMonitor = (*messageFinder)(nil)
type messageFinder struct {
mcid cid.Cid // the message cid to find
outm *types.Message
outr *vm.ApplyRet
}
func (m *messageFinder) MessageApplied(ctx context.Context, ts *types.TipSet, mcid cid.Cid, msg *types.Message, ret *vm.ApplyRet, implicit bool) error {
if m.mcid == mcid {
m.outm = msg
m.outr = ret
return errHaltExecution // message was found, no need to continue
}
return nil
}