Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Small bug fixes #2367

Merged
merged 3 commits into from
Nov 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions cmd/utils/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -1531,6 +1531,8 @@ func MakeGenesis() *core.Genesis {
genesis = core.DefaultLocalGenesisBlock(consensusEngine, genesisNonce)
case params.DevName:
Fatalf("Developer chains are ephemeral")
default:
genesis = core.DefaultGenesisBlock(genesisNonce)
Djadih marked this conversation as resolved.
Show resolved Hide resolved
}
return genesis
}
Expand Down
36 changes: 16 additions & 20 deletions p2p/node/peerManager/peerManager.go
Original file line number Diff line number Diff line change
Expand Up @@ -511,15 +511,24 @@ func (pm *BasicPeerManager) queryDHT(topic *pubsubManager.Topic, peerList map[p2
}

func (pm *BasicPeerManager) getBestPeers(topic string) map[p2p.PeerID]struct{} {
return pm.getPeersHelper(pm.peerDBs[topic][Best], c_minBestPeersFromDb)
if db, ok := pm.peerDBs[topic]; ok {
return pm.getPeersHelper(db[Best], c_minBestPeersFromDb)
}
return make(map[peer.ID]struct{})
}

func (pm *BasicPeerManager) getResponsivePeers(topic string) map[p2p.PeerID]struct{} {
return pm.getPeersHelper(pm.peerDBs[topic][Responsive], c_minResponsivePeersFromDb)
if db, ok := pm.peerDBs[topic]; ok {
return pm.getPeersHelper(db[Responsive], c_minBestPeersFromDb)
}
return make(map[peer.ID]struct{})
}

func (pm *BasicPeerManager) getLastResortPeers(topic string) map[p2p.PeerID]struct{} {
return pm.getPeersHelper(pm.peerDBs[topic][LastResort], c_minLastResortPeersFromDb)
if db, ok := pm.peerDBs[topic]; ok {
return pm.getPeersHelper(db[LastResort], c_minBestPeersFromDb)
}
return make(map[peer.ID]struct{})
}

func (pm *BasicPeerManager) AdjustPeerQuality(peer p2p.PeerID, topic string, adjFn func(int) int) {
Expand All @@ -530,25 +539,12 @@ func (pm *BasicPeerManager) AdjustPeerQuality(peer p2p.PeerID, topic string, adj
pm.recategorizePeer(peer, topic)
}

func (pm *BasicPeerManager) calculatePeerLiveness(peer p2p.PeerID) float64 {
peerTag := pm.GetTagInfo(peer)
if peerTag == nil {
return 0
}

liveness := peerTag.Tags["liveness_reports"]
latents := peerTag.Tags["latency_reports"]
return float64(liveness) / float64(latents)
}

func (pm *BasicPeerManager) calculatePeerResponsiveness(peer p2p.PeerID) float64 {
peerTag := pm.GetTagInfo(peer)
if peerTag == nil {
func (pm *BasicPeerManager) GetPeerQuality(peer p2p.PeerID) int {
if info := pm.GetTagInfo(peer); info != nil {
return info.Tags["quality"]
} else {
return 0
}
responses := peerTag.Tags["responses_served"]
misses := peerTag.Tags["responses_missed"]
return float64(responses) / float64(misses)
}

// Peers will be divided into three buckets (good, bad, ugly) based on their quality score
Expand Down
Loading