Class LevelDBFullPrunedBlockStore
- All Implemented Interfaces:
UTXOProvider
,BlockStore
,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
-
Field Summary
Modifier and TypeFieldDescriptionprotected boolean
protected org.bitcoinj.store.LevelDBFullPrunedBlockStore.BloomFilter
protected StoredBlock
protected Sha256Hash
protected String
protected int
protected long
protected boolean
protected long
protected int
protected long
protected int
protected Map<ByteBuffer,
UTXO> protected Map<ByteBuffer,
UTXO> protected Set<ByteBuffer>
protected StoredBlock
protected Sha256Hash
-
Constructor Summary
ConstructorDescriptionLevelDBFullPrunedBlockStore
(NetworkParameters params, String filename, int blockCount) LevelDBFullPrunedBlockStore
(NetworkParameters params, String filename, int blockCount, long leveldbReadCache, int leveldbWriteCache, int openOutCache, boolean instrument, int exitBlock) -
Method Summary
Modifier and TypeMethodDescriptionvoid
void
Adds aUTXO
to the list of unspent TransactionOutputsvoid
Begins/Commits/Aborts a database transaction.void
close()
Closes the store.void
get
(Sha256Hash hash) Returns the StoredBlock given a hash.get
(Sha256Hash hash, boolean wasUndoableOnly) Returns theStoredBlock
that represents the top of the chain of greatest total work.int
Get the height of the chain head.Returns the StoredBlock that was added as a StoredUndoableBlock given a hash.getOpenTransactionOutputs
(List<ECKey> keys) Get the list ofUTXO
's for given keys.Get theNetworkParameters
of this store.getTransactionOutput
(Sha256Hash hash, long index) Gets aUTXO
with the given hash and index, or null if none is foundgetUndoBlock
(Sha256Hash hash) Returns aStoredUndoableBlock
whose block.getHash() method will be equal to the parameter.Returns theStoredBlock
that 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.boolean
hasUnspentOutputs
(Sha256Hash hash, int numOutputs) True if this store has any unspent outputs from a transaction with a hash equal to the first parametervoid
put
(StoredBlock block) Saves the given block header+extra data.void
put
(StoredBlock storedBlock, StoredUndoableBlock undoableBlock) Saves the givenStoredUndoableBlock
andStoredBlock
.protected void
putUpdateStoredBlock
(StoredBlock storedBlock, boolean wasUndoable) void
Removes aUTXO
from the list of unspent TransactionOutputs Note that the coinbase of the genesis block should NEVER be spendable and thus never in the list.void
void
setChainHead
(StoredBlock chainHead) Sets theStoredBlock
that represents the top of the chain of greatest total work.void
setVerifiedChainHead
(StoredBlock chainHead) Sets theStoredBlock
that represents the top of the chain of greatest total work that has been fully verified.
-
Field Details
-
chainHeadHash
-
chainHeadBlock
-
verifiedChainHeadHash
-
verifiedChainHeadBlock
-
fullStoreDepth
protected int fullStoreDepth -
instrument
protected boolean instrument -
hit
protected long hit -
miss
protected long miss -
utxoCache
-
utxoUncommittedCache
-
utxoUncommittedDeletedCache
-
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 Details
-
LevelDBFullPrunedBlockStore
-
LevelDBFullPrunedBlockStore
public LevelDBFullPrunedBlockStore(NetworkParameters params, String filename, int blockCount, long leveldbReadCache, int leveldbWriteCache, int openOutCache, boolean instrument, int exitBlock)
-
-
Method Details
-
put
Description copied from interface:BlockStore
Saves 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:
put
in interfaceBlockStore
- Throws:
BlockStoreException
-
getChainHead
Description copied from interface:BlockStore
Returns theStoredBlock
that 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:
getChainHead
in interfaceBlockStore
- Throws:
BlockStoreException
-
setChainHead
Description copied from interface:BlockStore
Sets theStoredBlock
that represents the top of the chain of greatest total work.- Specified by:
setChainHead
in interfaceBlockStore
- Throws:
BlockStoreException
-
close
Description copied from interface:BlockStore
Closes the store.- Specified by:
close
in interfaceBlockStore
- Throws:
BlockStoreException
-
getParams
Description copied from interface:BlockStore
Get theNetworkParameters
of this store.- Specified by:
getParams
in interfaceBlockStore
- Specified by:
getParams
in interfaceUTXOProvider
- Returns:
- The network params.
-
getOpenTransactionOutputs
Description copied from interface:UTXOProvider
Get the list ofUTXO
's for given keys.- Specified by:
getOpenTransactionOutputs
in interfaceUTXOProvider
- Parameters:
keys
- List of keys.- Returns:
- The list of transaction outputs.
- Throws:
UTXOProviderException
- If there is an error.
-
getChainHeadHeight
Description copied from interface:UTXOProvider
Get the height of the chain head.- Specified by:
getChainHeadHeight
in interfaceUTXOProvider
- Returns:
- The chain head height.
- Throws:
UTXOProviderException
- If there is an error.
-
putUpdateStoredBlock
-
put
public void put(StoredBlock storedBlock, StoredUndoableBlock undoableBlock) throws BlockStoreException Description copied from interface:FullPrunedBlockStore
Saves the given
StoredUndoableBlock
andStoredBlock
. Calculates keys from theStoredBlock
Though 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:
put
in interfaceFullPrunedBlockStore
- Throws:
BlockStoreException
- if there is a problem with the underlying storage layer, such as running out of disk space.
-
getOnceUndoableStoredBlock
Description copied from interface:FullPrunedBlockStore
Returns 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:
getOnceUndoableStoredBlock
in interfaceFullPrunedBlockStore
- Throws:
BlockStoreException
-
get
Description copied from interface:BlockStore
Returns 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:
get
in interfaceBlockStore
- Throws:
BlockStoreException
-
get
- Throws:
BlockStoreException
-
getUndoBlock
Description copied from interface:FullPrunedBlockStore
Returns aStoredUndoableBlock
whose 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 allStoredBlock
s have aStoredUndoableBlock
copy stored as well.- Specified by:
getUndoBlock
in interfaceFullPrunedBlockStore
- Throws:
BlockStoreException
-
getTransactionOutput
Description copied from interface:FullPrunedBlockStore
Gets aUTXO
with the given hash and index, or null if none is found- Specified by:
getTransactionOutput
in interfaceFullPrunedBlockStore
- Throws:
BlockStoreException
-
addUnspentTransactionOutput
Description copied from interface:FullPrunedBlockStore
Adds aUTXO
to the list of unspent TransactionOutputs- Specified by:
addUnspentTransactionOutput
in interfaceFullPrunedBlockStore
- Throws:
BlockStoreException
-
removeUnspentTransactionOutput
Description copied from interface:FullPrunedBlockStore
Removes aUTXO
from 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:
removeUnspentTransactionOutput
in interfaceFullPrunedBlockStore
- Throws:
BlockStoreException
- if there is an underlying storage issue, or out was not in the list.
-
hasUnspentOutputs
Description copied from interface:FullPrunedBlockStore
True if this store has any unspent outputs from a transaction with a hash equal to the first parameter- Specified by:
hasUnspentOutputs
in interfaceFullPrunedBlockStore
numOutputs
- the number of outputs the given transaction has- Throws:
BlockStoreException
-
getVerifiedChainHead
Description copied from interface:FullPrunedBlockStore
Returns theStoredBlock
that 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:
getVerifiedChainHead
in interfaceFullPrunedBlockStore
- Throws:
BlockStoreException
-
setVerifiedChainHead
Description copied from interface:FullPrunedBlockStore
Sets theStoredBlock
that 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 regularBlockStore
functions implemented as a part of a FullPrunedBlockStore.- Specified by:
setVerifiedChainHead
in interfaceFullPrunedBlockStore
- Throws:
BlockStoreException
-
beginDatabaseBatchWrite
Description copied from interface:FullPrunedBlockStore
Begins/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:
beginDatabaseBatchWrite
in interfaceFullPrunedBlockStore
- Throws:
BlockStoreException
-
commitDatabaseBatchWrite
- Specified by:
commitDatabaseBatchWrite
in interfaceFullPrunedBlockStore
- Throws:
BlockStoreException
-
abortDatabaseBatchWrite
- Specified by:
abortDatabaseBatchWrite
in interfaceFullPrunedBlockStore
- Throws:
BlockStoreException
-
resetStore
public void resetStore()
-