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: Re-arrange Chains traits for better composability #3912

Merged
merged 7 commits into from
Aug 31, 2023

Conversation

ramizhasan111
Copy link
Contributor

@ramizhasan111 ramizhasan111 commented Aug 29, 2023

Pull Request

Closes: PRO-803

Checklist

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

  • I am confident that the code works.
  • I have updated documentation where appropriate.

Summary

This PR re-arranges the Chain traits so that we can have a subset of associated types of the chain trait that can be re-used for multiple chains. Specifically, the ChainCrypto types that are shared across chains with the same crypto scheme (EVM chains for example). We can have one implementation of ChainCrypto trait for EVM chains that can then be re-used for all EVM chains. This then enables us to use a single key and a single threshold signature pallet that coordinates the signing for that ChainCrypto that can be shared across multiple chains. This would mean that in CFE we would have a single key and multisig client for all EVM chains .

Moreover, this also merges the ChainAbi trait into the main Chain trait since it didn't make too much sense to have a separate trait for abi types since it was already needed to be implemented for all chains alongside the Chain trait.

So, instead of having:

trait Chain {..}
trait ChainCrypto: Chain {..}
trait ChainAbi: ChainCrypto {..}.

we have

trait Chain {
 	type ChainCrypto: ChainCrypto;
	...
}

@codecov
Copy link

codecov bot commented Aug 29, 2023

Codecov Report

Merging #3912 (c7622a9) into main (c44279b) will decrease coverage by 0%.
The diff coverage is 56%.

@@          Coverage Diff          @@
##            main   #3912   +/-   ##
=====================================
- Coverage     71%     71%   -0%     
=====================================
  Files        366     370    +4     
  Lines      56798   56837   +39     
  Branches   56798   56837   +39     
=====================================
+ Hits       40545   40555   +10     
- Misses     14240   14252   +12     
- Partials    2013    2030   +17     
Files Changed Coverage Δ
engine/multisig/src/crypto.rs 76% <ø> (ø)
engine/multisig/src/crypto/bitcoin.rs 91% <0%> (-1%) ⬇️
engine/multisig/src/crypto/ed25519.rs 86% <ø> (ø)
engine/multisig/src/crypto/key_id.rs 63% <ø> (ø)
engine/src/multisig.rs 0% <0%> (ø)
engine/src/p2p.rs 16% <0%> (ø)
.../state_chain_observer/sc_observer/crypto_compat.rs 0% <0%> (ø)
engine/src/witness/common.rs 0% <ø> (ø)
...nked_chain_source/chunked_by_vault/egress_items.rs 0% <ø> (ø)
engine/src/witness/eth/key_manager.rs 0% <0%> (ø)
... and 68 more

... and 4 files with indirect coverage changes

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@ramizhasan111 ramizhasan111 marked this pull request as ready for review August 29, 2023 10:37
Copy link
Contributor

@kylezs kylezs left a comment

Choose a reason for hiding this comment

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

traits are fun 😄

engine/multisig/src/crypto/bitcoin.rs Outdated Show resolved Hide resolved
state-chain/chains/src/eth.rs Outdated Show resolved Hide resolved
@kylezs
Copy link
Contributor

kylezs commented Aug 29, 2023

meta comment: given this is a refactor... it should be refactor: and probably something more specific than this too, like refactor: move ChainAbi inside Chain trait :)

@msgmaxim
Copy link
Contributor

meta comment: given this is a refactor... it should be refactor: and probably something more specific than this too, like refactor: move ChainAbi inside Chain trait :)

I agree. Also, could we require (if we don't already) that each (non-trivial) PR should have a short summary with context/motivation? I try to make my PRs accessible to everyone, but I find it hard to keep up with changes coming from Berlin if they don't provide context.

@linear
Copy link

linear bot commented Aug 30, 2023

@dandanlen
Copy link
Collaborator

dandanlen commented Aug 30, 2023

meta comment: given this is a refactor... it should be refactor: and probably something more specific than this too, like refactor: move ChainAbi inside Chain trait :)

I agree. Also, could we require (if we don't already) that each (non-trivial) PR should have a short summary with context/motivation? I try to make my PRs accessible to everyone, but I find it hard to keep up with changes coming from Berlin if they don't provide context.

+1

@ramizhasan111 the PR template is there for a reason ;)

I've added some Linear issues to track this, am aware there were none.

@ramizhasan111
Copy link
Contributor Author

+1

@ramizhasan111 the PR template is there for a reason ;)

Sorry, thought about writing it but got a bit lazy haha
@msgmaxim i have added the summary now :)

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.

Looking good 👍

state-chain/chains/src/lib.rs Outdated Show resolved Hide resolved
payload: &<Abi as ChainCrypto>::Payload,
current_key: &<Abi as ChainCrypto>::AggKey,
signature: &<Abi as ChainCrypto>::ThresholdSignature,
payload: &<<C as Chain>::ChainCrypto as ChainCrypto>::Payload,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Similar to the XFor<T, I> type aliases in the pallets, we could create:

type AggKeyFor<C> = <<C as Chain>::ChainCrypto as ChainCrypto>::AggKey; etc.

Might remove some of the noise from these declarations? For example this would become:
payload: &PayloadFor<C>,

state-chain/chains/src/lib.rs Outdated Show resolved Hide resolved
state-chain/chains/src/eth.rs Outdated Show resolved Hide resolved
@ramizhasan111 ramizhasan111 changed the title feat: Chains traits refactor refactor: Re-arrange Chains traits for better composability Aug 30, 2023
@ramizhasan111 ramizhasan111 requested a review from a team as a code owner August 30, 2023 15:23
@ramizhasan111 ramizhasan111 requested review from niklasnatter and zoheb391 and removed request for a team August 30, 2023 15:23
@msgmaxim
Copy link
Contributor

+1
@ramizhasan111 the PR template is there for a reason ;)

Sorry, thought about writing it but got a bit lazy haha @msgmaxim i have added the summary now :)

Thanks! 🙂

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.

One minor suggestion, apart from that LGTM.

state-chain/chains/src/eth/api/register_redemption.rs Outdated Show resolved Hide resolved
@dandanlen
Copy link
Collaborator

Please let's update from main and make sure there are no hidden conflicts.

@dandanlen dandanlen merged commit fa452ac into main Aug 31, 2023
42 checks passed
@dandanlen dandanlen deleted the feat/better-chain-traits branch August 31, 2023 18:18
syan095 added a commit that referenced this pull request Sep 4, 2023
* origin/main:
  Fix: Correct Select Median Implementation (#3934)
  fix: independent witnessing startup (#3913)
  🍒 cherry-pick: changes in release for CI and chainspec (#3933)
  refactor: Re-arrange Chains traits for better composability (#3912)
  fix: log error when we try to transfer *more* than we have fetched (#3930)
  chore: add checks and increase timeout (#3928)
  Add `bind_redeem_address` to CLI (#3908)
  🍒 cherry-pick: add missing prod dockerfiles (#3926)
  chore: skip localnet specific tests in devnet 🤫 (#3919)
  fix: broadcast success should be witnessable after a rotation (#3921)

# Conflicts:
#	state-chain/chains/src/eth/api.rs
#	state-chain/runtime/src/chainflip.rs
syan095 added a commit that referenced this pull request Sep 5, 2023
…on-integration

* origin/main:
  Added CFE setting for logging span lifecycles (#3936)
  fix: only burn flip if non zero (#3932)
  Fix: Correct Select Median Implementation (#3934)
  fix: independent witnessing startup (#3913)
  🍒 cherry-pick: changes in release for CI and chainspec (#3933)
  refactor: Re-arrange Chains traits for better composability (#3912)
  fix: log error when we try to transfer *more* than we have fetched (#3930)
  chore: add checks and increase timeout (#3928)
  Add `bind_redeem_address` to CLI (#3908)
  🍒 cherry-pick: add missing prod dockerfiles (#3926)
  chore: skip localnet specific tests in devnet 🤫 (#3919)
  fix: broadcast success should be witnessable after a rotation (#3921)

# Conflicts:
#	state-chain/cf-integration-tests/src/network.rs
dandanlen added a commit that referenced this pull request Sep 6, 2023
Co-authored-by: dandanlen <3168260+dandanlen@users.noreply.github.com>
dandanlen added a commit that referenced this pull request Sep 6, 2023
Co-authored-by: dandanlen <3168260+dandanlen@users.noreply.github.com>
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

4 participants