MCPcopy Create free account
hub / github.com/chain/Core / BootstrapSnapshot

Function BootstrapSnapshot

core/fetch/bootstrap.go:68–91  ·  view source on GitHub ↗

BootstrapSnapshot downloads and stores the most recent snapshot from the provided peer. It's run when bootstrapping a new Core to an existing network. It should be run before invoking Chain.Recover.

(ctx context.Context, c *protocol.Chain, store protocol.Store, peer *rpc.Client, health func(error))

Source from the content-addressed store, hash-verified

66// provided peer. It's run when bootstrapping a new Core to an existing
67// network. It should be run before invoking Chain.Recover.
68func BootstrapSnapshot(ctx context.Context, c *protocol.Chain, store protocol.Store, peer *rpc.Client, health func(error)) *SnapshotProgress {
69 const maxAttempts = 5
70
71 // Return a *SnapshotProgress so that the caller can track the
72 // progress of the download.
73 progress := &SnapshotProgress{stopped: make(chan struct{})}
74 go func() {
75 for attempt := 1; attempt <= maxAttempts; attempt++ {
76 progress.mu.Lock()
77 progress.attempt = attempt
78 progress.downloadProgress = nil
79 progress.mu.Unlock()
80
81 err := fetchSnapshot(ctx, peer, store, progress)
82 health(err)
83 if err == nil {
84 break
85 }
86 logNetworkError(ctx, err)
87 }
88 close(progress.stopped)
89 }()
90 return progress
91}
92
93// fetchSnapshot fetches the latest snapshot from the generator and applies it
94// to the store. It should only be called on freshly configured cores--

Callers

nothing calls this directly

Calls 2

fetchSnapshotFunction · 0.85
logNetworkErrorFunction · 0.85

Tested by

no test coverage detected