* Fix panic.

* check for empty blockBytes in stage bodies

---------

Co-authored-by: “GheisMohammadi” <36589218+GheisMohammadi@users.noreply.github.com>
pull/4443/head
Konstantin 1 year ago committed by GitHub
parent 10119bd8d5
commit 6a2f9cd4c7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 6
      api/service/stagedstreamsync/block_manager.go
  2. 7
      api/service/stagedstreamsync/stage_bodies.go

@ -84,7 +84,7 @@ func (gbm *blockDownloadManager) HandleRequestResult(bns []uint64, blockBytes []
for i, bn := range bns {
delete(gbm.requesting, bn)
if len(blockBytes[i]) <= 1 {
if indexExists(blockBytes, i) && len(blockBytes[i]) <= 1 {
gbm.retries.push(bn)
} else {
gbm.processing[bn] = struct{}{}
@ -97,6 +97,10 @@ func (gbm *blockDownloadManager) HandleRequestResult(bns []uint64, blockBytes []
return nil
}
func indexExists[T any](slice []T, index int) bool {
return index >= 0 && index < len(slice)
}
// SetDownloadDetails sets the download details for a batch of blocks
func (gbm *blockDownloadManager) SetDownloadDetails(bns []uint64, loopID int, streamID sttypes.StreamID) error {
gbm.lock.Lock()

@ -168,6 +168,13 @@ func (b *StageBodies) runBlockWorkerLoop(gbm *blockDownloadManager, wg *sync.Wai
Msg(WrapStagedSyncMsg("downloadRawBlocks failed"))
err = errors.Wrap(err, "request error")
gbm.HandleRequestError(batch, err, stid)
} else if blockBytes == nil || len(blockBytes) == 0 {
utils.Logger().Warn().
Str("stream", string(stid)).
Interface("block numbers", batch).
Msg(WrapStagedSyncMsg("downloadRawBlocks failed, received empty blockBytes"))
err := errors.New("downloadRawBlocks received empty blockBytes")
gbm.HandleRequestError(batch, err, stid)
} else {
if err = b.saveBlocks(gbm.tx, batch, blockBytes, sigBytes, loopID, stid); err != nil {
panic(ErrSaveBlocksToDbFailed)

Loading…
Cancel
Save