MCPcopy Create free account
hub / github.com/CPChain/chain / importChain

Function importChain

cmd/cpchain/cmd_chain.go:245–335  ·  view source on GitHub ↗
(ctx *cli.Context)

Source from the content-addressed store, hash-verified

243}
244
245func importChain(ctx *cli.Context) error {
246 if len(ctx.Args()) != 1 {
247 log.Fatalf("This command requires a single argument for the imported file")
248 }
249
250 log.Info("Begin import")
251 cfg, node := newConfigNode(ctx)
252
253 primitive_register.RegisterPrimitiveContracts()
254 chain, chainDb := commons.OpenChain(ctx, node, &cfg.Cpc)
255 defer chainDb.Close()
256
257 // Start periodically gathering memory profiles
258 var peakMemAlloc, peakMemSys uint64
259 go func() {
260 stats := new(runtime.MemStats)
261 for {
262 runtime.ReadMemStats(stats)
263 if atomic.LoadUint64(&peakMemAlloc) < stats.Alloc {
264 atomic.StoreUint64(&peakMemAlloc, stats.Alloc)
265 }
266 if atomic.LoadUint64(&peakMemSys) < stats.Sys {
267 atomic.StoreUint64(&peakMemSys, stats.Sys)
268 }
269 time.Sleep(5 * time.Second)
270 }
271 }()
272 // Import the chain
273 start := time.Now()
274
275 if err := commons.ImportChain(chain, ctx.Args().First()); err != nil {
276 log.Error("Import error", "err", err)
277 }
278 // flush the caches
279 chain.Stop()
280
281 fmt.Printf("Import done in %v.\n\n", time.Since(start))
282
283 // Output pre-compaction stats mostly to see the import trashing
284 db := chainDb.(*database.LDBDatabase)
285
286 stats, err := db.LDB().GetProperty("leveldb.stats")
287 if err != nil {
288 log.Fatalf("Failed to read database stats: %v", err)
289 }
290 fmt.Println(stats)
291
292 ioStats, err := db.LDB().GetProperty("leveldb.iostats")
293 if err != nil {
294 log.Fatalf("Failed to read database iostats: %v", err)
295 }
296 fmt.Println(ioStats)
297
298 fmt.Printf("Trie cache misses: %d\n", trie.CacheMisses())
299 fmt.Printf("Trie cache unloads: %d\n\n", trie.CacheUnloads())
300
301 // Print the memory statistics used by the importing
302 mem := new(runtime.MemStats)

Callers

nothing calls this directly

Calls 9

newConfigNodeFunction · 0.85
SleepMethod · 0.80
ImportChainMethod · 0.80
LDBMethod · 0.80
InfoMethod · 0.65
CloseMethod · 0.65
NowMethod · 0.65
ErrorMethod · 0.65
StopMethod · 0.65

Tested by

no test coverage detected