From f0103161ae8c38b99898166472484a26a2302165 Mon Sep 17 00:00:00 2001 From: Jacky Wang Date: Thu, 6 Jan 2022 18:06:22 -0800 Subject: [PATCH 1/3] [sync] release one runlock at forEachPeer, and change default maxPeerHeight to maxInt if error --- api/service/legacysync/syncing.go | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/api/service/legacysync/syncing.go b/api/service/legacysync/syncing.go index 447f29999..8252b5759 100644 --- a/api/service/legacysync/syncing.go +++ b/api/service/legacysync/syncing.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,8 +1058,10 @@ func (ss *StateSync) getMaxPeerHeight(isBeacon bool) uint64 { Msg("[SYNC] getMaxPeerHeight") lock.Lock() - if response != nil && maxHeight < response.BlockHeight { - maxHeight = response.BlockHeight + if response != nil { + if maxHeight == uint64(math.MaxUint64) || maxHeight < response.BlockHeight { + maxHeight = response.BlockHeight + } } lock.Unlock() }() From 1c37a17d3b4029b23c4761556fccd77adebd44ad Mon Sep 17 00:00:00 2001 From: Jacky Wang Date: Thu, 6 Jan 2022 18:29:29 -0800 Subject: [PATCH 2/3] [sync] fix rossetta test --- rosetta/services/network.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/rosetta/services/network.go b/rosetta/services/network.go index 825e47fe6..15faf490f 100644 --- a/rosetta/services/network.go +++ b/rosetta/services/network.go @@ -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.MaxInt64 { + targetInt = 0 + } currentIndex := currentHeader.Number().Int64() ss := &types.SyncStatus{ CurrentIndex: ¤tIndex, From 866d3a684dd9d54068918736172e6dd9b43cb986 Mon Sep 17 00:00:00 2001 From: Jacky Wang Date: Sun, 9 Jan 2022 21:52:32 -0800 Subject: [PATCH 3/3] further fix the rossetta test --- rosetta/services/network.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rosetta/services/network.go b/rosetta/services/network.go index 15faf490f..06e9d8e68 100644 --- a/rosetta/services/network.go +++ b/rosetta/services/network.go @@ -118,7 +118,7 @@ func (s *NetworkAPI) NetworkStatus( } } targetInt := int64(targetHeight) - if targetHeight == math.MaxInt64 { + if targetHeight == math.MaxUint64 { targetInt = 0 } currentIndex := currentHeader.Number().Int64()