Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Delay broadcasting of taker fee tx #2488

Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
03d0a22
Allow spending of unconfirmed BSQ change outputs
ManfredKarrer Mar 1, 2019
4332c16
Cleanup
ManfredKarrer Mar 1, 2019
dd96a18
Delay broadcasting of taker fee tx
ManfredKarrer Mar 2, 2019
e62557c
Merge branch 'master' into allow-spending-unconfirmed-bsq-utxs
ManfredKarrer Mar 2, 2019
6c11fc1
Add altcoin payment method for live trading
ManfredKarrer Mar 3, 2019
11adc99
Use super classes for cryptCurrencyAccount and payload
ManfredKarrer Mar 3, 2019
54e39c3
Remove dev button, add "trade instant" checkbox
ManfredKarrer Mar 3, 2019
992480d
Refactoring: Renaming
ManfredKarrer Mar 3, 2019
9475cf2
Merge branch 'master' into allow-spending-unconfirmed-bsq-utxs
ManfredKarrer Mar 3, 2019
1802508
Fix BSQ balance display for unconfirmed change outputs
ManfredKarrer Mar 3, 2019
568be3d
Add missing check for isAvailableForSpending at unverifiedBalance
ManfredKarrer Mar 3, 2019
a0dd010
Fix balance update in case at vote result. Rename methods
ManfredKarrer Mar 3, 2019
8d73308
Refactor: Rename onParseTxsComplete to onParseBlockComplete
ManfredKarrer Mar 3, 2019
e414e91
Refactor: Rename onParseTxsCompleteAfterBatchProcessing to
ManfredKarrer Mar 3, 2019
c5a383d
Fix balance for confiscated bonds
ManfredKarrer Mar 3, 2019
b9bfa83
Merge branch 'master' into avoid-taker-fee-publishing-for-failed-trades
ManfredKarrer Mar 3, 2019
f44e9b1
Merge branch 'master' into avoid-taker-fee-publishing-for-failed-trades
ManfredKarrer Mar 3, 2019
44f5798
Merge branch 'master' into add-live-trading
ManfredKarrer Mar 4, 2019
997819e
Add line break
ManfredKarrer Mar 4, 2019
0711ab9
Reduce timeout to 90 sec
ManfredKarrer Mar 4, 2019
ed6fa7b
Increase TTL for offer from 7 to 8 min.
ManfredKarrer Mar 4, 2019
afd9d9c
Fix table layout
ManfredKarrer Mar 4, 2019
35dfc4b
Delay broadcasting of taker fee tx
ManfredKarrer Mar 2, 2019
db4c6f5
Reduce timeout to 90 sec
ManfredKarrer Mar 4, 2019
e4bd079
List Arqma (ARQ)
ArqTras Mar 4, 2019
5b6d986
Merge pull request #2433 from ArqTras/arqma
ripcurlx Mar 4, 2019
9e7a619
Merge branch 'master' into add-live-trading
ManfredKarrer Mar 4, 2019
804f8e9
Improve wording
ManfredKarrer Mar 4, 2019
dcadbdf
Merge branch 'master' into avoid-taker-fee-publishing-for-failed-trades
ManfredKarrer Mar 4, 2019
f790bfc
Merge branch 'add-live-trading'
ManfredKarrer Mar 4, 2019
c91792c
Fix incorrect BSQ validator in send BSQ view
ManfredKarrer Mar 4, 2019
64f085c
Merge branch 'allow-spending-unconfirmed-bsq-utxs'
ManfredKarrer Mar 4, 2019
ba376fe
Add TxType to bsqWalletService.commit call
ManfredKarrer Mar 4, 2019
46d15dc
Merge remote-tracking branch 'origin/avoid-taker-fee-publishing-for-f…
ManfredKarrer Mar 4, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions core/src/main/java/bisq/core/btc/wallet/BtcWalletService.java
Original file line number Diff line number Diff line change
Expand Up @@ -589,6 +589,12 @@ public AddressEntry getFreshAddressEntry() {
return getOrCreateAddressEntry(context, addressEntry);
}

public AddressEntry getNewAddressEntry(String offerId, AddressEntry.Context context) {
AddressEntry entry = new AddressEntry(wallet.freshReceiveKey(), context, offerId);
addressEntryList.addAddressEntry(entry);
return entry;
}

private AddressEntry getOrCreateAddressEntry(AddressEntry.Context context, Optional<AddressEntry> addressEntry) {
if (addressEntry.isPresent()) {
return addressEntry.get();
Expand Down
48 changes: 21 additions & 27 deletions core/src/main/java/bisq/core/btc/wallet/TradeWalletService.java
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,8 @@ public Transaction createBtcTradingFeeTx(Address fundingAddress,
Coin tradingFee,
Coin txFee,
String feeReceiverAddresses,
TxBroadcaster.Callback callback)
boolean doBroadcast,
@Nullable TxBroadcaster.Callback callback)
throws InsufficientMoneyException, AddressFormatException {
log.debug("fundingAddress " + fundingAddress.toString());
log.debug("reservedForTradeAddress " + reservedForTradeAddress.toString());
Expand Down Expand Up @@ -216,7 +217,8 @@ public Transaction createBtcTradingFeeTx(Address fundingAddress,
wallet.completeTx(sendRequest);
WalletService.printTx("tradingFeeTx", tradingFeeTx);

broadcastTx(tradingFeeTx, callback);
if (doBroadcast && callback != null)
broadcastTx(tradingFeeTx, callback);

return tradingFeeTx;
} catch (Throwable t) {
Expand Down Expand Up @@ -327,15 +329,15 @@ public Transaction completeBsqTradingFeeTx(Transaction preparedBsqTx,
* The taker creates a dummy transaction to get the input(s) and optional change output for the amount and the takersAddress for that trade.
* That will be used to send to the maker for creating the deposit transaction.
*
*
* @param takeOfferFeeTx The take offer fee tx
* @param inputAmount Amount of takers input
* @param txFee Mining fee
* @param takersAddress Address of taker
* @return A data container holding the inputs, the output value and address
* @throws TransactionVerificationException
* @throws WalletException
*/
public InputsAndChangeOutput takerCreatesDepositsTxInputs(Coin inputAmount, Coin txFee, Address takersAddress, Address takersChangeAddress) throws
TransactionVerificationException, WalletException {
public InputsAndChangeOutput takerCreatesDepositsTxInputs(Transaction takeOfferFeeTx, Coin inputAmount, Coin txFee, Address takersAddress) throws
TransactionVerificationException {
log.debug("takerCreatesDepositsTxInputs called");
log.debug("inputAmount " + inputAmount.toFriendlyString());
log.debug("txFee " + txFee.toFriendlyString());
Expand All @@ -349,15 +351,13 @@ public InputsAndChangeOutput takerCreatesDepositsTxInputs(Coin inputAmount, Coin
/*
The tx we create has that structure:

IN[0] any input > inputAmount (including tx fee) (unsigned)
IN[1...n] optional inputs supported, but normally there is just 1 input (unsigned)
IN[0] input from taker fee tx > inputAmount (including tx fee) (unsigned)
OUT[0] dummyOutputAmount (inputAmount - tx fee)
OUT[1] Optional Change = inputAmount - dummyOutputAmount - tx fee

We are only interested in the inputs and the optional change output.
We are only interested in the inputs.
We get the exact input value from the taker fee tx so we don't create a change output.
*/


// inputAmount includes the tx fee. So we subtract the fee to get the dummyOutputAmount.
Coin dummyOutputAmount = inputAmount.subtract(txFee);

Expand All @@ -370,11 +370,12 @@ OUT[0] dummyOutputAmount (inputAmount - tx fee)
// Find the needed inputs to pay the output, optionally add 1 change output.
// Normally only 1 input and no change output is used, but we support multiple inputs and 1 change output.
// Our spending transaction output is from the create offer fee payment.
addAvailableInputsAndChangeOutputs(dummyTX, takersAddress, takersChangeAddress, txFee);

// The completeTx() call signs the input, but we don't want to pass over signed tx inputs so we remove the signature
WalletService.removeSignatures(dummyTX);
// We created the take offer fee tx in the structure that the second output is for the funds for the deposit tx.
TransactionOutput reservedForTradeOutput = takeOfferFeeTx.getOutputs().get(1);
dummyTX.addInput(reservedForTradeOutput);

WalletService.removeSignatures(dummyTX);
WalletService.verifyTransaction(dummyTX);

//WalletService.printTx("dummyTX", dummyTX);
Expand All @@ -388,20 +389,13 @@ OUT[0] dummyOutputAmount (inputAmount - tx fee)
})
.collect(Collectors.toList());

// We don't support more then 1 change outputs, so there are max. 2 outputs
checkArgument(dummyTX.getOutputs().size() < 3);
// Only interested in optional change output, the dummy output at index 0 is ignored (that's why we use index 1)
TransactionOutput changeOutput = dummyTX.getOutputs().size() == 2 ? dummyTX.getOutputs().get(1) : null;
long changeOutputValue = 0L;
String changeOutputAddress = null;
if (changeOutput != null) {
changeOutputValue = changeOutput.getValue().getValue();
Address addressFromP2PKHScript = changeOutput.getAddressFromP2PKHScript(params);
checkNotNull(addressFromP2PKHScript, "changeOutput.getAddressFromP2PKHScript(params) must not be null");
changeOutputAddress = addressFromP2PKHScript.toString();
}

return new InputsAndChangeOutput(new ArrayList<>(rawTransactionInputList), changeOutputValue, changeOutputAddress);
// TODO changeOutputValue and changeOutputAddress is not used as taker spends exact amount from fee tx.
// Change is handled already at the fee tx creation so the handling of a change output for the deposit tx
// can be removed here. We still keep it atm as we prefer to not introduce a larger
// refactoring. When new trade protocol gets implemented this can be cleaned.
// The maker though can have a change output if the taker takes less as the max. offer amount!
return new InputsAndChangeOutput(new ArrayList<>(rawTransactionInputList), 0, null);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/bisq/core/offer/OfferPayload.java
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ public static OfferPayload fromProto(PB.OfferPayload proto) {

@Override
public long getTTL() {
return TimeUnit.MINUTES.toMillis(7);
return TimeUnit.MINUTES.toMillis(8);
}

@Override
Expand Down
3 changes: 1 addition & 2 deletions core/src/main/java/bisq/core/offer/OpenOffer.java
Original file line number Diff line number Diff line change
Expand Up @@ -126,10 +126,9 @@ public void setStorage(Storage<TradableList<OpenOffer>> storage) {
}

public void setState(State state) {
log.trace("setState" + state);
boolean changed = this.state != state;
this.state = state;
if (changed)
if (changed && storage != null)
storage.queueUpForSave();

// We keep it reserved for a limited time, if trade preparation fails we revert to available state
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ protected void run() {
offer.getMakerFee(),
offer.getTxFee(),
arbitrator.getBtcAddress(),
true,
new TxBroadcaster.Callback() {
@Override
public void onSuccess(Transaction transaction) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import bisq.core.trade.protocol.tasks.buyer_as_taker.BuyerAsTakerSignAndPublishDepositTx;
import bisq.core.trade.protocol.tasks.taker.CreateTakerFeeTx;
import bisq.core.trade.protocol.tasks.taker.TakerProcessPublishDepositTxRequest;
import bisq.core.trade.protocol.tasks.taker.TakerPublishFeeTx;
import bisq.core.trade.protocol.tasks.taker.TakerSelectMediator;
import bisq.core.trade.protocol.tasks.taker.TakerSendDepositTxPublishedMessage;
import bisq.core.trade.protocol.tasks.taker.TakerSendPayDepositRequest;
Expand Down Expand Up @@ -149,6 +150,7 @@ private void handle(PublishDepositTxRequest tradeMessage, NodeAddress sender) {
VerifyPeersAccountAgeWitness.class,
TakerVerifyMakerFeePayment.class,
TakerVerifyAndSignContract.class,
TakerPublishFeeTx.class,
BuyerAsTakerSignAndPublishDepositTx.class,
TakerSendDepositTxPublishedMessage.class,
PublishTradeStatistics.class
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import bisq.core.trade.protocol.tasks.seller_as_taker.SellerAsTakerSignAndPublishDepositTx;
import bisq.core.trade.protocol.tasks.taker.CreateTakerFeeTx;
import bisq.core.trade.protocol.tasks.taker.TakerProcessPublishDepositTxRequest;
import bisq.core.trade.protocol.tasks.taker.TakerPublishFeeTx;
import bisq.core.trade.protocol.tasks.taker.TakerSelectMediator;
import bisq.core.trade.protocol.tasks.taker.TakerSendDepositTxPublishedMessage;
import bisq.core.trade.protocol.tasks.taker.TakerSendPayDepositRequest;
Expand Down Expand Up @@ -141,6 +142,7 @@ private void handle(PublishDepositTxRequest tradeMessage, NodeAddress sender) {
VerifyPeersAccountAgeWitness.class,
TakerVerifyMakerFeePayment.class,
TakerVerifyAndSignContract.class,
TakerPublishFeeTx.class,
SellerAsTakerSignAndPublishDepositTx.class,
TakerSendDepositTxPublishedMessage.class,
PublishTradeStatistics.class
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@

@Slf4j
public abstract class TradeProtocol {
private static final long TIMEOUT = 120;
private static final long TIMEOUT = 90;

protected final ProcessModel processModel;
private final DecryptedDirectMessageListener decryptedDirectMessageListener;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
package bisq.core.trade.protocol.tasks.buyer_as_taker;

import bisq.core.btc.model.AddressEntry;
import bisq.core.btc.wallet.BtcWalletService;
import bisq.core.btc.model.InputsAndChangeOutput;
import bisq.core.btc.wallet.BtcWalletService;
import bisq.core.trade.Trade;
import bisq.core.trade.protocol.tasks.TradeTask;

Expand Down Expand Up @@ -51,12 +51,11 @@ protected void run() {
BtcWalletService walletService = processModel.getBtcWalletService();
Address takersAddress = walletService.getOrCreateAddressEntry(processModel.getOffer().getId(),
AddressEntry.Context.RESERVED_FOR_TRADE).getAddress();
Address takersChangeAddress = walletService.getFreshAddressEntry().getAddress();
InputsAndChangeOutput result = processModel.getTradeWalletService().takerCreatesDepositsTxInputs(
processModel.getTakeOfferFeeTx(),
takerInputAmount,
txFee.subtract(bsqTakerFee),
takersAddress,
takersChangeAddress);
takersAddress);
processModel.setRawTransactionInputs(result.rawTransactionInputs);
processModel.setChangeOutputValue(result.changeOutputValue);
processModel.setChangeOutputAddress(result.changeOutputAddress);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
package bisq.core.trade.protocol.tasks.seller_as_taker;

import bisq.core.btc.model.AddressEntry;
import bisq.core.btc.wallet.BtcWalletService;
import bisq.core.btc.model.InputsAndChangeOutput;
import bisq.core.btc.wallet.BtcWalletService;
import bisq.core.trade.Trade;
import bisq.core.trade.protocol.tasks.TradeTask;

Expand Down Expand Up @@ -49,12 +49,11 @@ protected void run() {
BtcWalletService walletService = processModel.getBtcWalletService();
Address takersAddress = walletService.getOrCreateAddressEntry(processModel.getOffer().getId(),
AddressEntry.Context.RESERVED_FOR_TRADE).getAddress();
Address takersChangeAddress = walletService.getFreshAddressEntry().getAddress();
InputsAndChangeOutput result = processModel.getTradeWalletService().takerCreatesDepositsTxInputs(
processModel.getTakeOfferFeeTx(),
takerInputAmount,
txFee,
takersAddress,
takersChangeAddress);
takersAddress);

processModel.setRawTransactionInputs(result.rawTransactionInputs);
processModel.setChangeOutputValue(result.changeOutputValue);
Expand Down
Loading