diff --git a/.coveralls.yml b/.coveralls.yml deleted file mode 100644 index b9bb9a805..000000000 --- a/.coveralls.yml +++ /dev/null @@ -1,2 +0,0 @@ -repo_token: cr4Aim5IFC8A7IvStlMHQbVMRvBhRq0YH - diff --git a/api/service/blockproposal/service.go b/api/service/blockproposal/service.go index ad163d9bb..02eb97efd 100644 --- a/api/service/blockproposal/service.go +++ b/api/service/blockproposal/service.go @@ -47,9 +47,7 @@ func (s *Service) StopService() { } // NotifyService notify service -func (s *Service) NotifyService(params map[string]interface{}) { - return -} +func (s *Service) NotifyService(params map[string]interface{}) {} // SetMessageChan sets up message channel to service. func (s *Service) SetMessageChan(messageChan chan *msg_pb.Message) { diff --git a/api/service/clientsupport/service.go b/api/service/clientsupport/service.go index a8367a3af..4ab9ce570 100644 --- a/api/service/clientsupport/service.go +++ b/api/service/clientsupport/service.go @@ -52,9 +52,7 @@ func (s *Service) SetMessageChan(messageChan chan *msg_pb.Message) { } // NotifyService notify service -func (s *Service) NotifyService(params map[string]interface{}) { - return -} +func (s *Service) NotifyService(params map[string]interface{}) {} // APIs for the services. func (s *Service) APIs() []rpc.API { diff --git a/api/service/consensus/service.go b/api/service/consensus/service.go index 86b04d22a..483fc4310 100644 --- a/api/service/consensus/service.go +++ b/api/service/consensus/service.go @@ -41,9 +41,7 @@ func (s *Service) StopService() { } // NotifyService notify service -func (s *Service) NotifyService(params map[string]interface{}) { - return -} +func (s *Service) NotifyService(params map[string]interface{}) {} // SetMessageChan sets up message channel to service. func (s *Service) SetMessageChan(messageChan chan *msg_pb.Message) { diff --git a/api/service/discovery/discovery_test.go b/api/service/discovery/discovery_test.go index 0d143a509..d0c1b885f 100644 --- a/api/service/discovery/discovery_test.go +++ b/api/service/discovery/discovery_test.go @@ -12,11 +12,7 @@ import ( "github.com/harmony-one/harmony/p2p/p2pimpl" ) -var ( - ip = "127.0.0.1" - port = "7099" - dService *Service -) +var dService *Service func TestDiscoveryService(t *testing.T) { nodePriKey, _, err := utils.LoadKeyFromFile("/tmp/127.0.0.1.12345.key") diff --git a/api/service/explorer/service.go b/api/service/explorer/service.go index 7fc636d3b..342240474 100644 --- a/api/service/explorer/service.go +++ b/api/service/explorer/service.go @@ -160,9 +160,7 @@ func (s *Service) GetTotalSupply(w http.ResponseWriter, r *http.Request) { } // NotifyService notify service. -func (s *Service) NotifyService(params map[string]interface{}) { - return -} +func (s *Service) NotifyService(params map[string]interface{}) {} // SetMessageChan sets up message channel to service. func (s *Service) SetMessageChan(messageChan chan *msg_pb.Message) { diff --git a/api/service/manager_test.go b/api/service/manager_test.go index 5ab0fa1dd..bb2f95986 100644 --- a/api/service/manager_test.go +++ b/api/service/manager_test.go @@ -1,61 +1,12 @@ package service import ( - "fmt" "testing" - "time" - "github.com/ethereum/go-ethereum/rpc" msg_pb "github.com/harmony-one/harmony/api/proto/message" nodeconfig "github.com/harmony-one/harmony/internal/configs/node" ) -type SupportSyncingTest struct { - msgChan chan *msg_pb.Message - status *int -} - -func (s *SupportSyncingTest) StartService() { - fmt.Println("SupportSyncingTest starting") - if s.status != nil { - *s.status = 1 - } -} - -func (s *SupportSyncingTest) StopService() { - fmt.Println("SupportSyncingTest stopping") - if s.status != nil { - *s.status = 2 - } -} - -func (s *SupportSyncingTest) NotifyService(data map[string]interface{}) { - t := data["test"].(*testing.T) - - if s.msgChan != data["chan"].(chan *msg_pb.Message) { - t.Error("message chan is not equal to the one from the passing params") - } -} -func (s *SupportSyncingTest) SetMessageChan(msgChan chan *msg_pb.Message) { - s.msgChan = msgChan -} - -func (s *SupportSyncingTest) APIs() []rpc.API { return nil } - -// Test TakeAction. -func TestTakeAction(t *testing.T) { - m := &Manager{} - m.SetupServiceManager() - - for i := 0; i < 2; i++ { - select { - case <-time.After(100 * time.Millisecond): - return - } - } - -} - func TestMessageChan(t *testing.T) { m := &Manager{} m.SetupServiceManager() @@ -65,9 +16,15 @@ func TestMessageChan(t *testing.T) { func TestInit(t *testing.T) { if GroupIDShards[nodeconfig.ShardID(0)] != nodeconfig.NewGroupIDByShardID(0) { - t.Errorf("GroupIDShards[0]: %v != GroupIDBeacon: %v", GroupIDShards[nodeconfig.ShardID(0)], nodeconfig.NewGroupIDByShardID(0)) + t.Errorf("GroupIDShards[0]: %v != GroupIDBeacon: %v", + GroupIDShards[nodeconfig.ShardID(0)], + nodeconfig.NewGroupIDByShardID(0), + ) } if len(GroupIDShards) != nodeconfig.MaxShards { - t.Errorf("len(GroupIDShards): %v != TotalShards: %v", len(GroupIDShards), nodeconfig.MaxShards) + t.Errorf("len(GroupIDShards): %v != TotalShards: %v", + len(GroupIDShards), + nodeconfig.MaxShards, + ) } } diff --git a/api/service/networkinfo/service.go b/api/service/networkinfo/service.go index e09c34d0a..508d496c6 100644 --- a/api/service/networkinfo/service.go +++ b/api/service/networkinfo/service.go @@ -201,10 +201,14 @@ func (s *Service) DoService() { libp2pdis.Advertise(ctx, s.discovery, string(s.Rendezvous)) // 0 is beacon chain FIXME: use a constant libp2pdis.Advertise(ctx, s.discovery, string(nodeconfig.NewClientGroupIDByShardID(0))) - utils.Logger().Info().Str("Rendezvous", string(s.Rendezvous)).Msg("Successfully announced!") + utils.Logger().Info(). + Str("Rendezvous", string(s.Rendezvous)). + Msg("Successfully announced!") default: var err error - s.peerInfo, err = s.discovery.FindPeers(ctx, string(s.Rendezvous), coredis.Limit(discoveryLimit)) + s.peerInfo, err = s.discovery.FindPeers( + ctx, string(s.Rendezvous), coredis.Limit(discoveryLimit), + ) if err != nil { utils.Logger().Error().Err(err).Msg("FindPeers") return @@ -224,11 +228,6 @@ func (s *Service) findPeers(ctx context.Context) { } for peer := range s.peerInfo { if peer.ID != s.Host.GetP2PHost().ID() && len(peer.ID) > 0 { - // utils.Logger().Info(). - // Interface("peer", peer.ID). - // Interface("addr", peer.Addrs). - // Interface("my ID", s.Host.GetP2PHost().ID()). - // Msg("Found Peer") if err := s.Host.GetP2PHost().Connect(ctx, peer); err != nil { utils.Logger().Warn().Err(err).Interface("peer", peer).Msg("can't connect to peer node") // break if the node can't connect to peers, waiting for another peer @@ -260,7 +259,6 @@ func (s *Service) findPeers(ctx context.Context) { } utils.Logger().Info().Msg("PeerInfo Channel Closed") - return } // StopService stops network info service. @@ -279,9 +277,7 @@ func (s *Service) StopService() { } // NotifyService notify service -func (s *Service) NotifyService(params map[string]interface{}) { - return -} +func (s *Service) NotifyService(params map[string]interface{}) {} // SetMessageChan sets up message channel to service. func (s *Service) SetMessageChan(messageChan chan *msg_pb.Message) { diff --git a/api/service/syncing/syncing.go b/api/service/syncing/syncing.go index e1d07c2c7..3c6527df6 100644 --- a/api/service/syncing/syncing.go +++ b/api/service/syncing/syncing.go @@ -166,7 +166,7 @@ func (sc *SyncConfig) FindPeerByHash(peerHash []byte) *SyncPeerConfig { sc.mtx.RLock() defer sc.mtx.RUnlock() for _, pc := range sc.peers { - if bytes.Compare(pc.peerHash, peerHash) == 0 { + if bytes.Equal(pc.peerHash, peerHash) { return pc } } @@ -493,7 +493,7 @@ func (ss *StateSync) getMaxConsensusBlockFromParentHash(parentHash common.Hash) ss.syncConfig.ForEachPeer(func(peerConfig *SyncPeerConfig) (brk bool) { for _, block := range peerConfig.newBlocks { ph := block.ParentHash() - if bytes.Compare(ph[:], parentHash[:]) == 0 { + if bytes.Equal(ph[:], parentHash[:]) { candidateBlocks = append(candidateBlocks, block) break } @@ -521,7 +521,7 @@ func (ss *StateSync) getMaxConsensusBlockFromParentHash(parentHash common.Hash) func (ss *StateSync) getBlockFromOldBlocksByParentHash(parentHash common.Hash) *types.Block { for _, block := range ss.commonBlocks { ph := block.ParentHash() - if bytes.Compare(ph[:], parentHash[:]) == 0 { + if bytes.Equal(ph[:], parentHash[:]) { return block } } @@ -531,7 +531,7 @@ func (ss *StateSync) getBlockFromOldBlocksByParentHash(parentHash common.Hash) * func (ss *StateSync) getBlockFromLastMileBlocksByParentHash(parentHash common.Hash) *types.Block { for _, block := range ss.lastMileBlocks { ph := block.ParentHash() - if bytes.Compare(ph[:], parentHash[:]) == 0 { + if bytes.Equal(ph[:], parentHash[:]) { return block } } @@ -773,40 +773,33 @@ func (ss *StateSync) SyncLoop(bc *core.BlockChain, worker *worker.Worker, isBeac // remove SyncLoopFrequency ticker := time.NewTicker(SyncLoopFrequency * time.Second) defer ticker.Stop() -Loop: - for { - select { - case <-ticker.C: - otherHeight := ss.getMaxPeerHeight(isBeacon) - currentHeight := bc.CurrentBlock().NumberU64() - - if currentHeight >= otherHeight { - utils.Logger().Info(). - Msgf("[SYNC] Node is now IN SYNC! (isBeacon: %t, ShardID: %d, otherHeight: %d, currentHeight: %d)", - isBeacon, bc.ShardID(), otherHeight, currentHeight) - break Loop - } else { - utils.Logger().Debug(). - Msgf("[SYNC] Node is Not in Sync (isBeacon: %t, ShardID: %d, otherHeight: %d, currentHeight: %d)", - isBeacon, bc.ShardID(), otherHeight, currentHeight) - } - startHash := bc.CurrentBlock().Hash() - size := uint32(otherHeight - currentHeight) - if size > SyncLoopBatchSize { - size = SyncLoopBatchSize - } - err := ss.ProcessStateSync(startHash[:], size, bc, worker) - if err != nil { - utils.Logger().Error().Err(err). - Msgf("[SYNC] ProcessStateSync failed (isBeacon: %t, ShardID: %d, otherHeight: %d, currentHeight: %d)", - isBeacon, bc.ShardID(), otherHeight, currentHeight) - // should we still call UpdateConsensusInformation() upon state sync failure? - // how to handle error here? - } - ss.purgeOldBlocksFromCache() - if consensus != nil { - consensus.SetMode(consensus.UpdateConsensusInformation()) - } + for range ticker.C { + otherHeight := ss.getMaxPeerHeight(isBeacon) + currentHeight := bc.CurrentBlock().NumberU64() + if currentHeight >= otherHeight { + utils.Logger().Info(). + Msgf("[SYNC] Node is now IN SYNC! (isBeacon: %t, ShardID: %d, otherHeight: %d, currentHeight: %d)", + isBeacon, bc.ShardID(), otherHeight, currentHeight) + return + } + utils.Logger().Debug(). + Msgf("[SYNC] Node is Not in Sync (isBeacon: %t, ShardID: %d, otherHeight: %d, currentHeight: %d)", + isBeacon, bc.ShardID(), otherHeight, currentHeight) + + startHash := bc.CurrentBlock().Hash() + size := uint32(otherHeight - currentHeight) + if size > SyncLoopBatchSize { + size = SyncLoopBatchSize + } + err := ss.ProcessStateSync(startHash[:], size, bc, worker) + if err != nil { + utils.Logger().Error().Err(err). + Msgf("[SYNC] ProcessStateSync failed (isBeacon: %t, ShardID: %d, otherHeight: %d, currentHeight: %d)", + isBeacon, bc.ShardID(), otherHeight, currentHeight) + } + ss.purgeOldBlocksFromCache() + if consensus != nil { + consensus.SetMode(consensus.UpdateConsensusInformation()) } } ss.purgeAllBlocksFromCache() diff --git a/api/service/syncing/syncing_test.go b/api/service/syncing/syncing_test.go index ed395f292..902c90336 100644 --- a/api/service/syncing/syncing_test.go +++ b/api/service/syncing/syncing_test.go @@ -35,8 +35,11 @@ func TestCompareSyncPeerConfigByblockHashes(t *testing.T) { assert.Equal(t, CompareSyncPeerConfigByblockHashes(syncPeerConfig1, syncPeerConfig2), 0, "syncPeerConfig1 is equal to syncPeerConfig2") // syncPeerConfig1 is less than syncPeerConfig2 - blockHashes1 = blockHashes1[:1] - assert.Equal(t, CompareSyncPeerConfigByblockHashes(syncPeerConfig1, syncPeerConfig2), 0, "syncPeerConfig1 is less than syncPeerConfig2") + assert.Equal(t, + CompareSyncPeerConfigByblockHashes( + syncPeerConfig1, syncPeerConfig2, + ), + 0, "syncPeerConfig1 is less than syncPeerConfig2") } func TestCreateStateSync(t *testing.T) { diff --git a/appspec.yml b/appspec.yml deleted file mode 100644 index 49d72af78..000000000 --- a/appspec.yml +++ /dev/null @@ -1,22 +0,0 @@ -version: 0.0 -os: linux -files: - - source: / - destination: /home/ec2-user/projects/src/harmony -hooks: - BeforeInstall: - - location: aws-scripts/say_hello.sh - timeout: 10 - runas: root - AfterInstall: - - location: aws-scripts/setup.sh - timeout: 300 - runas: root - ApplicationStart: - - location: aws-scripts/run_instance.sh - timeout: 300 - runas: root - ApplicationStop: - - location: aws-scripts/say_bye.sh - timeout: 10 - runas: root diff --git a/core/tx_cacher.go b/core/tx_cacher.go deleted file mode 100644 index 14bf795c7..000000000 --- a/core/tx_cacher.go +++ /dev/null @@ -1,63 +0,0 @@ -// Copyright 2018 The go-ethereum Authors -// This file is part of the go-ethereum library. -// -// The go-ethereum library is free software: you can redistribute it and/or modify -// it under the terms of the GNU Lesser General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// The go-ethereum library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public License -// along with the go-ethereum library. If not, see . - -package core - -import ( - "github.com/ethereum/go-ethereum/core/types" -) - -// txSenderCacherRequest is a request for recovering transaction senders with a -// specific signature scheme and caching it into the transactions themselves. -// -// The inc field defines the number of transactions to skip after each recovery, -// which is used to feed the same underlying input array to different threads but -// ensure they process the early transactions fast. -type txSenderCacherRequest struct { - signer types.Signer - txs []*types.Transaction - inc int -} - -// txSenderCacher is a helper structure to concurrently ecrecover transaction -// senders from digital signatures on background threads. -type txSenderCacher struct { - threads int - tasks chan *txSenderCacherRequest -} - -// newTxSenderCacher creates a new transaction sender background cacher and starts -// as many processing goroutines as allowed by the GOMAXPROCS on construction. -func newTxSenderCacher(threads int) *txSenderCacher { - cacher := &txSenderCacher{ - tasks: make(chan *txSenderCacherRequest, threads), - threads: threads, - } - for i := 0; i < threads; i++ { - go cacher.cache() - } - return cacher -} - -// cache is an infinite loop, caching transaction senders from various forms of -// data structures. -func (cacher *txSenderCacher) cache() { - for task := range cacher.tasks { - for i := 0; i < len(task.txs); i += task.inc { - types.Sender(task.signer, task.txs[i]) - } - } -} diff --git a/node/service_setup.go b/node/service_setup.go index 5b77bbd59..f8bcdc52e 100644 --- a/node/service_setup.go +++ b/node/service_setup.go @@ -18,7 +18,7 @@ import ( func (node *Node) setupForValidator() { nodeConfig, chanPeer := node.initNodeConfiguration() - // Register peer discovery service. No need to do staking for beacon chain node. + // Register peer discovery service node.serviceManager.RegisterService( service.PeerDiscovery, discovery.New(node.host, nodeConfig, chanPeer, node.AddBeaconPeer),