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: fallback for vault swap if no broker provided #5507

Open
wants to merge 17 commits into
base: main
Choose a base branch
from

Conversation

Janislav
Copy link
Contributor

@Janislav Janislav commented Dec 17, 2024

Pull Request

Closes: PRO-1804

Checklist

Please conduct a thorough self-review before opening the PR.

  • I am confident that the code works.
  • I have written sufficient tests.
  • I have written and tested required migrations.
  • I have updated documentation where appropriate.

Summary

Adding refund functionality if there is no broker provided in the vault swap. If we identify on the prewitness stage that there is no broker provided or the account provided is no broker, we mark the tx as aborted. When the deposit gets eventually fully witnessed, we check if it was identified as aborted and directly try to refund it. If the refund should not be possible (failing to create the API call for e.x) we push the details of the tx to another storage item to remember the tx.

Non-Breaking changes

If this PR includes non-breaking changes, select the non-breaking label. On merge, CI will automatically cherry-pick the commit to a PR against the release branch.

@Janislav Janislav force-pushed the feat/pro-1804/fallback-for-vault-swap branch from 54149de to 48dcf8e Compare January 31, 2025 16:14
Copy link

codecov bot commented Jan 31, 2025

Codecov Report

Attention: Patch coverage is 98.83721% with 1 line in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
state-chain/pallets/cf-ingress-egress/src/lib.rs 96% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

@Janislav Janislav force-pushed the feat/pro-1804/fallback-for-vault-swap branch from 11c9efd to f2ba32b Compare February 5, 2025 12:38
@Janislav Janislav changed the title Feat: PRO-1804 - fallback for vault swap feat: PRO-1804 - fallback for vault swap Feb 10, 2025
@Janislav Janislav changed the title feat: PRO-1804 - fallback for vault swap feat: fallback for vault swap if no broker provided Feb 10, 2025
@Janislav Janislav force-pushed the feat/pro-1804/fallback-for-vault-swap branch from 22f89a1 to e1840f6 Compare February 10, 2025 13:58
@Janislav Janislav marked this pull request as ready for review February 10, 2025 16:43
@@ -766,6 +766,18 @@ pub mod pallet {
pub type NetworkFeeDeductionFromBoostPercent<T: Config<I>, I: 'static = ()> =
StorageValue<_, Percent, ValueQuery>;

/// Stores the tx_id of an aborted vault transaction. At the moment we consider a vault
/// transaction as aborted if
Copy link
Collaborator

Choose a reason for hiding this comment

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

This comment is incomplete.

/// transaction as aborted if
#[pallet::storage]
pub(crate) type AbortedVaultTransaction<T: Config<I>, I: 'static = ()> =
StorageMap<_, Identity, TransactionInIdFor<T, I>, ()>;
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't think we can use Identity for the TransactionInId (we don't really have any guarantees about what it contains). TwoX64 hash should be enough though.

/// Stores the details of an aborted vault transaction. In case we fail to refund we store the
/// details in this storage item.
#[pallet::storage]
pub(crate) type AbortedVaultTransactionDetails<T: Config<I>, I: 'static = ()> =
Copy link
Collaborator

Choose a reason for hiding this comment

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

Do we need two separate storage items? Can we not just use this with an optional value?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We can also unify it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

EDIT: We can not unify it and it's better to keep it separate. We could even argue to just remove this and not save this, since this is a very theoretical case. After we enforced refund parameters, the only case a refund could fail is when fail to build an API call, but that should actually never happen.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yes exactly - we don't need the map with a () value.

@@ -2161,6 +2193,12 @@ impl<T: Config<I>, I: 'static> Pallet<T, I> {
boost_fee,
}: VaultDepositWitness<T, I>,
) {
if Self::should_reject_vault_swap(&broker_fee) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

We only check this when we pre-witness. Why not on full deposits? What about chains where we don't have pre-witnessing - am I missing something?

Copy link
Contributor Author

@Janislav Janislav Feb 12, 2025

Choose a reason for hiding this comment

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

I think we should always have the prewitness step, right? The reason why we do it here is boost. Otherwise, we would first send out the funds and then later also refund it.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Pretty sure we only prewitness for Bitcoin. Also, sometimes we miss the pre-witness (for example if there's a reorg).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Okay, but checking it only on full deposit is not an option since it could be a boosted BTC transaction. We have to check it on both stages but only refund it on full deposit

- Skipping on prewitness stage and refund when we finalize the deposit
- Removed obsolete storage items
- Fixed tests
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.

2 participants