Skip to content
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

We shouldn't use hardcoded values here #19

Open
wants to merge 7 commits into
base: geewalletLightningMilestone4
Choose a base branch
from

Conversation

aarani
Copy link

@aarani aarani commented Dec 10, 2020

This code assumes that the person who broadcasted the commitment transaction is always the funder and the person who is trying to spend the broadcasted remote commitment is always the fundee. This passed geewallet CI tests because that's the only case we test in geewallet end-to-end tests.

knocte and others added 6 commits November 13, 2020 11:38
- LICENSE: change from MIT to AGPL (.Kiss fork)
- Change package name suffix from .Core to .Kiss
(skipping native build)
This commit adds the following:

* getFundsFromForceClosingTransaction

This function takes an on-chain transaction which spends the channel
funds and tries to extract spendable utxos out of it. If successful, it
returns a TransactionBuilder with txins added for each spendable output
of the closing transaction and with the necessary keys and
BuilderExtension added. To recover funds from a broadcast commitment
transaction you just need to call this function, add outputs to the
returned TransactionBuilder to send the money where you want it to go,
then broadcast the transaction.

* CommitmentToLocalBuilderExtension

This is an NBitcoin BuilderExtension that tells TransactionBuilder how
to recognise and sign lightning commitment transaction to_local outputs.
getFundsFromForceClosingTransaction adds this extension to the
TransactionBuilder it returns if it's needed to sign the transaction.

* SeqConsumer

A computation expression which makes it easy to write code that consumes
a sequence one element at a time.

* OptionCE

A computation expression for creation options. Similar to the result
computation expression.
It seems that these attributes can cause this compilation error in F#4.0:
error FS0927: The kind of the type specified by its attributes does not match the kind implied by its definition

Newer versions of F# (like 4.5 or even newer, like the one being used
by .NETCore to build the binary that is later published in nuget) allow
compiling this code with no issues, but if you reference the generated
assembly later from an old F# compiler, it could generate exceptions at
runtime, e.g.: System.BadFormatImageException (or other types) whose
inner exception could be the following:

System.TypeLoadException : Could not load type of field 'GWallet.Backend.UtxoCoin.Lightning.SerializedChannel:MinSafeDepth@' (6) due to: Expected reference type but got type kind 17

FSharp.Core's Result type is also affected by this so in this commit we
create a replacement for it that is only used in the BouncyCastle build
(which we now rename as 'Portability' build).

Forward-ported from a4a59d0

Co-authored-by: Andres G. Aragoneses <knocte@gmail.com>
Co-authored-by: Andrew Cann <shum@canndrew.org>
This NBitcoin issue: MetacoSA/NBitcoin#931
somehow still hasn't been fixed properly (our geewallet CI still encounters it,
surprisingly).

So let's reapply the workaround[1] that we had removed[2].

[1] joemphilips@d813a97
[2] joemphilips@256893c
In this commit, we add a function to prepare a Punishment Tx for later
broadcasting incase of illegal broadcasting of a revoked transaction.
@knocte
Copy link
Member

knocte commented Dec 10, 2020

@canndrew please review

@knocte
Copy link
Member

knocte commented Dec 10, 2020

We shouldn't use hardcoded values here

It's not wise to use the word here in a commit message title. How about Channel/CommitmentsModule: avoid hardcoding values

@knocte
Copy link
Member

knocte commented Dec 10, 2020

This passed our test because that's the only case we test in our end-to-end tests.

Take in account at some point I'll be proposing our commits to upstream DNL, and this commit message seems to be implicitly referring to geewallet. I guess you mean passed our test -> passed geewallet CI tests and end-to-end tests -> geewallet end-to-end tests.

@knocte
Copy link
Member

knocte commented Dec 10, 2020

I've just realised that m4 is revocation, not channel closing; so really this PR should be retargeted to m3

@aarani
Copy link
Author

aarani commented Dec 10, 2020

I've just realised that m4 is revocation, not channel closing; so really this PR should be retargeted to m3

but the code that this bug got introduced is in m4

@knocte
Copy link
Member

knocte commented Dec 10, 2020

So if force-closing is implemented from tthe m3 branch of this repo, it wouldn't have this bug?

@knocte
Copy link
Member

knocte commented Dec 10, 2020

but the code that this bug got introduced

what's the exact commit? (I ask because I want to check if it's in DNL upstream)

@aarani
Copy link
Author

aarani commented Dec 10, 2020

So if force-closing is implemented from the m3 branch of this repo, it wouldn't have this bug?

the whole "spending the commitment transactions" code is in m4 you can't implement force close in m3 without backporting that commit

@knocte
Copy link
Member

knocte commented Dec 11, 2020

That commit is implementing revocation. Force-closing is a different concept that doesn't need revocation for it to work. If there's any subset part of that commit, though, that needs to be there for force-closing to work, then it can be implemented by Andrew in the m3 branch (and later I will rebase that m4 commit on top of that).

@canndrew
Copy link
Member

This looks good to me. Thanks for picking up on it.

This code assumes that the person who broadcasted
the commitment transaction is always the funder and
the person who is trying to spend the broadcasted
remote commitment is always the fundee.
This passed geewallet CI tests because that's
the only case we test in geewallet end-to-end tests.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants