com.google.bitcoin.store
Class MemoryFullPrunedBlockStore

java.lang.Object
  extended by com.google.bitcoin.store.MemoryFullPrunedBlockStore
All Implemented Interfaces:
BlockStore, FullPrunedBlockStore

public class MemoryFullPrunedBlockStore
extends Object
implements FullPrunedBlockStore

Keeps StoredBlocks, StoredUndoableBlocks and StoredTransactionOutputs in memory. Used primarily for unit testing.


Nested Class Summary
protected static class MemoryFullPrunedBlockStore.StoredBlockAndWasUndoableFlag
           
 
Constructor Summary
MemoryFullPrunedBlockStore(NetworkParameters params, int fullStoreDepth)
          Set up the MemoryFullPrunedBlockStore
 
Method Summary
 void abortDatabaseBatchWrite()
           
 void addUnspentTransactionOutput(StoredTransactionOutput out)
          Adds a StoredTransactionOutput 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 getChainHead()
          Returns the StoredBlock that represents the top of the chain of greatest total work.
 StoredBlock getOnceUndoableStoredBlock(Sha256Hash hash)
          Returns the StoredBlock that was added as a StoredUndoableBlock given a hash.
 StoredTransactionOutput getTransactionOutput(Sha256Hash hash, long index)
          Gets a StoredTransactionOutput 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.
 void removeUnspentTransactionOutput(StoredTransactionOutput out)
          Removes a StoredTransactionOutput 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 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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MemoryFullPrunedBlockStore

public MemoryFullPrunedBlockStore(NetworkParameters params,
                                  int fullStoreDepth)
Set up the MemoryFullPrunedBlockStore

Parameters:
params - The network parameters of this block store - used to get genesis block
fullStoreDepth - The depth of blocks to keep FullStoredBlocks instead of StoredBlocks
Method Detail

put

public void put(StoredBlock block)
         throws BlockStoreException
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 interface BlockStore
Throws:
BlockStoreException

put

public void put(StoredBlock storedBlock,
                StoredUndoableBlock undoableBlock)
         throws BlockStoreException
Description copied from interface: 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.

Specified by:
put in interface FullPrunedBlockStore
Throws:
BlockStoreException - if there is a problem with the underlying storage layer, such as running out of disk space.

get

@Nullable
public StoredBlock get(Sha256Hash hash)
                throws BlockStoreException
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 interface BlockStore
Throws:
BlockStoreException

getOnceUndoableStoredBlock

@Nullable
public StoredBlock getOnceUndoableStoredBlock(Sha256Hash hash)
                                       throws BlockStoreException
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 interface FullPrunedBlockStore
Throws:
BlockStoreException

getUndoBlock

@Nullable
public StoredUndoableBlock getUndoBlock(Sha256Hash hash)
                                 throws BlockStoreException
Description copied from interface: FullPrunedBlockStore
Returns a 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 StoredBlocks have a StoredUndoableBlock copy stored as well.

Specified by:
getUndoBlock in interface FullPrunedBlockStore
Throws:
BlockStoreException

getChainHead

public StoredBlock getChainHead()
                         throws BlockStoreException
Description copied from interface: BlockStore
Returns the 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.

Specified by:
getChainHead in interface BlockStore
Throws:
BlockStoreException

setChainHead

public void setChainHead(StoredBlock chainHead)
                  throws BlockStoreException
Description copied from interface: BlockStore
Sets the StoredBlock that represents the top of the chain of greatest total work.

Specified by:
setChainHead in interface BlockStore
Throws:
BlockStoreException

getVerifiedChainHead

public StoredBlock getVerifiedChainHead()
                                 throws BlockStoreException
Description copied from interface: FullPrunedBlockStore
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.

Specified by:
getVerifiedChainHead in interface FullPrunedBlockStore
Throws:
BlockStoreException

setVerifiedChainHead

public void setVerifiedChainHead(StoredBlock chainHead)
                          throws BlockStoreException
Description copied from interface: FullPrunedBlockStore
Sets the 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) 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.

Specified by:
setVerifiedChainHead in interface FullPrunedBlockStore
Throws:
BlockStoreException

close

public void close()
Description copied from interface: BlockStore
Closes the store.

Specified by:
close in interface BlockStore

getTransactionOutput

@Nullable
public StoredTransactionOutput getTransactionOutput(Sha256Hash hash,
                                                             long index)
                                             throws BlockStoreException
Description copied from interface: FullPrunedBlockStore
Gets a StoredTransactionOutput with the given hash and index, or null if none is found

Specified by:
getTransactionOutput in interface FullPrunedBlockStore
Throws:
BlockStoreException

addUnspentTransactionOutput

public void addUnspentTransactionOutput(StoredTransactionOutput out)
                                 throws BlockStoreException
Description copied from interface: FullPrunedBlockStore
Adds a StoredTransactionOutput to the list of unspent TransactionOutputs

Specified by:
addUnspentTransactionOutput in interface FullPrunedBlockStore
Throws:
BlockStoreException

removeUnspentTransactionOutput

public void removeUnspentTransactionOutput(StoredTransactionOutput out)
                                    throws BlockStoreException
Description copied from interface: FullPrunedBlockStore
Removes a StoredTransactionOutput 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 interface FullPrunedBlockStore
Throws:
BlockStoreException - if there is an underlying storage issue, or out was not in the list.

beginDatabaseBatchWrite

public void beginDatabaseBatchWrite()
                             throws BlockStoreException
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 interface FullPrunedBlockStore
Throws:
BlockStoreException

commitDatabaseBatchWrite

public void commitDatabaseBatchWrite()
                              throws BlockStoreException
Specified by:
commitDatabaseBatchWrite in interface FullPrunedBlockStore
Throws:
BlockStoreException

abortDatabaseBatchWrite

public void abortDatabaseBatchWrite()
                             throws BlockStoreException
Specified by:
abortDatabaseBatchWrite in interface FullPrunedBlockStore
Throws:
BlockStoreException

hasUnspentOutputs

public boolean hasUnspentOutputs(Sha256Hash hash,
                                 int numOutputs)
                          throws BlockStoreException
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 interface FullPrunedBlockStore
numOutputs - the number of outputs the given transaction has
Throws:
BlockStoreException


Copyright © 2014. All rights reserved.