<h3>Description</h3>
<p><code>WalletAppSetup</code> is instantiated on Bisq app's startup by Guice. Its constructor calls <code>Preferences::getUseTorForBitcoinJ</code>, which in turn queries the singleton <code>LocalBitcoinNode</code> for whether or not a local Bitcoin node will be used.</p>
<p>The problem is that <code>LocalBitcoinNode</code> does not actually check for a local Bitcoin node until it is told to during one of the later stages of setup (in <code>BisqSetup::step2</code>).</p>
<p>The reason why LocalBitcoinNode does not throw an exception when it is queried too early is that the queries return a cached value (which is populated by the check triggered in <code>BisqSetup::step2</code>), but the cache is initialized to <code>false</code> (signifying that a locally running Bitcoin node is not found), so when LocalBitcoinNode is queried too early it just returns <code>false</code>.</p>
<p>That's how this erronious usage went unnoticed, and there could be other usages like this.</p>
<p><a href="https://github.com/bisq-network/bisq/pull/3982" data-hovercard-type="pull_request" data-hovercard-url="/bisq-network/bisq/pull/3982/hovercard">This PR</a> affects this a bit. It switches LocalBitcoinNode from using plain <code>boolean</code> to using <code>Optional<Boolean></code>, the rationale being that a variable that describes the result of a detection attempt in this case has 3 possible states: detected; undetected; not yet attempted detection (represented by <code>Optional.empty()</code>). As the PR is now, in case <code>LocalBitcoinNode</code> is queried before it has performed its checks, it reverts to the old behaviour (returning <code>false</code>), but it also logs an error message with a stacktrace. That's how this bug was discovered.</p>
<h3>Steps to reproduce</h3>
<p>You could use the mentioned PR, which makes <code>LocalBitcoinNode</code> aware of whether or not the checks have been performed, or, you could log the <code>LocalBitcoinNode</code> query inside <code>Preferences::getUseTorForBitcoinJ</code> and run a local Bitcoin node (you would see that <code>LocalBitcoinNode</code> sometimes says that there isn't a local Bitcoin node).</p>
<h3>Expected behaviour</h3>
<p><code>LocalBitcoinNode</code> to return accurate information ("undetected" is not the same as "detection has not been attempted"), and one of the following:<br>
a) assure that <code>LocalBitcoinNode</code> is never queried when its checks were not performed beforehand;<br>
b) or, assure that it is impossible to do that.</p>
<h3>Possible solution</h3>
<p>Restructure <code>LocalBitcoinNode</code> to trigger a detection whenever it is queried, but the detection is not yet performed.</p>

<p style="font-size:small;-webkit-text-size-adjust:none;color:#666;">—<br />You are receiving this because you are subscribed to this thread.<br />Reply to this email directly, <a href="https://github.com/bisq-network/bisq/issues/4005?email_source=notifications&email_token=AJFFTNUX3M5MPWUHIF3TTCLREQJR7A5CNFSM4K2OX3D2YY3PNVWWK3TUL52HS4DFUVEXG43VMWVGG33NNVSW45C7NFSM4IP2MMIA">view it on GitHub</a>, or <a href="https://github.com/notifications/unsubscribe-auth/AJFFTNVJ24XHOCYTNCWQ5HLREQJR7ANCNFSM4K2OX3DQ">unsubscribe</a>.<img src="https://github.com/notifications/beacon/AJFFTNQAFR7ZT5XU47DRLDLREQJR7A5CNFSM4K2OX3D2YY3PNVWWK3TUL52HS4DFUVEXG43VMWVGG33NNVSW45C7NFSM4IP2MMIA.gif" height="1" width="1" alt="" /></p>
<script type="application/ld+json">[
{
"@context": "http://schema.org",
"@type": "EmailMessage",
"potentialAction": {
"@type": "ViewAction",
"target": "https://github.com/bisq-network/bisq/issues/4005?email_source=notifications\u0026email_token=AJFFTNUX3M5MPWUHIF3TTCLREQJR7A5CNFSM4K2OX3D2YY3PNVWWK3TUL52HS4DFUVEXG43VMWVGG33NNVSW45C7NFSM4IP2MMIA",
"url": "https://github.com/bisq-network/bisq/issues/4005?email_source=notifications\u0026email_token=AJFFTNUX3M5MPWUHIF3TTCLREQJR7A5CNFSM4K2OX3D2YY3PNVWWK3TUL52HS4DFUVEXG43VMWVGG33NNVSW45C7NFSM4IP2MMIA",
"name": "View Issue"
},
"description": "View this Issue on GitHub",
"publisher": {
"@type": "Organization",
"name": "GitHub",
"url": "https://github.com"
}
}
]</script>