Merge pull request #3587 from JackyWYX/stream_legacysync

[stream] rename dns syncing package to legacysync
pull/3586/head
Rongjian Lan 4 years ago committed by GitHub
commit 53bde710af
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 6
      api/service/explorer/service.go
  2. 2
      api/service/legacysync/downloader/client.go
  3. 0
      api/service/legacysync/downloader/errors.go
  4. 0
      api/service/legacysync/downloader/gen.sh
  5. 2
      api/service/legacysync/downloader/interface.go
  6. 0
      api/service/legacysync/downloader/proto/downloader.go
  7. 0
      api/service/legacysync/downloader/proto/downloader.pb.go
  8. 0
      api/service/legacysync/downloader/proto/downloader.proto
  9. 2
      api/service/legacysync/downloader/server.go
  10. 2
      api/service/legacysync/errors.go
  11. 6
      api/service/legacysync/syncing.go
  12. 0
      api/service/legacysync/syncing.md
  13. 4
      api/service/legacysync/syncing_test.go
  14. 4
      cmd/harmony/main.go
  15. 6
      node/node.go
  16. 20
      node/node_syncing.go

@ -14,7 +14,7 @@ import (
"github.com/ethereum/go-ethereum/rpc" "github.com/ethereum/go-ethereum/rpc"
"github.com/gorilla/mux" "github.com/gorilla/mux"
msg_pb "github.com/harmony-one/harmony/api/proto/message" msg_pb "github.com/harmony-one/harmony/api/proto/message"
"github.com/harmony-one/harmony/api/service/syncing" "github.com/harmony-one/harmony/api/service/legacysync"
"github.com/harmony-one/harmony/core" "github.com/harmony-one/harmony/core"
"github.com/harmony-one/harmony/internal/chain" "github.com/harmony-one/harmony/internal/chain"
"github.com/harmony-one/harmony/internal/common" "github.com/harmony-one/harmony/internal/common"
@ -45,12 +45,12 @@ type Service struct {
Storage *Storage Storage *Storage
server *http.Server server *http.Server
messageChan chan *msg_pb.Message messageChan chan *msg_pb.Message
stateSync *syncing.StateSync stateSync *legacysync.StateSync
blockchain *core.BlockChain blockchain *core.BlockChain
} }
// New returns explorer service. // New returns explorer service.
func New(selfPeer *p2p.Peer, ss *syncing.StateSync, bc *core.BlockChain) *Service { func New(selfPeer *p2p.Peer, ss *legacysync.StateSync, bc *core.BlockChain) *Service {
return &Service{IP: selfPeer.IP, Port: selfPeer.Port, stateSync: ss, blockchain: bc} return &Service{IP: selfPeer.IP, Port: selfPeer.Port, stateSync: ss, blockchain: bc}
} }

@ -5,7 +5,7 @@ import (
"fmt" "fmt"
"time" "time"
pb "github.com/harmony-one/harmony/api/service/syncing/downloader/proto" pb "github.com/harmony-one/harmony/api/service/legacysync/downloader/proto"
"github.com/harmony-one/harmony/internal/utils" "github.com/harmony-one/harmony/internal/utils"
"google.golang.org/grpc" "google.golang.org/grpc"
) )

@ -1,7 +1,7 @@
package downloader package downloader
import ( import (
pb "github.com/harmony-one/harmony/api/service/syncing/downloader/proto" pb "github.com/harmony-one/harmony/api/service/legacysync/downloader/proto"
) )
// DownloadInterface is the interface for downloader package. // DownloadInterface is the interface for downloader package.

