mirror of
https://github.com/bisq-network/bisq.git
synced 2024-11-19 18:03:12 +01:00
Handle RPC errors
- Trigger apply from snapshot if rpc error is detected - Add warn handler to show only warning msg instead of error msg if btc full node is not running in full mode
This commit is contained in:
parent
a27391da16
commit
f27918c28a
@ -88,7 +88,8 @@ public class BisqHeadlessApp implements HeadlessApp {
|
||||
bisqSetup.setDisplayUpdateHandler((alert, key) -> log.info("onDisplayUpdateHandler"));
|
||||
bisqSetup.setDisplayAlertHandler(alert -> log.info("onDisplayAlertHandler. alert={}", alert));
|
||||
bisqSetup.setDisplayPrivateNotificationHandler(privateNotification -> log.info("onDisplayPrivateNotificationHandler. privateNotification={}", privateNotification));
|
||||
bisqSetup.setDaoSetupErrorHandler(errorMessage -> log.info("onDaoSetupErrorHandler. errorMessage={}", errorMessage));
|
||||
bisqSetup.setDaoErrorMessageHandler(errorMessage -> log.info("onDaoErrorMessageHandler. errorMessage={}", errorMessage));
|
||||
bisqSetup.setDaoWarnMessageHandler(warnMessage -> log.info("onDaoWarnMessageHandler. warnMessage={}", warnMessage));
|
||||
bisqSetup.setDisplaySecurityRecommendationHandler(key -> log.info("onDisplaySecurityRecommendationHandler"));
|
||||
bisqSetup.setDisplayLocalhostHandler(key -> log.info("onDisplayLocalhostHandler"));
|
||||
bisqSetup.setWrongOSArchitectureHandler(msg -> log.info("onWrongOSArchitectureHandler. msg={}", msg));
|
||||
|
@ -161,8 +161,9 @@ public class BisqSetup {
|
||||
@Setter
|
||||
@Nullable
|
||||
private Consumer<String> cryptoSetupFailedHandler, chainFileLockedExceptionHandler,
|
||||
spvFileCorruptedHandler, lockedUpFundsHandler, daoSetupErrorHandler, filterWarningHandler,
|
||||
displaySecurityRecommendationHandler, displayLocalhostHandler, wrongOSArchitectureHandler;
|
||||
spvFileCorruptedHandler, lockedUpFundsHandler, daoErrorMessageHandler, daoWarnMessageHandler,
|
||||
filterWarningHandler, displaySecurityRecommendationHandler, displayLocalhostHandler,
|
||||
wrongOSArchitectureHandler;
|
||||
@Setter
|
||||
@Nullable
|
||||
private Consumer<Boolean> displayTorNetworkSettingsHandler;
|
||||
@ -626,8 +627,11 @@ public class BisqSetup {
|
||||
|
||||
if (DevEnv.isDaoActivated()) {
|
||||
daoSetup.onAllServicesInitialized(errorMessage -> {
|
||||
if (daoSetupErrorHandler != null)
|
||||
daoSetupErrorHandler.accept(errorMessage);
|
||||
if (daoErrorMessageHandler != null)
|
||||
daoErrorMessageHandler.accept(errorMessage);
|
||||
}, warningMessage -> {
|
||||
if (daoWarnMessageHandler != null)
|
||||
daoWarnMessageHandler.accept(warningMessage);
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -36,12 +36,11 @@ import bisq.core.dao.node.BsqNodeProvider;
|
||||
import bisq.core.dao.node.explorer.ExportJsonFilesService;
|
||||
import bisq.core.dao.state.DaoStateService;
|
||||
|
||||
import bisq.common.handlers.ErrorMessageHandler;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
/**
|
||||
* High level entry point for Dao domain.
|
||||
@ -94,8 +93,10 @@ public class DaoSetup {
|
||||
daoSetupServices.add(bsqNodeProvider.getBsqNode());
|
||||
}
|
||||
|
||||
public void onAllServicesInitialized(ErrorMessageHandler errorMessageHandler) {
|
||||
public void onAllServicesInitialized(Consumer<String> errorMessageHandler,
|
||||
Consumer<String> warnMessageHandler) {
|
||||
bsqNode.setErrorMessageHandler(errorMessageHandler);
|
||||
bsqNode.setWarnMessageHandler(warnMessageHandler);
|
||||
|
||||
daoSetupServices.forEach(daoSetupServices -> {
|
||||
daoSetupServices.addListeners();
|
||||
|
@ -30,14 +30,13 @@ import bisq.core.dao.state.model.blockchain.Block;
|
||||
import bisq.network.p2p.P2PService;
|
||||
import bisq.network.p2p.P2PServiceListener;
|
||||
|
||||
import bisq.common.handlers.ErrorMessageHandler;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
@ -59,7 +58,9 @@ public abstract class BsqNode implements DaoSetupService {
|
||||
protected boolean parseBlockchainComplete;
|
||||
protected boolean p2pNetworkReady;
|
||||
@Nullable
|
||||
protected ErrorMessageHandler errorMessageHandler;
|
||||
protected Consumer<String> errorMessageHandler;
|
||||
@Nullable
|
||||
protected Consumer<String> warnMessageHandler;
|
||||
protected List<RawBlock> pendingBlocks = new ArrayList<>();
|
||||
|
||||
|
||||
@ -134,10 +135,14 @@ public abstract class BsqNode implements DaoSetupService {
|
||||
// API
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
public void setErrorMessageHandler(@Nullable ErrorMessageHandler errorMessageHandler) {
|
||||
public void setErrorMessageHandler(Consumer<String> errorMessageHandler) {
|
||||
this.errorMessageHandler = errorMessageHandler;
|
||||
}
|
||||
|
||||
public void setWarnMessageHandler(Consumer<String> warnMessageHandler) {
|
||||
this.warnMessageHandler = warnMessageHandler;
|
||||
}
|
||||
|
||||
public abstract void shutDown();
|
||||
|
||||
|
||||
|
@ -241,67 +241,30 @@ public class FullNode extends BsqNode {
|
||||
private void handleError(Throwable throwable) {
|
||||
String errorMessage = "An error occurred: Error=" + throwable.toString();
|
||||
log.error(errorMessage);
|
||||
throwable.printStackTrace();
|
||||
|
||||
if (throwable instanceof RpcException) {
|
||||
Throwable cause = throwable.getCause();
|
||||
if (cause != null) {
|
||||
if (cause instanceof HttpLayerException) {
|
||||
if (((HttpLayerException) cause).getCode() == 1004004)
|
||||
errorMessage = "You have configured Bisq to run as DAO full node but there is not " +
|
||||
if (((HttpLayerException) cause).getCode() == 1004004) {
|
||||
if (warnMessageHandler != null)
|
||||
warnMessageHandler.accept("You have configured Bisq to run as DAO full node but there is not " +
|
||||
"localhost Bitcoin Core node detected. You need to have Bitcoin Core started and synced before " +
|
||||
"starting Bisq. Please restart Bisq with proper DAO full node setup or switch to lite node mode.";
|
||||
"starting Bisq. Please restart Bisq with proper DAO full node setup or switch to lite node mode.");
|
||||
return;
|
||||
}
|
||||
} else if (cause instanceof NotificationHandlerException) {
|
||||
// Maybe we need to react specifically to errors as in NotificationHandlerException.getError()
|
||||
// So far only IO_UNKNOWN was observed
|
||||
log.error("Error type of NotificationHandlerException: " + ((NotificationHandlerException) cause).getError().toString());
|
||||
// TODO need check types for startReOrgFromLastSnapshot?
|
||||
// IO_UNKNOWN requires startReOrgFromLastSnapshot
|
||||
/* switch (((NotificationHandlerException) throwable).getError()) {
|
||||
case ARGS_COUNT_UNEVEN:
|
||||
case ARGS_COUNT_UNEQUAL:
|
||||
case ARGS_VALUE_NEGATIVE:
|
||||
case ARGS_NULL:
|
||||
case ARGS_CONTAIN_NULL:
|
||||
case ARGS_HTTP_METHOD_UNSUPPORTED:
|
||||
case ARGS_HTTP_AUTHSCHEME_UNSUPPORTED:
|
||||
case ARGS_BTCD_BLOCKSTATUS_UNSUPPORTED:
|
||||
case ARGS_BTCD_CHAINSTATUS_UNSUPPORTED:
|
||||
case ARGS_BTCD_CHAINTYPE_UNSUPPORTED:
|
||||
case ARGS_BTCD_CHECKLEVEL_UNSUPPORTED:
|
||||
case ARGS_BTCD_CONNECTIONTYPE_UNSUPPORTED:
|
||||
case ARGS_BTCD_NETWORKTYPE_UNSUPPORTED:
|
||||
case ARGS_BTCD_PAYMENTCATEGORY_UNSUPPORTED:
|
||||
case ARGS_BTCD_PEERCONTROL_UNSUPPORTED:
|
||||
case ARGS_BTCD_SCRIPTTYPE_UNSUPPORTED:
|
||||
case ARGS_BTCD_SIGHASHTYPE_UNSUPPORTED:
|
||||
case ARGS_BTCD_NOTIFICATION_UNSUPPORTED:
|
||||
case ARGS_BTCD_PROVIDER_NULL:
|
||||
case REQUEST_HTTP_FAULT:
|
||||
case RESPONSE_HTTP_CLIENT_FAULT:
|
||||
case RESPONSE_HTTP_SERVER_FAULT:
|
||||
case RESPONSE_JSONRPC_NULL:
|
||||
case RESPONSE_JSONRPC_NULL_ID:
|
||||
case RESPONSE_JSONRPC_UNEQUAL_IDS:
|
||||
case IO_STREAM_UNCLOSED:
|
||||
case IO_SOCKET_UNINITIALIZED:
|
||||
case IO_SERVERSOCKET_UNINITIALIZED:
|
||||
break;
|
||||
case IO_UNKNOWN:
|
||||
startReOrgFromLastSnapshot();
|
||||
break;
|
||||
case IO_COMMUNICATION:
|
||||
case IO_BITCOIND:
|
||||
case PARSE_URI_FAILED:
|
||||
case PARSE_JSON_UNKNOWN:
|
||||
case PARSE_JSON_MALFORMED:
|
||||
case MAP_JSON_UNKNOWN:
|
||||
default:
|
||||
break;
|
||||
}*/
|
||||
|
||||
startReOrgFromLastSnapshot();
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (errorMessageHandler != null)
|
||||
errorMessageHandler.handleErrorMessage(errorMessage);
|
||||
errorMessageHandler.accept(errorMessage);
|
||||
}
|
||||
}
|
||||
|
@ -139,8 +139,8 @@ public class RpcService {
|
||||
nodeConfig.setProperty("node.bitcoind.http.auth_scheme", "Basic");
|
||||
BtcdClientImpl client = new BtcdClientImpl(httpProvider, nodeConfig);
|
||||
daemon = new BtcdDaemonImpl(client, throwable -> {
|
||||
throwable.printStackTrace();
|
||||
log.error(throwable.toString());
|
||||
throwable.printStackTrace();
|
||||
UserThread.execute(() -> errorHandler.accept(new RpcException(throwable)));
|
||||
});
|
||||
log.info("Setup took {} ms", System.currentTimeMillis() - startTs);
|
||||
|
@ -321,7 +321,8 @@ public class MainViewModel implements ViewModel, BisqSetup.BisqSetupCompleteList
|
||||
.onClose(privateNotificationManager::removePrivateNotification)
|
||||
.useIUnderstandButton()
|
||||
.show());
|
||||
bisqSetup.setDaoSetupErrorHandler(errorMessage -> new Popup<>().error(errorMessage).show());
|
||||
bisqSetup.setDaoErrorMessageHandler(errorMessage -> new Popup<>().error(errorMessage).show());
|
||||
bisqSetup.setDaoWarnMessageHandler(warnMessage -> new Popup<>().warning(warnMessage).show());
|
||||
bisqSetup.setDisplaySecurityRecommendationHandler(key ->
|
||||
new Popup<>().headLine(Res.get("popup.securityRecommendation.headline"))
|
||||
.information(Res.get("popup.securityRecommendation.msg"))
|
||||
|
Loading…
Reference in New Issue
Block a user