-
Notifications
You must be signed in to change notification settings - Fork 2.3k
conctractcourt: check sweep sanity + reliable publication #1936
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
Merged
Roasbeef
merged 4 commits into
lightningnetwork:master
from
cfromknecht:cnct-sane-txn-reliable-pub
Oct 25, 2018
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
b7aebd9
cnct/contract_resolvers: reliably publish commit sweep
cfromknecht 682c4c9
cnct/contract_resolvers: reliably publish htlc success sweep
cfromknecht f957b78
cnct/contract_resolvers: ignore duplicate publication error
cfromknecht f9cec4a
cnct/contract_resolvers: propagate checkpoint failures
cfromknecht File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -171,6 +171,7 @@ func (h *htlcTimeoutResolver) Resolve() (ContractResolver, error) { | |
|
|
||
| if err := h.Checkpoint(h); err != nil { | ||
| log.Errorf("unable to Checkpoint: %v", err) | ||
| return nil, err | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -481,23 +482,24 @@ func (h *htlcSuccessResolver) Resolve() (ContractResolver, error) { | |
| log.Infof("%T(%x): crafted sweep tx=%v", h, | ||
| h.payHash[:], spew.Sdump(h.sweepTx)) | ||
|
|
||
| // With the sweep transaction confirmed, we'll now | ||
| // With the sweep transaction signed, we'll now | ||
| // Checkpoint our state. | ||
| if err := h.Checkpoint(h); err != nil { | ||
| log.Errorf("unable to Checkpoint: %v", err) | ||
| } | ||
|
|
||
| // Finally, we'll broadcast the sweep transaction to | ||
| // the network. | ||
| // | ||
| // TODO(roasbeef): validate first? | ||
| if err := h.PublishTx(h.sweepTx); err != nil { | ||
| log.Infof("%T(%x): unable to publish tx: %v", | ||
| h, h.payHash[:], err) | ||
| return nil, err | ||
| } | ||
| } | ||
|
|
||
| // Regardless of whether an existing transaction was found or newly | ||
| // constructed, we'll broadcast the sweep transaction to the | ||
| // network. | ||
| err := h.PublishTx(h.sweepTx) | ||
| if err != nil && err != lnwallet.ErrDoubleSpend { | ||
| log.Infof("%T(%x): unable to publish tx: %v", | ||
| h, h.payHash[:], err) | ||
| return nil, err | ||
| } | ||
|
|
||
| // With the sweep transaction broadcast, we'll wait for its | ||
| // confirmation. | ||
| sweepTXID := h.sweepTx.TxHash() | ||
|
|
@@ -535,7 +537,8 @@ func (h *htlcSuccessResolver) Resolve() (ContractResolver, error) { | |
| // the claiming process. | ||
| // | ||
| // TODO(roasbeef): after changing sighashes send to tx bundler | ||
| if err := h.PublishTx(h.htlcResolution.SignedSuccessTx); err != nil { | ||
| err := h.PublishTx(h.htlcResolution.SignedSuccessTx) | ||
| if err != nil && err != lnwallet.ErrDoubleSpend { | ||
| return nil, err | ||
| } | ||
|
|
||
|
|
@@ -558,6 +561,7 @@ func (h *htlcSuccessResolver) Resolve() (ContractResolver, error) { | |
|
|
||
| if err := h.Checkpoint(h); err != nil { | ||
| log.Errorf("unable to Checkpoint: %v", err) | ||
| return nil, err | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -1258,18 +1262,33 @@ func (c *commitSweepResolver) Resolve() (ContractResolver, error) { | |
| log.Infof("%T(%v): sweeping commit output with tx=%v", c, | ||
| c.chanPoint, spew.Sdump(c.sweepTx)) | ||
|
|
||
| // Finally, we'll broadcast the sweep transaction to the | ||
| // network. | ||
| if err := c.PublishTx(c.sweepTx); err != nil { | ||
| // With the sweep transaction constructed, we'll now Checkpoint | ||
| // our state. | ||
| if err := c.Checkpoint(c); err != nil { | ||
| log.Errorf("unable to Checkpoint: %v", err) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Print resolvertype+channelpoint?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We'll print the chan point in the char arb. |
||
| return nil, err | ||
| } | ||
|
|
||
| // With the sweep transaction checkpointed, we'll now publish | ||
| // the transaction. Upon restart, the resolver will immediately | ||
| // take the case below since the sweep tx is checkpointed. | ||
| err := c.PublishTx(c.sweepTx) | ||
| if err != nil && err != lnwallet.ErrDoubleSpend { | ||
| log.Errorf("%T(%v): unable to publish sweep tx: %v", | ||
| c, c.chanPoint, err) | ||
| return nil, err | ||
| } | ||
|
|
||
| // With the sweep transaction confirmed, we'll now Checkpoint | ||
| // our state. | ||
| if err := c.Checkpoint(c); err != nil { | ||
| log.Errorf("unable to Checkpoint: %v", err) | ||
| // If the sweep transaction has been generated, and the remote party | ||
| // broadcast the commit transaction, we'll republish it for reliability | ||
| // to ensure it confirms. The resolver will enter this case after | ||
| // checkpointing in the case above, ensuring we reliably on restarts. | ||
| case c.sweepTx != nil && !isLocalCommitTx: | ||
| err := c.PublishTx(c.sweepTx) | ||
| if err != nil && err != lnwallet.ErrDoubleSpend { | ||
| log.Errorf("%T(%v): unable to publish sweep tx: %v", | ||
| c, c.chanPoint, err) | ||
| return nil, err | ||
| } | ||
|
|
||
| // Otherwise, this is our commitment transaction, So we'll obtain the | ||
|
|
@@ -1307,6 +1326,7 @@ func (c *commitSweepResolver) Resolve() (ContractResolver, error) { | |
|
|
||
| if err := c.Checkpoint(c); err != nil { | ||
| log.Errorf("unable to Checkpoint: %v", err) | ||
| return nil, err | ||
| } | ||
| case <-c.Quit: | ||
| return nil, fmt.Errorf("quitting") | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