Added new features to Blagominer: support for HTTPS connections and servers requiring custom headers

in #utopian-io5 years ago (edited)

Quick project info

This software is a "mining" software for a family of cryptocurrencies based on so-called Proof-of-Capacity. The best information about that concept is available in info materials from the BURST coin. You can learn some technical bits from resources on their home page, for example this whitepaper.

Repository

GitHub: https://github.com/quetzalcoatl/blagominer/

Sidenote: This is somewhat tricky. You may notice that it has been forked from andzno1's repository. That's true, but as far as I know, andzno1 doesn't continue this project, so I took it over and forked my own from it. Actually, you can find many more old copies of this project, because it moved from person to person several times. Often by copying, not forking, so GitHub does not show the whole derivation chain properly.

Those historical ones that I've found are, in reverse order:

Utopian (re)Submission note

This is a resubmission of previous post under the same title. The previous one was rejected due to some misunderstanding. I discussed it with Knowledges and got green light to shorten the post and resubmit.

New Features

This submission is related to my work on this project between Jun 3, 2019 - Jun 2, 2019, with later socket leak bugfixes from Jun 7, 2019, important stability update.

At this point of time I considered it to be a bit too early and untested, so I have not published a "release" yet, however you may see those improvements included in v1.200001.0 released a bit later

1. Adding custom pool-specific headers and parameters to DL submission

Feature branch for this change is feature/custom-headers.

My work on this project began with the idea of making the Blagominer easier to use by small causal miners. While setting up BURST mining is pretty straightforward, setting up BHD mining often requires use of a so-called proxy that injects some custom headers, like X-Account which identifies miner's account in the pool website. An example of such BHD mining pool is The Foxy Pool. Blagominer could not be connected directly to this pool due to X-Account http header required by the pool, as otherwise the pool could not track and transfer earnings properly. Typical installation targetting Foxy Pool so-called Foxy Proxy as a mediating node.

These changes turned out to be pretty simple, so most of the work was actually contained in a single commit:

  • added new configuration section for configuring headers
  • a bit of code to prebuild and cache a part of the HTTP query related to headers

In a similar way, I also included support for custom http header for BURST connections, and added support for custom http query parameters fo BURST/BHD sections.

2. Support for HTTPS connections

Feature branch for this change is feature/https.

Simply speaking, the Blagominer lacked any HTTPS support, so it could not connect to any pool using HTTPS. Also if the pool used services like Cloudflare, these could attempted to force a redirect to a HTTPS connection, causing Blagominer to fail.

To solve this, I added HTTPS support to the core 3 networking operations performed by the miner, namely: poll(), send_i(), and confirm_i(). Later it turned out that those are actually two operations, known better as getMiningInfo (poll) and submitNonce (send_i, confirm_i).

Changes for this part were far more extensive and spanned about 15 commits. To make a long story short, let me just say that I:

  • added a UseHTTPS per-coin switch to the miner.conf file
  • refactored actual transport operations away from poll(), send_i() and confirm_i()
  • implemented separate HTTPS implementations with help of curl, preserving existing logic as much as it possible
  • duplicated sessions queue that held pending sockets, and adapted the copy to hold pending curl handles

After those changes, I began testing Blagominer on Foxy Pool without proxy software, and early tests proved it runs fine and cooperates with the pool properly.

3. Cleaning up socket leaks.

Feature branch: get-rid-of-socket-leaks

Longer HTTPS tests exposed some connection-managing issues. A pool of dead sockets was piling up (detected with ProcessHacker2). After a few 8-hour test runs, each gathered tens or hundreds of stale sockets. On Jun 7, 2019 I managed to fix that.

It turned out that almost all of original poll(), send_i() and confirm_i() had handle leaks. When I implemented HTTPS support, I deliberately preserved old logic to ensure I don't break anything accidentally. However, while on the main flow these routines cleaned up everything properly, in many error handling branches it did not, and now both HTTP and HTTPS code leaked.

A series of 5 commits takes care of them well. After that I performed another set of 8-hrs test runs later and number of open connections stopped growing.

