Skip to content

Commit cc0b4c3

Browse files
committedOct 29, 2009
addr relaying fixes, proxy option and privacy patches, detect connect to self, non-final tx locktime changes, fix hide unconfirmed generated
·
v29.0noversion
1 parent 6ccefea commit cc0b4c3

File tree

19 files changed

+1209
-339
lines changed

19 files changed

+1209
-339
lines changed
 

‎build.txt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
BitCoin v0.1.6 ALPHA
1+
BitCoin v0.1.6 BETA
22

33
Copyright (c) 2009 Satoshi Nakamoto
44
Distributed under the MIT/X11 software license, see the accompanying
@@ -19,10 +19,10 @@ Dependencies
1919
Libraries you need to obtain separately to build:
2020

2121
default path download
22-
wxWidgets \wxWidgets http://www.wxwidgets.org/downloads/
23-
OpenSSL \OpenSSL http://www.openssl.org/source/
24-
Berkeley DB \DB http://www.oracle.com/technology/software/products/berkeley-db/index.html
25-
Boost \Boost http://www.boost.org/users/download/
22+
wxWidgets \wxwidgets http://www.wxwidgets.org/downloads/
23+
OpenSSL \openssl http://www.openssl.org/source/
24+
Berkeley DB \db http://www.oracle.com/technology/software/products/berkeley-db/index.html
25+
Boost \boost http://www.boost.org/users/download/
2626

2727
Their licenses:
2828
wxWidgets LGPL 2.1 with very liberal exceptions
@@ -75,7 +75,7 @@ If you want to use it with MSVC, generate the .lib file
7575
Berkeley DB
7676
-----------
7777
Using MinGW and MSYS:
78-
cd \DB\build_unix
78+
cd \db\build_unix
7979
sh ../dist/configure --enable-mingw --enable-cxx
8080
make
8181

‎db.cpp

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -121,10 +121,12 @@ void CDB::Close()
121121
pdb->close(0);
122122
delete pdb;
123123
pdb = NULL;
124-
dbenv.txn_checkpoint(0, 0, 0);
125124

126125
CRITICAL_BLOCK(cs_db)
126+
{
127+
dbenv.txn_checkpoint(0, 0, 0);
127128
--mapFileUseCount[strFile];
129+
}
128130

129131
RandAddSeed();
130132
}
@@ -376,11 +378,11 @@ bool CTxDB::LoadBlockIndex()
376378
{
377379
if (pindexGenesisBlock == NULL)
378380
return true;
379-
return error("CTxDB::LoadBlockIndex() : hashBestChain not found\n");
381+
return error("CTxDB::LoadBlockIndex() : hashBestChain not found");
380382
}
381383

382384
if (!mapBlockIndex.count(hashBestChain))
383-
return error("CTxDB::LoadBlockIndex() : blockindex for hashBestChain not found\n");
385+
return error("CTxDB::LoadBlockIndex() : blockindex for hashBestChain not found");
384386
pindexBest = mapBlockIndex[hashBestChain];
385387
nBestHeight = pindexBest->nHeight;
386388
printf("LoadBlockIndex(): hashBestChain=%s height=%d\n", hashBestChain.ToString().substr(0,14).c_str(), nBestHeight);
@@ -500,16 +502,15 @@ bool CReviewDB::WriteReviews(uint256 hash, const vector<CReview>& vReviews)
500502
CWalletDB::~CWalletDB()
501503
{
502504
// Flush whenever all handles to wallet.dat are closed
503-
Close();
504505
CRITICAL_BLOCK(cs_db)
505506
{
507+
Close(); // close includes a txn_checkpoint
506508
map<string, int>::iterator mi = mapFileUseCount.find(strFile);
507509
if (mi != mapFileUseCount.end())
508510
{
509511
int nRefCount = (*mi).second;
510512
if (nRefCount == 0)
511513
{
512-
dbenv.txn_checkpoint(0, 0, 0);
513514
dbenv.lsn_reset(strFile.c_str(), 0);
514515
mapFileUseCount.erase(mi++);
515516
}
@@ -600,6 +601,9 @@ bool CWalletDB::LoadWallet(vector<unsigned char>& vchDefaultKeyRet)
600601
if (strKey == "nLimitProcessors") ssValue >> nLimitProcessors;
601602
if (strKey == "fMinimizeToTray") ssValue >> fMinimizeToTray;
602603
if (strKey == "fMinimizeOnClose") ssValue >> fMinimizeOnClose;
604+
if (strKey == "fUseProxy") ssValue >> fUseProxy;
605+
if (strKey == "addrProxy") ssValue >> addrProxy;
606+
603607
}
604608
}
605609
}
@@ -610,6 +614,9 @@ bool CWalletDB::LoadWallet(vector<unsigned char>& vchDefaultKeyRet)
610614
printf("addrIncoming = %s\n", addrIncoming.ToString().c_str());
611615
printf("fMinimizeToTray = %d\n", fMinimizeToTray);
612616
printf("fMinimizeOnClose = %d\n", fMinimizeOnClose);
617+
printf("fUseProxy = %d\n", fUseProxy);
618+
printf("addrProxy = %s\n", addrProxy.ToString().c_str());
619+
613620

