dcrd/internal/mining
Dave Collins bf57746c3b
standalone: Introduce CalcTSpendWindow.
This existing code for calculating treasury spend window values, namely
CalculateTSpendWindowStart and CalculateTSpendWindowEnd, has a couple of
footguns:

- The starting value calculation returns totally invalid values without
  an error when provided with a expiry that is prior to the first voting
  window
- Expiry values that are invalid for the start calc are valid for the
  end calc even though they should not be

As a result, the code for handling the error paths in the rpc server and
mining code produces error messages that don't make sense in some cases
because they blindly print the start value without checking the error.

To remove the aforementioned footguns and also address the incorrect
error messages, the following overview of changes are made:

- Replaces the CalculateTSpendWindowStart and CalculateTSpendWindowEnd
  functions with a single combined CalcTSpendWindow function that
  properly checks for expiries before the first possible voting interval
- Modifies the returned errors to match the new reality
- Shortens the prefix to Calc to match the rest of the function names in
  the package
- Updates the incorrect error handling paths to avoid reporting the
  values that are not guaranteed to be meaningful and modifies the error
  messages to be more consistent
- Adds a comprehensive set of tests for the new function

Note that in addition to addressing the aforementioned issues, this
approach has at least a couple of other benefits:

- It is more efficient to have a single function with a single bounds
  check
- Almost all callers outside of the tests need both the start and end
  value anyway, so it allows more compact code

Finally, this updates all callers in the repository accordingly.
2020-09-29 11:32:13 -05:00
..
cpuminer cpuminer: Improve already discrete mining error. 2020-09-02 13:24:51 -05:00
doc.go cpuminer: Refactor code to its own package. 2020-07-22 20:06:28 -05:00
error.go mining: Move to internal. 2020-07-20 18:07:59 -05:00
log.go mining: Move to internal. 2020-07-20 18:07:59 -05:00
mining_test.go mining: Move to internal. 2020-07-20 18:07:59 -05:00
mining.go standalone: Introduce CalcTSpendWindow. 2020-09-29 11:32:13 -05:00
policy_test.go mining: Move to internal. 2020-07-20 18:07:59 -05:00
policy.go mining: Move to internal. 2020-07-20 18:07:59 -05:00
README.md mining: Move to internal. 2020-07-20 18:07:59 -05:00

mining

Build Status ISC License Doc

Overview

This package is currently a work in progress.

License

Package mining is licensed under the copyfree ISC License.