mirror of
https://github.com/bitcoinj/bitcoinj.git
synced 2025-02-26 07:23:53 +01:00
AbstractBlockChain: Fix some nullity annotations and a few other misc things.
This commit is contained in:
parent
d316cf316f
commit
a8a8d3a044
1 changed files with 18 additions and 14 deletions
|
@ -26,6 +26,7 @@ import com.google.common.util.concurrent.SettableFuture;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import javax.annotation.Nullable;
|
||||||
import java.math.BigInteger;
|
import java.math.BigInteger;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.concurrent.CopyOnWriteArrayList;
|
import java.util.concurrent.CopyOnWriteArrayList;
|
||||||
|
@ -109,9 +110,10 @@ public abstract class AbstractBlockChain {
|
||||||
Block block;
|
Block block;
|
||||||
Set<Sha256Hash> filteredTxHashes;
|
Set<Sha256Hash> filteredTxHashes;
|
||||||
List<Transaction> filteredTxn;
|
List<Transaction> filteredTxn;
|
||||||
OrphanBlock(Block block, Set<Sha256Hash> filteredTxHashes, List<Transaction> filteredTxn) {
|
OrphanBlock(Block block, @Nullable Set<Sha256Hash> filteredTxHashes, @Nullable List<Transaction> filteredTxn) {
|
||||||
Preconditions.checkArgument((block.transactions == null && filteredTxHashes != null && filteredTxn != null)
|
final boolean filtered = filteredTxHashes != null && filteredTxn != null;
|
||||||
|| (block.transactions != null && filteredTxHashes == null && filteredTxn == null));
|
Preconditions.checkArgument((block.transactions == null && filtered)
|
||||||
|
|| (block.transactions != null && !filtered));
|
||||||
this.block = block;
|
this.block = block;
|
||||||
this.filteredTxHashes = filteredTxHashes;
|
this.filteredTxHashes = filteredTxHashes;
|
||||||
this.filteredTxn = filteredTxn;
|
this.filteredTxn = filteredTxn;
|
||||||
|
@ -223,7 +225,7 @@ public abstract class AbstractBlockChain {
|
||||||
*/
|
*/
|
||||||
public boolean add(Block block) throws VerificationException, PrunedException {
|
public boolean add(Block block) throws VerificationException, PrunedException {
|
||||||
try {
|
try {
|
||||||
return add(block, null, null, true);
|
return add(block, true, null, null);
|
||||||
} catch (BlockStoreException e) {
|
} catch (BlockStoreException e) {
|
||||||
// TODO: Figure out a better way to propagate this exception to the user.
|
// TODO: Figure out a better way to propagate this exception to the user.
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
|
@ -257,7 +259,7 @@ public abstract class AbstractBlockChain {
|
||||||
for (Transaction tx : filteredTxn) {
|
for (Transaction tx : filteredTxn) {
|
||||||
checkState(filteredTxnHashSet.remove(tx.getHash()));
|
checkState(filteredTxnHashSet.remove(tx.getHash()));
|
||||||
}
|
}
|
||||||
return add(block.getBlockHeader(), filteredTxnHashSet, filteredTxn, true);
|
return add(block.getBlockHeader(), true, filteredTxnHashSet, filteredTxn);
|
||||||
} catch (BlockStoreException e) {
|
} catch (BlockStoreException e) {
|
||||||
// TODO: Figure out a better way to propagate this exception to the user.
|
// TODO: Figure out a better way to propagate this exception to the user.
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
|
@ -305,8 +307,8 @@ public abstract class AbstractBlockChain {
|
||||||
private long statsBlocksAdded;
|
private long statsBlocksAdded;
|
||||||
|
|
||||||
// filteredTxHashList and filteredTxn[i].GetHash() should be mutually exclusive
|
// filteredTxHashList and filteredTxn[i].GetHash() should be mutually exclusive
|
||||||
private boolean add(Block block, Set<Sha256Hash> filteredTxHashList, List<Transaction> filteredTxn, boolean tryConnecting)
|
private boolean add(Block block, boolean tryConnecting,
|
||||||
throws BlockStoreException, VerificationException, PrunedException {
|
@Nullable Set<Sha256Hash> filteredTxHashList, @Nullable List<Transaction> filteredTxn) throws BlockStoreException, VerificationException, PrunedException {
|
||||||
lock.lock();
|
lock.lock();
|
||||||
try {
|
try {
|
||||||
// TODO: Use read/write locks to ensure that during chain download properties are still low latency.
|
// TODO: Use read/write locks to ensure that during chain download properties are still low latency.
|
||||||
|
@ -392,8 +394,8 @@ public abstract class AbstractBlockChain {
|
||||||
// than the previous one when connecting (eg median timestamp check)
|
// than the previous one when connecting (eg median timestamp check)
|
||||||
// It could be exposed, but for now we just set it to shouldVerifyTransactions()
|
// It could be exposed, but for now we just set it to shouldVerifyTransactions()
|
||||||
private void connectBlock(final Block block, StoredBlock storedPrev, boolean expensiveChecks,
|
private void connectBlock(final Block block, StoredBlock storedPrev, boolean expensiveChecks,
|
||||||
Set<Sha256Hash> filteredTxHashList, final List<Transaction> filteredTxn)
|
@Nullable final Set<Sha256Hash> filteredTxHashList,
|
||||||
throws BlockStoreException, VerificationException, PrunedException {
|
@Nullable final List<Transaction> filteredTxn) throws BlockStoreException, VerificationException, PrunedException {
|
||||||
checkState(lock.isLocked());
|
checkState(lock.isLocked());
|
||||||
// Check that we aren't connecting a block that fails a checkpoint check
|
// Check that we aren't connecting a block that fails a checkpoint check
|
||||||
if (!params.passesCheckpoint(storedPrev.getHeight() + 1, block.getHash()))
|
if (!params.passesCheckpoint(storedPrev.getHeight() + 1, block.getHash()))
|
||||||
|
@ -464,8 +466,9 @@ public abstract class AbstractBlockChain {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void informListenersForNewBlock(final Block block, final NewBlockType newBlockType,
|
private void informListenersForNewBlock(final Block block, final NewBlockType newBlockType,
|
||||||
final Set<Sha256Hash> filteredTxHashList,
|
@Nullable final Set<Sha256Hash> filteredTxHashList,
|
||||||
final List<Transaction> filteredTxn, final StoredBlock newStoredBlock) throws VerificationException {
|
@Nullable final List<Transaction> filteredTxn,
|
||||||
|
final StoredBlock newStoredBlock) throws VerificationException {
|
||||||
// Notify the listeners of the new block, so the depth and workDone of stored transactions can be updated
|
// Notify the listeners of the new block, so the depth and workDone of stored transactions can be updated
|
||||||
// (in the case of the listener being a wallet). Wallets need to know how deep each transaction is so
|
// (in the case of the listener being a wallet). Wallets need to know how deep each transaction is so
|
||||||
// coinbases aren't used before maturity.
|
// coinbases aren't used before maturity.
|
||||||
|
@ -501,8 +504,8 @@ public abstract class AbstractBlockChain {
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void informListenerForNewTransactions(Block block, NewBlockType newBlockType,
|
private static void informListenerForNewTransactions(Block block, NewBlockType newBlockType,
|
||||||
Set<Sha256Hash> filteredTxHashList,
|
@Nullable Set<Sha256Hash> filteredTxHashList,
|
||||||
List<Transaction> filteredTxn,
|
@Nullable List<Transaction> filteredTxn,
|
||||||
StoredBlock newStoredBlock, boolean first,
|
StoredBlock newStoredBlock, boolean first,
|
||||||
BlockChainListener listener) throws VerificationException {
|
BlockChainListener listener) throws VerificationException {
|
||||||
if (block.transactions != null || filteredTxn != null) {
|
if (block.transactions != null || filteredTxn != null) {
|
||||||
|
@ -732,7 +735,7 @@ public abstract class AbstractBlockChain {
|
||||||
}
|
}
|
||||||
// Otherwise we can connect it now.
|
// Otherwise we can connect it now.
|
||||||
// False here ensures we don't recurse infinitely downwards when connecting huge chains.
|
// False here ensures we don't recurse infinitely downwards when connecting huge chains.
|
||||||
add(orphanBlock.block, orphanBlock.filteredTxHashes, orphanBlock.filteredTxn, false);
|
add(orphanBlock.block, false, orphanBlock.filteredTxHashes, orphanBlock.filteredTxn);
|
||||||
iter.remove();
|
iter.remove();
|
||||||
blocksConnectedThisRound++;
|
blocksConnectedThisRound++;
|
||||||
}
|
}
|
||||||
|
@ -880,6 +883,7 @@ public abstract class AbstractBlockChain {
|
||||||
*
|
*
|
||||||
* @return from or one of froms parents, or null if "from" does not identify an orphan block
|
* @return from or one of froms parents, or null if "from" does not identify an orphan block
|
||||||
*/
|
*/
|
||||||
|
@Nullable
|
||||||
public Block getOrphanRoot(Sha256Hash from) {
|
public Block getOrphanRoot(Sha256Hash from) {
|
||||||
lock.lock();
|
lock.lock();
|
||||||
try {
|
try {
|
||||||
|
|
Loading…
Add table
Reference in a new issue