Skip to content

Fix GBT: Restore "!segwit" and "csv" to "rules" key #17946

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 19, 2020

Conversation

luke-jr
Copy link
Member

@luke-jr luke-jr commented Jan 17, 2020

#16060 removed CSV & segwit from versionbits, breaking the "rules" key returned by GBT.

Without this, miners don't know they're mining segwit blocks, and should fall back to pre-segwit block creation.

@fanquake fanquake requested a review from jnewbery January 17, 2020 06:13
@ryanofsky
Copy link
Contributor

ryanofsky commented Jan 17, 2020

Comments in IRC provide some context: without the information in rules field "miners have no way to know what rules are being used and might produce invalid blocks"

@jnewbery
Copy link
Contributor

Discussion in 16060 is here: #16060 (comment)

@luke-jr
Copy link
Member Author

luke-jr commented Jan 17, 2020

(For clarity, I didn't mean fixing this bug in a separate PR, but rather the missing "!" and/or bad name/description of the gbt_force flag.)

Copy link
Contributor

@jnewbery jnewbery left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@luke-jr : The rules field hasn't been populated with "!segwit" since 0.15 (#9955 changed the behaviour so that "segwit" would be included as a rule instead of "!segwit").

In IRC you stated that "miners have no way to know what rules are being used and might produce invalid blocks". Do you have any additional information about that? In what way would miners produce invalid blocks? Do you know of any miners that have had a problem because of this?

I don't have any objection to this change, but I'd like to better understand how miners have been impacted by this.

@luke-jr
Copy link
Member Author

luke-jr commented Jan 17, 2020

#9955 introduced a bug, sure, but that bug would only have impacted Segwit-unaware miners. Segwit-aware miners would have continued to work correctly because they saw that segwit was an active rule.

Removing the rule entirely means that sigops are counted differently, and transactions may not include witness data. I don't know if there are any real-world miners impacted by this, but it is at least theoretically possible (IIRC, at least some branches of Eloipool support a safety trim based on sigop counts).

@jnewbery
Copy link
Contributor

that bug would only have impacted Segwit-unaware miners.

I think you have this the wrong way round. Segwit-unaware miners would see "segwit" in the rules, but according to BIP 9:

Without this ["!"] prefix, GBT clients may assume the rule will not impact usage of the template as-is;

and so the segwit-unaware miner would use the template, but not be able to add the witness commitment to the coinbase.

sigops are counted differently

Since #14811, the GBT request must include "segwit" in the rule array, so sigops are always counted according to BIP 141 rules. Whether or not the return object includes "segwit" in the rules doesn't change this.

In any case, I think it's fine to make this change because it doesn't really matter. Segwit has been active for two years and all miners using 0.18 onwards have to set "segwit" in the rules. I find it very hard to believe that any are reading what's returned in the rules field.

@luke-jr
Copy link
Member Author

luke-jr commented Jan 18, 2020

I think you have this the wrong way round. Segwit-unaware miners would see "segwit" in the rules,

They would fail by mining invalid blocks, instead of failing explicitly. Either way, they fail.

Segwit-capable miners, on the other hand, shouldn't fail, but might because they think they're mining a non-segwit block.

Since #14811, the GBT request must include "segwit" in the rule array, so sigops are always counted according to BIP 141 rules.

The request rule doesn't affect sigop counting, only indicates the client can understand a segwit template. Sigop counting is enabled only when the template has segwit in its rules list.

@jameshilliard
Copy link
Contributor

FYI without this mining with ckpool breaks since it will only try to produce segwit blocks when the segwit rule is seen.

@@ -212,6 +207,7 @@ def run_test(self):
assert tmpl['sigoplimit'] == 80000
assert tmpl['transactions'][0]['txid'] == txid
assert tmpl['transactions'][0]['sigops'] == 8
assert '!segwit' in tmpl['rules']
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't we also test for 'csv' being present here?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Going to merge this to not invalidate ACKs. Test improvements are welcome and can be submitted in a follow-up

@jnewbery
Copy link
Contributor

FYI without this mining with ckpool breaks since it will only try to produce segwit blocks when the segwit rule is seen.

@jameshilliard can you point me at the code that does that? The only getblocktemplate "rules" handling code I was able to find in ckpool was checking that the gbt response doesn't contain an unknown rule: https://bitbucket.org/ckolivas/ckpool/src/73f560cf3144f824823077c1b9e1663d89823ed7/src/bitcoin.c#lines-127

@jameshilliard
Copy link
Contributor

@jnewbery Well here's the workaround ck had to apply.

@sipa
Copy link
Member

sipa commented May 18, 2020

ACK 412d5fe

@jnewbery
Copy link
Contributor

Thanks for the references, James.

Tested ACK 412d5fe.

@maflcko maflcko merged commit aa8d768 into bitcoin:master May 19, 2020
@jnewbery
Copy link
Contributor

This should be backported to v0.20.

@maflcko
Copy link
Member

maflcko commented May 19, 2020

This this need a new rc? Maybe not for a two-line change?

I suggest either creating a backport pr or bringing it up in the meeting, so that it is not forgotten.

sidhujag pushed a commit to syscoin/syscoin that referenced this pull request May 19, 2020
412d5fe QA: feature_segwit: Check that template "rules" includes "!segwit" as appropriate (Luke Dashjr)
2abe8cc Bugfix: Include "csv","!segwit" in "rules" (Luke Dashjr)

Pull request description:

  bitcoin#16060 removed CSV & segwit from versionbits, breaking the "rules" key returned by GBT.

  Without this, miners don't know they're mining segwit blocks, and should fall back to pre-segwit block creation.

ACKs for top commit:
  sipa:
    ACK 412d5fe
  jnewbery:
    Tested ACK 412d5fe.

Tree-SHA512: 825d72e257dc0dd4941f2fe498d8d4f4f2a21b9505cd21a8f9eb7fb5d6d7dd9219347928cf90bb57a777920ce24295859763e64fa8a22ebb58fc2380f80f5615
@maflcko maflcko added this to the 0.19.2 milestone May 19, 2020
fanquake pushed a commit to fanquake/bitcoin that referenced this pull request May 20, 2020
They have been missing since buried deployments were merged

Github-Pull: bitcoin#17946
Rebased-From: 2abe8cc
fanquake pushed a commit to fanquake/bitcoin that referenced this pull request May 20, 2020
@fanquake fanquake mentioned this pull request May 20, 2020
maflcko pushed a commit that referenced this pull request Jun 2, 2020
412d5fe QA: feature_segwit: Check that template "rules" includes "!segwit" as appropriate (Luke Dashjr)
2abe8cc Bugfix: Include "csv","!segwit" in "rules" (Luke Dashjr)

Pull request description:

  Original branch merges cleanly (no rebase needed)

  See also #17946

ACKs for top commit:
  jnewbery:
    utACK 412d5fe

Tree-SHA512: 8b269f7782c10f02dc245cc377d91f594474eade6a32184a49fa2ed3928d91917e4b83eefee6947bfb5ffff54eca2781f8cf2169c1f0ad3fefca1d4b3cf304dd
maflcko pushed a commit that referenced this pull request Aug 11, 2020
be95147 Updated appveyor job to checkout a specific vcpkg commit ID. (Aaron Clauson)
1fd9cd2 appveyor: Remove clcache (MarcoFalke)
8c0a959 Remove cached directories and associated script blocks from appveyor CI configuration. (Aaron Clauson)
d70f700 lint: fix shellcheck URL in CI install (fanquake)
f8f7d91 test: remove Cirrus CI FreeBSD job (fanquake)
b7e16a8 Add missing QPainterPath include (Andrew Chow)
30a2814 gui: Avoid Wallet::GetBalance in WalletModel::pollBalanceChanged (João Barbosa)
0d87a5b QA: feature_segwit: Check that template "rules" includes "!segwit" as appropriate (Luke Dashjr)
bde6a5a Bugfix: Include "csv","!segwit" in "rules" (Luke Dashjr)
e422f65 build: Set libevent minimum version to 2.0.21 (Hennadii Stepanov)
0d0dd6a Update with new Windows code signing certificate (Andrew Chow)

Pull request description:

  Backports the following to the 0.19 branch:

  * #17946 - Fix GBT: Restore "!segwit" and "csv" to "rules" key
  * #18160 - gui: Avoid Wallet::GetBalance in WalletModel::pollBalanceChanged
  * #18425 - releases: Update with new Windows code signing certificate
  * #18676 - build: Check libevent minimum version in configure script
  * #19097 - qt: Add missing QPainterPath include (as per #19510)
  * #18640 - appveyor: Remove clcache
  * #19444 - test: Remove cached directories and associated script blocks from appveyor config
  * #19612 - lint: fix shellcheck URL in CI install
  * #18001 -  Updated appveyor job to checkout a specific vcpkg commit ID

  Closes: #19510.

ACKs for top commit:
  jnewbery:
    ACK be95147
  MarcoFalke:
    cherry-pick ACK be95147 🌎

Tree-SHA512: 2ec7e3ae1da99799ff6f8cfe26095d6885cffe6952b18a7e236dc5e657b3918225c2601b8c8e17cdff5319c40cb0a214d9fad49b0ff2f54af1db7c81d83a1df5
@Sjors Sjors mentioned this pull request Oct 17, 2020
MarkLTZ added a commit to litecoinz-core/litecoinz that referenced this pull request Oct 22, 2020
@bitcoin bitcoin locked as resolved and limited conversation to collaborators Feb 15, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants