diff options
author | Pieter Wuille <pieter.wuille@gmail.com> | 2012-07-01 18:54:00 +0200 |
---|---|---|
committer | Pieter Wuille <pieter.wuille@gmail.com> | 2012-10-20 23:08:57 +0200 |
commit | 450cbb0944cd20a06ce806e6679a1f4c83c50db2 (patch) | |
tree | 5c6fd4998dfcc81b5383ad490c1ffe53d372dec7 /src/db.h | |
parent | bba89aa82a80f0373dcb7288d96d5b0fcb453d73 (diff) |
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.
Diffstat (limited to 'src/db.h')
-rw-r--r-- | src/db.h | 40 |
1 files changed, 21 insertions, 19 deletions
@@ -17,10 +17,8 @@ class CAddress; class CAddrMan; class CBlockLocator; class CDiskBlockIndex; -class CDiskTxPos; class CMasterKey; class COutPoint; -class CTxIndex; class CWallet; class CWalletTx; @@ -316,39 +314,43 @@ public: -/** Access to the transaction database (blkindex.dat) */ -class CTxDB : public CDB +/** Access to the transaction database (coins.dat) */ +class CCoinsDB : public CDB { public: - CTxDB(const char* pszMode="r+") : CDB("blkindex.dat", pszMode) { } + CCoinsDB(const char* pszMode="r+") : CDB("coins.dat", pszMode) { } private: - CTxDB(const CTxDB&); - void operator=(const CTxDB&); + CCoinsDB(const CCoinsDB&); + void operator=(const CCoinsDB&); public: - bool ReadTxIndex(uint256 hash, CTxIndex& txindex); - bool UpdateTxIndex(uint256 hash, const CTxIndex& txindex); - bool AddTxIndex(const CTransaction& tx, const CDiskTxPos& pos, int nHeight); - bool EraseTxIndex(const CTransaction& tx); - bool ContainsTx(uint256 hash); - bool ReadDiskTx(uint256 hash, CTransaction& tx, CTxIndex& txindex); - bool ReadDiskTx(uint256 hash, CTransaction& tx); - bool ReadDiskTx(COutPoint outpoint, CTransaction& tx, CTxIndex& txindex); - bool ReadDiskTx(COutPoint outpoint, CTransaction& tx); - bool WriteBlockIndex(const CDiskBlockIndex& blockindex); + bool ReadCoins(uint256 hash, CCoins &coins); + bool WriteCoins(uint256 hash, const CCoins& coins); + bool HaveCoins(uint256 hash); bool ReadHashBestChain(uint256& hashBestChain); bool WriteHashBestChain(uint256 hashBestChain); +}; + +/** Access to the block database (chain.dat) */ +class CChainDB : public CDB +{ +public: + CChainDB(const char* pszMode="r+") : CDB("chain.dat", pszMode) { } +private: + CChainDB(const CChainDB&); + void operator=(const CChainDB&); +public: + bool WriteBlockIndex(const CDiskBlockIndex& blockindex); bool ReadBestInvalidWork(CBigNum& bnBestInvalidWork); bool WriteBestInvalidWork(CBigNum bnBestInvalidWork); bool ReadBlockFileInfo(int nFile, CBlockFileInfo &fileinfo); bool WriteBlockFileInfo(int nFile, const CBlockFileInfo &fileinfo); bool ReadLastBlockFile(int &nFile); bool WriteLastBlockFile(int nFile); - bool LoadBlockIndex(); -private: bool LoadBlockIndexGuts(); }; +bool LoadBlockIndex(CCoinsDB &coinsdb, CChainDB &chaindb); /** Access to the (IP) address database (peers.dat) */ |