BIP 0145: Difference between revisions

From Bitcoin Wiki
Jump to navigation Jump to search
Spaz926 (talk | contribs)
Created page with "{{bip}} <pre> BIP: 145 Title: getblocktemplate Updates for Segregated Witness Authors: Luke Dashjr <luke+bip22@dashjr.org> Status: Draft Type: Standards Track Cre..."
 
934 (talk | contribs)
Update BIP text with latest version from https://github.com/bitcoin/bips/blob/b5723035e23896d0/bip-0145.mediawiki
 
(One intermediate revision by the same user not shown)
Line 1: Line 1:
{{bip}}
{{bip}}
{{BipMoved|bip-0145.mediawiki}}


<pre>
<pre>
   BIP: 145
   BIP: 145
  Layer: API/RPC
   Title: getblocktemplate Updates for Segregated Witness
   Title: getblocktemplate Updates for Segregated Witness
   Authors: Luke Dashjr <luke+bip22@dashjr.org>
   Author: Luke Dashjr <luke+bip22@dashjr.org>
   Status: Draft
  Comments-Summary: No comments yet.
  Comments-URI: https://github.com/bitcoin/bips/wiki/Comments:BIP-0145
   Status: Final
   Type: Standards Track
   Type: Standards Track
   Created: 2016-01-30
   Created: 2016-01-30
  License: BSD-2-Clause
          OPL
</pre>
</pre>


{{BipMoved|bip-0145.mediawiki}}
==Abstract==
 
This BIP describes modifications to the getblocktemplate JSON-RPC call ([[bip-0022.mediawiki|BIP 22]]) to support segregated witness as defined by [[bip-0141.mediawiki|BIP 141]].
 
==Specification==
 
===Block Template===
 
The template Object is revised to include a new key:
 
{| class="wikitable"
!colspan=4| template
|-
! Key !! Required !! Type !! Description
|-
| weightlimit || No || Number || total weight allowed in blocks
|}
 
The '!' rule prefix MUST be enabled on the "segwit" rule for templates including transactions with witness data.
In particular, note that even if the client's "rules" list lacks "segwit", server MAY support old miners by producing a witness-free template and omitting the '!' rule prefix for "segwit" in the template's "rules" list.
If the GBT server does not support producing witness-free templates after its activation, it must also use the '!' rule prefix in the "vbavailable" list prior to activation.
 
====Transactions Object Format====
 
The Objects listed in the response's "transactions" key is revised to include these keys:
 
{| class="wikitable"
!colspan=3|template "transactions" element
|-
! Key !! Type !! Description
|-
| txid || String || transaction id encoded in hexadecimal; required for transactions with witness data
|-
| weight || Number || numeric weight of the transaction, as counted for purposes of the block's weightlimit; if key is not present, weight is unknown and clients MUST NOT assume it is zero, although they MAY choose to calculate it themselves
|-
| hash || String || reversed hash of complete transaction (with witness data included) encoded in hexadecimal
|}
 
Transactions with witness data may only be included if the template's "rules" list (see [[bip-0009.mediawiki#getblocktemplate_changes|BIP 9]]) includes "segwit".
 
===Sigops===
 
For templates with "segwit" enabled as a rule, the "sigoplimit" and "sigops" keys must use the new values as calculated in [[bip-0141.mediawiki#Sigops|BIP 141]].
 
===Block Assembly with Witness Transactions===
 
When block assembly is done without witness transactions, no changes are made by this BIP, and it should be assembled as previously.
 
When witness transactions are included in the block, the primary merkle root MUST be calculated with those transactions' "txid" field instead of "hash". A secondary merkle root MUST be calculated as per [[bip-0141.mediawiki#Commitment_structure|BIP 141's commitment structure specification]] to be inserted into the generation (coinbase) transaction.
 
