Permalink
Browse files

Dramatic speed fix to blockchain wallet scan! 1.5s/wlt!

  • Loading branch information...
1 parent 52458bd commit be51a025f1e6f39ae89266914e81a8ff0acccc64 @etotheipi committed Dec 9, 2011
Showing with 51 additions and 27 deletions.
  1. +42 −0 cppForSwig/BlockUtils.cpp
  2. +4 −4 cppForSwig/BlockUtilsTest.cpp
  3. +3 −21 manuallyCreateTx.py
  4. +2 −2 swigPbeEngine.py
View
@@ -289,6 +289,48 @@ void BtcWallet::scanTx(TxRef & tx,
vector<bool> thisTxInIsOurs (tx.getNumTxIn(), false);
vector<bool> thisTxOutIsOurs(tx.getNumTxOut(), false);
+ // Since 99.99%+ of all transactions are not ours, let's do the
+ // fastest bulk filter possible, even though it will add
+ // redundant computation to the tx that are ours.
+ //
+ // TODO: We may even consider doing lower-level ops to pull
+ // out the exact information we need from the binary
+ // stream, and avoid constructing TxInRef/TxOutRef objs
+ for(uint32_t iin=0; iin<tx.getNumTxIn(); iin++)
+ {
+ // We have the txin, now check if it contains one of our TxOuts
+ if(txioMap_.find(tx.getTxInRef(iin).getOutPoint()) !=
+ txioMap_.end())
+ anyTxInIsOurs = true;
+ }
+ for(uint32_t iout=0; iout<tx.getNumTxOut(); iout++)
+ {
+ // Check our wallets to see if we have any output addresses
+ static TxOutRef txout;
+ txout = tx.getTxOutRef(iout);
+
+ // Make sure we capture the non-std scripts
+ if( txout.getScriptType() == TXOUT_SCRIPT_UNKNOWN )
+ {
+ for(uint32_t i=0; i<addrPtrVect_.size(); i++)
+ {
+ BtcAddress & thisAddr = *(addrPtrVect_[i]);
+ BinaryData const & addr20 = thisAddr.getAddrStr20();
+
+ if(txout.getScriptRef().find(thisAddr.getAddrStr20()) > -1)
+ scanNonStdTx(blknum, txIndex, tx, iout, thisAddr);
+ continue;
+ }
+ }
+
+ if( hasAddr(txout.getRecipientAddr()) )
+ anyTxOutIsOurs = true;
+ }
+
+
+ if( !anyTxOutIsOurs && !anyTxInIsOurs)
+ return;
+
///// LOOP OVER ALL ADDRESSES ////
for(uint32_t i=0; i<addrPtrVect_.size(); i++)
{
@@ -46,14 +46,14 @@ int main(void)
string blkfile("/home/alan/.bitcoin/blk0001.dat");
//string blkfile("C:/Documents and Settings/VBox/Application Data/Bitcoin/blk0001.dat");
- //printTestHeader("Read-and-Organize-Blockchain");
- //TestReadAndOrganizeChain(blkfile);
+ printTestHeader("Read-and-Organize-Blockchain");
+ TestReadAndOrganizeChain(blkfile);
//printTestHeader("Find-Non-Standard-Tx");
//TestFindNonStdTx(blkfile);
- //printTestHeader("Wallet-Relevant-Tx-Scan");
- //TestScanForWalletTx(blkfile);
+ printTestHeader("Wallet-Relevant-Tx-Scan");
+ TestScanForWalletTx(blkfile);
//printTestHeader("Blockchain-Reorg-Unit-Test");
//TestReorgBlockchain(blkfile);
View
@@ -36,7 +36,7 @@
# Figure out a *good* selection of TxOuts to use
-prelimSelection = PySelectCoins(utxoList, 4*recipValue, fee)
+prelimSelection = PySelectCoins(utxoList, recipValue, fee)
feeRecommended = calcMinSuggestedFees(prelimSelection, recipValue, fee)
pprintUnspentTxOutList(prelimSelection, 'Selected TxOuts for (tgt,fee)=(%s,%s)' % \
(coin2str(recipValue), coin2str(fee)))
@@ -45,26 +45,8 @@
# Construct the output addresses, with a random order
recipPairs = []
-recipPairs.append(['12irKW1XFSnnu6v5FevcC3wZ6hfvPmaEDQ', recipValue])
-recipPairs.append(['1PymCiNzubeTtJt47dqFdi31Zy9MAM1YZk', recipValue])
-recipPairs.append(['1H3Jbv99F7Ng8oiadCovvda17CGZ9EFkPM', recipValue])
-recipPairs.append(['16jN5NhB4eoUqFrSvuNnvDEc57oz6GRNi4', recipValue])
-recipPairs.append(['17aLXn2XHKH7nhwdCPaWmkY6jgr36zSjyz', recipValue])
-recipPairs.append(['1PjURhoxGr6cdK5YY5SyDDY2pQhEpbZdoK', recipValue])
-recipPairs.append(['1NgBFTvqM6FsooFtkvFgf7VxzRBdXKnxpR', recipValue])
-recipPairs.append(['176msrhhemi6q8DEdpBCoTQJvRCiGV5qEm', recipValue])
-recipPairs.append(['16FSHWWyUv6wzT9qpbi7tCaovf6XX7T9xN', recipValue])
-recipPairs.append([recipAddr, recipValue])
-recipPairs.append(['1JiLbGTrVNmk6BsePVQWmBiD7DFUDmMYXw', recipValue])
-recipPairs.append(['124DJWV7vYS8DUcVan4SXcGNAubopS1BHj', recipValue])
-recipPairs.append(['1PESigPSLwsvaQAQfCDDPZM21i9m8Vqt21', recipValue])
-recipPairs.append(['18i1rVZHMMXQwRxZuSrHZrpqUoejkV2Gh2', recipValue])
-recipPairs.append(['1PZjRprkrM93GVXNdJ5zu7C1p84weTovWj', recipValue])
-recipPairs.append(['14cKqt9e8QvgMaBrwbuykBjha1vXNtaj72', recipValue])
-recipPairs.append(['1QJUzen8xL7EyBTGnkDUX6fnoMX9TL1fU7', recipValue])
-recipPairs.append(['17iRBkToUTzDvVpXsNUT8usT6c6aEDe15R', recipValue])
-recipPairs.append(['1NVJS8DWLdrte45rc5oGvWyjrAe9y1rtFt', recipValue])
-recipPairs.append(['1MzxEf2Ck9XSC7U5y5DHQvMyPhL2UNcjSD', recipValue])
+recipPairs.append(['16FSHWWyUv6wzT9qpbi7tCaovf6XX7T9xN', long(recipValue/2)])
+recipPairs.append([recipAddr, long(recipValue/2)])
#pair1 = [recipAddr, recipValue]
#pair2 = [pywlt.getAddrByIndex(0), sumTxOutList(prelimSelection)-(recipValue+fee)]
#if random.uniform(0,1) < 0.5:
View
@@ -413,8 +413,8 @@ def __init__(self):
self.eofByte = 0
self.cppWallet = None # Mirror of PyBtcWallet in C++ object
self.cppInfo = {} # Extra info about each address to help sync
- self.kdfMethod = KdfRomix()
- self.cryptMethod = CryptoAES()
+ self.kdfMethod = None
+ self.cryptMethod = None
self.kdfKey = SecureBinaryData() # KdfKey is binary
# Other private-key info is in actual PyPrivateKey objects
self.privKeyGen = PyPrivateKey()

0 comments on commit be51a02

Please sign in to comment.