diff --git a/core/src/main/java/com/google/bitcoin/core/AbstractBlockChain.java b/core/src/main/java/com/google/bitcoin/core/AbstractBlockChain.java index 5aafa59f..15b7a431 100644 --- a/core/src/main/java/com/google/bitcoin/core/AbstractBlockChain.java +++ b/core/src/main/java/com/google/bitcoin/core/AbstractBlockChain.java @@ -399,7 +399,7 @@ public abstract class AbstractBlockChain { private void connectBlock(final Block block, StoredBlock storedPrev, boolean expensiveChecks, @Nullable final List filteredTxHashList, @Nullable final Map filteredTxn) throws BlockStoreException, VerificationException, PrunedException { - checkState(lock.isLocked()); + checkState(lock.isHeldByCurrentThread()); boolean filtered = filteredTxHashList != null && filteredTxn != null; boolean fullBlock = block.transactions != null && !filtered; // If !filtered and !fullBlock then we have just a header. @@ -576,7 +576,7 @@ public abstract class AbstractBlockChain { */ private void handleNewBestChain(StoredBlock storedPrev, StoredBlock newChainHead, Block block, boolean expensiveChecks) throws BlockStoreException, VerificationException, PrunedException { - checkState(lock.isLocked()); + checkState(lock.isHeldByCurrentThread()); // This chain has overtaken the one we currently believe is best. Reorganize is required. // // Firstly, calculate the block at which the chain diverged. We only need to examine the @@ -733,7 +733,7 @@ public abstract class AbstractBlockChain { * For each block in orphanBlocks, see if we can now fit it on top of the chain and if so, do so. */ private void tryConnectingOrphans() throws VerificationException, BlockStoreException, PrunedException { - checkState(lock.isLocked()); + checkState(lock.isHeldByCurrentThread()); // For each block in our orphan list, try and fit it onto the head of the chain. If we succeed remove it // from the list and keep going. If we changed the head of the list at the end of the round try again until // we can't fit anything else on the top. @@ -773,7 +773,7 @@ public abstract class AbstractBlockChain { * Throws an exception if the blocks difficulty is not correct. */ private void checkDifficultyTransitions(StoredBlock storedPrev, Block nextBlock) throws BlockStoreException, VerificationException { - checkState(lock.isLocked()); + checkState(lock.isHeldByCurrentThread()); Block prev = storedPrev.getHeader(); // Is this supposed to be a difficulty transition point? @@ -842,7 +842,7 @@ public abstract class AbstractBlockChain { } private void checkTestnetDifficulty(StoredBlock storedPrev, Block prev, Block next) throws VerificationException, BlockStoreException { - checkState(lock.isLocked()); + checkState(lock.isHeldByCurrentThread()); // After 15th February 2012 the rules on the testnet change to avoid people running up the difficulty // and then leaving, making it too hard to mine a block. On non-difficulty transition points, easy // blocks are allowed if there has been a span of 20 minutes without one. diff --git a/core/src/main/java/com/google/bitcoin/core/FullPrunedBlockChain.java b/core/src/main/java/com/google/bitcoin/core/FullPrunedBlockChain.java index 6a1bbb07..96efae08 100644 --- a/core/src/main/java/com/google/bitcoin/core/FullPrunedBlockChain.java +++ b/core/src/main/java/com/google/bitcoin/core/FullPrunedBlockChain.java @@ -124,7 +124,7 @@ public class FullPrunedBlockChain extends AbstractBlockChain { @Override protected TransactionOutputChanges connectTransactions(int height, Block block) throws VerificationException, BlockStoreException { - checkState(lock.isLocked()); + checkState(lock.isHeldByCurrentThread()); if (block.transactions == null) throw new RuntimeException("connectTransactions called with Block that didn't have transactions!"); if (!params.passesCheckpoint(height, block.getHash())) @@ -255,7 +255,7 @@ public class FullPrunedBlockChain extends AbstractBlockChain { */ protected synchronized TransactionOutputChanges connectTransactions(StoredBlock newBlock) throws VerificationException, BlockStoreException, PrunedException { - checkState(lock.isLocked()); + checkState(lock.isHeldByCurrentThread()); if (!params.passesCheckpoint(newBlock.getHeight(), newBlock.getHeader().getHash())) throw new VerificationException("Block failed checkpoint lockin at " + newBlock.getHeight()); @@ -392,7 +392,7 @@ public class FullPrunedBlockChain extends AbstractBlockChain { */ @Override protected void disconnectTransactions(StoredBlock oldBlock) throws PrunedException, BlockStoreException { - checkState(lock.isLocked()); + checkState(lock.isHeldByCurrentThread()); blockStore.beginDatabaseBatchWrite(); try { StoredUndoableBlock undoBlock = blockStore.getUndoBlock(oldBlock.getHeader().getHash()); @@ -413,7 +413,7 @@ public class FullPrunedBlockChain extends AbstractBlockChain { @Override protected void doSetChainHead(StoredBlock chainHead) throws BlockStoreException { - checkState(lock.isLocked()); + checkState(lock.isHeldByCurrentThread()); blockStore.setVerifiedChainHead(chainHead); blockStore.commitDatabaseBatchWrite(); } @@ -425,7 +425,7 @@ public class FullPrunedBlockChain extends AbstractBlockChain { @Override protected StoredBlock getStoredBlockInCurrentScope(Sha256Hash hash) throws BlockStoreException { - checkState(lock.isLocked()); + checkState(lock.isHeldByCurrentThread()); return blockStore.getOnceUndoableStoredBlock(hash); } } diff --git a/core/src/main/java/com/google/bitcoin/core/MemoryPool.java b/core/src/main/java/com/google/bitcoin/core/MemoryPool.java index 0d74ab5c..bb22917e 100644 --- a/core/src/main/java/com/google/bitcoin/core/MemoryPool.java +++ b/core/src/main/java/com/google/bitcoin/core/MemoryPool.java @@ -266,7 +266,7 @@ public class MemoryPool { } private void markBroadcast(PeerAddress byPeer, Transaction tx) { - checkState(lock.isLocked()); + checkState(lock.isHeldByCurrentThread()); final TransactionConfidence confidence = tx.getConfidence(); confidence.markBroadcastBy(byPeer); confidence.queueListeners(TransactionConfidence.Listener.ChangeReason.SEEN_PEERS); diff --git a/core/src/main/java/com/google/bitcoin/core/PeerGroup.java b/core/src/main/java/com/google/bitcoin/core/PeerGroup.java index 9180ce0f..e8b475b3 100644 --- a/core/src/main/java/com/google/bitcoin/core/PeerGroup.java +++ b/core/src/main/java/com/google/bitcoin/core/PeerGroup.java @@ -884,7 +884,7 @@ public class PeerGroup extends AbstractIdleService implements TransactionBroadca } private void setupPingingForNewPeer(final Peer peer) { - checkState(lock.isLocked()); + checkState(lock.isHeldByCurrentThread()); if (peer.getPeerVersionMessage().clientVersion < Pong.MIN_PROTOCOL_VERSION) return; if (getPingIntervalMsec() <= 0) @@ -930,7 +930,7 @@ public class PeerGroup extends AbstractIdleService implements TransactionBroadca /** Returns true if at least one peer received an inv. */ private boolean announcePendingWalletTransactions(List announceWallets, List announceToPeers) { - checkState(lock.isLocked()); + checkState(lock.isHeldByCurrentThread()); // Build up an inv announcing the hashes of all pending transactions in all our wallets. InventoryMessage inv = new InventoryMessage(params); for (Wallet w : announceWallets) { diff --git a/core/src/main/java/com/google/bitcoin/core/Wallet.java b/core/src/main/java/com/google/bitcoin/core/Wallet.java index 72e9493c..e0facf80 100644 --- a/core/src/main/java/com/google/bitcoin/core/Wallet.java +++ b/core/src/main/java/com/google/bitcoin/core/Wallet.java @@ -765,7 +765,7 @@ public class Wallet implements Serializable, BlockChainListener, PeerFilterProvi * the double spent inputs are not ours. Returns the pending tx that was double spent or null if none found. */ private boolean checkForDoubleSpendAgainstPending(Transaction tx, boolean takeAction) { - checkState(lock.isLocked()); + checkState(lock.isHeldByCurrentThread()); // Compile a set of outpoints that are spent by tx. HashSet outpoints = new HashSet(); for (TransactionInput input : tx.getInputs()) { @@ -824,7 +824,7 @@ public class Wallet implements Serializable, BlockChainListener, PeerFilterProvi private void receive(Transaction tx, StoredBlock block, BlockChain.NewBlockType blockType) throws VerificationException { // Runs in a peer thread. - checkState(lock.isLocked()); + checkState(lock.isHeldByCurrentThread()); BigInteger prevBalance = getBalance(); Sha256Hash txHash = tx.getHash(); boolean bestChain = blockType == BlockChain.NewBlockType.BEST_CHAIN; @@ -989,7 +989,7 @@ public class Wallet implements Serializable, BlockChainListener, PeerFilterProvi * re-org. Places the tx into the right pool, handles coinbase transactions, handles double-spends and so on. */ private void processTxFromBestChain(Transaction tx) throws VerificationException { - checkState(lock.isLocked()); + checkState(lock.isHeldByCurrentThread()); checkState(!pending.containsKey(tx.getHash())); // This TX may spend our existing outputs even though it was not pending. This can happen in unit @@ -1049,7 +1049,7 @@ public class Wallet implements Serializable, BlockChainListener, PeerFilterProvi * @param fromChain If true, the tx appeared on the current best chain, if false it was pending. */ private void updateForSpends(Transaction tx, boolean fromChain) throws VerificationException { - checkState(lock.isLocked()); + checkState(lock.isHeldByCurrentThread()); if (fromChain) checkState(!pending.containsKey(tx.getHash())); for (TransactionInput input : tx.getInputs()) { @@ -1160,7 +1160,7 @@ public class Wallet implements Serializable, BlockChainListener, PeerFilterProvi * If the owned transactions outputs are not all marked as spent, and it's in the spent map, move it. */ private void maybeMovePool(Transaction tx, String context) { - checkState(lock.isLocked()); + checkState(lock.isHeldByCurrentThread()); if (tx.isEveryOwnedOutputSpent(this)) { // There's nothing left I can spend in this transaction. if (unspent.remove(tx.getHash()) != null) { @@ -1330,7 +1330,7 @@ public class Wallet implements Serializable, BlockChainListener, PeerFilterProvi * Adds the given transaction to the given pools and registers a confidence change listener on it. */ private void addWalletTransaction(Pool pool, Transaction tx) { - checkState(lock.isLocked()); + checkState(lock.isHeldByCurrentThread()); switch (pool) { case UNSPENT: checkState(unspent.put(tx.getHash(), tx) == null); @@ -1881,7 +1881,7 @@ public class Wallet implements Serializable, BlockChainListener, PeerFilterProvi } private LinkedList calculateSpendCandidates(boolean excludeImmatureCoinbases) { - checkState(lock.isLocked()); + checkState(lock.isHeldByCurrentThread()); LinkedList candidates = Lists.newLinkedList(); for (Transaction tx : Iterables.concat(unspent.values(), pending.values())) { // Do not try and spend coinbases that were mined too recently, the protocol forbids it. @@ -2139,7 +2139,7 @@ public class Wallet implements Serializable, BlockChainListener, PeerFilterProvi private void toStringHelper(StringBuilder builder, Map transactionMap, AbstractBlockChain chain) { - checkState(lock.isLocked()); + checkState(lock.isHeldByCurrentThread()); for (Transaction tx : transactionMap.values()) { try { builder.append("Sends "); @@ -2838,7 +2838,7 @@ public class Wallet implements Serializable, BlockChainListener, PeerFilterProvi // Runs any balance futures in the user code thread. private void checkBalanceFuturesLocked(@Nullable BigInteger avail) { - checkState(lock.isLocked()); + checkState(lock.isHeldByCurrentThread()); BigInteger estimated = null; final ListIterator it = balanceFutureRequests.listIterator(); while (it.hasNext()) { @@ -2937,7 +2937,7 @@ public class Wallet implements Serializable, BlockChainListener, PeerFilterProvi // anything and hold no locks). private void queueOnTransactionConfidenceChanged(final Transaction tx) { - checkState(lock.isLocked()); + checkState(lock.isHeldByCurrentThread()); for (final ListenerRegistration registration : eventListeners) { registration.executor.execute(new Runnable() { @Override @@ -2951,7 +2951,7 @@ public class Wallet implements Serializable, BlockChainListener, PeerFilterProvi private void maybeQueueOnWalletChanged() { // Don't invoke the callback in some circumstances, eg, whilst we are re-organizing or fiddling with // transactions due to a new block arriving. It will be called later instead. - checkState(lock.isLocked()); + checkState(lock.isHeldByCurrentThread()); checkState(onWalletChangedSuppressions >= 0); if (onWalletChangedSuppressions > 0) return; for (final ListenerRegistration registration : eventListeners) { @@ -2965,7 +2965,7 @@ public class Wallet implements Serializable, BlockChainListener, PeerFilterProvi } private void queueOnCoinsReceived(final Transaction tx, final BigInteger balance, final BigInteger newBalance) { - checkState(lock.isLocked()); + checkState(lock.isHeldByCurrentThread()); for (final ListenerRegistration registration : eventListeners) { registration.executor.execute(new Runnable() { @Override @@ -2977,7 +2977,7 @@ public class Wallet implements Serializable, BlockChainListener, PeerFilterProvi } private void queueOnCoinsSent(final Transaction tx, final BigInteger prevBalance, final BigInteger newBalance) { - checkState(lock.isLocked()); + checkState(lock.isHeldByCurrentThread()); for (final ListenerRegistration registration : eventListeners) { registration.executor.execute(new Runnable() { @Override @@ -2989,7 +2989,7 @@ public class Wallet implements Serializable, BlockChainListener, PeerFilterProvi } private void queueOnReorganize() { - checkState(lock.isLocked()); + checkState(lock.isHeldByCurrentThread()); checkState(insideReorg); for (final ListenerRegistration registration : eventListeners) { registration.executor.execute(new Runnable() { @@ -3002,7 +3002,7 @@ public class Wallet implements Serializable, BlockChainListener, PeerFilterProvi } private void queueOnKeysAdded(final List keys) { - checkState(lock.isLocked()); + checkState(lock.isHeldByCurrentThread()); for (final ListenerRegistration registration : eventListeners) { registration.executor.execute(new Runnable() { @Override