mirror of
https://github.com/haveno-dex/haveno.git
synced 2025-06-09 15:43:08 -04:00
incease fee as testnet is spammed with tx with high fees. use FxTimer in fx classes (gui). Use scheduledExecutor instead of timer
This commit is contained in:
parent
8716a506e8
commit
e456883f9b
19 changed files with 176 additions and 175 deletions
|
@ -17,12 +17,15 @@
|
|||
|
||||
package io.bitsquare.arbitration;
|
||||
|
||||
import com.google.common.util.concurrent.MoreExecutors;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.name.Named;
|
||||
import io.bitsquare.app.ProgramArguments;
|
||||
import io.bitsquare.common.UserThread;
|
||||
import io.bitsquare.common.crypto.KeyRing;
|
||||
import io.bitsquare.common.handlers.ErrorMessageHandler;
|
||||
import io.bitsquare.common.handlers.ResultHandler;
|
||||
import io.bitsquare.common.util.Utilities;
|
||||
import io.bitsquare.p2p.Address;
|
||||
import io.bitsquare.p2p.FirstPeerAuthenticatedListener;
|
||||
import io.bitsquare.p2p.P2PService;
|
||||
|
@ -33,7 +36,6 @@ import javafx.collections.FXCollections;
|
|||
import javafx.collections.ObservableMap;
|
||||
import org.bitcoinj.core.ECKey;
|
||||
import org.bitcoinj.core.Utils;
|
||||
import org.reactfx.util.FxTimer;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
|
@ -41,11 +43,12 @@ import javax.annotation.Nullable;
|
|||
import java.math.BigInteger;
|
||||
import java.security.PublicKey;
|
||||
import java.security.SignatureException;
|
||||
import java.time.Duration;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ScheduledThreadPoolExecutor;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
|
@ -87,6 +90,7 @@ public class ArbitratorManager {
|
|||
private static final String publicKeyForTesting = "027a381b5333a56e1cc3d90d3a7d07f26509adf7029ed06fc997c656621f8da1ee";
|
||||
private final boolean isDevTest;
|
||||
private FirstPeerAuthenticatedListener firstPeerAuthenticatedListener;
|
||||
private ScheduledThreadPoolExecutor republishArbitratorExecutor;
|
||||
|
||||
@Inject
|
||||
public ArbitratorManager(@Named(ProgramArguments.DEV_TEST) boolean isDevTest, KeyRing keyRing, ArbitratorService arbitratorService, User user) {
|
||||
|
@ -108,6 +112,10 @@ public class ArbitratorManager {
|
|||
});
|
||||
}
|
||||
|
||||
public void shutDown() {
|
||||
MoreExecutors.shutdownAndAwaitTermination(republishArbitratorExecutor, 500, TimeUnit.MILLISECONDS);
|
||||
}
|
||||
|
||||
public void onAllServicesInitialized() {
|
||||
if (user.getRegisteredArbitrator() != null) {
|
||||
|
||||
|
@ -126,10 +134,8 @@ public class ArbitratorManager {
|
|||
}
|
||||
|
||||
// re-publish periodically
|
||||
FxTimer.runPeriodically(
|
||||
Duration.ofMillis(Arbitrator.TTL / 2),
|
||||
() -> republishArbitrator()
|
||||
);
|
||||
republishArbitratorExecutor = Utilities.getScheduledThreadPoolExecutor("", 1, 5, 5);
|
||||
republishArbitratorExecutor.schedule(() -> republishArbitrator(), Arbitrator.TTL / 2, TimeUnit.MILLISECONDS);
|
||||
}
|
||||
|
||||
applyArbitrators();
|
||||
|
@ -183,7 +189,7 @@ public class ArbitratorManager {
|
|||
resultHandler.handleResult();
|
||||
|
||||
if (arbitratorsObservableMap.size() > 0)
|
||||
FxTimer.runLater(Duration.ofMillis(1000), this::applyArbitrators);
|
||||
UserThread.runAfter(() -> applyArbitrators(), 1);
|
||||
},
|
||||
errorMessageHandler::handleErrorMessage);
|
||||
}
|
||||
|
|
|
@ -40,7 +40,10 @@ public class FeePolicy {
|
|||
|
||||
// Other good source is: https://tradeblock.com/blockchain 15-100 satoshis/byte
|
||||
|
||||
public static final Coin TX_FEE = Coin.valueOf(30000); // 0.0003 BTC about 0.06 EUR @ 200 EUR/BTC: about 90 satoshi /byte
|
||||
// On testnet currently fees are 0.002 BTC, so increase fee to 0.005 BTC to get for sure into blocks for testing
|
||||
public static final Coin TX_FEE = Coin.valueOf(500000); // 0.005 BTC about 0.06 EUR @ 200 EUR/BTC: about 90 satoshi /byte
|
||||
// TODO use original value again for mainnet
|
||||
// public static final Coin TX_FEE = Coin.valueOf(30000); // 0.0003 BTC about 0.06 EUR @ 200 EUR/BTC: about 90 satoshi /byte
|
||||
|
||||
static {
|
||||
// we use our fee as default fee
|
||||
|
@ -49,11 +52,11 @@ public class FeePolicy {
|
|||
|
||||
public static final Coin DUST = Coin.valueOf(546);
|
||||
|
||||
//TODO for testing
|
||||
// TODO use original value again for mainnet
|
||||
public static final Coin CREATE_OFFER_FEE = Coin.valueOf(40000); // 0.0001 BTC 0.1% of 1 BTC about 0.2 EUR @ 200 EUR/BTC
|
||||
//public static final Coin CREATE_OFFER_FEE = Coin.valueOf(100000); // 0.001 BTC 0.1% of 1 BTC about 0.2 EUR @ 200 EUR/BTC
|
||||
public static final Coin TAKE_OFFER_FEE = CREATE_OFFER_FEE;
|
||||
//TODO for testing
|
||||
// TODO use original value again for mainnet
|
||||
public static final Coin SECURITY_DEPOSIT = Coin.valueOf(10000); // 0.0001 BTC; about 20 EUR @ 200 EUR/BTC
|
||||
//public static final Coin SECURITY_DEPOSIT = Coin.valueOf(10000000); // 0.1 BTC; about 20 EUR @ 200 EUR/BTC
|
||||
}
|
||||
|
|
|
@ -141,7 +141,8 @@ public class TradeWalletService {
|
|||
public Transaction createTradingFeeTx(AddressEntry addressEntry, Coin tradingFee, String feeReceiverAddresses)
|
||||
throws InsufficientMoneyException, AddressFormatException {
|
||||
Transaction tradingFeeTx = new Transaction(params);
|
||||
Preconditions.checkArgument(tradingFee.compareTo(FeePolicy.TX_FEE) > 0);
|
||||
Preconditions.checkArgument(tradingFee.compareTo(FeePolicy.TX_FEE.add(Transaction.MIN_NONDUST_OUTPUT)) > 0,
|
||||
"You cannot send an amount which are smaller than the fee + dust output.");
|
||||
Coin outPutAmount = tradingFee.subtract(FeePolicy.TX_FEE);
|
||||
tradingFeeTx.addOutput(outPutAmount, new Address(params, feeReceiverAddresses));
|
||||
|
||||
|
|
|
@ -40,8 +40,6 @@ import org.bitcoinj.params.TestNet3Params;
|
|||
import org.bitcoinj.utils.Threading;
|
||||
import org.bitcoinj.wallet.DeterministicSeed;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.reactfx.util.FxTimer;
|
||||
import org.reactfx.util.Timer;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.spongycastle.crypto.params.KeyParameter;
|
||||
|
@ -52,7 +50,6 @@ import javax.inject.Named;
|
|||
import java.io.File;
|
||||
import java.net.InetAddress;
|
||||
import java.net.UnknownHostException;
|
||||
import java.time.Duration;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.CopyOnWriteArraySet;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
@ -70,7 +67,7 @@ public class WalletService {
|
|||
|
||||
public static final String DIR_KEY = "wallet.dir";
|
||||
public static final String PREFIX_KEY = "wallet.prefix";
|
||||
private static final long STARTUP_TIMEOUT = 60 * 1000;
|
||||
private static final long STARTUP_TIMEOUT_SEC = 60;
|
||||
|
||||
private final CopyOnWriteArraySet<AddressConfidenceListener> addressConfidenceListeners = new CopyOnWriteArraySet<>();
|
||||
private final CopyOnWriteArraySet<TxConfidenceListener> txConfidenceListeners = new CopyOnWriteArraySet<>();
|
||||
|
@ -127,13 +124,10 @@ public class WalletService {
|
|||
|
||||
Threading.USER_THREAD = UserThread.getExecutor();
|
||||
|
||||
Timer timeoutTimer = FxTimer.runLater(
|
||||
Duration.ofMillis(STARTUP_TIMEOUT),
|
||||
() -> {
|
||||
Utilities.setThreadName("WalletService:StartupTimeout");
|
||||
exceptionHandler.handleException(new TimeoutException("Wallet did not initialize in " + STARTUP_TIMEOUT / 1000 + " seconds."));
|
||||
}
|
||||
);
|
||||
Timer timeoutTimer = UserThread.runAfter(() -> {
|
||||
Utilities.setThreadName("WalletService:StartupTimeout");
|
||||
exceptionHandler.handleException(new TimeoutException("Wallet did not initialize in " + STARTUP_TIMEOUT_SEC / 1000 + " seconds."));
|
||||
}, STARTUP_TIMEOUT_SEC);
|
||||
|
||||
// If seed is non-null it means we are restoring from backup.
|
||||
walletAppKit = new WalletAppKit(params, walletDir, "Bitsquare") {
|
||||
|
@ -194,8 +188,10 @@ public class WalletService {
|
|||
|
||||
// set after wallet is ready
|
||||
tradeWalletService.setWalletAppKit(walletAppKit);
|
||||
timeoutTimer.stop();
|
||||
UserThread.execute(resultHandler::handleResult);
|
||||
timeoutTimer.cancel();
|
||||
|
||||
// onSetupCompleted in walletAppKit is not the called on the last invocations, so we add a bit of delay
|
||||
UserThread.runAfter(() -> resultHandler.handleResult(), 100, TimeUnit.MILLISECONDS);
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -240,7 +236,7 @@ public class WalletService {
|
|||
public void failed(@NotNull Service.State from, @NotNull Throwable failure) {
|
||||
walletAppKit = null;
|
||||
log.error("walletAppKit failed");
|
||||
timeoutTimer.stop();
|
||||
timeoutTimer.cancel();
|
||||
UserThread.execute(() -> exceptionHandler.handleException(failure));
|
||||
}
|
||||
}, Threading.USER_THREAD);
|
||||
|
@ -451,6 +447,8 @@ public class WalletService {
|
|||
KeyParameter aesKey,
|
||||
FutureCallback<Transaction> callback) throws AddressFormatException, IllegalArgumentException, InsufficientMoneyException {
|
||||
Transaction tx = new Transaction(params);
|
||||
checkArgument(amount.compareTo(FeePolicy.TX_FEE.add(Transaction.MIN_NONDUST_OUTPUT)) > 0,
|
||||
"You cannot send an amount which are smaller than the fee + dust output.");
|
||||
tx.addOutput(amount.subtract(FeePolicy.TX_FEE), new Address(params, toAddress));
|
||||
|
||||
Wallet.SendRequest sendRequest = Wallet.SendRequest.forTx(tx);
|
||||
|
|
|
@ -18,17 +18,15 @@
|
|||
package io.bitsquare.trade.offer;
|
||||
|
||||
import io.bitsquare.app.Version;
|
||||
import io.bitsquare.common.UserThread;
|
||||
import io.bitsquare.common.util.Utilities;
|
||||
import io.bitsquare.storage.Storage;
|
||||
import io.bitsquare.trade.Tradable;
|
||||
import io.bitsquare.trade.TradableList;
|
||||
import org.reactfx.util.FxTimer;
|
||||
import org.reactfx.util.Timer;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.time.Duration;
|
||||
import java.util.Date;
|
||||
|
||||
public class OpenOffer implements Tradable, Serializable {
|
||||
|
@ -38,7 +36,8 @@ public class OpenOffer implements Tradable, Serializable {
|
|||
private static final Logger log = LoggerFactory.getLogger(OpenOffer.class);
|
||||
|
||||
// Timeout for offer reservation during takeoffer process. If deposit tx is not completed in that time we reset the offer to AVAILABLE state.
|
||||
transient private static final long TIMEOUT = 30 * 1000;
|
||||
transient private static final long TIMEOUT_SEC = 30;
|
||||
private java.util.Timer timeoutTimer;
|
||||
|
||||
public enum State {
|
||||
AVAILABLE,
|
||||
|
@ -50,7 +49,6 @@ public class OpenOffer implements Tradable, Serializable {
|
|||
private final Offer offer;
|
||||
private State state = State.AVAILABLE;
|
||||
|
||||
transient private Timer timeoutTimer;
|
||||
transient private Storage<TradableList<OpenOffer>> storage;
|
||||
|
||||
public OpenOffer(Offer offer, Storage<TradableList<OpenOffer>> storage) {
|
||||
|
@ -100,19 +98,17 @@ public class OpenOffer implements Tradable, Serializable {
|
|||
private void startTimeout() {
|
||||
stopTimeout();
|
||||
|
||||
timeoutTimer = FxTimer.runLater(
|
||||
Duration.ofMillis(TIMEOUT),
|
||||
() -> {
|
||||
Utilities.setThreadName("OpenOffer:Timeout");
|
||||
log.info("Timeout reached");
|
||||
if (state == State.RESERVED)
|
||||
setState(State.AVAILABLE);
|
||||
});
|
||||
timeoutTimer = UserThread.runAfter(() -> {
|
||||
Utilities.setThreadName("OpenOffer:Timeout");
|
||||
log.info("Timeout reached");
|
||||
if (state == State.RESERVED)
|
||||
setState(State.AVAILABLE);
|
||||
}, TIMEOUT_SEC);
|
||||
}
|
||||
|
||||
private void stopTimeout() {
|
||||
if (timeoutTimer != null) {
|
||||
timeoutTimer.stop();
|
||||
timeoutTimer.cancel();
|
||||
timeoutTimer = null;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -40,17 +40,16 @@ import io.bitsquare.trade.protocol.placeoffer.PlaceOfferModel;
|
|||
import io.bitsquare.trade.protocol.placeoffer.PlaceOfferProtocol;
|
||||
import io.bitsquare.user.User;
|
||||
import javafx.collections.ObservableList;
|
||||
import org.reactfx.util.FxTimer;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import javax.inject.Named;
|
||||
import java.io.File;
|
||||
import java.time.Duration;
|
||||
import java.util.Optional;
|
||||
import java.util.Timer;
|
||||
import java.util.TimerTask;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import static com.google.inject.internal.util.$Preconditions.checkNotNull;
|
||||
import static io.bitsquare.util.Validator.nonEmptyStringOf;
|
||||
|
@ -189,8 +188,9 @@ public class OpenOfferManager {
|
|||
offerBookService.removeOfferAtShutDown(openOffer.getOffer());
|
||||
}
|
||||
|
||||
// delay a bit before we signal that we are done to give time for network
|
||||
if (completeHandler != null)
|
||||
FxTimer.runLater(Duration.ofMillis(500), completeHandler::run);
|
||||
UserThread.runAfter(() -> completeHandler.run(), 500, TimeUnit.MILLISECONDS);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
|
||||
package io.bitsquare.trade.protocol.availability;
|
||||
|
||||
import io.bitsquare.common.UserThread;
|
||||
import io.bitsquare.common.handlers.ErrorMessageHandler;
|
||||
import io.bitsquare.common.handlers.ResultHandler;
|
||||
import io.bitsquare.common.taskrunner.TaskRunner;
|
||||
|
@ -29,27 +30,23 @@ import io.bitsquare.trade.protocol.availability.messages.OfferMessage;
|
|||
import io.bitsquare.trade.protocol.availability.tasks.GetPeerAddress;
|
||||
import io.bitsquare.trade.protocol.availability.tasks.ProcessOfferAvailabilityResponse;
|
||||
import io.bitsquare.trade.protocol.availability.tasks.SendOfferAvailabilityRequest;
|
||||
import org.reactfx.util.FxTimer;
|
||||
import org.reactfx.util.Timer;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.time.Duration;
|
||||
|
||||
import static io.bitsquare.util.Validator.nonEmptyStringOf;
|
||||
|
||||
public class OfferAvailabilityProtocol {
|
||||
private static final Logger log = LoggerFactory.getLogger(OfferAvailabilityProtocol.class);
|
||||
|
||||
private static final long TIMEOUT = 30 * 1000;
|
||||
private static final long TIMEOUT_SEC = 30;
|
||||
|
||||
private final OfferAvailabilityModel model;
|
||||
private final ResultHandler resultHandler;
|
||||
private final ErrorMessageHandler errorMessageHandler;
|
||||
private final DecryptedMailListener decryptedMailListener;
|
||||
private Timer timeoutTimer;
|
||||
|
||||
private TaskRunner<OfferAvailabilityModel> taskRunner;
|
||||
private java.util.Timer timeoutTimer;
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -144,16 +141,16 @@ public class OfferAvailabilityProtocol {
|
|||
private void startTimeout() {
|
||||
stopTimeout();
|
||||
|
||||
timeoutTimer = FxTimer.runLater(Duration.ofMillis(TIMEOUT), () -> {
|
||||
timeoutTimer = UserThread.runAfter(() -> {
|
||||
Utilities.setThreadName("OfferAvailabilityProtocol:Timeout");
|
||||
log.warn("Timeout reached");
|
||||
errorMessageHandler.handleErrorMessage("Timeout reached: Peer has not responded.");
|
||||
});
|
||||
}, TIMEOUT_SEC);
|
||||
}
|
||||
|
||||
private void stopTimeout() {
|
||||
if (timeoutTimer != null) {
|
||||
timeoutTimer.stop();
|
||||
timeoutTimer.cancel();
|
||||
timeoutTimer = null;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
|
||||
package io.bitsquare.trade.protocol.trade;
|
||||
|
||||
import io.bitsquare.common.UserThread;
|
||||
import io.bitsquare.common.crypto.PubKeyRing;
|
||||
import io.bitsquare.common.util.Utilities;
|
||||
import io.bitsquare.p2p.Address;
|
||||
|
@ -28,24 +29,21 @@ import io.bitsquare.trade.TakerTrade;
|
|||
import io.bitsquare.trade.Trade;
|
||||
import io.bitsquare.trade.protocol.trade.messages.TradeMessage;
|
||||
import io.bitsquare.trade.protocol.trade.tasks.shared.SetupPayoutTxLockTimeReachedListener;
|
||||
import org.reactfx.util.FxTimer;
|
||||
import org.reactfx.util.Timer;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.security.PublicKey;
|
||||
import java.time.Duration;
|
||||
|
||||
import static io.bitsquare.util.Validator.nonEmptyStringOf;
|
||||
|
||||
public abstract class TradeProtocol {
|
||||
private static final Logger log = LoggerFactory.getLogger(TradeProtocol.class);
|
||||
private static final long TIMEOUT = 30 * 1000;
|
||||
private static final long TIMEOUT_SEC = 30;
|
||||
|
||||
protected final ProcessModel processModel;
|
||||
private final DecryptedMailListener decryptedMailListener;
|
||||
private Timer timeoutTimer;
|
||||
protected Trade trade;
|
||||
private java.util.Timer timeoutTimer;
|
||||
|
||||
public TradeProtocol(Trade trade) {
|
||||
this.trade = trade;
|
||||
|
@ -125,18 +123,18 @@ public abstract class TradeProtocol {
|
|||
protected void startTimeout() {
|
||||
stopTimeout();
|
||||
|
||||
timeoutTimer = FxTimer.runLater(Duration.ofMillis(TIMEOUT), () -> {
|
||||
timeoutTimer = UserThread.runAfter(() -> {
|
||||
Utilities.setThreadName("TradeProtocol:Timeout");
|
||||
log.error("Timeout reached");
|
||||
trade.setErrorMessage("A timeout occurred.");
|
||||
cleanupTradable();
|
||||
cleanup();
|
||||
});
|
||||
}, TIMEOUT_SEC);
|
||||
}
|
||||
|
||||
protected void stopTimeout() {
|
||||
if (timeoutTimer != null) {
|
||||
timeoutTimer.stop();
|
||||
timeoutTimer.cancel();
|
||||
timeoutTimer = null;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue