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))
| 66 | // provided peer. It's run when bootstrapping a new Core to an existing |
| 67 | // network. It should be run before invoking Chain.Recover. |
| 68 | func 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-- |
nothing calls this directly
no test coverage detected