Skip to content

Commit

Permalink
Merge branch '0.5.0.x' into 0.5.x
Browse files Browse the repository at this point in the history
  • Loading branch information
luke-jr committed Mar 3, 2012
2 parents 6fb186f + 7013cc3 commit 9cf600e
Show file tree
Hide file tree
Showing 17 changed files with 148 additions and 43 deletions.
24 changes: 16 additions & 8 deletions src/bitcoinrpc.cpp
Expand Up @@ -318,7 +318,7 @@ Value getinfo(const Array& params, bool fHelp)
obj.push_back(Pair("keypoolsize", pwalletMain->GetKeyPoolSize()));
obj.push_back(Pair("paytxfee", ValueFromAmount(nTransactionFee)));
if (pwalletMain->IsCrypted())
obj.push_back(Pair("unlocked_until", (boost::int64_t)nWalletUnlockTime));
obj.push_back(Pair("unlocked_until", (boost::int64_t)nWalletUnlockTime / 1000));
obj.push_back(Pair("errors", GetWarnings("statusbar")));
return obj;
}
Expand Down Expand Up @@ -1407,25 +1407,33 @@ void ThreadTopUpKeyPool(void* parg)

void ThreadCleanWalletPassphrase(void* parg)
{
int64 nMyWakeTime = GetTime() + *((int*)parg);
int64 nMyWakeTime = GetTimeMillis() + *((int*)parg) * 1000;

ENTER_CRITICAL_SECTION(cs_nWalletUnlockTime);

if (nWalletUnlockTime == 0)
{
nWalletUnlockTime = nMyWakeTime;

while (GetTime() < nWalletUnlockTime)
do
{
int64 nToSleep = GetTime() - nWalletUnlockTime;
if (nWalletUnlockTime==0)
break;
int64 nToSleep = nWalletUnlockTime - GetTimeMillis();
if (nToSleep <= 0)
break;

LEAVE_CRITICAL_SECTION(cs_nWalletUnlockTime);
Sleep(nToSleep);
ENTER_CRITICAL_SECTION(cs_nWalletUnlockTime);
}

nWalletUnlockTime = 0;
pwalletMain->Lock();
} while(1);

if (nWalletUnlockTime)
{
nWalletUnlockTime = 0;
pwalletMain->Lock();
}
}
else
{
Expand Down Expand Up @@ -1523,9 +1531,9 @@ Value walletlock(const Array& params, bool fHelp)
if (!pwalletMain->IsCrypted())
throw JSONRPCError(-15, "Error: running with an unencrypted wallet, but walletlock was called.");

pwalletMain->Lock();
CRITICAL_BLOCK(cs_nWalletUnlockTime)
{
pwalletMain->Lock();
nWalletUnlockTime = 0;
}

Expand Down
1 change: 1 addition & 0 deletions src/checkpoints.cpp
Expand Up @@ -30,6 +30,7 @@ namespace Checkpoints
(118000, uint256("0x000000000000774a7f8a7a12dc906ddb9e17e75d684f15e00f8767f9e8f36553"))
(134444, uint256("0x00000000000005b12ffd4cd315cd34ffd4a594f430ac814c91184a0d42d2b0fe"))
(140700, uint256("0x000000000000033b512028abb90e1626d8b346fd0ed598ac0a3c371138dce2bd"))
(168000, uint256("0x000000000000099e61ea72015e79632f216fe6cb33d7899acb35b75c8303b763"))
;

bool CheckBlock(int nHeight, const uint256& hash)
Expand Down
13 changes: 9 additions & 4 deletions src/init.cpp
Expand Up @@ -206,10 +206,10 @@ bool AppInit2(int argc, char* argv[])
#endif
#endif
" -paytxfee=<amt> \t " + _("Fee per kB to add to transactions you send\n") +
#ifdef GUI
#ifdef QT_GUI
" -server \t\t " + _("Accept command line and JSON-RPC commands\n") +
#endif
#if !defined(WIN32) && !defined(GUI)
#if !defined(WIN32) && !defined(QT_GUI)
" -daemon \t\t " + _("Run in the background as a daemon and accept commands\n") +
#endif
" -testnet \t\t " + _("Use the test network\n") +
Expand Down Expand Up @@ -241,14 +241,19 @@ bool AppInit2(int argc, char* argv[])

// Remove tabs
strUsage.erase(std::remove(strUsage.begin(), strUsage.end(), '\t'), strUsage.end());
#if defined(QT_GUI) && defined(WIN32)
// On windows, show a message box, as there is no stderr
wxMessageBox(strUsage, "Usage");
#else
fprintf(stderr, "%s", strUsage.c_str());
#endif
return false;
}

