@Override @Nullable public synchronized StoredUndoableBlock getUndoBlock(Sha256Hash hash) throws BlockStoreException { Preconditions.checkNotNull(fullBlockMap, "MemoryFullPrunedBlockStore is closed"); return fullBlockMap.get(hash); }
public void removeByMultiKey(MultiKeyType key) { Set<UniqueKeyType> set = mapKeys.remove(key); if (set != null) for (UniqueKeyType uniqueKey : set) removeByUniqueKey(uniqueKey); } }
@Override public synchronized final void put(StoredBlock storedBlock, StoredUndoableBlock undoableBlock) throws BlockStoreException { Preconditions.checkNotNull(blockMap, "MemoryFullPrunedBlockStore is closed"); Sha256Hash hash = storedBlock.getHeader().getHash(); fullBlockMap.put(hash, storedBlock.getHeight(), undoableBlock); blockMap.put(hash, new StoredBlockAndWasUndoableFlag(storedBlock, true)); }
@Override public synchronized final void setVerifiedChainHead(StoredBlock chainHead) throws BlockStoreException { Preconditions.checkNotNull(blockMap, "MemoryFullPrunedBlockStore is closed"); this.verifiedChainHead = chainHead; if (this.chainHead.getHeight() < chainHead.getHeight()) setChainHead(chainHead); // Potential leak here if not all blocks get setChainHead'd // Though the FullPrunedBlockStore allows for this, the current AbstractBlockChain will not do it. fullBlockMap.removeByMultiKey(chainHead.getHeight() - fullStoreDepth); }
@Override public synchronized void abortDatabaseBatchWrite() throws BlockStoreException { blockMap.abortDatabaseBatchWrite(); fullBlockMap.AbortTransaction(); transactionOutputMap.abortDatabaseBatchWrite(); }
@Override public synchronized void commitDatabaseBatchWrite() throws BlockStoreException { blockMap.commitDatabaseBatchWrite(); fullBlockMap.CommitTransaction(); transactionOutputMap.commitDatabaseBatchWrite(); }
@Override public synchronized void beginDatabaseBatchWrite() throws BlockStoreException { blockMap.beginDatabaseBatchWrite(); fullBlockMap.BeginTransaction(); transactionOutputMap.beginDatabaseBatchWrite(); }
/** * Set up the MemoryFullPrunedBlockStore * @param params The network parameters of this block store - used to get genesis block * @param fullStoreDepth The depth of blocks to keep FullStoredBlocks instead of StoredBlocks */ public MemoryFullPrunedBlockStore(NetworkParameters params, int fullStoreDepth) { blockMap = new TransactionalHashMap<Sha256Hash, StoredBlockAndWasUndoableFlag>(); fullBlockMap = new TransactionalMultiKeyHashMap<Sha256Hash, Integer, StoredUndoableBlock>(); transactionOutputMap = new TransactionalHashMap<StoredTransactionOutPoint, UTXO>(); this.fullStoreDepth = fullStoreDepth > 0 ? fullStoreDepth : 1; // Insert the genesis block. try { StoredBlock storedGenesisHeader = new StoredBlock(params.getGenesisBlock().cloneAsHeader(), params.getGenesisBlock().getWork(), 0); // The coinbase in the genesis block is not spendable List<Transaction> genesisTransactions = Lists.newLinkedList(); StoredUndoableBlock storedGenesis = new StoredUndoableBlock(params.getGenesisBlock().getHash(), genesisTransactions); put(storedGenesisHeader, storedGenesis); setChainHead(storedGenesisHeader); setVerifiedChainHead(storedGenesisHeader); this.params = params; } catch (BlockStoreException e) { throw new RuntimeException(e); // Cannot happen. } catch (VerificationException e) { throw new RuntimeException(e); // Cannot happen. } }
@Override public synchronized final void put(StoredBlock storedBlock, StoredUndoableBlock undoableBlock) throws BlockStoreException { Preconditions.checkNotNull(blockMap, "MemoryFullPrunedBlockStore is closed"); Sha256Hash hash = storedBlock.getHeader().getHash(); fullBlockMap.put(hash, storedBlock.getHeight(), undoableBlock); blockMap.put(hash, new StoredBlockAndWasUndoableFlag(storedBlock, true)); }
@Override public synchronized final void setVerifiedChainHead(StoredBlock chainHead) throws BlockStoreException { Preconditions.checkNotNull(blockMap, "MemoryFullPrunedBlockStore is closed"); this.verifiedChainHead = chainHead; if (this.chainHead.getHeight() < chainHead.getHeight()) setChainHead(chainHead); // Potential leak here if not all blocks get setChainHead'd // Though the FullPrunedBlockStore allows for this, the current AbstractBlockChain will not do it. fullBlockMap.removeByMultiKey(chainHead.getHeight() - fullStoreDepth); }
@Override public synchronized void abortDatabaseBatchWrite() throws BlockStoreException { blockMap.abortDatabaseBatchWrite(); fullBlockMap.AbortTransaction(); transactionOutputMap.abortDatabaseBatchWrite(); }
@Override public synchronized void commitDatabaseBatchWrite() throws BlockStoreException { blockMap.commitDatabaseBatchWrite(); fullBlockMap.CommitTransaction(); transactionOutputMap.commitDatabaseBatchWrite(); }
@Override public synchronized void beginDatabaseBatchWrite() throws BlockStoreException { blockMap.beginDatabaseBatchWrite(); fullBlockMap.BeginTransaction(); transactionOutputMap.beginDatabaseBatchWrite(); }
/** * Set up the MemoryFullPrunedBlockStore * @param params The network parameters of this block store - used to get genesis block * @param fullStoreDepth The depth of blocks to keep FullStoredBlocks instead of StoredBlocks */ public MemoryFullPrunedBlockStore(NetworkParameters params, int fullStoreDepth) { blockMap = new TransactionalHashMap<>(); fullBlockMap = new TransactionalMultiKeyHashMap<>(); transactionOutputMap = new TransactionalHashMap<>(); this.fullStoreDepth = fullStoreDepth > 0 ? fullStoreDepth : 1; // Insert the genesis block. try { StoredBlock storedGenesisHeader = new StoredBlock(params.getGenesisBlock().cloneAsHeader(), params.getGenesisBlock().getWork(), 0); // The coinbase in the genesis block is not spendable List<Transaction> genesisTransactions = Lists.newLinkedList(); StoredUndoableBlock storedGenesis = new StoredUndoableBlock(params.getGenesisBlock().getHash(), genesisTransactions); put(storedGenesisHeader, storedGenesis); setChainHead(storedGenesisHeader); setVerifiedChainHead(storedGenesisHeader); this.params = params; } catch (BlockStoreException e) { throw new RuntimeException(e); // Cannot happen. } catch (VerificationException e) { throw new RuntimeException(e); // Cannot happen. } }
@Override public synchronized final void put(StoredBlock storedBlock, StoredUndoableBlock undoableBlock) throws BlockStoreException { Preconditions.checkNotNull(blockMap, "MemoryFullPrunedBlockStore is closed"); Sha256Hash hash = storedBlock.getHeader().getHash(); fullBlockMap.put(hash, storedBlock.getHeight(), undoableBlock); blockMap.put(hash, new StoredBlockAndWasUndoableFlag(storedBlock, true)); }
public void removeByMultiKey(MultiKeyType key) { Set<UniqueKeyType> set = mapKeys.remove(key); if (set != null) for (UniqueKeyType uniqueKey : set) removeByUniqueKey(uniqueKey); } }
@Override public synchronized final void setVerifiedChainHead(StoredBlock chainHead) throws BlockStoreException { Preconditions.checkNotNull(blockMap, "MemoryFullPrunedBlockStore is closed"); this.verifiedChainHead = chainHead; if (this.chainHead.getHeight() < chainHead.getHeight()) setChainHead(chainHead); // Potential leak here if not all blocks get setChainHead'd // Though the FullPrunedBlockStore allows for this, the current AbstractBlockChain will not do it. fullBlockMap.removeByMultiKey(chainHead.getHeight() - fullStoreDepth); }
@Override @Nullable public synchronized StoredUndoableBlock getUndoBlock(Sha256Hash hash) throws BlockStoreException { Preconditions.checkNotNull(fullBlockMap, "MemoryFullPrunedBlockStore is closed"); return fullBlockMap.get(hash); }
@Override public synchronized void abortDatabaseBatchWrite() throws BlockStoreException { blockMap.abortDatabaseBatchWrite(); fullBlockMap.AbortTransaction(); transactionOutputMap.abortDatabaseBatchWrite(); }
@Override public synchronized void commitDatabaseBatchWrite() throws BlockStoreException { blockMap.commitDatabaseBatchWrite(); fullBlockMap.CommitTransaction(); transactionOutputMap.commitDatabaseBatchWrite(); }