Merge pull request #7180 from HenrikJannsen/2_further-refactorings-and-improvements

Further refactorings and improvements [B]
This commit is contained in:
Alejandro García 2024-06-28 21:54:35 +00:00 committed by GitHub
commit 9920595399
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
15 changed files with 52 additions and 144 deletions

View File

@ -21,4 +21,9 @@ import bisq.common.handlers.ResultHandler;
public interface GracefulShutDownHandler {
void gracefulShutDown(ResultHandler resultHandler);
default void gracefulShutDown() {
gracefulShutDown(() -> {
});
}
}

View File

@ -33,6 +33,7 @@ import bisq.network.p2p.P2PService;
import bisq.network.p2p.seed.SeedNodeRepository;
import bisq.common.UserThread;
import bisq.common.app.AppModule;
import bisq.common.app.DevEnv;
import bisq.common.config.Config;
import bisq.common.file.JsonFileManager;
@ -73,12 +74,22 @@ public abstract class ExecutableForAppWithP2p extends BisqExecutable {
UserThread.setExecutor(executorService);
}
@Override
protected AppModule getModule() {
return new ModuleForAppWithP2p(config);
}
@Override
protected void startApplication() {
// Pin that as it is used in PaymentMethods and verification in TradeStatistics
tradeLimits = injector.getInstance(TradeLimits.class);
}
@Override
protected void launchApplication() {
onApplicationLaunched();
}
@Override
public void onSetupComplete() {
log.info("onSetupComplete");

View File

@ -95,7 +95,6 @@ import javafx.beans.property.SimpleObjectProperty;
import javafx.collections.ObservableList;
import javafx.collections.transformation.FilteredList;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
@ -731,8 +730,8 @@ public class DaoFacade implements DaoSetupService {
daoStateStorageService.resyncDaoStateFromGenesis(resultHandler);
}
public void removeAndBackupAllDaoData(File storageDir) throws IOException {
daoStateStorageService.removeAndBackupAllDaoData(storageDir);
public void removeAndBackupAllDaoData() throws IOException {
daoStateStorageService.removeAndBackupAllDaoData();
}
public boolean isMyRole(Role role) {

View File

@ -34,11 +34,9 @@ import bisq.common.config.Config;
import bisq.common.util.GcUtil;
import javax.inject.Inject;
import javax.inject.Named;
import com.google.common.annotations.VisibleForTesting;
import java.io.File;
import java.io.IOException;
import java.util.LinkedList;
@ -68,7 +66,6 @@ public class DaoStateSnapshotService implements DaoSetupService, DaoStateListene
private final BsqWalletService bsqWalletService;
private final Preferences preferences;
private final Config config;
private final File storageDir;
private protobuf.DaoState daoStateCandidate;
private LinkedList<DaoStateHash> hashChainCandidate = new LinkedList<>();
@ -95,8 +92,7 @@ public class DaoStateSnapshotService implements DaoSetupService, DaoStateListene
WalletsSetup walletsSetup,
BsqWalletService bsqWalletService,
Preferences preferences,
Config config,
@Named(Config.STORAGE_DIR) File storageDir) {
Config config) {
this.daoStateService = daoStateService;
this.genesisTxInfo = genesisTxInfo;
this.daoStateStorageService = daoStateStorageService;
@ -105,7 +101,6 @@ public class DaoStateSnapshotService implements DaoSetupService, DaoStateListene
this.bsqWalletService = bsqWalletService;
this.preferences = preferences;
this.config = config;
this.storageDir = storageDir;
}
@ -334,7 +329,7 @@ public class DaoStateSnapshotService implements DaoSetupService, DaoStateListene
return;
}
try {
daoStateStorageService.removeAndBackupAllDaoData(storageDir);
daoStateStorageService.removeAndBackupAllDaoData();
// the restart handler informs the user of the need to restart bisq (in desktop mode)
if (resyncDaoStateFromResourcesHandler == null) {
log.error("resyncDaoStateFromResourcesHandler COULD NOT be called as it has not been initialized yet");

View File

@ -351,8 +351,9 @@ public class DaoState implements PersistablePayload {
",\n paramChangeList=" + paramChangeList +
",\n evaluatedProposalList=" + evaluatedProposalList +
",\n decryptedBallotsWithMeritsList=" + decryptedBallotsWithMeritsList +
",\n txCache=" + txCache +
",\n txOutputsByTxOutputType=" + txOutputsByTxOutputType +
/* ",\n txCache=" + txCache +
",\n blocksByHeight=" + blocksByHeight +
",\n txOutputsByTxOutputType=" + txOutputsByTxOutputType +*/
"\n}";
}
}

View File

@ -204,7 +204,7 @@ public class DaoStateStorageService extends StoreService<DaoStateStore> {
bsqBlocksStorageService.removeBlocksInDirectory();
}
public void removeAndBackupAllDaoData(File storageDir) throws IOException {
public void removeAndBackupAllDaoData() throws IOException {
// We delete all DAO consensus data and remove the daoState so it will rebuild from latest
// resource files.
String backupDirName = "out_of_sync_dao_data";

View File

@ -41,7 +41,6 @@ public class DaoStateSnapshotServiceTest {
null,
null,
null,
null,
null);
}

View File

@ -65,8 +65,6 @@ import javafx.collections.transformation.SortedList;
import javafx.util.Callback;
import java.io.File;
import java.util.Comparator;
import java.util.HashSet;
import java.util.Map;
@ -83,7 +81,6 @@ public abstract class StateMonitorView<StH extends StateHash,
protected final CycleService cycleService;
protected final PeriodService periodService;
protected final Set<NodeAddress> seedNodeAddresses;
private final File storageDir;
protected TextField statusTextField;
protected Button resyncFromResourcesButton;
@ -110,14 +107,12 @@ public abstract class StateMonitorView<StH extends StateHash,
DaoFacade daoFacade,
CycleService cycleService,
PeriodService periodService,
SeedNodeRepository seedNodeRepository,
File storageDir) {
SeedNodeRepository seedNodeRepository) {
this.daoStateService = daoStateService;
this.daoFacade = daoFacade;
this.cycleService = cycleService;
this.periodService = periodService;
this.seedNodeAddresses = new HashSet<>(seedNodeRepository.getSeedNodeAddresses());
this.storageDir = storageDir;
}
@Override
@ -286,7 +281,7 @@ public abstract class StateMonitorView<StH extends StateHash,
private void resyncFromResources() {
try {
daoFacade.removeAndBackupAllDaoData(storageDir);
daoFacade.removeAndBackupAllDaoData();
new Popup().attention(Res.get("setting.preferences.dao.resyncFromResources.popup"))
.useShutDownButton()
.hideCloseButton()

View File

@ -33,10 +33,7 @@ import bisq.core.locale.Res;
import bisq.network.p2p.seed.SeedNodeRepository;
import bisq.common.config.Config;
import javax.inject.Inject;
import javax.inject.Named;
import javafx.scene.control.TableCell;
import javafx.scene.control.TableColumn;
@ -45,8 +42,6 @@ import javafx.beans.property.ReadOnlyObjectWrapper;
import javafx.util.Callback;
import java.io.File;
import java.util.Comparator;
import java.util.Map;
import java.util.stream.Collectors;
@ -68,9 +63,8 @@ public class BlindVoteStateMonitorView extends StateMonitorView<BlindVoteStateHa
BlindVoteStateMonitoringService blindVoteStateMonitoringService,
CycleService cycleService,
PeriodService periodService,
SeedNodeRepository seedNodeRepository,
@Named(Config.STORAGE_DIR) File storageDir) {
super(daoStateService, daoFacade, cycleService, periodService, seedNodeRepository, storageDir);
SeedNodeRepository seedNodeRepository) {
super(daoStateService, daoFacade, cycleService, periodService, seedNodeRepository);
this.blindVoteStateMonitoringService = blindVoteStateMonitoringService;
}

View File

@ -35,11 +35,9 @@ import bisq.core.locale.Res;
import bisq.network.p2p.seed.SeedNodeRepository;
import bisq.common.config.Config;
import bisq.common.util.Utilities;
import javax.inject.Inject;
import javax.inject.Named;
import javafx.scene.control.TableCell;
import javafx.scene.control.TableColumn;
@ -50,8 +48,6 @@ import javafx.collections.ListChangeListener;
import javafx.util.Callback;
import java.io.File;
import java.util.Comparator;
import java.util.Map;
import java.util.function.IntSupplier;
@ -75,9 +71,8 @@ public class DaoStateMonitorView extends StateMonitorView<DaoStateHash, DaoState
DaoStateMonitoringService daoStateMonitoringService,
CycleService cycleService,
PeriodService periodService,
SeedNodeRepository seedNodeRepository,
@Named(Config.STORAGE_DIR) File storageDir) {
super(daoStateService, daoFacade, cycleService, periodService, seedNodeRepository, storageDir);
SeedNodeRepository seedNodeRepository) {
super(daoStateService, daoFacade, cycleService, periodService, seedNodeRepository);
this.daoStateMonitoringService = daoStateMonitoringService;
}

View File

@ -33,10 +33,7 @@ import bisq.core.locale.Res;
import bisq.network.p2p.seed.SeedNodeRepository;
import bisq.common.config.Config;
import javax.inject.Inject;
import javax.inject.Named;
import javafx.scene.control.TableCell;
import javafx.scene.control.TableColumn;
@ -45,8 +42,6 @@ import javafx.beans.property.ReadOnlyObjectWrapper;
import javafx.util.Callback;
import java.io.File;
import java.util.Comparator;
import java.util.Map;
import java.util.stream.Collectors;
@ -67,9 +62,8 @@ public class ProposalStateMonitorView extends StateMonitorView<ProposalStateHash
ProposalStateMonitoringService proposalStateMonitoringService,
CycleService cycleService,
PeriodService periodService,
SeedNodeRepository seedNodeRepository,
@Named(Config.STORAGE_DIR) File storageDir) {
super(daoStateService, daoFacade, cycleService, periodService, seedNodeRepository, storageDir);
SeedNodeRepository seedNodeRepository) {
super(daoStateService, daoFacade, cycleService, periodService, seedNodeRepository);
this.proposalStateMonitoringService = proposalStateMonitoringService;
}

View File

@ -107,8 +107,6 @@ import javafx.util.Callback;
import javafx.util.Duration;
import javafx.util.StringConverter;
import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
@ -151,7 +149,6 @@ public class PreferencesView extends ActivatableViewAndModel<GridPane, Preferenc
private final FilterManager filterManager;
private final DaoFacade daoFacade;
private final boolean isBmFullNodeFromOptions;
private final File storageDir;
private ListView<FiatCurrency> fiatCurrenciesListView;
private ComboBox<FiatCurrency> fiatCurrenciesComboBox;
@ -198,8 +195,7 @@ public class PreferencesView extends ActivatableViewAndModel<GridPane, Preferenc
@Named(Config.IS_BM_FULL_NODE) boolean isBmFullNodeFromOptions,
@Named(Config.RPC_USER) String rpcUser,
@Named(Config.RPC_PASSWORD) String rpcPassword,
@Named(Config.RPC_BLOCK_NOTIFICATION_PORT) int rpcBlockNotificationPort,
@Named(Config.STORAGE_DIR) File storageDir) {
@Named(Config.RPC_BLOCK_NOTIFICATION_PORT) int rpcBlockNotificationPort) {
super(model);
this.user = user;
this.burningManAccountingService = burningManAccountingService;
@ -211,7 +207,6 @@ public class PreferencesView extends ActivatableViewAndModel<GridPane, Preferenc
this.filterManager = filterManager;
this.daoFacade = daoFacade;
this.isBmFullNodeFromOptions = isBmFullNodeFromOptions;
this.storageDir = storageDir;
daoFullModeFromOptionsSet = config.fullDaoNodeOptionSetExplicitly &&
rpcUser != null && !rpcUser.isEmpty() &&
rpcPassword != null && !rpcPassword.isEmpty() &&
@ -1225,7 +1220,7 @@ public class PreferencesView extends ActivatableViewAndModel<GridPane, Preferenc
resyncDaoFromResourcesButton.setOnAction(e -> {
try {
daoFacade.removeAndBackupAllDaoData(storageDir);
daoFacade.removeAndBackupAllDaoData();
new Popup().attention(Res.get("setting.preferences.dao.resyncFromResources.popup"))
.useShutDownButton()
.hideCloseButton()

View File

@ -22,7 +22,6 @@ import bisq.core.account.witness.AccountAgeWitnessService;
import bisq.core.app.TorSetup;
import bisq.core.app.misc.AppSetupWithP2PAndDAO;
import bisq.core.app.misc.ExecutableForAppWithP2p;
import bisq.core.app.misc.ModuleForAppWithP2p;
import bisq.core.dao.SignVerifyService;
import bisq.core.dao.governance.bond.reputation.BondedReputationRepository;
import bisq.core.dao.governance.bond.role.BondedRolesRepository;
@ -39,7 +38,6 @@ import bisq.network.p2p.peers.PeerManager;
import bisq.common.Timer;
import bisq.common.UserThread;
import bisq.common.app.AppModule;
import bisq.common.app.Version;
import bisq.common.config.BaseCurrencyNetwork;
import bisq.common.config.Config;
@ -83,27 +81,11 @@ public class RestApi extends ExecutableForAppWithP2p {
checkMemory(config, this);
}
@Override
protected void launchApplication() {
UserThread.execute(() -> {
try {
onApplicationLaunched();
} catch (Exception e) {
e.printStackTrace();
}
});
}
///////////////////////////////////////////////////////////////////////////////////////////
// We continue with a series of synchronous execution tasks
///////////////////////////////////////////////////////////////////////////////////////////
@Override
protected AppModule getModule() {
return new ModuleForAppWithP2p(config);
}
@Override
protected void applyInjector() {
super.applyInjector();
@ -206,11 +188,6 @@ public class RestApi extends ExecutableForAppWithP2p {
}
public void gracefulShutDown() {
gracefulShutDown(() -> {
});
}
@Override
public void gracefulShutDown(ResultHandler resultHandler) {
super.gracefulShutDown(resultHandler);

View File

@ -19,7 +19,6 @@ package bisq.seednode;
import bisq.core.app.TorSetup;
import bisq.core.app.misc.ExecutableForAppWithP2p;
import bisq.core.app.misc.ModuleForAppWithP2p;
import bisq.core.dao.state.DaoStateSnapshotService;
import bisq.core.user.CookieKey;
import bisq.core.user.User;
@ -32,9 +31,9 @@ import bisq.network.p2p.seed.SeedNodeRepository;
import bisq.common.Timer;
import bisq.common.UserThread;
import bisq.common.app.AppModule;
import bisq.common.app.Capabilities;
import bisq.common.app.Capability;
import bisq.common.app.Version;
import bisq.common.config.BaseCurrencyNetwork;
import bisq.common.config.Config;
import bisq.common.handlers.ResultHandler;
@ -50,17 +49,18 @@ import lombok.extern.slf4j.Slf4j;
@Slf4j
public class SeedNodeMain extends ExecutableForAppWithP2p {
private static final long CHECK_CONNECTION_LOSS_SEC = 30;
private static final String VERSION = "1.9.17";
private SeedNode seedNode;
public static void main(String[] args) {
new SeedNodeMain().execute(args);
}
private final SeedNode seedNode;
private Timer checkConnectionLossTime;
public SeedNodeMain() {
super("Bisq Seednode", "bisq-seednode", "bisq_seednode", VERSION);
}
super("Bisq Seednode", "bisq-seednode", "bisq_seednode", Version.VERSION);
public static void main(String[] args) {
System.out.println("SeedNode.VERSION: " + VERSION);
new SeedNodeMain().execute(args);
seedNode = new SeedNode();
}
@Override
@ -68,7 +68,6 @@ public class SeedNodeMain extends ExecutableForAppWithP2p {
super.doExecute();
checkMemory(config, this);
keepRunning();
}
@ -77,23 +76,6 @@ public class SeedNodeMain extends ExecutableForAppWithP2p {
Capabilities.app.addAll(Capability.SEED_NODE);
}
@Override
protected void launchApplication() {
UserThread.execute(() -> {
try {
seedNode = new SeedNode();
onApplicationLaunched();
} catch (Exception e) {
e.printStackTrace();
}
});
}
@Override
protected void onApplicationLaunched() {
super.onApplicationLaunched();
}
///////////////////////////////////////////////////////////////////////////////////////////
// UncaughtExceptionHandler implementation
@ -112,11 +94,6 @@ public class SeedNodeMain extends ExecutableForAppWithP2p {
// We continue with a series of synchronous execution tasks
///////////////////////////////////////////////////////////////////////////////////////////
@Override
protected AppModule getModule() {
return new ModuleForAppWithP2p(config);
}
@Override
protected void applyInjector() {
super.applyInjector();
@ -237,11 +214,6 @@ public class SeedNodeMain extends ExecutableForAppWithP2p {
}
private void gracefulShutDown() {
gracefulShutDown(() -> {
});
}
@Override
public void gracefulShutDown(ResultHandler resultHandler) {
seedNode.shutDown();

View File

@ -18,63 +18,39 @@
package bisq.statistics;
import bisq.core.app.misc.ExecutableForAppWithP2p;
import bisq.core.app.misc.ModuleForAppWithP2p;
import bisq.common.UserThread;
import bisq.common.app.AppModule;
import bisq.common.app.Version;
import lombok.extern.slf4j.Slf4j;
@Slf4j
public class StatisticsMain extends ExecutableForAppWithP2p {
private static final String VERSION = "1.0.1";
private Statistics statistics;
public StatisticsMain() {
super("Bisq Statsnode", "bisq-statistics", "bisq_statistics", VERSION);
}
public static void main(String[] args) {
log.info("Statistics.VERSION: " + VERSION);
new StatisticsMain().execute(args);
}
private final Statistics statistics;
public StatisticsMain() {
super("Bisq Statsnode", "bisq-statistics", "bisq_statistics", Version.VERSION);
statistics = new Statistics();
}
@Override
protected void doExecute() {
super.doExecute();
checkMemory(config, this);
keepRunning();
}
@Override
protected void launchApplication() {
UserThread.execute(() -> {
try {
statistics = new Statistics();
UserThread.execute(this::onApplicationLaunched);
} catch (Exception e) {
e.printStackTrace();
}
});
}
@Override
protected void onApplicationLaunched() {
super.onApplicationLaunched();
}
///////////////////////////////////////////////////////////////////////////////////////////
// We continue with a series of synchronous execution tasks
///////////////////////////////////////////////////////////////////////////////////////////
@Override
protected AppModule getModule() {
return new ModuleForAppWithP2p(config);
}
@Override
protected void applyInjector() {
super.applyInjector();