|
6 | 6 | "io"
|
7 | 7 | "sync"
|
8 | 8 |
|
| 9 | + "github.com/btcsuite/btcd/txscript" |
9 | 10 | "github.com/btcsuite/btcd/wire"
|
10 | 11 | "github.com/btcsuite/btcutil"
|
11 | 12 | "github.com/lightningnetwork/lnd/input"
|
@@ -172,24 +173,45 @@ func (c *commitSweepResolver) Resolve() (ContractResolver, error) {
|
172 | 173 | }
|
173 | 174 | }
|
174 | 175 |
|
175 |
| - // We're dealing with our commitment transaction if the delay on the |
176 |
| - // resolution isn't zero. |
177 |
| - isLocalCommitTx := c.commitResolution.MaturityDelay != 0 |
178 |
| - |
179 |
| - // There're two types of commitments, those that have tweaks |
180 |
| - // for the remote key (us in this case), and those that don't. |
181 |
| - // We'll rely on the presence of the commitment tweak to to |
182 |
| - // discern which type of commitment this is. |
| 176 | + // The output is on our local commitment if the script starts with |
| 177 | + // OP_IF for the revocation clause. On the remote commitment it will |
| 178 | + // either be a regular P2WKH or a simple sig spend with a CSV delay. |
| 179 | + isLocalCommitTx := c.commitResolution.SelfOutputSignDesc.WitnessScript[0] == txscript.OP_IF |
| 180 | + isDelayedOutput := c.commitResolution.MaturityDelay != 0 |
| 181 | + |
| 182 | + c.log.Debugf("isDelayedOutput=%v, isLocalCommitTx=%v", isDelayedOutput, |
| 183 | + isLocalCommitTx) |
| 184 | + |
| 185 | + // There're three types of commitments, those that have tweaks |
| 186 | + // for the remote key (us in this case), those that don't, and a third |
| 187 | + // where there is no tweak and the output is delayed. On the local |
| 188 | + // commitment our output will always be delayed. We'll rely on the |
| 189 | + // presence of the commitment tweak to to discern which type of |
| 190 | + // commitment this is. |
183 | 191 | var witnessType input.WitnessType
|
184 | 192 | switch {
|
| 193 | + |
| 194 | + // Delayed output to us on our local commitment. |
185 | 195 | case isLocalCommitTx:
|
186 | 196 | witnessType = input.CommitmentTimeLock
|
| 197 | + |
| 198 | + // A confirmed output to us on the remote commitment. |
| 199 | + case isDelayedOutput: |
| 200 | + witnessType = input.CommitmentToRemoteConfirmed |
| 201 | + |
| 202 | + // A non-delayed output on the remote commitment where the key is |
| 203 | + // tweakless. |
187 | 204 | case c.commitResolution.SelfOutputSignDesc.SingleTweak == nil:
|
188 | 205 | witnessType = input.CommitSpendNoDelayTweakless
|
| 206 | + |
| 207 | + // A non-delayed output on the remote commitment where the key is |
| 208 | + // tweaked. |
189 | 209 | default:
|
190 | 210 | witnessType = input.CommitmentNoDelay
|
191 | 211 | }
|
192 | 212 |
|
| 213 | + c.log.Infof("Sweeping with witness type: %v", witnessType) |
| 214 | + |
193 | 215 | // We'll craft an input with all the information required for
|
194 | 216 | // the sweeper to create a fully valid sweeping transaction to
|
195 | 217 | // recover these coins.
|
|
0 commit comments