Skip to content

feat(cvm): initial eth support (wires until final step transfer shortcut , eth abi message, erc20)#4182

Merged
dzmitry-lahoda merged 9 commits intomainfrom
dz/b/9
Oct 10, 2023
Merged

feat(cvm): initial eth support (wires until final step transfer shortcut , eth abi message, erc20)#4182
dzmitry-lahoda merged 9 commits intomainfrom
dz/b/9

Conversation

@dzmitry-lahoda
Copy link
Contributor

@dzmitry-lahoda dzmitry-lahoda commented Oct 9, 2023

Required for merge:

  • pr-workflow-check / draft-release-check is ✅ success
  • Other rules GitHub shows you, or can be read in configuration

Makes review faster:

  • PR title is my best effort to provide summary of changes and has clear text to be part of release notes
  • I marked PR by misc label if it should not be in release notes
  • Linked Zenhub/Github/Slack/etc reference if one exists
  • I was clear on what type of deployment required to release my changes (node, runtime, contract, indexer, on chain operation, frontend, infrastructure) if any in PR title or description
  • Added reviewer into Reviewers
  • I tagged(@) or used other form of notification of one person who I think can handle best review of this PR
  • I have proved that PR has no general regressions of relevant features and processes required to release into production
  • Any dependency updates made, was done according guides from relevant dependency
  • Clicking all checkboxes
  • Adding detailed description of changes when it feels appropriate (for example when PR is big)

@github-actions
Copy link

github-actions bot commented Oct 9, 2023

Pull reviewers stats

Stats of the last 30 days for composable:

User Total reviews Time to review Total comments
dzmitry-lahoda 8 41m 2
blasrodri 8 18h 47m 6
RustNinja 8 16h 17m 0
JafarAz 8 1h 31m 3
kkast 6 3h 2m 12
mina86 2 16h 36m 1
0xBrainjar2 2 6h 41m 0
vmarkushin 1 16h 47m 4
fl-y 1 18h 46m 0

@github-actions
Copy link

github-actions bot commented Oct 9, 2023

# run Composable node
nix run "github:ComposableFi/composable/refs/pull/4182/merge" --allow-import-from-derivation --extra-experimental-features "flakes nix-command" --no-sandbox --accept-flake-config --option sandbox relaxed
# run local Picasso DevNet (for CosmWasm development)
nix run "github:ComposableFi/composable/refs/pull/4182/merge#devnet-picasso" --allow-import-from-derivation --extra-experimental-features "flakes nix-command" --no-sandbox --accept-flake-config --option sandbox relaxed 
# CosmWasm on Substrate CLI tool
nix run "github:ComposableFi/composable/refs/pull/4182/merge#ccw" --allow-import-from-derivation --extra-experimental-features "flakes nix-command" --no-sandbox --accept-flake-config --option sandbox relaxed 
# run cross chain devnet with Dotsama and Cosmos nodes 
nix run "github:ComposableFi/composable/refs/pull/4182/merge#devnet-xc-fresh" --allow-import-from-derivation --extra-experimental-features "flakes nix-command" --no-sandbox --accept-flake-config --option sandbox relaxed 
# or same with docker
nix build "github:ComposableFi/composable/refs/pull/4182/merge#devnet-xc-image" --allow-import-from-derivation --extra-experimental-features "flakes nix-command" --no-sandbox --accept-flake-config --option sandbox relaxed \
&& docker load --input result && docker run -it --entrypoint bash devnet-xc:latest -c /bin/devnet-xc-fresh 

About nix

