Merge pull request #3925 from sqrrm/dump-delayed-tx

Dump delayed tx
This commit is contained in:
Christoph Atteneder 2020-02-03 12:03:25 +01:00 committed by GitHub
commit ff10857fe6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 57 additions and 10 deletions

View File

@ -114,6 +114,7 @@ public class Config {
public static final String GENESIS_BLOCK_HEIGHT = "genesisBlockHeight";
public static final String GENESIS_TOTAL_SUPPLY = "genesisTotalSupply";
public static final String DAO_ACTIVATED = "daoActivated";
public static final String DUMP_DELAYED_PAYOUT_TXS = "dumpDelayedPayoutTxs";
// Default values for certain options
public static final int UNSPECIFIED_PORT = -1;
@ -195,6 +196,7 @@ public class Config {
public final String genesisTxId;
public final int genesisBlockHeight;
public final long genesisTotalSupply;
public final boolean dumpDelayedPayoutTxs;
// Properties derived from options but not exposed as options themselves
public final File torDir;
@ -597,6 +599,12 @@ public class Config {
.ofType(boolean.class)
.defaultsTo(true);
ArgumentAcceptingOptionSpec<Boolean> dumpDelayedPayoutTxsOpt =
parser.accepts(DUMP_DELAYED_PAYOUT_TXS, "Dump delayed payout transactions to file")
.withRequiredArg()
.ofType(boolean.class)
.defaultsTo(false);
try {
CompositeOptionSet options = new CompositeOptionSet();
@ -701,6 +709,7 @@ public class Config {
this.genesisBlockHeight = options.valueOf(genesisBlockHeightOpt);
this.genesisTotalSupply = options.valueOf(genesisTotalSupplyOpt);
this.daoActivated = options.valueOf(daoActivatedOpt) || !baseCurrencyNetwork.isMainnet();
this.dumpDelayedPayoutTxs = options.valueOf(dumpDelayedPayoutTxsOpt);
} catch (OptionException ex) {
throw new ConfigException("problem parsing option '%s': %s",
ex.options().get(0),

View File

@ -57,13 +57,16 @@ import bisq.network.p2p.P2PService;
import bisq.network.p2p.SendMailboxMessageListener;
import bisq.common.ClockWatcher;
import bisq.common.config.Config;
import bisq.common.crypto.KeyRing;
import bisq.common.handlers.ErrorMessageHandler;
import bisq.common.handlers.FaultHandler;
import bisq.common.handlers.ResultHandler;
import bisq.common.proto.network.NetworkEnvelope;
import bisq.common.proto.persistable.PersistedDataHost;
import bisq.common.storage.JsonFileManager;
import bisq.common.storage.Storage;
import bisq.common.util.Utilities;
import org.bitcoinj.core.AddressFormatException;
import org.bitcoinj.core.Coin;
@ -72,6 +75,7 @@ import org.bitcoinj.core.Transaction;
import org.bitcoinj.core.TransactionConfidence;
import javax.inject.Inject;
import javax.inject.Named;
import com.google.common.util.concurrent.FutureCallback;
@ -86,6 +90,8 @@ import javafx.collections.ObservableList;
import org.spongycastle.crypto.params.KeyParameter;
import java.io.File;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
@ -141,6 +147,8 @@ public class TradeManager implements PersistedDataHost {
private final LongProperty numPendingTrades = new SimpleLongProperty();
@Getter
private final ObservableList<Trade> tradesWithoutDepositTx = FXCollections.observableArrayList();
private final boolean dumpDelayedPayoutTxs;
private final JsonFileManager jsonFileManager;
///////////////////////////////////////////////////////////////////////////////////////////
@ -167,7 +175,9 @@ public class TradeManager implements PersistedDataHost {
RefundAgentManager refundAgentManager,
DaoFacade daoFacade,
ClockWatcher clockWatcher,
Storage<TradableList<Trade>> storage) {
Storage<TradableList<Trade>> storage,
@Named(Config.STORAGE_DIR) File storageDir,
@Named(Config.DUMP_DELAYED_PAYOUT_TXS) boolean dumpDelayedPayoutTxs) {
this.user = user;
this.keyRing = keyRing;
this.btcWalletService = btcWalletService;
@ -187,6 +197,7 @@ public class TradeManager implements PersistedDataHost {
this.refundAgentManager = refundAgentManager;
this.daoFacade = daoFacade;
this.clockWatcher = clockWatcher;
this.dumpDelayedPayoutTxs = dumpDelayedPayoutTxs;
tradableListStorage = storage;
@ -222,6 +233,9 @@ public class TradeManager implements PersistedDataHost {
}
}
});
jsonFileManager = new JsonFileManager(storageDir);
}
@Override
@ -233,6 +247,7 @@ public class TradeManager implements PersistedDataHost {
if (offer != null)
offer.setPriceFeedService(priceFeedService);
});
maybeDumpDelayedPayoutTxs();
}
@ -285,13 +300,13 @@ public class TradeManager implements PersistedDataHost {
removePreparedTradeList.add(trade);
}
if (trade.getDepositTx() == null) {
log.warn("Deposit tx for trader with ID {} is null at initPendingTrades. " +
"This can happen for valid transaction in rare cases (e.g. after a SPV resync). " +
"We leave it to the user to move the trade to failed trades if the problem persists.",
trade.getId());
tradesWithoutDepositTx.add(trade);
}
if (trade.getDepositTx() == null) {
log.warn("Deposit tx for trader with ID {} is null at initPendingTrades. " +
"This can happen for valid transaction in rare cases (e.g. after a SPV resync). " +
"We leave it to the user to move the trade to failed trades if the problem persists.",
trade.getId());
tradesWithoutDepositTx.add(trade);
}
}
);
@ -460,7 +475,7 @@ public class TradeManager implements PersistedDataHost {
model,
tradeResultHandler);
},
errorMessageHandler::handleErrorMessage);
errorMessageHandler);
}
private void createTrade(Coin amount,
@ -530,7 +545,7 @@ public class TradeManager implements PersistedDataHost {
Trade trade, ResultHandler resultHandler, FaultHandler faultHandler) {
String fromAddress = btcWalletService.getOrCreateAddressEntry(trade.getId(),
AddressEntry.Context.TRADE_PAYOUT).getAddressString();
FutureCallback<Transaction> callback = new FutureCallback<Transaction>() {
FutureCallback<Transaction> callback = new FutureCallback<>() {
@Override
public void onSuccess(@javax.annotation.Nullable Transaction transaction) {
if (transaction != null) {
@ -778,4 +793,25 @@ public class TradeManager implements PersistedDataHost {
public void persistTrades() {
tradableList.persist();
}
@SuppressWarnings("InnerClassMayBeStatic")
class DelayedPayoutHash {
String tradeId;
String delayedPayoutTx;
DelayedPayoutHash(String tradeId, String delayedPayoutTx) {
this.tradeId = tradeId;
this.delayedPayoutTx = delayedPayoutTx;
}
}
private void maybeDumpDelayedPayoutTxs() {
if (!dumpDelayedPayoutTxs)
return;
var delayedPayoutHashes = tradableList.stream()
.map(trade -> new DelayedPayoutHash(trade.getId(),
Utilities.bytesAsHexString(trade.getDelayedPayoutTxBytes())))
.collect(Collectors.toList());
jsonFileManager.writeToDisc(Utilities.objectToJson(delayedPayoutHashes), "delayed_payout_txs");
}
}

View File

@ -33,6 +33,7 @@ import bisq.common.config.Config;
import com.google.inject.Singleton;
import static bisq.common.config.Config.DUMP_DELAYED_PAYOUT_TXS;
import static bisq.common.config.Config.DUMP_STATISTICS;
import static com.google.inject.name.Names.named;
@ -56,5 +57,6 @@ public class TradeModule extends AppModule {
bind(ReferralIdService.class).in(Singleton.class);
bind(AssetTradeActivityCheck.class).in(Singleton.class);
bindConstant().annotatedWith(named(DUMP_STATISTICS)).to(config.dumpStatistics);
bindConstant().annotatedWith(named(DUMP_DELAYED_PAYOUT_TXS)).to(config.dumpDelayedPayoutTxs);
}
}