From d8b5d1693a04754af162379c6ac82c25ec31b30c Mon Sep 17 00:00:00 2001 From: Jacky Wang Date: Mon, 3 May 2021 11:23:34 -0700 Subject: [PATCH] [sync] fix a panic issue found in stream tests --- node/node_syncing.go | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/node/node_syncing.go b/node/node_syncing.go index 89ef503e4..2ce127ce0 100644 --- a/node/node_syncing.go +++ b/node/node_syncing.go @@ -87,8 +87,15 @@ func (node *Node) createStateSync() *legacysync.StateSync { // Thus for compatibility, we are doing the arithmetics here, and not to change the // protocol itself. This is just the temporary hack and will not be a concern after // state sync. - syncPort := node.downloaderServer.Port - mutatedPort := strconv.Itoa(syncPort + legacysync.SyncingPortDifference) + var mySyncPort int + if node.downloaderServer != nil { + mySyncPort = node.downloaderServer.Port + } else { + // If local sync server is not started, the port field in protocol is actually not + // functional, simply set it to default value. + mySyncPort = nodeconfig.DefaultDNSPort + } + mutatedPort := strconv.Itoa(mySyncPort + legacysync.SyncingPortDifference) return legacysync.CreateStateSync(node.SelfPeer.IP, mutatedPort, node.GetSyncID(), node.NodeConfig.Role() == nodeconfig.ExplorerNode) }