614621
// The transaction fee setting won't be needed for many years to come.
615622
// Setting it to zero here in case they set it to something in an earlier version.
@@ -639,7 +646,7 @@ bool LoadWallet(bool& fFirstRunRet)
639646
else
640647
{
641648
// Create new keyUser and set as default key
642-
RandAddSeed(true);
649+
RandAddSeedPerfmon();
643650
keyUser.MakeNewKey();
644651
if (!AddKey(keyUser))
645652
return false;

‎headers.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#ifdef _MSC_VER
66
#pragma warning(disable:4786)
77
#pragma warning(disable:4804)
8+
#pragma warning(disable:4805)
89
#pragma warning(disable:4717)
910
#endif
1011
#ifdef _WIN32_WINNT
@@ -62,6 +63,7 @@ using namespace boost;
6263

6364

6465

66+
#include "strlcpy.h"
6567
#include "serialize.h"
6668
#include "uint256.h"
6769
#include "util.h"

‎irc.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,9 @@ void ThreadIRCSeed(void* parg)
163163
int nErrorWait = 10;
164164
int nRetryWait = 10;
165165

166+
if (fUseProxy && addrProxy.port == htons(9050))
167+
return;
168+
166169
while (!fShutdown)
167170
{
168171
CAddress addrConnect("216.155.130.130:6667");
@@ -191,9 +194,10 @@ void ThreadIRCSeed(void* parg)
191194
return;
192195
}
193196

194-
string strMyName = EncodeAddress(addrLocalHost);
195-
196-
if (!addrLocalHost.IsRoutable())
197+
string strMyName;
198+
if (addrLocalHost.IsRoutable() && !fUseProxy)
199+
strMyName = EncodeAddress(addrLocalHost);
200+
else
197201
strMyName = strprintf("x%u", GetRand(1000000000));
198202

199203

‎key.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class key_error : public std::runtime_error
3535
};
3636

3737

38-
// secure_allocator is defined is serialize.h
38+
// secure_allocator is defined in serialize.h
3939
typedef vector<unsigned char, secure_allocator<unsigned char> > CPrivKey;
4040

4141

‎main.cpp

