Improve logs. Minor cleanups

Signed-off-by: HenrikJannsen <boilingfrog@gmx.com>
This commit is contained in:
HenrikJannsen 2024-06-20 18:32:07 +07:00
parent b3580c05f7
commit d12b6608c7
No known key found for this signature in database
GPG Key ID: 02AA2BAE387C8307
10 changed files with 52 additions and 44 deletions

View File

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

View File

@ -51,11 +51,11 @@ public class TorSetup {
File hiddenservice = new File(Paths.get(torDir.getAbsolutePath(), "hiddenservice").toString());
try {
FileUtil.deleteDirectory(torDir, hiddenservice, true);
log.info("All Tor files except hiddenservice directory got deleted");
if (resultHandler != null)
resultHandler.run();
} catch (IOException e) {
e.printStackTrace();
log.error(e.toString());
log.error("cleanupTorFiles failed", e);
if (errorMessageHandler != null)
errorMessageHandler.handleErrorMessage(e.toString());
}

View File

@ -39,8 +39,8 @@ import bisq.common.file.JsonFileManager;
import bisq.common.handlers.ResultHandler;
import bisq.common.persistence.PersistenceManager;
import bisq.common.setup.GracefulShutDownHandler;
import bisq.common.util.SingleThreadExecutorUtils;
import bisq.common.util.Profiler;
import bisq.common.util.SingleThreadExecutorUtils;
import java.time.Instant;
import java.time.ZoneId;
@ -229,7 +229,7 @@ public abstract class ExecutableForAppWithP2p extends BisqExecutable {
log.warn("\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n" +
"We are over our memory limit ({}) and trigger a shutdown. usedMemory: {} MB. freeMemory: {} MB" +
"\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n",
(int) maxMemory, usedMemory, Profiler.getFreeMemoryInMB());
maxMemory, usedMemory, Profiler.getFreeMemoryInMB());
shutDown(gracefulShutDownHandler);
}
}, 5);

View File

@ -42,6 +42,7 @@ import bisq.common.UserThread;
import bisq.common.config.Config;
import bisq.common.crypto.Hash;
import bisq.common.file.FileUtil;
import bisq.common.util.Hex;
import bisq.common.util.Utilities;
import javax.inject.Inject;
@ -120,6 +121,7 @@ public class DaoStateMonitoringService implements DaoSetupService, DaoStateListe
@Getter
private final ObservableList<UtxoMismatch> utxoMismatches = FXCollections.observableArrayList();
// TODO add recent checkpoint
private final List<Checkpoint> checkpoints = Arrays.asList(
new Checkpoint(586920, Utilities.decodeFromHex("523aaad4e760f6ac6196fec1b3ec9a2f42e5b272"))
);
@ -454,8 +456,8 @@ public class DaoStateMonitoringService implements DaoSetupService, DaoStateListe
// confiscated funds are still in the utxo set
long sumUtxo = daoStateService.getUnspentTxOutputMap().values().stream().mapToLong(BaseTxOutput::getValue).sum();
long sumBsq = genesisTotalSupply + compensationIssuance + reimbursementIssuance - totalAmountOfBurntBsq;
if (sumBsq != sumUtxo) {
log.error("BSQ Utxos are not matching. sumBsq={}; sumUtxo={}", sumBsq, sumUtxo);
utxoMismatches.add(new UtxoMismatch(block.getHeight(), sumUtxo, sumBsq));
}
}
@ -467,12 +469,17 @@ public class DaoStateMonitoringService implements DaoSetupService, DaoStateListe
.findAny()
.ifPresent(daoStateHash -> {
if (Arrays.equals(daoStateHash.getHash(), checkpoint.getHash())) {
log.info("Passed checkpoint {}", checkpoint.toString());
log.info("Passed checkpoint {}", checkpoint);
} else {
if (checkpointFailed) {
return;
}
checkpointFailed = true;
log.warn("verifyCheckpoints failed. We resunc from resources " +
"daoStateHash.getHash()={}, checkpoint.getHash()={}, checkpoint {}",
Hex.encode(daoStateHash.getHash()),
Hex.encode(checkpoint.getHash()),
checkpoint);
try {
// Delete state and stop
removeFile("DaoStateStore");
@ -481,10 +488,8 @@ public class DaoStateMonitoringService implements DaoSetupService, DaoStateListe
removeFile("TempProposalStore");
listeners.forEach(Listener::onCheckpointFailed);
log.error("Failed checkpoint {}", checkpoint.toString());
} catch (Throwable t) {
t.printStackTrace();
log.error(t.toString());
log.error("removeAndBackupAllDaoData failed", t);
}
}
}));

View File

@ -164,7 +164,8 @@ public class FullNode extends BsqNode {
chainTipHeight = blockHeight;
doParseBlock(rawBlock).ifPresent(this::onNewBlock);
} catch (RequiredReorgFromSnapshotException ignore) {
} catch (RequiredReorgFromSnapshotException e) {
log.warn("doParseBlock at addBlockHandler failed because of a blockchain reorg. {}", e.toString());
}
},
this::handleError);
@ -256,8 +257,8 @@ public class FullNode extends BsqNode {
// We are done
resultHandler.handleResult();
}
} catch (RequiredReorgFromSnapshotException ignore) {
// If we get a reorg we don't continue to call parseBlockRecursively
} catch (RequiredReorgFromSnapshotException e) {
log.warn("doParseBlock at parseBlockRecursively failed because of a blockchain reorg. {}", e.toString());
}
},
errorHandler);

