verify InitTradeRequest matches previously assigned arbitrator (#2048)

This commit is contained in:
woodser 2025-11-22 09:11:07 -04:00 committed by GitHub
parent 8867e9eb3b
commit 8697b5344f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 27 additions and 10 deletions

View file

@ -98,14 +98,22 @@ public class BuyerAsTakerProtocol extends BuyerProtocol implements TakerProtocol
@Override
public void handleInitTradeRequest(InitTradeRequest message,
NodeAddress peer) {
log.info(TradeProtocol.LOG_HIGHLIGHT + "handleInitTradeRequest() for {} {} from {}", trade.getClass().getSimpleName(), trade.getShortId(), peer);
NodeAddress sender) {
log.info(TradeProtocol.LOG_HIGHLIGHT + "handleInitTradeRequest() for {} {} from {}", trade.getClass().getSimpleName(), trade.getShortId(), sender);
ThreadUtils.execute(() -> {
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();
expect(phase(Trade.Phase.INIT)
.with(message)
.from(peer))
.from(sender))
.setup(tasks(
ApplyFilter.class,
ProcessInitTradeRequest.class,
@ -113,10 +121,10 @@ public class BuyerAsTakerProtocol extends BuyerProtocol implements TakerProtocol
.using(new TradeTaskRunner(trade,
() -> {
startTimeout();
handleTaskRunnerSuccess(peer, message);
handleTaskRunnerSuccess(sender, message);
},
errorMessage -> {
handleTaskRunnerFault(peer, message, errorMessage);
handleTaskRunnerFault(sender, message, errorMessage);
}))
.withTimeout(TRADE_STEP_TIMEOUT_SECONDS))
.executeTasks(true);

View file

@ -98,14 +98,22 @@ public class SellerAsTakerProtocol extends SellerProtocol implements TakerProtoc
@Override
public void handleInitTradeRequest(InitTradeRequest message,
NodeAddress peer) {
log.info(TradeProtocol.LOG_HIGHLIGHT + "handleInitTradeRequest() for {} {} from {}", trade.getClass().getSimpleName(), trade.getShortId(), peer);
NodeAddress sender) {
log.info(TradeProtocol.LOG_HIGHLIGHT + "handleInitTradeRequest() for {} {} from {}", trade.getClass().getSimpleName(), trade.getShortId(), sender);
ThreadUtils.execute(() -> {
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();
expect(phase(Trade.Phase.INIT)
.with(message)
.from(peer))
.from(sender))
.setup(tasks(
ApplyFilter.class,
ProcessInitTradeRequest.class,
@ -113,10 +121,10 @@ public class SellerAsTakerProtocol extends SellerProtocol implements TakerProtoc
.using(new TradeTaskRunner(trade,
() -> {
startTimeout();
handleTaskRunnerSuccess(peer, message);
handleTaskRunnerSuccess(sender, message);
},
errorMessage -> {
handleTaskRunnerFault(peer, message, errorMessage);
handleTaskRunnerFault(sender, message, errorMessage);
}))
.withTimeout(TRADE_STEP_TIMEOUT_SECONDS))
.executeTasks(true);

View file

@ -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");
Arbitrator arbitrator = processModel.getUser().getAcceptedArbitratorByAddress(request.getArbitratorNodeAddress());
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().setPubKeyRing(arbitrator.getPubKeyRing());
sender = trade.getTradePeer(processModel.getTempTradePeerNodeAddress());