Skip to content

Commit d4674c4

Browse files
committed
refactor: move block storage functions to src/node/blockstorage
1 parent 8eb9623 commit d4674c4

File tree

22 files changed

+218
-129
lines changed

22 files changed

+218
-129
lines changed

src/Makefile.am

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ GRIDCOIN_CORE_H = \
142142
mruset.h \
143143
netbase.h \
144144
net.h \
145+
node/blockstorage.h \
145146
pbkdf2.h \
146147
policy/fees.h \
147148
policy/policy.h \
@@ -239,6 +240,7 @@ GRIDCOIN_CORE_CPP = addrdb.cpp \
239240
miner.cpp \
240241
netbase.cpp \
241242
net.cpp \
243+
node/blockstorage.cpp \
242244
noui.cpp \
243245
pbkdf2.cpp \
244246
policy/policy.cpp \

src/chainparams.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,9 @@ class CMainParams : public CChainParams {
6464
consensus.BlockV9TallyHeight = 1144120;
6565
consensus.BlockV10Height = 1420000;
6666
consensus.BlockV11Height = 2053000;
67+
// "standard" scrypt target limit for proof of work, results in 0,000244140625 proof-of-work difficulty.
68+
// Equivalent to ~arith_uint256() >> 20 or 1e0fffff in compact notation.
69+
consensus.powLimit = uint256S("00000fffffffffffffffffffffffffffffffffffffffffffffffffffffffffff");
6770
/**
6871
* The message start string is designed to be unlikely to occur in normal data.
6972
* The characters are rarely used upper ASCII, not valid as UTF-8, and produce
@@ -146,6 +149,8 @@ class CTestNetParams : public CChainParams {
146149
consensus.BlockV9TallyHeight = 399120;
147150
consensus.BlockV10Height = 629409;
148151
consensus.BlockV11Height = 1301500;
152+
// Equivalent to ~arith_uint256() >> 16 or 1f00ffff in compact notation.
153+
consensus.powLimit = uint256S("0000ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff");
149154

150155
pchMessageStart[0] = 0xcd;
151156
pchMessageStart[1] = 0xf2;

src/consensus/params.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,5 +29,7 @@ struct Params {
2929
int BlockV10Height;
3030
/** Block height at which v11 blocks are created */
3131
int BlockV11Height;
32+
33+
uint256 powLimit;
3234
};
3335
} // namespace Consensus

src/gridcoin/accrual/snapshot.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,15 @@
66

77
#include "amount.h"
88
#include "arith_uint256.h"
9+
#include "chainparams.h"
910
#include "fs.h"
1011
#include "gridcoin/account.h"
1112
#include "gridcoin/accrual/computer.h"
1213
#include "gridcoin/beacon.h"
1314
#include "gridcoin/cpid.h"
1415
#include "gridcoin/superblock.h"
1516
#include "gridcoin/support/filehash.h"
17+
#include "node/blockstorage.h"
1618
#include "serialize.h"
1719
#include "streams.h"
1820
#include "tinyformat.h"
@@ -1638,7 +1640,7 @@ class SnapshotBaselineBuilder
16381640

16391641
CBlock block;
16401642

