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

Block: add methods to calculate difficulty of a consecutive header/block #929

Merged
merged 5 commits into from
Nov 6, 2020
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
block: calcDifficultyFromHeader option comment description improvements
holgerd77 committed Nov 6, 2020
commit 8cb1b1f383982f3224af54116a034c3f7e032d0e
6 changes: 3 additions & 3 deletions packages/block/src/header.ts
Original file line number Diff line number Diff line change
@@ -223,9 +223,9 @@ export class BlockHeader {
this._validateBufferLengths()
this._checkDAOExtraData()

// Now we have set all the values of this Header, we possibly have set a dummy `difficulty` value (defaults to 0)
// If we have a `calcDifficultyFromHeader` block option parameter, we instead set difficulty to this value.

// Now we have set all the values of this Header, we possibly have set a dummy
// `difficulty` value (defaults to 0). If we have a `calcDifficultyFromHeader`
// block option parameter, we instead set difficulty to this value.
if (options.calcDifficultyFromHeader) {
this.difficulty = this.canonicalDifficulty(options.calcDifficultyFromHeader)
}
4 changes: 3 additions & 1 deletion packages/block/src/types.ts
Original file line number Diff line number Diff line change
@@ -38,7 +38,9 @@ export interface BlockOptions {
initWithGenesisHeader?: boolean

/**
* If a `BlockHeader` is given, then this header is used to calculate the difficulty upon creating the Block Header.
* If a preceding `BlockHeader` (usually the parent header) is given the preceding
* header will be used to calculate the difficulty for this block and the calculated
* difficulty takes precedence over a provided static `difficulty` value.
*/
calcDifficultyFromHeader?: BlockHeader
Copy link
Member

Choose a reason for hiding this comment

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

If a BlockHeader is given, then this header is used to calculate the difficulty upon creating the Block Header.

This was to prone yet for misunderstanding, have updated the comment with an additional commit. The double Block Header reference was too confusing - one refering to the header provided and one to the header created.

Some general note: I think the usage of "this" in these kind of option comments often don't work, since it is always a bit misleading in the sense that it becomes not 100% clear if "this" refers to "this" option provided or to "this" instance created, I now stumbled upon this (haha 😄 ) a couple of times. Think it works better to in doubt be a bit more redundant and e.g. repeat "the header provided" instead of using "this header".

Copy link
Member Author

Choose a reason for hiding this comment

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

Ah yes I'm somewhat used to write this in these descriptions, will have to self-review those sometimes 👍

}