Refactoring: renaming

This commit is contained in:
HenrikJannsen 2024-06-20 17:35:47 +07:00
parent 87ea800f66
commit b3580c05f7
No known key found for this signature in database
GPG key ID: 02AA2BAE387C8307
18 changed files with 55 additions and 56 deletions

View file

@ -99,7 +99,7 @@ public class BisqHeadlessApp implements HeadlessApp {
bisqSetup.setQubesOSInfoHandler(() -> log.info("setQubesOSInfoHandler"));
bisqSetup.setDownGradePreventionHandler(lastVersion -> log.info("Downgrade from version {} to version {} is not supported",
lastVersion, Version.VERSION));
bisqSetup.setDaoRequiresRestartHandler(() -> {
bisqSetup.setResyncDaoStateFromResourcesHandler(() -> {
log.info("There was a problem with synchronizing the DAO state. " +
"A restart of the application is required to fix the issue.");
gracefulShutDownHandler.gracefulShutDown(() -> {

View file

@ -44,7 +44,6 @@ import bisq.core.support.dispute.mediation.MediationManager;
import bisq.core.support.dispute.refund.RefundManager;
import bisq.core.trade.TradeManager;
import bisq.core.trade.bisq_v1.TradeTxException;
import bisq.core.user.BlockChainExplorer;
import bisq.core.user.Preferences;
import bisq.core.user.User;
import bisq.core.util.FormattingUtils;
@ -201,7 +200,7 @@ public class BisqSetup {
private Runnable qubesOSInfoHandler;
@Setter
@Nullable
private Runnable daoRequiresRestartHandler;
private Runnable resyncDaoStateFromResourcesHandler;
@Setter
@Nullable
private Runnable torAddressUpgradeHandler;
@ -493,7 +492,7 @@ public class BisqSetup {
voteResultExceptionHandler,
revolutAccountsUpdateHandler,
amazonGiftCardAccountsUpdateHandler,
daoRequiresRestartHandler);
resyncDaoStateFromResourcesHandler);
if (walletsSetup.downloadPercentageProperty().get() == 1) {
checkForLockedUpFunds();

View file

@ -209,7 +209,7 @@ public class DomainInitialisation {
Consumer<VoteResultException> voteResultExceptionHandler,
Consumer<List<RevolutAccount>> revolutAccountsUpdateHandler,
Consumer<List<AmazonGiftCardAccount>> amazonGiftCardAccountsUpdateHandler,
Runnable daoRequiresRestartHandler) {
Runnable resyncDaoStateFromResourcesHandler) {
clockWatcher.start();
PersistenceManager.onAllServicesInitialized();
@ -256,7 +256,7 @@ public class DomainInitialisation {
daoWarnMessageHandler.accept(warningMessage);
});
daoStateSnapshotService.setDaoRequiresRestartHandler(daoRequiresRestartHandler);
daoStateSnapshotService.setResyncDaoStateFromResourcesHandler(resyncDaoStateFromResourcesHandler);
tradeStatisticsManager.onAllServicesInitialized();

View file

@ -731,8 +731,8 @@ public class DaoFacade implements DaoSetupService {
daoStateStorageService.resyncDaoStateFromGenesis(resultHandler);
}
public void resyncDaoStateFromResources(File storageDir) throws IOException {
daoStateStorageService.resyncDaoStateFromResources(storageDir);
public void removeAndBackupAllDaoData(File storageDir) throws IOException {
daoStateStorageService.removeAndBackupAllDaoData(storageDir);
}
public boolean isMyRole(Role role) {

View file

@ -93,7 +93,7 @@ public class DaoStateMonitoringService implements DaoSetupService, DaoStateListe
default void onDaoStateHashesChanged() {
}
default void onCheckpointFail() {
default void onCheckpointFailed() {
}
default void onDaoStateBlockCreated() {
@ -480,7 +480,7 @@ public class DaoStateMonitoringService implements DaoSetupService, DaoStateListe
removeFile("ProposalStore");
removeFile("TempProposalStore");
listeners.forEach(Listener::onCheckpointFail);
listeners.forEach(Listener::onCheckpointFailed);
log.error("Failed checkpoint {}", checkpoint.toString());
} catch (Throwable t) {
t.printStackTrace();

View file

@ -74,10 +74,10 @@ public class DaoStateSnapshotService implements DaoSetupService, DaoStateListene
private LinkedList<DaoStateHash> hashChainCandidate = new LinkedList<>();
private List<Block> blocksCandidate;
private int snapshotHeight;
private int chainHeightOfLastApplySnapshot;
private int chainHeightOfLastAppliedSnapshot;
@Setter
@Nullable
private Runnable daoRequiresRestartHandler;
private Runnable resyncDaoStateFromResourcesHandler;
private int daoRequiresRestartHandlerAttempts = 0;
private boolean readyForPersisting = true;
private boolean isParseBlockChainComplete;
@ -215,7 +215,7 @@ public class DaoStateSnapshotService implements DaoSetupService, DaoStateListene
snapshotHeight != chainHeight;
if (isSnapshotHeight(chainHeight) &&
!daoStateService.getBlocks().isEmpty() &&
isValidHeight(daoStateService.getBlockHeightOfLastBlock()) &&
isHeightAtLeastGenesisHeight(daoStateService.getBlockHeightOfLastBlock()) &&
noSnapshotCandidateOrDifferentHeight) {
// We protect to get called while we are not completed with persisting the daoState. This can take about
@ -287,9 +287,9 @@ public class DaoStateSnapshotService implements DaoSetupService, DaoStateListene
resyncDaoStateFromResources();
return;
}
if (isValidHeight(heightOfLastBlock)) {
if (chainHeightOfLastApplySnapshot != chainHeightOfPersisted) {
chainHeightOfLastApplySnapshot = chainHeightOfPersisted;
if (isHeightAtLeastGenesisHeight(heightOfLastBlock)) {
if (chainHeightOfLastAppliedSnapshot != chainHeightOfPersisted) {
chainHeightOfLastAppliedSnapshot = chainHeightOfPersisted;
daoStateService.applySnapshot(persistedBsqState);
daoStateMonitoringService.applySnapshot(persistedDaoStateHashChain);
daoStateStorageService.releaseMemory();
@ -299,7 +299,7 @@ public class DaoStateSnapshotService implements DaoSetupService, DaoStateListene
log.warn("We applied already a snapshot with chainHeight {}. " +
"We remove all dao store files and shutdown. After a restart resource files will " +
"be applied if available.",
chainHeightOfLastApplySnapshot);
chainHeightOfLastAppliedSnapshot);
resyncDaoStateFromResources();
}
}
@ -322,28 +322,28 @@ public class DaoStateSnapshotService implements DaoSetupService, DaoStateListene
// Private
///////////////////////////////////////////////////////////////////////////////////////////
private boolean isValidHeight(int heightOfLastBlock) {
private boolean isHeightAtLeastGenesisHeight(int heightOfLastBlock) {
return heightOfLastBlock >= genesisTxInfo.getGenesisBlockHeight();
}
private void resyncDaoStateFromResources() {
log.info("resyncDaoStateFromResources called");
if (daoRequiresRestartHandler == null && ++daoRequiresRestartHandlerAttempts <= 3) {
log.warn("daoRequiresRestartHandler has not been initialized yet, will try again in 10 seconds");
log.info("removeAndBackupAllDaoData called");
if (resyncDaoStateFromResourcesHandler == null && ++daoRequiresRestartHandlerAttempts <= 3) {
log.warn("resyncDaoStateFromResourcesHandler has not been initialized yet, will try again in 10 seconds");
UserThread.runAfter(this::resyncDaoStateFromResources, 10); // a delay for the app to init
return;
}
try {
daoStateStorageService.resyncDaoStateFromResources(storageDir);
daoStateStorageService.removeAndBackupAllDaoData(storageDir);
// the restart handler informs the user of the need to restart bisq (in desktop mode)
if (daoRequiresRestartHandler == null) {
log.error("daoRequiresRestartHandler COULD NOT be called as it has not been initialized yet");
if (resyncDaoStateFromResourcesHandler == null) {
log.error("resyncDaoStateFromResourcesHandler COULD NOT be called as it has not been initialized yet");
} else {
log.info("calling daoRequiresRestartHandler...");
daoRequiresRestartHandler.run();
log.info("calling resyncDaoStateFromResourcesHandler...");
resyncDaoStateFromResourcesHandler.run();
}
} catch (IOException e) {
log.error("Error at resyncDaoStateFromResources: {}", e.toString());
log.error("Error at removeAndBackupAllDaoData: {}", e.toString());
}
}

View file

@ -28,8 +28,8 @@ import bisq.common.UserThread;
import bisq.common.config.Config;
import bisq.common.file.FileUtil;
import bisq.common.persistence.PersistenceManager;
import bisq.common.util.SingleThreadExecutorUtils;
import bisq.common.util.GcUtil;
import bisq.common.util.SingleThreadExecutorUtils;
import javax.inject.Inject;
import javax.inject.Named;
@ -114,7 +114,7 @@ public class DaoStateStorageService extends StoreService<DaoStateStore> {
// After we have written to disk we remove the daoStateAsProto in the store to avoid that it stays in
// memory there until the next persist call.
log.info("Persist daoState took {} ms", System.currentTimeMillis() - ts);
store.releaseMemory();
store.clear();
GcUtil.maybeReleaseMemory();
UserThread.execute(completeHandler);
});
@ -182,7 +182,7 @@ public class DaoStateStorageService extends StoreService<DaoStateStore> {
public void releaseMemory() {
blocks.clear();
store.releaseMemory();
store.clear();
GcUtil.maybeReleaseMemory();
}
@ -200,7 +200,7 @@ public class DaoStateStorageService extends StoreService<DaoStateStore> {
bsqBlocksStorageService.removeBlocksInDirectory();
}
public void resyncDaoStateFromResources(File storageDir) throws IOException {
public void removeAndBackupAllDaoData(File storageDir) 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

@ -77,7 +77,7 @@ public class DaoStateStore implements PersistableEnvelope {
return new DaoStateStore(proto.getDaoState(), daoStateHashList);
}
public void releaseMemory() {
public void clear() {
daoStateAsProto = null;
daoStateHashChain = null;
}

View file

@ -137,8 +137,8 @@ public class BisqAppMain extends BisqExecutable {
@Override
protected void startApplication() {
Cookie cookie = injector.getInstance(User.class).getCookie();
cookie.getAsOptionalBoolean(CookieKey.CLEAN_TOR_DIR_AT_RESTART).ifPresent(wasCleanTorDirSet -> {
if (wasCleanTorDirSet) {
cookie.getAsOptionalBoolean(CookieKey.CLEAN_TOR_DIR_AT_RESTART).ifPresent(cleanTorDirAtRestart -> {
if (cleanTorDirAtRestart) {
injector.getInstance(TorSetup.class).cleanupTorFiles(() -> {
log.info("Tor directory reset");
cookie.remove(CookieKey.CLEAN_TOR_DIR_AT_RESTART);

View file

@ -434,7 +434,7 @@ public class MainView extends InitializableView<StackPane, MainViewModel>
}
@Override
public void onCheckpointFail() {
public void onCheckpointFailed() {
new Popup().attention(Res.get("dao.monitor.daoState.checkpoint.popup"))
.useShutDownButton()
.show();

View file

@ -501,7 +501,7 @@ public class MainViewModel implements ViewModel, BisqSetup.BisqSetupListener {
.show();
});
bisqSetup.setDaoRequiresRestartHandler(() -> new Popup().warning(Res.get("popup.warn.daoRequiresRestart"))
bisqSetup.setResyncDaoStateFromResourcesHandler(() -> new Popup().warning(Res.get("popup.warn.daoRequiresRestart"))
.useShutDownButton()
.hideCloseButton()
.show());

View file

@ -86,7 +86,7 @@ public abstract class StateMonitorView<StH extends StateHash,
private final File storageDir;
protected TextField statusTextField;
protected Button resyncButton;
protected Button resyncFromResourcesButton;
protected TableView<BLI> tableView;
protected TableView<CLI> conflictTableView;
@ -135,12 +135,12 @@ public abstract class StateMonitorView<StH extends StateHash,
daoStateService.addDaoStateListener(this);
resyncButton.visibleProperty().bind(isInConflictWithSeedNode
resyncFromResourcesButton.visibleProperty().bind(isInConflictWithSeedNode
.or(isDaoStateBlockChainNotConnecting));
resyncButton.managedProperty().bind(isInConflictWithSeedNode
resyncFromResourcesButton.managedProperty().bind(isInConflictWithSeedNode
.or(isDaoStateBlockChainNotConnecting));
resyncButton.setOnAction(ev -> resyncDaoState());
resyncFromResourcesButton.setOnAction(ev -> resyncFromResources());
if (daoStateService.isParseBlockChainComplete()) {
onDataUpdate();
@ -159,10 +159,10 @@ public abstract class StateMonitorView<StH extends StateHash,
daoStateService.removeDaoStateListener(this);
resyncButton.visibleProperty().unbind();
resyncButton.managedProperty().unbind();
resyncFromResourcesButton.visibleProperty().unbind();
resyncFromResourcesButton.managedProperty().unbind();
resyncButton.setOnAction(null);
resyncFromResourcesButton.setOnAction(null);
}
@ -284,9 +284,9 @@ public abstract class StateMonitorView<StH extends StateHash,
GUIUtil.setFitToRowsForTableView(tableView, 25, 28, 2, 5);
}
private void resyncDaoState() {
private void resyncFromResources() {
try {
daoFacade.resyncDaoStateFromResources(storageDir);
daoFacade.removeAndBackupAllDaoData(storageDir);
new Popup().attention(Res.get("setting.preferences.dao.resyncFromResources.popup"))
.useShutDownButton()
.hideCloseButton()

View file

@ -81,7 +81,7 @@ public class BlindVoteStateMonitorView extends StateMonitorView<BlindVoteStateHa
statusTextField = FormBuilder.addTopLabelTextField(root, ++gridRow,
Res.get("dao.monitor.state")).second;
resyncButton = FormBuilder.addButton(root, ++gridRow, Res.get("dao.monitor.resync"), 10);
resyncFromResourcesButton = FormBuilder.addButton(root, ++gridRow, Res.get("dao.monitor.resync"), 10);
super.initialize();
}

View file

@ -90,7 +90,7 @@ public class DaoStateMonitorView extends StateMonitorView<DaoStateHash, DaoState
statusTextField = FormBuilder.addTopLabelTextField(root, ++gridRow,
Res.get("dao.monitor.state")).second;
resyncButton = FormBuilder.addButton(root, ++gridRow, Res.get("dao.monitor.resync"), 10);
resyncFromResourcesButton = FormBuilder.addButton(root, ++gridRow, Res.get("dao.monitor.resync"), 10);
super.initialize();
}
@ -126,7 +126,7 @@ public class DaoStateMonitorView extends StateMonitorView<DaoStateHash, DaoState
}
@Override
public void onCheckpointFail() {
public void onCheckpointFailed() {
}
///////////////////////////////////////////////////////////////////////////////////////////

View file

@ -80,7 +80,7 @@ public class ProposalStateMonitorView extends StateMonitorView<ProposalStateHash
statusTextField = FormBuilder.addTopLabelTextField(root, ++gridRow,
Res.get("dao.monitor.state")).second;
resyncButton = FormBuilder.addButton(root, ++gridRow, Res.get("dao.monitor.resync"), 10);
resyncFromResourcesButton = FormBuilder.addButton(root, ++gridRow, Res.get("dao.monitor.resync"), 10);
super.initialize();
}

View file

@ -1225,7 +1225,7 @@ public class PreferencesView extends ActivatableViewAndModel<GridPane, Preferenc
resyncDaoFromResourcesButton.setOnAction(e -> {
try {
daoFacade.resyncDaoStateFromResources(storageDir);
daoFacade.removeAndBackupAllDaoData(storageDir);
new Popup().attention(Res.get("setting.preferences.dao.resyncFromResources.popup"))
.useShutDownButton()
.hideCloseButton()

View file

@ -108,7 +108,7 @@ public class RestApi extends ExecutableForAppWithP2p {
protected void applyInjector() {
super.applyInjector();
injector.getInstance(DaoStateSnapshotService.class).setDaoRequiresRestartHandler(this::gracefulShutDown);
injector.getInstance(DaoStateSnapshotService.class).setResyncDaoStateFromResourcesHandler(this::gracefulShutDown);
}
@Override
@ -116,8 +116,8 @@ public class RestApi extends ExecutableForAppWithP2p {
super.startApplication();
Cookie cookie = injector.getInstance(User.class).getCookie();
cookie.getAsOptionalBoolean(CookieKey.CLEAN_TOR_DIR_AT_RESTART).ifPresent(wasCleanTorDirSet -> {
if (wasCleanTorDirSet) {
cookie.getAsOptionalBoolean(CookieKey.CLEAN_TOR_DIR_AT_RESTART).ifPresent(cleanTorDirAtRestart -> {
if (cleanTorDirAtRestart) {
injector.getInstance(TorSetup.class).cleanupTorFiles(() -> {
log.info("Tor directory reset");
cookie.remove(CookieKey.CLEAN_TOR_DIR_AT_RESTART);

View file

@ -123,7 +123,7 @@ public class SeedNodeMain extends ExecutableForAppWithP2p {
seedNode.setInjector(injector);
injector.getInstance(DaoStateSnapshotService.class).setDaoRequiresRestartHandler(
injector.getInstance(DaoStateSnapshotService.class).setResyncDaoStateFromResourcesHandler(
// We shut down with a deterministic delay per seed to avoid that all seeds shut down at the
// same time in case of a reorg. We use 30 sec. as distance delay between the seeds to be on the
// safe side. We have 12 seeds so that's 6 minutes.
@ -149,8 +149,8 @@ public class SeedNodeMain extends ExecutableForAppWithP2p {
super.startApplication();
/* Cookie cookie = injector.getInstance(User.class).getCookie();
cookie.getAsOptionalBoolean(CookieKey.CLEAN_TOR_DIR_AT_RESTART).ifPresent(wasCleanTorDirSet -> {
if (wasCleanTorDirSet) {
cookie.getAsOptionalBoolean(CookieKey.CLEAN_TOR_DIR_AT_RESTART).ifPresent(cleanTorDirAtRestart -> {
if (cleanTorDirAtRestart) {
injector.getInstance(TorSetup.class).cleanupTorFiles(() -> {
log.info("Tor directory reset");
cookie.remove(CookieKey.CLEAN_TOR_DIR_AT_RESTART);