Skip to content

Commit

Permalink
Merge pull request #2273 from div72/move-block-methods
Browse files Browse the repository at this point in the history
refactor: move block storage functions to src/node/blockstorage
  • Loading branch information
jamescowens authored Aug 15, 2021
2 parents ecd0c59 + d4674c4 commit 338da0c
Show file tree
Hide file tree
Showing 22 changed files with 218 additions and 129 deletions.
2 changes: 2 additions & 0 deletions src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ GRIDCOIN_CORE_H = \
mruset.h \
netbase.h \
net.h \
node/blockstorage.h \
pbkdf2.h \
policy/fees.h \
policy/policy.h \
Expand Down Expand Up @@ -239,6 +240,7 @@ GRIDCOIN_CORE_CPP = addrdb.cpp \
miner.cpp \
netbase.cpp \
net.cpp \
node/blockstorage.cpp \
noui.cpp \
pbkdf2.cpp \
policy/policy.cpp \
Expand Down
5 changes: 5 additions & 0 deletions src/chainparams.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ class CMainParams : public CChainParams {
consensus.BlockV9TallyHeight = 1144120;
consensus.BlockV10Height = 1420000;
consensus.BlockV11Height = 2053000;
// "standard" scrypt target limit for proof of work, results in 0,000244140625 proof-of-work difficulty.
// Equivalent to ~arith_uint256() >> 20 or 1e0fffff in compact notation.
consensus.powLimit = uint256S("00000fffffffffffffffffffffffffffffffffffffffffffffffffffffffffff");
/**
* The message start string is designed to be unlikely to occur in normal data.
* The characters are rarely used upper ASCII, not valid as UTF-8, and produce
Expand Down Expand Up @@ -146,6 +149,8 @@ class CTestNetParams : public CChainParams {
consensus.BlockV9TallyHeight = 399120;
consensus.BlockV10Height = 629409;
consensus.BlockV11Height = 1301500;
// Equivalent to ~arith_uint256() >> 16 or 1f00ffff in compact notation.
consensus.powLimit = uint256S("0000ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff");

pchMessageStart[0] = 0xcd;
pchMessageStart[1] = 0xf2;
Expand Down
2 changes: 2 additions & 0 deletions src/consensus/params.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,7 @@ struct Params {
int BlockV10Height;
/** Block height at which v11 blocks are created */
int BlockV11Height;

uint256 powLimit;
};
} // namespace Consensus
4 changes: 3 additions & 1 deletion src/gridcoin/accrual/snapshot.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@

#include "amount.h"
#include "arith_uint256.h"
#include "chainparams.h"
#include "fs.h"
#include "gridcoin/account.h"
#include "gridcoin/accrual/computer.h"
#include "gridcoin/beacon.h"
#include "gridcoin/cpid.h"
#include "gridcoin/superblock.h"
#include "gridcoin/support/filehash.h"
#include "node/blockstorage.h"
#include "serialize.h"
#include "streams.h"
#include "tinyformat.h"
Expand Down Expand Up @@ -1641,7 +1643,7 @@ class SnapshotBaselineBuilder

CBlock block;

