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 |
pm47
left a comment
There was a problem hiding this comment.
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.
Unhandled message should be handled differently
|
|
||
| implicit val shouldWritePretty: ShouldWritePretty = ShouldWritePretty.True | ||
|
|
||
| case class CustomTypeHints(custom: Map[Class[_], String]) extends TypeHints { |
There was a problem hiding this comment.
Can this be put in a separate file?
There was a problem hiding this comment.
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", |
| } | ||
| // 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.
@sstone can you double check this? this is quite sensitive
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
| 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.
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>
| 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.
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 18 if prefix == "lntb" || prefix == "lnbcrt" => Base58Check.encode(Base58.Prefix.ScriptAddressTestnet, data) | ||
| 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.
Bech32 prefix should be "bcrt", not "tb"
|
LGTM, i'll add the fallback address for /receive in #885 |
This is a simpler alternative to #867, with the following limitations:
OnChainRefundsDband associated API callsPaymentSettlingOnChain/PaymentLostOnChainevents will be sentexactly once per payment and have less information
HtlcTimeoutTx