Browse Source

Fixed CN error messages for mining.

cn_mining
Jianping Wu 6 years ago
parent
commit
27617b446b
  1. 4
      src/Makefile.am
  2. 3
      src/Makefile.bench.include
  3. 2
      src/Makefile.qt.include
  4. 2
      src/Makefile.qttest.include
  5. 6
      src/Makefile.test.include
  6. 8
      src/httprpc.cpp
  7. 68
      src/rpc/mining.cpp

4
src/Makefile.am

@ -54,12 +54,12 @@ $(LIBSECP256K1): $(wildcard secp256k1/src/*) $(wildcard secp256k1/include/*)
EXTRA_LIBRARIES += \ EXTRA_LIBRARIES += \
$(LIBBITCOIN_CRYPTO) \ $(LIBBITCOIN_CRYPTO) \
$(LIBBITCOIN_UTIL) \ $(LIBBITCOIN_UTIL) \
$(LIBBITCOIN_CNUTILS) \
$(LIBBITCOIN_COMMON) \ $(LIBBITCOIN_COMMON) \
$(LIBBITCOIN_CONSENSUS) \ $(LIBBITCOIN_CONSENSUS) \
$(LIBBITCOIN_SERVER) \ $(LIBBITCOIN_SERVER) \
$(LIBBITCOIN_CLI) \ $(LIBBITCOIN_CLI) \
$(LIBBITCOIN_WALLET) \ $(LIBBITCOIN_WALLET) \
$(LIBBITCOIN_CNUTILS) \
$(LIBBITCOIN_ZMQ) $(LIBBITCOIN_ZMQ)
lib_LTLIBRARIES = $(LIBBITCOINCONSENSUS) lib_LTLIBRARIES = $(LIBBITCOINCONSENSUS)
@ -457,11 +457,11 @@ kevacoind_LDADD = \
$(LIBBITCOIN_COMMON) \ $(LIBBITCOIN_COMMON) \
$(LIBUNIVALUE) \ $(LIBUNIVALUE) \
$(LIBBITCOIN_UTIL) \ $(LIBBITCOIN_UTIL) \
$(LIBBITCOIN_CNUTILS) \
$(LIBBITCOIN_WALLET) \ $(LIBBITCOIN_WALLET) \
$(LIBBITCOIN_ZMQ) \ $(LIBBITCOIN_ZMQ) \
$(LIBBITCOIN_CONSENSUS) \ $(LIBBITCOIN_CONSENSUS) \
$(LIBBITCOIN_CRYPTO) \ $(LIBBITCOIN_CRYPTO) \
$(LIBBITCOIN_CNUTILS) \
$(LIBLEVELDB) \ $(LIBLEVELDB) \
$(LIBLEVELDB_SSE42) \ $(LIBLEVELDB_SSE42) \
$(LIBMEMENV) \ $(LIBMEMENV) \

3
src/Makefile.bench.include

@ -37,7 +37,6 @@ bench_bench_kevacoin_LDADD = \
$(LIBBITCOIN_SERVER) \ $(LIBBITCOIN_SERVER) \
$(LIBBITCOIN_COMMON) \ $(LIBBITCOIN_COMMON) \
$(LIBBITCOIN_UTIL) \ $(LIBBITCOIN_UTIL) \
$(LIBBITCOIN_CNUTILS) \
$(LIBBITCOIN_CONSENSUS) \ $(LIBBITCOIN_CONSENSUS) \
$(LIBBITCOIN_CRYPTO) \ $(LIBBITCOIN_CRYPTO) \
$(LIBLEVELDB) \ $(LIBLEVELDB) \
@ -55,7 +54,7 @@ bench_bench_kevacoin_SOURCES += bench/coin_selection.cpp
bench_bench_kevacoin_LDADD += $(LIBBITCOIN_WALLET) $(LIBBITCOIN_CONSENSUS) $(LIBBITCOIN_CRYPTO) bench_bench_kevacoin_LDADD += $(LIBBITCOIN_WALLET) $(LIBBITCOIN_CONSENSUS) $(LIBBITCOIN_CRYPTO)
endif endif
bench_bench_kevacoin_LDADD += $(BOOST_LIBS) $(BDB_LIBS) $(SSL_LIBS) $(CRYPTO_LIBS) $(MINIUPNPC_LIBS) $(EVENT_PTHREADS_LIBS) $(EVENT_LIBS) bench_bench_kevacoin_LDADD += $(BOOST_LIBS) $(BDB_LIBS) $(SSL_LIBS) $(CRYPTO_LIBS) $(MINIUPNPC_LIBS) $(EVENT_PTHREADS_LIBS) $(EVENT_LIBS) $(LIBBITCOIN_CNUTILS)
bench_bench_kevacoin_LDFLAGS = $(RELDFLAGS) $(AM_LDFLAGS) $(LIBTOOL_APP_LDFLAGS) bench_bench_kevacoin_LDFLAGS = $(RELDFLAGS) $(AM_LDFLAGS) $(LIBTOOL_APP_LDFLAGS)
CLEAN_BITCOIN_BENCH = bench/*.gcda bench/*.gcno $(GENERATED_BENCH_FILES) CLEAN_BITCOIN_BENCH = bench/*.gcda bench/*.gcno $(GENERATED_BENCH_FILES)

2
src/Makefile.qt.include

@ -436,7 +436,7 @@ endif
if ENABLE_ZMQ if ENABLE_ZMQ
qt_kevacoin_qt_LDADD += $(LIBBITCOIN_ZMQ) $(ZMQ_LIBS) qt_kevacoin_qt_LDADD += $(LIBBITCOIN_ZMQ) $(ZMQ_LIBS)
endif endif
qt_kevacoin_qt_LDADD += $(LIBBITCOIN_CLI) $(LIBBITCOIN_COMMON) $(LIBBITCOIN_UTIL) $(LIBBITCOIN_CNUTILS) $(LIBBITCOIN_CONSENSUS) $(LIBBITCOIN_CRYPTO) $(LIBUNIVALUE) $(LIBLEVELDB) $(LIBLEVELDB_SSE42) $(LIBMEMENV) \ qt_kevacoin_qt_LDADD += $(LIBBITCOIN_CLI) $(LIBBITCOIN_COMMON) $(LIBBITCOIN_UTIL) $(LIBBITCOIN_CONSENSUS) $(LIBBITCOIN_CRYPTO) $(LIBUNIVALUE) $(LIBBITCOIN_CNUTILS) $(LIBLEVELDB) $(LIBLEVELDB_SSE42) $(LIBMEMENV) \
$(BOOST_LIBS) $(QT_LIBS) $(QT_DBUS_LIBS) $(QR_LIBS) $(PROTOBUF_LIBS) $(BDB_LIBS) $(SSL_LIBS) $(CRYPTO_LIBS) $(MINIUPNPC_LIBS) $(LIBSECP256K1) \ $(BOOST_LIBS) $(QT_LIBS) $(QT_DBUS_LIBS) $(QR_LIBS) $(PROTOBUF_LIBS) $(BDB_LIBS) $(SSL_LIBS) $(CRYPTO_LIBS) $(MINIUPNPC_LIBS) $(LIBSECP256K1) \
$(EVENT_PTHREADS_LIBS) $(EVENT_LIBS) $(EVENT_PTHREADS_LIBS) $(EVENT_LIBS)
qt_kevacoin_qt_LDFLAGS = $(RELDFLAGS) $(AM_LDFLAGS) $(QT_LDFLAGS) $(LIBTOOL_APP_LDFLAGS) qt_kevacoin_qt_LDFLAGS = $(RELDFLAGS) $(AM_LDFLAGS) $(QT_LDFLAGS) $(LIBTOOL_APP_LDFLAGS)

2
src/Makefile.qttest.include

@ -57,7 +57,7 @@ endif
if ENABLE_ZMQ if ENABLE_ZMQ
qt_test_test_kevacoin_qt_LDADD += $(LIBBITCOIN_ZMQ) $(ZMQ_LIBS) qt_test_test_kevacoin_qt_LDADD += $(LIBBITCOIN_ZMQ) $(ZMQ_LIBS)
endif endif
qt_test_test_kevacoin_qt_LDADD += $(LIBBITCOIN_CLI) $(LIBBITCOIN_COMMON) $(LIBBITCOIN_UTIL) $(LIBBITCOIN_CNUTILS) $(LIBBITCOIN_CONSENSUS) $(LIBBITCOIN_CRYPTO) $(LIBUNIVALUE) $(LIBLEVELDB) \ qt_test_test_kevacoin_qt_LDADD += $(LIBBITCOIN_CLI) $(LIBBITCOIN_COMMON) $(LIBBITCOIN_UTIL) $(LIBBITCOIN_CONSENSUS) $(LIBBITCOIN_CRYPTO) $(LIBUNIVALUE) $(LIBLEVELDB) $(LIBBITCOIN_CNUTILS) \
$(LIBLEVELDB_SSE42) $(LIBMEMENV) $(BOOST_LIBS) $(QT_DBUS_LIBS) $(QT_TEST_LIBS) $(QT_LIBS) \ $(LIBLEVELDB_SSE42) $(LIBMEMENV) $(BOOST_LIBS) $(QT_DBUS_LIBS) $(QT_TEST_LIBS) $(QT_LIBS) \
$(QR_LIBS) $(PROTOBUF_LIBS) $(BDB_LIBS) $(SSL_LIBS) $(CRYPTO_LIBS) $(MINIUPNPC_LIBS) $(LIBSECP256K1) \ $(QR_LIBS) $(PROTOBUF_LIBS) $(BDB_LIBS) $(SSL_LIBS) $(CRYPTO_LIBS) $(MINIUPNPC_LIBS) $(LIBSECP256K1) \
$(EVENT_PTHREADS_LIBS) $(EVENT_LIBS) $(EVENT_PTHREADS_LIBS) $(EVENT_LIBS)

6
src/Makefile.test.include

@ -104,7 +104,7 @@ test_test_kevacoin_LDADD =
if ENABLE_WALLET if ENABLE_WALLET
test_test_kevacoin_LDADD += $(LIBBITCOIN_WALLET) test_test_kevacoin_LDADD += $(LIBBITCOIN_WALLET)
endif endif
test_test_kevacoin_LDADD += $(LIBBITCOIN_SERVER) $(LIBBITCOIN_CLI) $(LIBBITCOIN_COMMON) $(LIBBITCOIN_UTIL) $(LIBBITCOIN_CNUTILS) $(LIBBITCOIN_CONSENSUS) $(LIBBITCOIN_CRYPTO) $(LIBUNIVALUE) \ test_test_kevacoin_LDADD += $(LIBBITCOIN_SERVER) $(LIBBITCOIN_CLI) $(LIBBITCOIN_COMMON) $(LIBBITCOIN_UTIL) $(LIBBITCOIN_CONSENSUS) $(LIBBITCOIN_CRYPTO) $(LIBUNIVALUE) $(LIBBITCOIN_CNUTILS) \
$(LIBLEVELDB) $(LIBLEVELDB_SSE42) $(LIBMEMENV) $(BOOST_LIBS) $(BOOST_UNIT_TEST_FRAMEWORK_LIB) $(LIBSECP256K1) $(EVENT_LIBS) $(EVENT_PTHREADS_LIBS) $(LIBLEVELDB) $(LIBLEVELDB_SSE42) $(LIBMEMENV) $(BOOST_LIBS) $(BOOST_UNIT_TEST_FRAMEWORK_LIB) $(LIBSECP256K1) $(EVENT_LIBS) $(EVENT_PTHREADS_LIBS)
test_test_kevacoin_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS) test_test_kevacoin_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS)
@ -127,10 +127,10 @@ test_test_kevacoin_fuzzy_LDADD = \
$(LIBBITCOIN_SERVER) \ $(LIBBITCOIN_SERVER) \
$(LIBBITCOIN_COMMON) \ $(LIBBITCOIN_COMMON) \
$(LIBBITCOIN_UTIL) \ $(LIBBITCOIN_UTIL) \
$(LIBBITCOIN_CNUTILS) \
$(LIBBITCOIN_CONSENSUS) \ $(LIBBITCOIN_CONSENSUS) \
$(LIBBITCOIN_CRYPTO) \ $(LIBBITCOIN_CRYPTO) \
$(LIBSECP256K1) $(LIBSECP256K1) \
$(LIBBITCOIN_CNUTILS)
test_test_kevacoin_fuzzy_LDADD += $(BOOST_LIBS) $(CRYPTO_LIBS) test_test_kevacoin_fuzzy_LDADD += $(BOOST_LIBS) $(CRYPTO_LIBS)
# #

8
src/httprpc.cpp

@ -77,6 +77,12 @@ static void JSONErrorReply(HTTPRequest* req, const UniValue& objError, const Uni
else if (code == RPC_METHOD_NOT_FOUND) else if (code == RPC_METHOD_NOT_FOUND)
nStatus = HTTP_NOT_FOUND; nStatus = HTTP_NOT_FOUND;
// Cryptonote error message, the status code is OK.
UniValue cn_code = find_value(objError, "cn_code");
if (!cn_code.isNull()) {
nStatus = HTTP_OK;
}
std::string strReply = JSONRPCReply(NullUniValue, objError, id); std::string strReply = JSONRPCReply(NullUniValue, objError, id);
req->WriteHeader("Content-Type", "application/json"); req->WriteHeader("Content-Type", "application/json");
@ -86,7 +92,7 @@ static void JSONErrorReply(HTTPRequest* req, const UniValue& objError, const Uni
//This function checks username and password against -rpcauth //This function checks username and password against -rpcauth
//entries from config file. //entries from config file.
static bool multiUserAuthorized(std::string strUserPass) static bool multiUserAuthorized(std::string strUserPass)
{ {
if (strUserPass.find(':') == std::string::npos) { if (strUserPass.find(':') == std::string::npos) {
return false; return false;
} }

68
src/rpc/mining.cpp

@ -270,6 +270,32 @@ UniValue prioritisetransaction(const JSONRPCRequest& request)
return true; return true;
} }
//---------------------------------------------------------------
// Cryptonote error codes
#define CORE_RPC_ERROR_CODE_WRONG_PARAM -1
#define CORE_RPC_ERROR_CODE_TOO_BIG_HEIGHT -2
#define CORE_RPC_ERROR_CODE_TOO_BIG_RESERVE_SIZE -3
#define CORE_RPC_ERROR_CODE_WRONG_WALLET_ADDRESS -4
#define CORE_RPC_ERROR_CODE_INTERNAL_ERROR -5
#define CORE_RPC_ERROR_CODE_WRONG_BLOCKBLOB -6
#define CORE_RPC_ERROR_CODE_BLOCK_NOT_ACCEPTED -7
#define CORE_RPC_ERROR_CODE_CORE_BUSY -9
#define CORE_RPC_ERROR_CODE_WRONG_BLOCKBLOB_SIZE -10
#define CORE_RPC_ERROR_CODE_UNSUPPORTED_RPC -11
#define CORE_RPC_ERROR_CODE_MINING_TO_SUBADDRESS -12
#define CORE_RPC_ERROR_CODE_REGTEST_REQUIRED -13
// Cryptonote error response
UniValue CN_JSONRPCError(int code, const std::string& message)
{
UniValue error(UniValue::VOBJ);
// Indicate that this is cryptonote error.
error.push_back(Pair("cn_code", code));
error.push_back(Pair("code", code));
error.push_back(Pair("message", message));
return error;
}
// NOTE: Assumes a conclusive result; if result is inconclusive, it must be handled by caller // NOTE: Assumes a conclusive result; if result is inconclusive, it must be handled by caller
static UniValue BIP22ValidationResult(const CValidationState& state) static UniValue BIP22ValidationResult(const CValidationState& state)
@ -279,15 +305,15 @@ static UniValue BIP22ValidationResult(const CValidationState& state)
std::string strRejectReason = state.GetRejectReason(); std::string strRejectReason = state.GetRejectReason();
if (state.IsError()) if (state.IsError())
throw JSONRPCError(RPC_VERIFY_ERROR, strRejectReason); throw CN_JSONRPCError(CORE_RPC_ERROR_CODE_BLOCK_NOT_ACCEPTED, strRejectReason);
if (state.IsInvalid()) if (state.IsInvalid())
{ {
if (strRejectReason.empty()) if (strRejectReason.empty())
return "rejected"; throw CN_JSONRPCError(CORE_RPC_ERROR_CODE_BLOCK_NOT_ACCEPTED, "rejected");
return strRejectReason; throw CN_JSONRPCError(CORE_RPC_ERROR_CODE_BLOCK_NOT_ACCEPTED, strRejectReason);
} }
// Should be impossible // Should be impossible
return "valid?"; throw CN_JSONRPCError(CORE_RPC_ERROR_CODE_BLOCK_NOT_ACCEPTED, "valid?");
} }
std::string gbt_vb_name(const Consensus::DeploymentPos pos) { std::string gbt_vb_name(const Consensus::DeploymentPos pos) {
@ -605,40 +631,35 @@ static uint256 CryptoHashToUint256(const crypto::hash& hash)
return uint256(prev_id); return uint256(prev_id);
} }
// Cryptonote RPC call, only one parameter allowed. // Cryptonote RPC call
UniValue submitblock(const JSONRPCRequest& request) UniValue submitblock(const JSONRPCRequest& request)
{ {
if (request.fHelp || request.params.size() != 1) { if (request.fHelp || request.params.size() != 1) {
throw std::runtime_error( throw std::runtime_error(
"submitblock \"hexdata\"\n" "submitblock \"hexdata\"\n"
"\nAttempts to submit new block to network.\n" "\nAttempts to submit new block to network.\n"
"See https://en.bitcoin.it/wiki/BIP_0022 for full specification.\n"
"\nArguments\n" "\nArguments\n"
"1. \"hexdata\" (string, required) the hex-encoded block data to submit\n" "1. \"hexdata\" (string, required) the hex-encoded block data to submit\n"
"2. \"dummy\" (optional) dummy value, for compatibility with BIP22. This value is ignored.\n"
"\nResult:\n" "\nResult:\n"
"\nExamples:\n" "\nExamples:\n"
+ HelpExampleCli("submitblock", "\"mydata\"") + HelpExampleCli("submitblock", "\"mydata\"")
+ HelpExampleRpc("submitblock", "\"mydata\"")
); );
} }
cryptonote::blobdata blockblob; cryptonote::blobdata blockblob;
if(!epee::string_tools::parse_hexstr_to_binbuff(request.params[0].get_str(), blockblob)) if(!epee::string_tools::parse_hexstr_to_binbuff(request.params[0].get_str(), blockblob)) {
{ throw CN_JSONRPCError(CORE_RPC_ERROR_CODE_WRONG_BLOCKBLOB, "Wrong block blob");
throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "Wrong block blob");
} }
cryptonote::block cnblock = AUTO_VAL_INIT(cnblock); cryptonote::block cnblock = AUTO_VAL_INIT(cnblock);
if(!cryptonote::parse_and_validate_block_from_blob(blockblob, cnblock)) if(!cryptonote::parse_and_validate_block_from_blob(blockblob, cnblock)) {
{ throw CN_JSONRPCError(CORE_RPC_ERROR_CODE_WRONG_BLOCKBLOB, "Wrong block blob");
throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "Wrong block blob");
} }
cryptonote::tx_extra_keva_block keva_block_blob; cryptonote::tx_extra_keva_block keva_block_blob;
if (!cryptonote::get_keva_block_from_extra(cnblock.miner_tx.extra, keva_block_blob)) { if (!cryptonote::get_keva_block_from_extra(cnblock.miner_tx.extra, keva_block_blob)) {
throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "Could not get Kevacoin block"); throw CN_JSONRPCError(CORE_RPC_ERROR_CODE_WRONG_BLOCKBLOB, "Could not get Kevacoin block");
} }
std::shared_ptr<CBlock> blockptr = std::make_shared<CBlock>(); std::shared_ptr<CBlock> blockptr = std::make_shared<CBlock>();
@ -649,11 +670,11 @@ UniValue submitblock(const JSONRPCRequest& request)
ssBlock >> block; ssBlock >> block;
} }
catch (const std::exception&) { catch (const std::exception&) {
throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "Failed to deserialize keva block"); throw CN_JSONRPCError(CORE_RPC_ERROR_CODE_WRONG_BLOCKBLOB, "Failed to deserialize keva block");
} }
if (block.vtx.empty() || !block.vtx[0]->IsCoinBase()) { if (block.vtx.empty() || !block.vtx[0]->IsCoinBase()) {
throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "Block does not start with a coinbase"); throw CN_JSONRPCError(CORE_RPC_ERROR_CODE_WRONG_BLOCKBLOB, "Block does not start with a coinbase");
} }
block.cnHeader.major_version = cnblock.major_version; block.cnHeader.major_version = cnblock.major_version;
@ -669,10 +690,9 @@ UniValue submitblock(const JSONRPCRequest& request)
uint256 hash = block.GetHash(); uint256 hash = block.GetHash();
// Cryptonote prev_id is used to store the block hash of kevacoin. // Cryptonote prev_id is used to store the block hash of kevacoin.
if (hash != block.cnHeader.prev_id) { if (hash != block.cnHeader.prev_id) {
throw JSONRPCError(RPC_VERIFY_ERROR, "Kevacoin block hash does not match cryptnote hash"); throw CN_JSONRPCError(CORE_RPC_ERROR_CODE_WRONG_PARAM, "Kevacoin block hash does not match cryptnote hash");
} }
// TODO: fix the return message.
bool fBlockPresent = false; bool fBlockPresent = false;
{ {
LOCK(cs_main); LOCK(cs_main);
@ -680,10 +700,10 @@ UniValue submitblock(const JSONRPCRequest& request)
if (mi != mapBlockIndex.end()) { if (mi != mapBlockIndex.end()) {
CBlockIndex *pindex = mi->second; CBlockIndex *pindex = mi->second;
if (pindex->IsValid(BLOCK_VALID_SCRIPTS)) { if (pindex->IsValid(BLOCK_VALID_SCRIPTS)) {
return "duplicate"; throw CN_JSONRPCError(CORE_RPC_ERROR_CODE_BLOCK_NOT_ACCEPTED, "duplicate");
} }
if (pindex->nStatus & BLOCK_FAILED_MASK) { if (pindex->nStatus & BLOCK_FAILED_MASK) {
return "duplicate-invalid"; throw CN_JSONRPCError(CORE_RPC_ERROR_CODE_BLOCK_NOT_ACCEPTED, "duplicate-invalid");
} }
// Otherwise, we might only have the header - process the block before returning // Otherwise, we might only have the header - process the block before returning
fBlockPresent = true; fBlockPresent = true;
@ -704,12 +724,12 @@ UniValue submitblock(const JSONRPCRequest& request)
UnregisterValidationInterface(&sc); UnregisterValidationInterface(&sc);
if (fBlockPresent) { if (fBlockPresent) {
if (fAccepted && !sc.found) { if (fAccepted && !sc.found) {
return "duplicate-inconclusive"; throw CN_JSONRPCError(CORE_RPC_ERROR_CODE_BLOCK_NOT_ACCEPTED, "duplicate-inconclusive");
} }
return "duplicate"; throw CN_JSONRPCError(CORE_RPC_ERROR_CODE_BLOCK_NOT_ACCEPTED, "duplicate");
} }
if (!sc.found) { if (!sc.found) {
return "inconclusive"; throw CN_JSONRPCError(CORE_RPC_ERROR_CODE_BLOCK_NOT_ACCEPTED, "inconclusive");
} }
return BIP22ValidationResult(sc.state); return BIP22ValidationResult(sc.state);
} }

Loading…
Cancel
Save