Skip to content

Send events when HTLCs settle on-chain#884

Merged
araspitzu merged 18 commits intomasterfrom
extended-api-pm
Apr 3, 2019
Merged

Send events when HTLCs settle on-chain#884
araspitzu merged 18 commits intomasterfrom
extended-api-pm

Conversation

@pm47
Copy link
Copy Markdown
Member

@pm47 pm47 commented Mar 6, 2019

This is a simpler alternative to #867, with the following limitations:

  • no OnChainRefundsDb and associated API calls
  • PaymentSettlingOnChain/PaymentLostOnChain events 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

@pm47 pm47 force-pushed the extended-api-pm branch from 663d111 to ea00496 Compare March 7, 2019 09:51
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
@araspitzu araspitzu changed the title [WIP] Send events when HTLCs settle on-chain Send events when HTLCs settle on-chain Mar 28, 2019
@araspitzu
Copy link
Copy Markdown
Contributor

TODO: update the doc

Copy link
Copy Markdown
Member Author

@pm47 pm47 left a 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")
Copy link
Copy Markdown
Member Author

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


implicit val shouldWritePretty: ShouldWritePretty = ShouldWritePretty.True

case class CustomTypeHints(custom: Map[Class[_], String]) extends TypeHints {
Copy link
Copy Markdown
Member Author

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?

Copy link
Copy Markdown
Contributor

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",
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice

}
// 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)
Copy link
Copy Markdown
Member Author

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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes LGTM

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)
Copy link
Copy Markdown
Member Author

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?

Copy link
Copy Markdown
Member

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

araspitzu and others added 5 commits March 29, 2019 16:57
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)
Copy link
Copy Markdown
Member

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 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)
Copy link
Copy Markdown
Member

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"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in 5e476fd

@araspitzu araspitzu requested a review from sstone April 2, 2019 12:11
@araspitzu
Copy link
Copy Markdown
Contributor

LGTM, i'll add the fallback address for /receive in #885

@araspitzu araspitzu merged commit 3a56ad9 into master Apr 3, 2019
@araspitzu araspitzu deleted the extended-api-pm branch April 3, 2019 09:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants