improve handling of certain electrum server errors

This commit is contained in:
Craig Raw 2022-12-02 17:16:34 +02:00
parent 6871810c7c
commit 8de14dcbce
2 changed files with 15 additions and 3 deletions

View file

@ -150,7 +150,7 @@ public class SimpleElectrumServerRpc implements ElectrumServerRpc {
//If there is an error with the server connection, don't keep trying - this may take too long given many blocks
throw new ElectrumServerRpcException("Failed to retrieve block header for block height: " + blockHeight, e);
} catch(JsonRpcException e) {
log.warn("Failed to retrieve block header for block height: " + blockHeight + " (" + e.getErrorMessage() + ")");
log.warn("Failed to retrieve block header for block height: " + blockHeight + (e.getErrorMessage() != null ? " (" + e.getErrorMessage().getMessage() + ")" : ""));
} catch(Exception e) {
log.warn("Failed to retrieve block header for block height: " + blockHeight + " (" + e.getMessage() + ")");
}
@ -193,6 +193,11 @@ public class SimpleElectrumServerRpc implements ElectrumServerRpc {
client.createRequest().returnAs(VerboseTransaction.class).method("blockchain.transaction.get").id(idCounter.incrementAndGet()).params(txid, true).execute());
result.put(txid, verboseTransaction);
} catch(Exception e) {
if(e instanceof JsonRpcException jsonRpcException && jsonRpcException.getErrorMessage() != null
&& jsonRpcException.getErrorMessage().getMessage().startsWith("No such mempool or blockchain transaction")) {
continue;
}
//electrs-esplora does not currently support the verbose parameter, so try to fetch an incomplete VerboseTransaction without it
//Note that without the script hash associated with the transaction, we can't get a block height as there is no way in the Electrum RPC protocol to do this
//We mark this VerboseTransaction as incomplete by assigning it a Sha256Hash.ZERO_HASH blockhash

View file

@ -1109,11 +1109,18 @@ public class HeadersController extends TransactionFormController implements Init
broadcastTransactionService.setOnFailed(workerStateEvent -> {
broadcastProgressBar.setProgress(0);
log.error("Error broadcasting transaction", workerStateEvent.getSource().getException());
if(workerStateEvent.getSource().getException() != null && workerStateEvent.getSource().getException().getMessage() != null
&& workerStateEvent.getSource().getException().getMessage().startsWith("min relay fee not met")) {
String failMessage = "";
if(workerStateEvent.getSource().getException() != null && workerStateEvent.getSource().getException().getMessage() != null) {
failMessage = workerStateEvent.getSource().getException().getMessage();
}
if(failMessage.startsWith("min relay fee not met")) {
AppServices.showErrorDialog("Error broadcasting transaction", "The fee rate for the signed transaction is below the minimum " + AppServices.getMinimumRelayFeeRate() + " sats/vB. " +
"This usually happens because a keystore has created a signature that is larger than necessary.\n\n" +
"You can solve this by recreating the transaction with a slightly increased fee rate.");
} else if(failMessage.startsWith("bad-txns-inputs-missingorspent")) {
AppServices.showErrorDialog("Error broadcasting transaction", "The server returned an error indicating some or all of the UTXOs this transaction is spending are missing or have already been spent.");
} else {
AppServices.showErrorDialog("Error broadcasting transaction", "The server returned an error when broadcasting the transaction. The server response is contained in the log (See Help > Show Log File).");
}