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

fix(survey): Check for nil PeerID before deref #1120

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
6 changes: 4 additions & 2 deletions tasks/survey/minerprotocols/minerprotocols.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,9 +147,11 @@ func (t *Task) Close() error {
func fetchMinerProtocolModel(ctx context.Context, api API, addr address.Address, minerInfo lapi.MinerInfo, start time.Time, results chan *observed.MinerProtocol) {
// since miners may choose if their peerID is set in their info
var peerID string
if minerInfo.PeerId != nil {
peerID = minerInfo.PeerId.String()
Comment on lines 149 to -151
Copy link
Member

@frrist frrist Jan 30, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this would be more clear if this check were moved into getMinerAddrInfo. If the peerID is nil that method can just return and log an error. What do you think @placer14?

if minerInfo.PeerId == nil {
log.Debugw("failed with empty peer id for miner", "miner", addr)
return
}
peerID = minerInfo.PeerId.String()

// extract any multiaddresses the miner has set in their info, they may have none bail if that is the case.
minerPeerInfo, err := getMinerAddrInfo(minerInfo)
Expand Down