Class LevelDBFullPrunedBlockStore
- java.lang.Object
 - 
- org.bitcoinj.store.LevelDBFullPrunedBlockStore
 
 
- 
- All Implemented Interfaces:
 UTXOProvider,BlockStore,FullPrunedBlockStore
public class LevelDBFullPrunedBlockStore extends java.lang.Object implements FullPrunedBlockStore
An implementation of a Fully Pruned Block Store using a leveldb implementation as the backing data store.
Includes number of caches to optimise the initial blockchain download.
 
- 
- 
Nested Class Summary
Nested Classes Modifier and Type Class Description classLevelDBFullPrunedBlockStore.LRUCache 
- 
Field Summary
Fields Modifier and Type Field Description protected booleanautoCommitprotected org.bitcoinj.store.LevelDBFullPrunedBlockStore.BloomFilterbloomprotected StoredBlockchainHeadBlockprotected Sha256HashchainHeadHashprotected java.lang.Stringfilenameprotected intfullStoreDepthprotected longhitprotected booleaninstrumentprotected longleveldbReadCacheprotected intleveldbWriteCacheprotected longmissprotected intopenOutCacheprotected java.util.Map<java.nio.ByteBuffer,UTXO>utxoCacheprotected java.util.Map<java.nio.ByteBuffer,UTXO>utxoUncommittedCacheprotected java.util.Set<java.nio.ByteBuffer>utxoUncommittedDeletedCacheprotected StoredBlockverifiedChainHeadBlockprotected Sha256HashverifiedChainHeadHash 
- 
Constructor Summary
Constructors Constructor Description LevelDBFullPrunedBlockStore(NetworkParameters params, java.lang.String filename, int blockCount)LevelDBFullPrunedBlockStore(NetworkParameters params, java.lang.String filename, int blockCount, long leveldbReadCache, int leveldbWriteCache, int openOutCache, boolean instrument, int exitBlock) 
- 
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidabortDatabaseBatchWrite()voidaddUnspentTransactionOutput(UTXO out)Adds aUTXOto the list of unspent TransactionOutputsvoidbeginDatabaseBatchWrite()Begins/Commits/Aborts a database transaction.voidclose()Closes the store.voidcommitDatabaseBatchWrite()StoredBlockget(Sha256Hash hash)Returns the StoredBlock given a hash.StoredBlockget(Sha256Hash hash, boolean wasUndoableOnly)StoredBlockgetChainHead()Returns theStoredBlockthat represents the top of the chain of greatest total work.intgetChainHeadHeight()Get the height of the chain head.StoredBlockgetOnceUndoableStoredBlock(Sha256Hash hash)Returns the StoredBlock that was added as a StoredUndoableBlock given a hash.java.util.List<UTXO>getOpenTransactionOutputs(java.util.List<ECKey> keys)Get the list ofUTXO's for given keys.NetworkParametersgetParams()Get theNetworkParametersof this store.UTXOgetTransactionOutput(Sha256Hash hash, long index)Gets aUTXOwith the given hash and index, or null if none is foundStoredUndoableBlockgetUndoBlock(Sha256Hash hash)Returns aStoredUndoableBlockwhose block.getHash() method will be equal to the parameter.StoredBlockgetVerifiedChainHead()Returns theStoredBlockthat represents the top of the chain of greatest total work that has been fully verified and the point in the chain at which the unspent transaction output set in this store represents.booleanhasUnspentOutputs(Sha256Hash hash, int numOutputs)True if this store has any unspent outputs from a transaction with a hash equal to the first parametervoidput(StoredBlock block)Saves the given block header+extra data.voidput(StoredBlock storedBlock, StoredUndoableBlock undoableBlock)Saves the givenStoredUndoableBlockandStoredBlock.protected voidputUpdateStoredBlock(StoredBlock storedBlock, boolean wasUndoable)voidremoveUnspentTransactionOutput(UTXO out)Removes aUTXOfrom the list of unspent TransactionOutputs Note that the coinbase of the genesis block should NEVER be spendable and thus never in the list.voidresetStore()voidsetChainHead(StoredBlock chainHead)Sets theStoredBlockthat represents the top of the chain of greatest total work.voidsetVerifiedChainHead(StoredBlock chainHead)Sets theStoredBlockthat represents the top of the chain of greatest total work that has been fully verified. 
 - 
 
- 
- 
Field Detail
- 
chainHeadHash
protected Sha256Hash chainHeadHash
 
- 
chainHeadBlock
protected StoredBlock chainHeadBlock
 
- 
verifiedChainHeadHash
protected Sha256Hash verifiedChainHeadHash
 
- 
verifiedChainHeadBlock
protected StoredBlock verifiedChainHeadBlock
 
- 
fullStoreDepth
protected int fullStoreDepth
 
- 
instrument
protected boolean instrument
 
- 
hit
protected long hit
 
- 
miss
protected long miss
 
- 
utxoCache
protected java.util.Map<java.nio.ByteBuffer,UTXO> utxoCache
 
- 
utxoUncommittedCache
protected java.util.Map<java.nio.ByteBuffer,UTXO> utxoUncommittedCache
 
- 
utxoUncommittedDeletedCache
protected java.util.Set<java.nio.ByteBuffer> utxoUncommittedDeletedCache
 
- 
filename
protected java.lang.String filename
 
- 
autoCommit
protected boolean autoCommit
 
- 
leveldbReadCache
protected long leveldbReadCache
 
- 
leveldbWriteCache
protected int leveldbWriteCache
 
- 
openOutCache
protected int openOutCache
 
- 
bloom
protected org.bitcoinj.store.LevelDBFullPrunedBlockStore.BloomFilter bloom
 
 - 
 
- 
Constructor Detail
- 
LevelDBFullPrunedBlockStore
public LevelDBFullPrunedBlockStore(NetworkParameters params, java.lang.String filename, int blockCount)
 
- 
LevelDBFullPrunedBlockStore
public LevelDBFullPrunedBlockStore(NetworkParameters params, java.lang.String filename, int blockCount, long leveldbReadCache, int leveldbWriteCache, int openOutCache, boolean instrument, int exitBlock)
 
 - 
 
- 
Method Detail
- 
put
public void put(StoredBlock block) throws BlockStoreException
Description copied from interface:BlockStoreSaves the given block header+extra data. The key isn't specified explicitly as it can be calculated from the StoredBlock directly. Can throw if there is a problem with the underlying storage layer such as running out of disk space.- Specified by:
 putin interfaceBlockStore- Throws:
 BlockStoreException
 
- 
getChainHead
public StoredBlock getChainHead() throws BlockStoreException
Description copied from interface:BlockStoreReturns theStoredBlockthat represents the top of the chain of greatest total work. Note that this can be arbitrarily expensive, you probably should useAbstractBlockChain.getChainHead()or perhapsAbstractBlockChain.getBestChainHeight()which will run in constant time and not take any heavyweight locks.- Specified by:
 getChainHeadin interfaceBlockStore- Throws:
 BlockStoreException
 
- 
setChainHead
public void setChainHead(StoredBlock chainHead) throws BlockStoreException
Description copied from interface:BlockStoreSets theStoredBlockthat represents the top of the chain of greatest total work.- Specified by:
 setChainHeadin interfaceBlockStore- Throws:
 BlockStoreException
 
- 
close
public void close() throws BlockStoreExceptionDescription copied from interface:BlockStoreCloses the store.- Specified by:
 closein interfaceBlockStore- Throws:
 BlockStoreException
 
- 
getParams
public NetworkParameters getParams()
Description copied from interface:BlockStoreGet theNetworkParametersof this store.- Specified by:
 getParamsin interfaceBlockStore- Specified by:
 getParamsin interfaceUTXOProvider- Returns:
 - The network params.
 
 
- 
getOpenTransactionOutputs
public java.util.List<UTXO> getOpenTransactionOutputs(java.util.List<ECKey> keys) throws UTXOProviderException
Description copied from interface:UTXOProviderGet the list ofUTXO's for given keys.- Specified by:
 getOpenTransactionOutputsin interfaceUTXOProvider- Parameters:
 keys- List of keys.- Returns:
 - The list of transaction outputs.
 - Throws:
 UTXOProviderException- If there is an error.
 
- 
getChainHeadHeight
public int getChainHeadHeight() throws UTXOProviderExceptionDescription copied from interface:UTXOProviderGet the height of the chain head.- Specified by:
 getChainHeadHeightin interfaceUTXOProvider- Returns:
 - The chain head height.
 - Throws:
 UTXOProviderException- If there is an error.
 
- 
putUpdateStoredBlock
protected void putUpdateStoredBlock(StoredBlock storedBlock, boolean wasUndoable)
 
- 
put
public void put(StoredBlock storedBlock, StoredUndoableBlock undoableBlock) throws BlockStoreException
Description copied from interface:FullPrunedBlockStoreSaves the given
StoredUndoableBlockandStoredBlock. Calculates keys from theStoredBlockThough not required for proper function of a FullPrunedBlockStore, any user of a FullPrunedBlockStore should ensure that a StoredUndoableBlock for each block up to the fully verified chain head has been added to this block store using this function (not put(StoredBlock)), so that the ability to perform reorgs is maintained.
- Specified by:
 putin interfaceFullPrunedBlockStore- Throws:
 BlockStoreException- if there is a problem with the underlying storage layer, such as running out of disk space.
 
- 
getOnceUndoableStoredBlock
public StoredBlock getOnceUndoableStoredBlock(Sha256Hash hash) throws BlockStoreException
Description copied from interface:FullPrunedBlockStoreReturns the StoredBlock that was added as a StoredUndoableBlock given a hash. The returned values block.getHash() method will be equal to the parameter. If no such block is found, returns null.- Specified by:
 getOnceUndoableStoredBlockin interfaceFullPrunedBlockStore- Throws:
 BlockStoreException
 
- 
get
public StoredBlock get(Sha256Hash hash) throws BlockStoreException
Description copied from interface:BlockStoreReturns the StoredBlock given a hash. The returned values block.getHash() method will be equal to the parameter. If no such block is found, returns null.- Specified by:
 getin interfaceBlockStore- Throws:
 BlockStoreException
 
