Update datacap actor to query datacap instead of verifreg
This commit is contained in:
parent
7c62f9e6ab
commit
1973e44f49
@ -50,6 +50,8 @@ func MakeState(store adt.Store, av actorstypes.Version, governor address.Address
|
|||||||
type State interface {
|
type State interface {
|
||||||
cbor.Marshaler
|
cbor.Marshaler
|
||||||
|
|
||||||
|
ForEachClient(func(addr address.Address, dcap abi.StoragePower) error) error
|
||||||
|
VerifiedClientDataCap(address.Address) (bool, abi.StoragePower, error)
|
||||||
Governor() (address.Address, error)
|
Governor() (address.Address, error)
|
||||||
GetState() interface{}
|
GetState() interface{}
|
||||||
}
|
}
|
||||||
|
@ -4,6 +4,7 @@ import (
|
|||||||
"golang.org/x/xerrors"
|
"golang.org/x/xerrors"
|
||||||
|
|
||||||
"github.com/filecoin-project/go-address"
|
"github.com/filecoin-project/go-address"
|
||||||
|
"github.com/filecoin-project/go-state-types/abi"
|
||||||
actorstypes "github.com/filecoin-project/go-state-types/actors"
|
actorstypes "github.com/filecoin-project/go-state-types/actors"
|
||||||
builtin9 "github.com/filecoin-project/go-state-types/builtin"
|
builtin9 "github.com/filecoin-project/go-state-types/builtin"
|
||||||
"github.com/filecoin-project/go-state-types/cbor"
|
"github.com/filecoin-project/go-state-types/cbor"
|
||||||
@ -50,6 +51,8 @@ func MakeState(store adt.Store, av actorstypes.Version, governor address.Address
|
|||||||
type State interface {
|
type State interface {
|
||||||
cbor.Marshaler
|
cbor.Marshaler
|
||||||
|
|
||||||
|
ForEachClient(func(addr address.Address, dcap abi.StoragePower) error) error
|
||||||
|
VerifiedClientDataCap(address.Address) (bool, abi.StoragePower, error)
|
||||||
Governor() (address.Address, error)
|
Governor() (address.Address, error)
|
||||||
GetState() interface{}
|
GetState() interface{}
|
||||||
}
|
}
|
||||||
|
@ -10,7 +10,6 @@ import (
|
|||||||
|
|
||||||
datacap{{.v}} "github.com/filecoin-project/go-state-types/builtin{{.import}}datacap"
|
datacap{{.v}} "github.com/filecoin-project/go-state-types/builtin{{.import}}datacap"
|
||||||
adt{{.v}} "github.com/filecoin-project/go-state-types/builtin{{.import}}util/adt"
|
adt{{.v}} "github.com/filecoin-project/go-state-types/builtin{{.import}}util/adt"
|
||||||
builtin{{.v}} "github.com/filecoin-project/go-state-types/builtin"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var _ State = (*state{{.v}})(nil)
|
var _ State = (*state{{.v}})(nil)
|
||||||
@ -47,4 +46,16 @@ func (s *state{{.v}}) Governor() (address.Address, error) {
|
|||||||
|
|
||||||
func (s *state{{.v}}) GetState() interface{} {
|
func (s *state{{.v}}) GetState() interface{} {
|
||||||
return &s.State
|
return &s.State
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *state{{.v}}) ForEachClient(cb func(addr address.Address, dcap abi.StoragePower) error) error {
|
||||||
|
return forEachCap(s.store, actors.Version{{.v}}, s.verifiedClients, cb)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *state{{.v}}) verifiedClients() (adt.Map, error) {
|
||||||
|
return adt{{.v}}.AsMap(s.store, s.Token.Balances, int(s.Token.HamtBitWidth))
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *state{{.v}}) VerifiedClientDataCap(addr address.Address) (bool, abi.StoragePower, error) {
|
||||||
|
return getDataCap(s.store, actors.Version{{.v}}, s.verifiedClients, addr)
|
||||||
|
}
|
||||||
|
52
chain/actors/builtin/datacap/util.go
Normal file
52
chain/actors/builtin/datacap/util.go
Normal file
@ -0,0 +1,52 @@
|
|||||||
|
package datacap
|
||||||
|
|
||||||
|
import (
|
||||||
|
"golang.org/x/xerrors"
|
||||||
|
|
||||||
|
"github.com/filecoin-project/go-address"
|
||||||
|
"github.com/filecoin-project/go-state-types/abi"
|
||||||
|
"github.com/filecoin-project/go-state-types/big"
|
||||||
|
|
||||||
|
"github.com/filecoin-project/lotus/chain/actors"
|
||||||
|
"github.com/filecoin-project/lotus/chain/actors/adt"
|
||||||
|
)
|
||||||
|
|
||||||
|
// taking this as a function instead of asking the caller to call it helps reduce some of the error
|
||||||
|
// checking boilerplate.
|
||||||
|
//
|
||||||
|
// "go made me do it"
|
||||||
|
type rootFunc func() (adt.Map, error)
|
||||||
|
|
||||||
|
func getDataCap(store adt.Store, ver actors.Version, root rootFunc, addr address.Address) (bool, abi.StoragePower, error) {
|
||||||
|
if addr.Protocol() != address.ID {
|
||||||
|
return false, big.Zero(), xerrors.Errorf("can only look up ID addresses")
|
||||||
|
}
|
||||||
|
vh, err := root()
|
||||||
|
if err != nil {
|
||||||
|
return false, big.Zero(), xerrors.Errorf("loading datacap actor: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
var dcap abi.StoragePower
|
||||||
|
if found, err := vh.Get(abi.AddrKey(addr), &dcap); err != nil {
|
||||||
|
return false, big.Zero(), xerrors.Errorf("looking up addr: %w", err)
|
||||||
|
} else if !found {
|
||||||
|
return false, big.Zero(), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
return true, dcap, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func forEachCap(store adt.Store, ver actors.Version, root rootFunc, cb func(addr address.Address, dcap abi.StoragePower) error) error {
|
||||||
|
vh, err := root()
|
||||||
|
if err != nil {
|
||||||
|
return xerrors.Errorf("loading verified clients: %w", err)
|
||||||
|
}
|
||||||
|
var dcap abi.StoragePower
|
||||||
|
return vh.ForEach(&dcap, func(key string) error {
|
||||||
|
a, err := address.NewFromBytes([]byte(key))
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return cb(a, dcap)
|
||||||
|
})
|
||||||
|
}
|
@ -4,8 +4,11 @@ import (
|
|||||||
"github.com/ipfs/go-cid"
|
"github.com/ipfs/go-cid"
|
||||||
|
|
||||||
"github.com/filecoin-project/go-address"
|
"github.com/filecoin-project/go-address"
|
||||||
|
"github.com/filecoin-project/go-state-types/abi"
|
||||||
datacap9 "github.com/filecoin-project/go-state-types/builtin/v9/datacap"
|
datacap9 "github.com/filecoin-project/go-state-types/builtin/v9/datacap"
|
||||||
|
adt9 "github.com/filecoin-project/go-state-types/builtin/v9/util/adt"
|
||||||
|
|
||||||
|
"github.com/filecoin-project/lotus/chain/actors"
|
||||||
"github.com/filecoin-project/lotus/chain/actors/adt"
|
"github.com/filecoin-project/lotus/chain/actors/adt"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -44,3 +47,15 @@ func (s *state9) Governor() (address.Address, error) {
|
|||||||
func (s *state9) GetState() interface{} {
|
func (s *state9) GetState() interface{} {
|
||||||
return &s.State
|
return &s.State
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *state9) ForEachClient(cb func(addr address.Address, dcap abi.StoragePower) error) error {
|
||||||
|
return forEachCap(s.store, actors.Version9, s.verifiedClients, cb)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *state9) verifiedClients() (adt.Map, error) {
|
||||||
|
return adt9.AsMap(s.store, s.Token.Balances, int(s.Token.HamtBitWidth))
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *state9) VerifiedClientDataCap(addr address.Address) (bool, abi.StoragePower, error) {
|
||||||
|
return getDataCap(s.store, actors.Version9, s.verifiedClients, addr)
|
||||||
|
}
|
||||||
|
@ -12,6 +12,7 @@ import (
|
|||||||
|
|
||||||
"github.com/filecoin-project/go-address"
|
"github.com/filecoin-project/go-address"
|
||||||
"github.com/filecoin-project/go-state-types/abi"
|
"github.com/filecoin-project/go-state-types/abi"
|
||||||
|
actorstypes "github.com/filecoin-project/go-state-types/actors"
|
||||||
"github.com/filecoin-project/go-state-types/big"
|
"github.com/filecoin-project/go-state-types/big"
|
||||||
verifregtypes8 "github.com/filecoin-project/go-state-types/builtin/v8/verifreg"
|
verifregtypes8 "github.com/filecoin-project/go-state-types/builtin/v8/verifreg"
|
||||||
verifregtypes9 "github.com/filecoin-project/go-state-types/builtin/v9/verifreg"
|
verifregtypes9 "github.com/filecoin-project/go-state-types/builtin/v9/verifreg"
|
||||||
@ -22,6 +23,7 @@ import (
|
|||||||
"github.com/filecoin-project/lotus/build"
|
"github.com/filecoin-project/lotus/build"
|
||||||
"github.com/filecoin-project/lotus/chain/actors"
|
"github.com/filecoin-project/lotus/chain/actors"
|
||||||
"github.com/filecoin-project/lotus/chain/actors/adt"
|
"github.com/filecoin-project/lotus/chain/actors/adt"
|
||||||
|
"github.com/filecoin-project/lotus/chain/actors/builtin/datacap"
|
||||||
"github.com/filecoin-project/lotus/chain/actors/builtin/verifreg"
|
"github.com/filecoin-project/lotus/chain/actors/builtin/verifreg"
|
||||||
"github.com/filecoin-project/lotus/chain/types"
|
"github.com/filecoin-project/lotus/chain/types"
|
||||||
)
|
)
|
||||||
@ -169,15 +171,40 @@ var filplusListClientsCmd = &cli.Command{
|
|||||||
defer closer()
|
defer closer()
|
||||||
ctx := ReqContext(cctx)
|
ctx := ReqContext(cctx)
|
||||||
|
|
||||||
act, err := api.StateGetActor(ctx, verifreg.Address, types.EmptyTSK)
|
apibs := blockstore.NewAPIBlockstore(api)
|
||||||
|
store := adt.WrapStore(ctx, cbor.NewCborStore(apibs))
|
||||||
|
|
||||||
|
nv, err := api.StateNetworkVersion(ctx, types.EmptyTSK)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
apibs := blockstore.NewAPIBlockstore(api)
|
av, err := actorstypes.VersionForNetwork(nv)
|
||||||
store := adt.WrapStore(ctx, cbor.NewCborStore(apibs))
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
st, err := verifreg.Load(store, act)
|
if av <= 8 {
|
||||||
|
act, err := api.StateGetActor(ctx, verifreg.Address, types.EmptyTSK)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
st, err := verifreg.Load(store, act)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return st.ForEachClient(func(addr address.Address, dcap abi.StoragePower) error {
|
||||||
|
_, err := fmt.Printf("%s: %s\n", addr, dcap)
|
||||||
|
return err
|
||||||
|
})
|
||||||
|
}
|
||||||
|
act, err := api.StateGetActor(ctx, datacap.Address, types.EmptyTSK)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
st, err := datacap.Load(store, act)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -336,7 +363,7 @@ var filplusSignRemoveDataCapProposal = &cli.Command{
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
_, dataCap, err := st.VerifiedClientDataCap(clientIdAddr)
|
dataCap, err := api.StateVerifiedClientStatus(ctx, clientIdAddr, types.EmptyTSK)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return xerrors.Errorf("failed to find verified client data cap: %w", err)
|
return xerrors.Errorf("failed to find verified client data cap: %w", err)
|
||||||
}
|
}
|
||||||
|
@ -34,7 +34,6 @@ var verifRegCmd = &cli.Command{
|
|||||||
verifRegAddVerifierFromAccountCmd,
|
verifRegAddVerifierFromAccountCmd,
|
||||||
verifRegVerifyClientCmd,
|
verifRegVerifyClientCmd,
|
||||||
verifRegListVerifiersCmd,
|
verifRegListVerifiersCmd,
|
||||||
verifRegListClientsCmd,
|
|
||||||
verifRegCheckClientCmd,
|
verifRegCheckClientCmd,
|
||||||
verifRegCheckVerifierCmd,
|
verifRegCheckVerifierCmd,
|
||||||
verifRegRemoveVerifiedClientDataCapCmd,
|
verifRegRemoveVerifiedClientDataCapCmd,
|
||||||
@ -286,38 +285,6 @@ var verifRegListVerifiersCmd = &cli.Command{
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
var verifRegListClientsCmd = &cli.Command{
|
|
||||||
Name: "list-clients",
|
|
||||||
Usage: "list all verified clients",
|
|
||||||
Hidden: true,
|
|
||||||
Action: func(cctx *cli.Context) error {
|
|
||||||
fmt.Println("DEPRECATED: This behavior is being moved to `lotus filplus`")
|
|
||||||
api, closer, err := lcli.GetFullNodeAPI(cctx)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
defer closer()
|
|
||||||
ctx := lcli.ReqContext(cctx)
|
|
||||||
|
|
||||||
act, err := api.StateGetActor(ctx, verifreg.Address, types.EmptyTSK)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
apibs := blockstore.NewAPIBlockstore(api)
|
|
||||||
store := adt.WrapStore(ctx, cbor.NewCborStore(apibs))
|
|
||||||
|
|
||||||
st, err := verifreg.Load(store, act)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
return st.ForEachClient(func(addr address.Address, dcap abi.StoragePower) error {
|
|
||||||
_, err := fmt.Printf("%s: %s\n", addr, dcap)
|
|
||||||
return err
|
|
||||||
})
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
var verifRegCheckClientCmd = &cli.Command{
|
var verifRegCheckClientCmd = &cli.Command{
|
||||||
Name: "check-client",
|
Name: "check-client",
|
||||||
Usage: "check verified client remaining bytes",
|
Usage: "check verified client remaining bytes",
|
||||||
|
@ -30,6 +30,7 @@ import (
|
|||||||
"github.com/filecoin-project/lotus/build"
|
"github.com/filecoin-project/lotus/build"
|
||||||
"github.com/filecoin-project/lotus/chain/actors"
|
"github.com/filecoin-project/lotus/chain/actors"
|
||||||
"github.com/filecoin-project/lotus/chain/actors/builtin"
|
"github.com/filecoin-project/lotus/chain/actors/builtin"
|
||||||
|
"github.com/filecoin-project/lotus/chain/actors/builtin/datacap"
|
||||||
"github.com/filecoin-project/lotus/chain/actors/builtin/market"
|
"github.com/filecoin-project/lotus/chain/actors/builtin/market"
|
||||||
"github.com/filecoin-project/lotus/chain/actors/builtin/miner"
|
"github.com/filecoin-project/lotus/chain/actors/builtin/miner"
|
||||||
"github.com/filecoin-project/lotus/chain/actors/builtin/multisig"
|
"github.com/filecoin-project/lotus/chain/actors/builtin/multisig"
|
||||||
@ -1399,26 +1400,56 @@ func (a *StateAPI) StateVerifierStatus(ctx context.Context, addr address.Address
|
|||||||
// Returns zero if there is no entry in the data cap table for the
|
// Returns zero if there is no entry in the data cap table for the
|
||||||
// address.
|
// address.
|
||||||
func (m *StateModule) StateVerifiedClientStatus(ctx context.Context, addr address.Address, tsk types.TipSetKey) (*abi.StoragePower, error) {
|
func (m *StateModule) StateVerifiedClientStatus(ctx context.Context, addr address.Address, tsk types.TipSetKey) (*abi.StoragePower, error) {
|
||||||
act, err := m.StateGetActor(ctx, verifreg.Address, tsk)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
aid, err := m.StateLookupID(ctx, addr, tsk)
|
aid, err := m.StateLookupID(ctx, addr, tsk)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Warnf("lookup failure %v", err)
|
log.Warnf("lookup failure %v", err)
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
vrs, err := verifreg.Load(m.StateManager.ChainStore().ActorStore(ctx), act)
|
nv, err := m.StateNetworkVersion(ctx, tsk)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, xerrors.Errorf("failed to load verified registry state: %w", err)
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
verified, dcap, err := vrs.VerifiedClientDataCap(aid)
|
av, err := actorstypes.VersionForNetwork(nv)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, xerrors.Errorf("looking up verified client: %w", err)
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var dcap abi.StoragePower
|
||||||
|
var verified bool
|
||||||
|
if av <= 8 {
|
||||||
|
act, err := m.StateGetActor(ctx, verifreg.Address, tsk)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
vrs, err := verifreg.Load(m.StateManager.ChainStore().ActorStore(ctx), act)
|
||||||
|
if err != nil {
|
||||||
|
return nil, xerrors.Errorf("failed to load verified registry state: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
verified, dcap, err = vrs.VerifiedClientDataCap(aid)
|
||||||
|
if err != nil {
|
||||||
|
return nil, xerrors.Errorf("looking up verified client: %w", err)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
act, err := m.StateGetActor(ctx, datacap.Address, tsk)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
dcs, err := datacap.Load(m.StateManager.ChainStore().ActorStore(ctx), act)
|
||||||
|
if err != nil {
|
||||||
|
return nil, xerrors.Errorf("failed to load datacap actor state: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
verified, dcap, err = dcs.VerifiedClientDataCap(aid)
|
||||||
|
if err != nil {
|
||||||
|
return nil, xerrors.Errorf("looking up verified client: %w", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if !verified {
|
if !verified {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user