Polkadot-Blockchain-Academy / Academy-PoW

PoW blockchain node to gain hands-on experience starting a real network together
The Unlicense
24 stars 43 forks source link

Add Ethereum components from Frontier #9

Closed notlesh closed 1 year ago

notlesh commented 1 year ago

This PR adds Ethereum compatibility components from Frontier. Solves #4.

TODO:

notlesh commented 1 year ago

@JoshOrndorff 5641c09 adds a pallet designed to impl pallet_evm::AddressMapping in a very trivial way. PTAL and see if you think that's appropriate.

Briefly, it maps H160 -> AccountId32 insecurely. origin must be signed and the signer's account id is used for the mapping. No updates are allowed, only new mappings if no such entry exists.

JoshOrndorff commented 1 year ago

Indeed, this simple pallet is what I had in mind. I think you will need to store the mapping in both directions though. If I remember correctly, the one you have is for the account mapping, and you will need the other one for the withdraw origin.

notlesh commented 1 year ago

FYI, I've merged main after #10, resolved conflicts with git checkout --ours, then ran cargo fmt to reintroduce the format changes. I may have lost some clippy fixes but CI should catch that, right @fbielejec ? (I have compilation errors that prevent clippy from running at the moment)

fbielejec commented 1 year ago

FYI, I've merged main after #10, resolved conflicts with git checkout --ours, then ran cargo fmt to reintroduce the format changes. I may have lost some clippy fixes but CI should catch that, right @fbielejec ? (I have compilation errors that prevent clippy from running at the moment)

Correct - clippy is "deterministic" so as long as you have the same stable version of rust the lints it proposes will be the same as on CI server (same for fmt)

notlesh commented 1 year ago

Merge main conflicts resolved, but there were some logical conflicts it introduced, e.g.:

error[E0761]: file for module `rpc` found at both "node/src/rpc.rs" and "node/src/rpc/mod.rs"

Which I'll work on $soon.

JoshOrndorff commented 1 year ago

I'm testing this manually trying to get it merged soon. I want to be able to deploy and execute some contract in the evm, and I can't yet do that.

I'm trying with remix and also with polkadot js apps. Trying the node in instant seal and pow. It seems like I'm having fee related issues. Is there some particular gas price you have in mind, or other tips?

JoshOrndorff commented 1 year ago

I've messed with the address mapping a little bit. One bug I noticed is that both Alice and Bob can map the same ethereum H160 address, let's call it Gerald. This is trouble because if Gerald sends an eth transaction to pallet ethereum, only one of Alice or Bob will be charged fees.

It might be nice to make a similar check to the one you make for Native addresses first.

On a related note, I've got a start installing unified accounts which I think would be really nice in #20. What do you think about using that and eliminating the manual mapping?

One thing we have to check is whether tolls that were built for pallet contracts are smart enough to support that.

JoshOrndorff commented 1 year ago

I've disabled fees, and I'm now able to deploy and call a contract using polkadot js. That's a good start! Now to Metamask.

I can see my balance (with a funny number of decimals). But when I try to send tokens the transactions fail.