Skip to content

Commit

Permalink
use human-readable errors instead of cryptic codes.
Browse files Browse the repository at this point in the history
  • Loading branch information
fiatjaf committed Sep 27, 2022
1 parent a7c0ff5 commit 2054d76
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 37 deletions.
34 changes: 10 additions & 24 deletions src/main/scala/Channel.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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"
)
Expand All @@ -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
Expand Down
14 changes: 1 addition & 13 deletions src/main/scala/Database.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down

0 comments on commit 2054d76

Please sign in to comment.