@@ -73,7 +73,7 @@ static const uint256 hashGenesisBlockTestNet = uint256S("0x00006e037d7b84104208e
73
73
// ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
74
74
inline bool IsProtocolV2 (int nHeight)
75
75
{
76
- return (fTestNet ? nHeight > 2060 : nHeight > 85400 );
76
+ return (fTestNet ? nHeight > 2060 : nHeight > 85400 );
77
77
}
78
78
79
79
inline bool IsResearchAgeEnabled (int nHeight)
@@ -119,7 +119,7 @@ inline bool IsV11Enabled(int nHeight)
119
119
120
120
inline int GetSuperblockAgeSpacing (int nHeight)
121
121
{
122
- return (fTestNet ? 86400 : (nHeight > 364500 ) ? 86400 : 43200 );
122
+ return (fTestNet ? 86400 : (nHeight > 364500 ) ? 86400 : 43200 );
123
123
}
124
124
125
125
inline bool IsV9Enabled_Tally (int nHeight)
@@ -617,7 +617,7 @@ class CTransaction
617
617
// Denial-of-service detection:
618
618
mutable int nDoS;
619
619
bool DoS (int nDoSIn, bool fIn ) const { nDoS += nDoSIn; return fIn ; }
620
- std::string hashBoinc;
620
+ std::string hashBoinc;
621
621
622
622
CTransaction ()
623
623
{
@@ -635,7 +635,7 @@ class CTransaction
635
635
READWRITE (vout);
636
636
READWRITE (nLockTime);
637
637
638
- READWRITE (hashBoinc);
638
+ READWRITE (hashBoinc);
639
639
}
640
640
641
641
void SetNull ()
@@ -646,7 +646,7 @@ class CTransaction
646
646
vout.clear ();
647
647
nLockTime = 0 ;
648
648
nDoS = 0 ; // Denial-of-service prevention
649
- hashBoinc=" " ;
649
+ hashBoinc=" " ;
650
650
}
651
651
652
652
bool IsNull () const
@@ -1003,19 +1003,83 @@ class CTxIndex
1003
1003
* Blocks are appended to blk0001.dat files on disk. Their location on disk
1004
1004
* is indexed by CBlockIndex objects in memory.
1005
1005
*/
1006
- class CBlock
1006
+ class CBlockHeader
1007
1007
{
1008
1008
public:
1009
+ static const int32_t CURRENT_VERSION = 10 ;
1010
+
1009
1011
// header
1010
- static const int CURRENT_VERSION = 10 ;
1011
- int nVersion;
1012
+ int32_t nVersion;
1012
1013
uint256 hashPrevBlock;
1013
1014
uint256 hashMerkleRoot;
1014
- unsigned int nTime;
1015
- unsigned int nBits;
1015
+ uint32_t nTime;
1016
+ uint32_t nBits;
1017
+ uint32_t nNonce;
1016
1018
1017
- unsigned int nNonce;
1019
+ CBlockHeader ()
1020
+ {
1021
+ SetNull ();
1022
+ }
1023
+
1024
+ ADD_SERIALIZE_METHODS;
1025
+
1026
+ template <typename Stream, typename Operation>
1027
+ inline void SerializationOp (Stream& s, Operation ser_action)
1028
+ {
1029
+ READWRITE (nVersion);
1030
+ READWRITE (hashPrevBlock);
1031
+ READWRITE (hashMerkleRoot);
1032
+ READWRITE (nTime);
1033
+ READWRITE (nBits);
1034
+
1035
+ // Besides early blocks, Gridcoin uses Proof-of-Stake for consensus,
1036
+ // so we don't need the nonce field. Don't serialize it after blocks
1037
+ // version 11 and later:
1038
+ //
1039
+ if (nVersion <= 10 ) {
1040
+ READWRITE (nNonce);
1041
+ }
1042
+ }
1043
+
1044
+ void SetNull ()
1045
+ {
1046
+ nVersion = CURRENT_VERSION;
1047
+ hashPrevBlock.SetNull ();
1048
+ hashMerkleRoot.SetNull ();
1049
+ nTime = 0 ;
1050
+ nBits = 0 ;
1051
+ nNonce = 0 ;
1052
+ }
1018
1053
1054
+ bool IsNull () const
1055
+ {
1056
+ return (nBits == 0 );
1057
+ }
1058
+
1059
+ uint256 GetHash () const
1060
+ {
1061
+ if (nVersion >= 11 )
1062
+ return Hash (BEGIN (nVersion), END (nBits));
1063
+ else if (nVersion >= 7 )
1064
+ return Hash (BEGIN (nVersion), END (nNonce));
1065
+ else
1066
+ return GetPoWHash ();
1067
+ }
1068
+
1069
+ uint256 GetPoWHash () const
1070
+ {
1071
+ return scrypt_blockhash (CVOIDBEGIN (nVersion));
1072
+ }
1073
+
1074
+ int64_t GetBlockTime () const
1075
+ {
1076
+ return (int64_t )nTime;
1077
+ }
1078
+ };
1079
+
1080
+ class CBlock : public CBlockHeader
1081
+ {
1082
+ public:
1019
1083
// network and disk
1020
1084
std::vector<CTransaction> vtx;
1021
1085
@@ -1037,17 +1101,18 @@ class CBlock
1037
1101
SetNull ();
1038
1102
}
1039
1103
1104
+ CBlock (const CBlockHeader &header)
1105
+ {
1106
+ SetNull ();
1107
+ *(static_cast <CBlockHeader*>(this )) = header;
1108
+ }
1109
+
1040
1110
ADD_SERIALIZE_METHODS;
1041
1111
1042
1112
template <typename Stream, typename Operation>
1043
1113
inline void SerializationOp (Stream& s, Operation ser_action)
1044
1114
{
1045
- READWRITE (nVersion);
1046
- READWRITE (hashPrevBlock);
1047
- READWRITE (hashMerkleRoot);
1048
- READWRITE (nTime);
1049
- READWRITE (nBits);
1050
- READWRITE (nNonce);
1115
+ READWRITEAS (CBlockHeader, *this );
1051
1116
1052
1117
// ConnectBlock depends on vtx following header to generate CDiskTxPos
1053
1118
if (!(s.GetType () & (SER_GETHASH|SER_BLOCKHEADERONLY))) {
@@ -1077,35 +1142,25 @@ class CBlock
1077
1142
1078
1143
void SetNull ()
1079
1144
{
1080
- nVersion = CBlock::CURRENT_VERSION;
1081
- hashPrevBlock.SetNull ();
1082
- hashMerkleRoot.SetNull ();
1083
- nTime = 0 ;
1084
- nBits = 0 ;
1085
- nNonce = 0 ;
1145
+ CBlockHeader::SetNull ();
1146
+
1086
1147
vtx.clear ();
1087
1148
vchBlockSig.clear ();
1088
- vMerkleTree.clear ();
1149
+ vMerkleTree.clear ();
1089
1150
nDoS = 0 ;
1090
1151
m_claim = NN::Claim ();
1091
1152
}
1092
1153
1093
- bool IsNull () const
1154
+ CBlockHeader GetBlockHeader () const
1094
1155
{
1095
- return (nBits == 0 );
1096
- }
1097
-
1098
- uint256 GetHash () const
1099
- {
1100
- if (nVersion > 6 )
1101
- return Hash (BEGIN (nVersion), END (nNonce));
1102
- else
1103
- return GetPoWHash ();
1104
- }
1105
-
1106
- uint256 GetPoWHash () const
1107
- {
1108
- return scrypt_blockhash (CVOIDBEGIN (nVersion));
1156
+ CBlockHeader block;
1157
+ block.nVersion = nVersion;
1158
+ block.hashPrevBlock = hashPrevBlock;
1159
+ block.hashMerkleRoot = hashMerkleRoot;
1160
+ block.nTime = nTime;
1161
+ block.nBits = nBits;
1162
+ block.nNonce = nNonce;
1163
+ return block;
1109
1164
}
1110
1165
1111
1166
const NN::Claim& GetClaim () const
@@ -1140,11 +1195,6 @@ class CBlock
1140
1195
return GetClaim ().m_superblock ;
1141
1196
}
1142
1197
1143
- int64_t GetBlockTime () const
1144
- {
1145
- return (int64_t )nTime;
1146
- }
1147
-
1148
1198
// entropy bit for stake modifier if chosen by modifier
1149
1199
unsigned int GetStakeEntropyBit () const
1150
1200
{
@@ -1438,9 +1488,9 @@ class CBlockIndex
1438
1488
nIsContract = 0 ;
1439
1489
}
1440
1490
1441
- CBlock GetBlockHeader () const
1491
+ CBlockHeader GetBlockHeader () const
1442
1492
{
1443
- CBlock block;
1493
+ CBlockHeader block;
1444
1494
block.nVersion = nVersion;
1445
1495
if (pprev)
1446
1496
block.hashPrevBlock = pprev->GetBlockHash ();
@@ -1689,7 +1739,7 @@ class CDiskBlockIndex : public CBlockIndex
1689
1739
if (fUseFastIndex && (nTime < GetAdjustedTime () - 24 * 60 * 60 ) && !blockHash.IsNull ())
1690
1740
return blockHash;
1691
1741
1692
- CBlock block;
1742
+ CBlockHeader block;
1693
1743
block.nVersion = nVersion;
1694
1744
block.hashPrevBlock = hashPrev;
1695
1745
block.hashMerkleRoot = hashMerkleRoot;
0 commit comments