PPCoin: Move vchBlockSig to after vtx and fix CDiskTxPos calculation
authorScott Nadal <scottnadal@gmail.com>
Sat, 31 Mar 2012 18:42:13 +0000 (19:42 +0100)
committerScott Nadal <scottnadal@gmail.com>
Sat, 31 Mar 2012 18:42:13 +0000 (19:42 +0100)
src/main.cpp
src/main.h

index a6cdccb..388f1db 100644 (file)
@@ -1062,7 +1062,7 @@ bool CBlock::ConnectBlock(CTxDB& txdb, CBlockIndex* pindex)
         return false;
 
     //// issue here: it doesn't know the version
-    unsigned int nTxPos = pindex->nBlockPos + ::GetSerializeSize(CBlock(), SER_DISK) - 1 + GetSizeOfCompactSize(vtx.size());
+    unsigned int nTxPos = pindex->nBlockPos + ::GetSerializeSize(CBlock(), SER_DISK) - (2 * GetSizeOfCompactSize(0)) + GetSizeOfCompactSize(vtx.size());
 
     map<uint256, CTxIndex> mapQueuedChanges;
     int64 nFees = 0;
index 59b88ce..cad0069 100644 (file)
@@ -807,13 +807,12 @@ public:
     unsigned int nBits;
     unsigned int nNonce;
 
-    // ppcoin: block signature (not considered part of header)
-    //         signed by coin base txout[0]'s owner
-    std::vector<unsigned char> vchBlockSig;
-
     // network and disk
     std::vector<CTransaction> vtx;
 
+    // ppcoin: block signature - signed by coin base txout[0]'s owner
+    std::vector<unsigned char> vchBlockSig;
+
     // memory only
     mutable std::vector<uint256> vMerkleTree;
 
@@ -836,16 +835,16 @@ public:
         READWRITE(nBits);
         READWRITE(nNonce);
 
-        // ConnectBlock depends on vtx being last so it can calculate offset
+        // ConnectBlock depends on vtx following header to generate CDiskTxPos
         if (!(nType & (SER_GETHASH|SER_BLOCKHEADERONLY)))
         {
-            READWRITE(vchBlockSig);
             READWRITE(vtx);
+            READWRITE(vchBlockSig);
         }
         else if (fRead)
         {
-            const_cast<CBlock*>(this)->vchBlockSig.clear();
             const_cast<CBlock*>(this)->vtx.clear();
+            const_cast<CBlock*>(this)->vchBlockSig.clear();
         }
     )
 
@@ -857,8 +856,8 @@ public:
         nTime = 0;
         nBits = 0;
         nNonce = 0;
-        vchBlockSig.clear();
         vtx.clear();
+        vchBlockSig.clear();
         vMerkleTree.clear();
         nDoS = 0;
     }
@@ -1003,14 +1002,14 @@ public:
 
     void print() const
     {
-        printf("CBlock(hash=%s, ver=%d, hashPrevBlock=%s, hashMerkleRoot=%s, nTime=%u, nBits=%08x, nNonce=%u, vchBlockSig=%s, vtx=%d)\n",
+        printf("CBlock(hash=%s, ver=%d, hashPrevBlock=%s, hashMerkleRoot=%s, nTime=%u, nBits=%08x, nNonce=%u, vtx=%d, vchBlockSig=%s)\n",
             GetHash().ToString().substr(0,20).c_str(),
             nVersion,
             hashPrevBlock.ToString().substr(0,20).c_str(),
             hashMerkleRoot.ToString().substr(0,10).c_str(),
             nTime, nBits, nNonce,
-            HexStr(vchBlockSig.begin(), vchBlockSig.end()).c_str(),
-            vtx.size());
+            vtx.size(),
+            HexStr(vchBlockSig.begin(), vchBlockSig.end()).c_str());
         for (int i = 0; i < vtx.size(); i++)
         {
             printf("  ");