@@ -12,6 +12,7 @@ import (
1212 "github.com/filecoin-project/go-fil-markets/storagemarket"
1313 "github.com/filecoin-project/go-state-types/abi"
1414 "github.com/filecoin-project/lotus/api"
15+ marketevents "github.com/filecoin-project/lotus/markets/loggers"
1516 "github.com/ipfs/go-cid"
1617 logger "github.com/ipfs/go-log/v2"
1718 iface "github.com/ipfs/interface-go-ipfs-core"
@@ -35,15 +36,16 @@ var (
3536// FilCold is a ColdStorage implementation which saves data in the Filecoin network.
3637// It assumes the underlying Filecoin client has access to an IPFS node where data is stored.
3738type FilCold struct {
38- ms ffs.MinerSelector
39- dm * dealsModule.Module
40- wm wallet.Module
41- ipfs iface.CoreAPI
42- chain FilChain
43- l ffs.JobLogger
44- lsm * lotus.SyncMonitor
45- minPieceSize uint64
46- semaphDealPrep chan struct {}
39+ ms ffs.MinerSelector
40+ dm * dealsModule.Module
41+ wm wallet.Module
42+ ipfs iface.CoreAPI
43+ chain FilChain
44+ l ffs.JobLogger
45+ lsm * lotus.SyncMonitor
46+ minPieceSize uint64
47+ retrNextEventTimeout time.Duration
48+ semaphDealPrep chan struct {}
4749}
4850
4951var _ ffs.ColdStorage = (* FilCold )(nil )
@@ -54,17 +56,18 @@ type FilChain interface {
5456}
5557
5658// New returns a new FilCold instance.
57- func New (ms ffs.MinerSelector , dm * dealsModule.Module , wm wallet.Module , ipfs iface.CoreAPI , chain FilChain , l ffs.JobLogger , lsm * lotus.SyncMonitor , minPieceSize uint64 , maxParallelDealPreparing int ) * FilCold {
59+ func New (ms ffs.MinerSelector , dm * dealsModule.Module , wm wallet.Module , ipfs iface.CoreAPI , chain FilChain , l ffs.JobLogger , lsm * lotus.SyncMonitor , minPieceSize uint64 , maxParallelDealPreparing int , retrievalNextEventTimeout time. Duration ) * FilCold {
5860 return & FilCold {
59- ms : ms ,
60- dm : dm ,
61- wm : wm ,
62- ipfs : ipfs ,
63- chain : chain ,
64- l : l ,
65- lsm : lsm ,
66- minPieceSize : minPieceSize ,
67- semaphDealPrep : make (chan struct {}, maxParallelDealPreparing ),
61+ ms : ms ,
62+ dm : dm ,
63+ wm : wm ,
64+ ipfs : ipfs ,
65+ chain : chain ,
66+ l : l ,
67+ lsm : lsm ,
68+ minPieceSize : minPieceSize ,
69+ retrNextEventTimeout : retrievalNextEventTimeout ,
70+ semaphDealPrep : make (chan struct {}, maxParallelDealPreparing ),
6871 }
6972}
7073
@@ -76,21 +79,39 @@ func (fc *FilCold) Fetch(ctx context.Context, pyCid cid.Cid, piCid *cid.Cid, wad
7679 return ffs.FetchInfo {}, fmt .Errorf ("fetching from deal module: %s" , err )
7780 }
7881 fc .l .Log (ctx , "Fetching from %s..." , miner )
79- var fundsSpent uint64
80- var lastMsg string
81- for e := range events {
82- if e .Err != "" {
83- return ffs.FetchInfo {}, fmt .Errorf ("event error in retrieval progress: %s" , e .Err )
84- }
85- strEvent := retrievalmarket .ClientEvents [e .Event ]
86- strDealStatus := retrievalmarket .DealStatuses [e .Status ]
87- fundsSpent = e .FundsSpent .Uint64 ()
88- newMsg := fmt .Sprintf ("Received %s, total spent: %sFIL (%s/%s)" , humanize .IBytes (e .BytesReceived ), util .AttoFilToFil (fundsSpent ), strEvent , strDealStatus )
89- if newMsg != lastMsg {
90- fc .l .Log (ctx , newMsg )
91- lastMsg = newMsg
82+
83+ var (
84+ fundsSpent uint64
85+ lastMsg string
86+ lastEvent marketevents.RetrievalEvent
87+ )
88+ Loop:
89+ for {
90+ select {
91+ case <- time .After (fc .retrNextEventTimeout ):
92+ return ffs.FetchInfo {}, fmt .Errorf ("didn't receive events for %d minutes" , int64 (fc .retrNextEventTimeout .Minutes ()))
93+ case e , ok := <- events :
94+ if ! ok {
95+ break Loop
96+ }
97+ if e .Err != "" {
98+ return ffs.FetchInfo {}, fmt .Errorf ("event error in retrieval progress: %s" , e .Err )
99+ }
100+ strEvent := retrievalmarket .ClientEvents [e .Event ]
101+ strDealStatus := retrievalmarket .DealStatuses [e .Status ]
102+ fundsSpent = e .FundsSpent .Uint64 ()
103+ newMsg := fmt .Sprintf ("Received %s, total spent: %sFIL (%s/%s)" , humanize .IBytes (e .BytesReceived ), util .AttoFilToFil (fundsSpent ), strEvent , strDealStatus )
104+ if newMsg != lastMsg {
105+ fc .l .Log (ctx , newMsg )
106+ lastMsg = newMsg
107+ }
108+ lastEvent = e
92109 }
93110 }
111+ if lastEvent .Status != retrievalmarket .DealStatusCompleted {
112+ return ffs.FetchInfo {}, fmt .Errorf ("retrieval failed with status %s and message %s" , retrievalmarket .DealStatuses [lastEvent .Status ], lastMsg )
113+ }
114+
94115 return ffs.FetchInfo {RetrievedMiner : miner , FundsSpent : fundsSpent }, nil
95116}
96117
0 commit comments