diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml new file mode 100644 index 00000000..6fdb6ba4 --- /dev/null +++ b/.github/workflows/go.yml @@ -0,0 +1,34 @@ +name: Go + +on: + push: + branches: + - master + pull_request: + branches: + - '**' + +jobs: + + build: + runs-on: ubuntu-18.04 + steps: + - uses: actions/checkout@v2 + + - name: Set up Go + uses: actions/setup-go@v2 + with: + go-version: 1.17 + + - name: install deps + run: sudo apt-get install make ftp git bzr curl hwloc libhwloc-dev mesa-opencl-icd ocl-icd-opencl-dev wget -y && sudo apt upgrade -y + + - name: Build + env: + GOPROXY: "https://proxy.golang.org,direct" + GO111MODULE: "on" + run: | + make + + - name: Test + run: go test -v ./... diff --git a/.github/workflows/golangci-lint.yml b/.github/workflows/golangci-lint.yml new file mode 100644 index 00000000..cf03c12a --- /dev/null +++ b/.github/workflows/golangci-lint.yml @@ -0,0 +1,26 @@ +name: golangci-lint + +on: + push: + branches: + - master + pull_request: + branches: + - "**" + +jobs: + golangci: + name: lint + runs-on: ubuntu-18.04 + steps: + - uses: actions/checkout@v2 + + - name: install deps + run: sudo apt-get install make ftp git bzr curl hwloc libhwloc-dev mesa-opencl-icd ocl-icd-opencl-dev wget -y && sudo apt upgrade -y + + - name: Make dep + run: make deps + + - uses: dominikh/staticcheck-action@v1.1.0 + with: + version: "2021.1.1" diff --git a/.github/workflows/tag-workflow.yml b/.github/workflows/tag-workflow.yml index 13ba37de..e4cc1858 100644 --- a/.github/workflows/tag-workflow.yml +++ b/.github/workflows/tag-workflow.yml @@ -99,7 +99,7 @@ jobs: run: sudo apt-get install make ncftp mesa-opencl-icd ocl-icd-opencl-dev gcc git bzr jq pkg-config curl clang build-essential hwloc libhwloc-dev wget -y && sudo apt upgrade -y - name: Build run: | - go clean --modcache && make deps && make + go clean --modcache && make mkdir ./release && mv ./market-client ./venus-market ./release - name: Zip Release diff --git a/Makefile b/Makefile index 6a4b6188..1408f6e8 100644 --- a/Makefile +++ b/Makefile @@ -42,21 +42,15 @@ build-dep/.update-modules: build-dep; git submodule update --init --recursive touch $@ -ffi-version-check: - @[[ "$$(awk '/const Version/{print $$5}' extern/filecoin-ffi/version.go)" -eq 3 ]] || (echo "FFI version mismatch, update submodules"; exit 1) -BUILD_DEPS+=ffi-version-check - -.PHONY: ffi-version-check - - ## build test: - rm -rf models/test_sqlite_db* go test -race ./... lint: $(BUILD_DEPS) - go run github.com/golangci/golangci-lint/cmd/golangci-lint run + staticcheck ./... + +deps: $(BUILD_DEPS) dist-clean: git clean -xdff diff --git a/client/client.go b/client/client.go index 839f89ca..c946521d 100644 --- a/client/client.go +++ b/client/client.go @@ -51,7 +51,6 @@ import ( datatransfer "github.com/filecoin-project/go-data-transfer" "github.com/filecoin-project/go-fil-markets/discovery" "github.com/filecoin-project/go-fil-markets/retrievalmarket" - rm "github.com/filecoin-project/go-fil-markets/retrievalmarket" "github.com/filecoin-project/go-fil-markets/storagemarket" "github.com/filecoin-project/go-fil-markets/storagemarket/network" "github.com/filecoin-project/go-fil-markets/stores" @@ -87,7 +86,7 @@ type API struct { SMDealClient storagemarket.StorageClient RetDiscovery discovery.PeerResolver - Retrieval rm.RetrievalClient + Retrieval retrievalmarket.RetrievalClient // accessors for imports and retrievals. Imports ClientImportMgr @@ -438,12 +437,12 @@ func (a *API) ClientFindData(ctx context.Context, root cid.Cid, piece *cid.Cid) if err != nil { return nil, err } - pp := rm.RetrievalPeer{ + pp := retrievalmarket.RetrievalPeer{ Address: p.Address, ID: *mi.PeerId, } - out = append(out, a.makeRetrievalQuery(ctx, pp, root, piece, rm.QueryParams{})) + out = append(out, a.makeRetrievalQuery(ctx, pp, root, piece, retrievalmarket.QueryParams{})) } return out, nil @@ -454,25 +453,25 @@ func (a *API) ClientMinerQueryOffer(ctx context.Context, miner address.Address, if err != nil { return types.QueryOffer{}, err } - rp := rm.RetrievalPeer{ + rp := retrievalmarket.RetrievalPeer{ Address: miner, ID: *mi.PeerId, } - return a.makeRetrievalQuery(ctx, rp, root, piece, rm.QueryParams{}), nil + return a.makeRetrievalQuery(ctx, rp, root, piece, retrievalmarket.QueryParams{}), nil } -func (a *API) makeRetrievalQuery(ctx context.Context, rp rm.RetrievalPeer, payload cid.Cid, piece *cid.Cid, qp rm.QueryParams) types.QueryOffer { +func (a *API) makeRetrievalQuery(ctx context.Context, rp retrievalmarket.RetrievalPeer, payload cid.Cid, piece *cid.Cid, qp retrievalmarket.QueryParams) types.QueryOffer { queryResponse, err := a.Retrieval.Query(ctx, rp, payload, qp) if err != nil { return types.QueryOffer{Err: err.Error(), Miner: rp.Address, MinerPeer: rp} } var errStr string switch queryResponse.Status { - case rm.QueryResponseAvailable: + case retrievalmarket.QueryResponseAvailable: errStr = "" - case rm.QueryResponseUnavailable: + case retrievalmarket.QueryResponseUnavailable: errStr = fmt.Sprintf("retrieval query offer was unavailable: %s", queryResponse.Message) - case rm.QueryResponseError: + case retrievalmarket.QueryResponseError: errStr = fmt.Sprintf("retrieval query offer errored: %s", queryResponse.Message) } @@ -773,14 +772,14 @@ func (a *API) ClientRetrieve(ctx context.Context, params types.RetrievalOrder) ( }, nil } -func (a *API) doRetrieval(ctx context.Context, order types.RetrievalOrder, sel datamodel.Node) (rm.DealID, error) { +func (a *API) doRetrieval(ctx context.Context, order types.RetrievalOrder, sel datamodel.Node) (retrievalmarket.DealID, error) { if order.MinerPeer == nil || order.MinerPeer.ID == "" { mi, err := a.Full.StateMinerInfo(ctx, order.Miner, vTypes.EmptyTSK) if err != nil { return 0, err } - order.MinerPeer = &rm.RetrievalPeer{ + order.MinerPeer = &retrievalmarket.RetrievalPeer{ ID: *mi.PeerId, Address: order.Miner, } @@ -796,7 +795,7 @@ func (a *API) doRetrieval(ctx context.Context, order types.RetrievalOrder, sel d ppb := vTypes.BigDiv(order.Total, vTypes.NewInt(order.Size)) - params, err := rm.NewParamsV1(ppb, order.PaymentInterval, order.PaymentIntervalIncrease, sel, order.Piece, order.UnsealPrice) + params, err := retrievalmarket.NewParamsV1(ppb, order.PaymentInterval, order.PaymentIntervalIncrease, sel, order.Piece, order.UnsealPrice) if err != nil { return 0, xerrors.Errorf("Error in retrieval params: %s", err) } @@ -820,13 +819,13 @@ func (a *API) doRetrieval(ctx context.Context, order types.RetrievalOrder, sel d return id, nil } -func (a *API) ClientRetrieveWait(ctx context.Context, deal rm.DealID) error { +func (a *API) ClientRetrieveWait(ctx context.Context, deal retrievalmarket.DealID) error { ctx, cancel := context.WithCancel(ctx) defer cancel() - subscribeEvents := make(chan rm.ClientDealState, 1) + subscribeEvents := make(chan retrievalmarket.ClientDealState, 1) - unsubscribe := a.Retrieval.SubscribeToEvents(func(event rm.ClientEvent, state rm.ClientDealState) { + unsubscribe := a.Retrieval.SubscribeToEvents(func(event retrievalmarket.ClientEvent, state retrievalmarket.ClientDealState) { // We'll check the deal IDs inside consumeAllEvents. if state.ID != deal { return @@ -855,15 +854,15 @@ func (a *API) ClientRetrieveWait(ctx context.Context, deal rm.DealID) error { return xerrors.New("Retrieval Timed Out") case state := <-subscribeEvents: switch state.Status { - case rm.DealStatusCompleted: + case retrievalmarket.DealStatusCompleted: return nil - case rm.DealStatusRejected: + case retrievalmarket.DealStatusRejected: return xerrors.Errorf("Retrieval Proposal Rejected: %s", state.Message) - case rm.DealStatusCancelled: + case retrievalmarket.DealStatusCancelled: return xerrors.Errorf("Retrieval was cancelled externally: %s", state.Message) case - rm.DealStatusDealNotFound, - rm.DealStatusErrored: + retrievalmarket.DealStatusDealNotFound, + retrievalmarket.DealStatusErrored: return xerrors.Errorf("Retrieval Error: %s", state.Message) } } @@ -1187,7 +1186,7 @@ func (a *API) ClientListRetrievals(ctx context.Context) ([]types.RetrievalInfo, func (a *API) ClientGetRetrievalUpdates(ctx context.Context) (<-chan types.RetrievalInfo, error) { updates := make(chan types.RetrievalInfo) - unsub := a.Retrieval.SubscribeToEvents(func(_ rm.ClientEvent, deal rm.ClientDealState) { + unsub := a.Retrieval.SubscribeToEvents(func(_ retrievalmarket.ClientEvent, deal retrievalmarket.ClientDealState) { updates <- a.newRetrievalInfo(ctx, deal) }) @@ -1199,7 +1198,7 @@ func (a *API) ClientGetRetrievalUpdates(ctx context.Context) (<-chan types.Retri return updates, nil } -func (a *API) newRetrievalInfoWithTransfer(ch *types2.DataTransferChannel, deal rm.ClientDealState) types.RetrievalInfo { +func (a *API) newRetrievalInfoWithTransfer(ch *types2.DataTransferChannel, deal retrievalmarket.ClientDealState) types.RetrievalInfo { return types.RetrievalInfo{ PayloadCID: deal.PayloadCID, ID: deal.ID, @@ -1217,7 +1216,7 @@ func (a *API) newRetrievalInfoWithTransfer(ch *types2.DataTransferChannel, deal } } -func (a *API) newRetrievalInfo(ctx context.Context, v rm.ClientDealState) types.RetrievalInfo { +func (a *API) newRetrievalInfo(ctx context.Context, v retrievalmarket.ClientDealState) types.RetrievalInfo { // Find the data transfer associated with this deal var transferCh *types2.DataTransferChannel if v.ChannelID != nil { diff --git a/cmd/market-client/transfer.go b/cmd/market-client/transfer.go index 739771c9..6f9686ec 100644 --- a/cmd/market-client/transfer.go +++ b/cmd/market-client/transfer.go @@ -144,7 +144,7 @@ var transferRestartCmd = &cli.Command{ transferUint, err := strconv.ParseUint(cctx.Args().First(), 10, 64) if err != nil { - return fmt.Errorf("Error reading transfer ID: %w", err) + return fmt.Errorf("error reading transfer ID: %w", err) } transferID := datatransfer.TransferID(transferUint) initiator := cctx.Bool("initiator") @@ -209,7 +209,7 @@ var transferCancelCmd = &cli.Command{ transferUint, err := strconv.ParseUint(cctx.Args().First(), 10, 64) if err != nil { - return fmt.Errorf("Error reading transfer ID: %w", err) + return fmt.Errorf("error reading transfer ID: %w", err) } transferID := datatransfer.TransferID(transferUint) initiator := cctx.Bool("initiator") diff --git a/fundmgr/fundmanager.go b/fundmgr/fundmanager.go index b374b5f0..944e2cc0 100644 --- a/fundmgr/fundmanager.go +++ b/fundmgr/fundmanager.go @@ -241,7 +241,8 @@ func (a *fundedAddress) requestAndWait(ctx context.Context, wallet address.Addre } // Used by the tests -func (a *fundedAddress) onProcessStart(fn func() bool) { // nolint +//lint:ignore U1000 ingore this for now +func (a *fundedAddress) onProcessStart(fn func() bool) { a.lk.Lock() defer a.lk.Unlock() diff --git a/go.mod b/go.mod index ed0b15d1..81ff01d8 100644 --- a/go.mod +++ b/go.mod @@ -93,6 +93,7 @@ require ( go.uber.org/multierr v1.7.0 go.uber.org/zap v1.19.1 golang.org/x/sync v0.0.0-20210220032951-036812b2e83c + golang.org/x/tools v0.1.9 // indirect golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 gorm.io/driver/mysql v1.1.1 gorm.io/gorm v1.21.12 @@ -101,5 +102,4 @@ require ( replace ( github.com/filecoin-project/filecoin-ffi => ./extern/filecoin-ffi github.com/filecoin-project/go-jsonrpc => github.com/ipfs-force-community/go-jsonrpc v0.1.4-0.20210721095535-a67dff16de21 - github.com/ipfs/go-ipfs-cmds => github.com/ipfs-force-community/go-ipfs-cmds v0.6.1-0.20210521090123-4587df7fa0ab ) diff --git a/go.sum b/go.sum index cfe0fa89..077195d8 100644 --- a/go.sum +++ b/go.sum @@ -1037,7 +1037,6 @@ github.com/influxdata/influxdb1-client v0.0.0-20200827194710-b269163b24ab/go.mod github.com/influxdata/line-protocol v0.0.0-20200327222509-2487e7298839 h1:W9WBk7wlPfJLvMCdtV4zPulc4uCPrlywQOmbFOhgQNU= github.com/influxdata/line-protocol v0.0.0-20200327222509-2487e7298839/go.mod h1:xaLFMmpvUxqXtVkUJfg9QmT88cDaCJ3ZKgdZ78oO8Qo= github.com/intel/goresctrl v0.2.0/go.mod h1:+CZdzouYFn5EsxgqAQTEzMfwKwuc0fVdMrT9FCCAVRQ= -github.com/ipfs-force-community/go-ipfs-cmds v0.6.1-0.20210521090123-4587df7fa0ab/go.mod h1:ZgYiWVnCk43ChwoH8hAmI1IRbuVtq3GSTHwtRB/Kqhk= github.com/ipfs-force-community/go-jsonrpc v0.1.4-0.20210721095535-a67dff16de21 h1:ht754GJKTx1uYy4gYUhJxxefhKqxReo/654URuB+Ksk= github.com/ipfs-force-community/go-jsonrpc v0.1.4-0.20210721095535-a67dff16de21/go.mod h1:XBBpuKIMaXIIzeqzO1iucq4GvbF8CxmXRFoezRh+Cx4= github.com/ipfs-force-community/metrics v1.0.0/go.mod h1:mn40SioMuKtjmRumHFy/fJ26Pn028XuDjUJE9dorjyw= @@ -1130,6 +1129,7 @@ github.com/ipfs/go-ipfs-chunker v0.0.1/go.mod h1:tWewYK0we3+rMbOh7pPFGDyypCtvGcB github.com/ipfs/go-ipfs-chunker v0.0.5 h1:ojCf7HV/m+uS2vhUGWcogIIxiO5ubl5O57Q7NapWLY8= github.com/ipfs/go-ipfs-chunker v0.0.5/go.mod h1:jhgdF8vxRHycr00k13FM8Y0E+6BoalYeobXmUyTreP8= github.com/ipfs/go-ipfs-cmdkit v0.0.1/go.mod h1:9FtbMdUabcSqv/G4/8WCxSLxkZxn/aZEFrxxqnVcRbg= +github.com/ipfs/go-ipfs-cmds v0.6.1-0.20220212012746-40b8fddb899f/go.mod h1:y0bflH6m4g6ary4HniYt98UqbrVnRxmRarzeMdLIUn0= github.com/ipfs/go-ipfs-delay v0.0.0-20181109222059-70721b86a9a8/go.mod h1:8SP1YXK1M1kXuc4KJZINY3TQQ03J2rwBG9QfXmbRPrw= github.com/ipfs/go-ipfs-delay v0.0.1 h1:r/UXYyRcddO6thwOnhiznIAiSvxMECGgtv35Xs1IeRQ= github.com/ipfs/go-ipfs-delay v0.0.1/go.mod h1:8SP1YXK1M1kXuc4KJZINY3TQQ03J2rwBG9QfXmbRPrw= @@ -2454,6 +2454,7 @@ github.com/yuin/goldmark v1.1.32/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9de github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k= github.com/yuin/goldmark v1.4.0/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k= +github.com/yuin/goldmark v1.4.1/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k= github.com/yvasiyarov/go-metrics v0.0.0-20140926110328-57bccd1ccd43/go.mod h1:aX5oPXxHm3bOH+xeAttToC8pqch2ScQN/JoXYupl6xs= github.com/yvasiyarov/gorelic v0.0.0-20141212073537-a9bba5b9ab50/go.mod h1:NUSPSUX/bi6SeDMUh6brw0nXpxHnc96TguQh0+r/ssA= github.com/yvasiyarov/newrelic_platform_go v0.0.0-20140908184405-b21fdbd4370f/go.mod h1:GlGEuHIJweS1mbCqG+7vt2nvWLzLLnRHbXz5JKd/Qbg= @@ -2670,8 +2671,9 @@ golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.4.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.4.1/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= -golang.org/x/mod v0.5.0 h1:UG21uOlmZabA4fW5i7ZX6bjw1xELEGg/ZLgZq9auk/Q= golang.org/x/mod v0.5.0/go.mod h1:5OXOZSfqPIIbmVBIIKWRFfZjPR0E5r58TLhUjH0a2Ro= +golang.org/x/mod v0.5.1 h1:OJxoQ/rynoF0dcCdI7cLPktw/hR2cueqYfjm43oqK38= +golang.org/x/mod v0.5.1/go.mod h1:5OXOZSfqPIIbmVBIIKWRFfZjPR0E5r58TLhUjH0a2Ro= golang.org/x/net v0.0.0-20180719180050-a680a1efc54d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= @@ -2747,6 +2749,7 @@ golang.org/x/net v0.0.0-20210805182204-aaa1db679c0d/go.mod h1:9nx3DQGgdP8bBQD5qx golang.org/x/net v0.0.0-20210813160813-60bc85c4be6d/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/net v0.0.0-20210825183410-e898025ed96a/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/net v0.0.0-20210917221730-978cfadd31cf/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= +golang.org/x/net v0.0.0-20211015210444-4f30a5c0130f/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/net v0.0.0-20211209124913-491a49abca63/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/net v0.0.0-20211216030914-fe4d6282115f h1:hEYJvxw1lSnWIl8X9ofsYMklzaDs90JI2az5YMd4fPM= golang.org/x/net v0.0.0-20211216030914-fe4d6282115f/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= @@ -2921,6 +2924,7 @@ golang.org/x/sys v0.0.0-20210903071746-97244b99971b/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.0.0-20210906170528-6f6e22806c34/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210917161153-d61c044b1678/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210927094055-39ccf1dd6fa6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20211019181941-9d821ace8654/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20211025201205-69cdffdb9359/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20211116061358-0a5406a5449c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e h1:fLOSk5Q00efkSvAm+4xcoXD+RRmLmmulPn5I3Y9F2EM= @@ -3067,8 +3071,9 @@ golang.org/x/tools v0.1.2/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= golang.org/x/tools v0.1.3/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= golang.org/x/tools v0.1.4/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= golang.org/x/tools v0.1.5/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= -golang.org/x/tools v0.1.7 h1:6j8CgantCy3yc8JGBqkDLMKWqZ0RDU2g1HVgacojGWQ= golang.org/x/tools v0.1.7/go.mod h1:LGqMHiF4EqQNHR1JncWGqT5BVaXmza+X+BDGol+dOxo= +golang.org/x/tools v0.1.9 h1:j9KsMiaP1c3B0OTQGth0/k+miLGTgLsAFUCrF2vLcF8= +golang.org/x/tools v0.1.9/go.mod h1:nABZi5QlRsZVlzPpHl034qft6wpY4eDcsTt5AaioBiU= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= diff --git a/minermgr/minermgr.go b/minermgr/minermgr.go index f2c0fe23..38865009 100644 --- a/minermgr/minermgr.go +++ b/minermgr/minermgr.go @@ -262,21 +262,17 @@ func (m *UserMgrImpl) distAddress(ctx context.Context, addrs ...types.User) erro func (m *UserMgrImpl) refreshUsers(ctx context.Context) { tm := time.NewTicker(time.Minute) defer tm.Stop() - for { - select { - case <-tm.C: - miners, err := m.getMinerFromVenusAuth(context.TODO(), 0, 0) - if err != nil { - log.Errorf("unable to get venus miner from venus auth %s", err) - } + for range tm.C { + miners, err := m.getMinerFromVenusAuth(context.TODO(), 0, 0) + if err != nil { + log.Errorf("unable to get venus miner from venus auth %s", err) + } - err = m.distAddress(ctx, miners...) - if err != nil { - log.Errorf("unable to append new user to address manager %s", err) - } + err = m.distAddress(ctx, miners...) + if err != nil { + log.Errorf("unable to append new user to address manager %s", err) } } - } func convertConfigAddress(addrs []config.User) []types.User { addrs2 := make([]types.User, len(addrs)) diff --git a/piecestorage/protocol.go b/piecestorage/protocol.go index 3b784b8a..a430dda8 100644 --- a/piecestorage/protocol.go +++ b/piecestorage/protocol.go @@ -131,7 +131,7 @@ func ParserProtocol(pro string, cfg interface{}) error { func lookupMethod(val reflect.Type, name string) (string, error) { for i := 0; i < val.NumField(); i++ { - if strings.ToLower(val.Field(i).Name) == strings.ToLower(name) { + if strings.EqualFold(val.Field(i).Name, name) { return val.Field(i).Name, nil } } diff --git a/piecestorage/s3.go b/piecestorage/s3.go index 23f2b7f5..392adb19 100644 --- a/piecestorage/s3.go +++ b/piecestorage/s3.go @@ -14,7 +14,6 @@ import ( "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/s3" "github.com/aws/aws-sdk-go/service/s3/s3manager" - _ "github.com/aws/aws-sdk-go/service/s3/s3manager" "github.com/filecoin-project/venus-market/config" "github.com/filecoin-project/venus-market/utils" logging "github.com/ipfs/go-log/v2" @@ -75,11 +74,10 @@ func ParseS3Endpoint(endPoint string) (string, string, string, error) { } type s3PieceStorage struct { - s3Cfg config.S3PieceStorage - bucket string - s3Client *s3.S3 - uploader *s3manager.Uploader - downloader *s3manager.Downloader + s3Cfg config.S3PieceStorage + bucket string + s3Client *s3.S3 + uploader *s3manager.Uploader } func newS3PieceStorage(s3Cfg config.S3PieceStorage) (IPieceStorage, error) { diff --git a/retrievalprovider/provider_environments.go b/retrievalprovider/provider_environments.go index 070e9b76..89b16ebf 100644 --- a/retrievalprovider/provider_environments.go +++ b/retrievalprovider/provider_environments.go @@ -23,16 +23,16 @@ import ( // CheckDealParams verifies the given deal params are acceptable func CheckDealParams(ask *types.RetrievalAsk, pricePerByte abi.TokenAmount, paymentInterval uint64, paymentIntervalIncrease uint64, unsealPrice abi.TokenAmount) error { if pricePerByte.LessThan(ask.PricePerByte) { - return errors.New("Price per byte too low") + return errors.New("price per byte too low") } if paymentInterval > ask.PaymentInterval { - return errors.New("Payment interval too large") + return errors.New("payment interval too large") } if paymentIntervalIncrease > ask.PaymentIntervalIncrease { - return errors.New("Payment interval increase too large") + return errors.New("payment interval increase too large") } if !ask.UnsealPrice.Nil() && unsealPrice.LessThan(ask.UnsealPrice) { - return errors.New("Unseal price too small") + return errors.New("unseal price too small") } return nil } diff --git a/retrievalprovider/requestvalidation.go b/retrievalprovider/requestvalidation.go index ce445d2f..aa209f07 100644 --- a/retrievalprovider/requestvalidation.go +++ b/retrievalprovider/requestvalidation.go @@ -50,7 +50,7 @@ func NewProviderRequestValidator(paymentAddr address.Address, storageDeals repo. // ValidatePush validates a push request received from the peer that will send data func (rv *ProviderRequestValidator) ValidatePush(isRestart bool, _ datatransfer.ChannelID, sender peer.ID, voucher datatransfer.Voucher, baseCid cid.Cid, selector ipld.Node) (datatransfer.VoucherResult, error) { - return nil, errors.New("No pushes accepted") + return nil, errors.New("no pushes accepted") } // ValidatePull validates a pull request received from the peer that will receive data diff --git a/retrievalprovider/revalidator.go b/retrievalprovider/revalidator.go index 65c55913..901c415e 100644 --- a/retrievalprovider/revalidator.go +++ b/retrievalprovider/revalidator.go @@ -13,7 +13,6 @@ import ( types "github.com/filecoin-project/venus/venus-shared/types/market" "github.com/filecoin-project/go-fil-markets/retrievalmarket" - rm "github.com/filecoin-project/go-fil-markets/retrievalmarket" "github.com/filecoin-project/go-fil-markets/retrievalmarket/migrations" ) @@ -39,7 +38,7 @@ func NewProviderRevalidator(fullNode v1api.FullNode, payAPI *paychmgr.PaychAPI, // Revalidate revalidates a request with a new voucher func (pr *ProviderRevalidator) Revalidate(channelID datatransfer.ChannelID, voucher datatransfer.Voucher) (datatransfer.VoucherResult, error) { // read payment, or fail - payment, ok := voucher.(*rm.DealPayment) + payment, ok := voucher.(*retrievalmarket.DealPayment) var legacyProtocol bool if !ok { legacyPayment, ok := voucher.(*migrations.DealPayment0) @@ -67,7 +66,7 @@ func (pr *ProviderRevalidator) Revalidate(channelID datatransfer.ChannelID, vouc } -func (pr *ProviderRevalidator) processPayment(ctx context.Context, deal *types.ProviderDealState, payment *rm.DealPayment) (*retrievalmarket.DealResponse, error) { +func (pr *ProviderRevalidator) processPayment(ctx context.Context, deal *types.ProviderDealState, payment *retrievalmarket.DealPayment) (*retrievalmarket.DealResponse, error) { // Save voucher received, err := pr.payAPI.PaychVoucherAdd(context.TODO(), payment.PaymentChannel, payment.PaymentVoucher, nil, big.Zero()) if err != nil { @@ -93,7 +92,7 @@ func (pr *ProviderRevalidator) processPayment(ctx context.Context, deal *types.P _ = pr.retrievalDealHandler.CancelDeal(ctx, deal) return errorDealResponse(deal.Identifier(), err), err } - return &rm.DealResponse{ + return &retrievalmarket.DealResponse{ ID: deal.ID, Status: deal.Status, PaymentOwed: owed, @@ -103,31 +102,31 @@ func (pr *ProviderRevalidator) processPayment(ctx context.Context, deal *types.P // resume deal deal.FundsReceived = big.Add(deal.FundsReceived, received) // only update interval if the payment is for bytes and not for unsealing. - if deal.Status != rm.DealStatusFundsNeededUnseal { + if deal.Status != retrievalmarket.DealStatusFundsNeededUnseal { deal.CurrentInterval = deal.NextInterval() } var resp *retrievalmarket.DealResponse err = datatransfer.ErrResume switch deal.Status { - case rm.DealStatusFundsNeeded: - deal.Status = rm.DealStatusOngoing - case rm.DealStatusFundsNeededLastPayment: - deal.Status = rm.DealStatusFinalizing + case retrievalmarket.DealStatusFundsNeeded: + deal.Status = retrievalmarket.DealStatusOngoing + case retrievalmarket.DealStatusFundsNeededLastPayment: + deal.Status = retrievalmarket.DealStatusFinalizing log.Infof("provider: funds needed: last payment") - resp = &rm.DealResponse{ + resp = &retrievalmarket.DealResponse{ ID: deal.ID, - Status: rm.DealStatusCompleted, + Status: retrievalmarket.DealStatusCompleted, } //not start transfer data is unsealing - case rm.DealStatusFundsNeededUnseal: + case retrievalmarket.DealStatusFundsNeededUnseal: //pay for unseal goto unseal - deal.Status = rm.DealStatusUnsealing + deal.Status = retrievalmarket.DealStatusUnsealing defer func() { go pr.retrievalDealHandler.UnsealData(ctx, deal) //nolint }() err = nil - case rm.DealStatusUnsealing: + case retrievalmarket.DealStatusUnsealing: err = nil } @@ -170,11 +169,11 @@ func paymentOwed(deal *types.ProviderDealState, totalPaid big.Int) big.Int { return owed } -func errorDealResponse(dealID rm.ProviderDealIdentifier, err error) *rm.DealResponse { - return &rm.DealResponse{ +func errorDealResponse(dealID retrievalmarket.ProviderDealIdentifier, err error) *retrievalmarket.DealResponse { + return &retrievalmarket.DealResponse{ ID: dealID.DealID, Message: err.Error(), - Status: rm.DealStatusErrored, + Status: retrievalmarket.DealStatusErrored, } } @@ -201,7 +200,7 @@ func (pr *ProviderRevalidator) OnPullDataSent(chid datatransfer.ChannelID, addit if !deal.PricePerByte.IsZero() { log.Debugf("provider: total sent %d < interval %d, sending block", totalSent, deal.CurrentInterval) } - deal.Status = rm.DealStatusOngoing + deal.Status = retrievalmarket.DealStatusOngoing deal.TotalSent = totalSent return true, nil, pr.deals.SaveDeal(ctx, deal) } @@ -213,14 +212,14 @@ func (pr *ProviderRevalidator) OnPullDataSent(chid datatransfer.ChannelID, addit deal.TotalSent = totalSent // Request payment switch deal.Status { - case rm.DealStatusOngoing, rm.DealStatusUnsealed: - deal.Status = rm.DealStatusFundsNeeded - case rm.DealStatusFundsNeeded: + case retrievalmarket.DealStatusOngoing, retrievalmarket.DealStatusUnsealed: + deal.Status = retrievalmarket.DealStatusFundsNeeded + case retrievalmarket.DealStatusFundsNeeded: //doing nothing - case rm.DealStatusBlocksComplete: - deal.Status = rm.DealStatusFundsNeededLastPayment - case rm.DealStatusNew: - deal.Status = rm.DealStatusFundsNeededUnseal + case retrievalmarket.DealStatusBlocksComplete: + deal.Status = retrievalmarket.DealStatusFundsNeededLastPayment + case retrievalmarket.DealStatusNew: + deal.Status = retrievalmarket.DealStatusFundsNeededUnseal } err = pr.deals.SaveDeal(ctx, deal) @@ -228,9 +227,9 @@ func (pr *ProviderRevalidator) OnPullDataSent(chid datatransfer.ChannelID, addit return true, nil, err } - return true, finalResponse(&rm.DealResponse{ + return true, finalResponse(&retrievalmarket.DealResponse{ ID: deal.DealProposal.ID, - Status: rm.DealStatusFundsNeeded, + Status: retrievalmarket.DealStatusFundsNeeded, PaymentOwed: paymentOwed, }, deal.LegacyProtocol), datatransfer.ErrPause } @@ -257,7 +256,7 @@ func (pr *ProviderRevalidator) OnComplete(chid datatransfer.ChannelID) (bool, da return true, nil, err } - deal.Status = rm.DealStatusBlocksComplete + deal.Status = retrievalmarket.DealStatusBlocksComplete err = pr.deals.SaveDeal(ctx, deal) if err != nil { return true, nil, err @@ -269,30 +268,30 @@ func (pr *ProviderRevalidator) OnComplete(chid datatransfer.ChannelID) (bool, da paymentOwed := big.Mul(abi.NewTokenAmount(int64(totalSent-totalPaidFor)), deal.PricePerByte) if paymentOwed.Equals(big.Zero()) { log.Infof("OnComplete xxxx") - return true, finalResponse(&rm.DealResponse{ + return true, finalResponse(&retrievalmarket.DealResponse{ ID: deal.DealProposal.ID, - Status: rm.DealStatusCompleted, + Status: retrievalmarket.DealStatusCompleted, }, deal.LegacyProtocol), nil } // Send a request for payment log.Debugf("provider: last payment owed %d = (total sent %d - paid for %d) * price per byte %d", paymentOwed, totalSent, totalPaidFor, deal.PricePerByte) - deal.Status = rm.DealStatusFundsNeededLastPayment + deal.Status = retrievalmarket.DealStatusFundsNeededLastPayment deal.TotalSent = totalSent err = pr.deals.SaveDeal(ctx, deal) if err != nil { return true, nil, err } - return true, finalResponse(&rm.DealResponse{ + return true, finalResponse(&retrievalmarket.DealResponse{ ID: deal.DealProposal.ID, - Status: rm.DealStatusFundsNeededLastPayment, + Status: retrievalmarket.DealStatusFundsNeededLastPayment, PaymentOwed: paymentOwed, }, deal.LegacyProtocol), datatransfer.ErrPause } -func finalResponse(response *rm.DealResponse, legacyProtocol bool) datatransfer.Voucher { +func finalResponse(response *retrievalmarket.DealResponse, legacyProtocol bool) datatransfer.Voucher { if response == nil { return nil } diff --git a/storageprovider/deal_handler.go b/storageprovider/deal_handler.go index 9cc48cda..8373ea76 100644 --- a/storageprovider/deal_handler.go +++ b/storageprovider/deal_handler.go @@ -26,7 +26,6 @@ import ( "github.com/filecoin-project/go-state-types/big" "github.com/filecoin-project/go-state-types/exitcode" "github.com/filecoin-project/specs-actors/v7/actors/builtin/market" - market7 "github.com/filecoin-project/specs-actors/v7/actors/builtin/market" "github.com/filecoin-project/specs-actors/v7/actors/builtin/miner" minermgr2 "github.com/filecoin-project/venus-market/minermgr" @@ -156,7 +155,7 @@ func (storageDealPorcess *StorageDealProcessImpl) AcceptDeal(ctx context.Context // Check that the delta between the start and end epochs (the deal // duration) is within acceptable bounds - minDuration, maxDuration := market7.DealDurationBounds(proposal.PieceSize) + minDuration, maxDuration := market.DealDurationBounds(proposal.PieceSize) if proposal.Duration() < minDuration || proposal.Duration() > maxDuration { return storageDealPorcess.HandleReject(ctx, minerDeal, storagemarket.StorageDealRejecting, xerrors.Errorf("deal duration out of bounds (min, max, provided): %d, %d, %d", minDuration, maxDuration, proposal.Duration())) } diff --git a/storageprovider/provider.go b/storageprovider/provider.go index 7fe8b22c..844f3c8c 100644 --- a/storageprovider/provider.go +++ b/storageprovider/provider.go @@ -24,7 +24,6 @@ import ( "github.com/filecoin-project/venus/pkg/constants" vCrypto "github.com/filecoin-project/venus/pkg/crypto" - "github.com/filecoin-project/venus/pkg/events" "github.com/filecoin-project/venus/pkg/events/state" "github.com/filecoin-project/venus/venus-shared/actors/builtin/market" "github.com/filecoin-project/venus/venus-shared/actors/builtin/miner" @@ -46,7 +45,6 @@ type ProviderNodeAdapter struct { fundMgr *fundmgr.FundManager msgClient clients.IMixMessage - ev *events.Events dealPublisher *DealPublisher