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

Add Block proof-of-work validation function #509

Merged
merged 6 commits into from
Jan 27, 2016
Merged

Add Block proof-of-work validation function #509

merged 6 commits into from
Jan 27, 2016

Conversation

dcousens
Copy link
Contributor

@dcousens dcousens commented Dec 8, 2015

Might be a way to do this nicely without resorting to using bigi, but, for now, here it is.
Should probably get some more test fixtures from core if possible.

@dcousens dcousens self-assigned this Dec 8, 2015
@dcousens dcousens added this to the 2.2.0 milestone Dec 8, 2015
})

it('returns ' + f.valid + ' for ' + f.id, function () {
assert.strictEqual(block.verifyPow(), f.valid)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@jprichardson @weilu any thoughts on verifyPow as a name?

@dcousens
Copy link
Contributor Author

dcousens commented Dec 9, 2015

Removed the need for bigi by just using a lexicographical comparison.
This could be further optimized by avoiding the allocation of a Buffer or storing target after calculation.

@dcousens
Copy link
Contributor Author

dcousens commented Dec 9, 2015

Mostly good to go now 👍 , just need a few more fixtures to verify that calculateTarget is implemented correctly.

@dcousens dcousens force-pushed the pow branch 3 times, most recently from dc94583 to ccfba68 Compare December 9, 2015 04:12
target.fill(0)

var exponent = ((bits & 0xff000000) >> 24) - 3
var value = bits & 0x00ffffff
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Its unclear if this should be bits & 0x007fffff or 0x00ffffff.
I'm happy with this as is for now, will wait to enforce that it verifies for the mainnet blockchain before merge.

@dcousens
Copy link
Contributor Author

dcousens commented Jan 4, 2016

Matched against every possible target value in the uint32_t space in terms of bitcoin/bitcoin consensus.
So, good to go 👍

dcousens added a commit that referenced this pull request Jan 27, 2016
Add Block proof-of-work validation function
@dcousens dcousens merged commit f391351 into master Jan 27, 2016
@dcousens dcousens deleted the pow branch January 27, 2016 14:00
@dcousens
Copy link
Contributor Author

@jprichardson guessing you were OK with this API? If not, please comment within 24 hours :)

@jprichardson
Copy link
Member

@jprichardson guessing you were OK with this API? If not, please comment within 24 hours :)

Yep :) ACK.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants