@@ -22,6 +22,7 @@ import (
22
22
"github.com/filecoin-project/lotus/storage/sealer/ffiwrapper"
23
23
"github.com/mitchellh/go-homedir"
24
24
25
+ "github.com/filecoin-project/lotus/chain/types"
25
26
"golang.org/x/xerrors"
26
27
"gopkg.in/cheggaaa/pb.v1"
27
28
)
@@ -92,7 +93,7 @@ func ImportFromFsFile(ctx context.Context, r repo.Repo, fs fs.File, snapshot boo
92
93
return nil
93
94
}
94
95
95
- func ImportChain (ctx context.Context , r repo.Repo , fname string , snapshot bool ) (err error ) {
96
+ func ImportChain (ctx context.Context , r repo.Repo , fname string , snapshot bool , backfillTipsetkeyRange int ) (err error ) {
96
97
var rd io.Reader
97
98
var l int64
98
99
if strings .HasPrefix (fname , "http://" ) || strings .HasPrefix (fname , "https://" ) {
@@ -189,6 +190,13 @@ func ImportChain(ctx context.Context, r repo.Repo, fname string, snapshot bool)
189
190
return fmt .Errorf ("importing chain failed: %w" , err )
190
191
}
191
192
193
+ // The cst.Import function will only backfill 1800 epochs of tipsetkey,
194
+ // Hence, the function is to backfill more epochs covered by the snapshot.
195
+ err = backfillTipsetKey (ctx , ts , cst , backfillTipsetkeyRange )
196
+ if err != nil {
197
+ log .Errorf ("backfill tipsetkey failed: %w" , err )
198
+ }
199
+
192
200
if err := cst .FlushValidationCache (ctx ); err != nil {
193
201
return fmt .Errorf ("flushing validation cache failed: %w" , err )
194
202
}
@@ -222,3 +230,21 @@ func ImportChain(ctx context.Context, r repo.Repo, fname string, snapshot bool)
222
230
223
231
return nil
224
232
}
233
+
234
+ func backfillTipsetKey (ctx context.Context , root * types.TipSet , cs * store.ChainStore , backfillRange int ) (err error ) {
235
+ ts := root
236
+ log .Infof ("backfilling the tipsetkey into chainstore, attempt to backfill the last %v epochs starting from the head." , backfillRange )
237
+ for i := 0 ; i < backfillRange ; i ++ {
238
+ err = cs .PersistTipset (ctx , ts )
239
+ if err != nil {
240
+ return
241
+ }
242
+ parentTsKey := ts .Parents ()
243
+ ts , err = cs .LoadTipSet (ctx , parentTsKey )
244
+ if ts == nil || err != nil {
245
+ log .Infof ("Only able to load the last %d tipsets" , i )
246
+ break
247
+ }
248
+ }
249
+ return
250
+ }
0 commit comments