-
Notifications
You must be signed in to change notification settings - Fork 128
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
Avg vote time calculations #471
Comments
For reference, that should be 7860, not 8102. There was a typo in the formula. Since the probability of voting by a given block formula is: The EV is: This is confirmed by calculating the statistics from the chain across all tickets since the beginning with dcrvotetimes:
|
@davecgh any recommendations on how to code this into GO so we can derive from params rather than hard code 7860? I tried a for loop sum, but end up with overflows rather quickly. Looked briefly for internet references to go and summations - NL. |
There are a lot of techniques you can use to the estimate the result, but rather than going heavy into the math, I would suggest just using wolfram to calculate the values for the two networks, since they aren't going to change very often, if ever, and then add an func assertProbabilityParams(params *chaincfg.Params, ticketPoolSize, ticketsPerBlock uint16, ticketExpiry uint32) {
if params.TicketPoolSize != ticketPoolSize {
panic(fmt.Sprintf("ticket pool size for %s is %d instead of expected %d",
params.Name, params.TicketPoolSize, ticketPoolSize)
}
// Same for the others
}
func init() {
assertProbabilityParams(&chaincfg.MainNetParams, 8192, 5, 40960)
assertProbabilityParams(&chaincfg.TestNet2Params, 1024, 5, 6144)
} |
It's not too bad if you apply a log to the equation:
7860.917491203549 |
Prints 7860.917491184401 |
I still suspect that asserting things haven't changed and just using constants for the values along with comments how they were derived is probably a good idea since there are certainly a lot of other assumptions made accordingly, but it can certainly be estimated via logs as @chappjc pointed out. If you want to go that route, you can simplify it further by knowing that the target pool size is always the number of tickets per block times the defined ticket pool size. The result is that the CDF will reduce to package main
import (
"fmt"
"math"
"github.com/decred/dcrd/chaincfg"
)
func calcMeanVotingBlocks(params *chaincfg.Params) int64 {
poolSize := float64(params.TicketPoolSize)
var v float64
for i := float64(1); i <= float64(params.TicketExpiry); i++ {
v += math.Exp(math.Log(i) + (i-1)*math.Log(poolSize-1) - i*math.Log(poolSize))
}
return int64(v)
}
func main() {
fmt.Println("mainnet", calcMeanVotingBlocks(&chaincfg.MainNetParams))
fmt.Println("testnet2", calcMeanVotingBlocks(&chaincfg.TestNet2Params))
} Output:
EDIT: You can, of course, make that more efficient by computing the constant |
Thank you. This is exactly what I needed. I spoke with @raedah and we are going to put in a variation of the calculated version you both came up with. |
resolved by PR #468, specifically |
Avg vote time calculation being used is currently based on ticket pool param. On mainnet 8192 blocks is what is used and arrives at 28.44 days, but average vote time probability calculations comes to 8102 blocks which is 28.13 days. Needs to be resolved on home page ROI calculation as well as the APR pull request. #468
This can also be worked into an improved version of the luck calculation, probably as a separate PR.
The text was updated successfully, but these errors were encountered: