Showing posts with label tips & howtos. Show all posts
Showing posts with label tips & howtos. Show all posts

Sunday, March 16, 2014

Things to consider for profitable cryptocurrency mining

There is a looong discussion on Reddit on whether Dogecoin mining is profitable or not. I do not claim I'd had the stamina to read all the way through it, but a theme seems to get repeated ("yes it is" - "no it isn't").

The opinions also vary widely on the usefulness of so called altcoins (meaning anything other than Bitcoin). Surely any coin (I think I'll from now on use "coin" instead of the more tedious "cryptocurrency") that is not accepted widely as payment isn't really useful as a token of exchange, i.e. payment, but both for miners and traders they might prove useful. However, as these coins come and go it's essential to assess if the value of a given coin is expected to stay or increase in the future to prevent losses.

Trading aside (since that's not my cup of tea), once one has established adequate level of trust on a given coin, there are things to consider (after considering the efficiency of your mining hardware):
  • Do you want to take the exchange risk involved in holding on a coin for more than a day? If you do, do you see a given coin increasing in exchange value in the near future?
  • If you're going for low exchange risk and will immediately sell what you mine, does the lower risk factor counter the daily transaction and exchange fees? Also, what coin is the most profitable today regarding difficulty, reward, network hash rate and the target coin/currency?
  • Even if you're willing to take the exchange risk, it's worth checking the profitability based on difficulty, reward and network hash rate.
There are a number of mining profitability calculators around the Net. There are CoinWarz, Dustcoin, CrabCoins and whatnot (please don't get offended if your favourite one is not listed, those are just random ones I ended up to). I got interested in how those calculators actually estimate (as for that it is, estimation, since random events are in play) the profitability - and I think everyone who's using the calculators should be interested as well. CoinWarz does the calculation on the server so I couldn't check their code, but both Dustcoin and CrabCoins reveal their formula in the page source. Both also use pretty much the same formula:

 time [s] x hashrate [H/s] x reward
------------------------------------
         difficulty x A

where A = 0x100010001h at Dustcoin and A = 2^32 at CrabCoins. Since those values are close to being the same, the sites give almost exactly the same results.

At this point I started looking up more calculators. CoinSelect, Where to Mine and Criptovalute seemed to give the same results so I guess they use the same formula, too. And hey, the formula does make sense: The longer the time, the greater your hash rate or the greater the reward, the greater will be the profit - and the greater the difficulty, the smaller will be the profit. What bugs me is that coefficient A as I don't know where it is derived. The actual code at Dustcoin uses two other constants in place of it, but they are likewise as cryptic to me. I'd be glad if someone pointed me to an explanation for the coefficient.

One thing to note about the calculators: Always check if they are using the correct up-to-date data. Difficulty might be off from the current one, as well as exchange rates, and even the reward (but that would mean their data is really stale). It makes sense to check at least two sources that you trust to eliminate the risk of deciding based on incorrect data.

It is very likely that an extremely favourable mining situation will not go on for long, as also other miners will come to mine thus raising the hash rate which in turn will make difficulty rise. So, there will be constant ebb and flow which also means one should automate pool/coin switching based on estimated profit to continuously adapt to the changing situation. There is already software for that, quick googling brought up CryptoSwitcher and I remember having seen others as well. E.g. cgminer has API that allows centralised remote controlling of miners and when you add automatic decision making based on network data, your miners should be always after the largest profits, or at least staying away from the least profitable coins.

It should be quite easy to implement home-brewn mining automation since e.g. CoinWarz offers an API that one could use to directly access their profitability data. The free version allows 25 calls in 24 hours, meaning the situation could be checked once an hour, which should be quite enough when you're not doing this too seriously. The lack of real-time network data can be compensated by steering away from the most volatile coins. There will still be the risk of sudden large exchange rate changes, but those should be rare enough to keep the risk relatively small.

Finally, for those who want it to be extremely easy, there are mining pools that automatically do the switching for you. If you trust their algorithm does a good work, one of those is the easiest way to get the benefits of coin switching.
submit to reddit Delicious

Sunday, February 2, 2014

Adding sharing buttons for Pinterest, Reddit, Delicious, Stumbleupon and LinkedIn to a Blogger blog

My better half wanted to add a Pin It button to her blog and needed my help, so I did some googling around it to find out how to do it. As a result I figured I could also add support for some other sharing sites in my own blog as well. It was not as straight-forward as many blog posts and support docs on the subject do claim, so I'll tell here what I did in order to get them all nicely lined up. I hope this makes life easier for somebody else.

This was the resulting row of buttons,
in case I end up changing the layout later on...


Pinterest

There is a rather good blog post at bloggercentral.com on adding Pin It button to Blogger, and it also tells the basics about the blog template.

However, I had very little luck with the embedded template editor (after trying two browsers including Chromium, saving the template after changes didn't work), and found out it is way better to take the XML backup of the template and use a good text editor to modify that. Remember to save your changes on a different name! On Linux e.g. kedit and gedit work fine, but on Windows it was tougher since Notepad doesn't understand Unix style line breaks, and Wordpad isn't really a text editor so it is not guaranteed to preserve formatting. I downloaded Notepad++ Portable for the task (since it does not require system-wide installation), but any decent text editor that supports UTF-8 encoding and Unix style line breaks should do.

The other thing that didn't go as the instructions said was the placement of the button code - in both of the blogs it was required to add the button at the second occurrence of <data:blog.post/>. I should study more of the template structure to figure out in what cases the other occurrences are being used, but anyway I made the addition to all of them.

Reddit

The support doc on reddit.com shows many options for the button, all with sample HTML code, but there is a catch in using them with Blogger. All the samples would more or less work on a single blog post, but they wouldn't work on the blog home page which has many posts. The advanced options down the page show a way to go with some of the buttons (those that use a script tag), but in all cases the page reference needs to be modified to suit Blogger. Below is what I use.
<a expr:href='&quot;http://www.reddit.com/submit?url=&quot; + data:post.url'>
 <img src='http://www.reddit.com/static/spreddit7.gif' alt='submit to reddit' border='0'/> </a>

Noteworthy things:
  1. Usage of expr prefix on href attribute tells Blogger that it needs to interpret the attribute value which contains references to layout data tags (e.g. data:post.url).
  2. Also quoting needs some tuning, since the whole expression to be interpreted requires quotes around it, and the static text part in it also needs to be enclosed in quotes, thus the two occurrences of &quot;.
If you'd be using those buttons that have just a script tag in the example, just look at the example given under Interactive button advanced settings and change the values of reddit_url and reddit_title to point to data:post.url and data:post.title, respectively. However, reddit seems to figure out the title from the URL if title is not given, which is nice since I didn't find a way to make Blogger understand multiple URL parameters (although it should be possible and I do know how to format a GET request with multiple parameters).

Delicious

Also delicious.com shows a working sample of their button, but as mentioned just above with reddit, it didn't work that well with multiple parameters on the URL in Blogger template. However, it seems to be enough to put just the url parameter there. Also in this case I moved the request URL to href attribute even though it is not as neat as hiding it in the onClick handler. So, here's what I use:
<a expr:href='&quot;http://del.icio.us/post?url=&quot; + data:post.url' target='_blank'>
  <img border='0' alt='Delicious' title='Del.icio.us' src='https://delicious.com/img/logo.png' height='16' width='16' />
</a>

Stumbleupon

The badge creator at stumbleupon.com looks rather fancy, but at that point I had grown a bit tired of all fancy things which are hard to put into the template, and so I took the easy route of peeking at a page with a working badge and extracting the URL and the icon from there. Not quite as recommended, but it seems to work, too:
<a class='logo' target='_blank' expr:href='&quot;http://www.stumbleupon.com/submit?url=&quot; + data:post.url'>
  <img border='0' alt='Stumbleupon' src='http://cdn.stumble-upon.com/i/badges/badgeLogo18x18.png?v5' height='18' width='18' />
</a>

LinkedIn

There is a share plugin generator on developer.linkedin.com which gives the necessary code for the share button, and the data-url attribute with added expr prefix gets its value from data:blog.url just like in all the above.

The final touch

All of the above would work just fine alone, but putting them together took some additional effort for the result to look nicely aligned. From the Pinterest sample code I took the enclosing div, and put all the rest within that, too. However, the icons ended up aligned pretty bad, and so I added vertical alignment.

That solved all but Pin It  and inShare buttons, which have enforced styles from the accompanying Javascript code. For Pinterest it is possible to just ditch the Javascript and go with plain link+icon, but LinkedIn has made it more complex, so I ended up adjusting the styling of the enclosing div and adding some spacers to add some space around the buttons.

So here is my template addition as a whole:
<style type='text/css'> 
  #sharing-wrapper {margin:10px 0 0 0; text-align:left; vertical-align:baseline !important; padding:0px !important;}
  #sharing-wrapper img {padding: 0px !important;}
  #sharing-wrapper .spacer {padding-left: 8px;}
</style> 

<div id='sharing-wrapper'>

<!-- pinterest start -->
  <a data-pin-config='none' data-pin-do='buttonPin' expr:href='&quot;http://pinterest.com/pin/create/button/?url=&quot; + data:post.url'>
    <img src='//assets.pinterest.com/images/pidgets/pin_it_button.png'/>
  </a>
  <span style='margin-left:-44px;'>
    <a data-pin-config='none' data-pin-do='buttonBookmark' href='//pinterest.com/pin/create/button/' style='outline:none;border:none;'/>
  </span>
  <script src='http://assets.pinterest.com/js/pinit.js' type='text/javascript'/> 
<!-- pinterest end -->

<span class='spacer'/>

<!-- reddit.com start -->
<a expr:href='&quot;http://www.reddit.com/submit?url=&quot; + data:post.url'>
  <img src='http://www.reddit.com/static/spreddit7.gif' alt='submit to reddit' border='0'/> </a>
<!-- reddit.com end -->

<span class='spacer'/>

<!-- del.icio.us start -->
<a expr:href='&quot;http://del.icio.us/post?url=&quot; + data:post.url' target='_blank'>
  <img border='0' alt='Delicious' title='Del.icio.us' src='https://delicious.com/img/logo.png' height='16' width='16' />
</a>
<!-- del.icio.us end -->

<span class='spacer'/>

<!-- stumbleupon start -->
<a class='logo' target='_blank' expr:href='&quot;http://www.stumbleupon.com/submit?url=&quot; + data:post.url'>
  <img border='0' alt='Stumbleupon' src='http://cdn.stumble-upon.com/i/badges/badgeLogo18x18.png?v5' height='18' width='18' />
</a>
<!-- stumbleupon end -->

<span class='spacer'/> 
<!-- linkedin start -->
<script src='//platform.linkedin.com/in.js' type='text/javascript'></script>
<script type='IN/Share' expr:data-url='data:post.url'></script>
<!-- linkedin end -->

</div>
I put that right after <data:blog.post/> tag so that it appears after the post body text. It would be even nicer to have it on the same row as the built-in share buttons, but that would really require figuring out the templating more deeply than I am willing to do right now.

In addition, put the following right before </body>, since repeating it for every post messes up the positioning of Pin It button on blog home page:
<script src='http://assets.pinterest.com/js/pinit.js' type='text/javascript'/>

(oh, and since this blog is visually not that fancy, I think I'll drop Pinterest out, I doubt anyone would pin from this anyway...)

Addendum (5.2.2014): Digg and Tumblr

Later I also added Digg and Tumbr sharing.

Digg was simple, although the current incarnation doesn't seem to provide any official share button or widget.Thus I just made a link to their submit URL and used their favicon for the icon.

Tumblr was a bit harder, since the official JavaScript version only works on single post pages (not on the blog home page) and when using a simple GET request URL, the shared URL needs to be encoded - which Blogger template API can't handle (also they don't seem to fetch the page title automatically so that, too, must be encoded and included in the link). So I made my own inline JS to create the link the way I want it to be.

Here are the additions to the above, placed just before ending the </div>:
<span class='spacer'/>

<!-- digg start -->
<a class='logo' expr:href='&quot;http://digg.com/submit?url=&quot; + data:post.url' target='_blank'>
  <img alt='Digg' border='0' height='18' src='http://digg.com/static/images/digg_favicon.png' width='18'/>
</a>
<!-- digg end -->

<span class='spacer'/>

<!-- tumblr start -->
<script type='text/javascript'>
  var strPostUrl = "<data:post.url/>";
  var strPostTitle = "<data:post.title/>";
  document.write("&lt;a href='http://www.tumblr.com/share/link?url="
    +encodeURIComponent(strPostUrl)+"&amp;name="+encodeURIComponent(strPostTitle)
    +"' target='_blank' title='Share on Tumblr'&gt;&lt;img src='http://platform.tumblr.com/v1/share_3.png' width='129' height='20'/&gt;&lt;/a&gt;");
</script>
<!-- tumblr end -->
submit to reddit Delicious

Sunday, January 12, 2014

Employing random hardware for Litecoin mining

Cryptocurrencies are a prominent trend at the moment, with Bitcoin (BTC) leading the way. In fact, BTC seems to already have passed the limits of hype and boomed also financially to the extent that mining of BTC is hardly anymore profitable unless you have a state of the art mining rig (and there is a chance the rig won't pay for itself as the mining difficulty rises). For the ones who want to try the ever-lucrative miracle of getting bucks out of thin air (or more precicely, out of CPU/GPU cycles), there are fortunately many alternatives left. Litecoin (LTC) is maybe currently the most prominent alternative for BTC (at least measured by market capitalisation) that can be mined (source: coinmarkercap.com). Ripples is ahead of LTC in market cap but it works differently to the likes of BTC.

That's it for the financial part of this post. I'll give whatever I will get mined to charity, and with the hardware I have there's no risk of getting rich in this business. Anyway, I got interested of the possibility to easily harness the processing power of unused hardware along the lines of plug it in and leave it there to crunch numbers. The same idea could be employed to anything that uses massively distributed processing.

I selected a live Linux distro on a USB stick as the OS for the experiment. Linux, since it doesn't require much resources, is easy to tweak and free to use, and I'm more familiar with it than Windows. Grml Live Linux was the one I chose to use, mostly because of the small footprint (good fit for old 512MB sticks).

There were two things in this project that I hadn't done before: customising a live distro (to add miner software) and re-producing a bootable ISO image. The first part ended up being pretty trivial, even though Grml uses squashed file system so I had to unsquash it first and squash it up again after modifications. Since I won't need to retain any run-time changes in the filesystem between reboots squashfs is just fine for the purpose.


Customising of the live image

Mount the original Grml ISO and copy it somewhere for modifications:

> sudo mount /var/tmp/grml32-full_2013.09.iso -o loop /media/cdimage
> cp /media/cdimage /var/tmp

Unsquash the root filesystem, modify it and put it back together:

> mkdir /var/tmp/grml32-custom
> cd /var/tmp/grml32-custom
> unsquashfs /var/tmp/cdimage/live/grml32-full/grml32-full.squashfs 


[copy stuff and adjust to run on the target setup]

> cd ..
> mksquashfs grml32-custom/squashfs-root/ \
  /var/tmp/grml32-custom_2013.09.squashfs -b 262144
> cp grml32-custom.squashfs /var/tmp/cdimage/live/grml32-full/

I ended up using the same block size for the squashfs as the original (thus "-b 262144"), but likely that doesn't matter much other than reduced overhead for large files since the default block size mksquashfs uses is pretty small.

Finally, to save space, I deleted the original .squashfs file from live/grml32-full/ and modified live/grml32-full/filesystem.module to point to the customised version.


Re-building the ISO

This took me a while to solve, since there were all kinds of instructions on the net how to produce a bootable ISO, but none worked. With genisoimage I got as far as being able to boot with the image file using QEmu, but after copying the image on the USB stick it wasn't working anymore. The issue seemed to be that the image didn't contain proper partition table (checking with cfdisk showed no partitions). Of course, one could just have the contents of the root partition in the image and then install boot loader manually after installing the image, but I preferred to produce a neat and simple image that does everything the original one does, too.

I finally ended up using xorriso as instructed somewhere:

> xorriso -as genisoimage -r -o grml32-custom_2013.09.iso \
  -b boot/isolinux/isolinux.bin -c boot/isolinux/boot.cat \
  -no-emul-boot -boot-info-table -boot-load-size 4 \
  -V "GRML_custom" -iso-level 3 -partition_offset 16 \
  -isohybrid-mbr /usr/lib/syslinux/isohdpfx.bin /var/tmp/cdimage/

Finally, just I just cat'd the image on the USB drive.

This required me to install xorriso and syslinux and their dependencies from the Debian repository, but that was all extra that was needed.


The aftermath

I used cpuminer in this experiment because that is what I use on my boxes anyway (couldn't get cgminer to compile, and I doubt my low-end GPUs would provide much extra power anyway). I had built init.d script for minerd which makes it rather easy to construct a plug-in-and-mine solution.
The nice thing here was that Grml had all the required libraries already so I had just to copy over the executable, scripts and config files. I don't know how much it affects that I am now running an executable built for old AMD Athlon XP on a Intel Core i5, but unless there is good evidence that compiling for a newer target CPU would do any good, I don't bother. At least this way the executable should run on pretty much all hardware that is worth trying - the old Athlon XP here gets about 0.8 khash/sec which is pretty near at not worth trying...

Interestingly, running 4 miner threads on the Core i5 chip (which advertises 4 cores due to hyper-threading) gained about 14.1 khash/sec, but since that also meant having the laptop fan blow at top rpm constantly, I changed to running only 2 miner threads, still gaining about 9.7 khash/sec. This is a good example on the limitations of shared-something CPU architectures, but probaly also an example on how the turbo boost technology can compensate by reaping the headroom left in TDP due to only using part of the chip.

(edit: after measuring the actual power draw with both 4 and 2 mining threads it was obvious that the power vs. hashing efficiency is much better with 4 cores)
submit to reddit Delicious