Skip to content

Commit

Permalink
remove log
Browse files Browse the repository at this point in the history
  • Loading branch information
blindchaser committed Oct 28, 2024
1 parent 7371943 commit 10b32a5
Show file tree
Hide file tree
Showing 6 changed files with 5 additions and 48 deletions.
8 changes: 0 additions & 8 deletions internal/blocksync/pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -358,12 +358,6 @@ func (pool *BlockPool) SetPeerRange(peerID types.NodeID, base int64, height int6
pool.mtx.Lock()
defer pool.mtx.Unlock()

// blockSyncPeers := pool.peerManager.GetBlockSyncPeers()
// if len(blockSyncPeers) > 0 && !blockSyncPeers[peerID] {
// pool.logger.Info(fmt.Sprintf("Skip adding peer %s for blocksync, num of blocksync peers: %d, num of pool peers: %d", peerID, len(blockSyncPeers), len(pool.peers)))
// return
// }

peer := pool.peers[peerID]
if peer != nil {
peer.base = base
Expand Down Expand Up @@ -461,7 +455,6 @@ func (pool *BlockPool) pickIncrAvailablePeer(height int64) *bpPeer {
peer := pool.peers[nodeId]
if peer.didTimeout {
pool.removePeer(peer.id, true)
fmt.Printf("[YIREN-DEBUG] Remove peer %s because it timed out\n", peer.id)
continue
}
if peer.numPending >= maxPendingRequestsPerPeer {
Expand All @@ -473,7 +466,6 @@ func (pool *BlockPool) pickIncrAvailablePeer(height int64) *bpPeer {
// We only want to work with peers that are ready & connected (not dialing)
if pool.peerManager.State(nodeId) == "ready,connected" {
goodPeers = append(goodPeers, nodeId)
fmt.Printf("[YIREN-DEBUG] Append Peer %s is ready and connected\n", nodeId)
}

// Skip the ones with zero score to avoid connecting to bad peers
Expand Down
3 changes: 0 additions & 3 deletions internal/blocksync/reactor.go
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,6 @@ func (r *Reactor) handleMessage(ctx context.Context, envelope *p2p.Envelope, blo
return r.respondToPeer(ctx, msg, envelope.From, blockSyncCh)
case *bcproto.BlockResponse:
block, err := types.BlockFromProto(msg.Block)
fmt.Printf("[YIREN-DEBUG] Received block response from peer %s, block height: %d\n", envelope.From, block.Height)
if err != nil {
r.logger.Error("failed to convert block from proto",
"peer", envelope.From,
Expand Down Expand Up @@ -397,7 +396,6 @@ func (r *Reactor) processPeerUpdate(ctx context.Context, peerUpdate p2p.PeerUpda
},
}); err != nil {
r.pool.RemovePeer(peerUpdate.NodeID)
fmt.Printf("[YIREN-DEBUG] StatusUp Removed peer: %s\n", peerUpdate.NodeID)
if err := blockSyncCh.SendError(ctx, p2p.PeerError{
NodeID: peerUpdate.NodeID,
Err: err,
Expand All @@ -408,7 +406,6 @@ func (r *Reactor) processPeerUpdate(ctx context.Context, peerUpdate p2p.PeerUpda

case p2p.PeerStatusDown:
r.pool.RemovePeer(peerUpdate.NodeID)
fmt.Printf("[YIREN-DEBUG] StatusDown Removed peer: %s\n", peerUpdate.NodeID)
}
}

Expand Down
34 changes: 5 additions & 29 deletions internal/p2p/peermanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,6 @@ func (m *PeerManager) prunePeers() error {
// exists, the address is added to it if it isn't already present. This will push
// low scoring peers out of the address book if it exceeds the maximum size.
func (m *PeerManager) Add(address NodeAddress) (bool, error) {
fmt.Printf("[ADD-DEBUG] Add: Adding peer %s with address %s\n", address.NodeID, address.String())
if err := address.Validate(); err != nil {
return false, err
}
Expand Down Expand Up @@ -543,7 +542,6 @@ func (m *PeerManager) TryDialNext() (NodeAddress, error) {

for _, peer := range m.store.Ranked() {
if m.dialing[peer.ID] || m.connected[peer.ID] {
fmt.Printf("[YIREN-DEBUG] TryDialNext: Peer %s is in dialing or connected\n", peer.ID)
continue
}

Expand All @@ -565,7 +563,6 @@ func (m *PeerManager) TryDialNext() (NodeAddress, error) {
return NodeAddress{}, nil
}
m.upgrading[upgradeFromPeer] = peer.ID
fmt.Printf("[YIREN-DEBUG] Upgrade candidate found: %s, upgrading from: %s\n", upgradeFromPeer, peer.ID)
}

m.dialing[peer.ID] = true
Expand Down Expand Up @@ -600,7 +597,6 @@ func (m *PeerManager) DialFailed(ctx context.Context, address NodeAddress) error
addressInfo.LastDialFailure = time.Now().UTC()
addressInfo.DialFailures++
peer.ConsecSuccessfulBlocks = 0
// fmt.Printf("[SCORE-DEBUG] DialFailed: %s, ConsecSuccessfulBlocks: %d\n", peer.ID, peer.ConsecSuccessfulBlocks)
// We need to invalidate the cache after score changed
m.store.ranked = nil
if err := m.store.Set(peer); err != nil {
Expand Down Expand Up @@ -851,14 +847,12 @@ func (m *PeerManager) Disconnected(ctx context.Context, peerID types.NodeID) {
// check for potential overflow
if m.store.peers[peerID].NumOfDisconnections < math.MaxInt64 {
m.store.peers[peerID].NumOfDisconnections++
// fmt.Printf("[SCORE-DEBUG] Disconnected, PeerId: %s, NumOfDisconnections: %d\n", peerID, m.store.peers[peerID].NumOfDisconnections)
} else {
fmt.Printf("Warning: NumOfDisconnections for peer %s has reached its maximum value\n", peerID)
m.store.peers[peerID].NumOfDisconnections = 0
}

m.store.peers[peerID].ConsecSuccessfulBlocks = 0
// fmt.Printf("[SCORE-DEBUG] Disconnected, PeerId: %s ConsecSuccessfulBlocks: %d\n", peerID, m.store.peers[peerID].ConsecSuccessfulBlocks)
m.store.ranked = nil
}

Expand Down Expand Up @@ -1008,14 +1002,6 @@ func (m *PeerManager) processPeerEvent(ctx context.Context, pu PeerUpdate) {
if _, ok := m.store.peers[pu.NodeID]; !ok {
m.store.peers[pu.NodeID] = &peerInfo{}
}
switch pu.Status {
case PeerStatusBad:
//m.store.peers[pu.NodeID].MutableScore--
fmt.Printf("[YIREN-DEBUG] ProcessPeerEvent PeerStatusBad, PeerId: %s, Score: %d\n", pu.NodeID, m.store.peers[pu.NodeID].MutableScore)
case PeerStatusGood:
m.store.peers[pu.NodeID].MutableScore++
fmt.Printf("[YIREN-DEBUG] ProcessPeerEvent PeerStatusGood, PeerId: %s, Score: %d\n", pu.NodeID, m.store.peers[pu.NodeID].MutableScore)
}
// Invalidate the cache after score changed
m.store.ranked = nil
}
Expand Down Expand Up @@ -1424,6 +1410,7 @@ func (p *peerInfo) Copy() peerInfo {
// Score calculates a score for the peer. Higher-scored peers will be
// preferred over lower scores.
func (p *peerInfo) Score() PeerScore {
// Use predetermined scores if set
if p.FixedScore > 0 {
return p.FixedScore
}
Expand All @@ -1436,33 +1423,22 @@ func (p *peerInfo) Score() PeerScore {
score = int64(PeerScorePersistent)
}

// add points for consecutive successful block syncs
if p.ConsecSuccessfulBlocks > 0 {
fmt.Printf("[SCORE-DEBUG] Add Points PeerId: %s, ConsecSuccessfulBlocks: %d\n", p.ID, p.ConsecSuccessfulBlocks)
}
// Add points for block sync performance
score += p.ConsecSuccessfulBlocks / 5

// Penalize for dial failures with time decay
for _, addr := range p.AddressInfo {
// DialFailures is reset when dials succeed, so this
// is either the number of dial failures or 0.
failureScore := float64(addr.DialFailures) * math.Exp(-0.1*float64(time.Since(addr.LastDialFailure).Hours()))
// if int64(failureScore) > 0 {
// fmt.Printf("[SCORE-DEBUG] PeerId: %s, failureScore: %d\n", p.ID, int64(failureScore))
// }
score -= int64(failureScore)
}

// Calculate a time-based decay factor for NumOfDisconnections
// Penalize for disconnections with time decay
timeSinceLastDisconnect := time.Since(p.LastConnected)
decayFactor := math.Exp(-0.1 * timeSinceLastDisconnect.Hours())
effectiveDisconnections := int64(float64(p.NumOfDisconnections) * decayFactor)
// We consider lowering the score for every 3 disconnection events
// if effectiveDisconnections/3 > 0 {
// fmt.Printf("[SCORE-DEBUG] PeerId: %s, NumOfDisconnections: %d\n", p.ID, effectiveDisconnections/3)
// }
score -= effectiveDisconnections / 3

// the cap of score is MaxPeerScoreNotPersistent
// Cap score for non-persistent peers
if !p.Persistent && score > int64(MaxPeerScoreNotPersistent) {
score = int64(MaxPeerScoreNotPersistent)
}
Expand Down
1 change: 0 additions & 1 deletion internal/p2p/pex/reactor.go
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,6 @@ func (r *Reactor) handlePexMessage(ctx context.Context, envelope *p2p.Envelope,
r.logger.Error(fmt.Sprintf("PEX parse node address error %s", err))
continue
}
fmt.Printf("[YIREN-DEBUG] Received PEX response from peer %s, address: %s\n", envelope.From, peerAddress)
added, err := r.peerManager.Add(peerAddress)
if err != nil {
logger.Error("failed to add PEX address", "address", peerAddress, "err", err)
Expand Down
2 changes: 0 additions & 2 deletions internal/p2p/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -656,7 +656,6 @@ func (r *Router) connectPeer(ctx context.Context, address NodeAddress) {
return
case err != nil:
r.logger.Error("failed to handshake with peer", "peer", address, "err", err)
fmt.Printf("[YIREN-DEBUG] Handshake failed with peer %s, close connection\n", address.NodeID)
if err = r.peerManager.DialFailed(ctx, address); err != nil {
r.logger.Error("failed to report dial failure", "peer", address, "err", err)
}
Expand All @@ -673,7 +672,6 @@ func (r *Router) connectPeer(ctx context.Context, address NodeAddress) {

r.logger.Debug("failed to dial peer",
"op", "outgoing/dialing", "peer", address.NodeID, "err", err)
fmt.Printf("[YIREN-DEBUG] Dial failed peer, error: %s\n", err)
conn.Close()
return
}
Expand Down
5 changes: 0 additions & 5 deletions internal/state/execution.go
Original file line number Diff line number Diff line change
Expand Up @@ -332,18 +332,13 @@ func (blockExec *BlockExecutor) ApplyBlock(
defer commitSpan.End()
}
// Lock mempool, commit app state, update mempoool.
commitStart := time.Now()
retainHeight, err := blockExec.Commit(ctx, state, block, fBlockRes.TxResults)
if err != nil {
return state, fmt.Errorf("commit failed for application: %w", err)
}
if commitSpan != nil {
commitSpan.End()
}
// if commit took more than 1000ms, log it
if time.Since(commitStart) > 1000*time.Millisecond {
fmt.Printf("[TM-DEBUG] Commit in blockExec took %s for height %d\n", time.Since(commitStart), block.Height)
}

// Update evpool with the latest state.
blockExec.evpool.Update(ctx, state, block.Evidence)
Expand Down

0 comments on commit 10b32a5

Please sign in to comment.