@@ -14,6 +14,7 @@ import (
1414 "github.com/filecoin-project/go-state-types/cbor"
1515 cid "github.com/ipfs/go-cid"
1616 "github.com/ipfs/go-datastore"
17+ "github.com/ipfs/go-datastore/autobatch"
1718 "github.com/multiformats/go-multihash"
1819 "golang.org/x/crypto/blake2b"
1920)
@@ -86,11 +87,11 @@ type SnapshotReader interface {
8687// ImportSnapshotToDatastore imports an F3 snapshot into the specified Datastore
8788//
8889// Checkout the snapshot format specification at <https://github.com/filecoin-project/FIPs/blob/master/FRCs/frc-0108.md>
89- func ImportSnapshotToDatastore (ctx context.Context , snapshot SnapshotReader , ds datastore.Datastore ) error {
90+ func ImportSnapshotToDatastore (ctx context.Context , snapshot SnapshotReader , ds datastore.Batching ) error {
9091 return importSnapshotToDatastoreWithTestingPowerTableFrequency (ctx , snapshot , ds , 0 )
9192}
9293
93- func importSnapshotToDatastoreWithTestingPowerTableFrequency (ctx context.Context , snapshot SnapshotReader , ds datastore.Datastore , testingPowerTableFrequency uint64 ) error {
94+ func importSnapshotToDatastoreWithTestingPowerTableFrequency (ctx context.Context , snapshot SnapshotReader , ds datastore.Batching , testingPowerTableFrequency uint64 ) error {
9495 headerBytes , err := readSnapshotBlockBytes (snapshot )
9596 if err != nil {
9697 return err
@@ -100,7 +101,9 @@ func importSnapshotToDatastoreWithTestingPowerTableFrequency(ctx context.Context
100101 if err != nil {
101102 return fmt .Errorf ("failed to decode snapshot header: %w" , err )
102103 }
103- cs , err := OpenOrCreateStore (ctx , ds , header .FirstInstance , header .InitialPowerTable )
104+ dsb := autobatch .NewAutoBatching (ds , 1000 )
105+ defer dsb .Flush (ctx )
106+ cs , err := OpenOrCreateStore (ctx , dsb , header .FirstInstance , header .InitialPowerTable )
104107 if testingPowerTableFrequency > 0 {
105108 cs .powerTableFrequency = testingPowerTableFrequency
106109 }
@@ -173,7 +176,7 @@ func readSnapshotBlockBytes(reader SnapshotReader) ([]byte, error) {
173176 return nil , err
174177 }
175178 buf := make ([]byte , n1 )
176- n2 , err := reader . Read ( buf )
179+ n2 , err := io . ReadFull ( reader , buf )
177180 if err != nil {
178181 return nil , err
179182 }
0 commit comments