Skip to content

Commit cc3a06b

Browse files
laanwjcodablock
authored andcommitted
Merge bitcoin#7863: getblockchaininfo: make bip9_softforks an object, not an array.
d12760b rpc-tests: handle KeyError nicely in test_framework.py (Rusty Russell) 85c807c getblockchaininfo: make bip9_softforks an object, not an array. (Rusty Russell)
1 parent 5b1ad12 commit cc3a06b

File tree

4 files changed

+12
-18
lines changed

4 files changed

+12
-18
lines changed

qa/rpc-tests/bip9-softforks.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -77,11 +77,7 @@ def generate_blocks(self, number, version, test_blocks = []):
7777

7878
def get_bip9_status(self, key):
7979
info = self.nodes[0].getblockchaininfo()
80-
for row in info['bip9_softforks']:
81-
if row['id'] == key:
82-
return row
83-
raise IndexError ('key:"%s" not found' % key)
84-
80+
return info['bip9_softforks'][key]
8581

8682
def test_BIP(self, bipName, activated_version, invalidate, invalidatePostSignature, bitno):
8783
wait_to_sync(self.nodes[0])

qa/rpc-tests/test_framework/test_framework.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,9 @@ def main(self):
142142
except AssertionError as e:
143143
print("Assertion failed: "+ str(e))
144144
traceback.print_tb(sys.exc_info()[2])
145+
except KeyError as e:
146+
print("key not found: "+ str(e))
147+
traceback.print_tb(sys.exc_info()[2])
145148
except Exception as e:
146149
print("Unexpected exception caught during testing: " + repr(e))
147150
traceback.print_tb(sys.exc_info()[2])

qa/rpc-tests/test_framework/util.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -605,7 +605,4 @@ def create_lots_of_big_transactions(node, txouts, utxos, fee):
605605

606606
def get_bip9_status(node, key):
607607
info = node.getblockchaininfo()
608-
for row in info['bip9_softforks']:
609-
if row['id'] == key:
610-
return row
611-
raise IndexError ('key:"%s" not found' % key)
608+
return info['bip9_softforks'][key]

src/rpc/blockchain.cpp

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -801,10 +801,9 @@ static UniValue SoftForkDesc(const std::string &name, int version, CBlockIndex*
801801
return rv;
802802
}
803803

804-
static UniValue BIP9SoftForkDesc(const std::string& name, const Consensus::Params& consensusParams, Consensus::DeploymentPos id)
804+
static UniValue BIP9SoftForkDesc(const Consensus::Params& consensusParams, Consensus::DeploymentPos id)
805805
{
806806
UniValue rv(UniValue::VOBJ);
807-
rv.push_back(Pair("id", name));
808807
const ThresholdState thresholdState = VersionBitsTipState(consensusParams, id);
809808
switch (thresholdState) {
810809
case THRESHOLD_DEFINED: rv.push_back(Pair("status", "defined")); break;
@@ -853,15 +852,14 @@ UniValue getblockchaininfo(const UniValue& params, bool fHelp)
853852
" \"reject\": { ... } (object) progress toward rejecting pre-softfork blocks (same fields as \"enforce\")\n"
854853
" }, ...\n"
855854
" ],\n"
856-
" \"bip9_softforks\": [ (array) status of BIP9 softforks in progress\n"
857-
" {\n"
858-
" \"id\": \"xxxx\", (string) name of the softfork\n"
855+
" \"bip9_softforks\": { (object) status of BIP9 softforks in progress\n"
856+
" \"xxxx\" : { (string) name of the softfork\n"
859857
" \"status\": \"xxxx\", (string) one of \"defined\", \"started\", \"lockedin\", \"active\", \"failed\"\n"
860858
" \"bit\": xx, (numeric) the bit, 0-28, in the block version field used to signal this soft fork\n"
861859
" \"startTime\": xx, (numeric) the minimum median time past of a block at which the bit gains its meaning\n"
862860
" \"timeout\": xx (numeric) the median time past of a block at which the deployment is considered failed if not yet locked in\n"
863861
" }\n"
864-
" ]\n"
862+
" }\n"
865863
"}\n"
866864
"\nExamples:\n"
867865
+ HelpExampleCli("getblockchaininfo", "")
@@ -884,12 +882,12 @@ UniValue getblockchaininfo(const UniValue& params, bool fHelp)
884882
const Consensus::Params& consensusParams = Params().GetConsensus();
885883
CBlockIndex* tip = chainActive.Tip();
886884
UniValue softforks(UniValue::VARR);
887-
UniValue bip9_softforks(UniValue::VARR);
885+
UniValue bip9_softforks(UniValue::VOBJ);
888886
softforks.push_back(SoftForkDesc("bip34", 2, tip, consensusParams));
889887
softforks.push_back(SoftForkDesc("bip66", 3, tip, consensusParams));
890888
softforks.push_back(SoftForkDesc("bip65", 4, tip, consensusParams));
891-
bip9_softforks.push_back(BIP9SoftForkDesc("csv", consensusParams, Consensus::DEPLOYMENT_CSV));
892-
bip9_softforks.push_back(BIP9SoftForkDesc("dip0001", consensusParams, Consensus::DEPLOYMENT_DIP0001));
889+
bip9_softforks.push_back(Pair("csv", BIP9SoftForkDesc(consensusParams, Consensus::DEPLOYMENT_CSV)));
890+
bip9_softforks.push_back(Pair("dip0001", BIP9SoftForkDesc(consensusParams, Consensus::DEPLOYMENT_DIP0001)));
893891
obj.push_back(Pair("softforks", softforks));
894892
obj.push_back(Pair("bip9_softforks", bip9_softforks));
895893

0 commit comments

Comments
 (0)