Delay callback of tx broadcaster

This commit is contained in:
Manfred Karrer 2018-01-09 21:15:58 +01:00
parent 1b7db08e68
commit 7f0e871007
No known key found for this signature in database
GPG Key ID: 401250966A6B2C46
4 changed files with 22 additions and 14 deletions

View File

@ -10,7 +10,7 @@ public class DevEnv {
// peer (click user icon and alt+r), filter/block offers by various data like offer ID (cmd + f).
// The user can set a program argument to ignore all of those privileged network_messages. They are intended for
// emergency cases only (beside update message and arbitrator registration).
public static final boolean USE_DEV_PRIVILEGE_KEYS = false;
public static final boolean USE_DEV_PRIVILEGE_KEYS = true;
public static final String DEV_PRIVILEGE_PUB_KEY = "027a381b5333a56e1cc3d90d3a7d07f26509adf7029ed06fc997c656621f8da1ee";
public static final String DEV_PRIVILEGE_PRIV_KEY = "6ac43ea1df2a290c1c8391736aa42e4339c5cb4f110ff0257a13b63211977b7a";
@ -18,7 +18,7 @@ public class DevEnv {
// If set to true we ignore several UI behavior like confirmation popups as well dummy accounts are created and
// offers are filled with default values. Intended to make dev testing faster.
@SuppressWarnings("PointlessBooleanExpression")
public static final boolean DEV_MODE = STRESS_TEST_MODE || false;
public static final boolean DEV_MODE = STRESS_TEST_MODE || true;
public static final boolean DAO_PHASE2_ACTIVATED = false;
public static final boolean DAO_TRADING_ACTIVATED = false;

View File

@ -316,22 +316,28 @@ public abstract class WalletService {
Futures.addCallback(peerGroup.broadcastTransaction(tx).future(), new FutureCallback<Transaction>() {
@Override
public void onSuccess(@Nullable Transaction result) {
if (broadcastTimers.containsKey(tx.getHashAsString())) {
// If the timeout has not been called we call the callback.onSuccess
timeoutTimer.stop();
broadcastTimers.remove(tx.getHashAsString());
callback.onSuccess(tx);
} else {
// Timeout was triggered, nothing to do anymore.
log.info("onSuccess for tx {} was already called from timeout handler. ", tx.getHashAsString());
}
// At regtest we get called immediately back but we want to make sure that the handler is not called
// before the caller is finished.
UserThread.execute(() -> {
if (broadcastTimers.containsKey(tx.getHashAsString())) {
// If the timeout has not been called we call the callback.onSuccess
timeoutTimer.stop();
broadcastTimers.remove(tx.getHashAsString());
callback.onSuccess(tx);
} else {
// Timeout was triggered, nothing to do anymore.
log.info("onSuccess for tx {} was already called from timeout handler. ", tx.getHashAsString());
}
});
}
@Override
public void onFailure(@NotNull Throwable t) {
timeoutTimer.stop();
broadcastTimers.remove(tx.getHashAsString());
callback.onFailure(t);
UserThread.execute(() -> {
timeoutTimer.stop();
broadcastTimers.remove(tx.getHashAsString());
callback.onFailure(t);
});
}
});
printTx("BSQ broadcast Tx", tx);

View File

@ -108,6 +108,7 @@ public class BuyerAsTakerSignAndPublishDepositTx extends TradeTask {
}
}
});
// We set the deposit tx in case we get the onFailure called.
trade.setDepositTx(depositTx);
} catch (Throwable t) {
failed(t);

View File

@ -109,6 +109,7 @@ public class SellerAsTakerSignAndPublishDepositTx extends TradeTask {
}
}
});
// We set the deposit tx in case we get the onFailure called.
trade.setDepositTx(depositTx);
} catch (Throwable t) {
final Contract contract = trade.getContract();