From b5208597102cdbf7e43c81642ff2bf51e2a9f97e Mon Sep 17 00:00:00 2001 From: CalDescent Date: Sun, 16 Aug 2020 17:02:58 +0100 Subject: [PATCH 1/3] Redeem 1000 sats from P2SH-B. Previously, this was set to zero, but caused the Electrum nodes to fail with a 'dust' error. Ideally we need to redeem at least 700 sats in order to stand a chance of exceeding the dust threshold (3000 sats/kB). --- src/main/java/org/qortal/controller/TradeBot.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/qortal/controller/TradeBot.java b/src/main/java/org/qortal/controller/TradeBot.java index ec7209c90..f00c40847 100644 --- a/src/main/java/org/qortal/controller/TradeBot.java +++ b/src/main/java/org/qortal/controller/TradeBot.java @@ -64,6 +64,7 @@ public TradeBotData getTradeBotData() { private static final Logger LOGGER = LogManager.getLogger(TradeBot.class); private static final Random RANDOM = new SecureRandom(); private static final long FEE_AMOUNT = 5000L; + private static final long P2SHB_REDEEM_AMOUNT = 1000L; private static TradeBot instance; @@ -766,7 +767,7 @@ private void handleBobWaitingForP2shB(Repository repository, TradeBotData tradeB } // Redeem P2SH-B using secret-B - Coin redeemAmount = Coin.ZERO; // The real funds are in P2SH-A + Coin redeemAmount = Coin.valueOf(P2SHB_REDEEM_AMOUNT); // The real funds are in P2SH-A ECKey redeemKey = ECKey.fromPrivate(tradeBotData.getTradePrivateKey()); List fundingOutputs = BTC.getInstance().getUnspentOutputs(p2shAddress); byte[] receivingAccountInfo = tradeBotData.getReceivingAccountInfo(); From 197f8cdb283ce2d0ecdd380317b9edb4e9ce1cfc Mon Sep 17 00:00:00 2001 From: CalDescent Date: Sun, 16 Aug 2020 17:19:57 +0100 Subject: [PATCH 2/3] Added comment. --- src/main/java/org/qortal/controller/TradeBot.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/qortal/controller/TradeBot.java b/src/main/java/org/qortal/controller/TradeBot.java index f00c40847..145817756 100644 --- a/src/main/java/org/qortal/controller/TradeBot.java +++ b/src/main/java/org/qortal/controller/TradeBot.java @@ -767,7 +767,7 @@ private void handleBobWaitingForP2shB(Repository repository, TradeBotData tradeB } // Redeem P2SH-B using secret-B - Coin redeemAmount = Coin.valueOf(P2SHB_REDEEM_AMOUNT); // The real funds are in P2SH-A + Coin redeemAmount = Coin.valueOf(P2SHB_REDEEM_AMOUNT); // We need to redeem an amount higher than the dust threshold (3000 sats/kB). The real funds are in P2SH-A ECKey redeemKey = ECKey.fromPrivate(tradeBotData.getTradePrivateKey()); List fundingOutputs = BTC.getInstance().getUnspentOutputs(p2shAddress); byte[] receivingAccountInfo = tradeBotData.getReceivingAccountInfo(); From 289a1e18c35cfaf8504eb2960a624d1d266dde07 Mon Sep 17 00:00:00 2001 From: CalDescent Date: Sun, 16 Aug 2020 20:38:59 +0100 Subject: [PATCH 3/3] Redeem 1000 sats from P2SH-B when processing a refund. Otherwise this transaction is also rejected due to the 'dust' error. Note: we can probably skip this entire step, as the majority of the P2SA-B balance is needed to pay for its own transaction fee, even when refunded. --- src/main/java/org/qortal/controller/TradeBot.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/qortal/controller/TradeBot.java b/src/main/java/org/qortal/controller/TradeBot.java index 145817756..48c273ccb 100644 --- a/src/main/java/org/qortal/controller/TradeBot.java +++ b/src/main/java/org/qortal/controller/TradeBot.java @@ -977,7 +977,7 @@ private void handleAliceRefundingP2shB(Repository repository, TradeBotData trade byte[] redeemScriptBytes = BTCP2SH.buildScript(tradeBotData.getTradeForeignPublicKeyHash(), crossChainTradeData.lockTimeB, crossChainTradeData.creatorBitcoinPKH, crossChainTradeData.hashOfSecretB); String p2shAddress = BTC.getInstance().deriveP2shAddress(redeemScriptBytes); - Coin refundAmount = Coin.ZERO; + Coin refundAmount = Coin.valueOf(P2SHB_REDEEM_AMOUNT); // We need to redeem an amount higher than the dust threshold (3000 sats/kB). The rest will be used to pay the fee. ECKey refundKey = ECKey.fromPrivate(tradeBotData.getTradePrivateKey()); List fundingOutputs = BTC.getInstance().getUnspentOutputs(p2shAddress);