diff --git a/Cargo.lock b/Cargo.lock index 7fc391ca1..e6be00dc4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -59,7 +59,7 @@ dependencies = [ "cipher", "ctr", "ghash", - "subtle", + "subtle 2.4.1", ] [[package]] @@ -82,15 +82,6 @@ dependencies = [ "memchr", ] -[[package]] -name = "ansi_term" -version = "0.11.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ee49baf6cb617b853aa8d93bf420db2383fab46d314482ca2803b40d5fde979b" -dependencies = [ - "winapi 0.3.9", -] - [[package]] name = "ansi_term" version = "0.12.1" @@ -360,6 +351,18 @@ dependencies = [ "winapi 0.3.9", ] +[[package]] +name = "auto_impl" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7862e21c893d65a1650125d157eaeec691439379a1cee17ee49031b79236ada4" +dependencies = [ + "proc-macro-error", + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "autocfg" version = "1.0.1" @@ -847,11 +850,11 @@ dependencies = [ [[package]] name = "clap" -version = "2.33.3" +version = "2.34.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "37e58ac78573c40708d45522f0d80fa2f01cc4f9b4e2bf749807255454312002" +checksum = "a0610544180c38b88101fecf2dd634b174a62eef6946f84dfc6a7127512b381c" dependencies = [ - "ansi_term 0.11.0", + "ansi_term", "atty", "bitflags", "strsim", @@ -986,6 +989,16 @@ version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7a81dae078cea95a014a339291cec439d2f232ebe854a9d672b796c6afafa9b7" +[[package]] +name = "crypto-mac" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4434400df11d95d556bac068ddfedd482915eb18fe8bea89bc80b6e4b1c179e5" +dependencies = [ + "generic-array 0.12.4", + "subtle 1.0.0", +] + [[package]] name = "crypto-mac" version = "0.8.0" @@ -993,7 +1006,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b584a330336237c1eecd3e94266efb216c56ed91225d634cb2991c5f3fd1aeab" dependencies = [ "generic-array 0.14.4", - "subtle", + "subtle 2.4.1", ] [[package]] @@ -1003,7 +1016,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b1d1a86f49236c215f271d40892d5fc950490551400b02ef360692c29815c714" dependencies = [ "generic-array 0.14.4", - "subtle", + "subtle 2.4.1", ] [[package]] @@ -1054,7 +1067,7 @@ dependencies = [ "byteorder", "digest 0.8.1", "rand_core 0.5.1", - "subtle", + "subtle 2.4.1", "zeroize", ] @@ -1067,7 +1080,7 @@ dependencies = [ "byteorder", "digest 0.9.0", "rand_core 0.5.1", - "subtle", + "subtle 2.4.1", "zeroize", ] @@ -1289,12 +1302,139 @@ version = "1.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "68b91989ae21441195d7d9b9993a2f9295c7e1a8c96255d8b729accddc124797" +[[package]] +name = "ethbloom" +version = "0.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bfb684ac8fa8f6c5759f788862bb22ec6fe3cb392f6bfd08e3c64b603661e3f8" +dependencies = [ + "crunchy", + "fixed-hash", + "impl-codec", + "impl-rlp", + "impl-serde", + "scale-info", + "tiny-keccak", +] + +[[package]] +name = "ethereum" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "81fb916554a4dba293ea69c69ad5653e21d770a9d0c2496b5fa0a1f5a3946d87" +dependencies = [ + "bytes 1.1.0", + "ethereum-types", + "hash-db", + "hash256-std-hasher", + "parity-scale-codec", + "rlp", + "rlp-derive", + "scale-info", + "serde", + "sha3 0.9.1", + "triehash", +] + +[[package]] +name = "ethereum" +version = "0.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34c90e0a755da706ce0970ec0fa8cc48aabcc8e8efa1245336acf718dab06ffe" +dependencies = [ + "bytes 1.1.0", + "ethereum-types", + "hash-db", + "hash256-std-hasher", + "parity-scale-codec", + "rlp", + "rlp-derive", + "scale-info", + "serde", + "sha3 0.9.1", + "triehash", +] + +[[package]] +name = "ethereum-types" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "05136f7057fe789f06e6d41d07b34e6f70d8c86e5693b60f97aaa6553553bdaf" +dependencies = [ + "ethbloom", + "fixed-hash", + "impl-codec", + "impl-rlp", + "impl-serde", + "primitive-types", + "scale-info", + "uint", +] + [[package]] name = "event-listener" version = "2.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f7531096570974c3a9dcf9e4b8e1cede1ec26cf5046219fb3b9d897503b9be59" +[[package]] +name = "evm" +version = "0.33.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "408ffdd509e16de15ea9b51f5333748f6086601f29d445d2ba53dd7e95565574" +dependencies = [ + "auto_impl", + "environmental", + "ethereum 0.11.1", + "evm-core", + "evm-gasometer", + "evm-runtime", + "log", + "parity-scale-codec", + "primitive-types", + "rlp", + "scale-info", + "serde", + "sha3 0.8.2", +] + +[[package]] +name = "evm-core" +version = "0.33.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4dfe4f2a56c4c05a8107b8596380e2332fc2019ffcf56b8f2d01971393a30c4d" +dependencies = [ + "funty", + "parity-scale-codec", + "primitive-types", + "scale-info", + "serde", +] + +[[package]] +name = "evm-gasometer" +version = "0.33.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c446679607eacac4e8c8738e20c97ea9b3c86eddd8b43666744b05f416037bd9" +dependencies = [ + "environmental", + "evm-core", + "evm-runtime", + "primitive-types", +] + +[[package]] +name = "evm-runtime" +version = "0.33.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "419e8434ac6e850a8a4bc09a19406264582d1940913b2920be2af948f4ffc49b" +dependencies = [ + "environmental", + "evm-core", + "primitive-types", + "sha3 0.8.2", +] + [[package]] name = "exit-future" version = "0.2.0" @@ -1334,6 +1474,131 @@ dependencies = [ "instant", ] +[[package]] +name = "fc-consensus" +version = "2.0.0-dev" +source = "git+https://github.com/humanode-network/frontier?branch=substrate-1a30fa2#864ef8d7e97ede08c758394c5f9e2a57bbef7218" +dependencies = [ + "async-trait", + "derive_more", + "fc-db", + "fp-consensus", + "fp-rpc", + "futures 0.3.17", + "log", + "parity-scale-codec", + "sc-client-api", + "sc-consensus", + "sp-api", + "sp-block-builder", + "sp-blockchain", + "sp-consensus", + "sp-core", + "sp-inherents", + "sp-runtime", + "sp-timestamp", + "substrate-prometheus-endpoint", +] + +[[package]] +name = "fc-db" +version = "2.0.0-dev" +source = "git+https://github.com/humanode-network/frontier?branch=substrate-1a30fa2#864ef8d7e97ede08c758394c5f9e2a57bbef7218" +dependencies = [ + "fp-storage", + "kvdb", + "kvdb-rocksdb", + "pallet-ethereum", + "parity-scale-codec", + "parking_lot", + "sp-core", + "sp-database", + "sp-runtime", +] + +[[package]] +name = "fc-mapping-sync" +version = "2.0.0-dev" +source = "git+https://github.com/humanode-network/frontier?branch=substrate-1a30fa2#864ef8d7e97ede08c758394c5f9e2a57bbef7218" +dependencies = [ + "fc-consensus", + "fc-db", + "fp-consensus", + "fp-rpc", + "futures 0.3.17", + "futures-timer 3.0.2", + "log", + "sc-client-api", + "sp-api", + "sp-blockchain", + "sp-runtime", +] + +[[package]] +name = "fc-rpc" +version = "2.0.0-dev" +source = "git+https://github.com/humanode-network/frontier?branch=substrate-1a30fa2#864ef8d7e97ede08c758394c5f9e2a57bbef7218" +dependencies = [ + "ethereum 0.11.1", + "ethereum-types", + "evm", + "fc-consensus", + "fc-db", + "fc-rpc-core", + "fp-consensus", + "fp-evm", + "fp-rpc", + "fp-storage", + "futures 0.3.17", + "jsonrpc-core", + "jsonrpc-core-client", + "jsonrpc-derive", + "jsonrpc-pubsub", + "libsecp256k1 0.3.5", + "log", + "lru 0.6.6", + "pallet-ethereum", + "pallet-evm", + "parity-scale-codec", + "parking_lot", + "rand 0.7.3", + "rlp", + "rustc-hex", + "sc-client-api", + "sc-network", + "sc-rpc", + "sc-service", + "sc-transaction-pool", + "sc-transaction-pool-api", + "sha3 0.8.2", + "sp-api", + "sp-block-builder", + "sp-blockchain", + "sp-io", + "sp-runtime", + "sp-storage", + "sp-transaction-pool", + "tokio", +] + +[[package]] +name = "fc-rpc-core" +version = "1.1.0-dev" +source = "git+https://github.com/humanode-network/frontier?branch=substrate-1a30fa2#864ef8d7e97ede08c758394c5f9e2a57bbef7218" +dependencies = [ + "ethereum 0.11.1", + "ethereum-types", + "jsonrpc-core", + "jsonrpc-core-client", + "jsonrpc-derive", + "jsonrpc-pubsub", + "rlp", + "rustc-hex", + "serde", + "serde_json", + "sha3 0.8.2", +] + [[package]] name = "fdlimit" version = "0.2.1" @@ -1438,6 +1703,71 @@ dependencies = [ "percent-encoding 2.1.0", ] +[[package]] +name = "fp-consensus" +version = "2.0.0-dev" +source = "git+https://github.com/humanode-network/frontier?branch=substrate-1a30fa2#864ef8d7e97ede08c758394c5f9e2a57bbef7218" +dependencies = [ + "ethereum 0.11.1", + "parity-scale-codec", + "rlp", + "sha3 0.8.2", + "sp-core", + "sp-runtime", + "sp-std", +] + +[[package]] +name = "fp-evm" +version = "3.0.0-dev" +source = "git+https://github.com/humanode-network/frontier?branch=substrate-1a30fa2#864ef8d7e97ede08c758394c5f9e2a57bbef7218" +dependencies = [ + "evm", + "parity-scale-codec", + "serde", + "sp-core", + "sp-std", +] + +[[package]] +name = "fp-rpc" +version = "3.0.0-dev" +source = "git+https://github.com/humanode-network/frontier?branch=substrate-1a30fa2#864ef8d7e97ede08c758394c5f9e2a57bbef7218" +dependencies = [ + "ethereum 0.11.1", + "ethereum-types", + "fp-evm", + "parity-scale-codec", + "scale-info", + "sp-api", + "sp-core", + "sp-io", + "sp-runtime", + "sp-std", +] + +[[package]] +name = "fp-self-contained" +version = "1.0.0-dev" +source = "git+https://github.com/humanode-network/frontier?branch=substrate-1a30fa2#864ef8d7e97ede08c758394c5f9e2a57bbef7218" +dependencies = [ + "ethereum 0.10.0", + "frame-support", + "parity-scale-codec", + "parity-util-mem", + "scale-info", + "serde", + "sha3 0.8.2", + "sp-core", + "sp-io", + "sp-runtime", +] + +[[package]] +name = "fp-storage" +version = "2.0.0" +source = "git+https://github.com/humanode-network/frontier?branch=substrate-1a30fa2#864ef8d7e97ede08c758394c5f9e2a57bbef7218" + [[package]] name = "fragile" version = "1.0.0" @@ -1623,6 +1953,16 @@ dependencies = [ "sp-api", ] +[[package]] +name = "frontier-api" +version = "0.1.0" +dependencies = [ + "pallet-ethereum", + "parity-scale-codec", + "sp-api", + "sp-std", +] + [[package]] name = "fs-swap" version = "0.2.6" @@ -1690,9 +2030,9 @@ dependencies = [ [[package]] name = "futures-channel" -version = "0.3.17" +version = "0.3.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5da6ba8c3bb3c165d3c7319fc1cc8304facf1fb8db99c5de877183c08a273888" +checksum = "ba3dda0b6588335f360afc675d0564c17a77a2bda81ca178a4b6081bd86c7f0b" dependencies = [ "futures-core", "futures-sink", @@ -1700,9 +2040,9 @@ dependencies = [ [[package]] name = "futures-core" -version = "0.3.17" +version = "0.3.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "88d1c26957f23603395cd326b0ffe64124b818f4449552f960d815cfba83a53d" +checksum = "d0c8ff0461b82559810cdccfde3215c3f373807f5e5232b71479bff7bb2583d7" [[package]] name = "futures-executor" @@ -1718,9 +2058,9 @@ dependencies = [ [[package]] name = "futures-io" -version = "0.3.17" +version = "0.3.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "522de2a0fe3e380f1bc577ba0474108faf3f6b18321dbf60b3b9c39a75073377" +checksum = "b1f9d34af5a1aac6fb380f735fe510746c38067c5bf16c7fd250280503c971b2" [[package]] name = "futures-lite" @@ -1739,12 +2079,10 @@ dependencies = [ [[package]] name = "futures-macro" -version = "0.3.17" +version = "0.3.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "18e4a4b95cea4b4ccbcf1c5675ca7c4ee4e9e75eb79944d07defde18068f79bb" +checksum = "6dbd947adfffb0efc70599b3ddcf7b5597bb5fa9e245eb99f62b3a5f7bb8bd3c" dependencies = [ - "autocfg", - "proc-macro-hack", "proc-macro2", "quote", "syn", @@ -1763,15 +2101,15 @@ dependencies = [ [[package]] name = "futures-sink" -version = "0.3.17" +version = "0.3.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "36ea153c13024fe480590b3e3d4cad89a0cfacecc24577b68f86c6ced9c2bc11" +checksum = "e3055baccb68d74ff6480350f8d6eb8fcfa3aa11bdc1a1ae3afdd0514617d508" [[package]] name = "futures-task" -version = "0.3.17" +version = "0.3.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1d3d00f4eddb73e498a54394f228cd55853bdf059259e8e7bc6e69d408892e99" +checksum = "6ee7c6485c30167ce4dfb83ac568a849fe53274c831081476ee13e0dce1aad72" [[package]] name = "futures-timer" @@ -1787,11 +2125,10 @@ checksum = "e64b03909df88034c26dc1547e8970b91f98bdb65165d6a4e9110d94263dbb2c" [[package]] name = "futures-util" -version = "0.3.17" +version = "0.3.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "36568465210a3a6ee45e1f165136d68671471a501e632e9a98d96872222b5481" +checksum = "d9b5cf40b47a271f77a8b1bec03ca09044d99d2372c0de244e66430761127164" dependencies = [ - "autocfg", "futures 0.1.31", "futures-channel", "futures-core", @@ -1802,8 +2139,6 @@ dependencies = [ "memchr", "pin-project-lite 0.2.7", "pin-utils", - "proc-macro-hack", - "proc-macro-nested", "slab", ] @@ -1900,9 +2235,9 @@ dependencies = [ [[package]] name = "h2" -version = "0.3.7" +version = "0.3.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7fd819562fcebdac5afc5c113c3ec36f902840b70fd4fc458799c8ce4607ae55" +checksum = "0c9de88456263e249e241fcd211d3954e2c9b0ef7ccfc235a444eb367cae3689" dependencies = [ "bytes 1.1.0", "fnv", @@ -1919,9 +2254,9 @@ dependencies = [ [[package]] name = "handlebars" -version = "4.1.6" +version = "4.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "167fa173496c9eadd8749cca6f8339ac88e248f3ad2442791d0b743318a94fc0" +checksum = "2483bce82dd3ed52509d0117e4a30a488bd608be250ed7a0185301314239ed31" dependencies = [ "log", "pest", @@ -2016,6 +2351,16 @@ version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b07f60793ff0a4d9cef0f18e63b5357e06209987153a64648c972c1e5aff336f" +[[package]] +name = "hmac" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5dcb5e64cda4c23119ab41ba960d1e170a774c8e4b9d9e6a9bc18aabf5e59695" +dependencies = [ + "crypto-mac 0.7.0", + "digest 0.8.1", +] + [[package]] name = "hmac" version = "0.8.1" @@ -2036,6 +2381,17 @@ dependencies = [ "digest 0.9.0", ] +[[package]] +name = "hmac-drbg" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c6e570451493f10f6581b48cdd530413b63ea9e780f544bfd3bdcaa0d89d1a7b" +dependencies = [ + "digest 0.8.1", + "generic-array 0.12.4", + "hmac 0.7.1", +] + [[package]] name = "hmac-drbg" version = "0.3.0" @@ -2121,6 +2477,11 @@ dependencies = [ "async-trait", "bioauth-consensus", "bioauth-flow", + "fc-consensus", + "fc-db", + "fc-mapping-sync", + "fc-rpc", + "fc-rpc-core", "fdlimit", "frame-benchmarking-cli", "futures 0.3.17", @@ -2131,6 +2492,8 @@ dependencies = [ "indoc", "ngrok-api", "pallet-bioauth", + "pallet-dynamic-fee", + "pallet-evm", "parity-scale-codec", "qr2term", "reqwest", @@ -2145,6 +2508,7 @@ dependencies = [ "sc-executor", "sc-finality-grandpa", "sc-network", + "sc-rpc", "sc-service", "sc-telemetry", "sc-tracing", @@ -2155,6 +2519,7 @@ dependencies = [ "sp-application-crypto", "sp-consensus", "sp-consensus-aura", + "sp-core", "sp-finality-grandpa", "sp-keystore", "sp-panic-handler", @@ -2173,15 +2538,28 @@ version = "0.1.0" dependencies = [ "bioauth-flow", "bioauth-flow-api", + "fc-db", + "fc-rpc", + "fc-rpc-core", + "fp-rpc", + "frontier-api", "humanode-runtime", "jsonrpc-core", + "jsonrpc-pubsub", + "pallet-ethereum", "pallet-transaction-payment-rpc", + "primitives-frontier", "robonode-client", + "sc-client-api", + "sc-network", + "sc-rpc", "sc-rpc-api", + "sc-transaction-pool", "sc-transaction-pool-api", "sp-api", "sp-block-builder", "sp-blockchain", + "sp-runtime", "substrate-frame-rpc-system", ] @@ -2192,16 +2570,26 @@ dependencies = [ "bioauth-consensus-api", "bioauth-flow-api", "chrono", + "fp-rpc", + "fp-self-contained", "frame-benchmarking", "frame-executive", "frame-support", "frame-system", "frame-system-benchmarking", "frame-system-rpc-runtime-api", + "frontier-api", "hex-literal", "pallet-aura", "pallet-balances", + "pallet-base-fee", "pallet-bioauth", + "pallet-dynamic-fee", + "pallet-ethereum", + "pallet-evm", + "pallet-evm-precompile-modexp", + "pallet-evm-precompile-sha3fips", + "pallet-evm-precompile-simple", "pallet-grandpa", "pallet-randomness-collective-flip", "pallet-sudo", @@ -2229,9 +2617,9 @@ dependencies = [ [[package]] name = "hyper" -version = "0.14.14" +version = "0.14.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2b91bb1f221b6ea1f1e4371216b70f40748774c2fb5971b450c07773fb92d26b" +checksum = "b7ec3e62bdc98a2f0393a5048e4c30ef659440ea6e0e572965103e72bd836f55" dependencies = [ "bytes 1.1.0", "futures-channel", @@ -2349,6 +2737,15 @@ dependencies = [ "parity-scale-codec", ] +[[package]] +name = "impl-rlp" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f28220f89297a075ddc7245cd538076ee98b01f2a9c23a53a4f1105d5a322808" +dependencies = [ + "rlp", +] + [[package]] name = "impl-serde" version = "0.3.1" @@ -2805,7 +3202,7 @@ dependencies = [ "futures 0.3.17", "futures-timer 3.0.2", "lazy_static", - "libsecp256k1", + "libsecp256k1 0.7.0", "log", "multiaddr", "multihash 0.14.0", @@ -3055,7 +3452,7 @@ dependencies = [ "pin-project 1.0.8", "rand 0.7.3", "salsa20", - "sha3", + "sha3 0.9.1", ] [[package]] @@ -3234,6 +3631,22 @@ dependencies = [ "libc", ] +[[package]] +name = "libsecp256k1" +version = "0.3.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fc1e2c808481a63dc6da2074752fdd4336a3c8fcc68b83db6f1fd5224ae7962" +dependencies = [ + "arrayref", + "crunchy", + "digest 0.8.1", + "hmac-drbg 0.2.0", + "rand 0.7.3", + "sha2 0.8.2", + "subtle 2.4.1", + "typenum", +] + [[package]] name = "libsecp256k1" version = "0.7.0" @@ -3243,7 +3656,7 @@ dependencies = [ "arrayref", "base64", "digest 0.9.0", - "hmac-drbg", + "hmac-drbg 0.3.0", "libsecp256k1-core", "libsecp256k1-gen-ecmult", "libsecp256k1-gen-genmult", @@ -3261,7 +3674,7 @@ checksum = "5be9b9bb642d8522a44d533eab56c16c738301965504753b03ad1de3425d5451" dependencies = [ "crunchy", "digest 0.9.0", - "subtle", + "subtle 2.4.1", ] [[package]] @@ -3633,7 +4046,7 @@ dependencies = [ "generic-array 0.14.4", "multihash-derive", "sha2 0.9.8", - "sha3", + "sha3 0.9.1", "unsigned-varint 0.5.1", ] @@ -3846,6 +4259,20 @@ dependencies = [ "winapi 0.3.9", ] +[[package]] +name = "num" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "43db66d1170d347f9a065114077f7dccb00c1b9478c89384490a3425279a4606" +dependencies = [ + "num-bigint 0.4.3", + "num-complex", + "num-integer", + "num-iter", + "num-rational 0.4.0", + "num-traits", +] + [[package]] name = "num-bigint" version = "0.2.6" @@ -3857,6 +4284,17 @@ dependencies = [ "num-traits", ] +[[package]] +name = "num-bigint" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f93ab6289c7b344a8a9f60f88d80aa20032336fe78da341afc91c8a2341fc75f" +dependencies = [ + "autocfg", + "num-integer", + "num-traits", +] + [[package]] name = "num-complex" version = "0.4.0" @@ -3876,6 +4314,17 @@ dependencies = [ "num-traits", ] +[[package]] +name = "num-iter" +version = "0.1.42" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b2021c8337a54d21aca0d59a92577a029af9431cb59b909b03252b9c164fad59" +dependencies = [ + "autocfg", + "num-integer", + "num-traits", +] + [[package]] name = "num-rational" version = "0.2.4" @@ -3883,7 +4332,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5c000134b5dbf44adc5cb772486d335293351644b801551abe8f75c84cfa4aef" dependencies = [ "autocfg", - "num-bigint", + "num-bigint 0.2.6", "num-integer", "num-traits", ] @@ -3895,6 +4344,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d41702bd167c2df5520b384281bc111a4b5efcf7fbc4c9c222c815b07e0a6a6a" dependencies = [ "autocfg", + "num-bigint 0.4.3", "num-integer", "num-traits", ] @@ -4057,6 +4507,21 @@ dependencies = [ "sp-std", ] +[[package]] +name = "pallet-base-fee" +version = "1.0.0" +source = "git+https://github.com/humanode-network/frontier?branch=substrate-1a30fa2#864ef8d7e97ede08c758394c5f9e2a57bbef7218" +dependencies = [ + "frame-support", + "frame-system", + "pallet-evm", + "parity-scale-codec", + "scale-info", + "serde", + "sp-core", + "sp-runtime", +] + [[package]] name = "pallet-bioauth" version = "0.1.0" @@ -4075,6 +4540,114 @@ dependencies = [ "sp-std", ] +[[package]] +name = "pallet-dynamic-fee" +version = "4.0.0-dev" +source = "git+https://github.com/humanode-network/frontier?branch=substrate-1a30fa2#864ef8d7e97ede08c758394c5f9e2a57bbef7218" +dependencies = [ + "async-trait", + "frame-support", + "frame-system", + "pallet-evm", + "parity-scale-codec", + "scale-info", + "serde", + "sp-core", + "sp-inherents", + "sp-runtime", + "sp-std", +] + +[[package]] +name = "pallet-ethereum" +version = "4.0.0-dev" +source = "git+https://github.com/humanode-network/frontier?branch=substrate-1a30fa2#864ef8d7e97ede08c758394c5f9e2a57bbef7218" +dependencies = [ + "ethereum 0.11.1", + "ethereum-types", + "evm", + "fp-consensus", + "fp-evm", + "fp-rpc", + "fp-self-contained", + "fp-storage", + "frame-support", + "frame-system", + "pallet-balances", + "pallet-evm", + "pallet-timestamp", + "parity-scale-codec", + "rlp", + "rustc-hex", + "scale-info", + "serde", + "sha3 0.8.2", + "sp-io", + "sp-runtime", + "sp-std", +] + +[[package]] +name = "pallet-evm" +version = "6.0.0-dev" +source = "git+https://github.com/humanode-network/frontier?branch=substrate-1a30fa2#864ef8d7e97ede08c758394c5f9e2a57bbef7218" +dependencies = [ + "evm", + "evm-gasometer", + "evm-runtime", + "fp-evm", + "frame-benchmarking", + "frame-support", + "frame-system", + "hex", + "log", + "pallet-balances", + "pallet-timestamp", + "parity-scale-codec", + "primitive-types", + "rlp", + "scale-info", + "serde", + "sha3 0.8.2", + "sp-core", + "sp-io", + "sp-runtime", + "sp-std", +] + +[[package]] +name = "pallet-evm-precompile-modexp" +version = "2.0.0-dev" +source = "git+https://github.com/humanode-network/frontier?branch=substrate-1a30fa2#864ef8d7e97ede08c758394c5f9e2a57bbef7218" +dependencies = [ + "fp-evm", + "num", + "sp-core", + "sp-io", +] + +[[package]] +name = "pallet-evm-precompile-sha3fips" +version = "2.0.0-dev" +source = "git+https://github.com/humanode-network/frontier?branch=substrate-1a30fa2#864ef8d7e97ede08c758394c5f9e2a57bbef7218" +dependencies = [ + "fp-evm", + "sp-core", + "sp-io", + "tiny-keccak", +] + +[[package]] +name = "pallet-evm-precompile-simple" +version = "2.0.0-dev" +source = "git+https://github.com/humanode-network/frontier?branch=substrate-1a30fa2#864ef8d7e97ede08c758394c5f9e2a57bbef7218" +dependencies = [ + "fp-evm", + "ripemd160", + "sp-core", + "sp-io", +] + [[package]] name = "pallet-grandpa" version = "4.0.0-dev" @@ -4281,8 +4854,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6f4cb4e169446179cbc6b8b6320cc9fca49bd2e94e8db25f25f200a8ea774770" dependencies = [ "cfg-if 1.0.0", + "ethereum-types", "hashbrown", "impl-trait-for-tuples", + "lru 0.6.6", "parity-util-mem-derive", "parking_lot", "primitive-types", @@ -4603,6 +5178,7 @@ checksum = "05e4722c697a58a99d5d06a08c30821d7c082a4632198de1eaa5a6c22ef42373" dependencies = [ "fixed-hash", "impl-codec", + "impl-rlp", "impl-serde", "scale-info", "uint", @@ -4618,6 +5194,18 @@ dependencies = [ "sp-std", ] +[[package]] +name = "primitives-frontier" +version = "0.1.0" +dependencies = [ + "fp-rpc", + "frontier-api", + "pallet-ethereum", + "sp-api", + "sp-blockchain", + "sp-runtime", +] + [[package]] name = "primitives-liveness-data" version = "0.1.0" @@ -4670,18 +5258,6 @@ dependencies = [ "version_check", ] -[[package]] -name = "proc-macro-hack" -version = "0.5.19" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dbf0c48bc1d91375ae5c3cd81e3722dff1abcf81a30960240640d223f59fe0e5" - -[[package]] -name = "proc-macro-nested" -version = "0.1.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bc881b2c22681370c6a780e47af9840ef841837bc98118431d4e1868bd0c1086" - [[package]] name = "proc-macro2" version = "1.0.32" @@ -5079,6 +5655,38 @@ dependencies = [ "winapi 0.3.9", ] +[[package]] +name = "ripemd160" +version = "0.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2eca4ecc81b7f313189bf73ce724400a07da2a6dac19588b03c8bd76a2dcc251" +dependencies = [ + "block-buffer 0.9.0", + "digest 0.9.0", + "opaque-debug 0.3.0", +] + +[[package]] +name = "rlp" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "999508abb0ae792aabed2460c45b89106d97fe4adac593bdaef433c2605847b5" +dependencies = [ + "bytes 1.1.0", + "rustc-hex", +] + +[[package]] +name = "rlp-derive" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e33d7b2abe0c340d8797fe2907d3f20d3b5ea5908683618bfe80df7f621f672a" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "robonode-client" version = "0.1.0" @@ -5518,7 +6126,7 @@ version = "0.10.0-dev" source = "git+https://github.com/humanode-network/substrate?branch=master#1a30fa202e00dfeac07cb648e1f557ce938d5f1a" dependencies = [ "lazy_static", - "libsecp256k1", + "libsecp256k1 0.7.0", "log", "parity-scale-codec", "parking_lot", @@ -5614,7 +6222,7 @@ name = "sc-informant" version = "0.10.0-dev" source = "git+https://github.com/humanode-network/substrate?branch=master#1a30fa202e00dfeac07cb648e1f557ce938d5f1a" dependencies = [ - "ansi_term 0.12.1", + "ansi_term", "futures 0.3.17", "futures-timer 3.0.2", "log", @@ -5932,7 +6540,7 @@ name = "sc-tracing" version = "4.0.0-dev" source = "git+https://github.com/humanode-network/substrate?branch=master#1a30fa202e00dfeac07cb648e1f557ce938d5f1a" dependencies = [ - "ansi_term 0.12.1", + "ansi_term", "atty", "chrono", "lazy_static", @@ -6071,7 +6679,7 @@ dependencies = [ "rand 0.7.3", "rand_core 0.5.1", "sha2 0.8.2", - "subtle", + "subtle 2.4.1", "zeroize", ] @@ -6284,6 +6892,19 @@ dependencies = [ "opaque-debug 0.3.0", ] +[[package]] +name = "sha3" +version = "0.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dd26bc0e7a2e3a7c959bc494caf58b72ee0c71d67704e9520f736ca7e4853ecf" +dependencies = [ + "block-buffer 0.7.3", + "byte-tools", + "digest 0.8.1", + "keccak", + "opaque-debug 0.2.3", +] + [[package]] name = "sha3" version = "0.9.1" @@ -6391,7 +7012,7 @@ dependencies = [ "ring", "rustc_version 0.3.3", "sha2 0.9.8", - "subtle", + "subtle 2.4.1", "x25519-dalek", ] @@ -6597,7 +7218,7 @@ dependencies = [ "hex", "impl-serde", "lazy_static", - "libsecp256k1", + "libsecp256k1 0.7.0", "log", "merlin", "num-traits", @@ -6721,7 +7342,7 @@ source = "git+https://github.com/humanode-network/substrate?branch=master#1a30fa dependencies = [ "futures 0.3.17", "hash-db", - "libsecp256k1", + "libsecp256k1 0.7.0", "log", "parity-scale-codec", "parking_lot", @@ -7199,7 +7820,7 @@ name = "substrate-wasm-builder" version = "5.0.0-dev" source = "git+https://github.com/humanode-network/substrate?branch=master#1a30fa202e00dfeac07cb648e1f557ce938d5f1a" dependencies = [ - "ansi_term 0.12.1", + "ansi_term", "build-helper", "cargo_metadata", "sp-maybe-compressed-blob", @@ -7209,6 +7830,12 @@ dependencies = [ "wasm-gc-api", ] +[[package]] +name = "subtle" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2d67a5a62ba6e01cb2192ff309324cb4875d0c451d55fe2319433abe7a05a8ee" + [[package]] name = "subtle" version = "2.4.1" @@ -7367,11 +7994,10 @@ checksum = "cda74da7e1a664f795bb1f8a87ec406fb89a02522cf6e50620d016add6dbbf5c" [[package]] name = "tokio" -version = "1.13.0" +version = "1.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "588b2d10a336da58d877567cd8fb8a14b463e2104910f8132cd054b4b96e29ee" +checksum = "fbbf1c778ec206785635ce8ad57fe52b3009ae9e0c9f574a728f3049d3e55838" dependencies = [ - "autocfg", "bytes 1.1.0", "libc", "memchr", @@ -7387,9 +8013,9 @@ dependencies = [ [[package]] name = "tokio-macros" -version = "1.5.1" +version = "1.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "114383b041aa6212c579467afa0075fbbdd0718de036100bc0ba7961d8cb9095" +checksum = "b557f72f448c511a979e2564e55d74e6c4432fc96ff4f6241bc6bded342643b7" dependencies = [ "proc-macro2", "quote", @@ -7540,7 +8166,7 @@ version = "0.2.25" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0e0d2eaa99c3c2e41547cfa109e910a68ea03823cccad4a0525dcbc9b01e8c71" dependencies = [ - "ansi_term 0.12.1", + "ansi_term", "chrono", "lazy_static", "matchers", @@ -7602,6 +8228,16 @@ dependencies = [ "hash-db", ] +[[package]] +name = "triehash" +version = "0.8.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a1631b201eb031b563d2e85ca18ec8092508e262a3196ce9bd10a67ec87b9f5c" +dependencies = [ + "hash-db", + "rlp", +] + [[package]] name = "trust-dns-proto" version = "0.20.3" @@ -7775,7 +8411,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9f214e8f697e925001e66ec2c6e37a4ef93f0f78c2eed7814394e10c62025b05" dependencies = [ "generic-array 0.14.4", - "subtle", + "subtle 2.4.1", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index a848b85b4..6547170dc 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,3 +1,33 @@ [workspace] resolver = "2" members = ["crates/*"] + +[patch."https://github.com/paritytech/substrate"] +frame-benchmarking = { git = "https://github.com/humanode-network/substrate", branch = "master" } +frame-support = { git = "https://github.com/humanode-network/substrate", branch = "master" } +frame-system = { git = "https://github.com/humanode-network/substrate", branch = "master" } +pallet-balances = { git = "https://github.com/humanode-network/substrate", branch = "master" } +pallet-timestamp = { git = "https://github.com/humanode-network/substrate", branch = "master" } +sc-block-builder = { git = "https://github.com/humanode-network/substrate", branch = "master" } +sc-client-api = { git = "https://github.com/humanode-network/substrate", branch = "master" } +sc-consensus = { git = "https://github.com/humanode-network/substrate", branch = "master" } +sc-network = { git = "https://github.com/humanode-network/substrate", branch = "master" } +sc-rpc = { git = "https://github.com/humanode-network/substrate", branch = "master" } +sc-service = { git = "https://github.com/humanode-network/substrate", branch = "master" } +sc-transaction-pool = { git = "https://github.com/humanode-network/substrate", branch = "master" } +sc-transaction-pool-api = { git = "https://github.com/humanode-network/substrate", branch = "master" } +sp-api = { git = "https://github.com/humanode-network/substrate", branch = "master" } +sp-block-builder = { git = "https://github.com/humanode-network/substrate", branch = "master" } +sp-blockchain = { git = "https://github.com/humanode-network/substrate", branch = "master" } +sp-consensus = { git = "https://github.com/humanode-network/substrate", branch = "master" } +sp-core = { git = "https://github.com/humanode-network/substrate", branch = "master" } +sp-database = { git = "https://github.com/humanode-network/substrate", branch = "master" } +sp-externalities = { git = "https://github.com/humanode-network/substrate", branch = "master" } +sp-inherents = { git = "https://github.com/humanode-network/substrate", branch = "master" } +sp-io = { git = "https://github.com/humanode-network/substrate", branch = "master" } +sp-runtime = { git = "https://github.com/humanode-network/substrate", branch = "master" } +sp-std = { git = "https://github.com/humanode-network/substrate", branch = "master" } +sp-storage = { git = "https://github.com/humanode-network/substrate", branch = "master" } +sp-timestamp = { git = "https://github.com/humanode-network/substrate", branch = "master" } +sp-transaction-pool = { git = "https://github.com/humanode-network/substrate", branch = "master" } +substrate-prometheus-endpoint = { git = "https://github.com/humanode-network/substrate", branch = "master" } diff --git a/crates/frontier-api/Cargo.toml b/crates/frontier-api/Cargo.toml new file mode 100644 index 000000000..ab4f6e297 --- /dev/null +++ b/crates/frontier-api/Cargo.toml @@ -0,0 +1,15 @@ +[package] +name = "frontier-api" +version = "0.1.0" +edition = "2021" +publish = false + +[dependencies] +codec = { package = "parity-scale-codec", version = "2", default-features = false } +pallet-ethereum = { default-features = false, git = "https://github.com/humanode-network/frontier", branch = "substrate-1a30fa2" } +sp-api = { default-features = false, git = "https://github.com/humanode-network/substrate", branch = "master" } +sp-std = { default-features = false, git = "https://github.com/humanode-network/substrate", branch = "master" } + +[features] +default = ["std"] +std = ["codec/std", "sp-api/std", "sp-std/std", "pallet-ethereum/std"] diff --git a/crates/frontier-api/src/lib.rs b/crates/frontier-api/src/lib.rs new file mode 100644 index 000000000..d2d45c62c --- /dev/null +++ b/crates/frontier-api/src/lib.rs @@ -0,0 +1,14 @@ +//! The runtime API for the frontier related stuff. + +#![cfg_attr(not(feature = "std"), no_std)] + +use codec::Decode; +use sp_std::prelude::*; + +sp_api::decl_runtime_apis! { + /// Runtime API for the transaction converter. + pub trait TransactionConverterApi { + /// Convert an ethereum transaction to an extrinsic. + fn convert_transaction(transaction: pallet_ethereum::Transaction) -> Extrinsic; + } +} diff --git a/crates/humanode-peer/Cargo.toml b/crates/humanode-peer/Cargo.toml index 825a7ed3e..7d4e0e971 100644 --- a/crates/humanode-peer/Cargo.toml +++ b/crates/humanode-peer/Cargo.toml @@ -21,11 +21,18 @@ robonode-client = { version = "0.1", path = "../robonode-client" } anyhow = "1" async-trait = "0.1" codec = { package = "parity-scale-codec", version = "2.0.0" } +fc-consensus = { default-features = false, git = "https://github.com/humanode-network/frontier", branch = "substrate-1a30fa2" } +fc-db = { default-features = false, git = "https://github.com/humanode-network/frontier", branch = "substrate-1a30fa2" } +fc-mapping-sync = { default-features = false, git = "https://github.com/humanode-network/frontier", branch = "substrate-1a30fa2" } +fc-rpc = { default-features = false, git = "https://github.com/humanode-network/frontier", branch = "substrate-1a30fa2" } +fc-rpc-core = { default-features = false, git = "https://github.com/humanode-network/frontier", branch = "substrate-1a30fa2" } fdlimit = "0.2" frame-benchmarking-cli = { git = "https://github.com/humanode-network/substrate", branch = "master" } futures = "0.3" hex = "0.4.3" hex-literal = "0.3" +pallet-dynamic-fee = { default-features = false, git = "https://github.com/humanode-network/frontier", branch = "substrate-1a30fa2" } +pallet-evm = { default-features = false, git = "https://github.com/humanode-network/frontier", branch = "substrate-1a30fa2" } qr2term = "0.2" reqwest = "0.11" sc-basic-authorship = { git = "https://github.com/humanode-network/substrate", branch = "master" } @@ -38,6 +45,7 @@ sc-consensus-aura = { git = "https://github.com/humanode-network/substrate", bra sc-executor = { git = "https://github.com/humanode-network/substrate", branch = "master" } sc-finality-grandpa = { git = "https://github.com/humanode-network/substrate", branch = "master" } sc-network = { git = "https://github.com/humanode-network/substrate", branch = "master" } +sc-rpc = { git = "https://github.com/humanode-network/substrate", branch = "master" } sc-service = { git = "https://github.com/humanode-network/substrate", branch = "master" } sc-telemetry = { git = "https://github.com/humanode-network/substrate", branch = "master" } sc-tracing = { git = "https://github.com/humanode-network/substrate", branch = "master" } @@ -47,6 +55,7 @@ serde = { version = "1", features = ["derive"] } sp-application-crypto = { git = "https://github.com/humanode-network/substrate", branch = "master" } sp-consensus = { git = "https://github.com/humanode-network/substrate", branch = "master" } sp-consensus-aura = { git = "https://github.com/humanode-network/substrate", branch = "master" } +sp-core = { git = "https://github.com/humanode-network/substrate", branch = "master" } sp-finality-grandpa = { git = "https://github.com/humanode-network/substrate", branch = "master" } sp-keystore = { git = "https://github.com/humanode-network/substrate", branch = "master" } sp-panic-handler = { git = "https://github.com/humanode-network/substrate", branch = "master" } diff --git a/crates/humanode-peer/src/chain_spec.rs b/crates/humanode-peer/src/chain_spec.rs index 570e8efb1..22da927cf 100644 --- a/crates/humanode-peer/src/chain_spec.rs +++ b/crates/humanode-peer/src/chain_spec.rs @@ -2,19 +2,22 @@ use hex_literal::hex; use humanode_runtime::{ - AccountId, AuraConfig, BalancesConfig, BioauthConfig, GenesisConfig, GrandpaConfig, - RobonodePublicKeyWrapper, Signature, SudoConfig, SystemConfig, UnixMilliseconds, WASM_BINARY, + AccountId, AuraConfig, BalancesConfig, BioauthConfig, EVMConfig, EthereumConfig, GenesisConfig, + GrandpaConfig, RobonodePublicKeyWrapper, Signature, SudoConfig, SystemConfig, UnixMilliseconds, + WASM_BINARY, }; use pallet_bioauth::{AuthTicketNonce, Authentication}; use sc_chain_spec_derive::{ChainSpecExtension, ChainSpecGroup}; use sc_service::ChainType; use serde::{Deserialize, Serialize}; use sp_consensus_aura::sr25519::AuthorityId as AuraId; +use sp_core::{H160, U256}; use sp_finality_grandpa::AuthorityId as GrandpaId; use sp_runtime::{ app_crypto::{sr25519, Pair, Public}, traits::{IdentifyAccount, Verify}, }; +use std::{collections::BTreeMap, str::FromStr}; /// The concrete chain spec type we're using for the humanode network. pub type ChainSpec = sc_service::GenericChainSpec; @@ -211,6 +214,48 @@ fn testnet_genesis( consumed_auth_ticket_nonces, active_authentications, }, + evm: EVMConfig { + accounts: { + let mut map = BTreeMap::new(); + map.insert( + // H160 address of Alice dev account + // Derived from SS58 (42 prefix) address + // SS58: 5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY + // hex: 0xd43593c715fdd31c61141abd04a99fd6822c8558854ccde39a5684e7a56da27d + // Using the full hex key, truncating to the first 20 bytes (the first 40 hex chars) + H160::from_str("d43593c715fdd31c61141abd04a99fd6822c8558") + .expect("internal H160 is valid; qed"), + pallet_evm::GenesisAccount { + balance: U256::from_str("0xffffffffffffffffffffffffffffffff") + .expect("internal U256 is valid; qed"), + code: Default::default(), + nonce: Default::default(), + storage: Default::default(), + }, + ); + map.insert( + // H160 address of Gerald dev account + // Public address: 0x6Be02d1d3665660d22FF9624b7BE0551ee1Ac91b + // Private key: 0x99b3c12287537e38c90a9219d4cb074a89a16e9cdb20bf85728ebd97c343e342 + // A proper private key should be used to allow testing EVM as Ethereum developer + // For example, use it at Metamask, Remix, Truffle configuration, etc + // We don't have a good converter between Substrate and Ethereum private keys for now. + H160::from_str("6be02d1d3665660d22ff9624b7be0551ee1ac91b") + .expect("internal H160 is valid; qed"), + pallet_evm::GenesisAccount { + balance: U256::from_str("0xffffffffffffffffffffffffffffffff") + .expect("internal U256 is valid; qed"), + code: Default::default(), + nonce: Default::default(), + storage: Default::default(), + }, + ); + map + }, + }, + ethereum: EthereumConfig {}, + dynamic_fee: Default::default(), + base_fee: Default::default(), } } diff --git a/crates/humanode-peer/src/cli/config.rs b/crates/humanode-peer/src/cli/config.rs index c00ec8e20..2d71136c5 100644 --- a/crates/humanode-peer/src/cli/config.rs +++ b/crates/humanode-peer/src/cli/config.rs @@ -44,10 +44,18 @@ pub trait CliConfigurationExt: SubstrateCliConfigurationProvider { } }); + let evm = self.evm_params().map(|params| configuration::Evm { + max_past_logs: params.max_past_logs, + max_stored_filters: params.max_stored_filters, + target_gas_price: params.target_gas_price, + fee_history_limit: params.fee_history_limit, + }); + Ok(Configuration { substrate, bioauth_flow, bioauth_perform_enroll: self.bioauth_perform_enroll(), + evm, }) } @@ -60,6 +68,11 @@ pub trait CliConfigurationExt: SubstrateCliConfigurationProvider { fn bioauth_perform_enroll(&self) -> bool { false } + + /// Provide the evm params, if available. + fn evm_params(&self) -> Option<¶ms::EvmParams> { + None + } } /// Indirect relation to the [`sc_cli::CliConfiguration`] for any type. diff --git a/crates/humanode-peer/src/cli/params.rs b/crates/humanode-peer/src/cli/params.rs index cfeed50b3..4259cb5af 100644 --- a/crates/humanode-peer/src/cli/params.rs +++ b/crates/humanode-peer/src/cli/params.rs @@ -31,3 +31,24 @@ pub struct BioauthFlowParams { #[structopt(long, value_name = "ROBONODE_URL")] pub robonode_url: Option, } + +/// Shared CLI parameters used to configure evm. +#[derive(Debug, StructOpt, Clone)] +pub struct EvmParams { + /// Maximum number of logs to keep from the latest block; + /// it is not possible to query logs older than this amount from the latest block in the past. + #[structopt(long, default_value = "10000")] + pub max_past_logs: u32, + + /// Maximum number of stored filters. + #[structopt(long, default_value = "500")] + pub max_stored_filters: usize, + + /// The dynamic-fee pallet target gas price set by block author. + #[structopt(long, default_value = "1")] + pub target_gas_price: u64, + + /// Maximum fee history cache size. + #[structopt(long, default_value = "2048")] + pub fee_history_limit: u64, +} diff --git a/crates/humanode-peer/src/cli/run_cmd.rs b/crates/humanode-peer/src/cli/run_cmd.rs index 676f97b01..3cbd1da1c 100644 --- a/crates/humanode-peer/src/cli/run_cmd.rs +++ b/crates/humanode-peer/src/cli/run_cmd.rs @@ -19,6 +19,10 @@ pub struct RunCmd { /// Run the bioauth enroll flow before the authentication. #[structopt(long = "bioauth-enroll")] bioauth_perform_enroll: bool, + + #[allow(missing_docs, clippy::missing_docs_in_private_items)] + #[structopt(flatten)] + pub evm_params: params::EvmParams, } impl SubstrateCliConfigurationProvider for RunCmd { @@ -37,4 +41,8 @@ impl CliConfigurationExt for RunCmd { fn bioauth_perform_enroll(&self) -> bool { self.bioauth_perform_enroll } + + fn evm_params(&self) -> Option<¶ms::EvmParams> { + Some(&self.evm_params) + } } diff --git a/crates/humanode-peer/src/configuration.rs b/crates/humanode-peer/src/configuration.rs index 63a59824b..305e7f2e9 100644 --- a/crates/humanode-peer/src/configuration.rs +++ b/crates/humanode-peer/src/configuration.rs @@ -17,6 +17,9 @@ pub struct Configuration { /// Whether to perform the bioauth enroll before the authentication or not. pub bioauth_perform_enroll: bool, + + /// EVM configuration, + pub evm: Option, } /// Bioauth flow configuration parameters. @@ -47,3 +50,19 @@ impl BioauthFlow { Ok((webapp_url, rpc_url)) } } + +/// EVM configuration parameters. +pub struct Evm { + /// Maximum number of blocks to keep the log information available + /// for querying via the RPC (from the latest block). + pub max_past_logs: u32, + + /// Maximum number of stored filters. + pub max_stored_filters: usize, + + /// The dynamic-fee pallet target gas price set by block author. + pub target_gas_price: u64, + + /// Maximum fee history cache size. + pub fee_history_limit: u64, +} diff --git a/crates/humanode-peer/src/service/frontier.rs b/crates/humanode-peer/src/service/frontier.rs new file mode 100644 index 000000000..8476f67e8 --- /dev/null +++ b/crates/humanode-peer/src/service/frontier.rs @@ -0,0 +1,28 @@ +//! The Frontier related stuff. + +use super::Block; +use sc_cli::SubstrateCli; +use sc_service::BasePath; + +/// Create frontier dir. +pub fn database_dir(config: &sc_service::Configuration) -> std::path::PathBuf { + let config_dir = config + .base_path + .as_ref() + .map(|base_path| base_path.config_dir(config.chain_spec.id())) + .unwrap_or_else(|| { + BasePath::from_project("", "", &crate::cli::Root::executable_name()) + .config_dir(config.chain_spec.id()) + }); + config_dir.join("frontier").join("db") +} + +/// Construct frontier backend. +pub fn open_backend(config: &sc_service::Configuration) -> Result, String> { + fc_db::Backend::::new(&fc_db::DatabaseSettings { + source: fc_db::DatabaseSettingsSrc::RocksDb { + path: database_dir(config), + cache_size: 0, + }, + }) +} diff --git a/crates/humanode-peer/src/service.rs b/crates/humanode-peer/src/service/mod.rs similarity index 80% rename from crates/humanode-peer/src/service.rs rename to crates/humanode-peer/src/service/mod.rs index bb3ccdb3f..b97f43db5 100644 --- a/crates/humanode-peer/src/service.rs +++ b/crates/humanode-peer/src/service/mod.rs @@ -1,10 +1,13 @@ //! Initializing, bootstrapping and launching the node from a provided configuration. #![allow(clippy::type_complexity)] -use std::{marker::PhantomData, sync::Arc, time::Duration}; - +use fc_consensus::FrontierBlockImport; +use fc_mapping_sync::{MappingSyncWorker, SyncStrategy}; +use fc_rpc::EthTask; +use fc_rpc_core::types::{FeeHistoryCache, FilterPool}; +use futures::StreamExt; use humanode_runtime::{self, opaque::Block, RuntimeApi}; -use sc_client_api::ExecutorProvider; +use sc_client_api::{BlockchainEvents, ExecutorProvider}; use sc_consensus_aura::{ImportQueueParams, SlotDuration, SlotProportion, StartAuraParams}; pub use sc_executor::NativeElseWasmExecutor; use sc_finality_grandpa::SharedVoterState; @@ -12,10 +15,19 @@ use sc_service::{Error as ServiceError, KeystoreContainer, PartialComponents, Ta use sc_telemetry::{Telemetry, TelemetryWorker}; use sp_consensus::SlotData; use sp_consensus_aura::sr25519::{AuthorityId as AuraId, AuthorityPair as AuraPair}; +use sp_core::U256; +use std::{ + collections::BTreeMap, + marker::PhantomData, + sync::{Arc, Mutex}, + time::Duration, +}; use tracing::*; use crate::configuration::Configuration; +pub mod frontier; + /// Declare an instance of the native executor named `ExecutorDispatch`. Include the wasm binary as /// the equivalent wasm code. pub struct ExecutorDispatch; @@ -45,9 +57,22 @@ type FullClient = sc_service::TFullClient; type FullBackend = sc_service::TFullBackend; /// Full node select chain type. type FullSelectChain = sc_consensus::LongestChain; -/// Full node Grandpa type. +/// Full type for GrandpaBlockImport. type FullGrandpa = sc_finality_grandpa::GrandpaBlockImport; +/// Full type for FrontierBlockImport. +type FullFrontier = FrontierBlockImport; +/// Full type for BioauthBlockImport. +type FullBioauth = bioauth_consensus::BioauthBlockImport< + FullBackend, + Block, + FullClient, + FullFrontier, + bioauth_consensus::aura::BlockAuthorExtractor, + bioauth_consensus::api::AuthorizationVerifier, +>; +/// Frontier backend type. +type FrontierBackend = fc_db::Backend; /// Construct a bare keystore from the configuration. pub fn keystore_container( @@ -77,25 +102,25 @@ pub fn new_partial( ( FullGrandpa, sc_finality_grandpa::LinkHalf, - bioauth_consensus::BioauthBlockImport< - FullBackend, - Block, - FullClient, - FullGrandpa, - bioauth_consensus::aura::BlockAuthorExtractor, - bioauth_consensus::api::AuthorizationVerifier, - >, + FullBioauth, SlotDuration, Duration, + Arc, Option, ), >, ServiceError, > { let Configuration { - substrate: config, .. + substrate: config, + evm: evm_config, + .. } = config; + let evm_config = evm_config + .as_ref() + .ok_or_else(|| ServiceError::Other("evm config is not set".into()))?; + let telemetry = config .telemetry_endpoints .clone() @@ -145,15 +170,23 @@ pub fn new_partial( telemetry.as_ref().map(|x| x.handle()), )?; + let frontier_backend = Arc::new(frontier::open_backend(config)?); + let frontier_block_import = FrontierBlockImport::new( + grandpa_block_import.clone(), + Arc::clone(&client), + Arc::clone(&frontier_backend), + ); + let bioauth_consensus_block_import = bioauth_consensus::BioauthBlockImport::new( Arc::clone(&client), - grandpa_block_import.clone(), + frontier_block_import, bioauth_consensus::aura::BlockAuthorExtractor::new(Arc::clone(&client)), bioauth_consensus::api::AuthorizationVerifier::new(Arc::clone(&client)), ); let slot_duration = sc_consensus_aura::slot_duration(&*client)?; let raw_slot_duration = slot_duration.slot_duration(); + let eth_target_gas_price = evm_config.target_gas_price; let import_queue = sc_consensus_aura::import_queue::(ImportQueueParams { @@ -169,7 +202,10 @@ pub fn new_partial( raw_slot_duration, ); - Ok((timestamp, slot)) + let dynamic_fee = + pallet_dynamic_fee::InherentDataProvider(U256::from(eth_target_gas_price)); + + Ok((timestamp, slot, dynamic_fee)) }, spawner: &task_manager.spawn_essential_handle(), can_author_with: sp_consensus::CanAuthorWithNativeVersion::new( @@ -194,6 +230,7 @@ pub fn new_partial( bioauth_consensus_block_import, slot_duration, raw_slot_duration, + frontier_backend, telemetry, ), }) @@ -217,6 +254,7 @@ pub async fn new_full(config: Configuration) -> Result Result Result Result = None; let prometheus_registry = config.prometheus_registry().cloned(); + let eth_target_gas_price = evm_config.target_gas_price; + let eth_filter_pool: Option = Some(Arc::new(Mutex::new(BTreeMap::new()))); + let eth_fee_history_cache: FeeHistoryCache = Arc::new(Mutex::new(BTreeMap::new())); + let eth_fee_history_limit = evm_config.fee_history_limit; + let eth_overrides = humanode_rpc::overrides_handle(Arc::clone(&client)); let proposer_factory = sc_basic_authorship::ProposerFactory::new( task_manager.spawn_handle(), @@ -292,6 +339,23 @@ pub async fn new_full(config: Configuration) -> Result Result Result Result Result { +pub struct Deps { /// The client instance to use. pub client: Arc, /// Transaction pool instance. @@ -24,22 +45,84 @@ pub struct Deps { pub bioauth_flow_slot: Arc, /// Extracts the currently used validator key. pub validator_key_extractor: VKE, + /// Graph pool instance. + pub graph: Arc>, + /// Network service + pub network: Arc>, + /// EthFilterApi pool. + pub eth_filter_pool: Option, + /// Maximum number of stored filters. + pub eth_max_stored_filters: usize, + /// Backend. + pub eth_backend: Arc>, + /// Maximum number of logs in a query. + pub eth_max_past_logs: u32, + /// Maximum fee history cache size. + pub eth_fee_history_limit: u64, + /// Fee history cache. + pub eth_fee_history_cache: FeeHistoryCache, + /// Subscription task executor instance. + pub subscription_task_executor: Arc, + /// Ethereum data access overrides. + pub eth_overrides: Arc>, + /// Cache for Ethereum block data. + pub eth_block_data_cache: Arc>, +} + +/// A helper function to handle overrides. +pub fn overrides_handle(client: Arc) -> Arc> +where + C: ProvideRuntimeApi + StorageProvider + AuxStore, + C: HeaderBackend + HeaderMetadata, + C: Send + Sync + 'static, + C::Api: fp_rpc::EthereumRuntimeRPCApi, + BE: Backend + 'static, + BE::State: StateBackend, +{ + let mut overrides_map = BTreeMap::new(); + overrides_map.insert( + EthereumStorageSchema::V1, + Box::new(SchemaV1Override::new(Arc::clone(&client))) + as Box + Send + Sync>, + ); + overrides_map.insert( + EthereumStorageSchema::V2, + Box::new(SchemaV2Override::new(Arc::clone(&client))) + as Box + Send + Sync>, + ); + overrides_map.insert( + EthereumStorageSchema::V3, + Box::new(SchemaV3Override::new(Arc::clone(&client))) + as Box + Send + Sync>, + ); + + Arc::new(OverrideHandle { + schemas: overrides_map, + fallback: Box::new(RuntimeApiStorageOverride::new(Arc::clone(&client))), + }) } /// Instantiate all RPC extensions. -pub fn create(deps: Deps) -> jsonrpc_core::IoHandler +pub fn create( + deps: Deps, +) -> jsonrpc_core::IoHandler where - C: ProvideRuntimeApi, + BE: Backend + 'static, + C: ProvideRuntimeApi + StorageProvider + AuxStore, + C: BlockchainEvents, C: HeaderBackend + HeaderMetadata + 'static, C: Send + Sync + 'static, C::Api: substrate_frame_rpc_system::AccountNonceApi, C::Api: pallet_transaction_payment_rpc::TransactionPaymentRuntimeApi, C::Api: bioauth_flow_api::BioauthFlowApi, C::Api: BlockBuilder, - P: TransactionPool + 'static, + C::Api: fp_rpc::EthereumRuntimeRPCApi, + C::Api: frontier_api::TransactionConverterApi, VKE: ValidatorKeyExtractorT + Send + Sync + 'static, VKE::PublicKeyType: Encode, VKE::Error: std::fmt::Debug, + P: TransactionPool + 'static, + A: ChainApi + 'static, { use pallet_transaction_payment_rpc::{TransactionPayment, TransactionPaymentApi}; use substrate_frame_rpc_system::{FullSystem, SystemApi}; @@ -52,11 +135,22 @@ where robonode_client, bioauth_flow_slot, validator_key_extractor, + graph, + network, + eth_filter_pool, + eth_max_stored_filters, + eth_backend, + eth_max_past_logs, + eth_fee_history_limit, + eth_fee_history_cache, + subscription_task_executor, + eth_overrides, + eth_block_data_cache, } = deps; io.extend_with(SystemApi::to_delegate(FullSystem::new( Arc::clone(&client), - pool, + Arc::clone(&pool), deny_unsafe, ))); @@ -71,5 +165,54 @@ where Arc::clone(&client), ))); + io.extend_with(EthApiServer::to_delegate(EthApi::new( + Arc::clone(&client), + Arc::clone(&pool), + graph, + primitives_frontier::RuntimeTransactionConverter::new(Arc::clone(&client)), + Arc::clone(&network), + Vec::new(), + Arc::clone(ð_overrides), + Arc::clone(ð_backend), + true, + eth_max_past_logs, + Arc::clone(ð_block_data_cache), + eth_fee_history_limit, + eth_fee_history_cache, + ))); + + io.extend_with(Web3ApiServer::to_delegate(Web3Api::new(Arc::clone( + &client, + )))); + + io.extend_with(EthPubSubApiServer::to_delegate(EthPubSubApi::new( + pool, + Arc::clone(&client), + Arc::clone(&network), + SubscriptionManager::::with_id_provider( + HexEncodedIdProvider::default(), + subscription_task_executor, + ), + Arc::clone(ð_overrides), + ))); + + io.extend_with(NetApiServer::to_delegate(NetApi::new( + Arc::clone(&client), + Arc::clone(&network), + // Whether to format the `peer_count` response as Hex (default) or not. + true, + ))); + + if let Some(eth_filter_pool) = eth_filter_pool { + io.extend_with(EthFilterApiServer::to_delegate(EthFilterApi::new( + client, + eth_backend, + eth_filter_pool, + eth_max_stored_filters, + eth_max_past_logs, + eth_block_data_cache, + ))); + } + io } diff --git a/crates/humanode-runtime/Cargo.toml b/crates/humanode-runtime/Cargo.toml index 956f90e0e..4ce0d1bf9 100644 --- a/crates/humanode-runtime/Cargo.toml +++ b/crates/humanode-runtime/Cargo.toml @@ -11,6 +11,7 @@ substrate-wasm-builder = { git = "https://github.com/humanode-network/substrate" [dependencies] bioauth-consensus-api = { version = "0.1", path = "../bioauth-consensus-api", default-features = false } bioauth-flow-api = { version = "0.1", path = "../bioauth-flow-api", default-features = false } +frontier-api = { version = "0.1", path = "../frontier-api", default-features = false } pallet-bioauth = { version = "0.1", path = "../pallet-bioauth", default-features = false } primitives-auth-ticket = { version = "0.1", path = "../primitives-auth-ticket", default-features = false } robonode-crypto = { version = "0.1", path = "../robonode-crypto", default-features = false } @@ -19,6 +20,8 @@ chrono = { version = "0.4.19", default-features = false } codec = { package = "parity-scale-codec", version = "2", default-features = false, features = [ "derive", ] } +fp-rpc = { default-features = false, git = "https://github.com/humanode-network/frontier", branch = "substrate-1a30fa2" } +fp-self-contained = { default-features = false, git = "https://github.com/humanode-network/frontier", branch = "substrate-1a30fa2" } frame-benchmarking = { default-features = false, optional = true, git = "https://github.com/humanode-network/substrate", branch = "master" } frame-executive = { default-features = false, git = "https://github.com/humanode-network/substrate", branch = "master" } frame-support = { default-features = false, git = "https://github.com/humanode-network/substrate", branch = "master" } @@ -28,6 +31,13 @@ frame-system-rpc-runtime-api = { default-features = false, git = "https://github hex-literal = { version = "0.3", optional = true } pallet-aura = { default-features = false, git = "https://github.com/humanode-network/substrate", branch = "master" } pallet-balances = { default-features = false, git = "https://github.com/humanode-network/substrate", branch = "master" } +pallet-base-fee = { default-features = false, git = "https://github.com/humanode-network/frontier", branch = "substrate-1a30fa2" } +pallet-dynamic-fee = { default-features = false, git = "https://github.com/humanode-network/frontier", branch = "substrate-1a30fa2" } +pallet-ethereum = { default-features = false, git = "https://github.com/humanode-network/frontier", branch = "substrate-1a30fa2" } +pallet-evm = { default-features = false, git = "https://github.com/humanode-network/frontier", branch = "substrate-1a30fa2" } +pallet-evm-precompile-modexp = { default-features = false, git = "https://github.com/humanode-network/frontier", branch = "substrate-1a30fa2" } +pallet-evm-precompile-sha3fips = { default-features = false, git = "https://github.com/humanode-network/frontier", branch = "substrate-1a30fa2" } +pallet-evm-precompile-simple = { default-features = false, git = "https://github.com/humanode-network/frontier", branch = "substrate-1a30fa2" } pallet-grandpa = { default-features = false, git = "https://github.com/humanode-network/substrate", branch = "master" } pallet-randomness-collective-flip = { default-features = false, git = "https://github.com/humanode-network/substrate", branch = "master" } pallet-sudo = { default-features = false, git = "https://github.com/humanode-network/substrate", branch = "master" } @@ -76,6 +86,12 @@ std = [ "pallet-aura/std", "pallet-bioauth/std", "pallet-balances/std", + "pallet-base-fee/std", + "pallet-ethereum/std", + "pallet-evm/std", + "pallet-evm-precompile-simple/std", + "pallet-evm-precompile-sha3fips/std", + "pallet-dynamic-fee/std", "pallet-grandpa/std", "pallet-randomness-collective-flip/std", "pallet-sudo/std", diff --git a/crates/humanode-runtime/src/frontier_precompiles.rs b/crates/humanode-runtime/src/frontier_precompiles.rs new file mode 100644 index 000000000..e25c77610 --- /dev/null +++ b/crates/humanode-runtime/src/frontier_precompiles.rs @@ -0,0 +1,66 @@ +use pallet_evm::{Context, Precompile, PrecompileResult, PrecompileSet}; +use sp_core::H160; +use sp_std::marker::PhantomData; + +use pallet_evm_precompile_modexp::Modexp; +use pallet_evm_precompile_sha3fips::Sha3FIPS256; +use pallet_evm_precompile_simple::{ECRecover, ECRecoverPublicKey, Identity, Ripemd160, Sha256}; + +pub struct FrontierPrecompiles(PhantomData); + +impl Default for FrontierPrecompiles { + fn default() -> Self { + Self(Default::default()) + } +} + +impl FrontierPrecompiles +where + R: pallet_evm::Config, +{ + pub fn used_addresses() -> sp_std::vec::Vec { + sp_std::vec![1, 2, 3, 4, 5, 1024, 1025] + .into_iter() + .map(|x| hash(x as u64)) + .collect() + } +} + +impl PrecompileSet for FrontierPrecompiles +where + R: pallet_evm::Config, +{ + fn execute( + &self, + address: H160, + input: &[u8], + target_gas: Option, + context: &Context, + is_static: bool, + ) -> Option { + match address { + // Ethereum precompiles : + a if a == hash(1) => Some(ECRecover::execute(input, target_gas, context, is_static)), + a if a == hash(2) => Some(Sha256::execute(input, target_gas, context, is_static)), + a if a == hash(3) => Some(Ripemd160::execute(input, target_gas, context, is_static)), + a if a == hash(4) => Some(Identity::execute(input, target_gas, context, is_static)), + a if a == hash(5) => Some(Modexp::execute(input, target_gas, context, is_static)), + // Non-Frontier specific nor Ethereum precompiles : + a if a == hash(1024) => { + Some(Sha3FIPS256::execute(input, target_gas, context, is_static)) + } + a if a == hash(1025) => Some(ECRecoverPublicKey::execute( + input, target_gas, context, is_static, + )), + _ => None, + } + } + + fn is_precompile(&self, address: H160) -> bool { + Self::used_addresses().contains(&address) + } +} + +fn hash(a: u64) -> H160 { + H160::from_low_u64_be(a) +} diff --git a/crates/humanode-runtime/src/lib.rs b/crates/humanode-runtime/src/lib.rs index 02b8415d5..796e3d477 100644 --- a/crates/humanode-runtime/src/lib.rs +++ b/crates/humanode-runtime/src/lib.rs @@ -10,7 +10,11 @@ #[cfg(feature = "std")] include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs")); +use fp_rpc::TransactionStatus; use pallet_bioauth::AuthTicket; +use pallet_ethereum::{Call::transact, Transaction as EthereumTransaction}; +use pallet_evm::FeeCalculator; +use pallet_evm::{Account as EVMAccount, EnsureAddressTruncated, HashedAddressMapping, Runner}; use pallet_grandpa::{ fg_primitives, AuthorityId as GrandpaId, AuthorityList as GrandpaAuthorityList, }; @@ -20,15 +24,20 @@ use scale_info::TypeInfo; use serde::{Deserialize, Serialize}; use sp_api::impl_runtime_apis; use sp_consensus_aura::sr25519::AuthorityId as AuraId; -use sp_core::{crypto::KeyTypeId, OpaqueMetadata}; +use sp_core::{ + crypto::{KeyTypeId, Public}, + OpaqueMetadata, H160, H256, U256, +}; use sp_runtime::traits::{ AccountIdLookup, BlakeTwo256, Block as BlockT, IdentifyAccount, NumberFor, Verify, }; use sp_runtime::{ create_runtime_str, generic, impl_opaque_keys, - transaction_validity::{TransactionSource, TransactionValidity}, + traits::{Dispatchable, PostDispatchInfoOf}, + transaction_validity::{TransactionSource, TransactionValidity, TransactionValidityError}, ApplyExtrinsicResult, MultiSignature, }; +use sp_std::marker::PhantomData; use sp_std::prelude::*; #[cfg(feature = "std")] use sp_version::NativeVersion; @@ -38,12 +47,12 @@ use sp_version::RuntimeVersion; use codec::{Decode, Encode, MaxEncodedLen}; pub use frame_support::{ construct_runtime, parameter_types, - traits::{KeyOwnerProofSystem, Randomness}, + traits::{FindAuthor, KeyOwnerProofSystem, Randomness}, weights::{ constants::{BlockExecutionWeight, ExtrinsicBaseWeight, RocksDbWeight, WEIGHT_PER_SECOND}, IdentityFee, Weight, }, - StorageValue, + ConsensusEngineId, StorageValue, }; pub use pallet_balances::Call as BalancesCall; pub use pallet_timestamp::Call as TimestampCall; @@ -52,6 +61,9 @@ use pallet_transaction_payment::CurrencyAdapter; pub use sp_runtime::BuildStorage; pub use sp_runtime::{Perbill, Permill}; +mod frontier_precompiles; +use frontier_precompiles::FrontierPrecompiles; + mod display_moment; /// An index to a block. @@ -440,6 +452,84 @@ impl pallet_bioauth::Config for Runtime { type MaxNonces = MaxNonces; } +pub fn get_ethereum_address(authority_id: AuraId) -> H160 { + H160::from_slice(&authority_id.to_raw_vec()[4..24]) +} + +pub struct FindAuthorTruncated(PhantomData); +impl> FindAuthor for FindAuthorTruncated { + fn find_author<'a, I>(digests: I) -> Option + where + I: 'a + IntoIterator, + { + if let Some(author_index) = F::find_author(digests) { + let authority_id = Aura::authorities()[author_index as usize].clone(); + return Some(get_ethereum_address(authority_id)); + } + None + } +} + +parameter_types! { + pub const ChainId: u64 = 42; + pub BlockGasLimit: U256 = U256::from(u32::max_value()); + pub PrecompilesValue: FrontierPrecompiles = FrontierPrecompiles::<_>::default(); +} + +impl pallet_evm::Config for Runtime { + type FeeCalculator = BaseFee; + type GasWeightMapping = (); + type BlockHashMapping = pallet_ethereum::EthereumBlockHashMapping; + type CallOrigin = EnsureAddressTruncated; + type WithdrawOrigin = EnsureAddressTruncated; + type AddressMapping = HashedAddressMapping; + type Currency = Balances; + type Event = Event; + type Runner = pallet_evm::runner::stack::Runner; + type PrecompilesType = FrontierPrecompiles; + type PrecompilesValue = PrecompilesValue; + type ChainId = ChainId; + type BlockGasLimit = BlockGasLimit; + type OnChargeTransaction = (); + type FindAuthor = FindAuthorTruncated; +} + +impl pallet_ethereum::Config for Runtime { + type Event = Event; + type StateRoot = pallet_ethereum::IntermediateStateRoot; +} + +frame_support::parameter_types! { + pub BoundDivision: U256 = U256::from(1024); +} + +impl pallet_dynamic_fee::Config for Runtime { + type MinGasPriceBoundDivisor = BoundDivision; +} + +frame_support::parameter_types! { + pub IsActive: bool = true; +} + +pub struct BaseFeeThreshold; +impl pallet_base_fee::BaseFeeThreshold for BaseFeeThreshold { + fn lower() -> Permill { + Permill::zero() + } + fn ideal() -> Permill { + Permill::from_parts(500_000) + } + fn upper() -> Permill { + Permill::from_parts(1_000_000) + } +} + +impl pallet_base_fee::Config for Runtime { + type Event = Event; + type Threshold = BaseFeeThreshold; + type IsActive = IsActive; +} + // Create the runtime by composing the FRAME pallets that were previously // configured. construct_runtime!( @@ -457,6 +547,10 @@ construct_runtime!( TransactionPayment: pallet_transaction_payment::{Pallet, Storage}, Sudo: pallet_sudo::{Pallet, Call, Config, Storage, Event}, Grandpa: pallet_grandpa::{Pallet, Call, Storage, Config, Event}, + Ethereum: pallet_ethereum::{Pallet, Call, Storage, Event, Config, Origin}, + EVM: pallet_evm::{Pallet, Config, Call, Storage, Event}, + DynamicFee: pallet_dynamic_fee::{Pallet, Call, Storage, Config, Inherent}, + BaseFee: pallet_base_fee::{Pallet, Call, Storage, Config, Event}, } ); @@ -478,8 +572,10 @@ pub type SignedExtra = ( pallet_transaction_payment::ChargeTransactionPayment, ); /// Unchecked extrinsic type as expected by this runtime. -pub type UncheckedExtrinsic = generic::UncheckedExtrinsic; -/// Extrinsic type that has already been checked. +pub type UncheckedExtrinsic = + fp_self_contained::UncheckedExtrinsic; + +/// Executive: handles dispatch to the various modules. pub type Executive = frame_executive::Executive< Runtime, Block, @@ -488,6 +584,53 @@ pub type Executive = frame_executive::Executive< AllPalletsWithSystem, >; +impl fp_self_contained::SelfContainedCall for Call { + type SignedInfo = H160; + + fn is_self_contained(&self) -> bool { + match self { + Call::Ethereum(call) => call.is_self_contained(), + _ => false, + } + } + + fn check_self_contained(&self) -> Option> { + match self { + Call::Ethereum(call) => call.check_self_contained(), + _ => None, + } + } + + fn validate_self_contained(&self, info: &Self::SignedInfo) -> Option { + match self { + Call::Ethereum(call) => call.validate_self_contained(info), + _ => None, + } + } + + fn pre_dispatch_self_contained( + &self, + info: &Self::SignedInfo, + ) -> Option> { + match self { + Call::Ethereum(call) => call.pre_dispatch_self_contained(info), + _ => None, + } + } + + fn apply_self_contained( + self, + info: Self::SignedInfo, + ) -> Option>> { + match self { + call @ Call::Ethereum(pallet_ethereum::Call::transact { .. }) => Some(call.dispatch( + Origin::from(pallet_ethereum::RawOrigin::EthereumTransaction(info)), + )), + _ => None, + } + } +} + impl_runtime_apis! { impl sp_api::Core for Runtime { fn version() -> RuntimeVersion { @@ -580,6 +723,17 @@ impl_runtime_apis! { } } + impl frontier_api::TransactionConverterApi for Runtime { + fn convert_transaction(transaction: pallet_ethereum::Transaction) -> opaque::UncheckedExtrinsic { + let extrinsic = UncheckedExtrinsic::new_unsigned( + pallet_ethereum::Call::::transact { transaction }.into(), + ); + let encoded = extrinsic.encode(); + opaque::UncheckedExtrinsic::decode(&mut &encoded[..]) + .expect("Encoded extrinsic is always valid") + } + } + impl sp_session::SessionKeys for Runtime { fn generate_session_keys(seed: Option>) -> Vec { opaque::SessionKeys::generate(seed) @@ -628,6 +782,137 @@ impl_runtime_apis! { } } + impl fp_rpc::EthereumRuntimeRPCApi for Runtime { + fn chain_id() -> u64 { + ::ChainId::get() + } + + fn account_basic(address: H160) -> EVMAccount { + EVM::account_basic(&address) + } + + fn gas_price() -> U256 { + ::FeeCalculator::min_gas_price() + } + + fn account_code_at(address: H160) -> Vec { + EVM::account_codes(address) + } + + fn author() -> H160 { + >::find_author() + } + + fn storage_at(address: H160, index: U256) -> H256 { + let mut tmp = [0u8; 32]; + index.to_big_endian(&mut tmp); + EVM::account_storages(address, H256::from_slice(&tmp[..])) + } + + fn call( + from: H160, + to: H160, + data: Vec, + value: U256, + gas_limit: U256, + max_fee_per_gas: Option, + max_priority_fee_per_gas: Option, + nonce: Option, + estimate: bool, + access_list: Option)>>, + ) -> Result { + let config = if estimate { + let mut config = ::config().clone(); + config.estimate = true; + config + } else { + ::config().clone() + }; + + ::Runner::call( + from, + to, + data, + value, + gas_limit.low_u64(), + max_fee_per_gas, + max_priority_fee_per_gas, + nonce, + access_list.unwrap_or_default(), + &config, + ).map_err(|err| err.into()) + } + + fn create( + from: H160, + data: Vec, + value: U256, + gas_limit: U256, + max_fee_per_gas: Option, + max_priority_fee_per_gas: Option, + nonce: Option, + estimate: bool, + access_list: Option)>>, + ) -> Result { + let config = if estimate { + let mut config = ::config().clone(); + config.estimate = true; + config + } else { + ::config().clone() + }; + + ::Runner::create( + from, + data, + value, + gas_limit.low_u64(), + max_fee_per_gas, + max_priority_fee_per_gas, + nonce, + access_list.unwrap_or_default(), + &config, + ).map_err(|err| err.into()) + } + + fn current_transaction_statuses() -> Option> { + Ethereum::current_transaction_statuses() + } + + fn current_block() -> Option { + Ethereum::current_block() + } + + fn current_receipts() -> Option> { + Ethereum::current_receipts() + } + + fn current_all() -> ( + Option, + Option>, + Option> + ) { + ( + Ethereum::current_block(), + Ethereum::current_receipts(), + Ethereum::current_transaction_statuses() + ) + } + + fn extrinsic_filter( + xts: Vec<::Extrinsic>, + ) -> Vec { + xts.into_iter().filter_map(|xt| match xt.0.function { + Call::Ethereum(transact { transaction }) => Some(transaction), + _ => None + }).collect::>() + } + + fn elasticity() -> Option { + Some(BaseFee::elasticity()) + } + } + impl pallet_transaction_payment_rpc_runtime_api::TransactionPaymentApi for Runtime { fn query_info( diff --git a/crates/primitives-frontier/Cargo.toml b/crates/primitives-frontier/Cargo.toml new file mode 100644 index 000000000..eb8a5d74b --- /dev/null +++ b/crates/primitives-frontier/Cargo.toml @@ -0,0 +1,14 @@ +[package] +name = "primitives-frontier" +version = "0.1.0" +edition = "2021" +publish = false + +[dependencies] +frontier-api = { version = "0.1", path = "../frontier-api", default-features = false } + +fp-rpc = { default-features = false, git = "https://github.com/humanode-network/frontier", branch = "substrate-1a30fa2" } +pallet-ethereum = { default-features = false, git = "https://github.com/humanode-network/frontier", branch = "substrate-1a30fa2" } +sp-api = { default-features = false, git = "https://github.com/humanode-network/substrate", branch = "master" } +sp-blockchain = { default-features = false, git = "https://github.com/humanode-network/substrate", branch = "master" } +sp-runtime = { default-features = false, git = "https://github.com/humanode-network/substrate", branch = "master" } diff --git a/crates/primitives-frontier/src/lib.rs b/crates/primitives-frontier/src/lib.rs new file mode 100644 index 000000000..a341210a2 --- /dev/null +++ b/crates/primitives-frontier/src/lib.rs @@ -0,0 +1,40 @@ +//! Frontier related primitives. + +use frontier_api::TransactionConverterApi; +use sp_api::ProvideRuntimeApi; +use sp_blockchain::HeaderBackend; +use sp_runtime::traits::Block as BlockT; +use std::{marker::PhantomData, sync::Arc}; + +/// Ethereum transaction converter to an extrinsic. +pub struct RuntimeTransactionConverter { + /// The client provides access to the runtime. + client: Arc, + /// The type of the block used in the chain. + _phantom_block: PhantomData, +} + +impl RuntimeTransactionConverter { + /// Create a new [`RuntimeTransactionConverter`]. + pub fn new(client: Arc) -> Self { + Self { + client, + _phantom_block: PhantomData, + } + } +} + +impl fp_rpc::ConvertTransaction + for RuntimeTransactionConverter +where + Client: HeaderBackend + ProvideRuntimeApi, + Client::Api: TransactionConverterApi, +{ + fn convert_transaction(&self, transaction: pallet_ethereum::Transaction) -> Block::Extrinsic { + let at = sp_api::BlockId::Hash(self.client.info().best_hash); + self.client + .runtime_api() + .convert_transaction(&at, transaction) + .unwrap() + } +}