feat: state API for verified client data cap

This commit is contained in:
Dirk McCormick 2020-07-02 11:57:10 -04:00
parent 055a8efe10
commit 2c7aa318c1
5 changed files with 67 additions and 20 deletions

View File

@ -4,6 +4,8 @@ import (
"context"
"time"
"github.com/filecoin-project/specs-actors/actors/builtin/verifreg"
"github.com/ipfs/go-cid"
"github.com/ipfs/go-filestore"
"github.com/libp2p/go-libp2p-core/peer"
@ -239,6 +241,7 @@ type FullNode interface {
StateGetReceipt(context.Context, cid.Cid, types.TipSetKey) (*types.MessageReceipt, error)
StateMinerSectorCount(context.Context, address.Address, types.TipSetKey) (MinerSectors, error)
StateCompute(context.Context, abi.ChainEpoch, []*types.Message, types.TipSetKey) (*ComputeStateOutput, error)
StateVerifiedClientStatus(ctx context.Context, addr address.Address, tsk types.TipSetKey) (verifreg.DataCap, error)
// MethodGroup: Msig
// The Msig methods are used to interact with multisig wallets on the

View File

@ -2,6 +2,7 @@ package apistruct
import (
"context"
"github.com/filecoin-project/specs-actors/actors/builtin/verifreg"
"io"
"github.com/ipfs/go-cid"
@ -156,6 +157,7 @@ type FullNodeStruct struct {
StateMinerSectorCount func(context.Context, address.Address, types.TipSetKey) (api.MinerSectors, error) `perm:"read"`
StateListMessages func(ctx context.Context, match *types.Message, tsk types.TipSetKey, toht abi.ChainEpoch) ([]cid.Cid, error) `perm:"read"`
StateCompute func(context.Context, abi.ChainEpoch, []*types.Message, types.TipSetKey) (*api.ComputeStateOutput, error) `perm:"read"`
StateVerifiedClientStatus func(context.Context, address.Address, types.TipSetKey) (verifreg.DataCap, error) `perm:"read"`
MsigGetAvailableBalance func(context.Context, address.Address, types.TipSetKey) (types.BigInt, error) `perm:"read"`
MsigCreate func(context.Context, uint64, []address.Address, types.BigInt, address.Address, types.BigInt) (cid.Cid, error) `perm:"sign"`
@ -690,6 +692,10 @@ func (c *FullNodeStruct) StateCompute(ctx context.Context, height abi.ChainEpoch
return c.Internal.StateCompute(ctx, height, msgs, tsk)
}
func (c *FullNodeStruct) StateVerifiedClientStatus(ctx context.Context, addr address.Address, tsk types.TipSetKey) (verifreg.DataCap, error) {
return c.Internal.StateVerifiedClientStatus(ctx, addr, tsk)
}
func (c *FullNodeStruct) MsigGetAvailableBalance(ctx context.Context, a address.Address, tsk types.TipSetKey) (types.BigInt, error) {
return c.Internal.MsigGetAvailableBalance(ctx, a, tsk)
}

View File

@ -316,6 +316,30 @@ var clientDealCmd = &cli.Command{
ref.TransferType = storagemarket.TTManual
}
// Check if the address is a verified client
dcap, err := api.StateVerifiedClientStatus(ctx, a, types.EmptyTSK)
if err != nil {
return err
}
verifiedDeal := false
if !dcap.IsZero() {
verifiedDeal = true
}
// If the user has explicitly set the --verified-deal flag
if cctx.IsSet("verified-deal") {
// If --verified-deal is true, but the address is not a verified
// client, return an error
verifiedDealParam := cctx.Bool("verified-deal")
if verifiedDealParam && dcap.IsZero() {
return xerrors.Errorf("address %s does not have verified client status", a)
}
// Override the default
verifiedDeal = verifiedDealParam
}
proposal, err := api.ClientStartDeal(ctx, &lapi.StartDealParams{
Data: ref,
Wallet: a,
@ -324,7 +348,7 @@ var clientDealCmd = &cli.Command{
MinBlocksDuration: uint64(dur),
DealStartEpoch: abi.ChainEpoch(cctx.Int64("start-epoch")),
FastRetrieval: cctx.Bool("fast-retrieval"),
VerifiedDeal: cctx.Bool("verified-deal"),
VerifiedDeal: verifiedDeal,
})
if err != nil {
return err

View File

@ -299,29 +299,11 @@ var verifRegCheckClientCmd = &cli.Command{
defer closer()
ctx := lcli.ReqContext(cctx)
act, err := api.StateGetActor(ctx, builtin.VerifiedRegistryActorAddr, types.EmptyTSK)
dcap, err := api.StateVerifiedClientStatus(ctx, caddr, types.EmptyTSK)
if err != nil {
return err
}
apibs := apibstore.NewAPIBlockstore(api)
cst := cbor.NewCborStore(apibs)
var st verifreg.State
if err := cst.Get(ctx, act.Head, &st); err != nil {
return err
}
vh, err := hamt.LoadNode(ctx, cst, st.VerifiedClients)
if err != nil {
return err
}
var dcap verifreg.DataCap
if err := vh.Find(ctx, string(caddr.Bytes()), &dcap); err != nil {
return err
}
fmt.Println(dcap)
return nil

View File

@ -4,6 +4,7 @@ import (
"bytes"
"context"
"fmt"
"github.com/filecoin-project/specs-actors/actors/builtin/verifreg"
"strconv"
cid "github.com/ipfs/go-cid"
@ -810,3 +811,34 @@ func (a *StateAPI) StateMinerAvailableBalance(ctx context.Context, maddr address
return types.BigAdd(st.GetAvailableBalance(act.Balance), vested), nil
}
// StateVerifiedClientStatus returns the data cap for the given address, or zero if the client is not registered
func (a *StateAPI) StateVerifiedClientStatus(ctx context.Context, addr address.Address, tsk types.TipSetKey) (verifreg.DataCap, error) {
act, err := a.StateGetActor(ctx, builtin.VerifiedRegistryActorAddr, tsk)
if err != nil {
return verifreg.DataCap{}, err
}
cst := cbor.NewCborStore(a.StateManager.ChainStore().Blockstore())
var st verifreg.State
if err := cst.Get(ctx, act.Head, &st); err != nil {
return verifreg.DataCap{}, err
}
vh, err := hamt.LoadNode(ctx, cst, st.VerifiedClients)
if err != nil {
return verifreg.DataCap{}, err
}
var dcap verifreg.DataCap
if err := vh.Find(ctx, string(addr.Bytes()), &dcap); err != nil {
// If there is no entry in the data cap table, just return zero
if err == hamt.ErrNotFound {
return verifreg.DataCap{}, nil
}
return verifreg.DataCap{}, err
}
return dcap, nil
}