diff --git a/chain/vm/runtime.go b/chain/vm/runtime.go index 472017a00..4c6bf1848 100644 --- a/chain/vm/runtime.go +++ b/chain/vm/runtime.go @@ -27,8 +27,30 @@ import ( "github.com/filecoin-project/lotus/chain/types" ) +type Message struct { + msg types.Message +} + +func (m *Message) Caller() address.Address { + if m.msg.From.Protocol() != address.ID { + panic("runtime message has a non-ID caller") + } + return m.msg.From +} + +func (m *Message) Receiver() address.Address { + if m.msg.To != address.Undef && m.msg.To.Protocol() != address.ID { + panic("runtime message has a non-ID receiver") + } + return m.msg.To +} + +func (m *Message) ValueReceived() abi.TokenAmount { + return m.msg.Value +} + type Runtime struct { - types.Message + Message rt0.Syscalls ctx context.Context diff --git a/chain/vm/vm.go b/chain/vm/vm.go index aec356fb4..a5072f8c5 100644 --- a/chain/vm/vm.go +++ b/chain/vm/vm.go @@ -134,7 +134,7 @@ func (vm *VM) makeRuntime(ctx context.Context, msg *types.Message, origin addres resT, _ := rt.ResolveAddress(msg.To) // may be set to undef if recipient doesn't exist yet vmm.To = resT - rt.Message = vmm + rt.Message = Message{msg: vmm} return rt } @@ -265,13 +265,15 @@ func (vm *VM) send(ctx context.Context, msg *types.Message, parent *Runtime, return nil, aerrors.Wrapf(err, "could not create account") } toActor = a - nmsg := types.Message{ - To: aid, - From: rt.vmsg.Caller(), - Value: rt.vmsg.ValueReceived(), + nmsg := Message{ + msg: types.Message{ + To: aid, + From: rt.Message.Caller(), + Value: rt.Message.ValueReceived(), + }, } - rt.vmsg = &nmsg + rt.Message = nmsg } else { return nil, aerrors.Escalate(err, "getting actor") }