fix: return NotFoundErr from StateVerifiedClientStatus() if addr not found

This commit is contained in:
Dirk McCormick 2020-07-02 14:49:08 -04:00
parent 2c7aa318c1
commit 8489fb258a
3 changed files with 15 additions and 13 deletions

View File

@ -2,6 +2,7 @@ package api
import ( import (
"context" "context"
"golang.org/x/xerrors"
"time" "time"
"github.com/filecoin-project/specs-actors/actors/builtin/verifreg" "github.com/filecoin-project/specs-actors/actors/builtin/verifreg"
@ -535,3 +536,5 @@ type Fault struct {
Miner address.Address Miner address.Address
Epoch abi.ChainEpoch Epoch abi.ChainEpoch
} }
var NotFoundErr = xerrors.Errorf("Not found")

View File

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

View File

@ -812,7 +812,9 @@ func (a *StateAPI) StateMinerAvailableBalance(ctx context.Context, maddr address
return types.BigAdd(st.GetAvailableBalance(act.Balance), vested), nil 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 // StateVerifiedClientStatus returns the data cap for the given address.
// Returns ErrNotFound if there is not entry in the data cap table for the
// address.
func (a *StateAPI) StateVerifiedClientStatus(ctx context.Context, addr address.Address, tsk types.TipSetKey) (verifreg.DataCap, error) { func (a *StateAPI) StateVerifiedClientStatus(ctx context.Context, addr address.Address, tsk types.TipSetKey) (verifreg.DataCap, error) {
act, err := a.StateGetActor(ctx, builtin.VerifiedRegistryActorAddr, tsk) act, err := a.StateGetActor(ctx, builtin.VerifiedRegistryActorAddr, tsk)
if err != nil { if err != nil {
@ -833,9 +835,8 @@ func (a *StateAPI) StateVerifiedClientStatus(ctx context.Context, addr address.A
var dcap verifreg.DataCap var dcap verifreg.DataCap
if err := vh.Find(ctx, string(addr.Bytes()), &dcap); err != nil { 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 { if err == hamt.ErrNotFound {
return verifreg.DataCap{}, nil return verifreg.DataCap{}, api.NotFoundErr
} }
return verifreg.DataCap{}, err return verifreg.DataCap{}, err
} }