<p>Doing a grep on <code>SERIALIZE_TRANSACTION_NO_WITNESS</code> shows that it's ORed with <code>PROTOCOL_VERSION</code> when creating a <code>CDataStream</code> object for example. This is the first clue that the no witness flag is to be found along with the version protocol.</p>

<p>A little more digging shows that this define is used when building a Tx message in lines <a href="https://github.com/bitcoin/bitcoin/blob/fb7b5293844ea6adc5dcf5ad0a0c5890b4495939/src/net_processing.cpp#L1105-L1126" rel="nofollow noreferrer">1105-1126 of net_processing.cpp (v0.15.0.1)</a>:</p>

<pre><code>        else if (inv.type == MSG_TX || inv.type == MSG_WITNESS_TX)
        {
            // Send stream from relay memory
            bool push = false;
            auto mi = mapRelay.find(inv.hash);
            int nSendFlags = (inv.type == MSG_TX ? SERIALIZE_TRANSACTION_NO_WITNESS : 0);
            if (mi != mapRelay.end()) {
                connman.PushMessage(pfrom, msgMaker.Make(nSendFlags, NetMsgType::TX, *mi-&gt;second));
                push = true;
            } else if (pfrom-&gt;timeLastMempoolReq) {
                auto txinfo = mempool.info(inv.hash);
                // To protect privacy, do not answer getdata using the mempool when
                // that TX couldn't have been INVed in reply to a MEMPOOL request.
                if (txinfo.tx &amp;&amp; txinfo.nTime &lt;= pfrom-&gt;timeLastMempoolReq) {
                    connman.PushMessage(pfrom, msgMaker.Make(nSendFlags, NetMsgType::TX, *txinfo.tx));
                    push = true;
                }
            }
            if (!push) {
                vNotFound.push_back(inv);
            }
        }
</code></pre>

<p>The above code shows that the <code>int</code> variable <code>nSendFlags</code> may contain the no witness flag. Later, <code>msgMaker.Make</code> will use this variable to create the Tx message as shown in line  <a href="https://github.com/bitcoin/bitcoin/blob/fb7b5293844ea6adc5dcf5ad0a0c5890b4495939/src/net_processing.cpp#L1119" rel="nofollow noreferrer">1119</a>:</p>

<pre><code>                    connman.PushMessage(pfrom, msgMaker.Make(nSendFlags, NetMsgType::TX, *txinfo.tx));
</code></pre>

<p>You can then follow the serialization by looking at the class <code>CNetMsgMaker</code> in <code>netmessagemaker.h</code> which itself uses <code>CVectorWriter</code> to serialize the data.</p>

<p>To summarize, the <code>GetVersion()</code> value is built using the protocol version optionally ORed with the <code>SERIALIZE_TRANSACTION_NO_WITNESS</code>. This value is never sent over the wire. It's used only to control the serialization of the Tx message.</p>

CC BY-SA 3.0
2017-11-06T23:04:23.570Z
2017-11-06T23:04:23.570Z
ricvg
<p>In Bitcoin Core, when is <code>fAllowWitness</code> evaluated to <code>true</code>?</p>

<p><a href="https://github.com/bitcoin/bitcoin/blob/master/src/primitives/transaction.h#L198" rel="nofollow noreferrer">transaction.h</a></p>

<pre><code>const bool fAllowWitness = !(s.GetVersion() &amp; SERIALIZE_TRANSACTION_NO_WITNESS);
</code></pre>

<p>In particular, I cant figure out the value of <code>s.GetVersion()</code></p>

<p>Thank you</p>

<bitcoin-core><segregated-witness>
Bitcoin Core - When is fAllowWitness evaluated to true?
tsknakamura
# Bitcoin Core - When is fAllowWitness evaluated to true?

(Asked by: username_0 on 2017-09-13)

In Bitcoin Core, when is `fAllowWitness` evaluated to `true`?

[transaction.h](https://github.com/bitcoin/bitcoin/blob/master/src/primitives/transaction.h#L198)

```
const bool fAllowWitness = !(s.GetVersion() & SERIALIZE_TRANSACTION_NO_WITNESS);

```

In particular, I cant figure out the value of `s.GetVersion()`

Thank you

**Tags:** bitcoin-core, segregated-witness


---

## 1 answers

### Answer by username_1 on 2017-11-06. Score: 3 | Accepted answer

Doing a grep on `SERIALIZE_TRANSACTION_NO_WITNESS` shows that it's ORed with `PROTOCOL_VERSION` when creating a `CDataStream` object for example. This is the first clue that the no witness flag is to be found along with the version protocol.

A little more digging shows that this define is used when building a Tx message in lines [1105-1126 of net\_processing.cpp (v0.15.0.1)](https://github.com/bitcoin/bitcoin/blob/fb7b5293844ea6adc5dcf5ad0a0c5890b4495939/src/net_processing.cpp#L1105-L1126):

```
        else if (inv.type == MSG_TX || inv.type == MSG_WITNESS_TX)
        {
            // Send stream from relay memory
            bool push = false;
            auto mi = mapRelay.find(inv.hash);
            int nSendFlags = (inv.type == MSG_TX ? SERIALIZE_TRANSACTION_NO_WITNESS : 0);
            if (mi != mapRelay.end()) {
                connman.PushMessage(pfrom, msgMaker.Make(nSendFlags, NetMsgType::TX, *mi->second));
                push = true;
            } else if (pfrom->timeLastMempoolReq) {
                auto txinfo = mempool.info(inv.hash);
                // To protect privacy, do not answer getdata using the mempool when
                // that TX couldn't have been INVed in reply to a MEMPOOL request.
                if (txinfo.tx && txinfo.nTime <= pfrom->timeLastMempoolReq) {
                    connman.PushMessage(pfrom, msgMaker.Make(nSendFlags, NetMsgType::TX, *txinfo.tx));
                    push = true;
                }
            }
            if (!push) {
                vNotFound.push_back(inv);
            }
        }

```

The above code shows that the `int` variable `nSendFlags` may contain the no witness flag. Later, `msgMaker.Make` will use this variable to create the Tx message as shown in line [1119](https://github.com/bitcoin/bitcoin/blob/fb7b5293844ea6adc5dcf5ad0a0c5890b4495939/src/net_processing.cpp#L1119):

```
                    connman.PushMessage(pfrom, msgMaker.Make(nSendFlags, NetMsgType::TX, *txinfo.tx));

```

You can then follow the serialization by looking at the class `CNetMsgMaker` in `netmessagemaker.h` which itself uses `CVectorWriter` to serialize the data.

To summarize, the `GetVersion()` value is built using the protocol version optionally ORed with the `SERIALIZE_TRANSACTION_NO_WITNESS`. This value is never sent over the wire. It's used only to control the serialization of the Tx message.


---

