Merge pull request #3973 from JackyWYX/sync_stuck_fix

[sync] release one rlock and change default value at getMaxPeerHeight
pull/3982/head v4.3.2
Soph 3 years ago committed by GitHub
commit 4615505d2f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 15
      api/service/legacysync/syncing.go
  2. 6
      rosetta/services/network.go

@ -11,6 +11,8 @@ import (
"sync"
"time"
"github.com/ethereum/go-ethereum/common/math"
nodeconfig "github.com/harmony-one/harmony/internal/configs/node"
"github.com/Workiva/go-datastructures/queue"
@ -130,8 +132,11 @@ func (sc *SyncConfig) AddPeer(peer *SyncPeerConfig) {
// It breaks the iteration iff the function returns true.
func (sc *SyncConfig) ForEachPeer(f func(peer *SyncPeerConfig) (brk bool)) {
sc.mtx.RLock()
defer sc.mtx.RUnlock()
for _, peer := range sc.peers {
peers := make([]*SyncPeerConfig, len(sc.peers))
copy(peers, sc.peers)
sc.mtx.RUnlock()
for _, peer := range peers {
if f(peer) {
break
}
@ -1031,7 +1036,7 @@ func (ss *StateSync) RegisterNodeInfo() int {
// getMaxPeerHeight gets the maximum blockchain heights from peers
func (ss *StateSync) getMaxPeerHeight(isBeacon bool) uint64 {
maxHeight := uint64(0)
maxHeight := uint64(math.MaxUint64)
var (
wg sync.WaitGroup
lock sync.Mutex
@ -1053,9 +1058,11 @@ func (ss *StateSync) getMaxPeerHeight(isBeacon bool) uint64 {
Msg("[SYNC] getMaxPeerHeight")
lock.Lock()
if response != nil && maxHeight < response.BlockHeight {
if response != nil {
if maxHeight == uint64(math.MaxUint64) || maxHeight < response.BlockHeight {
maxHeight = response.BlockHeight
}
}
lock.Unlock()
}()
return

@ -5,6 +5,8 @@ import (
"fmt"
"math/big"
"github.com/ethereum/go-ethereum/common/math"
"github.com/coinbase/rosetta-sdk-go/server"
"github.com/coinbase/rosetta-sdk-go/types"
"github.com/ethereum/go-ethereum/rpc"
@ -115,8 +117,10 @@ func (s *NetworkAPI) NetworkStatus(
}
}
}
targetInt := int64(targetHeight)
if targetHeight == math.MaxUint64 {
targetInt = 0
}
currentIndex := currentHeader.Number().Int64()
ss := &types.SyncStatus{
CurrentIndex: &currentIndex,

Loading…
Cancel
Save