1
0
Fork 0
mirror of https://github.com/bitcoin/bips.git synced 2025-02-23 15:20:50 +01:00
bitcoin-bips/bip-codeshark-segwit-peer-services.mediawiki

119 lines
4.4 KiB
Text
Raw Normal View History

2015-12-24 14:23:27 -05:00
<pre>
BIP: x
Title: Segregated Witness (Peer Services)
2015-12-25 19:03:02 -05:00
Author: Eric Lombrozo <elombrozo@gmail.com>
Pieter Wuille <pieter.wuille@gmail.com>
2015-12-24 14:23:27 -05:00
Status: Draft
Type: Standards Track
Created: 2015-12
</pre>
==Abstract==
This BIP defines new messages and serialization formats for propagation of transactions and blocks committing to segregated witness structures.
==Motivation==
2015-12-25 19:14:36 -05:00
In addition to defining witness structures and requiring commitments in future blocks (BIPxxxx - Consensus segwit BIP), new mechanisms must be defined to allow peers to advertise support for segregated witness and to relay the witness structures and request them from other peers without breaking compatibility with older nodes.
2015-12-24 14:23:27 -05:00
==Specification==
2015-12-25 18:57:27 -05:00
=== Serialization ===
2015-12-24 17:23:02 -05:00
A new serialization format for tx messages is added to the peer-to-peer protocol.
2015-12-24 14:23:27 -05:00
2015-12-24 17:23:02 -05:00
The serialization has the following structure:
2015-12-24 14:23:27 -05:00
{| class="wikitable" style="width: auto; text-align: center; font-size: smaller; table-layout: fixed;"
!Field Size
!Name
!Type
!Description
|-
| 4
| version
| int32_t
| Transaction data format version
|-
| 1
| marker
| char
| Must be zero
|-
| 1
| flag
| char
| Must be nonzero
|-
| 1+
| txin_count
| var_int
| Number of transaction inputs
|-
| 41+
| txins
| txin[]
| A list of one or more transaction inputs
|-
| 1+
| txout_count
| var_int
| Number of transaction outputs
|-
| 9+
| txouts
| txouts[]
| A list of one or more transaction outputs
|-
2015-12-25 18:57:27 -05:00
| 1+
| txin_witnesses
| txin_witnesses[]
| A list of one or more transaction input witnesses (note: the count is just txin_count)
2015-12-24 14:23:27 -05:00
|-
| 4
| lock_time
| uint32_t
| The block number or timestamp until which the transaction is locked
|}
2015-12-24 17:23:02 -05:00
Parsers supporting this BIP will be able to distinguish between the old serialization format (without the witnesses) and this one. The marker byte is set to zero so that this structure will never parse as a valid transaction in a parser that does not support this BIP. If parsing were to succeeded, such a transaction would contain no inputs and a single output.
If all witnesses are empty, the old serialization format should be used.
Witness objects can be extended to contain other kinds of witness data not yet specified. This BIP is agnostic to the witness data structure, defined in BIPxxxx (Consensus Segwit BIP), and treats it as an arbitrary byte array.
2015-12-24 17:23:02 -05:00
* '''Rationale for not having an independent message type with its own serialization''': this would require separate "tx" and "block" messages, and all RPC calls operating on raw transactions would need to be duplicated, or need inefficinent or nondeterministic guesswork to know which type is to be used.
2015-12-24 17:23:02 -05:00
* '''Rationale for not using just a single 0x00 byte as marker''': that would lead to empty transactions (no inputs, no outputs, which are used in some tests) to be interpreted as new serialized data.
* '''Rationale for the 0x01 flag byte in between''': this will allow us to easily add more extra non-committed data to transactions (like txouts being spent, ...). It can be interpreted as a bitvector.
2015-12-24 14:23:27 -05:00
2015-12-25 18:57:27 -05:00
=== Handshake ===
A new message 'havewitness' is sent after receiving 'verack' to
2015-12-24 14:23:27 -05:00
indicate that a node can provide witness if requested (similar to
2015-12-25 18:57:27 -05:00
'sendheaders') (Note: it might be better to signal this with a services bit in the version message)
2015-12-24 14:23:27 -05:00
2015-12-25 18:57:27 -05:00
=== Relay ===
New inv types MSG_WITNESS_TX and MSG_WITNESS_BLOCK are added, only
2015-12-24 14:23:27 -05:00
for use in getdata. Inv itself still use just MSG_TX and MSG_BLOCK,
similar to MSG_FILTERED_BLOCK.
2015-12-25 18:57:27 -05:00
* '''Rationale for not advertizing witnessness in invs''': we don't always use invs anymore (with 'sendheaders' BIP 130), plus it's not useful: implicitly, every transaction and block have a witness, old ones just have empty ones.
2015-12-24 14:23:27 -05:00
2015-12-25 18:57:27 -05:00
=== Hashes ===
2015-12-25 19:17:00 -05:00
Transaction hashes used in the transaction merkle tree and txin outpoints are always computed using the old non-witness
serialization.
Support for a new hash including the witness data is added that is
computed from the new witness serialization. (Note that transactions
with an empty witness always use the old serialization,
and therefore, they have witness hash equal to normal hash.)
<img src=bip-codeshark-segwit-peer-services/witnesstx.png></img>
2015-12-24 14:23:27 -05:00
== Credits ==
Special thanks to Gregory Maxwell for originating many of the ideas in this BIP and Luke-Jr for figuring out how to deploy this as a soft fork.
== Reference Implementation ==
https://github.com/sipa/bitcoin/commits/segwit
== Copyright ==
This document is placed in the public domain.