-
Notifications
You must be signed in to change notification settings - Fork 170
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
feat: Add accumulattive PoW functionality to btclightclient #51
Conversation
) | ||
|
||
func CalcWork(header *wire.BlockHeader) *big.Int { | ||
return blockchain.CalcWork(header.Bits) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can see here that Bits
are some compact representation of the difficulty target.
Are you certain that it's the target that needs to be added, and by no means the actual number of zeroes in the hash, right? I guess it makes sense, since discovering a very high number of leading zeroes probably happened by a random accident, rather than more work spent to look for it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good!
4da6bfb
to
9b736c8
Compare
* Add query for validator
Depends on #50
This PR introduces accumulative PoW functionality. It accomplishes this through the addition of a new
hash -> AccPoW
storage which stores the bytes ofbig.Int
objects.When a new header is added, it's accumulative PoW is calculated as the sum of its work (gathered from the
CalcWork(header.Bits)
function of btcd) and the accumulated PoW of its parent. If the accumulative PoW of the new header is bigger than the accumulative PoW of the tip of the canonical chain, then the tip is updated.