-
Notifications
You must be signed in to change notification settings - Fork 313
primitives: Add subsidy calcs. #2920
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
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 tasks
dnldd
reviewed
Apr 10, 2022
dnldd
reviewed
Apr 10, 2022
c38a6f7 to
3182c0d
Compare
dnldd
approved these changes
Apr 11, 2022
rstaudt2
approved these changes
Apr 12, 2022
Member
rstaudt2
left a comment
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. Test coverage looks great as well:
go test -run="TestSubsidyCacheCalcs|TestTotalSubsidy|TestTotalSubsidyDCP0010|TestCalcBlockSubsidySparseCaching" -coverprofile=cov.out &&
go tool cover -func=cov.out
github.com/decred/dcrd/internal/staging/primitives/subsidy.go:155: NewSubsidyCache 100.0%
github.com/decred/dcrd/internal/staging/primitives/subsidy.go:174: Len 100.0%
github.com/decred/dcrd/internal/staging/primitives/subsidy.go:175: Less 100.0%
github.com/decred/dcrd/internal/staging/primitives/subsidy.go:176: Swap 100.0%
github.com/decred/dcrd/internal/staging/primitives/subsidy.go:191: CalcBlockSubsidy 100.0%
github.com/decred/dcrd/internal/staging/primitives/subsidy.go:289: calcWorkSubsidy 100.0%
github.com/decred/dcrd/internal/staging/primitives/subsidy.go:332: CalcWorkSubsidy 100.0%
github.com/decred/dcrd/internal/staging/primitives/subsidy.go:365: calcStakeVoteSubsidy 100.0%
github.com/decred/dcrd/internal/staging/primitives/subsidy.go:400: CalcStakeVoteSubsidy 100.0%
github.com/decred/dcrd/internal/staging/primitives/subsidy.go:427: CalcTreasurySubsidy 100.0%
54433fa to
41230c6
Compare
dajohi
approved these changes
Apr 19, 2022
This implements a subsidy cache with funcs to calculate subsidies for
proof-of-work, votes, and the treasury and includes a full suite of
tests.
It consists of ports of the related code in blockchain/standalone with
the following modifications:
- Removes the subsidy split parameters from SubsidyParams since the
chaincfg implementations are deprecated
- Uses hard-coded constants for the PoW, PoS, and treasury splits both
prior to and after the activation of DCP0010
- Removes the version 1 methods and renames the version 2 variants to
take their place:
- CalcWorkSubsidyV2 -> CalcWorkSubsidy
- CalcStakeVoteSubsidyV2 -> CalcStakeVoteSubsidy
- Consolidates the tests specific to the decentralized treasury agenda
into their counterparts
- Includes additional maintainer notes with the expected way to update
the code without needing a major module bump should it ever be
necessary
CalcSubsidyCacheSparse 26023311 45.99 ns/op 0 B/op 0 allocs/op CalcWorkSubsidy 21051818 52.12 ns/op 0 B/op 0 allocs/op CalcStakeVoteSubsidy 22216708 53.44 ns/op 0 B/op 0 allocs/op CalcTreasurySubsidy 22610749 49.78 ns/op 0 B/op 0 allocs/op
41230c6 to
7124399
Compare
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This implements a subsidy cache with funcs to calculate subsidies for proof-of-work, votes, and the treasury and includes a full suite of tests and benchmarks.
It consists of ports of the related code in
blockchain/standalonewith the following modifications:SubsidyParamssince thechaincfgimplementations are deprecatedCalcWorkSubsidyV2->CalcWorkSubsidyCalcStakeVoteSubsidyV2->CalcStakeVoteSubsidyThe following benchmarks show the performance of the most relevant methods:
This is work towards #2786.