Skip to content

Conversation

sdaftuar
Copy link
Member

@sdaftuar sdaftuar commented Mar 8, 2017

Segwit's version bit will be signalled for all invocations of CreateNewBlock,
and not specifying segwit only will cause CreateNewBlock to skip transactions
with witness from being selected. (Note that CreateNewBlock's performance may suffer if the mempool has witness transactions that are being skipped, so this is not a recommended configuration.)

Originally we didn't signal segwit unless the getblocktemplate caller explicitly indicated support, in order to prevent segwit from activating before any miners actually had support for the witness commitment. Now that many blocks are signalling segwit already, this is not a material concern.

Also, I need to figure out how to add a test to segwit.py to check that witness transactions would in fact be skipped.

As per IRC discussion, I think we should consider this for backport to the 0.14 branch.

Copy link
Contributor

@gmaxwell gmaxwell left a comment

Choose a reason for hiding this comment

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

Concept ACK.

#assert_raises_jsonrpc(-8, "Support for 'segwit' rule requires explicit client support", self.nodes[0].getblocktemplate, {})
tmpl = self.nodes[0].getblocktemplate()
# TODO: add a transaction with witness to mempool, and verify it's not
# selected for mining.
Copy link
Member

Choose a reason for hiding this comment

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

Should test that witness tx can't sneak in as an ancestor of non-witness, too.

Copy link
Member Author

Choose a reason for hiding this comment

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

I concur.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done in 7db565c

@@ -683,7 +689,6 @@ UniValue getblocktemplate(const JSONRPCRequest& request)
result.push_back(Pair("bits", strprintf("%08x", pblock->nBits)));
result.push_back(Pair("height", (int64_t)(pindexPrev->nHeight+1)));

const struct BIP9DeploymentInfo& segwit_info = VersionBitsDeploymentInfo[Consensus::DEPLOYMENT_SEGWIT];
if (!pblocktemplate->vchCoinbaseCommitment.empty() && setClientRules.find(segwit_info.name) != setClientRules.end()) {
Copy link
Member

Choose a reason for hiding this comment

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

Use fMineWitnessTransactions here?

Copy link
Member Author

Choose a reason for hiding this comment

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

Addressed in 24428bd.

@@ -533,7 +539,7 @@ UniValue getblocktemplate(const JSONRPCRequest& request)

// Create new block
CScript scriptDummy = CScript() << OP_TRUE;
pblocktemplate = BlockAssembler(Params()).CreateNewBlock(scriptDummy);
pblocktemplate = BlockAssembler(Params()).CreateNewBlock(scriptDummy, fMineWitnessTransactions);
Copy link
Member

Choose a reason for hiding this comment

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

This is cached across calls, so it requires a bit more complexity.

Copy link
Member Author

Choose a reason for hiding this comment

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

I think I fixed this in 24428bd.

@JeremyRubin
Copy link
Contributor

Maybe transactions with a witness should not get inserted into the mempool?

@sdaftuar
Copy link
Member Author

sdaftuar commented Mar 9, 2017

Maybe transactions with a witness should not get inserted into the mempool?

@JeremyRubin Sure, and miners could also continue to use 0.13.0 or older for getblocktemplate (while submitting their blocks to later version software, which would work just fine post-segwit activation). Many working configurations are possible; I think we're just trying to add a simple way to support more miners out of the box. Personally I don't think it's worth making big code changes -- like redoing mempool policy on the fly for miners who aren't invoking gbt with segwit support -- to achieve this functionality, as this isn't a recommended setup, just a tolerable one.

(If we wanted to make CNB fast in this configuration, then I think the easiest thing to do would be to say add an int to each mempool entry that counts the number of ancestors that have witnesses, and use that skip over transactions faster in CNB, but this doesn't seem worth it to me.)

Copy link
Member

@luke-jr luke-jr left a comment

Choose a reason for hiding this comment

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

utACK (might be better to have two caches, but I doubt it matters)

@laanwj
Copy link
Member

laanwj commented Mar 9, 2017

Concept ACK

@sdaftuar
Copy link
Member Author

sdaftuar commented Mar 9, 2017

Added a test to segwit.py

@laanwj laanwj added this to the 0.14.1 milestone Mar 9, 2017
@sdaftuar sdaftuar force-pushed the 2017-03-mining-segwit-changes branch from 7db565c to a4a20d8 Compare March 10, 2017 13:30
@sdaftuar
Copy link
Member Author

Rebased (conflict was in segwit.py) and squashed the fixup commit.

@TheBlueMatt
Copy link
Contributor

utACK a4a20d8a8de77b45e33cbdb8018dc30c9176fccd

@gmaxwell
Copy link
Contributor

ACK.

Had to go refresh myself on the proper meaning of the "!' prefix. Perhaps the documentation (e.g. BIPs) should be updated to give that a name, "Mandatory prefix". BIP 145 also needs a clear and direct call out to the extensions established in BIP9, not after it's already using them. Otherwise it's easily confusing. :)

@laanwj
Copy link
Member

laanwj commented Mar 14, 2017

Merge conflict in segwit.py after #9970

Segwit's version bit will be signalled for all invocations of CreateNewBlock,
and not specifying segwit only will cause CreateNewBlock to skip transactions
with witness from being selected.
@sdaftuar sdaftuar force-pushed the 2017-03-mining-segwit-changes branch from a4a20d8 to c85ffe6 Compare March 14, 2017 10:52
@sdaftuar
Copy link
Member Author

Rebased.

@laanwj laanwj merged commit c85ffe6 into bitcoin:master Mar 14, 2017
laanwj added a commit that referenced this pull request Mar 14, 2017
…alling or mining

c85ffe6 Test transaction selection when gbt called without segwit support (Suhas Daftuar)
abe7b3d Don't require segwit in getblocktemplate for segwit signalling or mining (Suhas Daftuar)

Tree-SHA512: 172496b6d7cdf1879de1266748f2b4ed9fd2ba9ff4a1fd964d74d73c674c16d74bf01a3ba42bf25f2d69f348217c0bbf3412ac64821f222efc9de25a287a5240
sdaftuar added a commit to sdaftuar/bitcoin that referenced this pull request Mar 16, 2017
Segwit's version bit will be signalled for all invocations of CreateNewBlock,
and not specifying segwit only will cause CreateNewBlock to skip transactions
with witness from being selected.

Github-Pull: bitcoin#9955
Rebased-From: abe7b3d
sdaftuar added a commit to sdaftuar/bitcoin that referenced this pull request Mar 16, 2017
@ajtowns ajtowns mentioned this pull request Jul 31, 2019
@bitcoin bitcoin locked as resolved and limited conversation to collaborators Sep 8, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants