public class FullPrunedBlockChain extends AbstractBlockChain
A FullPrunedBlockChain works in conjunction with a FullPrunedBlockStore
to verify all the rules of the
Bitcoin system, with the downside being a large cost in system resources. Fully verifying means all unspent
transaction outputs are stored. Once a transaction output is spent and that spend is buried deep enough, the data
related to it is deleted to ensure disk space usage doesn't grow forever. For this reason a pruning node cannot
serve the full block chain to other clients, but it nevertheless provides the same security guarantees as Bitcoin
Core does.
AbstractBlockChain.NewBlockType
Modifier and Type | Field and Description |
---|---|
protected FullPrunedBlockStore |
blockStore
Keeps a map of block hashes to StoredBlocks.
|
chainHead, FP_ESTIMATOR_ALPHA, FP_ESTIMATOR_BETA, lock, params
Constructor and Description |
---|
FullPrunedBlockChain(Context context,
FullPrunedBlockStore blockStore)
Constructs a block chain connected to the given store.
|
FullPrunedBlockChain(Context context,
java.util.List<Wallet> listeners,
FullPrunedBlockStore blockStore)
Constructs a block chain connected to the given list of wallets and a store.
|
FullPrunedBlockChain(Context context,
Wallet wallet,
FullPrunedBlockStore blockStore)
Constructs a block chain connected to the given wallet and store.
|
FullPrunedBlockChain(NetworkParameters params,
FullPrunedBlockStore blockStore)
|
FullPrunedBlockChain(NetworkParameters params,
java.util.List<Wallet> listeners,
FullPrunedBlockStore blockStore)
|
FullPrunedBlockChain(NetworkParameters params,
Wallet wallet,
FullPrunedBlockStore blockStore)
Constructs a block chain connected to the given wallet and store.
|
Modifier and Type | Method and Description |
---|---|
protected StoredBlock |
addToBlockStore(StoredBlock storedPrev,
Block block)
Adds/updates the given
Block with the block store. |
protected StoredBlock |
addToBlockStore(StoredBlock storedPrev,
Block header,
TransactionOutputChanges txOutChanges)
Adds/updates the given
StoredBlock with the block store. |
protected TransactionOutputChanges |
connectTransactions(int height,
Block block)
Connect each transaction in block.transactions, verifying them as we go and removing spent outputs
If an error is encountered in a transaction, no changes should be made to the underlying BlockStore.
|
protected TransactionOutputChanges |
connectTransactions(StoredBlock newBlock)
Used during reorgs to connect a block previously on a fork
|
protected void |
disconnectTransactions(StoredBlock oldBlock)
This is broken for blocks that do not pass BIP30, so all BIP30-failing blocks which are allowed to fail BIP30
must be checkpointed.
|
protected void |
doSetChainHead(StoredBlock chainHead)
Called before setting chain head in memory.
|
protected StoredBlock |
getStoredBlockInCurrentScope(Sha256Hash hash)
For a standard BlockChain, this should return blockStore.get(hash),
for a FullPrunedBlockChain blockStore.getOnceUndoableStoredBlock(hash)
|
protected void |
notSettingChainHead()
Called if we (possibly) previously called disconnectTransaction/connectTransactions,
but will not be calling preSetChainHead as a block failed verification.
|
protected void |
rollbackBlockStore(int height)
Rollback the block store to a given height.
|
void |
setRunScripts(boolean value)
Whether or not to run scripts whilst accepting blocks (i.e.
|
protected boolean |
shouldVerifyTransactions()
Whether or not we are maintaining a set of unspent outputs and are verifying all transactions.
|
add, add, addNewBestBlockListener, addNewBestBlockListener, addReorganizeListener, addReorganizeListener, addTransactionReceivedListener, addTransactionReceivedListener, addWallet, drainOrphanBlocks, estimateBlockTime, getBestChainHeight, getBlockStore, getChainHead, getFalsePositiveRate, getHeightFuture, getOrphanRoot, getVersionTally, isOrphan, removeNewBestBlockListener, removeReorganizeListener, removeTransactionReceivedListener, removeWallet, resetFalsePositiveEstimate, setChainHead, trackFilteredTransactions
protected final FullPrunedBlockStore blockStore
public FullPrunedBlockChain(Context context, Wallet wallet, FullPrunedBlockStore blockStore) throws BlockStoreException
Wallet
you can construct
one from scratch, or you can deserialize a saved wallet from disk using
Wallet.loadFromFile(File, WalletExtension...)
BlockStoreException
public FullPrunedBlockChain(NetworkParameters params, Wallet wallet, FullPrunedBlockStore blockStore) throws BlockStoreException
Wallet
you can construct
one from scratch, or you can deserialize a saved wallet from disk using
Wallet.loadFromFile(File, WalletExtension...)
BlockStoreException
public FullPrunedBlockChain(Context context, FullPrunedBlockStore blockStore) throws BlockStoreException
BlockStoreException
public FullPrunedBlockChain(NetworkParameters params, FullPrunedBlockStore blockStore) throws BlockStoreException
BlockStoreException
public FullPrunedBlockChain(Context context, java.util.List<Wallet> listeners, FullPrunedBlockStore blockStore) throws BlockStoreException
BlockStoreException
public FullPrunedBlockChain(NetworkParameters params, java.util.List<Wallet> listeners, FullPrunedBlockStore blockStore) throws BlockStoreException
BlockStoreException
protected StoredBlock addToBlockStore(StoredBlock storedPrev, Block header, TransactionOutputChanges txOutChanges) throws BlockStoreException, VerificationException
AbstractBlockChain
StoredBlock
with the block store.
This version is used when the transactions have already been verified to properly spend txOutputChanges.addToBlockStore
in class AbstractBlockChain
storedPrev
- The StoredBlock
which immediately precedes block.header
- The StoredBlock
to add/update.txOutChanges
- The total sum of all changes made by this block to the set of open transaction outputs
(from a call to connectTransactions), if in fully verifying mode (null otherwise).StoredBlock
BlockStoreException
- if a failure occurs while storing a blockVerificationException
- if the block is invalidprotected StoredBlock addToBlockStore(StoredBlock storedPrev, Block block) throws BlockStoreException, VerificationException
AbstractBlockChain
Block
with the block store.
This version is used when the transactions have not been verified.addToBlockStore
in class AbstractBlockChain
storedPrev
- The StoredBlock
which immediately precedes block.block
- The Block
to add/update.StoredBlock
BlockStoreException
- if a failure occurs while storing a blockVerificationException
- if the block is invalidprotected void rollbackBlockStore(int height) throws BlockStoreException
AbstractBlockChain
BlockChain
instances.rollbackBlockStore
in class AbstractBlockChain
height
- height to roll back toBlockStoreException
- if the operation fails or is unsupported.protected boolean shouldVerifyTransactions()
AbstractBlockChain
shouldVerifyTransactions
in class AbstractBlockChain
public void setRunScripts(boolean value)
protected TransactionOutputChanges connectTransactions(int height, Block block) throws VerificationException, BlockStoreException
AbstractBlockChain
connectTransactions
in class AbstractBlockChain
height
- block height to attach atblock
- block to connectVerificationException
- if an attempt was made to spend an already-spent output, or if a transaction incorrectly solved an output script.BlockStoreException
- if the block store had an underlying error.protected TransactionOutputChanges connectTransactions(StoredBlock newBlock) throws VerificationException, BlockStoreException, PrunedException
connectTransactions
in class AbstractBlockChain
newBlock
- block to loadVerificationException
- if an attempt was made to spend an already-spent output, or if a transaction incorrectly solved an output script.BlockStoreException
- if the block store had an underlying error or newBlock does not exist in the block store at all.PrunedException
- if newBlock does not exist as a StoredUndoableBlock
in the block store.protected void disconnectTransactions(StoredBlock oldBlock) throws PrunedException, BlockStoreException
disconnectTransactions
in class AbstractBlockChain
oldBlock
- block to disconnectPrunedException
- if block does not exist as a StoredUndoableBlock
in the block store.BlockStoreException
- if the block store had an underlying error or block does not exist in the block store at all.protected void doSetChainHead(StoredBlock chainHead) throws BlockStoreException
AbstractBlockChain
doSetChainHead
in class AbstractBlockChain
chainHead
- chain head to setBlockStoreException
- if a failure occurs while storing a blockprotected void notSettingChainHead() throws BlockStoreException
AbstractBlockChain
notSettingChainHead
in class AbstractBlockChain
BlockStoreException
- if a failure occurs while storing a blockprotected StoredBlock getStoredBlockInCurrentScope(Sha256Hash hash) throws BlockStoreException
AbstractBlockChain
getStoredBlockInCurrentScope
in class AbstractBlockChain
hash
- hash of block to fetchBlockStoreException
- if a failure occurs while storing a block