namecoin / namecoin-core

Namecoin full node + wallet based on the current Bitcoin Core codebase.
https://www.namecoin.org/
MIT License
463 stars 147 forks source link

getblocktemplate does not indicate segwit activated #330

Open DrHaribo opened 5 years ago

DrHaribo commented 5 years ago

Even after segwit is activated namecoind's getblocktemplate does not indicate that this is so in the rules section of the json data that is returned.

namecoind:

  "rules": [
  ],

bitcoind:

  "rules": [
    "csv",
    "segwit"
  ],
JeremyRand commented 5 years ago

CSV was activated in Namecoin at the same time as SegWit. The fact that both of them are missing for Namecoin's GBT output is interesting.

@domob1812 Is this disparity likely to be because CSV and SegWit were activated via BIP 9 in Bitcoin but via UASF in Namecoin?

@DrHaribo based on your experience with mining workflow, is this likely to be an explanation for why both Poolin and Slush believed their systems would enforce the softfork but ended up mining invalid blocks when the softfork activated (which they later were able to correct)?

domob1812 commented 5 years ago

Interesting! The rules are filled in here: https://github.com/namecoin/namecoin-core/blob/5026155158efb285079f088a3812e090dec5c246/src/rpc/mining.cpp#L581-L622

This code only takes BIP9 into account, so that's presumably the reason. Note that Bitcoin 0.19 also changed activation of Segwit and CSV retrospectively to be based on a block height, so I guess that version also won't include them in the result (as opposed to Bitcoin 0.18).

DrHaribo commented 5 years ago

@JeremyRand this could very well be the reason some pools would have issues.

Here is the (extra paranoid) logic I use to determine whether to make a segwit block:

Use segwit if the rules list contains "segwit" OR if the rules list contains "!segwit" OR if the transactions list has at least one transaction with a txid that differs from its hash.

If you are missing that last part then you could (because of this bug) end up making non-segwit blocks containing segwit transactions.

domob1812 commented 5 years ago

Indeed, that sounds like a plausible explanation. For the future, is there any point in not just always creating a segwit block, though?

Especially with the Bitcoin change I mentioned (version 0.19 has the segwit activation "buried" and won't list it as BIP9 anymore), this is likely something that pools should do anyway.

DrHaribo commented 5 years ago

True, using this type of logic is mostly useful during the transition or if you have generic code handling other cryptocurrencies. If you only mine BTC+NMC then you could hardcode it at this point.

JeremyRand commented 5 years ago

Thanks for the explanation @DrHaribo . I'm going to check with Poolin and Slush to see whether they can confirm or refute whether that was the cause of the issues they encountered.