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

[WIP] funding: add publisher #6400

Draft
wants to merge 8 commits into
base: master
Choose a base branch
from

Conversation

ellemouton
Copy link
Collaborator

@ellemouton ellemouton commented Apr 11, 2022

Fixes #4760

Fixes #386

Fixes #7868

The publisher does a few tx checks (sanity, standard, mempool test (not implemented yet)) before actually attempting to publish the transaction. Errors from each call is wrapped so that it is easy to reason about for the caller.

Still a WIP. Looking for approach comments. The last commit is a bit messy but i will clean it up after approach ACK.

Context:

The funding manager calls Publish at 2 points:

  1. during funding flow handleFundingSigned, after persisting the channel and deleting (not canceling) the reservation context.
  2. on startup: it tries to broadcast the funding tx without having a lock on the inputs.

I think we need to manage make decisions differently for each of the above scenarios:

  1. For this scenario: we can safety abort the process if:

    • sanity check fails
    • (standardness check or mempool test check fails) && this was not an externally constructed tx. If this was externally funded then we should continue to monitor the channel.

    When we abort, we should make sure to release the locks on the utxos.

  2. In this scenario, we need to be a bit more careful because at this point we dont know if the tx has ever been published before. So in this case, we only abort if we get a sanity check error OR we get a ErrDoubleSpend error.

Scope?:

The following still needs to be done. Should any of these be included in this PR?

  • need to thread bitcoind testmempool call through to its rpc
  • should add a testmempool fund to btcd's mempool struct and add the call to its rpc so we can call it
  • for all the cases that we are lenient and dont fail the tx, we should instead occasionally try to rebroadcast it and after a few blocks, maybe we then release the inputs and wait for double spend. (note ,this double-spend-wait already happens in the startup scenario since the inputs are not locked. But it still requires the re-broadcasting logic)

Depends on btcsuite/btcd#1840

@ellemouton
Copy link
Collaborator Author

cc @yyforyongyu & @Crypt-iQ : looking for some approach comments before continuing. Pls see description :)

@Crypt-iQ
Copy link
Collaborator

on startup: it tries to broadcast the funding tx without having a lock on the inputs.

This seems like a bug?

@yyforyongyu
Copy link
Member

Overall looks good.

The funding manager calls Publish at 2 points:

There's another place we call PublishTransaction in batch funding.

sanity check fails

Wonder what these checks are. Are they ln-specific or bitcoin-specific? Do we have similar checks in PublishTransaction already?

@Crypt-iQ
Copy link
Collaborator

Wonder what these checks are. Are they ln-specific or bitcoin-specific? Do we have similar checks in PublishTransaction already?

I'm guessing this is the lite version of bitcoin transaction standardness - I think PublishTransaction calls it

(standardness check or mempool test check fails) && this was not an externally constructed tx. If this was externally funded then we should continue to monitor the channel.

why not abort if the tx is non-standard? if the mempool accept API fails due to ancestor limits / is full, we should probably keep the channel. AFAIK the only way to get tx standardness in bitcoind without broadcasting the transaction is to call the mempool accept API - maybe there's another RPC though.


// calcPastMedianTime calculates the median time of the previous few blocks
// prior to, and including, the block node.
func calcPastMedianTime(chain chain.Interface) (time.Time, error) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

i dont think this should be copied

@Crypt-iQ
Copy link
Collaborator

Crypt-iQ commented Jun 1, 2022

on startup: it tries to broadcast the funding tx without having a lock on the inputs.

This seems like a bug?

roasbeef said the locks are persisted and don't need to be re-acquired on startup, so this actually seems like correct behavior?

@lightninglabs-deploy
Copy link

@ellemouton, remember to re-request review from reviewers when ready

@ellemouton
Copy link
Collaborator Author

closing for the time being as im not actively working on this

@Roasbeef
Copy link
Member

Roasbeef commented Aug 7, 2023

Re-opening as related to #7868. I think push the branch to origin, that way someone can take over just by building off that branch.

@Roasbeef Roasbeef reopened this Aug 7, 2023
@ellemouton
Copy link
Collaborator Author

I think push the branch to origin, that way someone can take over just by building off that branch.

done!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
6 participants