mirror of
https://github.com/bisq-network/bisq.git
synced 2024-11-19 18:03:12 +01:00
Add check for min peers connected for broadcast
This commit is contained in:
parent
c1d04cd435
commit
846aa494ca
@ -1205,9 +1205,10 @@ public class TradeWalletService {
|
||||
}
|
||||
|
||||
private void addAvailableInputsAndChangeOutputs(Transaction transaction, Address address, Address changeAddress, Coin txFee) throws WalletException {
|
||||
SendRequest sendRequest = null;
|
||||
try {
|
||||
// Lets let the framework do the work to find the right inputs
|
||||
SendRequest sendRequest = SendRequest.forTx(transaction);
|
||||
sendRequest = SendRequest.forTx(transaction);
|
||||
sendRequest.shuffleOutputs = false;
|
||||
sendRequest.aesKey = aesKey;
|
||||
// We use a fixed fee
|
||||
@ -1222,10 +1223,11 @@ public class TradeWalletService {
|
||||
// We don't commit that tx to the wallet as it will be changed later and it's not signed yet.
|
||||
// So it will not change the wallet balance.
|
||||
checkNotNull(wallet, "wallet must not be null");
|
||||
// TODO we got here exceptions with missing funds. Not reproducable but leave log for better debugging.
|
||||
log.info("print tx before wallet.completeTx: " + sendRequest.tx.toString());
|
||||
wallet.completeTx(sendRequest);
|
||||
} catch (Throwable t) {
|
||||
if (sendRequest != null && sendRequest.tx != null)
|
||||
log.warn("addAvailableInputsAndChangeOutputs: sendRequest.tx={}, sendRequest.tx.getOutputs()={}", sendRequest.tx, sendRequest.tx.getOutputs());
|
||||
|
||||
throw new WalletException(t);
|
||||
}
|
||||
}
|
||||
|
@ -97,6 +97,7 @@ public class WalletsSetup {
|
||||
private final List<Runnable> setupCompletedHandlers = new ArrayList<>();
|
||||
public final BooleanProperty shutDownComplete = new SimpleBooleanProperty();
|
||||
private WalletConfig walletConfig;
|
||||
private int minBroadcastConnections;
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Constructor
|
||||
@ -273,6 +274,7 @@ public class WalletsSetup {
|
||||
|
||||
private void configPeerNodes(Socks5Proxy socks5Proxy) {
|
||||
if (params == RegTestParams.get()) {
|
||||
minBroadcastConnections = 1;
|
||||
if (regTestHost == RegTestHost.REG_TEST_SERVER) {
|
||||
try {
|
||||
walletConfig.setPeerNodes(new PeerAddress(InetAddress.getByName(RegTestHost.SERVER_IP), params.getPort()));
|
||||
@ -286,6 +288,7 @@ public class WalletsSetup {
|
||||
}
|
||||
} else {
|
||||
List<BitcoinNodes.BtcNode> btcNodeList = new ArrayList<>();
|
||||
minBroadcastConnections = (int) Math.floor(DEFAULT_CONNECTIONS * 0.8);
|
||||
switch (BitcoinNodes.BitcoinNodesOption.values()[preferences.getBitcoinNodesOptionOrdinal()]) {
|
||||
case CUSTOM:
|
||||
String bitcoinNodesString = preferences.getBitcoinNodes();
|
||||
@ -307,7 +310,8 @@ public class WalletsSetup {
|
||||
|
||||
// We require only 4 nodes instead of 7 (for 9 max connections) because our provided nodes
|
||||
// are more reliable than random public nodes.
|
||||
walletConfig.setMinBroadcastConnections(4);
|
||||
minBroadcastConnections = 4;
|
||||
walletConfig.setMinBroadcastConnections(minBroadcastConnections);
|
||||
break;
|
||||
}
|
||||
|
||||
@ -511,6 +515,10 @@ public class WalletsSetup {
|
||||
.collect(Collectors.toSet());
|
||||
}
|
||||
|
||||
public boolean hasSufficientPeersForBroadcast() {
|
||||
return bisqEnvironment.isBitcoinLocalhostNodeRunning() ? true : numPeers.get() >= minBroadcastConnections;
|
||||
}
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Inner classes
|
||||
|
@ -29,6 +29,7 @@ import io.bisq.common.monetary.Volume;
|
||||
import io.bisq.common.util.MathUtils;
|
||||
import io.bisq.core.app.BisqEnvironment;
|
||||
import io.bisq.core.btc.Restrictions;
|
||||
import io.bisq.core.btc.wallet.WalletsSetup;
|
||||
import io.bisq.core.offer.Offer;
|
||||
import io.bisq.core.offer.OfferPayload;
|
||||
import io.bisq.core.payment.PaymentAccount;
|
||||
@ -64,6 +65,7 @@ class CreateOfferViewModel extends ActivatableWithDataModel<CreateOfferDataModel
|
||||
private final BsqValidator bsqValidator;
|
||||
private final SecurityDepositValidator securityDepositValidator;
|
||||
private final P2PService p2PService;
|
||||
private final WalletsSetup walletsSetup;
|
||||
private final PriceFeedService priceFeedService;
|
||||
private final Navigation navigation;
|
||||
private final BSFormatter btcFormatter;
|
||||
@ -159,6 +161,7 @@ class CreateOfferViewModel extends ActivatableWithDataModel<CreateOfferDataModel
|
||||
BsqValidator bsqValidator,
|
||||
SecurityDepositValidator securityDepositValidator,
|
||||
P2PService p2PService,
|
||||
WalletsSetup walletsSetup,
|
||||
PriceFeedService priceFeedService,
|
||||
Navigation navigation,
|
||||
BSFormatter btcFormatter,
|
||||
@ -172,6 +175,7 @@ class CreateOfferViewModel extends ActivatableWithDataModel<CreateOfferDataModel
|
||||
this.bsqValidator = bsqValidator;
|
||||
this.securityDepositValidator = securityDepositValidator;
|
||||
this.p2PService = p2PService;
|
||||
this.walletsSetup = walletsSetup;
|
||||
this.priceFeedService = priceFeedService;
|
||||
this.navigation = navigation;
|
||||
this.btcFormatter = btcFormatter;
|
||||
@ -886,7 +890,7 @@ class CreateOfferViewModel extends ActivatableWithDataModel<CreateOfferDataModel
|
||||
}
|
||||
|
||||
boolean isBootstrapped() {
|
||||
return p2PService.isBootstrapped();
|
||||
return p2PService.isBootstrapped() && walletsSetup.hasSufficientPeersForBroadcast();
|
||||
}
|
||||
|
||||
|
||||
|
@ -430,7 +430,7 @@ public class OfferBookView extends ActivatableViewAndModel<GridPane, OfferBookVi
|
||||
}
|
||||
|
||||
private void onTakeOffer(Offer offer) {
|
||||
if (model.isBootstrapped())
|
||||
if (model.isBootstrapped() && model.hasSufficientPeersForBroadcast())
|
||||
offerActionHandler.onTakeOffer(offer);
|
||||
else
|
||||
new Popup<>().information(Res.get("popup.warning.notFullyConnected")).show();
|
||||
|
@ -26,6 +26,7 @@ import io.bisq.common.handlers.ResultHandler;
|
||||
import io.bisq.common.locale.*;
|
||||
import io.bisq.common.monetary.Price;
|
||||
import io.bisq.common.monetary.Volume;
|
||||
import io.bisq.core.btc.wallet.WalletsSetup;
|
||||
import io.bisq.core.filter.FilterManager;
|
||||
import io.bisq.core.offer.Offer;
|
||||
import io.bisq.core.offer.OfferPayload;
|
||||
@ -72,6 +73,7 @@ class OfferBookViewModel extends ActivatableViewModel {
|
||||
final PriceFeedService priceFeedService;
|
||||
private final ClosedTradableManager closedTradableManager;
|
||||
private final FilterManager filterManager;
|
||||
private final WalletsSetup walletsSetup;
|
||||
final AccountAgeWitnessService accountAgeWitnessService;
|
||||
private final Navigation navigation;
|
||||
final BSFormatter formatter;
|
||||
@ -103,10 +105,18 @@ class OfferBookViewModel extends ActivatableViewModel {
|
||||
|
||||
@SuppressWarnings("WeakerAccess")
|
||||
@Inject
|
||||
public OfferBookViewModel(User user, OpenOfferManager openOfferManager, OfferBook offerBook,
|
||||
Preferences preferences, P2PService p2PService, PriceFeedService priceFeedService,
|
||||
ClosedTradableManager closedTradableManager, FilterManager filterManager,
|
||||
AccountAgeWitnessService accountAgeWitnessService, Navigation navigation, BSFormatter formatter) {
|
||||
public OfferBookViewModel(User user,
|
||||
OpenOfferManager openOfferManager,
|
||||
OfferBook offerBook,
|
||||
Preferences preferences,
|
||||
P2PService p2PService,
|
||||
PriceFeedService priceFeedService,
|
||||
ClosedTradableManager closedTradableManager,
|
||||
FilterManager filterManager,
|
||||
WalletsSetup walletsSetup,
|
||||
AccountAgeWitnessService accountAgeWitnessService,
|
||||
Navigation navigation,
|
||||
BSFormatter formatter) {
|
||||
super();
|
||||
|
||||
this.openOfferManager = openOfferManager;
|
||||
@ -117,6 +127,7 @@ class OfferBookViewModel extends ActivatableViewModel {
|
||||
this.priceFeedService = priceFeedService;
|
||||
this.closedTradableManager = closedTradableManager;
|
||||
this.filterManager = filterManager;
|
||||
this.walletsSetup = walletsSetup;
|
||||
this.accountAgeWitnessService = accountAgeWitnessService;
|
||||
this.navigation = navigation;
|
||||
this.formatter = formatter;
|
||||
@ -247,6 +258,10 @@ class OfferBookViewModel extends ActivatableViewModel {
|
||||
return p2PService.isBootstrapped();
|
||||
}
|
||||
|
||||
boolean hasSufficientPeersForBroadcast() {
|
||||
return walletsSetup.hasSufficientPeersForBroadcast();
|
||||
}
|
||||
|
||||
TradeCurrency getSelectedTradeCurrency() {
|
||||
return selectedTradeCurrency;
|
||||
}
|
||||
|
@ -36,7 +36,9 @@ class OpenOffersViewModel extends ActivatableWithDataModel<OpenOffersDataModel>
|
||||
|
||||
|
||||
@Inject
|
||||
public OpenOffersViewModel(OpenOffersDataModel dataModel, P2PService p2PService, BSFormatter formatter) {
|
||||
public OpenOffersViewModel(OpenOffersDataModel dataModel,
|
||||
P2PService p2PService,
|
||||
BSFormatter formatter) {
|
||||
super(dataModel);
|
||||
|
||||
this.p2PService = p2PService;
|
||||
|
Loading…
Reference in New Issue
Block a user