Research
Timechain
Search Donate
Sponsors
Cake Wallet, private Bitcoin and Monero walletSideShift.ai, no-signup crypto exchangeOrangeRock, non-custodial bitcoin spot and perps tradingBraiins Hashpower, buy and sell Bitcoin hashrateeCash.com
What changed

Bitcoin v0.3.7 → v0.3.8

8 files · +84 · −37 · b34e8c3c3 · 2010-08-04 · Satoshi Nakamoto

Release commit message: new safety feature displays a warning message and locks down RPC if it detects a problem that may require an upgrade -- version 0.3.8

Previous diff: v0.3.6 → v0.3.7. Next: v0.3.8 → v0.3.10.

db.cpp (modified)

1--- v0.3.7/db.cpp2+++ v0.3.8/db.cpp3@@ -342,6 +342,16 @@4     return Write(string("hashBestChain"), hashBestChain);5 }6 7+bool CTxDB::ReadBestInvalidWork(CBigNum& bnBestInvalidWork)8+{9+    return Read(string("bnBestInvalidWork"), bnBestInvalidWork);10+}11+12+bool CTxDB::WriteBestInvalidWork(CBigNum bnBestInvalidWork)13+{14+    return Write(string("bnBestInvalidWork"), bnBestInvalidWork);15+}16+17 CBlockIndex* InsertBlockIndex(uint256 hash)18 {19     if (hash == 0)20@@ -446,6 +456,9 @@21     bnBestChainWork = pindexBest->bnChainWork;22     printf("LoadBlockIndex(): hashBestChain=%s  height=%d\n", hashBestChain.ToString().substr(0,16).c_str(), nBestHeight);23 24+    // Load bnBestInvalidWork, OK if it doesn't exist25+    ReadBestInvalidWork(bnBestInvalidWork);26+27     return true;28 }29 

db.h (modified)

1--- v0.3.7/db.h2+++ v0.3.8/db.h3@@ -280,6 +280,8 @@4     bool EraseBlockIndex(uint256 hash);5     bool ReadHashBestChain(uint256& hashBestChain);6     bool WriteHashBestChain(uint256 hashBestChain);7+    bool ReadBestInvalidWork(CBigNum& bnBestInvalidWork);8+    bool WriteBestInvalidWork(CBigNum bnBestInvalidWork);9     bool LoadBlockIndex();10 };11 

main.cpp (modified)

1--- v0.3.7/main.cpp2+++ v0.3.8/main.cpp3@@ -25,6 +25,7 @@4 CBlockIndex* pindexGenesisBlock = NULL;5 int nBestHeight = -1;6 CBigNum bnBestChainWork = 0;7+CBigNum bnBestInvalidWork = 0;8 uint256 hashBestChain = 0;9 CBlockIndex* pindexBest = NULL;10 int64 nTimeBestReceived = 0;11@@ -794,12 +795,12 @@12     return pblock->GetHash();13 }14 15-int64 CBlock::GetBlockValue(int64 nFees) const16+int64 CBlock::GetBlockValue(int nHeight, int64 nFees) const17 {18     int64 nSubsidy = 50 * COIN;19 20     // Subsidy is cut in half every 4 years21-    nSubsidy >>= (nBestHeight / 210000);22+    nSubsidy >>= (nHeight / 210000);23 24     return nSubsidy + nFees;25 }26@@ -863,6 +864,28 @@27     }28     return (GetTime() - nLastUpdate < 10 &&29             pindexBest->nTime < GetTime() - 24 * 60 * 60);30+}31+32+bool IsLockdown()33+{34+    if (!pindexBest)35+        return false;36+    return (bnBestInvalidWork > bnBestChainWork + pindexBest->GetBlockWork() * 6);37+}38+39+void Lockdown(CBlockIndex* pindexNew)40+{41+    if (pindexNew->bnChainWork > bnBestInvalidWork)42+    {43+        bnBestInvalidWork = pindexNew->bnChainWork;44+        CTxDB().WriteBestInvalidWork(bnBestInvalidWork);45+        MainFrameRepaint();46+    }47+    printf("Lockdown: invalid block=%s  height=%d  work=%s\n", pindexNew->GetBlockHash().ToString().substr(0,22).c_str(), pindexNew->nHeight, pindexNew->bnChainWork.ToString().c_str());48+    printf("Lockdown:  current best=%s  height=%d  work=%s\n", hashBestChain.ToString().substr(0,22).c_str(), nBestHeight, bnBestChainWork.ToString().c_str());49+    printf("Lockdown: IsLockdown()=%d\n", (IsLockdown() ? 1 : 0));50+    if (IsLockdown())51+        printf("Lockdown: WARNING: Displayed transactions may not be correct!  You may need to upgrade.\n");52 }53 54 55@@ -1086,7 +1109,7 @@56             return false;57     }58 59-    if (vtx[0].GetValueOut() > GetBlockValue(nFees))60+    if (vtx[0].GetValueOut() > GetBlockValue(pindex->nHeight, nFees))61         return false;62 63     // Update block index on disk without changing it in memory.64@@ -1116,11 +1139,13 @@65     CBlockIndex* plonger = pindexNew;66     while (pfork != plonger)67     {68-        if (!(pfork = pfork->pprev))69-            return error("Reorganize() : pfork->pprev is null");70         while (plonger->nHeight > pfork->nHeight)71             if (!(plonger = plonger->pprev))72                 return error("Reorganize() : plonger->pprev is null");73+        if (pfork == plonger)74+            break;75+        if (!(pfork = pfork->pprev))76+            return error("Reorganize() : pfork->pprev is null");77     }78 79     // List of what to disconnect80@@ -1160,16 +1185,8 @@81             return error("Reorganize() : ReadFromDisk for connect failed");82         if (!block.ConnectBlock(txdb, pindex))83         {84-            // Invalid block, delete the rest of this branch85+            // Invalid block86             txdb.TxnAbort();87-            for (int j = i; j < vConnect.size(); j++)88-            {89-                CBlockIndex* pindex = vConnect[j];90-                pindex->EraseBlockFromDisk();91-                txdb.EraseBlockIndex(pindex->GetBlockHash());92-                mapBlockIndex.erase(pindex->GetBlockHash());93-                delete pindex;94-            }95             return error("Reorganize() : ConnectBlock failed");96         }97 98@@ -1227,12 +1244,12 @@99     pindexNew->bnChainWork = (pindexNew->pprev ? pindexNew->pprev->bnChainWork : 0) + pindexNew->GetBlockWork();100 101     CTxDB txdb;102-    txdb.TxnBegin();103     txdb.WriteBlockIndex(CDiskBlockIndex(pindexNew));104 105     // New best106     if (pindexNew->bnChainWork > bnBestChainWork)107     {108+        txdb.TxnBegin();109         if (pindexGenesisBlock == NULL && hash == hashGenesisBlock)110         {111             pindexGenesisBlock = pindexNew;112@@ -1244,9 +1261,7 @@113             if (!ConnectBlock(txdb, pindexNew) || !txdb.WriteHashBestChain(hash))114             {115                 txdb.TxnAbort();116-                pindexNew->EraseBlockFromDisk();117-                mapBlockIndex.erase(pindexNew->GetBlockHash());118-                delete pindexNew;119+                Lockdown(pindexNew);120                 return error("AddToBlockIndex() : ConnectBlock failed");121             }122             txdb.TxnCommit();123@@ -1262,9 +1277,11 @@124             if (!Reorganize(txdb, pindexNew))125             {126                 txdb.TxnAbort();127+                Lockdown(pindexNew);128                 return error("AddToBlockIndex() : Reorganize failed");129             }130         }131+        txdb.TxnCommit();132 133         // New best block134         hashBestChain = hash;135@@ -1273,10 +1290,9 @@136         bnBestChainWork = pindexNew->bnChainWork;137         nTimeBestReceived = GetTime();138         nTransactionsUpdated++;139-        printf("AddToBlockIndex: new best=%s  height=%d\n", hashBestChain.ToString().substr(0,16).c_str(), nBestHeight);140-    }141-142-    txdb.TxnCommit();143+        printf("AddToBlockIndex: new best=%s  height=%d  work=%s\n", hashBestChain.ToString().substr(0,22).c_str(), nBestHeight, bnBestChainWork.ToString().c_str());144+    }145+146     txdb.Close();147 148     if (pindexNew == pindexBest)149@@ -1352,7 +1368,7 @@150 151     // Check that all transactions are finalized152     foreach(const CTransaction& tx, vtx)153-        if (!tx.IsFinal(nTime))154+        if (!tx.IsFinal(pindexPrev->nHeight+1, nTime))155             return error("AcceptBlock() : contains a non-final transaction");156 157     // Check proof of work158@@ -2648,7 +2664,7 @@159             }160         }161         pblock->nBits = nBits;162-        pblock->vtx[0].vout[0].nValue = pblock->GetBlockValue(nFees);163+        pblock->vtx[0].vout[0].nValue = pblock->GetBlockValue(pindexPrev->nHeight+1, nFees);164         printf("Running BitcoinMiner with %d transactions in block\n", pblock->vtx.size());165 166 

main.h (modified)

1--- v0.3.7/main.h2+++ v0.3.8/main.h3@@ -33,6 +33,7 @@4 extern CBlockIndex* pindexGenesisBlock;5 extern int nBestHeight;6 extern CBigNum bnBestChainWork;7+extern CBigNum bnBestInvalidWork;8 extern uint256 hashBestChain;9 extern CBlockIndex* pindexBest;10 extern unsigned int nTransactionsUpdated;11@@ -80,6 +81,7 @@12 void ThreadBitcoinMiner(void* parg);13 void BitcoinMiner();14 bool IsInitialBlockDownload();15+bool IsLockdown();16 17 18 19@@ -410,15 +412,16 @@20         return SerializeHash(*this);21     }22 23-    bool IsFinal(int64 nBlockTime=0) const24-    {25-        // Time based nLockTime implemented in 0.1.6,26-        // do not use time based until most 0.1.5 nodes have upgraded.27+    bool IsFinal(int nBlockHeight=0, int64 nBlockTime=0) const28+    {29+        // Time based nLockTime implemented in 0.1.630         if (nLockTime == 0)31             return true;32+        if (nBlockHeight == 0)33+            nBlockHeight = nBestHeight;34         if (nBlockTime == 0)35             nBlockTime = GetAdjustedTime();36-        if (nLockTime < (nLockTime < 500000000 ? nBestHeight : nBlockTime))37+        if (nLockTime < (nLockTime < 500000000 ? nBlockHeight : nBlockTime))38             return true;39         foreach(const CTxIn& txin, vin)40             if (!txin.IsFinal())41@@ -1046,7 +1049,7 @@42     }43 44 45-    int64 GetBlockValue(int64 nFees) const;46+    int64 GetBlockValue(int nHeight, int64 nFees) const;47     bool DisconnectBlock(CTxDB& txdb, CBlockIndex* pindex);48     bool ConnectBlock(CTxDB& txdb, CBlockIndex* pindex);49     bool ReadFromDisk(const CBlockIndex* blockindex, bool fReadTransactions=true);

rpc.cpp (modified)

1--- v0.3.7/rpc.cpp2+++ v0.3.8/rpc.cpp3@@ -946,6 +946,10 @@4 5                 printf("ThreadRPCServer method=%s\n", strMethod.c_str());6 7+                // Observe lockdown8+                if (IsLockdown() && strMethod != "help" && strMethod != "stop" && strMethod != "getgenerate" && strMethod != "setgenerate")9+                    throw runtime_error("WARNING: Displayed transactions may not be correct!  You may need to upgrade.");10+11                 // Execute12                 map<string, rpcfn_type>::iterator mi = mapCallTable.find(strMethod);13                 if (mi == mapCallTable.end())

serialize.h (modified)

1--- v0.3.7/serialize.h2+++ v0.3.8/serialize.h3@@ -19,7 +19,7 @@4 class CDataStream;5 class CAutoFile;6 7-static const int VERSION = 307;8+static const int VERSION = 308;9 static const char* pszSubVer = "";10 11 

setup.nsi (modified)

1--- v0.3.7/setup.nsi2+++ v0.3.8/setup.nsi3@@ -7,7 +7,7 @@4 5 # General Symbol Definitions6 !define REGKEY "SOFTWARE\$(^Name)"7-!define VERSION 0.3.78+!define VERSION 0.3.89 !define COMPANY "Bitcoin project"10 !define URL http://www.bitcoin.org/11 12@@ -42,12 +42,12 @@13 !insertmacro MUI_LANGUAGE English14 15 # Installer attributes16-OutFile bitcoin-0.3.7-win32-setup.exe17+OutFile bitcoin-0.3.8-win32-setup.exe18 InstallDir $PROGRAMFILES\Bitcoin19 CRCCheck on20 XPStyle on21 ShowInstDetails show22-VIProductVersion 0.3.7.023+VIProductVersion 0.3.8.024 VIAddVersionKey ProductName Bitcoin25 VIAddVersionKey ProductVersion "${VERSION}"26 VIAddVersionKey CompanyName "${COMPANY}"

ui.cpp (modified)

1--- v0.3.7/ui.cpp2+++ v0.3.8/ui.cpp3@@ -196,6 +196,8 @@4 5 void CalledSetStatusBar(const string& strText, int nField)6 {7+    if (nField == 0 && IsLockdown())8+        return;9     if (pframeMain && pframeMain->m_statusBar)10         pframeMain->m_statusBar->SetStatusText(strText, nField);11 }12@@ -376,7 +378,7 @@13     // to get rid of the deprecated warning.  Just ignore it.14     if (!event.Iconized())15         fClosedToTray = false;16-#ifdef __WXGTK__17+#if defined(__WXGTK__) || defined(__WXMAC_OSX__)18     if (mapArgs.count("-minimizetotray")) {19 #endif20     // The tray icon sometimes disappears on ubuntu karmic21@@ -1011,6 +1013,13 @@22     RefreshStatusColumn();23 24     // Update status bar25+    static bool fPrevLockdown;26+    if (IsLockdown())27+        m_statusBar->SetStatusText(string("    ") + _("WARNING: Displayed transactions may not be correct!  You may need to upgrade."), 0);28+    else if (fPrevLockdown)29+        m_statusBar->SetStatusText("", 0);30+    fPrevLockdown = IsLockdown();31+32     string strGen = "";33     if (fGenerateBitcoins)34         strGen = _("    Generating");35@@ -1598,7 +1607,7 @@36     //m_listBox->Append(_("Test 2"));37     m_listBox->SetSelection(0);38     SelectPage(0);39-#ifdef __WXGTK__40+#if defined(__WXGTK__) || defined(__WXMAC_OSX__)41     m_checkBoxStartOnSystemStartup->SetLabel(_("&Start Bitcoin on window system startup"));42     if (!mapArgs.count("-minimizetotray"))43     {44@@ -2697,7 +2706,7 @@45     pframeMain = new CMainFrame(NULL);46     if (mapArgs.count("-min"))47         pframeMain->Iconize(true);48-#ifdef __WXGTK__49+#if defined(__WXGTK__) || defined(__WXMAC_OSX__)50     if (!mapArgs.count("-minimizetotray"))51         fMinimizeToTray = false;52 #endif
0:000:00