From 4606d5fb310f2e0e4d7fde85795dadcfd7489acf Mon Sep 17 00:00:00 2001 From: HashEngineering Date: Tue, 19 Mar 2024 06:39:32 -0700 Subject: [PATCH] fix: reduce logging and use markers (#248) --- .../java/org/bitcoinj/coinjoin/CoinJoin.java | 4 +- .../org/bitcoinj/coinjoin/CoinJoinAccept.java | 2 +- .../coinjoin/CoinJoinBaseManager.java | 4 +- .../coinjoin/CoinJoinBaseSession.java | 3 +- .../coinjoin/CoinJoinClientManager.java | 8 +- .../coinjoin/CoinJoinClientQueueManager.java | 16 ++-- .../coinjoin/CoinJoinClientSession.java | 76 ++++++++++--------- .../bitcoinj/coinjoin/CoinJoinConstants.java | 5 ++ .../org/bitcoinj/coinjoin/CoinJoinQueue.java | 6 +- .../coinjoin/CoinJoinStatusUpdate.java | 2 +- .../coinjoin/utils/KeyHolderStorage.java | 8 +- .../coinjoin/utils/MasternodeGroup.java | 24 +++--- .../signers/CoinJoinTransactionSigner.java | 2 +- .../bitcoinj/wallet/CoinJoinExtension.java | 24 +++--- .../java/org/bitcoinj/wallet/WalletEx.java | 21 +++-- .../org/bitcoinj/coinjoin/CoinJoinServer.java | 2 +- 16 files changed, 113 insertions(+), 94 deletions(-) diff --git a/core/src/main/java/org/bitcoinj/coinjoin/CoinJoin.java b/core/src/main/java/org/bitcoinj/coinjoin/CoinJoin.java index 71cc9fbb93..4b94013cbf 100644 --- a/core/src/main/java/org/bitcoinj/coinjoin/CoinJoin.java +++ b/core/src/main/java/org/bitcoinj/coinjoin/CoinJoin.java @@ -182,14 +182,14 @@ public static boolean isCollateralValid(Transaction txCollateral, boolean checkI } nValueIn = nValueIn.add(tx.getOutput(txin.getOutpoint().getIndex()).getValue()); } else { - log.info("coinjoin: -- Unknown inputs in collateral transaction, txCollateral={}", txCollateral); /* Continued */ + log.info("coinjoin: Unknown inputs in collateral transaction, txCollateral={}", txCollateral); /* Continued */ return false; } } //collateral transactions are required to pay out a small fee to the miners if (nValueIn.minus(nValueOut).isLessThan(getCollateralAmount())) { - log.info("coinjoin: did not include enough fees in transaction: fees: {}, txCollateral={}", nValueOut.minus(nValueIn), txCollateral); /* Continued */ + log.info("coinjoin: did not include enough fees in transaction: fees: {}, txCollateral={}", nValueOut.minus(nValueIn), txCollateral); /* Continued */ return false; } } diff --git a/core/src/main/java/org/bitcoinj/coinjoin/CoinJoinAccept.java b/core/src/main/java/org/bitcoinj/coinjoin/CoinJoinAccept.java index 29dc74a4f2..b563f06b04 100644 --- a/core/src/main/java/org/bitcoinj/coinjoin/CoinJoinAccept.java +++ b/core/src/main/java/org/bitcoinj/coinjoin/CoinJoinAccept.java @@ -56,7 +56,7 @@ protected void bitcoinSerializeToStream(OutputStream stream) throws IOException @Override public String toString() { return String.format( - "CoinJoinAccept(denomination=%d, txCollateral=%s)", + "CoinJoinAccept(denom=%d, txCol=%s)", denomination, txCollateral.getTxId() ); diff --git a/core/src/main/java/org/bitcoinj/coinjoin/CoinJoinBaseManager.java b/core/src/main/java/org/bitcoinj/coinjoin/CoinJoinBaseManager.java index 0f4e117f69..88ea4f0060 100644 --- a/core/src/main/java/org/bitcoinj/coinjoin/CoinJoinBaseManager.java +++ b/core/src/main/java/org/bitcoinj/coinjoin/CoinJoinBaseManager.java @@ -27,6 +27,8 @@ import java.util.Iterator; import java.util.concurrent.locks.ReentrantLock; +import static org.bitcoinj.coinjoin.CoinJoinConstants.COINJOIN_EXTRA; + public class CoinJoinBaseManager { private final Logger log = LoggerFactory.getLogger(CoinJoinBaseManager.class); @@ -50,7 +52,7 @@ protected void checkQueue() { while (it.hasNext()) { CoinJoinQueue queue = it.next(); if (queue.isTimeOutOfBounds(Utils.currentTimeSeconds())) { - log.info("Removing a queue {}", queue); + log.info(COINJOIN_EXTRA, "Removing a queue {}", queue); it.remove(); } } diff --git a/core/src/main/java/org/bitcoinj/coinjoin/CoinJoinBaseSession.java b/core/src/main/java/org/bitcoinj/coinjoin/CoinJoinBaseSession.java index 424049e73f..c485fbf292 100644 --- a/core/src/main/java/org/bitcoinj/coinjoin/CoinJoinBaseSession.java +++ b/core/src/main/java/org/bitcoinj/coinjoin/CoinJoinBaseSession.java @@ -38,6 +38,7 @@ import java.util.concurrent.atomic.AtomicReference; import java.util.concurrent.locks.ReentrantLock; +import static org.bitcoinj.coinjoin.CoinJoinConstants.COINJOIN_EXTRA; import static org.bitcoinj.coinjoin.PoolMessage.ERR_ALREADY_HAVE; import static org.bitcoinj.coinjoin.PoolMessage.ERR_DENOM; import static org.bitcoinj.coinjoin.PoolMessage.ERR_FEES; @@ -137,7 +138,7 @@ public ValidInOuts check(TransactionOutput txout) { } for (TransactionInput txin :vin){ - log.info(" txin={}", txin); + log.info(COINJOIN_EXTRA, " txin={}", txin); if (txin.getOutpoint() == null) { log.info("coinjoin: ERROR: invalid input!"); diff --git a/core/src/main/java/org/bitcoinj/coinjoin/CoinJoinClientManager.java b/core/src/main/java/org/bitcoinj/coinjoin/CoinJoinClientManager.java index c0cfe69548..a561e948e8 100644 --- a/core/src/main/java/org/bitcoinj/coinjoin/CoinJoinClientManager.java +++ b/core/src/main/java/org/bitcoinj/coinjoin/CoinJoinClientManager.java @@ -64,6 +64,7 @@ import static com.google.common.base.Preconditions.checkArgument; import static org.bitcoinj.coinjoin.CoinJoinConstants.COINJOIN_AUTO_TIMEOUT_MAX; import static org.bitcoinj.coinjoin.CoinJoinConstants.COINJOIN_AUTO_TIMEOUT_MIN; +import static org.bitcoinj.coinjoin.CoinJoinConstants.COINJOIN_EXTRA; public class CoinJoinClientManager implements WalletCoinsReceivedEventListener { private static final Logger log = LoggerFactory.getLogger(CoinJoinClientManager.class); @@ -293,7 +294,7 @@ public boolean doAutomaticDenominating(boolean dryRun) { if (!dryRun && waitForAnotherBlock()) { if (Utils.currentTimeMillis() - lastTimeReportTooRecent > 15000 ) { strAutoDenomResult = "Last successful action was too recent."; - log.info("DoAutomaticDenominating -- {}", strAutoDenomResult); + log.info("DoAutomaticDenominating: {}", strAutoDenomResult); lastTimeReportTooRecent = Utils.currentTimeMillis(); } return false; @@ -317,7 +318,8 @@ public boolean trySubmitDenominate(MasternodeAddress mnAddr) { session.submitDenominate(); return true; } else { - log.info("mixingMasternode {} != mnAddr {} or {} != {}", mnMixing != null ? mnMixing.getService().getSocketAddress() : "null", mnAddr.getSocketAddress(), + log.info(COINJOIN_EXTRA, "mixingMasternode {} != mnAddr {} or {} != {}", + mnMixing != null ? mnMixing.getService().getSocketAddress() : "null", mnAddr.getSocketAddress(), session.getState(), PoolState.POOL_STATE_QUEUE); } } @@ -407,7 +409,7 @@ public void processMN(SimplifiedMasternodeListEntry mn) { continue; } - log.info("coinjoin: found, masternode={}", dmn.getProTxHash()); + log.info("coinjoin: found, masternode={}", dmn.getProTxHash().toString().substring(0, 16)); return dmn; } diff --git a/core/src/main/java/org/bitcoinj/coinjoin/CoinJoinClientQueueManager.java b/core/src/main/java/org/bitcoinj/coinjoin/CoinJoinClientQueueManager.java index 9450068f07..73ae24bf70 100644 --- a/core/src/main/java/org/bitcoinj/coinjoin/CoinJoinClientQueueManager.java +++ b/core/src/main/java/org/bitcoinj/coinjoin/CoinJoinClientQueueManager.java @@ -28,6 +28,8 @@ import java.util.HashMap; import java.util.function.Predicate; +import static org.bitcoinj.coinjoin.CoinJoinConstants.COINJOIN_EXTRA; + public class CoinJoinClientQueueManager extends CoinJoinBaseManager { private final Context context; private final Logger log = LoggerFactory.getLogger(CoinJoinClientManager.class); @@ -51,7 +53,7 @@ public void processDSQueue(Peer from, CoinJoinQueue dsq, boolean enable_bip61) { // no way the same mn can send another dsq with the same readiness this soon if (!spammingMasternodes.containsKey(dsq.getProTxHash())) { spammingMasternodes.put(dsq.getProTxHash(), Utils.currentTimeMillis()); - log.info("coinjoin: DSQUEUE -- Peer {} is sending WAY too many dsq messages for a masternode {}", from.getAddress().getAddr(), dsq.getProTxHash()); + log.info(COINJOIN_EXTRA, "coinjoin: DSQUEUE: Peer {} is sending WAY too many dsq messages for a masternode {}", from.getAddress().getAddr(), dsq.getProTxHash()); } return; } @@ -62,7 +64,7 @@ public void processDSQueue(Peer from, CoinJoinQueue dsq, boolean enable_bip61) { } - log.info("coinjoin: DSQUEUE -- {} new", dsq); + log.info(COINJOIN_EXTRA, "coinjoin: DSQUEUE -- {} new", dsq); if (dsq.isTimeOutOfBounds()) return; @@ -79,24 +81,24 @@ public void processDSQueue(Peer from, CoinJoinQueue dsq, boolean enable_bip61) { // if the queue is ready, submit if we can if (dsq.isReady() && isTrySubmitDenominate(dmn)) { - log.info("coinjoin: DSQUEUE -- CoinJoin queue ({}) is ready on masternode {}", dsq, dmn.getService()); + log.info("coinjoin: DSQUEUE: {} is ready on masternode {}", dsq, dmn.getService()); } else { long nLastDsq = context.masternodeMetaDataManager.getMetaInfo(dmn.getProTxHash()).getLastDsq(); long nDsqThreshold = context.masternodeMetaDataManager.getDsqThreshold(dmn.getProTxHash(), mnList.getValidMNsCount()); - log.info("coinjoin: DSQUEUE -- lastDsq: {} dsqThreshold: {} dsqCount: {}", nLastDsq, nDsqThreshold, context.masternodeMetaDataManager.getDsqCount()); + log.info(COINJOIN_EXTRA, "coinjoin: DSQUEUE -- lastDsq: {} dsqThreshold: {} dsqCount: {}", + nLastDsq, nDsqThreshold, context.masternodeMetaDataManager.getDsqCount()); // don't allow a few nodes to dominate the queuing process if (nLastDsq != 0 && nDsqThreshold > context.masternodeMetaDataManager.getDsqCount()) { if (!spammingMasternodes.containsKey(dsq.getProTxHash())) { spammingMasternodes.put(dsq.getProTxHash(), Utils.currentTimeMillis()); - log.info("coinjoin: DSQUEUE -- Masternode {} is sending too many dsq messages", dmn.getProTxHash()); + log.info(COINJOIN_EXTRA, "coinjoin: DSQUEUE: Masternode {} is sending too many dsq messages", dmn.getProTxHash()); } return; } context.masternodeMetaDataManager.allowMixing(dmn.getProTxHash()); - log.info("coinjoin: DSQUEUE -- new CoinJoin queue ({}) from masternode {}", dsq, dmn.getService()); - + log.info("coinjoin: DSQUEUE: new {} from masternode {}", dsq, dmn.getService().getAddr()); context.coinJoinManager.coinJoinClientManagers.values().stream().anyMatch(new Predicate() { @Override diff --git a/core/src/main/java/org/bitcoinj/coinjoin/CoinJoinClientSession.java b/core/src/main/java/org/bitcoinj/coinjoin/CoinJoinClientSession.java index a6c843fd9c..5e5306b089 100644 --- a/core/src/main/java/org/bitcoinj/coinjoin/CoinJoinClientSession.java +++ b/core/src/main/java/org/bitcoinj/coinjoin/CoinJoinClientSession.java @@ -75,6 +75,7 @@ import static org.bitcoinj.coinjoin.CoinJoinConstants.COINJOIN_DENOM_OUTPUTS_THRESHOLD; import static org.bitcoinj.coinjoin.CoinJoinConstants.COINJOIN_ENTRY_MAX_SIZE; +import static org.bitcoinj.coinjoin.CoinJoinConstants.COINJOIN_EXTRA; import static org.bitcoinj.coinjoin.CoinJoinConstants.COINJOIN_QUEUE_TIMEOUT; import static org.bitcoinj.coinjoin.CoinJoinConstants.COINJOIN_SIGNING_TIMEOUT; import static org.bitcoinj.coinjoin.PoolMessage.ERR_CONNECTION_TIMEOUT; @@ -152,12 +153,12 @@ private boolean createDenominated(Coin balanceToDenominate, boolean dryRun) { return true; } - log.info("coinjoin: createDenominated({}) -- failed! ", balanceToDenominate.toFriendlyString()); + log.info("coinjoin: createDenominated({}) failed! ", balanceToDenominate.toFriendlyString()); return false; } public void processTransaction(Transaction tx) { - log.info("processing tx of {}: {}", tx.getValue(mixingWallet), tx.getTxId()); + log.info(COINJOIN_EXTRA, "processing tx of {}: {}", tx.getValue(mixingWallet), tx.getTxId()); if (collateralSessionMap.containsKey(tx.getTxId())) { queueTransactionListeners(tx, collateralSessionMap.get(tx.getTxId()), CoinJoinTransactionType.MixingFee); } @@ -393,7 +394,7 @@ private boolean makeCollateralAmounts() { // This still leaves more than enough room for another data of typical MakeCollateralAmounts tx. List vecTally = mixingWallet.selectCoinsGroupedByAddresses(false, false, true, 400); if (vecTally.isEmpty()) { - log.info("coinjoin -- SelectCoinsGroupedByAddresses can't find any inputs!\n"); + log.info("coinjoin: selectCoinsGroupedByAddresses can't find any inputs!\n"); return false; } @@ -418,7 +419,7 @@ public int compare(CompactTallyItem a, CompactTallyItem b) { } // If we got here then something is terribly broken actually - log.info("coinjoin -- ERROR: Can't make collaterals!\n"); + log.error("coinjoin: ERROR: Can't make collaterals!\n"); return false; } private boolean makeCollateralAmounts(CompactTallyItem tallyItem, boolean fTryDenominated) { @@ -612,7 +613,7 @@ private boolean joinExistingQueue(Coin balanceNeedsAnonymized) { mixingWallet.getContext().coinJoinManager.addPendingMasternode(this); setState(POOL_STATE_QUEUE); timeLastSuccessfulStep.set(Utils.currentTimeSeconds()); - log.info("coinjoin: join existing queue -> pending connection, sessionDenom: {} ({}), addr={}", + log.info("coinjoin: join existing queue -> pending connection, denom: {} ({}), addr={}", sessionDenom, CoinJoin.denominationToString(sessionDenom), dmn.getService()); setStatus(PoolStatus.CONNECTING); joined = true; @@ -671,7 +672,7 @@ private boolean startNewQueue(Coin balanceNeedsAnonymized) { continue; } - log.info("coinjoin: attempt {} connection to masternode {}, protx: {}", nTries + 1, dmn.getService(), dmn.getProTxHash()); + log.info("coinjoin: attempt {} connection to mn {}, protx: {}", nTries + 1, dmn.getService(), dmn.getProTxHash().toString().substring(0, 16)); // try to get a single random denom out of setAmounts while (sessionDenom == 0) { @@ -768,7 +769,8 @@ private boolean prepareDenominate(int minRounds, int maxRounds, StringBuilder st if (vecPSInOutPairsRet.isEmpty()) { keyHolderStorage.returnAll(); - strErrorRet.append("Can't prepare current denominated outputs"); + if (strErrorRet.length() == 0) + strErrorRet.append("Can't prepare current denominated outputs"); return false; } @@ -787,7 +789,7 @@ private boolean prepareDenominate(int minRounds, int maxRounds, StringBuilder st private boolean sendDenominate(List> vecPSInOutPairs) { if (txMyCollateral.getInputs().isEmpty()) { - log.info("coinjoin: -- CoinJoin collateral not set"); + log.info("coinjoin: CoinJoin collateral not set"); return false; } @@ -808,7 +810,7 @@ private boolean sendDenominate(List vecTxDSInTmp = Lists.newArrayList(); @@ -821,7 +823,7 @@ private boolean sendDenominate(List MSG_POOL_MAX.value) { - log.info("DSCOMPLETE -- nMsgMessageID is out of bounds: {}", completeMessage.getMsgMessageID()); + log.info("DSCOMPLETE: msgID is out of bounds: {}", completeMessage.getMsgMessageID()); return; } if (sessionID.get() != completeMessage.getMsgSessionID()) { - log.info("DSCOMPLETE -- message doesn't match current CoinJoin session: nSessionID: {} nMsgSessionID: {}", sessionID.get(), completeMessage.getMsgSessionID()); + log.info("DSCOMPLETE: message doesn't match current CoinJoin session: SID: {} msgID: {} ({})", + sessionID.get(), completeMessage.getMsgSessionID(), + CoinJoin.getMessageByID(completeMessage.getMsgMessageID())); return; } - log.info("DSCOMPLETE -- nMsgSessionID {} nMsgMessageID {} ({})", completeMessage.getMsgSessionID(), + log.info("DSCOMPLETE: msgSID {} msg {} ({})", completeMessage.getMsgSessionID(), completeMessage.getMsgMessageID(), CoinJoin.getMessageByID(completeMessage.getMsgMessageID())); completedTransaction(completeMessage.getMsgMessageID()); @@ -1327,7 +1331,7 @@ public boolean doAutomaticDenominating(boolean fDryRun) { setStatus(PoolStatus.ERR_NOT_ENOUGH_FUNDS); queueSessionCompleteListeners(getState(), ERR_SESSION); } - log.info("coinjoin: balance to low: {}", fDryRun); + log.info("coinjoin: balance too low: dryRun: {}", fDryRun); return false; } @@ -1353,9 +1357,9 @@ public boolean doAutomaticDenominating(boolean fDryRun) { balanceNeedsAnonymized = balanceNeedsAnonymized.add(nAdditionalDenom); } - log.info("coinjoin: wallet stats:\n{}", bal); + log.info(COINJOIN_EXTRA, "coinjoin: wallet stats:\n{}", bal); - log.info("coinjoin: current stats:\n" + + log.info(COINJOIN_EXTRA, "coinjoin: current stats:\n" + " min: {}\n" + " myTrusted: {}\n" + " balanceAnonymizable: {}\n" + @@ -1490,10 +1494,10 @@ public boolean submitDenominate() { for (int i = 0; i < CoinJoinClientOptions.getRounds() + CoinJoinClientOptions.getRandomRounds(); ++i) { if (prepareDenominate(i, i, strError, vecTxDSIn, vecPSInOutPairsTmp, true)) { - log.info("coinjoin: Running CoinJoin denominate for {} rounds, success", i); + log.info("coinjoin: Running CoinJoin denominate for {} rounds, success", i); vecInputsByRounds.add(new Pair<>(i, vecPSInOutPairsTmp.size())); } else { - log.info("coinjoin: Running CoinJoin denominate for {} rounds, error: {}", i, strError); + log.info(COINJOIN_EXTRA, "coinjoin: Running CoinJoin denominate for {} rounds, error: {}", i, strError); } } @@ -1507,23 +1511,23 @@ public int compare(Pair a, Pair b) { log.info("coinjoin: vecInputsByRounds(size={}) for denom {}", vecInputsByRounds.size(), sessionDenom); for (Pair pair : vecInputsByRounds) { - log.info("coinjoin: vecInputsByRounds: rounds: {}, inputs: {}", pair.getFirst(), pair.getSecond()); + log.info(COINJOIN_EXTRA, "coinjoin: vecInputsByRounds: rounds: {}, inputs: {}", pair.getFirst(), pair.getSecond()); } int nRounds = vecInputsByRounds.get(0).getFirst(); if (prepareDenominate(nRounds, nRounds, strError, vecTxDSIn, vecPSInOutPairsTmp)) { - log.info("coinjoin: Running CoinJoin denominate for {} rounds, success", nRounds); + log.info("coinjoin: Running CoinJoin denominate for {} rounds, success", nRounds); return sendDenominate(vecPSInOutPairsTmp); } // We failed? That's strange but let's just make final attempt and try to mix everything if (prepareDenominate(0, CoinJoinClientOptions.getRounds() - 1, strError, vecTxDSIn, vecPSInOutPairsTmp)) { - log.info("coinjoin: Running CoinJoin denominate for all rounds, success\n"); + log.info("coinjoin: Running CoinJoin denominate for all rounds, success\n"); return sendDenominate(vecPSInOutPairsTmp); } // Should never actually get here but just in case - log.info("coinjoin: Running CoinJoin denominate for all rounds, error: {}", strError); + log.info("coinjoin: Running CoinJoin denominate for all rounds, error: {}", strError); strAutoDenomResult = strError.toString(); return false; } @@ -1538,7 +1542,7 @@ public boolean processPendingDsaRequest() { public boolean process(Peer peer) { timeLastSuccessfulStep.set(Utils.currentTimeSeconds()); peer.sendMessage(pendingDsaRequest.getDsa()); - log.info("coinjoin: valid collateral before sending: {}", CoinJoin.isCollateralValid(pendingDsaRequest.getDsa().getTxCollateral())); + log.info(COINJOIN_EXTRA, "coinjoin: valid collateral before sending: {}", CoinJoin.isCollateralValid(pendingDsaRequest.getDsa().getTxCollateral())); log.info("sending {} to {}", pendingDsaRequest.getDsa(), peer); return true; } @@ -1599,8 +1603,8 @@ public String toString() { ", dsa=" + pendingDsaRequest + ", entries=" + entries.size() + ", state=" + state + - ", sessionID=" + sessionID + - ", sessionDenom=" + CoinJoin.denominationToString(sessionDenom) + "[" + sessionDenom + "]" + + ", SID=" + sessionID + + ", denom=" + CoinJoin.denominationToString(sessionDenom) + "[" + sessionDenom + "]" + '}'; } diff --git a/core/src/main/java/org/bitcoinj/coinjoin/CoinJoinConstants.java b/core/src/main/java/org/bitcoinj/coinjoin/CoinJoinConstants.java index 93f71f7b3b..d157f67702 100644 --- a/core/src/main/java/org/bitcoinj/coinjoin/CoinJoinConstants.java +++ b/core/src/main/java/org/bitcoinj/coinjoin/CoinJoinConstants.java @@ -18,6 +18,8 @@ import org.bitcoinj.core.Coin; import org.bitcoinj.core.NetworkParameters; +import org.slf4j.Marker; +import org.slf4j.MarkerFactory; public class CoinJoinConstants { public static final int COINJOIN_AUTO_TIMEOUT_MIN = 5; @@ -63,4 +65,7 @@ public class CoinJoinConstants { public static final int COINJOIN_KEYS_THRESHOLD_STOP = 50; // Pseudorandomly mix up to this many times in addition to base round count public static final int COINJOIN_RANDOM_ROUNDS = 3; + + public static Marker COINJOIN_EXTRA = MarkerFactory.getMarker("coinjoin-extra"); + public static Marker COINJOIN = MarkerFactory.getMarker("coinjoin-extra"); } diff --git a/core/src/main/java/org/bitcoinj/coinjoin/CoinJoinQueue.java b/core/src/main/java/org/bitcoinj/coinjoin/CoinJoinQueue.java index 3a71109910..b19ed672ef 100644 --- a/core/src/main/java/org/bitcoinj/coinjoin/CoinJoinQueue.java +++ b/core/src/main/java/org/bitcoinj/coinjoin/CoinJoinQueue.java @@ -123,7 +123,7 @@ public boolean checkSignature(BLSPublicKey pubKey) { BLSSignature sig = new BLSSignature(signature.getBytes(), BLSScheme.isLegacyDefault()); if (!sig.verifyInsecure(pubKey, hash)) { - log.info("CoinJoinQueue-CheckSignature -- VerifyInsecure() failed\n"); + log.info("CoinJoinQueue-CheckSignature: verifyInsecure failed\n"); return false; } @@ -145,13 +145,13 @@ public boolean sign(BLSSecretKey blsKeyOperator) { @Override public String toString() { return String.format( - "CoinJoinQueue(denomination=%s[%d], time=%d[expired=%s], ready=%s, proTxHash=%s)", + "CoinJoinQueue(denom=%s[%d], t=%d[exp=%s], ready=%s, proTxHash=%s)", CoinJoin.denominationToString(denomination), denomination, time, isTimeOutOfBounds(), ready, - proTxHash + proTxHash.toString().substring(0, 16) ); } diff --git a/core/src/main/java/org/bitcoinj/coinjoin/CoinJoinStatusUpdate.java b/core/src/main/java/org/bitcoinj/coinjoin/CoinJoinStatusUpdate.java index bdaf6e44b4..59932ac929 100644 --- a/core/src/main/java/org/bitcoinj/coinjoin/CoinJoinStatusUpdate.java +++ b/core/src/main/java/org/bitcoinj/coinjoin/CoinJoinStatusUpdate.java @@ -79,7 +79,7 @@ protected void bitcoinSerializeToStream(OutputStream stream) throws IOException @Override public String toString() { return String.format( - "CoinJoinStatusUpdate(sessionID=%d, state=%s, statusUpdate=%s, messageID=%s)", + "CoinJoinStatusUpdate(sID=%d, state=%s, statusUpdate=%s, msgID=%s)", sessionID, state, statusUpdate, diff --git a/core/src/main/java/org/bitcoinj/coinjoin/utils/KeyHolderStorage.java b/core/src/main/java/org/bitcoinj/coinjoin/utils/KeyHolderStorage.java index 1dfd22c82d..8b12252ffd 100644 --- a/core/src/main/java/org/bitcoinj/coinjoin/utils/KeyHolderStorage.java +++ b/core/src/main/java/org/bitcoinj/coinjoin/utils/KeyHolderStorage.java @@ -26,6 +26,8 @@ import java.util.ArrayList; import java.util.concurrent.locks.ReentrantLock; +import static org.bitcoinj.coinjoin.CoinJoinConstants.COINJOIN_EXTRA; + public class KeyHolderStorage { static final Logger log = LoggerFactory.getLogger(KeyHolderStorage.class); private final ReentrantLock lock = Threading.lock("storage"); @@ -39,7 +41,7 @@ public Script addKey(WalletEx wallet) { lock.lock(); try { storage.add(keyHolder); - log.info("KeyHolderStorage.addKey -- storage size {}", storage.size()); + log.info(COINJOIN_EXTRA, "KeyHolderStorage.addKey: storage size {}", storage.size()); } finally { lock.unlock(); } @@ -60,7 +62,7 @@ public void keepAll() { for (KeyHolder key : tmp) { key.keepKey(); } - log.info("keepAll -- {} keys kept", tmp.size()); + log.info(COINJOIN_EXTRA, "keepAll: {} keys kept", tmp.size()); } } @@ -78,7 +80,7 @@ public void returnAll() { for (KeyHolder key : tmp) { key.returnKey(); } - log.info("returnAll -- {} keys returned", tmp.size()); + log.info(COINJOIN_EXTRA, "returnAll: {} keys returned", tmp.size()); } } } diff --git a/core/src/main/java/org/bitcoinj/coinjoin/utils/MasternodeGroup.java b/core/src/main/java/org/bitcoinj/coinjoin/utils/MasternodeGroup.java index c77caf936c..9b61ffbf54 100644 --- a/core/src/main/java/org/bitcoinj/coinjoin/utils/MasternodeGroup.java +++ b/core/src/main/java/org/bitcoinj/coinjoin/utils/MasternodeGroup.java @@ -56,6 +56,7 @@ import java.util.function.Consumer; import static java.lang.Math.min; +import static org.bitcoinj.coinjoin.CoinJoinConstants.COINJOIN_EXTRA; public class MasternodeGroup extends PeerGroup implements NewBestBlockListener { @@ -79,7 +80,7 @@ public InetSocketAddress[] getPeers(long services, long timeoutValue, TimeUnit t if (session.getMixingMasternodeInfo() != null && !pendingClosingMasternodes.contains(session.getMixingMasternodeInfo())) { addresses.add(session.getMixingMasternodeInfo().getService().getSocketAddress()); addressMap.put(session.getMixingMasternodeInfo().getService(), session); - log.info("discovery: {} -> {}", session.getMixingMasternodeInfo().getService().getSocketAddress(), session); + log.info("discovery: {} -> {}", session.getMixingMasternodeInfo().getService().getAddr(), session); } } } finally { @@ -226,7 +227,7 @@ private void updateMaxConnections() { pendingMasternodesLock.unlock(); } try { - log.info("updating max connections to min({}, {})", maxConnections, min(maxConnections, CoinJoinClientOptions.getSessions())); + log.info(COINJOIN_EXTRA, "updating max connections to min({}, {})", maxConnections, min(maxConnections, CoinJoinClientOptions.getSessions())); setMaxConnections(min(maxConnections, CoinJoinClientOptions.getSessions())); } catch (NoSuchElementException e) { // swallow, though this is not good, which @@ -331,7 +332,8 @@ protected Peer connectTo(PeerAddress address, boolean incrementMaxConnections, i } Peer peer = super.connectTo(address, incrementMaxConnections, connectTimeoutMillis); - log.info("masternode[connecting] {}: {}; {}", peer.getAddress().getSocketAddress(), session.getMixingMasternodeInfo().getProTxHash(), session); + log.info("masternode[connecting] {}: {}; {}", peer.getAddress().getSocketAddress(), + session.getMixingMasternodeInfo().getProTxHash().toString().substring(0, 16), session); return peer; } @@ -370,7 +372,8 @@ private void checkMasternodesWithoutSessions() { found = true; } } else { - log.info("session is not connected to a masternode: {}", session); + // TODO: we may not need this anymore + log.info(COINJOIN_EXTRA, "session is not connected to a masternode: {}", session); } } if (!found) { @@ -382,14 +385,11 @@ private void checkMasternodesWithoutSessions() { pendingMasternodesLock.unlock(); } log.info("need to drop {} masternodes", masternodesToDrop.size()); - masternodesToDrop.forEach(new Consumer() { - @Override - public void accept(Peer peer) { - Masternode mn = context.masternodeListManager.getListAtChainTip().getMNByAddress(peer.getAddress().getSocketAddress()); - //pendingSessions.remove(mn.getProTxHash()); - log.info("masternode will be disconnected: {}: {}", peer, mn.getProTxHash()); - peer.close(); - } + masternodesToDrop.forEach(peer -> { + Masternode mn = context.masternodeListManager.getListAtChainTip().getMNByAddress(peer.getAddress().getSocketAddress()); + //pendingSessions.remove(mn.getProTxHash()); + log.info("masternode will be disconnected: {}: {}", peer, mn.getProTxHash()); + peer.close(); }); } diff --git a/core/src/main/java/org/bitcoinj/signers/CoinJoinTransactionSigner.java b/core/src/main/java/org/bitcoinj/signers/CoinJoinTransactionSigner.java index bb3a44a02d..f6e9be3c7f 100644 --- a/core/src/main/java/org/bitcoinj/signers/CoinJoinTransactionSigner.java +++ b/core/src/main/java/org/bitcoinj/signers/CoinJoinTransactionSigner.java @@ -137,7 +137,7 @@ public boolean signInputs(ProposedTransaction propTx, KeyBag keyBag) { txIn.setScriptSig(inputScript); sigs.add(tx.getInput(i)); - log.info("coinjoin: nMyInputIndex: {}, sigs.size(): {}, scriptSig={}", i, sigs.size(), tx.getInput(i).getScriptSig()); + log.info("coinjoin: myInputIndex: {}, sigs.size: {}, scriptSig={}", i, sigs.size(), tx.getInput(i).getScriptSig()); } else { throw new IllegalStateException(Utils.HEX.encode(script)); } diff --git a/core/src/main/java/org/bitcoinj/wallet/CoinJoinExtension.java b/core/src/main/java/org/bitcoinj/wallet/CoinJoinExtension.java index 293620eae0..897e84ab27 100644 --- a/core/src/main/java/org/bitcoinj/wallet/CoinJoinExtension.java +++ b/core/src/main/java/org/bitcoinj/wallet/CoinJoinExtension.java @@ -23,6 +23,7 @@ import net.jcip.annotations.GuardedBy; import org.bitcoinj.coinjoin.CoinJoin; import org.bitcoinj.coinjoin.CoinJoinClientOptions; +import org.bitcoinj.coinjoin.CoinJoinConstants; import org.bitcoinj.core.Address; import org.bitcoinj.core.BlockChain; import org.bitcoinj.core.Coin; @@ -60,6 +61,7 @@ import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkState; import static java.lang.Math.max; +import static org.bitcoinj.coinjoin.CoinJoinConstants.COINJOIN_EXTRA; import static org.dashj.bls.Utils.HexUtils.HEX; /** @@ -327,7 +329,7 @@ public void addUnusedKey(DeterministicKey key) { try { unusedKeys.put(KeyId.fromBytes(key.getPubKeyHash()), key); keyUsage.put(key, false); - log.info("adding unused key: {} / {} ", HEX.encode(key.getPubKeyHash()), key.getPath()); + log.info(COINJOIN_EXTRA, "adding unused key: {} / {} ", HEX.encode(key.getPubKeyHash()), key.getPath()); } finally { unusedKeysLock.unlock(); } @@ -340,9 +342,9 @@ public void addUnusedKey(KeyId keyId) { if (key != null) { unusedKeys.put(KeyId.fromBytes(key.getPubKeyHash()), key); keyUsage.put(key, false); - log.info("adding unused key: {} / {}", HEX.encode(key.getPubKeyHash()), key.getPath()); + log.info(COINJOIN_EXTRA, "adding unused key: {} / {}", HEX.encode(key.getPubKeyHash()), key.getPath()); } else { - log.warn("cannot find {}", keyId); + log.warn(COINJOIN_EXTRA, "cannot find {}", keyId); } } finally { unusedKeysLock.unlock(); @@ -353,13 +355,13 @@ public DeterministicKey getUnusedKey() { unusedKeysLock.lock(); try { if (unusedKeys.isEmpty()) { - log.info("obtaining fresh key"); - log.info("keyUsage map has unused keys: {}", keyUsage.values().stream().noneMatch(used -> used), getUnusedKeyCount()); + log.info(COINJOIN_EXTRA, "obtaining fresh key"); + log.info(COINJOIN_EXTRA, "keyUsage map has unused keys: {}, unused key count: {}", keyUsage.values().stream().noneMatch(used -> used), getUnusedKeyCount()); return (DeterministicKey) freshReceiveKey(); } else { DeterministicKey key = unusedKeys.values().stream().findFirst().get(); - log.info("reusing key: {} / {}", HEX.encode(key.getPubKeyHash()), key); - log.info("keyUsage map says this key is used: {}, unused key count: {}", keyUsage.get(key), getUnusedKeyCount()); + log.info(COINJOIN_EXTRA, "reusing key: {} / {}", HEX.encode(key.getPubKeyHash()), key); + log.info(COINJOIN_EXTRA, "keyUsage map says this key is used: {}, unused key count: {}", keyUsage.get(key), getUnusedKeyCount()); // remove the key unusedKeys.remove(KeyId.fromBytes(key.getPubKeyHash())); @@ -378,7 +380,7 @@ public void removeUnusedKey(KeyId keyId) { unusedKeys.remove(keyId); IDeterministicKey key = (IDeterministicKey) findKeyFromPubKeyHash(keyId.getBytes(), Script.ScriptType.P2PKH); keyUsage.put(key, true); - log.info("remove unused key: {} / {}", HEX.encode(keyId.getBytes()), key); + log.info(COINJOIN_EXTRA, "remove unused key: {} / {}", HEX.encode(keyId.getBytes()), key); } finally { unusedKeysLock.unlock(); } @@ -401,7 +403,7 @@ public void processTransaction(Transaction tx, StoredBlock block, BlockChain.New @Override public IDeterministicKey freshReceiveKey() { IDeterministicKey freshKey = super.freshReceiveKey(); - log.info("fresh key: {} / {}", HEX.encode(freshKey.getPubKeyHash()), freshKey); + log.info(COINJOIN_EXTRA, "fresh key: {} / {}", HEX.encode(freshKey.getPubKeyHash()), freshKey); keyUsage.put(freshKey, true); return freshKey; } @@ -454,10 +456,10 @@ public void refreshUnusedKeys() { usedKeys.forEach(key -> unusedKeys.remove(KeyId.fromBytes(key.getPubKeyHash()))); - unusedKeys.forEach((keyId, key) -> log.info("unused key: {}", key)); + unusedKeys.forEach((keyId, key) -> log.info(COINJOIN_EXTRA, "unused key: {}", key)); keyUsage.forEach((key, used) -> { if (!used) - log.info("unused key: {}", key); + log.info(COINJOIN_EXTRA, "unused key: {}", key); }); loadedKeys = true; } finally { diff --git a/core/src/main/java/org/bitcoinj/wallet/WalletEx.java b/core/src/main/java/org/bitcoinj/wallet/WalletEx.java index e00fe3864f..0f650a1e24 100644 --- a/core/src/main/java/org/bitcoinj/wallet/WalletEx.java +++ b/core/src/main/java/org/bitcoinj/wallet/WalletEx.java @@ -24,7 +24,6 @@ import org.bitcoinj.core.TransactionInput; import org.bitcoinj.core.TransactionOutPoint; import org.bitcoinj.core.TransactionOutput; -import org.bitcoinj.core.UTXOProvider; import org.bitcoinj.core.Utils; import org.bitcoinj.core.VerificationException; import org.bitcoinj.crypto.ChildNumber; @@ -44,11 +43,11 @@ import java.util.Comparator; import java.util.HashMap; import java.util.HashSet; -import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Set; +import static org.bitcoinj.coinjoin.CoinJoinConstants.COINJOIN_EXTRA; import static org.bitcoinj.core.NetworkParameters.MAX_MONEY; public class WalletEx extends Wallet { @@ -392,7 +391,7 @@ int getRealOutpointCoinJoinRounds(TransactionOutPoint outpoint, int rounds) { roundsRef = -3; mapOutpointRoundsCache.put(outpoint, roundsRef); - log.info(String.format("UPDATED %-70s %3d (collateral)", outpoint.toStringCpp(), roundsRef)); + log.info(COINJOIN_EXTRA, String.format("UPDATED %-70s %3d (collateral)", outpoint.toStringCpp(), roundsRef)); return roundsRef; } @@ -401,7 +400,7 @@ int getRealOutpointCoinJoinRounds(TransactionOutPoint outpoint, int rounds) { roundsRef = -2; mapOutpointRoundsCache.put(outpoint, roundsRef); - log.info(String.format("UPDATED %-70s %3d (non-denominated)", outpoint.toStringCpp(), roundsRef)); + log.info(COINJOIN_EXTRA, String.format("UPDATED %-70s %3d (non-denominated)", outpoint.toStringCpp(), roundsRef)); return roundsRef; } @@ -411,7 +410,7 @@ int getRealOutpointCoinJoinRounds(TransactionOutPoint outpoint, int rounds) { roundsRef = 0; mapOutpointRoundsCache.put(outpoint, roundsRef); - log.info(String.format("UPDATED %-70s %3d (non-denominated)", outpoint.toStringCpp(), roundsRef)); + log.info(COINJOIN_EXTRA, String.format("UPDATED %-70s %3d (non-denominated)", outpoint.toStringCpp(), roundsRef)); return roundsRef; } } @@ -433,7 +432,7 @@ int getRealOutpointCoinJoinRounds(TransactionOutPoint outpoint, int rounds) { ? (nShortest >= roundsMax - 1 ? roundsMax : nShortest + 1) // good, we a +1 to the shortest one but only roundsMax rounds max allowed : 0; // too bad, we are the fist one in that chain mapOutpointRoundsCache.put(outpoint, roundsRef); - log.info(String.format("UPDATED %-70s %3d (coinjoin)", outpoint.toStringCpp(), roundsRef)); + log.info(COINJOIN_EXTRA, String.format("UPDATED %-70s %3d (coinjoin)", outpoint.toStringCpp(), roundsRef)); return roundsRef; } finally { lock.unlock(); @@ -859,7 +858,7 @@ public boolean selectTxDSInsByDenomination(int nDenom, Coin nValueMax, List log.info(" output: {}", output)); + log.info(COINJOIN_EXTRA, "No results found for {}", CoinJoin.denominationToAmount(nDenom).toFriendlyString()); + vCoins.forEach(output -> log.info(COINJOIN_EXTRA, " output: {}", output)); } return nValueTotal.isPositive(); diff --git a/core/src/test/java/org/bitcoinj/coinjoin/CoinJoinServer.java b/core/src/test/java/org/bitcoinj/coinjoin/CoinJoinServer.java index 5dfc09a294..6ea0828452 100644 --- a/core/src/test/java/org/bitcoinj/coinjoin/CoinJoinServer.java +++ b/core/src/test/java/org/bitcoinj/coinjoin/CoinJoinServer.java @@ -501,7 +501,7 @@ public CoinJoinResult addEntry(CoinJoinEntry entry) { ArrayList vin = Lists.newArrayList(); for (TransactionInput txin : entry.getMixingInputs()) { - log.info("coinjoin: -- txin={}",txin); + log.info("coinjoin: txin={}",txin); lock.lock(); try { for (CoinJoinEntry inner_entry :entries) {