Skip to content

Commit

Permalink
improve checkPrerequisites to be able to continue with minimum streams
Browse files Browse the repository at this point in the history
  • Loading branch information
GheisMohammadi committed Aug 24, 2023
1 parent 1ae0bd0 commit fc07d0c
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
5 changes: 5 additions & 0 deletions api/service/stagedstreamsync/short_range_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (

"github.com/ethereum/go-ethereum/common"
"github.com/harmony-one/harmony/core/types"
"github.com/harmony-one/harmony/internal/utils"
syncProto "github.com/harmony-one/harmony/p2p/stream/protocols/sync"
sttypes "github.com/harmony-one/harmony/p2p/stream/types"
"github.com/pkg/errors"
Expand Down Expand Up @@ -132,6 +133,10 @@ func (sh *srHelper) getBlocksByHashes(ctx context.Context, hashes []common.Hash,

func (sh *srHelper) checkPrerequisites() error {
if sh.syncProtocol.NumStreams() < sh.config.Concurrency {
utils.Logger().Info().
Int("available streams", sh.syncProtocol.NumStreams()).
Interface("concurrency", sh.config.Concurrency).
Msg("not enough streams to do concurrent processes")
return ErrNotEnoughStreams
}
return nil
Expand Down
7 changes: 6 additions & 1 deletion api/service/stagedstreamsync/stage_epoch.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,12 @@ func (sr *StageEpoch) doShortRangeSyncForEpochSync(ctx context.Context, s *Stage
}

if err := sh.checkPrerequisites(); err != nil {
return 0, errors.Wrap(err, "prerequisite")
// if error is ErrNotEnoughStreams but still some streams available,
// it can continue syncing, otherwise return error
// here we are not doing concurrent processes, so even 1 stream should be enough
if err != ErrNotEnoughStreams || s.state.protocol.NumStreams() == 0 {
return 0, errors.Wrap(err, "prerequisite")
}
}
curBN := s.state.bc.CurrentBlock().NumberU64()
bns := make([]uint64, 0, BlocksPerRequest)
Expand Down
7 changes: 6 additions & 1 deletion api/service/stagedstreamsync/stage_short_range.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,12 @@ func (sr *StageShortRange) doShortRangeSync(ctx context.Context, s *StageState)
}

if err := sh.checkPrerequisites(); err != nil {
return 0, errors.Wrap(err, "prerequisite")
// if error is ErrNotEnoughStreams but still two streams available,
// it can continue syncing, otherwise return error
// at least 2 streams are needed to do concurrent processes
if err != ErrNotEnoughStreams || s.state.protocol.NumStreams() < 2 {
return 0, errors.Wrap(err, "prerequisite")
}
}
curBN := sr.configs.bc.CurrentBlock().NumberU64()
blkNums := sh.prepareBlockHashNumbers(curBN)
Expand Down

0 comments on commit fc07d0c

Please sign in to comment.