@dzmitry-lahoda dzmitry-lahoda changed the title feat(cvm): eth chains and transfer support feat(cvm): initial eth support (transfer Oct 9, 2023
@dzmitry-lahoda dzmitry-lahoda changed the title feat(cvm): initial eth support (transfer feat(cvm): initial eth support (wires until final step transfer shortcut , eth abi message, erc20) Oct 9, 2023
@dzmitry-lahoda dzmitry-lahoda requested a review from kkast October 9, 2023 18:39
@dzmitry-lahoda dzmitry-lahoda marked this pull request as ready for review October 9, 2023 18:39
@dzmitry-lahoda dzmitry-lahoda enabled auto-merge (squash) October 9, 2023 18:40
kkast
kkast previously requested changes Oct 10, 2023
mina86
mina86 previously approved these changes Oct 10, 2023
pub fn ibc_ics_20_transfer_shortcut(
deps: Deps,
msg: &xc_core::gateway::BridgeForwardMsg,
) -> Result<IbcIcs20TransferShortcutRoute, ContractError> {
Copy link
Contributor

Choose a reason for hiding this comment

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

This sounds like -> Result<Option<IbcIcs20TransferShortcutRoute>, ContractError> to me and Ok(None) returned if use_shortcut is false or unset I guess.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

option with/vs result opinionated.

my opinion if there is result there is no need option, given rust made results as ergonomic as options, do not see reason to use option.

also soon rust will have keyword generics around result (at least they say), even more less need to use option.

also in case of error like no asset/connection - neither option/result observable as it tries to invoke general program, so it does not improves debugging.

also some languages ditch options, like Roc, as lead to more onsistentencies, Option, is just Result<T,()>

Copy link
Contributor

Choose a reason for hiding this comment

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

If the error this function returns doesn’t matter and is never inspected than this should be Option<IbcIcs20TransferShortcutRoute> then. If the function returns an error and the error is ignored, that raises questions. My understanding of this function is that it can return:

  • an error which should be propagated,
  • None if shortcut is disabled or
  • Some(shortcut) if shortcut is enabled.

Thus my suggestion is Result<Option<_>, _>. This isn’t opinionated. It better documents what the function returns.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If the error this function returns doesn’t matter and is never inspected than this should be Option then

than i have instead of writing ? to collapse it to None manually? right? until rust will make any error to be None ?, i recall it was not the case some time ago.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

if the function returns an error and the error is ignored, that raises questions.

why than not raises question ignoring errors inside function if it returns Option? and error is not ignored, it just tells that there is no shortcut for some reason. later I can log it just to see traces from production on routes resolutions. so i better return error and have logs higher level, than make option and prevent higher level to debug.

Copy link
Contributor Author

@dzmitry-lahoda dzmitry-lahoda Oct 10, 2023

Choose a reason for hiding this comment

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

an error which should be propagated,
None if shortcut is disabled or
Some(shortcut) if shortcut is enabled.
Thus my suggestion is Result<Option<_>, _>. This isn’t opinionated. It better documents what the function returns.

I understand these words, but thing is i do not see how it helps ergonomics/debugging, it may help some readers, but that is opinionated.

Copy link
Contributor

Choose a reason for hiding this comment

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

than i have instead of writing ? to collapse it to None manually? right? until rust will make any error to be None ?, i recall it was not the case some time ago.

I don’t understand what you’re asking. You’re currently ignoring the error. If the function can fail in a way which needs to be propagated further than it should return Result and you can use ? to handle the error. If the function indicates whether shortcut should be used and returns that shortcut if so than there are no errors to consider and you don’t need ?.

why than not raises question ignoring errors inside function if it returns Option?

Because if the function returns an Option than the implication is that it doesn’t fail. That’s the difference for having Result and Option as separate type. Documenting semantics of the values.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If I would return Option, but one of methods called inside returns error. Would ? make Result in case of error become None? So I do not have to call something .map_error_to_option().

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I would be happy to document failing to solve shortcut as one of enum variants.

Method tries to get shortcut route, it cannot get, it errors. Why? Because either no connection or shortcut disabled, or other reason. For me option is just another case. Specifically direct IBC ICS20 connection not found. But later for sure will have non direct solutions by unrolling prefix path (need to build index for that so). In this case no direct connection means nothing. So would no direction be error or option? I would prefer error so I can log it for tracing.

Copy link
Contributor

Choose a reason for hiding this comment

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

If I would return Option, but one of methods called inside returns error. Would ? make Result in case of error become None? So I do not have to call something .map_error_to_option().

If one of the calls return an error, why isn’t it propagated? (And for function returning Option, dealing with Result is just .ok()?).

Method tries to get shortcut route, it cannot get, it errors. Why? Because either no connection or shortcut disabled, or other reason.

But shortcut being disabled is not an error. Unless I misunderstand something, there are three possible options: shortcut, no shortcut or error. If shortcut is enabled and resolved correctly, caller uses the shortcut; if shortcut is disabled, caller uses full path; and if some error while figuring out error happens, caller propagates that error. This is best modelled by Result<Option<_>, _>. With plain Result<_> the caller must now match on the error type to decide whether error needs to be propagated or ‘no shortcut’ path chosen.


let coin = Coin::new(amount.0, route.local_native_denom.clone());
let (msg, event) = if let Ok(transfer_shortcut) =
ibc_ics_20_transfer_shortcut(deps.as_ref(), &msg)
Copy link
Contributor

Choose a reason for hiding this comment

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

Why are we ignoring error? As commented on the function, it seems to me that this function should return Result<Option<_>, _> and then this would be if let Some(shortcut) = ibc_ics_20_transfer_shortcut(deps.as_ref(), &msg)?.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

will be in next PR to act according shortcut. now no chains configured to use it.

unimplemented!("add tracking lock for funds return usual cosmos message to transfer as defined in {:?}", transfer_shortcut);

dzmitry-lahoda and others added 2 commits October 10, 2023 15:01
Co-authored-by: Michal Nazarewicz <mina86@mina86.com>
Signed-off-by: dzmitry-lahoda <dzmitry@lahoda.pro>
@dzmitry-lahoda
Copy link
Contributor Author

@mina86 will improve that big use routes to send message method in next PR where will use all routes.

I will not use result<option< , see my comment.

mina86
mina86 previously approved these changes Oct 10, 2023
@dzmitry-lahoda dzmitry-lahoda merged commit 054ee16 into main Oct 10, 2023
@dzmitry-lahoda dzmitry-lahoda deleted the dz/b/9 branch October 10, 2023 16:57
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