Skip to content

Commit c846781

Browse files
authored
Make Tor optional for blockchain watchdogs (#1958)
This change lets node operators disable the use of Tor for blockchain watchdogs if they'd rather use cleartext HTTP instead.
1 parent 273fae9 commit c846781

File tree

7 files changed

+20
-12
lines changed

7 files changed

+20
-12
lines changed

docs/Tor.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,4 +174,10 @@ eclair.blockchain-watchdog.sources = [
174174
"blockstream.info",
175175
"mempool.space"
176176
]
177+
```
178+
179+
Also, you can disable Tor for all watchdog sources altogether using:
180+
181+
```s
182+
eclair.socks5.use-for-watchdogs = false
177183
```

eclair-core/src/main/resources/reference.conf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,7 @@ eclair {
327327
use-for-ipv4 = true
328328
use-for-ipv6 = true
329329
use-for-tor = true
330+
use-for-watchdogs = true
330331
randomize-credentials = false // this allows tor stream isolation
331332
}
332333

eclair-core/src/main/scala/fr/acinq/eclair/NodeParams.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,8 @@ object NodeParams extends Logging {
292292
randomizeCredentials = config.getBoolean("socks5.randomize-credentials"),
293293
useForIPv4 = config.getBoolean("socks5.use-for-ipv4"),
294294
useForIPv6 = config.getBoolean("socks5.use-for-ipv6"),
295-
useForTor = config.getBoolean("socks5.use-for-tor")
295+
useForTor = config.getBoolean("socks5.use-for-tor"),
296+
useForWatchdogs = config.getBoolean("socks5.use-for-watchdogs"),
296297
))
297298
} else {
298299
None

eclair-core/src/main/scala/fr/acinq/eclair/blockchain/watchdogs/BlockchainWatchdog.scala

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,9 @@ object BlockchainWatchdog {
6868
*/
6969
def apply(nodeParams: NodeParams, maxRandomDelay: FiniteDuration, blockTimeout: FiniteDuration = 15 minutes): Behavior[Command] = {
7070
Behaviors.setup { context =>
71-
implicit val sttpBackend = ExplorerApi.createSttpBackend(nodeParams.socksProxy_opt)
72-
71+
val socksProxy_opt = nodeParams.socksProxy_opt.flatMap(params => if (params.useForWatchdogs) Some(params) else None)
72+
implicit val sttpBackend = ExplorerApi.createSttpBackend(socksProxy_opt)
7373
val chainHash = nodeParams.chainHash
74-
val socksProxy_opt = nodeParams.socksProxy_opt
7574
val sources = nodeParams.blockchainWatchdogSources
7675

7776
val explorers = Seq(

eclair-core/src/main/scala/fr/acinq/eclair/tor/Socks5Connection.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ object Socks5Connection {
217217
def portToByteString(port: Int): ByteString = ByteString((port & 0x0000ff00) >> 8, port & 0x000000ff)
218218
}
219219

220-
case class Socks5ProxyParams(address: InetSocketAddress, credentials_opt: Option[Credentials], randomizeCredentials: Boolean, useForIPv4: Boolean, useForIPv6: Boolean, useForTor: Boolean)
220+
case class Socks5ProxyParams(address: InetSocketAddress, credentials_opt: Option[Credentials], randomizeCredentials: Boolean, useForIPv4: Boolean, useForIPv6: Boolean, useForTor: Boolean, useForWatchdogs: Boolean)
221221

222222
object Socks5ProxyParams {
223223

eclair-core/src/test/scala/fr/acinq/eclair/blockchain/watchdogs/BlockchainWatchdogSpec.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,8 @@ class BlockchainWatchdogSpec extends ScalaTestWithActorTestKit(ConfigFactory.loa
106106
randomizeCredentials = true,
107107
useForIPv4 = true,
108108
useForIPv6 = true,
109-
useForTor = true)
109+
useForTor = true,
110+
useForWatchdogs = true)
110111

111112
if (proxyAcceptsConnections(proxyParams)) {
112113
val eventListener = TestProbe[DangerousBlocksSkew]()

eclair-core/src/test/scala/fr/acinq/eclair/tor/Socks5ConnectionSpec.scala

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,27 +31,27 @@ class Socks5ConnectionSpec extends AnyFunSuite {
3131

3232
assert(Socks5ProxyParams.proxyAddress(
3333
socketAddress = new InetSocketAddress("1.2.3.4", 9735),
34-
proxyParams = Socks5ProxyParams(address = proxyAddress, credentials_opt = None, randomizeCredentials = false, useForIPv4 = true, useForIPv6 = true, useForTor = true)).contains(proxyAddress))
34+
proxyParams = Socks5ProxyParams(address = proxyAddress, credentials_opt = None, randomizeCredentials = false, useForIPv4 = true, useForIPv6 = true, useForTor = true, useForWatchdogs = true)).contains(proxyAddress))
3535

3636
assert(Socks5ProxyParams.proxyAddress(
3737
socketAddress = new InetSocketAddress("1.2.3.4", 9735),
38-
proxyParams = Socks5ProxyParams(address = proxyAddress, credentials_opt = None, randomizeCredentials = false, useForIPv4 = false, useForIPv6 = true, useForTor = true)).isEmpty)
38+
proxyParams = Socks5ProxyParams(address = proxyAddress, credentials_opt = None, randomizeCredentials = false, useForIPv4 = false, useForIPv6 = true, useForTor = true, useForWatchdogs = true)).isEmpty)
3939

4040
assert(Socks5ProxyParams.proxyAddress(
4141
socketAddress = new InetSocketAddress("[fc92:97a3:e057:b290:abd8:9bd6:135d:7e7]", 9735),
42-
proxyParams = Socks5ProxyParams(address = proxyAddress, credentials_opt = None, randomizeCredentials = false, useForIPv4 = true, useForIPv6 = true, useForTor = true)).contains(proxyAddress))
42+
proxyParams = Socks5ProxyParams(address = proxyAddress, credentials_opt = None, randomizeCredentials = false, useForIPv4 = true, useForIPv6 = true, useForTor = true, useForWatchdogs = true)).contains(proxyAddress))
4343

4444
assert(Socks5ProxyParams.proxyAddress(
4545
socketAddress = new InetSocketAddress("[fc92:97a3:e057:b290:abd8:9bd6:135d:7e7]", 9735),
46-
proxyParams = Socks5ProxyParams(address = proxyAddress, credentials_opt = None, randomizeCredentials = false, useForIPv4 = true, useForIPv6 = false, useForTor = true)).isEmpty)
46+
proxyParams = Socks5ProxyParams(address = proxyAddress, credentials_opt = None, randomizeCredentials = false, useForIPv4 = true, useForIPv6 = false, useForTor = true, useForWatchdogs = true)).isEmpty)
4747

4848
assert(Socks5ProxyParams.proxyAddress(
4949
socketAddress = new InetSocketAddress("iq7zhmhck54vcax2vlrdcavq2m32wao7ekh6jyeglmnuuvv3js57r4id.onion", 9735),
50-
proxyParams = Socks5ProxyParams(address = proxyAddress, credentials_opt = None, randomizeCredentials = false, useForIPv4 = true, useForIPv6 = true, useForTor = true)).contains(proxyAddress))
50+
proxyParams = Socks5ProxyParams(address = proxyAddress, credentials_opt = None, randomizeCredentials = false, useForIPv4 = true, useForIPv6 = true, useForTor = true, useForWatchdogs = true)).contains(proxyAddress))
5151

5252
assert(Socks5ProxyParams.proxyAddress(
5353
socketAddress = new InetSocketAddress("iq7zhmhck54vcax2vlrdcavq2m32wao7ekh6jyeglmnuuvv3js57r4id.onion", 9735),
54-
proxyParams = Socks5ProxyParams(address = proxyAddress, credentials_opt = None, randomizeCredentials = false, useForIPv4 = true, useForIPv6 = true, useForTor = false)).isEmpty)
54+
proxyParams = Socks5ProxyParams(address = proxyAddress, credentials_opt = None, randomizeCredentials = false, useForIPv4 = true, useForIPv6 = true, useForTor = false, useForWatchdogs = true)).isEmpty)
5555

5656
}
5757

0 commit comments

Comments
 (0)