Class SPVBlockStore

  • All Implemented Interfaces:
    BlockStore

    public class SPVBlockStore
    extends java.lang.Object
    implements BlockStore
    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 Detail

      • lock

        protected final java.util.concurrent.locks.ReentrantLock lock
      • DEFAULT_CAPACITY

        public static final int DEFAULT_CAPACITY
        The default number of headers that will be stored in the ring buffer.
        See Also:
        Constant Field Values
      • buffer

        protected volatile java.nio.MappedByteBuffer buffer
      • notFoundCache

        protected java.util.LinkedHashMap<Sha256Hash,​java.lang.Object> notFoundCache
      • fileLock

        protected java.nio.channels.FileLock fileLock
      • randomAccessFile

        protected java.io.RandomAccessFile randomAccessFile
    • Constructor Detail

      • SPVBlockStore

        public SPVBlockStore​(NetworkParameters params,
                             java.io.File file)
                      throws BlockStoreException
        Creates and initializes an SPV block store that can hold DEFAULT_CAPACITY block headers. Will create the given file if it's missing. This operation will block on disk.
        Parameters:
        file - file to use for the block store
        Throws:
        BlockStoreException - if something goes wrong
      • SPVBlockStore

        public SPVBlockStore​(NetworkParameters params,
                             java.io.File file,
                             int capacity,
                             boolean grow)
                      throws BlockStoreException
        Creates and initializes an SPV block store that can hold a given amount of blocks. Will create the given file if it's missing. This operation will block on disk.
        Parameters:
        file - file to use for the block store
        capacity - custom capacity in number of block headers
        grow - wether or not to migrate an existing block store of different capacity
        Throws:
        BlockStoreException - if something goes wrong