<blockquote>
<p>double hashed format: ie SHA256(SHA256(rawtransaction))</p>
</blockquote>
<p>Your understanding of this is very, very wrong.</p>
<p>The data structure stored in a blockchain is not <strong>double hashed</strong>. Instead there are <strong>two hashes</strong> stored in the data structure.</p>
<p>Instead of <code>SHA256(SHA256(rawtransaction))</code>. You should visualize the blockchain data structure as:</p>
<pre><code>struct Block {
    Transactions[] transactions;
    int256 nonce;
    int256 previousHash; // SHA256(previous.transactions + previous.nonce + previous.previousHash)
    int256 hash;         // SHA256(this.transactions + this.nonce + this.previousHash)
}
</code></pre>
<p>You can see, the data structure is linked to the previous block by including the hash of the previous block as part of its own data. This is the &quot;chain&quot; part of blockchain. The definition of the entire set of blocks is recursive because to calculate the hash of the previous block you need to calculate the hash of the block before that and so on until you get to the genesis block.</p>
<p>The raw committed transactions are part of the block.</p>

CC BY-SA 4.0
2021-05-31T16:42:29.873Z
Um, no. Double hashing is indeed used in blockchain. I can give you lots of references, e.g. https://bitcoin.stackexchange.com/questions/8443/where-is-double-hashing-performed-in-bitcoin. I know how the chain part of the blockchain works. The real answer is that in (for example) links in current transaction to input transactions, the current transaction stores the double hash of the previous transaction. Double hashing is used elsewhere too.
Marc
CC BY-SA 4.0
2021-06-01T04:32:48.023Z
Note: the example of the block structure given in this answer works to give a basic understanding, but it is not truly accurate. See: https://en.bitcoin.it/wiki/Protocol_documentation#Block_Headers
chytrik
CC BY-SA 4.0
2021-05-31T11:51:42.140Z
2021-05-31T11:51:42.140Z
slebetman
<p>This is a question of definition.</p>
<p>The blockchain doesn't store anything, it's an abstract data structure that's collectively maintained by nodes in a network. Those nodes are the ones that store things. That may or may not include the actual transaction data - it doesn't matter.</p>
<p>The Bitcoin blockchain consists of hash-linked block headers. Every block header contains the hash of the previous block header. Every block header also contains a hash of all the transaction hashes in it (through a Merkle tree). Those transaction hashes obviously are hashes of the transaction data itself.</p>
<p>That's a definition of the structure all nodes need to agree on, because it involves hashes, and those hashes need to match. But what they actually store of that is their own business. Full nodes with unpruned history will store all transactions and all blocks. Pruned nodes may store all transactions and blocks down to a particular point in history. More lightweight nodes may only store the block headers plus transactions the user is interested in.</p>

CC BY-SA 4.0
2021-05-31T16:44:15.947Z
So the raw transaction is indeed stored in the nodes (full nodes at least, and possibly pruned ones) and each transaction stores a double hashed representation of its input transactions: https://bitcoin.stackexchange.com/questions/8443/where-is-double-hashing-performed-in-bitcoin
Marc
CC BY-SA 4.0
2021-05-31T16:47:38.167Z
Yes, transactions are typically serialized and stored that way, but again: they don't have to be. How things are stored is up to the individual node software. E.g. some software uses a compressed representation that can omit repeated input hashes. The only thing that matters is how a txid is defined, which is a double-SH256 of the transaction data in "network serialization" which indeed includes the txids of the previous tx that created the UTXOs being spent. If somewhere can store things differently, but still agree on that hash, everything is ok.
Pieter Wuille
CC BY-SA 4.0
2021-05-31T01:54:46.470Z
2021-05-31T01:54:46.470Z
Pieter Wuille
<p>My understanding is that transactions are stored on the blockchain in double hashed format: ie SHA256(SHA256(rawtransaction)). But it is also possible to get access to the raw transaction. This means that the raw transaction data must be stored somewhere. So where is the raw transaction data stored, if it isn't stored on the blockchain? Or was my initial statement incorrect about transactions being stored in double hashed format? I don't think the raw transaction data can be extracted by reversing the double hash operation.</p>

