Skip to content

Commit

Permalink
Merge pull request #509 from ipfs-force-community/feat/direct-deal
Browse files Browse the repository at this point in the history
feat: implement direct deal
  • Loading branch information
LinZexiao authored Mar 11, 2024
2 parents 2eae8a5 + ee9ed0d commit 1e81ea3
Show file tree
Hide file tree
Showing 32 changed files with 3,181 additions and 200 deletions.
6 changes: 1 addition & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,7 @@ dist-clean:
git clean -xdff
git submodule deinit --all -f

build: $(BUILD_DEPS)
rm -f droplet-client
rm -f droplet
go build -o ./droplet-client $(GOFLAGS) ./cmd/droplet-client
go build -o ./droplet $(GOFLAGS) ./cmd/droplet
build: droplet droplet-client

droplet: $(BUILD_DEPS)
rm -f droplet
Expand Down
45 changes: 45 additions & 0 deletions api/impl/venus_market.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"github.com/filecoin-project/go-fil-markets/storagemarket"
"github.com/filecoin-project/go-fil-markets/stores"
"github.com/filecoin-project/go-state-types/abi"
"github.com/google/uuid"
"github.com/hashicorp/go-multierror"
"github.com/ipfs/go-cid"
logging "github.com/ipfs/go-log/v2"
Expand Down Expand Up @@ -66,6 +67,8 @@ type MarketNodeImpl struct {
DealPublisher *storageprovider.DealPublisher
DealAssigner storageprovider.DealAssiger

DirectDealProvider *storageprovider.DirectDealProvider

AuthClient jwtclient.IAuthClient

Messager clients2.IMixMessage
Expand Down Expand Up @@ -1103,6 +1106,29 @@ func (m *MarketNodeImpl) UpdateDealOnPacking(ctx context.Context, miner address.
return m.DealAssigner.UpdateDealOnPacking(ctx, miner, dealId, sectorid, offset)
}

func (m *MarketNodeImpl) AssignDeals(ctx context.Context, sid abi.SectorID, ssize abi.SectorSize, spec *types.GetDealSpec) ([]*types.DealInfoV2, error) {
mAddr, err := address.NewIDAddress(uint64(sid.Miner))
if err != nil {
return nil, err
}
if err := jwtclient.CheckPermissionByMiner(ctx, m.AuthClient, mAddr); err != nil {
return nil, err
}

head, err := m.FullNode.ChainHead(ctx)
if err != nil {
return nil, fmt.Errorf("get chain head %w", err)
}
return m.DealAssigner.AssignDeals(ctx, sid, ssize, head.Height(), spec)
}

func (m *MarketNodeImpl) ReleaseDirectDeals(ctx context.Context, miner address.Address, allocationIDs []vTypes.AllocationId) error {
if err := jwtclient.CheckPermissionByMiner(ctx, m.AuthClient, miner); err != nil {
return err
}
return m.DealAssigner.ReleaseDirectDeals(ctx, miner, allocationIDs)
}

func (m *MarketNodeImpl) UpdateDealStatus(ctx context.Context, miner address.Address, dealId abi.DealID, pieceStatus types.PieceStatus, dealStatus storagemarket.StorageDealStatus) error {
if err := jwtclient.CheckPermissionByMiner(ctx, m.AuthClient, miner); err != nil {
return err
Expand Down Expand Up @@ -1324,3 +1350,22 @@ func (m *MarketNodeImpl) DealsBatchImportData(ctx context.Context, refs types.Im

return results, nil
}

func (m *MarketNodeImpl) ImportDirectDeal(ctx context.Context, dealParams *types.DirectDealParams) error {
if len(dealParams.DealParams) == 0 {
return errors.New("deal params is empty")
}
return m.DirectDealProvider.ImportDeals(ctx, dealParams)
}

func (m *MarketNodeImpl) GetDirectDeal(ctx context.Context, id uuid.UUID) (*types.DirectDeal, error) {
return m.Repo.DirectDealRepo().GetDeal(ctx, id)
}

func (m *MarketNodeImpl) GetDirectDealByAllocationID(ctx context.Context, id vTypes.AllocationId) (*types.DirectDeal, error) {
return m.Repo.DirectDealRepo().GetDealByAllocationID(ctx, uint64(id))
}

func (m *MarketNodeImpl) ListDirectDeals(ctx context.Context, queryParams types.DirectDealQueryParams) ([]*types.DirectDeal, error) {
return m.Repo.DirectDealRepo().ListDeal(ctx, queryParams)
}
Loading

0 comments on commit 1e81ea3

Please sign in to comment.