rename daemon to monerod

This commit is contained in:
woodser 2025-07-16 15:46:36 -04:00 committed by woodser
parent 68ee80c6ef
commit f4d2646cf3
8 changed files with 81 additions and 81 deletions

View file

@ -106,15 +106,15 @@ public final class XmrConnectionService {
private boolean isInitialized;
private boolean pollInProgress;
private MoneroDaemonRpc daemon;
private MoneroDaemonRpc monerod;
private Boolean isConnected = false;
@Getter
private MoneroDaemonInfo lastInfo;
private Long lastFallbackInvocation;
private Long lastLogPollErrorTimestamp;
private long lastLogDaemonNotSyncedTimestamp;
private long lastLogMonerodNotSyncedTimestamp;
private Long syncStartHeight;
private TaskLooper daemonPollLooper;
private TaskLooper monerodPollLooper;
private long lastRefreshPeriodMs;
@Getter
private boolean isShutDownStarted;
@ -188,16 +188,16 @@ public final class XmrConnectionService {
log.info("Shutting down {}", getClass().getSimpleName());
isInitialized = false;
synchronized (lock) {
if (daemonPollLooper != null) daemonPollLooper.stop();
daemon = null;
if (monerodPollLooper != null) monerodPollLooper.stop();
monerod = null;
}
}
// ------------------------ CONNECTION MANAGEMENT -------------------------
public MoneroDaemonRpc getDaemon() {
public MoneroDaemonRpc getMonerod() {
accountService.checkAccountOpen();
return this.daemon;
return this.monerod;
}
public String getProxyUri() {
@ -402,7 +402,7 @@ public final class XmrConnectionService {
}
public void verifyConnection() {
if (daemon == null) throw new RuntimeException("No connection to Monero node");
if (monerod == null) throw new RuntimeException("No connection to Monero node");
if (!Boolean.TRUE.equals(isConnected())) throw new RuntimeException("No connection to Monero node");
if (!isSyncedWithinTolerance()) throw new RuntimeException("Monero node is not synced");
}
@ -565,8 +565,8 @@ public final class XmrConnectionService {
// register local node listener
xmrLocalNode.addListener(new XmrLocalNodeListener() {
@Override
public void onNodeStarted(MoneroDaemonRpc daemon) {
log.info("Local monero node started, height={}", daemon.getHeight());
public void onNodeStarted(MoneroDaemonRpc monerod) {
log.info("Local monero node started, height={}", monerod.getHeight());
}
@Override
@ -707,15 +707,15 @@ public final class XmrConnectionService {
private void onConnectionChanged(MoneroRpcConnection currentConnection) {
if (isShutDownStarted || !accountService.isAccountOpen()) return;
if (currentConnection == null) {
log.warn("Setting daemon connection to null", new Throwable("Stack trace"));
log.warn("Setting monerod connection to null", new Throwable("Stack trace"));
}
synchronized (lock) {
if (currentConnection == null) {
daemon = null;
monerod = null;
isConnected = false;
connectionList.setCurrentConnectionUri(null);
} else {
daemon = new MoneroDaemonRpc(currentConnection);
monerod = new MoneroDaemonRpc(currentConnection);
isConnected = currentConnection.isConnected();
connectionList.removeConnection(currentConnection.getUri());
connectionList.addConnection(currentConnection);
@ -730,11 +730,11 @@ public final class XmrConnectionService {
}
// update key image poller
keyImagePoller.setDaemon(getDaemon());
keyImagePoller.setMonerod(getMonerod());
keyImagePoller.setRefreshPeriodMs(getKeyImageRefreshPeriodMs());
// update polling
doPollDaemon();
doPollMonerod();
if (currentConnection != getConnection()) return; // polling can change connection
UserThread.runAfter(() -> updatePolling(), getInternalRefreshPeriodMs() / 1000);
@ -754,37 +754,37 @@ public final class XmrConnectionService {
private void startPolling() {
synchronized (lock) {
if (daemonPollLooper != null) daemonPollLooper.stop();
daemonPollLooper = new TaskLooper(() -> pollDaemon());
daemonPollLooper.start(getInternalRefreshPeriodMs());
if (monerodPollLooper != null) monerodPollLooper.stop();
monerodPollLooper = new TaskLooper(() -> pollMonerod());
monerodPollLooper.start(getInternalRefreshPeriodMs());
}
}
private void stopPolling() {
synchronized (lock) {
if (daemonPollLooper != null) {
daemonPollLooper.stop();
daemonPollLooper = null;
if (monerodPollLooper != null) {
monerodPollLooper.stop();
monerodPollLooper = null;
}
}
}
private void pollDaemon() {
private void pollMonerod() {
if (pollInProgress) return;
doPollDaemon();
doPollMonerod();
}
private void doPollDaemon() {
private void doPollMonerod() {
synchronized (pollLock) {
pollInProgress = true;
if (isShutDownStarted) return;
try {
// poll daemon
if (daemon == null && !fallbackRequiredBeforeConnectionSwitch()) switchToBestConnection();
// poll monerod
if (monerod == null && !fallbackRequiredBeforeConnectionSwitch()) switchToBestConnection();
try {
if (daemon == null) throw new RuntimeException("No connection to Monero daemon");
lastInfo = daemon.getInfo();
if (monerod == null) throw new RuntimeException("No connection to Monero daemon");
lastInfo = monerod.getInfo();
} catch (Exception e) {
// skip handling if shutting down
@ -796,13 +796,13 @@ public final class XmrConnectionService {
if (connectionServiceFallbackType.get() == null && (lastFallbackInvocation == null || System.currentTimeMillis() - lastFallbackInvocation > FALLBACK_INVOCATION_PERIOD_MS)) {
lastFallbackInvocation = System.currentTimeMillis();
if (usedSyncingLocalNodeBeforeStartup) {
log.warn("Failed to fetch daemon info from local connection on startup: " + e.getMessage());
log.warn("Failed to fetch monerod info from local connection on startup: " + e.getMessage());
connectionServiceFallbackType.set(XmrConnectionFallbackType.LOCAL);
} else if (isProvidedConnections()) {
log.warn("Failed to fetch daemon info from provided connections on startup: " + e.getMessage());
log.warn("Failed to fetch monerod info from provided connections on startup: " + e.getMessage());
connectionServiceFallbackType.set(XmrConnectionFallbackType.PROVIDED);
} else {
log.warn("Failed to fetch daemon info from custom connection on startup: " + e.getMessage());
log.warn("Failed to fetch monerod info from custom connection on startup: " + e.getMessage());
connectionServiceFallbackType.set(XmrConnectionFallbackType.CUSTOM);
}
}
@ -811,18 +811,18 @@ public final class XmrConnectionService {
// log error message periodically
if (lastLogPollErrorTimestamp == null || System.currentTimeMillis() - lastLogPollErrorTimestamp > HavenoUtils.LOG_POLL_ERROR_PERIOD_MS) {
log.warn("Failed to fetch daemon info, trying to switch to best connection, error={}", e.getMessage());
log.warn("Failed to fetch monerod info, trying to switch to best connection, error={}", e.getMessage());
if (DevEnv.isDevMode()) log.error(ExceptionUtils.getStackTrace(e));
lastLogPollErrorTimestamp = System.currentTimeMillis();
}
// switch to best connection
switchToBestConnection();
if (daemon == null) throw new RuntimeException("No connection to Monero daemon after error handling");
lastInfo = daemon.getInfo(); // caught internally if still fails
if (monerod == null) throw new RuntimeException("No connection to Monero daemon after error handling");
lastInfo = monerod.getInfo(); // caught internally if still fails
}
// connected to daemon
// connected to monerod
isConnected = true;
connectionServiceFallbackType.set(null);
@ -832,10 +832,10 @@ public final class XmrConnectionService {
// write sync status to preferences
preferences.getXmrNodeSettings().setSyncBlockchain(blockchainSyncing);
// throttle warnings if daemon not synced
if (!isSyncedWithinTolerance() && System.currentTimeMillis() - lastLogDaemonNotSyncedTimestamp > HavenoUtils.LOG_DAEMON_NOT_SYNCED_WARN_PERIOD_MS) {
// throttle warnings if monerod not synced
if (!isSyncedWithinTolerance() && System.currentTimeMillis() - lastLogMonerodNotSyncedTimestamp > HavenoUtils.LOG_MONEROD_NOT_SYNCED_WARN_PERIOD_MS) {
log.warn("Our chain height: {} is out of sync with peer nodes chain height: {}", chainHeight.get(), getTargetHeight());
lastLogDaemonNotSyncedTimestamp = System.currentTimeMillis();
lastLogMonerodNotSyncedTimestamp = System.currentTimeMillis();
}
// announce connection change if refresh period changes
@ -878,7 +878,7 @@ public final class XmrConnectionService {
// handle error recovery
if (lastLogPollErrorTimestamp != null) {
log.info("Successfully fetched daemon info after previous error");
log.info("Successfully fetched monerod info after previous error");
lastLogPollErrorTimestamp = null;
}
@ -886,7 +886,7 @@ public final class XmrConnectionService {
getConnectionServiceErrorMsg().set(null);
} catch (Exception e) {
// not connected to daemon
// not connected to monerod
isConnected = false;
// skip if shut down

View file

@ -101,7 +101,7 @@ public class HavenoUtils {
// other configuration
public static final long LOG_POLL_ERROR_PERIOD_MS = 1000 * 60 * 4; // log poll errors up to once every 4 minutes
public static final long LOG_DAEMON_NOT_SYNCED_WARN_PERIOD_MS = 1000 * 30; // log warnings when daemon not synced once every 30s
public static final long LOG_MONEROD_NOT_SYNCED_WARN_PERIOD_MS = 1000 * 30; // log warnings when daemon not synced once every 30s
public static final int PRIVATE_OFFER_PASSPHRASE_NUM_WORDS = 8; // number of words in a private offer passphrase
// synchronize requests to the daemon

View file

@ -1736,8 +1736,8 @@ public abstract class Trade extends XmrWalletBase implements Tradable, Model {
ThreadUtils.submitToPool(() -> {
// get trade's deposit txs from daemon
MoneroTx makerDepositTx = getMaker().getDepositTxHash() == null ? null : xmrWalletService.getDaemon().getTx(getMaker().getDepositTxHash());
MoneroTx takerDepositTx = getTaker().getDepositTxHash() == null ? null : xmrWalletService.getDaemon().getTx(getTaker().getDepositTxHash());
MoneroTx makerDepositTx = getMaker().getDepositTxHash() == null ? null : xmrWalletService.getMonerod().getTx(getMaker().getDepositTxHash());
MoneroTx takerDepositTx = getTaker().getDepositTxHash() == null ? null : xmrWalletService.getMonerod().getTx(getTaker().getDepositTxHash());
// remove trade and wallet if neither deposit tx published
if (makerDepositTx == null && takerDepositTx == null) {
@ -2202,13 +2202,13 @@ public abstract class Trade extends XmrWalletBase implements Tradable, Model {
private void setStartTimeFromUnlockedTxs() {
long now = System.currentTimeMillis();
final long tradeTime = getTakeOfferDate().getTime();
MoneroDaemon daemonRpc = xmrWalletService.getDaemon();
if (daemonRpc == null) throw new RuntimeException("Cannot set start time for trade " + getId() + " because it has no connection to monerod");
MoneroDaemon monerod = xmrWalletService.getMonerod();
if (monerod == null) throw new RuntimeException("Cannot set start time for trade " + getId() + " because it has no connection to monerod");
if (getMakerDepositTx() == null || (getTakerDepositTx() == null && !hasBuyerAsTakerWithoutDeposit())) throw new RuntimeException("Cannot set start time for trade " + getId() + " because its unlocked deposit tx is null. Is client connected to a daemon?");
// get unlock time of last deposit tx
long unlockHeight = Math.max(getMakerDepositTx().getHeight() + XmrWalletService.NUM_BLOCKS_UNLOCK - 1, hasBuyerAsTakerWithoutDeposit() ? 0l : getTakerDepositTx().getHeight() + XmrWalletService.NUM_BLOCKS_UNLOCK - 1);
long unlockTime = daemonRpc.getBlockByHeight(unlockHeight).getTimestamp() * 1000;
long unlockTime = monerod.getBlockByHeight(unlockHeight).getTimestamp() * 1000;
// If block date is in future (Date in blocks can be off by +/- 2 hours) we use our current date.
// If block date is earlier than our trade date we use our trade date.
@ -2976,13 +2976,13 @@ public abstract class Trade extends XmrWalletBase implements Tradable, Model {
// get payout height if unknown
if (payoutHeight == null && getPayoutTxId() != null && isPayoutPublished()) {
MoneroTx tx = xmrWalletService.getDaemon().getTx(getPayoutTxId());
MoneroTx tx = xmrWalletService.getMonerod().getTx(getPayoutTxId());
if (tx == null) log.warn("Payout tx not found for {} {}, txId={}", getTrade().getClass().getSimpleName(), getId(), getPayoutTxId());
else if (tx.isConfirmed()) payoutHeight = tx.getHeight();
}
// sync wallet if confirm or unlock expected
long currentHeight = xmrWalletService.getDaemon().getHeight();
long currentHeight = xmrWalletService.getMonerod().getHeight();
if (!isPayoutConfirmed() || (payoutHeight != null && currentHeight >= payoutHeight + XmrWalletService.NUM_BLOCKS_UNLOCK)) {
log.info("Syncing idle trade wallet to update payout tx, tradeId={}", getId());
syncAndPollWallet();

View file

@ -155,7 +155,7 @@ public class ArbitratorProcessDepositRequest extends TradeTask {
processModel.getTradeManager().requestPersistence();
// relay deposit txs when both requests received
MoneroDaemon daemon = trade.getXmrWalletService().getDaemon();
MoneroDaemon monerod = trade.getXmrWalletService().getMonerod();
if (hasBothContractSignatures()) {
// check timeout and extend just before relaying
@ -168,19 +168,19 @@ public class ArbitratorProcessDepositRequest extends TradeTask {
try {
// submit maker tx to pool but do not relay
MoneroSubmitTxResult makerResult = daemon.submitTxHex(processModel.getMaker().getDepositTxHex(), true);
MoneroSubmitTxResult makerResult = monerod.submitTxHex(processModel.getMaker().getDepositTxHex(), true);
if (!makerResult.isGood()) throw new RuntimeException("Error submitting maker deposit tx: " + JsonUtils.serialize(makerResult));
txHashes.add(processModel.getMaker().getDepositTxHash());
// submit taker tx to pool but do not relay
if (!trade.hasBuyerAsTakerWithoutDeposit()) {
MoneroSubmitTxResult takerResult = daemon.submitTxHex(processModel.getTaker().getDepositTxHex(), true);
MoneroSubmitTxResult takerResult = monerod.submitTxHex(processModel.getTaker().getDepositTxHex(), true);
if (!takerResult.isGood()) throw new RuntimeException("Error submitting taker deposit tx: " + JsonUtils.serialize(takerResult));
txHashes.add(processModel.getTaker().getDepositTxHash());
}
// relay txs
daemon.relayTxsByHash(txHashes);
monerod.relayTxsByHash(txHashes);
depositTxsRelayed = true;
// update trade state
@ -192,7 +192,7 @@ public class ArbitratorProcessDepositRequest extends TradeTask {
// flush txs from pool
try {
daemon.flushTxPool(txHashes);
monerod.flushTxPool(txHashes);
} catch (Exception e2) {
log.warn("Error flushing deposit txs from pool for trade {}: {}\n", trade.getId(), e2.getMessage(), e2);
}

View file

@ -50,7 +50,7 @@ public class ProcessDepositResponse extends TradeTask {
// publish deposit transaction for redundancy
try {
model.getXmrWalletService().getDaemon().submitTxHex(trade.getSelf().getDepositTxHex());
model.getXmrWalletService().getMonerod().submitTxHex(trade.getSelf().getDepositTxHex());
} catch (Exception e) {
log.error("Failed to redundantly publish deposit transaction for {} {}", trade.getClass().getSimpleName(), trade.getShortId(), e);
}

View file

@ -41,7 +41,7 @@ import haveno.core.trade.HavenoUtils;
@Slf4j
public class XmrKeyImagePoller {
private MoneroDaemon daemon;
private MoneroDaemon monerod;
private long refreshPeriodMs;
private Object lock = new Object();
private Map<String, Set<String>> keyImageGroups = new HashMap<String, Set<String>>();
@ -63,12 +63,12 @@ public class XmrKeyImagePoller {
/**
* Construct the listener.
*
* @param daemon - the Monero daemon to poll
* @param monerod - the Monero daemon to poll
* @param refreshPeriodMs - refresh period in milliseconds
*/
public XmrKeyImagePoller(MoneroDaemon daemon, long refreshPeriodMs) {
public XmrKeyImagePoller(MoneroDaemon monerod, long refreshPeriodMs) {
looper = new TaskLooper(() -> poll());
setDaemon(daemon);
setMonerod(monerod);
setRefreshPeriodMs(refreshPeriodMs);
}
@ -100,10 +100,10 @@ public class XmrKeyImagePoller {
/**
* Set the Monero daemon to fetch key images from.
*
* @param daemon - the daemon to fetch key images from
* @param monerod - the daemon to fetch key images from
*/
public void setDaemon(MoneroDaemon daemon) {
this.daemon = daemon;
public void setMonerod(MoneroDaemon monerod) {
this.monerod = monerod;
}
/**
@ -111,8 +111,8 @@ public class XmrKeyImagePoller {
*
* @return the daemon to fetch key images from
*/
public MoneroDaemon getDaemon() {
return daemon;
public MoneroDaemon getMonerod() {
return monerod;
}
/**
@ -243,8 +243,8 @@ public class XmrKeyImagePoller {
}
public void poll() {
if (daemon == null) {
log.warn("Cannot poll key images because daemon is null");
if (monerod == null) {
log.warn("Cannot poll key images because monerod is null");
return;
}
@ -252,7 +252,7 @@ public class XmrKeyImagePoller {
List<MoneroKeyImageSpentStatus> spentStatuses = null;
List<String> keyImages = new ArrayList<String>(getNextKeyImageBatch());
try {
spentStatuses = keyImages.isEmpty() ? new ArrayList<MoneroKeyImageSpentStatus>() : daemon.getKeyImageSpentStatuses(keyImages); // TODO monero-java: if order of getKeyImageSpentStatuses is guaranteed, then it should take list parameter
spentStatuses = keyImages.isEmpty() ? new ArrayList<MoneroKeyImageSpentStatus>() : monerod.getKeyImageSpentStatuses(keyImages); // TODO monero-java: if order of getKeyImageSpentStatuses is guaranteed, then it should take list parameter
} catch (Exception e) {
// limit error logging

View file

@ -298,8 +298,8 @@ public class XmrWalletService extends XmrWalletBase {
return false;
}
public MoneroDaemonRpc getDaemon() {
return xmrConnectionService.getDaemon();
public MoneroDaemonRpc getMonerod() {
return xmrConnectionService.getMonerod();
}
public boolean isProxyApplied() {
@ -754,22 +754,22 @@ public class XmrWalletService extends XmrWalletBase {
*/
public MoneroTx verifyTradeTx(String offerId, BigInteger tradeFeeAmount, String feeAddress, BigInteger sendAmount, String sendAddress, String txHash, String txHex, String txKey, List<String> keyImages) {
if (txHash == null) throw new IllegalArgumentException("Cannot verify trade tx with null id");
MoneroDaemonRpc daemon = getDaemon();
MoneroDaemonRpc monerod = getMonerod();
MoneroWallet wallet = getWallet();
MoneroTx tx = null;
synchronized (lock) {
try {
// verify tx not submitted to pool
tx = daemon.getTx(txHash);
tx = monerod.getTx(txHash);
if (tx != null) throw new RuntimeException("Tx is already submitted");
// submit tx to pool
MoneroSubmitTxResult result = daemon.submitTxHex(txHex, true); // TODO (woodser): invert doNotRelay flag to relay for library consistency?
MoneroSubmitTxResult result = monerod.submitTxHex(txHex, true); // TODO (woodser): invert doNotRelay flag to relay for library consistency?
if (!result.isGood()) throw new RuntimeException("Failed to submit tx to daemon: " + JsonUtils.serialize(result));
// get pool tx which has weight and size
for (MoneroTx poolTx : daemon.getTxPool()) if (poolTx.getHash().equals(txHash)) tx = poolTx;
for (MoneroTx poolTx : monerod.getTxPool()) if (poolTx.getHash().equals(txHash)) tx = poolTx;
if (tx == null) throw new RuntimeException("Tx is not in pool after being submitted");
// verify key images
@ -824,9 +824,9 @@ public class XmrWalletService extends XmrWalletBase {
throw e;
} finally {
try {
daemon.flushTxPool(txHash); // flush tx from pool
monerod.flushTxPool(txHash); // flush tx from pool
} catch (MoneroRpcError err) {
System.out.println(daemon.getRpcConnection());
System.out.println(monerod.getRpcConnection());
throw err.getCode().equals(-32601) ? new RuntimeException("Failed to flush tx from pool. Arbitrator must use trusted, unrestricted daemon") : err;
}
}
@ -855,7 +855,7 @@ public class XmrWalletService extends XmrWalletBase {
}
// get fee estimates per kB from daemon
MoneroFeeEstimate feeEstimates = getDaemon().getFeeEstimate();
MoneroFeeEstimate feeEstimates = getMonerod().getFeeEstimate();
BigInteger baseFeeEstimate = feeEstimates.getFees().get(priority.ordinal() - 1);
BigInteger qmask = feeEstimates.getQuantizationMask();
log.info("Monero base fee estimate={}, qmask={}", baseFeeEstimate, qmask);
@ -879,8 +879,8 @@ public class XmrWalletService extends XmrWalletBase {
synchronized (txCache) {
// fetch txs
if (getDaemon() == null) xmrConnectionService.verifyConnection(); // will throw
List<MoneroTx> txs = getDaemon().getTxs(txHashes, true);
if (getMonerod() == null) xmrConnectionService.verifyConnection(); // will throw
List<MoneroTx> txs = getMonerod().getTxs(txHashes, true);
// store to cache
for (MoneroTx tx : txs) txCache.put(tx.getHash(), Optional.of(tx));
@ -1431,8 +1431,8 @@ public class XmrWalletService extends XmrWalletBase {
// open or create wallet main wallet
if (wallet == null) {
MoneroDaemonRpc daemon = xmrConnectionService.getDaemon();
log.info("Initializing main wallet with monerod=" + (daemon == null ? "null" : daemon.getRpcConnection().getUri()));
MoneroDaemonRpc monerod = xmrConnectionService.getMonerod();
log.info("Initializing main wallet with monerod=" + (monerod == null ? "null" : monerod.getRpcConnection().getUri()));
if (walletExists(MONERO_WALLET_NAME)) {
wallet = openWallet(MONERO_WALLET_NAME, rpcBindPort, isProxyApplied(wasWalletSynced));
} else if (Boolean.TRUE.equals(xmrConnectionService.isConnected())) {
@ -2025,7 +2025,7 @@ public class XmrWalletService extends XmrWalletBase {
if (!xmrConnectionService.isSyncedWithinTolerance()) {
// throttle warnings
if (System.currentTimeMillis() - lastLogDaemonNotSyncedTimestamp > HavenoUtils.LOG_DAEMON_NOT_SYNCED_WARN_PERIOD_MS) {
if (System.currentTimeMillis() - lastLogDaemonNotSyncedTimestamp > HavenoUtils.LOG_MONEROD_NOT_SYNCED_WARN_PERIOD_MS) {
log.warn("Monero daemon is not synced within tolerance, height={}, targetHeight={}, monerod={}", xmrConnectionService.chainHeightProperty().get(), xmrConnectionService.getTargetHeight(), xmrConnectionService.getConnection() == null ? null : xmrConnectionService.getConnection().getUri());
lastLogDaemonNotSyncedTimestamp = System.currentTimeMillis();
}

View file

@ -140,7 +140,7 @@ public class OfferViewUtil {
public static void submitTransactionHex(XmrWalletService xmrWalletService,
TableView tableView,
String reserveTxHex) {
MoneroSubmitTxResult result = xmrWalletService.getDaemon().submitTxHex(reserveTxHex);
MoneroSubmitTxResult result = xmrWalletService.getMonerod().submitTxHex(reserveTxHex);
log.info("submitTransactionHex: reserveTxHex={} result={}", result);
tableView.refresh();