Eth: 0x00cce8E2e56a543abc084920eee3f88eFD0921ea

Wednesday, May 27, 2015

Ethereum GPU Mining: Ubuntu 14.04 LTS From Scratch


----------------------------
11/27/2015
This guide is now OUTDATED and has been updated: The New Guide  

-----------------------------
7/30/2015
Updated Multi-GPU commands
Updated instructions for building cpp-ethereum

7/29/2015 @ 11:46pm
Added instructions on transitioning from testnet to Frontier. 
-----------------------------

I tried for two days to install Ethereum for GPU mining and I was tired of reading the Ethereum.org posts and getting no where. I'm a novice when it comes to all this collaborative code development so I just needed a simple-stupid guide for me! I've collated everything in one place for those that are running Ubuntu. This works from a clean install of Ubuntu 14.04 LTS. 

Note: I found this works best if you don't have your GPU card in while doing the initial Ubuntu install (this caused issues for me as the on-board video and GPU were fighting for monitor control or I was hallucinating). 

Start Install:

at the command line type:

 sudo apt-get -y update  
 sudo apt-get -y upgrade -f  
go to system& settings>Software&Updates>Updates &click Pre-released updates (trusty proposed)shut down the computer
install the GPU and GPU power
boot up the computer
then go to system & settings > Additional Drivers & your GPU should be listed there, select Using video driver fror the AMD graphics accelerators from fglrx-updates (proprietary)
apply changes and close

back to the command line: 
 sudo apt-get -y install git  
 sudo apt-get -y install software-properties-common  
 sudo add-apt-repository ppa:ethereum/ethereum  
 sudo apt-get update  
 sudo apt-get install -y build-essential libgmp3-dev golang  
 sudo apt-get -y upgrade  
 git clone https://github.com/ethereum/go-ethereum  
 cd go-ethereum  

backup your old key file (if you mined on test net):
 sudo cp -r ~/.ethereum/keystore ~/Desktop/  

Now lets continue with geth install and get the latest version of geth:
 git checkout master 


