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

Fix issue of Trade Step 1 validation done too soon #5746

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 4 additions & 4 deletions core/src/main/java/bisq/core/trade/Trade.java
Original file line number Diff line number Diff line change
Expand Up @@ -119,10 +119,10 @@ public enum State {

// DEPOSIT_TX_PUBLISHED_MSG
// seller perspective
SELLER_SENT_DEPOSIT_TX_PUBLISHED_MSG(Phase.DEPOSIT_PUBLISHED),
SELLER_SAW_ARRIVED_DEPOSIT_TX_PUBLISHED_MSG(Phase.DEPOSIT_PUBLISHED),
SELLER_STORED_IN_MAILBOX_DEPOSIT_TX_PUBLISHED_MSG(Phase.DEPOSIT_PUBLISHED),
SELLER_SEND_FAILED_DEPOSIT_TX_PUBLISHED_MSG(Phase.DEPOSIT_PUBLISHED),
@Deprecated SELLER_SENT_DEPOSIT_TX_PUBLISHED_MSG(Phase.DEPOSIT_PUBLISHED),
@Deprecated SELLER_SAW_ARRIVED_DEPOSIT_TX_PUBLISHED_MSG(Phase.DEPOSIT_PUBLISHED),
@Deprecated SELLER_STORED_IN_MAILBOX_DEPOSIT_TX_PUBLISHED_MSG(Phase.DEPOSIT_PUBLISHED),
@Deprecated SELLER_SEND_FAILED_DEPOSIT_TX_PUBLISHED_MSG(Phase.DEPOSIT_PUBLISHED),

// buyer perspective
BUYER_RECEIVED_DEPOSIT_TX_PUBLISHED_MSG(Phase.DEPOSIT_PUBLISHED),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ protected void handle(DelayedPayoutTxSignatureResponse message, NodeAddress peer
}

protected void handle(ShareBuyerPaymentAccountMessage message, NodeAddress peer) {
expect(anyPhase(Trade.Phase.DEPOSIT_PUBLISHED, Trade.Phase.DEPOSIT_CONFIRMED)
expect(anyPhase(Trade.Phase.TAKER_FEE_PUBLISHED, Trade.Phase.DEPOSIT_PUBLISHED, Trade.Phase.DEPOSIT_CONFIRMED)
.with(message)
.from(peer))
.setup(tasks(SellerProcessShareBuyerPaymentAccountMessage.class,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,16 +79,15 @@ protected TradeMailboxMessage getTradeMailboxMessage(String tradeId) {

@Override
protected void setStateSent() {
trade.setStateIfValidTransitionTo(Trade.State.SELLER_SENT_DEPOSIT_TX_PUBLISHED_MSG);

processModel.getTradeManager().requestPersistence();
// we no longer set deprecated state (Trade.State.SELLER_SENT_DEPOSIT_TX_PUBLISHED_MSG);
// see https://github.com/bisq-network/bisq/pull/5746#issuecomment-939879623
}

@Override
protected void setStateArrived() {
trade.setStateIfValidTransitionTo(Trade.State.SELLER_SAW_ARRIVED_DEPOSIT_TX_PUBLISHED_MSG);
// we no longer set deprecated state (Trade.State.SELLER_SAW_ARRIVED_DEPOSIT_TX_PUBLISHED_MSG);
// see https://github.com/bisq-network/bisq/pull/5746#issuecomment-939879623

processModel.getTradeManager().requestPersistence();
cleanup();
// Complete is called in base class
}
Expand All @@ -101,9 +100,9 @@ protected void onStoredInMailbox() {

@Override
protected void setStateStoredInMailbox() {
trade.setStateIfValidTransitionTo(Trade.State.SELLER_STORED_IN_MAILBOX_DEPOSIT_TX_PUBLISHED_MSG);
// we no longer set deprecated state (Trade.State.SELLER_STORED_IN_MAILBOX_DEPOSIT_TX_PUBLISHED_MSG);
// see https://github.com/bisq-network/bisq/pull/5746#issuecomment-939879623

processModel.getTradeManager().requestPersistence();
// The DepositTxAndDelayedPayoutTxMessage is a mailbox message as earlier we use only the deposit tx which can
// be also received from the network once published.
// Now we send the delayed payout tx as well and with that this message is mandatory for continuing the protocol.
Expand All @@ -125,12 +124,11 @@ protected void onFault(String errorMessage, TradeMessage message) {

@Override
protected void setStateFault() {
trade.setStateIfValidTransitionTo(Trade.State.SELLER_SEND_FAILED_DEPOSIT_TX_PUBLISHED_MSG);
// we no longer set deprecated state (Trade.State.SELLER_SEND_FAILED_DEPOSIT_TX_PUBLISHED_MSG);
// see https://github.com/bisq-network/bisq/pull/5746#issuecomment-939879623
if (!trade.isDepositConfirmed()) {
tryToSendAgainLater();
}

processModel.getTradeManager().requestPersistence();
}

@Override
Expand Down Expand Up @@ -184,9 +182,9 @@ private void onMessageStateChange(MessageState newValue) {
// Once we receive an ACK from our msg we know the peer has received the msg and we stop.
if (newValue == MessageState.ACKNOWLEDGED) {
// We treat a ACK like SELLER_SAW_ARRIVED_DEPOSIT_TX_PUBLISHED_MSG
trade.setStateIfValidTransitionTo(Trade.State.SELLER_SAW_ARRIVED_DEPOSIT_TX_PUBLISHED_MSG);
// we no longer set deprecated state (Trade.State.SELLER_SAW_ARRIVED_DEPOSIT_TX_PUBLISHED_MSG);
// see https://github.com/bisq-network/bisq/pull/5746#issuecomment-939879623

processModel.getTradeManager().requestPersistence();
cleanup();
complete();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,8 @@ private void updateMoveTradeToFailedColumnState() {
}

private boolean isMaybeInvalidTrade(Trade trade) {
return trade.isTxChainInvalid() || trade.hasErrorMessage();
return trade.hasErrorMessage() ||
(Trade.Phase.DEPOSIT_PUBLISHED.ordinal() <= trade.getPhase().ordinal() && trade.isTxChainInvalid());
}

private void onMoveInvalidTradeToFailedTrades(Trade trade) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -433,15 +433,9 @@ private void onTradeStateChanged(Trade.State tradeState) {


// #################### Phase DEPOSIT_PAID
case SELLER_PUBLISHED_DEPOSIT_TX:

// DEPOSIT_TX_PUBLISHED_MSG
// seller perspective
case SELLER_SENT_DEPOSIT_TX_PUBLISHED_MSG:
case SELLER_SAW_ARRIVED_DEPOSIT_TX_PUBLISHED_MSG:
case SELLER_STORED_IN_MAILBOX_DEPOSIT_TX_PUBLISHED_MSG:
case SELLER_SEND_FAILED_DEPOSIT_TX_PUBLISHED_MSG:

case SELLER_PUBLISHED_DEPOSIT_TX:
// buyer perspective
case BUYER_RECEIVED_DEPOSIT_TX_PUBLISHED_MSG:

Expand Down
8 changes: 4 additions & 4 deletions proto/src/main/proto/pb.proto
Original file line number Diff line number Diff line change
Expand Up @@ -1498,10 +1498,10 @@ message Trade {
MAKER_SEND_FAILED_PUBLISH_DEPOSIT_TX_REQUEST = 6;
TAKER_RECEIVED_PUBLISH_DEPOSIT_TX_REQUEST = 7;
SELLER_PUBLISHED_DEPOSIT_TX = 8;
SELLER_SENT_DEPOSIT_TX_PUBLISHED_MSG = 9;
SELLER_SAW_ARRIVED_DEPOSIT_TX_PUBLISHED_MSG = 10;
SELLER_STORED_IN_MAILBOX_DEPOSIT_TX_PUBLISHED_MSG = 11;
SELLER_SEND_FAILED_DEPOSIT_TX_PUBLISHED_MSG = 12;
SELLER_SENT_DEPOSIT_TX_PUBLISHED_MSG = 9 [deprecated = true];
SELLER_SAW_ARRIVED_DEPOSIT_TX_PUBLISHED_MSG = 10 [deprecated = true];
SELLER_STORED_IN_MAILBOX_DEPOSIT_TX_PUBLISHED_MSG = 11 [deprecated = true];
SELLER_SEND_FAILED_DEPOSIT_TX_PUBLISHED_MSG = 12 [deprecated = true];
BUYER_RECEIVED_DEPOSIT_TX_PUBLISHED_MSG = 13;
BUYER_SAW_DEPOSIT_TX_IN_NETWORK = 14;
DEPOSIT_CONFIRMED_IN_BLOCK_CHAIN = 15;
Expand Down