Merge pull request #2654 from patricklodder/1.14.5-namecoin-aux-api

[rpc] configure auxpow rpc methods to use Namecoin-compatible API
This commit is contained in:
Ross Nicoll 2021-11-01 22:15:46 +00:00 committed by GitHub
commit 2076361f88
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 71 additions and 8 deletions

View File

@ -23,7 +23,7 @@ class CreateAuxBlockTest(BitcoinTestFramework):
def setup_network(self):
self.nodes = []
self.nodes.append(start_node(0, self.options.tmpdir, ["-debug", "-txindex"]))
self.nodes.append(start_node(1, self.options.tmpdir, ["-debug"]))
self.nodes.append(start_node(1, self.options.tmpdir, ["-debug", "-rpcnamecoinapi"]))
connect_nodes_bi(self.nodes, 0, 1)
self.sync_all()
@ -170,6 +170,25 @@ class CreateAuxBlockTest(BitcoinTestFramework):
except JSONRPCException as exc:
assert_equal(exc.error["code"], -8)
self.sync_all()
# Call createauxblock while using the Namecoin API
nmc_api_auxblock = self.nodes[1].createauxblock(dummy_p2pkh_addr)
# must not contain a "target" field, but a "_target" field
assert "target" not in nmc_api_auxblock
assert "_target" in nmc_api_auxblock
reversedTarget = auxpow.reverseHex(nmc_api_auxblock["_target"])
apow = auxpow.computeAuxpowWithChainId(nmc_api_auxblock["hash"], reversedTarget, "98", True)
res = self.nodes[1].submitauxblock(nmc_api_auxblock["hash"], apow)
assert res
self.sync_all()
# check the mined block
self.check_mined_block(nmc_api_auxblock, apow, dummy_p2pkh_addr, Decimal("500000"))
def check_mined_block(self, auxblock, apow, addr, min_value, txid=None):
# Call getblock and verify the auxpow field.
data = self.nodes[1].getblock(auxblock["hash"])

View File

@ -12,9 +12,22 @@ from test_framework import scrypt_auxpow as auxpow
class GetAuxBlockTest (BitcoinTestFramework):
def __init__(self):
super().__init__()
self.setup_clean_chain = True
self.num_nodes = 2
self.is_network_split = False
def setup_network(self):
self.nodes = []
self.nodes.append(start_node(0, self.options.tmpdir, ["-debug"]))
self.nodes.append(start_node(1, self.options.tmpdir, ["-debug", "-rpcnamecoinapi"]))
connect_nodes_bi(self.nodes, 0, 1)
self.sync_all()
def run_test (self):
# Generate a block so that we are not "downloading blocks".
self.nodes[0].generate (1)
self.nodes[0].generate(100)
# Compare basic data of getauxblock to getblocktemplate.
auxblock = self.nodes[0].getauxblock ()
@ -117,5 +130,19 @@ class GetAuxBlockTest (BitcoinTestFramework):
coinbase = tx['vin'][0]['coinbase']
assert_equal ("01%02x01" % auxblock['height'], coinbase[0 : 6]) # DOGE: We mine less blocks in these tests
# Call getauxblock while using the Namecoin API
nmc_api_auxblock = self.nodes[1].getauxblock()
# must not contain a "target" field, but a "_target" field
assert "target" not in nmc_api_auxblock
assert "_target" in nmc_api_auxblock
reversedTarget = auxpow.reverseHex(nmc_api_auxblock["_target"])
apow = auxpow.computeAuxpowWithChainId(nmc_api_auxblock["hash"], reversedTarget, "98", True)
res = self.nodes[1].getauxblock(nmc_api_auxblock["hash"], apow)
assert res
self.sync_all()
if __name__ == '__main__':
GetAuxBlockTest ().main ()

View File

