Bugfix: Runtime's Receiver() should only return ID addresses
This commit is contained in:
parent
8739b938db
commit
b71b743420
@ -31,41 +31,41 @@ func init() {
|
||||
var EmptyObjectCid cid.Cid
|
||||
|
||||
// TryCreateAccountActor creates account actors from only BLS/SECP256K1 addresses.
|
||||
func TryCreateAccountActor(rt *Runtime, addr address.Address) (*types.Actor, aerrors.ActorError) {
|
||||
func TryCreateAccountActor(rt *Runtime, addr address.Address) (*types.Actor, address.Address, aerrors.ActorError) {
|
||||
if err := rt.chargeGasSafe(PricelistByEpoch(rt.height).OnCreateActor()); err != nil {
|
||||
return nil, err
|
||||
return nil, address.Undef, err
|
||||
}
|
||||
|
||||
addrID, err := rt.state.RegisterNewAddress(addr)
|
||||
if err != nil {
|
||||
return nil, aerrors.Escalate(err, "registering actor address")
|
||||
return nil, address.Undef, aerrors.Escalate(err, "registering actor address")
|
||||
}
|
||||
|
||||
act, aerr := makeActor(actors.VersionForNetwork(rt.NetworkVersion()), addr)
|
||||
if aerr != nil {
|
||||
return nil, aerr
|
||||
return nil, address.Undef, aerr
|
||||
}
|
||||
|
||||
if err := rt.state.SetActor(addrID, act); err != nil {
|
||||
return nil, aerrors.Escalate(err, "creating new actor failed")
|
||||
return nil, address.Undef, aerrors.Escalate(err, "creating new actor failed")
|
||||
}
|
||||
|
||||
p, err := actors.SerializeParams(&addr)
|
||||
if err != nil {
|
||||
return nil, aerrors.Escalate(err, "couldn't serialize params for actor construction")
|
||||
return nil, address.Undef, aerrors.Escalate(err, "couldn't serialize params for actor construction")
|
||||
}
|
||||
// call constructor on account
|
||||
|
||||
_, aerr = rt.internalSend(builtin0.SystemActorAddr, addrID, builtin0.MethodsAccount.Constructor, big.Zero(), p)
|
||||
if aerr != nil {
|
||||
return nil, aerrors.Wrap(aerr, "failed to invoke account constructor")
|
||||
return nil, address.Undef, aerrors.Wrap(aerr, "failed to invoke account constructor")
|
||||
}
|
||||
|
||||
act, err = rt.state.GetActor(addrID)
|
||||
if err != nil {
|
||||
return nil, aerrors.Escalate(err, "loading newly created actor failed")
|
||||
return nil, address.Undef, aerrors.Escalate(err, "loading newly created actor failed")
|
||||
}
|
||||
return act, nil
|
||||
return act, addrID, nil
|
||||
}
|
||||
|
||||
func makeActor(ver actors.Version, addr address.Address) (*types.Actor, aerrors.ActorError) {
|
||||
|
@ -131,6 +131,9 @@ func (vm *VM) makeRuntime(ctx context.Context, msg *types.Message, origin addres
|
||||
rt.Abortf(exitcode.SysErrInvalidReceiver, "resolve msg.From address failed")
|
||||
}
|
||||
vmm.From = resF
|
||||
resT, _ := rt.ResolveAddress(msg.To)
|
||||
// may be set to undef if recipient doesn't exist yet
|
||||
vmm.To = resT
|
||||
rt.Message = vmm
|
||||
|
||||
return rt
|
||||
@ -257,11 +260,18 @@ func (vm *VM) send(ctx context.Context, msg *types.Message, parent *Runtime,
|
||||
toActor, err := st.GetActor(msg.To)
|
||||
if err != nil {
|
||||
if xerrors.Is(err, types.ErrActorNotFound) {
|
||||
a, err := TryCreateAccountActor(rt, msg.To)
|
||||
a, aid, err := TryCreateAccountActor(rt, msg.To)
|
||||
if err != nil {
|
||||
return nil, aerrors.Wrapf(err, "could not create account")
|
||||
}
|
||||
toActor = a
|
||||
nmsg := types.Message{
|
||||
To: aid,
|
||||
From: rt.vmsg.Caller(),
|
||||
Value: rt.vmsg.ValueReceived(),
|
||||
}
|
||||
|
||||
rt.vmsg = &nmsg
|
||||
} else {
|
||||
return nil, aerrors.Escalate(err, "getting actor")
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user