Lines changed: 57 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -415,6 +415,10 @@ bool CTransaction::AcceptTransaction(CTxDB& txdb, bool fCheckInputs, bool* pfMis
415415
if (!CheckTransaction())
416416
return error("AcceptTransaction() : CheckTransaction failed");
417417

418+
// To help v0.1.5 clients who would see it as negative number. please delete this later.
419+
if (nLockTime > INT_MAX)
420+
return error("AcceptTransaction() : not accepting nLockTime beyond 2038");
421+
418422
// Do we already have it?
419423
uint256 hash = GetHash();
420424
CRITICAL_BLOCK(cs_mapTransactions)
@@ -1214,6 +1218,12 @@ bool CBlock::AcceptBlock()
12141218
if (nTime <= pindexPrev->GetMedianTimePast())
12151219
return error("AcceptBlock() : block's timestamp is too early");
12161220

1221+
// Check that all transactions are finalized (starting around 30 Nov 2009)
1222+
if (nBestHeight > 31000) // 25620 + 5320
1223+
foreach(const CTransaction& tx, vtx)
1224+
if (!tx.IsFinal(nTime))
1225+
return error("AcceptBlock() : contains a non-final transaction");
1226+
12171227
// Check proof of work
12181228
if (nBits != GetNextWorkRequired(pindexPrev))
12191229
return error("AcceptBlock() : incorrect proof of work");
@@ -1649,7 +1659,7 @@ bool ProcessMessages(CNode* pfrom)
16491659
CDataStream& vRecv = pfrom->vRecv;
16501660
if (vRecv.empty())
16511661
return true;
1652-
printf("ProcessMessages(%d bytes)\n", vRecv.size());
1662+
//printf("ProcessMessages(%d bytes)\n", vRecv.size());
16531663

16541664
//
16551665
// Message format
@@ -1692,7 +1702,7 @@ bool ProcessMessages(CNode* pfrom)
16921702
{
16931703
// Rewind and wait for rest of message
16941704
///// need a mechanism to give up waiting for overlong message size error
1695-
printf("MESSAGE-BREAK\n");
1705+
//printf("message-break\n");
16961706
vRecv.insert(vRecv.begin(), BEGIN(hdr), END(hdr));
16971707
Sleep(100);
16981708
break;
@@ -1711,7 +1721,20 @@ bool ProcessMessages(CNode* pfrom)
17111721
fRet = ProcessMessage(pfrom, strCommand, vMsg);
17121722
CheckForShutdown(2);
17131723
}
1714-
CATCH_PRINT_EXCEPTION("ProcessMessage()")
1724+
catch (std::ios_base::failure& e) {
1725+
if (strstr(e.what(), "CDataStream::read() : end of data"))
1726+
{
1727+
// Allow exceptions from underlength message on vRecv
1728+
LogException(&e, "ProcessMessage()");
1729+
}
1730+
else
1731+
PrintException(&e, "ProcessMessage()");
1732+
} catch (std::exception& e) {
1733+
PrintException(&e, "ProcessMessage()");
1734+
} catch (...) {
1735+
PrintException(NULL, "ProcessMessage()");
1736+
}
1737+
17151738
if (!fRet)
17161739
printf("ProcessMessage(%s, %d bytes) FAILED\n", strCommand.c_str(), nMessageSize);
17171740
}
@@ -1726,7 +1749,8 @@ bool ProcessMessages(CNode* pfrom)
17261749
bool ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv)
17271750
{
17281751
static map<unsigned int, vector<unsigned char> > mapReuseKey;
1729-
printf("received: %-12s (%d bytes)\n", strCommand.c_str(), vRecv.size());
1752+
RandAddSeedPerfmon();
1753+
printf("received: %s (%d bytes)\n", strCommand.c_str(), vRecv.size());
17301754
if (nDropMessagesTest > 0 && GetRand(nDropMessagesTest) == 0)
17311755
{
17321756
printf("dropmessages DROPPING RECV MESSAGE\n");
@@ -1735,18 +1759,32 @@ bool ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv)
17351759

17361760

17371761

1762+
17381763
if (strCommand == "version")
17391764
{
1740-
// Can only do this once
1765+
// Each connection can only send one version message
17411766
if (pfrom->nVersion != 0)
17421767
return false;
17431768

17441769
int64 nTime;
17451770
CAddress addrMe;
1771+
CAddress addrFrom;
1772+
uint64 nNonce = 1;
17461773
vRecv >> pfrom->nVersion >> pfrom->nServices >> nTime >> addrMe;
1774+
if (pfrom->nVersion >= 106 && !vRecv.empty())
1775+
vRecv >> addrFrom >> nNonce;
17471776
if (pfrom->nVersion == 0)
17481777
return false;
17491778

1779+
// Disconnect if we connected to ourself
1780+
if (nNonce == nLocalHostNonce)
1781+
{
1782+
pfrom->fDisconnect = true;
1783+
pfrom->vRecv.clear();
1784+
pfrom->vSend.clear();
1785+
return true;
1786+
}
1787+
17501788
pfrom->vSend.SetVersion(min(pfrom->nVersion, VERSION));
17511789
pfrom->vRecv.SetVersion(min(pfrom->nVersion, VERSION));
17521790

@@ -1767,6 +1805,8 @@ bool ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv)
17671805
pfrom->PushMessage("getblocks", CBlockLocator(pindexBest), uint256(0));
17681806
}
17691807

1808+
pfrom->fSuccessfullyConnected = true;
1809+
17701810
printf("version message: version %d\n", pfrom->nVersion);
17711811
}
17721812

@@ -1800,16 +1840,16 @@ bool ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv)
18001840
if (fShutdown)
18011841
return true;
18021842
AddAddress(addrdb, addr);
1803-
if (addr.IsRoutable() && addr.ip != addrLocalHost.ip)
1843+
pfrom->AddAddressKnown(addr);
1844+
if (!pfrom->fGetAddr && addr.IsRoutable())
18041845
{
18051846
// Put on lists to send to other nodes
1806-
pfrom->setAddrKnown.insert(addr);
18071847
CRITICAL_BLOCK(cs_vNodes)
18081848
foreach(CNode* pnode, vNodes)
1809-
if (!pnode->setAddrKnown.count(addr))
1810-
pnode->vAddrToSend.push_back(addr);
1849+
pnode->PushAddress(addr);
18111850
}
18121851
}
1852+
pfrom->fGetAddr = false;
18131853
}
18141854

18151855

