Skip to content

Commit

Permalink
Merge pull request #277 from syscoin/dev-3.x
Browse files Browse the repository at this point in the history
Dev 3.x

Former-commit-id: 53011dc
  • Loading branch information
sidhujag committed Sep 6, 2018
2 parents f15f40a + aa9f248 commit 022451e
Show file tree
Hide file tree
Showing 6 changed files with 91 additions and 8 deletions.
2 changes: 1 addition & 1 deletion configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ dnl require autoconf 2.60 (AS_ECHO/AS_ECHO_N)
AC_PREREQ([2.60])
define(_CLIENT_VERSION_MAJOR, 3)
define(_CLIENT_VERSION_MINOR, 1)
define(_CLIENT_VERSION_REVISION, 1)
define(_CLIENT_VERSION_REVISION, 2)
define(_CLIENT_VERSION_BUILD, 0)
define(_CLIENT_VERSION_IS_RELEASE, true)
define(_DASH_VERSION_MAJOR, 0)
Expand Down
17 changes: 12 additions & 5 deletions src/chainparams.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -215,10 +215,10 @@ class CMainParams : public CChainParams {


// The best chain should have at least this much work.
consensus.nMinimumChainWork = uint256S("0x00");
consensus.nMinimumChainWork = uint256S("0x0000000000000000000000000000000000000000005634d096686def750e9842"); // 176000

// By default assume that the signatures in ancestors of this block are valid.
consensus.defaultAssumeValid = uint256S("0x00");
consensus.defaultAssumeValid = uint256S("0x92025d074fdd503b0f0f4d4a11dcfbc8a57509d0a196bb400ebdb19556d61b0d"); // 176000

/**
* The message start string is designed to be unlikely to occur in normal data.
Expand Down Expand Up @@ -283,13 +283,20 @@ class CMainParams : public CChainParams {
checkpointData = {
{
{ 0, uint256S("0x000006e5c08d6d2414435b294210266753b05a75f90e926dd5e6082306812622") },
{ 100000, uint256S("28b16c3500a8ede47d2a2373f9a5f9a25f38273daf3b4da2ba0001ca80fe6c4b") },
{ 150000, uint256S("8e1a7181aaa84885d741b803d18d283663d0b25f8763224281dcc09c4fa874c9") },
{ 170000, uint256S("98f57b8ca0834c19edad1dd01ebe13809956ec35b57b5d0b237eb7fee0a59965") },
{ 170001, uint256S("796579749c97a1bb0414457a7833ac9968b93987292ccda9481172ae548b1588") },
{ 171000, uint256S("4f2a4785a18e693c3283cc2c66c9f2b93f3fd20b8ee958f23b7a9f30800d13d2") },
{ 176000, uint256S("92025d074fdd503b0f0f4d4a11dcfbc8a57509d0a196bb400ebdb19556d61b0d") },
}
};

chainTxData = ChainTxData{
0,
0,
0
// Data from rpc: getchaintxstats 4096 92025d074fdd503b0f0f4d4a11dcfbc8a57509d0a196bb400ebdb19556d61b0d
/* nTime */ 1536219041,
/* nTxCount */ 307792,
/* dTxRate */ 0.019
};
}
};
Expand Down
2 changes: 1 addition & 1 deletion src/clientversion.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
//! These need to be macros, as clientversion.cpp's and syscoin*-res.rc's voodoo requires it
#define CLIENT_VERSION_MAJOR 3
#define CLIENT_VERSION_MINOR 1
#define CLIENT_VERSION_REVISION 1
#define CLIENT_VERSION_REVISION 2
#define CLIENT_VERSION_BUILD 0

//! Set to true for release, false for prerelease or test build
Expand Down
75 changes: 75 additions & 0 deletions src/rpc/blockchain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1619,11 +1619,86 @@ UniValue reconsiderblock(const JSONRPCRequest& request)

return NullUniValue;
}
UniValue getchaintxstats(const JSONRPCRequest& request)
{
if (request.fHelp || request.params.size() > 2)
throw std::runtime_error(
"getchaintxstats ( nblocks blockhash )\n"
"\nCompute statistics about the total number and rate of transactions in the chain.\n"
"\nArguments:\n"
"1. nblocks (numeric, optional) Size of the window in number of blocks (default: one month).\n"
"2. \"blockhash\" (string, optional) The hash of the block that ends the window.\n"
"\nResult:\n"
"{\n"
" \"time\": xxxxx, (numeric) The timestamp for the final block in the window in UNIX format.\n"
" \"txcount\": xxxxx, (numeric) The total number of transactions in the chain up to that point.\n"
" \"window_final_block_hash\": \"...\", (string) The hash of the final block in the window.\n"
" \"window_block_count\": xxxxx, (numeric) Size of the window in number of blocks.\n"
" \"window_tx_count\": xxxxx, (numeric) The number of transactions in the window. Only returned if \"window_block_count\" is > 0.\n"
" \"window_interval\": xxxxx, (numeric) The elapsed time in the window in seconds. Only returned if \"window_block_count\" is > 0.\n"
" \"txrate\": x.xx, (numeric) The average rate of transactions per second in the window. Only returned if \"window_interval\" is > 0.\n"
"}\n"
"\nExamples:\n"
+ HelpExampleCli("getchaintxstats", "")
+ HelpExampleRpc("getchaintxstats", "2016")
);

const CBlockIndex* pindex;
int blockcount = 30 * 24 * 60 * 60 / Params().GetConsensus().nPowTargetSpacing; // By default: 1 month

if (request.params[1].isNull()) {
LOCK(cs_main);
pindex = chainActive.Tip();
}
else {
uint256 hash = uint256S(request.params[1].get_str());
LOCK(cs_main);
pindex = mapBlockIndex[hash];
if (!pindex) {
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Block not found");
}
if (!chainActive.Contains(pindex)) {
throw JSONRPCError(RPC_INVALID_PARAMETER, "Block is not in main chain");
}
}

assert(pindex != nullptr);

if (request.params[0].isNull()) {
blockcount = std::max(0, std::min(blockcount, pindex->nHeight - 1));
}
else {
blockcount = request.params[0].get_int();

if (blockcount < 0 || (blockcount > 0 && blockcount >= pindex->nHeight)) {
throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid block count: should be between 0 and the block's height - 1");
}
}

const CBlockIndex* pindexPast = pindex->GetAncestor(pindex->nHeight - blockcount);
int nTimeDiff = pindex->GetMedianTimePast() - pindexPast->GetMedianTimePast();
int nTxDiff = pindex->nChainTx - pindexPast->nChainTx;

UniValue ret(UniValue::VOBJ);
ret.pushKV("time", (int64_t)pindex->nTime);
ret.pushKV("txcount", (int64_t)pindex->nChainTx);
ret.pushKV("window_final_block_hash", pindex->GetBlockHash().GetHex());
ret.pushKV("window_block_count", blockcount);
if (blockcount > 0) {
ret.pushKV("window_tx_count", nTxDiff);
ret.pushKV("window_interval", nTimeDiff);
if (nTimeDiff > 0) {
ret.pushKV("txrate", ((double)nTxDiff) / nTimeDiff);
}
}

return ret;
}
static const CRPCCommand commands[] =
{ // category name actor (function) okSafe argNames
// --------------------- ------------------------ ----------------------- ------ ----------
{ "blockchain", "getblockchaininfo", &getblockchaininfo, true, {} },
{ "blockchain", "getchaintxstats", &getchaintxstats, true, { "nblocks", "blockhash" } },
{ "blockchain", "getbestblockhash", &getbestblockhash, true, {} },
{ "blockchain", "getblockcount", &getblockcount, true, {} },
{ "blockchain", "getblock", &getblock, true, {"blockhash","verbose"} },
Expand Down
1 change: 1 addition & 0 deletions src/rpc/client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ static const CRPCConvertParam vRPCConvertParams[] =
{ "getblockheader", 1, "verbose" },
{ "getblockheaders", 1, "count" },
{ "getblockheaders", 2, "verbose" },
{ "getchaintxstats", 0, "nblocks" },
{ "gettransaction", 1, "include_watchonly" },
{ "getrawtransaction", 1, "verbose" },
{ "createrawtransaction", 0, "inputs" },
Expand Down
2 changes: 1 addition & 1 deletion src/version.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
*/


static const int PROTOCOL_VERSION = 70223;
static const int PROTOCOL_VERSION = 70224;

//! initial proto version, to be increased after version/verack negotiation
static const int INIT_PROTO_VERSION = 209;
Expand Down

0 comments on commit 022451e

Please sign in to comment.