From 4642954e722f4d5b1ec1166267e39f954eb1d4a4 Mon Sep 17 00:00:00 2001 From: Conner Fromknecht Date: Fri, 15 Mar 2019 02:30:59 -0700 Subject: [PATCH] watchtower/wtclient/backup_task: bind to ClientSession instead of SessionInfo --- watchtower/wtclient/backup_task.go | 15 ++++++++------- watchtower/wtclient/backup_task_internal_test.go | 16 ++++++++-------- 2 files changed, 16 insertions(+), 15 deletions(-) diff --git a/watchtower/wtclient/backup_task.go b/watchtower/wtclient/backup_task.go index 17c4c5a7..c88bfd0f 100644 --- a/watchtower/wtclient/backup_task.go +++ b/watchtower/wtclient/backup_task.go @@ -34,9 +34,8 @@ import ( // necessary components are stripped out and encrypted before being sent to // the tower in a StateUpdate. type backupTask struct { - chanID lnwire.ChannelID - commitHeight uint64 - breachInfo *lnwallet.BreachRetribution + id wtdb.BackupID + breachInfo *lnwallet.BreachRetribution // state-dependent variables @@ -96,8 +95,10 @@ func newBackupTask(chanID *lnwire.ChannelID, } return &backupTask{ - chanID: *chanID, - commitHeight: breachInfo.RevokedStateNum, + id: wtdb.BackupID{ + ChanID: *chanID, + CommitHeight: breachInfo.RevokedStateNum, + }, breachInfo: breachInfo, toLocalInput: toLocalInput, toRemoteInput: toRemoteInput, @@ -125,7 +126,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) error { +func (t *backupTask) bindSession(session *wtdb.ClientSession) error { // First we'll begin by deriving a weight estimate for the justice // transaction. The final weight can be different depending on whether @@ -154,7 +155,7 @@ func (t *backupTask) bindSession(session *wtdb.SessionInfo) error { // in the current session's policy. outputs, err := session.Policy.ComputeJusticeTxOuts( t.totalAmt, int64(weightEstimate.Weight()), - t.sweepPkScript, session.RewardAddress, + t.sweepPkScript, session.RewardPkScript, ) if err != nil { return err diff --git a/watchtower/wtclient/backup_task_internal_test.go b/watchtower/wtclient/backup_task_internal_test.go index c38e5c97..2c25c9a0 100644 --- a/watchtower/wtclient/backup_task_internal_test.go +++ b/watchtower/wtclient/backup_task_internal_test.go @@ -69,7 +69,7 @@ type backupTaskTest struct { expSweepAmt int64 expRewardAmt int64 expRewardScript []byte - session *wtdb.SessionInfo + session *wtdb.ClientSession bindErr error expSweepScript []byte signer input.Signer @@ -205,13 +205,13 @@ func genTaskTest( expSweepAmt: expSweepAmt, expRewardAmt: expRewardAmt, expRewardScript: rewardScript, - session: &wtdb.SessionInfo{ + session: &wtdb.ClientSession{ Policy: wtpolicy.Policy{ BlobType: blobType, SweepFeeRate: sweepFeeRate, RewardRate: 10000, }, - RewardAddress: rewardScript, + RewardPkScript: rewardScript, }, bindErr: bindErr, expSweepScript: makeAddrSlice(22), @@ -379,7 +379,7 @@ var backupTaskTests = []backupTaskTest{ } // TestBackupTaskBind tests the initialization and binding of a backupTask to a -// SessionInfo. After a succesfful bind, all parameters of the justice +// ClientSession. After a successful bind, all parameters of the justice // transaction should be solidified, so we assert there correctness. In an // unsuccessful bind, the session-dependent parameters should be unmodified so // that the backup task can be rescheduled if necessary. Finally, we assert that @@ -401,14 +401,14 @@ func testBackupTask(t *testing.T, test backupTaskTest) { // Assert that all parameters set during initialization are properly // populated. - if task.chanID != test.chanID { + if task.id.ChanID != test.chanID { t.Fatalf("channel id mismatch, want: %s, got: %s", - test.chanID, task.chanID) + test.chanID, task.id.ChanID) } - if task.commitHeight != test.breachInfo.RevokedStateNum { + if task.id.CommitHeight != test.breachInfo.RevokedStateNum { t.Fatalf("commit height mismatch, want: %d, got: %d", - test.breachInfo.RevokedStateNum, task.commitHeight) + test.breachInfo.RevokedStateNum, task.id.CommitHeight) } if task.totalAmt != test.expTotalAmt {