Panic if runtime's Message has non-ID caller or receiver
This commit is contained in:
parent
b71b743420
commit
757aa1039f
@ -27,8 +27,30 @@ import (
|
|||||||
"github.com/filecoin-project/lotus/chain/types"
|
"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 {
|
type Runtime struct {
|
||||||
types.Message
|
Message
|
||||||
rt0.Syscalls
|
rt0.Syscalls
|
||||||
|
|
||||||
ctx context.Context
|
ctx context.Context
|
||||||
|
@ -134,7 +134,7 @@ func (vm *VM) makeRuntime(ctx context.Context, msg *types.Message, origin addres
|
|||||||
resT, _ := rt.ResolveAddress(msg.To)
|
resT, _ := rt.ResolveAddress(msg.To)
|
||||||
// may be set to undef if recipient doesn't exist yet
|
// may be set to undef if recipient doesn't exist yet
|
||||||
vmm.To = resT
|
vmm.To = resT
|
||||||
rt.Message = vmm
|
rt.Message = Message{msg: vmm}
|
||||||
|
|
||||||
return rt
|
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")
|
return nil, aerrors.Wrapf(err, "could not create account")
|
||||||
}
|
}
|
||||||
toActor = a
|
toActor = a
|
||||||
nmsg := types.Message{
|
nmsg := Message{
|
||||||
|
msg: types.Message{
|
||||||
To: aid,
|
To: aid,
|
||||||
From: rt.vmsg.Caller(),
|
From: rt.Message.Caller(),
|
||||||
Value: rt.vmsg.ValueReceived(),
|
Value: rt.Message.ValueReceived(),
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
rt.vmsg = &nmsg
|
rt.Message = nmsg
|
||||||
} else {
|
} else {
|
||||||
return nil, aerrors.Escalate(err, "getting actor")
|
return nil, aerrors.Escalate(err, "getting actor")
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user