Skip to content

Instantly share code, notes, and snippets.

@joschisan
Last active April 17, 2024 16:56
Show Gist options
  • Save joschisan/21e8faa5839ef372138fdbf80ffc64f9 to your computer and use it in GitHub Desktop.
Save joschisan/21e8faa5839ef372138fdbf80ffc64f9 to your computer and use it in GitHub Desktop.

SendStates

graph LR

Funding -- funding transaction is rejected --> Failure
Funding -- funding transaction is accepted --> Funded
Funded -- payment attempt expires --> Refunding
Funded -- gateway cancels payment attempt --> Refunding
Funded -- payment is confirmed  --> Success
Refunding -- payment is confirmed --> Success
Refunding -- ecash is minted --> Refunded
Refunding -- minting ecash fails --> Failure

Loading

ReceiveStates

graph LR

Pending -- payment is confirmed --> Claiming
Pending -- invoice expires --> Expired
Claiming -- ecash is minted --> Claimed
Claiming -- minting ecash fails --> Failure
Loading
@m1sterc001guy
Copy link

create a state transition that awaits the outgoing contract to be claimed with the preimage

Is this state transition necessary? I thought the gateway would return to the client the preimage, then the client would present the preimage to the federation? My thinking is that the last transition (waiting on the gateway to return the preimage or the forfeit signature) is sufficient.

if we obtain the actual preimage we are done, otherwise we can be sure that the contract could not have been claimed by the client since it was invalid and can claim it ourselves with the decrypted preimage as a proof of misbehavior on the clients side

Refresh my memory on this part. I understand that it is now possible to prove to the federation that the client did not supply a valid preimage. Is there a punishment in this case? What do you mean by "claim it ourselves"?

@joschisan
Copy link
Author

My thinking is that the last transition (waiting on the gateway to return the preimage or the forfeit signature) is sufficient.

But what if the gateway would claim the htlc with the preimage but does not return it to the client? If the HTLC is claimed we need to consider the payment successful no matter what the gateway returns.

No there is no punishment, claim it ourselves meant the gateway gets its funding refunded.

@m1sterc001guy
Copy link

Got it, I keep forgetting that either the client or the gateway can submit these transactions.

If that's the case, what is the use case for the gateway returning the preimage/forfeit signature back to the client? Couldn't it just construct/submit these transactions itself?

@joschisan
Copy link
Author

it returns the preimage as a response to the post request so the payment can be shown to the user as settled as quickly as possible.
The forfeit signature is needed to proof to the federation that the gateway agrees to cancel the outgoing contract.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment