I wanted to have some tools for managing pooled mining - eg a simple way to check expected bitcoin earning with a change in difficulty like this morning
, overall hash rate based on 'number of shares found reported' by miner, automated script to access JSON data on deepbit.net and create graphs etc., so I wrote and tested some yesterday.
R is a great tool for this - it's a simple math language, flexible and easy to use. If you don't know R and don't want to learn, you can just download R (google "CRAN"), start it, and copy/paste the scripts below into the R console. I've tried to make them easy as possible to use and I've commented them up with examples.
My tools can do the following:
1. Find hash rate for pooled mining based on found blocks reported by mining software
2. Find expected number of shares/blocks for pooled mining based on hashrate
3. Determine required hashrate to produce a given no. of expected bitcoins for current Difficulty for a given time period (days), block value <- 50 coins
4. Determine required hashrate to produce a given no. of expected bitcoins at any Difficulty for a given time period (days), block value <- 50 coins
5. Determine no. of expected bitcoins for a given hashrate, at current Difficulty for a given time period (days) and for block value<-50coins
6. Determine no. of expected bitcoins for a given hashrate, at any Difficulty for a given time period (days) and for block value<-50coins
Just a thought - I don't really want people to use code they don't understand without someone vetting it first. That's a bad security habit. So if you just want to use the tools without having to follow what I've done, maybe wait until someone looks at it and vets it in a post.
The scripts to access JSON API and aggregate deepbit.net stats and for network charts are too long, ugly and uncommented to post here.
If you want RJSONIO scripts, chart porn or have any requests, PM me.
Hope you find the tools handy!
28-05-2011 Edit: fixed and updated a few things.
### R code tools for pooled miners 28-05-2011
### Update:
### Bugfix in 1 and 6 (yes, srsly)
### updated examples to current difficulty
### Contents:
### 1. Find hash rate for pooled mining based on found blocks reported by mining software
### 2. Find expected number of shares/blocks for pooled mining based on hashrate
### 3. Determine required hashrate to produce a given no. of expected bitcoins
### at current Difficulty for a given time period (days), block value <- 50 coins
### 4. Determine required hashrate to produce a given no. of expected bitcoins
### at any Difficulty for a given time period (days), block value <- 50 coins
### 5. Determine no. of expected bitcoins for a given hashrate,
### at current Difficulty for a given time period (days) and for blockvalue<-50coins
### 6. Determine no. of expected bitcoins for a given hashrate,
### at any Difficulty for a given time period (days) and for blockvalue<-50coins
#
#
### 1. R code for finding hash rate for pooled mining based on found blocks reported by mining software
#
#usage:
#
#h.rate(number of blocks/shares since start, current time in format "%d:%m:%H:%M")
#(don't forget to use "")result in
#result in Mhps
#
#eg: (at the time this was done,
#> h.rate(836,"28:05:16:18")
#[1] 332.4623
#to change date or time format to your preference
#see http://stat.ethz.ch/R-manual/R-patched/library/base/html/strptime.html for details
h.rate<-function(blocks,start.time)
{
current.time<-format(Sys.time(),"%d:%m:%H:%M")
diff.time<-(as.numeric(as.difftime(c(start.time,current.time),
"%d:%m:%H:%M")[2]-as.difftime(c(start.time,current.time),
"%d:%m:%H:%M")[1])*3600) #seconds between now and start.time
(blocks*2^32)/(10^6*diff.time) #function based on time = difficulty * 2^32 / hashrate
} #assuming blocks average to difficulty over time
### 2. R code for finding expected number of shares/blocks for pooled mining based on hashrate
#
#usage:
#
#blocks(hashrate(Mhps), current time in format "%d:%m:%H:%M)
#
#eg, at the time this was done,
#> n.blocks(332.4623,"28:05:16:18")
#[1] 836
#change date or time format to your preference
#see http://stat.ethz.ch/R-manual/R-patched/library/base/html/strptime.html for details
n.blocks<-function(hrate,start.time)
{
current.time<-format(Sys.time(),"%d:%m:%H:%M") #set date and time format
diff.time<-(as.numeric(as.difftime(c(start.time,current.time),
format="%d:%m:%H:%M")[2]-as.numeric(as.difftime(c(start.time,current.time),
format="%d:%m:%H:%M")[1]))*3600) #hours between now and start.time
round((hrate*10^6*diff.time)/2^32) #function based on time = difficulty * 2^32 / hashrate
} #assuming blocks average to difficulty over time
### 3. R code to determine required hashrate to produce a given no. of expected bitcoins
### at current Difficulty for a given time period (days), block value <- 50 coins
### current Difficulty obtainable thanks to blockexplorer.com
#
#usage:
#
#h.rate.currentdiff(time period (days),required number of bitcoins)
#
#eg, for the current difficulty (434882.7)
#> h.rate.currentdiff(3,5)
#Read 1 item
#[1] 720.6046
#
# means atm you need a hashrate of 1213.624 to get 5 bitcoins in 1 day
h.rate.currentdiff<-function(days,bitcoins)
{
block.val<-50
current.difficulty<-scan(url("http://blockexplorer.com/q/getdifficulty"))
((current.difficulty)*2^32)/(10^6*days*24*3600) * (bitcoins/block.val)
}
### 4. R code to determine required hashrate to produce a given no. of expected bitcoins
###### at any Difficulty for a given time period (days), block value <- 50 coins
#
#usage:
#
#h.rate.otherdiff(time period (days),required number of bitcoins, any Difficulty level)
#
#eg, for the previous difficulty (244139.5)
# > h.rate.otherdiff(3,5,244139.5)
# [1] 404.5413
#
# means at the previous Difficulty you only needed hashrate of 404.5413 to get 5 bitcoins in 3 days
h.rate.otherdiff<-function(days,bitcoins,otherdiff)
{
block.val<-50
((otherdiff)*2^32)/(10^6*days*24*3600) * (bitcoins/block.val)
}
### 5. R code for determining no. of expected bitcoins for a given hashrate,
### at current Difficulty for a given time period (days) and for blockvalue<-50coins
### current Difficulty obtainable thanks to blockexplorer.com
#
#usage:
#coins.currentdiff(days,hashrate)
#
#eg, for the current difficulty (434882.7)
#> coins.currentdiff(1,700)
#Read 1 item
#[1] 1.619011
#
# ie ~ 1.62 coins per day on average for 700 Mhps
#
#
coins.currentdiff<-function(days,hashrate)
{
block.val<-50
current.difficulty<-scan(url("http://blockexplorer.com/q/getdifficulty"))
(block.val*10^6*days*24*3600*hashrate)/((current.difficulty)*2^32)
}
### 6. R code for determining no. of expected bitcoins for a given hashrate,
### at any Difficulty for a given time period (days) and for blockvalue<-50coins
#
#usage:
#
#h.rate.otherdiff(time period (days),required number of bitcoins, any Difficulty level)
#
#eg, for some future possible difficulty (400000)
#
#> coins.otherdiff(1,700,600000)
#[1] 1.173466
#
# ie at Difficulty 600000, you could expect 1.17 coins per day on average for 700 Mhps
#
coins.otherdiff<-function(days,hashrate,otherdiff)
{
block.val<-50
(block.val*10^6*days*24*3600*hashrate)/((otherdiff)*2^32)
}
################## EOF #########################################