Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Sync Response Handling and Context Usage in doGetBlocksByHashesRequest #4713

Merged
merged 1 commit into from
Jul 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions api/service/legacysync/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,21 @@ func getMaxPeerHeight(syncConfig *SyncConfig) (uint64, error) {
syncConfig.RemovePeer(peerConfig, fmt.Sprintf("failed getMaxPeerHeight for shard %d with message: %s", syncConfig.ShardID(), err.Error()))
return
}
utils.Logger().Info().Str("peerIP", peerConfig.peer.IP).Uint64("blockHeight", response.BlockHeight).
Msg("[SYNC] getMaxPeerHeight")

lock.Lock()
if response != nil {
lock.Lock()
utils.Logger().Info().
Str("peerIP", peerConfig.peer.IP).
Uint64("blockHeight", response.BlockHeight).
Msg("[SYNC] getMaxPeerHeight")
if response.BlockHeight < math.MaxUint32 { // That's enough for decades.
if maxHeight == uint64(math.MaxUint64) || maxHeight < response.BlockHeight {
maxHeight = response.BlockHeight
}
}
lock.Unlock()
}
lock.Unlock()

}()
return
})
Expand Down
2 changes: 1 addition & 1 deletion api/service/legacysync/syncing.go
Original file line number Diff line number Diff line change
Expand Up @@ -883,7 +883,7 @@ func (ss *StateSync) UpdateBlockAndStatus(block *types.Block, bc core.BlockChain
if err := bc.Engine().VerifyHeaderSignature(bc, block.Header(), sig, bitmap); err != nil {
return errors.Wrapf(err, "verify header signature %v", block.Hash().String())
}
utils.Logger().Debug().Int64("elapsed time", time.Now().Sub(startTime).Milliseconds()).Msg("[Sync] VerifyHeaderSignature")
utils.Logger().Debug().Int64("elapsed time", time.Since(startTime).Milliseconds()).Msg("[Sync] VerifyHeaderSignature")
}
err := bc.Engine().VerifyHeader(bc, block.Header(), verifySeal)
if err == engine.ErrUnknownAncestor {
Expand Down
2 changes: 1 addition & 1 deletion hmy/downloader/shortrange.go
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ func (sh *srHelper) doGetBlocksByNumbersRequest(bns []uint64) ([]*types.Block, s
}

func (sh *srHelper) doGetBlocksByHashesRequest(ctx context.Context, hashes []common.Hash, wl []sttypes.StreamID) ([]*types.Block, sttypes.StreamID, error) {
ctx, cancel := context.WithTimeout(sh.ctx, 10*time.Second)
ctx, cancel := context.WithTimeout(ctx, 10*time.Second)
defer cancel()

blocks, stid, err := sh.syncProtocol.GetBlocksByHashes(ctx, hashes,
Expand Down