fix account address resolution

it's in the actor state only if it is a v5 (or later) state tree
This commit is contained in:
vyzo 2022-11-10 05:01:44 +02:00
parent 2588b45826
commit 6e72910d31
2 changed files with 15 additions and 3 deletions

View File

@ -24,6 +24,8 @@ type StateTree interface {
SetActor(addr address.Address, act *Actor) error
// GetActor returns the actor from any type of `addr` provided.
GetActor(addr address.Address) (*Actor, error)
Version() StateTreeVersion
}
type storageWrapper struct {

View File

@ -30,6 +30,7 @@ import (
"github.com/filecoin-project/lotus/chain/actors/adt"
"github.com/filecoin-project/lotus/chain/actors/aerrors"
"github.com/filecoin-project/lotus/chain/actors/builtin"
"github.com/filecoin-project/lotus/chain/actors/builtin/account"
"github.com/filecoin-project/lotus/chain/actors/builtin/reward"
"github.com/filecoin-project/lotus/chain/state"
"github.com/filecoin-project/lotus/chain/types"
@ -54,10 +55,19 @@ func ResolveToKeyAddr(state types.StateTree, cst cbor.IpldStore, addr address.Ad
if err != nil {
return address.Undef, xerrors.Errorf("failed to find actor: %s", addr)
}
if state.Version() >= types.StateTreeVersion5 {
if act.Address == nil {
return address.Undef, xerrors.Errorf("actor doesn't have expected address: %s", addr)
}
return *act.Address, nil
} else {
aast, err := account.Load(adt.WrapStore(context.TODO(), cst), act)
if err != nil {
return address.Undef, xerrors.Errorf("failed to get account actor state for %s: %w", addr, err)
}
return aast.PubkeyAddress()
}
}
var (