-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Beat [3/4]: prepare resolvers to handle the blockbeat
#9276
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
Changes from all commits
82d77bb
3cb48a0
10d9544
693287f
fe29961
7e0623c
066d351
c108487
d78fd7a
629c037
406f443
dcf7144
dfaff63
fe4ab4e
dbfe5df
1c8cbc8
b6c4dd9
b3cec2c
7751b1b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,6 +2,7 @@ package contractcourt | |
|
|
||
| import ( | ||
| "errors" | ||
| "fmt" | ||
| "io" | ||
| "sync" | ||
|
|
||
|
|
@@ -23,9 +24,6 @@ type anchorResolver struct { | |
| // anchor is the outpoint on the commitment transaction. | ||
| anchor wire.OutPoint | ||
|
|
||
| // resolved reflects if the contract has been fully resolved or not. | ||
| resolved bool | ||
|
|
||
| // broadcastHeight is the height that the original contract was | ||
| // broadcast to the main-chain at. We'll use this value to bound any | ||
| // historical queries to the chain for spends/confirmations. | ||
|
|
@@ -71,7 +69,7 @@ func newAnchorResolver(anchorSignDescriptor input.SignDescriptor, | |
| currentReport: report, | ||
| } | ||
|
|
||
| r.initLogger(r) | ||
| r.initLogger(fmt.Sprintf("%T(%v)", r, r.anchor)) | ||
|
|
||
| return r | ||
| } | ||
|
|
@@ -83,49 +81,14 @@ func (c *anchorResolver) ResolverKey() []byte { | |
| return nil | ||
| } | ||
|
|
||
| // Resolve offers the anchor output to the sweeper and waits for it to be swept. | ||
| // Resolve waits for the output to be swept. | ||
|
ziggie1984 marked this conversation as resolved.
|
||
| // | ||
| // NOTE: Part of the ContractResolver interface. | ||
| func (c *anchorResolver) Resolve() (ContractResolver, error) { | ||
| // Attempt to update the sweep parameters to the post-confirmation | ||
| // situation. We don't want to force sweep anymore, because the anchor | ||
| // lost its special purpose to get the commitment confirmed. It is just | ||
| // an output that we want to sweep only if it is economical to do so. | ||
| // | ||
| // An exclusive group is not necessary anymore, because we know that | ||
| // this is the only anchor that can be swept. | ||
| // | ||
| // We also clear the parent tx information for cpfp, because the | ||
| // commitment tx is confirmed. | ||
| // | ||
| // After a restart or when the remote force closes, the sweeper is not | ||
| // yet aware of the anchor. In that case, it will be added as new input | ||
| // to the sweeper. | ||
| witnessType := input.CommitmentAnchor | ||
|
|
||
| // For taproot channels, we need to use the proper witness type. | ||
| if c.chanType.IsTaproot() { | ||
| witnessType = input.TaprootAnchorSweepSpend | ||
| } | ||
|
|
||
| anchorInput := input.MakeBaseInput( | ||
| &c.anchor, witnessType, &c.anchorSignDescriptor, | ||
| c.broadcastHeight, nil, | ||
| ) | ||
|
|
||
| resultChan, err := c.Sweeper.SweepInput( | ||
| &anchorInput, | ||
| sweep.Params{ | ||
| // For normal anchor sweeping, the budget is 330 sats. | ||
| Budget: btcutil.Amount( | ||
| anchorInput.SignDesc().Output.Value, | ||
| ), | ||
|
|
||
| // There's no rush to sweep the anchor, so we use a nil | ||
| // deadline here. | ||
| DeadlineHeight: fn.None[int32](), | ||
| }, | ||
| ) | ||
| if err != nil { | ||
| return nil, err | ||
| // If we're already resolved, then we can exit early. | ||
| if c.IsResolved() { | ||
| c.log.Errorf("already resolved") | ||
| return nil, nil | ||
| } | ||
|
|
||
| var ( | ||
|
|
@@ -134,7 +97,7 @@ func (c *anchorResolver) Resolve() (ContractResolver, error) { | |
| ) | ||
|
|
||
| select { | ||
| case sweepRes := <-resultChan: | ||
| case sweepRes := <-c.sweepResultChan: | ||
| switch sweepRes.Err { | ||
| // Anchor was swept successfully. | ||
| case nil: | ||
|
|
@@ -160,6 +123,8 @@ func (c *anchorResolver) Resolve() (ContractResolver, error) { | |
| return nil, errResolverShuttingDown | ||
| } | ||
|
|
||
| c.log.Infof("resolved in tx %v", spendTx) | ||
|
|
||
| // Update report to reflect that funds are no longer in limbo. | ||
| c.reportLock.Lock() | ||
| if outcome == channeldb.ResolverOutcomeClaimed { | ||
|
|
@@ -171,7 +136,7 @@ func (c *anchorResolver) Resolve() (ContractResolver, error) { | |
| ) | ||
| c.reportLock.Unlock() | ||
|
|
||
| c.resolved = true | ||
| c.markResolved() | ||
| return nil, c.PutResolverReport(nil, report) | ||
| } | ||
|
|
||
|
|
@@ -180,15 +145,10 @@ func (c *anchorResolver) Resolve() (ContractResolver, error) { | |
| // | ||
| // NOTE: Part of the ContractResolver interface. | ||
| func (c *anchorResolver) Stop() { | ||
| close(c.quit) | ||
| } | ||
| c.log.Debugf("stopping...") | ||
| defer c.log.Debugf("stopped") | ||
|
|
||
| // IsResolved returns true if the stored state in the resolve is fully | ||
| // resolved. In this case the target output can be forgotten. | ||
| // | ||
| // NOTE: Part of the ContractResolver interface. | ||
| func (c *anchorResolver) IsResolved() bool { | ||
| return c.resolved | ||
| close(c.quit) | ||
| } | ||
|
|
||
| // SupplementState allows the user of a ContractResolver to supplement it with | ||
|
|
@@ -215,3 +175,68 @@ func (c *anchorResolver) Encode(w io.Writer) error { | |
| // A compile time assertion to ensure anchorResolver meets the | ||
| // ContractResolver interface. | ||
| var _ ContractResolver = (*anchorResolver)(nil) | ||
|
|
||
| // Launch offers the anchor output to the sweeper. | ||
| func (c *anchorResolver) Launch() error { | ||
|
Collaborator
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. I think we should only launch the anchor resolver only in 2 cases:
could you elaborate why we launch the Anchor also here:
Member
Author
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. that's what the |
||
| if c.isLaunched() { | ||
| c.log.Tracef("already launched") | ||
|
ziggie1984 marked this conversation as resolved.
|
||
| return nil | ||
| } | ||
|
|
||
| c.log.Debugf("launching resolver...") | ||
| c.markLaunched() | ||
|
|
||
| // If we're already resolved, then we can exit early. | ||
| if c.IsResolved() { | ||
| c.log.Errorf("already resolved") | ||
| return nil | ||
| } | ||
|
|
||
| // Attempt to update the sweep parameters to the post-confirmation | ||
| // situation. We don't want to force sweep anymore, because the anchor | ||
| // lost its special purpose to get the commitment confirmed. It is just | ||
| // an output that we want to sweep only if it is economical to do so. | ||
| // | ||
| // An exclusive group is not necessary anymore, because we know that | ||
| // this is the only anchor that can be swept. | ||
| // | ||
| // We also clear the parent tx information for cpfp, because the | ||
| // commitment tx is confirmed. | ||
| // | ||
| // After a restart or when the remote force closes, the sweeper is not | ||
| // yet aware of the anchor. In that case, it will be added as new input | ||
| // to the sweeper. | ||
| witnessType := input.CommitmentAnchor | ||
|
|
||
| // For taproot channels, we need to use the proper witness type. | ||
| if c.chanType.IsTaproot() { | ||
| witnessType = input.TaprootAnchorSweepSpend | ||
| } | ||
|
|
||
| anchorInput := input.MakeBaseInput( | ||
| &c.anchor, witnessType, &c.anchorSignDescriptor, | ||
| c.broadcastHeight, nil, | ||
| ) | ||
|
|
||
| resultChan, err := c.Sweeper.SweepInput( | ||
| &anchorInput, | ||
| sweep.Params{ | ||
| // For normal anchor sweeping, the budget is 330 sats. | ||
| Budget: btcutil.Amount( | ||
| anchorInput.SignDesc().Output.Value, | ||
| ), | ||
|
|
||
| // There's no rush to sweep the anchor, so we use a nil | ||
| // deadline here. | ||
| DeadlineHeight: fn.None[int32](), | ||
| }, | ||
| ) | ||
|
|
||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| c.sweepResultChan = resultChan | ||
|
|
||
| return nil | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.