Skip to content

Commit 2c08975

Browse files
authored
Sanitize logs (#246)
* Don't print seed with LocalKeyManager * Don't log ping and pong
1 parent 8871b29 commit 2c08975

File tree

2 files changed

+15
-10
lines changed

2 files changed

+15
-10
lines changed

src/commonMain/kotlin/fr/acinq/eclair/crypto/LocalKeyManager.kt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,13 @@ import fr.acinq.eclair.transactions.Transactions
99
data class LocalKeyManager(val seed: ByteVector, val chainHash: ByteVector32) : KeyManager {
1010

1111
private val master = DeterministicWallet.generate(seed)
12-
1312
override val nodeKey: DeterministicWallet.ExtendedPrivateKey = derivePrivateKey(master, nodeKeyBasePath(chainHash))
14-
1513
override val nodeId: PublicKey get() = nodeKey.publicKey
1614

15+
override fun toString(): String {
16+
return "LocalKeyManager(seed=xxx,chainHash=$chainHash)"
17+
}
18+
1719
private fun internalKeyPath(channelKeyPath: List<Long>, index: Long): List<Long> = channelKeyBasePath(chainHash) + channelKeyPath + index
1820

1921
private fun internalKeyPath(channelKeyPath: KeyPath, index: Long): List<Long> = internalKeyPath(channelKeyPath.path, index)

src/commonMain/kotlin/fr/acinq/eclair/io/Peer.kt

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,10 @@ data class PaymentNotSent(val request: SendPayment, val reason: OutgoingPaymentF
5656
data class PaymentSent(val request: SendPayment, val payment: OutgoingPayment) : PeerListenerEvent()
5757
data class ChannelClosing(val channelId: ByteVector32) : PeerListenerEvent()
5858

59-
object SendSwapInRequest: PeerEvent()
60-
data class SwapInResponseEvent(val swapInResponse: SwapInResponse): PeerListenerEvent()
61-
data class SwapInPendingEvent(val swapInPending: SwapInPending): PeerListenerEvent()
62-
data class SwapInConfirmedEvent(val swapInConfirmed: SwapInConfirmed): PeerListenerEvent()
59+
object SendSwapInRequest : PeerEvent()
60+
data class SwapInResponseEvent(val swapInResponse: SwapInResponse) : PeerListenerEvent()
61+
data class SwapInPendingEvent(val swapInPending: SwapInPending) : PeerListenerEvent()
62+
data class SwapInConfirmedEvent(val swapInConfirmed: SwapInConfirmed) : PeerListenerEvent()
6363

6464
@OptIn(ExperimentalStdlibApi::class, ExperimentalCoroutinesApi::class, ExperimentalTime::class)
6565
class Peer(
@@ -269,12 +269,14 @@ class Peer(
269269
sendToPeer(ping)
270270
}
271271
}
272+
272273
suspend fun checkPaymentsTimeout() {
273274
while (isActive) {
274275
delay(30.seconds)
275276
input.send(CheckPaymentsTimeout)
276277
}
277278
}
279+
278280
suspend fun listen() {
279281
try {
280282
while (isActive) {
@@ -287,10 +289,11 @@ class Peer(
287289
closeSocket()
288290
}
289291
}
292+
290293
suspend fun respond() {
291294
// Reset the output channel to avoid sending obsolete messages
292295
output = Channel(BUFFERED)
293-
for(msg in output) send(msg)
296+
for (msg in output) send(msg)
294297
}
295298

296299
launch { doPing() }
@@ -308,8 +311,8 @@ class Peer(
308311

309312
suspend fun sendToPeer(msg: LightningMessage) {
310313
val encoded = LightningMessage.encode(msg)
311-
// Avoids polluting the logs with pongs
312-
if (msg !is Pong) logger.info { "n:$remoteNodeId sending $msg" }
314+
// Avoids polluting the logs with pings/pongs
315+
if (msg !is Ping && msg !is Pong) logger.info { "n:$remoteNodeId sending $msg" }
313316
if (!output.isClosedForSend) output.send(encoded)
314317
}
315318

@@ -481,7 +484,7 @@ class Peer(
481484
when {
482485
event is BytesReceived -> {
483486
val msg = LightningMessage.decode(event.data)
484-
msg?.let { logger.info { "n:$remoteNodeId received $it" } }
487+
msg?.let { if (it !is Ping && it !is Pong) logger.info { "n:$remoteNodeId received $it" } }
485488
when {
486489
msg is Init -> {
487490
val theirFeatures = Features(msg.features)

0 commit comments

Comments
 (0)