diff --git a/watchtower/wtclient/backup_task.go b/watchtower/wtclient/backup_task.go index 1e5dd4b2e..17c4c5a7b 100644 --- a/watchtower/wtclient/backup_task.go +++ b/watchtower/wtclient/backup_task.go @@ -43,6 +43,7 @@ type backupTask struct { toLocalInput input.Input toRemoteInput input.Input totalAmt btcutil.Amount + sweepPkScript []byte // session-dependent variables @@ -53,7 +54,8 @@ type backupTask struct { // newBackupTask initializes a new backupTask and populates all state-dependent // variables. func newBackupTask(chanID *lnwire.ChannelID, - breachInfo *lnwallet.BreachRetribution) *backupTask { + breachInfo *lnwallet.BreachRetribution, + sweepPkScript []byte) *backupTask { // Parse the non-dust outputs from the breach transaction, // simultaneously computing the total amount contained in the inputs @@ -100,6 +102,7 @@ func newBackupTask(chanID *lnwire.ChannelID, toLocalInput: toLocalInput, toRemoteInput: toRemoteInput, totalAmt: btcutil.Amount(totalAmt), + sweepPkScript: sweepPkScript, } } @@ -122,8 +125,7 @@ func (t *backupTask) inputs() map[wire.OutPoint]input.Input { // SessionInfo's policy. If no error is returned, the task has been bound to the // session and can be queued to upload to the tower. Otherwise, the bind failed // and should be rescheduled with a different session. -func (t *backupTask) bindSession(session *wtdb.SessionInfo, - sweepPkScript []byte) error { +func (t *backupTask) bindSession(session *wtdb.SessionInfo) error { // First we'll begin by deriving a weight estimate for the justice // transaction. The final weight can be different depending on whether @@ -152,7 +154,7 @@ func (t *backupTask) bindSession(session *wtdb.SessionInfo, // in the current session's policy. outputs, err := session.Policy.ComputeJusticeTxOuts( t.totalAmt, int64(weightEstimate.Weight()), - sweepPkScript, session.RewardAddress, + t.sweepPkScript, session.RewardAddress, ) if err != nil { return err @@ -170,7 +172,7 @@ func (t *backupTask) bindSession(session *wtdb.SessionInfo, // session-dependent variables, and signs the resulting transaction. The // required pieces from signatures, witness scripts, etc are then packaged into // a JusticeKit and encrypted using the breach transaction's key. -func (t *backupTask) craftSessionPayload(sweepPkScript []byte, +func (t *backupTask) craftSessionPayload( signer input.Signer) (wtdb.BreachHint, []byte, error) { var hint wtdb.BreachHint @@ -179,7 +181,7 @@ func (t *backupTask) craftSessionPayload(sweepPkScript []byte, // to-local script, and the remote CSV delay. keyRing := t.breachInfo.KeyRing justiceKit := &blob.JusticeKit{ - SweepAddress: sweepPkScript, + SweepAddress: t.sweepPkScript, RevocationPubKey: toBlobPubKey(keyRing.RevocationKey), LocalDelayPubKey: toBlobPubKey(keyRing.DelayKey), CSVDelay: t.breachInfo.RemoteDelay, diff --git a/watchtower/wtclient/backup_task_internal_test.go b/watchtower/wtclient/backup_task_internal_test.go index 261726205..c38e5c974 100644 --- a/watchtower/wtclient/backup_task_internal_test.go +++ b/watchtower/wtclient/backup_task_internal_test.go @@ -397,7 +397,7 @@ func TestBackupTask(t *testing.T) { func testBackupTask(t *testing.T, test backupTaskTest) { // Create a new backupTask from the channel id and breach info. - task := newBackupTask(&test.chanID, test.breachInfo) + task := newBackupTask(&test.chanID, test.breachInfo, test.expSweepScript) // Assert that all parameters set during initialization are properly // populated. @@ -452,7 +452,7 @@ func testBackupTask(t *testing.T, test backupTaskTest) { // Now, bind the session to the task. If successful, this locks in the // session's negotiated parameters and allows the backup task to derive // the final free variables in the justice transaction. - err := task.bindSession(test.session, test.expSweepScript) + err := task.bindSession(test.session) if err != test.bindErr { t.Fatalf("expected: %v when binding session, got: %v", test.bindErr, err) @@ -509,9 +509,7 @@ func testBackupTask(t *testing.T, test backupTaskTest) { // Now, we'll construct, sign, and encrypt the blob containing the parts // needed to reconstruct the justice transaction. - hint, encBlob, err := task.craftSessionPayload( - test.expSweepScript, test.signer, - ) + hint, encBlob, err := task.craftSessionPayload(test.signer) if err != nil { t.Fatalf("unable to craft session payload: %v", err) }