fTestNet = GetBoolArg("-testnet");
fDebug = GetBoolArg("-debug");

#if !defined(WIN32) && !defined(GUI)
#if !defined(WIN32) && !defined(QT_GUI)
fDaemon = GetBoolArg("-daemon");
#else
fDaemon = false;
Expand Down Expand Up @@ -279,7 +284,7 @@ bool AppInit2(int argc, char* argv[])
}
#endif

#if !defined(WIN32) && !defined(GUI)
#if !defined(WIN32) && !defined(QT_GUI)
if (fDaemon)
{
// Daemonize
Expand Down
4 changes: 2 additions & 2 deletions src/irc.cpp
Expand Up @@ -110,14 +110,14 @@ bool RecvLine(SOCKET hSocket, string& strLine)
if (nBytes == 0)
{
// socket closed
printf("IRC socket closed\n");
printf("socket closed\n");
return false;
}
else
{
// socket error
int nErr = WSAGetLastError();
printf("IRC recv failed: %d\n", nErr);
printf("recv failed: %d\n", nErr);
return false;
}
}
Expand Down
5 changes: 4 additions & 1 deletion src/key.h
Expand Up @@ -229,10 +229,13 @@ class CKey
if (vchSecret.size() != 32)
throw key_error("CKey::SetSecret() : secret must be 32 bytes");
BIGNUM *bn = BN_bin2bn(&vchSecret[0],32,BN_new());
if (bn == NULL)
if (bn == NULL)
throw key_error("CKey::SetSecret() : BN_bin2bn failed");
if (!EC_KEY_regenerate_key(pkey,bn))
{
BN_clear_free(bn);
throw key_error("CKey::SetSecret() : EC_KEY_regenerate_key failed");
}
BN_clear_free(bn);
fSet = true;
return true;
Expand Down
57 changes: 52 additions & 5 deletions src/main.cpp
Expand Up @@ -166,13 +166,14 @@ void static ResendWalletTransactions()
// mapOrphanTransactions
//

void static AddOrphanTx(const CDataStream& vMsg)
void AddOrphanTx(const CDataStream& vMsg)
{
CTransaction tx;
CDataStream(vMsg) >> tx;
uint256 hash = tx.GetHash();
if (mapOrphanTransactions.count(hash))
return;

CDataStream* pvMsg = mapOrphanTransactions[hash] = new CDataStream(vMsg);
BOOST_FOREACH(const CTxIn& txin, tx.vin)
mapOrphanTransactionsByPrev.insert(make_pair(txin.prevout.hash, pvMsg));
Expand Down Expand Up @@ -200,6 +201,23 @@ void static EraseOrphanTx(uint256 hash)
mapOrphanTransactions.erase(hash);
}

int LimitOrphanTxSize(int nMaxOrphans)
{
int nEvicted = 0;
while (mapOrphanTransactions.size() > nMaxOrphans)
{
// Evict a random orphan:
std::vector<unsigned char> randbytes(32);
RAND_bytes(&randbytes[0], 32);
uint256 randomhash(randbytes);
map<uint256, CDataStream*>::iterator it = mapOrphanTransactions.lower_bound(randomhash);
if (it == mapOrphanTransactions.end())
it = mapOrphanTransactions.begin();
EraseOrphanTx(it->first);
++nEvicted;
}
return nEvicted;
}



Expand Down Expand Up @@ -839,8 +857,10 @@ bool CTransaction::DisconnectInputs(CTxDB& txdb)
}

// Remove transaction from index
if (!txdb.EraseTxIndex(*this))
return error("DisconnectInputs() : EraseTxPos failed");
// This can fail if a duplicate of this transaction was in a chain that got
// reorganized away. This is only possible if this transaction was completely
// spent, so erasing it would be a no-op anway.
txdb.EraseTxIndex(*this);

return true;
}
Expand Down Expand Up @@ -1050,6 +1070,26 @@ bool CBlock::ConnectBlock(CTxDB& txdb, CBlockIndex* pindex)
if (!CheckBlock())
return false;

