Skip to content

Commit

Permalink
Adds better error checking for chifra chunks index --pin
Browse files Browse the repository at this point in the history
  • Loading branch information
tjayrush committed Sep 20, 2024
1 parent f3a0a69 commit 20ab6cd
Showing 1 changed file with 25 additions and 16 deletions.
41 changes: 25 additions & 16 deletions src/apps/chifra/internal/chunks/handle_pin.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,40 +96,49 @@ func (opts *ChunksOptions) HandlePin(rCtx *output.RenderCtx, blockNums []base.Bl
return rng1.First < rng2.First
})

for _, path := range fileList {
failCnt := 1.0
for i := 0; i < len(fileList); i++ {
sleep := opts.Sleep

path := fileList[i]
if opts.Globals.Verbose {
logger.Info("pinning path:", path)
}

local, remote, err := pinning.PinOneChunk(chain, path, opts.Remote)
if err != nil {
errorChan <- err
logger.Error("Pin failed:", path, err)
}

blMatches, idxMatches := matches(&local, &remote)
opts.matchReport(blMatches, local.BloomHash, remote.BloomHash)
opts.matchReport(idxMatches, local.IndexHash, remote.IndexHash)
failCnt *= 2.
sleep = failCnt
i-- // try again after sleeping for a bit
logger.Info(colors.Yellow, "Sleeping for", sleep, "seconds then trying again.", colors.Off)

if opts.Remote {
man.Chunks = append(man.Chunks, remote)
} else {
man.Chunks = append(man.Chunks, local)
}
_ = man.SaveManifest(chain, outPath)
blMatches, idxMatches := matches(&local, &remote)
opts.matchReport(blMatches, local.BloomHash, remote.BloomHash)
opts.matchReport(idxMatches, local.IndexHash, remote.IndexHash)

if opts.Globals.Verbose {
if opts.Remote {
fmt.Println("result.Remote:", remote.String())
man.Chunks = append(man.Chunks, remote)
} else {
fmt.Println("result.Local:", local.String())
man.Chunks = append(man.Chunks, local)
}
_ = man.SaveManifest(chain, outPath)

if opts.Globals.Verbose {
if opts.Remote {
fmt.Println("result.Remote:", remote.String())
} else {
fmt.Println("result.Local:", local.String())
}
}
}

sleep := opts.Sleep
if sleep > 0 {
ms := time.Duration(sleep*1000) * time.Millisecond
if !opts.Globals.TestMode {
logger.Info(fmt.Sprintf("Sleeping for %g seconds", sleep))
logger.Info("Sleeping for", sleep, "seconds")
}
time.Sleep(ms)
}
Expand Down

0 comments on commit 20ab6cd

Please sign in to comment.