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

Refactor: vault_swap should take TransactionInId #5409

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

Conversation

Janislav
Copy link
Contributor

@Janislav Janislav commented Nov 11, 2024

Pull Request

Closes: PRO-1760

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

  • Replaces the TransactionHash with TransactionInId
  • Did all the necessary refactor to handle the convert between the usage of generic and none-generic pallets
  • Fixed all tests and benchmarks
  • Change the engine where necessary

Non-Breaking changes

This is a breaking change, but I don't think we touched anything that is live yet. That means we should check with the frontends. The following things have chanded:

  • The vault_swap_request extrinsic in the ingress egress pallet -> We are changed the name of tx_hash to tx_id
  • The SwapRequested event in the swapping pallet -> tx_hash is now tx_id and the SwapOrigin is SwapOrigin now

In terms of migration, I think we are good. I didn't see any usage SwapOrigin in or former tx_hash in storage, which means there is no need for a migration.

Copy link

codecov bot commented Nov 11, 2024

Codecov Report

Attention: Patch coverage is 71.60494% with 23 lines in your changes missing coverage. Please review.

Project coverage is 71%. Comparing base (c22b70a) to head (248016f).

Files with missing lines Patch % Lines
state-chain/chains/src/lib.rs 68% 3 Missing and 3 partials ⚠️
state-chain/pallets/cf-ingress-egress/src/lib.rs 60% 4 Missing and 2 partials ⚠️
engine/src/witness/evm/vault.rs 0% 4 Missing ⚠️
engine/src/witness/arb.rs 0% 3 Missing ⚠️
engine/src/witness/eth.rs 0% 3 Missing ⚠️
state-chain/pallets/cf-swapping/src/lib.rs 50% 1 Missing ⚠️
Additional details and impacted files
@@          Coverage Diff           @@
##            main   #5409    +/-   ##
======================================
- Coverage     71%     71%    -0%     
======================================
  Files        489     489            
  Lines      86667   86563   -104     
  Branches   86667   86563   -104     
======================================
- Hits       61958   61794   -164     
- Misses     21798   21853    +55     
- Partials    2911    2916     +5     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@albert-llimos
Copy link
Contributor

@Janislav I know this is a draft but I've seen that you've used SolHash for Solana, which seems to be the obvious option. However, due to witnessing shortcomings, we will need to use (SolAddress, u64) for Solana as AccountAddress and slot number. I wrote it in the Linear comments but I can see how it was not too clear.
https://linear.app/chainflip/issue/PRO-1760/vault-swaps-should-take-transactioninid-instead-of-transactionhash#comment-26f67a54
Let me know if anything is unclear.

@Janislav
Copy link
Contributor Author

Mhhh... We will and can use whatever we decide the TransactionInId for Solana should be, but I think this should be not part of this PR, right? I assume changing this has also some other side effects and deserves it's own PR/Ticket I guess.

@albert-llimos
Copy link
Contributor

Mhhh... We will and can use whatever we decide the TransactionInId for Solana should be, but I think this should be not part of this PR, right? I assume changing this has also some other side effects and deserves it's own PR/Ticket I guess.

I was thinking that you can already declare it as the correct type for Solana, as the SolHash is not what we want. The work on the engine to report the correct value for that will of course be in another PR.

@Janislav
Copy link
Contributor Author

Okay, since we are really not using TransactionInId for anything for Solana right now, we might get away with just changing the type. I was worried it could be more complex than that (migrations, tests, benchmark, engine). In this case we can do it straight in this PR I think.

(typeof id === 'string' && 'Vault' in data.origin && data.origin.Vault.txHash === id);
(typeof id === 'string' &&
'Vault' in data.origin &&
data.origin.Vault.txHash.ByteHash === id);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

FYI: For now, it's safe to assume that we always have to deal with EVM or BTC, so it will be always a H256 hash string. If this should change, we have to handle this somehow.

Copy link
Contributor

Choose a reason for hiding this comment

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

We have the Solana Vault swaps PR in the pipeline that will definitely break that. I'll make sure to update that after this is complete. Thanks for pointing that out.

@Janislav Janislav force-pushed the refactor/pro-1760/use-txinid-in-vault-swaps branch from cabf11d to 615f472 Compare November 12, 2024 10:42
@Janislav Janislav marked this pull request as ready for review November 12, 2024 12:33
@Janislav Janislav force-pushed the refactor/pro-1760/use-txinid-in-vault-swaps branch from 615f472 to 248016f Compare November 13, 2024 10:27
Copy link
Collaborator

@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 don't think we need a generic SwapOrigin: The only reason we ever construct a SwapOrigin<TxInId> is to convert it to a SwapOrigin<TxInIdAnyChain>. Instead of building what we don't want and then converting it to what we need, we could just build what we need. We just need a way to wrap the chain-specific id to the the 'any chain' enum.

Comment on lines +6 to +7
use cf_primitives::TxId;
use sp_core::H256;
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: please group these with the rest of the imports.

Comment on lines +598 to +600
pub trait ConvertTransactionInIdToAnyChain<TransactionInId> {
fn convert(origin: SwapOrigin<TransactionInId>) -> SwapOrigin<TransactionInIdForAnyChain>;
}
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 really need a new trait? Can we not just add a constraint to TransactionInId : Into<TransactionInIdForAnyChain, and a map method to SwapOrigin?

#[derive(Debug, Clone, TypeInfo, Encode, Decode, PartialEq, Eq)]
pub enum TransactionInIdForAnyChain {
// Used by Ethereum, Arbitrum and BTC.
ByteHash(H256),
Copy link
Collaborator

@dandanlen dandanlen Nov 13, 2024

Choose a reason for hiding this comment

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

I think it makes sense to split this up per ChainCrypto, and also use scoped types for clarity:

Bitcoin(<BitcoinCrypto as ChainCrypto>::TransactionInId),
Evm(<EvmCrypto as ChainCrypto>::TransactionInId),
// etc.

For example we might want to use bitcoin's backward-serialized tx hash type without impacting what we use for Eth/Arb.

DepositChannel {
deposit_address: address::EncodedAddress,
channel_id: ChannelId,
deposit_block_height: u64,
},
Vault {
tx_hash: TransactionHash,
tx_id: TransactionInId,
Copy link
Collaborator

Choose a reason for hiding this comment

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

It's bit odd that SwapOrigin::DepositChannel uses EncodedAddress (ie. it's not chain-specific) but SwapOrigin::Vault is a chain-specific variant... 🤔

Do we need SwapOrigin to be generic at all? Can this variant not just be concrete?

Vault { tx_id: TransactionInIdForAnyChain }

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.

3 participants