Skip to content

Commit

Permalink
Revert "might revert, peer refresh logic"
Browse files Browse the repository at this point in the history
This reverts commit afab0c2.
  • Loading branch information
czarcas7ic committed Jun 22, 2024
1 parent 568ffaa commit 79021c2
Showing 1 changed file with 9 additions and 69 deletions.
78 changes: 9 additions & 69 deletions blocksync/pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -437,45 +437,6 @@ func (pool *BlockPool) sortPeers() {
})
}

// TODO: Might revert start
func (pool *BlockPool) refreshPeers() {
pool.mtx.Lock()
defer pool.mtx.Unlock()

// Logic to refresh peers, e.g., disconnect and reconnect
for peerID, peer := range pool.peers {
if peer.didTimeout {
pool.removePeer(peerID)
}
}

// // Optionally, add logic to reconnect to new peers
// // This is a placeholder and should be replaced with actual peer connection logic
// pool.connectToNewPeers()
}

func (pool *BlockPool) releaseAllRequests() {
pool.mtx.Lock()
defer pool.mtx.Unlock()

// Logic to release all requests
for height, requester := range pool.requesters {
requester.Stop()
delete(pool.requesters, height)
}
}

func (pool *BlockPool) requestNextBlock() {
pool.mtx.Lock()
defer pool.mtx.Unlock()

// Logic to request the next block needed
nextHeight := pool.height
pool.makeNextRequester(nextHeight)
}

// TODO: Might revert end

func (pool *BlockPool) makeNextRequester(nextHeight int64) {
pool.mtx.Lock()
request := newBPRequester(pool, nextHeight)
Expand Down Expand Up @@ -737,39 +698,18 @@ func (bpr *bpRequester) pickPeerAndSendRequest() {
bpr.mtx.Unlock()

var peer *bpPeer
timeout := time.After(30 * time.Second) // Set a timeout for 30 seconds

PICK_PEER_LOOP:
for {
select {
case <-timeout:
bpr.Logger.Debug("Timeout reached, refreshing peers", "height", bpr.height)
bpr.pool.refreshPeers() // Add a method to refresh peers
bpr.pool.releaseAllRequests() // Add a method to release all requests
bpr.pool.requestNextBlock() // Add a method to request the next block needed
timeout = time.After(30 * time.Second) // Reset the timeout
default:
if !bpr.IsRunning() || !bpr.pool.IsRunning() {
return
}
peer = bpr.pool.pickIncrAvailablePeer(bpr.height, secondPeerID)
if peer == nil {
bpr.Logger.Debug("No peers currently available; will retry shortly", "height", bpr.height)
time.Sleep(requestInterval)
continue PICK_PEER_LOOP
}
break PICK_PEER_LOOP
if !bpr.IsRunning() || !bpr.pool.IsRunning() {
return
}
peer = bpr.pool.pickIncrAvailablePeer(bpr.height, secondPeerID)
if peer == nil {
bpr.Logger.Debug("No peers currently available; will retry shortly", "height", bpr.height)
time.Sleep(requestInterval)
continue PICK_PEER_LOOP
}
// if !bpr.IsRunning() || !bpr.pool.IsRunning() {
// return
// }
// peer = bpr.pool.pickIncrAvailablePeer(bpr.height, secondPeerID)
// if peer == nil {
// bpr.Logger.Debug("No peers currently available; will retry shortly", "height", bpr.height)
// time.Sleep(requestInterval)
// continue PICK_PEER_LOOP
// }
// break PICK_PEER_LOOP
break PICK_PEER_LOOP
}
bpr.mtx.Lock()
bpr.peerID = peer.id
Expand Down

0 comments on commit 79021c2

Please sign in to comment.