added claimtrie field back to getblocktemplate

I also included a test to ensure that we don't forget it next time
This commit is contained in:
Brannon King 2019-05-22 09:56:38 -06:00
parent 5a393f5b14
commit 9cb4064adb
2 changed files with 19 additions and 9 deletions

View file

@ -351,13 +351,14 @@ static UniValue getblocktemplate(const JSONRPCRequest& request)
" \"value\" (string) A way the block template may be changed, e.g. 'time', 'transactions', 'prevblock'\n" " \"value\" (string) A way the block template may be changed, e.g. 'time', 'transactions', 'prevblock'\n"
" ,...\n" " ,...\n"
" ],\n" " ],\n"
" \"noncerange\" : \"00000000ffffffff\",(string) A range of valid nonces\n" " \"noncerange\" : \"00000000ffffffff\", (string) A range of valid nonces\n"
" \"sigoplimit\" : n, (numeric) limit of sigops in blocks\n" " \"sigoplimit\" : n, (numeric) limit of sigops in blocks\n"
" \"sizelimit\" : n, (numeric) limit of block size\n" " \"sizelimit\" : n, (numeric) limit of block size\n"
" \"weightlimit\" : n, (numeric) limit of block weight\n" " \"weightlimit\" : n, (numeric) limit of block weight\n"
" \"curtime\" : ttt, (numeric) current timestamp in seconds since epoch (Jan 1 1970 GMT)\n" " \"curtime\" : ttt, (numeric) current timestamp in seconds since epoch (Jan 1 1970 GMT)\n"
" \"bits\" : \"xxxxxxxx\", (string) compressed target of next block\n" " \"bits\" : \"xxxxxxxx\", (string) compressed target of next block\n"
" \"height\" : n (numeric) The height of the next block\n" " \"height\" : n (numeric) The height of the next block\n"
" \"claimtrie\" : \"00000000ffffffff\", (string) The root hash of the claim trie in hex\n"
"}\n" "}\n"
"\nExamples:\n" "\nExamples:\n"
@ -432,7 +433,9 @@ static UniValue getblocktemplate(const JSONRPCRequest& request)
if (strMode != "template") if (strMode != "template")
throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid mode"); throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid mode");
if(!g_connman) if (Params().NetworkIDString() != "lbrycrdreg") // who should own this constant?
{
if (!g_connman)
throw JSONRPCError(RPC_CLIENT_P2P_DISABLED, "Error: Peer-to-peer functionality missing or disabled"); throw JSONRPCError(RPC_CLIENT_P2P_DISABLED, "Error: Peer-to-peer functionality missing or disabled");
if (g_connman->GetNodeCount(CConnman::CONNECTIONS_ALL) == 0) if (g_connman->GetNodeCount(CConnman::CONNECTIONS_ALL) == 0)
@ -440,7 +443,7 @@ static UniValue getblocktemplate(const JSONRPCRequest& request)
if (IsInitialBlockDownload()) if (IsInitialBlockDownload())
throw JSONRPCError(RPC_CLIENT_IN_INITIAL_DOWNLOAD, "LBRYcrd is downloading blocks..."); throw JSONRPCError(RPC_CLIENT_IN_INITIAL_DOWNLOAD, "LBRYcrd is downloading blocks...");
}
static unsigned int nTransactionsUpdatedLast; static unsigned int nTransactionsUpdatedLast;
if (!lpval.isNull()) if (!lpval.isNull())
@ -652,6 +655,7 @@ static UniValue getblocktemplate(const JSONRPCRequest& request)
result.pushKV("mintime", (int64_t)pindexPrev->GetMedianTimePast()+1); result.pushKV("mintime", (int64_t)pindexPrev->GetMedianTimePast()+1);
result.pushKV("mutable", aMutable); result.pushKV("mutable", aMutable);
result.pushKV("noncerange", "00000000ffffffff"); result.pushKV("noncerange", "00000000ffffffff");
int64_t nSigOpLimit = MAX_BLOCK_SIGOPS_COST; int64_t nSigOpLimit = MAX_BLOCK_SIGOPS_COST;
int64_t nSizeLimit = MAX_BLOCK_SERIALIZED_SIZE; int64_t nSizeLimit = MAX_BLOCK_SERIALIZED_SIZE;
if (fPreSegWit) { if (fPreSegWit) {
@ -667,7 +671,8 @@ static UniValue getblocktemplate(const JSONRPCRequest& request)
} }
result.pushKV("curtime", pblock->GetBlockTime()); result.pushKV("curtime", pblock->GetBlockTime());
result.pushKV("bits", strprintf("%08x", pblock->nBits)); result.pushKV("bits", strprintf("%08x", pblock->nBits));
result.pushKV("height", (int64_t)(pindexPrev->nHeight+1)); result.pushKV("height", (int64_t)(pindexPrev->nHeight)+1);
result.pushKV("claimtrie", pblock->hashClaimTrie.GetHex());
if (!pblocktemplate->vchCoinbaseCommitment.empty() && fSupportsSegwit) { if (!pblocktemplate->vchCoinbaseCommitment.empty() && fSupportsSegwit) {
result.pushKV("default_witness_commitment", HexStr(pblocktemplate->vchCoinbaseCommitment.begin(), pblocktemplate->vchCoinbaseCommitment.end())); result.pushKV("default_witness_commitment", HexStr(pblocktemplate->vchCoinbaseCommitment.begin(), pblocktemplate->vchCoinbaseCommitment.end()));

View file

@ -3947,9 +3947,13 @@ BOOST_AUTO_TEST_CASE(claim_rpcs_rollback3_test)
rpcfn_type getclaimsforname = tableRPC["getclaimsforname"]->actor; rpcfn_type getclaimsforname = tableRPC["getclaimsforname"]->actor;
rpcfn_type getvalueforname = tableRPC["getvalueforname"]->actor; rpcfn_type getvalueforname = tableRPC["getvalueforname"]->actor;
rpcfn_type getblocktemplate = tableRPC["getblocktemplate"]->actor;
JSONRPCRequest req; JSONRPCRequest req;
req.params = UniValue(UniValue::VARR); req.params = UniValue(UniValue::VARR);
UniValue templateResults = getblocktemplate(req);
BOOST_CHECK_EQUAL(templateResults["claimtrie"].get_str(), chainActive.Tip()->hashClaimTrie.GetHex());
req.params.push_back(UniValue(sName1)); req.params.push_back(UniValue(sName1));
req.params.push_back(blockHash.GetHex()); req.params.push_back(blockHash.GetHex());
@ -3959,6 +3963,7 @@ BOOST_AUTO_TEST_CASE(claim_rpcs_rollback3_test)
UniValue valueResults = getvalueforname(req); UniValue valueResults = getvalueforname(req);
BOOST_CHECK_EQUAL(valueResults["value"].get_str(), HexStr(sValue1)); BOOST_CHECK_EQUAL(valueResults["value"].get_str(), HexStr(sValue1));
BOOST_CHECK_EQUAL(valueResults["amount"].get_int(), 3); BOOST_CHECK_EQUAL(valueResults["amount"].get_int(), 3);
} }
BOOST_AUTO_TEST_SUITE_END() BOOST_AUTO_TEST_SUITE_END()