Finding the optimal solution for handling fees for DeFi farmers, Xinghuo Mining Pool talks about the design principle of GasNow
橙皮书
2020-09-18 07:50
本文约4244字,阅读全文需要约17分钟
How to save gas to the greatest extent while mining?

Editor's Note: This article comes fromOrange Book (ID: chengpishu), reprinted by Odaily with authorization.

Editor's Note: This article comes from

Orange Book (ID: chengpishu)

Orange Book (ID: chengpishu)

, reprinted by Odaily with authorization.

The popularity of DeFi mining continues to this day. As the most important position of DeFi, the throughput of Ethereum has once again become a bottleneck. The most important performance is that the Gas Price of Ethereum continues to hit new highs. From the original 40-50 Gwei, 400-500 Gwei when it soared to the highest.

Gas is essentially an auction mechanism. The block space is limited. When the number of transactions is too large, miners will give priority to packaging transactions with higher fees. Behind the ultra-high yield of liquidity mining, every farmer is racing against time to dig and sell. DeFi players have become extremely sensitive to the speed requirements for transaction packaging and on-chain.

If you want to complete the transaction faster, you need to pay a higher Gas price. So how much Gas Price is appropriate? Generally, people in the industry are used to checking gas fees through etherscan or eth gas station, but what many people don’t know is that these data actually have a certain lag and are not necessarily accurate.

A product that Orange Book has come into contact with recently is called GasNow, which is an experimental small product of the Spark Mining Pool team for ordinary users. It hopes to provide real-time Gas prices for DeFi farmers, so that traders can find the most cost-effective fee pricing. Based on the internal data of the Spark Pool, GasNow tries to obtain a real-time and more accurate Gas price through the pending transaction queue, which is obviously different from the calculation method based on historical data on the chain.

For this article, Orange Book found Uncle Miao, the product manager of SparkPool, and chatted about the product design of GasNow. The following is the text of the interview.

Orange Book: How was the GasNow project initiated in the first place?

Uncle Meow: At the beginning, we also checked the gas price on etherscan or gas station, but later found that their data was not very accurate. Many times the gas price displayed on it was very high, but we found that the gas price on the spark mining pool may be lower The transaction has been packaged. So we thought, can we make a more accurate data display through the data of the mining pool. Originally purely to address my own needs. Later, I found that it would be good to open it up to ordinary users, so I made the current GasNow, which is a minimalist tool.

At this stage, because DeFi liquidity mining is very popular, if you look at the historical data of Gas prices, it is actually much higher than the previous ICO stage. During the ICO period, the gas price also rose slightly, but not as sharply as it is now. Of course, the Gas Limit has always been close to full capacity. In other words, Ethereum has always been relatively congested, but at this stage, people have higher requirements for speed and more demand for "queue jumping" while congested. This is where it is different from before.

Orange Book: GasNow is the Gas price calculated based on the pending transaction queue of Spark Mining Pool. In contrast, why are the data of other countries not so accurate?

Uncle Meow: Generally, there are two ways to calculate the gas price. One is to estimate the current gas fee based on the data on the chain, such as the usage of Gas Limit and Gas Price in the past 100 blocks, and make a model based on historical data. speculate. Another method is to use the transaction queue currently being packaged to see the gas price of each transaction, and then sort to find the median, average, etc. in it to get a more suitable data.

The second approach is to use data closer to the current moment. It is more real-time. For many Dex traders, the speed is very high. They are very sensitive to whether they can package the transaction in the first time. GasNow hopes to provide them with a more accurate Gas price reference for these users.

Spark Mining Pool itself has accumulated data in this area, so we don’t need to do secondary development, and we can finish GasNow very quickly. Of course, on the other hand, the GasNow product is naturally suitable for mining pools, because the business model of the mining pool itself is relatively simple, which is to collect transactions from the entire network as quickly as possible, and package these transactions into blocks faster .

The responsibility of the mining pool is to protect the security of the entire network, attract more people to come in to mine, and just do the water delivery service to earn money with peace of mind. Therefore, the mining pool is willing to open up the data of this part of the transaction, and there is no need to cover it up, and it has no impact on the business model. So in the end, it is very justifiable to open a product like GasNow based on the mining pool.

Orange Book: Is there any difference between this method and running a node by myself, and then traversing to obtain the packaged transactions in the Mempool of each node through the Ethereum network protocol?

Uncle Meow: If you run a node by yourself, for example, if the node is set in Hangzhou, then because Ethereum is a global network, the transactions you can get first may be in Hangzhou, then in China, and finally in foreign regions. Due to network delays in foreign regions, some transaction data may be delayed. In the end, the data you have may only be partially accurate, which will affect the accuracy and real-time performance of your final calculation of Gas prices.

The business model of the mining pool determines that it naturally needs to get all the transaction data to be processed in the entire network faster and more comprehensively, so it will be more accurate and faster to rely on the data of the mining pool, and at the same time, it will save effort in development .

