HTLCs#27
Conversation
- LICENSE: change from MIT to AGPL (.Kiss fork) - Change package name suffix from .Core to .Kiss (skipping native build)
According to lightning spec, if the receiver agrees with the fee, it should reply with a closing_signed with the same fee_satoshis value so to transport this message we need to pass it inside MutualClosePerformed event, to be transported to the other peer. Source: https://github.com/lightningnetwork/lightning-rfc/blob/master/02-peer-protocol.md#requirements-6 Upstream PR: joemphilips#168
Hmac should be written during the packet serialization and not during the payload serialization
All-zero initial packets should only be used for generating test vectors because of possible privacy leak. "Create packet (reference test vector)" testcase updated to new testcases provided by the RFC repo to meet this change of spec. See more: lightning/bolts@8dd0b75 https://github.com/lightningnetwork/lightning-rfc/blob/master/04-onion-routing.md#packet-construction
Secret field inside TLVPayload's PaymentData is PaymentSecret and not PaymentPreimage and It's used for mpp.
| channelPrivKeys.SignHtlcTx htlc.Value localPerCommitmentPoint | ||
| ) | ||
| localHtlcSigsAndHTLCTxs |> List.map(fst), localHtlcSigsAndHTLCTxs |> List.map(snd) |> Seq.cast<IHTLCTx> |> List.ofSeq | ||
| let HTLCTxsAndSignatures = |
There was a problem hiding this comment.
local vars should be camelCase, not PascalCase; now, I understand this var name starts with "HTLC" which is an acronym, but I like to do what the .NET BCL do wrt naming sometimes: HTTP -> Http, therefore HTLC -> Htlc, so here it can be htlcTxsAndSignatures
| : TransactionSignature * PSBT = | ||
| let htlcPrivKey = perCommitmentPoint.DeriveHtlcPrivKey this.HtlcBasepointSecret | ||
| let htlcPubKey = htlcPrivKey.HtlcPubKey() | ||
| psbt.Settings.CustomBuilderExtensions <- ([new HTLCReceivedExtensions() :> BuilderExtension; new HTLCOfferedExtensions():> BuilderExtension] |> Seq.ofList) |
There was a problem hiding this comment.
nits:
- missing a space before
:> - please split line in many, it's too long
- are HTLCReceivedExtensions and HTLCOfferedExtensions IDisposable? if not, then remove the
newkeyword
| assert (stream.Length = padding1.Length) | ||
| xor(padding1, stream) | ||
| ) [||] | ||
| let rec internal generateFiller (keyType: string) (payloads: byte[] list) (sharedSecrets: Key list) = |
There was a problem hiding this comment.
use array<byte> and list<Key> pls
| // set of filler bytes by using chacha20 with a key derived from the session | ||
| // key. | ||
| let DeterministicPacketFiller (sessionKey: Key) = | ||
| generateStream(generateKey("pad",sessionKey.ToBytes()), 1300) |
There was a problem hiding this comment.
- 1300: magic number? pls put in a constant
- space after comma
| // instances that required deterministic packet generation. | ||
| [<Obsolete("BlankPacketFiller is obsolete, see here: https://github.com/lightningnetwork/lightning-rfc/commit/8dd0b75809c9a7498bb9031a6674e5f58db509f4", false)>] | ||
| let BlankPacketFiller _= | ||
| Array.zeroCreate 1300 |
| } | ||
| with | ||
| static member Create (sessionKey: Key, pubKeys: PubKey list, payloads: byte[] list, ad: byte[]) = | ||
| static member Create (sessionKey: Key, pubKeys: PubKey list, payloads: byte[] list, ad: byte[], initialPacketFiller: Key -> byte[]) = |
| @@ -1,4 +1,4 @@ | |||
| <Project Sdk="Microsoft.NET.Sdk" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | |||
| <Project Sdk="Microsoft.NET.Sdk" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | |||
There was a problem hiding this comment.
nit: no need to change this line
| UInt64.FromTruncatedBytes(tlv.Value) | ||
| |> LNMoney.MilliSatoshis | ||
| |> AmountToForward | ||
| | 4UL -> | ||
| NBitcoin.Utils.ToUInt32(tlv.Value, false) | ||
| UInt32.FromTruncatedBytes(tlv.Value) |
There was a problem hiding this comment.
no need for parens in the 2 lines of both hunks above
| ScriptCoin(coin, redeem) | ||
| let dest = Scripts.toLocalDelayed localRevocationPubKey toLocalDelay localDelayedPaymentPubKey | ||
| // we have already done dust limit check above | ||
| txb.Extensions.Add (new HTLCReceivedExtensions()) |
There was a problem hiding this comment.
is HTLCReceivedExtensions IDisposable? if not, then remove the new
| buf | ||
|
|
||
| member private x.GetLeadingZerosCount() = | ||
| if (x = 0UL) then |
| 3 | ||
| else if (x &&& 0xffff000000000000UL = 0UL) then | ||
| 2 | ||
| else if (x &&& 0xff00000000000000UL = 0UL) then |
There was a problem hiding this comment.
please replace all else if occurrences with elif
There was a problem hiding this comment.
(and no need for parenthesis in all lines above)
| member x.GetTruncatedBytes() = | ||
| let numZeros = | ||
| x.GetLeadingZerosCount() | ||
| x.GetBytesBigEndian() |> Array.skip(numZeros) |
There was a problem hiding this comment.
no need for parenthesis at the end
| 3 | ||
| else if (x &&& 0xffff0000u = 0u) then | ||
| 2 | ||
| else if (x &&& 0xff000000u = 0u) then |
There was a problem hiding this comment.
same here about parenthesis and elif
| member x.GetTruncatedBytes() = | ||
| let numZeros = | ||
| x.GetLeadingZerosCount() | ||
| x.GetBytesBigEndian() |> Array.skip(numZeros) |
| | Ok data -> Some data | ||
| | Error _consumeAllError -> None | ||
|
|
||
| type internal HTLCOfferedExtensions() = |
There was a problem hiding this comment.
rename to HtlcOfferedExtensions as per previous suggestion
| |> expectTransactionError | ||
| let! finalizedCommitTx = tmp | ||
| let sortedHTLCTXs = Helpers.sortBothHTLCs htlcTimeoutTxs htlcSuccessTxs | ||
| let sortedHTLCTXs = Helpers.sortBothHTLCs htlcTimeoutTxs htlcSuccessTxs |
| |> List.ofSeq | ||
| |> Seq.ofList | ||
|
|
||
| Console.WriteLine(JsonConvert.SerializeObject(ops)) |
There was a problem hiding this comment.
remove Console.WriteLine? if you leave it there, explain why, and use 2 parenthesis instead of 4
| // should return null, indicating to NBitcoin that the sigScript | ||
| // could not be generated. | ||
| match pubKey with | ||
| | null -> null |
There was a problem hiding this comment.
let's use Option.ofObj instead of checking for null
| let remoteHtlcSig = signer.Sign (parameters.RemoteHtlcPubKey.RawPubKey()) | ||
| Script [ | ||
| Op.GetPushOp (remoteHtlcSig.ToBytes()) | ||
| ] |
There was a problem hiding this comment.
there's duplication in these 2 blocks, let's have just 1 block
| |> List.ofSeq | ||
| |> Seq.ofList | ||
|
|
||
| Console.WriteLine(JsonConvert.SerializeObject(ops)) |
PSBT sign function needs transaction builder for any non-predefined script template
f817da9 to
0340b0b
Compare
0389f6a to
60d2401
Compare
419cd8d to
f0461b4
Compare
37fe5af to
1f418fe
Compare
bd34034 to
b67e13f
Compare
Work in progress...