GetBlockChecked always returning genesis block? currently I'm exploring Bitcoin source code and I tried to add custom function getblockvalue inside of blockchain.cpp. 
Purpose of function is to return sum of all transaction outputs inside of a block based on given height as an argument.
static UniValue getblockvalue(const JSONRPCRequest&amp; request)
{
    int blockHeight = request.params[0].get_int();
    if (blockHeight &lt; 0 || blockHeight &gt; ::ChainActive().Height())
    {
        throw JSONRPCError(RPC_INVALID_PARAMETER, &quot;Block height out of range&quot;);
    }
        
    CBlockIndex* pBlockIndex = ::ChainActive()[blockHeight];
    if(pBlockIndex == nullptr)
    {
        throw JSONRPCError(RPC_INVALID_PARAMETER, &quot;Block index is NULL&quot;);
    
    }
    const CBlock block = GetBlockChecked(pBlockIndex);
    UniValue resultObject(UniValue::VOBJ);
    double blockValue = 0;
    int numberOfTransactions = 0;
    
    for(const auto &amp;transaction : block.vtx)
    {
        for (unsigned int i = 0; i &lt; transaction-&gt;vout.size(); ++i)
        {
            blockValue+= transaction-&gt;vout[i].nValue;
        }
        ++numberOfTransactions;
    }
    
    resultObject.pushKV(&quot;blockHeight&quot;,          (int)blockHeight);
    resultObject.pushKV(&quot;numberOfTransactions&quot;, (int)numberOfTransactions);
    resultObject.pushKV(&quot;blockValue&quot;,           ValueFromAmount(blockValue));
    
    return resultObject;
}


I did all necessary changes: I added argument to vRPCConvertParams[] and extended CRPCCommand commands[].
So, I tried calling bitcoin-cli -testnet getblockvalue 25; result is: 
{
&quot;blockHeight&quot; : 25,
&quot;numberOfTransactions&quot; : 1,
&quot;blockValue&quot; : 50.00000000
}

The result is the same for every given block height. It always gives me information about genesis block. Can you help me what did I do wrong here?
Ok, so the code is just fine as Andrew assumed. 
It was odd to me that first several blocks are the same. They all have one transaction and the same output value of 50BTC, but according to site https://blockstream.info/testnet/, where you just type a block height in search bar and you can see all transactions inside of resulting block, this is correct.