Commit graph

419 commits

Author SHA1 Message Date
Gavin Andresen 8b83e2fc2e Merge pull request #2074 from sipa/minor
Two minor inconvenience fixes
2012-12-12 09:10:44 -08:00
Richard Schwab 303b0009dc Change timestamps to use ISO8601 formatting 2012-12-12 16:32:22 +01:00
Pieter Wuille 622da5df6e Merge pull request #2068 from Diapolo/CheckDiskSpace
some CheckDiskSpace() related changes
2012-12-07 13:33:24 -08:00
Pieter Wuille 3fb9b99cca Allow lengthy block reconnections to be interrupted
When the coin database is out of date with the block database, the
best block in it is automatically switched to. This reconnection
process can take time, so allow it to be interrupted.

This also stops block connection as soon as shutdown is requested,
leading to a faster shutdown.
2012-12-06 22:04:59 +01:00
Pieter Wuille c8b2e4426b Update the block file counter in database when using -reindex
This problem is like earth (mostly harmless). After/during a
-reindex, it means the statistics about the last block file
reported in debug.log are always of blk00000.dat instead of the
last file. Apart from that, it means a few more database entries
need to be read when finding a file to append to the first time.
2012-12-06 22:04:58 +01:00
Pieter Wuille 89b7019be8 Reconstruct coins/ from scratch when missing. 2012-12-06 17:00:12 +01:00
Pieter Wuille d79775a04d Merge pull request #2057 from Diapolo/FlushBlockFile
FlushBlockFile(): check for valid FILE pointer
2012-12-06 01:35:36 -08:00
Pieter Wuille cd1391ae4d Merge pull request #2056 from sipa/fix_2052
Fixes for obscure mempool-checkpoint interaction
2012-12-05 14:15:17 -08:00
Pieter Wuille 8a28bb6dee Add -benchmark for reporting block processing times 2012-12-05 23:06:01 +01:00
Pieter Wuille a485c1b69e Merge pull request #2063 from Diapolo/CDiskBlockPos
add 2 constructors in CDiskBlockPos to simplify class usage
2012-12-05 14:01:03 -08:00
Philip Kaufmann fa45c26a0e call CheckDiskSpace() before pre-allocating space
- even if we are allowed to fail pre-allocating, it's better to check
  for sufficient space before calling AllocateFileRange() and if we
  are out of disk space return with error()
- the above change allows us to remove the CheckDiskSpace() check
  in CBlock::AcceptBlock()
2012-12-05 14:39:09 +01:00
Philip Kaufmann a8a4b9673e add 2 constructors in CDiskBlockPos to simplify class usage
- add a default-constructor, which simply calls SetNull() and a
  constructor to directly pass nFile and nPos
- change code to use that new constructors
2012-12-03 10:19:17 +01:00
Pieter Wuille d33a9218ab Make SetBestChain() atomic
In case a reorganisation fails, the internal state could become
inconsistent (memory only). Previously, a cache per block connect
or disconnect action was used, so blocks could not be applied in
a partial way. Extend this to a cache for the entire reorganisation,
making it atomic entirely. This also simplifies the code a bit.
2012-12-02 01:43:35 +01:00
Philip Kaufmann b19388dd88 FlushBlockFile(): check for valid FILE pointer
- don't call FileCommit() and fclose() if no valid FILE pointer was
  returned by OpenBlockFile()
2012-12-01 11:36:53 +01:00
Pieter Wuille cd7fb7d1de Merge pull request #2033 from sipa/kickconflicts
Bugfix: remove conflicting transactions from memory pool
2012-11-30 17:10:07 -08:00
Pieter Wuille 8259c57321 Only send reorged txn to mempool after checkpoint 2012-12-01 02:09:41 +01:00
Gavin Andresen aaef016a07 Merge pull request #2037 from luke-jr/printpriority
Allow -printpriority without -debug
2012-11-30 16:16:59 -08:00
Pieter Wuille 038784b979 Enable script verification for reorganized mempool tx 2012-12-01 00:45:17 +01:00
Luke Dashjr 2646080e3d Allow -printpriority without -debug 2012-11-26 16:30:54 +00:00
Philip Kaufmann 5350ea4171 update CClientUIInterface and remove orphan Wx stuff
- fix ThreadSafeMessageBox always displays error icon
- allow to specify MSG_ERROR / MSG_WARNING or MSG_INFORMATION without a
  custom caption / title
- allow to specify CClientUIInterface::ICON_ERROR / ICON_WARNING and
  ICON_INFORMATION (which is default) as message box icon
- remove CClientUIInterface::OK from ThreadSafeMessageBox-calls, as
  the OK button will be set as default, if none is specified
- prepend "Bitcoin - " to used captions
- rename BitcoinGUI::error() -> BitcoinGUI::message() and add function
  documentation
- change all style parameters and enum flags to unsigned
- update code to use that new API

- update Client- and WalletModel to use new BitcoinGUI::message() and
  rename the classes error() method into message()
- include the possibility to supply the wanted icon for messages from
  Client- and WalletModel via "style" parameter
2012-11-26 13:32:31 +01:00
Pieter Wuille 231b399952 Bugfix: remove conflicting transactions from memory pool
When a transaction A is in the memory pool, while a transaction B
(which shares an input with A) gets accepted into a block, A was
kept forever in the memory pool.

This commit adds a CTxMemPool::removeConflicts method, which
removes transactions that conflict with a given transaction, and
all their children.

This results in less transactions in the memory pool, and faster
construction of new blocks.
2012-11-25 11:50:35 +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
Pieter Wuille c07a1a6ee4 Merge pull request #1980 from sipa/noreorgsame
Do not reorganize if new branch has same amount of work
2012-11-22 13:33:03 -08:00
Philip Kaufmann 11406c89fe ConnectBlock(): fix error() format to be unsigned
- I introduced the wrong format macro with my former patch (#2018), this
  needs to be signed not unsigned (thanks Luke-Jr)
2012-11-17 09:57:58 +01:00
Philip Kaufmann 42152c3da9 ensure we use our format macros to avoid compilation warnings
- fixes 2 warnings I observed while compiling on Windows with MinGW
2012-11-16 08:29:47 +01:00
Jeff Garzik 3ef292dc7d Merge pull request #1670 from luke-jr/blksubstr
Use full block hash as unique identifier in debug.log
2012-11-15 18:47:07 -08:00
Jeff Garzik 824e196054 Merge pull request #2005 from Diapolo/fixes_main
some small fixes for main.cpp/.h
2012-11-15 18:20:35 -08:00
Jeff Garzik a0bf93b809 Merge pull request #2012 from luke-jr/invblk_errs
Print error for coinbase-pays-too-much case of ConnectBlock failing
2012-11-15 18:18:55 -08: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 99d0d0f356 Introduce script verification flags
These flags select features to be enabled/disabled during script
evaluation/checking, instead of several booleans passed along.
Currently these flags are defined:
* SCRIPT_VERIFY_P2SH: enable BIP16-style subscript evaluation
* SCRIPT_VERIFY_STRICTENC: enforce strict adherence to pubkey/sig encoding standards.
2012-11-15 23:00:16 +01:00
Luke Dashjr 4ade04ddbd Print error for coinbase-pays-too-much case of ConnectBlock failing 2012-11-14 19:16:56 +00:00
Luke Dashjr f3a84c3a6b Abstract block hash substr extraction (for debug.log) into BlockHashStr inline 2012-11-13 21:18:32 +00:00
Philip Kaufmann 13e5cce4c3 some small fixes for main.cpp/.h
- remove an unwanted ";" at the end of the ~CCoinsView() destructor
- in FindBlockPos() and FindUndoPos() only call fclose(), is file is open
- fix an error string in the CBlockUndo class
2012-11-11 13:16:42 +01:00
Philip Kaufmann b56585d067 fix some missing indentations in main.cpp for better readability 2012-11-10 14:26:34 +01:00
Pieter Wuille 7fea484674 Add -reindex, to perform in-place reindexing of block chain files
Flushes the blktree/ and coins/ databases, and reindexes the
block chain files, as if their contents was loaded via -loadblock.

Based on earlier work by Jeff Garzik.
2012-11-09 01:06:32 +01:00
Pieter Wuille 7a5b7535bf Move ThreadImport to init.cpp 2012-11-09 01:06:32 +01:00
Pieter Wuille 05d9726805 LoadExternalBlockFile switched to CBufferedFile 2012-11-09 01:06:06 +01:00
Pieter Wuille cd6dc96c4f Do not reorganize if new branch has same amount of work 2012-11-05 21:24:11 +01:00
Pieter Wuille 1c83b0a377 Cache size optimizations 2012-11-04 18:06:25 +01:00
Pieter Wuille 28982cc9dc Remove P2SH transition code: P2SH violations may cause DoS trigger 2012-10-29 00:41:39 +01:00
Pieter Wuille 344620e953 Merge pull request #1904 from laanwj/2012_10_remove_getorder
remove "checkorder" P2P command
2012-10-25 11:41:22 -07:00
Pieter Wuille 66444558a5 Merge pull request #1953 from gmaxwell/createnewblock-race
Fixes a race condition in CreateNewBlock and a future null deref on testnet.
2012-10-25 11:30:51 -07:00
Wladimir J. van der Laan 1f7c5c5a3e Merge pull request #1926 from laanwj/2012_10_maindummybounds
Fix out-of-bounds read in main (issue #1924)
2012-10-25 06:12:10 -07:00
Wladimir J. van der Laan 62e21fb5d0 Show warning when using prerelease version
Implements #1948

- Add macro `CLIENT_VERSION_IS_RELEASE` to clientversion.h
- When running a prerelease (the above macro is `false`):
  - In UI, show an orange warning bar at the top. This will be used for other
    warnings (and alerts) as well, instead of the status bar.
  - For `bitcoind`, show the warning in the "errors" field in `getinfo`
    response.
2012-10-25 07:33:45 +02:00
Wladimir J. van der Laan 4fbad9124e Fix out-of-bounds read noticed by Ricardo Correia
Sizeof() returned the size of a pointer instead of the size of the buffer.
Fixes issue #1924.
2012-10-24 08:26:50 +02:00
Gregory Maxwell faff50d129 Fixes a race condition in CreateNewBlock and a future null deref on testnet.
CreateNewBlock was reading pindexBest at the start before taking the lock
so it was possible to have the the block content not match the prevheader
and this can also trigger a newly added assert in ConnectBlock.

I noticed this during a code review after twobitcoins reported that ab91bf39
(BIP30 for all blocks) could cause a null dereference on a modified node
that mined during the IBD, or on testnet when it reached heights 91842 and
91880 due to CreateNewBlock calling ConnectBlock with pindex->phashBlock NULL.
2012-10-24 02:13:03 -04:00
Pieter Wuille 4afc0b5411 Bugfix: actually use CCoinsViewMemPool 2012-10-23 01:43:33 +02:00
Pieter Wuille c2ed184f98 Added some comments
Some clarifications after a code review by Mike Hearn.
2012-10-23 00:27:17 +02:00
Pieter Wuille 1e64c2d585 Bugfix: off-by-one in priority calculation 2012-10-23 00:23:39 +02:00
Pieter Wuille 9e957fb3b1 Bugfix: add missing fee check 2012-10-23 00:23:39 +02:00
Pieter Wuille 56424040a4 Bugfix: off-by-one error in coinbase maturity check 2012-10-23 00:23:39 +02:00
Philip Kaufmann 729b180686 change blockchain -> block chain (spelling)
- Wiki says "block chain" is correct ;)
- remove some unneeded spaces I found in the source, while fixing the spelling
2012-10-21 21:32:25 +02:00
Philip Kaufmann 039bcbf12d remove init messages from ThreadImport()
- remove uiInterface.InitMessage() calls from ThreadImport(), as Qt
  doesn't like them getting called out of it's main thread and because the
  thread will continue to run after the GUI was loaded
2012-10-21 21:16:52 +02:00
Pieter Wuille beeb57610c Add gettxout and gettxoutsetinfo RPCs 2012-10-20 23:08:57 +02:00
Pieter Wuille 2d8a48292b LevelDB block and coin databases
Split off CBlockTreeDB and CCoinsViewDB into txdb-*.{cpp,h} files,
implemented by either LevelDB or BDB.

Based on code from earlier commits by Mike Hearn in his leveldb
branch.
2012-10-20 23:08:57 +02:00
Pieter Wuille 44d40f26dc Flush and sync block data 2012-10-20 23:08:57 +02:00
Pieter Wuille d979e6e36a Use singleton block tree database instance 2012-10-20 23:08:57 +02:00
Pieter Wuille 857c61df0b Prepare database format for multi-stage block processing
This commit adds a status field and a transaction counter to the block
indexes.
2012-10-20 23:08:57 +02:00
Pieter Wuille 13c51f20f6 Direct CCoins references
To prevent excessive copying of CCoins in and out of the CCoinsView
implementations, introduce a GetCoins() function in CCoinsViewCache
with returns a direct reference. The block validation and connection
logic is updated to require caching CCoinsViews, and exploits the
GetCoins() function heavily.
2012-10-20 23:08:57 +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
Pieter Wuille bba89aa82a Pre-allocate block and undo files in chunks
Introduce a AllocateFileRange() function in util, which wipes or
at least allocates a given range of a file. It can be overriden
by more efficient OS-dependent versions if necessary.

Block and undo files are now allocated in chunks of 16 and 1 MiB,
respectively.
2012-10-20 23:08:57 +02:00
Pieter Wuille 5382bcf8cd Multiple blocks per file
Change the block storage layer again, this time with multiple files
per block, but tracked by txindex.dat database entries. The file
format is exactly the same as the earlier blk00001.dat, but with
smaller files (128 MiB for now).

The database entries track how many bytes each block file already
uses, how many blocks are in it, which range of heights is present
and which range of dates.
2012-10-20 23:08:57 +02:00
Pieter Wuille 8adf48dc9b Preliminary undo file creation
Create files (one per block) with undo information for the transactions
in it.
2012-10-20 23:08:57 +02:00
Pieter Wuille 630fd8dcb6 One file per block
Refactor of the block storage code, which now stores one file per block.
This will allow easier pruning, as blocks can be removed individually.
2012-10-20 23:08:57 +02:00
Pieter Wuille 0fa593d0fb Compact serialization for amounts
Special serializer/deserializer for amount values. It is optimized for
values which have few non-zero digits in decimal representation. Most
amounts currently in the txout set take only 1 or 2 bytes to
represent.
2012-10-20 23:08:56 +02:00
Jeff Garzik 38ac953b9d Merge pull request #1880 from sipa/threadimport
Move external block import to separate thread
2012-10-20 13:36:36 -07:00
Jeff Garzik dee0ee2ac9 Merge pull request #1742 from sipa/canonical
Check for canonical public keys and signatures
2012-10-20 10:56:04 -07:00
Pieter Wuille 66b02c93e6 Move external block import to separate thread 2012-10-20 01:54:10 +02:00
Jeff Garzik de2b9459bd Merge pull request #1834 from jgarzik/kickblocks
P2P: Do not request blocks from peers with fewer blocks than us
2012-10-08 15:15:58 -07:00
Jeff Garzik b855abb8db Revert "Send 'mempool' P2P command at the start of each P2P session"
Fat-fingered on github, and merged this too early.

This reverts commit 22f9b06903.
2012-10-08 18:14:15 -04:00
Jeff Garzik 56caa38a67 Merge pull request #1833 from jgarzik/mempool-query
Send 'mempool' P2P command at the start of each P2P session
2012-10-08 15:12:25 -07:00
Wladimir J. van der Laan 529a4d4824 remove "checkorder" and "reply" P2P commands
These command are a leftover from send-to-IP transactions, which have been
removed a long time ago.
Also removes CNode::mapRequests and CNode::PushRequests, as these were
only used for the mentioned commands.
2012-10-03 20:09:33 +02:00
Philip Kaufmann d210f4f5b8 fix -Wformat warnings all over the source 2012-10-01 19:45:42 +02:00
Jeff Garzik 22f9b06903 Send 'mempool' P2P command at the start of each P2P session
to query remote node mempool contents.
2012-09-24 13:53:44 -04:00
Jeff Garzik 93dd68e924 P2P: Do not request blocks from peers with fewer blocks than us
If the remote node has a shorter chain, do not waste our
special getblocks request on them.
2012-09-24 13:26:09 -04:00
Pieter Wuille 58bc86e37f Check for canonical public keys and signatures
Only enabled inside tests for now.
2012-09-21 01:24:25 +02:00
Jeff Garzik b1d3e95a0a When rejected TX relay due to lack of fees, log full txid 2012-09-18 15:24:31 -04:00
Jeff Garzik f8c449b5c8 Merge pull request #1812 from jgarzik/misc-07
Two minor generic cleanups done during OP_DROP hacking
2012-09-18 09:14:53 -07:00
Gregory Maxwell ab91bf39b7 Apply BIP30 checks to all blocks except the two historic violations.
Matt pointed out some time ago that there existed a minor DOS
attack where a node in its initial block download could be wedged
by an overwrite attack in a fork created between checkpoints before
a time where BIP30 was enforced. Now that the BIP30 timestamp
is irreversibly past the check can be more aggressive and apply to
all blocks except the two historic violations.
2012-09-09 20:11:04 -04:00
Jeff Garzik 17f8d6e400 Improve debug logging, for mempool TXs that do not include sufficient fees 2012-09-09 17:05:26 -04:00
Jeff Garzik 76970091f1 Cosmetic: move CTransaction::GetMinFee out of header file 2012-09-09 17:01:18 -04:00
Gavin Andresen 91c218a1cb Merge branch 'testnet_alert' of git://github.com/gavinandresen/bitcoin-git 2012-09-05 11:38:38 -04:00
Philip Kaufmann 8d367c7e66 fix signed/unsigned usage in BlockFilePath() 2012-09-05 08:34:41 +02:00
Jeff Garzik 42613c97d5 Add block file naming helper, BlockFilePath() 2012-09-04 21:40:26 -04:00
Jeff Garzik bec02998b4 Merge pull request #1779 from xanatos/patch-15
Useless vector declaration
2012-09-04 08:59:05 -07:00
xanatos 89fbd1f11c Useless vector declaration
The vector isn't referenced in the small code block it's declared. I don't see any "useful" side effect in its declaration.
2012-09-03 17:53:27 +03:00
Wladimir J. van der Laan 4d1d94c56c Rename CreateThread to NewThread
Prevent clash with win32 API symbol
2012-08-29 20:25:37 +02:00
Gavin Andresen f35c6c4fb9 Refactor: move alert code from main to alert.cpp/h 2012-08-28 17:04:54 -04:00
Gavin Andresen ea2fda46c3 Special-case the last alert for alert-key-compromised case
Hard-code a special nId=max int alert, to be broadcast if the
alert key is ever compromised. It applies to all versions, never
expires, cancels all previous alerts, and has a fixed message:
   URGENT: Alert key compromised, upgrade required

Variations are not allowed (ignored), so an attacker with
the private key cannot broadcast empty-message nId=max alerts.
2012-08-27 10:22:57 -04:00
Gavin Andresen d5a52d9b3e Alert system DoS prevention
This fixes two alert system vulnerabilities found by
Sergio Lerner; you could send peers unlimited numbers
of invalid alert message to try to either fill up their
debug.log with messages and/or keep their CPU busy
checking signatures.

Fixed by disconnecting/banning peers if they send 10 or more
bad (invalid/expired/cancelled) alerts.
2012-08-26 17:08:18 -04:00
Pieter Wuille 65ce215641 Make 0-value outputs non-standard 2012-08-24 12:15:12 +02:00
Gregory Maxwell bdab0cf58c Avoid leaving return types or function attributes on their own lines. 2012-08-24 02:48:19 -04:00
Pieter Wuille 5c88e3c108 Do not accept orphan blocks in -loadblock mode 2012-08-21 19:18:53 +02:00
Gavin Andresen d18f2fd9d6 Reject block.nVersion<=1 blocks if network has upgraded to version=2
If 950 of the last 1,000 blocks are nVersion=2, reject nVersion=1
(or zero, but no bitcoin release has created block.nVersion=0) blocks
-- 75 of last 100 on testnet3.

This rule is being put in place now so that we don't have to go
through another "express support" process to get what we really
want, which is for every single new block to include the block height
in the coinbase.
2012-08-20 10:46:07 -04:00
Gavin Andresen de237cbfa4 Block height in coinbase as a new block rule
"Version 2" blocks are blocks that have nVersion=2 and
have the block height as the first item in their coinbase.
Block-height-in-the-coinbase is strictly enforced when
version=2 blocks are a supermajority in the block chain
(750 of the last 1,000 blocks on main net, 51 of 100 for
testnet). This does not affect old clients/miners at all,
which will continue producing nVersion=1 blocks, and
which will continue to be valid.
2012-08-20 10:46:07 -04:00
Jeff Garzik b3a570d158 Merge pull request #1641 from jgarzik/mempool
Add 'mempool' P2P command, and extend 'getdata' behavior
2012-08-20 07:21:34 -07:00
Jeff Garzik dabb95b892 Merge pull request #1678 from Diapolo/LoadExternalBlockFile_add_timer
log how long LoadExternalBlockFile() takes in ms (Benchmark)
2012-08-17 08:45:11 -07:00
Philip Kaufmann 1e7027b41e fix a compiler sign warning in OpenBlockFile() 2012-08-17 10:35:51 +02:00