-
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
Refactor: vault_swap should take TransactionInId #5409
base: main
Are you sure you want to change the base?
Conversation
Codecov ReportAttention: Patch coverage is
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. |
@Janislav I know this is a draft but I've seen that you've used |
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. |
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. |
bouncer/shared/utils.ts
Outdated
(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); |
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.
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.
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.
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.
cabf11d
to
615f472
Compare
- Added a struct that can convert from a generic TxID to a static TxID representation - Integrated the converter into the runtime - Fixed the witnessing
615f472
to
248016f
Compare
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 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.
use cf_primitives::TxId; | ||
use sp_core::H256; |
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: please group these with the rest of the imports.
pub trait ConvertTransactionInIdToAnyChain<TransactionInId> { | ||
fn convert(origin: SwapOrigin<TransactionInId>) -> SwapOrigin<TransactionInIdForAnyChain>; | ||
} |
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.
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), |
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 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, |
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.
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 }
Pull Request
Closes: PRO-1760
Checklist
Please conduct a thorough self-review before opening the PR.
Summary
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:
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.