fix initsync and host creation

pull/4351/head
“GheisMohammadi” 2 years ago committed by Casey Gardiner
parent 35d393cc79
commit 601422a631
  1. 15
      api/service/stagedstreamsync/downloader.go
  2. 2
      api/service/stagedstreamsync/stage_heads.go
  3. 16
      p2p/host.go
  4. 2
      p2p/stream/protocols/sync/protocol.go

@ -186,7 +186,7 @@ func (d *Downloader) waitForBootFinish() {
func (d *Downloader) loop() {
ticker := time.NewTicker(10 * time.Second)
defer ticker.Stop()
initSync := d.bc.ShardID() != shard.BeaconChainShardID
initSync := true
trigger := func() {
select {
case d.downloadC <- struct{}{}:
@ -228,11 +228,13 @@ func (d *Downloader) loop() {
time.Sleep(1 * time.Second)
continue
}
d.logger.Info().Int("block added", addedBN).
Uint64("current height", d.bc.CurrentBlock().NumberU64()).
Bool("initSync", initSync).
Uint32("shard", d.bc.ShardID()).
Msg(WrapStagedSyncMsg("sync finished"))
if initSync {
d.logger.Info().Int("block added", addedBN).
Uint64("current height", d.bc.CurrentBlock().NumberU64()).
Bool("initSync", initSync).
Uint32("shard", d.bc.ShardID()).
Msg(WrapStagedSyncMsg("sync finished"))
}
if addedBN != 0 {
// If block number has been changed, trigger another sync
@ -242,7 +244,6 @@ func (d *Downloader) loop() {
d.bh.insertSync()
}
}
d.stagedSyncInstance.initSync = false
initSync = false
case <-d.closeC:

@ -73,8 +73,6 @@ func (heads *StageHeads) Exec(firstCycle bool, invalidBlockRevert bool, s *Stage
}
if currentHeight >= maxHeight {
utils.Logger().Info().Uint64("current number", currentHeight).Uint64("target number", maxHeight).
Msg(WrapStagedSyncMsg("early return of long range sync"))
return nil
}

@ -118,11 +118,6 @@ func NewHost(cfg HostConfig) (Host, error) {
self = cfg.Self
key = cfg.BLSKey
)
// listenAddr, err := ma.NewMultiaddr(fmt.Sprintf("/ip4/%s/tcp/%s", self.IP, self.Port))
// if err != nil {
// return nil, errors.Wrapf(err,
// "cannot create listen multiaddr from port %#v", self.Port)
// }
addr := fmt.Sprintf("/ip4/%s/tcp/%s", self.IP, self.Port)
listenAddr := libp2p.ListenAddrStrings(
@ -131,9 +126,10 @@ func NewHost(cfg HostConfig) (Host, error) {
)
ctx, cancel := context.WithCancel(context.Background())
// TODO: move low and high to configs
connmgr, err := connmgr.NewConnManager(
int(cfg.MaxPeers), // Lowwater
int(cfg.MaxPeers)*cfg.MaxConnPerIP, // HighWater,
int(10), // Lowwater
int(10000)*cfg.MaxConnPerIP, // HighWater,
connmgr.WithGracePeriod(time.Minute),
)
if err != nil {
@ -141,7 +137,6 @@ func NewHost(cfg HostConfig) (Host, error) {
return nil, err
}
var idht *dht.IpfsDHT
p2pHost, err := libp2p.New(
listenAddr,
libp2p.Identity(key),
@ -167,7 +162,10 @@ func NewHost(cfg HostConfig) (Host, error) {
// performance issues.
libp2p.EnableNATService(),
libp2p.BandwidthReporter(newCounter()),
libp2p.ForceReachabilityPublic(),
// ForceReachabilityPublic overrides automatic reachability detection in the AutoNAT subsystem,
// forcing the local node to believe it is reachable externally.
// libp2p.ForceReachabilityPublic(),
// prevent dialing of public addresses
libp2p.ConnectionGater(NewGater(cfg.DisablePrivateIPScan)),
)

@ -171,7 +171,7 @@ func (p *Protocol) HandleStream(raw libp2p_network.Stream) {
Msg("failed to add new stream")
return
}
fmt.Println("Node connected to", raw.Conn().RemotePeer().String(), "(", st.ProtoID(), ")")
fmt.Println("Connected to", raw.Conn().RemotePeer().String(), "(", st.ProtoID(), ")")
st.run()
}

Loading…
Cancel
Save