Auto merge of #1308 - str4d:1181-getmininginfo-testnet-difficulty-rules, r=ebfull
Separate concepts of block difficulty and network difficulty in RPC "Block difficulty" is the difficulty listed in a block's header, which in the testnet can sometimes be min-difficulty (if time-since-last-block is too large). "Network difficulty" is the difficulty that the network was trying to satisfy at a particular block height. In mainnet this is always equal to the difficulty of the solved block for that height, but in testnet the network difficulty is derived from the last non-min-difficulty block difficulty. This commit fixes the RPC APIs that are intended to show network difficulty, so that on testnet they don't sometimes drop to 1.0, confusing users. Closes #1181
This commit is contained in:
@@ -6,9 +6,37 @@
|
||||
#include "chainparams.h"
|
||||
#include "clientversion.h"
|
||||
#include "primitives/block.h"
|
||||
#include "rpcserver.h"
|
||||
#include "streams.h"
|
||||
#include "utilstrencodings.h"
|
||||
|
||||
TEST(rpc, GetDifficultyTestnetRules) {
|
||||
SelectParams(CBaseChainParams::TESTNET);
|
||||
|
||||
CBlockIndex prev;
|
||||
prev.nTime = 1472700000;
|
||||
prev.nBits = 0x201fffff;
|
||||
|
||||
CBlockIndex curr;
|
||||
curr.pprev = &prev;
|
||||
curr.nTime = 1472700300;
|
||||
curr.nBits = 0x207fffff;
|
||||
|
||||
// Time interval is within 5 minutes, so the min-difficulty block should be
|
||||
// interpreted as a valid network difficulty.
|
||||
EXPECT_EQ(1, GetDifficulty(&curr));
|
||||
EXPECT_EQ(1, GetNetworkDifficulty(&curr));
|
||||
|
||||
curr.nTime += 1;
|
||||
|
||||
// Time interval is over 5 minutes, so the min-difficulty block should be
|
||||
// ignored for network difficulty determination.
|
||||
EXPECT_EQ(1, GetDifficulty(&curr));
|
||||
// We have to check this directly, because of some combination of rounding
|
||||
// and truncation issues that result in Google Test displaying 4 != 4
|
||||
EXPECT_EQ((double)0x7fffff/(double)0x1fffff, GetNetworkDifficulty(&curr));
|
||||
}
|
||||
|
||||
extern json_spirit::Object blockToJSON(const CBlock& block, const CBlockIndex* blockindex, bool txDetails = false);
|
||||
|
||||
TEST(rpc, check_blockToJSON_returns_minified_solution) {
|
||||
|
||||
Reference in New Issue
Block a user