Commit graph

169 commits

Author SHA1 Message Date
Jeff Garzik 8da9dd0725 Wallet: optimize rescan to skip blocks prior to birthday 2013-06-10 09:38:13 -04:00
Jeff Garzik 3869fb89b6 Wallet: store key creation time. Calculate whole-wallet birthday.
This also encapsulate wallet-read state information into CWalletScanState.
2013-06-10 09:36:29 -04:00
Eric Lombrozo 05df3fc68d Removed AcceptToMemoryPool method from CTransaction. This method belongs to the mempool instance.
Removed AreInputsStandard from CTransaction, made it a regular function in main.
Moved CTransaction::GetOutputFor to CCoinsViewCache.

Moved GetLegacySigOpCount and GetP2SHSigOpCount out of CTransaction into regular functions in main.

Moved GetValueIn and HaveInputs from CTransaction into CCoinsViewCache.

Moved AllowFree, ClientCheckInputs, CheckInputs, UpdateCoins, and CheckTransaction out of CTransaction and into main.

Moved IsStandard and IsFinal out of CTransaction and put them in main as IsStandardTx and IsFinalTx. Moved GetValueOut out of CTransaction into main. Moved CTxIn, CTxOut, and CTransaction into core.

Added minimum fee parameter to CTxOut::IsDust() temporarily until CTransaction is moved to core.h so that CTxOut needn't know about CTransaction.
2013-06-05 23:15:20 -07:00
Eric Lombrozo 788536f175 Moved CInPoint to core. Removed GetMinFee from CTransaction and made it a regular function in main. 2013-06-05 23:15:19 -07:00
Cory Fields 34994ebcb0 build: cosmetics after last commit 2013-06-04 03:54:14 -04:00
Cory Fields ee4b170c92 build: use runtime setting for wallet rather than QT_GUI define 2013-06-04 03:54:14 -04:00
Jeff Garzik d397715661 Merge pull request #2644 from sipa/constfindblock
Make FindBlockByHeight constant-time
2013-05-30 08:06:44 -07:00
Jeff Garzik 9c95a2e836 Merge pull request #2625 from gavinandresen/walletlock_asio
Use boost::asio::deadline_timer for walletpassphrase timeout
2013-05-30 08:01:22 -07:00
Pieter Wuille dfa23b94c2 CSecret/CKey -> CKey/CPubKey split/refactor 2013-05-30 05:20:21 +02:00
Pieter Wuille 0fe8010a10 Make FindBlockByHeight constant-time.
Remove the pnext pointer in CBlockIndex, and replace it with a
vBlockIndexByHeight vector (no effect on memory usage). pnext can
now be replaced by vBlockIndexByHeight[nHeight+1], but
FindBlockByHeight becomes constant-time.

This also means the entire mapBlockIndex structure and the block
index entries in it become purely blocktree-related data, and
independent from the currently active chain, potentially allowing
them to be protected by separate mutexes in the future.
2013-05-12 19:52:16 +02:00
Gavin Andresen 92f2c1fe0f Use boost::asio::deadline_timer for walletpassphrase timeout
New method in bitcoinrpc:  RunLater, that uses a map of deadline
timers to run a function later.

Behavior of walletpassphrase is changed; before, calling
walletpassphrase again before the lock timeout passed
would result in: Error: Wallet is already unlocked.

You would have to call lockwallet before walletpassphrase.

Now: the last walletpassphrase with correct password
wins, and overrides any previous timeout.

Fixes issue# 1961 which was caused by spawning too many threads.

Test plan:

Start with encrypted wallet, password 'foo'
NOTE:
 python -c 'import time; print("%d"%time.time())'
... will tell you current unix timestamp.

Try:

walletpassphrase foo 600
getinfo
EXPECT: unlocked_until is about 10 minutes in the future

walletpassphrase foo 1
sleep 2
sendtoaddress mun74Bvba3B1PF2YkrF4NsgcJwHXXh12LF 11
EXPECT: Error: Please enter the wallet passphrase with walletpassphrase first.

walletpassphrase foo 600
walletpassphrase foo 0
getinfo
EXPECT: wallet is locked (unlocked_until is 0)

walletpassphrase foo 10
walletpassphrase foo 600
getinfo
EXPECT: wallet is unlocked until 10 minutes in future

walletpassphrase foo 60
walletpassphrase bar 600
EXPECT: Error, incorrect passphrase
getinfo
EXPECT: wallet still scheduled to lock 60 seconds from first (successful) walletpassphrase
2013-05-07 11:47:33 -04:00
Gavin Andresen 33edd0a477 Merge pull request #2577 from gavinandresen/fee_bandaid
Treat dust outputs as non-standard, un-hardcode TX_FEE constants
2013-05-04 10:15:39 -07:00
Gavin Andresen 61a845dcb6 Merge pull request #2566 from sipa/nodef
Allow the default key to be unavailable
2013-05-03 14:33:02 -07:00
Gavin Andresen 000dc55181 Un-hardcode TX_FEE constants
Allow setting of MIN_TX_FEE / MIN_RELAY_TX_FEE with
-mintxfee / -mintxrelayfee

Default values are the same (0.0001 BTC).
2013-05-03 10:54:31 -04:00
Gavin Andresen 1f00f4e9c9 CreateTransaction: return strFailReason on failure 2013-05-03 10:54:31 -04:00
Gavin Andresen 8de9bb53af Define dust transaction outputs, and make them non-standard 2013-05-03 10:52:09 -04:00
Gavin Andresen 2f15e86a68 Do not write to wallet during LoadWallet
When debugging another issue, I found a hang-during-startup race condition due to
LoadWallet calling SetMinVersion (via LoadCryptedKey).

Writing to the file that you're in the process of reading is a bad idea.
2013-05-02 12:43:07 -04:00
Pieter Wuille 360cfe142c Allow the default key to be unavailable
This solves the issue where no default key can be added after -salvagewallet.
2013-04-25 19:36:10 +02:00
Gavin Andresen f158e363a4 Merge pull request #2478 from sipa/fullhash
Always print full hashes (tx, block, inv)
2013-04-09 10:57:16 -07:00
Gavin Andresen 1829134afe Merge pull request #2272 from gavinandresen/getbalancefix
Fix getbalance discrepency
2013-04-08 06:37:58 -07:00
Pieter Wuille 1c06aa98c6 Always print full hashes (tx, block, inv) 2013-04-07 03:43:55 +02:00
Gavin Andresen b31499ec72 Clean up shutdown process 2013-04-03 19:57:53 -04:00
Gavin Andresen aaeb443791 Merge pull request #2312 from gmaxwell/random_random
ApproximateBestSubset internal RNG to prevent degenerate behavior.
2013-02-22 08:57:38 -08:00
Gavin Andresen 49e332f6fc Merge pull request #1974 from kjj2/walletnotify
Add -walletnotify to call an external script on wallet transactions
2013-02-22 08:47:04 -08:00
Gregory Maxwell 907a2aa4c7 Internal RNG for approximateBestSubset to prevent degenerate behavior.
This fixes test_bitcoin failures on openbsd reported by dhill on IRC.

  On some systems rand() is a simple LCG over 2^31 and so it produces
an even-odd sequence.  ApproximateBestSubset was only using the least
significant bit and so every run of the iterative solver would be the
same for some inputs, resulting in some pretty dumb decisions.

Using something other than the least significant bit would paper over
the issue but who knows what other way a system's rand() might get us
here.  Instead we use an internal RNG with a period of something like
2^60 which is well behaved.  This also makes it possible to make the
selection deterministic for the tests, if we wanted to implement that.
2013-02-18 14:13:39 -08:00
Gavin Andresen 41e1a0d766 Make transactions larger than 100K non-standard
Extremely large transactions with lots of inputs can cost the network
almost as much to process as they cost the sender in fees.

We would never create transactions larger than 100K big; this change
makes transactions larger than 100K non-standard, so they are not
relayed/mined by default. This is most important for miners that might
create blocks larger than 250K big, who could be vulnerable to a
make-your-blocks-so-expensive-to-verify-they-get-orphaned attack.
2013-02-05 10:08:35 -05:00
Gavin Andresen d28bd8b7ca Fix getbalance discrepency
Two changes:

Use IsConfirmed() instead of IsFinal(), so 'getbalance "*" 0' uses the same
'is this output spendable' criteria as 'getbalance'. Fixes issue #172.

And a tiny refactor to CWallet::GetBalance() (redundant call to IsFinal -- IsConfirmed
calls IsFinal).
getbalance with no arguments and 'getbalance "*" 0' could return different different results,
2013-02-04 14:04:26 -05:00
Gavin Andresen ac7b8ea086 Correctly randomize change output position 2013-01-30 13:56:35 -05:00
Gavin Andresen 434fa60d75 Merge pull request #2182 from gavinandresen/addressoracle
Remove IsFromMe() check in CTxMemPool::accept()
2013-01-26 11:27:48 -08:00
Gregory Maxwell d40c164369 Merge pull request #1872 from gmaxwell/listaddrnotmine
In listaddressgroupings push down the IsMine check to run on each input.
2013-01-21 16:30:34 -08:00
Matt Corallo 269d9c6492 Replace RelayMessage with RelayTransaction. 2013-01-16 12:48:02 -05:00
Gavin Andresen ce99358f4a Remove IsFromMe() check in CTxMemPool::accept()
Fixes issue #2178 : attacker could penny-flood with invalid-signature
transactions to deduce which addresses belonged to your node.

I'm committing this early for code review; I still need to write up
a test plan.

Executive summary of fix: check all transactions received from the network
for penny-flood rate-limiting before adding to the memory pool. But do NOT
ratelimit transactions added to the memory pool:
  - because of blockchain reorgs
  - stored in the wallet and added at startup
  - sent from the GUI or one of the send* RPC commands (CWallet::CommitTransaction)

The limit-free-transactions code really should be a method on CNode, with
counters per-peer. But that is a bigger change for another day.
2013-01-15 09:10:22 -05:00
Gregory Maxwell d7836552e6 If the prio. will be enough after the next block don't force fees.
If the user was really after the fastest possible confirmation times
they would be manually setting a fee. In cases where the wallet builds
a transaction with a priority that is too low to qualify as free until
the next block, go ahead without a fee.  Confirmation frequently takes
multiple blocks even when a minimum fee is provided.
2012-12-26 14:16:45 -05:00
Gregory Maxwell a3fad2119b In listaddressgroupings push down the IsMine check to run on each input.
This avoids a potential crash when trying to read the scrippubkeys on
transactions where the first input IsMine but some of the rest are not
when running listaddressgroupings.
2012-12-14 07:35:56 -05:00
Gavin Andresen 78504bb04f Merge pull request #1861 from jgarzik/coinlock
Add new RPC "lockunspent", to prevent spending of selected outputs
2012-12-12 09:15:43 -08:00
Philip Kaufmann 15d8ff2029 rework ThreadSafeAskFee() / askFee() functions
- remove unused parameter from ThreadSafeAskFee(), which also results in
  the removal of an orphan translation-string
2012-12-04 21:35:41 +01:00
Pieter Wuille 7818d230a2 Merge pull request #2013 from sipa/blockheader
Split off CBlockHeader from CBlock
2012-11-24 13:54:12 -08:00
Gavin Andresen e45d39f9ee Merge pull request #2009 from sipa/fixmove
Prevent RPC 'move' from deadlocking
2012-11-16 08:09:41 -08:00
Jeff Garzik fdbb537d26 Add new RPC "lockunspent", to prevent spending of selected outputs
and associated RPC "listlockunspent".

This is a memory-only filter, which is empty when a node restarts.
2012-11-15 21:11:30 -05:00
Pieter Wuille e754cf4133 Split off CBlockHeader from CBlock
Cleaner and removes the need for the application-specific flags in
serialize.h.
2012-11-16 00:12:33 +01:00
Pieter Wuille 4291e8feab Prevent RPC 'move' from deadlocking
It seemed to create two CWalletDB objects that both grab the
database lock.
2012-11-14 00:31:56 +01:00
Philip Kaufmann 966a0e8cc9 add CWalletTx::GetImmatureCredit() and use it in CWallet::GetImmatureBalance() 2012-11-13 07:56:48 +01:00
Wladimir J. van der Laan 86406daeca Merge pull request #1830 from Diapolo/trans_rem_spaces
fix some double-spaces in strings
2012-11-04 23:34:57 -08:00
kjj2 cae686d31e Add -walletnotify to call an external script on wallet transactions 2012-11-03 10:07:57 -05:00
Pieter Wuille 5eaf91a428 Bugfix: do not keep relaying spent wallet transactions
The original test (checking whether the transaction occurs in the
txindex) is not usable anymore, as it will miss anything already
fully spent. However, as merkle transactions (and by extension,
wallet transactions) track which block they were last seen being
included in, we can use that to determine the need for
rebroadcasting.
2012-11-01 18:06:29 +01:00
Philip Kaufmann 6b3783a9c9 fix some double-spaces in strings
- remove some unneeded stuff in sendcoinsentry.ui
- harmonize some "Error:"-messages
2012-10-25 22:25:50 +02:00
Pieter Wuille ddba582377 Bugfix: do not mark all future coins spent 2012-10-21 15:19:19 +02:00
Pieter Wuille 64dd46fd05 Transaction hash caching
Use CBlock's vMerkleTree to cache transaction hashes, and pass them
along as argument in more function calls. During initial block download,
this results in every transaction's hash to be only computed once.
2012-10-20 23:08:57 +02:00
Pieter Wuille ae8bfd12da Batch block connection during IBD
During the initial block download (or -loadblock), delay connection
of new blocks a bit, and perform them in a single action. This reduces
the load on the database engine, as subsequent blocks often update an
earlier block's transaction already.
2012-10-20 23:08:57 +02:00
Pieter Wuille 450cbb0944 Ultraprune
This switches bitcoin's transaction/block verification logic to use a
"coin database", which contains all unredeemed transaction output scripts,
amounts and heights.

The name ultraprune comes from the fact that instead of a full transaction
index, we only (need to) keep an index with unspent outputs. For now, the
blocks themselves are kept as usual, although they are only necessary for
serving, rescanning and reorganizing.

The basic datastructures are CCoins (representing the coins of a single
transaction), and CCoinsView (representing a state of the coins database).
There are several implementations for CCoinsView. A dummy, one backed by
the coins database (coins.dat), one backed by the memory pool, and one
that adds a cache on top of it. FetchInputs, ConnectInputs, ConnectBlock,
DisconnectBlock, ... now operate on a generic CCoinsView.

The block switching logic now builds a single cached CCoinsView with
changes to be committed to the database before any changes are made.
This means no uncommitted changes are ever read from the database, and
should ease the transition to another database layer which does not
support transactions (but does support atomic writes), like LevelDB.

For the getrawtransaction() RPC call, access to a txid-to-disk index
would be preferable. As this index is not necessary or even useful
for any other part of the implementation, it is not provided. Instead,
getrawtransaction() uses the coin database to find the block height,
and then scans that block to find the requested transaction. This is
slow, but should suffice for debug purposes.
2012-10-20 23:08:57 +02:00