The algorithm of “matching coins” Bitcoin blockchain will soon receive an important update. Code, deciding which data to participate in the formation transactions will be optimized to reduce fees for remittances.

“Algorithm of the coins in Bitcoin Core, in fact, you need to seriously refined, especially in relation to transactional commissions. It is inefficient and to calculate the required number of charges it creates a weird cycle,” said one of the developers of Bitcoin Core Andrew Chow (Andrew Chow).

Agrees with him and mark Erhardt, an engineer of the client for the cryptocurrency wallet BitGo. In a recent interview podcast Noded, he called the algorithm “too confusing”; Erhardt was also the first to create part solutions for the optimization of the selection of coins about two years ago.

Based on the proposals of the engineer the project was created, a new algorithm, “BnB” — “branch and bound” (eng. “branch and link”). It modelirovanii code effectively assembles the data, while not causing damage to the scale and reducing the transaction fees.

The principle of its operation is quite simple. Primary root algorithm of the coins, by default, creates and registers in the data transaction outputs to “surrender”. So, when sending 0.2 BTC program can decide to take part of the data constituting 0.3 BTC and send them to two choices: the amount and the recipient’s balance for the sender. The algorithm can also create a few “spare” outputs (UTXO) for the section of the transaction between them, while using them only partially.

BnB, on the other hand, tries to eliminate as many options as possible so that there was no need to send the rest back. In short, he carefully analyzes the input transaction data, selecting data for an exact match with the required amount.

According to Andrew Chow, the introduction of BnB is beneficial to both developers and users:

“This will reduce the number of UTXO. In addition, transactions exact coin base and the desired amount will be less than those in which there is an opportunity, which means that users will save on fees and the unit will be more space to place other transaction.”

The results of the tests in simulation show that the new algorithm is able to deliver ~40% of transactions from unnecessary data. The developers do not plan to stop there: according to Chow, the algorithm will add “simple random capture”.

Extra data in the block with a large volume of transactions greatly slow down their speed. Together with the high charges, this led to the fact that BTC has lost its popularity in some markets — for example, in darkwave.