-
Notifications
You must be signed in to change notification settings - Fork 102
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
Conversation
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.
There was a problem hiding this 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 { |
There was a problem hiding this comment.
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", |
There was a problem hiding this comment.
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
lastIdx := len(s.SendPkt.UnsignedTx.TxOut) - 1 | ||
currentFee := inputAmt - outputAmt | ||
feeDelta := int64(requiredFee) - currentFee | ||
s.SendPkt.UnsignedTx.TxOut[lastIdx].Value += feeDelta |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be -=
?
There was a problem hiding this comment.
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 🤦♂️
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 notundershooting in fees.