change ResolveToKeyAddr => ResolveToDeterministicAddr + friends.

This commit is contained in:
Raúl Kripalani 2023-01-13 00:53:53 +00:00
parent 2c839924c6
commit 6de2aca8ae
21 changed files with 75 additions and 72 deletions

View File

@ -585,9 +585,9 @@ func (filec *FilecoinEC) checkBlockMessages(ctx context.Context, b *types.FullBl
return xerrors.Errorf("block had invalid secpk message at index %d: %w", i, err) return xerrors.Errorf("block had invalid secpk message at index %d: %w", i, err)
} }
// `From` being an account actor is only validated inside the `vm.ResolveToKeyAddr` call // `From` being an account actor is only validated inside the `vm.ResolveToDeterministicAddr` call
// in `StateManager.ResolveToKeyAddress` here (and not in `checkMsg`). // in `StateManager.ResolveToDeterministicAddress` here (and not in `checkMsg`).
kaddr, err := filec.sm.ResolveToKeyAddress(ctx, m.Message.From, baseTs) kaddr, err := filec.sm.ResolveToDeterministicAddress(ctx, m.Message.From, baseTs)
if err != nil { if err != nil {
return xerrors.Errorf("failed to resolve key addr: %w", err) return xerrors.Errorf("failed to resolve key addr: %w", err)
} }

View File

@ -477,7 +477,7 @@ func (mp *MessagePool) resolveToKey(ctx context.Context, addr address.Address) (
} }
// resolve the address // resolve the address
ka, err := mp.api.StateAccountKeyAtFinality(ctx, addr, mp.curTs) ka, err := mp.api.StateDeterministicAddressAtFinality(ctx, addr, mp.curTs)
if err != nil { if err != nil {
return address.Undef, err return address.Undef, err
} }

View File

@ -161,7 +161,7 @@ func (tma *testMpoolAPI) GetActorAfter(addr address.Address, ts *types.TipSet) (
}, nil }, nil
} }
func (tma *testMpoolAPI) StateAccountKeyAtFinality(ctx context.Context, addr address.Address, ts *types.TipSet) (address.Address, error) { func (tma *testMpoolAPI) StateDeterministicAddressAtFinality(ctx context.Context, addr address.Address, ts *types.TipSet) (address.Address, error) {
if addr.Protocol() != address.BLS && addr.Protocol() != address.SECP256K1 && addr.Protocol() != address.Delegated { if addr.Protocol() != address.BLS && addr.Protocol() != address.SECP256K1 && addr.Protocol() != address.Delegated {
return address.Undef, fmt.Errorf("given address was not a key addr") return address.Undef, fmt.Errorf("given address was not a key addr")
} }

View File

@ -28,7 +28,7 @@ type Provider interface {
PutMessage(ctx context.Context, m types.ChainMsg) (cid.Cid, error) PutMessage(ctx context.Context, m types.ChainMsg) (cid.Cid, error)
PubSubPublish(string, []byte) error PubSubPublish(string, []byte) error
GetActorAfter(address.Address, *types.TipSet) (*types.Actor, error) GetActorAfter(address.Address, *types.TipSet) (*types.Actor, error)
StateAccountKeyAtFinality(context.Context, address.Address, *types.TipSet) (address.Address, error) StateDeterministicAddressAtFinality(context.Context, address.Address, *types.TipSet) (address.Address, error)
StateNetworkVersion(context.Context, abi.ChainEpoch) network.Version StateNetworkVersion(context.Context, abi.ChainEpoch) network.Version
MessagesForBlock(context.Context, *types.BlockHeader) ([]*types.Message, []*types.SignedMessage, error) MessagesForBlock(context.Context, *types.BlockHeader) ([]*types.Message, []*types.SignedMessage, error)
MessagesForTipset(context.Context, *types.TipSet) ([]types.ChainMsg, error) MessagesForTipset(context.Context, *types.TipSet) ([]types.ChainMsg, error)
@ -102,8 +102,8 @@ func (mpp *mpoolProvider) GetActorAfter(addr address.Address, ts *types.TipSet)
return st.GetActor(addr) return st.GetActor(addr)
} }
func (mpp *mpoolProvider) StateAccountKeyAtFinality(ctx context.Context, addr address.Address, ts *types.TipSet) (address.Address, error) { func (mpp *mpoolProvider) StateDeterministicAddressAtFinality(ctx context.Context, addr address.Address, ts *types.TipSet) (address.Address, error) {
return mpp.sm.ResolveToKeyAddressAtFinality(ctx, addr, ts) return mpp.sm.ResolveToDeterministicAddressAtFinality(ctx, addr, ts)
} }
func (mpp *mpoolProvider) StateNetworkVersion(ctx context.Context, height abi.ChainEpoch) network.Version { func (mpp *mpoolProvider) StateNetworkVersion(ctx context.Context, height abi.ChainEpoch) network.Version {

View File

@ -48,7 +48,7 @@ func GetMinerWorkerRaw(ctx context.Context, sm *StateManager, st cid.Cid, maddr
return address.Undef, xerrors.Errorf("failed to load actor info: %w", err) return address.Undef, xerrors.Errorf("failed to load actor info: %w", err)
} }
return vm.ResolveToKeyAddr(state, sm.cs.ActorStore(ctx), info.Worker) return vm.ResolveToDeterministicAddr(state, sm.cs.ActorStore(ctx), info.Worker)
} }
func GetPower(ctx context.Context, sm *StateManager, ts *types.TipSet, maddr address.Address) (power.Claim, power.Claim, bool, error) { func GetPower(ctx context.Context, sm *StateManager, ts *types.TipSet, maddr address.Address) (power.Claim, power.Claim, bool, error) {
@ -381,7 +381,7 @@ func MinerGetBaseInfo(ctx context.Context, sm *StateManager, bcs beacon.Schedule
return nil, err return nil, err
} }
worker, err := sm.ResolveToKeyAddress(ctx, info.Worker, ts) worker, err := sm.ResolveToDeterministicAddress(ctx, info.Worker, ts)
if err != nil { if err != nil {
return nil, xerrors.Errorf("resolving worker address: %w", err) return nil, xerrors.Errorf("resolving worker address: %w", err)
} }

View File

@ -200,7 +200,7 @@ func (sm *StateManager) callInternal(ctx context.Context, msg *types.Message, pr
var ret *vm.ApplyRet var ret *vm.ApplyRet
var gasInfo api.MsgGasCost var gasInfo api.MsgGasCost
if checkGas { if checkGas {
fromKey, err := sm.ResolveToKeyAddress(ctx, msg.From, ts) fromKey, err := sm.ResolveToDeterministicAddress(ctx, msg.From, ts)
if err != nil { if err != nil {
return nil, xerrors.Errorf("could not resolve key: %w", err) return nil, xerrors.Errorf("could not resolve key: %w", err)
} }

View File

@ -48,7 +48,7 @@ func (s *RPCStateManager) LookupID(ctx context.Context, addr address.Address, ts
return s.gapi.StateLookupID(ctx, addr, ts.Key()) return s.gapi.StateLookupID(ctx, addr, ts.Key())
} }
func (s *RPCStateManager) ResolveToKeyAddress(ctx context.Context, addr address.Address, ts *types.TipSet) (address.Address, error) { func (s *RPCStateManager) ResolveToDeterministicAddress(ctx context.Context, addr address.Address, ts *types.TipSet) (address.Address, error) {
return s.gapi.StateAccountKey(ctx, addr, ts.Key()) return s.gapi.StateAccountKey(ctx, addr, ts.Key())
} }

View File

@ -42,7 +42,7 @@ type StateManagerAPI interface {
GetPaychState(ctx context.Context, addr address.Address, ts *types.TipSet) (*types.Actor, paych.State, error) GetPaychState(ctx context.Context, addr address.Address, ts *types.TipSet) (*types.Actor, paych.State, error)
LoadActorTsk(ctx context.Context, addr address.Address, tsk types.TipSetKey) (*types.Actor, error) LoadActorTsk(ctx context.Context, addr address.Address, tsk types.TipSetKey) (*types.Actor, error)
LookupID(ctx context.Context, addr address.Address, ts *types.TipSet) (address.Address, error) LookupID(ctx context.Context, addr address.Address, ts *types.TipSet) (address.Address, error)
ResolveToKeyAddress(ctx context.Context, addr address.Address, ts *types.TipSet) (address.Address, error) ResolveToDeterministicAddress(ctx context.Context, addr address.Address, ts *types.TipSet) (address.Address, error)
} }
type versionSpec struct { type versionSpec struct {
@ -207,9 +207,9 @@ func (sm *StateManager) Beacon() beacon.Schedule {
return sm.beacon return sm.beacon
} }
// ResolveToKeyAddress is similar to `vm.ResolveToKeyAddr` but does not allow `Actor` type of addresses. // ResolveToDeterministicAddress is similar to `vm.ResolveToDeterministicAddr` but does not allow `Actor` type of addresses.
// Uses the `TipSet` `ts` to generate the VM state. // Uses the `TipSet` `ts` to generate the VM state.
func (sm *StateManager) ResolveToKeyAddress(ctx context.Context, addr address.Address, ts *types.TipSet) (address.Address, error) { func (sm *StateManager) ResolveToDeterministicAddress(ctx context.Context, addr address.Address, ts *types.TipSet) (address.Address, error) {
switch addr.Protocol() { switch addr.Protocol() {
case address.BLS, address.SECP256K1, address.Delegated: case address.BLS, address.SECP256K1, address.Delegated:
return addr, nil return addr, nil
@ -230,7 +230,7 @@ func (sm *StateManager) ResolveToKeyAddress(ctx context.Context, addr address.Ad
return address.Undef, xerrors.Errorf("failed to load parent state tree at tipset %s: %w", ts.Parents(), err) return address.Undef, xerrors.Errorf("failed to load parent state tree at tipset %s: %w", ts.Parents(), err)
} }
resolved, err := vm.ResolveToKeyAddr(tree, cst, addr) resolved, err := vm.ResolveToDeterministicAddr(tree, cst, addr)
if err == nil { if err == nil {
return resolved, nil return resolved, nil
} }
@ -246,12 +246,12 @@ func (sm *StateManager) ResolveToKeyAddress(ctx context.Context, addr address.Ad
return address.Undef, xerrors.Errorf("failed to load state tree at tipset %s: %w", ts, err) return address.Undef, xerrors.Errorf("failed to load state tree at tipset %s: %w", ts, err)
} }
return vm.ResolveToKeyAddr(tree, cst, addr) return vm.ResolveToDeterministicAddr(tree, cst, addr)
} }
// ResolveToKeyAddressAtFinality is similar to stmgr.ResolveToKeyAddress but fails if the ID address being resolved isn't reorg-stable yet. // ResolveToDeterministicAddressAtFinality is similar to stmgr.ResolveToDeterministicAddress but fails if the ID address being resolved isn't reorg-stable yet.
// It should not be used for consensus-critical subsystems. // It should not be used for consensus-critical subsystems.
func (sm *StateManager) ResolveToKeyAddressAtFinality(ctx context.Context, addr address.Address, ts *types.TipSet) (address.Address, error) { func (sm *StateManager) ResolveToDeterministicAddressAtFinality(ctx context.Context, addr address.Address, ts *types.TipSet) (address.Address, error) {
switch addr.Protocol() { switch addr.Protocol() {
case address.BLS, address.SECP256K1, address.Delegated: case address.BLS, address.SECP256K1, address.Delegated:
return addr, nil return addr, nil
@ -287,7 +287,7 @@ func (sm *StateManager) ResolveToKeyAddressAtFinality(ctx context.Context, addr
} }
} }
resolved, err := vm.ResolveToKeyAddr(tree, cst, addr) resolved, err := vm.ResolveToDeterministicAddr(tree, cst, addr)
if err == nil { if err == nil {
return resolved, nil return resolved, nil
} }
@ -296,7 +296,7 @@ func (sm *StateManager) ResolveToKeyAddressAtFinality(ctx context.Context, addr
} }
func (sm *StateManager) GetBlsPublicKey(ctx context.Context, addr address.Address, ts *types.TipSet) (pubk []byte, err error) { func (sm *StateManager) GetBlsPublicKey(ctx context.Context, addr address.Address, ts *types.TipSet) (pubk []byte, err error) {
kaddr, err := sm.ResolveToKeyAddress(ctx, addr, ts) kaddr, err := sm.ResolveToDeterministicAddress(ctx, addr, ts)
if err != nil { if err != nil {
return pubk, xerrors.Errorf("failed to resolve address to key address: %w", err) return pubk, xerrors.Errorf("failed to resolve address to key address: %w", err)
} }

View File

@ -276,7 +276,7 @@ func (x *FvmExtern) workerKeyAtLookback(ctx context.Context, minerId address.Add
return address.Undef, gasUsed, err return address.Undef, gasUsed, err
} }
raddr, err := ResolveToKeyAddr(stateTree, cstWithGas, info.Worker) raddr, err := ResolveToDeterministicAddr(stateTree, cstWithGas, info.Worker)
if err != nil { if err != nil {
return address.Undef, gasUsed, err return address.Undef, gasUsed, err
} }

View File

@ -249,7 +249,7 @@ func (rt *Runtime) GetRandomnessFromBeacon(personalization crypto.DomainSeparati
func (rt *Runtime) NewActorAddress() address.Address { func (rt *Runtime) NewActorAddress() address.Address {
var b bytes.Buffer var b bytes.Buffer
oa, _ := ResolveToKeyAddr(rt.vm.cstate, rt.vm.cst, rt.origin) oa, _ := ResolveToDeterministicAddr(rt.vm.cstate, rt.vm.cst, rt.origin)
if err := oa.MarshalCBOR(&b); err != nil { // todo: spec says cbor; why not just bytes? if err := oa.MarshalCBOR(&b); err != nil { // todo: spec says cbor; why not just bytes?
panic(aerrors.Fatalf("writing caller address into a buffer: %v", err)) panic(aerrors.Fatalf("writing caller address into a buffer: %v", err))
} }

View File

@ -255,7 +255,7 @@ func (ss *syscallShim) workerKeyAtLookback(height abi.ChainEpoch) (address.Addre
return address.Undef, err return address.Undef, err
} }
return ResolveToKeyAddr(ss.cstate, ss.cst, info.Worker) return ResolveToDeterministicAddr(ss.cstate, ss.cst, info.Worker)
} }
func (ss *syscallShim) VerifyPoSt(info proof7.WindowPoStVerifyInfo) error { func (ss *syscallShim) VerifyPoSt(info proof7.WindowPoStVerifyInfo) error {
@ -325,7 +325,7 @@ func (ss *syscallShim) VerifyReplicaUpdate(update proof7.ReplicaUpdateInfo) erro
func (ss *syscallShim) VerifySignature(sig crypto.Signature, addr address.Address, input []byte) error { func (ss *syscallShim) VerifySignature(sig crypto.Signature, addr address.Address, input []byte) error {
// TODO: in genesis setup, we are currently faking signatures // TODO: in genesis setup, we are currently faking signatures
kaddr, err := ResolveToKeyAddr(ss.cstate, ss.cst, addr) kaddr, err := ResolveToDeterministicAddr(ss.cstate, ss.cst, addr)
if err != nil { if err != nil {
return err return err
} }

View File

@ -45,8 +45,10 @@ var (
gasOnActorExec = newGasCharge("OnActorExec", 0, 0) gasOnActorExec = newGasCharge("OnActorExec", 0, 0)
) )
// ResolveToKeyAddr returns the public key type of address (`BLS`/`SECP256K1`) of an account actor identified by `addr`. // ResolveToDeterministicAddr returns the public key type of address
func ResolveToKeyAddr(state types.StateTree, cst cbor.IpldStore, addr address.Address) (address.Address, error) { // (`BLS`/`SECP256K1`) of an actor identified by `addr`, or its
// delegated address.
func ResolveToDeterministicAddr(state types.StateTree, cst cbor.IpldStore, addr address.Address) (address.Address, error) {
if addr.Protocol() == address.BLS || addr.Protocol() == address.SECP256K1 || addr.Protocol() == address.Delegated { if addr.Protocol() == address.BLS || addr.Protocol() == address.SECP256K1 || addr.Protocol() == address.Delegated {
return addr, nil return addr, nil
} }

View File

@ -333,9 +333,10 @@
# env var: LOTUS_ACTOREVENT_MAXFILTERHEIGHTRANGE # env var: LOTUS_ACTOREVENT_MAXFILTERHEIGHTRANGE
#MaxFilterHeightRange = 2880 #MaxFilterHeightRange = 2880
# EventHistoryDatabasePath is the full path to a sqlite database that will be used to index actor events to # ActorEventDatabasePath is the full path to a sqlite database that will be used to index actor events to
# support the historic filter APIs. If the database does not exist it will be created. The directory containing # support the historic filter APIs. If the database does not exist it will be created. The directory containing
# the database must already exist and be writeable. # the database must already exist and be writeable. If a relative path is provided here, sqlite treats it as
# relative to the CWD (current working directory).
# #
# type: string # type: string
# env var: LOTUS_ACTOREVENT_ACTOREVENTDATABASEPATH # env var: LOTUS_ACTOREVENT_ACTOREVENTDATABASEPATH

View File

@ -261,7 +261,7 @@ func gasEstimateGasLimit(
msg.GasFeeCap = big.Zero() msg.GasFeeCap = big.Zero()
msg.GasPremium = big.Zero() msg.GasPremium = big.Zero()
fromA, err := smgr.ResolveToKeyAddress(ctx, msgIn.From, currTs) fromA, err := smgr.ResolveToDeterministicAddress(ctx, msgIn.From, currTs)
if err != nil { if err != nil {
return -1, xerrors.Errorf("getting key address: %w", err) return -1, xerrors.Errorf("getting key address: %w", err)
} }

View File

@ -175,7 +175,7 @@ func (a *MpoolAPI) MpoolPushMessage(ctx context.Context, msg *types.Message, spe
} }
} }
fromA, err := a.Stmgr.ResolveToKeyAddress(ctx, msg.From, nil) fromA, err := a.Stmgr.ResolveToDeterministicAddress(ctx, msg.From, nil)
if err != nil { if err != nil {
return nil, xerrors.Errorf("getting key address: %w", err) return nil, xerrors.Errorf("getting key address: %w", err)
} }

View File

@ -508,7 +508,7 @@ func (m *StateModule) StateAccountKey(ctx context.Context, addr address.Address,
return address.Undef, xerrors.Errorf("loading tipset %s: %w", tsk, err) return address.Undef, xerrors.Errorf("loading tipset %s: %w", tsk, err)
} }
return m.StateManager.ResolveToKeyAddress(ctx, addr, ts) return m.StateManager.ResolveToDeterministicAddress(ctx, addr, ts)
} }
func (a *StateAPI) StateReadState(ctx context.Context, actor address.Address, tsk types.TipSetKey) (*api.ActorState, error) { func (a *StateAPI) StateReadState(ctx context.Context, actor address.Address, tsk types.TipSetKey) (*api.ActorState, error) {

View File

@ -36,7 +36,7 @@ func (a *WalletAPI) WalletBalance(ctx context.Context, addr address.Address) (ty
} }
func (a *WalletAPI) WalletSign(ctx context.Context, k address.Address, msg []byte) (*crypto.Signature, error) { func (a *WalletAPI) WalletSign(ctx context.Context, k address.Address, msg []byte) (*crypto.Signature, error) {
keyAddr, err := a.StateManagerAPI.ResolveToKeyAddress(ctx, k, nil) keyAddr, err := a.StateManagerAPI.ResolveToDeterministicAddress(ctx, k, nil)
if err != nil { if err != nil {
return nil, xerrors.Errorf("failed to resolve ID address: %w", keyAddr) return nil, xerrors.Errorf("failed to resolve ID address: %w", keyAddr)
} }
@ -46,7 +46,7 @@ func (a *WalletAPI) WalletSign(ctx context.Context, k address.Address, msg []byt
} }
func (a *WalletAPI) WalletSignMessage(ctx context.Context, k address.Address, msg *types.Message) (*types.SignedMessage, error) { func (a *WalletAPI) WalletSignMessage(ctx context.Context, k address.Address, msg *types.Message) (*types.SignedMessage, error) {
keyAddr, err := a.StateManagerAPI.ResolveToKeyAddress(ctx, k, nil) keyAddr, err := a.StateManagerAPI.ResolveToDeterministicAddress(ctx, k, nil)
if err != nil { if err != nil {
return nil, xerrors.Errorf("failed to resolve ID address: %w", keyAddr) return nil, xerrors.Errorf("failed to resolve ID address: %w", keyAddr)
} }

View File

@ -28,7 +28,7 @@ var errProofNotSupported = errors.New("payment channel proof parameter is not su
// stateManagerAPI defines the methods needed from StateManager // stateManagerAPI defines the methods needed from StateManager
type stateManagerAPI interface { type stateManagerAPI interface {
ResolveToKeyAddress(ctx context.Context, addr address.Address, ts *types.TipSet) (address.Address, error) ResolveToDeterministicAddress(ctx context.Context, addr address.Address, ts *types.TipSet) (address.Address, error)
GetPaychState(ctx context.Context, addr address.Address, ts *types.TipSet) (*types.Actor, paych.State, error) GetPaychState(ctx context.Context, addr address.Address, ts *types.TipSet) (*types.Actor, paych.State, error)
Call(ctx context.Context, msg *types.Message, ts *types.TipSet) (*api.InvocResult, error) Call(ctx context.Context, msg *types.Message, ts *types.TipSet) (*api.InvocResult, error)
} }

View File

@ -63,7 +63,7 @@ func (sm *mockStateManager) setPaychState(a address.Address, actor *types.Actor,
sm.paychState[a] = mockPchState{actor, state} sm.paychState[a] = mockPchState{actor, state}
} }
func (sm *mockStateManager) ResolveToKeyAddress(ctx context.Context, addr address.Address, ts *types.TipSet) (address.Address, error) { func (sm *mockStateManager) ResolveToDeterministicAddress(ctx context.Context, addr address.Address, ts *types.TipSet) (address.Address, error) {
sm.lk.Lock() sm.lk.Lock()
defer sm.lk.Unlock() defer sm.lk.Unlock()
keyAddr, ok := sm.accountState[addr] keyAddr, ok := sm.accountState[addr]

View File

@ -211,7 +211,7 @@ func (ca *channelAccessor) checkVoucherValidUnlocked(ctx context.Context, ch add
return nil, err return nil, err
} }
from, err := ca.api.ResolveToKeyAddress(ctx, f, nil) from, err := ca.api.ResolveToDeterministicAddress(ctx, f, nil)
if err != nil { if err != nil {
return nil, err return nil, err
} }

View File

@ -28,7 +28,7 @@ func (ca *stateAccessor) loadStateChannelInfo(ctx context.Context, ch address.Ad
if err != nil { if err != nil {
return nil, err return nil, err
} }
from, err := ca.sm.ResolveToKeyAddress(ctx, f, nil) from, err := ca.sm.ResolveToDeterministicAddress(ctx, f, nil)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -36,7 +36,7 @@ func (ca *stateAccessor) loadStateChannelInfo(ctx context.Context, ch address.Ad
if err != nil { if err != nil {
return nil, err return nil, err
} }
to, err := ca.sm.ResolveToKeyAddress(ctx, t, nil) to, err := ca.sm.ResolveToDeterministicAddress(ctx, t, nil)
if err != nil { if err != nil {
return nil, err return nil, err
} }