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. |
||
|---|---|---|
| .. | ||
| cpuminer | ||
| doc.go | ||
| error.go | ||
| log.go | ||
| mining_test.go | ||
| mining.go | ||
| policy_test.go | ||
| policy.go | ||
| README.md | ||