Skip to main content

How does bitcoin work?

Nowadays only lazy person probably hasn't heard about Bitcoin. Some people have heard about it, but very few have wondered how it works inside it. Many are satisfied with the knowledge, which is enough to start a wallet, get and send cryptocurrency to another one or sell it. It works - that's fine, but how exactly - it doesn't matter. Nevertheless, it is necessary to know, because this information can remove a lot of questions and avoid problems with usage.

Network

As many sources tell us, Bitcoin is a peer-to-peer payment system (network) whose unit of account is the cryptocurrency of the same name.

A peer-to-peer network is a computer network, which is based on the principle of equality of all its participants. Each node (peer), or node as they are also known, acts as both a client and a server. This organization allows the network to remain functional with any number and any combination of available nodes (the sum does not change when rearranging the places of the sums). All peers are participants in the network, so the main feature of the system is complete decentralization: there is no central administrator or server. Instead of the term «peer-to-peer» one can use definitions such as: decentralized, peer-to-peer or p2p (peer-to-peer) network.

Blockchain

The basis of bitcoin, and incidentally also its transaction ledger, is an ordered sequence (chain) of data sets (blocks), or simply: blockchain. Each block of the bitcoin network holds up to 1 MB of data, takes an average of 10 minutes to form, contains information about all the transactions placed in it and information that links it to the previous block.

Each block in the chain is cryptographically linked to the previous and the next. This interconnection protects the network from future substitution or modification of existing blocks, making the blockchain immutable and the transactions irreversible.

The blockchain is not a single block, but a single block, and the transactions are irreversible.

Principle of operation

For a better understanding of how the bitcoin network works, let's imagine a hypothetical crypto-enthusiast, Tony, who has a bitcoin wallet with 2 BTC in his balance. We have already discussed what a bitcoin wallet is in our previous articles. What is a bitcoin wallet?

Our Tony wants to give 1 BTC to his friend Cindy, and in order to do that he needs her unique bitcoin wallet address (analogous to an account number in a traditional bank). Tony enters this address into the appropriate entry field of his wallet, and in the other field he specifies the amount of the transfer - 1 BTC. Then Tony moves on to setting the amount of commission for the transaction, here we will stop in a little more detail.

Transactions and network load

In bitcoin, as with any other payment system, transactions occur, that is, assets move from one customer to another. Bitcoin transactions are subject to a commission which is rewarded to the miners who confirm those transactions. The higher the fee and the lower the network load, the faster the transactions are confirmed.

The network load refers to the aggregate number of participants sending their transfers at the same time.

Basically, a transaction is a set of information that tells the network's participants by how much the sender's balance has decreased, and by how much the recipient's balance has increased.

Miners

For a transaction to be successful, it must be confirmed (validated) by a Miner. Now, these are specialized organizations that use powerful computing equipment (ASIC-farms) to check transactions for &lquo;correctness» collect these transactions into blocks, and the blocks are sequentially attached to each other. It takes the network algorithm an average of 10 minutes to generate 1 block, during which the miners perform the same type of computational work every second in search of the one and only correct solution. It's not hard, it's not a math problem, but it's a very large amount of work that's hard to do with a small amount of processing power, quickly and efficiently.

Miners are rewarded for their work in the form of BTCs. This reward consists of the commissions which users paid for the transactions and brand new bitcoins, which are generated by the network itself at the moment when a new block is collected and validated from the transactions. The new bitcoins are a reward for the miners for their work. Every 210,000 blocks, the reward for miners for a found block is halved, this is called halving.

commissions

Let's go back to our crypto-enthusiast… By setting the amount of commission per transaction, Tony is guided by the fact that for every byte of information he has to pay a certain amount of satoshi - a fractional fraction of a bitcoin. Since Tony doesn't know how much data his transaction will take, he decides to save money and set the price at 1 satoshi per byte.

For you readers, we'll tell you how the weight and cost of Tony's transaction is generated. Those 2 BTC he has on his balance appeared in his wallet for a reason. Tony earned them. 1 BTC in 2017, 1 BTC in 2018. Now he wants to send half of it to his girlfriend. His transaction, in addition to information about the number of coins, will include information about the addresses from which the coins came to him (called inputs), information about the recipients' addresses (called outputs), and information about his own address.

- Each input from which coins were received weighs ~148 bytes

- Each output to which the coins go is ~34 bytes

- The transaction itself weighs ~10 bytes, regardless of the number of addresses or transfer amount.

Calculating: 148*2+34*2+10=374 bytes. Now we know that our «greedy» Tony will pay 374 satoshi for the transaction.

Surrender

You might ask, why do we multiply 34 (recipient address weight) by 2 when there is only one recipient? The thing is that when you send part of your balance to someone, not a part but the whole amount goes from your balance, and after validation, that is including the transaction in the block, the balance (minus the network commission) goes back to your wallet. Therefore, in addition to the information about the recipient's address, the transaction also includes information about the sender's address, that is, your address. This return is called surrender.

Mempool

Putting up a paltry commission of 374 satoshi, Tony confirms sending 1 BTC and waits for the miners to confirm this transaction.

The only thing is that the miners don't rush to confirm it, the transaction ends up in the mempool - the confirmation queue book. Why? Because miners want to make money, not just operate their equipment, because they will only get 374 satoshi for confirming Tony's transaction. Especially for such very cheap transactions the mempool with its sorting system exists.

Miners primarily «take easier transactions from mempool with higher commissions, because it is more profitable to confirm them and there is more space in the block.

In fact, if the sender uses SegWit technology, their outbound transactions weigh less than normal transactions, which also attracts miners.

But don't think that once a transaction reaches a mempool, it gets a sequential number. No. The queue is dynamic, and every second there are multiple transactions with different fees and weights, so our Tony's transaction can take a long time to confirm. And most importantly, while it's in the mempool, Tony can't dispose of the change.

Factually, in such a situation, the sender's balances are sort of «frozen». This mechanism protects the network from spam transactions-something where a spammer generates a lot of cheap payloads and overloads the network.

As long as Tony's transaction is in the mempool, it is not considered approved, and it is not considered hung. At the same time, it can stay in the queue for quite a long time - until it's confirmed, or until it's deleted by the validating nodes from the mempool. Statistically, the maximum queue waiting time is ~3 days, but at times of high network activity, it can last for a week or longer.

You'll agree that the speed of transfers these days is one of the priority features when it comes to using payment systems, and queues like this are not very pleasant, to say the least.

There are many ways to push a transaction through a meme. All of them are quite complicated to understand and implement for the average user, and some of them border on such a fraudulent way as «double-spending» (re-spending). Nevertheless, there is one great feature that anyone can use, so let's talk about it. It is called «Replace-by-Fee (RBF).

Replace-by-fee (RBF)

Not every bitcoin wallet at the moment, much less a mobile one, has such advanced functionality.

RBF is about editing an existing transaction that is in a mempool.

Edit means that the new transaction will use the same inputs as the old transaction, but the commission will be changed. Such an edited transaction will not be considered «double-spending» as using the Replace-by-Fee option will avoid this. The bitcoin network nodes treat the edited transaction as an old transaction, and it will be moved in the mempool queue to more attractive positions for miners.

So if the commission is too low, increasing it is a normal practice if you want to speed up the transaction. Don't disregard RBF and enable it before making a transaction, this can be a hedge in case the transfer is delayed in the queue.

Confirmation

Tony realized in time that his greed could cause Cindy not to receive the gift at all, so he used the RBF feature in time to increase the commission. The transaction, as expected, became more attractive to the miners, and they included it in the next block - the transaction received 1 confirmation. With each subsequent block found, this transaction will receive 1 additional confirmation. When there are 6 or more such confirmations, the transaction is considered confirmed.

Transaction speed

When we talk about transaction speed, we should understand that there is no clear value. But let's calculate it based on Tony's transaction and the data we have.

Condition:

  • size per block ~1 MB (1’048’576 bytes);

each block filled with transactions is generated every ~10 minutes (600 seconds);

  • our Tony's transaction has a weight of 374 bytes;

Decision:

  • 1’048’576 bytes : 374 bytes = 2803.6 transactions in one ten-minute block.
  • 2803.6 transactions : 600 seconds = 4.6 transactions per second.

An answer: Every second, miners confirm ~5 transactions similar to Tony's transaction.

Of course, these are all approximate values, as the processing rate varies every second and depends on many factors. The main thing is to have your transaction taken from the mempool as soon as possible, and if that happens, your transfer will reach the recipient within 1-600 seconds. The main thing is to have your transaction taken from the mempool as soon as possible, and if that happens, your transfer will reach the recipient within 1-600 seconds.

Factually, once a transaction is included in a block, the recipient can not only see the funds in their balance, but also under certain conditions dispose of them. Quick, isn't it?

Yes, but what about the 6 confirmations rule? Six blocks, 10 minutes each, for a total of 1 hour.

Bitcoin clients

It's all about the software that cryptocurrency holders use. Classic Bitcoin wallets will display the transaction as «unconfirmed» until it receives six confirmations (blocks).

Services that accept BTC as payment can put their own limits on the number of blocks needed for confirmation (7, 10, 45, 214 …).

BTCs, which are generated by the network as a reward for finding a block, can only be used after 100 confirmations, but classic bitcoin wallets will not display coins received for finding a block until 120 confirmations have been received.

The number «6» was not chosen by chance. With each new block, the transaction becomes less vulnerable to being tampered with or changed. To do something with an already confirmed transaction in a block, one would have to «rewrite» all subsequent blocks, and that requires very huge computing power and millions of dollars of investment. And the more confirmations the transaction receives, the more secure it will be.

But in a blockchain as powerful and resilient as bitcoin, it's more a requirement of the recipient of the transaction, not a rule of the protocol.

That's why our Cindy and Tony don't use the classic bitcoin wallet, but a very advanced and functional one. Because of the feature of using unconfirmed transactions that is activated in it, Tony's outgoing transaction will immediately appear in Cindy's wallet when it is included in the block. In doing so, Tony will be able to dispose of his change immediately, and Cindy will be able to dispose of the gift she received.

Switching «SegWit + RBF + use of unconfirmed transactions» allows us to squeeze the maximum speed out of the BTC blockchain, which is important for non-custodian services.

Ahead of you asking what kind of bitcoin wallet Tony and Cindy are using, let's answer right away: Trustee Wallet. With this wallet, RBF is a bitcoin wallet, and it's a bitcoin wallet.

Conclusion

Bitcoin is very complex and very technological. It's impossible to describe all the intricacies and nuances of its work in one article, but we did tell you about its basics. Now you know what complicated journeys your coins make within just one single transaction between two wallets, and at what speed. How and how the network protects itself from hacks, spam attacks, scams, or rash rookie behavior.

Sustainability of bitcoin depends on miners and users alike, and the more participants there are in the network, the more secure and decentralized it becomes.

blog.trusteeglobal.com

Comments

Popular posts from this blog

Promising cryptocurrencies for investment in 2021

The cryptocurrency market has shown significant growth over the past year. Bitcoin rate increased by more than 700%, up to $68,000, although now the rate has fallen to $55,000. Ethereum rose in price by almost 1200%, now the altcoin costs $2500. Most of the leading coins by capitalization showed similar dynamics, but not all of them. Among them, there are some that rose in price insignificantly over the past 12 months. Let's break down the promising cryptocurrencies in 2021 for investing.