What Exactly is my Bitcoin Miner Doing?

What Exactly is my Bitcoin Miner Doing?

At SoloSatoshi.com, we’re passionate about empowering individuals in the world of Bitcoin mining. As a leading retailer of unique Bitcoin miners like the Bitaxe Supra, and various other mining tools, we frequently encounter questions from our community about the intricacies of Bitcoin mining. We’ve noticed a recurring theme in these inquiries: What does a Bitcoin miner do? What’s happening? How do mining pools distribute data, and how do miners use this data to “mine” Bitcoin? In response to these frequently asked questions, we’ve decided to create this comprehensive guide and release some sample code (graciously donated by one of our customers). Our goal is to demystify the Bitcoin mining process by providing clear explanations, images and videos, and practical examples with code that you can run yourself. Whether you’re a curious newcomer or an experienced miner looking to deepen your understanding, this article aims to shed light on the fascinating world of Bitcoin mining.

Introduction to Bitcoin Mining:

Alright, we have to cover a brief section here just to cover our bases and ensure that this article is, indeed, comprehensive.  So, really quick, if you don’t already know what Bitcoin mining is:

What is Bitcoin mining? Bitcoin mining is the process of using specialized computer hardware to validate and record transactions on the Bitcoin blockchain. Miners compete to solve complex mathematical puzzles (the details of which we will cover extensively below), with the winner earning the right to add a new block of transactions to the blockchain and receive newly minted bitcoins as a reward. In the case of most of our readers and anyone with half a brain, Bitcoin mining is now done by ASICs.  ASICs are what you are using in the Bitaxe, etc.

Why is mining necessary? Mining serves two crucial functions in the Bitcoin network:

  1. It secures the network by making it computationally expensive to alter the blockchain’s history.
  2. It provides a decentralized mechanism for issuing new bitcoins into circulation, following a predetermined schedule.

This process ensures the integrity and security of the Bitcoin network while maintaining its decentralized nature, free from control by any single entity or government.

Mining Hardware

Types of Bitcoin miners

  • ASICs (Application-Specific Integrated Circuits): Highly specialized and efficient, designed solely for Bitcoin mining. Examples sold by SoloSatoshi.com include the Bitaxe which offer unique features for small-scale miners.
  • GPUs (Graphics Processing Units): Less efficient than ASICs, but more versatile. Not used for Bitcoin Mining.
  • CPUs (Central Processing Units): Least efficient and a complete waste of time for Bitcoin mining today.

Evolution of mining hardware

Everything you need to know about the evolution Bitcoin Mining Hardware

Energy consumption and efficiency

  • Measured in joules per terahash (J/TH)
  • Modern ASICs: 15-40 J/TH
  • Bitaxe efficiency: approximately 15 J/TH
  • Efficiency crucial for profitability due to high energy costs
  • Trend towards more energy-efficient hardware to reduce operational costs and environmental impact, with compact miners like Bitaxe offering accessible options for energy-conscious miners

Okay, so What Exactly is my Bitcoin Miner Doing?

Alright, let’s get to it then. Now that we’ve covered the basics of Bitcoin mining and the hardware involved, let’s dive into the heart of the mining process: block headers and mining data. Understanding these elements is crucial for grasping how miners actually contribute to the Bitcoin network. We’ll explore what a block header is, its components, and provide a real-world example using our first code demonstration. Then, we’ll shift our focus to mining pools, which have become an integral part of the mining ecosystem. We’ll explain how these pools distribute work among miners, introduce the Stratum protocol, and showcase a live example of pool data communication using our second code demonstration. This practical approach will give you an insider’s view of the data miners work with and how they interact with the Bitcoin network through mining pools. Whether you’re a hands-on miner or simply curious about the technical details, these sections will provide valuable insights into the inner workings of Bitcoin mining.

Steps to Mining a Block (Simplified):

  1. Gather necessary data (listed and visualized below)
  2. Build the block header out of the data gathered
  3. Hash the block header using a nonce assigned by your pool
  4. Hash the hash of the result of step 3.
  5. Compare the resulting hash to the difficulty threshold.
  6. Change nonce (or sometimes other data) and restart at step 2

Block Headers and Mining Data:

What is a block header? A block header is a condensed representation of a block in the Bitcoin blockchain. It contains crucial information about the block and is used by miners in the mining process. The block header is what miners actually hash when attempting to solve a block!

Components of a block header: A Bitcoin block header consists of six main components:

  1. Version: Indicates the block version number.
  2. Previous Block Hash: A 256-bit hash of the previous block’s header.
  3. Merkle Root: A 256-bit hash representing all the transactions in the block.
  4. Timestamp: The approximate creation time of the block.
  5. Difficulty Target: The current mining difficulty.
  6. Nonce: A 32-bit number that miners change to generate different hashes.

Demonstrating block header data (Code Example 1)

  • Explanation of the API call and data retrieved: Our code example uses an API call to retrieve information about the last solved block on the Bitcoin blockchain. This API call fetches real-time data from the Bitcoin network, providing us with all the necessary components to construct a block header.
  • Breakdown of the block header components:  You can see that the code exports the necessary data to build the blockheader and this data is color-coded.  The data is then formatted to what the block header needs and then concatenated all into one string as outlined in the image.
  • “Block Header (hex)”: The characters following this are what your miner is actually using to “mine” the block.
  • Step-by-Step Hashing:  This shows the results of the hashes when all of the correct information was given and the block was solved.
Bitcoin Solved Block Data
Bitcoin Solved Block Data

Here is the code (python) that you can run yourself that shows the details of the last solved block.  Please do not abuse the code or the API.  Sometimes the calls timeout or the block information isn’t available.  Wait 20 seconds and try again.  This code is basically a playground for testing.  It has several modes.  You can learn more by running code -h.  This will give you a help menu for all of the available options.

Here’s a video of the “verify mode” code in action:

Let’s Talk About Your Mining Pool:

So, where does all of this information to build the block header come from?  Your mining pool.  On a Bitaxe miner, your default solo mining pool is web.public-pool.io.  Unless you are running your own node and pool software alongside the node, you are most likely mining to a pool.  That means all of the data your miners need to build the block header come from the pool.  The good thing about the pool is that it manages all of the miners so that they aren’t duplicating work.

How mining pools distribute work

Mining pools distribute work to individual miners through a process called “work sharing.” Here’s how it typically works:

  1. The pool server constructs a block template with all necessary information except the nonce.
  2. This template is divided into smaller units of work, each with a different starting nonce range.
  3. These work units are distributed to individual miners in the pool.
  4. Miners work on their assigned ranges, submitting any potential solutions back to the pool.
  5. If a valid block is found, the pool submits it to the network and distributes rewards among participants.

Stratum protocol basics

The Stratum protocol is the most common method for communication between miners and pools. Key aspects include:

  1. JSON-RPC based: Uses a simple, text-based format for messages.
  2. TCP/IP communication: Allows for real-time, two-way communication.
  3. Subscription-based: Miners subscribe to receive work from the pool.
  4. Low overhead: Designed for efficiency in high-frequency communication.
  5. Supports various mining-related methods: Such as submitting shares, requesting new work, etc.

Live example of pool data (Code Example 2): 

Below is an image that shows data coming directly from a mining pool

Miner Emulator - Pool Data
Miner Emulator – Pool Data
  • Our second code example acts as a proxy between your miner and public-pool. It connects to a live mining pool, receives and parses the data from the pool to make it readable, and constructs a block header based on this information. This provides a real-time view of what actual miners receive from pools. This lets you see exactly what the pool is sending out and exactly what your miner is working on.  This code requires you have a server that can run python.  Then, you will need to point your miners at the server.
  • Color-coded breakdown of received data: The emulator presents the received data in a color-coded format for easy understanding:

Interpreting the live pool data: By observing this live data, we can see:

  1. How frequently pools update work (usually every few seconds).
  2. Changes in the Merkle root as new transactions are added to the block template.
  3. Updates to the timestamp.
  4. Adjustments in difficulty target if the network difficulty changes.
  5. The specific nonce ranges assigned to our emulated miner.

This live demonstration illustrates the dynamic nature of mining pool communication. Miners must constantly receive updated work to ensure they’re mining on the most current block template, maximizing their chances of finding a valid block and receiving rewards.

Understanding this process is crucial for anyone involved in Bitcoin mining, whether using small-scale devices like Bitaxe or larger ASIC operations. It demonstrates the intricate dance between pools and miners that keeps the Bitcoin network secure and operational.

And, Finally – Mining Difficulty and Rewards:

Bitcoin’s mining difficulty is a dynamic parameter that adjusts approximately every two weeks (or 2016 blocks) to maintain a consistent average block time of 10 minutes. Here’s how it works:

  1. The network measures the time it took to mine the last 2016 blocks.
  2. If this time is less than two weeks, the difficulty increases.
  3. If it’s more than two weeks, the difficulty decreases.
  4. The adjustment is proportional to the difference in time, with a maximum change of 4x in either direction.

This system ensures that as more mining power joins the network, it doesn’t result in faster block creation. Instead, the network becomes more secure as it requires more computational power to mine blocks.

Block rewards and halving events

Block rewards are the primary incentive for miners to secure the Bitcoin network. Key points include:

  1. Initial reward: The first Bitcoin blocks provided a reward of 50 BTC.
  2. Halving events: Approximately every four years (or 210,000 blocks), the block reward is cut in half.
  3. Current reward: As of 2024, the block reward is 3.125 BTC.
  4. Limited supply: This system will continue until around 2140 when all 21 million bitcoins will have been mined.

Halving events are significant because they reduce the rate at which new bitcoins are created, contributing to Bitcoin’s deflationary nature.

Transaction fees as part of mining rewards

As block rewards decrease over time, transaction fees become an increasingly important part of miners’ income:

  1. Fee market: Users attach fees to their transactions to incentivize miners to include them in the next block.
  2. Variable amounts: Fees fluctuate based on network congestion and transaction priority.
  3. Block space competition: During high-activity periods, higher fees are necessary to ensure quick confirmation.
  4. Future sustainability: As block rewards approach zero, transaction fees are expected to become the primary income for miners.
  5. Economic balance: Fees must be high enough to incentivize mining but low enough to keep Bitcoin transactions economically viable.

As of September 2024, the Bitcoin mining difficulty is approximately 92.67 trillion. This number represents the difficulty target that a block hash must meet to be considered valid.

To understand this in practical terms:

  1. The difficulty target is a 256-bit number.
  2. To solve a block, miners must find a hash that is lower than this target.
  3. With the current difficulty, a valid hash must start with approximately 19-20 leading zeros when represented in hexadecimal.

For example, a recently solved block hash might look like this:

0000000000000000000275e3c8c3c7d0e6f535d5a515c5b3a2ddd12ff5g5h5i5

Notice the long string of zeros at the beginning. This is what makes finding a valid hash so computationally intensive. Miners must try billions of nonce values to find a hash that starts with this many zeros.

For perspective:

  • At difficulty 1 (the lowest possible), any hash would be valid.
  • At the current difficulty (Sept 2024), only about 1 in 92 trillion hashes will be valid.

This high difficulty ensures the security of the Bitcoin network, as it makes it extremely costly and time-consuming for any entity to attempt to manipulate the blockchain. For individual miners or those using devices like Bitaxe, this underscores the importance of joining mining pools to have a realistic chance of contributing to found blocks and earning rewards.

For small-scale miners using devices like Bitaxe helps understand these dynamics are crucial. The interplay between difficulty adjustments, block rewards, and transaction fees shapes the long-term sustainability and profitability of Bitcoin mining at all scales.

A Summary of How a Bitaxe Works:

So, that’s it!  It really isn’t that complicated.  A Quick summary:

  1. Your miner connects to a pool and gets the required information it needs to build a block header.
  2. It builds the block header using the information it was provided by the pool.
  3. It does two SHA-256 Hashes on the Block Header string.
  4. It compares the final hash result to the difficulty required to “solve” the block.
  5. Should your miner “solve” a block, it reports the findings to the pool.
  6. The pool then confirms the solution and propagates the data to the other nodes.
  7. You get a 3.125 BTC Reward for solving the block!

This Post Has 2 Comments

  1. Tim Rhoades

    How do I link my account to my Bitcoin wallet when the Bitcoin is found?

    1. Matt

      There will be a section in the setup guide that explains this, but you put your wallet address into the Bitaxe (Stratum User) and it pays to that address in the event of block found. 🙂

Leave a Reply