@@ -2009,7 +2049,7 @@ bool ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv)
20092049
return true;
20102050
const CAddress& addr = item.second;
20112051
if (addr.nTime > nSince)
2012-
pfrom->vAddrToSend.push_back(addr);
2052+
pfrom->PushAddress(addr);
20132053
}
20142054
}
20152055
}
@@ -2108,8 +2148,11 @@ bool SendMessages(CNode* pto)
21082148
vector<CAddress> vAddrToSend;
21092149
vAddrToSend.reserve(pto->vAddrToSend.size());
21102150
foreach(const CAddress& addr, pto->vAddrToSend)
2111-
if (!pto->setAddrKnown.count(addr))
2151+
{
2152+
// returns true if wasn't already contained in the set
2153+
if (pto->setAddrKnown.insert(addr).second)
21122154
vAddrToSend.push_back(addr);
2155+
}
21132156
pto->vAddrToSend.clear();
21142157
if (!vAddrToSend.empty())
21152158
pto->PushMessage("addr", vAddrToSend);
@@ -2193,7 +2236,7 @@ void GenerateBitcoins(bool fGenerate)
21932236
if (fLimitProcessors && nProcessors > nLimitProcessors)
21942237
nProcessors = nLimitProcessors;
21952238
int nAddThreads = nProcessors - vnThreadsRunning[3];
2196-
printf("starting %d bitcoinminer threads\n", nAddThreads);
2239+
printf("Starting %d BitcoinMiner threads\n", nAddThreads);
21972240
for (int i = 0; i < nAddThreads; i++)
21982241
if (_beginthread(ThreadBitcoinMiner, 0, NULL) == -1)
21992242
printf("Error: _beginthread(ThreadBitcoinMiner) failed\n");
@@ -2207,7 +2250,7 @@ void ThreadBitcoinMiner(void* parg)
22072250
try
22082251
{
22092252
bool fRet = BitcoinMiner();
2210-
printf("BitcoinMiner returned %s\n\n\n", fRet ? "true" : "false");
2253+
printf("BitcoinMiner returned %s\n", fRet ? "true" : "false");
22112254
vnThreadsRunning[3]--;
22122255
}
22132256
catch (std::exception& e) {
@@ -2737,7 +2780,7 @@ bool SendMoney(CScript scriptPubKey, int64 nValue, CWalletTx& wtxNew)
27372780
else
27382781
strError = "Error: Transaction creation failed ";
27392782
wxMessageBox(strError, "Sending...");
2740-
return error("SendMoney() : %s\n", strError.c_str());
2783+
return error("SendMoney() : %s", strError.c_str());
27412784
}
27422785
if (!CommitTransactionSpent(wtxNew, key))
27432786
{

‎main.h

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,7 @@ class CTransaction
366366
int nVersion;
367367
vector<CTxIn> vin;
368368
vector<CTxOut> vout;
369-
int nLockTime;
369+
unsigned int nLockTime;
370370

371371

372372
CTransaction()
@@ -401,9 +401,15 @@ class CTransaction
401401
return SerializeHash(*this);
402402
}
403403

404-
bool IsFinal() const
404+
bool IsFinal(int64 nBlockTime=0) const
405405
{
406-
if (nLockTime == 0 || nLockTime < nBestHeight)
406+
// Time based nLockTime implemented in 0.1.6,
407+
// do not use time based until most 0.1.5 nodes have upgraded.
408+
if (nBlockTime == 0)
409+
nBlockTime = GetAdjustedTime();
410+
if (nLockTime == 0)
411+
return true;
412+
if (nLockTime < (nLockTime < 500000000 ? nBestHeight : nBlockTime))
407413
return true;
408414
foreach(const CTxIn& txin, vin)
409415
if (!txin.IsFinal())
@@ -686,8 +692,9 @@ class CWalletTx : public CMerkleTx
686692
char fSpent;
687693
//// probably need to sign the order info so know it came from payer
688694

689-
// memory only
695+
// memory only UI hints
690696
mutable unsigned int nTimeDisplayed;
697+
mutable int nLinesDisplayed;
691698

692699

693700
CWalletTx()
@@ -712,6 +719,7 @@ class CWalletTx : public CMerkleTx
712719
fFromMe = false;
713720
fSpent = false;
714721
nTimeDisplayed = 0;
722+
nLinesDisplayed = 0;
715723
}
716724

717725
IMPLEMENT_SERIALIZE

‎makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ endif
1717

1818

1919

20-
INCLUDEPATHS=-I"/boost" -I"/DB/build_unix" -I"/OpenSSL/include" -I"/wxWidgets/lib/vc_lib/mswd" -I"/wxWidgets/include"
21-
LIBPATHS=-L"/DB/build_unix" -L"/OpenSSL/out" -L"/wxWidgets/lib/gcc_lib"
20+
INCLUDEPATHS=-I"/boost" -I"/db/build_unix" -I"/openssl/include" -I"/wxwidgets/lib/vc_lib/mswd" -I"/wxwidgets/include"
21+
LIBPATHS=-L"/db/build_unix" -L"/openssl/out" -L"/wxwidgets/lib/gcc_lib"
2222
LIBS= \
2323
-l db_cxx \
2424
-l eay32 \

0 commit comments

Comments
 (0)
Please sign in to comment.