<p>That whole vector is to keep track of how many blocks have passed since a transaction entered the mempool and what feerate it is. So it allows the estimator to look up how many transactions have been in the mempool for Y blocks at a feerate of X. This allows it to see what feerate is probably needed in order for a transaction to be confirmed in Y blocks.</p>

<p>If you just had the number of transactions at each feerate, that only tells you the feerate distribution of unconfirmed transactions. This is not helpful for estimating how many blocks will pass before a transaction becomes included in a block.</p>

CC BY-SA 4.0
2019-11-28T03:34:26.487Z
2019-11-28T03:34:26.487Z
Ava Chow
<p>I am reading the code of rpc's <code>estimateSmartFee</code> method , and I can't understand why using <code>blockIndex</code> in <code>unconfTxs</code> ? </p>

<p><code>estimateSmartFee</code> loop <code>unconfTxs</code> to get feeRate(code: <a href="https://github.com/bitcoin/bitcoin/blob/0.18/src/policy/fees.cpp#L291" rel="nofollow noreferrer">https://github.com/bitcoin/bitcoin/blob/0.18/src/policy/fees.cpp#L291</a>)</p>

<p>But the value <code>unconfTxs[blockIndex][bucketindex]</code> will be reseted in <code>TxConfirmStats::ClearCurrent</code> or reduced in <code>TxConfirmStats::removeTx</code>.
Why not just define like this <code>unconfTxs[bucketindex]</code>?</p>

<p>source file <a href="https://github.com/bitcoin/bitcoin/blob/0.18/src/policy/fees.cpp" rel="nofollow noreferrer">fees.cpp</a></p>



<pre><code>unsigned int TxConfirmStats::NewTx(unsigned int nBlockHeight, double val)
{
    unsigned int bucketindex = bucketMap.lower_bound(val)-&gt;second;
    unsigned int blockIndex = nBlockHeight % unconfTxs.size();
    unconfTxs[blockIndex][bucketindex]++;
    return bucketindex;
}
</code></pre>

<p>the <code>unconfTxs</code></p>



<pre><code>    // Mempool counts of outstanding transactions
    // For each bucket X, track the number of transactions in the mempool
    // that are unconfirmed for each possible confirmation value Y
    std::vector&lt;std::vector&lt;int&gt; &gt; unconfTxs;  //unconfTxs[Y][X]
</code></pre>

<bitcoind>
why using `blockIndex` in bitcoin's code `unconfTxs`
Toknsit Toknsit
# why using `blockIndex` in bitcoin's code `unconfTxs`

(Asked by: username_0 on 2019-11-28)

I am reading the code of rpc's `estimateSmartFee` method , and I can't understand why using `blockIndex` in `unconfTxs` ?

`estimateSmartFee` loop `unconfTxs` to get feeRate(code: <https://github.com/bitcoin/bitcoin/blob/0.18/src/policy/fees.cpp#L291>)

But the value `unconfTxs[blockIndex][bucketindex]` will be reseted in `TxConfirmStats::ClearCurrent` or reduced in `TxConfirmStats::removeTx`.
Why not just define like this `unconfTxs[bucketindex]`?

source file [fees.cpp](https://github.com/bitcoin/bitcoin/blob/0.18/src/policy/fees.cpp)

```
unsigned int TxConfirmStats::NewTx(unsigned int nBlockHeight, double val)
{
    unsigned int bucketindex = bucketMap.lower_bound(val)->second;
    unsigned int blockIndex = nBlockHeight % unconfTxs.size();
    unconfTxs[blockIndex][bucketindex]++;
    return bucketindex;
}

```

the `unconfTxs`

```
    // Mempool counts of outstanding transactions
    // For each bucket X, track the number of transactions in the mempool
    // that are unconfirmed for each possible confirmation value Y
    std::vector<std::vector<int> > unconfTxs;  //unconfTxs[Y][X]

```

**Tags:** bitcoind


---

## 1 answers

### Answer by username_1 on 2019-11-28. Score: 1

That whole vector is to keep track of how many blocks have passed since a transaction entered the mempool and what feerate it is. So it allows the estimator to look up how many transactions have been in the mempool for Y blocks at a feerate of X. This allows it to see what feerate is probably needed in order for a transaction to be confirmed in Y blocks.

If you just had the number of transactions at each feerate, that only tells you the feerate distribution of unconfirmed transactions. This is not helpful for estimating how many blocks will pass before a transaction becomes included in a block.


---