Servers MUST NOT include a commitment in the "coinbasetxn" key on the template. Clients MUST insert the commitment as an additional output at the end of the final generation (coinbase) transaction. Only if the template includes a "mutable" key (see [[bip-0023.mediawiki#Mutations|BIP 23 Mutations]]) including "generation", the client MAY in that case place the commitment output in any position it chooses, provided that no later output matches the commitment pattern.
 
==Motivation==
 
Segregated witness substantially changes the structure of blocks, so the previous getblocktemplate specification is no longer sufficient.
It additionally also adds a new way of counting resource limits, and so GBT must be extended to convey this information correctly as well.
 
==Rationale==
 
Why doesn't "weightlimit" simply redefine the existing "sizelimit"?
* "sizelimit" is already enforced by clients by counting the sum of bytes in transactions' "data" keys.
* Servers may wish to limit the overall size of a block, independently from the "weight" of the block.
 
Why is "sigoplimit" redefined instead of a new "sigopweightlimit" being added?
* The old limit was already arbitrarily defined, and could not be counted by clients on their own anyway. The concept of "sigop weight" is merely a change in the arbitrary formula used.
 
Why is "sigoplimit" divided by 4?
* To resemble the previous values. (FIXME: is this a good reason? maybe we shouldn't divide it?)
 
Why is the witness commitment required to be added to the end of the generation transaction rather than anywhere else?
* Servers which do not allow modification of the generation outputs ought to be checking this as part of the validity of submissions. By requiring a specific placement, they can simply strip the commitment and do a byte-for-byte comparison of the outputs. Placing it at the end avoids the possibility of a later output matching the pattern and overriding it.
 
Why shouldn't the server simply add the commitment upfront in the "coinbasetxn", and simply send the client stripped transaction data?
* It would become impossible for servers to specify only "coinbasevalue", since clients would no longer have the information required to construct the commitment.
* getblocktemplate is intended to be a *decentralised* mining protocol, and allowing clients to be blinded to the content of the block works contrary to that purpose.
* BIP 23's "transactions" mutations allow the client to modify the transaction-set on their own, which is impossible without the complete transaction data.
 
==Reference Implementation==
 
* [https://github.com/bitcoin/libblkmaker/tree/segwit libblkmaker]
* [https://github.com/luke-jr/eloipool/tree/segwit Eloipool]
* [https://github.com/bitcoin/bitcoin/pull/7404/files Bitcoin Core]
 
==See Also==
* [[bip-0009.mediawiki|BIP 9: Version bits with timeout and delay]]
* [[bip-0022.mediawiki|BIP 22: getblocktemplate - Fundamentals]]
* [[bip-0023.mediawiki|BIP 23: getblocktemplate - Pooled Mining]]
* [[bip-0141.mediawiki|BIP 141: Segregated Witness (Consensus layer)]]
 
==Copyright==
 
This BIP is dual-licensed under the Open Publication License and BSD 2-clause license.

Latest revision as of 18:00, 24 September 2019

This page describes a BIP (Bitcoin Improvement Proposal).
Please see BIP 2 for more information about BIPs and creating them. Please do not just create a wiki page.

Please do not modify this page. This is a mirror of the BIP from the source Git repository here.

  BIP: 145
  Layer: API/RPC
  Title: getblocktemplate Updates for Segregated Witness
  Author: Luke Dashjr <luke+bip22@dashjr.org>
  Comments-Summary: No comments yet.
  Comments-URI: https://github.com/bitcoin/bips/wiki/Comments:BIP-0145
  Status: Final
  Type: Standards Track
  Created: 2016-01-30
  License: BSD-2-Clause
           OPL

Abstract

This BIP describes modifications to the getblocktemplate JSON-RPC call (BIP 22) to support segregated witness as defined by BIP 141.

Specification

Block Template

The template Object is revised to include a new key:

template
Key Required Type Description
weightlimit No Number total weight allowed in blocks

The '!' rule prefix MUST be enabled on the "segwit" rule for templates including transactions with witness data. In particular, note that even if the client's "rules" list lacks "segwit", server MAY support old miners by producing a witness-free template and omitting the '!' rule prefix for "segwit" in the template's "rules" list. If the GBT server does not support producing witness-free templates after its activation, it must also use the '!' rule prefix in the "vbavailable" list prior to activation.

Transactions Object Format

The Objects listed in the response's "transactions" key is revised to include these keys:

template "transactions" element
Key Type Description
txid String transaction id encoded in hexadecimal; required for transactions with witness data
weight Number numeric weight of the transaction, as counted for purposes of the block's weightlimit; if key is not present, weight is unknown and clients MUST NOT assume it is zero, although they MAY choose to calculate it themselves
hash String reversed hash of complete transaction (with witness data included) encoded in hexadecimal

Transactions with witness data may only be included if the template's "rules" list (see BIP 9) includes "segwit".

Sigops

For templates with "segwit" enabled as a rule, the "sigoplimit" and "sigops" keys must use the new values as calculated in BIP 141.

Block Assembly with Witness Transactions

When block assembly is done without witness transactions, no changes are made by this BIP, and it should be assembled as previously.

When witness transactions are included in the block, the primary merkle root MUST be calculated with those transactions' "txid" field instead of "hash". A secondary merkle root MUST be calculated as per BIP 141's commitment structure specification to be inserted into the generation (coinbase) transaction.

Servers MUST NOT include a commitment in the "coinbasetxn" key on the template. Clients MUST insert the commitment as an additional output at the end of the final generation (coinbase) transaction. Only if the template includes a "mutable" key (see BIP 23 Mutations) including "generation", the client MAY in that case place the commitment output in any position it chooses, provided that no later output matches the commitment pattern.

Motivation

Segregated witness substantially changes the structure of blocks, so the previous getblocktemplate specification is no longer sufficient. It additionally also adds a new way of counting resource limits, and so GBT must be extended to convey this information correctly as well.

Rationale

Why doesn't "weightlimit" simply redefine the existing "sizelimit"?

  • "sizelimit" is already enforced by clients by counting the sum of bytes in transactions' "data" keys.
  • Servers may wish to limit the overall size of a block, independently from the "weight" of the block.

Why is "sigoplimit" redefined instead of a new "sigopweightlimit" being added?

  • The old limit was already arbitrarily defined, and could not be counted by clients on their own anyway. The concept of "sigop weight" is merely a change in the arbitrary formula used.

Why is "sigoplimit" divided by 4?

  • To resemble the previous values. (FIXME: is this a good reason? maybe we shouldn't divide it?)

Why is the witness commitment required to be added to the end of the generation transaction rather than anywhere else?

  • Servers which do not allow modification of the generation outputs ought to be checking this as part of the validity of submissions. By requiring a specific placement, they can simply strip the commitment and do a byte-for-byte comparison of the outputs. Placing it at the end avoids the possibility of a later output matching the pattern and overriding it.

Why shouldn't the server simply add the commitment upfront in the "coinbasetxn", and simply send the client stripped transaction data?

  • It would become impossible for servers to specify only "coinbasevalue", since clients would no longer have the information required to construct the commitment.
  • getblocktemplate is intended to be a *decentralised* mining protocol, and allowing clients to be blinded to the content of the block works contrary to that purpose.
  • BIP 23's "transactions" mutations allow the client to modify the transaction-set on their own, which is impossible without the complete transaction data.

Reference Implementation

See Also

Copyright

This BIP is dual-licensed under the Open Publication License and BSD 2-clause license.