From bfdc854dbd8278333dbf17ef3d5dea6416a7399b Mon Sep 17 00:00:00 2001 From: Ross Nicoll Date: Mon, 18 Aug 2014 19:08:54 +0100 Subject: [PATCH] Disable AuxPoW RPC commands until switchover block AuxPoW RPC commands now return a failure message until the switchover block on the respective network. Also cleaned up RPC error values to use enum values rather than magic numbers. --- src/main.h | 3 +++ src/rpcmining.cpp | 18 ++++++++++++++---- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/src/main.h b/src/main.h index cd512846e..30b8524f0 100644 --- a/src/main.h +++ b/src/main.h @@ -621,6 +621,9 @@ bool ConnectBlock(CBlock& block, CValidationState& state, CBlockIndex* pindex, C // Add this block to the block index, and if necessary, switch the active block chain to this bool AddToBlockIndex(CBlock& block, CValidationState& state, const CDiskBlockPos& pos); +// Get the block at which AuxPoW is enabled for this network +int GetAuxPowStartBlock(); + // Context-independent validity checks bool CheckBlockHeader(const CBlockHeader& block, CValidationState& state, int nHeight, bool fCheckPOW = true); bool CheckBlock(const CBlock& block, CValidationState& state, int nHeight, bool fCheckPOW = true, bool fCheckMerkleRoot = true); diff --git a/src/rpcmining.cpp b/src/rpcmining.cpp index 4103e7f4c..afcbb9235 100644 --- a/src/rpcmining.cpp +++ b/src/rpcmining.cpp @@ -657,10 +657,15 @@ Value getworkaux(const Array& params, bool fHelp) ); if (vNodes.empty()) - throw JSONRPCError(-9, "Dogecoin is not connected!"); + throw JSONRPCError(RPC_CLIENT_NOT_CONNECTED, "Dogecoin is not connected!"); if (IsInitialBlockDownload()) - throw JSONRPCError(-10, "Dogecoin is downloading blocks..."); + throw JSONRPCError(RPC_CLIENT_IN_INITIAL_DOWNLOAD, "Dogecoin is downloading blocks..."); + + // We use height plus one because we're testing the next block + if ((chainActive.Tip()->nHeight+1) < GetAuxPowStartBlock()) { + throw JSONRPCError(RPC_METHOD_NOT_FOUND, "getworkaux method is not available until switch-over block."); + } static map > mapNewBlock; static vector vNewBlockTemplate; @@ -817,10 +822,15 @@ Value getauxblock(const Array& params, bool fHelp) "the aux proof of work and returns true if it was successful."); if (vNodes.empty()) - throw JSONRPCError(-9, "Dogecoin is not connected!"); + throw JSONRPCError(RPC_CLIENT_NOT_CONNECTED, "Dogecoin is not connected!"); if (IsInitialBlockDownload()) - throw JSONRPCError(-10, "Dogecoin is downloading blocks..."); + throw JSONRPCError(RPC_CLIENT_IN_INITIAL_DOWNLOAD, "Dogecoin is downloading blocks..."); + + // We use height plus one because we're testing the next block + if ((chainActive.Tip()->nHeight+1) < GetAuxPowStartBlock()) { + throw JSONRPCError(RPC_METHOD_NOT_FOUND, "getauxblock method is not available until switch-over block."); + } static map mapNewBlock; static vector vNewBlockTemplate;