Move prev/next sb height logic from rpc to CSuperblock::GetNearestSuperblocksHeights (#1919)

This commit is contained in:
UdjinM6 2018-02-12 15:46:55 +03:00 committed by GitHub
parent 312088b560
commit 0670695fea
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 24 additions and 23 deletions

View File

@ -523,6 +523,25 @@ bool CSuperblock::IsValidBlockHeight(int nBlockHeight)
((nBlockHeight % Params().GetConsensus().nSuperblockCycle) == 0);
}
void CSuperblock::GetNearestSuperblocksHeights(int nBlockHeight, int& nLastSuperblockRet, int& nNextSuperblockRet)
{
const Consensus::Params& consensusParams = Params().GetConsensus();
int nSuperblockStartBlock = consensusParams.nSuperblockStartBlock;
int nSuperblockCycle = consensusParams.nSuperblockCycle;
// Get first superblock
int nFirstSuperblockOffset = (nSuperblockCycle - nSuperblockStartBlock % nSuperblockCycle) % nSuperblockCycle;
int nFirstSuperblock = nSuperblockStartBlock + nFirstSuperblockOffset;
if(nBlockHeight < nFirstSuperblock) {
nLastSuperblockRet = 0;
nNextSuperblockRet = nFirstSuperblock;
} else {
nLastSuperblockRet = nBlockHeight - nBlockHeight % nSuperblockCycle;
nNextSuperblockRet = nLastSuperblockRet + nSuperblockCycle;
}
}
CAmount CSuperblock::GetPaymentsLimit(int nBlockHeight)
{
const Consensus::Params& consensusParams = Params().GetConsensus();

View File

@ -160,6 +160,7 @@ public:
CSuperblock(uint256& nHash);
static bool IsValidBlockHeight(int nBlockHeight);
static void GetNearestSuperblocksHeights(int nBlockHeight, int& nLastSuperblockRet, int& nNextSuperblockRet);
static CAmount GetPaymentsLimit(int nBlockHeight);
int GetStatus() { return nStatus; }

View File

@ -931,31 +931,12 @@ UniValue getgovernanceinfo(const JSONRPCRequest& request)
);
}
// Compute last/next superblock
int nLastSuperblock, nNextSuperblock;
LOCK(cs_main);
// Get current block height
int nBlockHeight = 0;
{
LOCK(cs_main);
nBlockHeight = (int)chainActive.Height();
}
int nLastSuperblock = 0, nNextSuperblock = 0;
int nBlockHeight = chainActive.Height();
// Get chain parameters
int nSuperblockStartBlock = Params().GetConsensus().nSuperblockStartBlock;
int nSuperblockCycle = Params().GetConsensus().nSuperblockCycle;
// Get first superblock
int nFirstSuperblockOffset = (nSuperblockCycle - nSuperblockStartBlock % nSuperblockCycle) % nSuperblockCycle;
int nFirstSuperblock = nSuperblockStartBlock + nFirstSuperblockOffset;
if(nBlockHeight < nFirstSuperblock){
nLastSuperblock = 0;
nNextSuperblock = nFirstSuperblock;
} else {
nLastSuperblock = nBlockHeight - nBlockHeight % nSuperblockCycle;
nNextSuperblock = nLastSuperblock + nSuperblockCycle;
}
CSuperblock::GetNearestSuperblocksHeights(nBlockHeight, nLastSuperblock, nNextSuperblock);
UniValue obj(UniValue::VOBJ);
obj.push_back(Pair("governanceminquorum", Params().GetConsensus().nGovernanceMinQuorum));