Join GitHub today
GitHub is home to over 20 million developers working together to host and review code, manage projects, and build software together.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
Already on GitHub? Sign in to your account
Add preciousblock RPC #6996
Conversation
laanwj
added
RPC/REST/ZMQ
Validation
labels
Nov 12, 2015
|
This was suggested in #6995. |
sipa
referenced this pull request
Nov 12, 2015
Open
the RPC should have commands to specify the side of a fork considered 'current' #6995
kanoi
commented
Nov 12, 2015
|
Awesome name :) |
|
Concept ACK. This needs to document that overriding the first seen block behavior in slows network convergence and can increase the rate of long reorganizations. |
MarcoFalke
and 1 other
commented on an outdated diff
Nov 12, 2015
| + { | ||
| + LOCK(cs_main); | ||
| + if (mapBlockIndex.count(hash) == 0) | ||
| + throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Block not found"); | ||
| + | ||
| + pblockindex = mapBlockIndex[hash]; | ||
| + } | ||
| + | ||
| + CValidationState state; | ||
| + PreciousBlock(state, Params().GetConsensus(), pblockindex); | ||
| + | ||
| + if (!state.IsValid()) { | ||
| + throw JSONRPCError(RPC_DATABASE_ERROR, state.GetRejectReason()); | ||
| + } | ||
| + | ||
| + return NullUniValue; |
MarcoFalke
Member
|
|
I would prefer if it would only prefer the given block over other blocks that arrived within, eg, 10 seconds of the other block in question. On November 12, 2015 3:59:35 AM PST, Pieter Wuille notifications@github.com wrote:
|
|
@TheBlueMatt That would be a much larger change, as we don't track receive time. |
|
Indeed, not sure it's worth it, but would prefer if we could :). On November 12, 2015 12:33:08 PM PST, Pieter Wuille notifications@github.com wrote:
|
|
utACK |
|
I'm sympathetic with matt's ask; but I don't think it's worth it-- it'll get bypassed (which then puts parties back into a mode of modifying the consensus code), and it would imply that 10 seconds was "safe"-- I have no idea if it is... the inherent preference for your own blocks by virtue of hearing the first already hurts convergence; so I think it would be fair to say that no amount additional is "safe"... but having a well constructed option is much safer than people trying to achieve this with invalidateblock. |
kanoi
commented
Nov 13, 2015
|
Well any numerical limitation would of course only require a few bytes of code change to circumvent so would seem to be somewhat a waste of time considering the extra work involved: as @sipa suggests |
|
@gmaxwell What do you mean by 'saturate' ? |
|
Ok, changed the approach a bit. It now only keeps a counter per tip, and resets it when more work was added. |
|
By saturate I mean what you did, sat_add(int_min, -1) = int_min |
|
Rebased. |
|
ut ACK |
|
There is a bug in the unit tests that can lead to a race condition. |
|
Fixed. |
|
Rebased. |
sdaftuar
commented on an outdated diff
Dec 14, 2015
| + self.nodes.append(start_node(1, self.options.tmpdir, ["-debug"])) | ||
| + self.nodes.append(start_node(2, self.options.tmpdir, ["-debug"])) | ||
| + | ||
| + def run_test(self): | ||
| + print "Mine blocks A-B-C on Node 0" | ||
| + self.nodes[0].generate(3) | ||
| + assert(self.nodes[0].getblockcount() == 3) | ||
| + hashC = self.nodes[0].getbestblockhash() | ||
| + print "Mine competing blocks E-F-G on Node 1" | ||
| + self.nodes[1].generate(3) | ||
| + assert(self.nodes[1].getblockcount() == 3) | ||
| + hashG = self.nodes[1].getbestblockhash() | ||
| + assert(hashC != hashG) | ||
| + print "Connect nodes and check no reorg occurs" | ||
| + connect_nodes_bi(self.nodes,0,1) | ||
| + sync_blocks(self.nodes[0:2]) |
sdaftuar
Member
|
sdaftuar
commented on an outdated diff
Dec 14, 2015
| + assert(self.nodes[1].getblockcount() == 3) | ||
| + hashG = self.nodes[1].getbestblockhash() | ||
| + assert(hashC != hashG) | ||
| + print "Connect nodes and check no reorg occurs" | ||
| + connect_nodes_bi(self.nodes,0,1) | ||
| + sync_blocks(self.nodes[0:2]) | ||
| + assert(self.nodes[0].getbestblockhash() == hashC) | ||
| + assert(self.nodes[1].getbestblockhash() == hashG) | ||
| + print "Make Node0 prefer block G" | ||
| + self.nodes[0].preciousblock(hashG) | ||
| + assert(self.nodes[0].getbestblockhash() == hashG) | ||
| + print "Make Node0 prefer block C again" | ||
| + self.nodes[0].preciousblock(hashC) | ||
| + assert(self.nodes[0].getbestblockhash() == hashC) | ||
| + print "Make Node1 prefer block C" | ||
| + self.nodes[1].preciousblock(hashC) |
sdaftuar
Member
|
|
Needs rebase |
luke-jr
commented on an outdated diff
Feb 12, 2016
| + | ||
| +# | ||
| +# Test PreciousBlock code | ||
| +# | ||
| + | ||
| +from test_framework.test_framework import BitcoinTestFramework | ||
| +from test_framework.util import * | ||
| + | ||
| +class PreciousTest(BitcoinTestFramework): | ||
| + def setup_chain(self): | ||
| + print("Initializing test directory "+self.options.tmpdir) | ||
| + initialize_chain_clean(self.options.tmpdir, 3) | ||
| + | ||
| + def setup_network(self): | ||
| + self.nodes = [] | ||
| + self.is_network_split = False |
|
|
added a commit
to luke-jr/bitcoin
that referenced
this pull request
Feb 13, 2016
|
This can break CheckBlockIndex: if (pindex->nChainTx == 0) assert(pindex->nSequenceId == 0); // nSequenceId can't be set for blocks that aren't linkedThis assumption is no longer true if we use preciousblock on a not-yet-downloaded block (and this can occur in the RPC test). |
|
Needs rebase. |
MarcoFalke
commented on an outdated diff
Jun 3, 2016
| @@ -0,0 +1,87 @@ | ||
| +#!/usr/bin/env python2 |
MarcoFalke
Member
|
|
needs rebase |
laanwj
added
the
Feature
label
Jun 16, 2016
added a commit
to bitcoinknots/bitcoin
that referenced
this pull request
Jun 28, 2016
added a commit
to bitcoinknots/bitcoin
that referenced
this pull request
Aug 6, 2016
|
Pushed a rebase to my repo |
|
Are you still planning to do this? |
|
@luke-jr Your rebase does not fix the comment you made here: #6996 (comment) ? |
MarcoFalke
commented on an outdated diff
Aug 26, 2016
| @@ -0,0 +1,87 @@ | ||
| +#!/usr/bin/env python3 | ||
| +# Copyright (c) 2015 The Bitcoin Core developers | ||
| +# Distributed under the MIT software license, see the accompanying | ||
| +# file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||
| + | ||
| +# | ||
| +# Test PreciousBlock code | ||
| +# | ||
| + | ||
| +from test_framework.test_framework import BitcoinTestFramework | ||
| +from test_framework.util import * | ||
| + | ||
| +class PreciousTest(BitcoinTestFramework): | ||
| + def setup_chain(self): |
|
|
sipa
added some commits
Aug 26, 2016
|
@luke-jr Ah, a link to that would have been useful :) I've squashed the fixes and split into 2 commits. |
|
utACK 5805ac8 |
laanwj
merged commit 5805ac8
into
bitcoin:master
Oct 18, 2016
1 check passed
added a commit
that referenced
this pull request
Oct 18, 2016
|
utACK 5805ac8 |
|
that was a surprise merge! Are there any plans that anyone knows of to use this? I would love to see some use-cases for documentation purposes. |
sipa commentedNov 12, 2015
This adds a new PRC 'preciousblock' to mark a block as precious. A precious block will be treated as if it was received earlier than any other competing block.