From a0e54a9650b52007d68b2070fe15a50c50aef44a Mon Sep 17 00:00:00 2001 From: Conner Fromknecht Date: Tue, 15 Sep 2020 12:48:23 -0400 Subject: [PATCH] watchtower/lookout: use correct to-local-penalty size for anchors This commit fixes the to-local-witness estimate to use the correct witness size estimate for anchor channels. We retain the off-by-one bug from the original constant otherwise. --- watchtower/lookout/justice_descriptor.go | 9 +++++++-- watchtower/lookout/justice_descriptor_test.go | 9 +++++++-- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/watchtower/lookout/justice_descriptor.go b/watchtower/lookout/justice_descriptor.go index e86748e2..016bc4aa 100644 --- a/watchtower/lookout/justice_descriptor.go +++ b/watchtower/lookout/justice_descriptor.go @@ -284,8 +284,13 @@ func (p *JusticeDescriptor) CreateJusticeTxn() (*wire.MsgTx, error) { // An older ToLocalPenaltyWitnessSize constant used to underestimate the // size by one byte. The diferrence in weight can cause different output // values on the sweep transaction, so we mimic the original bug to - // avoid invalidating signatures by older clients. - weightEstimate.AddWitnessInput(input.ToLocalPenaltyWitnessSize - 1) + // avoid invalidating signatures by older clients. For anchor channels + // we correct this and use the correct witness size. + if p.JusticeKit.BlobType.IsAnchorChannel() { + weightEstimate.AddWitnessInput(input.ToLocalPenaltyWitnessSize) + } else { + weightEstimate.AddWitnessInput(input.ToLocalPenaltyWitnessSize - 1) + } sweepInputs = append(sweepInputs, toLocalInput) diff --git a/watchtower/lookout/justice_descriptor_test.go b/watchtower/lookout/justice_descriptor_test.go index 88ef40ae..dcc79d3f 100644 --- a/watchtower/lookout/justice_descriptor_test.go +++ b/watchtower/lookout/justice_descriptor_test.go @@ -192,8 +192,13 @@ func testJusticeDescriptor(t *testing.T, blobType blob.Type) { // An older ToLocalPenaltyWitnessSize constant used to underestimate the // size by one byte. The diferrence in weight can cause different output // values on the sweep transaction, so we mimic the original bug and - // create signatures using the original weight estimate. - weightEstimate.AddWitnessInput(input.ToLocalPenaltyWitnessSize - 1) + // create signatures using the original weight estimate. For anchor + // channels we fix this and use the correct witness size. + if isAnchorChannel { + weightEstimate.AddWitnessInput(input.ToLocalPenaltyWitnessSize) + } else { + weightEstimate.AddWitnessInput(input.ToLocalPenaltyWitnessSize - 1) + } if isAnchorChannel { weightEstimate.AddWitnessInput(input.ToRemoteConfirmedWitnessSize)