-
Notifications
You must be signed in to change notification settings - Fork 14
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
feat: shave fees on ingress #4335
Conversation
e1a1103
to
7eb8882
Compare
- set tracked fees to zero - handle edge cases in asset conversion - return remaining input instead of converted input
44479eb
to
6c12a4f
Compare
Codecov ReportAttention:
Additional details and impacted files@@ Coverage Diff @@
## main #4335 +/- ##
======================================
- Coverage 71% 71% -0%
======================================
Files 390 393 +3
Lines 66407 66667 +260
Branches 66407 66667 +260
======================================
+ Hits 47451 47497 +46
- Misses 16580 16740 +160
- Partials 2376 2430 +54 ☔ View full report in Codecov by Sentry. |
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.
I'll do another pass tomorrow.
_asset: <Bitcoin as Chain>::ChainAsset, | ||
) -> <Bitcoin as Chain>::ChainAmount { | ||
// Include the min fee so we over-estimate the cost. | ||
self.btc_fee_info.min_fee_required_per_tx + self.btc_fee_info.fee_per_input_utxo |
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.
min_fee_required_per_tx is not an overestimate as we assume 10 bytes for this min, but the maximum amount of bytes in a transaction that isn't associated with an input/output, seems to be 26 bytes (https://en.bitcoin.it/wiki/Transaction). So we could under-estimate if there are large numbers of inputs or outputs.
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.
I'm not clear on the reason a fee numbers need to be taken on ingress here. I think a comment would be helpful as the reasoning for the fees being needed is different for each chain.
In the Eth case, we take fees in the ingress case because we do a fetch into the vault. And someone has to pay for that.
But in the Btc case, we take fees to pay for the cost of including the UXTO, in some future egress.
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.
Also I believe the min_fee_required_per_tx is actually not needed, as you are basically double counting it in the estimate_egress_fee.
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.
As discussed, I agree that we are double-counting the min_fee_required_per_tx but this is deliberate to ensure we overestimate the fees. I agree there is plenty of room for improvement. I'll add some comments that hopefully make some of this a bit clearer.
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.
I will add these comments separately if that's ok - have them prepared but forgot to push the commit. And I don't want to push it now and delay the PR anoother 40 minutes while CI completes.
IngressOrEgress::Egress, | ||
asset, | ||
amount, | ||
), | ||
to: destination_address, | ||
}); | ||
DepositBalances::<T, I>::mutate(asset, |tracker| { |
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.
Believe you should be passing the result from withhold_transaction_fee here.
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.
On reflection I'm not so sure - the fee is no longer in a deposit (ie. available to be spent), it's now in the withheld assets, which are earmarked for paying 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.
I think if we do what alastair suggested, we also need to account for it in the other places where the deposit tracker is mutated. So basically the mark_as_fetched
and the register_deposit
functions should also take the net amount for accounting to be correct. Alternatively, we can leave it as as and include the fee in the accounting at all places DepositTracker is mutated.
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.
I think leaving it as is probably the best option. It would still do its job of tracking the deposits (kind off). Doing it the right way would require non-trivial changes.
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.
As mentioned in Discord - I think it's correct as is. The withheld assets should be considered 'spent' ie. they are no longer ours.
…4339) * feat: add ingress/egress fees to cf_ingress_egress_environment rpc * chore: use named Instances --------- Co-authored-by: kylezs <zsembery.kyle@gmail.com>
* feat: shave fees on ingress * feat: withhold tx fees * fix: adjust fee calculations * feat: withhold ingress and egress fee on ingress * fix: basic mock implementations * fix: missing import * fix: eth fetch doens't incur transfer cost * feat: withhold fees in correct asset * fix: more accurate eth fee calculations * feat: shave egress fee at egress * feat: instant asset conversion for tx fees * fix: typo * fix: get integration tests to pass: - set tracked fees to zero - handle edge cases in asset conversion - return remaining input instead of converted input * fix: withhold fees in gas asset * fix: doc comments * fix: correct polkadot fees * chore: clippy * fix bouncer * fix: better output amount estimation method * feat: a unit test * feat: add ingress/egress fees to cf_ingress_egress_environment rpc (#4339) * feat: add ingress/egress fees to cf_ingress_egress_environment rpc * chore: use named Instances --------- Co-authored-by: kylezs <zsembery.kyle@gmail.com> --------- Co-authored-by: Martin Rieke <martin@chainflip.io> Co-authored-by: kylezs <zsembery.kyle@gmail.com>
…-timeout * origin/main: feat: end to end network upgrade github action (#4274) feat: spec_version of PR is greater than spec version of current release (#4355) feat: enforce version is greater than release version on PRs to main (#4351) fix: btc witnesser test failing sometimes (#4353) fix: connections can become stale when reconnecting (#4310) chore: add `chainflip-rpc-node` systemd file 🚀 (#4352) feat: API Bins check SC compatibility (#4342) chore: update runtime spec checks ⛓️ (#4349) feat: Add version cmd to all bins (#4343) fix: changelog check 🤫 (#4348) chore: update docker tags 🐳 (#4347) chore: add runtime version check 👀 (#4344) feat: shave fees on ingress (#4335) pick/persa fixes (#4329) feat: track btc fees on success (#4334) ensure we dont create BTC transaction outputs below the bitcoin dust limit (#4340) fix: sweeping before withdrawal (#4337)
Closes: PRO-1047