@ -5,7 +5,7 @@ import (
"log" "log"
"net" "net"
pb "github.com/harmony-one/harmony/api/service/syncing/downloader/proto" pb "github.com/harmony-one/harmony/api/service/legacysync/downloader/proto"
"github.com/harmony-one/harmony/internal/utils" "github.com/harmony-one/harmony/internal/utils"
"google.golang.org/grpc" "google.golang.org/grpc"

@ -1,4 +1,4 @@
package syncing package legacysync
import "errors" import "errors"

@ -1,4 +1,4 @@
package syncing package legacysync
import ( import (
"bytes" "bytes"
@ -14,8 +14,8 @@ import (
"github.com/Workiva/go-datastructures/queue" "github.com/Workiva/go-datastructures/queue"
"github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/rlp" "github.com/ethereum/go-ethereum/rlp"
"github.com/harmony-one/harmony/api/service/syncing/downloader" "github.com/harmony-one/harmony/api/service/legacysync/downloader"
pb "github.com/harmony-one/harmony/api/service/syncing/downloader/proto" pb "github.com/harmony-one/harmony/api/service/legacysync/downloader/proto"
"github.com/harmony-one/harmony/consensus" "github.com/harmony-one/harmony/consensus"
"github.com/harmony-one/harmony/consensus/engine" "github.com/harmony-one/harmony/consensus/engine"
"github.com/harmony-one/harmony/core" "github.com/harmony-one/harmony/core"

@ -1,4 +1,4 @@
package syncing package legacysync
import ( import (
"errors" "errors"
@ -7,7 +7,7 @@ import (
"strings" "strings"
"testing" "testing"
"github.com/harmony-one/harmony/api/service/syncing/downloader" "github.com/harmony-one/harmony/api/service/legacysync/downloader"
"github.com/harmony-one/harmony/p2p" "github.com/harmony-one/harmony/p2p"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
) )

@ -20,8 +20,8 @@ import (
"github.com/ethereum/go-ethereum/log" "github.com/ethereum/go-ethereum/log"
"github.com/harmony-one/bls/ffi/go/bls" "github.com/harmony-one/bls/ffi/go/bls"
"github.com/harmony-one/harmony/api/service" "github.com/harmony-one/harmony/api/service"
"github.com/harmony-one/harmony/api/service/legacysync"
"github.com/harmony-one/harmony/api/service/prometheus" "github.com/harmony-one/harmony/api/service/prometheus"
"github.com/harmony-one/harmony/api/service/syncing"
"github.com/harmony-one/harmony/common/fdlimit" "github.com/harmony-one/harmony/common/fdlimit"
"github.com/harmony-one/harmony/common/ntp" "github.com/harmony-one/harmony/common/ntp"
"github.com/harmony-one/harmony/consensus" "github.com/harmony-one/harmony/consensus"
@ -633,7 +633,7 @@ func setupConsensusAndNode(hc harmonyConfig, nodeConfig *nodeconfig.ConfigType)
} else if hc.Network.LegacySyncing { } else if hc.Network.LegacySyncing {
currentNode.SyncingPeerProvider = node.NewLegacySyncingPeerProvider(currentNode) currentNode.SyncingPeerProvider = node.NewLegacySyncingPeerProvider(currentNode)
} else { } else {
currentNode.SyncingPeerProvider = node.NewDNSSyncingPeerProvider(hc.Network.DNSZone, syncing.GetSyncingPort(strconv.Itoa(hc.Network.DNSPort))) currentNode.SyncingPeerProvider = node.NewDNSSyncingPeerProvider(hc.Network.DNSZone, legacysync.GetSyncingPort(strconv.Itoa(hc.Network.DNSPort)))
} }
// TODO: refactor the creation of blockchain out of node.New() // TODO: refactor the creation of blockchain out of node.New()

@ -17,8 +17,8 @@ import (
msg_pb "github.com/harmony-one/harmony/api/proto/message" msg_pb "github.com/harmony-one/harmony/api/proto/message"
proto_node "github.com/harmony-one/harmony/api/proto/node" proto_node "github.com/harmony-one/harmony/api/proto/node"
"github.com/harmony-one/harmony/api/service" "github.com/harmony-one/harmony/api/service"
"github.com/harmony-one/harmony/api/service/syncing" "github.com/harmony-one/harmony/api/service/legacysync"
"github.com/harmony-one/harmony/api/service/syncing/downloader" "github.com/harmony-one/harmony/api/service/legacysync/downloader"
"github.com/harmony-one/harmony/consensus" "github.com/harmony-one/harmony/consensus"
"github.com/harmony-one/harmony/core" "github.com/harmony-one/harmony/core"
"github.com/harmony-one/harmony/core/rawdb" "github.com/harmony-one/harmony/core/rawdb"
@ -90,7 +90,7 @@ type Node struct {
downloaderServer *downloader.Server downloaderServer *downloader.Server
// Syncing component. // Syncing component.
syncID [SyncIDLength]byte // a unique ID for the node during the state syncing process with peers syncID [SyncIDLength]byte // a unique ID for the node during the state syncing process with peers
stateSync, beaconSync *syncing.StateSync stateSync, beaconSync *legacysync.StateSync
peerRegistrationRecord map[string]*syncConfig // record registration time (unixtime) of peers begin in syncing peerRegistrationRecord map[string]*syncConfig // record registration time (unixtime) of peers begin in syncing
SyncingPeerProvider SyncingPeerProvider SyncingPeerProvider SyncingPeerProvider
// The p2p host used to send/receive p2p messages // The p2p host used to send/receive p2p messages

@ -9,9 +9,9 @@ import (
"github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/rlp" "github.com/ethereum/go-ethereum/rlp"
"github.com/harmony-one/harmony/api/service/syncing" "github.com/harmony-one/harmony/api/service/legacysync"
"github.com/harmony-one/harmony/api/service/syncing/downloader" "github.com/harmony-one/harmony/api/service/legacysync/downloader"
downloader_pb "github.com/harmony-one/harmony/api/service/syncing/downloader/proto" downloader_pb "github.com/harmony-one/harmony/api/service/legacysync/downloader/proto"
"github.com/harmony-one/harmony/core" "github.com/harmony-one/harmony/core"
"github.com/harmony-one/harmony/core/types" "github.com/harmony-one/harmony/core/types"
nodeconfig "github.com/harmony-one/harmony/internal/configs/node" nodeconfig "github.com/harmony-one/harmony/internal/configs/node"
@ -49,7 +49,7 @@ func getNeighborPeers(neighbor *sync.Map) []p2p.Peer {
neighbor.Range(func(k, v interface{}) bool { neighbor.Range(func(k, v interface{}) bool {
p := v.(p2p.Peer) p := v.(p2p.Peer)
t := p.Port t := p.Port
p.Port = syncing.GetSyncingPort(t) p.Port = legacysync.GetSyncingPort(t)
tmp = append(tmp, p) tmp = append(tmp, p)
return true return true
}) })
@ -69,8 +69,8 @@ func (node *Node) IsSameHeight() (uint64, bool) {
return node.stateSync.IsSameBlockchainHeight(node.Blockchain()) return node.stateSync.IsSameBlockchainHeight(node.Blockchain())
} }
func (node *Node) getStateSync() *syncing.StateSync { func (node *Node) getStateSync() *legacysync.StateSync {
return syncing.CreateStateSync(node.SelfPeer.IP, node.SelfPeer.Port, return legacysync.CreateStateSync(node.SelfPeer.IP, node.SelfPeer.Port,
node.GetSyncID(), node.NodeConfig.Role() == nodeconfig.ExplorerNode) node.GetSyncID(), node.NodeConfig.Role() == nodeconfig.ExplorerNode)
} }
@ -245,7 +245,7 @@ func (node *Node) DoSyncing(bc *core.BlockChain, worker *worker.Worker, willJoin
// doSync keep the node in sync with other peers, willJoinConsensus means the node will try to join consensus after catch up // doSync keep the node in sync with other peers, willJoinConsensus means the node will try to join consensus after catch up
func (node *Node) doSync(bc *core.BlockChain, worker *worker.Worker, willJoinConsensus bool) { func (node *Node) doSync(bc *core.BlockChain, worker *worker.Worker, willJoinConsensus bool) {
if node.stateSync.GetActivePeerNumber() < syncing.NumPeersLowBound { if node.stateSync.GetActivePeerNumber() < legacysync.NumPeersLowBound {
shardID := bc.ShardID() shardID := bc.ShardID()
peers, err := node.SyncingPeerProvider.SyncingPeers(shardID) peers, err := node.SyncingPeerProvider.SyncingPeers(shardID)
if err != nil { if err != nil {
@ -321,7 +321,7 @@ func (node *Node) InitSyncingServer() {
func (node *Node) StartSyncingServer() { func (node *Node) StartSyncingServer() {
utils.Logger().Info().Msg("[SYNC] support_syncing: StartSyncingServer") utils.Logger().Info().Msg("[SYNC] support_syncing: StartSyncingServer")
if node.downloaderServer.GrpcServer == nil { if node.downloaderServer.GrpcServer == nil {
node.downloaderServer.Start(node.SelfPeer.IP, syncing.GetSyncingPort(node.SelfPeer.Port)) node.downloaderServer.Start(node.SelfPeer.IP, legacysync.GetSyncingPort(node.SelfPeer.Port))
} }
} }
@ -371,7 +371,7 @@ func (node *Node) CalculateResponse(request *downloader_pb.DownloaderRequest, in
if request.BlockHash == nil { if request.BlockHash == nil {
return response, fmt.Errorf("[SYNC] GetBlockHashes Request BlockHash is NIL") return response, fmt.Errorf("[SYNC] GetBlockHashes Request BlockHash is NIL")
} }
if request.Size == 0 || request.Size > syncing.SyncLoopBatchSize { if request.Size == 0 || request.Size > legacysync.SyncLoopBatchSize {
return response, fmt.Errorf("[SYNC] GetBlockHashes Request contains invalid Size %v", request.Size) return response, fmt.Errorf("[SYNC] GetBlockHashes Request contains invalid Size %v", request.Size)
} }
size := uint64(request.Size) size := uint64(request.Size)
@ -465,7 +465,7 @@ func (node *Node) CalculateResponse(request *downloader_pb.DownloaderRequest, in
return response, nil return response, nil
} else { } else {
response.Type = downloader_pb.DownloaderResponse_FAIL response.Type = downloader_pb.DownloaderResponse_FAIL
syncPort := syncing.GetSyncingPort(port) syncPort := legacysync.GetSyncingPort(port)
client := downloader.ClientSetup(ip, syncPort) client := downloader.ClientSetup(ip, syncPort)
if client == nil { if client == nil {
utils.Logger().Warn(). utils.Logger().Warn().

Loading…
Cancel
Save