Skip to content

Registry sketch and implementation for EVM chains #1

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

Merged
merged 16 commits into from
Nov 8, 2022
Merged

Conversation

tolak
Copy link
Collaborator

@tolak tolak commented Oct 28, 2022

This PR introduces the Registry module, which will contain the registration of

  • EVM chain registration (implemented in this PR)
  • Substrate chain registration (upcoming PR)
  • Bridge registration (upcoming PR)
  • Dex registration (upcoming PR)

@tolak tolak force-pushed the registry/evm-chain branch from 1994ce5 to 2a8b1e5 Compare November 3, 2022 11:24
@tolak tolak marked this pull request as draft November 4, 2022 06:40
@tolak
Copy link
Collaborator Author

tolak commented Nov 4, 2022

Convert this PR to draft, will be opened again when finished refactor

@tolak tolak marked this pull request as ready for review November 7, 2022 13:48
@tolak tolak changed the title Evm chain basic functions Registry sketch and implementation for EVM chains Nov 7, 2022
Copy link
Contributor

@tenheadedlion tenheadedlion left a comment

Choose a reason for hiding this comment

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

LGTM, there are 2 points I want to discuss:

  1. Is there a workaround to keep the current functionalities but remove the ink dependencies from the index module? the existence of ink libraries lessens the feel of SDK in index/.
  2. abi.json should be placed in the application layer(the contracts/)

For the first point, I think it's possible to get rid of SpreadLayout and PackedLayout

// somewhere in index/
// don't care about SpreadLayout, which may not make it to ink4.0, introducing it breaks the abstraction
pub struct EvmChain {
    info: ChainInfo,
    assets: Vec<AssetInfo>
}

// somewhere in contracts/
#[ink(storage)]
pub struct SomeStorage {
   map: Mapping<String, Vec<u8>> // or [u8; 1024]
}

// in a contract method:
fn register_method(args: ...) {
  // create an EvmChain
 let chain = EvmChain::from(args...);
 self.map.insert(args.name, 
  chain.encode() // or: somehow, if `Vec<u8>` is not allowed as the value type of the mapping, think of a way to do this: `chain.to_array()`
);
}

@@ -15,6 +18,9 @@ hex = { version = "0.4.3", default-features = false }
pink-extension = { version = "0.1", default-features = false, features = ["ink-as-dependency"] }
pink-web3 = { git = "https://github.com/Phala-Network/pink-web3.git", branch = "pink", default-features = false, features = ["pink", "signing"]}
xcm = { git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.29", default-features = false }
ink_storage = { version = "3", default-features = false }
Copy link
Contributor

Choose a reason for hiding this comment

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

In a previous PR I deliberately remove these ink! dependencies, is there a way we can do without them?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I totally understand, however, due to the layout mechanism of Ink storage, If we'd like to store our types in storage, we must declare types with layout derived. Like this issue talked about. There is why ink_storage was introduced, sure we can save everything in the contract as bytes, but that's also bad for the code readability. Ink4 seems abandon the layout, haven't gotten a certain answer from the team.

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't see why storing things in bytes in contracts is bad for readability, with a pair of proper encoder and decoder there is no problem with readability. Actually ink! is the cause of unreadability, there is no need for ink to stay in index/, if you don't have time, I can take care of it in another PR

@@ -0,0 +1,156 @@
[
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we move this abi.json into the contracts/ directory?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

If index contains stuff to interact with EVM contract, it's ok to put it here. Why you said it should belong to the application layer?

Copy link
Contributor

Choose a reason for hiding this comment

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

let's say it's just a matter of aesthetics, if index is playing the role of SDK, or Engine, then it shouldn't configure itself inside, it should provide an interface for users to configure it. If something should be hardcoded then it should be placed somewhere like constants.rs or abis.rs, anything that exists in the form of an asset(like png, txt) is suspiciously not a part of the code and should be placed outside, as the input to the application.

@tenheadedlion tenheadedlion self-requested a review November 8, 2022 05:01
Copy link
Contributor

@tenheadedlion tenheadedlion left a comment

Choose a reason for hiding this comment

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

There are disagreements on styles and readability, let's find another time to talk about these things

transport,
// PHA address
token_address,
include_bytes!("./res/erc20-abi.json"),
Copy link
Contributor

Choose a reason for hiding this comment

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

my two cents objection to hardcoding: It seems like EvmChain can be initiated from abi_json:

impl EvmChain {
   fn new( abi_json: &[u8], ...) -> Result<Self>
}

EvmChain is intended to be initiated in the contract layer, you can pass the abi.json to its constructor in some contract method.

or you can let EvmChain carries the abi_json, which is absolutely not a good idea because abi is used once and once only.

pub struct EvmChain {
    pub info: ChainInfo,
    pub assets: Vec<AssetInfo>,
    abi: Vec<u8>
}

@@ -15,6 +18,9 @@ hex = { version = "0.4.3", default-features = false }
pink-extension = { version = "0.1", default-features = false, features = ["ink-as-dependency"] }
pink-web3 = { git = "https://github.com/Phala-Network/pink-web3.git", branch = "pink", default-features = false, features = ["pink", "signing"]}
xcm = { git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.29", default-features = false }
ink_storage = { version = "3", default-features = false }
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't see why storing things in bytes in contracts is bad for readability, with a pair of proper encoder and decoder there is no problem with readability. Actually ink! is the cause of unreadability, there is no need for ink to stay in index/, if you don't have time, I can take care of it in another PR

@@ -0,0 +1,156 @@
[
Copy link
Contributor

Choose a reason for hiding this comment

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

let's say it's just a matter of aesthetics, if index is playing the role of SDK, or Engine, then it shouldn't configure itself inside, it should provide an interface for users to configure it. If something should be hardcoded then it should be placed somewhere like constants.rs or abis.rs, anything that exists in the form of an asset(like png, txt) is suspiciously not a part of the code and should be placed outside, as the input to the application.

@tolak tolak merged commit 38f0326 into main Nov 8, 2022
@tolak tolak deleted the registry/evm-chain branch November 8, 2022 05:58
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