- 
get
public StoredBlock get(Sha256Hash hash, boolean wasUndoableOnly) throws BlockStoreException
- Throws:
 BlockStoreException
 
- 
getUndoBlock
public StoredUndoableBlock getUndoBlock(Sha256Hash hash) throws BlockStoreException
Description copied from interface:FullPrunedBlockStoreReturns aStoredUndoableBlockwhose block.getHash() method will be equal to the parameter. If no such block is found, returns null. Note that this may return null more often than get(Sha256Hash hash) as not allStoredBlocks have aStoredUndoableBlockcopy stored as well.- Specified by:
 getUndoBlockin interfaceFullPrunedBlockStore- Throws:
 BlockStoreException
 
- 
getTransactionOutput
public UTXO getTransactionOutput(Sha256Hash hash, long index) throws BlockStoreException
Description copied from interface:FullPrunedBlockStoreGets aUTXOwith the given hash and index, or null if none is found- Specified by:
 getTransactionOutputin interfaceFullPrunedBlockStore- Throws:
 BlockStoreException
 
- 
addUnspentTransactionOutput
public void addUnspentTransactionOutput(UTXO out) throws BlockStoreException
Description copied from interface:FullPrunedBlockStoreAdds aUTXOto the list of unspent TransactionOutputs- Specified by:
 addUnspentTransactionOutputin interfaceFullPrunedBlockStore- Throws:
 BlockStoreException
 
- 
removeUnspentTransactionOutput
public void removeUnspentTransactionOutput(UTXO out) throws BlockStoreException
Description copied from interface:FullPrunedBlockStoreRemoves aUTXOfrom the list of unspent TransactionOutputs Note that the coinbase of the genesis block should NEVER be spendable and thus never in the list.- Specified by:
 removeUnspentTransactionOutputin interfaceFullPrunedBlockStore- Throws:
 BlockStoreException- if there is an underlying storage issue, or out was not in the list.
 
- 
hasUnspentOutputs
public boolean hasUnspentOutputs(Sha256Hash hash, int numOutputs) throws BlockStoreException
Description copied from interface:FullPrunedBlockStoreTrue if this store has any unspent outputs from a transaction with a hash equal to the first parameter- Specified by:
 hasUnspentOutputsin interfaceFullPrunedBlockStorenumOutputs- the number of outputs the given transaction has- Throws:
 BlockStoreException
 
- 
getVerifiedChainHead
public StoredBlock getVerifiedChainHead() throws BlockStoreException
Description copied from interface:FullPrunedBlockStoreReturns theStoredBlockthat represents the top of the chain of greatest total work that has been fully verified and the point in the chain at which the unspent transaction output set in this store represents.- Specified by:
 getVerifiedChainHeadin interfaceFullPrunedBlockStore- Throws:
 BlockStoreException
 
- 
setVerifiedChainHead
public void setVerifiedChainHead(StoredBlock chainHead) throws BlockStoreException
Description copied from interface:FullPrunedBlockStoreSets theStoredBlockthat represents the top of the chain of greatest total work that has been fully verified. It should generally be set after a batch of updates to the transaction unspent output set, before a call to commitDatabaseBatchWrite. If chainHead has a greater height than the non-verified chain head (ie that set withBlockStore.setChainHead(org.bitcoinj.core.StoredBlock)) the non-verified chain head should be set to the one set here. In this way a class using a FullPrunedBlockStore only in full-verification mode can ignore the regularBlockStorefunctions implemented as a part of a FullPrunedBlockStore.- Specified by:
 setVerifiedChainHeadin interfaceFullPrunedBlockStore- Throws:
 BlockStoreException
 
- 
beginDatabaseBatchWrite
public void beginDatabaseBatchWrite() throws BlockStoreExceptionDescription copied from interface:FullPrunedBlockStoreBegins/Commits/Aborts a database transaction.
If abortDatabaseBatchWrite() is called by the same thread that called beginDatabaseBatchWrite(), any data writes between this call and abortDatabaseBatchWrite() made by the same thread should be discarded.
Furthermore, any data written after a call to beginDatabaseBatchWrite() should not be readable by any other threads until commitDatabaseBatchWrite() has been called by this thread. Multiple calls to beginDatabaseBatchWrite() in any given thread should be ignored and treated as one call.
- Specified by:
 beginDatabaseBatchWritein interfaceFullPrunedBlockStore- Throws:
 BlockStoreException
 
- 
commitDatabaseBatchWrite
public void commitDatabaseBatchWrite() throws BlockStoreException- Specified by:
 commitDatabaseBatchWritein interfaceFullPrunedBlockStore- Throws:
 BlockStoreException
 
- 
abortDatabaseBatchWrite
public void abortDatabaseBatchWrite() throws BlockStoreException- Specified by:
 abortDatabaseBatchWritein interfaceFullPrunedBlockStore- Throws:
 BlockStoreException
 
- 
resetStore
public void resetStore()
 
 - 
 
 -