From 8489fb258a5948a9e892cde985a5d9a458a1d58a Mon Sep 17 00:00:00 2001 From: Dirk McCormick Date: Thu, 2 Jul 2020 14:49:08 -0400 Subject: [PATCH] fix: return NotFoundErr from StateVerifiedClientStatus() if addr not found --- api/api_full.go | 3 +++ cli/client.go | 18 ++++++++---------- node/impl/full/state.go | 7 ++++--- 3 files changed, 15 insertions(+), 13 deletions(-) diff --git a/api/api_full.go b/api/api_full.go index 5b36d2241..ea6aed7fc 100644 --- a/api/api_full.go +++ b/api/api_full.go @@ -2,6 +2,7 @@ package api import ( "context" + "golang.org/x/xerrors" "time" "github.com/filecoin-project/specs-actors/actors/builtin/verifreg" @@ -535,3 +536,5 @@ type Fault struct { Miner address.Address Epoch abi.ChainEpoch } + +var NotFoundErr = xerrors.Errorf("Not found") diff --git a/cli/client.go b/cli/client.go index 30300fcf0..7432105cd 100644 --- a/cli/client.go +++ b/cli/client.go @@ -317,27 +317,25 @@ var clientDealCmd = &cli.Command{ } // Check if the address is a verified client - dcap, err := api.StateVerifiedClientStatus(ctx, a, types.EmptyTSK) - if err != nil { + _, err = api.StateVerifiedClientStatus(ctx, a, types.EmptyTSK) + isVerified := true + if err == lapi.NotFoundErr { + isVerified = false + } else 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() { + if verifiedDealParam && !isVerified { return xerrors.Errorf("address %s does not have verified client status", a) } // Override the default - verifiedDeal = verifiedDealParam + isVerified = verifiedDealParam } proposal, err := api.ClientStartDeal(ctx, &lapi.StartDealParams{ @@ -348,7 +346,7 @@ var clientDealCmd = &cli.Command{ MinBlocksDuration: uint64(dur), DealStartEpoch: abi.ChainEpoch(cctx.Int64("start-epoch")), FastRetrieval: cctx.Bool("fast-retrieval"), - VerifiedDeal: verifiedDeal, + VerifiedDeal: isVerified, }) if err != nil { return err diff --git a/node/impl/full/state.go b/node/impl/full/state.go index f1f1c06cb..d18c76d3c 100644 --- a/node/impl/full/state.go +++ b/node/impl/full/state.go @@ -812,7 +812,9 @@ 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 +// 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) { act, err := a.StateGetActor(ctx, builtin.VerifiedRegistryActorAddr, tsk) if err != nil { @@ -833,9 +835,8 @@ func (a *StateAPI) StateVerifiedClientStatus(ctx context.Context, addr address.A 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{}, api.NotFoundErr } return verifreg.DataCap{}, err }