Mercurial > hg > bitcoin
annotate src/main.cpp @ 941:e6547ebc0bd1 draft
Bugfix: Use timestamp in coinbase rather than "bits", needed to ensure coinbase txn is unique even if address is the same
author | Luke Dashjr <luke-jr+git@utopios.org> |
---|---|
date | Tue, 06 Sep 2011 16:39:05 -0400 |
parents | 26f82de9f2cc |
children | 4f02348aa51e |
rev | line source |
---|---|
575
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1 // Copyright (c) 2009-2010 Satoshi Nakamoto |
846 | 2 // Copyright (c) 2011 The Bitcoin developers |
575
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
3 // Distributed under the MIT/X11 software license, see the accompanying |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
4 // file license.txt or http://www.opensource.org/licenses/mit-license.php. |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
5 #include "headers.h" |
605
1ae81ad9b0e5
Only include db.h when we have to.
Jordan Lewis <jordanthelewis@gmail.com>
parents:
595
diff
changeset
|
6 #include "db.h" |
607
92e329774c81
Only include net.h when we have to
Jordan Lewis <jordanthelewis@gmail.com>
parents:
605
diff
changeset
|
7 #include "net.h" |
608
1dbd290981a9
Only include init.h when we have to
Jordan Lewis <jordanthelewis@gmail.com>
parents:
607
diff
changeset
|
8 #include "init.h" |
575
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
9 #include "cryptopp/sha.h" |
695
9609c7af94ba
Fix missing includes needed for Boost 1.46.
Shane Wegner <shane-github@csy.ca>
parents:
690
diff
changeset
|
10 #include <boost/filesystem.hpp> |
611
503d51554676
Only include certain boost headers if necessary.
Jordan Lewis <jordanthelewis@gmail.com>
parents:
608
diff
changeset
|
11 #include <boost/filesystem/fstream.hpp> |
575
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
12 |
595
e630bbb11629
make bitcoin include files more modular
Wladimir J. van der Laan <laanwj@gmail.com>
parents:
588
diff
changeset
|
13 using namespace std; |
e630bbb11629
make bitcoin include files more modular
Wladimir J. van der Laan <laanwj@gmail.com>
parents:
588
diff
changeset
|
14 using namespace boost; |
575
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
15 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
16 // |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
17 // Global state |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
18 // |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
19 |
690 | 20 CCriticalSection cs_setpwalletRegistered; |
21 set<CWallet*> setpwalletRegistered; | |
22 | |
575
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
23 CCriticalSection cs_main; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
24 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
25 map<uint256, CTransaction> mapTransactions; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
26 CCriticalSection cs_mapTransactions; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
27 unsigned int nTransactionsUpdated = 0; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
28 map<COutPoint, CInPoint> mapNextTx; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
29 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
30 map<uint256, CBlockIndex*> mapBlockIndex; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
31 uint256 hashGenesisBlock("0x000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f"); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
32 CBigNum bnProofOfWorkLimit(~uint256(0) >> 32); |
738
7d6b511630d6
Block-chain lock-in at 134444
Gavin Andresen <gavinandresen@gmail.com>
parents:
718
diff
changeset
|
33 const int nTotalBlocksEstimate = 134444; // Conservative estimate of total nr of blocks on main chain |
7d6b511630d6
Block-chain lock-in at 134444
Gavin Andresen <gavinandresen@gmail.com>
parents:
718
diff
changeset
|
34 const int nInitialBlockThreshold = 120; // Regard blocks up until N-threshold as "initial download" |
575
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
35 CBlockIndex* pindexGenesisBlock = NULL; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
36 int nBestHeight = -1; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
37 CBigNum bnBestChainWork = 0; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
38 CBigNum bnBestInvalidWork = 0; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
39 uint256 hashBestChain = 0; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
40 CBlockIndex* pindexBest = NULL; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
41 int64 nTimeBestReceived = 0; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
42 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
43 map<uint256, CBlock*> mapOrphanBlocks; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
44 multimap<uint256, CBlock*> mapOrphanBlocksByPrev; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
45 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
46 map<uint256, CDataStream*> mapOrphanTransactions; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
47 multimap<uint256, CDataStream*> mapOrphanTransactionsByPrev; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
48 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
49 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
50 double dHashesPerSec; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
51 int64 nHPSTimerStart; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
52 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
53 // Settings |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
54 int fGenerateBitcoins = false; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
55 int64 nTransactionFee = 0; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
56 int fLimitProcessors = false; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
57 int nLimitProcessors = 1; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
58 int fMinimizeToTray = true; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
59 int fMinimizeOnClose = true; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
60 #if USE_UPNP |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
61 int fUseUPnP = true; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
62 #else |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
63 int fUseUPnP = false; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
64 #endif |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
65 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
66 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
67 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
68 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
69 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
70 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
71 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
72 ////////////////////////////////////////////////////////////////////////////// |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
73 // |
690 | 74 // dispatching functions |
575
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
75 // |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
76 |
690 | 77 void RegisterWallet(CWallet* pwalletIn) |
575
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
78 { |
690 | 79 CRITICAL_BLOCK(cs_setpwalletRegistered) |
80 { | |
81 setpwalletRegistered.insert(pwalletIn); | |
82 } | |
575
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
83 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
84 |
690 | 85 void UnregisterWallet(CWallet* pwalletIn) |
575
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
86 { |
690 | 87 CRITICAL_BLOCK(cs_setpwalletRegistered) |
575
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
88 { |
690 | 89 setpwalletRegistered.erase(pwalletIn); |
575
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
90 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
91 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
92 |
690 | 93 bool static IsFromMe(CTransaction& tx) |
575
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
94 { |
690 | 95 BOOST_FOREACH(CWallet* pwallet, setpwalletRegistered) |
96 if (pwallet->IsFromMe(tx)) | |
97 return true; | |
98 return false; | |
99 } | |
100 | |
101 bool static GetTransaction(const uint256& hashTx, CWalletTx& wtx) | |
102 { | |
103 BOOST_FOREACH(CWallet* pwallet, setpwalletRegistered) | |
104 if (pwallet->GetTransaction(hashTx,wtx)) | |
105 return true; | |
575
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
106 return false; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
107 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
108 |
690 | 109 void static EraseFromWallets(uint256 hash) |
110 { | |
111 BOOST_FOREACH(CWallet* pwallet, setpwalletRegistered) | |
112 pwallet->EraseFromWallet(hash); | |
113 } | |
114 | |
115 void static SyncWithWallets(const CTransaction& tx, const CBlock* pblock = NULL, bool fUpdate = false) | |
575
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
116 { |
690 | 117 BOOST_FOREACH(CWallet* pwallet, setpwalletRegistered) |
118 pwallet->AddToWalletIfInvolvingMe(tx, pblock, fUpdate); | |
575
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
119 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
120 |
690 | 121 void static SetBestChain(const CBlockLocator& loc) |
122 { | |
123 BOOST_FOREACH(CWallet* pwallet, setpwalletRegistered) | |
124 pwallet->SetBestChain(loc); | |
125 } | |
126 | |
127 void static UpdatedTransaction(const uint256& hashTx) | |
575
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
128 { |
690 | 129 BOOST_FOREACH(CWallet* pwallet, setpwalletRegistered) |
130 pwallet->UpdatedTransaction(hashTx); | |
131 } | |
132 | |
133 void static PrintWallets(const CBlock& block) | |
134 { | |
135 BOOST_FOREACH(CWallet* pwallet, setpwalletRegistered) | |
136 pwallet->PrintWallet(block); | |
575
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
137 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
138 |
690 | 139 void static Inventory(const uint256& hash) |
140 { | |
141 BOOST_FOREACH(CWallet* pwallet, setpwalletRegistered) | |
142 pwallet->Inventory(hash); | |
143 } | |
144 | |
145 void static ResendWalletTransactions() | |
146 { | |
147 BOOST_FOREACH(CWallet* pwallet, setpwalletRegistered) | |
148 pwallet->ResendWalletTransactions(); | |
149 } | |
575
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
150 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
151 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
152 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
153 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
154 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
155 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
156 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
157 ////////////////////////////////////////////////////////////////////////////// |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
158 // |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
159 // mapOrphanTransactions |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
160 // |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
161 |
690 | 162 void static AddOrphanTx(const CDataStream& vMsg) |
575
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
163 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
164 CTransaction tx; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
165 CDataStream(vMsg) >> tx; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
166 uint256 hash = tx.GetHash(); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
167 if (mapOrphanTransactions.count(hash)) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
168 return; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
169 CDataStream* pvMsg = mapOrphanTransactions[hash] = new CDataStream(vMsg); |
595
e630bbb11629
make bitcoin include files more modular
Wladimir J. van der Laan <laanwj@gmail.com>
parents:
588
diff
changeset
|
170 BOOST_FOREACH(const CTxIn& txin, tx.vin) |
575
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
171 mapOrphanTransactionsByPrev.insert(make_pair(txin.prevout.hash, pvMsg)); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
172 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
173 |
690 | 174 void static EraseOrphanTx(uint256 hash) |
575
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
175 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
176 if (!mapOrphanTransactions.count(hash)) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
177 return; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
178 const CDataStream* pvMsg = mapOrphanTransactions[hash]; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
179 CTransaction tx; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
180 CDataStream(*pvMsg) >> tx; |
595
e630bbb11629
make bitcoin include files more modular
Wladimir J. van der Laan <laanwj@gmail.com>
parents:
588
diff
changeset
|
181 BOOST_FOREACH(const CTxIn& txin, tx.vin) |
575
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
182 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
183 for (multimap<uint256, CDataStream*>::iterator mi = mapOrphanTransactionsByPrev.lower_bound(txin.prevout.hash); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
184 mi != mapOrphanTransactionsByPrev.upper_bound(txin.prevout.hash);) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
185 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
186 if ((*mi).second == pvMsg) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
187 mapOrphanTransactionsByPrev.erase(mi++); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
188 else |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
189 mi++; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
190 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
191 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
192 delete pvMsg; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
193 mapOrphanTransactions.erase(hash); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
194 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
195 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
196 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
197 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
198 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
199 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
200 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
201 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
202 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
203 ////////////////////////////////////////////////////////////////////////////// |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
204 // |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
205 // CTransaction and CTxIndex |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
206 // |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
207 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
208 bool CTransaction::ReadFromDisk(CTxDB& txdb, COutPoint prevout, CTxIndex& txindexRet) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
209 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
210 SetNull(); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
211 if (!txdb.ReadTxIndex(prevout.hash, txindexRet)) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
212 return false; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
213 if (!ReadFromDisk(txindexRet.pos)) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
214 return false; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
215 if (prevout.n >= vout.size()) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
216 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
217 SetNull(); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
218 return false; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
219 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
220 return true; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
221 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
222 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
223 bool CTransaction::ReadFromDisk(CTxDB& txdb, COutPoint prevout) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
224 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
225 CTxIndex txindex; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
226 return ReadFromDisk(txdb, prevout, txindex); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
227 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
228 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
229 bool CTransaction::ReadFromDisk(COutPoint prevout) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
230 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
231 CTxDB txdb("r"); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
232 CTxIndex txindex; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
233 return ReadFromDisk(txdb, prevout, txindex); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
234 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
235 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
236 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
237 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
238 int CMerkleTx::SetMerkleBranch(const CBlock* pblock) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
239 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
240 if (fClient) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
241 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
242 if (hashBlock == 0) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
243 return 0; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
244 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
245 else |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
246 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
247 CBlock blockTmp; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
248 if (pblock == NULL) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
249 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
250 // Load the block this tx is in |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
251 CTxIndex txindex; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
252 if (!CTxDB("r").ReadTxIndex(GetHash(), txindex)) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
253 return 0; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
254 if (!blockTmp.ReadFromDisk(txindex.pos.nFile, txindex.pos.nBlockPos)) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
255 return 0; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
256 pblock = &blockTmp; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
257 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
258 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
259 // Update the tx's hashBlock |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
260 hashBlock = pblock->GetHash(); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
261 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
262 // Locate the transaction |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
263 for (nIndex = 0; nIndex < pblock->vtx.size(); nIndex++) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
264 if (pblock->vtx[nIndex] == *(CTransaction*)this) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
265 break; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
266 if (nIndex == pblock->vtx.size()) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
267 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
268 vMerkleBranch.clear(); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
269 nIndex = -1; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
270 printf("ERROR: SetMerkleBranch() : couldn't find tx in block\n"); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
271 return 0; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
272 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
273 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
274 // Fill in merkle branch |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
275 vMerkleBranch = pblock->GetMerkleBranch(nIndex); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
276 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
277 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
278 // Is the tx in a block that's in the main chain |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
279 map<uint256, CBlockIndex*>::iterator mi = mapBlockIndex.find(hashBlock); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
280 if (mi == mapBlockIndex.end()) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
281 return 0; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
282 CBlockIndex* pindex = (*mi).second; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
283 if (!pindex || !pindex->IsInMainChain()) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
284 return 0; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
285 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
286 return pindexBest->nHeight - pindex->nHeight + 1; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
287 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
288 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
289 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
290 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
291 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
292 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
293 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
294 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
295 bool CTransaction::CheckTransaction() const |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
296 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
297 // Basic checks that don't depend on any context |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
298 if (vin.empty() || vout.empty()) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
299 return error("CTransaction::CheckTransaction() : vin or vout empty"); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
300 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
301 // Size limits |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
302 if (::GetSerializeSize(*this, SER_NETWORK) > MAX_BLOCK_SIZE) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
303 return error("CTransaction::CheckTransaction() : size limits failed"); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
304 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
305 // Check for negative or overflow output values |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
306 int64 nValueOut = 0; |
595
e630bbb11629
make bitcoin include files more modular
Wladimir J. van der Laan <laanwj@gmail.com>
parents:
588
diff
changeset
|
307 BOOST_FOREACH(const CTxOut& txout, vout) |
575
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
308 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
309 if (txout.nValue < 0) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
310 return error("CTransaction::CheckTransaction() : txout.nValue negative"); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
311 if (txout.nValue > MAX_MONEY) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
312 return error("CTransaction::CheckTransaction() : txout.nValue too high"); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
313 nValueOut += txout.nValue; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
314 if (!MoneyRange(nValueOut)) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
315 return error("CTransaction::CheckTransaction() : txout total out of range"); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
316 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
317 |
833
2d64c5debf03
Check for duplicate txins in CheckTransaction.
Matt Corallo <matt@bluematt.me>
parents:
824
diff
changeset
|
318 // Check for duplicate inputs |
2d64c5debf03
Check for duplicate txins in CheckTransaction.
Matt Corallo <matt@bluematt.me>
parents:
824
diff
changeset
|
319 set<COutPoint> vInOutPoints; |
2d64c5debf03
Check for duplicate txins in CheckTransaction.
Matt Corallo <matt@bluematt.me>
parents:
824
diff
changeset
|
320 BOOST_FOREACH(const CTxIn& txin, vin) |
2d64c5debf03
Check for duplicate txins in CheckTransaction.
Matt Corallo <matt@bluematt.me>
parents:
824
diff
changeset
|
321 { |
2d64c5debf03
Check for duplicate txins in CheckTransaction.
Matt Corallo <matt@bluematt.me>
parents:
824
diff
changeset
|
322 if (vInOutPoints.count(txin.prevout)) |
2d64c5debf03
Check for duplicate txins in CheckTransaction.
Matt Corallo <matt@bluematt.me>
parents:
824
diff
changeset
|
323 return false; |
2d64c5debf03
Check for duplicate txins in CheckTransaction.
Matt Corallo <matt@bluematt.me>
parents:
824
diff
changeset
|
324 vInOutPoints.insert(txin.prevout); |
2d64c5debf03
Check for duplicate txins in CheckTransaction.
Matt Corallo <matt@bluematt.me>
parents:
824
diff
changeset
|
325 } |
2d64c5debf03
Check for duplicate txins in CheckTransaction.
Matt Corallo <matt@bluematt.me>
parents:
824
diff
changeset
|
326 |
575
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
327 if (IsCoinBase()) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
328 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
329 if (vin[0].scriptSig.size() < 2 || vin[0].scriptSig.size() > 100) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
330 return error("CTransaction::CheckTransaction() : coinbase script size"); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
331 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
332 else |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
333 { |
595
e630bbb11629
make bitcoin include files more modular
Wladimir J. van der Laan <laanwj@gmail.com>
parents:
588
diff
changeset
|
334 BOOST_FOREACH(const CTxIn& txin, vin) |
575
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
335 if (txin.prevout.IsNull()) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
336 return error("CTransaction::CheckTransaction() : prevout is null"); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
337 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
338 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
339 return true; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
340 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
341 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
342 bool CTransaction::AcceptToMemoryPool(CTxDB& txdb, bool fCheckInputs, bool* pfMissingInputs) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
343 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
344 if (pfMissingInputs) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
345 *pfMissingInputs = false; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
346 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
347 if (!CheckTransaction()) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
348 return error("AcceptToMemoryPool() : CheckTransaction failed"); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
349 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
350 // Coinbase is only valid in a block, not as a loose transaction |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
351 if (IsCoinBase()) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
352 return error("AcceptToMemoryPool() : coinbase as individual tx"); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
353 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
354 // To help v0.1.5 clients who would see it as a negative number |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
355 if ((int64)nLockTime > INT_MAX) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
356 return error("AcceptToMemoryPool() : not accepting nLockTime beyond 2038 yet"); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
357 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
358 // Safety limits |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
359 unsigned int nSize = ::GetSerializeSize(*this, SER_NETWORK); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
360 // Checking ECDSA signatures is a CPU bottleneck, so to avoid denial-of-service |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
361 // attacks disallow transactions with more than one SigOp per 34 bytes. |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
362 // 34 bytes because a TxOut is: |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
363 // 20-byte address + 8 byte bitcoin amount + 5 bytes of ops + 1 byte script length |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
364 if (GetSigOpCount() > nSize / 34 || nSize < 100) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
365 return error("AcceptToMemoryPool() : nonstandard transaction"); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
366 |
576
8ec6d5e778e5
Manual merge of jaromil's source tree reorg commit.
Jeff Garzik <jeff@garzik.org>
parents:
575
diff
changeset
|
367 // Rather not work on nonstandard transactions (unless -testnet) |
8ec6d5e778e5
Manual merge of jaromil's source tree reorg commit.
Jeff Garzik <jeff@garzik.org>
parents:
575
diff
changeset
|
368 if (!fTestNet && !IsStandard()) |
575
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
369 return error("AcceptToMemoryPool() : nonstandard transaction type"); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
370 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
371 // Do we already have it? |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
372 uint256 hash = GetHash(); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
373 CRITICAL_BLOCK(cs_mapTransactions) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
374 if (mapTransactions.count(hash)) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
375 return false; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
376 if (fCheckInputs) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
377 if (txdb.ContainsTx(hash)) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
378 return false; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
379 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
380 // Check for conflicts with in-memory transactions |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
381 CTransaction* ptxOld = NULL; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
382 for (int i = 0; i < vin.size(); i++) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
383 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
384 COutPoint outpoint = vin[i].prevout; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
385 if (mapNextTx.count(outpoint)) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
386 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
387 // Disable replacement feature for now |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
388 return false; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
389 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
390 // Allow replacing with a newer version of the same transaction |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
391 if (i != 0) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
392 return false; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
393 ptxOld = mapNextTx[outpoint].ptx; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
394 if (ptxOld->IsFinal()) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
395 return false; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
396 if (!IsNewerThan(*ptxOld)) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
397 return false; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
398 for (int i = 0; i < vin.size(); i++) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
399 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
400 COutPoint outpoint = vin[i].prevout; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
401 if (!mapNextTx.count(outpoint) || mapNextTx[outpoint].ptx != ptxOld) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
402 return false; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
403 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
404 break; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
405 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
406 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
407 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
408 if (fCheckInputs) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
409 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
410 // Check against previous transactions |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
411 map<uint256, CTxIndex> mapUnused; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
412 int64 nFees = 0; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
413 if (!ConnectInputs(txdb, mapUnused, CDiskTxPos(1,1,1), pindexBest, nFees, false, false)) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
414 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
415 if (pfMissingInputs) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
416 *pfMissingInputs = true; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
417 return error("AcceptToMemoryPool() : ConnectInputs failed %s", hash.ToString().substr(0,10).c_str()); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
418 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
419 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
420 // Don't accept it if it can't get into a block |
654
a8a8e3a6f08a
bugfix: accept free transactions
Pieter Wuille <pieter.wuille@gmail.com>
parents:
638
diff
changeset
|
421 if (nFees < GetMinFee(1000, true, true)) |
575
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
422 return error("AcceptToMemoryPool() : not enough fees"); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
423 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
424 // Continuously rate-limit free transactions |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
425 // This mitigates 'penny-flooding' -- sending thousands of free transactions just to |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
426 // be annoying or make other's transactions take longer to confirm. |
638
6046cfa5296f
Separate required fee for relaying and creation
Pieter Wuille <pieter.wuille@gmail.com>
parents:
595
diff
changeset
|
427 if (nFees < MIN_RELAY_TX_FEE) |
575
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
428 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
429 static CCriticalSection cs; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
430 static double dFreeCount; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
431 static int64 nLastTime; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
432 int64 nNow = GetTime(); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
433 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
434 CRITICAL_BLOCK(cs) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
435 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
436 // Use an exponentially decaying ~10-minute window: |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
437 dFreeCount *= pow(1.0 - 1.0/600.0, (double)(nNow - nLastTime)); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
438 nLastTime = nNow; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
439 // -limitfreerelay unit is thousand-bytes-per-minute |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
440 // At default rate it would take over a month to fill 1GB |
690 | 441 if (dFreeCount > GetArg("-limitfreerelay", 15)*10*1000 && !IsFromMe(*this)) |
575
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
442 return error("AcceptToMemoryPool() : free transaction rejected by rate limiter"); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
443 if (fDebug) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
444 printf("Rate limit dFreeCount: %g => %g\n", dFreeCount, dFreeCount+nSize); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
445 dFreeCount += nSize; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
446 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
447 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
448 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
449 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
450 // Store transaction in memory |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
451 CRITICAL_BLOCK(cs_mapTransactions) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
452 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
453 if (ptxOld) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
454 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
455 printf("AcceptToMemoryPool() : replacing tx %s with new version\n", ptxOld->GetHash().ToString().c_str()); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
456 ptxOld->RemoveFromMemoryPool(); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
457 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
458 AddToMemoryPoolUnchecked(); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
459 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
460 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
461 ///// are we sure this is ok when loading transactions or restoring block txes |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
462 // If updated, erase old tx from wallet |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
463 if (ptxOld) |
690 | 464 EraseFromWallets(ptxOld->GetHash()); |
575
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
465 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
466 printf("AcceptToMemoryPool(): accepted %s\n", hash.ToString().substr(0,10).c_str()); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
467 return true; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
468 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
469 |
689
9df222fa1ef1
move wallet code to separate file
Pieter Wuille <pieter.wuille@gmail.com>
parents:
688
diff
changeset
|
470 bool CTransaction::AcceptToMemoryPool(bool fCheckInputs, bool* pfMissingInputs) |
9df222fa1ef1
move wallet code to separate file
Pieter Wuille <pieter.wuille@gmail.com>
parents:
688
diff
changeset
|
471 { |
9df222fa1ef1
move wallet code to separate file
Pieter Wuille <pieter.wuille@gmail.com>
parents:
688
diff
changeset
|
472 CTxDB txdb("r"); |
9df222fa1ef1
move wallet code to separate file
Pieter Wuille <pieter.wuille@gmail.com>
parents:
688
diff
changeset
|
473 return AcceptToMemoryPool(txdb, fCheckInputs, pfMissingInputs); |
9df222fa1ef1
move wallet code to separate file
Pieter Wuille <pieter.wuille@gmail.com>
parents:
688
diff
changeset
|
474 } |
575
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
475 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
476 bool CTransaction::AddToMemoryPoolUnchecked() |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
477 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
478 // Add to memory pool without checking anything. Don't call this directly, |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
479 // call AcceptToMemoryPool to properly check the transaction first. |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
480 CRITICAL_BLOCK(cs_mapTransactions) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
481 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
482 uint256 hash = GetHash(); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
483 mapTransactions[hash] = *this; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
484 for (int i = 0; i < vin.size(); i++) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
485 mapNextTx[vin[i].prevout] = CInPoint(&mapTransactions[hash], i); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
486 nTransactionsUpdated++; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
487 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
488 return true; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
489 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
490 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
491 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
492 bool CTransaction::RemoveFromMemoryPool() |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
493 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
494 // Remove transaction from memory pool |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
495 CRITICAL_BLOCK(cs_mapTransactions) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
496 { |
595
e630bbb11629
make bitcoin include files more modular
Wladimir J. van der Laan <laanwj@gmail.com>
parents:
588
diff
changeset
|
497 BOOST_FOREACH(const CTxIn& txin, vin) |
575
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
498 mapNextTx.erase(txin.prevout); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
499 mapTransactions.erase(GetHash()); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
500 nTransactionsUpdated++; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
501 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
502 return true; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
503 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
504 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
505 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
506 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
507 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
508 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
509 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
510 int CMerkleTx::GetDepthInMainChain(int& nHeightRet) const |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
511 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
512 if (hashBlock == 0 || nIndex == -1) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
513 return 0; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
514 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
515 // Find the block it claims to be in |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
516 map<uint256, CBlockIndex*>::iterator mi = mapBlockIndex.find(hashBlock); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
517 if (mi == mapBlockIndex.end()) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
518 return 0; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
519 CBlockIndex* pindex = (*mi).second; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
520 if (!pindex || !pindex->IsInMainChain()) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
521 return 0; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
522 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
523 // Make sure the merkle branch connects to this block |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
524 if (!fMerkleVerified) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
525 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
526 if (CBlock::CheckMerkleBranch(GetHash(), vMerkleBranch, nIndex) != pindex->hashMerkleRoot) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
527 return 0; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
528 fMerkleVerified = true; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
529 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
530 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
531 nHeightRet = pindex->nHeight; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
532 return pindexBest->nHeight - pindex->nHeight + 1; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
533 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
534 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
535 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
536 int CMerkleTx::GetBlocksToMaturity() const |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
537 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
538 if (!IsCoinBase()) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
539 return 0; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
540 return max(0, (COINBASE_MATURITY+20) - GetDepthInMainChain()); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
541 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
542 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
543 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
544 bool CMerkleTx::AcceptToMemoryPool(CTxDB& txdb, bool fCheckInputs) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
545 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
546 if (fClient) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
547 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
548 if (!IsInMainChain() && !ClientConnectInputs()) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
549 return false; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
550 return CTransaction::AcceptToMemoryPool(txdb, false); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
551 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
552 else |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
553 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
554 return CTransaction::AcceptToMemoryPool(txdb, fCheckInputs); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
555 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
556 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
557 |
689
9df222fa1ef1
move wallet code to separate file
Pieter Wuille <pieter.wuille@gmail.com>
parents:
688
diff
changeset
|
558 bool CMerkleTx::AcceptToMemoryPool() |
9df222fa1ef1
move wallet code to separate file
Pieter Wuille <pieter.wuille@gmail.com>
parents:
688
diff
changeset
|
559 { |
9df222fa1ef1
move wallet code to separate file
Pieter Wuille <pieter.wuille@gmail.com>
parents:
688
diff
changeset
|
560 CTxDB txdb("r"); |
9df222fa1ef1
move wallet code to separate file
Pieter Wuille <pieter.wuille@gmail.com>
parents:
688
diff
changeset
|
561 return AcceptToMemoryPool(txdb); |
9df222fa1ef1
move wallet code to separate file
Pieter Wuille <pieter.wuille@gmail.com>
parents:
688
diff
changeset
|
562 } |
9df222fa1ef1
move wallet code to separate file
Pieter Wuille <pieter.wuille@gmail.com>
parents:
688
diff
changeset
|
563 |
575
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
564 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
565 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
566 bool CWalletTx::AcceptWalletTransaction(CTxDB& txdb, bool fCheckInputs) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
567 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
568 CRITICAL_BLOCK(cs_mapTransactions) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
569 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
570 // Add previous supporting transactions first |
595
e630bbb11629
make bitcoin include files more modular
Wladimir J. van der Laan <laanwj@gmail.com>
parents:
588
diff
changeset
|
571 BOOST_FOREACH(CMerkleTx& tx, vtxPrev) |
575
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
572 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
573 if (!tx.IsCoinBase()) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
574 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
575 uint256 hash = tx.GetHash(); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
576 if (!mapTransactions.count(hash) && !txdb.ContainsTx(hash)) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
577 tx.AcceptToMemoryPool(txdb, fCheckInputs); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
578 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
579 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
580 return AcceptToMemoryPool(txdb, fCheckInputs); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
581 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
582 return false; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
583 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
584 |
689
9df222fa1ef1
move wallet code to separate file
Pieter Wuille <pieter.wuille@gmail.com>
parents:
688
diff
changeset
|
585 bool CWalletTx::AcceptWalletTransaction() |
575
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
586 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
587 CTxDB txdb("r"); |
689
9df222fa1ef1
move wallet code to separate file
Pieter Wuille <pieter.wuille@gmail.com>
parents:
688
diff
changeset
|
588 return AcceptWalletTransaction(txdb); |
575
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
589 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
590 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
591 int CTxIndex::GetDepthInMainChain() const |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
592 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
593 // Read block header |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
594 CBlock block; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
595 if (!block.ReadFromDisk(pos.nFile, pos.nBlockPos, false)) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
596 return 0; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
597 // Find the block in the index |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
598 map<uint256, CBlockIndex*>::iterator mi = mapBlockIndex.find(block.GetHash()); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
599 if (mi == mapBlockIndex.end()) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
600 return 0; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
601 CBlockIndex* pindex = (*mi).second; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
602 if (!pindex || !pindex->IsInMainChain()) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
603 return 0; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
604 return 1 + nBestHeight - pindex->nHeight; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
605 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
606 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
607 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
608 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
609 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
610 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
611 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
612 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
613 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
614 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
615 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
616 ////////////////////////////////////////////////////////////////////////////// |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
617 // |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
618 // CBlock and CBlockIndex |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
619 // |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
620 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
621 bool CBlock::ReadFromDisk(const CBlockIndex* pindex, bool fReadTransactions) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
622 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
623 if (!fReadTransactions) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
624 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
625 *this = pindex->GetBlockHeader(); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
626 return true; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
627 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
628 if (!ReadFromDisk(pindex->nFile, pindex->nBlockPos, fReadTransactions)) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
629 return false; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
630 if (GetHash() != pindex->GetBlockHash()) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
631 return error("CBlock::ReadFromDisk() : GetHash() doesn't match index"); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
632 return true; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
633 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
634 |
690 | 635 uint256 static GetOrphanRoot(const CBlock* pblock) |
575
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
636 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
637 // Work back to the first block in the orphan chain |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
638 while (mapOrphanBlocks.count(pblock->hashPrevBlock)) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
639 pblock = mapOrphanBlocks[pblock->hashPrevBlock]; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
640 return pblock->GetHash(); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
641 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
642 |
690 | 643 int64 static GetBlockValue(int nHeight, int64 nFees) |
575
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
644 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
645 int64 nSubsidy = 50 * COIN; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
646 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
647 // Subsidy is cut in half every 4 years |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
648 nSubsidy >>= (nHeight / 210000); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
649 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
650 return nSubsidy + nFees; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
651 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
652 |
690 | 653 unsigned int static GetNextWorkRequired(const CBlockIndex* pindexLast) |
575
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
654 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
655 const int64 nTargetTimespan = 14 * 24 * 60 * 60; // two weeks |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
656 const int64 nTargetSpacing = 10 * 60; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
657 const int64 nInterval = nTargetTimespan / nTargetSpacing; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
658 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
659 // Genesis block |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
660 if (pindexLast == NULL) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
661 return bnProofOfWorkLimit.GetCompact(); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
662 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
663 // Only change once per interval |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
664 if ((pindexLast->nHeight+1) % nInterval != 0) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
665 return pindexLast->nBits; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
666 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
667 // Go back by what we want to be 14 days worth of blocks |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
668 const CBlockIndex* pindexFirst = pindexLast; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
669 for (int i = 0; pindexFirst && i < nInterval-1; i++) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
670 pindexFirst = pindexFirst->pprev; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
671 assert(pindexFirst); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
672 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
673 // Limit adjustment step |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
674 int64 nActualTimespan = pindexLast->GetBlockTime() - pindexFirst->GetBlockTime(); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
675 printf(" nActualTimespan = %"PRI64d" before bounds\n", nActualTimespan); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
676 if (nActualTimespan < nTargetTimespan/4) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
677 nActualTimespan = nTargetTimespan/4; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
678 if (nActualTimespan > nTargetTimespan*4) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
679 nActualTimespan = nTargetTimespan*4; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
680 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
681 // Retarget |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
682 CBigNum bnNew; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
683 bnNew.SetCompact(pindexLast->nBits); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
684 bnNew *= nActualTimespan; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
685 bnNew /= nTargetTimespan; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
686 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
687 if (bnNew > bnProofOfWorkLimit) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
688 bnNew = bnProofOfWorkLimit; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
689 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
690 /// debug print |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
691 printf("GetNextWorkRequired RETARGET\n"); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
692 printf("nTargetTimespan = %"PRI64d" nActualTimespan = %"PRI64d"\n", nTargetTimespan, nActualTimespan); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
693 printf("Before: %08x %s\n", pindexLast->nBits, CBigNum().SetCompact(pindexLast->nBits).getuint256().ToString().c_str()); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
694 printf("After: %08x %s\n", bnNew.GetCompact(), bnNew.getuint256().ToString().c_str()); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
695 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
696 return bnNew.GetCompact(); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
697 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
698 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
699 bool CheckProofOfWork(uint256 hash, unsigned int nBits) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
700 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
701 CBigNum bnTarget; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
702 bnTarget.SetCompact(nBits); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
703 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
704 // Check range |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
705 if (bnTarget <= 0 || bnTarget > bnProofOfWorkLimit) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
706 return error("CheckProofOfWork() : nBits below minimum work"); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
707 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
708 // Check proof of work matches claimed amount |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
709 if (hash > bnTarget.getuint256()) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
710 return error("CheckProofOfWork() : hash doesn't match nBits"); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
711 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
712 return true; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
713 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
714 |
702
ddf3fdf690a5
add GetTotalBlocksEstimate() function, move magic number to constant
Wladimir J. van der Laan <laanwj@gmail.com>
parents:
688
diff
changeset
|
715 // Return conservative estimate of total number of blocks, 0 if unknown |
ddf3fdf690a5
add GetTotalBlocksEstimate() function, move magic number to constant
Wladimir J. van der Laan <laanwj@gmail.com>
parents:
688
diff
changeset
|
716 int GetTotalBlocksEstimate() |
ddf3fdf690a5
add GetTotalBlocksEstimate() function, move magic number to constant
Wladimir J. van der Laan <laanwj@gmail.com>
parents:
688
diff
changeset
|
717 { |
ddf3fdf690a5
add GetTotalBlocksEstimate() function, move magic number to constant
Wladimir J. van der Laan <laanwj@gmail.com>
parents:
688
diff
changeset
|
718 if(fTestNet) |
ddf3fdf690a5
add GetTotalBlocksEstimate() function, move magic number to constant
Wladimir J. van der Laan <laanwj@gmail.com>
parents:
688
diff
changeset
|
719 { |
ddf3fdf690a5
add GetTotalBlocksEstimate() function, move magic number to constant
Wladimir J. van der Laan <laanwj@gmail.com>
parents:
688
diff
changeset
|
720 return 0; |
ddf3fdf690a5
add GetTotalBlocksEstimate() function, move magic number to constant
Wladimir J. van der Laan <laanwj@gmail.com>
parents:
688
diff
changeset
|
721 } |
ddf3fdf690a5
add GetTotalBlocksEstimate() function, move magic number to constant
Wladimir J. van der Laan <laanwj@gmail.com>
parents:
688
diff
changeset
|
722 else |
ddf3fdf690a5
add GetTotalBlocksEstimate() function, move magic number to constant
Wladimir J. van der Laan <laanwj@gmail.com>
parents:
688
diff
changeset
|
723 { |
ddf3fdf690a5
add GetTotalBlocksEstimate() function, move magic number to constant
Wladimir J. van der Laan <laanwj@gmail.com>
parents:
688
diff
changeset
|
724 return nTotalBlocksEstimate; |
ddf3fdf690a5
add GetTotalBlocksEstimate() function, move magic number to constant
Wladimir J. van der Laan <laanwj@gmail.com>
parents:
688
diff
changeset
|
725 } |
ddf3fdf690a5
add GetTotalBlocksEstimate() function, move magic number to constant
Wladimir J. van der Laan <laanwj@gmail.com>
parents:
688
diff
changeset
|
726 } |
ddf3fdf690a5
add GetTotalBlocksEstimate() function, move magic number to constant
Wladimir J. van der Laan <laanwj@gmail.com>
parents:
688
diff
changeset
|
727 |
575
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
728 bool IsInitialBlockDownload() |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
729 { |
702
ddf3fdf690a5
add GetTotalBlocksEstimate() function, move magic number to constant
Wladimir J. van der Laan <laanwj@gmail.com>
parents:
688
diff
changeset
|
730 if (pindexBest == NULL || nBestHeight < (GetTotalBlocksEstimate()-nInitialBlockThreshold)) |
575
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
731 return true; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
732 static int64 nLastUpdate; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
733 static CBlockIndex* pindexLastBest; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
734 if (pindexBest != pindexLastBest) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
735 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
736 pindexLastBest = pindexBest; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
737 nLastUpdate = GetTime(); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
738 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
739 return (GetTime() - nLastUpdate < 10 && |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
740 pindexBest->GetBlockTime() < GetTime() - 24 * 60 * 60); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
741 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
742 |
690 | 743 void static InvalidChainFound(CBlockIndex* pindexNew) |
575
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
744 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
745 if (pindexNew->bnChainWork > bnBestInvalidWork) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
746 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
747 bnBestInvalidWork = pindexNew->bnChainWork; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
748 CTxDB().WriteBestInvalidWork(bnBestInvalidWork); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
749 MainFrameRepaint(); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
750 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
751 printf("InvalidChainFound: invalid block=%s height=%d work=%s\n", pindexNew->GetBlockHash().ToString().substr(0,20).c_str(), pindexNew->nHeight, pindexNew->bnChainWork.ToString().c_str()); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
752 printf("InvalidChainFound: current best=%s height=%d work=%s\n", hashBestChain.ToString().substr(0,20).c_str(), nBestHeight, bnBestChainWork.ToString().c_str()); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
753 if (pindexBest && bnBestInvalidWork > bnBestChainWork + pindexBest->GetBlockWork() * 6) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
754 printf("InvalidChainFound: WARNING: Displayed transactions may not be correct! You may need to upgrade, or other nodes may need to upgrade.\n"); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
755 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
756 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
757 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
758 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
759 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
760 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
761 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
762 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
763 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
764 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
765 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
766 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
767 bool CTransaction::DisconnectInputs(CTxDB& txdb) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
768 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
769 // Relinquish previous transactions' spent pointers |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
770 if (!IsCoinBase()) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
771 { |
595
e630bbb11629
make bitcoin include files more modular
Wladimir J. van der Laan <laanwj@gmail.com>
parents:
588
diff
changeset
|
772 BOOST_FOREACH(const CTxIn& txin, vin) |
575
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
773 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
774 COutPoint prevout = txin.prevout; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
775 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
776 // Get prev txindex from disk |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
777 CTxIndex txindex; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
778 if (!txdb.ReadTxIndex(prevout.hash, txindex)) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
779 return error("DisconnectInputs() : ReadTxIndex failed"); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
780 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
781 if (prevout.n >= txindex.vSpent.size()) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
782 return error("DisconnectInputs() : prevout.n out of range"); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
783 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
784 // Mark outpoint as not spent |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
785 txindex.vSpent[prevout.n].SetNull(); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
786 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
787 // Write back |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
788 if (!txdb.UpdateTxIndex(prevout.hash, txindex)) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
789 return error("DisconnectInputs() : UpdateTxIndex failed"); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
790 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
791 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
792 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
793 // Remove transaction from index |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
794 if (!txdb.EraseTxIndex(*this)) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
795 return error("DisconnectInputs() : EraseTxPos failed"); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
796 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
797 return true; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
798 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
799 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
800 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
801 bool CTransaction::ConnectInputs(CTxDB& txdb, map<uint256, CTxIndex>& mapTestPool, CDiskTxPos posThisTx, |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
802 CBlockIndex* pindexBlock, int64& nFees, bool fBlock, bool fMiner, int64 nMinFee) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
803 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
804 // Take over previous transactions' spent pointers |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
805 if (!IsCoinBase()) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
806 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
807 int64 nValueIn = 0; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
808 for (int i = 0; i < vin.size(); i++) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
809 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
810 COutPoint prevout = vin[i].prevout; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
811 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
812 // Read txindex |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
813 CTxIndex txindex; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
814 bool fFound = true; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
815 if (fMiner && mapTestPool.count(prevout.hash)) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
816 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
817 // Get txindex from current proposed changes |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
818 txindex = mapTestPool[prevout.hash]; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
819 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
820 else |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
821 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
822 // Read txindex from txdb |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
823 fFound = txdb.ReadTxIndex(prevout.hash, txindex); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
824 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
825 if (!fFound && (fBlock || fMiner)) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
826 return fMiner ? false : error("ConnectInputs() : %s prev tx %s index entry not found", GetHash().ToString().substr(0,10).c_str(), prevout.hash.ToString().substr(0,10).c_str()); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
827 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
828 // Read txPrev |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
829 CTransaction txPrev; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
830 if (!fFound || txindex.pos == CDiskTxPos(1,1,1)) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
831 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
832 // Get prev tx from single transactions in memory |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
833 CRITICAL_BLOCK(cs_mapTransactions) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
834 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
835 if (!mapTransactions.count(prevout.hash)) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
836 return error("ConnectInputs() : %s mapTransactions prev not found %s", GetHash().ToString().substr(0,10).c_str(), prevout.hash.ToString().substr(0,10).c_str()); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
837 txPrev = mapTransactions[prevout.hash]; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
838 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
839 if (!fFound) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
840 txindex.vSpent.resize(txPrev.vout.size()); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
841 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
842 else |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
843 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
844 // Get prev tx from disk |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
845 if (!txPrev.ReadFromDisk(txindex.pos)) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
846 return error("ConnectInputs() : %s ReadFromDisk prev tx %s failed", GetHash().ToString().substr(0,10).c_str(), prevout.hash.ToString().substr(0,10).c_str()); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
847 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
848 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
849 if (prevout.n >= txPrev.vout.size() || prevout.n >= txindex.vSpent.size()) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
850 return error("ConnectInputs() : %s prevout.n out of range %d %d %d prev tx %s\n%s", GetHash().ToString().substr(0,10).c_str(), prevout.n, txPrev.vout.size(), txindex.vSpent.size(), prevout.hash.ToString().substr(0,10).c_str(), txPrev.ToString().c_str()); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
851 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
852 // If prev is coinbase, check that it's matured |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
853 if (txPrev.IsCoinBase()) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
854 for (CBlockIndex* pindex = pindexBlock; pindex && pindexBlock->nHeight - pindex->nHeight < COINBASE_MATURITY; pindex = pindex->pprev) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
855 if (pindex->nBlockPos == txindex.pos.nBlockPos && pindex->nFile == txindex.pos.nFile) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
856 return error("ConnectInputs() : tried to spend coinbase at depth %d", pindexBlock->nHeight - pindex->nHeight); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
857 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
858 // Verify signature |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
859 if (!VerifySignature(txPrev, *this, i)) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
860 return error("ConnectInputs() : %s VerifySignature failed", GetHash().ToString().substr(0,10).c_str()); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
861 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
862 // Check for conflicts |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
863 if (!txindex.vSpent[prevout.n].IsNull()) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
864 return fMiner ? false : error("ConnectInputs() : %s prev tx already used at %s", GetHash().ToString().substr(0,10).c_str(), txindex.vSpent[prevout.n].ToString().c_str()); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
865 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
866 // Check for negative or overflow input values |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
867 nValueIn += txPrev.vout[prevout.n].nValue; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
868 if (!MoneyRange(txPrev.vout[prevout.n].nValue) || !MoneyRange(nValueIn)) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
869 return error("ConnectInputs() : txin values out of range"); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
870 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
871 // Mark outpoints as spent |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
872 txindex.vSpent[prevout.n] = posThisTx; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
873 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
874 // Write back |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
875 if (fBlock) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
876 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
877 if (!txdb.UpdateTxIndex(prevout.hash, txindex)) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
878 return error("ConnectInputs() : UpdateTxIndex failed"); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
879 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
880 else if (fMiner) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
881 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
882 mapTestPool[prevout.hash] = txindex; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
883 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
884 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
885 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
886 if (nValueIn < GetValueOut()) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
887 return error("ConnectInputs() : %s value in < value out", GetHash().ToString().substr(0,10).c_str()); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
888 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
889 // Tally transaction fees |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
890 int64 nTxFee = nValueIn - GetValueOut(); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
891 if (nTxFee < 0) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
892 return error("ConnectInputs() : %s nTxFee < 0", GetHash().ToString().substr(0,10).c_str()); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
893 if (nTxFee < nMinFee) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
894 return false; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
895 nFees += nTxFee; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
896 if (!MoneyRange(nFees)) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
897 return error("ConnectInputs() : nFees out of range"); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
898 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
899 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
900 if (fBlock) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
901 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
902 // Add transaction to disk index |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
903 if (!txdb.AddTxIndex(*this, posThisTx, pindexBlock->nHeight)) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
904 return error("ConnectInputs() : AddTxPos failed"); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
905 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
906 else if (fMiner) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
907 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
908 // Add transaction to test pool |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
909 mapTestPool[GetHash()] = CTxIndex(CDiskTxPos(1,1,1), vout.size()); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
910 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
911 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
912 return true; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
913 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
914 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
915 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
916 bool CTransaction::ClientConnectInputs() |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
917 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
918 if (IsCoinBase()) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
919 return false; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
920 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
921 // Take over previous transactions' spent pointers |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
922 CRITICAL_BLOCK(cs_mapTransactions) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
923 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
924 int64 nValueIn = 0; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
925 for (int i = 0; i < vin.size(); i++) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
926 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
927 // Get prev tx from single transactions in memory |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
928 COutPoint prevout = vin[i].prevout; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
929 if (!mapTransactions.count(prevout.hash)) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
930 return false; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
931 CTransaction& txPrev = mapTransactions[prevout.hash]; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
932 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
933 if (prevout.n >= txPrev.vout.size()) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
934 return false; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
935 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
936 // Verify signature |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
937 if (!VerifySignature(txPrev, *this, i)) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
938 return error("ConnectInputs() : VerifySignature failed"); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
939 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
940 ///// this is redundant with the mapNextTx stuff, not sure which I want to get rid of |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
941 ///// this has to go away now that posNext is gone |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
942 // // Check for conflicts |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
943 // if (!txPrev.vout[prevout.n].posNext.IsNull()) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
944 // return error("ConnectInputs() : prev tx already used"); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
945 // |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
946 // // Flag outpoints as used |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
947 // txPrev.vout[prevout.n].posNext = posThisTx; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
948 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
949 nValueIn += txPrev.vout[prevout.n].nValue; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
950 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
951 if (!MoneyRange(txPrev.vout[prevout.n].nValue) || !MoneyRange(nValueIn)) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
952 return error("ClientConnectInputs() : txin values out of range"); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
953 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
954 if (GetValueOut() > nValueIn) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
955 return false; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
956 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
957 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
958 return true; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
959 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
960 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
961 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
962 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
963 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
964 bool CBlock::DisconnectBlock(CTxDB& txdb, CBlockIndex* pindex) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
965 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
966 // Disconnect in reverse order |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
967 for (int i = vtx.size()-1; i >= 0; i--) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
968 if (!vtx[i].DisconnectInputs(txdb)) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
969 return false; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
970 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
971 // Update block index on disk without changing it in memory. |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
972 // The memory index structure will be changed after the db commits. |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
973 if (pindex->pprev) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
974 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
975 CDiskBlockIndex blockindexPrev(pindex->pprev); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
976 blockindexPrev.hashNext = 0; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
977 if (!txdb.WriteBlockIndex(blockindexPrev)) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
978 return error("DisconnectBlock() : WriteBlockIndex failed"); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
979 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
980 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
981 return true; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
982 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
983 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
984 bool CBlock::ConnectBlock(CTxDB& txdb, CBlockIndex* pindex) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
985 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
986 // Check it again in case a previous version let a bad block in |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
987 if (!CheckBlock()) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
988 return false; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
989 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
990 //// issue here: it doesn't know the version |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
991 unsigned int nTxPos = pindex->nBlockPos + ::GetSerializeSize(CBlock(), SER_DISK) - 1 + GetSizeOfCompactSize(vtx.size()); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
992 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
993 map<uint256, CTxIndex> mapUnused; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
994 int64 nFees = 0; |
595
e630bbb11629
make bitcoin include files more modular
Wladimir J. van der Laan <laanwj@gmail.com>
parents:
588
diff
changeset
|
995 BOOST_FOREACH(CTransaction& tx, vtx) |
575
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
996 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
997 CDiskTxPos posThisTx(pindex->nFile, pindex->nBlockPos, nTxPos); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
998 nTxPos += ::GetSerializeSize(tx, SER_DISK); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
999 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1000 if (!tx.ConnectInputs(txdb, mapUnused, posThisTx, pindex, nFees, true, false)) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1001 return false; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1002 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1003 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1004 if (vtx[0].GetValueOut() > GetBlockValue(pindex->nHeight, nFees)) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1005 return false; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1006 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1007 // Update block index on disk without changing it in memory. |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1008 // The memory index structure will be changed after the db commits. |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1009 if (pindex->pprev) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1010 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1011 CDiskBlockIndex blockindexPrev(pindex->pprev); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1012 blockindexPrev.hashNext = pindex->GetBlockHash(); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1013 if (!txdb.WriteBlockIndex(blockindexPrev)) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1014 return error("ConnectBlock() : WriteBlockIndex failed"); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1015 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1016 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1017 // Watch for transactions paying to me |
595
e630bbb11629
make bitcoin include files more modular
Wladimir J. van der Laan <laanwj@gmail.com>
parents:
588
diff
changeset
|
1018 BOOST_FOREACH(CTransaction& tx, vtx) |
690 | 1019 SyncWithWallets(tx, this, true); |
575
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1020 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1021 return true; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1022 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1023 |
690 | 1024 bool static Reorganize(CTxDB& txdb, CBlockIndex* pindexNew) |
575
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1025 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1026 printf("REORGANIZE\n"); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1027 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1028 // Find the fork |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1029 CBlockIndex* pfork = pindexBest; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1030 CBlockIndex* plonger = pindexNew; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1031 while (pfork != plonger) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1032 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1033 while (plonger->nHeight > pfork->nHeight) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1034 if (!(plonger = plonger->pprev)) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1035 return error("Reorganize() : plonger->pprev is null"); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1036 if (pfork == plonger) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1037 break; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1038 if (!(pfork = pfork->pprev)) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1039 return error("Reorganize() : pfork->pprev is null"); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1040 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1041 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1042 // List of what to disconnect |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1043 vector<CBlockIndex*> vDisconnect; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1044 for (CBlockIndex* pindex = pindexBest; pindex != pfork; pindex = pindex->pprev) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1045 vDisconnect.push_back(pindex); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1046 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1047 // List of what to connect |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1048 vector<CBlockIndex*> vConnect; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1049 for (CBlockIndex* pindex = pindexNew; pindex != pfork; pindex = pindex->pprev) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1050 vConnect.push_back(pindex); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1051 reverse(vConnect.begin(), vConnect.end()); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1052 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1053 // Disconnect shorter branch |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1054 vector<CTransaction> vResurrect; |
595
e630bbb11629
make bitcoin include files more modular
Wladimir J. van der Laan <laanwj@gmail.com>
parents:
588
diff
changeset
|
1055 BOOST_FOREACH(CBlockIndex* pindex, vDisconnect) |
575
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1056 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1057 CBlock block; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1058 if (!block.ReadFromDisk(pindex)) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1059 return error("Reorganize() : ReadFromDisk for disconnect failed"); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1060 if (!block.DisconnectBlock(txdb, pindex)) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1061 return error("Reorganize() : DisconnectBlock failed"); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1062 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1063 // Queue memory transactions to resurrect |
595
e630bbb11629
make bitcoin include files more modular
Wladimir J. van der Laan <laanwj@gmail.com>
parents:
588
diff
changeset
|
1064 BOOST_FOREACH(const CTransaction& tx, block.vtx) |
575
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1065 if (!tx.IsCoinBase()) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1066 vResurrect.push_back(tx); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1067 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1068 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1069 // Connect longer branch |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1070 vector<CTransaction> vDelete; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1071 for (int i = 0; i < vConnect.size(); i++) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1072 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1073 CBlockIndex* pindex = vConnect[i]; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1074 CBlock block; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1075 if (!block.ReadFromDisk(pindex)) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1076 return error("Reorganize() : ReadFromDisk for connect failed"); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1077 if (!block.ConnectBlock(txdb, pindex)) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1078 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1079 // Invalid block |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1080 txdb.TxnAbort(); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1081 return error("Reorganize() : ConnectBlock failed"); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1082 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1083 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1084 // Queue memory transactions to delete |
595
e630bbb11629
make bitcoin include files more modular
Wladimir J. van der Laan <laanwj@gmail.com>
parents:
588
diff
changeset
|
1085 BOOST_FOREACH(const CTransaction& tx, block.vtx) |
575
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1086 vDelete.push_back(tx); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1087 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1088 if (!txdb.WriteHashBestChain(pindexNew->GetBlockHash())) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1089 return error("Reorganize() : WriteHashBestChain failed"); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1090 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1091 // Make sure it's successfully written to disk before changing memory structure |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1092 if (!txdb.TxnCommit()) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1093 return error("Reorganize() : TxnCommit failed"); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1094 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1095 // Disconnect shorter branch |
595
e630bbb11629
make bitcoin include files more modular
Wladimir J. van der Laan <laanwj@gmail.com>
parents:
588
diff
changeset
|
1096 BOOST_FOREACH(CBlockIndex* pindex, vDisconnect) |
575
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1097 if (pindex->pprev) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1098 pindex->pprev->pnext = NULL; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1099 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1100 // Connect longer branch |
595
e630bbb11629
make bitcoin include files more modular
Wladimir J. van der Laan <laanwj@gmail.com>
parents:
588
diff
changeset
|
1101 BOOST_FOREACH(CBlockIndex* pindex, vConnect) |
575
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1102 if (pindex->pprev) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1103 pindex->pprev->pnext = pindex; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1104 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1105 // Resurrect memory transactions that were in the disconnected branch |
595
e630bbb11629
make bitcoin include files more modular
Wladimir J. van der Laan <laanwj@gmail.com>
parents:
588
diff
changeset
|
1106 BOOST_FOREACH(CTransaction& tx, vResurrect) |
575
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1107 tx.AcceptToMemoryPool(txdb, false); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1108 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1109 // Delete redundant memory transactions that are in the connected branch |
595
e630bbb11629
make bitcoin include files more modular
Wladimir J. van der Laan <laanwj@gmail.com>
parents:
588
diff
changeset
|
1110 BOOST_FOREACH(CTransaction& tx, vDelete) |
575
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1111 tx.RemoveFromMemoryPool(); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1112 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1113 return true; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1114 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1115 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1116 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1117 bool CBlock::SetBestChain(CTxDB& txdb, CBlockIndex* pindexNew) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1118 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1119 uint256 hash = GetHash(); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1120 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1121 txdb.TxnBegin(); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1122 if (pindexGenesisBlock == NULL && hash == hashGenesisBlock) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1123 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1124 txdb.WriteHashBestChain(hash); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1125 if (!txdb.TxnCommit()) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1126 return error("SetBestChain() : TxnCommit failed"); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1127 pindexGenesisBlock = pindexNew; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1128 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1129 else if (hashPrevBlock == hashBestChain) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1130 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1131 // Adding to current best branch |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1132 if (!ConnectBlock(txdb, pindexNew) || !txdb.WriteHashBestChain(hash)) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1133 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1134 txdb.TxnAbort(); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1135 InvalidChainFound(pindexNew); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1136 return error("SetBestChain() : ConnectBlock failed"); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1137 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1138 if (!txdb.TxnCommit()) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1139 return error("SetBestChain() : TxnCommit failed"); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1140 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1141 // Add to current best branch |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1142 pindexNew->pprev->pnext = pindexNew; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1143 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1144 // Delete redundant memory transactions |
595
e630bbb11629
make bitcoin include files more modular
Wladimir J. van der Laan <laanwj@gmail.com>
parents:
588
diff
changeset
|
1145 BOOST_FOREACH(CTransaction& tx, vtx) |
575
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1146 tx.RemoveFromMemoryPool(); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1147 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1148 else |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1149 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1150 // New best branch |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1151 if (!Reorganize(txdb, pindexNew)) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1152 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1153 txdb.TxnAbort(); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1154 InvalidChainFound(pindexNew); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1155 return error("SetBestChain() : Reorganize failed"); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1156 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1157 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1158 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1159 // Update best block in wallet (so we can detect restored wallets) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1160 if (!IsInitialBlockDownload()) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1161 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1162 const CBlockLocator locator(pindexNew); |
690 | 1163 ::SetBestChain(locator); |
575
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1164 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1165 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1166 // New best block |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1167 hashBestChain = hash; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1168 pindexBest = pindexNew; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1169 nBestHeight = pindexBest->nHeight; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1170 bnBestChainWork = pindexNew->bnChainWork; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1171 nTimeBestReceived = GetTime(); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1172 nTransactionsUpdated++; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1173 printf("SetBestChain: new best=%s height=%d work=%s\n", hashBestChain.ToString().substr(0,20).c_str(), nBestHeight, bnBestChainWork.ToString().c_str()); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1174 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1175 return true; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1176 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1177 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1178 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1179 bool CBlock::AddToBlockIndex(unsigned int nFile, unsigned int nBlockPos) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1180 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1181 // Check for duplicate |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1182 uint256 hash = GetHash(); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1183 if (mapBlockIndex.count(hash)) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1184 return error("AddToBlockIndex() : %s already exists", hash.ToString().substr(0,20).c_str()); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1185 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1186 // Construct new block index object |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1187 CBlockIndex* pindexNew = new CBlockIndex(nFile, nBlockPos, *this); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1188 if (!pindexNew) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1189 return error("AddToBlockIndex() : new CBlockIndex failed"); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1190 map<uint256, CBlockIndex*>::iterator mi = mapBlockIndex.insert(make_pair(hash, pindexNew)).first; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1191 pindexNew->phashBlock = &((*mi).first); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1192 map<uint256, CBlockIndex*>::iterator miPrev = mapBlockIndex.find(hashPrevBlock); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1193 if (miPrev != mapBlockIndex.end()) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1194 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1195 pindexNew->pprev = (*miPrev).second; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1196 pindexNew->nHeight = pindexNew->pprev->nHeight + 1; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1197 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1198 pindexNew->bnChainWork = (pindexNew->pprev ? pindexNew->pprev->bnChainWork : 0) + pindexNew->GetBlockWork(); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1199 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1200 CTxDB txdb; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1201 txdb.TxnBegin(); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1202 txdb.WriteBlockIndex(CDiskBlockIndex(pindexNew)); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1203 if (!txdb.TxnCommit()) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1204 return false; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1205 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1206 // New best |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1207 if (pindexNew->bnChainWork > bnBestChainWork) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1208 if (!SetBestChain(txdb, pindexNew)) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1209 return false; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1210 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1211 txdb.Close(); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1212 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1213 if (pindexNew == pindexBest) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1214 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1215 // Notify UI to display prev block's coinbase if it was ours |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1216 static uint256 hashPrevBestCoinBase; |
690 | 1217 UpdatedTransaction(hashPrevBestCoinBase); |
575
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1218 hashPrevBestCoinBase = vtx[0].GetHash(); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1219 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1220 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1221 MainFrameRepaint(); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1222 return true; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1223 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1224 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1225 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1226 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1227 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1228 bool CBlock::CheckBlock() const |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1229 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1230 // These are checks that are independent of context |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1231 // that can be verified before saving an orphan block. |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1232 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1233 // Size limits |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1234 if (vtx.empty() || vtx.size() > MAX_BLOCK_SIZE || ::GetSerializeSize(*this, SER_NETWORK) > MAX_BLOCK_SIZE) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1235 return error("CheckBlock() : size limits failed"); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1236 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1237 // Check proof of work matches claimed amount |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1238 if (!CheckProofOfWork(GetHash(), nBits)) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1239 return error("CheckBlock() : proof of work failed"); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1240 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1241 // Check timestamp |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1242 if (GetBlockTime() > GetAdjustedTime() + 2 * 60 * 60) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1243 return error("CheckBlock() : block timestamp too far in the future"); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1244 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1245 // First transaction must be coinbase, the rest must not be |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1246 if (vtx.empty() || !vtx[0].IsCoinBase()) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1247 return error("CheckBlock() : first tx is not coinbase"); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1248 for (int i = 1; i < vtx.size(); i++) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1249 if (vtx[i].IsCoinBase()) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1250 return error("CheckBlock() : more than one coinbase"); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1251 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1252 // Check transactions |
595
e630bbb11629
make bitcoin include files more modular
Wladimir J. van der Laan <laanwj@gmail.com>
parents:
588
diff
changeset
|
1253 BOOST_FOREACH(const CTransaction& tx, vtx) |
575
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1254 if (!tx.CheckTransaction()) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1255 return error("CheckBlock() : CheckTransaction failed"); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1256 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1257 // Check that it's not full of nonstandard transactions |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1258 if (GetSigOpCount() > MAX_BLOCK_SIGOPS) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1259 return error("CheckBlock() : too many nonstandard transactions"); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1260 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1261 // Check merkleroot |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1262 if (hashMerkleRoot != BuildMerkleTree()) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1263 return error("CheckBlock() : hashMerkleRoot mismatch"); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1264 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1265 return true; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1266 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1267 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1268 bool CBlock::AcceptBlock() |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1269 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1270 // Check for duplicate |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1271 uint256 hash = GetHash(); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1272 if (mapBlockIndex.count(hash)) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1273 return error("AcceptBlock() : block already in mapBlockIndex"); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1274 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1275 // Get prev block index |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1276 map<uint256, CBlockIndex*>::iterator mi = mapBlockIndex.find(hashPrevBlock); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1277 if (mi == mapBlockIndex.end()) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1278 return error("AcceptBlock() : prev block not found"); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1279 CBlockIndex* pindexPrev = (*mi).second; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1280 int nHeight = pindexPrev->nHeight+1; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1281 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1282 // Check proof of work |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1283 if (nBits != GetNextWorkRequired(pindexPrev)) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1284 return error("AcceptBlock() : incorrect proof of work"); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1285 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1286 // Check timestamp against prev |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1287 if (GetBlockTime() <= pindexPrev->GetMedianTimePast()) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1288 return error("AcceptBlock() : block's timestamp is too early"); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1289 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1290 // Check that all transactions are finalized |
595
e630bbb11629
make bitcoin include files more modular
Wladimir J. van der Laan <laanwj@gmail.com>
parents:
588
diff
changeset
|
1291 BOOST_FOREACH(const CTransaction& tx, vtx) |
575
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1292 if (!tx.IsFinal(nHeight, GetBlockTime())) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1293 return error("AcceptBlock() : contains a non-final transaction"); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1294 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1295 // Check that the block chain matches the known block chain up to a checkpoint |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1296 if (!fTestNet) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1297 if ((nHeight == 11111 && hash != uint256("0x0000000069e244f73d78e8fd29ba2fd2ed618bd6fa2ee92559f542fdb26e7c1d")) || |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1298 (nHeight == 33333 && hash != uint256("0x000000002dd5588a74784eaa7ab0507a18ad16a236e7b1ce69f00d7ddfb5d0a6")) || |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1299 (nHeight == 68555 && hash != uint256("0x00000000001e1b4903550a0b96e9a9405c8a95f387162e4944e8d9fbe501cd6a")) || |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1300 (nHeight == 70567 && hash != uint256("0x00000000006a49b14bcf27462068f1264c961f11fa2e0eddd2be0791e1d4124a")) || |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1301 (nHeight == 74000 && hash != uint256("0x0000000000573993a3c9e41ce34471c079dcf5f52a0e824a81e7f953b8661a20")) || |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1302 (nHeight == 105000 && hash != uint256("0x00000000000291ce28027faea320c8d2b054b2e0fe44a773f3eefb151d6bdc97")) || |
738
7d6b511630d6
Block-chain lock-in at 134444
Gavin Andresen <gavinandresen@gmail.com>
parents:
718
diff
changeset
|
1303 (nHeight == 118000 && hash != uint256("0x000000000000774a7f8a7a12dc906ddb9e17e75d684f15e00f8767f9e8f36553")) || |
7d6b511630d6
Block-chain lock-in at 134444
Gavin Andresen <gavinandresen@gmail.com>
parents:
718
diff
changeset
|
1304 (nHeight == 134444 && hash != uint256("0x00000000000005b12ffd4cd315cd34ffd4a594f430ac814c91184a0d42d2b0fe"))) |
575
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1305 return error("AcceptBlock() : rejected by checkpoint lockin at %d", nHeight); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1306 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1307 // Write block to history file |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1308 if (!CheckDiskSpace(::GetSerializeSize(*this, SER_DISK))) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1309 return error("AcceptBlock() : out of disk space"); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1310 unsigned int nFile = -1; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1311 unsigned int nBlockPos = 0; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1312 if (!WriteToDisk(nFile, nBlockPos)) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1313 return error("AcceptBlock() : WriteToDisk failed"); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1314 if (!AddToBlockIndex(nFile, nBlockPos)) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1315 return error("AcceptBlock() : AddToBlockIndex failed"); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1316 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1317 // Relay inventory, but don't relay old inventory during initial block download |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1318 if (hashBestChain == hash) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1319 CRITICAL_BLOCK(cs_vNodes) |
595
e630bbb11629
make bitcoin include files more modular
Wladimir J. van der Laan <laanwj@gmail.com>
parents:
588
diff
changeset
|
1320 BOOST_FOREACH(CNode* pnode, vNodes) |
738
7d6b511630d6
Block-chain lock-in at 134444
Gavin Andresen <gavinandresen@gmail.com>
parents:
718
diff
changeset
|
1321 if (nBestHeight > (pnode->nStartingHeight != -1 ? pnode->nStartingHeight - 2000 : 134444)) |
575
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1322 pnode->PushInventory(CInv(MSG_BLOCK, hash)); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1323 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1324 return true; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1325 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1326 |
690 | 1327 bool static ProcessBlock(CNode* pfrom, CBlock* pblock) |
575
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1328 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1329 // Check for duplicate |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1330 uint256 hash = pblock->GetHash(); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1331 if (mapBlockIndex.count(hash)) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1332 return error("ProcessBlock() : already have block %d %s", mapBlockIndex[hash]->nHeight, hash.ToString().substr(0,20).c_str()); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1333 if (mapOrphanBlocks.count(hash)) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1334 return error("ProcessBlock() : already have block (orphan) %s", hash.ToString().substr(0,20).c_str()); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1335 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1336 // Preliminary checks |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1337 if (!pblock->CheckBlock()) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1338 return error("ProcessBlock() : CheckBlock FAILED"); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1339 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1340 // If don't already have its previous block, shunt it off to holding area until we get it |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1341 if (!mapBlockIndex.count(pblock->hashPrevBlock)) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1342 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1343 printf("ProcessBlock: ORPHAN BLOCK, prev=%s\n", pblock->hashPrevBlock.ToString().substr(0,20).c_str()); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1344 CBlock* pblock2 = new CBlock(*pblock); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1345 mapOrphanBlocks.insert(make_pair(hash, pblock2)); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1346 mapOrphanBlocksByPrev.insert(make_pair(pblock2->hashPrevBlock, pblock2)); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1347 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1348 // Ask this guy to fill in what we're missing |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1349 if (pfrom) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1350 pfrom->PushGetBlocks(pindexBest, GetOrphanRoot(pblock2)); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1351 return true; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1352 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1353 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1354 // Store to disk |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1355 if (!pblock->AcceptBlock()) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1356 return error("ProcessBlock() : AcceptBlock FAILED"); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1357 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1358 // Recursively process any orphan blocks that depended on this one |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1359 vector<uint256> vWorkQueue; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1360 vWorkQueue.push_back(hash); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1361 for (int i = 0; i < vWorkQueue.size(); i++) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1362 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1363 uint256 hashPrev = vWorkQueue[i]; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1364 for (multimap<uint256, CBlock*>::iterator mi = mapOrphanBlocksByPrev.lower_bound(hashPrev); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1365 mi != mapOrphanBlocksByPrev.upper_bound(hashPrev); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1366 ++mi) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1367 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1368 CBlock* pblockOrphan = (*mi).second; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1369 if (pblockOrphan->AcceptBlock()) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1370 vWorkQueue.push_back(pblockOrphan->GetHash()); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1371 mapOrphanBlocks.erase(pblockOrphan->GetHash()); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1372 delete pblockOrphan; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1373 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1374 mapOrphanBlocksByPrev.erase(hashPrev); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1375 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1376 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1377 printf("ProcessBlock: ACCEPTED\n"); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1378 return true; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1379 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1380 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1381 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1382 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1383 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1384 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1385 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1386 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1387 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1388 bool CheckDiskSpace(uint64 nAdditionalBytes) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1389 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1390 uint64 nFreeBytesAvailable = filesystem::space(GetDataDir()).available; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1391 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1392 // Check for 15MB because database could create another 10MB log file at any time |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1393 if (nFreeBytesAvailable < (uint64)15000000 + nAdditionalBytes) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1394 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1395 fShutdown = true; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1396 string strMessage = _("Warning: Disk space is low "); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1397 strMiscWarning = strMessage; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1398 printf("*** %s\n", strMessage.c_str()); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1399 ThreadSafeMessageBox(strMessage, "Bitcoin", wxOK | wxICON_EXCLAMATION); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1400 CreateThread(Shutdown, NULL); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1401 return false; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1402 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1403 return true; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1404 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1405 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1406 FILE* OpenBlockFile(unsigned int nFile, unsigned int nBlockPos, const char* pszMode) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1407 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1408 if (nFile == -1) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1409 return NULL; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1410 FILE* file = fopen(strprintf("%s/blk%04d.dat", GetDataDir().c_str(), nFile).c_str(), pszMode); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1411 if (!file) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1412 return NULL; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1413 if (nBlockPos != 0 && !strchr(pszMode, 'a') && !strchr(pszMode, 'w')) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1414 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1415 if (fseek(file, nBlockPos, SEEK_SET) != 0) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1416 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1417 fclose(file); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1418 return NULL; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1419 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1420 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1421 return file; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1422 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1423 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1424 static unsigned int nCurrentBlockFile = 1; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1425 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1426 FILE* AppendBlockFile(unsigned int& nFileRet) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1427 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1428 nFileRet = 0; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1429 loop |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1430 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1431 FILE* file = OpenBlockFile(nCurrentBlockFile, 0, "ab"); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1432 if (!file) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1433 return NULL; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1434 if (fseek(file, 0, SEEK_END) != 0) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1435 return NULL; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1436 // FAT32 filesize max 4GB, fseek and ftell max 2GB, so we must stay under 2GB |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1437 if (ftell(file) < 0x7F000000 - MAX_SIZE) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1438 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1439 nFileRet = nCurrentBlockFile; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1440 return file; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1441 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1442 fclose(file); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1443 nCurrentBlockFile++; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1444 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1445 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1446 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1447 bool LoadBlockIndex(bool fAllowNew) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1448 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1449 if (fTestNet) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1450 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1451 hashGenesisBlock = uint256("0x00000007199508e34a9ff81e6ec0c477a4cccff2a4767a8eee39c11db367b008"); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1452 bnProofOfWorkLimit = CBigNum(~uint256(0) >> 28); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1453 pchMessageStart[0] = 0xfa; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1454 pchMessageStart[1] = 0xbf; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1455 pchMessageStart[2] = 0xb5; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1456 pchMessageStart[3] = 0xda; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1457 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1458 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1459 // |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1460 // Load block index |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1461 // |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1462 CTxDB txdb("cr"); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1463 if (!txdb.LoadBlockIndex()) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1464 return false; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1465 txdb.Close(); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1466 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1467 // |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1468 // Init with genesis block |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1469 // |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1470 if (mapBlockIndex.empty()) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1471 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1472 if (!fAllowNew) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1473 return false; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1474 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1475 // Genesis Block: |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1476 // CBlock(hash=000000000019d6, ver=1, hashPrevBlock=00000000000000, hashMerkleRoot=4a5e1e, nTime=1231006505, nBits=1d00ffff, nNonce=2083236893, vtx=1) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1477 // CTransaction(hash=4a5e1e, ver=1, vin.size=1, vout.size=1, nLockTime=0) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1478 // CTxIn(COutPoint(000000, -1), coinbase 04ffff001d0104455468652054696d65732030332f4a616e2f32303039204368616e63656c6c6f72206f6e206272696e6b206f66207365636f6e64206261696c6f757420666f722062616e6b73) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1479 // CTxOut(nValue=50.00000000, scriptPubKey=0x5F1DF16B2B704C8A578D0B) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1480 // vMerkleTree: 4a5e1e |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1481 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1482 // Genesis block |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1483 const char* pszTimestamp = "The Times 03/Jan/2009 Chancellor on brink of second bailout for banks"; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1484 CTransaction txNew; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1485 txNew.vin.resize(1); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1486 txNew.vout.resize(1); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1487 txNew.vin[0].scriptSig = CScript() << 486604799 << CBigNum(4) << vector<unsigned char>((const unsigned char*)pszTimestamp, (const unsigned char*)pszTimestamp + strlen(pszTimestamp)); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1488 txNew.vout[0].nValue = 50 * COIN; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1489 txNew.vout[0].scriptPubKey = CScript() << ParseHex("04678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38c4f35504e51ec112de5c384df7ba0b8d578a4c702b6bf11d5f") << OP_CHECKSIG; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1490 CBlock block; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1491 block.vtx.push_back(txNew); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1492 block.hashPrevBlock = 0; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1493 block.hashMerkleRoot = block.BuildMerkleTree(); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1494 block.nVersion = 1; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1495 block.nTime = 1231006505; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1496 block.nBits = 0x1d00ffff; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1497 block.nNonce = 2083236893; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1498 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1499 if (fTestNet) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1500 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1501 block.nTime = 1296688602; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1502 block.nBits = 0x1d07fff8; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1503 block.nNonce = 384568319; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1504 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1505 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1506 //// debug print |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1507 printf("%s\n", block.GetHash().ToString().c_str()); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1508 printf("%s\n", hashGenesisBlock.ToString().c_str()); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1509 printf("%s\n", block.hashMerkleRoot.ToString().c_str()); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1510 assert(block.hashMerkleRoot == uint256("0x4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b")); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1511 block.print(); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1512 assert(block.GetHash() == hashGenesisBlock); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1513 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1514 // Start new block file |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1515 unsigned int nFile; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1516 unsigned int nBlockPos; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1517 if (!block.WriteToDisk(nFile, nBlockPos)) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1518 return error("LoadBlockIndex() : writing genesis block to disk failed"); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1519 if (!block.AddToBlockIndex(nFile, nBlockPos)) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1520 return error("LoadBlockIndex() : genesis block not accepted"); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1521 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1522 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1523 return true; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1524 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1525 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1526 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1527 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1528 void PrintBlockTree() |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1529 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1530 // precompute tree structure |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1531 map<CBlockIndex*, vector<CBlockIndex*> > mapNext; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1532 for (map<uint256, CBlockIndex*>::iterator mi = mapBlockIndex.begin(); mi != mapBlockIndex.end(); ++mi) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1533 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1534 CBlockIndex* pindex = (*mi).second; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1535 mapNext[pindex->pprev].push_back(pindex); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1536 // test |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1537 //while (rand() % 3 == 0) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1538 // mapNext[pindex->pprev].push_back(pindex); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1539 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1540 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1541 vector<pair<int, CBlockIndex*> > vStack; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1542 vStack.push_back(make_pair(0, pindexGenesisBlock)); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1543 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1544 int nPrevCol = 0; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1545 while (!vStack.empty()) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1546 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1547 int nCol = vStack.back().first; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1548 CBlockIndex* pindex = vStack.back().second; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1549 vStack.pop_back(); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1550 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1551 // print split or gap |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1552 if (nCol > nPrevCol) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1553 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1554 for (int i = 0; i < nCol-1; i++) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1555 printf("| "); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1556 printf("|\\\n"); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1557 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1558 else if (nCol < nPrevCol) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1559 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1560 for (int i = 0; i < nCol; i++) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1561 printf("| "); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1562 printf("|\n"); |
690 | 1563 } |
575
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1564 nPrevCol = nCol; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1565 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1566 // print columns |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1567 for (int i = 0; i < nCol; i++) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1568 printf("| "); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1569 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1570 // print item |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1571 CBlock block; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1572 block.ReadFromDisk(pindex); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1573 printf("%d (%u,%u) %s %s tx %d", |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1574 pindex->nHeight, |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1575 pindex->nFile, |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1576 pindex->nBlockPos, |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1577 block.GetHash().ToString().substr(0,20).c_str(), |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1578 DateTimeStrFormat("%x %H:%M:%S", block.GetBlockTime()).c_str(), |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1579 block.vtx.size()); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1580 |
690 | 1581 PrintWallets(block); |
575
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1582 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1583 // put the main timechain first |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1584 vector<CBlockIndex*>& vNext = mapNext[pindex]; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1585 for (int i = 0; i < vNext.size(); i++) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1586 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1587 if (vNext[i]->pnext) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1588 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1589 swap(vNext[0], vNext[i]); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1590 break; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1591 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1592 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1593 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1594 // iterate children |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1595 for (int i = 0; i < vNext.size(); i++) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1596 vStack.push_back(make_pair(nCol+i, vNext[i])); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1597 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1598 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1599 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1600 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1601 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1602 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1603 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1604 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1605 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1606 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1607 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1608 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1609 ////////////////////////////////////////////////////////////////////////////// |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1610 // |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1611 // CAlert |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1612 // |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1613 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1614 map<uint256, CAlert> mapAlerts; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1615 CCriticalSection cs_mapAlerts; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1616 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1617 string GetWarnings(string strFor) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1618 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1619 int nPriority = 0; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1620 string strStatusBar; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1621 string strRPC; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1622 if (GetBoolArg("-testsafemode")) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1623 strRPC = "test"; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1624 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1625 // Misc warnings like out of disk space and clock is wrong |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1626 if (strMiscWarning != "") |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1627 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1628 nPriority = 1000; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1629 strStatusBar = strMiscWarning; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1630 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1631 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1632 // Longer invalid proof-of-work chain |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1633 if (pindexBest && bnBestInvalidWork > bnBestChainWork + pindexBest->GetBlockWork() * 6) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1634 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1635 nPriority = 2000; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1636 strStatusBar = strRPC = "WARNING: Displayed transactions may not be correct! You may need to upgrade, or other nodes may need to upgrade."; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1637 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1638 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1639 // Alerts |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1640 CRITICAL_BLOCK(cs_mapAlerts) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1641 { |
595
e630bbb11629
make bitcoin include files more modular
Wladimir J. van der Laan <laanwj@gmail.com>
parents:
588
diff
changeset
|
1642 BOOST_FOREACH(PAIRTYPE(const uint256, CAlert)& item, mapAlerts) |
575
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1643 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1644 const CAlert& alert = item.second; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1645 if (alert.AppliesToMe() && alert.nPriority > nPriority) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1646 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1647 nPriority = alert.nPriority; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1648 strStatusBar = alert.strStatusBar; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1649 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1650 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1651 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1652 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1653 if (strFor == "statusbar") |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1654 return strStatusBar; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1655 else if (strFor == "rpc") |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1656 return strRPC; |
776
f64d738664f8
fix warnings: expression result unused [-Wunused-value]
Giel van Schijndel <me@mortis.eu>
parents:
768
diff
changeset
|
1657 assert(!"GetWarnings() : invalid parameter"); |
575
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1658 return "error"; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1659 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1660 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1661 bool CAlert::ProcessAlert() |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1662 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1663 if (!CheckSignature()) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1664 return false; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1665 if (!IsInEffect()) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1666 return false; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1667 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1668 CRITICAL_BLOCK(cs_mapAlerts) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1669 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1670 // Cancel previous alerts |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1671 for (map<uint256, CAlert>::iterator mi = mapAlerts.begin(); mi != mapAlerts.end();) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1672 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1673 const CAlert& alert = (*mi).second; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1674 if (Cancels(alert)) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1675 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1676 printf("cancelling alert %d\n", alert.nID); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1677 mapAlerts.erase(mi++); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1678 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1679 else if (!alert.IsInEffect()) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1680 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1681 printf("expiring alert %d\n", alert.nID); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1682 mapAlerts.erase(mi++); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1683 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1684 else |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1685 mi++; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1686 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1687 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1688 // Check if this alert has been cancelled |
595
e630bbb11629
make bitcoin include files more modular
Wladimir J. van der Laan <laanwj@gmail.com>
parents:
588
diff
changeset
|
1689 BOOST_FOREACH(PAIRTYPE(const uint256, CAlert)& item, mapAlerts) |
575
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1690 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1691 const CAlert& alert = item.second; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1692 if (alert.Cancels(*this)) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1693 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1694 printf("alert already cancelled by %d\n", alert.nID); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1695 return false; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1696 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1697 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1698 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1699 // Add to mapAlerts |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1700 mapAlerts.insert(make_pair(GetHash(), *this)); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1701 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1702 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1703 printf("accepted alert %d, AppliesToMe()=%d\n", nID, AppliesToMe()); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1704 MainFrameRepaint(); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1705 return true; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1706 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1707 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1708 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1709 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1710 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1711 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1712 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1713 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1714 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1715 ////////////////////////////////////////////////////////////////////////////// |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1716 // |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1717 // Messages |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1718 // |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1719 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1720 |
690 | 1721 bool static AlreadyHave(CTxDB& txdb, const CInv& inv) |
575
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1722 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1723 switch (inv.type) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1724 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1725 case MSG_TX: return mapTransactions.count(inv.hash) || mapOrphanTransactions.count(inv.hash) || txdb.ContainsTx(inv.hash); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1726 case MSG_BLOCK: return mapBlockIndex.count(inv.hash) || mapOrphanBlocks.count(inv.hash); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1727 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1728 // Don't know what it is, just say we already got one |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1729 return true; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1730 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1731 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1732 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1733 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1734 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1735 // The message start string is designed to be unlikely to occur in normal data. |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1736 // The characters are rarely used upper ascii, not valid as UTF-8, and produce |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1737 // a large 4-byte int at any alignment. |
848
991dade03d33
Use 'unsigned char' rather than 'char' for pchMessageStart.
Venkatesh Srinivas <me@endeavour.zapto.org>
parents:
824
diff
changeset
|
1738 unsigned char pchMessageStart[4] = { 0xf9, 0xbe, 0xb4, 0xd9 }; |
575
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1739 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1740 |
690 | 1741 bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv) |
575
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1742 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1743 static map<unsigned int, vector<unsigned char> > mapReuseKey; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1744 RandAddSeedPerfmon(); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1745 if (fDebug) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1746 printf("%s ", DateTimeStrFormat("%x %H:%M:%S", GetTime()).c_str()); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1747 printf("received: %s (%d bytes)\n", strCommand.c_str(), vRecv.size()); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1748 if (mapArgs.count("-dropmessagestest") && GetRand(atoi(mapArgs["-dropmessagestest"])) == 0) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1749 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1750 printf("dropmessagestest DROPPING RECV MESSAGE\n"); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1751 return true; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1752 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1753 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1754 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1755 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1756 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1757 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1758 if (strCommand == "version") |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1759 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1760 // Each connection can only send one version message |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1761 if (pfrom->nVersion != 0) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1762 return false; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1763 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1764 int64 nTime; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1765 CAddress addrMe; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1766 CAddress addrFrom; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1767 uint64 nNonce = 1; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1768 vRecv >> pfrom->nVersion >> pfrom->nServices >> nTime >> addrMe; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1769 if (pfrom->nVersion == 10300) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1770 pfrom->nVersion = 300; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1771 if (pfrom->nVersion >= 106 && !vRecv.empty()) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1772 vRecv >> addrFrom >> nNonce; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1773 if (pfrom->nVersion >= 106 && !vRecv.empty()) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1774 vRecv >> pfrom->strSubVer; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1775 if (pfrom->nVersion >= 209 && !vRecv.empty()) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1776 vRecv >> pfrom->nStartingHeight; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1777 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1778 if (pfrom->nVersion == 0) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1779 return false; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1780 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1781 // Disconnect if we connected to ourself |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1782 if (nNonce == nLocalHostNonce && nNonce > 1) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1783 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1784 printf("connected to self at %s, disconnecting\n", pfrom->addr.ToString().c_str()); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1785 pfrom->fDisconnect = true; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1786 return true; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1787 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1788 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1789 // Be shy and don't send version until we hear |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1790 if (pfrom->fInbound) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1791 pfrom->PushVersion(); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1792 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1793 pfrom->fClient = !(pfrom->nServices & NODE_NETWORK); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1794 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1795 AddTimeData(pfrom->addr.ip, nTime); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1796 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1797 // Change version |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1798 if (pfrom->nVersion >= 209) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1799 pfrom->PushMessage("verack"); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1800 pfrom->vSend.SetVersion(min(pfrom->nVersion, VERSION)); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1801 if (pfrom->nVersion < 209) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1802 pfrom->vRecv.SetVersion(min(pfrom->nVersion, VERSION)); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1803 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1804 if (!pfrom->fInbound) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1805 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1806 // Advertise our address |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1807 if (addrLocalHost.IsRoutable() && !fUseProxy) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1808 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1809 CAddress addr(addrLocalHost); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1810 addr.nTime = GetAdjustedTime(); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1811 pfrom->PushAddress(addr); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1812 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1813 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1814 // Get recent addresses |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1815 if (pfrom->nVersion >= 31402 || mapAddresses.size() < 1000) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1816 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1817 pfrom->PushMessage("getaddr"); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1818 pfrom->fGetAddr = true; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1819 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1820 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1821 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1822 // Ask the first connected node for block updates |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1823 static int nAskedForBlocks; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1824 if (!pfrom->fClient && (nAskedForBlocks < 1 || vNodes.size() <= 1)) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1825 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1826 nAskedForBlocks++; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1827 pfrom->PushGetBlocks(pindexBest, uint256(0)); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1828 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1829 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1830 // Relay alerts |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1831 CRITICAL_BLOCK(cs_mapAlerts) |
595
e630bbb11629
make bitcoin include files more modular
Wladimir J. van der Laan <laanwj@gmail.com>
parents:
588
diff
changeset
|
1832 BOOST_FOREACH(PAIRTYPE(const uint256, CAlert)& item, mapAlerts) |
575
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1833 item.second.RelayTo(pfrom); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1834 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1835 pfrom->fSuccessfullyConnected = true; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1836 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1837 printf("version message: version %d, blocks=%d\n", pfrom->nVersion, pfrom->nStartingHeight); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1838 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1839 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1840 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1841 else if (pfrom->nVersion == 0) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1842 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1843 // Must have a version message before anything else |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1844 return false; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1845 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1846 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1847 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1848 else if (strCommand == "verack") |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1849 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1850 pfrom->vRecv.SetVersion(min(pfrom->nVersion, VERSION)); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1851 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1852 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1853 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1854 else if (strCommand == "addr") |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1855 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1856 vector<CAddress> vAddr; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1857 vRecv >> vAddr; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1858 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1859 // Don't want addr from older versions unless seeding |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1860 if (pfrom->nVersion < 209) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1861 return true; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1862 if (pfrom->nVersion < 31402 && mapAddresses.size() > 1000) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1863 return true; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1864 if (vAddr.size() > 1000) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1865 return error("message addr size() = %d", vAddr.size()); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1866 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1867 // Store the new addresses |
796
361ab4abafbb
Single DB transaction for all addresses in a message
Patrick Varilly <patvarilly@gmail.com>
parents:
776
diff
changeset
|
1868 CAddrDB addrDB; |
361ab4abafbb
Single DB transaction for all addresses in a message
Patrick Varilly <patvarilly@gmail.com>
parents:
776
diff
changeset
|
1869 addrDB.TxnBegin(); |
575
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1870 int64 nNow = GetAdjustedTime(); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1871 int64 nSince = nNow - 10 * 60; |
595
e630bbb11629
make bitcoin include files more modular
Wladimir J. van der Laan <laanwj@gmail.com>
parents:
588
diff
changeset
|
1872 BOOST_FOREACH(CAddress& addr, vAddr) |
575
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1873 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1874 if (fShutdown) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1875 return true; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1876 // ignore IPv6 for now, since it isn't implemented anyway |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1877 if (!addr.IsIPv4()) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1878 continue; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1879 if (addr.nTime <= 100000000 || addr.nTime > nNow + 10 * 60) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1880 addr.nTime = nNow - 5 * 24 * 60 * 60; |
796
361ab4abafbb
Single DB transaction for all addresses in a message
Patrick Varilly <patvarilly@gmail.com>
parents:
776
diff
changeset
|
1881 AddAddress(addr, 2 * 60 * 60, &addrDB); |
575
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1882 pfrom->AddAddressKnown(addr); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1883 if (addr.nTime > nSince && !pfrom->fGetAddr && vAddr.size() <= 10 && addr.IsRoutable()) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1884 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1885 // Relay to a limited number of other nodes |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1886 CRITICAL_BLOCK(cs_vNodes) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1887 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1888 // Use deterministic randomness to send to the same nodes for 24 hours |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1889 // at a time so the setAddrKnowns of the chosen nodes prevent repeats |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1890 static uint256 hashSalt; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1891 if (hashSalt == 0) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1892 RAND_bytes((unsigned char*)&hashSalt, sizeof(hashSalt)); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1893 uint256 hashRand = hashSalt ^ (((int64)addr.ip)<<32) ^ ((GetTime()+addr.ip)/(24*60*60)); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1894 hashRand = Hash(BEGIN(hashRand), END(hashRand)); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1895 multimap<uint256, CNode*> mapMix; |
595
e630bbb11629
make bitcoin include files more modular
Wladimir J. van der Laan <laanwj@gmail.com>
parents:
588
diff
changeset
|
1896 BOOST_FOREACH(CNode* pnode, vNodes) |
575
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1897 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1898 if (pnode->nVersion < 31402) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1899 continue; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1900 unsigned int nPointer; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1901 memcpy(&nPointer, &pnode, sizeof(nPointer)); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1902 uint256 hashKey = hashRand ^ nPointer; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1903 hashKey = Hash(BEGIN(hashKey), END(hashKey)); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1904 mapMix.insert(make_pair(hashKey, pnode)); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1905 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1906 int nRelayNodes = 2; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1907 for (multimap<uint256, CNode*>::iterator mi = mapMix.begin(); mi != mapMix.end() && nRelayNodes-- > 0; ++mi) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1908 ((*mi).second)->PushAddress(addr); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1909 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1910 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1911 } |
796
361ab4abafbb
Single DB transaction for all addresses in a message
Patrick Varilly <patvarilly@gmail.com>
parents:
776
diff
changeset
|
1912 addrDB.TxnCommit(); // Save addresses (it's ok if this fails) |
575
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1913 if (vAddr.size() < 1000) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1914 pfrom->fGetAddr = false; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1915 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1916 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1917 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1918 else if (strCommand == "inv") |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1919 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1920 vector<CInv> vInv; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1921 vRecv >> vInv; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1922 if (vInv.size() > 50000) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1923 return error("message inv size() = %d", vInv.size()); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1924 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1925 CTxDB txdb("r"); |
595
e630bbb11629
make bitcoin include files more modular
Wladimir J. van der Laan <laanwj@gmail.com>
parents:
588
diff
changeset
|
1926 BOOST_FOREACH(const CInv& inv, vInv) |
575
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1927 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1928 if (fShutdown) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1929 return true; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1930 pfrom->AddInventoryKnown(inv); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1931 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1932 bool fAlreadyHave = AlreadyHave(txdb, inv); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1933 printf(" got inventory: %s %s\n", inv.ToString().c_str(), fAlreadyHave ? "have" : "new"); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1934 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1935 if (!fAlreadyHave) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1936 pfrom->AskFor(inv); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1937 else if (inv.type == MSG_BLOCK && mapOrphanBlocks.count(inv.hash)) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1938 pfrom->PushGetBlocks(pindexBest, GetOrphanRoot(mapOrphanBlocks[inv.hash])); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1939 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1940 // Track requests for our stuff |
690 | 1941 Inventory(inv.hash); |
575
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1942 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1943 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1944 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1945 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1946 else if (strCommand == "getdata") |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1947 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1948 vector<CInv> vInv; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1949 vRecv >> vInv; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1950 if (vInv.size() > 50000) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1951 return error("message getdata size() = %d", vInv.size()); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1952 |
595
e630bbb11629
make bitcoin include files more modular
Wladimir J. van der Laan <laanwj@gmail.com>
parents:
588
diff
changeset
|
1953 BOOST_FOREACH(const CInv& inv, vInv) |
575
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1954 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1955 if (fShutdown) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1956 return true; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1957 printf("received getdata for: %s\n", inv.ToString().c_str()); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1958 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1959 if (inv.type == MSG_BLOCK) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1960 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1961 // Send block from disk |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1962 map<uint256, CBlockIndex*>::iterator mi = mapBlockIndex.find(inv.hash); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1963 if (mi != mapBlockIndex.end()) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1964 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1965 CBlock block; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1966 block.ReadFromDisk((*mi).second); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1967 pfrom->PushMessage("block", block); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1968 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1969 // Trigger them to send a getblocks request for the next batch of inventory |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1970 if (inv.hash == pfrom->hashContinue) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1971 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1972 // Bypass PushInventory, this must send even if redundant, |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1973 // and we want it right after the last block so they don't |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1974 // wait for other stuff first. |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1975 vector<CInv> vInv; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1976 vInv.push_back(CInv(MSG_BLOCK, hashBestChain)); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1977 pfrom->PushMessage("inv", vInv); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1978 pfrom->hashContinue = 0; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1979 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1980 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1981 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1982 else if (inv.IsKnownType()) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1983 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1984 // Send stream from relay memory |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1985 CRITICAL_BLOCK(cs_mapRelay) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1986 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1987 map<CInv, CDataStream>::iterator mi = mapRelay.find(inv); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1988 if (mi != mapRelay.end()) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1989 pfrom->PushMessage(inv.GetCommand(), (*mi).second); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1990 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1991 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1992 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1993 // Track requests for our stuff |
690 | 1994 Inventory(inv.hash); |
575
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1995 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1996 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1997 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1998 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1999 else if (strCommand == "getblocks") |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2000 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2001 CBlockLocator locator; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2002 uint256 hashStop; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2003 vRecv >> locator >> hashStop; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2004 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2005 // Find the last block the caller has in the main chain |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2006 CBlockIndex* pindex = locator.GetBlockIndex(); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2007 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2008 // Send the rest of the chain |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2009 if (pindex) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2010 pindex = pindex->pnext; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2011 int nLimit = 500 + locator.GetDistanceBack(); |
718
3ce286fc9dc1
Limit response to getblocks to half of output buffer size
Pieter Wuille <pieter.wuille@gmail.com>
parents:
703
diff
changeset
|
2012 unsigned int nBytes = 0; |
575
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2013 printf("getblocks %d to %s limit %d\n", (pindex ? pindex->nHeight : -1), hashStop.ToString().substr(0,20).c_str(), nLimit); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2014 for (; pindex; pindex = pindex->pnext) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2015 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2016 if (pindex->GetBlockHash() == hashStop) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2017 { |
718
3ce286fc9dc1
Limit response to getblocks to half of output buffer size
Pieter Wuille <pieter.wuille@gmail.com>
parents:
703
diff
changeset
|
2018 printf(" getblocks stopping at %d %s (%u bytes)\n", pindex->nHeight, pindex->GetBlockHash().ToString().substr(0,20).c_str(), nBytes); |
575
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2019 break; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2020 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2021 pfrom->PushInventory(CInv(MSG_BLOCK, pindex->GetBlockHash())); |
718
3ce286fc9dc1
Limit response to getblocks to half of output buffer size
Pieter Wuille <pieter.wuille@gmail.com>
parents:
703
diff
changeset
|
2022 CBlock block; |
3ce286fc9dc1
Limit response to getblocks to half of output buffer size
Pieter Wuille <pieter.wuille@gmail.com>
parents:
703
diff
changeset
|
2023 block.ReadFromDisk(pindex, true); |
3ce286fc9dc1
Limit response to getblocks to half of output buffer size
Pieter Wuille <pieter.wuille@gmail.com>
parents:
703
diff
changeset
|
2024 nBytes += block.GetSerializeSize(SER_NETWORK); |
3ce286fc9dc1
Limit response to getblocks to half of output buffer size
Pieter Wuille <pieter.wuille@gmail.com>
parents:
703
diff
changeset
|
2025 if (--nLimit <= 0 || nBytes >= SendBufferSize()/2) |
575
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2026 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2027 // When this block is requested, we'll send an inv that'll make them |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2028 // getblocks the next batch of inventory. |
718
3ce286fc9dc1
Limit response to getblocks to half of output buffer size
Pieter Wuille <pieter.wuille@gmail.com>
parents:
703
diff
changeset
|
2029 printf(" getblocks stopping at limit %d %s (%u bytes)\n", pindex->nHeight, pindex->GetBlockHash().ToString().substr(0,20).c_str(), nBytes); |
575
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2030 pfrom->hashContinue = pindex->GetBlockHash(); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2031 break; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2032 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2033 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2034 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2035 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2036 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2037 else if (strCommand == "getheaders") |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2038 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2039 CBlockLocator locator; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2040 uint256 hashStop; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2041 vRecv >> locator >> hashStop; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2042 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2043 CBlockIndex* pindex = NULL; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2044 if (locator.IsNull()) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2045 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2046 // If locator is null, return the hashStop block |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2047 map<uint256, CBlockIndex*>::iterator mi = mapBlockIndex.find(hashStop); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2048 if (mi == mapBlockIndex.end()) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2049 return true; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2050 pindex = (*mi).second; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2051 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2052 else |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2053 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2054 // Find the last block the caller has in the main chain |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2055 pindex = locator.GetBlockIndex(); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2056 if (pindex) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2057 pindex = pindex->pnext; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2058 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2059 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2060 vector<CBlock> vHeaders; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2061 int nLimit = 2000 + locator.GetDistanceBack(); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2062 printf("getheaders %d to %s limit %d\n", (pindex ? pindex->nHeight : -1), hashStop.ToString().substr(0,20).c_str(), nLimit); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2063 for (; pindex; pindex = pindex->pnext) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2064 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2065 vHeaders.push_back(pindex->GetBlockHeader()); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2066 if (--nLimit <= 0 || pindex->GetBlockHash() == hashStop) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2067 break; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2068 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2069 pfrom->PushMessage("headers", vHeaders); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2070 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2071 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2072 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2073 else if (strCommand == "tx") |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2074 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2075 vector<uint256> vWorkQueue; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2076 CDataStream vMsg(vRecv); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2077 CTransaction tx; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2078 vRecv >> tx; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2079 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2080 CInv inv(MSG_TX, tx.GetHash()); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2081 pfrom->AddInventoryKnown(inv); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2082 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2083 bool fMissingInputs = false; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2084 if (tx.AcceptToMemoryPool(true, &fMissingInputs)) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2085 { |
690 | 2086 SyncWithWallets(tx, NULL, true); |
575
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2087 RelayMessage(inv, vMsg); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2088 mapAlreadyAskedFor.erase(inv); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2089 vWorkQueue.push_back(inv.hash); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2090 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2091 // Recursively process any orphan transactions that depended on this one |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2092 for (int i = 0; i < vWorkQueue.size(); i++) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2093 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2094 uint256 hashPrev = vWorkQueue[i]; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2095 for (multimap<uint256, CDataStream*>::iterator mi = mapOrphanTransactionsByPrev.lower_bound(hashPrev); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2096 mi != mapOrphanTransactionsByPrev.upper_bound(hashPrev); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2097 ++mi) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2098 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2099 const CDataStream& vMsg = *((*mi).second); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2100 CTransaction tx; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2101 CDataStream(vMsg) >> tx; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2102 CInv inv(MSG_TX, tx.GetHash()); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2103 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2104 if (tx.AcceptToMemoryPool(true)) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2105 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2106 printf(" accepted orphan tx %s\n", inv.hash.ToString().substr(0,10).c_str()); |
690 | 2107 SyncWithWallets(tx, NULL, true); |
575
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2108 RelayMessage(inv, vMsg); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2109 mapAlreadyAskedFor.erase(inv); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2110 vWorkQueue.push_back(inv.hash); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2111 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2112 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2113 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2114 |
595
e630bbb11629
make bitcoin include files more modular
Wladimir J. van der Laan <laanwj@gmail.com>
parents:
588
diff
changeset
|
2115 BOOST_FOREACH(uint256 hash, vWorkQueue) |
575
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2116 EraseOrphanTx(hash); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2117 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2118 else if (fMissingInputs) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2119 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2120 printf("storing orphan tx %s\n", inv.hash.ToString().substr(0,10).c_str()); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2121 AddOrphanTx(vMsg); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2122 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2123 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2124 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2125 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2126 else if (strCommand == "block") |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2127 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2128 CBlock block; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2129 vRecv >> block; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2130 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2131 printf("received block %s\n", block.GetHash().ToString().substr(0,20).c_str()); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2132 // block.print(); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2133 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2134 CInv inv(MSG_BLOCK, block.GetHash()); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2135 pfrom->AddInventoryKnown(inv); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2136 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2137 if (ProcessBlock(pfrom, &block)) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2138 mapAlreadyAskedFor.erase(inv); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2139 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2140 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2141 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2142 else if (strCommand == "getaddr") |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2143 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2144 // Nodes rebroadcast an addr every 24 hours |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2145 pfrom->vAddrToSend.clear(); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2146 int64 nSince = GetAdjustedTime() - 3 * 60 * 60; // in the last 3 hours |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2147 CRITICAL_BLOCK(cs_mapAddresses) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2148 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2149 unsigned int nCount = 0; |
595
e630bbb11629
make bitcoin include files more modular
Wladimir J. van der Laan <laanwj@gmail.com>
parents:
588
diff
changeset
|
2150 BOOST_FOREACH(const PAIRTYPE(vector<unsigned char>, CAddress)& item, mapAddresses) |
575
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2151 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2152 const CAddress& addr = item.second; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2153 if (addr.nTime > nSince) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2154 nCount++; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2155 } |
595
e630bbb11629
make bitcoin include files more modular
Wladimir J. van der Laan <laanwj@gmail.com>
parents:
588
diff
changeset
|
2156 BOOST_FOREACH(const PAIRTYPE(vector<unsigned char>, CAddress)& item, mapAddresses) |
575
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2157 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2158 const CAddress& addr = item.second; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2159 if (addr.nTime > nSince && GetRand(nCount) < 2500) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2160 pfrom->PushAddress(addr); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2161 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2162 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2163 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2164 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2165 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2166 else if (strCommand == "checkorder") |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2167 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2168 uint256 hashReply; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2169 vRecv >> hashReply; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2170 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2171 if (!GetBoolArg("-allowreceivebyip")) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2172 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2173 pfrom->PushMessage("reply", hashReply, (int)2, string("")); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2174 return true; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2175 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2176 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2177 CWalletTx order; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2178 vRecv >> order; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2179 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2180 /// we have a chance to check the order here |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2181 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2182 // Keep giving the same key to the same ip until they use it |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2183 if (!mapReuseKey.count(pfrom->addr.ip)) |
760
fd7e5b1cfc08
Add wallet privkey encryption.
Matt Corallo <matt@bluematt.me>
parents:
738
diff
changeset
|
2184 mapReuseKey[pfrom->addr.ip] = pwalletMain->GetOrReuseKeyFromPool(); |
575
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2185 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2186 // Send back approval of order and pubkey to use |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2187 CScript scriptPubKey; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2188 scriptPubKey << mapReuseKey[pfrom->addr.ip] << OP_CHECKSIG; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2189 pfrom->PushMessage("reply", hashReply, (int)0, scriptPubKey); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2190 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2191 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2192 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2193 else if (strCommand == "reply") |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2194 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2195 uint256 hashReply; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2196 vRecv >> hashReply; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2197 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2198 CRequestTracker tracker; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2199 CRITICAL_BLOCK(pfrom->cs_mapRequests) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2200 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2201 map<uint256, CRequestTracker>::iterator mi = pfrom->mapRequests.find(hashReply); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2202 if (mi != pfrom->mapRequests.end()) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2203 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2204 tracker = (*mi).second; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2205 pfrom->mapRequests.erase(mi); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2206 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2207 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2208 if (!tracker.IsNull()) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2209 tracker.fn(tracker.param1, vRecv); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2210 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2211 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2212 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2213 else if (strCommand == "ping") |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2214 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2215 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2216 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2217 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2218 else if (strCommand == "alert") |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2219 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2220 CAlert alert; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2221 vRecv >> alert; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2222 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2223 if (alert.ProcessAlert()) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2224 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2225 // Relay |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2226 pfrom->setKnown.insert(alert.GetHash()); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2227 CRITICAL_BLOCK(cs_vNodes) |
595
e630bbb11629
make bitcoin include files more modular
Wladimir J. van der Laan <laanwj@gmail.com>
parents:
588
diff
changeset
|
2228 BOOST_FOREACH(CNode* pnode, vNodes) |
575
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2229 alert.RelayTo(pnode); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2230 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2231 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2232 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2233 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2234 else |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2235 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2236 // Ignore unknown commands for extensibility |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2237 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2238 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2239 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2240 // Update the last seen time for this node's address |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2241 if (pfrom->fNetworkNode) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2242 if (strCommand == "version" || strCommand == "addr" || strCommand == "inv" || strCommand == "getdata" || strCommand == "ping") |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2243 AddressCurrentlyConnected(pfrom->addr); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2244 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2245 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2246 return true; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2247 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2248 |
689
9df222fa1ef1
move wallet code to separate file
Pieter Wuille <pieter.wuille@gmail.com>
parents:
688
diff
changeset
|
2249 bool ProcessMessages(CNode* pfrom) |
9df222fa1ef1
move wallet code to separate file
Pieter Wuille <pieter.wuille@gmail.com>
parents:
688
diff
changeset
|
2250 { |
9df222fa1ef1
move wallet code to separate file
Pieter Wuille <pieter.wuille@gmail.com>
parents:
688
diff
changeset
|
2251 CDataStream& vRecv = pfrom->vRecv; |
9df222fa1ef1
move wallet code to separate file
Pieter Wuille <pieter.wuille@gmail.com>
parents:
688
diff
changeset
|
2252 if (vRecv.empty()) |
9df222fa1ef1
move wallet code to separate file
Pieter Wuille <pieter.wuille@gmail.com>
parents:
688
diff
changeset
|
2253 return true; |
9df222fa1ef1
move wallet code to separate file
Pieter Wuille <pieter.wuille@gmail.com>
parents:
688
diff
changeset
|
2254 //if (fDebug) |
9df222fa1ef1
move wallet code to separate file
Pieter Wuille <pieter.wuille@gmail.com>
parents:
688
diff
changeset
|
2255 // printf("ProcessMessages(%u bytes)\n", vRecv.size()); |
9df222fa1ef1
move wallet code to separate file
Pieter Wuille <pieter.wuille@gmail.com>
parents:
688
diff
changeset
|
2256 |
9df222fa1ef1
move wallet code to separate file
Pieter Wuille <pieter.wuille@gmail.com>
parents:
688
diff
changeset
|
2257 // |
9df222fa1ef1
move wallet code to separate file
Pieter Wuille <pieter.wuille@gmail.com>
parents:
688
diff
changeset
|
2258 // Message format |
9df222fa1ef1
move wallet code to separate file
Pieter Wuille <pieter.wuille@gmail.com>
parents:
688
diff
changeset
|
2259 // (4) message start |
9df222fa1ef1
move wallet code to separate file
Pieter Wuille <pieter.wuille@gmail.com>
parents:
688
diff
changeset
|
2260 // (12) command |
9df222fa1ef1
move wallet code to separate file
Pieter Wuille <pieter.wuille@gmail.com>
parents:
688
diff
changeset
|
2261 // (4) size |
9df222fa1ef1
move wallet code to separate file
Pieter Wuille <pieter.wuille@gmail.com>
parents:
688
diff
changeset
|
2262 // (4) checksum |
9df222fa1ef1
move wallet code to separate file
Pieter Wuille <pieter.wuille@gmail.com>
parents:
688
diff
changeset
|
2263 // (x) data |
9df222fa1ef1
move wallet code to separate file
Pieter Wuille <pieter.wuille@gmail.com>
parents:
688
diff
changeset
|
2264 // |
9df222fa1ef1
move wallet code to separate file
Pieter Wuille <pieter.wuille@gmail.com>
parents:
688
diff
changeset
|
2265 |
9df222fa1ef1
move wallet code to separate file
Pieter Wuille <pieter.wuille@gmail.com>
parents:
688
diff
changeset
|
2266 loop |
9df222fa1ef1
move wallet code to separate file
Pieter Wuille <pieter.wuille@gmail.com>
parents:
688
diff
changeset
|
2267 { |
9df222fa1ef1
move wallet code to separate file
Pieter Wuille <pieter.wuille@gmail.com>
parents:
688
diff
changeset
|
2268 // Scan for message start |
9df222fa1ef1
move wallet code to separate file
Pieter Wuille <pieter.wuille@gmail.com>
parents:
688
diff
changeset
|
2269 CDataStream::iterator pstart = search(vRecv.begin(), vRecv.end(), BEGIN(pchMessageStart), END(pchMessageStart)); |
9df222fa1ef1
move wallet code to separate file
Pieter Wuille <pieter.wuille@gmail.com>
parents:
688
diff
changeset
|
2270 int nHeaderSize = vRecv.GetSerializeSize(CMessageHeader()); |
9df222fa1ef1
move wallet code to separate file
Pieter Wuille <pieter.wuille@gmail.com>
parents:
688
diff
changeset
|
2271 if (vRecv.end() - pstart < nHeaderSize) |
9df222fa1ef1
move wallet code to separate file
Pieter Wuille <pieter.wuille@gmail.com>
parents:
688
diff
changeset
|
2272 { |
9df222fa1ef1
move wallet code to separate file
Pieter Wuille <pieter.wuille@gmail.com>
parents:
688
diff
changeset
|
2273 if (vRecv.size() > nHeaderSize) |
9df222fa1ef1
move wallet code to separate file
Pieter Wuille <pieter.wuille@gmail.com>
parents:
688
diff
changeset
|
2274 { |
9df222fa1ef1
move wallet code to separate file
Pieter Wuille <pieter.wuille@gmail.com>
parents:
688
diff
changeset
|
2275 printf("\n\nPROCESSMESSAGE MESSAGESTART NOT FOUND\n\n"); |
9df222fa1ef1
move wallet code to separate file
Pieter Wuille <pieter.wuille@gmail.com>
parents:
688
diff
changeset
|
2276 vRecv.erase(vRecv.begin(), vRecv.end() - nHeaderSize); |
9df222fa1ef1
move wallet code to separate file
Pieter Wuille <pieter.wuille@gmail.com>
parents:
688
diff
changeset
|
2277 } |
9df222fa1ef1
move wallet code to separate file
Pieter Wuille <pieter.wuille@gmail.com>
parents:
688
diff
changeset
|
2278 break; |
9df222fa1ef1
move wallet code to separate file
Pieter Wuille <pieter.wuille@gmail.com>
parents:
688
diff
changeset
|
2279 } |
9df222fa1ef1
move wallet code to separate file
Pieter Wuille <pieter.wuille@gmail.com>
parents:
688
diff
changeset
|
2280 if (pstart - vRecv.begin() > 0) |
9df222fa1ef1
move wallet code to separate file
Pieter Wuille <pieter.wuille@gmail.com>
parents:
688
diff
changeset
|
2281 printf("\n\nPROCESSMESSAGE SKIPPED %d BYTES\n\n", pstart - vRecv.begin()); |
9df222fa1ef1
move wallet code to separate file
Pieter Wuille <pieter.wuille@gmail.com>
parents:
688
diff
changeset
|
2282 vRecv.erase(vRecv.begin(), pstart); |
9df222fa1ef1
move wallet code to separate file
Pieter Wuille <pieter.wuille@gmail.com>
parents:
688
diff
changeset
|
2283 |
9df222fa1ef1
move wallet code to separate file
Pieter Wuille <pieter.wuille@gmail.com>
parents:
688
diff
changeset
|
2284 // Read header |
9df222fa1ef1
move wallet code to separate file
Pieter Wuille <pieter.wuille@gmail.com>
parents:
688
diff
changeset
|
2285 vector<char> vHeaderSave(vRecv.begin(), vRecv.begin() + nHeaderSize); |
9df222fa1ef1
move wallet code to separate file
Pieter Wuille <pieter.wuille@gmail.com>
parents:
688
diff
changeset
|
2286 CMessageHeader hdr; |
9df222fa1ef1
move wallet code to separate file
Pieter Wuille <pieter.wuille@gmail.com>
parents:
688
diff
changeset
|
2287 vRecv >> hdr; |
9df222fa1ef1
move wallet code to separate file
Pieter Wuille <pieter.wuille@gmail.com>
parents:
688
diff
changeset
|
2288 if (!hdr.IsValid()) |
9df222fa1ef1
move wallet code to separate file
Pieter Wuille <pieter.wuille@gmail.com>
parents:
688
diff
changeset
|
2289 { |
9df222fa1ef1
move wallet code to separate file
Pieter Wuille <pieter.wuille@gmail.com>
parents:
688
diff
changeset
|
2290 printf("\n\nPROCESSMESSAGE: ERRORS IN HEADER %s\n\n\n", hdr.GetCommand().c_str()); |
9df222fa1ef1
move wallet code to separate file
Pieter Wuille <pieter.wuille@gmail.com>
parents:
688
diff
changeset
|
2291 continue; |
9df222fa1ef1
move wallet code to separate file
Pieter Wuille <pieter.wuille@gmail.com>
parents:
688
diff
changeset
|
2292 } |
9df222fa1ef1
move wallet code to separate file
Pieter Wuille <pieter.wuille@gmail.com>
parents:
688
diff
changeset
|
2293 string strCommand = hdr.GetCommand(); |
9df222fa1ef1
move wallet code to separate file
Pieter Wuille <pieter.wuille@gmail.com>
parents:
688
diff
changeset
|
2294 |
9df222fa1ef1
move wallet code to separate file
Pieter Wuille <pieter.wuille@gmail.com>
parents:
688
diff
changeset
|
2295 // Message size |
9df222fa1ef1
move wallet code to separate file
Pieter Wuille <pieter.wuille@gmail.com>
parents:
688
diff
changeset
|
2296 unsigned int nMessageSize = hdr.nMessageSize; |
9df222fa1ef1
move wallet code to separate file
Pieter Wuille <pieter.wuille@gmail.com>
parents:
688
diff
changeset
|
2297 if (nMessageSize > MAX_SIZE) |
9df222fa1ef1
move wallet code to separate file
Pieter Wuille <pieter.wuille@gmail.com>
parents:
688
diff
changeset
|
2298 { |
9df222fa1ef1
move wallet code to separate file
Pieter Wuille <pieter.wuille@gmail.com>
parents:
688
diff
changeset
|
2299 printf("ProcessMessage(%s, %u bytes) : nMessageSize > MAX_SIZE\n", strCommand.c_str(), nMessageSize); |
9df222fa1ef1
move wallet code to separate file
Pieter Wuille <pieter.wuille@gmail.com>
parents:
688
diff
changeset
|
2300 continue; |
9df222fa1ef1
move wallet code to separate file
Pieter Wuille <pieter.wuille@gmail.com>
parents:
688
diff
changeset
|
2301 } |
9df222fa1ef1
move wallet code to separate file
Pieter Wuille <pieter.wuille@gmail.com>
parents:
688
diff
changeset
|
2302 if (nMessageSize > vRecv.size()) |
9df222fa1ef1
move wallet code to separate file
Pieter Wuille <pieter.wuille@gmail.com>
parents:
688
diff
changeset
|
2303 { |
9df222fa1ef1
move wallet code to separate file
Pieter Wuille <pieter.wuille@gmail.com>
parents:
688
diff
changeset
|
2304 // Rewind and wait for rest of message |
9df222fa1ef1
move wallet code to separate file
Pieter Wuille <pieter.wuille@gmail.com>
parents:
688
diff
changeset
|
2305 vRecv.insert(vRecv.begin(), vHeaderSave.begin(), vHeaderSave.end()); |
9df222fa1ef1
move wallet code to separate file
Pieter Wuille <pieter.wuille@gmail.com>
parents:
688
diff
changeset
|
2306 break; |
9df222fa1ef1
move wallet code to separate file
Pieter Wuille <pieter.wuille@gmail.com>
parents:
688
diff
changeset
|
2307 } |
9df222fa1ef1
move wallet code to separate file
Pieter Wuille <pieter.wuille@gmail.com>
parents:
688
diff
changeset
|
2308 |
9df222fa1ef1
move wallet code to separate file
Pieter Wuille <pieter.wuille@gmail.com>
parents:
688
diff
changeset
|
2309 // Checksum |
9df222fa1ef1
move wallet code to separate file
Pieter Wuille <pieter.wuille@gmail.com>
parents:
688
diff
changeset
|
2310 if (vRecv.GetVersion() >= 209) |
9df222fa1ef1
move wallet code to separate file
Pieter Wuille <pieter.wuille@gmail.com>
parents:
688
diff
changeset
|
2311 { |
9df222fa1ef1
move wallet code to separate file
Pieter Wuille <pieter.wuille@gmail.com>
parents:
688
diff
changeset
|
2312 uint256 hash = Hash(vRecv.begin(), vRecv.begin() + nMessageSize); |
9df222fa1ef1
move wallet code to separate file
Pieter Wuille <pieter.wuille@gmail.com>
parents:
688
diff
changeset
|
2313 unsigned int nChecksum = 0; |
9df222fa1ef1
move wallet code to separate file
Pieter Wuille <pieter.wuille@gmail.com>
parents:
688
diff
changeset
|
2314 memcpy(&nChecksum, &hash, sizeof(nChecksum)); |
9df222fa1ef1
move wallet code to separate file
Pieter Wuille <pieter.wuille@gmail.com>
parents:
688
diff
changeset
|
2315 if (nChecksum != hdr.nChecksum) |
9df222fa1ef1
move wallet code to separate file
Pieter Wuille <pieter.wuille@gmail.com>
parents:
688
diff
changeset
|
2316 { |
9df222fa1ef1
move wallet code to separate file
Pieter Wuille <pieter.wuille@gmail.com>
parents:
688
diff
changeset
|
2317 printf("ProcessMessage(%s, %u bytes) : CHECKSUM ERROR nChecksum=%08x hdr.nChecksum=%08x\n", |
9df222fa1ef1
move wallet code to separate file
Pieter Wuille <pieter.wuille@gmail.com>
parents:
688
diff
changeset
|
2318 strCommand.c_str(), nMessageSize, nChecksum, hdr.nChecksum); |
9df222fa1ef1
move wallet code to separate file
Pieter Wuille <pieter.wuille@gmail.com>
parents:
688
diff
changeset
|
2319 continue; |
9df222fa1ef1
move wallet code to separate file
Pieter Wuille <pieter.wuille@gmail.com>
parents:
688
diff
changeset
|
2320 } |
9df222fa1ef1
move wallet code to separate file
Pieter Wuille <pieter.wuille@gmail.com>
parents:
688
diff
changeset
|
2321 } |
9df222fa1ef1
move wallet code to separate file
Pieter Wuille <pieter.wuille@gmail.com>
parents:
688
diff
changeset
|
2322 |
9df222fa1ef1
move wallet code to separate file
Pieter Wuille <pieter.wuille@gmail.com>
parents:
688
diff
changeset
|
2323 // Copy message to its own buffer |
9df222fa1ef1
move wallet code to separate file
Pieter Wuille <pieter.wuille@gmail.com>
parents:
688
diff
changeset
|
2324 CDataStream vMsg(vRecv.begin(), vRecv.begin() + nMessageSize, vRecv.nType, vRecv.nVersion); |
9df222fa1ef1
move wallet code to separate file
Pieter Wuille <pieter.wuille@gmail.com>
parents:
688
diff
changeset
|
2325 vRecv.ignore(nMessageSize); |
9df222fa1ef1
move wallet code to separate file
Pieter Wuille <pieter.wuille@gmail.com>
parents:
688
diff
changeset
|
2326 |
9df222fa1ef1
move wallet code to separate file
Pieter Wuille <pieter.wuille@gmail.com>
parents:
688
diff
changeset
|
2327 // Process message |
9df222fa1ef1
move wallet code to separate file
Pieter Wuille <pieter.wuille@gmail.com>
parents:
688
diff
changeset
|
2328 bool fRet = false; |
9df222fa1ef1
move wallet code to separate file
Pieter Wuille <pieter.wuille@gmail.com>
parents:
688
diff
changeset
|
2329 try |
9df222fa1ef1
move wallet code to separate file
Pieter Wuille <pieter.wuille@gmail.com>
parents:
688
diff
changeset
|
2330 { |
9df222fa1ef1
move wallet code to separate file
Pieter Wuille <pieter.wuille@gmail.com>
parents:
688
diff
changeset
|
2331 CRITICAL_BLOCK(cs_main) |
9df222fa1ef1
move wallet code to separate file
Pieter Wuille <pieter.wuille@gmail.com>
parents:
688
diff
changeset
|
2332 fRet = ProcessMessage(pfrom, strCommand, vMsg); |
9df222fa1ef1
move wallet code to separate file
Pieter Wuille <pieter.wuille@gmail.com>
parents:
688
diff
changeset
|
2333 if (fShutdown) |
9df222fa1ef1
move wallet code to separate file
Pieter Wuille <pieter.wuille@gmail.com>
parents:
688
diff
changeset
|
2334 return true; |
9df222fa1ef1
move wallet code to separate file
Pieter Wuille <pieter.wuille@gmail.com>
parents:
688
diff
changeset
|
2335 } |
9df222fa1ef1
move wallet code to separate file
Pieter Wuille <pieter.wuille@gmail.com>
parents:
688
diff
changeset
|
2336 catch (std::ios_base::failure& e) |
9df222fa1ef1
move wallet code to separate file
Pieter Wuille <pieter.wuille@gmail.com>
parents:
688
diff
changeset
|
2337 { |
9df222fa1ef1
move wallet code to separate file
Pieter Wuille <pieter.wuille@gmail.com>
parents:
688
diff
changeset
|
2338 if (strstr(e.what(), "end of data")) |
9df222fa1ef1
move wallet code to separate file
Pieter Wuille <pieter.wuille@gmail.com>
parents:
688
diff
changeset
|
2339 { |
9df222fa1ef1
move wallet code to separate file
Pieter Wuille <pieter.wuille@gmail.com>
parents:
688
diff
changeset
|
2340 // Allow exceptions from underlength message on vRecv |
9df222fa1ef1
move wallet code to separate file
Pieter Wuille <pieter.wuille@gmail.com>
parents:
688
diff
changeset
|
2341 printf("ProcessMessage(%s, %u bytes) : Exception '%s' caught, normally caused by a message being shorter than its stated length\n", strCommand.c_str(), nMessageSize, e.what()); |
9df222fa1ef1
move wallet code to separate file
Pieter Wuille <pieter.wuille@gmail.com>
parents:
688
diff
changeset
|
2342 } |
9df222fa1ef1
move wallet code to separate file
Pieter Wuille <pieter.wuille@gmail.com>
parents:
688
diff
changeset
|
2343 else if (strstr(e.what(), "size too large")) |
9df222fa1ef1
move wallet code to separate file
Pieter Wuille <pieter.wuille@gmail.com>
parents:
688
diff
changeset
|
2344 { |
9df222fa1ef1
move wallet code to separate file
Pieter Wuille <pieter.wuille@gmail.com>
parents:
688
diff
changeset
|
2345 // Allow exceptions from overlong size |
9df222fa1ef1
move wallet code to separate file
Pieter Wuille <pieter.wuille@gmail.com>
parents:
688
diff
changeset
|
2346 printf("ProcessMessage(%s, %u bytes) : Exception '%s' caught\n", strCommand.c_str(), nMessageSize, e.what()); |
9df222fa1ef1
move wallet code to separate file
Pieter Wuille <pieter.wuille@gmail.com>
parents:
688
diff
changeset
|
2347 } |
9df222fa1ef1
move wallet code to separate file
Pieter Wuille <pieter.wuille@gmail.com>
parents:
688
diff
changeset
|
2348 else |
9df222fa1ef1
move wallet code to separate file
Pieter Wuille <pieter.wuille@gmail.com>
parents:
688
diff
changeset
|
2349 { |
9df222fa1ef1
move wallet code to separate file
Pieter Wuille <pieter.wuille@gmail.com>
parents:
688
diff
changeset
|
2350 PrintExceptionContinue(&e, "ProcessMessage()"); |
9df222fa1ef1
move wallet code to separate file
Pieter Wuille <pieter.wuille@gmail.com>
parents:
688
diff
changeset
|
2351 } |
9df222fa1ef1
move wallet code to separate file
Pieter Wuille <pieter.wuille@gmail.com>
parents:
688
diff
changeset
|
2352 } |
9df222fa1ef1
move wallet code to separate file
Pieter Wuille <pieter.wuille@gmail.com>
parents:
688
diff
changeset
|
2353 catch (std::exception& e) { |
9df222fa1ef1
move wallet code to separate file
Pieter Wuille <pieter.wuille@gmail.com>
parents:
688
diff
changeset
|
2354 PrintExceptionContinue(&e, "ProcessMessage()"); |
9df222fa1ef1
move wallet code to separate file
Pieter Wuille <pieter.wuille@gmail.com>
parents:
688
diff
changeset
|
2355 } catch (...) { |
9df222fa1ef1
move wallet code to separate file
Pieter Wuille <pieter.wuille@gmail.com>
parents:
688
diff
changeset
|
2356 PrintExceptionContinue(NULL, "ProcessMessage()"); |
9df222fa1ef1
move wallet code to separate file
Pieter Wuille <pieter.wuille@gmail.com>
parents:
688
diff
changeset
|
2357 } |
9df222fa1ef1
move wallet code to separate file
Pieter Wuille <pieter.wuille@gmail.com>
parents:
688
diff
changeset
|
2358 |
9df222fa1ef1
move wallet code to separate file
Pieter Wuille <pieter.wuille@gmail.com>
parents:
688
diff
changeset
|
2359 if (!fRet) |
9df222fa1ef1
move wallet code to separate file
Pieter Wuille <pieter.wuille@gmail.com>
parents:
688
diff
changeset
|
2360 printf("ProcessMessage(%s, %u bytes) FAILED\n", strCommand.c_str(), nMessageSize); |
9df222fa1ef1
move wallet code to separate file
Pieter Wuille <pieter.wuille@gmail.com>
parents:
688
diff
changeset
|
2361 } |
9df222fa1ef1
move wallet code to separate file
Pieter Wuille <pieter.wuille@gmail.com>
parents:
688
diff
changeset
|
2362 |
9df222fa1ef1
move wallet code to separate file
Pieter Wuille <pieter.wuille@gmail.com>
parents:
688
diff
changeset
|
2363 vRecv.Compact(); |
9df222fa1ef1
move wallet code to separate file
Pieter Wuille <pieter.wuille@gmail.com>
parents:
688
diff
changeset
|
2364 return true; |
9df222fa1ef1
move wallet code to separate file
Pieter Wuille <pieter.wuille@gmail.com>
parents:
688
diff
changeset
|
2365 } |
575
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2366 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2367 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2368 bool SendMessages(CNode* pto, bool fSendTrickle) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2369 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2370 CRITICAL_BLOCK(cs_main) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2371 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2372 // Don't send anything until we get their version message |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2373 if (pto->nVersion == 0) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2374 return true; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2375 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2376 // Keep-alive ping |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2377 if (pto->nLastSend && GetTime() - pto->nLastSend > 30 * 60 && pto->vSend.empty()) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2378 pto->PushMessage("ping"); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2379 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2380 // Resend wallet transactions that haven't gotten in a block yet |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2381 ResendWalletTransactions(); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2382 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2383 // Address refresh broadcast |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2384 static int64 nLastRebroadcast; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2385 if (GetTime() - nLastRebroadcast > 24 * 60 * 60) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2386 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2387 nLastRebroadcast = GetTime(); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2388 CRITICAL_BLOCK(cs_vNodes) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2389 { |
595
e630bbb11629
make bitcoin include files more modular
Wladimir J. van der Laan <laanwj@gmail.com>
parents:
588
diff
changeset
|
2390 BOOST_FOREACH(CNode* pnode, vNodes) |
575
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2391 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2392 // Periodically clear setAddrKnown to allow refresh broadcasts |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2393 pnode->setAddrKnown.clear(); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2394 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2395 // Rebroadcast our address |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2396 if (addrLocalHost.IsRoutable() && !fUseProxy) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2397 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2398 CAddress addr(addrLocalHost); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2399 addr.nTime = GetAdjustedTime(); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2400 pnode->PushAddress(addr); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2401 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2402 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2403 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2404 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2405 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2406 // Clear out old addresses periodically so it's not too much work at once |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2407 static int64 nLastClear; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2408 if (nLastClear == 0) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2409 nLastClear = GetTime(); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2410 if (GetTime() - nLastClear > 10 * 60 && vNodes.size() >= 3) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2411 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2412 nLastClear = GetTime(); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2413 CRITICAL_BLOCK(cs_mapAddresses) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2414 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2415 CAddrDB addrdb; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2416 int64 nSince = GetAdjustedTime() - 14 * 24 * 60 * 60; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2417 for (map<vector<unsigned char>, CAddress>::iterator mi = mapAddresses.begin(); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2418 mi != mapAddresses.end();) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2419 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2420 const CAddress& addr = (*mi).second; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2421 if (addr.nTime < nSince) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2422 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2423 if (mapAddresses.size() < 1000 || GetTime() > nLastClear + 20) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2424 break; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2425 addrdb.EraseAddress(addr); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2426 mapAddresses.erase(mi++); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2427 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2428 else |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2429 mi++; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2430 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2431 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2432 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2433 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2434 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2435 // |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2436 // Message: addr |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2437 // |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2438 if (fSendTrickle) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2439 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2440 vector<CAddress> vAddr; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2441 vAddr.reserve(pto->vAddrToSend.size()); |
595
e630bbb11629
make bitcoin include files more modular
Wladimir J. van der Laan <laanwj@gmail.com>
parents:
588
diff
changeset
|
2442 BOOST_FOREACH(const CAddress& addr, pto->vAddrToSend) |
575
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2443 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2444 // returns true if wasn't already contained in the set |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2445 if (pto->setAddrKnown.insert(addr).second) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2446 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2447 vAddr.push_back(addr); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2448 // receiver rejects addr messages larger than 1000 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2449 if (vAddr.size() >= 1000) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2450 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2451 pto->PushMessage("addr", vAddr); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2452 vAddr.clear(); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2453 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2454 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2455 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2456 pto->vAddrToSend.clear(); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2457 if (!vAddr.empty()) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2458 pto->PushMessage("addr", vAddr); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2459 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2460 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2461 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2462 // |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2463 // Message: inventory |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2464 // |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2465 vector<CInv> vInv; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2466 vector<CInv> vInvWait; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2467 CRITICAL_BLOCK(pto->cs_inventory) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2468 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2469 vInv.reserve(pto->vInventoryToSend.size()); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2470 vInvWait.reserve(pto->vInventoryToSend.size()); |
595
e630bbb11629
make bitcoin include files more modular
Wladimir J. van der Laan <laanwj@gmail.com>
parents:
588
diff
changeset
|
2471 BOOST_FOREACH(const CInv& inv, pto->vInventoryToSend) |
575
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2472 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2473 if (pto->setInventoryKnown.count(inv)) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2474 continue; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2475 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2476 // trickle out tx inv to protect privacy |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2477 if (inv.type == MSG_TX && !fSendTrickle) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2478 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2479 // 1/4 of tx invs blast to all immediately |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2480 static uint256 hashSalt; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2481 if (hashSalt == 0) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2482 RAND_bytes((unsigned char*)&hashSalt, sizeof(hashSalt)); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2483 uint256 hashRand = inv.hash ^ hashSalt; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2484 hashRand = Hash(BEGIN(hashRand), END(hashRand)); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2485 bool fTrickleWait = ((hashRand & 3) != 0); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2486 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2487 // always trickle our own transactions |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2488 if (!fTrickleWait) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2489 { |
690 | 2490 CWalletTx wtx; |
2491 if (GetTransaction(inv.hash, wtx)) | |
2492 if (wtx.fFromMe) | |
2493 fTrickleWait = true; | |
575
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2494 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2495 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2496 if (fTrickleWait) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2497 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2498 vInvWait.push_back(inv); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2499 continue; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2500 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2501 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2502 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2503 // returns true if wasn't already contained in the set |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2504 if (pto->setInventoryKnown.insert(inv).second) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2505 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2506 vInv.push_back(inv); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2507 if (vInv.size() >= 1000) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2508 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2509 pto->PushMessage("inv", vInv); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2510 vInv.clear(); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2511 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2512 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2513 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2514 pto->vInventoryToSend = vInvWait; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2515 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2516 if (!vInv.empty()) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2517 pto->PushMessage("inv", vInv); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2518 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2519 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2520 // |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2521 // Message: getdata |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2522 // |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2523 vector<CInv> vGetData; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2524 int64 nNow = GetTime() * 1000000; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2525 CTxDB txdb("r"); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2526 while (!pto->mapAskFor.empty() && (*pto->mapAskFor.begin()).first <= nNow) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2527 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2528 const CInv& inv = (*pto->mapAskFor.begin()).second; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2529 if (!AlreadyHave(txdb, inv)) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2530 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2531 printf("sending getdata: %s\n", inv.ToString().c_str()); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2532 vGetData.push_back(inv); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2533 if (vGetData.size() >= 1000) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2534 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2535 pto->PushMessage("getdata", vGetData); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2536 vGetData.clear(); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2537 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2538 } |
820
7e5ff9087b80
Actually use mapAlreadyAskedFor.
Matt Corallo <matt@bluematt.me>
parents:
796
diff
changeset
|
2539 mapAlreadyAskedFor[inv] = nNow; |
575
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2540 pto->mapAskFor.erase(pto->mapAskFor.begin()); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2541 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2542 if (!vGetData.empty()) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2543 pto->PushMessage("getdata", vGetData); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2544 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2545 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2546 return true; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2547 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2548 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2549 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2550 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2551 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2552 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2553 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2554 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2555 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2556 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2557 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2558 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2559 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2560 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2561 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2562 ////////////////////////////////////////////////////////////////////////////// |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2563 // |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2564 // BitcoinMiner |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2565 // |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2566 |
690 | 2567 int static FormatHashBlocks(void* pbuffer, unsigned int len) |
575
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2568 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2569 unsigned char* pdata = (unsigned char*)pbuffer; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2570 unsigned int blocks = 1 + ((len + 8) / 64); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2571 unsigned char* pend = pdata + 64 * blocks; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2572 memset(pdata + len, 0, 64 * blocks - len); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2573 pdata[len] = 0x80; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2574 unsigned int bits = len * 8; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2575 pend[-1] = (bits >> 0) & 0xff; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2576 pend[-2] = (bits >> 8) & 0xff; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2577 pend[-3] = (bits >> 16) & 0xff; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2578 pend[-4] = (bits >> 24) & 0xff; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2579 return blocks; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2580 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2581 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2582 using CryptoPP::ByteReverse; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2583 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2584 static const unsigned int pSHA256InitState[8] = |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2585 {0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a, 0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19}; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2586 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2587 inline void SHA256Transform(void* pstate, void* pinput, const void* pinit) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2588 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2589 memcpy(pstate, pinit, 32); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2590 CryptoPP::SHA256::Transform((CryptoPP::word32*)pstate, (CryptoPP::word32*)pinput); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2591 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2592 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2593 // |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2594 // ScanHash scans nonces looking for a hash with at least some zero bits. |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2595 // It operates on big endian data. Caller does the byte reversing. |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2596 // All input buffers are 16-byte aligned. nNonce is usually preserved |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2597 // between calls, but periodically or if nNonce is 0xffff0000 or above, |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2598 // the block is rebuilt and nNonce starts over at zero. |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2599 // |
690 | 2600 unsigned int static ScanHash_CryptoPP(char* pmidstate, char* pdata, char* phash1, char* phash, unsigned int& nHashesDone) |
575
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2601 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2602 unsigned int& nNonce = *(unsigned int*)(pdata + 12); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2603 for (;;) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2604 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2605 // Crypto++ SHA-256 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2606 // Hash pdata using pmidstate as the starting state into |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2607 // preformatted buffer phash1, then hash phash1 into phash |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2608 nNonce++; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2609 SHA256Transform(phash1, pdata, pmidstate); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2610 SHA256Transform(phash, phash1, pSHA256InitState); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2611 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2612 // Return the nonce if the hash has at least some zero bits, |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2613 // caller will check if it has enough to reach the target |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2614 if (((unsigned short*)phash)[14] == 0) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2615 return nNonce; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2616 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2617 // If nothing found after trying for a while, return -1 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2618 if ((nNonce & 0xffff) == 0) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2619 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2620 nHashesDone = 0xffff+1; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2621 return -1; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2622 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2623 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2624 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2625 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2626 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2627 class COrphan |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2628 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2629 public: |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2630 CTransaction* ptx; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2631 set<uint256> setDependsOn; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2632 double dPriority; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2633 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2634 COrphan(CTransaction* ptxIn) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2635 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2636 ptx = ptxIn; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2637 dPriority = 0; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2638 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2639 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2640 void print() const |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2641 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2642 printf("COrphan(hash=%s, dPriority=%.1f)\n", ptx->GetHash().ToString().substr(0,10).c_str(), dPriority); |
595
e630bbb11629
make bitcoin include files more modular
Wladimir J. van der Laan <laanwj@gmail.com>
parents:
588
diff
changeset
|
2643 BOOST_FOREACH(uint256 hash, setDependsOn) |
575
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2644 printf(" setDependsOn %s\n", hash.ToString().substr(0,10).c_str()); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2645 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2646 }; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2647 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2648 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2649 CBlock* CreateNewBlock(CReserveKey& reservekey) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2650 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2651 CBlockIndex* pindexPrev = pindexBest; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2652 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2653 // Create new block |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2654 auto_ptr<CBlock> pblock(new CBlock()); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2655 if (!pblock.get()) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2656 return NULL; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2657 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2658 // Create coinbase tx |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2659 CTransaction txNew; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2660 txNew.vin.resize(1); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2661 txNew.vin[0].prevout.SetNull(); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2662 txNew.vout.resize(1); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2663 txNew.vout[0].scriptPubKey << reservekey.GetReservedKey() << OP_CHECKSIG; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2664 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2665 // Add our coinbase tx as first transaction |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2666 pblock->vtx.push_back(txNew); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2667 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2668 // Collect memory pool transactions into the block |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2669 int64 nFees = 0; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2670 CRITICAL_BLOCK(cs_main) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2671 CRITICAL_BLOCK(cs_mapTransactions) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2672 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2673 CTxDB txdb("r"); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2674 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2675 // Priority order to process transactions |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2676 list<COrphan> vOrphan; // list memory doesn't move |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2677 map<uint256, vector<COrphan*> > mapDependers; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2678 multimap<double, CTransaction*> mapPriority; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2679 for (map<uint256, CTransaction>::iterator mi = mapTransactions.begin(); mi != mapTransactions.end(); ++mi) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2680 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2681 CTransaction& tx = (*mi).second; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2682 if (tx.IsCoinBase() || !tx.IsFinal()) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2683 continue; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2684 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2685 COrphan* porphan = NULL; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2686 double dPriority = 0; |
595
e630bbb11629
make bitcoin include files more modular
Wladimir J. van der Laan <laanwj@gmail.com>
parents:
588
diff
changeset
|
2687 BOOST_FOREACH(const CTxIn& txin, tx.vin) |
575
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2688 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2689 // Read prev transaction |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2690 CTransaction txPrev; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2691 CTxIndex txindex; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2692 if (!txPrev.ReadFromDisk(txdb, txin.prevout, txindex)) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2693 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2694 // Has to wait for dependencies |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2695 if (!porphan) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2696 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2697 // Use list for automatic deletion |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2698 vOrphan.push_back(COrphan(&tx)); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2699 porphan = &vOrphan.back(); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2700 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2701 mapDependers[txin.prevout.hash].push_back(porphan); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2702 porphan->setDependsOn.insert(txin.prevout.hash); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2703 continue; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2704 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2705 int64 nValueIn = txPrev.vout[txin.prevout.n].nValue; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2706 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2707 // Read block header |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2708 int nConf = txindex.GetDepthInMainChain(); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2709 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2710 dPriority += (double)nValueIn * nConf; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2711 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2712 if (fDebug && GetBoolArg("-printpriority")) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2713 printf("priority nValueIn=%-12I64d nConf=%-5d dPriority=%-20.1f\n", nValueIn, nConf, dPriority); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2714 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2715 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2716 // Priority is sum(valuein * age) / txsize |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2717 dPriority /= ::GetSerializeSize(tx, SER_NETWORK); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2718 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2719 if (porphan) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2720 porphan->dPriority = dPriority; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2721 else |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2722 mapPriority.insert(make_pair(-dPriority, &(*mi).second)); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2723 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2724 if (fDebug && GetBoolArg("-printpriority")) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2725 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2726 printf("priority %-20.1f %s\n%s", dPriority, tx.GetHash().ToString().substr(0,10).c_str(), tx.ToString().c_str()); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2727 if (porphan) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2728 porphan->print(); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2729 printf("\n"); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2730 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2731 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2732 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2733 // Collect transactions into block |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2734 map<uint256, CTxIndex> mapTestPool; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2735 uint64 nBlockSize = 1000; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2736 int nBlockSigOps = 100; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2737 while (!mapPriority.empty()) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2738 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2739 // Take highest priority transaction off priority queue |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2740 double dPriority = -(*mapPriority.begin()).first; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2741 CTransaction& tx = *(*mapPriority.begin()).second; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2742 mapPriority.erase(mapPriority.begin()); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2743 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2744 // Size limits |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2745 unsigned int nTxSize = ::GetSerializeSize(tx, SER_NETWORK); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2746 if (nBlockSize + nTxSize >= MAX_BLOCK_SIZE_GEN) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2747 continue; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2748 int nTxSigOps = tx.GetSigOpCount(); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2749 if (nBlockSigOps + nTxSigOps >= MAX_BLOCK_SIGOPS) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2750 continue; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2751 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2752 // Transaction fee required depends on block size |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2753 bool fAllowFree = (nBlockSize + nTxSize < 4000 || CTransaction::AllowFree(dPriority)); |
638
6046cfa5296f
Separate required fee for relaying and creation
Pieter Wuille <pieter.wuille@gmail.com>
parents:
595
diff
changeset
|
2754 int64 nMinFee = tx.GetMinFee(nBlockSize, fAllowFree, true); |
575
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2755 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2756 // Connecting shouldn't fail due to dependency on other memory pool transactions |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2757 // because we're already processing them in order of dependency |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2758 map<uint256, CTxIndex> mapTestPoolTmp(mapTestPool); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2759 if (!tx.ConnectInputs(txdb, mapTestPoolTmp, CDiskTxPos(1,1,1), pindexPrev, nFees, false, true, nMinFee)) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2760 continue; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2761 swap(mapTestPool, mapTestPoolTmp); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2762 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2763 // Added |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2764 pblock->vtx.push_back(tx); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2765 nBlockSize += nTxSize; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2766 nBlockSigOps += nTxSigOps; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2767 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2768 // Add transactions that depend on this one to the priority queue |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2769 uint256 hash = tx.GetHash(); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2770 if (mapDependers.count(hash)) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2771 { |
595
e630bbb11629
make bitcoin include files more modular
Wladimir J. van der Laan <laanwj@gmail.com>
parents:
588
diff
changeset
|
2772 BOOST_FOREACH(COrphan* porphan, mapDependers[hash]) |
575
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2773 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2774 if (!porphan->setDependsOn.empty()) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2775 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2776 porphan->setDependsOn.erase(hash); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2777 if (porphan->setDependsOn.empty()) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2778 mapPriority.insert(make_pair(-porphan->dPriority, porphan->ptx)); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2779 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2780 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2781 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2782 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2783 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2784 pblock->vtx[0].vout[0].nValue = GetBlockValue(pindexPrev->nHeight+1, nFees); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2785 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2786 // Fill in header |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2787 pblock->hashPrevBlock = pindexPrev->GetBlockHash(); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2788 pblock->hashMerkleRoot = pblock->BuildMerkleTree(); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2789 pblock->nTime = max(pindexPrev->GetMedianTimePast()+1, GetAdjustedTime()); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2790 pblock->nBits = GetNextWorkRequired(pindexPrev); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2791 pblock->nNonce = 0; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2792 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2793 return pblock.release(); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2794 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2795 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2796 |
941
e6547ebc0bd1
Bugfix: Use timestamp in coinbase rather than "bits", needed to ensure coinbase txn is unique even if address is the same
Luke Dashjr <luke-jr+git@utopios.org>
parents:
939
diff
changeset
|
2797 void IncrementExtraNonce(CBlock* pblock, CBlockIndex* pindexPrev, unsigned int& nExtraNonce) |
575
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2798 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2799 // Update nExtraNonce |
939
26f82de9f2cc
Merge branch 'getwork_dedupe' into unique_coinbase
Luke Dashjr <luke-jr+git@utopios.org>
parents:
871
diff
changeset
|
2800 static uint256 hashPrevBlock; |
26f82de9f2cc
Merge branch 'getwork_dedupe' into unique_coinbase
Luke Dashjr <luke-jr+git@utopios.org>
parents:
871
diff
changeset
|
2801 if (hashPrevBlock != pblock->hashPrevBlock) |
575
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2802 { |
939
26f82de9f2cc
Merge branch 'getwork_dedupe' into unique_coinbase
Luke Dashjr <luke-jr+git@utopios.org>
parents:
871
diff
changeset
|
2803 nExtraNonce = 0; |
26f82de9f2cc
Merge branch 'getwork_dedupe' into unique_coinbase
Luke Dashjr <luke-jr+git@utopios.org>
parents:
871
diff
changeset
|
2804 hashPrevBlock = pblock->hashPrevBlock; |
575
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2805 } |
939
26f82de9f2cc
Merge branch 'getwork_dedupe' into unique_coinbase
Luke Dashjr <luke-jr+git@utopios.org>
parents:
871
diff
changeset
|
2806 ++nExtraNonce; |
941
e6547ebc0bd1
Bugfix: Use timestamp in coinbase rather than "bits", needed to ensure coinbase txn is unique even if address is the same
Luke Dashjr <luke-jr+git@utopios.org>
parents:
939
diff
changeset
|
2807 pblock->vtx[0].vin[0].scriptSig = CScript() << pblock->nTime << CBigNum(nExtraNonce); |
575
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2808 pblock->hashMerkleRoot = pblock->BuildMerkleTree(); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2809 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2810 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2811 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2812 void FormatHashBuffers(CBlock* pblock, char* pmidstate, char* pdata, char* phash1) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2813 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2814 // |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2815 // Prebuild hash buffers |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2816 // |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2817 struct |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2818 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2819 struct unnamed2 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2820 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2821 int nVersion; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2822 uint256 hashPrevBlock; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2823 uint256 hashMerkleRoot; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2824 unsigned int nTime; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2825 unsigned int nBits; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2826 unsigned int nNonce; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2827 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2828 block; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2829 unsigned char pchPadding0[64]; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2830 uint256 hash1; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2831 unsigned char pchPadding1[64]; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2832 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2833 tmp; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2834 memset(&tmp, 0, sizeof(tmp)); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2835 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2836 tmp.block.nVersion = pblock->nVersion; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2837 tmp.block.hashPrevBlock = pblock->hashPrevBlock; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2838 tmp.block.hashMerkleRoot = pblock->hashMerkleRoot; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2839 tmp.block.nTime = pblock->nTime; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2840 tmp.block.nBits = pblock->nBits; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2841 tmp.block.nNonce = pblock->nNonce; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2842 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2843 FormatHashBlocks(&tmp.block, sizeof(tmp.block)); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2844 FormatHashBlocks(&tmp.hash1, sizeof(tmp.hash1)); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2845 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2846 // Byte swap all the input buffer |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2847 for (int i = 0; i < sizeof(tmp)/4; i++) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2848 ((unsigned int*)&tmp)[i] = ByteReverse(((unsigned int*)&tmp)[i]); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2849 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2850 // Precalc the first half of the first hash, which stays constant |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2851 SHA256Transform(pmidstate, &tmp.block, pSHA256InitState); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2852 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2853 memcpy(pdata, &tmp.block, 128); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2854 memcpy(phash1, &tmp.hash1, 64); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2855 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2856 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2857 |
690 | 2858 bool CheckWork(CBlock* pblock, CWallet& wallet, CReserveKey& reservekey) |
575
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2859 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2860 uint256 hash = pblock->GetHash(); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2861 uint256 hashTarget = CBigNum().SetCompact(pblock->nBits).getuint256(); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2862 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2863 if (hash > hashTarget) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2864 return false; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2865 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2866 //// debug print |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2867 printf("BitcoinMiner:\n"); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2868 printf("proof-of-work found \n hash: %s \ntarget: %s\n", hash.GetHex().c_str(), hashTarget.GetHex().c_str()); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2869 pblock->print(); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2870 printf("%s ", DateTimeStrFormat("%x %H:%M", GetTime()).c_str()); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2871 printf("generated %s\n", FormatMoney(pblock->vtx[0].vout[0].nValue).c_str()); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2872 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2873 // Found a solution |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2874 CRITICAL_BLOCK(cs_main) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2875 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2876 if (pblock->hashPrevBlock != hashBestChain) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2877 return error("BitcoinMiner : generated block is stale"); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2878 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2879 // Remove key from key pool |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2880 reservekey.KeepKey(); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2881 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2882 // Track how many getdata requests this block gets |
690 | 2883 CRITICAL_BLOCK(wallet.cs_mapRequestCount) |
2884 wallet.mapRequestCount[pblock->GetHash()] = 0; | |
575
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2885 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2886 // Process this block the same as if we had received it from another node |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2887 if (!ProcessBlock(NULL, pblock)) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2888 return error("BitcoinMiner : ProcessBlock, block not accepted"); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2889 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2890 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2891 Sleep(2000); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2892 return true; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2893 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2894 |
690 | 2895 void static ThreadBitcoinMiner(void* parg); |
2896 | |
2897 void static BitcoinMiner(CWallet *pwallet) | |
575
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2898 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2899 printf("BitcoinMiner started\n"); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2900 SetThreadPriority(THREAD_PRIORITY_LOWEST); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2901 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2902 // Each thread has its own key and counter |
690 | 2903 CReserveKey reservekey(pwallet); |
575
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2904 unsigned int nExtraNonce = 0; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2905 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2906 while (fGenerateBitcoins) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2907 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2908 if (AffinityBugWorkaround(ThreadBitcoinMiner)) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2909 return; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2910 if (fShutdown) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2911 return; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2912 while (vNodes.empty() || IsInitialBlockDownload()) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2913 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2914 Sleep(1000); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2915 if (fShutdown) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2916 return; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2917 if (!fGenerateBitcoins) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2918 return; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2919 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2920 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2921 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2922 // |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2923 // Create new block |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2924 // |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2925 unsigned int nTransactionsUpdatedLast = nTransactionsUpdated; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2926 CBlockIndex* pindexPrev = pindexBest; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2927 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2928 auto_ptr<CBlock> pblock(CreateNewBlock(reservekey)); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2929 if (!pblock.get()) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2930 return; |
941
e6547ebc0bd1
Bugfix: Use timestamp in coinbase rather than "bits", needed to ensure coinbase txn is unique even if address is the same
Luke Dashjr <luke-jr+git@utopios.org>
parents:
939
diff
changeset
|
2931 IncrementExtraNonce(pblock.get(), pindexPrev, nExtraNonce); |
575
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2932 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2933 printf("Running BitcoinMiner with %d transactions in block\n", pblock->vtx.size()); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2934 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2935 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2936 // |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2937 // Prebuild hash buffers |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2938 // |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2939 char pmidstatebuf[32+16]; char* pmidstate = alignup<16>(pmidstatebuf); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2940 char pdatabuf[128+16]; char* pdata = alignup<16>(pdatabuf); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2941 char phash1buf[64+16]; char* phash1 = alignup<16>(phash1buf); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2942 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2943 FormatHashBuffers(pblock.get(), pmidstate, pdata, phash1); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2944 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2945 unsigned int& nBlockTime = *(unsigned int*)(pdata + 64 + 4); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2946 unsigned int& nBlockNonce = *(unsigned int*)(pdata + 64 + 12); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2947 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2948 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2949 // |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2950 // Search |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2951 // |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2952 int64 nStart = GetTime(); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2953 uint256 hashTarget = CBigNum().SetCompact(pblock->nBits).getuint256(); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2954 uint256 hashbuf[2]; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2955 uint256& hash = *alignup<16>(hashbuf); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2956 loop |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2957 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2958 unsigned int nHashesDone = 0; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2959 unsigned int nNonceFound; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2960 |
576
8ec6d5e778e5
Manual merge of jaromil's source tree reorg commit.
Jeff Garzik <jeff@garzik.org>
parents:
575
diff
changeset
|
2961 // Crypto++ SHA-256 |
8ec6d5e778e5
Manual merge of jaromil's source tree reorg commit.
Jeff Garzik <jeff@garzik.org>
parents:
575
diff
changeset
|
2962 nNonceFound = ScanHash_CryptoPP(pmidstate, pdata + 64, phash1, |
8ec6d5e778e5
Manual merge of jaromil's source tree reorg commit.
Jeff Garzik <jeff@garzik.org>
parents:
575
diff
changeset
|
2963 (char*)&hash, nHashesDone); |
575
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2964 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2965 // Check if something found |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2966 if (nNonceFound != -1) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2967 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2968 for (int i = 0; i < sizeof(hash)/4; i++) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2969 ((unsigned int*)&hash)[i] = ByteReverse(((unsigned int*)&hash)[i]); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2970 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2971 if (hash <= hashTarget) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2972 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2973 // Found a solution |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2974 pblock->nNonce = ByteReverse(nNonceFound); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2975 assert(hash == pblock->GetHash()); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2976 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2977 SetThreadPriority(THREAD_PRIORITY_NORMAL); |
690 | 2978 CheckWork(pblock.get(), *pwalletMain, reservekey); |
575
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2979 SetThreadPriority(THREAD_PRIORITY_LOWEST); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2980 break; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2981 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2982 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2983 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2984 // Meter hashes/sec |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2985 static int64 nHashCounter; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2986 if (nHPSTimerStart == 0) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2987 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2988 nHPSTimerStart = GetTimeMillis(); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2989 nHashCounter = 0; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2990 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2991 else |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2992 nHashCounter += nHashesDone; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2993 if (GetTimeMillis() - nHPSTimerStart > 4000) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2994 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2995 static CCriticalSection cs; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2996 CRITICAL_BLOCK(cs) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2997 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2998 if (GetTimeMillis() - nHPSTimerStart > 4000) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
2999 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
3000 dHashesPerSec = 1000.0 * nHashCounter / (GetTimeMillis() - nHPSTimerStart); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
3001 nHPSTimerStart = GetTimeMillis(); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
3002 nHashCounter = 0; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
3003 string strStatus = strprintf(" %.0f khash/s", dHashesPerSec/1000.0); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
3004 UIThreadCall(boost::bind(CalledSetStatusBar, strStatus, 0)); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
3005 static int64 nLogTime; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
3006 if (GetTime() - nLogTime > 30 * 60) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
3007 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
3008 nLogTime = GetTime(); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
3009 printf("%s ", DateTimeStrFormat("%x %H:%M", GetTime()).c_str()); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
3010 printf("hashmeter %3d CPUs %6.0f khash/s\n", vnThreadsRunning[3], dHashesPerSec/1000.0); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
3011 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
3012 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
3013 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
3014 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
3015 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
3016 // Check for stop or if block needs to be rebuilt |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
3017 if (fShutdown) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
3018 return; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
3019 if (!fGenerateBitcoins) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
3020 return; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
3021 if (fLimitProcessors && vnThreadsRunning[3] > nLimitProcessors) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
3022 return; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
3023 if (vNodes.empty()) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
3024 break; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
3025 if (nBlockNonce >= 0xffff0000) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
3026 break; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
3027 if (nTransactionsUpdated != nTransactionsUpdatedLast && GetTime() - nStart > 60) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
3028 break; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
3029 if (pindexPrev != pindexBest) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
3030 break; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
3031 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
3032 // Update nTime every few seconds |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
3033 pblock->nTime = max(pindexPrev->GetMedianTimePast()+1, GetAdjustedTime()); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
3034 nBlockTime = ByteReverse(pblock->nTime); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
3035 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
3036 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
3037 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
3038 |
690 | 3039 void static ThreadBitcoinMiner(void* parg) |
575
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
3040 { |
690 | 3041 CWallet* pwallet = (CWallet*)parg; |
689
9df222fa1ef1
move wallet code to separate file
Pieter Wuille <pieter.wuille@gmail.com>
parents:
688
diff
changeset
|
3042 try |
575
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
3043 { |
689
9df222fa1ef1
move wallet code to separate file
Pieter Wuille <pieter.wuille@gmail.com>
parents:
688
diff
changeset
|
3044 vnThreadsRunning[3]++; |
690 | 3045 BitcoinMiner(pwallet); |
689
9df222fa1ef1
move wallet code to separate file
Pieter Wuille <pieter.wuille@gmail.com>
parents:
688
diff
changeset
|
3046 vnThreadsRunning[3]--; |
9df222fa1ef1
move wallet code to separate file
Pieter Wuille <pieter.wuille@gmail.com>
parents:
688
diff
changeset
|
3047 } |
9df222fa1ef1
move wallet code to separate file
Pieter Wuille <pieter.wuille@gmail.com>
parents:
688
diff
changeset
|
3048 catch (std::exception& e) { |
9df222fa1ef1
move wallet code to separate file
Pieter Wuille <pieter.wuille@gmail.com>
parents:
688
diff
changeset
|
3049 vnThreadsRunning[3]--; |
9df222fa1ef1
move wallet code to separate file
Pieter Wuille <pieter.wuille@gmail.com>
parents:
688
diff
changeset
|
3050 PrintException(&e, "ThreadBitcoinMiner()"); |
9df222fa1ef1
move wallet code to separate file
Pieter Wuille <pieter.wuille@gmail.com>
parents:
688
diff
changeset
|
3051 } catch (...) { |
9df222fa1ef1
move wallet code to separate file
Pieter Wuille <pieter.wuille@gmail.com>
parents:
688
diff
changeset
|
3052 vnThreadsRunning[3]--; |
9df222fa1ef1
move wallet code to separate file
Pieter Wuille <pieter.wuille@gmail.com>
parents:
688
diff
changeset
|
3053 PrintException(NULL, "ThreadBitcoinMiner()"); |
575
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
3054 } |
689
9df222fa1ef1
move wallet code to separate file
Pieter Wuille <pieter.wuille@gmail.com>
parents:
688
diff
changeset
|
3055 UIThreadCall(boost::bind(CalledSetStatusBar, "", 0)); |
9df222fa1ef1
move wallet code to separate file
Pieter Wuille <pieter.wuille@gmail.com>
parents:
688
diff
changeset
|
3056 nHPSTimerStart = 0; |
9df222fa1ef1
move wallet code to separate file
Pieter Wuille <pieter.wuille@gmail.com>
parents:
688
diff
changeset
|
3057 if (vnThreadsRunning[3] == 0) |
9df222fa1ef1
move wallet code to separate file
Pieter Wuille <pieter.wuille@gmail.com>
parents:
688
diff
changeset
|
3058 dHashesPerSec = 0; |
9df222fa1ef1
move wallet code to separate file
Pieter Wuille <pieter.wuille@gmail.com>
parents:
688
diff
changeset
|
3059 printf("ThreadBitcoinMiner exiting, %d threads remaining\n", vnThreadsRunning[3]); |
9df222fa1ef1
move wallet code to separate file
Pieter Wuille <pieter.wuille@gmail.com>
parents:
688
diff
changeset
|
3060 } |
9df222fa1ef1
move wallet code to separate file
Pieter Wuille <pieter.wuille@gmail.com>
parents:
688
diff
changeset
|
3061 |
9df222fa1ef1
move wallet code to separate file
Pieter Wuille <pieter.wuille@gmail.com>
parents:
688
diff
changeset
|
3062 |
690 | 3063 void GenerateBitcoins(bool fGenerate, CWallet* pwallet) |
689
9df222fa1ef1
move wallet code to separate file
Pieter Wuille <pieter.wuille@gmail.com>
parents:
688
diff
changeset
|
3064 { |
9df222fa1ef1
move wallet code to separate file
Pieter Wuille <pieter.wuille@gmail.com>
parents:
688
diff
changeset
|
3065 if (fGenerateBitcoins != fGenerate) |
575
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
3066 { |
689
9df222fa1ef1
move wallet code to separate file
Pieter Wuille <pieter.wuille@gmail.com>
parents:
688
diff
changeset
|
3067 fGenerateBitcoins = fGenerate; |
690 | 3068 WriteSetting("fGenerateBitcoins", fGenerateBitcoins); |
689
9df222fa1ef1
move wallet code to separate file
Pieter Wuille <pieter.wuille@gmail.com>
parents:
688
diff
changeset
|
3069 MainFrameRepaint(); |
575
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
3070 } |
689
9df222fa1ef1
move wallet code to separate file
Pieter Wuille <pieter.wuille@gmail.com>
parents:
688
diff
changeset
|
3071 if (fGenerateBitcoins) |
575
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
3072 { |
689
9df222fa1ef1
move wallet code to separate file
Pieter Wuille <pieter.wuille@gmail.com>
parents:
688
diff
changeset
|
3073 int nProcessors = boost::thread::hardware_concurrency(); |
9df222fa1ef1
move wallet code to separate file
Pieter Wuille <pieter.wuille@gmail.com>
parents:
688
diff
changeset
|
3074 printf("%d processors\n", nProcessors); |
9df222fa1ef1
move wallet code to separate file
Pieter Wuille <pieter.wuille@gmail.com>
parents:
688
diff
changeset
|
3075 if (nProcessors < 1) |
9df222fa1ef1
move wallet code to separate file
Pieter Wuille <pieter.wuille@gmail.com>
parents:
688
diff
changeset
|
3076 nProcessors = 1; |
9df222fa1ef1
move wallet code to separate file
Pieter Wuille <pieter.wuille@gmail.com>
parents:
688
diff
changeset
|
3077 if (fLimitProcessors && nProcessors > nLimitProcessors) |
9df222fa1ef1
move wallet code to separate file
Pieter Wuille <pieter.wuille@gmail.com>
parents:
688
diff
changeset
|
3078 nProcessors = nLimitProcessors; |
9df222fa1ef1
move wallet code to separate file
Pieter Wuille <pieter.wuille@gmail.com>
parents:
688
diff
changeset
|
3079 int nAddThreads = nProcessors - vnThreadsRunning[3]; |
9df222fa1ef1
move wallet code to separate file
Pieter Wuille <pieter.wuille@gmail.com>
parents:
688
diff
changeset
|
3080 printf("Starting %d BitcoinMiner threads\n", nAddThreads); |
9df222fa1ef1
move wallet code to separate file
Pieter Wuille <pieter.wuille@gmail.com>
parents:
688
diff
changeset
|
3081 for (int i = 0; i < nAddThreads; i++) |
575
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
3082 { |
690 | 3083 if (!CreateThread(ThreadBitcoinMiner, pwallet)) |
689
9df222fa1ef1
move wallet code to separate file
Pieter Wuille <pieter.wuille@gmail.com>
parents:
688
diff
changeset
|
3084 printf("Error: CreateThread(ThreadBitcoinMiner) failed\n"); |
9df222fa1ef1
move wallet code to separate file
Pieter Wuille <pieter.wuille@gmail.com>
parents:
688
diff
changeset
|
3085 Sleep(10); |
575
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
3086 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
3087 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
3088 } |