Clean up code.

pull/4389/head
frozen 2 years ago committed by Casey Gardiner
parent d13f4d033d
commit 47386c06a5
  1. 2
      node/node.go
  2. 28
      node/node_syncing.go

@ -1029,6 +1029,7 @@ func New(
unixTimeAtNodeStart: time.Now().Unix(), unixTimeAtNodeStart: time.Now().Unix(),
TransactionErrorSink: types.NewTransactionErrorSink(), TransactionErrorSink: types.NewTransactionErrorSink(),
crosslinks: crosslinks.New(), crosslinks: crosslinks.New(),
syncID: GenerateSyncID(),
} }
// Get the node config that's created in the harmony.go program. // Get the node config that's created in the harmony.go program.
@ -1039,7 +1040,6 @@ func New(
} }
node.HarmonyConfig = harmonyconfig node.HarmonyConfig = harmonyconfig
copy(node.syncID[:], GenerateRandomString(SyncIDLength))
if host != nil { if host != nil {
node.host = host node.host = host
node.SelfPeer = host.GetSelfPeer() node.SelfPeer = host.GetSelfPeer()

@ -5,7 +5,6 @@ import (
"math/rand" "math/rand"
"net" "net"
"strconv" "strconv"
"sync"
"time" "time"
"github.com/harmony-one/harmony/internal/tikv" "github.com/harmony-one/harmony/internal/tikv"
@ -65,28 +64,11 @@ func GenerateRandomString(n int) string {
return string(b) return string(b)
} }
// getNeighborPeers is a helper function to return list of peers // GenerateSyncID generates a random string with given length
// based on different neightbor map func GenerateSyncID() [SyncIDLength]byte {
func getNeighborPeers(neighbor *sync.Map) []p2p.Peer { var syncID [SyncIDLength]byte
tmp := []p2p.Peer{} copy(syncID[:], GenerateRandomString(SyncIDLength))
neighbor.Range(func(k, v interface{}) bool { return syncID
p := v.(p2p.Peer)
t := p.Port
p.Port = legacysync.GetSyncingPort(t)
tmp = append(tmp, p)
return true
})
return tmp
}
// DoSyncWithoutConsensus gets sync-ed to blockchain without joining consensus
func (node *Node) DoSyncWithoutConsensus() {
go node.DoSyncing(node.Blockchain(), node.Worker, false) //Don't join consensus
}
// IsSameHeight tells whether node is at same bc height as a peer
func (node *Node) IsSameHeight() (uint64, bool) {
return node.SyncInstance().IsSameBlockchainHeight(node.Blockchain())
} }
func (node *Node) createStateSync(bc core.BlockChain) *legacysync.StateSync { func (node *Node) createStateSync(bc core.BlockChain) *legacysync.StateSync {

Loading…
Cancel
Save