<p>Bitcoin Core has no idea which transactions already exist in the chain. It does not maintain a full index, because... it doesn't need to. In fact, when running in pruning mode, it doesn't even have the chain or its transactions at all.</p>

<p>The only thing it has is the set of unspent transaction outputs. Since you're trying to replay an existing transaction, all the inputs are already spent by its previous instance. As a result, the expected and correct response is that inputs are missing - i.e. your transaction is a double spend, and thus invalid.</p>

<p>I'd say that this is one of the advantages of the UTXO model: a replay and a double spend are one and the same, and there is no need to distinguish.</p>

CC BY-SA 3.0
2017-08-17T03:02:40.627Z
In that case, what is the point of fHaveChain in https://github.com/bitcoin/bitcoin/blob/master/src/rpc/rawtransaction.cpp#L950 which throws RPC_TRANSACTION_ALREADY_IN_CHAIN ?
meshcollider
CC BY-SA 3.0
2017-08-17T04:05:59.240Z
@MeshCollider If I'm reading it right, if some of the outputs of the transaction exist in the blockchain *and* are unspent, then sendrawtransaction fails with that error, instead of failing with the missing inputs error.
Nick ODell
CC BY-SA 3.0
2017-08-17T01:49:16.460Z
2017-08-17T22:07:33.053Z
2017-08-17T22:07:33.053Z
Pieter Wuille
<p>In an attempt to more fully understand raw transactions etc, I went to look at tx <a href="https://blockchain.info/tx/518c41d5e59114f6a23383afbe95f02cdd09cb50cabd8390bdd9162a890435b3" rel="nofollow noreferrer">518c41d5e59114f6a23383afbe95f02cdd09cb50cabd8390bdd9162a890435b3</a> in its <a href="https://blockchain.info/tx/518c41d5e59114f6a23383afbe95f02cdd09cb50cabd8390bdd9162a890435b3?format=hex" rel="nofollow noreferrer">raw form</a> being:</p>

<blockquote>
  <p>01000000017871f56f7be2743293abb1adccf21526265e4ad793fddbc08508417293fd6b4e000000006a47304402201f3b98d55c16a1ff9e66cbdd5533fd74d18362477f50dbce357d66e1233ba469022066fd837cf7e1e030f5aab0f22fec06c7d98ee948fd8b9aba185512426079e0a201210284ca3e364bebb4cafb9fa76624927078e16a4244314f824ea8acff0ef1ba4627ffffffff0220a10700000000001976a91488d924f51033b74a895863a5fb57fd545529df7d88ac81f1d909000000001976a914db4c1f7949870fae5cdc366a45e2ea39c084547c88ac00000000</p>
</blockquote>

<p>I then tried to submit that raw form, just copy and paste into my bitcoin wallet program to "sendrawtransaction" and got the error <code>missing inputs (code -25)</code>.  This seems odd in it of itself because since this is an exact copy and paste of the raw transaction that is on the blockchain, shouldn't it not be missing anything at all?  Also, shouldn't I be getting a "transaction already exists" error instead?  Or do I not understand something about how raw transactions are submitted?</p>

<raw-transaction><transaction-input>
Submitted a raw tx that was already on the blockchain, to test it. I got 'missing inputs' instead of 'already exists'. Why?
Mine
# Submitted a raw tx that was already on the blockchain, to test it. I got 'missing inputs' instead of 'already exists'. Why?

(Asked by: username_0 on 2017-08-16)

In an attempt to more fully understand raw transactions etc, I went to look at tx [518c41d5e59114f6a23383afbe95f02cdd09cb50cabd8390bdd9162a890435b3](https://blockchain.info/tx/518c41d5e59114f6a23383afbe95f02cdd09cb50cabd8390bdd9162a890435b3) in its [raw form](https://blockchain.info/tx/518c41d5e59114f6a23383afbe95f02cdd09cb50cabd8390bdd9162a890435b3?format=hex) being:

> 01000000017871f56f7be2743293abb1adccf21526265e4ad793fddbc08508417293fd6b4e000000006a47304402201f3b98d55c16a1ff9e66cbdd5533fd74d18362477f50dbce357d66e1233ba469022066fd837cf7e1e030f5aab0f22fec06c7d98ee948fd8b9aba185512426079e0a201210284ca3e364bebb4cafb9fa76624927078e16a4244314f824ea8acff0ef1ba4627ffffffff0220a10700000000001976a91488d924f51033b74a895863a5fb57fd545529df7d88ac81f1d909000000001976a914db4c1f7949870fae5cdc366a45e2ea39c084547c88ac00000000

I then tried to submit that raw form, just copy and paste into my bitcoin wallet program to "sendrawtransaction" and got the error `missing inputs (code -25)`. This seems odd in it of itself because since this is an exact copy and paste of the raw transaction that is on the blockchain, shouldn't it not be missing anything at all? Also, shouldn't I be getting a "transaction already exists" error instead? Or do I not understand something about how raw transactions are submitted?

**Tags:** raw-transaction, transaction-input


---

## 1 answers

### Answer by username_1 on 2017-08-17. Score: 4 | Accepted answer

Bitcoin Core has no idea which transactions already exist in the chain. It does not maintain a full index, because... it doesn't need to. In fact, when running in pruning mode, it doesn't even have the chain or its transactions at all.

The only thing it has is the set of unspent transaction outputs. Since you're trying to replay an existing transaction, all the inputs are already spent by its previous instance. As a result, the expected and correct response is that inputs are missing - i.e. your transaction is a double spend, and thus invalid.

I'd say that this is one of the advantages of the UTXO model: a replay and a double spend are one and the same, and there is no need to distinguish.

> **Comments:**
> **username_2**: In that case, what is the point of fHaveChain in https://github.com/bitcoin/bitcoin/blob/master/src/rpc/rawtransaction.cpp#L950 which throws RPC_TRANSACTION_ALREADY_IN_CHAIN ?  
> **username_3**: @MeshCollider If I'm reading it right, if some of the outputs of the transaction exist in the blockchain *and* are unspent, then sendrawtransaction fails with that error, instead of failing with the missing inputs error.  

---

