return Write(string("hashBestChain"), hashBestChain);
}
+bool CTxDB::ReadBestInvalidWork(CBigNum& bnBestInvalidWork)
+{
+ return Read(string("bnBestInvalidWork"), bnBestInvalidWork);
+}
+
+bool CTxDB::WriteBestInvalidWork(CBigNum bnBestInvalidWork)
+{
+ return Write(string("bnBestInvalidWork"), bnBestInvalidWork);
+}
+
CBlockIndex* InsertBlockIndex(uint256 hash)
{
if (hash == 0)
bnBestChainWork = pindexBest->bnChainWork;
printf("LoadBlockIndex(): hashBestChain=%s height=%d\n", hashBestChain.ToString().substr(0,16).c_str(), nBestHeight);
+ // Load bnBestInvalidWork, OK if it doesn't exist
+ ReadBestInvalidWork(bnBestInvalidWork);
+
return true;
}
bool EraseBlockIndex(uint256 hash);
bool ReadHashBestChain(uint256& hashBestChain);
bool WriteHashBestChain(uint256 hashBestChain);
+ bool ReadBestInvalidWork(CBigNum& bnBestInvalidWork);
+ bool WriteBestInvalidWork(CBigNum bnBestInvalidWork);
bool LoadBlockIndex();
};
CBlockIndex* pindexGenesisBlock = NULL;
int nBestHeight = -1;
CBigNum bnBestChainWork = 0;
+CBigNum bnBestInvalidWork = 0;
uint256 hashBestChain = 0;
CBlockIndex* pindexBest = NULL;
int64 nTimeBestReceived = 0;
return pblock->GetHash();
}
-int64 CBlock::GetBlockValue(int64 nFees) const
+int64 CBlock::GetBlockValue(int nHeight, int64 nFees) const
{
int64 nSubsidy = 50 * COIN;
// Subsidy is cut in half every 4 years
- nSubsidy >>= (nBestHeight / 210000);
+ nSubsidy >>= (nHeight / 210000);
return nSubsidy + nFees;
}
pindexBest->nTime < GetTime() - 24 * 60 * 60);
}
+bool IsLockdown()
+{
+ if (!pindexBest)
+ return false;
+ return (bnBestInvalidWork > bnBestChainWork + pindexBest->GetBlockWork() * 6);
+}
+
+void Lockdown(CBlockIndex* pindexNew)
+{
+ if (pindexNew->bnChainWork > bnBestInvalidWork)
+ {
+ bnBestInvalidWork = pindexNew->bnChainWork;
+ CTxDB().WriteBestInvalidWork(bnBestInvalidWork);
+ MainFrameRepaint();
+ }
+ 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());
+ printf("Lockdown: current best=%s height=%d work=%s\n", hashBestChain.ToString().substr(0,22).c_str(), nBestHeight, bnBestChainWork.ToString().c_str());
+ printf("Lockdown: IsLockdown()=%d\n", (IsLockdown() ? 1 : 0));
+ if (IsLockdown())
+ printf("Lockdown: WARNING: Displayed transactions may not be correct! You may need to upgrade.\n");
+}
+
return false;
}
- if (vtx[0].GetValueOut() > GetBlockValue(nFees))
+ if (vtx[0].GetValueOut() > GetBlockValue(pindex->nHeight, nFees))
return false;
// Update block index on disk without changing it in memory.
CBlockIndex* plonger = pindexNew;
while (pfork != plonger)
{
- if (!(pfork = pfork->pprev))
- return error("Reorganize() : pfork->pprev is null");
while (plonger->nHeight > pfork->nHeight)
if (!(plonger = plonger->pprev))
return error("Reorganize() : plonger->pprev is null");
+ if (pfork == plonger)
+ break;
+ if (!(pfork = pfork->pprev))
+ return error("Reorganize() : pfork->pprev is null");
}
// List of what to disconnect
return error("Reorganize() : ReadFromDisk for connect failed");
if (!block.ConnectBlock(txdb, pindex))
{
- // Invalid block, delete the rest of this branch
+ // Invalid block
txdb.TxnAbort();
- for (int j = i; j < vConnect.size(); j++)
- {
- CBlockIndex* pindex = vConnect[j];
- pindex->EraseBlockFromDisk();
- txdb.EraseBlockIndex(pindex->GetBlockHash());
- mapBlockIndex.erase(pindex->GetBlockHash());
- delete pindex;
- }
return error("Reorganize() : ConnectBlock failed");
}
pindexNew->bnChainWork = (pindexNew->pprev ? pindexNew->pprev->bnChainWork : 0) + pindexNew->GetBlockWork();
CTxDB txdb;
- txdb.TxnBegin();
txdb.WriteBlockIndex(CDiskBlockIndex(pindexNew));
// New best
if (pindexNew->bnChainWork > bnBestChainWork)
{
+ txdb.TxnBegin();
if (pindexGenesisBlock == NULL && hash == hashGenesisBlock)
{
pindexGenesisBlock = pindexNew;
if (!ConnectBlock(txdb, pindexNew) || !txdb.WriteHashBestChain(hash))
{
txdb.TxnAbort();
- pindexNew->EraseBlockFromDisk();
- mapBlockIndex.erase(pindexNew->GetBlockHash());
- delete pindexNew;
+ Lockdown(pindexNew);
return error("AddToBlockIndex() : ConnectBlock failed");
}
txdb.TxnCommit();
if (!Reorganize(txdb, pindexNew))
{
txdb.TxnAbort();
+ Lockdown(pindexNew);
return error("AddToBlockIndex() : Reorganize failed");
}
}
+ txdb.TxnCommit();
// New best block
hashBestChain = hash;
bnBestChainWork = pindexNew->bnChainWork;
nTimeBestReceived = GetTime();
nTransactionsUpdated++;
- printf("AddToBlockIndex: new best=%s height=%d\n", hashBestChain.ToString().substr(0,16).c_str(), nBestHeight);
+ printf("AddToBlockIndex: new best=%s height=%d work=%s\n", hashBestChain.ToString().substr(0,22).c_str(), nBestHeight, bnBestChainWork.ToString().c_str());
}
- txdb.TxnCommit();
txdb.Close();
if (pindexNew == pindexBest)
// Check that all transactions are finalized
foreach(const CTransaction& tx, vtx)
- if (!tx.IsFinal(nTime))
+ if (!tx.IsFinal(pindexPrev->nHeight+1, nTime))
return error("AcceptBlock() : contains a non-final transaction");
// Check proof of work
}
}
pblock->nBits = nBits;
- pblock->vtx[0].vout[0].nValue = pblock->GetBlockValue(nFees);
+ pblock->vtx[0].vout[0].nValue = pblock->GetBlockValue(pindexPrev->nHeight+1, nFees);
printf("Running BitcoinMiner with %d transactions in block\n", pblock->vtx.size());
extern CBlockIndex* pindexGenesisBlock;
extern int nBestHeight;
extern CBigNum bnBestChainWork;
+extern CBigNum bnBestInvalidWork;
extern uint256 hashBestChain;
extern CBlockIndex* pindexBest;
extern unsigned int nTransactionsUpdated;
void ThreadBitcoinMiner(void* parg);
void BitcoinMiner();
bool IsInitialBlockDownload();
+bool IsLockdown();
return SerializeHash(*this);
}
- bool IsFinal(int64 nBlockTime=0) const
+ bool IsFinal(int nBlockHeight=0, int64 nBlockTime=0) const
{
- // Time based nLockTime implemented in 0.1.6,
- // do not use time based until most 0.1.5 nodes have upgraded.
+ // Time based nLockTime implemented in 0.1.6
if (nLockTime == 0)
return true;
+ if (nBlockHeight == 0)
+ nBlockHeight = nBestHeight;
if (nBlockTime == 0)
nBlockTime = GetAdjustedTime();
- if (nLockTime < (nLockTime < 500000000 ? nBestHeight : nBlockTime))
+ if (nLockTime < (nLockTime < 500000000 ? nBlockHeight : nBlockTime))
return true;
foreach(const CTxIn& txin, vin)
if (!txin.IsFinal())
}
- int64 GetBlockValue(int64 nFees) const;
+ int64 GetBlockValue(int nHeight, int64 nFees) const;
bool DisconnectBlock(CTxDB& txdb, CBlockIndex* pindex);
bool ConnectBlock(CTxDB& txdb, CBlockIndex* pindex);
bool ReadFromDisk(const CBlockIndex* blockindex, bool fReadTransactions=true);
printf("ThreadRPCServer method=%s\n", strMethod.c_str());
+ // Observe lockdown
+ if (IsLockdown() && strMethod != "help" && strMethod != "stop" && strMethod != "getgenerate" && strMethod != "setgenerate")
+ throw runtime_error("WARNING: Displayed transactions may not be correct! You may need to upgrade.");
+
// Execute
map<string, rpcfn_type>::iterator mi = mapCallTable.find(strMethod);
if (mi == mapCallTable.end())
class CDataStream;
class CAutoFile;
-static const int VERSION = 307;
+static const int VERSION = 308;
static const char* pszSubVer = "";
# General Symbol Definitions
!define REGKEY "SOFTWARE\$(^Name)"
-!define VERSION 0.3.7
+!define VERSION 0.3.8
!define COMPANY "Bitcoin project"
!define URL http://www.bitcoin.org/
!insertmacro MUI_LANGUAGE English
# Installer attributes
-OutFile bitcoin-0.3.7-win32-setup.exe
+OutFile bitcoin-0.3.8-win32-setup.exe
InstallDir $PROGRAMFILES\Bitcoin
CRCCheck on
XPStyle on
ShowInstDetails show
-VIProductVersion 0.3.7.0
+VIProductVersion 0.3.8.0
VIAddVersionKey ProductName Bitcoin
VIAddVersionKey ProductVersion "${VERSION}"
VIAddVersionKey CompanyName "${COMPANY}"
void CalledSetStatusBar(const string& strText, int nField)
{
+ if (nField == 0 && IsLockdown())
+ return;
if (pframeMain && pframeMain->m_statusBar)
pframeMain->m_statusBar->SetStatusText(strText, nField);
}
// to get rid of the deprecated warning. Just ignore it.
if (!event.Iconized())
fClosedToTray = false;
-#ifdef __WXGTK__
+#if defined(__WXGTK__) || defined(__WXMAC_OSX__)
if (mapArgs.count("-minimizetotray")) {
#endif
// The tray icon sometimes disappears on ubuntu karmic
RefreshStatusColumn();
// Update status bar
+ static bool fPrevLockdown;
+ if (IsLockdown())
+ m_statusBar->SetStatusText(string(" ") + _("WARNING: Displayed transactions may not be correct! You may need to upgrade."), 0);
+ else if (fPrevLockdown)
+ m_statusBar->SetStatusText("", 0);
+ fPrevLockdown = IsLockdown();
+
string strGen = "";
if (fGenerateBitcoins)
strGen = _(" Generating");
//m_listBox->Append(_("Test 2"));
m_listBox->SetSelection(0);
SelectPage(0);
-#ifdef __WXGTK__
+#if defined(__WXGTK__) || defined(__WXMAC_OSX__)
m_checkBoxStartOnSystemStartup->SetLabel(_("&Start Bitcoin on window system startup"));
if (!mapArgs.count("-minimizetotray"))
{
pframeMain = new CMainFrame(NULL);
if (mapArgs.count("-min"))
pframeMain->Iconize(true);
-#ifdef __WXGTK__
+#if defined(__WXGTK__) || defined(__WXMAC_OSX__)
if (!mapArgs.count("-minimizetotray"))
fMinimizeToTray = false;
#endif