// Do not allow blocks that contain transactions which 'overwrite' older transactions,
// unless those are already completely spent.
// If such overwrites are allowed, coinbases and transactions depending upon those
// can be duplicated to remove the ability to spend the first instance -- even after
// being sent to another address.
// See BIP30 and http://r6.ca/blog/20120206T005236Z.html for more information.
// This logic is not necessary for memory pool transactions, as AcceptToMemoryPool
// already refuses previously-known transaction id's entirely.
// This rule applies to all blocks whose timestamp is after March 15, 2012, 0:00 UTC.
// On testnet it is enabled as of februari 20, 2012, 0:00 UTC.
if (pindex->nTime > 1331769600 || (fTestNet && pindex->nTime > 1329696000))
BOOST_FOREACH(CTransaction& tx, vtx)
{
CTxIndex txindexOld;
if (txdb.ReadTxIndex(tx.GetHash(), txindexOld))
BOOST_FOREACH(CDiskTxPos &pos, txindexOld.vSpent)
if (pos.IsNull())
return false;
}

//// issue here: it doesn't know the version
unsigned int nTxPos = pindex->nBlockPos + ::GetSerializeSize(CBlock(), SER_DISK) - 1 + GetSizeOfCompactSize(vtx.size());

Expand Down Expand Up @@ -1406,7 +1446,8 @@ bool ProcessBlock(CNode* pfrom, CBlock* pblock)
int64 deltaTime = pblock->GetBlockTime() - pcheckpoint->nTime;
if (deltaTime < 0)
{
pfrom->Misbehaving(100);
if (pfrom)
pfrom->Misbehaving(100);
return error("ProcessBlock() : block with timestamp before last checkpoint");
}
CBigNum bnNewBlock;
Expand All @@ -1415,7 +1456,8 @@ bool ProcessBlock(CNode* pfrom, CBlock* pblock)
bnRequired.SetCompact(ComputeMinWork(pcheckpoint->nBits, deltaTime));
if (bnNewBlock > bnRequired)
{
pfrom->Misbehaving(100);
if (pfrom)
pfrom->Misbehaving(100);
return error("ProcessBlock() : block with too little proof-of-work");
}
}
Expand Down Expand Up @@ -2222,6 +2264,11 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv)
{
printf("storing orphan tx %s\n", inv.hash.ToString().substr(0,10).c_str());
AddOrphanTx(vMsg);

// DoS prevention: do not allow mapOrphanTransactions to grow unbounded
int nEvicted = LimitOrphanTxSize(MAX_ORPHAN_TRANSACTIONS);
if (nEvicted > 0)
printf("mapOrphan overflow, removed %d tx\n", nEvicted);
}
if (tx.nDoS) pfrom->Misbehaving(tx.nDoS);
}
Expand Down
1 change: 1 addition & 0 deletions src/main.h
Expand Up @@ -30,6 +30,7 @@ class CBlockIndex;
static const unsigned int MAX_BLOCK_SIZE = 1000000;
static const unsigned int MAX_BLOCK_SIZE_GEN = MAX_BLOCK_SIZE/2;
static const int MAX_BLOCK_SIGOPS = MAX_BLOCK_SIZE/50;
static const int MAX_ORPHAN_TRANSACTIONS = MAX_BLOCK_SIZE/100;
static const int64 COIN = 100000000;
static const int64 CENT = 1000000;
static const int64 MIN_TX_FEE = 50000;
Expand Down
12 changes: 8 additions & 4 deletions src/qt/bitcoin.cpp
Expand Up @@ -147,9 +147,12 @@ int main(int argc, char *argv[])
app.setApplicationName(QApplication::translate("main", "Bitcoin-Qt"));

QSplashScreen splash(QPixmap(":/images/splash"), 0);
splash.show();
splash.setAutoFillBackground(true);
splashref = &splash;
if (!GetBoolArg("-min"))
{
splash.show();
splash.setAutoFillBackground(true);
splashref = &splash;
}

app.processEvents();

Expand All @@ -163,7 +166,8 @@ int main(int argc, char *argv[])
// Put this in a block, so that BitcoinGUI is cleaned up properly before
// calling Shutdown() in case of exceptions.
BitcoinGUI window;
splash.finish(&window);
if (splashref)
splash.finish(&window);
OptionsModel optionsModel(pwalletMain);
ClientModel clientModel(&optionsModel);
WalletModel walletModel(pwalletMain, &optionsModel);
Expand Down
15 changes: 11 additions & 4 deletions src/qt/bitcoingui.cpp
Expand Up @@ -470,7 +470,11 @@ void BitcoinGUI::setNumBlocks(int count)
QString text;

