diff --git a/cmd/lotus-storage-miner/init.go b/cmd/lotus-storage-miner/init.go index 9704eca09..4aefb004e 100644 --- a/cmd/lotus-storage-miner/init.go +++ b/cmd/lotus-storage-miner/init.go @@ -6,7 +6,6 @@ import ( "crypto/rand" "encoding/json" "fmt" - "github.com/filecoin-project/lotus/storagemarketadapter" "io/ioutil" "os" "path/filepath" @@ -22,16 +21,17 @@ import ( "gopkg.in/urfave/cli.v2" "github.com/filecoin-project/go-address" - "github.com/filecoin-project/go-cbor-util" - "github.com/filecoin-project/go-sectorbuilder" + cborutil "github.com/filecoin-project/go-cbor-util" "github.com/filecoin-project/go-fil-markets/storagemarket" deals "github.com/filecoin-project/go-fil-markets/storagemarket/impl" + "github.com/filecoin-project/go-sectorbuilder" lapi "github.com/filecoin-project/lotus/api" "github.com/filecoin-project/lotus/build" "github.com/filecoin-project/lotus/chain/actors" "github.com/filecoin-project/lotus/chain/types" lcli "github.com/filecoin-project/lotus/cli" "github.com/filecoin-project/lotus/genesis" + "github.com/filecoin-project/lotus/markets/utils" "github.com/filecoin-project/lotus/miner" "github.com/filecoin-project/lotus/node/modules" "github.com/filecoin-project/lotus/node/modules/dtypes" @@ -283,7 +283,7 @@ func migratePreSealMeta(ctx context.Context, api lapi.FullNode, presealDir strin dealKey := datastore.NewKey(deals.ProviderDsPrefix).ChildString(proposalCid.String()) - proposal, err := storagemarketadapter.ToSharedStorageDealProposal(§or.Deal) + proposal, err := utils.ToSharedStorageDealProposal(§or.Deal) if err != nil { return err } diff --git a/go.mod b/go.mod index ee48d7fe5..b2a08de0d 100644 --- a/go.mod +++ b/go.mod @@ -52,7 +52,6 @@ require ( github.com/ipfs/go-merkledag v0.2.4 github.com/ipfs/go-path v0.0.7 github.com/ipfs/go-unixfs v0.2.2-0.20190827150610-868af2e9e5cb - github.com/ipld/go-ipld-prime v0.0.2-0.20191108012745-28a82f04c785 github.com/libp2p/go-libp2p v0.4.2 github.com/libp2p/go-libp2p-circuit v0.1.4 github.com/libp2p/go-libp2p-connmgr v0.1.0 diff --git a/go.sum b/go.sum index b6e36c0bd..a15c42b49 100644 --- a/go.sum +++ b/go.sum @@ -113,7 +113,6 @@ github.com/filecoin-project/go-data-transfer v0.0.0-20191219005021-4accf56bd2ce github.com/filecoin-project/go-data-transfer v0.0.0-20191219005021-4accf56bd2ce/go.mod h1:b14UWxhxVCAjrQUYvVGrQRRsjAh79wXYejw9RbUcAww= github.com/filecoin-project/go-fil-markets v0.0.0-20200110170857-c200f161be42 h1:7OW2AiWtwxwtYnC16CiXZ/idQ7w3W7W1hhX+N4YSAyQ= github.com/filecoin-project/go-fil-markets v0.0.0-20200110170857-c200f161be42/go.mod h1:Q5fvJGMISyUIna19DpoqiqTas4L9RVD7w3Udv7uCrTo= -github.com/filecoin-project/go-fil-markets v0.0.0-20200110172620-7ac5a8af146a h1:mLz0GBjx8nlztlo2sZ6w1JbuyN7EX7zoCYQBblrgoBM= github.com/filecoin-project/go-paramfetch v0.0.0-20200102181131-b20d579f2878 h1:YicJT9xhPzZ1SBGiJFNUCkfwqK/G9vFyY1ytKBSjNJA= github.com/filecoin-project/go-paramfetch v0.0.0-20200102181131-b20d579f2878 h1:YicJT9xhPzZ1SBGiJFNUCkfwqK/G9vFyY1ytKBSjNJA= github.com/filecoin-project/go-paramfetch v0.0.0-20200102181131-b20d579f2878/go.mod h1:40kI2Gv16mwcRsHptI3OAV4nlOEU7wVDc4RgMylNFjU= @@ -700,6 +699,7 @@ github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnIn github.com/spf13/viper v1.3.2/go.mod h1:ZiWeW+zYFKm7srdB9IoDzzZXaJaI5eL9QjNiN/DMA2s= github.com/src-d/envconfig v1.0.0/go.mod h1:Q9YQZ7BKITldTBnoxsE5gOeB5y66RyPXeue/R4aaNBc= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/objx v0.1.1 h1:2vfRuCMp5sSVIDSqO8oNnWJq7mPa6KVP3iPIwFBuy8A= github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= diff --git a/lib/sharedutils/converters.go b/lib/sharedutils/converters.go deleted file mode 100644 index 58a5b44f9..000000000 --- a/lib/sharedutils/converters.go +++ /dev/null @@ -1,101 +0,0 @@ -package sharedutils - -import ( - "bytes" - sharedamount "github.com/filecoin-project/go-fil-markets/shared/tokenamount" - sharedtypes "github.com/filecoin-project/go-fil-markets/shared/types" - "github.com/filecoin-project/lotus/chain/types" -) - - -func FromSharedTokenAmount(in sharedamount.TokenAmount) types.BigInt { - return types.BigInt{Int: in.Int} -} - -func ToSharedTokenAmount(in types.BigInt) sharedamount.TokenAmount { - return sharedamount.TokenAmount{Int: in.Int} -} - -func ToSharedSignedVoucher(in *types.SignedVoucher) (*sharedtypes.SignedVoucher, error) { - var encoded bytes.Buffer - err := in.MarshalCBOR(&encoded) - if err != nil { - return nil, err - } - var out sharedtypes.SignedVoucher - err = out.UnmarshalCBOR(&encoded) - if err != nil { - return nil, err - } - return &out, nil -} - -func FromSharedSignedVoucher(in *sharedtypes.SignedVoucher) (*types.SignedVoucher, error) { - var encoded bytes.Buffer - err := in.MarshalCBOR(&encoded) - if err != nil { - return nil, err - } - var out types.SignedVoucher - err = out.UnmarshalCBOR(&encoded) - if err != nil { - return nil, err - } - return &out, nil -} - -func ToSharedSignature(in *types.Signature) (*sharedtypes.Signature, error) { - var encoded bytes.Buffer - err := in.MarshalCBOR(&encoded) - if err != nil { - return nil, err - } - var out sharedtypes.Signature - err = out.UnmarshalCBOR(&encoded) - if err != nil { - return nil, err - } - return &out, nil -} - -func FromSharedSignature(in *sharedtypes.Signature) (*types.Signature, error) { - var encoded bytes.Buffer - err := in.MarshalCBOR(&encoded) - if err != nil { - return nil, err - } - var out types.Signature - err = out.UnmarshalCBOR(&encoded) - if err != nil { - return nil, err - } - return &out, nil -} - -func ToSharedStorageAsk(in *types.SignedStorageAsk) (*sharedtypes.SignedStorageAsk, error) { - var encoded bytes.Buffer - err := in.MarshalCBOR(&encoded) - if err != nil { - return nil, err - } - var out sharedtypes.SignedStorageAsk - err = out.UnmarshalCBOR(&encoded) - if err != nil { - return nil, err - } - return &out, nil -} - -func FromSignedStorageAsk(in *sharedtypes.SignedStorageAsk) (*types.SignedStorageAsk, error) { - var encoded bytes.Buffer - err := in.MarshalCBOR(&encoded) - if err != nil { - return nil, err - } - var out types.SignedStorageAsk - err = out.UnmarshalCBOR(&encoded) - if err != nil { - return nil, err - } - return &out, nil -} diff --git a/retrievaladapter/client.go b/markets/retrievaladapter/client.go similarity index 90% rename from retrievaladapter/client.go rename to markets/retrievaladapter/client.go index cd5f819e5..676398014 100644 --- a/retrievaladapter/client.go +++ b/markets/retrievaladapter/client.go @@ -2,13 +2,12 @@ package retrievaladapter import ( "context" - "github.com/filecoin-project/lotus/lib/sharedutils" "github.com/filecoin-project/go-address" "github.com/filecoin-project/go-fil-markets/retrievalmarket" retrievaltoken "github.com/filecoin-project/go-fil-markets/shared/tokenamount" retrievaltypes "github.com/filecoin-project/go-fil-markets/shared/types" - + "github.com/filecoin-project/lotus/markets/utils" payapi "github.com/filecoin-project/lotus/node/impl/paych" "github.com/filecoin-project/lotus/paych" ) @@ -27,7 +26,7 @@ func NewRetrievalClientNode(pmgr *paych.Manager, payapi payapi.PaychAPI) retriev // GetOrCreatePaymentChannel sets up a new payment channel if one does not exist // between a client and a miner and insures the client has the given amount of funds available in the channel func (rcn *retrievalClientNode) GetOrCreatePaymentChannel(ctx context.Context, clientAddress address.Address, minerAddress address.Address, clientFundsAvailable retrievaltoken.TokenAmount) (address.Address, error) { - paych, _, err := rcn.pmgr.GetPaych(ctx, clientAddress, minerAddress, sharedutils.FromSharedTokenAmount(clientFundsAvailable)) + paych, _, err := rcn.pmgr.GetPaych(ctx, clientAddress, minerAddress, utils.FromSharedTokenAmount(clientFundsAvailable)) return paych, err } @@ -42,9 +41,9 @@ func (rcn *retrievalClientNode) AllocateLane(paymentChannel address.Address) (ui // given payment channel so that all the payment vouchers in the lane add up // to the given amount (so the payment voucher will be for the difference) func (rcn *retrievalClientNode) CreatePaymentVoucher(ctx context.Context, paymentChannel address.Address, amount retrievaltoken.TokenAmount, lane uint64) (*retrievaltypes.SignedVoucher, error) { - voucher, err := rcn.payapi.PaychVoucherCreate(ctx, paymentChannel, sharedutils.FromSharedTokenAmount(amount), lane) + voucher, err := rcn.payapi.PaychVoucherCreate(ctx, paymentChannel, utils.FromSharedTokenAmount(amount), lane) if err != nil { return nil, err } - return sharedutils.ToSharedSignedVoucher(voucher) + return utils.ToSharedSignedVoucher(voucher) } diff --git a/retrievaladapter/provider.go b/markets/retrievaladapter/provider.go similarity index 86% rename from retrievaladapter/provider.go rename to markets/retrievaladapter/provider.go index d2499757b..82c765123 100644 --- a/retrievaladapter/provider.go +++ b/markets/retrievaladapter/provider.go @@ -2,16 +2,17 @@ package retrievaladapter import ( "context" - "github.com/filecoin-project/lotus/lib/sharedutils" + + "github.com/ipfs/go-cid" + blockstore "github.com/ipfs/go-ipfs-blockstore" "github.com/filecoin-project/go-address" "github.com/filecoin-project/go-fil-markets/retrievalmarket" retrievaltoken "github.com/filecoin-project/go-fil-markets/shared/tokenamount" retrievaltypes "github.com/filecoin-project/go-fil-markets/shared/types" "github.com/filecoin-project/lotus/api" + "github.com/filecoin-project/lotus/markets/utils" "github.com/filecoin-project/lotus/storage/sectorblocks" - "github.com/ipfs/go-cid" - blockstore "github.com/ipfs/go-ipfs-blockstore" ) type retrievalProviderNode struct { @@ -38,10 +39,10 @@ func (rpn *retrievalProviderNode) SealedBlockstore(approveUnseal func() error) b } func (rpn *retrievalProviderNode) SavePaymentVoucher(ctx context.Context, paymentChannel address.Address, voucher *retrievaltypes.SignedVoucher, proof []byte, expectedAmount retrievaltoken.TokenAmount) (retrievaltoken.TokenAmount, error) { - localVoucher, err := sharedutils.FromSharedSignedVoucher(voucher) + localVoucher, err := utils.FromSharedSignedVoucher(voucher) if err != nil { return retrievaltoken.FromInt(0), err } - added, err := rpn.full.PaychVoucherAdd(ctx, paymentChannel, localVoucher, proof, sharedutils.FromSharedTokenAmount(expectedAmount)) - return sharedutils.ToSharedTokenAmount(added), err + added, err := rpn.full.PaychVoucherAdd(ctx, paymentChannel, localVoucher, proof, utils.FromSharedTokenAmount(expectedAmount)) + return utils.ToSharedTokenAmount(added), err } diff --git a/storagemarketadapter/client_adapter.go b/markets/storageadapter/client.go similarity index 94% rename from storagemarketadapter/client_adapter.go rename to markets/storageadapter/client.go index d517c726b..519e12e57 100644 --- a/storagemarketadapter/client_adapter.go +++ b/markets/storageadapter/client.go @@ -1,4 +1,4 @@ -package storagemarketadapter +package storageadapter // this file implements storagemarket.StorageClientNode @@ -6,8 +6,6 @@ import ( "bytes" "context" - "github.com/filecoin-project/lotus/lib/sharedutils" - "golang.org/x/xerrors" "github.com/filecoin-project/go-address" @@ -23,6 +21,7 @@ import ( "github.com/filecoin-project/lotus/chain/stmgr" "github.com/filecoin-project/lotus/chain/store" "github.com/filecoin-project/lotus/chain/types" + "github.com/filecoin-project/lotus/markets/utils" "github.com/filecoin-project/lotus/node/impl/full" ) @@ -83,7 +82,7 @@ func (n *ClientNodeAdapter) ListStorageProviders(ctx context.Context) ([]*storag if err != nil { return nil, err } - storageProviderInfo := NewStorageProviderInfo(addr, workerAddr, sectorSize, peerId) + storageProviderInfo := utils.NewStorageProviderInfo(addr, workerAddr, sectorSize, peerId) out = append(out, &storageProviderInfo) } @@ -99,7 +98,7 @@ func (n *ClientNodeAdapter) ListClientDeals(ctx context.Context, addr address.Ad var out []storagemarket.StorageDeal for _, deal := range allDeals { - storageDeal := FromOnChainDeal(deal) + storageDeal := utils.FromOnChainDeal(deal) if storageDeal.Client == addr { out = append(out, storageDeal) } @@ -118,7 +117,7 @@ func (n *ClientNodeAdapter) AddFunds(ctx context.Context, addr address.Address, smsg, err := n.MpoolPushMessage(ctx, &types.Message{ To: actors.StorageMarketAddress, From: addr, - Value: sharedutils.FromSharedTokenAmount(amount), + Value: utils.FromSharedTokenAmount(amount), GasPrice: types.NewInt(0), GasLimit: types.NewInt(1000000), Method: actors.SMAMethods.AddBalance, @@ -140,7 +139,7 @@ func (n *ClientNodeAdapter) AddFunds(ctx context.Context, addr address.Address, } func (n *ClientNodeAdapter) EnsureFunds(ctx context.Context, addr address.Address, amount tokenamount.TokenAmount) error { - return n.fm.EnsureAvailable(ctx, addr, sharedutils.FromSharedTokenAmount(amount)) + return n.fm.EnsureAvailable(ctx, addr, utils.FromSharedTokenAmount(amount)) } func (n *ClientNodeAdapter) GetBalance(ctx context.Context, addr address.Address) (storagemarket.Balance, error) { @@ -149,7 +148,7 @@ func (n *ClientNodeAdapter) GetBalance(ctx context.Context, addr address.Address return storagemarket.Balance{}, err } - return ToSharedBalance(bal), nil + return utils.ToSharedBalance(bal), nil } // ValidatePublishedDeal validates that the provided deal has appeared on chain and references the same ClientDeal @@ -302,7 +301,7 @@ func (c *ClientNodeAdapter) OnDealSectorCommitted(ctx context.Context, provider } func (n *ClientNodeAdapter) SignProposal(ctx context.Context, signer address.Address, proposal *storagemarket.StorageDealProposal) error { - localProposal, err := FromSharedStorageDealProposal(proposal) + localProposal, err := utils.FromSharedStorageDealProposal(proposal) if err != nil { return err } @@ -310,7 +309,7 @@ func (n *ClientNodeAdapter) SignProposal(ctx context.Context, signer address.Add if err != nil { return err } - signature, err := sharedutils.ToSharedSignature(localProposal.ProposerSignature) + signature, err := utils.ToSharedSignature(localProposal.ProposerSignature) if err != nil { return err } diff --git a/storagemarketadapter/provider_adapter.go b/markets/storageadapter/provider.go similarity index 93% rename from storagemarketadapter/provider_adapter.go rename to markets/storageadapter/provider.go index a0df86096..abe7f66eb 100644 --- a/storagemarketadapter/provider_adapter.go +++ b/markets/storageadapter/provider.go @@ -1,4 +1,4 @@ -package storagemarketadapter +package storageadapter // this file implements storagemarket.StorageProviderNode @@ -6,8 +6,6 @@ import ( "bytes" "context" - "github.com/filecoin-project/lotus/lib/sharedutils" - "github.com/ipfs/go-cid" logging "github.com/ipfs/go-log" unixfile "github.com/ipfs/go-unixfs/file" @@ -21,6 +19,7 @@ import ( "github.com/filecoin-project/lotus/chain/actors" "github.com/filecoin-project/lotus/chain/types" "github.com/filecoin-project/lotus/lib/padreader" + "github.com/filecoin-project/lotus/markets/utils" "github.com/filecoin-project/lotus/node/modules/dtypes" "github.com/filecoin-project/lotus/storage/sectorblocks" ) @@ -52,7 +51,7 @@ func (n *ProviderNodeAdapter) PublishDeals(ctx context.Context, deal storagemark return 0, cid.Undef, err } - localProposal, err := FromSharedStorageDealProposal(&deal.Proposal) + localProposal, err := utils.FromSharedStorageDealProposal(&deal.Proposal) if err != nil { return 0, cid.Undef, err } @@ -141,7 +140,7 @@ func (n *ProviderNodeAdapter) ListProviderDeals(ctx context.Context, addr addres var out []storagemarket.StorageDeal for _, deal := range allDeals { - sharedDeal := FromOnChainDeal(deal) + sharedDeal := utils.FromOnChainDeal(deal) if sharedDeal.Provider == addr { out = append(out, sharedDeal) } @@ -160,11 +159,11 @@ func (n *ProviderNodeAdapter) SignBytes(ctx context.Context, signer address.Addr if err != nil { return nil, err } - return sharedutils.ToSharedSignature(localSignature) + return utils.ToSharedSignature(localSignature) } func (n *ProviderNodeAdapter) EnsureFunds(ctx context.Context, addr address.Address, amt tokenamount.TokenAmount) error { - return n.MarketEnsureAvailable(ctx, addr, sharedutils.FromSharedTokenAmount(amt)) + return n.MarketEnsureAvailable(ctx, addr, utils.FromSharedTokenAmount(amt)) } func (n *ProviderNodeAdapter) MostRecentStateId(ctx context.Context) (storagemarket.StateKey, error) { @@ -177,7 +176,7 @@ func (n *ProviderNodeAdapter) AddFunds(ctx context.Context, addr address.Address smsg, err := n.MpoolPushMessage(ctx, &types.Message{ To: actors.StorageMarketAddress, From: addr, - Value: sharedutils.FromSharedTokenAmount(amount), + Value: utils.FromSharedTokenAmount(amount), GasPrice: types.NewInt(0), GasLimit: types.NewInt(1000000), Method: actors.SMAMethods.AddBalance, @@ -204,7 +203,7 @@ func (n *ProviderNodeAdapter) GetBalance(ctx context.Context, addr address.Addre return storagemarket.Balance{}, err } - return ToSharedBalance(bal), nil + return utils.ToSharedBalance(bal), nil } var _ storagemarket.StorageProviderNode = &ProviderNodeAdapter{} diff --git a/markets/utils/converters.go b/markets/utils/converters.go new file mode 100644 index 000000000..58080896f --- /dev/null +++ b/markets/utils/converters.go @@ -0,0 +1,174 @@ +package utils + +import ( + "bytes" + + peer "github.com/libp2p/go-libp2p-peer" + + "github.com/filecoin-project/go-address" + sharedamount "github.com/filecoin-project/go-fil-markets/shared/tokenamount" + sharedtypes "github.com/filecoin-project/go-fil-markets/shared/types" + "github.com/filecoin-project/go-fil-markets/storagemarket" + "github.com/filecoin-project/lotus/chain/actors" + "github.com/filecoin-project/lotus/chain/types" +) + +func FromSharedTokenAmount(in sharedamount.TokenAmount) types.BigInt { + return types.BigInt{Int: in.Int} +} + +func ToSharedTokenAmount(in types.BigInt) sharedamount.TokenAmount { + return sharedamount.TokenAmount{Int: in.Int} +} + +func ToSharedSignedVoucher(in *types.SignedVoucher) (*sharedtypes.SignedVoucher, error) { + var encoded bytes.Buffer + err := in.MarshalCBOR(&encoded) + if err != nil { + return nil, err + } + var out sharedtypes.SignedVoucher + err = out.UnmarshalCBOR(&encoded) + if err != nil { + return nil, err + } + return &out, nil +} + +func FromSharedSignedVoucher(in *sharedtypes.SignedVoucher) (*types.SignedVoucher, error) { + var encoded bytes.Buffer + err := in.MarshalCBOR(&encoded) + if err != nil { + return nil, err + } + var out types.SignedVoucher + err = out.UnmarshalCBOR(&encoded) + if err != nil { + return nil, err + } + return &out, nil +} + +func ToSharedSignature(in *types.Signature) (*sharedtypes.Signature, error) { + var encoded bytes.Buffer + err := in.MarshalCBOR(&encoded) + if err != nil { + return nil, err + } + var out sharedtypes.Signature + err = out.UnmarshalCBOR(&encoded) + if err != nil { + return nil, err + } + return &out, nil +} + +func FromSharedSignature(in *sharedtypes.Signature) (*types.Signature, error) { + var encoded bytes.Buffer + err := in.MarshalCBOR(&encoded) + if err != nil { + return nil, err + } + var out types.Signature + err = out.UnmarshalCBOR(&encoded) + if err != nil { + return nil, err + } + return &out, nil +} + +func ToSharedStorageAsk(in *types.SignedStorageAsk) (*sharedtypes.SignedStorageAsk, error) { + var encoded bytes.Buffer + err := in.MarshalCBOR(&encoded) + if err != nil { + return nil, err + } + var out sharedtypes.SignedStorageAsk + err = out.UnmarshalCBOR(&encoded) + if err != nil { + return nil, err + } + return &out, nil +} + +func FromSignedStorageAsk(in *sharedtypes.SignedStorageAsk) (*types.SignedStorageAsk, error) { + var encoded bytes.Buffer + err := in.MarshalCBOR(&encoded) + if err != nil { + return nil, err + } + var out types.SignedStorageAsk + err = out.UnmarshalCBOR(&encoded) + if err != nil { + return nil, err + } + return &out, nil +} + +func NewStorageProviderInfo(address address.Address, miner address.Address, sectorSize uint64, peer peer.ID) storagemarket.StorageProviderInfo { + return storagemarket.StorageProviderInfo{ + Address: address, + Worker: miner, + SectorSize: sectorSize, + PeerID: peer, + } +} + +func FromOnChainDeal(deal actors.OnChainDeal) storagemarket.StorageDeal { + return storagemarket.StorageDeal{ + PieceRef: deal.PieceRef, + PieceSize: deal.PieceSize, + Client: deal.Client, + Provider: deal.Provider, + StoragePricePerEpoch: ToSharedTokenAmount(deal.StoragePricePerEpoch), + StorageCollateral: ToSharedTokenAmount(deal.StorageCollateral), + ActivationEpoch: deal.ActivationEpoch, + } +} + +func ToOnChainDeal(deal storagemarket.StorageDeal) actors.OnChainDeal { + return actors.OnChainDeal{ + PieceRef: deal.PieceRef, + PieceSize: deal.PieceSize, + Client: deal.Client, + Provider: deal.Provider, + StoragePricePerEpoch: FromSharedTokenAmount(deal.StoragePricePerEpoch), + StorageCollateral: FromSharedTokenAmount(deal.StorageCollateral), + ActivationEpoch: deal.ActivationEpoch, + } +} + +func ToSharedBalance(balance actors.StorageParticipantBalance) storagemarket.Balance { + return storagemarket.Balance{ + Locked: ToSharedTokenAmount(balance.Locked), + Available: ToSharedTokenAmount(balance.Available), + } +} + +func ToSharedStorageDealProposal(proposal *actors.StorageDealProposal) (*storagemarket.StorageDealProposal, error) { + var encoded bytes.Buffer + err := proposal.MarshalCBOR(&encoded) + if err != nil { + return nil, err + } + var out storagemarket.StorageDealProposal + err = out.UnmarshalCBOR(&encoded) + if err != nil { + return nil, err + } + return &out, nil +} + +func FromSharedStorageDealProposal(proposal *storagemarket.StorageDealProposal) (*actors.StorageDealProposal, error) { + var encoded bytes.Buffer + err := proposal.MarshalCBOR(&encoded) + if err != nil { + return nil, err + } + var out actors.StorageDealProposal + err = out.UnmarshalCBOR(&encoded) + if err != nil { + return nil, err + } + return &out, nil +} diff --git a/node/builder.go b/node/builder.go index 9a656563c..178f973e5 100644 --- a/node/builder.go +++ b/node/builder.go @@ -34,6 +34,7 @@ import ( "github.com/filecoin-project/lotus/chain/store" "github.com/filecoin-project/lotus/chain/types" "github.com/filecoin-project/lotus/chain/wallet" + "github.com/filecoin-project/lotus/markets/storageadapter" "github.com/filecoin-project/lotus/miner" "github.com/filecoin-project/lotus/node/config" "github.com/filecoin-project/lotus/node/hello" @@ -48,7 +49,6 @@ import ( "github.com/filecoin-project/lotus/peermgr" "github.com/filecoin-project/lotus/storage" "github.com/filecoin-project/lotus/storage/sectorblocks" - "github.com/filecoin-project/lotus/storagemarketadapter" ) // special is a type used to give keys to modules which @@ -230,7 +230,7 @@ func Online() Option { Override(new(dtypes.ClientDataTransfer), modules.NewClientDAGServiceDataTransfer), Override(new(*deals.ClientRequestValidator), modules.NewClientRequestValidator), Override(new(storagemarket.StorageClient), modules.StorageClient), - Override(new(storagemarket.StorageClientNode), storagemarketadapter.NewClientNodeAdapter), + Override(new(storagemarket.StorageClientNode), storageadapter.NewClientNodeAdapter), Override(RegisterClientValidatorKey, modules.RegisterClientValidator), Override(RunDealClientKey, modules.RunDealClient), @@ -254,7 +254,7 @@ func Online() Option { Override(new(dtypes.ProviderDataTransfer), modules.NewProviderDAGServiceDataTransfer), Override(new(*deals.ProviderRequestValidator), modules.NewProviderRequestValidator), Override(new(storagemarket.StorageProvider), modules.StorageProvider), - Override(new(storagemarket.StorageProviderNode), storagemarketadapter.NewProviderNodeAdapter), + Override(new(storagemarket.StorageProviderNode), storageadapter.NewProviderNodeAdapter), Override(RegisterProviderValidatorKey, modules.RegisterProviderValidator), Override(HandleRetrievalKey, modules.HandleRetrieval), Override(GetParamsKey, modules.GetParams), diff --git a/node/impl/client/client.go b/node/impl/client/client.go index 12eaf117c..5623f4ae1 100644 --- a/node/impl/client/client.go +++ b/node/impl/client/client.go @@ -32,11 +32,10 @@ import ( "github.com/filecoin-project/lotus/build" "github.com/filecoin-project/lotus/chain/store" "github.com/filecoin-project/lotus/chain/types" - "github.com/filecoin-project/lotus/lib/sharedutils" + "github.com/filecoin-project/lotus/markets/utils" "github.com/filecoin-project/lotus/node/impl/full" "github.com/filecoin-project/lotus/node/impl/paych" "github.com/filecoin-project/lotus/node/modules/dtypes" - "github.com/filecoin-project/lotus/storagemarketadapter" ) type API struct { @@ -75,7 +74,7 @@ func (a *API) ClientStartDeal(ctx context.Context, data cid.Cid, addr address.Ad if err != nil { return nil, xerrors.Errorf("failed getting miner worker: %w", err) } - providerInfo := storagemarketadapter.NewStorageProviderInfo(miner, mw, 0, pid) + providerInfo := utils.NewStorageProviderInfo(miner, mw, 0, pid) result, err := a.SMDealClient.ProposeStorageDeal( ctx, addr, @@ -83,7 +82,7 @@ func (a *API) ClientStartDeal(ctx context.Context, data cid.Cid, addr address.Ad data, storagemarket.Epoch(math.MaxUint64), storagemarket.Epoch(blocksDuration), - sharedutils.ToSharedTokenAmount(epochPrice), + utils.ToSharedTokenAmount(epochPrice), tokenamount.Empty) if err != nil { @@ -109,7 +108,7 @@ func (a *API) ClientListDeals(ctx context.Context) ([]api.DealInfo, error) { PieceRef: v.Proposal.PieceRef, Size: v.Proposal.PieceSize, - PricePerEpoch: sharedutils.FromSharedTokenAmount(v.Proposal.StoragePricePerEpoch), + PricePerEpoch: utils.FromSharedTokenAmount(v.Proposal.StoragePricePerEpoch), Duration: v.Proposal.Duration, } } @@ -129,7 +128,7 @@ func (a *API) ClientGetDealInfo(ctx context.Context, d cid.Cid) (*api.DealInfo, Provider: v.Proposal.Provider, PieceRef: v.Proposal.PieceRef, Size: v.Proposal.PieceSize, - PricePerEpoch: sharedutils.FromSharedTokenAmount(v.Proposal.StoragePricePerEpoch), + PricePerEpoch: utils.FromSharedTokenAmount(v.Proposal.StoragePricePerEpoch), Duration: v.Proposal.Duration, }, nil } @@ -163,7 +162,7 @@ func (a *API) ClientFindData(ctx context.Context, root cid.Cid) ([]api.QueryOffe out[k] = api.QueryOffer{ Root: root, Size: queryResponse.Size, - MinPrice: sharedutils.FromSharedTokenAmount(queryResponse.PieceRetrievalPrice()), + MinPrice: utils.FromSharedTokenAmount(queryResponse.PieceRetrievalPrice()), Miner: p.Address, // TODO: check MinerPeerID: p.ID, } @@ -294,7 +293,7 @@ func (a *API) ClientRetrieve(ctx context.Context, order api.RetrievalOrder, path ctx, order.Root.Bytes(), retrievalmarket.NewParamsV0(types.BigDiv(order.Total, types.NewInt(order.Size)).Int, 0, 0), - sharedutils.ToSharedTokenAmount(order.Total), + utils.ToSharedTokenAmount(order.Total), order.MinerPeerID, order.Client, order.Miner) @@ -321,10 +320,10 @@ func (a *API) ClientRetrieve(ctx context.Context, order api.RetrievalOrder, path } func (a *API) ClientQueryAsk(ctx context.Context, p peer.ID, miner address.Address) (*types.SignedStorageAsk, error) { - info := storagemarketadapter.NewStorageProviderInfo(miner, address.Undef, 0, p) + info := utils.NewStorageProviderInfo(miner, address.Undef, 0, p) signedAsk, err := a.SMDealClient.GetAsk(ctx, info) if err != nil { return nil, err } - return sharedutils.FromSignedStorageAsk(signedAsk) + return utils.FromSignedStorageAsk(signedAsk) } diff --git a/node/modules/client.go b/node/modules/client.go index 313672c6b..91796634d 100644 --- a/node/modules/client.go +++ b/node/modules/client.go @@ -5,7 +5,7 @@ import ( "path/filepath" "reflect" - "github.com/filecoin-project/lotus/retrievaladapter" + "github.com/filecoin-project/lotus/markets/retrievaladapter" "github.com/filecoin-project/go-fil-markets/retrievalmarket" "github.com/filecoin-project/go-fil-markets/retrievalmarket/discovery" diff --git a/node/modules/storageminer.go b/node/modules/storageminer.go index 4909a8e67..d74595012 100644 --- a/node/modules/storageminer.go +++ b/node/modules/storageminer.go @@ -40,7 +40,7 @@ import ( "github.com/filecoin-project/lotus/node/modules/helpers" "github.com/filecoin-project/lotus/node/repo" - "github.com/filecoin-project/lotus/retrievaladapter" + "github.com/filecoin-project/lotus/markets/retrievaladapter" "github.com/filecoin-project/lotus/storage" "github.com/filecoin-project/lotus/storage/sectorblocks" ) diff --git a/storagemarketadapter/utilities.go b/storagemarketadapter/utilities.go deleted file mode 100644 index 2922f9d1a..000000000 --- a/storagemarketadapter/utilities.go +++ /dev/null @@ -1,80 +0,0 @@ -package storagemarketadapter - -import ( - "bytes" - - "github.com/filecoin-project/go-address" - "github.com/filecoin-project/go-fil-markets/storagemarket" - - "github.com/filecoin-project/lotus/chain/actors" - "github.com/filecoin-project/lotus/lib/sharedutils" - peer "github.com/libp2p/go-libp2p-peer" -) - -func NewStorageProviderInfo(address address.Address, miner address.Address, sectorSize uint64, peer peer.ID) storagemarket.StorageProviderInfo { - return storagemarket.StorageProviderInfo{ - Address: address, - Worker: miner, - SectorSize: sectorSize, - PeerID: peer, - } -} - -func FromOnChainDeal(deal actors.OnChainDeal) storagemarket.StorageDeal { - return storagemarket.StorageDeal{ - PieceRef: deal.PieceRef, - PieceSize: deal.PieceSize, - Client: deal.Client, - Provider: deal.Provider, - StoragePricePerEpoch: sharedutils.ToSharedTokenAmount(deal.StoragePricePerEpoch), - StorageCollateral: sharedutils.ToSharedTokenAmount(deal.StorageCollateral), - ActivationEpoch: deal.ActivationEpoch, - } -} - -func ToOnChainDeal(deal storagemarket.StorageDeal) actors.OnChainDeal { - return actors.OnChainDeal{ - PieceRef: deal.PieceRef, - PieceSize: deal.PieceSize, - Client: deal.Client, - Provider: deal.Provider, - StoragePricePerEpoch: sharedutils.FromSharedTokenAmount(deal.StoragePricePerEpoch), - StorageCollateral: sharedutils.FromSharedTokenAmount(deal.StorageCollateral), - ActivationEpoch: deal.ActivationEpoch, - } -} - -func ToSharedBalance(balance actors.StorageParticipantBalance) storagemarket.Balance { - return storagemarket.Balance{ - Locked: sharedutils.ToSharedTokenAmount(balance.Locked), - Available: sharedutils.ToSharedTokenAmount(balance.Available), - } -} - -func ToSharedStorageDealProposal(proposal *actors.StorageDealProposal) (*storagemarket.StorageDealProposal, error) { - var encoded bytes.Buffer - err := proposal.MarshalCBOR(&encoded) - if err != nil { - return nil, err - } - var out storagemarket.StorageDealProposal - err = out.UnmarshalCBOR(&encoded) - if err != nil { - return nil, err - } - return &out, nil -} - -func FromSharedStorageDealProposal(proposal *storagemarket.StorageDealProposal) (*actors.StorageDealProposal, error) { - var encoded bytes.Buffer - err := proposal.MarshalCBOR(&encoded) - if err != nil { - return nil, err - } - var out actors.StorageDealProposal - err = out.UnmarshalCBOR(&encoded) - if err != nil { - return nil, err - } - return &out, nil -}