-
Notifications
You must be signed in to change notification settings - Fork 268
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Send events when HTLCs settle on-chain #884
Conversation
This is a simpler alternative to #867, with the following limitations: - no `OnChainRefundsDb` and associated API calls - `PaymentSettlingOnChain` event will be sent exactly once per payment and have less information - we don't touch `HtlcTimeoutTx` - use json4s type hints instead of manual attributes to case classes
# Conflicts: # eclair-core/src/main/scala/fr/acinq/eclair/api/Service.scala # eclair-core/src/main/scala/fr/acinq/eclair/payment/PaymentEvents.scala # eclair-core/src/test/scala/fr/acinq/eclair/api/JsonSerializersSpec.scala
TODO: update the doc |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This LGTM to me but is missing a test on PaymentSettlingOnChain
. Will take a stab at it
case received: PaymentReceived => flowInput.offer(received.paymentHash.toString) | ||
case message: PaymentFailed => flowInput.offer(Serialization.write(message)(formatsWithTypeHint)) | ||
case message: PaymentEvent => flowInput.offer(Serialization.write(message)(formatsWithTypeHint)) | ||
case other => logger.info(s"Unexpected ws message: $other") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unhandled message should be handled differently
@@ -186,4 +186,15 @@ object JsonSupport extends Json4sSupport { | |||
|
|||
implicit val shouldWritePretty: ShouldWritePretty = ShouldWritePretty.True | |||
|
|||
case class CustomTypeHints(custom: Map[Class[_], String]) extends TypeHints { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can this be put in a separate file?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it belongs here logically, it's where we define our application-wide JsonSupport and all the custom serializers.
// used to send typed messages over the websocket | ||
val formatsWithTypeHint = formats.withTypeHintFieldName("type") + | ||
CustomTypeHints(Map( | ||
classOf[PaymentSent] -> "payment-sent", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice
@@ -1247,6 +1247,11 @@ class Channel(val nodeParams: NodeParams, wallet: EclairWallet, remoteNodeId: Pu | |||
log.info(s"cannot fail overriden htlc #${add.id} paymentHash=${add.paymentHash} (origin not found)") | |||
} | |||
} | |||
// for our outgoing payments, let's send events if we know that they will settle on chain | |||
Closing | |||
.onchainOutgoingHtlcs(d.commitments.localCommit, d.commitments.remoteCommit, d.commitments.remoteNextCommitInfo.left.toOption.map(_.nextRemoteCommit), tx) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@sstone can you double check this? this is quite sensitive
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes LGTM
eclair-core/src/main/scala/fr/acinq/eclair/channel/Helpers.scala
Outdated
Show resolved
Hide resolved
eclair-core/src/main/scala/fr/acinq/eclair/channel/Helpers.scala
Outdated
Show resolved
Hide resolved
@@ -228,10 +228,10 @@ object PaymentRequest { | |||
f.version match { | |||
case 17 if prefix == "lnbc" => Base58Check.encode(Base58.Prefix.PubkeyAddress, data) | |||
case 18 if prefix == "lnbc" => Base58Check.encode(Base58.Prefix.ScriptAddress, data) | |||
case 17 if prefix == "lntb" => Base58Check.encode(Base58.Prefix.PubkeyAddressTestnet, data) | |||
case 18 if prefix == "lntb" => Base58Check.encode(Base58.Prefix.ScriptAddressTestnet, data) | |||
case 17 if prefix == "lntb" || prefix == "lnbcrt" => Base58Check.encode(Base58.Prefix.PubkeyAddressTestnet, data) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@sstone can you double check this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's correct because Base58 addresses on testnet and regtest have the same prefix, but not Bech32 addresses :(
But I think handling "lnbcrt" on a separate line looks a bit cleaner
…gy for websocket queue.
…d messages be handled by akka's default
Co-Authored-By: araspitzu <a.raspitzu@protonmail.com>
Co-Authored-By: pm47 <pm47@users.noreply.github.com>
@@ -228,10 +228,10 @@ object PaymentRequest { | |||
f.version match { | |||
case 17 if prefix == "lnbc" => Base58Check.encode(Base58.Prefix.PubkeyAddress, data) | |||
case 18 if prefix == "lnbc" => Base58Check.encode(Base58.Prefix.ScriptAddress, data) | |||
case 17 if prefix == "lntb" => Base58Check.encode(Base58.Prefix.PubkeyAddressTestnet, data) | |||
case 18 if prefix == "lntb" => Base58Check.encode(Base58.Prefix.ScriptAddressTestnet, data) | |||
case 17 if prefix == "lntb" || prefix == "lnbcrt" => Base58Check.encode(Base58.Prefix.PubkeyAddressTestnet, data) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's correct because Base58 addresses on testnet and regtest have the same prefix, but not Bech32 addresses :(
But I think handling "lnbcrt" on a separate line looks a bit cleaner
case version if prefix == "lnbc" => Bech32.encodeWitnessAddress("bc", version, data) | ||
case version if prefix == "lntb" => Bech32.encodeWitnessAddress("tb", version, data) | ||
case version if prefix == "lntb" || prefix == "lnbcrt" => Bech32.encodeWitnessAddress("tb", version, data) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bech32 prefix should be "bcrt", not "tb"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done in 5e476fd
LGTM, i'll add the fallback address for /receive in #885 |
This is a simpler alternative to #867, with the following limitations:
OnChainRefundsDb
and associated API callsPaymentSettlingOnChain
/PaymentLostOnChain
events will be sentexactly once per payment and have less information
HtlcTimeoutTx