mirror of
https://github.com/haveno-dex/haveno.git
synced 2025-11-29 07:56:39 -05:00
verify InitTradeRequest matches previously assigned arbitrator (#2048)
This commit is contained in:
parent
8867e9eb3b
commit
8697b5344f
3 changed files with 27 additions and 10 deletions
|
|
@ -98,14 +98,22 @@ public class BuyerAsTakerProtocol extends BuyerProtocol implements TakerProtocol
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handleInitTradeRequest(InitTradeRequest message,
|
public void handleInitTradeRequest(InitTradeRequest message,
|
||||||
NodeAddress peer) {
|
NodeAddress sender) {
|
||||||
log.info(TradeProtocol.LOG_HIGHLIGHT + "handleInitTradeRequest() for {} {} from {}", trade.getClass().getSimpleName(), trade.getShortId(), peer);
|
log.info(TradeProtocol.LOG_HIGHLIGHT + "handleInitTradeRequest() for {} {} from {}", trade.getClass().getSimpleName(), trade.getShortId(), sender);
|
||||||
ThreadUtils.execute(() -> {
|
ThreadUtils.execute(() -> {
|
||||||
synchronized (trade.getLock()) {
|
synchronized (trade.getLock()) {
|
||||||
|
|
||||||
|
// ignore if assigned a different arbitrator
|
||||||
|
NodeAddress nodeAddress = trade.getArbitrator().getNodeAddress();
|
||||||
|
if (nodeAddress != null && !nodeAddress.equals(sender)) {
|
||||||
|
log.warn("Ignoring InitTradeRequest because sender is not the arbitrator for the trade, tradeId={}, sender={}", message.getOfferId(), sender);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
latchTrade();
|
latchTrade();
|
||||||
expect(phase(Trade.Phase.INIT)
|
expect(phase(Trade.Phase.INIT)
|
||||||
.with(message)
|
.with(message)
|
||||||
.from(peer))
|
.from(sender))
|
||||||
.setup(tasks(
|
.setup(tasks(
|
||||||
ApplyFilter.class,
|
ApplyFilter.class,
|
||||||
ProcessInitTradeRequest.class,
|
ProcessInitTradeRequest.class,
|
||||||
|
|
@ -113,10 +121,10 @@ public class BuyerAsTakerProtocol extends BuyerProtocol implements TakerProtocol
|
||||||
.using(new TradeTaskRunner(trade,
|
.using(new TradeTaskRunner(trade,
|
||||||
() -> {
|
() -> {
|
||||||
startTimeout();
|
startTimeout();
|
||||||
handleTaskRunnerSuccess(peer, message);
|
handleTaskRunnerSuccess(sender, message);
|
||||||
},
|
},
|
||||||
errorMessage -> {
|
errorMessage -> {
|
||||||
handleTaskRunnerFault(peer, message, errorMessage);
|
handleTaskRunnerFault(sender, message, errorMessage);
|
||||||
}))
|
}))
|
||||||
.withTimeout(TRADE_STEP_TIMEOUT_SECONDS))
|
.withTimeout(TRADE_STEP_TIMEOUT_SECONDS))
|
||||||
.executeTasks(true);
|
.executeTasks(true);
|
||||||
|
|
|
||||||
|
|
@ -98,14 +98,22 @@ public class SellerAsTakerProtocol extends SellerProtocol implements TakerProtoc
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handleInitTradeRequest(InitTradeRequest message,
|
public void handleInitTradeRequest(InitTradeRequest message,
|
||||||
NodeAddress peer) {
|
NodeAddress sender) {
|
||||||
log.info(TradeProtocol.LOG_HIGHLIGHT + "handleInitTradeRequest() for {} {} from {}", trade.getClass().getSimpleName(), trade.getShortId(), peer);
|
log.info(TradeProtocol.LOG_HIGHLIGHT + "handleInitTradeRequest() for {} {} from {}", trade.getClass().getSimpleName(), trade.getShortId(), sender);
|
||||||
ThreadUtils.execute(() -> {
|
ThreadUtils.execute(() -> {
|
||||||
synchronized (trade.getLock()) {
|
synchronized (trade.getLock()) {
|
||||||
|
|
||||||
|
// ignore if assigned a different arbitrator
|
||||||
|
NodeAddress nodeAddress = trade.getArbitrator().getNodeAddress();
|
||||||
|
if (nodeAddress != null && !nodeAddress.equals(sender)) {
|
||||||
|
log.warn("Ignoring InitTradeRequest because sender is not the arbitrator for the trade, tradeId={}, sender={}", message.getOfferId(), sender);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
latchTrade();
|
latchTrade();
|
||||||
expect(phase(Trade.Phase.INIT)
|
expect(phase(Trade.Phase.INIT)
|
||||||
.with(message)
|
.with(message)
|
||||||
.from(peer))
|
.from(sender))
|
||||||
.setup(tasks(
|
.setup(tasks(
|
||||||
ApplyFilter.class,
|
ApplyFilter.class,
|
||||||
ProcessInitTradeRequest.class,
|
ProcessInitTradeRequest.class,
|
||||||
|
|
@ -113,10 +121,10 @@ public class SellerAsTakerProtocol extends SellerProtocol implements TakerProtoc
|
||||||
.using(new TradeTaskRunner(trade,
|
.using(new TradeTaskRunner(trade,
|
||||||
() -> {
|
() -> {
|
||||||
startTimeout();
|
startTimeout();
|
||||||
handleTaskRunnerSuccess(peer, message);
|
handleTaskRunnerSuccess(sender, message);
|
||||||
},
|
},
|
||||||
errorMessage -> {
|
errorMessage -> {
|
||||||
handleTaskRunnerFault(peer, message, errorMessage);
|
handleTaskRunnerFault(sender, message, errorMessage);
|
||||||
}))
|
}))
|
||||||
.withTimeout(TRADE_STEP_TIMEOUT_SECONDS))
|
.withTimeout(TRADE_STEP_TIMEOUT_SECONDS))
|
||||||
.executeTasks(true);
|
.executeTasks(true);
|
||||||
|
|
|
||||||
|
|
@ -132,6 +132,7 @@ public class ProcessInitTradeRequest extends TradeTask {
|
||||||
if (request.getTradePrice() != trade.getPrice().getValue()) throw new RuntimeException("Trade price does not match request's trade price");
|
if (request.getTradePrice() != trade.getPrice().getValue()) throw new RuntimeException("Trade price does not match request's trade price");
|
||||||
Arbitrator arbitrator = processModel.getUser().getAcceptedArbitratorByAddress(request.getArbitratorNodeAddress());
|
Arbitrator arbitrator = processModel.getUser().getAcceptedArbitratorByAddress(request.getArbitratorNodeAddress());
|
||||||
if (arbitrator == null) throw new RuntimeException("Arbitrator is not accepted by taker");
|
if (arbitrator == null) throw new RuntimeException("Arbitrator is not accepted by taker");
|
||||||
|
if (trade.getArbitrator().getNodeAddress() != null && !trade.getArbitrator().getNodeAddress().equals(request.getArbitratorNodeAddress())) throw new RuntimeException("Trade's arbitrator node address does not match request");
|
||||||
trade.getArbitrator().setNodeAddress(request.getArbitratorNodeAddress());
|
trade.getArbitrator().setNodeAddress(request.getArbitratorNodeAddress());
|
||||||
trade.getArbitrator().setPubKeyRing(arbitrator.getPubKeyRing());
|
trade.getArbitrator().setPubKeyRing(arbitrator.getPubKeyRing());
|
||||||
sender = trade.getTradePeer(processModel.getTempTradePeerNodeAddress());
|
sender = trade.getTradePeer(processModel.getTempTradePeerNodeAddress());
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue