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

blockchain/standalone: Implement a new module. #1808

Merged

Conversation

davecgh
Copy link
Member

@davecgh davecgh commented Aug 1, 2019

This implements a new module named blockchain/standalone which aims to provide several of the standalone functions currently available in blockchain and ultimately replace them in the next major version.

The primary goal of offering these functions via a separate module is to reduce the required dependencies to a minimum as compared to the blockchain module. It will be ideal for applications such as lightweight clients that need to ensure basic security properties hold and calculate appropriate vote subsidies and block explorers.

For example, some things an SPV wallet needs to prove are that the block headers all connect together, that they satisfy the proof of work requirements, and that a given transaction tree is valid for a given header.

The new module currently only provides functions related to proof of work, however, future commits will provide functions for merkle root calculation, subsidy calculation, and coinbase transaction identification. It is being done in stages to help ease review since it is consensus critical code.

It will not be released until the remaining functions have been implemented.

Finally, it also includes comprehensive tests, full package documentation, and basic usage examples.

@davecgh davecgh added this to the 1.5.0 milestone Aug 1, 2019
@davecgh
Copy link
Member Author

davecgh commented Aug 1, 2019

$ go test -coverprofile=cov.out && go tool cover -func cov.out
PASS
coverage: 100.0% of statements
ok      github.com/decred/dcrd/blockchain/standalone    0.408s
github.com/decred/dcrd/blockchain/standalone/error.go:36:       String                  100.0%
github.com/decred/dcrd/blockchain/standalone/error.go:52:       Error                   100.0%
github.com/decred/dcrd/blockchain/standalone/error.go:57:       ruleError               100.0%
github.com/decred/dcrd/blockchain/standalone/error.go:63:       IsErrorCode             100.0%
github.com/decred/dcrd/blockchain/standalone/pow.go:27:         HashToBig               100.0%
github.com/decred/dcrd/blockchain/standalone/pow.go:62:         CompactToBig            100.0%
github.com/decred/dcrd/blockchain/standalone/pow.go:94:         BigToCompact            100.0%
github.com/decred/dcrd/blockchain/standalone/pow.go:142:        CalcWork                100.0%
github.com/decred/dcrd/blockchain/standalone/pow.go:158:        checkProofOfWorkRange   100.0%
github.com/decred/dcrd/blockchain/standalone/pow.go:177:        CheckProofOfWorkRange   100.0%
github.com/decred/dcrd/blockchain/standalone/pow.go:185:        CheckProofOfWork        100.0%
total:                                                          (statements)            100.0%

@jrick
Copy link
Member

jrick commented Aug 1, 2019

Is the plan to migrate some of the standalone funcs from the stake package in the future?

@davecgh
Copy link
Member Author

davecgh commented Aug 1, 2019

I wasn't planning on doing that before the initial release, but yeah, I would like to do that eventually.

Copy link
Member

@matheusd matheusd left a comment

Choose a reason for hiding this comment

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

Verified there were no changes on the PoW code when compared to the current implementation in the blockchain package.

This implements a new module named blockchain/standalone which aims to
provide several of the standalone functions currently available in
blockchain and ultimately replace them in the next major version.

The primary goal of offering these functions via a separate module is to
reduce the required dependencies to a minimum as compared to the
blockchain module.  It will be ideal for applications such as
lightweight clients that need to ensure basic security properties hold
and calculate appropriate vote subsidies and block explorers.

For example, some things an SPV wallet needs to prove are that the block
headers all connect together, that they satisfy the proof of work
requirements, and that a given transaction tree is valid for a given
header.

The new module currently only provides functions related to proof of
work, however, future commits will provide functions for merkle root
calculation, subsidy calculation, and coinbase transaction
identification.  It is being done in stages to help ease review since it
is consensus critical code.

Finally, it also includes comprehensive tests, full package
documentation, and basic usage examples.
@davecgh davecgh force-pushed the introduce_blockchain_standalone_module branch from b32dd61 to 2c7d204 Compare August 6, 2019 15:29
@davecgh davecgh merged commit 2c7d204 into decred:master Aug 6, 2019
@davecgh davecgh deleted the introduce_blockchain_standalone_module branch August 6, 2019 15:55
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.

None yet

5 participants