watchtower/wtclient/backup_task: bind to ClientSession instead of SessionInfo
This commit is contained in:
parent
b1903451d9
commit
4642954e72
@ -34,9 +34,8 @@ import (
|
|||||||
// necessary components are stripped out and encrypted before being sent to
|
// necessary components are stripped out and encrypted before being sent to
|
||||||
// the tower in a StateUpdate.
|
// the tower in a StateUpdate.
|
||||||
type backupTask struct {
|
type backupTask struct {
|
||||||
chanID lnwire.ChannelID
|
id wtdb.BackupID
|
||||||
commitHeight uint64
|
breachInfo *lnwallet.BreachRetribution
|
||||||
breachInfo *lnwallet.BreachRetribution
|
|
||||||
|
|
||||||
// state-dependent variables
|
// state-dependent variables
|
||||||
|
|
||||||
@ -96,8 +95,10 @@ func newBackupTask(chanID *lnwire.ChannelID,
|
|||||||
}
|
}
|
||||||
|
|
||||||
return &backupTask{
|
return &backupTask{
|
||||||
chanID: *chanID,
|
id: wtdb.BackupID{
|
||||||
commitHeight: breachInfo.RevokedStateNum,
|
ChanID: *chanID,
|
||||||
|
CommitHeight: breachInfo.RevokedStateNum,
|
||||||
|
},
|
||||||
breachInfo: breachInfo,
|
breachInfo: breachInfo,
|
||||||
toLocalInput: toLocalInput,
|
toLocalInput: toLocalInput,
|
||||||
toRemoteInput: toRemoteInput,
|
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
|
// 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
|
// session and can be queued to upload to the tower. Otherwise, the bind failed
|
||||||
// and should be rescheduled with a different session.
|
// 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
|
// First we'll begin by deriving a weight estimate for the justice
|
||||||
// transaction. The final weight can be different depending on whether
|
// 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.
|
// in the current session's policy.
|
||||||
outputs, err := session.Policy.ComputeJusticeTxOuts(
|
outputs, err := session.Policy.ComputeJusticeTxOuts(
|
||||||
t.totalAmt, int64(weightEstimate.Weight()),
|
t.totalAmt, int64(weightEstimate.Weight()),
|
||||||
t.sweepPkScript, session.RewardAddress,
|
t.sweepPkScript, session.RewardPkScript,
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -69,7 +69,7 @@ type backupTaskTest struct {
|
|||||||
expSweepAmt int64
|
expSweepAmt int64
|
||||||
expRewardAmt int64
|
expRewardAmt int64
|
||||||
expRewardScript []byte
|
expRewardScript []byte
|
||||||
session *wtdb.SessionInfo
|
session *wtdb.ClientSession
|
||||||
bindErr error
|
bindErr error
|
||||||
expSweepScript []byte
|
expSweepScript []byte
|
||||||
signer input.Signer
|
signer input.Signer
|
||||||
@ -205,13 +205,13 @@ func genTaskTest(
|
|||||||
expSweepAmt: expSweepAmt,
|
expSweepAmt: expSweepAmt,
|
||||||
expRewardAmt: expRewardAmt,
|
expRewardAmt: expRewardAmt,
|
||||||
expRewardScript: rewardScript,
|
expRewardScript: rewardScript,
|
||||||
session: &wtdb.SessionInfo{
|
session: &wtdb.ClientSession{
|
||||||
Policy: wtpolicy.Policy{
|
Policy: wtpolicy.Policy{
|
||||||
BlobType: blobType,
|
BlobType: blobType,
|
||||||
SweepFeeRate: sweepFeeRate,
|
SweepFeeRate: sweepFeeRate,
|
||||||
RewardRate: 10000,
|
RewardRate: 10000,
|
||||||
},
|
},
|
||||||
RewardAddress: rewardScript,
|
RewardPkScript: rewardScript,
|
||||||
},
|
},
|
||||||
bindErr: bindErr,
|
bindErr: bindErr,
|
||||||
expSweepScript: makeAddrSlice(22),
|
expSweepScript: makeAddrSlice(22),
|
||||||
@ -379,7 +379,7 @@ var backupTaskTests = []backupTaskTest{
|
|||||||
}
|
}
|
||||||
|
|
||||||
// TestBackupTaskBind tests the initialization and binding of a backupTask to a
|
// 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
|
// transaction should be solidified, so we assert there correctness. In an
|
||||||
// unsuccessful bind, the session-dependent parameters should be unmodified so
|
// unsuccessful bind, the session-dependent parameters should be unmodified so
|
||||||
// that the backup task can be rescheduled if necessary. Finally, we assert that
|
// 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
|
// Assert that all parameters set during initialization are properly
|
||||||
// populated.
|
// populated.
|
||||||
if task.chanID != test.chanID {
|
if task.id.ChanID != test.chanID {
|
||||||
t.Fatalf("channel id mismatch, want: %s, got: %s",
|
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",
|
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 {
|
if task.totalAmt != test.expTotalAmt {
|
||||||
|
Loading…
Reference in New Issue
Block a user