Orange Book: Why can the mining pool get the transactions of the whole network faster than my single node? What aspects of optimization has it done?

Uncle Meow: In fact, this is a very simple cost issue: see if you can set up enough nodes. In order to get the transaction data of the whole network faster, the mining pool will set up different nodes in many places around the world, and the speed will be faster. In contrast, a single node is definitely not comparable. The advantage of a mining pool is that it can afford the cost of setting up these nodes.

Orange Book: So how many nodes do you have in the world now? Are the nodes cloud-based or physical?

Uncle Meow: This data should not be disclosed right now. In terms of node types, it can only be said that there will be various types. The matter of how many nodes to set up mainly depends on the cost performance. It is not only related to geographical location, but also related to the frequency of transactions sent in different regions. Assuming an extreme situation, if there is an Ethereum node in the North Pole, then it is impossible for you to set up a dedicated server in the North Pole for monitoring, and this North Pole node may only send a transaction in a few days, and the frequency is very low, then it may be Trade-offs will be made accordingly. On the contrary, other regions may have very intensive transactions, so more node monitoring needs to be deployed there.

Orange Book: GasNow’s product design is very minimal, and there are only four numbers on it (extreme speed, high speed, average, slow). How can ordinary users use it?

Uncle Meow: First of all, you need to understand that the upper limit of the Gas Limit for each block is 12.5 million. Different types of transactions require different amounts of gas. Common ETH transfers require 21,000 Gas, and complex contract transactions may require several million. Gas, so the number of transactions actually packaged in each block varies, ranging from dozens or even a few transactions at a minimum to more than 600 transactions at a maximum (12.5 million/21,000).

The calculation method of GasNow, the first step is to list all 2000 transactions in the queue to be packaged (tx1, tx2, tx3, tx4, ... txn ... tx2000), and then arrange them according to the Gas price from high to low. The N transactions (tx1, tx2, tx3, tx4...txn) that can be packaged in the next block, note that N here is uncertain.

On this basis, we calculated these four numbers, and their meanings are as follows: "Extreme Speed" mode represents the Gas price of the median transaction (tx1, tx2, tx3, tx4...txn), "High Speed" is the gas price of txn. "Normal" is the Gas price of the max(tx2n,500) transaction, and "Slow" is the Gas price of the max(tx5n,1000) transaction. If the next block can pack 300 transactions, that is, n=300, then "normal" means the gas price of the 600th transaction, and "slow" means the gas price of the 1500th transaction.

In fact, it is more minimalist. I think it may be enough to only put the first two numbers (extreme speed, high speed).

Orange Book: As long as the gas price I give is the same as the second number (high-speed mode, that is, the gas price of txn), it will definitely be included in the current block?

Uncle Meow: There are actually many possibilities, because it involves the issue of Gas Limit. For example, the Gas price you give is the same as the last transaction in the block currently being packaged. If the transaction is packaged and just uses up the Gas Limit of this block, then you have to move to the next block.

At the second block, if someone offers a higher Gas price at this time, it will be in front of you again. You can't pack it up immediately. So why doesn't GasNow make predictions based on historical data? Because predicting the order in which transactions are packaged is really, really hard. We still focus on the data at this moment and focus on solving real-time problems.

Orange Book: In addition to the four figures, there is also a chart of Pending Transactions on GasNow, can you explain the meaning of this chart?

Uncle Meow: The horizontal axis of this graph represents the gas price of the transaction, and the vertical axis represents the number of transactions greater than or equal to the gas price. So pending transactions actually represent a global information, including the gas price information of all pending transactions. The four numbers we selected are just four points in this global information coordinate.

Orange Book: GasNow is a small product, how do you think about the business model in the future?

Uncle Meow: Currently GasNow is free and open to all users. Wallets like imToken, MYKEY, MathWallet, and TokenPocket are also supported. At present, our server can still handle it. If the data request pressure is too high in the future, we may consider charging. GasNow's webpage is now automatically refreshed every 8 seconds, which is also based on the cost-effectiveness of the free model. If we switch to the websocket long link method, the server can directly push real-time data to the front-end page, but our overhead will be higher.

In terms of business model, GasNow cannot interfere with user operations, so it is difficult to charge. For different users, when sending a transaction, it is difficult to quantify a fixed value by referring to the Gas price given by our product. I don't think it's easy to charge. So it's free mode for now. What is the possibility behind it, I don't know for the time being.

Orange Book: Feels a bit like etherscan? They don't seem to have a business model, they just hang some advertisements on the page.

Uncle Meow: Well, it’s really not easy to charge for this kind of basic data service. In contrast, infura is easier to charge, and it does not need to charge ordinary users, and directly earns money from corporate customers, which is easier to price.

Orange Book: What's next for GasNow?

Uncle Meow: It should continue to maintain a relatively minimal product form. The core is to provide these four data, so the product you see now may be 90% complete, and the remaining 10% is how to make these four data smoother and more accurate, but the big aspects will not change up.

橙皮书
作者文库