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.
This commit is contained in:
Conner Fromknecht 2020-09-15 12:48:23 -04:00
parent d440cc4024
commit a0e54a9650
No known key found for this signature in database
GPG Key ID: E7D737B67FA592C7
2 changed files with 14 additions and 4 deletions

@ -284,8 +284,13 @@ func (p *JusticeDescriptor) CreateJusticeTxn() (*wire.MsgTx, error) {
// An older ToLocalPenaltyWitnessSize constant used to underestimate the // An older ToLocalPenaltyWitnessSize constant used to underestimate the
// size by one byte. The diferrence in weight can cause different output // size by one byte. The diferrence in weight can cause different output
// values on the sweep transaction, so we mimic the original bug to // values on the sweep transaction, so we mimic the original bug to
// avoid invalidating signatures by older clients. // avoid invalidating signatures by older clients. For anchor channels
weightEstimate.AddWitnessInput(input.ToLocalPenaltyWitnessSize - 1) // 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) sweepInputs = append(sweepInputs, toLocalInput)

@ -192,8 +192,13 @@ func testJusticeDescriptor(t *testing.T, blobType blob.Type) {
// An older ToLocalPenaltyWitnessSize constant used to underestimate the // An older ToLocalPenaltyWitnessSize constant used to underestimate the
// size by one byte. The diferrence in weight can cause different output // size by one byte. The diferrence in weight can cause different output
// values on the sweep transaction, so we mimic the original bug and // values on the sweep transaction, so we mimic the original bug and
// create signatures using the original weight estimate. // create signatures using the original weight estimate. For anchor
weightEstimate.AddWitnessInput(input.ToLocalPenaltyWitnessSize - 1) // channels we fix this and use the correct witness size.
if isAnchorChannel {
weightEstimate.AddWitnessInput(input.ToLocalPenaltyWitnessSize)
} else {
weightEstimate.AddWitnessInput(input.ToLocalPenaltyWitnessSize - 1)
}
if isAnchorChannel { if isAnchorChannel {
weightEstimate.AddWitnessInput(input.ToRemoteConfirmedWitnessSize) weightEstimate.AddWitnessInput(input.ToRemoteConfirmedWitnessSize)