[project] Unused yaml files, staticcheck fixes, dead tests that only delay build (#2755)

* [project] Unused yaml files

* [core] Remove dead tx_cacher.go

* [project] Further fixes from staticcheck
pull/2758/head
Edgar Aroutiounian 5 years ago committed by GitHub
parent a7b79616e2
commit 094a61301d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      .coveralls.yml
  2. 4
      api/service/blockproposal/service.go
  3. 4
      api/service/clientsupport/service.go
  4. 4
      api/service/consensus/service.go
  5. 6
      api/service/discovery/discovery_test.go
  6. 4
      api/service/explorer/service.go
  7. 59
      api/service/manager_test.go
  8. 18
      api/service/networkinfo/service.go
  9. 69
      api/service/syncing/syncing.go
  10. 7
      api/service/syncing/syncing_test.go
  11. 22
      appspec.yml
  12. 63
      core/tx_cacher.go
  13. 2
      node/service_setup.go

@ -1,2 +0,0 @@
repo_token: cr4Aim5IFC8A7IvStlMHQbVMRvBhRq0YH

@ -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) {

@ -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 {

@ -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) {

@ -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")

@ -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) {

@ -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,
)
}
}

@ -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) {

@ -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()

@ -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) {

@ -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

@ -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 <http://www.gnu.org/licenses/>.
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])
}
}
}

@ -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),

Loading…
Cancel
Save