lotus/markets/retrievaladapter/provider.go

82 lines
2.6 KiB
Go
Raw Normal View History

package retrievaladapter
import (
"context"
"io"
"github.com/filecoin-project/go-address"
"github.com/filecoin-project/go-fil-markets/retrievalmarket"
"github.com/filecoin-project/go-fil-markets/shared"
sectorstorage "github.com/filecoin-project/sector-storage"
2020-07-28 21:35:23 +00:00
"github.com/filecoin-project/sector-storage/storiface"
"github.com/filecoin-project/specs-actors/actors/abi"
2020-02-21 17:26:44 +00:00
"github.com/filecoin-project/specs-actors/actors/builtin/paych"
"github.com/filecoin-project/lotus/api"
"github.com/filecoin-project/lotus/chain/types"
"github.com/filecoin-project/lotus/storage"
)
type retrievalProviderNode struct {
2020-03-03 22:19:22 +00:00
miner *storage.Miner
2020-03-23 11:40:02 +00:00
sealer sectorstorage.SectorManager
2020-03-03 22:19:22 +00:00
full api.FullNode
}
// NewRetrievalProviderNode returns a new node adapter for a retrieval provider that talks to the
// Lotus Node
2020-03-23 11:40:02 +00:00
func NewRetrievalProviderNode(miner *storage.Miner, sealer sectorstorage.SectorManager, full api.FullNode) retrievalmarket.RetrievalProviderNode {
2020-03-03 22:19:22 +00:00
return &retrievalProviderNode{miner, sealer, full}
}
func (rpn *retrievalProviderNode) GetMinerWorkerAddress(ctx context.Context, miner address.Address, tok shared.TipSetToken) (address.Address, error) {
tsk, err := types.TipSetKeyFromBytes(tok)
if err != nil {
return address.Undef, err
}
mi, err := rpn.full.StateMinerInfo(ctx, miner, tsk)
return mi.Worker, err
}
2020-07-30 12:31:31 +00:00
func (rpn *retrievalProviderNode) UnsealSector(ctx context.Context, sectorID abi.SectorNumber, offset abi.UnpaddedPieceSize, length abi.UnpaddedPieceSize) (io.ReadCloser, error) {
si, err := rpn.miner.GetSectorInfo(sectorID)
if err != nil {
return nil, err
}
2020-03-17 20:19:52 +00:00
mid, err := address.IDFromAddress(rpn.miner.Address())
if err != nil {
2020-03-22 21:39:06 +00:00
return nil, err
2020-03-17 20:19:52 +00:00
}
sid := abi.SectorID{
2020-03-18 01:08:11 +00:00
Miner: abi.ActorID(mid),
2020-07-30 12:31:31 +00:00
Number: sectorID,
2020-03-17 20:19:52 +00:00
}
r, w := io.Pipe()
go func() {
2020-07-30 12:31:31 +00:00
err := rpn.sealer.ReadPiece(ctx, w, sid, storiface.UnpaddedByteIndex(offset), length, si.TicketValue, *si.CommD)
_ = w.CloseWithError(err)
}()
return r, nil
}
func (rpn *retrievalProviderNode) SavePaymentVoucher(ctx context.Context, paymentChannel address.Address, voucher *paych.SignedVoucher, proof []byte, expectedAmount abi.TokenAmount, tok shared.TipSetToken) (abi.TokenAmount, error) {
// TODO: respect the provided TipSetToken (a serialized TipSetKey) when
// querying the chain
added, err := rpn.full.PaychVoucherAdd(ctx, paymentChannel, voucher, proof, expectedAmount)
return added, err
}
func (rpn *retrievalProviderNode) GetChainHead(ctx context.Context) (shared.TipSetToken, abi.ChainEpoch, error) {
head, err := rpn.full.ChainHead(ctx)
if err != nil {
return nil, 0, err
}
return head.Key().Bytes(), head.Height(), nil
}