[0.17] blockheaders include block height, nodes validate it - #431
Conversation
2a12b30 to
a89d0eb
Compare
jtimon
left a comment
There was a problem hiding this comment.
Also, could use a rebase and move the -con_blockheightinheader to chainparams.
| READWRITE(hashPrevBlock); | ||
| READWRITE(hashMerkleRoot); | ||
| READWRITE(nTime); | ||
| if (gArgs.GetBoolArg("-con_blockheightinheader", true)) { |
There was a problem hiding this comment.
I think you need g_block_height_in_header here too
a89d0eb to
32c7386
Compare
commented
Oct 16, 2018
|
forgot to push my fixes that I believe fixed things. Will switch to chainparams setup next. |
32c7386 to
d8ee236
Compare
commented
Oct 18, 2018
|
Feature complete now, just no tests. |
04c8fe5 to
97b714f
Compare
| genesis = CreateGenesisBlock(1231006505, 2083236893, 0x1d00ffff, 1, 50 * COIN); | ||
| consensus.hashGenesisBlock = genesis.GetHash(); | ||
| assert(consensus.hashGenesisBlock == uint256S("0x000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f")); | ||
| consensus.blockheight_in_header = gArgs.GetBoolArg("-con_blockheightinheader", false); |
There was a problem hiding this comment.
No, just don't use -con_blockheightinheader at all outside of CCustomParams and you shouldn't need to touch neither CMainParams, CTestNetParams or CRegTestParams, specially not their asserts.
Perhaps it would be interesting to rebase on top of #436 and add a test like this:
{
'memo': 'default_style with height in header',
'genesis': 'c03f16ae9e2980de2b61fd6dc84af8ac4a37bea928af632166a6b36c5c871ddd',
'args': [
'-con_genesis_style=default_style',
'-con_blockheightinheader',
],
},
There was a problem hiding this comment.
It creates a new style genesis block for each network when iterating through network types during load, then hits the assert.
There was a problem hiding this comment.
That means blockheight_in_header is not really acting as false for main, test and regtest, no?
There was a problem hiding this comment.
It is, if you don't set -con_blockheightinheader to true
97b714f to
3f3b3ab
Compare
commented
Oct 22, 2018
|
I'm getting build failures for windows and other builds due to |
commented
Oct 22, 2018
|
tricked PR to refresh by closing/opening |
ba230a7 to
529efb1
Compare
529efb1 to
02bfec8
Compare
commented
Oct 25, 2018
|
Took essential fixes from #442 and squashed. |
02bfec8 to
15e8f6e
Compare
commented
Oct 26, 2018
|
Rebased, fixed some tests. |
e4a3331 to
977ea1a
Compare
commented
Oct 29, 2018
|
Finally resolves all issues and tests. Ready for review. |
commented
Oct 31, 2018
|
Note that for me many tests fail with |
commented
Oct 31, 2018
|
@mword ah good catch. Will take a look. |
commented
Nov 1, 2018
|
Looks like upstream moved all but two tests into the normal testing regime. We should probably mirror that if possible. |
977ea1a to
29763da
Compare
commented
Nov 5, 2018
|
rebased onto tip to catch most extended failures |
51a9458 to
a8c6fcd
Compare
commented
Nov 5, 2018
|
All builds passing, squashed. |
commented
Nov 6, 2018
|
tACK with one caveat: I ran test_runner.py twice once with --extended and then once without, the second run (without --extended) the rpc_rawtransaction.py test failed. I could not reproduce the failure. I ran test_runner.py again several with no problems and I ran the rpc_rawtransaction.py test by itself a number of times with no failures. |
commented
Nov 6, 2018
|
tACK a8c6fcd |
commented
Nov 13, 2018
|
will cherry-pick Blockstream/liquid#3 when merged |
commented
Nov 15, 2018
|
ACK when you merge liquid#3 :) |
commented
Nov 15, 2018
|
@stevenroose oh it appears I already mirror this logic in liquid#3, great minds yada yada |
commented
Nov 19, 2018
via email
|
It's never (de)serialed as non zero if not active. I can add the logic of
it makes you uncomfortable.
…On Mon, Nov 19, 2018, 5:32 PM Luke Dashjr ***@***.*** wrote:
***@***.**** commented on this pull request.
------------------------------
In src/chain.h
<#431 (comment)>
:
> @@ -403,6 +411,7 @@ class CDiskBlockIndex : public CBlockIndex
READWRITE(hashPrev);
READWRITE(hashMerkleRoot);
READWRITE(nTime);
+ READWRITE(block_height);
I don't understand why this doesn't matter. Bitcoin block indexes sure
won't have height here...
—
You are receiving this because you modified the open/close state.
Reply to this email directly, view it on GitHub
<#431 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AFgC07ez5yBT_9TmSEVIhSFxuoStdBKAks5uwzF9gaJpZM4XaAR->
.
|
| READWRITE(hashPrev); | ||
| READWRITE(hashMerkleRoot); | ||
| READWRITE(nTime); | ||
| READWRITE(block_height); |
There was a problem hiding this comment.
I don't understand why this doesn't need to be conditional. Bitcoin block indexes sure won't have height here...
There was a problem hiding this comment.
I'm not sure myself, but Greg discussed it with Jorge here: #431 (comment)
| // No subsidy for custom chains by default | ||
| consensus.genesis_subsidy = args.GetArg("-con_blocksubsidy", 0); | ||
|
|
||
| // Note: This global is needed to avoid circular dependency |
There was a problem hiding this comment.
with chainparams (ie if the global was a field in chainparams), because chainparams depends on block.
| pblock->hashPrevBlock = pindexPrev->GetBlockHash(); | ||
| UpdateTime(pblock, chainparams.GetConsensus(), pindexPrev); | ||
| if (g_con_blockheightinheader) { | ||
| pblock->block_height = nHeight; |
There was a problem hiding this comment.
Assignment probably doesn't need to be conditional.
| WITNESS_COMMITMENT_HEADER = b"\xaa\x21\xa9\xed" | ||
|
|
||
| def create_block(hashprev, coinbase, ntime=None): | ||
| def create_block(hashprev, coinbase, block_height, ntime=None): |
There was a problem hiding this comment.
Modifying the function signature like this is begging for silent bugs.
Instead, add block_height to the end, and always specify it by name (enforce with PEP 3102; ie, (hashprev, coinbase, ntime=None, *, block_height)).
There was a problem hiding this comment.
Ah that's what the random asterixes are for! :) Thanks
There was a problem hiding this comment.
Another option is to make ntime non optional.
| WITNESS_COMMITMENT_HEADER = b"\xaa\x21\xa9\xed" | ||
|
|
||
| def create_block(hashprev, coinbase, ntime=None): | ||
| def create_block(hashprev, coinbase, block_height, ntime=None): |
There was a problem hiding this comment.
Now that block_height is provided here, suggest making coinbase optional since almost all uses just call create_coinbase(block_height). Probably doesn't matter much unless/until this goes upstream...
There was a problem hiding this comment.
I'd have to implement a CScriptNum encoder in python.... sigh I'll do it :)
There was a problem hiding this comment.
Huh? create_coinbase (and serialize_script_num) already exists..
There was a problem hiding this comment.
de-serialize*. I want to grab it directly from the coinbase.
commented
Nov 19, 2018
Why wouldn't it take an existing CBlockIndex serialisation, and turn that bits into height, and nonce into bits? |
| gArgs.AddArg("-seednode=<ip>", "Use specified node as seed node. This option can be specified multiple times to connect to multiple nodes. (custom only)", true, OptionsCategory::CHAINPARAMS); | ||
| gArgs.AddArg("-con_blocksubsidy", "Defines the amount of block subsidy to start with, at genesis block.", false, OptionsCategory::CHAINPARAMS); | ||
| gArgs.AddArg("-con_connect_coinbase", "Connect outputs in genesis block to utxo database.", false, OptionsCategory::CHAINPARAMS); | ||
| gArgs.AddArg("-con_blockheightinheader", "Whether the chain includes the block height directly in the header, for easier validation of block height in low-resource environments.", false, OptionsCategory::CHAINPARAMS); |
There was a problem hiding this comment.
Perhaps indicate that defaults to true here?
commented
Nov 22, 2018
|
I dislike that this modifies many unrelated tests (because the new option defaults to true) instead of just copying or creating a specific one to test this. That's bad for rebases. |
commented
Nov 22, 2018
via email
|
The testing it provides is valuable (caught a number of things I hadn't
considered) but yes more effort could be made to not have so many lines
change. I need a python implementation of CScruptNum encoding IIRC to not
require a bunch of additional arguments everywhere.
…On Thu, Nov 22, 2018, 2:09 PM Jorge Timón ***@***.*** wrote:
I dislike that this modifies many unrelated tests (because the new option
defaults to true) instead of just copying or creating a specific one to
test this. That's bad for rebases.
Is it really necessary to default to true?
—
You are receiving this because you modified the open/close state.
Reply to this email directly, view it on GitHub
<#431 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AFgC01yByyEepugV8U7BZygUdZZvmPeqks5uxvZzgaJpZM4XaAR->
.
|
commented
Nov 22, 2018
|
Or you can just change the default to false, no? Perhaps duplicate and modify some tests if that has value, but run all of them with this set to true. |
commented
Nov 22, 2018
via email
|
We duplicated the tests do we're already testing with it off. Testing with
it on as well allows better testing coverage when possible. I can take a
look at the tests and see if we're testing anything meaningful. If not I
can break out a new test I guess that specifically tests what we care
about.
…On Thu, Nov 22, 2018, 2:14 PM Jorge Timón ***@***.*** wrote:
Or you can just change the default to false, no? Perhaps duplicate and
modify some tests if that has value, but run all of them with this set to
true.
What am I missing?
—
You are receiving this because you modified the open/close state.
Reply to this email directly, view it on GitHub
<#431 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AFgC006W5VysegSHwEND83UCtS64vkKeks5uxveqgaJpZM4XaAR->
.
|
commented
Nov 26, 2018
|
Pushed an update that is able to extract the block height directly from the coinbase input, and places it in the header. This shrinks the test diff by quite a bit. |
5d0d66c to
5a5941a
Compare
commented
Nov 26, 2018
|
squashed, passing tests, and ready for final review |
The block height validation is gated by the startup option `con_blockheightinheader`, accesible in custom chains only using option `chain=<name>`. Only if set to true will this field be (de)serialized and evaluated in consensus logic. Otherwise the field is simply ignored, other than being stored in memory as the default value 0.
5a5941a to
2bfabb3
Compare
commented
Nov 27, 2018
|
rebased and added default value message in help of true(assuming custom chains since that will be default later) |
commented
Nov 27, 2018
|
cool, tACK 2bfabb3! |
The feature is enabled by default in custom chains; cannot be activated in legacy chains.