Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tarofreighter: redo fee accounting for PSBT send pkt after adding input #148

Merged
merged 2 commits into from
Sep 28, 2022

Conversation

Roasbeef
Copy link
Member

In this commit, we fix an existing TODO to ensure that the final packet
we have has enough fees at the target fee level. Before this commit,
when we added our own input, we would cause the final fee to undershoot
the desired fee rate target. In order to fix this, we'll now compute the
total weight and then required fee (at the fee rate) to meet our target.
We'll then add this delta (target-current) to make sure we we're not
undershooting in fees.

In this commit, we fix an existing TODO to ensure that the final packet
we have has enough fees at the target fee level. Before this commit,
when we added our own input, we would cause the final fee to undershoot
the desired fee rate target. In order to fix this, we'll now compute the
total weight and then required fee (at the fee rate) to meet our target.
We'll then add this delta (`target-current`) to make sure we we're not
undershooting in fees.
Copy link
Member

@guggero guggero left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, LGTM 🎉

return err
}

switch addrType {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just curious: why aren't we using the txOut.PkScript here and do the same switch as above, but with outputs instead of inputs?

feeDelta := int64(requiredFee) - currentFee
s.SendPkt.UnsignedTx.TxOut[lastIdx].Value += feeDelta

log.Infof("Adjusting send pkt by factor of %v from %v sats to %v sats",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: not a factor but a delta. Also, one is a uint64 and the other is an Amount, so this renders as from 9800 sats to 0.00012662 BTC sats

@guggero guggero merged commit c427692 into main Sep 28, 2022
@guggero guggero deleted the enforce-fee-floor branch September 28, 2022 15:27
lastIdx := len(s.SendPkt.UnsignedTx.TxOut) - 1
currentFee := inputAmt - outputAmt
feeDelta := int64(requiredFee) - currentFee
s.SendPkt.UnsignedTx.TxOut[lastIdx].Value += feeDelta
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be -=?

Copy link
Member

@guggero guggero Sep 29, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thought the same at first too. But delta will be negative if we're overpaying and positive if we're underpaying. So adding is correct.

Edit: Never mind, brain fart. You're totally right. We need to decrease the change output value in order to increase the fee 🤦‍♂️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants