-
Notifications
You must be signed in to change notification settings - Fork 4
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
Conversation
91e2d25
to
1994ce5
Compare
1994ce5
to
2a8b1e5
Compare
Convert this PR to draft, will be opened again when finished refactor |
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.
LGTM, there are 2 points I want to discuss:
- Is there a workaround to keep the current functionalities but remove the
ink
dependencies from theindex
module? the existence ofink
libraries lessens the feel ofSDK
inindex/
. - 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 } |
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.
In a previous PR I deliberately remove these ink! dependencies, is there a way we can do without them?
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 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.
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 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 @@ | |||
[ |
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.
Can we move this abi.json
into the contracts/ directory?
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.
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?
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.
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.
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.
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"), |
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.
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 } |
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 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 @@ | |||
[ |
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.
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.
This PR introduces the
Registry
module, which will contain the registration of