Most of those patches are just adding proper cleanup on specific error code branch that lacked it, but in some places the number of missing cleanups was so large, that I leveraged smart-pointers to guarantee a RAII-style cleanup. An example of that is seen for example here where unique_ptr is exploited for this purpose by using a lambda with closesocket as its Deleter.

While bugfixes usually doesn't qualify, these leaks actually originate from "not my code" :) and I consider them an important "icing on the cake", as these leaks were present there for a long time and these patches significantly reduce socket/port consumption and improve stability of the miner.

GitHub Account

https://github.com/quetzalcoatl/

Fine print section

  1. The BURST image used in this article comes from wikimedia.
Sort:  

The Linux of Blockchain

looks like a very interesting catchword for a project. Interesting concept. I will have a look at Burstcoin.

Not an expert on the context, however, I can say that the post is decent quality.

As a side note, I see repeated commit messages. Squashing/Merging commits for such cases always creates a better GIT history. There is also a broken link on "get-rid-of-socket-leaks" link.

Looking forward to seeing more updates and development on blagominer :-)


Your contribution has been evaluated according to Utopian policies and guidelines, as well as a predefined set of questions pertaining to the category.

To view those questions and the relevant answers related to your post, click here.


Need help? Chat with us on Discord.

[utopian-moderator]

Thank you for your review!

I've just corrected that link, thanks.

Regarding those duplicated commit messages (like "fixed socket leak") I actually deliberately kept that as separate commits, one per leak fixed. Small commits really help with conflict resolution later, and I tend to work on many branches. But you're totally right - I should include at least "where" (i.e. leak was in method xyz) and "case info" for given leak (leaks when it skips a test; leaks when it errors-out on response; etc). I'll keep that in mind in future.

"The Linux of Blockchain".. yeah.. I wish they took a bit less boasting catchword. BURST coin started out nice, then died, then was revived, then later it's flagship pools got huge amounts of bad reputation due to PoCC's war(?) with BHD coin.. BHD, as shady as it seems to be, and as ridiculous with its sky-high mortgaging requirements, actually defends its price and slowly shows up on new exchanges - that somewhat proves that there is some potential in Proof-of-Capacity, but time will evaluate that as always :)

Have a nice reading about all of that!

Thank you for your review, @emrebeyler! Keep up the good work!

Hi @ookamisuuhaisha!

Your post was upvoted by @steem-ua, new Steem dApp, using UserAuthority for algorithmic post curation!
Your post is eligible for our upvote, thanks to our collaboration with @utopian-io!
Feel free to join our @steem-ua Discord server

Congratulations @ookamisuuhaisha! You have completed the following achievement on the Steem blockchain and have been rewarded with new badge(s) :

You received more than 100 upvotes. Your next target is to reach 250 upvotes.

You can view your badges on your Steem Board and compare to others on the Steem Ranking
If you no longer want to receive notifications, reply to this comment with the word STOP

You can upvote this notification to help all Steem users. Learn how here!

We are giving DAILY votes of 0.05$ to 0.10$ to all those who get into the @inteligentzia TRAIL at steemauto.com, take advantage now! Contact me by Discord if you need more information

I leave you a post tutorial: https://steemit.com/steempress/@inteligentzia/joininteligentziastrailandreceivedailyvotesworth005-8jz1sahkvf

Hi, @ookamisuuhaisha!

You just got a 0.05% upvote from SteemPlus!
To get higher upvotes, earn more SteemPlus Points (SPP). On your Steemit wallet, check your SPP balance and click on "How to earn SPP?" to find out all the ways to earn.
If you're not using SteemPlus yet, please check our last posts in here to see the many ways in which SteemPlus can improve your Steem experience on Steemit and Busy.

This post has received a 7.13 % upvote from @boomerang.

Hey, @ookamisuuhaisha!

Thanks for contributing on Utopian.
We’re already looking forward to your next contribution!

Get higher incentives and support Utopian.io!
Simply set @utopian.pay as a 5% (or higher) payout beneficiary on your contribution post (via SteemPlus or Steeditor).

Want to chat? Join us on Discord https://discord.gg/h52nFrV.

Vote for Utopian Witness!