<bitcoin-core><transactions><blockchain>
Where and how are raw transactions stored on the blockchain?
Marc
# Where and how are raw transactions stored on the blockchain?

(Asked by: username_0 on 2021-05-31)

My understanding is that transactions are stored on the blockchain in double hashed format: ie SHA256(SHA256(rawtransaction)). But it is also possible to get access to the raw transaction. This means that the raw transaction data must be stored somewhere. So where is the raw transaction data stored, if it isn't stored on the blockchain? Or was my initial statement incorrect about transactions being stored in double hashed format? I don't think the raw transaction data can be extracted by reversing the double hash operation.

**Tags:** bitcoin-core, transactions, blockchain


---

## 2 answers

### Answer by username_3 on 2021-05-31. Score: 10 | Accepted answer

This is a question of definition.

The blockchain doesn't store anything, it's an abstract data structure that's collectively maintained by nodes in a network. Those nodes are the ones that store things. That may or may not include the actual transaction data - it doesn't matter.

The Bitcoin blockchain consists of hash-linked block headers. Every block header contains the hash of the previous block header. Every block header also contains a hash of all the transaction hashes in it (through a Merkle tree). Those transaction hashes obviously are hashes of the transaction data itself.

That's a definition of the structure all nodes need to agree on, because it involves hashes, and those hashes need to match. But what they actually store of that is their own business. Full nodes with unpruned history will store all transactions and all blocks. Pruned nodes may store all transactions and blocks down to a particular point in history. More lightweight nodes may only store the block headers plus transactions the user is interested in.

> **Comments:**
> **username_0**: So the raw transaction is indeed stored in the nodes (full nodes at least, and possibly pruned ones) and each transaction stores a double hashed representation of its input transactions: https://bitcoin.stackexchange.com/questions/8443/where-is-double-hashing-performed-in-bitcoin  
> **username_3**: Yes, transactions are typically serialized and stored that way, but again: they don't have to be. How things are stored is up to the individual node software. E.g. some software uses a compressed representation that can omit repeated input hashes. The only thing that matters is how a txid is defined, which is a double-SH256 of the transaction data in "network serialization" which indeed includes the txids of the previous tx that created the UTXOs being spent. If somewhere can store things differently, but still agree on that hash, everything is ok.  

---

### Answer by username_1 on 2021-05-31. Score: 0

> double hashed format: ie SHA256(SHA256(rawtransaction))

Your understanding of this is very, very wrong.

The data structure stored in a blockchain is not **double hashed**. Instead there are **two hashes** stored in the data structure.

Instead of `SHA256(SHA256(rawtransaction))`. You should visualize the blockchain data structure as:

```
struct Block {
    Transactions[] transactions;
    int256 nonce;
    int256 previousHash; // SHA256(previous.transactions + previous.nonce + previous.previousHash)
    int256 hash;         // SHA256(this.transactions + this.nonce + this.previousHash)
}

```

You can see, the data structure is linked to the previous block by including the hash of the previous block as part of its own data. This is the "chain" part of blockchain. The definition of the entire set of blocks is recursive because to calculate the hash of the previous block you need to calculate the hash of the block before that and so on until you get to the genesis block.

The raw committed transactions are part of the block.

> **Comments:**
> **username_0**: Um, no. Double hashing is indeed used in blockchain. I can give you lots of references, e.g. https://bitcoin.stackexchange.com/questions/8443/where-is-double-hashing-performed-in-bitcoin. I know how the chain part of the blockchain works. The real answer is that in (for example) links in current transaction to input transactions, the current transaction stores the double hash of the previous transaction. Double hashing is used elsewhere too.  
> **username_2**: Note: the example of the block structure given in this answer works to give a basic understanding, but it is not truly accurate. See: https://en.bitcoin.it/wiki/Protocol_documentation#Block_Headers  

---

