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

feat: shave fees on ingress #4335

Merged
merged 21 commits into from
Dec 12, 2023
Merged

feat: shave fees on ingress #4335

merged 21 commits into from
Dec 12, 2023

Conversation

dandanlen
Copy link
Collaborator

@dandanlen dandanlen commented Dec 8, 2023

Closes: PRO-1047

state-chain/chains/src/eth.rs Show resolved Hide resolved
state-chain/chains/src/eth.rs Outdated Show resolved Hide resolved
Copy link

codecov bot commented Dec 11, 2023

Codecov Report

Attention: 113 lines in your changes are missing coverage. Please review.

Comparison is base (e8fd491) 71% compared to head (eadb16a) 71%.
Report is 4 commits behind head on main.

Files Patch % Lines
state-chain/runtime/src/lib.rs 8% 0 Missing and 44 partials ⚠️
state-chain/custom-rpc/src/lib.rs 59% 15 Missing ⚠️
state-chain/traits/src/mocks/asset_converter.rs 50% 12 Missing and 2 partials ⚠️
state-chain/chains/src/btc.rs 0% 13 Missing ⚠️
state-chain/chains/src/mocks.rs 0% 11 Missing ⚠️
state-chain/pallets/cf-pools/src/lib.rs 84% 6 Missing and 3 partials ⚠️
state-chain/chains/src/lib.rs 0% 6 Missing ⚠️
state-chain/pallets/cf-ingress-egress/src/lib.rs 97% 1 Missing ⚠️
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.
📢 Have feedback on the report? Share it here.

Copy link
Collaborator Author

@dandanlen dandanlen left a 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.

state-chain/chains/src/mocks.rs Show resolved Hide resolved
state-chain/pallets/cf-ingress-egress/src/lib.rs Outdated Show resolved Hide resolved
state-chain/primitives/src/chains.rs Show resolved Hide resolved
_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
Copy link
Contributor

@AlastairHolmes AlastairHolmes Dec 12, 2023

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.

Copy link
Contributor

@AlastairHolmes AlastairHolmes Dec 12, 2023

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.

Copy link
Contributor

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.

Copy link
Collaborator Author

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.

Copy link
Collaborator Author

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| {
Copy link
Contributor

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.

Copy link
Collaborator Author

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.

Copy link
Contributor

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.

Copy link
Contributor

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.

Copy link
Collaborator Author

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.

martin-chainflip and others added 4 commits December 12, 2023 14:57
…4339)

* feat: add ingress/egress fees to cf_ingress_egress_environment rpc

* chore: use named Instances

---------

Co-authored-by: kylezs <zsembery.kyle@gmail.com>
@kylezs kylezs marked this pull request as ready for review December 12, 2023 18:02
@kylezs kylezs requested a review from a team as a code owner December 12, 2023 18:02
@kylezs kylezs requested review from jerryafr and niklasnatter and removed request for a team December 12, 2023 18:02
@kylezs kylezs enabled auto-merge (squash) December 12, 2023 18:11
@kylezs kylezs merged commit 2e0efa1 into main Dec 12, 2023
41 checks passed
@kylezs kylezs deleted the feat/shave-fees-on-ingress branch December 12, 2023 18:11
kylezs added a commit that referenced this pull request Dec 12, 2023
* 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>
syan095 added a commit that referenced this pull request Dec 18, 2023
…-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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants