|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcom.google.bitcoin.store.SPVBlockStore
public class SPVBlockStore
An SPVBlockStore holds a limited number of block headers in a memory mapped ring buffer. With such a store, you may not be able to process very deep re-orgs and could be disconnected from the chain (requiring a replay), but as they are virtually unheard of this is not a significant risk.
| Field Summary | |
|---|---|
protected LinkedHashMap<Sha256Hash,StoredBlock> |
blockCache
|
protected MappedByteBuffer |
buffer
|
static int |
DEFAULT_NUM_HEADERS
The default number of headers that will be stored in the ring buffer. |
protected static int |
FILE_PROLOGUE_BYTES
|
protected FileLock |
fileLock
|
static String |
HEADER_MAGIC
|
protected StoredBlock |
lastChainHead
|
protected ReentrantLock |
lock
|
protected LinkedHashMap<Sha256Hash,Object> |
notFoundCache
|
protected static Object |
notFoundMarker
|
protected int |
numHeaders
|
protected NetworkParameters |
params
|
protected RandomAccessFile |
randomAccessFile
|
protected static int |
RECORD_SIZE
|
| Constructor Summary | |
|---|---|
SPVBlockStore(NetworkParameters params,
File file)
Creates and initializes an SPV block store. |
|
| Method Summary | |
|---|---|
void |
close()
Closes the store. |
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. |
int |
getFileSize()
Returns the size in bytes of the file that is used to store the chain with the current parameters. |
void |
put(StoredBlock block)
Saves the given block header+extra data. |
void |
setChainHead(StoredBlock chainHead)
Sets the StoredBlock that represents the top of the chain of greatest total work. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static final int DEFAULT_NUM_HEADERS
public static final String HEADER_MAGIC
protected volatile MappedByteBuffer buffer
protected int numHeaders
protected NetworkParameters params
protected ReentrantLock lock
protected LinkedHashMap<Sha256Hash,StoredBlock> blockCache
protected static final Object notFoundMarker
protected LinkedHashMap<Sha256Hash,Object> notFoundCache
protected FileLock fileLock
protected RandomAccessFile randomAccessFile
protected StoredBlock lastChainHead
protected static final int RECORD_SIZE
protected static final int FILE_PROLOGUE_BYTES
| Constructor Detail |
|---|
public SPVBlockStore(NetworkParameters params,
File file)
throws BlockStoreException
BlockStoreException| Method Detail |
|---|
public int getFileSize()
public void put(StoredBlock block)
throws BlockStoreException
BlockStore
put in interface BlockStoreBlockStoreException
@Nullable
public StoredBlock get(Sha256Hash hash)
throws BlockStoreException
BlockStore
get in interface BlockStoreBlockStoreException
public StoredBlock getChainHead()
throws BlockStoreException
BlockStoreStoredBlock 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 BlockStoreBlockStoreException
public void setChainHead(StoredBlock chainHead)
throws BlockStoreException
BlockStoreStoredBlock that represents the top of the chain of greatest total work.
setChainHead in interface BlockStoreBlockStoreException
public void close()
throws BlockStoreException
BlockStore
close in interface BlockStoreBlockStoreException
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||