Skip to content

Commit

Permalink
Use satoshi for htlc ordering (#1806)
Browse files Browse the repository at this point in the history
Fixes #1804.
  • Loading branch information
pm47 authored May 17, 2021
1 parent 0805d51 commit ec276f8
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ object Transactions {
* See https://github.com/lightningnetwork/lightning-rfc/issues/448#issuecomment-432074187.
*/
def sort(a: CommitmentOutputLink[CommitmentOutput], b: CommitmentOutputLink[CommitmentOutput]): Boolean = (a.commitmentOutput, b.commitmentOutput) match {
case (OutHtlc(OutgoingHtlc(htlcA)), OutHtlc(OutgoingHtlc(htlcB))) if htlcA.paymentHash == htlcB.paymentHash && htlcA.amountMsat == htlcB.amountMsat =>
case (OutHtlc(OutgoingHtlc(htlcA)), OutHtlc(OutgoingHtlc(htlcB))) if htlcA.paymentHash == htlcB.paymentHash && htlcA.amountMsat.truncateToSatoshi == htlcB.amountMsat.truncateToSatoshi =>
htlcA.cltvExpiry <= htlcB.cltvExpiry
case _ => LexicographicalOrdering.isLessThan(a.output, b.output)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -347,8 +347,8 @@
local_feerate_per_kw: 253
# HTLC 0 received amount 1000000 wscript 76a91414011f7254d96b819c76986c277d115efce6f7b58763ac67210394854aa6eab5b2a8122cc726e9dded053a2184d88256816826d6231c068d4a5b7c8201208763a914b8bcb07f6344b42ab04250c86a6e8b75d3fdbbc688527c21030d417a46946384f88d5f3337267c5e579765875dc4daca813e21734b140639e752ae677502f401b175ac6868
# HTLC 5 offered amount 5000000 wscript 76a91414011f7254d96b819c76986c277d115efce6f7b58763ac67210394854aa6eab5b2a8122cc726e9dded053a2184d88256816826d6231c068d4a5b7c820120876475527c21030d417a46946384f88d5f3337267c5e579765875dc4daca813e21734b140639e752ae67a9142002cc93ebefbb1b73f0af055dcc27a0b504ad7688ac6868
# HTLC 6 offered amount 5000000 wscript 76a91414011f7254d96b819c76986c277d115efce6f7b58763ac67210394854aa6eab5b2a8122cc726e9dded053a2184d88256816826d6231c068d4a5b7c820120876475527c21030d417a46946384f88d5f3337267c5e579765875dc4daca813e21734b140639e752ae67a9142002cc93ebefbb1b73f0af055dcc27a0b504ad7688ac6868
# HTLC 5 and 6 have CLTV 505 and 506, respectively, and preimage 0505050505050505050505050505050505050505050505050505050505050505
# HTLC 6 offered amount 5000001 wscript 76a91414011f7254d96b819c76986c277d115efce6f7b58763ac67210394854aa6eab5b2a8122cc726e9dded053a2184d88256816826d6231c068d4a5b7c820120876475527c21030d417a46946384f88d5f3337267c5e579765875dc4daca813e21734b140639e752ae67a9142002cc93ebefbb1b73f0af055dcc27a0b504ad7688ac6868
# HTLC 5 and 6 have CLTV 506 and 505, respectively, and preimage 0505050505050505050505050505050505050505050505050505050505050505
output commit_tx: 02000000000101bef67e4e2fb9ddeeb3461973cd4c62abb35050b1add772995b820b584a488489000000000038b02b8005e80300000000000022002052bfef0479d7b293c27e0f1eb294bea154c63a3294ef092c19af51409bce0e2a8813000000000000220020305c12e1a0bc21e283c131cea1c66d68857d28b7b2fce0a6fbc40c164852121b8813000000000000220020305c12e1a0bc21e283c131cea1c66d68857d28b7b2fce0a6fbc40c164852121bc0c62d0000000000160014ccf1af2f2aabee14bb40fa3851ab2301de843110a79f6a00000000002200204adb4e2f00643db396dd120d4e7dc17625f5f2c11a40d857accc862d6b7dd80e04004730440220586f17b3f3f6eec96a0dc7040f1a33174c707e032010421fa1965497cd1c81e602204476e6a4cc17d433e8ad82edff2ffa47c954ecb52aad9cc34382befb66f6e00001473044022069797b84fad1e0e7b02e1edeec80cb6e0b6f01170700bca273788715f55e0c560220260833550768b1db3ed88f8c005cf2560821b1879ec69834cd9765de25ec350601475221023da092f6980e58d2c037173180e9a465476026ee50f96695963e8efe436f54eb21030e9f7b623d2ccc7c9bd44d66d5ce21ce504c0acf6385a132cec6d3c39fa711c152ae3e195220
# local_htlc_signature = 3044022077803ffab08308ac6ceaba6024855029f31d88e1420ece6aac1cf35258efb42702207db2cfe24de7b19a6e0e95082c595643fe18b7e0f0071297b2bb940807e774d2
# remote_htlc_signature = 304502210087be93ccb1fd373ebd489c2dbe5f3a95a5cd7b173255f63367d063843f0ed263022027de0683bc4ac9afe1cdff48f16bb1a8e27789328b534e1cc39bf4dd0448ed69
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -347,8 +347,8 @@
local_feerate_per_kw: 253
# HTLC 0 received amount 1000000 wscript 76a91414011f7254d96b819c76986c277d115efce6f7b58763ac67210394854aa6eab5b2a8122cc726e9dded053a2184d88256816826d6231c068d4a5b7c8201208763a914b8bcb07f6344b42ab04250c86a6e8b75d3fdbbc688527c21030d417a46946384f88d5f3337267c5e579765875dc4daca813e21734b140639e752ae677502f401b175ac6868
# HTLC 5 offered amount 5000000 wscript 76a91414011f7254d96b819c76986c277d115efce6f7b58763ac67210394854aa6eab5b2a8122cc726e9dded053a2184d88256816826d6231c068d4a5b7c820120876475527c21030d417a46946384f88d5f3337267c5e579765875dc4daca813e21734b140639e752ae67a9142002cc93ebefbb1b73f0af055dcc27a0b504ad7688ac6868
# HTLC 6 offered amount 5000000 wscript 76a91414011f7254d96b819c76986c277d115efce6f7b58763ac67210394854aa6eab5b2a8122cc726e9dded053a2184d88256816826d6231c068d4a5b7c820120876475527c21030d417a46946384f88d5f3337267c5e579765875dc4daca813e21734b140639e752ae67a9142002cc93ebefbb1b73f0af055dcc27a0b504ad7688ac6868
# HTLC 5 and 6 have CLTV 505 and 506, respectively, and preimage 0505050505050505050505050505050505050505050505050505050505050505
# HTLC 6 offered amount 5000001 wscript 76a91414011f7254d96b819c76986c277d115efce6f7b58763ac67210394854aa6eab5b2a8122cc726e9dded053a2184d88256816826d6231c068d4a5b7c820120876475527c21030d417a46946384f88d5f3337267c5e579765875dc4daca813e21734b140639e752ae67a9142002cc93ebefbb1b73f0af055dcc27a0b504ad7688ac6868
# HTLC 5 and 6 have CLTV 506 and 505, respectively, and preimage 0505050505050505050505050505050505050505050505050505050505050505
output commit_tx: 02000000000101bef67e4e2fb9ddeeb3461973cd4c62abb35050b1add772995b820b584a488489000000000038b02b8005e80300000000000022002052bfef0479d7b293c27e0f1eb294bea154c63a3294ef092c19af51409bce0e2a8813000000000000220020305c12e1a0bc21e283c131cea1c66d68857d28b7b2fce0a6fbc40c164852121b8813000000000000220020305c12e1a0bc21e283c131cea1c66d68857d28b7b2fce0a6fbc40c164852121bc0c62d0000000000160014cc1b07838e387deacd0e5232e1e8b49f4c29e484a79f6a00000000002200204adb4e2f00643db396dd120d4e7dc17625f5f2c11a40d857accc862d6b7dd80e0400483045022100ef89cb399f7ced1b146709599aa8400927f1bdb673103cf1852a87c0e98f8c7c02202e63734c5dec54694fcd6c63907f7d2d73c28626771edf3c999d195d3e0711370147304402206a3e262d6dea521491f84d18abc6abe574e95b036d80fbafb97118651e69646c02205d9cf95aaad1bd5d08e1f64c306a719a606273172a343bd10ec073dcabbff26401475221023da092f6980e58d2c037173180e9a465476026ee50f96695963e8efe436f54eb21030e9f7b623d2ccc7c9bd44d66d5ce21ce504c0acf6385a132cec6d3c39fa711c152ae3e195220
# local_htlc_signature = 3045022100ecdff5abb3e083ca99fa6b24b37378bcb13416c111d870e7d1158a1f010d1e0002205a26b4f15e61965e130aabc9a538228d5706faf76ed1f7018962771428c9fa3f01
# remote_htlc_signature = 304402205526a4f4f5ec29f48133e35b90b3acb10d498c0e984230356d36a232ec3a053e0220495af5d99e309440f9d5cf728ae241316ad0e92f57854989c3b25aba31197d2401
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -392,8 +392,8 @@ trait TestVectorsSpec extends AnyFunSuite with Logging {
val preimage = hex"0505050505050505050505050505050505050505050505050505050505050505"
val someHtlcs = Seq(
IncomingHtlc(UpdateAddHtlc(ByteVector32.Zeroes, 0, 1000000.msat, Crypto.sha256(paymentPreimages(0)), CltvExpiry(500), TestConstants.emptyOnionPacket)),
OutgoingHtlc(UpdateAddHtlc(ByteVector32.Zeroes, 0, 5000000.msat, Crypto.sha256(preimage), CltvExpiry(505), TestConstants.emptyOnionPacket)),
OutgoingHtlc(UpdateAddHtlc(ByteVector32.Zeroes, 0, 5000000.msat, Crypto.sha256(preimage), CltvExpiry(506), TestConstants.emptyOnionPacket))
OutgoingHtlc(UpdateAddHtlc(ByteVector32.Zeroes, 0, 5000000.msat, Crypto.sha256(preimage), CltvExpiry(506), TestConstants.emptyOnionPacket)),
OutgoingHtlc(UpdateAddHtlc(ByteVector32.Zeroes, 1, 5000001.msat, Crypto.sha256(preimage), CltvExpiry(505), TestConstants.emptyOnionPacket))
)

val (commitTx, htlcTxs) = run(name, someHtlcs.toSet[DirectedHtlc])
Expand Down

0 comments on commit ec276f8

Please sign in to comment.