Mining efficiency and latency effects

Nicolas Paugam
Sesterce
Published in
8 min readJun 6, 2022

Decentralized networks are based on multiple computing nodes, rather than depending on a single server to handle all the workloads. In contrast to a centralized network, a decentralized system offers several advantages, such as increased reliability, scale, and privacy. This means that the network is decentralized so there is not a single point of failure, which is the result of the fact that users don’t have to rely on a centralized server for all processes. Additionally, decentralized networks are much easier to scale, because the network can be expanded by simply adding more machines. As well, this architecture provides greater privacy, since information is not routed through one point but rather through a multitude of points. Peer-to-peer (P2P) networks are a decentralized network based on peers sharing information and resources. A group of nodes act as a peer for each other, storing and sharing files collectively. Using a common protocol, they are working together to create a network capable of transferring any kind of data. This allows the members to exchange information without having to go through an intermediary. In order to accomplish this, P2P networks rely on protocols called application protocols (Layer 7 in OSI model) on top of the Internet protocol suite (TCP/IP). P2P networks operate in a relatively straightforward manner. Basically, what is done is to build a protocol so that nodes can communicate with each other directly and without intermediate. Figure 1 presents an example of P2P networks. In this model, each device can function independently, and decisions will be taken by consensus.

Fig.1. A peer-to-peer network.

On the other hand, on a cryptocurrency’s network, devices should be able to send transactions and suggest new blocks. Therefore, we would need a P2P network that allows nodes to communicate with one another.

I. P2P in Blockchain

P2P networks maintain blockchains as decentralized data ledgers. The blockchain is a protocol for recording transactions between the network peers, who adopt the consensus protocol in order to ensure those transactions are recorded. The consensus system for Bitcoin, is known as Proof-of-Work (PoW). Miners are nodes that compete to solve a difficult cryptographic challenge using a brute force search technique. The first miner to find a solution that contains all of the pending transactions in a block is rewarded with newly created crypto-coins. Miners are compensated by these rewards as a result of the operational cost mainly resulting from the consumption of electricity. A miner is awarded proportionally to how much it contributes in terms of computational effort in the protocol. Whenever the P2P network grows, the mining power owned by one miner shrinks, reducing the chances of repeating the gains. Because of that, miners are exposed to increasing operating costs, which has caused them to join forces and form mining pools [1]. A mining pool’s internal networks are typically client-server. For a mining pool to manage its miners, it uses dedicated servers. In order to mine, miners must be connected to pool servers that assign them jobs and notify them of new blocks. An discovered block is transmitted to the entire network once it has been discovered by a miner. Miner block reception latency is the time elapsed between the discovery of a block and its reception by the miner. Figure 2 shows a PoW-based blockchain operation.

Fig.2. PoW-based blockchain operation: (1) miners receive transactions from users and other miners, (2) candidate blocks are mined running consensus, (3) mined blocks are propagated, (4) miners append candidate blocks to their ledger copy (forks may occur, leading to inconsistencies) [2].

II. Mining of blocks

The blockchain consists of blocks, which are composed of a header and the list of transactions. In addition to the time and date of creating the block, it usually includes the block height (inside the blockchain), the hash of the block, and the hash of the previous block. In order to obtain a block’s hash, a large character string is created by concatenating the headers and transactions, and a hash function is applied to the message. Data of arbitrary size can be mapped to fixed-size values with a hash function. Applications using blockchain hash functions must be cryptographic, one-way and deterministic. A message with any given hash value must be nearly impossible to generate or to locate two messages with the same hash value. If only a tiny change is made in the message, the hash value can change dramatically. The new hash seems unrelated to the previous one [3]. This can be seen in applications such as bitcoin, where messages are turned into hashes of 256 bits using the SHA-256 function (See https://emn178.github.io/online-tools/sha256.html). For instance the hash of the title of this blog is

2b564f13ebff5b5779248a7eb13ba7462eb5f06bc6398b250982d633f7d0631e

By mining a block, one finds a hash value for a block that is lower than some target, a task that can only be performed by brute force due to the properties of cryptographic hash functions. Prior to applying the hash function to the block message, a nonce is appended to the block message in order to search for an appropriate hash value. Miner’s draw random 32-bit numbers until a value is found for a nonce that effectively results in a correct block hash.

Fig.3. A mined block with a hash value having on leading zero.

III. Orphan and Stale blocks

When two miners are solving the PoW puzzle at the same time on a blockchain, there can be unintentional forks when these miners try to tell the rest of the network they’ve won a block. This process of communication (propagation) does not happen instantly, due to latency. As an example, let’s consider we have a fork when miner A and miner B find a valid (n+1)th block of the network as follow:

Fig.4. Orphan and Stale block.

Under this scenario, each miner will broadcast his “winning” block to their nearest neighbors, who will then repeat the process. When the entire chain is aware of both # (n+1) and # (n+1)’, nodes will link the block # n as a reference/parent and keep the block they saw first at the head (# (n+1) or # (n+1)’). Let’s assume that a miner with # (n+1) as its heading block mines the next block # (n+2). This generates a longer chain for Miner B and as a result the entire network will follow the longest chain and cutt off the fork for # (n+1)’ which will be without a parent and be called an orphan block. Moreover, the orphan’s offspring block also is not included in the blockchain and marked as a stale block. The important note is that miners will not receive reward for stale blocks and it reduces the efficiency of mining.

IV. Mining efficiency

The mining efficiency is calculated by dividing the number of accepted shares and rejected shares, i.e.,

Mining Efficiency =accepted/(accepted+rejected) .

Generally, shares get rejected for two reasons:

A. When you are experiencing internet issues or when a pool or mining client is not processing the share as quickly as it should, then the share will be stale. This is usually fixed by decreasing the latency between the pool and your rig.

B. Shares can be rejected if their clients have compatibility issues or if there are issues with their hardware or overclocking settings.

V. Latency effect in the mining process

The term network latency, also known as lag, is used to describe communication delays over the network. A packet of data taking time to capture, transmit, process through multiple devices, then receive at its destination and decoded would be considered latency in networking. Low-latency networks have short transmission delays (desirable), while high-latency networks have longer transmission delays (undesirable).

In the mining process, TCP/IP connections to the pool expose us to the software that controls the pool, which may behave differently than the lower-level components of the operating system that handle Internet Control Message Protocol responses. What we are discussing in this article is propagation delay which is different from latencies caused by queuing delay in transaction submission or block generation delay. A large part of the latency can be attributed to the distance between the mining rig and the mining pool from which you request work [3–4].

There are some tools to check the latency between the mining pool and your rig such as:

Having a large latency can increase the number of orphan/stale blocks for a miner and leads to low efficiency. To illustrate the subject, let’s have a stratum ping latency comparison between different pools. Using some ping tools one can often evaluate the performance of various mining pools. Thus, it is preferable to measure the response time from the pool due to the possibility that they could be busy or using geolocation-based forwarding, positioning the connecting endpoint closer to the user. For a particular pool, servers are generally located all over the globe. Instead of using the general URL, one should use the location-specific URL for a better connection and lower latency. As an example, let’s consider Slush Pool. From our location in Marseille, France, we realized latency results from different stratum servers of Sluch Pool as follows. Please note that the pool latency determines how quickly you can send and receive hashes. It is worth mentioning that if your ping is less than 100ms, you have a good ping.

The result shows that considering our location, the Europe server of Slush Pool has the lowest latency compared to its other servers located all around the world. It is possible to obtain the same table for other pools such as binance pool, Hiveon pool, etc. .

VI. Conclusion

Mining is the process of solving many hashes as fast as possible. Adding any latency will have a negative effect on this fast process. This means that, in the mining process, high latency leads to a share not reaching the job deadline, being rejected, and as a result, not being paid for. Crypto miners need to pay attention to latency because it can impact their revenue. Some solutions can be considered to improve the latency such as moving the mining farm as close as possible to the pool’s location, or choosing the pool nearest the mining farm. Also, more bandwidth can be useful to reduce latency as more data packets can travel over a wider pipeline, thereby reducing the possibility of packets getting delayed.

References:

1- H Albrecher, D Finger, PO Goffard, “Blockchain mining in pools: Analyzing the trade-off between profitability and ruin”; Insurance: In 2022 Mathematics and Economics, Elsevier,1–34.

2- Wilhelmi, Francesc and Barrachina-Muoz, Sergio and Dini, Paolo, “End-to-End Latency Analysis and Optimal Block Size of Proof-of-Work Blockchain Applications”; arXiv preprint arXiv:2202.01497, 2022, 1–4.

3- Christian Decker and Roger Wattenhofer, “Information propagation in the bitcoin network”; In IEEE P2P 2013 Proceedings, IEEE, 1–10.

4- Ryunosuke Nagayama, Ryohei Banno, and Kazuyuki Shudo, “Identifying impacts of protocol and internet development on the bitcoin network”; In 2020 IEEE Symposium on Computers and Communications (ISCC), IEEE, 1–6.

5- Tong Cao, Jérémie Decouchant, Jiangshan Yu, and Paulo Esteves-Verissimo, “Characterizing the Impact of Network Delay on Bitcoin Mining”; In 2021 40th International Symposium on Reliable Distributed Systems (SRDS), IEEE, 109–119.

Useful links:

  • Average Transactions Per Block:

https://www.blockchain.com/charts/n-transactions-per-block

  • Bitcoin Average Transaction Fee:

https://ycharts.com/indicators/bitcoin_average_transaction_fee

  • Bitnodes network snapshot:

https://bitnodes.earn.com/nodes/

  • Cryptocurrency Market Capitalization:

https://coinmarketcap.com/

  • Global Ping Statistics:

https://wondernetwork.com/pings

  • FIBRE:

https://bitcoinfibre.org/

--

--