Removed legacy syncing peer provider. (#4260)

* Removed legacy syncing peer provider.

* Fix localnet.

* Fix migrate version.

* Rebased on main.

* Fix formatting.
pull/4318/head
Konstantin 2 years ago committed by GitHub
parent f75cccfe39
commit 8547c8c7b8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      cmd/harmony/config.go
  2. 6
      cmd/harmony/config_migrations.go
  3. 2
      cmd/harmony/default.go
  4. 4
      cmd/harmony/flags.go
  5. 19
      cmd/harmony/flags_test.go
  6. 2
      cmd/harmony/main.go
  7. 1
      internal/configs/harmony/harmony.go
  8. 28
      node/node.go
  9. 30
      node/node_syncing.go
  10. 118
      node/node_test.go
  11. 3
      rosetta/infra/harmony-mainnet.conf
  12. 3
      rosetta/infra/harmony-pstn.conf

@ -83,7 +83,6 @@ func getDefaultDNSSyncConfig(nt nodeconfig.NetworkType) harmonyconfig.DnsSync {
dnsSync := harmonyconfig.DnsSync{ dnsSync := harmonyconfig.DnsSync{
Port: port, Port: port,
Zone: zone, Zone: zone,
LegacySyncing: false,
ServerPort: nodeconfig.DefaultDNSPort, ServerPort: nodeconfig.DefaultDNSPort,
} }
switch nt { switch nt {

@ -288,6 +288,12 @@ func init() {
confTree.Set("Version", "2.5.7") confTree.Set("Version", "2.5.7")
return confTree return confTree
} }
migrations["2.5.7"] = func(confTree *toml.Tree) *toml.Tree {
confTree.Delete("DNSSync.LegacySyncing")
confTree.Set("Version", "2.5.8")
return confTree
}
// check that the latest version here is the same as in default.go // check that the latest version here is the same as in default.go
largestKey := getNextVersion(migrations) largestKey := getNextVersion(migrations)

@ -5,7 +5,7 @@ import (
nodeconfig "github.com/harmony-one/harmony/internal/configs/node" nodeconfig "github.com/harmony-one/harmony/internal/configs/node"
) )
const tomlConfigVersion = "2.5.7" const tomlConfigVersion = "2.5.8"
const ( const (
defNetworkType = nodeconfig.Mainnet defNetworkType = nodeconfig.Mainnet

@ -497,10 +497,6 @@ func applyDNSSyncFlags(cmd *cobra.Command, cfg *harmonyconfig.HarmonyConfig) {
} else if cli.IsFlagChanged(cmd, legacyDNSZoneFlag) { } else if cli.IsFlagChanged(cmd, legacyDNSZoneFlag) {
cfg.DNSSync.Zone = cli.GetStringFlagValue(cmd, legacyDNSZoneFlag) cfg.DNSSync.Zone = cli.GetStringFlagValue(cmd, legacyDNSZoneFlag)
} else if cli.IsFlagChanged(cmd, legacyDNSFlag) { } else if cli.IsFlagChanged(cmd, legacyDNSFlag) {
val := cli.GetBoolFlagValue(cmd, legacyDNSFlag)
if !val {
cfg.DNSSync.LegacySyncing = true
}
} }
if cli.IsFlagChanged(cmd, dnsPortFlag) { if cli.IsFlagChanged(cmd, dnsPortFlag) {

@ -297,7 +297,6 @@ func TestNetworkFlags(t *testing.T) {
DNSSync: harmonyconfig.DnsSync{ DNSSync: harmonyconfig.DnsSync{
Port: 9001, Port: 9001,
Zone: "8.8.8.8", Zone: "8.8.8.8",
LegacySyncing: false,
Server: true, Server: true,
ServerPort: 9002, ServerPort: 9002,
}, },
@ -314,24 +313,6 @@ func TestNetworkFlags(t *testing.T) {
DNSSync: harmonyconfig.DnsSync{ DNSSync: harmonyconfig.DnsSync{
Port: 9001, Port: 9001,
Zone: "8.8.8.8", Zone: "8.8.8.8",
LegacySyncing: false,
Server: true,
ServerPort: nodeconfig.GetDefaultDNSPort(nodeconfig.Pangaea),
},
},
},
{
args: []string{"--dns=false"},
expConfig: harmonyconfig.HarmonyConfig{
Network: harmonyconfig.NetworkConfig{
NetworkType: defNetworkType,
BootNodes: nodeconfig.GetDefaultBootNodes(defNetworkType),
},
DNSSync: harmonyconfig.DnsSync{
Port: nodeconfig.GetDefaultDNSPort(defNetworkType),
Zone: nodeconfig.GetDefaultDNSZone(defNetworkType),
LegacySyncing: true,
Client: true,
Server: true, Server: true,
ServerPort: nodeconfig.GetDefaultDNSPort(nodeconfig.Pangaea), ServerPort: nodeconfig.GetDefaultDNSPort(nodeconfig.Pangaea),
}, },

@ -730,8 +730,6 @@ func setupConsensusAndNode(hc harmonyconfig.HarmonyConfig, nodeConfig *nodeconfi
selfPort := hc.P2P.Port selfPort := hc.P2P.Port
currentNode.SyncingPeerProvider = node.NewLocalSyncingPeerProvider( currentNode.SyncingPeerProvider = node.NewLocalSyncingPeerProvider(
6000, uint16(selfPort), epochConfig.NumShards(), uint32(epochConfig.NumNodesPerShard())) 6000, uint16(selfPort), epochConfig.NumShards(), uint32(epochConfig.NumNodesPerShard()))
} else if hc.DNSSync.LegacySyncing {
currentNode.SyncingPeerProvider = node.NewLegacySyncingPeerProvider(currentNode)
} else { } else {
currentNode.SyncingPeerProvider = node.NewDNSSyncingPeerProvider(hc.DNSSync.Zone, strconv.Itoa(hc.DNSSync.Port)) currentNode.SyncingPeerProvider = node.NewDNSSyncingPeerProvider(hc.DNSSync.Zone, strconv.Itoa(hc.DNSSync.Port))
} }

@ -35,7 +35,6 @@ type HarmonyConfig struct {
type DnsSync struct { type DnsSync struct {
Port int // replaces: Network.DNSSyncPort Port int // replaces: Network.DNSSyncPort
Zone string // replaces: Network.DNSZone Zone string // replaces: Network.DNSZone
LegacySyncing bool // replaces: Network.LegacySyncing
Client bool // replaces: Sync.LegacyClient Client bool // replaces: Sync.LegacyClient
Server bool // replaces: Sync.LegacyServer Server bool // replaces: Sync.LegacyServer
ServerPort int ServerPort int

@ -93,11 +93,7 @@ type Node struct {
// Shard databases // Shard databases
shardChains shardchain.Collection shardChains shardchain.Collection
SelfPeer p2p.Peer SelfPeer p2p.Peer
// TODO: Neighbors should store only neighbor nodes in the same shard
Neighbors sync.Map // All the neighbor nodes, key is the sha256 of Peer IP/Port, value is the p2p.Peer
stateMutex sync.Mutex // mutex for change node state stateMutex sync.Mutex // mutex for change node state
// BeaconNeighbors store only neighbor nodes in the beacon chain shard
BeaconNeighbors sync.Map // All the neighbor nodes, key is the sha256 of Peer IP/Port, value is the p2p.Peer
TxPool *core.TxPool TxPool *core.TxPool
CxPool *core.CxPool // pool for missing cross shard receipts resend CxPool *core.CxPool // pool for missing cross shard receipts resend
Worker *worker.Worker Worker *worker.Worker
@ -1228,30 +1224,6 @@ func (node *Node) InitConsensusWithValidators() (err error) {
return nil return nil
} }
// AddPeers adds neighbors nodes
func (node *Node) AddPeers(peers []*p2p.Peer) int {
for _, p := range peers {
key := fmt.Sprintf("%s:%s:%s", p.IP, p.Port, p.PeerID)
_, ok := node.Neighbors.LoadOrStore(key, *p)
if !ok {
// !ok means new peer is stored
node.host.AddPeer(p)
continue
}
}
return node.host.GetPeerCount()
}
// AddBeaconPeer adds beacon chain neighbors nodes
// Return false means new neighbor peer was added
// Return true means redundant neighbor peer wasn't added
func (node *Node) AddBeaconPeer(p *p2p.Peer) bool {
key := fmt.Sprintf("%s:%s:%s", p.IP, p.Port, p.PeerID)
_, ok := node.BeaconNeighbors.LoadOrStore(key, *p)
return ok
}
func (node *Node) initNodeConfiguration() (service.NodeConfig, chan p2p.Peer, error) { func (node *Node) initNodeConfiguration() (service.NodeConfig, chan p2p.Peer, error) {
chanPeer := make(chan p2p.Peer) chanPeer := make(chan p2p.Peer)
nodeConfig := service.NodeConfig{ nodeConfig := service.NodeConfig{

@ -115,36 +115,6 @@ type SyncingPeerProvider interface {
SyncingPeers(shardID uint32) (peers []p2p.Peer, err error) SyncingPeers(shardID uint32) (peers []p2p.Peer, err error)
} }
// LegacySyncingPeerProvider uses neighbor lists stored in a Node to serve
// syncing peer list query.
type LegacySyncingPeerProvider struct {
node *Node
shardID func() uint32
}
// NewLegacySyncingPeerProvider creates and returns a new node-based syncing
// peer provider.
func NewLegacySyncingPeerProvider(node *Node) *LegacySyncingPeerProvider {
var shardID func() uint32
if node.shardChains != nil {
shardID = node.Blockchain().ShardID
}
return &LegacySyncingPeerProvider{node: node, shardID: shardID}
}
// SyncingPeers returns peers stored in neighbor maps in the node structure.
func (p *LegacySyncingPeerProvider) SyncingPeers(shardID uint32) (peers []p2p.Peer, err error) {
switch shardID {
case p.shardID():
peers = getNeighborPeers(&p.node.Neighbors)
case 0:
peers = getNeighborPeers(&p.node.BeaconNeighbors)
default:
return nil, errors.Errorf("unsupported shard ID %v", shardID)
}
return peers, nil
}
// DNSSyncingPeerProvider uses the given DNS zone to resolve syncing peers. // DNSSyncingPeerProvider uses the given DNS zone to resolve syncing peers.
type DNSSyncingPeerProvider struct { type DNSSyncingPeerProvider struct {
zone, port string zone, port string

@ -2,7 +2,6 @@ package node
import ( import (
"errors" "errors"
"sync"
"testing" "testing"
"github.com/harmony-one/harmony/consensus" "github.com/harmony-one/harmony/consensus"
@ -61,59 +60,6 @@ func TestNewNode(t *testing.T) {
} }
} }
func TestLegacySyncingPeerProvider(t *testing.T) {
t.Run("ShardChain", func(t *testing.T) {
p := makeLegacySyncingPeerProvider()
expectedPeers := []p2p.Peer{
{IP: "127.0.0.1", Port: "6001"},
{IP: "127.0.0.1", Port: "6003"},
}
actualPeers, err := p.SyncingPeers(1)
if assert.NoError(t, err) {
assert.ElementsMatch(t, actualPeers, expectedPeers)
}
})
t.Run("BeaconChain", func(t *testing.T) {
p := makeLegacySyncingPeerProvider()
expectedPeers := []p2p.Peer{
{IP: "127.0.0.1", Port: "6000"},
{IP: "127.0.0.1", Port: "6002"},
}
actualPeers, err := p.SyncingPeers(0)
if assert.NoError(t, err) {
assert.ElementsMatch(t, actualPeers, expectedPeers)
}
})
t.Run("NoMatch", func(t *testing.T) {
p := makeLegacySyncingPeerProvider()
_, err := p.SyncingPeers(999)
assert.Error(t, err)
})
}
func makeLegacySyncingPeerProvider() *LegacySyncingPeerProvider {
node := makeSyncOnlyNode()
p := NewLegacySyncingPeerProvider(node)
p.shardID = func() uint32 { return 1 }
return p
}
func makeSyncOnlyNode() *Node {
node := &Node{
Neighbors: sync.Map{},
BeaconNeighbors: sync.Map{},
}
node.Neighbors.Store(
"127.0.0.1:9001:omg", p2p.Peer{IP: "127.0.0.1", Port: "9001"})
node.Neighbors.Store(
"127.0.0.1:9003:wtf", p2p.Peer{IP: "127.0.0.1", Port: "9003"})
node.BeaconNeighbors.Store(
"127.0.0.1:9000:bbq", p2p.Peer{IP: "127.0.0.1", Port: "9000"})
node.BeaconNeighbors.Store(
"127.0.0.1:9002:cakes", p2p.Peer{IP: "127.0.0.1", Port: "9002"})
return node
}
func TestDNSSyncingPeerProvider(t *testing.T) { func TestDNSSyncingPeerProvider(t *testing.T) {
t.Run("Happy", func(t *testing.T) { t.Run("Happy", func(t *testing.T) {
p := NewDNSSyncingPeerProvider("example.com", "1234") p := NewDNSSyncingPeerProvider("example.com", "1234")
@ -181,67 +127,3 @@ func TestLocalSyncingPeerProvider(t *testing.T) {
func makeLocalSyncingPeerProvider() *LocalSyncingPeerProvider { func makeLocalSyncingPeerProvider() *LocalSyncingPeerProvider {
return NewLocalSyncingPeerProvider(6000, 6001, 2, 3) return NewLocalSyncingPeerProvider(6000, 6001, 2, 3)
} }
func TestAddBeaconPeer(t *testing.T) {
pubKey1 := bls.RandPrivateKey().GetPublicKey()
pubKey2 := bls.RandPrivateKey().GetPublicKey()
peers1 := []*p2p.Peer{
{
IP: "127.0.0.1",
Port: "8888",
ConsensusPubKey: pubKey1,
PeerID: "1234",
},
{
IP: "127.0.0.1",
Port: "9999",
ConsensusPubKey: pubKey2,
PeerID: "4567",
},
}
blsKey := bls.RandPrivateKey()
pubKey := blsKey.GetPublicKey()
leader := p2p.Peer{IP: "127.0.0.1", Port: "8982", ConsensusPubKey: pubKey}
priKey, _, _ := utils.GenKeyP2P("127.0.0.1", "9902")
host, err := p2p.NewHost(p2p.HostConfig{
Self: &leader,
BLSKey: priKey,
})
if err != nil {
t.Fatalf("newhost failure: %v", err)
}
engine := chain.NewEngine()
chainconfig := nodeconfig.GetShardConfig(shard.BeaconChainShardID).GetNetworkType().ChainConfig()
collection := shardchain.NewCollection(
nil, testDBFactory, &core.GenesisInitializer{NetworkType: nodeconfig.GetShardConfig(shard.BeaconChainShardID).GetNetworkType()}, engine, &chainconfig,
)
blockchain, err := collection.ShardChain(shard.BeaconChainShardID)
if err != nil {
t.Fatalf("Cannot craeate consensus: %v", err)
}
decider := quorum.NewDecider(
quorum.SuperMajorityVote, shard.BeaconChainShardID,
)
consensus, err := consensus.New(
host, shard.BeaconChainShardID, multibls.GetPrivateKeys(blsKey), blockchain, decider, 3, false,
)
archiveMode := make(map[uint32]bool)
archiveMode[0] = true
archiveMode[1] = false
node := New(host, consensus, engine, collection, nil, nil, nil, archiveMode, nil)
for _, p := range peers1 {
ret := node.AddBeaconPeer(p)
if ret {
t.Errorf("AddBeaconPeer Failed, expecting false, got %v, peer %v", ret, p)
}
}
for _, p := range peers1 {
ret := node.AddBeaconPeer(p)
if !ret {
t.Errorf("AddBeaconPeer Failed, expecting true, got %v, peer %v", ret, p)
}
}
}

@ -1,4 +1,4 @@
Version = "2.5.7" Version = "2.5.8"
[BLSKeys] [BLSKeys]
KMSConfigFile = "" KMSConfigFile = ""
@ -18,7 +18,6 @@ Version = "2.5.7"
[DNSSync] [DNSSync]
Client = true Client = true
LegacySyncing = false
Port = 6000 Port = 6000
Server = true Server = true
ServerPort = 6000 ServerPort = 6000

@ -1,4 +1,4 @@
Version = "2.5.7" Version = "2.5.8"
[BLSKeys] [BLSKeys]
KMSConfigFile = "" KMSConfigFile = ""
@ -18,7 +18,6 @@ Version = "2.5.7"
[DNSSync] [DNSSync]
Client = true Client = true
LegacySyncing = false
Port = 6000 Port = 6000
Server = true Server = true
ServerPort = 6000 ServerPort = 6000

Loading…
Cancel
Save