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

mining: fix data race #1894

Merged
merged 1 commit into from
Sep 11, 2019
Merged

mining: fix data race #1894

merged 1 commit into from
Sep 11, 2019

Conversation

dajohi
Copy link
Member

@dajohi dajohi commented Sep 11, 2019

Use the read template.

Fixes #1893

@dnldd
Copy link
Member

dnldd commented Sep 11, 2019

whoops, wanted to request a change there. How about using the read template after the lock:

// curTplHasNumVotes returns whether or not the current template is valid,
// builds on the provided hash, and contains the specified number of votes.
func (g *BgBlkTmplGenerator) curTplHasNumVotes(votedOnHash *chainhash.Hash, numVotes uint16) bool {
	g.templateMtx.Lock()

	template, err := g.template, g.templateErr
	g.templateMtx.Unlock()
	if template == nil || err != nil {
		return false
	}
	if template.Block.Header.PrevBlock != *votedOnHash {
		return false
	}
	return template.Block.Header.Voters == numVotes
}

@davecgh
Copy link
Member

davecgh commented Sep 11, 2019

I agree with @dnldd here. The issue isn't that the mutex is being unlocked too early, rather that it's supposed to be using the local after the unlock.

Use the read template.
@davecgh davecgh merged commit 78fd2b3 into decred:master Sep 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

BgBlkTmplGenerator: data race
3 participants