// Represent time from last generated block in human readable text
if(secs < 60)
if(secs <= 0)
{
// Fully up to date. Leave text empty.
}
else if(secs < 60)
{
text = tr("%n second(s) ago","",secs);
}
Expand All @@ -490,7 +494,7 @@ void BitcoinGUI::setNumBlocks(int count)
// Set icon state: spinning if catching up, tick otherwise
if(secs < 30*60)
{
tooltip = tr("Up to date") + QString("\n") + tooltip;
tooltip = tr("Up to date") + QString(".\n") + tooltip;
labelBlocksIcon->setPixmap(QIcon(":/icons/synced").pixmap(STATUSBAR_ICONSIZE,STATUSBAR_ICONSIZE));
}
else
Expand All @@ -500,8 +504,11 @@ void BitcoinGUI::setNumBlocks(int count)
syncIconMovie->start();
}

tooltip += QString("\n");
tooltip += tr("Last received block was generated %1.").arg(text);
if(!text.isEmpty())
{
tooltip += QString("\n");
tooltip += tr("Last received block was generated %1.").arg(text);
}

labelBlocksIcon->setToolTip(tooltip);
progressBarLabel->setToolTip(tooltip);
Expand Down
14 changes: 14 additions & 0 deletions src/qt/guiutil.cpp
Expand Up @@ -72,3 +72,17 @@ bool GUIUtil::parseBitcoinURL(const QUrl *url, SendCoinsRecipient *out)
}
return true;
}

bool GUIUtil::parseBitcoinURL(QString url, SendCoinsRecipient *out)
{
// Convert bitcoin:// to bitcoin:
//
// Cannot handle this later, because bitcoin:// will cause Qt to see the part after // as host,
// which will lowercase it (and thus invalidate the address).
if(url.startsWith("bitcoin://"))
{
url.replace(0, 10, "bitcoin:");
}
QUrl urlInstance(url);
return parseBitcoinURL(&urlInstance, out);
}
1 change: 1 addition & 0 deletions src/qt/guiutil.h
Expand Up @@ -31,6 +31,7 @@ class GUIUtil
// Parse "bitcoin:" URL into recipient object, return true on succesful parsing
// See Bitcoin URL definition discussion here: https://bitcointalk.org/index.php?topic=33490.0
static bool parseBitcoinURL(const QUrl *url, SendCoinsRecipient *out);
static bool parseBitcoinURL(QString url, SendCoinsRecipient *out);
};

#endif // GUIUTIL_H
10 changes: 10 additions & 0 deletions src/qt/sendcoinsdialog.cpp
Expand Up @@ -265,6 +265,16 @@ void SendCoinsDialog::handleURL(const QUrl *url)
pasteEntry(rv);
}

void SendCoinsDialog::handleURL(const QString &url)
{
SendCoinsRecipient rv;
if(!GUIUtil::parseBitcoinURL(url, &rv))
{
return;
}
pasteEntry(rv);
}

void SendCoinsDialog::setBalance(qint64 balance, qint64 unconfirmedBalance)
{
Q_UNUSED(unconfirmedBalance);
Expand Down
1 change: 1 addition & 0 deletions src/qt/sendcoinsdialog.h
Expand Up @@ -31,6 +31,7 @@ class SendCoinsDialog : public QDialog

void pasteEntry(const SendCoinsRecipient &rv);
void handleURL(const QUrl *url);
void handleURL(const QString &url);

public slots:
void clear();
Expand Down
5 changes: 3 additions & 2 deletions src/qt/sendcoinsentry.cpp
Expand Up @@ -59,8 +59,9 @@ void SendCoinsEntry::on_payTo_textChanged(const QString &address)
{
if(!model)
return;
ui->addAsLabel->setText(model->getAddressTableModel()->labelForAddress(address));
}
// Fill in label from address book, if no label is filled in yet
if(ui->addAsLabel->text().isEmpty())
ui->addAsLabel->setText(model->getAddressTableModel()->labelForAddress(address));}

void SendCoinsEntry::setModel(WalletModel *model)
{
Expand Down

0 comments on commit 9cf600e

Please sign in to comment.