Clear out your old blockchain (only if you've run geth on test net previously)
 sudo rm -r ~/.ethereum/extra/  
 sudo rm -r ~/.ethereum/state/  
 sudo rm -r ~/.ethereum/blockchain/  


we need to do some last things to setup for Frontier:

 sudo apt-get install curl    
 cd ~    
 sudo apt-get install -y python-pip python-dev build-essential   
 sudo pip install --upgrade pip   
 sudo pip install --upgrade virtualenv   
 mkdir genfiles  
 cd genfiles  
 curl -O -k https://raw.githubusercontent.com/ethereum/genesis_block_generator/master/mk_genesis_block.py    
 curl -O -k https://bootstrap.pypa.io/get-pip.py    
 sudo python get-pip.py    
 sudo python -m pip install bitcoin  
 cd ..  
 cd go-ethereum   
 make geth    
(if you throw an error on make geth and you go back and try and fix things, make sure to delete the go-ethereum directory before trying to make geth again (error help me!))



now we make a new wallet for Ethereum:


 build/bin/geth account new  

(enter in a password 2x)


now we'll install ethminer

 cd ~  
 sudo apt-get -y install language-pack-en-base  
 sudo dpkg-reconfigure locales  
 wget -O - http://llvm.org/apt/llvm-snapshot.gpg.key | sudo apt-key add -   
 sudo add-apt-repository "deb http://llvm.org/apt/trusty/ llvm-toolchain-trusty main"  
 sudo add-apt-repository ppa:ethereum/ethereum-qt  
 sudo add-apt-repository ppa:ethereum/ethereum-dev  
 sudo apt-get -y update  
 sudo apt-get -y upgrade  
 sudo apt-get -y install build-essential git cmake libboost-all-dev libgmp-dev libleveldb-dev libminiupnpc-dev libreadline-dev libncurses5-dev libcurl4-openssl-dev libcryptopp-dev libjson-rpc-cpp-dev libmicrohttpd-dev libjsoncpp-dev libargtable2-dev llvm-3.8-dev libedit-dev mesa-common-dev ocl-icd-libopencl1 opencl-headers libgoogle-perftools-dev qtbase5-dev qt5-default qtdeclarative5-dev libqt5webkit5-dev libqt5webengine5-dev ocl-icd-dev libv8-dev  
 git clone https://github.com/ethereum/cpp-ethereum  
 cd cpp-ethereum  
 git checkout master   
 mkdir build   
 cd build  
 cmake .. -DGUI=0 -DETHASHCL=1   
 make -j2  
 sudo make install  
 sudo apt-get install cpp-ethereum  #(Can someone confirm that skipping to this step still works)
 cd ~
 cd go-ethereum   

If cmake .. -DGUI=0 -DETHASHCL=1 fails for you, try this variant:
 cmake .. -DGUI=0 -DETHASHCL=1 -DEVMJIT=0  


 Once the genesis block is release do this: (No Longer Required in go-ethereum later than release/1.0.0)



 python ~/genfiles/mk_genesis_block.py --extradata 0x11bbe8db4e347b4e8c937c1c8370e4b5ed33adb3db69cbdb7a38e1e50b1b82fa > genesis_block.json  
 ./build/bin/geth --genesis ~/genfiles/genesis_block.json  


Sync with the Network & Benchmark:

at the command line type:


 cd go-ethereum  
 build/bin/geth -rpc console  
This will start syncing you up with the network. Once synced (you are only grabbing 1-2 blocks at a time) head back to the command line to benchmark. (Note: Personally I found the results of this benchmarking unreliable. Easier to just skip to the mining part):

Ctrl + C
 build/bin/geth --rpccorsdomain localhost 2>> geth.log &  
 ethminer -G -M --opencl-device 0  
 tail -f geth.log  

I initially had some trouble b/c I had an AMD embeded video card and an AMD GPU. Make sure you are targeting the right GPU card by changing the opencl-device # until you find the right card. Reference this list to see if you are targeting the right card.

 Once your are done benchmarking, post your results here.

Note: benchmarking using the code above causes geth to run in the background and thus if you try mining or running geth again, you might get an errors. Easiest thing to do at this point is close the terminal and open a new one. Or just restart the computer for good measure. Then you should have no problem going on to the mining step.

Mining:

Now we're done installing and benchmarking, lets start freaking MINING!

 build/bin/geth --rpc console 
 
I then open up a second terminal and type:

 ethminer -G --opencl-device X   

Where X is the value given by your benchmarking results. Keep doing the "etheminer -G --opencl-device X", one time for each GPU you have. It will take a few minutes for rpc console to sync up and get ready as well as a few more minutes for the miner to start hashing so be patient.

If you skipped the benchmarking part, at this point you should have a good idea of how fast your machine is mining so go and post the results of your average hashing here.  

If you're experiences errors eith Ethminer at this point check the reference posts below. 

Additionally, some GPUs may required an additional typed at the regular command console (not the geth console):

 export GPU_MAX_ALLOC_PERCENT=95  


One last check after you start mining, make sure your coinbase account (the account where your mining rewards will be deposited) is set. You can check this by typing the following inside the geth javascript console:
 web3.eth.coinbase  

If this returns '0x0' that means you're mining rewards will get sent into a big black hole. Fix this by typing the following inside the geth java scrypt console:
 web3.miner.setEtherbase(web3.eth.accounts[0])  

That will set your mining account to your primary account. 

Multi-GPU Mining: 

You can mine with multiple cards. Plug them both into your board and turn on geth "build/bin/geth -rpc console". Let the chain sync.
Then pop open a second terminal and type:

 ethminer -G -t X 
where X is the number of GPUs you have to mine on.
Cheers!

Updating:

Occasionally you will need to update your copy of geth and cpp by pulling down the latest release from github. You can perform this operation by:

 cd go-ethereum  
 git pull  
 make geth    
 cd ..  
 cd cpp-ethereum  
 git pull  
After pulling the latest revision of Geth, make sure to rebuild it using "make geth" as shown above. If you don't rebuild it, it causes major long-term problems. On rare occasion, you will need to completely wipe your blockchain and re-download it. Perform that operation as follows

 cd go-ethereum  
 build/bin/geth removedb   

References:

This post was put together by reading the following posts:
Mining FAQs Live Update
Frontier GPU guide 
Benchmark
Building on Ubuntu
Final Steps for Frontier 

Code formatting brought to you by codeformatter.

Tuesday, May 26, 2015

Motherboard Modifications

Recently purchase a new mother board and had an interesting experience where the mounting point for the CPU heat sink was incomplete. There are usually two mounting 'hooks' the hold the heat sink on the CPU and one of them was missing! The other one didn't have any screws. This was partially my fault because I purchased an Open Box from Microcenter.

As opposed to returning the board or waiting forever for replacements, I went ahead and worked out a solution that required two screws, a hack saw, a coat hanger, and some pliers. Start to finish pictures are shown below:

PC board with single mount installed with modified screws I found in the basement.
 Coat hanger strung under board with two ends poking out of holes for other plastic mounting location.
 Finished coat hanger pare twisted together and bent sideways to form the 'lip' for the heat sink to grab onto.
Side view of the same.

Sunday, January 25, 2015

Federal Government Bets on Bitcoin





In 2014, the IRS released a document outlining how they plan on taxing Bitcoin. The document, titled NOTICE 2014-21, lays out the foundation of their policy with treats Bitcoin like property. Choosing this method of taxation maximizes the revenues the governments receives from Bitcoin miners as long as the price of Bitcoin is rising (relative to USD). We will present a quick example to show the annual tax haul of the federal government in two scenarios, one in which the relative value of BTC to USD is falling, and the other in which BTC to USD is rising.

Scenario 1: Bitcoin loosing value against the dollar




Current Regulation:
INCOME TAX + CAP GAINS = $0

Potential Regulation:
CAP GAINS only =$360




Scenario 2: Bitcoin gaining value against the dollar



Current Regulation:
INCOME TAX + CAP GAINS = $1,365

Potential Regulation:
CAP GAINS only =$1,020




 

Why Should I Care?

  We all want to know yesterday exactly how Bitcoin is going to be regulated in the US and how it is treated for taxation can indicate if the federal government thinks Bitcoin will survive. In a market where the value of Bitcoin is spiraling down into oblivion, under current tax schemes, the federal government will tax miners basically nothing. However, if Bitcoin goes up in value instead, the taxes are 30% above what they would have been under a capital gains only rule. I think the federal government is on a spending binge and they are looking for revenue anywhere they can find it. And with the current tax regulation, they are betting on Bitcoin going up! Thus, for all the rhetoric about how Bitcoin is bad and helps people do bad things (ie. helping move money from conflict avocado sales south of the border), the federal government wants a slice of that sweet sweet Bitcoin Pie.

 Assumptions.

  Single household that has an income tax of 30% (fed+state) & capital gains of (20%), mining produce 0.5 BTC / month and cost 60 USD / month to operate. BTC are all exchanged for USD at the end of the year. Hardware deprecation effects are not included. BTC holds price steady after the end of the year and long term capital gains are applied to sales.

Friday, October 10, 2014

CFL vs. LED light bulb, Which is less expensive?

Problem Statement

As with all optimization problems, determining if you want to buy CFL bulbs to light your home, or the new LED bulbs, is a serious decision. (Especially now that the LED guys got the Nobel Prize!) I'm here to help. I've put together a few graphs of my findings. The long and the short if it is, it depends...

The total cost of CFL vs. LED is in some way related to the following factors:
  • Initial cost of the bulb ($)
  • Electricity consumption of the bulb (W/hr)
  • Average electricity costs in your area (kW/hr)
  • Return on Investment aka: ROI (%)
  • The number of bulbs you have in your house (#)
  • The average number of hours the bulbs are on during the day (hours on/day)
All of these variables are combined to come up with a unique profile of your costs. Our approach includes an assessment of the time value of money. To determine to total expenses of both products, we calculate total amount of money spent on the product including initial costs and reoccurring costs, as well as what that money would have been worth if it had been invested rather than spent. I will give you the rundown of a few scenarios.:

Scenario 1

15 bulbs are installed in a house that are on for an average of 5 hours / day. ROI is 3%. Electricity costs are 0.12$/(kW/hr), 800 Lumen CFL consumes 14W/hr and costs 1.66$ each, 800 Lumen LED consumes 9.5W/hr and costs $9.34 each.

So let's talk about what's happening here. On these graph, higher numbers on the Y axis is bad (we're looking to minimize expenses).  CFL beats out the LED option until year 14. However. Those shallow savings are soon wiped in year 15 as the LED bulbs have reached their 25,000 hour rating and must now be replaced. However, after this time, the values steadily diverge yielding a $200 savings after 30 years. That really isn't something to write home about.

Scenario 2

15 bulbs are installed in a house that are on for an average of 5 hours / day. ROI is 3%. Electricity costs are 0.12$/(kW/hr), 800 Lumen CFL consumes 14W/hr and costs 1.66$ each, 800 Lumen LED consumes 9.5W/hr and costs $5.00 each (only change).

This is a much more promising scenario where the price of LED bulbs has fallen by almost 1/2. Here we see it takes 4-5 years to break even and we have relatively steady savings from there on out to 30 years where our total savings is around $500. Not bad but still a long time to wait to save $500!.

Scenario 3

15 bulbs are installed in a house that are on for an average of 5 hours / day. ROI is 3%. Electricity costs are 0.20$/(kW/hr), 800 Lumen CFL consumes 14W/hr and costs 1.66$ each, 800 Lumen LED consumes 9.5W/hr and costs $5.00 each.

Here we have a scenario where the price of power has now also increased. This results in a pretty clear winner even in the short term. A $250 savings is realized within 5 years by switching to LED lights and over 30 years, a $2,500 savings is realized.

Conclusions

There are no simple answers here. It is hard to tell which solution will really save you a significant amount of cash in the near term. You might not want to rip out those CFLs till they burn out. What is clear from these studies is that no one can tell you for sure which one is less expensive unless they take a detailed look at your usage habits. One thing I would not do is just read the back of the package and assume that your usage profile fits theirs. (They are trying to get you to buy that box you're holding remember, so they have an incentive to paint it in a good light.) Any type of simple quick decision in this field is probably going to lead you down the path of spending more money.

Based on my usage profile, I'm expecting that once the bulbs hit $5.00 I'll slowly replace my CFLs with LEDs. I have to have something to show for 3 hours of work on a Friday :). And it'll insulate me against future price hikes by the electricity suppliers. $10.00 for the LED lights is just too expensive to make it worthwhile.

I've supplied the spreadsheet that I used for all the graphs included in this posting. I recommend that you check it out and plug in your own numbers. I hope it can help you figure out if CFL or LED is better for your application in less than the three hours it took me to put the analysis together!

Download Spreadsheet from Google Drive


Notes

Specs on the bulbs compared in this study can be found here:
CFL & LED

Disclosures

I am in no way affiliated with any light bulb manufacturers and I don't own any stock in them either and I have only purchased CFL bulbs in the last 5 years.

Sunday, March 4, 2012

If Statement in Matlab

How to do a double if statement in Matlab (have a process execute under 2 or more conditions):


Matlab 2011a (and other versions) is tricky program to code correctly. Sometimes you think you are doing everything right and you are not getting any warning messages but things are still broken. It is easy to do this with the IF statement. Recently I coded up a double or compound if statement and I thought it was working properly. I had the script:

However, Matlab 2011a will not check the second condition! Furthermore, it won't tell you there is a problem. The correct way to code this up to make sure both conditions are checked is to either brute force the problem by building in two if statements:

Or the more refined version, use the && operator to make sure both conditions are evaluated:

Read more on IF statements at Matlab documentation site.

Happy Coding
-Láscal

Thursday, March 1, 2012

How to Calculate Drag in LEO using Matlab

I'm going to highlight a simple model that can be used to calculate drag in Low Earth Orbit (LEO). Objects in orbit around earth experience atmospheric drag at altitudes of up to 1200km off the surface of the Earth. Spacecraft that orbit in LEO must compensate for drag or else their orbit will decay and they will burn up in the atmosphere. Anything that travels below 100km altitude is now so low that it will eventually either burn up or hit the surface of the planet. Drag is a complex force and there are many variables that one should take into account. However, we have simplified it down to the bare bones so you can understand the essentials in a simplified model. 

Things you will need: 
Data on your spacecraft you want to calculate drag on including: orbit altitude (assume circular orbit), surface area (assume spherical), mass of spacecraft, and the velocity of the spacecraft. Optional: A copy of Matlab to run example code.

Example Problem: 
For our example we will assume an altitude of 455 (km). From the velocity equation of a circular orbit Vcirular=sqrt(mu/radius). Where mu for the Earth is 398,600 (km^3/s^2). Radius = (altitude + radius of earth) = 455 (km) + 6378 (km) = 6833 (km).  Our velocity is therefore 7.64 (km/s) = 7640 (m/s). We will assume a spacecraft mass of 150 (kg). Furthermore we will assume our spacecraft is a sphere with a diameter of 5 (meters). 

Drag Equation:
Where p is the density of the atmosphere at that altitude, Cd is the coefficient of drag, V is our velocity and Area is the frontal area exposed to drag which is 1/2 the area of a sphere for our example. A good place to start is assuming a coefficient of drag of 2 to 2.2. This is typical of hypervelocity trajectories at the altitudes we are dealing with. Our velocity is 7640 (m/s) and our area for the front half of a sphere with a diameter of 5m is 39.26 (m^2). That leaves the density which is the most complicated part of the whole equation.


Estimate Density:
We will estimate the density of the environment using a model developed by James Wertz. This model assumes standard solar conditions and is broken up into altitude blocks. The reason it is broken up into blocks is because this creates a better estimate. The equation we will be applying is:
This equation says that the density a a point is equal to the nominal density (p0) multiplied by e to the power of the altitude over the scale height (H). Use the table below taken from Wertz' work to find the nominal density and scale height for the altitude of 455 (km).
Source: David A. Vallado, Wayne D. McClain - Fundamentals of astrodynamics and applications

For a 450 (km) altitude we will find our scale height to be 60.828 km and our nominal density to be 1.585*10^(-12) kg/(m^3). Plugging these values into the density equation we find a p value of 8.9425*10^(-16) kg/(m^3). 

Finalizing Drag:
We've found our density for the altitude we are orbiting (8.9425*10^(-16) kg/(m^3)), now we need to plug that along with everything else into our drag equation. The the area we found before is 39.26 (m^2). The drag coefficient (Cd) we are assuming is 2. Finally we found our velocity 7640 (m/s). Applying all these elements to the drag equation we find Fdrag =  -2.05*10^(-6) (kg*m/s^2). This force we can translate into an acceleration using the F=m*a relationship, where m is the mass of the spacecraft 150 (kg) and a is the acceleration (change in velocity) the spacecraft experiences from drag. 
 
Matlab Example File:
I've included a Matlab example file which you can call by putting it into your matlab directory and running: 
Dragmedown(altitude,diameter) 
Note: This program is case sensitive. Altitude should be in km and Diameter should be in meters. This program calculates the velocity just like we did assuming a circular orbit and calculates the frontal surface area.
 
Happy modeling!