1641-
if (!block.ReadFromDisk(pindex)) {
1643+
if (!ReadBlockFromDisk(block, pindex, Params().GetConsensus())) {
16421644
return error(
16431645
"SnapshotBaselineBuilder: failed to load superblock %" PRIu64,
16441646
pindex->nHeight);

src/gridcoin/contract/contract.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// file COPYING or https://opensource.org/licenses/mit-license.php.
44

55
#include "amount.h"
6+
#include "chainparams.h"
67
#include "main.h"
78
#include "gridcoin/appcache.h"
89
#include "gridcoin/claim.h"
@@ -16,6 +17,7 @@
1617
#include "gridcoin/tx_message.h"
1718
#include "gridcoin/voting/payloads.h"
1819
#include "gridcoin/voting/registry.h"
20+
#include "node/blockstorage.h"
1921
#include "util.h"
2022
#include "wallet/wallet.h"
2123

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

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

491493
if (pindex->IsSuperblock() && pindex->nVersion >= 11) {
492494
if (block.hashPrevBlock != pindex->pprev->GetBlockHash()
493-
&& !block.ReadFromDisk(pindex))
495+
&& !ReadBlockFromDisk(block, pindex, Params().GetConsensus()))
494496
{
495497
continue;
496498
}

src/gridcoin/quorum.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,14 @@
33
// file COPYING or https://opensource.org/licenses/mit-license.php.
44

55
#include "base58.h"
6+
#include "chainparams.h"
67
#include "main.h"
78
#include "gridcoin/claim.h"
89
#include "gridcoin/magnitude.h"
910
#include "gridcoin/quorum.h"
1011
#include "gridcoin/scraper/scraper_net.h"
1112
#include "gridcoin/superblock.h"
13+
#include "node/blockstorage.h"
1214
#include "util/reverse_iterator.h"
1315
#include <util/string.h>
1416

@@ -458,7 +460,7 @@ class LegacyConsensus
458460

459461
while (pindex && pindex->nHeight > min_height) {
460462
CBlock block;
461-
block.ReadFromDisk(pindex);
463+
ReadBlockFromDisk(block, pindex, Params().GetConsensus());
462464

463465
if (block.GetClaim().m_quorum_hash.Valid()) {
464466
Claim claim = block.PullClaim();

src/gridcoin/staking/difficulty.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,13 @@
55

66
#include "amount.h"
77
#include "bignum.h"
8+
#include "chainparams.h"
89
#include "init.h"
910
#include "gridcoin/staking/difficulty.h"
1011
#include "gridcoin/staking/kernel.h"
1112
#include "gridcoin/staking/status.h"
1213
#include "main.h"
14+
#include "node/blockstorage.h"
1315
#include "txdb.h"
1416
#include "wallet/wallet.h"
1517

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

370-
if (!CoinBlock.ReadFromDisk(txindex.pos.nFile, txindex.pos.nBlockPos, false)) continue;
372+
if (!ReadBlockFromDisk(CoinBlock, txindex.pos.nFile, txindex.pos.nBlockPos, Params().GetConsensus(), false))
373+
continue;
371374

372375
// We are going to store as an event the time that the UTXO matures (is available for staking again.)
373376
nTime = (CoinBlock.GetBlockTime() & ~ETTS_TIMESTAMP_MASK) + nStakeMinAge;

src/gridcoin/superblock.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@
22
// Distributed under the MIT/X11 software license, see the accompanying
33
// file COPYING or https://opensource.org/licenses/mit-license.php.
44

5+
#include "chainparams.h"
56
#include "compat/endian.h"
67
#include "hash.h"
78
#include "main.h"
89
#include "gridcoin/superblock.h"
910
#include "gridcoin/support/xml.h"
11+
#include "node/blockstorage.h"
1012
#include "sync.h"
1113
#include "util.h"
1214
#include "util/reverse_iterator.h"
@@ -981,7 +983,7 @@ SuperblockPtr SuperblockPtr::ReadFromDisk(const CBlockIndex* const pindex)
981983

982984
CBlock block;
983985

984-
if (!block.ReadFromDisk(pindex)) {
986+
if (!ReadBlockFromDisk(block, pindex, Params().GetConsensus())) {
985987
error("%s: failed to read superblock from disk", __func__);
986988
return Empty();
987989
}

src/gridcoin/voting/builders.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// file COPYING or https://opensource.org/licenses/mit-license.php.
44

55
#include "amount.h"
6+
#include "chainparams.h"
67
#include "init.h"
78
#include "main.h"
89
#include "gridcoin/beacon.h"
@@ -13,6 +14,7 @@
1314
#include "gridcoin/voting/claims.h"
1415
#include "gridcoin/voting/payloads.h"
1516
#include "gridcoin/voting/registry.h"
17+
#include "node/blockstorage.h"
1618
#include "ui_interface.h"
1719
#include "wallet/wallet.h"
1820
#include <util/string.h>
@@ -594,7 +596,7 @@ class MagnitudeClaimBuilder
594596
continue;
595597
}
596598

597-
if (!block.ReadFromDisk(pindex)) {
599+
if (!ReadBlockFromDisk(block, pindex, Params().GetConsensus())) {
598600
break;
599601
}
600602

src/gridcoin/voting/registry.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// file COPYING or https://opensource.org/licenses/mit-license.php.
44

55
#include "amount.h"
6+
#include "chainparams.h"
67
#include "main.h"
78
#include "gridcoin/claim.h"
89
#include "gridcoin/researcher.h"
@@ -12,6 +13,7 @@
1213
#include "gridcoin/voting/registry.h"
1314
#include "gridcoin/voting/vote.h"
1415
#include "gridcoin/support/block_finder.h"
16+
#include "node/blockstorage.h"
1517
#include "txdb.h"
1618
#include "ui_interface.h"
1719
#include "validation.h"
@@ -696,7 +698,7 @@ const PollReference* PollRegistry::TryByTxidWithAddHistoricalPollAndVotes(const
696698
// a valid vote.
697699
for (CBlockIndex* pindex = pindex_poll; pindex; pindex = pindex->pnext) {
698700
// If the block doesn't contain contract(s) or can't read, skip.
699-
if (!pindex->IsContract() || !block.ReadFromDisk(pindex, true)) continue;
701+
if (!pindex->IsContract() || !ReadBlockFromDisk(block, pindex, Params().GetConsensus())) continue;
700702

701703
// Skip coinbase and coinstake transactions:
702704
for (unsigned int i = 2; i < block.vtx.size(); ++i) {

0 commit comments

Comments
 (0)