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

feat: Add accumulattive PoW functionality to btclightclient #51

Merged
merged 2 commits into from
Jul 7, 2022

Conversation

vitsalis
Copy link
Member

@vitsalis vitsalis commented Jul 6, 2022

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 of big.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.

@vitsalis vitsalis requested a review from aakoshh July 6, 2022 10:26
@aakoshh aakoshh changed the base branch from main to btclightclient-cleanup July 6, 2022 11:36
)

func CalcWork(header *wire.BlockHeader) *big.Int {
return blockchain.CalcWork(header.Bits)
Copy link
Contributor

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.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yep, CalcWork is used by btcd to calculate work. More specifically:

When a block is received, the workSum for that particular block is calculated as CalcWork(header) + parent.workSum ref.

The CalcWork function, does an operation that generates a number that is inverse-related with the Bits ref

Copy link
Contributor

@aakoshh aakoshh left a comment

Choose a reason for hiding this comment

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

Looks good!

Base automatically changed from btclightclient-cleanup to main July 6, 2022 14:25
@vitsalis vitsalis merged commit 209dcdc into main Jul 7, 2022
@vitsalis vitsalis deleted the btclightclient-cumpow branch July 7, 2022 06:42
KonradStaniec added a commit that referenced this pull request Oct 25, 2023
* Add query for validator
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.

2 participants