public class LevelDBFullPrunedBlockStore extends 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.
Modifier and Type | Class and Description |
---|---|
class |
LevelDBFullPrunedBlockStore.LRUCache |
Modifier and Type | Field and Description |
---|---|
protected boolean |
autoCommit |
protected org.bitcoinj.store.LevelDBFullPrunedBlockStore.BloomFilter |
bloom |
protected StoredBlock |
chainHeadBlock |
protected Sha256Hash |
chainHeadHash |
protected String |
filename |
protected int |
fullStoreDepth |
protected long |
hit |
protected boolean |
instrument |
protected long |
leveldbReadCache |
protected int |
leveldbWriteCache |
protected long |
miss |
protected int |
openOutCache |
protected Map<ByteBuffer,UTXO> |
utxoCache |
protected Map<ByteBuffer,UTXO> |
utxoUncommittedCache |
protected Set<ByteBuffer> |
utxoUncommittedDeletedCache |
protected StoredBlock |
verifiedChainHeadBlock |
protected Sha256Hash |
verifiedChainHeadHash |
Constructor and Description |
---|
LevelDBFullPrunedBlockStore(NetworkParameters params,
String filename,
int blockCount) |
LevelDBFullPrunedBlockStore(NetworkParameters params,
String filename,
int blockCount,
long leveldbReadCache,
int leveldbWriteCache,
int openOutCache,
boolean instrument,
int exitBlock) |
Modifier and Type | Method and Description |
---|---|
void |
abortDatabaseBatchWrite() |
void |
addUnspentTransactionOutput(UTXO out)
Adds a
UTXO to the list of unspent TransactionOutputs |
void |
beginDatabaseBatchWrite()
Begins/Commits/Aborts a database transaction.
|
void |
close()
Closes the store.
|
void |
commitDatabaseBatchWrite() |
StoredBlock |
get(Sha256Hash hash)
Returns the StoredBlock given a hash.
|
StoredBlock |
get(Sha256Hash hash,
boolean wasUndoableOnly) |
StoredBlock |
getChainHead()
Returns the
StoredBlock that represents the top of the chain of greatest total work. |
int |
getChainHeadHeight()
Get the height of the chain head.
|
StoredBlock |
getOnceUndoableStoredBlock(Sha256Hash hash)
Returns the StoredBlock that was added as a StoredUndoableBlock given a hash.
|
List<UTXO> |
getOpenTransactionOutputs(List<Address> addresses)
Get the list of
UTXO 's for a given address. |
NetworkParameters |
getParams()
Get the
NetworkParameters of this store. |
UTXO |
getTransactionOutput(Sha256Hash hash,
long index)
Gets a
UTXO with the given hash and index, or null if none is found |
StoredUndoableBlock |
getUndoBlock(Sha256Hash hash)
Returns a
StoredUndoableBlock whose block.getHash() method will be equal to the parameter. |
StoredBlock |
getVerifiedChainHead()
Returns the
StoredBlock 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 parameter
|
void |
put(StoredBlock block)
Saves the given block header+extra data.
|
void |
put(StoredBlock storedBlock,
StoredUndoableBlock undoableBlock)
Saves the given
StoredUndoableBlock and StoredBlock . |
protected void |
putUpdateStoredBlock(StoredBlock storedBlock,
boolean wasUndoable) |
void |
removeUnspentTransactionOutput(UTXO out)
Removes a
UTXO 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 |
resetStore() |
void |
setChainHead(StoredBlock chainHead)
Sets the
StoredBlock that represents the top of the chain of greatest total work. |
void |
setVerifiedChainHead(StoredBlock chainHead)
Sets the
StoredBlock that represents the top of the chain of greatest total work that has been
fully verified. |
protected Sha256Hash chainHeadHash
protected StoredBlock chainHeadBlock
protected Sha256Hash verifiedChainHeadHash
protected StoredBlock verifiedChainHeadBlock
protected int fullStoreDepth
protected boolean instrument
protected long hit
protected long miss
protected Map<ByteBuffer,UTXO> utxoCache
protected Map<ByteBuffer,UTXO> utxoUncommittedCache
protected Set<ByteBuffer> utxoUncommittedDeletedCache
protected String filename
protected boolean autoCommit
protected long leveldbReadCache
protected int leveldbWriteCache
protected int openOutCache
protected org.bitcoinj.store.LevelDBFullPrunedBlockStore.BloomFilter bloom
public LevelDBFullPrunedBlockStore(NetworkParameters params, String filename, int blockCount)
public LevelDBFullPrunedBlockStore(NetworkParameters params, String filename, int blockCount, long leveldbReadCache, int leveldbWriteCache, int openOutCache, boolean instrument, int exitBlock)
public void put(StoredBlock block) throws BlockStoreException
BlockStore
put
in interface BlockStore
BlockStoreException
public StoredBlock getChainHead() throws BlockStoreException
BlockStore
StoredBlock
that represents the top of the chain of greatest total work. Note that this
can be arbitrarily expensive, you probably should use AbstractBlockChain.getChainHead()
or perhaps AbstractBlockChain.getBestChainHeight()
which will run in constant time and
not take any heavyweight locks.getChainHead
in interface BlockStore
BlockStoreException
public void setChainHead(StoredBlock chainHead) throws BlockStoreException
BlockStore
StoredBlock
that represents the top of the chain of greatest total work.setChainHead
in interface BlockStore
BlockStoreException
public void close() throws BlockStoreException
BlockStore
close
in interface BlockStore
BlockStoreException
public NetworkParameters getParams()
BlockStore
NetworkParameters
of this store.getParams
in interface UTXOProvider
getParams
in interface BlockStore
public List<UTXO> getOpenTransactionOutputs(List<Address> addresses) throws UTXOProviderException
UTXOProvider
UTXO
's for a given address.getOpenTransactionOutputs
in interface UTXOProvider
addresses
- List of address.UTXOProviderException
- If there is an error.public int getChainHeadHeight() throws UTXOProviderException
UTXOProvider
getChainHeadHeight
in interface UTXOProvider
UTXOProviderException
protected void putUpdateStoredBlock(StoredBlock storedBlock, boolean wasUndoable)
public void put(StoredBlock storedBlock, StoredUndoableBlock undoableBlock) throws BlockStoreException
FullPrunedBlockStore
Saves the given StoredUndoableBlock
and StoredBlock
. Calculates keys from the StoredBlock
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.
put
in interface FullPrunedBlockStore
BlockStoreException
- if there is a problem with the underlying storage layer, such as running out of disk space.public StoredBlock getOnceUndoableStoredBlock(Sha256Hash hash) throws BlockStoreException
FullPrunedBlockStore
getOnceUndoableStoredBlock
in interface FullPrunedBlockStore
BlockStoreException
public StoredBlock get(Sha256Hash hash) throws BlockStoreException
BlockStore
get
in interface BlockStore
BlockStoreException
public StoredBlock get(Sha256Hash hash, boolean wasUndoableOnly) throws BlockStoreException
BlockStoreException
public StoredUndoableBlock getUndoBlock(Sha256Hash hash) throws BlockStoreException
FullPrunedBlockStore
StoredUndoableBlock
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 all
StoredBlock
s have a StoredUndoableBlock
copy stored as well.getUndoBlock
in interface FullPrunedBlockStore
BlockStoreException
public UTXO getTransactionOutput(Sha256Hash hash, long index) throws BlockStoreException
FullPrunedBlockStore
UTXO
with the given hash and index, or null if none is foundgetTransactionOutput
in interface FullPrunedBlockStore
BlockStoreException
public void addUnspentTransactionOutput(UTXO out) throws BlockStoreException
FullPrunedBlockStore
UTXO
to the list of unspent TransactionOutputsaddUnspentTransactionOutput
in interface FullPrunedBlockStore
BlockStoreException
public void removeUnspentTransactionOutput(UTXO out) throws BlockStoreException
FullPrunedBlockStore
UTXO
from the list of unspent TransactionOutputs
Note that the coinbase of the genesis block should NEVER be spendable and thus never in the list.removeUnspentTransactionOutput
in interface FullPrunedBlockStore
BlockStoreException
- if there is an underlying storage issue, or out was not in the list.public boolean hasUnspentOutputs(Sha256Hash hash, int numOutputs) throws BlockStoreException
FullPrunedBlockStore
hasUnspentOutputs
in interface FullPrunedBlockStore
numOutputs
- the number of outputs the given transaction hasBlockStoreException
public StoredBlock getVerifiedChainHead() throws BlockStoreException
FullPrunedBlockStore
StoredBlock
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.getVerifiedChainHead
in interface FullPrunedBlockStore
BlockStoreException
public void setVerifiedChainHead(StoredBlock chainHead) throws BlockStoreException
FullPrunedBlockStore
StoredBlock
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 with
BlockStore.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 regular
BlockStore
functions implemented as a part of a FullPrunedBlockStore.setVerifiedChainHead
in interface FullPrunedBlockStore
BlockStoreException
public void beginDatabaseBatchWrite() throws BlockStoreException
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.
beginDatabaseBatchWrite
in interface FullPrunedBlockStore
BlockStoreException
public void commitDatabaseBatchWrite() throws BlockStoreException
commitDatabaseBatchWrite
in interface FullPrunedBlockStore
BlockStoreException
public void abortDatabaseBatchWrite() throws BlockStoreException
abortDatabaseBatchWrite
in interface FullPrunedBlockStore
BlockStoreException
public void resetStore()
Copyright © 2016. All rights reserved.