if (!block.ReadFromDisk(pindex)) {
if (!ReadBlockFromDisk(block, pindex, Params().GetConsensus())) {
return error(
"SnapshotBaselineBuilder: failed to load superblock %" PRIu64,
pindex->nHeight);
Expand Down
6 changes: 4 additions & 2 deletions src/gridcoin/contract/contract.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// file COPYING or https://opensource.org/licenses/mit-license.php.

#include "amount.h"
#include "chainparams.h"
#include "main.h"
#include "gridcoin/appcache.h"
#include "gridcoin/claim.h"
Expand All @@ -16,6 +17,7 @@
#include "gridcoin/tx_message.h"
#include "gridcoin/voting/payloads.h"
#include "gridcoin/voting/registry.h"
#include "node/blockstorage.h"
#include "util.h"
#include "wallet/wallet.h"

Expand Down Expand Up @@ -457,7 +459,7 @@ void GRC::ReplayContracts(CBlockIndex* pindex_end, CBlockIndex* pindex_start)
// have to be checked, OR the block index entry is already marked to contain contract(s),
// then apply the contracts found in the block.
if (beacons.NeedsIsContractCorrection() || pindex->IsContract()) {
if (!block.ReadFromDisk(pindex)) {
if (!ReadBlockFromDisk(block, pindex, Params().GetConsensus())) {
continue;
}

Expand Down Expand Up @@ -490,7 +492,7 @@ void GRC::ReplayContracts(CBlockIndex* pindex_end, CBlockIndex* pindex_start)

if (pindex->IsSuperblock() && pindex->nVersion >= 11) {
if (block.hashPrevBlock != pindex->pprev->GetBlockHash()
&& !block.ReadFromDisk(pindex))
&& !ReadBlockFromDisk(block, pindex, Params().GetConsensus()))
{
continue;
}
Expand Down
4 changes: 3 additions & 1 deletion src/gridcoin/quorum.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@
// file COPYING or https://opensource.org/licenses/mit-license.php.

#include "base58.h"
#include "chainparams.h"
#include "main.h"
#include "gridcoin/claim.h"
#include "gridcoin/magnitude.h"
#include "gridcoin/quorum.h"
#include "gridcoin/scraper/scraper_net.h"
#include "gridcoin/superblock.h"
#include "node/blockstorage.h"
#include "util/reverse_iterator.h"
#include <util/string.h>

Expand Down Expand Up @@ -458,7 +460,7 @@ class LegacyConsensus

while (pindex && pindex->nHeight > min_height) {
CBlock block;
block.ReadFromDisk(pindex);
ReadBlockFromDisk(block, pindex, Params().GetConsensus());

if (block.GetClaim().m_quorum_hash.Valid()) {
Claim claim = block.PullClaim();
Expand Down
5 changes: 4 additions & 1 deletion src/gridcoin/staking/difficulty.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@

#include "amount.h"
#include "bignum.h"
#include "chainparams.h"
#include "init.h"
#include "gridcoin/staking/difficulty.h"
#include "gridcoin/staking/kernel.h"
#include "gridcoin/staking/status.h"
#include "main.h"
#include "node/blockstorage.h"
#include "txdb.h"
#include "wallet/wallet.h"

Expand Down Expand Up @@ -367,7 +369,8 @@ double GRC::GetEstimatedTimetoStake(bool ignore_staking_status, double dDiff, do
CBlock CoinBlock; //Block which contains CoinTx
if (!txdb.ReadTxIndex(out.tx->GetHash(), txindex)) continue; //Ignore transactions that can't be read.

if (!CoinBlock.ReadFromDisk(txindex.pos.nFile, txindex.pos.nBlockPos, false)) continue;
if (!ReadBlockFromDisk(CoinBlock, txindex.pos.nFile, txindex.pos.nBlockPos, Params().GetConsensus(), false))
continue;

// We are going to store as an event the time that the UTXO matures (is available for staking again.)
nTime = (CoinBlock.GetBlockTime() & ~ETTS_TIMESTAMP_MASK) + nStakeMinAge;
Expand Down
4 changes: 3 additions & 1 deletion src/gridcoin/superblock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@
// Distributed under the MIT/X11 software license, see the accompanying
// file COPYING or https://opensource.org/licenses/mit-license.php.

#include "chainparams.h"
#include "compat/endian.h"
#include "hash.h"
#include "main.h"
#include "gridcoin/superblock.h"
#include "gridcoin/support/xml.h"
#include "node/blockstorage.h"
#include "sync.h"
#include "util.h"
#include "util/reverse_iterator.h"
Expand Down Expand Up @@ -1018,7 +1020,7 @@ SuperblockPtr SuperblockPtr::ReadFromDisk(const CBlockIndex* const pindex)

CBlock block;

if (!block.ReadFromDisk(pindex)) {
if (!ReadBlockFromDisk(block, pindex, Params().GetConsensus())) {
error("%s: failed to read superblock from disk", __func__);
return Empty();
}
Expand Down
4 changes: 3 additions & 1 deletion src/gridcoin/voting/builders.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// file COPYING or https://opensource.org/licenses/mit-license.php.

#include "amount.h"
#include "chainparams.h"
#include "init.h"
#include "main.h"
#include "gridcoin/beacon.h"
Expand All @@ -13,6 +14,7 @@
#include "gridcoin/voting/claims.h"
#include "gridcoin/voting/payloads.h"
#include "gridcoin/voting/registry.h"
#include "node/blockstorage.h"
#include "ui_interface.h"
#include "wallet/wallet.h"
#include <util/string.h>
Expand Down Expand Up @@ -592,7 +594,7 @@ class MagnitudeClaimBuilder
continue;
}

if (!block.ReadFromDisk(pindex)) {
if (!ReadBlockFromDisk(block, pindex, Params().GetConsensus())) {
break;
}

Expand Down
4 changes: 3 additions & 1 deletion src/gridcoin/voting/registry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// file COPYING or https://opensource.org/licenses/mit-license.php.

#include "amount.h"
#include "chainparams.h"
#include "main.h"
#include "gridcoin/claim.h"
#include "gridcoin/researcher.h"
Expand All @@ -12,6 +13,7 @@
#include "gridcoin/voting/registry.h"
#include "gridcoin/voting/vote.h"
#include "gridcoin/support/block_finder.h"
#include "node/blockstorage.h"
#include "txdb.h"
#include "ui_interface.h"
#include "validation.h"
Expand Down Expand Up @@ -696,7 +698,7 @@ const PollReference* PollRegistry::TryByTxidWithAddHistoricalPollAndVotes(const
// a valid vote.
for (CBlockIndex* pindex = pindex_poll; pindex; pindex = pindex->pnext) {
// If the block doesn't contain contract(s) or can't read, skip.
if (!pindex->IsContract() || !block.ReadFromDisk(pindex, true)) continue;
if (!pindex->IsContract() || !ReadBlockFromDisk(block, pindex, Params().GetConsensus())) continue;

// Skip coinbase and coinstake transactions:
for (unsigned int i = 2; i < block.vtx.size(); ++i) {
Expand Down
3 changes: 2 additions & 1 deletion src/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include "scheduler.h"
#include "gridcoin/gridcoin.h"
#include "miner.h"
#include "node/blockstorage.h"

#include <boost/algorithm/string/predicate.hpp>
#include <openssl/crypto.h>
Expand Down Expand Up @@ -1185,7 +1186,7 @@ bool AppInit2(ThreadHandlerPtr threads)
{
CBlockIndex* pindex = mi->second;
CBlock block;
block.ReadFromDisk(pindex);
ReadBlockFromDisk(block, pindex, Params().GetConsensus());
block.print();
LogPrintf("");
nFound++;
Expand Down
Loading

0 comments on commit 338da0c

Please sign in to comment.