decred / dcrd

Decred daemon in Go (golang).
https://decred.org
ISC License
731 stars 288 forks source link

Error exiting dcrwallet/dcrd daemon #3355

Closed vuonda closed 3 months ago

vuonda commented 3 months ago

dcrd exited, error appeared:

panic: runtime error: invalid memory address or nil pointer dereference [signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x8f9695] goroutine 50229228 [running]: github.com/decred/dcrd/wire.(MsgMixSecrets).Commitment(...) /home/x/go/pkg/mod/github.com/decred/dcrd/wire@v1.7.0/msgmixsecrets.go:204 github.com/decred/dcrd/mixing/mixclient.(Client).blame(0xc0002483c0, {0x103b320, 0xc0008c42a0}, 0xc002a04868) /home/x/go/pkg/mod/github.com/decred/dcrd/mixing@v0.1.0/mixclient/blame.go:168 +0xc15 github.com/decred/dcrd/mixing/mixclient.(Client).pairSession(0xc0002483c0, {0x103b2b0, 0xc0005245a0}, 0xc000b5a280, {0xc000aee508, 0x15, 0x99}, {0x0, 0xeddea7d60, 0x0}) /home/x/go/pkg/mod/github.com/decred/dcrd/mixing@v0.1.0/mixclient/client.go:901 +0x1045 created by github.com/decred/dcrd/mixing/mixclient.(Client).epochTicker in goroutine 38 /home/x/go/pkg/mod/github.com/decred/dcrd/mixing@v0.1.0/mixclient/client.go:604 +0x459

The error appears in dcrd's mixclient/blame.go file (line 168), when the variable rs (wire.MsgMixSecrets) has null value. Somehow the rs value is not set in peer

167.c.blake256HasherMu.Lock()

  1. cm := p.rs.Commitment(c.blake256Hasher)
  2. c.blake256HasherMu.Unlock()

The error can be reproduced and debugged at mixclient/client.go (from lines 851 to 865). If pr.Identity key does not exist in localPeers map, a new peer is created using the newRemotePeer() function. In this function, the value rs (wire.MsgMixSecrets) is not initialized and that is the cause of the error The first solution that comes to mind is to create a new MsgMixSecrets and set it to the peer's rs

for i, pr := range prs { p := ps.localPeers[pr.Identity] if p != nil { localPeerCount++ } else { p = newRemotePeer(pr) } p.myVk = uint32(i) p.myStart = m currentRun.peers = append(currentRun.peers, p) currentRun.mcounts = append(currentRun.mcounts, p.pr.MessageCount) m += p.pr.MessageCount }

jrick commented 3 months ago

Upgrade to 2.0.2.

davecgh commented 3 months ago

As mentioned, this is resolved in release version 2.0.2 of the software, but I would like to clarify that while your issue says "dcrd exited", it must have been dcrwallet that exited. The mixclient code is not used in dcrd itself since that is, as the name implies, client side code.

vuonda commented 3 months ago

@jrick @davecgh Thank you very much!