Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New: support to import deals using Boost #187

Merged
merged 38 commits into from
Jan 5, 2023
Merged
Show file tree
Hide file tree
Changes from 32 commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
efb889c
Merge pull request #183 from filswan/release-2.0.0
Normalnoise Sep 28, 2022
f306519
Update README-CN.md
Normalnoise Sep 28, 2022
068096b
replace go-swan-lib to local
Dec 13, 2022
444fa3c
New: support boost
Dec 14, 2022
7a74a66
Improve: build check
Dec 14, 2022
af3de74
New: add graphql client
Dec 16, 2022
8c0ec55
New: init and start boostd
Dec 19, 2022
4286b95
Improve: fix import cycle
Dec 19, 2022
fd71ce6
Improve: add ffi
Dec 19, 2022
ad6f2c8
Improve: replace ffi
Dec 26, 2022
4cedf76
Improve: delete ulimit
Dec 26, 2022
e827a78
Improve: modify init boostd
Dec 26, 2022
d1f40f3
Improve: modify init boostd
Dec 26, 2022
2efdcf8
Improve: modify start boostd
Dec 27, 2022
056d1af
Improve: modify start boostd
Dec 27, 2022
6a4a530
Improve: modify start boostd
Dec 27, 2022
e6d9305
Improve: modify start boostd
Dec 28, 2022
bc84987
Improve: add log
Dec 28, 2022
1dfeb3d
Improve: add log
Dec 28, 2022
5782c13
Improve: fix nil pointer
Dec 28, 2022
da67892
Improve: update boost token
Dec 28, 2022
da8e97e
Improve: get boost token
Dec 28, 2022
d09be0e
Improve: modify http server
Dec 28, 2022
d41b4a1
Improve: modify http server
Dec 28, 2022
b035791
Improve: modify deal status
Dec 29, 2022
c513f33
Improve: modify deal status
Dec 29, 2022
0587da4
Improve: modify deal status
Dec 29, 2022
e389d33
Improve: log format
Dec 29, 2022
366adfd
Improve: log format
Jan 2, 2023
1c669b9
Improve: log format
Jan 2, 2023
18e66bc
Improve: log format
Jan 2, 2023
6a42b64
Improve: delete log
Jan 3, 2023
b2b497e
Improve: update go-swan-lib
Jan 3, 2023
b2d9ec1
Merge pull request #5 from sonic-chain/boost
Normalnoise Jan 3, 2023
0a0c8f4
Merge branch 'releases' into main
sonic-chain Jan 4, 2023
baf4e8b
Update common.go
sonic-chain Jan 4, 2023
49bc51b
Update common.go
sonic-chain Jan 4, 2023
4a68abf
Update common.go
sonic-chain Jan 4, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "extern/filecoin-ffi"]
path = extern/filecoin-ffi
url = https://github.com/filecoin-project/filecoin-ffi.git
13 changes: 12 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,18 @@ BINARY_NAME=$(PROJECT_NAME)
PKG := "$(PROJECT_NAME)"
PKG_LIST := $(shell go list ${PKG}/... | grep -v /vendor/)

.PHONY: all build clean test help
.PHONY: all ffi build clean test help

all: build

test: ## Run unittests
@go test -short ${PKG_LIST}
@echo "Done testing."

ffi:
./extern/filecoin-ffi/install-filcrypto
.PHONY: ffi

build: ## Build the binary file
@go mod download
@go mod tidy
Expand All @@ -40,3 +44,10 @@ build-linux:
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 $(GOBUILD) -o $(GOBIN)/$(BINARY_NAME) -v main.go
build_win: test
CGO_ENABLED=0 GOOS=windows GOARCH=amd64 $(GOBUILD) -o $(GOBIN)/$(BINARY_NAME) -v main.go

build_boost:
git clone https://github.com/filecoin-project/boost
cd boost && git checkout v1.5.0
cd boost && make build && sudo mv boostd /usr/local/bin/
rm -rf boost
.PHONY: build_boost
3 changes: 3 additions & 0 deletions build_from_source.sh
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ sudo systemctl restart aria2c.service # Start Aria2

BINARY_NAME=swan-provider

git submodule update --init --recursive
make build_boost
make ffi
make
chmod +x ./build/${BINARY_NAME}
./build/${BINARY_NAME} daemon # Run swan provider
Expand Down
11 changes: 11 additions & 0 deletions common/constants/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,15 @@ const (

UPDATE_OFFLINE_DEAL_STATUS_FAIL = "failed to update offline deal status"
NOT_UPDATE_OFFLINE_DEAL_STATUS = "no need to update deal status in swan"

CHECKPOINT_ACCEPTED = "Accepted"
CHECKPOINT_TRANSFERRED = "Transferred"
CHECKPOINT_PULISHED = "Published"
CHECKPOINT_CONFIRMED = "PublishConfirmed"
CHECKPOINT_ADDPIECE = "AddedPiece"
CHECKPOINT_INDEX = "IndexedAndAnnounced"
CHECKPOINT_COMPLETE = "Complete"

MARKET_TYPE_LOTUS = "lotus"
MARKET_TYPE_BOOST = "boost"
)
87 changes: 87 additions & 0 deletions common/hql/client.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
package hql

import (
"context"
"errors"
"github.com/Khan/genqlient/graphql"
"net/http"
"swan-provider/common/hql/gen"
)

type Client struct {
hqlClient graphql.Client
}

func NewClient(endpoint string) (*Client, error) {
if endpoint == "" || len(endpoint) == 0 {
return nil, errors.New("graphql url is required")
}
client := graphql.NewClient(endpoint, http.DefaultClient)
return &Client{client}, nil
}

func (c Client) GetDealByUuid(dealUuid string) (*gen.DealResponse, error) {
return gen.Deal(context.TODO(), c.hqlClient, dealUuid)
}

var Checkpoint = map[string]string{
"Accepted": "Accepted",
"Transferred": "Transferred",
"Published": "Published",
"PublishConfirmed": "PublishConfirmed",
"AddedPiece": "AddedPiece",
"IndexedAndAnnounced": "IndexedAndAnnounced",
"Complete": "Complete",
}

func DealStatus(checkpoint, err string) string {
switch checkpoint {
case "Accepted":
return "StorageDealWaitingForData"
case "Transferred":
fallthrough
case "Published":
fallthrough
case "PublishConfirmed":
return "StorageDealAwaitingPreCommit"
case "AddedPiece":
fallthrough
case "IndexedAndAnnounced":
return "StorageDealSealing"
case "Complete":
switch err {
case "":
return "StorageDealActive"
case "Cancelled":
return "StorageDealNotFound"
}
return "StorageDealError"
}
return "StorageDealNotFound"
}

func Message(checkpoint, err string) string {
switch checkpoint {
case "Accepted":
return "Awaiting Offline Data Import"
case "Transferred":
return "Ready to Publish"
case "Published":
return "Awaiting Publish Confirmation"
case "PublishConfirmed":
return "Adding to Sector"
case "AddedPiece":
fallthrough
case "IndexedAndAnnounced":
return "sealing"
case "Complete":
switch err {
case "":
return "Complete"
case "Cancelled":
return "Cancelled"
}
return "Error: " + err
}
return "unknow"
}
111 changes: 111 additions & 0 deletions common/hql/gen/generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions common/hql/gen/model.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package gen

type ChainDealID struct {
TypeName string `json:"__typename"`
Value string `json:"n"`
}
14 changes: 14 additions & 0 deletions common/hql/genqlient.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
query Deal($uuid: ID!){
deal(id: $uuid) {
ID
ProviderAddress
PieceCid
IsVerified
SignedProposalCid
InboundFilePath
ChainDealID
Checkpoint
Err
Message
}
}
11 changes: 11 additions & 0 deletions common/hql/genqlient.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Default genqlient config; for full documentation see:
# https://github.com/Khan/genqlient/blob/main/docs/genqlient.yaml
schema: schema.graphql
operations:
- genqlient.graphql
generated: gen/generated.go
package: gen
context_type: context.Context
bindings:
Uint64:
type: swan-provider/common/gen.ChainDealID
Loading