<p>Both Bitcoin Core and Electrum have very similar behavior when it comes to setting the locktime. As already stated in your answer, this is used to prevent fee sniping. However, besides setting the locktime to the current block height, they also choose a random block height from 99 blocks into the past on average every 10 transactions <a href="https://github.com/bitcoin/bitcoin/blob/df73c23f5fac031cc9b2ec06a74275db5ea322e3/src/wallet/wallet.cpp#L2600" rel="nofollow noreferrer">here in Bitcoin</a>, <a href="https://github.com/spesmilo/electrum/blob/master/electrum/wallet.py#L188" rel="nofollow noreferrer">here in Electrum</a>. This is additionally done to give better privacy to transactions that are withheld for some time after signing (like Coinjoin transactions).</p>

CC BY-SA 4.0
2019-12-15T12:58:57.563Z
2019-12-15T12:58:57.563Z
TheCharlatan
<p>The locktime value is deliberately set to discourage a subtle attack known as "Fee sniping" and <a href="https://github.com/spesmilo/electrum/blob/a50f935aecc1a47dffce195808ed3b1839c8e3a0/electrum/wallet.py#L175" rel="nofollow noreferrer">randomly set to an earlier block height</a> to improve privacy (eg for CoinJoin users that need more setup time).</p>

<p>This is also <a href="https://github.com/bitcoin/bitcoin/blob/df73c23f5fac031cc9b2ec06a74275db5ea322e3/src/wallet/wallet.cpp#L2573" rel="nofollow noreferrer">done in Bitcoin Core</a> with the <code>nLockTime</code>.</p>

CC BY-SA 4.0
2019-09-02T16:10:22.097Z
2019-09-02T18:49:52.760Z
2019-09-02T18:49:52.760Z
Jonathan Cross
<p>Electrum includes a <code>locktime</code> in all transactions by default.</p>

<p>Usually the value is <em>equal to</em> the current block height, eg <code>592918</code>, however it <em>sometimes</em> drops perhaps 20 or so blocks.</p>

<p>What is going on here?</p>

<electrum><locktime><random>
Strange LockTime values in Electrum transactions?
Jonathan Cross
# Strange LockTime values in Electrum transactions?

(Asked by: username_0 on 2019-09-02)

Electrum includes a `locktime` in all transactions by default.

Usually the value is *equal to* the current block height, eg `592918`, however it *sometimes* drops perhaps 20 or so blocks.

What is going on here?

**Tags:** electrum, locktime, random


---

## 2 answers

### Answer by username_0 on 2019-09-02. Score: 5 | Accepted answer

The locktime value is deliberately set to discourage a subtle attack known as "Fee sniping" and [randomly set to an earlier block height](https://github.com/spesmilo/electrum/blob/a50f935aecc1a47dffce195808ed3b1839c8e3a0/electrum/wallet.py#L175) to improve privacy (eg for CoinJoin users that need more setup time).

This is also [done in Bitcoin Core](https://github.com/bitcoin/bitcoin/blob/df73c23f5fac031cc9b2ec06a74275db5ea322e3/src/wallet/wallet.cpp#L2573) with the `nLockTime`.


---

### Answer by username_1 on 2019-12-15. Score: 1

Both Bitcoin Core and Electrum have very similar behavior when it comes to setting the locktime. As already stated in your answer, this is used to prevent fee sniping. However, besides setting the locktime to the current block height, they also choose a random block height from 99 blocks into the past on average every 10 transactions [here in Bitcoin](https://github.com/bitcoin/bitcoin/blob/df73c23f5fac031cc9b2ec06a74275db5ea322e3/src/wallet/wallet.cpp#L2600), [here in Electrum](https://github.com/spesmilo/electrum/blob/master/electrum/wallet.py#L188). This is additionally done to give better privacy to transactions that are withheld for some time after signing (like Coinjoin transactions).


---

