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

I think the difficulty of computing a little problem! #1135

Open
baiyunping333 opened this issue Mar 3, 2018 · 0 comments
Open

I think the difficulty of computing a little problem! #1135

baiyunping333 opened this issue Mar 3, 2018 · 0 comments

Comments

@baiyunping333
Copy link

the code is here
origin code is:

func CalcWork(bits uint32) *big.Int {
	// Return a work value of zero if the passed difficulty bits represent
	// a negative number. Note this should not happen in practice with valid
	// blocks, but an invalid block could trigger it.
	difficultyNum := CompactToBig(bits)
	if difficultyNum.Sign() <= 0 {
		return big.NewInt(0)
	}

	// (1 << 256) / (difficultyNum + 1)
	denominator := new(big.Int).Add(difficultyNum, bigOne)
	return new(big.Int).Div(oneLsh256, denominator)
}

maybe should:

func CalcWorkN(bits uint32) *big.Int {
    // Return a work value of zero if the passed difficulty bits represent
    // a negative number. Note this should not happen in practice with valid
    // blocks, but an invalid block could trigger it.
    difficultyNum := CompactToBig(bits)
    if difficultyNum.Sign() <= 0 {
        return big.NewInt(0)
    }
    // CompactToBig(0x1d00ffff) / (difficultyNum + 1)
   denominator := new(big.Int).Add(difficultyNum, bigOne)
    return new(big.Int).Div(CompactToBig(0x1d00ffff), denominator)
}

Am I right?

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

No branches or pull requests

1 participant