@@ -14,6 +14,7 @@ import (
14
14
"github.com/filecoin-project/go-state-types/cbor"
15
15
cid "github.com/ipfs/go-cid"
16
16
"github.com/ipfs/go-datastore"
17
+ "github.com/ipfs/go-datastore/autobatch"
17
18
"github.com/multiformats/go-multihash"
18
19
"golang.org/x/crypto/blake2b"
19
20
)
@@ -86,11 +87,11 @@ type SnapshotReader interface {
86
87
// ImportSnapshotToDatastore imports an F3 snapshot into the specified Datastore
87
88
//
88
89
// 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 {
90
91
return importSnapshotToDatastoreWithTestingPowerTableFrequency (ctx , snapshot , ds , 0 )
91
92
}
92
93
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 {
94
95
headerBytes , err := readSnapshotBlockBytes (snapshot )
95
96
if err != nil {
96
97
return err
@@ -100,7 +101,9 @@ func importSnapshotToDatastoreWithTestingPowerTableFrequency(ctx context.Context
100
101
if err != nil {
101
102
return fmt .Errorf ("failed to decode snapshot header: %w" , err )
102
103
}
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 )
104
107
if testingPowerTableFrequency > 0 {
105
108
cs .powerTableFrequency = testingPowerTableFrequency
106
109
}
@@ -173,7 +176,7 @@ func readSnapshotBlockBytes(reader SnapshotReader) ([]byte, error) {
173
176
return nil , err
174
177
}
175
178
buf := make ([]byte , n1 )
176
- n2 , err := reader . Read ( buf )
179
+ n2 , err := io . ReadFull ( reader , buf )
177
180
if err != nil {
178
181
return nil , err
179
182
}
0 commit comments