diff --git a/qa/rpc-tests/blockchain.py b/qa/rpc-tests/blockchain.py index fdf77e9c5d..9209c5c2df 100755 --- a/qa/rpc-tests/blockchain.py +++ b/qa/rpc-tests/blockchain.py @@ -19,6 +19,7 @@ assert_is_hash_string, start_nodes, connect_nodes_bi, + assert_raises_message, ) @@ -45,21 +46,24 @@ def setup_network(self, split=False): def run_test(self): self._test_gettxoutsetinfo() self._test_getblockheader() + self._test_getblockheader(getblock=True) + self._test_getdifficulty() + self._test_getblockchaininfo() self.nodes[0].verifychain(4, 0) def _test_gettxoutsetinfo(self): node = self.nodes[0] res = node.gettxoutsetinfo() - assert_equal(res['total_amount'], Decimal('8725.00000000')) - assert_equal(res['transactions'], 200) + assert 'total_amount' not in res + assert_equal(res['transactions'], 1) assert_equal(res['height'], 200) - assert_equal(res['txouts'], 200) - assert_equal(res['bytes_serialized'], 13924), + assert_equal(res['txouts'], 100) + assert_equal(res['bytes_serialized'], 3948), assert_equal(len(res['bestblock']), 64) assert_equal(len(res['hash_serialized']), 64) - def _test_getblockheader(self): + def _test_getblockheader(self, getblock=False): node = self.nodes[0] assert_raises( @@ -67,23 +71,52 @@ def _test_getblockheader(self): besthash = node.getbestblockhash() secondbesthash = node.getblockhash(199) - header = node.getblockheader(besthash) + if getblock: + header = node.getblock(besthash) + else: + header = node.getblockheader(besthash) assert_equal(header['hash'], besthash) assert_equal(header['height'], 200) assert_equal(header['confirmations'], 1) assert_equal(header['previousblockhash'], secondbesthash) - assert_is_hex_string(header['chainwork']) assert_is_hash_string(header['hash']) assert_is_hash_string(header['previousblockhash']) assert_is_hash_string(header['merkleroot']) - assert_is_hash_string(header['bits'], length=None) assert isinstance(header['time'], int) assert isinstance(header['mediantime'], int) - assert isinstance(header['nonce'], int) assert isinstance(header['version'], int) assert isinstance(int(header['versionHex'], 16), int) - assert isinstance(header['difficulty'], int)#always 1 + assert 'nonce' not in header + assert 'bits' not in header + assert 'difficulty' not in header + assert 'chainwork' not in header + assert 'signblock_witness_asm' in header + assert 'signblock_witness_hex' in header + + def _test_getdifficulty(self): + assert_raises_message(JSONRPCException, + "getdifficulty is DEPRECATED for elements (which lacks pow), always returns this error", + self.nodes[0].getdifficulty) + + def _test_getblockchaininfo(self): + besthash = self.nodes[0].getbestblockhash() + res = self.nodes[0].getblockchaininfo() + + assert_equal(res['chain'], 'elementsregtest') + assert_equal(res['signblock_asm'], '1') + assert_equal(res['signblock_hex'], '51') + assert 'difficulty' not in res + assert 'chainwork' not in res + assert_equal(res['blocks'], 200) + assert_equal(res['headers'], 200) + assert_equal(res['bestblockhash'], besthash) + assert isinstance(res['mediantime'], int) + assert_equal(res['verificationprogress'], 1) + assert_equal(res['pruned'], False) + assert 'pruneheight' not in res + assert 'softforks' not in res + assert 'bip9_softforks' in res if __name__ == '__main__': BlockchainTest().main() diff --git a/qa/rpc-tests/pegging.py b/qa/rpc-tests/pegging.py index e98bf53d21..9009e1695c 100755 --- a/qa/rpc-tests/pegging.py +++ b/qa/rpc-tests/pegging.py @@ -8,7 +8,7 @@ import subprocess import shutil from decimal import Decimal - +from pdb import set_trace if len(sys.argv) < 2: print("path to bitcoind must be included as argument") sys.exit(0) diff --git a/src/pow.cpp b/src/pow.cpp index 22dc6b9136..5c676f0956 100644 --- a/src/pow.cpp +++ b/src/pow.cpp @@ -79,27 +79,3 @@ void ResetProof(CBlockHeader& block) { block.proof.solution.clear(); } - -double GetChallengeDifficulty(const CBlockIndex* blockindex) -{ - return 1; -} - -std::string GetChallengeStr(const CBlockIndex& block) -{ - return ScriptToAsmStr(block.proof.challenge); -} - -std::string GetChallengeStrHex(const CBlockIndex& block) -{ - return ScriptToAsmStr(block.proof.challenge); -} - -uint32_t GetNonce(const CBlockHeader& block) -{ - return 1; -} - -void SetNonce(CBlockHeader& block, uint32_t nNonce) -{ -} diff --git a/src/pow.h b/src/pow.h index 6e0f6a36dd..0da9e5d3e4 100644 --- a/src/pow.h +++ b/src/pow.h @@ -19,23 +19,14 @@ class CScript; class CWallet; class uint256; - /** Check whether a block hash satisfies the proof-of-work requirement specified by nBits */ bool CheckBitcoinProof(uint256 hash, unsigned int nBits); bool CheckProof(const CBlockHeader& block, const Consensus::Params&); -/** Scans nonces looking for a hash with at least some zero bits */ -bool MaybeGenerateProof(CBlockHeader* pblock, CWallet* pwallet); void ResetProof(CBlockHeader& block); bool CheckChallenge(const CBlockHeader& block, const CBlockIndex& indexLast, const Consensus::Params&); void ResetChallenge(CBlockHeader& block, const CBlockIndex& indexLast, const Consensus::Params&); +bool MaybeGenerateProof(CBlockHeader* pblock, CWallet* pwallet); CScript CombineBlockSignatures(const CBlockHeader& header, const CScript& scriptSig1, const CScript& scriptSig2); -/** Avoid using these functions when possible */ -double GetChallengeDifficulty(const CBlockIndex* blockindex); -std::string GetChallengeStr(const CBlockIndex& block); -std::string GetChallengeStrHex(const CBlockIndex& block); -uint32_t GetNonce(const CBlockHeader& block); -void SetNonce(CBlockHeader& block, uint32_t nNonce); - #endif // BITCOIN_POW_H diff --git a/src/rpc/blockchain.cpp b/src/rpc/blockchain.cpp index 0098386ab7..c756f8000d 100644 --- a/src/rpc/blockchain.cpp +++ b/src/rpc/blockchain.cpp @@ -9,6 +9,7 @@ #include "checkpoints.h" #include "coins.h" #include "consensus/validation.h" +#include "core_io.h" #include "validation.h" #include "policy/policy.h" #include "primitives/transaction.h" @@ -44,20 +45,6 @@ static CUpdatedBlock latestblock; extern void TxToJSON(const CTransaction& tx, const uint256 hashBlock, UniValue& entry); void ScriptPubKeyToJSON(const CScript& scriptPubKey, UniValue& out, bool fIncludeHex); -double GetDifficulty(const CBlockIndex* blockindex) -{ - // Floating point number that is a multiple of the minimum difficulty, - // minimum difficulty = 1.0. - if (blockindex == NULL) - { - if (chainActive.Tip() == NULL) - return 1.0; - else - blockindex = chainActive.Tip(); - } - return GetChallengeDifficulty(blockindex); -} - UniValue blockheaderToJSON(const CBlockIndex* blockindex) { UniValue result(UniValue::VOBJ); @@ -73,10 +60,8 @@ UniValue blockheaderToJSON(const CBlockIndex* blockindex) result.push_back(Pair("merkleroot", blockindex->hashMerkleRoot.GetHex())); result.push_back(Pair("time", (int64_t)blockindex->nTime)); result.push_back(Pair("mediantime", (int64_t)blockindex->GetMedianTimePast())); - result.push_back(Pair("nonce", (uint64_t)GetNonce(blockindex->GetBlockHeader()))); - result.push_back(Pair("bits", GetChallengeStr(blockindex->GetBlockHeader()))); - result.push_back(Pair("difficulty", GetDifficulty(blockindex))); - result.push_back(Pair("chainwork", blockindex->nChainWork.GetHex())); + result.push_back(Pair("signblock_witness_asm", ScriptToAsmStr(blockindex->proof.solution))); + result.push_back(Pair("signblock_witness_hex", HexStr(blockindex->proof.solution.begin(), blockindex->proof.solution.end()))); if (blockindex->pprev) result.push_back(Pair("previousblockhash", blockindex->pprev->GetBlockHash().GetHex())); @@ -117,10 +102,8 @@ UniValue blockToJSON(const CBlock& block, const CBlockIndex* blockindex, bool tx result.push_back(Pair("tx", txs)); result.push_back(Pair("time", block.GetBlockTime())); result.push_back(Pair("mediantime", (int64_t)blockindex->GetMedianTimePast())); - result.push_back(Pair("nonce", (uint64_t)GetNonce(block))); - result.push_back(Pair("bits", GetChallengeStr(block))); - result.push_back(Pair("difficulty", GetDifficulty(blockindex))); - result.push_back(Pair("chainwork", blockindex->nChainWork.GetHex())); + result.push_back(Pair("signblock_witness_asm", ScriptToAsmStr(blockindex->proof.solution))); + result.push_back(Pair("signblock_witness_hex", HexStr(blockindex->proof.solution.begin(), blockindex->proof.solution.end()))); if (blockindex->pprev) result.push_back(Pair("previousblockhash", blockindex->pprev->GetBlockHash().GetHex())); @@ -298,19 +281,7 @@ UniValue waitforblockheight(const JSONRPCRequest& request) UniValue getdifficulty(const JSONRPCRequest& request) { - if (request.fHelp || request.params.size() != 0) - throw runtime_error( - "getdifficulty\n" - "\nReturns the proof-of-work difficulty as a multiple of the minimum difficulty.\n" - "\nResult:\n" - "n.nnn (numeric) the proof-of-work difficulty as a multiple of the minimum difficulty.\n" - "\nExamples:\n" - + HelpExampleCli("getdifficulty", "") - + HelpExampleRpc("getdifficulty", "") - ); - - LOCK(cs_main); - return GetDifficulty(); + throw JSONRPCError(RPC_METHOD_NOT_FOUND, "getdifficulty is DEPRECATED for elements (which lacks pow), always returns this error"); } std::string EntryDescriptionString() @@ -632,10 +603,8 @@ UniValue getblockheader(const JSONRPCRequest& request) " \"merkleroot\" : \"xxxx\", (string) The merkle root\n" " \"time\" : ttt, (numeric) The block time in seconds since epoch (Jan 1 1970 GMT)\n" " \"mediantime\" : ttt, (numeric) The median block time in seconds since epoch (Jan 1 1970 GMT)\n" - " \"nonce\" : n, (numeric) The nonce\n" - " \"bits\" : \"1d00ffff\", (string) The bits\n" - " \"difficulty\" : x.xxx, (numeric) The difficulty\n" - " \"chainwork\" : \"0000...1f3\" (string) Expected number of hashes required to produce the current chain (in hex)\n" + " \"signblock_witness_asm\":\"asm\", (string) scriptSig for block signing (asm)'\n" + " \"signblock_witness_hex\":\"hex\", (string) scriptSig for block signing (hex)'\n" " \"previousblockhash\" : \"hash\", (string) The hash of the previous block\n" " \"nextblockhash\" : \"hash\", (string) The hash of the next block\n" "}\n" @@ -701,10 +670,8 @@ UniValue getblock(const JSONRPCRequest& request) " ],\n" " \"time\" : ttt, (numeric) The block time in seconds since epoch (Jan 1 1970 GMT)\n" " \"mediantime\" : ttt, (numeric) The median block time in seconds since epoch (Jan 1 1970 GMT)\n" - " \"nonce\" : n, (numeric) The nonce\n" - " \"bits\" : \"1d00ffff\", (string) The bits\n" - " \"difficulty\" : x.xxx, (numeric) The difficulty\n" - " \"chainwork\" : \"xxxx\", (string) Expected number of hashes required to produce the chain up to this block (in hex)\n" + " \"signblock_witness_asm\":\"asm\", (string) scriptSig for block signing (asm)'\n" + " \"signblock_witness_hex\":\"hex\", (string) scriptSig for block signing (hex)'\n" " \"previousblockhash\" : \"hash\", (string) The hash of the previous block\n" " \"nextblockhash\" : \"hash\" (string) The hash of the next block\n" "}\n" @@ -1064,24 +1031,15 @@ UniValue getblockchaininfo(const JSONRPCRequest& request) "\nResult:\n" "{\n" " \"chain\": \"xxxx\", (string) current network name as defined in BIP70 (main, test, regtest)\n" + " \"signblock_asm\":\"asm\", (string) scriptPubKey for block signing (asm)'\n" + " \"signblock_hex\":\"hex\", (string) scriptPubKey for block signing (hex)'\n" " \"blocks\": xxxxxx, (numeric) the current number of blocks processed in the server\n" " \"headers\": xxxxxx, (numeric) the current number of headers we have validated\n" " \"bestblockhash\": \"...\", (string) the hash of the currently best block\n" - " \"difficulty\": xxxxxx, (numeric) the current difficulty\n" " \"mediantime\": xxxxxx, (numeric) median time for the current best block\n" " \"verificationprogress\": xxxx, (numeric) estimate of verification progress [0..1]\n" - " \"chainwork\": \"xxxx\" (string) total amount of work in active chain, in hexadecimal\n" " \"pruned\": xx, (boolean) if the blocks are subject to pruning\n" " \"pruneheight\": xxxxxx, (numeric) lowest-height complete block stored\n" - " \"softforks\": [ (array) status of softforks in progress\n" - " {\n" - " \"id\": \"xxxx\", (string) name of softfork\n" - " \"version\": xx, (numeric) block version\n" - " \"reject\": { (object) progress toward rejecting pre-softfork blocks\n" - " \"status\": xx, (boolean) true if threshold reached\n" - " },\n" - " }, ...\n" - " ],\n" " \"bip9_softforks\": { (object) status of BIP9 softforks in progress\n" " \"xxxx\" : { (string) name of the softfork\n" " \"status\": \"xxxx\", (string) one of \"defined\", \"started\", \"locked_in\", \"active\", \"failed\"\n" @@ -1098,17 +1056,18 @@ UniValue getblockchaininfo(const JSONRPCRequest& request) ); LOCK(cs_main); + CBlockIndex* tip = chainActive.Tip(); UniValue obj(UniValue::VOBJ); obj.push_back(Pair("chain", Params().NetworkIDString())); obj.push_back(Pair("blocks", (int)chainActive.Height())); obj.push_back(Pair("headers", pindexBestHeader ? pindexBestHeader->nHeight : -1)); - obj.push_back(Pair("bestblockhash", chainActive.Tip()->GetBlockHash().GetHex())); - obj.push_back(Pair("difficulty", (double)GetDifficulty())); - obj.push_back(Pair("mediantime", (int64_t)chainActive.Tip()->GetMedianTimePast())); - obj.push_back(Pair("verificationprogress", GuessVerificationProgress(Params().TxData(), chainActive.Tip()))); - obj.push_back(Pair("chainwork", chainActive.Tip()->nChainWork.GetHex())); + obj.push_back(Pair("bestblockhash", tip->GetBlockHash().GetHex())); + obj.push_back(Pair("mediantime", (int64_t)tip->GetMedianTimePast())); + obj.push_back(Pair("verificationprogress", GuessVerificationProgress(Params().TxData(), tip))); obj.push_back(Pair("pruned", fPruneMode)); + obj.push_back(Pair("signblock_asm", ScriptToAsmStr(tip->proof.challenge))); + obj.push_back(Pair("signblock_hex", HexStr(tip->proof.challenge.begin(), tip->proof.challenge.end()))); const Consensus::Params& consensusParams = Params().GetConsensus(); UniValue bip9_softforks(UniValue::VOBJ); @@ -1118,7 +1077,7 @@ UniValue getblockchaininfo(const JSONRPCRequest& request) if (fPruneMode) { - CBlockIndex *block = chainActive.Tip(); + CBlockIndex *block = tip; while (block && block->pprev && (block->pprev->nStatus & BLOCK_HAVE_DATA)) block = block->pprev; diff --git a/src/rpc/mining.cpp b/src/rpc/mining.cpp index ac8188f96c..d814bc5ef0 100644 --- a/src/rpc/mining.cpp +++ b/src/rpc/mining.cpp @@ -273,7 +273,6 @@ UniValue getmininginfo(const JSONRPCRequest& request) obj.push_back(Pair("currentblocksize", (uint64_t)nLastBlockSize)); obj.push_back(Pair("currentblockweight", (uint64_t)nLastBlockWeight)); obj.push_back(Pair("currentblocktx", (uint64_t)nLastBlockTx)); - obj.push_back(Pair("difficulty", (double)GetDifficulty())); obj.push_back(Pair("errors", GetWarnings("statusbar"))); obj.push_back(Pair("networkhashps", getnetworkhashps(request))); obj.push_back(Pair("pooledtx", (uint64_t)mempool.size())); @@ -759,7 +758,6 @@ UniValue getblocktemplate(const JSONRPCRequest& request) result.push_back(Pair("coinbaseaux", aux)); result.push_back(Pair("coinbasevalue", (int64_t)pblock->vtx[0]->vout[0].nValue.GetAmount())); result.push_back(Pair("longpollid", chainActive.Tip()->GetBlockHash().GetHex() + i64tostr(nTransactionsUpdatedLast))); - result.push_back(Pair("target", GetChallengeStrHex(*pblock))); result.push_back(Pair("mintime", (int64_t)pindexPrev->GetMedianTimePast()+1)); result.push_back(Pair("mutable", aMutable)); result.push_back(Pair("noncerange", "00000000ffffffff")); @@ -776,7 +774,8 @@ UniValue getblocktemplate(const JSONRPCRequest& request) result.push_back(Pair("weightlimit", (int64_t)MAX_BLOCK_WEIGHT)); } result.push_back(Pair("curtime", pblock->GetBlockTime())); - result.push_back(Pair("bits", GetChallengeStr(*pblock))); + result.push_back(Pair("signblock_asm", ScriptToAsmStr(pblock->proof.challenge))); + result.push_back(Pair("signblock_hex", HexStr(pblock->proof.challenge.begin(), pblock->proof.challenge.end()))); result.push_back(Pair("height", (int64_t)(pindexPrev->nHeight+1))); if (!pblocktemplate->vchCoinbaseCommitment.empty() && fSupportsSegwit) { diff --git a/src/rpc/misc.cpp b/src/rpc/misc.cpp index 7252f3f751..a25b8d1460 100644 --- a/src/rpc/misc.cpp +++ b/src/rpc/misc.cpp @@ -107,7 +107,6 @@ UniValue getinfo(const JSONRPCRequest& request) if(g_connman) obj.push_back(Pair("connections", (int)g_connman->GetNodeCount(CConnman::CONNECTIONS_ALL))); obj.push_back(Pair("proxy", (proxy.IsValid() ? proxy.proxy.ToStringIPPort() : string()))); - obj.push_back(Pair("difficulty", (double)GetDifficulty())); obj.push_back(Pair("chain", Params().NetworkIDString())); #ifdef ENABLE_WALLET if (pwalletMain) { diff --git a/src/rpc/server.h b/src/rpc/server.h index 501dabc249..8b8744580d 100644 --- a/src/rpc/server.h +++ b/src/rpc/server.h @@ -198,7 +198,6 @@ extern std::vector ParseHexO(const UniValue& o, std::string strKe extern int64_t nWalletUnlockTime; extern CAmount AmountFromValue(const UniValue& value); extern UniValue ValueFromAmount(const CAmount& amount); -extern double GetDifficulty(const CBlockIndex* blockindex = NULL); extern std::string HelpRequiringPassphrase(); extern std::string HelpExampleCli(const std::string& methodname, const std::string& args); extern std::string HelpExampleRpc(const std::string& methodname, const std::string& args);