View File

@ -278,7 +278,7 @@ public class LiteNode extends BsqNode {
doParseBlock(block);
runDelayedBatchProcessing(blocks, resultHandler);
} catch (RequiredReorgFromSnapshotException e) {
log.warn("Interrupt batch processing because if a blockchain reorg. {}", e.toString());
log.warn("doParseBlock failed at runDelayedBatchProcessing because of a blockchain reorg. {}", e.toString());
}
});
}
@ -296,7 +296,8 @@ public class LiteNode extends BsqNode {
try {
doParseBlock(block);
} catch (RequiredReorgFromSnapshotException ignore) {
} catch (RequiredReorgFromSnapshotException e) {
log.warn("doParseBlock failed at onNewBlockReceived because of a blockchain reorg. {}", e.toString());
}
maybeExportToJson();

View File

@ -327,7 +327,7 @@ public class DaoStateSnapshotService implements DaoSetupService, DaoStateListene
}
private void resyncDaoStateFromResources() {
log.info("removeAndBackupAllDaoData called");
log.info("resyncDaoStateFromResources 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
@ -343,7 +343,7 @@ public class DaoStateSnapshotService implements DaoSetupService, DaoStateListene
resyncDaoStateFromResourcesHandler.run();
}
} catch (IOException e) {
log.error("Error at removeAndBackupAllDaoData: {}", e.toString());
log.error("Error at resyncDaoStateFromResources: {}", e.toString());
}
}

View File

@ -104,23 +104,23 @@ public class DaoStateStorageService extends StoreService<DaoStateStore> {
}
future = Optional.of(executorService.submit(() -> {
try {
Thread.currentThread().setName("Write-blocks-and-DaoState");
bsqBlocksStorageService.persistBlocks(blocks);
store.setDaoStateAsProto(daoStateAsProto);
store.setDaoStateHashChain(daoStateHashChain);
long ts = System.currentTimeMillis();
persistenceManager.persistNow(() -> {
// 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.clear();
GcUtil.maybeReleaseMemory();
UserThread.execute(completeHandler);
});
} catch (Exception e) {
log.error("Exception at persisting BSQ blocks and DaoState", e);
}
try {
Thread.currentThread().setName("Write-blocks-and-DaoState");
bsqBlocksStorageService.persistBlocks(blocks);
store.setDaoStateAsProto(daoStateAsProto);
store.setDaoStateHashChain(daoStateHashChain);
long ts = System.currentTimeMillis();
persistenceManager.persistNow(() -> {
// 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.clear();
GcUtil.maybeReleaseMemory();
UserThread.execute(completeHandler);
});
} catch (Exception e) {
log.error("Exception at persisting BSQ blocks and DaoState", e);
}
}));
}
@ -135,7 +135,7 @@ public class DaoStateStorageService extends StoreService<DaoStateStore> {
bsqBlocksStorageService.copyFromResources(postFix);
super.readFromResources(postFix, () -> {
// We got mapped back to user thread so we need to create a new thread again as we dont want to
// We got mapped back to user thread, so we need to create a new thread again as we don't want to
// execute on user thread
new Thread(() -> {
Thread.currentThread().setName("Read-BsqBlocksStore");
@ -148,8 +148,12 @@ public class DaoStateStorageService extends StoreService<DaoStateStore> {
if (!list.isEmpty()) {
int heightOfLastBlock = list.getLast().getHeight();
if (heightOfLastBlock != chainHeight) {
log.warn("heightOfLastBlock {} must match chainHeight {}", heightOfLastBlock, chainHeight);
// this error scenario is handled by DaoStateSnapshotService, it will resync from resources & reboot
log.error("Error at readFromResources. " +
"heightOfLastBlock not same as chainHeight.\n" +
"heightOfLastBlock={}; chainHeight={}.\n" +
"This error scenario is handled by DaoStateSnapshotService, " +
"it will resync from resources & reboot",
heightOfLastBlock, chainHeight);
}
}
} else {

View File

@ -139,10 +139,9 @@ public class BisqAppMain extends BisqExecutable {
Cookie cookie = injector.getInstance(User.class).getCookie();
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);
}, log::error);
injector.getInstance(TorSetup.class).cleanupTorFiles(() ->
cookie.remove(CookieKey.CLEAN_TOR_DIR_AT_RESTART),
log::error);
}
});

View File

@ -29,7 +29,6 @@ import bisq.core.locale.Res;
import bisq.core.user.CookieKey;
import bisq.core.user.User;
import bisq.common.UserThread;
import bisq.common.config.Config;
import bisq.common.util.Utilities;
@ -272,8 +271,7 @@ public class DisplayUpdateDownloadWindow extends Overlay<DisplayUpdateDownloadWi
BisqApp.getShutDownHandler().run();
doClose();
} catch (IOException e2) {
log.error(e2.getMessage());
e2.printStackTrace();
log.error("Error at Utilities.openFile", e2);
}
})
.onClose(this::doClose)