From 2054d761a92832b701364dbd746b35ccd98816b1 Mon Sep 17 00:00:00 2001 From: fiatjaf Date: Tue, 27 Sep 2022 14:22:41 -0300 Subject: [PATCH] use human-readable errors instead of cryptic codes. --- src/main/scala/Channel.scala | 34 ++++++++++------------------------ src/main/scala/Database.scala | 14 +------------- 2 files changed, 11 insertions(+), 37 deletions(-) diff --git a/src/main/scala/Channel.scala b/src/main/scala/Channel.scala index 3c43930..e65fec9 100644 --- a/src/main/scala/Channel.scala +++ b/src/main/scala/Channel.scala @@ -730,18 +730,12 @@ class Channel(peerId: ByteVector) { if (!isLocalSigOk || !isRemoteSigOk) { val (err, reason) = if (!isLocalSigOk) { ( - Error( - channelId, - HostedError.ERR_HOSTED_WRONG_LOCAL_SIG - ), + Error(channelId, "you sent an lcss with our sig wrong"), "peer sent LastCrossSignedState with a signature that isn't ours" ) } else { ( - Error( - channelId, - HostedError.ERR_HOSTED_WRONG_REMOTE_SIG - ), + Error(channelId, "your lcss signature is wrong"), "peer sent LastCrossSignedState with an invalid signature" ) } @@ -857,10 +851,7 @@ class Channel(peerId: ByteVector) { msg match { case f: UpdateFailHtlc if (f.reason.isEmpty) => { // fail the channel - val err = Error( - channelId, - HostedError.ERR_HOSTED_WRONG_REMOTE_SIG - ) + val err = Error(channelId, "reason is empty on update_fail_htlc") sendMessage(err) ChannelMaster.database.update { data => data @@ -902,10 +893,11 @@ class Channel(peerId: ByteVector) { state.lcssNext.localBalanceMsat < MilliSatoshi(0L) || state.lcssNext.remoteBalanceMsat < MilliSatoshi(0L) ) { - val err = Error( - channelId, - HostedError.ERR_HOSTED_MANUAL_SUSPEND - ) + val err = + Error( + channelId, + "you sent an update above your available balance" + ) sendMessage(err) ChannelMaster.database.update { data => data @@ -1274,10 +1266,7 @@ class Channel(peerId: ByteVector) { .modify(_.channels.at(peerId).localErrors) .using( _ + DetailedError( - Error( - channelId, - HostedError.ERR_HOSTED_CLOSED_BY_REMOTE_PEER - ), + Error(channelId, "just mirroring your error"), None, "peer sent an error" ) @@ -1296,10 +1285,7 @@ class Channel(peerId: ByteVector) { if (!expiredOutgoingHtlcs.isEmpty) { // if we have any HTLC, we fail the channel - val err = Error( - channelId, - HostedError.ERR_HOSTED_TIMED_OUT_OUTGOING_HTLC - ) + val err = Error(channelId, "one or more outgoing htlcs have timed out") sendMessage(err) // store one error for each htlc failed in this manner diff --git a/src/main/scala/Database.scala b/src/main/scala/Database.scala index 446db16..da4b392 100644 --- a/src/main/scala/Database.scala +++ b/src/main/scala/Database.scala @@ -42,19 +42,7 @@ case class DetailedError( htlc: Option[UpdateAddHtlc], reason: String ) { - def description: String = { - val tag = error.data.take(4) - val postTagData = error.data.drop(4) - - HostedError.knownHostedCodes.get(tag.toHex) match { - case Some(code) if postTagData.isEmpty => s"hosted-code=$code" - case Some(code) => - s"hosted-code=$code, extra=${error.copy(data = postTagData).toAscii}" - case None => error.toAscii - } - } - - override def toString: String = s"$description | $reason | $htlc" + override def toString: String = s"${error.toAscii} | $reason | $htlc" } class Database(val path: Path = Paths.get("poncho").toAbsolutePath()) {