Bitcoin Forum
November 18, 2024, 04:51:16 AM *
News: Latest Bitcoin Core release: 28.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: R tools for pooled mining  (Read 1562 times)
organofcorti (OP)
Donator
Legendary
*
Offline Offline

Activity: 2058
Merit: 1007


Poor impulse control.


View Profile WWW
May 27, 2011, 05:49:05 AM
Last edit: May 28, 2011, 09:51:14 AM by organofcorti
 #1

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  Angry , 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!  Grin

28-05-2011 Edit: fixed and updated a few things.

Code:
### 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 #########################################


Bitcoin network and pool analysis 12QxPHEuxDrs7mCyGSx1iVSozTwtquDB3r
follow @oocBlog for new post notifications
timmmay
Member
**
Offline Offline

Activity: 84
Merit: 10



View Profile
May 27, 2011, 12:52:26 PM
 #2

Thanks for this!  Nice to have some equations in a usable format Smiley

organofcorti (OP)
Donator
Legendary
*
Offline Offline

Activity: 2058
Merit: 1007


Poor impulse control.


View Profile WWW
May 28, 2011, 01:46:58 AM
 #3

Glad you like! Any problems using them?

I've noticed that for h.rate() the POSIXlt vs POSIXct issue means that on some systems Sys.time() gives GMT instead of local time, and for me that means a -ve h.rate which, since I am not unmaking solutions, is wrong  Embarrassed

I can't remember how to fix it, but for the moment (if its a problem for you), just change line:
Code:
current.time<-format(Sys.time(),"%d:%m:%H:%M")	#set date and time format

to:

Code:
GMT.timediff<-10     #time difference between you and GMT in hours
current.time<-format((Sys.time()+GMT.timediff*3600),"%d:%m:%H:%M") #set date and time format

which should fix it until I can remember how.


Bitcoin network and pool analysis 12QxPHEuxDrs7mCyGSx1iVSozTwtquDB3r
follow @oocBlog for new post notifications
timmmay
Member
**
Offline Offline

Activity: 84
Merit: 10



View Profile
May 28, 2011, 05:39:59 AM
 #4

Haven't tried yet and I'm now in hospital waitin to get surgery on my toe! Hope to give u some feedback next week Smiley

organofcorti (OP)
Donator
Legendary
*
Offline Offline

Activity: 2058
Merit: 1007


Poor impulse control.


View Profile WWW
May 28, 2011, 10:01:20 AM
 #5

Quote
Haven't tried yet

Just as well! My midnight scripting made me screw up the time based stuff in 1. and I left out block.val<-50 in 6. All good now though. Great for working out where we'll be in a few weeks. The RJSONIO script means I can graph my shares as they arrive, plot received coins, hashrate and diffculty together, it's sweet. If you like things like that.


Quote
I'm now in hospital waitin to get surgery on my toe! Hope to give u some feedback next week

I'll look forward to the feedback. Good luck with the, er .... toe? Rilly?


Bitcoin network and pool analysis 12QxPHEuxDrs7mCyGSx1iVSozTwtquDB3r
follow @oocBlog for new post notifications
timmmay
Member
**
Offline Offline

Activity: 84
Merit: 10



View Profile
May 28, 2011, 10:10:02 AM
 #6

Cool no worries.  I'm actually working with a friend who's doing the programming side of things.  I showed this to him today and he's going to hopefully look at it tonight.

Yeah I was mowing the grass today and somehow ended up with my foot under the mower and cut the crap out of my left big toe (through my socks and shoes too!).  It's not pretty...

Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!