{'fraction_non_alphanumeric': 0.030945298297802015, 'fraction_numerical': 0.008593620889109237, 'mean_word_length': 4.477483593573207, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 2, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
Predicting the confirmation time of Bitcoin transactions

We study the probabilistic distribution of the confirmation time of Bitcoin transactions, conditional on the current memory pool (i.e., the queue of transactions awaiting confirmation). The results of this paper are particularly interesting for users that want to make a Bitcoin transaction during `heavy-traffic situations', when the transaction demand exceeds the block capacity. In such situations, Bitcoin users tend to bid up the transaction fees, in order to gain priority over other users that pay a lower fee. We argue that the time until a Bitcoin transaction is confirmed can be modelled as a particular stochastic fluid queueing process (to be precise: a Cram\'er-Lundberg process). We approximate the queueing process in two different ways. The first approach leads to a lower bound on the confirmation probability, which becomes increasingly tight as traffic decreases. The second approach relies on a diffusion approximation with a continuity correction, which becomes increasingly accurate as traffic intensifies. The accuracy of the approximations under different traffic loads are evaluated in a simulation study.


Introduction
Bitcoin is a virtual currency, in the sense that it can be used to transact or store value in a peer-to-peer network on the internet. The main innovation of Bitcoin is that it can operate without central authority, as opposed to traditional money accounts that are run by banks. The Bitcoin network has been running since 2009; which is when the 'genesis block' was mined by an unknown person who refers to himself as Satoshi Nakamoto. Since then the popularity of Bitcoin has increased substantially. What became painfully obvious during December 2017 -January 2018, when the price of Bitcoin reached new all-time highs, is that the network is not capable of dealing with all transactions for low fees when the traffic intensity on the blockchain increases too much. During this period, Bitcoin users were paying as much as 50 US dollar for a simple transaction. The reason that users were paying such hefty fees, is that the network was clogged, and transactions with a higher fee get priority. It is clear that from a user perspective, it would be useful to have precise estimates of the confirmation time during such circumstances. This is the problem that is addressed in this paper.
Let us consider in some more detail how the Bitcoin blockchain works. Bitcoin relies on a protocol called proof-of-work. This protocal is basically a voting mechanism that decides which transactions should be included in the blockchain, and it acts as a replacement of a trusted third party. A blockchain is a chain of blocks, each of which contains a bunch of transactions that are considered verified or confirmed. Newly found blocks can be linked to the last block in the blockchain (in principle blocks can also be linked to earlier blocks, but then they will not be accepted by other nodes as the longest chain is seen as valid). Computers with strong computational power are competing to solve a cryptographic puzzle as quickly as possible, in order to get the right to determine the next block. Computers that perform this task are called miners, and they receive mining rewards for being the first to mine a new block. The reference to mining comes from the fact that these miners have to search large outcome spaces, and they need to get lucky to find a block. In that sense it is somewhat comparable to e.g. gold mining, where a large area is searched and occasionally some gold is found. It should be noted that all this computational effort is spent purely as a voting procedure, in the sense that solving the puzzle allows one to submit a vote on what should be the next block (although the vote need not be accepted by the majority of other nodes, e.g. if it contains invalid transactions). Another, possibly more obvious, voting mechanism would be to randomly select a computer or IP address to propose the next block. The problem with this idea is twofold. Firstly, there should be some central party that determines who gets selected, which creates a single point of failure which is exactly what Bitcoin tries to avoid. Secondly, one can 'fake' having many computers or cheaply create many IP-addresses, whereas it is impossible to solve the cryptographic puzzles without doing the work. The above explanation should clarify the idea behind, and the name of, the proofof-work protocol.
In addition to the mining reward, the miner receives the transaction fees corresponding to all transactions in the block. When users want to make a Bitcoin transaction, they send the details of the transaction, along with a fee, to a node in the Bitcoin network. This node will spread the transaction to other nodes. When a transaction is known within the network, we say that it is inside the mempool (short for memory pool). Miners are free to put any transactions from the mempool they want into the new block, but they obviously have the incentive to put the transactions in the block with the highest fee density (i.e., highest fee per unit of transaction data, often stated in Satoshi per byte, where 'Satoshi' refers to 10 −8 Bitcoin). The size of a transaction depends on the number of incoming transactions (inputs) that are linked to outgoing addresses (outputs). This implies that the size of a transaction is not fixed, and hence the number of transactions that fit in a block varies.
The blocks that are added to the chain have a maximum size of 1 Megabyte (MB): this is hardcoded in the Bitcoin software and ensures that the network remains stable. The difficulty of the cryptographic puzzle is periodically adjusted in such a way that a block is mined on average every 10 minutes (assuming that the so called hash rate, i.e. computational power, of the network remains fixed). This leads to a transaction capacity of about 7 transactions per second (depending on the size of the transactions). The time until a block is found is approximately exponentially distributed [6], which can be reasoned as follows. Miners search a very large search space at random. Each trial is independent of the previous, and each trial has an equal probability of success. Therefore, the number of trials until success has a geometric distribution. Since the success probability is very small and each trial takes in principle equally long, the geometric distribution can be approximated very closely by its continuous counterpart: the exponential distribution. The miner who solves the puzzle first, will take a time that is the minimum of all exponential times of all miners, which is again exponentially distributed. However, with data ranging over long enough time-spans, the hypothesis that blocks arrive after an exponential time can be falsified [4]. This can be explained by the fact that the hash rate of the whole network typically changes significantly in between difficulty adjustments.
During times of congestion, a Bitcoin user that wants to make a transaction is interested in the relation between the fee and confirmation time characteristics. The most obvious characteristics are the expected or 'worst-case' confirmation times (which means that the transaction will be confirmed with, say, 95% probability at that time). These quantities can be easily derived from the confirmation time distribution, which is the focus in this paper.

Current literature and algorithms
In the Bitcoin Core 0.15 release there is a function called estimatesmartfee. The input to this function is the maximum number of blocks after which you want your transaction to be included, and the output is the estimated fee that achieves this with a 95% probability. The estimation is purely data driven. The procedure keeps track of the number of transactions in a particular fee density bucket that made it into into the blockchain after a given number of blocks. Exponential smoothing is applied (with smoothing factor 0.998), to give higher weight to more recent transactions. For more details, see [3]. This algorithm will provide a reasonable benchmark, but one may expect improvements if the current mempool is also taken into account. Moreover, a purely data-driven approach only extrapolates from past data and is therefore lagging behind if the environment changes quickly. A model-based approach will be more flexible in adjusting to current circumstances.
Alternatively, there is an estimator based on simulation, see [2] and [1]. This algorithm is model based, and assumes arrivals and batch services at Poisson epochs. The transaction size (in bytes) and transaction fee are sampled from a joint distribution based on historic blocks. This algorithm has been backtested on historical data, and appears to performs well. A disadvantage is that simulations tend to be time consuming. In our approach we try to apply mathematical analysis in order to gain more insight and to avoid computationally burdensome simulations.
The paper [6] provides an analytical probabilistic modeling approach for confirmation times, where the transaction process is seen as a M/M N /1 queue with priorities and preemption. The stationary time until confirmation is analyzed. This provides understanding of the inner working of the Bitcoin blockchain on a system level, but it does not uncover the dynamics from a user perspective. For example, due to stationarity assumptions, the paper does not take into account information such as the current mempool and it is ignored that transactions have different sizes. Our paper aims to include these features, as they play an important role for predicting confirmation times.

Our approach and contributions
There are two sources of uncertainty of when a transaction will be confirmed: future block arrivals and future transaction arrivals. Since the average number of transactions per block is of the order ∼ 2000, there will also be of the order 2000 arrivals per batch departure in heavy-traffic situations. On such a scale, the main source of randomness is the block arrival process. Therefore, it is natural to model the amount of data with a higher fee as a Cramér-Lundberg process; this is a process well known from insurance mathematics and introduced in Section 2 below. In such models, the process slopes upwards with a fixed rate and there are jumps down at Poisson epochs. Typically, in the literature, it is assumed that the jumps down are phase type (e.g. exponential or Erlang), in which case relatively explicit results can be obtained with regards to the time until confirmation. However, in the case of Bitcoin, the jumps will be of size at most 1 (MB), since that is the max capacity of a block. We assume that all blocks will be completely filled whenever possible, which coincides with the miner's best interests. Cramér-Lundberg models with deterministic jumps down did not receive much attention in the literature, as results tend to be much more involved. One can appeal to general results involving spectrally negative Lévy processes, of which our model is a special case, or expressions for the busy period in an M/D/1 queue starting in a level x (cf. [7] or [9]). In either case, those results involve a double Laplace transform with respect to initial workload level and time, of which the inversion is computationally involved and potentially numerically unstable. Therefore we aim to derive more explicit and simple results. Firstly, we derive a lower bound on the probability that the transaction will be confirmed within a specified number of blocks. This approximation turns out to be close to simulated values when the traffic is relatively low. However, in heavy-traffic situations, the lower bound is very loose. Therefore, we also develop a second approach, based on a 'corrected' diffusion approximation.
In the diffusion approximation approach, we replace the Cramér-Lundberg process by a Brownian motion with the same drift, variance and starting point. This considerably simplifies the analysis for the confirmation time, as it is known that the hitting time of a Brownian motion with a drift towards the boundary has an inverse Gaussian distribution. Subsequently, we note that the approximation can be improved substantially by doing a 'continuity correction'. This correction entails that the Brownian motion does not start in the same starting point as the Cramér-Lundberg process, but it is adjusted by the expected undershoot (i.e., the expectation of the value that process hits whenever it crosses zero from above for the first time). A computational procedure to calculate the expected undershoot is provided. Subsequently, the improvement as a result of the continuity correction is assessed by simulations.

Outline
In Section 2 we introduce our notation and the Cramér-Lundberg model, and we state the mathematical objective. In Section 3 we describe the main theory: in Section 3.1 we compute a lower bound to the probability of confirmation within a certain number of blocks. This bound is relatively tight as traffic is low, but its performance is poor in heavy traffic. Subsequently, in Section 3.2 we consider a diffusion approximation which is particularly suitable for heavy-traffic regimes, but also works remarkably well in moderate-traffic situations. It is described how the approximation is corrected using the expected undershoot. Finally, in Section 4, the relative performance of the (corrected) Brownian approximations and the (simulated) Cramér-Lundberg model is considered.

Model
Given a transaction with a particular fee, let X(t) denote the position of that transaction in the mempool at time t, if it is ordered by fee density. We suppose that X(t) satisfies a Cramér-Lundberg type of model, i.e.: where the process is scaled such that blocks have size 1 and the time is scaled such that the Poisson process P (t) has interarrival times of mean 1, x 0 is the initial position in the mempool upon entering, and c ≥ 0 is the rate at which transaction data with higher priority arrives. Once the process hits zero, it means that the transaction under consideration has been confirmed. Thus τ = inf{t ≥ 0 : X(t) = 0} means that the transaction has been confirmed after τ time units. The main mathematical objective in this paper is to recover the distribution of τ . To ensure that P(τ < ∞) = 1, we assume that E X(1) < 0. This is not restrictive, as users want to have their transactions confirmed with probability one at some point in the future, which is achieved by paying a sufficiently high fee.
A sample path of the X(·) process is shown in Figure 1, which is compared to a snapshot of true mempool data. Notice the similarity between how these two processes behave. It appears that the slope in the true mempool process is approximately constant in this time window, corresponding to our modeling assumption.

Mathematical results
In this section, we first derive a lower bound, which will be tight in light-traffic situations (as will be demonstrated in Section 4). Subsequently, we describe the diffusion approximation approach, which involves deriving an algorithm that can determine the expected overshoot of the Cramér-Lundberg model with deterministic jumps.

A lower bound
Let T 1 , T 2 , . . . be a set of i.i.d., exponentially distributed, random variables with unit mean, that represent the time until the next block is found. Define X i = X(T i ). Then it holds that X n+1 = X n + cT n − 1.
For now, we assume that there is no sticky boundary at zero: the process can become negative and positive again. This means that, in the model, the transaction could switch from confirmed to unconfirmed. Therefore the actual probability of confirmation will be larger than the probability that the X(·) process is negative, i.e. we find a lower bound. Consider the following proposition.
Proposition 1. Suppose that given a fee density φ, one can determine the rate c = c(φ) at which transactions with a fee density higher than φ arrive and one can observe the initial place in the mempool x 0 = x 0 (φ), which is ordered by fee density. Then the probability of confirmation in at most n blocks, is bounded by P(confirmation in ≤ n blocks) ≥ 1 − n−1 k=0 y k n k! e −yn , with y n := max{ n − x 0 c , 0}.
Proof. The sum of n independent exponentially distributed random variables is Erlang distributed. In particular, with y n (x) := n−x 0 +x c , it holds that Since X n ≤ 0 implies "confirmation in ≤ n blocks", it follows that This gives us a lower bound which can be calculated very efficiently. The simulations in Section 4 reveal that the bound is quite tight when traffic is light (say, c ≤ 0.5), but the bound becomes poor in heavy-traffic situations.

Diffusion approximation
To simplify the analysis, we could replace the Cramér-Lundberg process by a Brownian motion with a matching drift and variance. Due to our time and space scaling, it is easy to see that the variance of the Cramér-Lundberg process equals unity. It is well known that the hitting time of a Brownian motion with a drift towards a constant boundary has an inverse Gaussian distribution. In certain cases, however, this approximation will perform rather poorly. For instance, if the starting position x 0 = 0 and the slope c = 0, then the hitting time is simply the realization of the first exponential interarrival time of the Poisson process. However, due to its properties, the Brownian motion will immediately go below the 0 boundary with probability one. We can 'correct' for this, by noting that the undershoot of the Cramér-Lundberg process below level 0 will be of size 1 in this case, and by letting the Brownian motion start in level 1. For general c > 0, the expected undershoot can still be calculated via the theorem and algorithm stated below. The idea of 'correcting' a diffusion approximation of a random walk by changing the initial point (and the drift) of the approximating Brownian motion is not new, cf. e.g. [11]. We contribute to this line of research by calculating the expected overshoot explicitly for this particular Cramér-Lundberg model. In the following theorem and its proof, we write n x to denote x , i.e. the smallest integer greater than or equal to x. Theorem 1. The undershoot S x below level 0 of the Cramér-Lundberg process that starts in level x, with P (t) a Poisson process with rate 1, satisfies, for 0 ≤ x ≤ 1, and for x > 1, The proof of this theorem can be found after the algorithm below. Note that Algorithm 1 is ideally implemented in a programming language that supports symbolic mathematics, such as Mathematica.
Algorithm 1. Initialize: Set c and n max (comment: n max needs to be large enough so that E S nmax ≈ lim x→∞ E S x and the x in value of interest E S x satisfies x < n max ) Step 1: x c a n (comment: a n is a constant that is yet to be determined) Step 2: Determine a n • Set n = 1. While n ≤ n max − 1: Solve a n = f n+1 (n) for a n+1 and increment n ← n + 1 (comment: this step expresses a n into a n−1 , into a n−2 , . . ., and finally into a 0 ) • Set a nmax−1 = a nmax and solve for a 0 (comment: since each a n was expressed into a 0 , we have thus determined each a n ) Output: E S x is given by f nx (x) Proof of Theorem 1 and Algorithm 1. By the memorylessness property of the exponential distribution, we have for 0 ≤ x ≤ 1 so in particular With n x = x and using a similar argument as above, we have for n x − 1 < x ≤ n x , This finishes the proof of the proposition. The algorithm is a straightforward application of the proof.
Using a slightly different approach than Algorithm 1, it is even possible to derive exact error bounds on the expected undershoot after n iterations. This can be done by using the expression of E S n−1 in terms of E S n , for all n.
Example 1. Using the theory above in the special case c = 1, it can be recursively calculated that Since clearly 0 ≤ E S n ≤ 1, for every n, we know that the error is at most the prefactor of E S n+1 . Therefore, after four iterations, it follows that This corresponds to the value 0.500 ± 0.001 (where the value after ± indicates the standard error) that we found by simulation.
An implementation of Algorithm 1 in Mathematica leads to Figure 2, where c is varied ranging from c = 0 to c = 1. In the particular case c = 1 (which implies zero drift and is known as 'no safety loading' in the insurance literature), the limiting density of the undershoot can be explicitly calculated, as the initial position tends to infinity. Indeed, with Y the random variable corresponding to jump sizes, [10,Theorem 6] states that the limiting density of the undershoot in case of zero drift and finite variance jump sizes satisfies In [8] it is derived under the same assumptions that which in case deterministic jumps of unit size simplifies to which is indeed the value to which E S x appears to converge, for x large, in the plot of Figure  2 corresponding to the case of c = 1.

Simulation
In this section we compare the diffusion and corrected diffusion approximation to the simulated Cramér-Lundberg process, both in a heavy-traffic (c = 0.95) and a light-traffic (c = 0.25) regime. In most cases we suppose that the starting position is x = 1: depending on your preferences and the traffic, it is reasonable in practice to pick your fee such that your initial position in the queue is of the order of one block. By Algorithm 1 we determined that the correction in the Brownian motion is approximately E S 1 = 0.36403 when c = 0.95 and E S 1 = 0.57833 when c = 0.25. Consider Figure 3 for the results. It is quickly observed that the corrected diffusion approximation is generally significantly more accurate than the uncorrected diffusion approximation. Moreover, it appears that in the heavy-traffic situation the diffusion approximation is more accurate than in the light-traffic situation.
In the light-traffic situation we can resort to the lower bound algorithm, of which the bounds will be quite tight in light traffic. Due to the nature of Proposition 1, we have to compare the confirmation probability after n blocks (rather than confirmation probability after a time t). We report the results corresponding to the lower bound in Tables 1, 2 and 3. We considered three cases: c = 0.25, c = 0.50 and c = 0.75. In Tables 2 and 3 we chose a starting point x = 1, but in Table 1 we increased the starting point to x = 4 (with c = 0.25 and x = 1 most confirmations would simply be after two blocks). Note that the lower bound is indeed below the simulated values, or above it within a standard deviation. In addition, it can be seen that the lower bound becomes increasingly loose as c increases. With practical applications in mind, we could say that the lower bounds are tight enough if and only if c ≤ 0.5, especially when one is interested in confirmation probabilities within the 90% to 100% range.

Further research and concluding remarks
There are several ways to continue this research, most notably in the following two ways: • In this research we assumed the existence of a single 'true' mempool, but in fact each node keeps track of its own mempool. The mempools are continuously updated with each other, but in reality there is some lag before new transactions spread through the entire network. Therefore it can happen that a miner finds a block while being unaware of some of the most recent transactions, implying that they will not be included in the block even though their fees may be sufficient. This effect is hard to model and arguably quite small, and therefore we ignored it. The model should be backtested on data to find out about the practical applicability. Fortunately, transaction data and mempool data is publicly available: it can be collected by setting up a Bitcoin node. • It would be interesting to solidify the mathematical fundementals of this paper by proving the following conjecture: As the traffic (c ↑ 1) and time are scaled appropriately, the Cramér-Lundberg process with deterministic jumps of fixed size, converges to a Brownian motion. As a result, the hitting time of the Cramér-Lundberg process converges to an inverse Gaussian distribution.