Bitcoin Forum

Bitcoin => Development & Technical Discussion => Topic started by: victoriobn on August 28, 2017, 10:57:41 PM



Title: What happens when non-Segwit transactions are sent to Segwit nodes?
Post by: victoriobn on August 28, 2017, 10:57:41 PM
Hi everyone,

I understand what happens when Segwit nodes broadcasts new transactions to non-Segwit (or legacy) nodes. Putting in a simple way, transactions are transmitted without witness data and is still considered valid to the legacy. Then, legacy validates it, adds to the mempool and broadcasts to all connected nodes.

What I don't understand is the opposite way. What happens when a legacy (or non-Segwit) node sends transactions to Segwit nodes? Segwit nodes understand this "old fashion" transaction? Or it needs to transform it into a Segwit transaction by "rearranging" the witness data before validating it and adding to the mempool?

The same questioning goes to the block when a non-Segwit node broadcasts it to a Segwit node.

Thanks in advance ;)





Title: Re: What happens when non-Segwit transactions are sent to Segwit nodes?
Post by: achow101 on August 28, 2017, 11:15:54 PM
Segwit nodes still understand legacy transactions. Segwit does not change this at all whatsoever. Furthermore, for transactions that do not have witnesses, the witness format of that transaction is the legacy transaction format. So nothing happens; everything works as normal.


Title: Re: What happens when non-Segwit transactions are sent to Segwit nodes?
Post by: victoriobn on August 29, 2017, 12:50:04 AM
@achow101 thanks a lot man!

So, both types of transactions can coexists in Segwit nodes mempool at the same time? They are then broadcasted to other nodes as is?

Just one more question: once a Segwit node receives a non-Segwit transaction, are there instructions like "if Segwit do this || if non-Segwit do that" in order to put it in the mempool?

The same reasoning apply to blocks sent from non-Segwit to Segwit nodes? I ask cause, when sending from a Segwit node, there are instructions that orientate the "block type" to be broadcasted accordingly to the destiny (Segwit or Legacy), as shown bellow:

Code:
if (inv.type == MSG_BLOCK)
     connman.PushMessageWithFlag(pfrom, SERIALIZE_TRANSACTION_NO_WITNESS, NetMsgType::BLOCK, block);
else if (inv.type == MSG_WITNESS_BLOCK)
     connman.PushMessage(pfrom, NetMsgType::BLOCK, block);

Thanks again :)


Title: Re: What happens when non-Segwit transactions are sent to Segwit nodes?
Post by: achow101 on August 29, 2017, 01:06:43 AM
So, both types of transactions can coexists in Segwit nodes mempool at the same time? They are then broadcasted to other nodes as is?
Yes.

Just one more question: once a Segwit node receives a non-Segwit transaction, are there instructions like "if Segwit do this || if non-Segwit do that" in order to put it in the mempool?
No. The verification processes are basically the same, but for segwit transactions, there are a few extra steps prior to main validation to check that a transaction that spends from witness transactions has a txwitness field and the marker and flag bytes.

The same reasoning apply to blocks sent from non-Segwit to Segwit nodes? I ask cause, when sending from a Segwit node, there are instructions that orientate the "block type" to be broadcasted accordingly to the destiny (Segwit or Legacy), as shown bellow:

Code:
if (inv.type == MSG_BLOCK)
     connman.PushMessageWithFlag(pfrom, SERIALIZE_TRANSACTION_NO_WITNESS, NetMsgType::BLOCK, block);
else if (inv.type == MSG_WITNESS_BLOCK)
     connman.PushMessage(pfrom, NetMsgType::BLOCK, block);

Thanks again :)
No. The block format is not different with segwit. The only thing different is that any transactions spending segwit outputs must be in the witness extended format (the format with marker and flag bytes and txwitness field). But the block format itself is not different.


Title: Re: What happens when non-Segwit transactions are sent to Segwit nodes?
Post by: polyhedron on August 29, 2017, 01:19:41 AM
No. The block format is not different with segwit. The only thing different is that any transactions spending segwit outputs must be in the witness extended format (the format with marker and flag bytes and txwitness field). But the block format itself is not different.
Can I understand it as, whether a transaction applies to SegWit or not, depends on the sender address, not receptor address nor the way it choose to send?


Title: Re: What happens when non-Segwit transactions are sent to Segwit nodes?
Post by: victoriobn on August 31, 2017, 03:00:53 PM
@achow101,

Currently I see that only about 5% of all tx are segwit tx.

So what happens to the block tx structure?

I mean, 95% non-segwit tx will be in the merkle tree alongside with the 5% segwit tx, right?

Also, only witness data from the 5% of segwit tx will be in the tiny coinbase witness merkle tree? How would it look like?

Thanks again man o/


Title: Re: What happens when non-Segwit transactions are sent to Segwit nodes?
Post by: achow101 on August 31, 2017, 03:08:45 PM
Can I understand it as, whether a transaction applies to SegWit or not, depends on the sender address, not receptor address nor the way it choose to send?
Yes.

@achow101,

Currently I see that only about 5% of all tx are segwit tx.

So what happens to the block tx structure?

I mean, 95% non-segwit tx will be in the merkle tree alongside with the 5% segwit tx, right?

Also, only witness data from the 5% of segwit tx will be in the tiny coinbase witness merkle tree? How would it look like?

Thanks again man o/
It doesn't look any different. The witness merkle root also contains the hashes of all of the non-witness transactions too since that is actually the hash of the entire transaction, not just the txid.


Title: Re: What happens when non-Segwit transactions are sent to Segwit nodes?
Post by: victoriobn on August 31, 2017, 04:25:39 PM
Got it @achow101

Thanks ;)