@ -503,6 +503,7 @@ std::string HelpMessage(HelpMessageMode mode)
if (showDebug) {
strUsage += HelpMessageOpt("-rpcworkqueue=<n>", strprintf("Set the depth of the work queue to service RPC calls (default: %d)", DEFAULT_HTTP_WORKQUEUE));
strUsage += HelpMessageOpt("-rpcservertimeout=<n>", strprintf("Timeout during HTTP requests (default: %d)", DEFAULT_HTTP_SERVER_TIMEOUT));
strUsage += HelpMessageOpt("-rpcnamecoinapi", strprintf(_("Use Namecoin-compatible AuxPow API structure, (default: %u)"), DEFAULT_USE_NAMECOIN_API));
}
return strUsage;
@ -1062,6 +1063,9 @@ bool AppInitParameterInteraction()
return false;
#endif
// Configure usage of the namecoin AuxPow API structure
fUseNamecoinApi = GetBoolArg("-rpcnamecoinapi", DEFAULT_USE_NAMECOIN_API);
fIsBareMultisigStd = GetBoolArg("-permitbaremultisig", DEFAULT_PERMIT_BAREMULTISIG);
fAcceptDatacarrier = GetBoolArg("-datacarrier", DEFAULT_ACCEPT_DATACARRIER);
nMaxDatacarrierBytes = GetArg("-datacarriersize", nMaxDatacarrierBytes);

View File

@ -974,6 +974,8 @@ UniValue estimatesmartpriority(const JSONRPCRequest& request)
/* ************************************************************************** */
/* Merge mining. */
bool fUseNamecoinApi;
/**
* The variables below are used to keep track of created and not yet
* submitted auxpow blocks. Lock them to be sure even for multiple
@ -1090,7 +1092,7 @@ static UniValue AuxMiningCreateBlock(const CScript& scriptPubKey)
result.pushKV("coinbasevalue", (int64_t)pblock->vtx[0]->vout[0].nValue);
result.pushKV("bits", strprintf("%08x", pblock->nBits));
result.pushKV("height", static_cast<int64_t> (pindexPrev->nHeight + 1));
result.pushKV("target", HexStr(BEGIN(target), END(target)));
result.pushKV(fUseNamecoinApi ? "_target" : "target", HexStr(BEGIN(target), END(target)));
return result;
}
@ -1147,8 +1149,12 @@ UniValue getauxblockbip22(const JSONRPCRequest& request)
" \"coinbasevalue\" (numeric) value of the block's coinbase\n"
" \"bits\" (string) compressed target of the block\n"
" \"height\" (numeric) height of the block\n"
" \"target\" (string) target in reversed byte order\n"
"}\n"
+ (std::string) (
fUseNamecoinApi
? " \"_target\" (string) target in reversed byte order\n"
: " \"target\" (string) target in reversed byte order\n"
)
+ "}\n"
"\nResult (with arguments):\n"
"xxxxx (boolean) whether the submitted block was correct\n"
"\nExamples:\n"
@ -1231,7 +1237,7 @@ UniValue getauxblockbip22(const JSONRPCRequest& request)
result.pushKV("coinbasevalue", (int64_t)pblock->vtx[0]->vout[0].nValue);
result.pushKV("bits", strprintf("%08x", pblock->nBits));
result.pushKV("height", static_cast<int64_t> (pindexPrev->nHeight + 1));
result.pushKV("target", HexStr(BEGIN(target), END(target)));
result.pushKV(fUseNamecoinApi ? "_target" : "target", HexStr(BEGIN(target), END(target)));
return result;
}
@ -1285,8 +1291,12 @@ UniValue createauxblock(const JSONRPCRequest& request)
" \"coinbasevalue\" (numeric) value of the block's coinbase\n"
" \"bits\" (string) compressed target of the block\n"
" \"height\" (numeric) height of the block\n"
" \"target\" (string) target in reversed byte order\n"
"}\n"
+ (std::string) (
fUseNamecoinApi
? " \"_target\" (string) target in reversed byte order\n"
: " \"target\" (string) target in reversed byte order\n"
)
+ "}\n"
"\nExamples:\n"
+ HelpExampleCli("createauxblock", "\"address\"")
+ HelpExampleRpc("createauxblock", "\"address\"")

View File

@ -21,6 +21,7 @@
#include <univalue.h>
static const unsigned int DEFAULT_RPC_SERIALIZE_VERSION = 1;
static const bool DEFAULT_USE_NAMECOIN_API = false;
class CRPCCommand;
@ -211,4 +212,6 @@ void RPCNotifyBlockChange(bool ibd, const CBlockIndex *);
// Retrieves any serialization flags requested in command line argument
int RPCSerializationFlags();
extern bool fUseNamecoinApi;
#endif // BITCOIN_RPCSERVER_H