From 47386c06a5df43a17ab23f9224637a4f53dd5c0e Mon Sep 17 00:00:00 2001 From: frozen <355847+Frozen@users.noreply.github.com> Date: Wed, 22 Mar 2023 00:06:39 -0300 Subject: [PATCH] Clean up code. --- node/node.go | 2 +- node/node_syncing.go | 28 +++++----------------------- 2 files changed, 6 insertions(+), 24 deletions(-) diff --git a/node/node.go b/node/node.go index ba398d628..13988e2ad 100644 --- a/node/node.go +++ b/node/node.go @@ -1029,6 +1029,7 @@ func New( unixTimeAtNodeStart: time.Now().Unix(), TransactionErrorSink: types.NewTransactionErrorSink(), crosslinks: crosslinks.New(), + syncID: GenerateSyncID(), } // Get the node config that's created in the harmony.go program. @@ -1039,7 +1040,6 @@ func New( } node.HarmonyConfig = harmonyconfig - copy(node.syncID[:], GenerateRandomString(SyncIDLength)) if host != nil { node.host = host node.SelfPeer = host.GetSelfPeer() diff --git a/node/node_syncing.go b/node/node_syncing.go index a0a8e6c84..05ddd4b6b 100644 --- a/node/node_syncing.go +++ b/node/node_syncing.go @@ -5,7 +5,6 @@ import ( "math/rand" "net" "strconv" - "sync" "time" "github.com/harmony-one/harmony/internal/tikv" @@ -65,28 +64,11 @@ func GenerateRandomString(n int) string { return string(b) } -// getNeighborPeers is a helper function to return list of peers -// based on different neightbor map -func getNeighborPeers(neighbor *sync.Map) []p2p.Peer { - tmp := []p2p.Peer{} - neighbor.Range(func(k, v interface{}) bool { - 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()) +// GenerateSyncID generates a random string with given length +func GenerateSyncID() [SyncIDLength]byte { + var syncID [SyncIDLength]byte + copy(syncID[:], GenerateRandomString(SyncIDLength)) + return syncID } func (node *Node) createStateSync(bc core.BlockChain) *legacysync.StateSync {