diff --git a/Cargo.lock b/Cargo.lock index ff79d3bc5f..6cabe37c1f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -516,7 +516,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "df752953c49ce90719c7bf1fc587bc8227aed04732ea0c0f85e5397d7fdbd1a1" dependencies = [ "include_dir", - "itertools", + "itertools 0.10.3", "proc-macro-error", "proc-macro2", "quote", @@ -615,7 +615,7 @@ dependencies = [ "ark-std", "derivative", "hashbrown 0.13.2", - "itertools", + "itertools 0.10.3", "num-traits", "rayon", "zeroize", @@ -683,7 +683,7 @@ dependencies = [ "ark-std", "derivative", "digest 0.10.7", - "itertools", + "itertools 0.10.3", "num-bigint 0.4.3", "num-traits", "paste", @@ -1100,7 +1100,7 @@ checksum = "a564d521dd56509c4c47480d00b80ee55f7e385ae48db5744c67ad50c92d2ebf" dependencies = [ "proc-macro2", "quote", - "syn 2.0.43", + "syn 2.0.47", ] [[package]] @@ -1136,6 +1136,15 @@ dependencies = [ "num-traits", ] +[[package]] +name = "atoi" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f28d99ec8bfea296261ca1af174f24225171fea9664ba9003cbebee704810528" +dependencies = [ + "num-traits", +] + [[package]] name = "atomic" version = "0.5.1" @@ -1239,7 +1248,7 @@ dependencies = [ "heck 0.4.1", "proc-macro2", "quote", - "syn 2.0.43", + "syn 2.0.47", ] [[package]] @@ -1404,13 +1413,13 @@ dependencies = [ "lazy_static", "lazycell", "peeking_take_while", - "prettyplease 0.2.9", + "prettyplease 0.2.16", "proc-macro2", "quote", "regex", "rustc-hash", "shlex", - "syn 2.0.43", + "syn 2.0.47", ] [[package]] @@ -2117,7 +2126,7 @@ dependencies = [ "heck 0.4.1", "proc-macro2", "quote", - "syn 2.0.43", + "syn 2.0.47", ] [[package]] @@ -2609,7 +2618,7 @@ dependencies = [ "cranelift-codegen 0.95.1", "cranelift-entity 0.95.1", "cranelift-frontend 0.95.1", - "itertools", + "itertools 0.10.3", "log", "smallvec", "wasmparser 0.102.0", @@ -2668,7 +2677,7 @@ dependencies = [ "clap 3.2.23", "criterion-plot", "futures", - "itertools", + "itertools 0.10.3", "lazy_static", "num-traits", "oorandom", @@ -2690,7 +2699,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6b50826342786a51a89e2da3a28f1c32b06e387201bc2d19791f622c673706b1" dependencies = [ "cast", - "itertools", + "itertools 0.10.3", ] [[package]] @@ -2930,7 +2939,7 @@ checksum = "83fdaf97f4804dcebfa5862639bc9ce4121e82140bec2a987ac5140294865b5b" dependencies = [ "proc-macro2", "quote", - "syn 2.0.43", + "syn 2.0.47", ] [[package]] @@ -3045,7 +3054,7 @@ dependencies = [ "proc-macro2", "quote", "strsim", - "syn 2.0.43", + "syn 2.0.47", ] [[package]] @@ -3078,7 +3087,7 @@ checksum = "29a358ff9f12ec09c3e61fef9b5a9902623a695a46a917b07f269bff1445611a" dependencies = [ "darling_core 0.20.1", "quote", - "syn 2.0.43", + "syn 2.0.47", ] [[package]] @@ -3209,7 +3218,7 @@ checksum = "5fe87ce4529967e0ba1dcf8450bab64d97dfd5010a6256187ffe2e43e6f0e049" dependencies = [ "proc-macro2", "quote", - "syn 2.0.43", + "syn 2.0.47", ] [[package]] @@ -3314,7 +3323,7 @@ dependencies = [ "proc-macro2", "proc-macro2-diagnostics 0.10.0", "quote", - "syn 2.0.43", + "syn 2.0.47", ] [[package]] @@ -3506,7 +3515,7 @@ dependencies = [ "proc-macro2", "quote", "regex", - "syn 2.0.43", + "syn 2.0.47", "termcolor", "toml 0.8.2", "walkdir", @@ -3518,6 +3527,12 @@ version = "0.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "77c90badedccf4105eca100756a0b1289e191f6fcbdadd3cee1d2f614f97da8f" +[[package]] +name = "dotenvy" +version = "0.15.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1aaf95b3e5c8f23aa320147307562d361db0ae0d51242340f558153b4eb2439b" + [[package]] name = "downcast" version = "0.11.0" @@ -3663,6 +3678,9 @@ name = "either" version = "1.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7fcaabb2fef8c910e7f4c7ce9f67a1283a1715879a7c230ca9d6d1ae31f16d91" +dependencies = [ + "serde", +] [[package]] name = "elliptic-curve" @@ -3768,7 +3786,7 @@ dependencies = [ "heck 0.4.1", "proc-macro2", "quote", - "syn 2.0.43", + "syn 2.0.47", ] [[package]] @@ -3808,7 +3826,7 @@ checksum = "5e9a1f9f7d83e59740248a6e14ecf93929ade55027844dfcea78beafccc15745" dependencies = [ "proc-macro2", "quote", - "syn 2.0.43", + "syn 2.0.47", ] [[package]] @@ -3954,6 +3972,24 @@ dependencies = [ "tiny-keccak", ] +[[package]] +name = "ethereum" +version = "0.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2e04d24d20b8ff2235cffbf242d5092de3aa45f77c5270ddbfadd2778ca13fea" +dependencies = [ + "bytes", + "ethereum-types", + "hash-db", + "hash256-std-hasher", + "parity-scale-codec", + "rlp", + "scale-info", + "serde", + "sha3", + "trie-root", +] + [[package]] name = "ethereum-types" version = "0.14.1" @@ -4030,14 +4066,14 @@ dependencies = [ "ethers-etherscan", "eyre", "hex", - "prettyplease 0.2.9", + "prettyplease 0.2.16", "proc-macro2", "quote", "regex", "reqwest", "serde", "serde_json", - "syn 2.0.43", + "syn 2.0.47", "toml 0.7.3", "walkdir", ] @@ -4055,7 +4091,7 @@ dependencies = [ "proc-macro2", "quote", "serde_json", - "syn 2.0.43", + "syn 2.0.47", ] [[package]] @@ -4081,7 +4117,7 @@ dependencies = [ "serde", "serde_json", "strum 0.25.0", - "syn 2.0.43", + "syn 2.0.47", "tempfile", "thiserror", "tiny-keccak", @@ -4222,6 +4258,64 @@ version = "2.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "77f3309417938f28bf8228fcff79a4a37103981e3e186d2ccd19c74b38f4eb71" +[[package]] +name = "evm" +version = "0.41.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "767f43e9630cc36cf8ff2777cbb0121b055f0d1fd6eaaa13b46a1808f0d0e7e9" +dependencies = [ + "auto_impl", + "environmental", + "ethereum", + "evm-core", + "evm-gasometer", + "evm-runtime", + "log", + "parity-scale-codec", + "primitive-types", + "rlp", + "scale-info", + "serde", + "sha3", +] + +[[package]] +name = "evm-core" +version = "0.41.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d1da6cedc5cedb4208e59467106db0d1f50db01b920920589f8e672c02fdc04f" +dependencies = [ + "parity-scale-codec", + "primitive-types", + "scale-info", + "serde", +] + +[[package]] +name = "evm-gasometer" +version = "0.41.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1dc0eb591abc5cd7b05bef6a036c2bb6c66ab6c5e0c5ce94bfe377ab670b1fd7" +dependencies = [ + "environmental", + "evm-core", + "evm-runtime", + "primitive-types", +] + +[[package]] +name = "evm-runtime" +version = "0.41.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "84bbe09b64ae13a29514048c1bb6fda6374ac0b4f6a1f15a443348ab88ef42cd" +dependencies = [ + "auto_impl", + "environmental", + "evm-core", + "primitive-types", + "sha3", +] + [[package]] name = "exit-future" version = "0.2.0" @@ -4241,7 +4335,7 @@ dependencies = [ "fs-err", "proc-macro2", "quote", - "syn 2.0.43", + "syn 2.0.47", ] [[package]] @@ -4275,6 +4369,192 @@ dependencies = [ "instant", ] +[[package]] +name = "fc-api" +version = "1.0.0-dev" +source = "git+https://github.com/kvinwang/frontier?branch=polkadot-v1.5.0#67990f8e62b7cc969ca62ec38318ab8a59da6142" +dependencies = [ + "async-trait", + "fp-storage", + "parity-scale-codec", + "sp-core", + "sp-runtime", +] + +[[package]] +name = "fc-cli" +version = "1.0.0-dev" +source = "git+https://github.com/kvinwang/frontier?branch=polkadot-v1.5.0#67990f8e62b7cc969ca62ec38318ab8a59da6142" +dependencies = [ + "clap 4.4.12", + "ethereum-types", + "fc-db", + "fp-rpc", + "fp-storage", + "sc-cli", + "serde", + "serde_json", + "sp-api", + "sp-blockchain", + "sp-runtime", +] + +[[package]] +name = "fc-consensus" +version = "2.0.0-dev" +source = "git+https://github.com/kvinwang/frontier?branch=polkadot-v1.5.0#67990f8e62b7cc969ca62ec38318ab8a59da6142" +dependencies = [ + "async-trait", + "fp-consensus", + "fp-rpc", + "sc-consensus", + "sp-api", + "sp-block-builder", + "sp-consensus", + "sp-runtime", + "thiserror", +] + +[[package]] +name = "fc-db" +version = "2.0.0-dev" +source = "git+https://github.com/kvinwang/frontier?branch=polkadot-v1.5.0#67990f8e62b7cc969ca62ec38318ab8a59da6142" +dependencies = [ + "async-trait", + "ethereum", + "fc-api", + "fc-storage", + "fp-consensus", + "fp-rpc", + "fp-storage", + "futures", + "kvdb-rocksdb", + "log", + "parity-db", + "parity-scale-codec", + "parking_lot 0.12.1", + "sc-client-api", + "sc-client-db", + "smallvec", + "sp-api", + "sp-blockchain", + "sp-core", + "sp-database", + "sp-runtime", + "sp-storage 13.0.0 (git+https://github.com/paritytech/polkadot-sdk.git?branch=release-polkadot-v1.5.0)", + "sqlx 0.7.1", + "tokio", +] + +[[package]] +name = "fc-mapping-sync" +version = "2.0.0-dev" +source = "git+https://github.com/kvinwang/frontier?branch=polkadot-v1.5.0#67990f8e62b7cc969ca62ec38318ab8a59da6142" +dependencies = [ + "fc-db", + "fc-storage", + "fp-consensus", + "fp-rpc", + "futures", + "futures-timer", + "log", + "parking_lot 0.12.1", + "sc-client-api", + "sc-utils", + "sp-api", + "sp-blockchain", + "sp-consensus", + "sp-core", + "sp-runtime", + "tokio", +] + +[[package]] +name = "fc-rpc" +version = "2.0.0-dev" +source = "git+https://github.com/kvinwang/frontier?branch=polkadot-v1.5.0#67990f8e62b7cc969ca62ec38318ab8a59da6142" +dependencies = [ + "ethereum", + "ethereum-types", + "evm", + "fc-api", + "fc-mapping-sync", + "fc-rpc-core", + "fc-storage", + "fp-evm", + "fp-rpc", + "fp-storage", + "futures", + "hex", + "jsonrpsee", + "libsecp256k1", + "log", + "pallet-evm", + "parity-scale-codec", + "prometheus", + "rand 0.8.5", + "rlp", + "sc-client-api", + "sc-consensus-aura", + "sc-network", + "sc-network-common", + "sc-network-sync", + "sc-rpc", + "sc-service", + "sc-transaction-pool", + "sc-transaction-pool-api", + "sc-utils", + "schnellru", + "serde", + "sp-api", + "sp-block-builder", + "sp-blockchain", + "sp-consensus", + "sp-consensus-aura", + "sp-core", + "sp-externalities 0.19.0 (git+https://github.com/paritytech/polkadot-sdk.git?branch=release-polkadot-v1.5.0)", + "sp-inherents", + "sp-io", + "sp-runtime", + "sp-state-machine", + "sp-storage 13.0.0 (git+https://github.com/paritytech/polkadot-sdk.git?branch=release-polkadot-v1.5.0)", + "sp-timestamp", + "substrate-prometheus-endpoint", + "thiserror", + "tokio", +] + +[[package]] +name = "fc-rpc-core" +version = "1.1.0-dev" +source = "git+https://github.com/kvinwang/frontier?branch=polkadot-v1.5.0#67990f8e62b7cc969ca62ec38318ab8a59da6142" +dependencies = [ + "ethereum", + "ethereum-types", + "jsonrpsee", + "rustc-hex", + "serde", + "serde_json", +] + +[[package]] +name = "fc-storage" +version = "1.0.0-dev" +source = "git+https://github.com/kvinwang/frontier?branch=polkadot-v1.5.0#67990f8e62b7cc969ca62ec38318ab8a59da6142" +dependencies = [ + "ethereum", + "ethereum-types", + "fp-rpc", + "fp-storage", + "parity-scale-codec", + "sc-client-api", + "sp-api", + "sp-blockchain", + "sp-io", + "sp-runtime", + "sp-storage 13.0.0 (git+https://github.com/paritytech/polkadot-sdk.git?branch=release-polkadot-v1.5.0)", +] + [[package]] name = "fdlimit" version = "0.3.0" @@ -4484,6 +4764,18 @@ dependencies = [ "num-traits", ] +[[package]] +name = "flume" +version = "0.10.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1657b4441c3403d9f7b3409e47575237dac27b1b5726df654a6ecbf92f0f7577" +dependencies = [ + "futures-core", + "futures-sink", + "pin-project", + "spin 0.9.3", +] + [[package]] name = "fnv" version = "1.0.7" @@ -4522,6 +4814,114 @@ dependencies = [ "percent-encoding", ] +[[package]] +name = "fp-account" +version = "1.0.0-dev" +source = "git+https://github.com/kvinwang/frontier?branch=polkadot-v1.5.0#67990f8e62b7cc969ca62ec38318ab8a59da6142" +dependencies = [ + "hex", + "impl-serde", + "libsecp256k1", + "log", + "parity-scale-codec", + "scale-info", + "serde", + "sp-core", + "sp-io", + "sp-runtime", + "sp-runtime-interface 17.0.0 (git+https://github.com/paritytech/polkadot-sdk.git?branch=release-polkadot-v1.5.0)", + "sp-std 8.0.0 (git+https://github.com/paritytech/polkadot-sdk.git?branch=release-polkadot-v1.5.0)", +] + +[[package]] +name = "fp-consensus" +version = "2.0.0-dev" +source = "git+https://github.com/kvinwang/frontier?branch=polkadot-v1.5.0#67990f8e62b7cc969ca62ec38318ab8a59da6142" +dependencies = [ + "ethereum", + "parity-scale-codec", + "sp-core", + "sp-runtime", + "sp-std 8.0.0 (git+https://github.com/paritytech/polkadot-sdk.git?branch=release-polkadot-v1.5.0)", +] + +[[package]] +name = "fp-dynamic-fee" +version = "1.0.0" +source = "git+https://github.com/kvinwang/frontier?branch=polkadot-v1.5.0#67990f8e62b7cc969ca62ec38318ab8a59da6142" +dependencies = [ + "async-trait", + "sp-core", + "sp-inherents", +] + +[[package]] +name = "fp-ethereum" +version = "1.0.0-dev" +source = "git+https://github.com/kvinwang/frontier?branch=polkadot-v1.5.0#67990f8e62b7cc969ca62ec38318ab8a59da6142" +dependencies = [ + "ethereum", + "ethereum-types", + "fp-evm", + "frame-support", + "parity-scale-codec", + "sp-std 8.0.0 (git+https://github.com/paritytech/polkadot-sdk.git?branch=release-polkadot-v1.5.0)", +] + +[[package]] +name = "fp-evm" +version = "3.0.0-dev" +source = "git+https://github.com/kvinwang/frontier?branch=polkadot-v1.5.0#67990f8e62b7cc969ca62ec38318ab8a59da6142" +dependencies = [ + "evm", + "frame-support", + "num_enum 0.7.1", + "parity-scale-codec", + "scale-info", + "serde", + "sp-core", + "sp-runtime", + "sp-std 8.0.0 (git+https://github.com/paritytech/polkadot-sdk.git?branch=release-polkadot-v1.5.0)", +] + +[[package]] +name = "fp-rpc" +version = "3.0.0-dev" +source = "git+https://github.com/kvinwang/frontier?branch=polkadot-v1.5.0#67990f8e62b7cc969ca62ec38318ab8a59da6142" +dependencies = [ + "ethereum", + "ethereum-types", + "fp-evm", + "parity-scale-codec", + "scale-info", + "sp-api", + "sp-core", + "sp-runtime", + "sp-state-machine", + "sp-std 8.0.0 (git+https://github.com/paritytech/polkadot-sdk.git?branch=release-polkadot-v1.5.0)", +] + +[[package]] +name = "fp-self-contained" +version = "1.0.0-dev" +source = "git+https://github.com/kvinwang/frontier?branch=polkadot-v1.5.0#67990f8e62b7cc969ca62ec38318ab8a59da6142" +dependencies = [ + "frame-support", + "parity-scale-codec", + "scale-info", + "serde", + "sp-runtime", +] + +[[package]] +name = "fp-storage" +version = "2.0.0" +source = "git+https://github.com/kvinwang/frontier?branch=polkadot-v1.5.0#67990f8e62b7cc969ca62ec38318ab8a59da6142" +dependencies = [ + "parity-scale-codec", + "serde", +] + [[package]] name = "fragile" version = "2.0.0" @@ -4568,7 +4968,7 @@ dependencies = [ "frame-system", "gethostname", "handlebars", - "itertools", + "itertools 0.10.3", "lazy_static", "linked-hash-map", "log", @@ -4609,7 +5009,7 @@ dependencies = [ "proc-macro-crate 2.0.1", "proc-macro2", "quote", - "syn 2.0.43", + "syn 2.0.47", ] [[package]] @@ -4743,13 +5143,13 @@ dependencies = [ "derive-syn-parse", "expander", "frame-support-procedural-tools", - "itertools", + "itertools 0.10.3", "macro_magic", "proc-macro-warning", "proc-macro2", "quote", "sp-core-hashing", - "syn 2.0.43", + "syn 2.0.47", ] [[package]] @@ -4761,7 +5161,7 @@ dependencies = [ "proc-macro-crate 2.0.1", "proc-macro2", "quote", - "syn 2.0.43", + "syn 2.0.47", ] [[package]] @@ -4771,7 +5171,7 @@ source = "git+https://github.com/paritytech/polkadot-sdk.git?branch=release-polk dependencies = [ "proc-macro2", "quote", - "syn 2.0.43", + "syn 2.0.47", ] [[package]] @@ -4960,6 +5360,17 @@ dependencies = [ "parking_lot 0.11.2", ] +[[package]] +name = "futures-intrusive" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d930c203dd0b6ff06e0201a4a2fe9149b43c684fd4420555b26d21b1a02956f" +dependencies = [ + "futures-core", + "lock_api", + "parking_lot 0.12.1", +] + [[package]] name = "futures-io" version = "0.3.28" @@ -4999,7 +5410,7 @@ checksum = "89ca545a94061b6365f2c7355b4b32bd20df3ff95f02da9329b34ccc3bd6ee72" dependencies = [ "proc-macro2", "quote", - "syn 2.0.43", + "syn 2.0.47", ] [[package]] @@ -5634,22 +6045,6 @@ dependencies = [ "want", ] -[[package]] -name = "hyper-rustls" -version = "0.23.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d87c48c02e0dc5e3b849a2041db3029fd066650f8f717c07bf8ed78ccb895cac" -dependencies = [ - "http", - "hyper", - "log", - "rustls 0.20.8", - "rustls-native-certs", - "tokio", - "tokio-rustls 0.23.4", - "webpki-roots 0.22.4", -] - [[package]] name = "hyper-rustls" version = "0.24.1" @@ -5664,6 +6059,7 @@ dependencies = [ "rustls-native-certs", "tokio", "tokio-rustls 0.24.1", + "webpki-roots 0.23.1", ] [[package]] @@ -5957,14 +6353,14 @@ dependencies = [ "impl-serde", "ink_ir", "ink_primitives", - "itertools", + "itertools 0.10.3", "log", "parity-scale-codec", "proc-macro2", "quote", "serde", "serde_json", - "syn 2.0.43", + "syn 2.0.47", ] [[package]] @@ -6018,10 +6414,10 @@ checksum = "1c0e2d96fc6e5b5cb1696b8057e72958315076dbe3f427e8f7722a346344f27a" dependencies = [ "blake2 0.10.6", "either", - "itertools", + "itertools 0.10.3", "proc-macro2", "quote", - "syn 2.0.43", + "syn 2.0.47", ] [[package]] @@ -6036,7 +6432,7 @@ dependencies = [ "parity-scale-codec", "proc-macro2", "quote", - "syn 2.0.43", + "syn 2.0.47", "synstructure 0.13.0", ] @@ -6256,6 +6652,15 @@ dependencies = [ "either", ] +[[package]] +name = "itertools" +version = "0.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "25db6b064527c5d482d0423354fcd07a89a2dfe07b67892e62411946db7f07b0" +dependencies = [ + "either", +] + [[package]] name = "itoa" version = "1.0.9" @@ -6282,9 +6687,9 @@ dependencies = [ [[package]] name = "jsonrpsee" -version = "0.16.2" +version = "0.16.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7d291e3a5818a2384645fd9756362e6d89cf0541b0b916fa7702ea4a9833608e" +checksum = "367a292944c07385839818bb71c8d76611138e2dedb0677d035b8da21d29c78b" dependencies = [ "jsonrpsee-client-transport", "jsonrpsee-core", @@ -6299,9 +6704,9 @@ dependencies = [ [[package]] name = "jsonrpsee-client-transport" -version = "0.16.2" +version = "0.16.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "965de52763f2004bc91ac5bcec504192440f0b568a5d621c59d9dbd6f886c3fb" +checksum = "c8b3815d9f5d5de348e5f162b316dc9cdf4548305ebb15b4eb9328e66cf27d7a" dependencies = [ "anyhow", "futures-channel", @@ -6316,17 +6721,17 @@ dependencies = [ "soketto", "thiserror", "tokio", - "tokio-rustls 0.23.4", + "tokio-rustls 0.24.1", "tokio-util 0.7.4", "tracing", - "webpki-roots 0.22.4", + "webpki-roots 0.25.3", ] [[package]] name = "jsonrpsee-core" -version = "0.16.2" +version = "0.16.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a4e70b4439a751a5de7dd5ed55eacff78ebf4ffe0fc009cb1ebb11417f5b536b" +checksum = "2b5dde66c53d6dcdc8caea1874a45632ec0fcf5b437789f1e45766a1512ce803" dependencies = [ "anyhow", "arrayvec 0.7.2", @@ -6353,13 +6758,13 @@ dependencies = [ [[package]] name = "jsonrpsee-http-client" -version = "0.16.2" +version = "0.16.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cc345b0a43c6bc49b947ebeb936e886a419ee3d894421790c969cc56040542ad" +checksum = "7e5f9fabdd5d79344728521bb65e3106b49ec405a78b66fbff073b72b389fa43" dependencies = [ "async-trait", "hyper", - "hyper-rustls 0.23.0", + "hyper-rustls", "jsonrpsee-core", "jsonrpsee-types", "rustc-hash", @@ -6372,9 +6777,9 @@ dependencies = [ [[package]] name = "jsonrpsee-proc-macros" -version = "0.16.2" +version = "0.16.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "baa6da1e4199c10d7b1d0a6e5e8bd8e55f351163b6f4b3cbb044672a69bd4c1c" +checksum = "44e8ab85614a08792b9bff6c8feee23be78c98d0182d4c622c05256ab553892a" dependencies = [ "heck 0.4.1", "proc-macro-crate 1.3.1", @@ -6385,9 +6790,9 @@ dependencies = [ [[package]] name = "jsonrpsee-server" -version = "0.16.2" +version = "0.16.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1fb69dad85df79527c019659a992498d03f8495390496da2f07e6c24c2b356fc" +checksum = "cf4d945a6008c9b03db3354fb3c83ee02d2faa9f2e755ec1dfb69c3551b8f4ba" dependencies = [ "futures-channel", "futures-util", @@ -6407,9 +6812,9 @@ dependencies = [ [[package]] name = "jsonrpsee-types" -version = "0.16.2" +version = "0.16.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5bd522fe1ce3702fd94812965d7bb7a3364b1c9aba743944c5a00529aae80f8c" +checksum = "245ba8e5aa633dd1c1e4fae72bce06e71f42d34c14a2767c6b4d173b57bee5e5" dependencies = [ "anyhow", "beef", @@ -6421,9 +6826,9 @@ dependencies = [ [[package]] name = "jsonrpsee-wasm-client" -version = "0.16.2" +version = "0.16.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a77310456f43c6c89bcba1f6b2fc2a28300da7c341f320f5128f8c83cc63232d" +checksum = "18e5df77c8f625d36e4cfb583c5a674eccebe32403fcfe42f7ceff7fac9324dd" dependencies = [ "jsonrpsee-client-transport", "jsonrpsee-core", @@ -6432,9 +6837,9 @@ dependencies = [ [[package]] name = "jsonrpsee-ws-client" -version = "0.16.2" +version = "0.16.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b83daeecfc6517cfe210df24e570fb06213533dfb990318fae781f4c7119dd9" +checksum = "4e1b3975ed5d73f456478681a417128597acd6a2487855fdb7b4a3d4d195bf5e" dependencies = [ "http", "jsonrpsee-client-transport", @@ -6574,7 +6979,7 @@ dependencies = [ "diff", "ena", "is-terminal", - "itertools", + "itertools 0.10.3", "lalrpop-util", "petgraph", "regex", @@ -7083,9 +7488,9 @@ dependencies = [ [[package]] name = "libsecp256k1" -version = "0.7.0" +version = "0.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b0452aac8bab02242429380e9b2f94ea20cea2b37e2c1777a1358799bbe97f37" +checksum = "95b09eff1b35ed3b33b877ced3a691fc7a481919c7e29c53c906226fcf55e2a1" dependencies = [ "arrayref", "base64 0.13.0", @@ -7124,9 +7529,20 @@ dependencies = [ name = "libsecp256k1-gen-genmult" version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3db8d6ba2cec9eacc40e6e8ccc98931840301f1006e95647ceb2dd5c3aa06f7c" +checksum = "3db8d6ba2cec9eacc40e6e8ccc98931840301f1006e95647ceb2dd5c3aa06f7c" +dependencies = [ + "libsecp256k1-core", +] + +[[package]] +name = "libsqlite3-sys" +version = "0.26.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "afc22eff61b133b115c6e8c74e818c628d6d5e7a502afea6f64dee076dd94326" dependencies = [ - "libsecp256k1-core", + "cc", + "pkg-config", + "vcpkg", ] [[package]] @@ -7333,7 +7749,7 @@ dependencies = [ "macro_magic_core", "macro_magic_macros", "quote", - "syn 2.0.43", + "syn 2.0.47", ] [[package]] @@ -7347,7 +7763,7 @@ dependencies = [ "macro_magic_core_macros", "proc-macro2", "quote", - "syn 2.0.43", + "syn 2.0.47", ] [[package]] @@ -7358,7 +7774,7 @@ checksum = "9ea73aa640dc01d62a590d48c0c3521ed739d53b27f919b25c3551e233481654" dependencies = [ "proc-macro2", "quote", - "syn 2.0.43", + "syn 2.0.47", ] [[package]] @@ -7369,7 +7785,7 @@ checksum = "ef9d79ae96aaba821963320eb2b6e34d17df1e5a83d8a1985c29cc5be59577b3" dependencies = [ "macro_magic_core", "quote", - "syn 2.0.43", + "syn 2.0.47", ] [[package]] @@ -8063,6 +8479,20 @@ version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "61807f77802ff30975e01f4f071c8ba10c022052f98b3294119f3e615d13e5be" +[[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", + "num-traits", +] + [[package]] name = "num-bigint" version = "0.3.3" @@ -8125,6 +8555,17 @@ dependencies = [ "num-traits", ] +[[package]] +name = "num-iter" +version = "0.1.43" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7d03e6c028c5dc5cac6e2dec0efda81fc887605bb3d884578bb6d6bf7514e252" +dependencies = [ + "autocfg", + "num-integer", + "num-traits", +] + [[package]] name = "num-rational" version = "0.4.1" @@ -8175,6 +8616,15 @@ dependencies = [ "num_enum_derive 0.6.1", ] +[[package]] +name = "num_enum" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "683751d591e6d81200c39fb0d1032608b77724f34114db54f571ff1317b337c0" +dependencies = [ + "num_enum_derive 0.7.1", +] + [[package]] name = "num_enum_derive" version = "0.5.7" @@ -8196,7 +8646,19 @@ dependencies = [ "proc-macro-crate 1.3.1", "proc-macro2", "quote", - "syn 2.0.43", + "syn 2.0.47", +] + +[[package]] +name = "num_enum_derive" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c11e44798ad209ccdd91fc192f0526a369a01234f7373e1b141c96d7cee4f0e" +dependencies = [ + "proc-macro-crate 2.0.1", + "proc-macro2", + "quote", + "syn 2.0.47", ] [[package]] @@ -8325,7 +8787,7 @@ checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c" dependencies = [ "proc-macro2", "quote", - "syn 2.0.43", + "syn 2.0.47", ] [[package]] @@ -8506,6 +8968,20 @@ dependencies = [ "sp-std 8.0.0 (git+https://github.com/paritytech/polkadot-sdk.git?branch=release-polkadot-v1.5.0)", ] +[[package]] +name = "pallet-base-fee" +version = "1.0.0" +source = "git+https://github.com/kvinwang/frontier?branch=polkadot-v1.5.0#67990f8e62b7cc969ca62ec38318ab8a59da6142" +dependencies = [ + "fp-evm", + "frame-support", + "frame-system", + "parity-scale-codec", + "scale-info", + "sp-core", + "sp-runtime", +] + [[package]] name = "pallet-bounties" version = "4.0.0-dev" @@ -8598,7 +9074,7 @@ source = "git+https://github.com/paritytech/polkadot-sdk.git?branch=release-polk dependencies = [ "proc-macro2", "quote", - "syn 2.0.43", + "syn 2.0.47", ] [[package]] @@ -8686,6 +9162,95 @@ dependencies = [ "sp-std 8.0.0 (git+https://github.com/paritytech/polkadot-sdk.git?branch=release-polkadot-v1.5.0)", ] +[[package]] +name = "pallet-ethereum" +version = "4.0.0-dev" +source = "git+https://github.com/kvinwang/frontier?branch=polkadot-v1.5.0#67990f8e62b7cc969ca62ec38318ab8a59da6142" +dependencies = [ + "ethereum", + "ethereum-types", + "evm", + "fp-consensus", + "fp-ethereum", + "fp-evm", + "fp-rpc", + "fp-storage", + "frame-support", + "frame-system", + "pallet-evm", + "parity-scale-codec", + "scale-info", + "sp-io", + "sp-runtime", + "sp-std 8.0.0 (git+https://github.com/paritytech/polkadot-sdk.git?branch=release-polkadot-v1.5.0)", +] + +[[package]] +name = "pallet-evm" +version = "6.0.0-dev" +source = "git+https://github.com/kvinwang/frontier?branch=polkadot-v1.5.0#67990f8e62b7cc969ca62ec38318ab8a59da6142" +dependencies = [ + "environmental", + "evm", + "fp-account", + "fp-evm", + "frame-benchmarking", + "frame-support", + "frame-system", + "hash-db", + "hex", + "hex-literal", + "impl-trait-for-tuples", + "log", + "parity-scale-codec", + "rlp", + "scale-info", + "sp-core", + "sp-io", + "sp-runtime", + "sp-std 8.0.0 (git+https://github.com/paritytech/polkadot-sdk.git?branch=release-polkadot-v1.5.0)", +] + +[[package]] +name = "pallet-evm-precompile-dispatch" +version = "2.0.0-dev" +source = "git+https://github.com/kvinwang/frontier?branch=polkadot-v1.5.0#67990f8e62b7cc969ca62ec38318ab8a59da6142" +dependencies = [ + "fp-evm", + "frame-support", + "pallet-evm", + "parity-scale-codec", + "sp-runtime", +] + +[[package]] +name = "pallet-evm-precompile-modexp" +version = "2.0.0-dev" +source = "git+https://github.com/kvinwang/frontier?branch=polkadot-v1.5.0#67990f8e62b7cc969ca62ec38318ab8a59da6142" +dependencies = [ + "fp-evm", + "num", +] + +[[package]] +name = "pallet-evm-precompile-sha3fips" +version = "2.0.0-dev" +source = "git+https://github.com/kvinwang/frontier?branch=polkadot-v1.5.0#67990f8e62b7cc969ca62ec38318ab8a59da6142" +dependencies = [ + "fp-evm", + "tiny-keccak", +] + +[[package]] +name = "pallet-evm-precompile-simple" +version = "2.0.0-dev" +source = "git+https://github.com/kvinwang/frontier?branch=polkadot-v1.5.0#67990f8e62b7cc969ca62ec38318ab8a59da6142" +dependencies = [ + "fp-evm", + "ripemd", + "sp-io", +] + [[package]] name = "pallet-evm_account_mapping" version = "0.0.1" @@ -8747,6 +9312,22 @@ dependencies = [ "sp-std 8.0.0 (git+https://github.com/paritytech/polkadot-sdk.git?branch=release-polkadot-v1.5.0)", ] +[[package]] +name = "pallet-hotfix-sufficients" +version = "1.0.0" +source = "git+https://github.com/kvinwang/frontier?branch=polkadot-v1.5.0#67990f8e62b7cc969ca62ec38318ab8a59da6142" +dependencies = [ + "frame-benchmarking", + "frame-support", + "frame-system", + "pallet-evm", + "parity-scale-codec", + "scale-info", + "sp-core", + "sp-runtime", + "sp-std 8.0.0 (git+https://github.com/paritytech/polkadot-sdk.git?branch=release-polkadot-v1.5.0)", +] + [[package]] name = "pallet-identity" version = "4.0.0-dev" @@ -9131,7 +9712,7 @@ dependencies = [ "proc-macro-crate 2.0.1", "proc-macro2", "quote", - "syn 2.0.43", + "syn 2.0.47", ] [[package]] @@ -9775,6 +10356,18 @@ dependencies = [ "clap 4.4.12", "clap_complete", "criterion", + "fc-api", + "fc-cli", + "fc-consensus", + "fc-db", + "fc-mapping-sync", + "fc-rpc", + "fc-rpc-core", + "fc-storage", + "fp-account", + "fp-dynamic-fee", + "fp-evm", + "fp-rpc", "frame-benchmarking", "frame-benchmarking-cli", "frame-system", @@ -9785,11 +10378,11 @@ dependencies = [ "nix 0.26.2", "node-executor", "node-primitives", - "node-rpc", "pallet-balances", "pallet-im-online", "pallet-timestamp", "pallet-transaction-payment", + "pallet-transaction-payment-rpc", "parity-scale-codec", "phala-node-rpc-ext", "phala-node-runtime", @@ -9805,8 +10398,10 @@ dependencies = [ "sc-client-db", "sc-consensus", "sc-consensus-babe", + "sc-consensus-babe-rpc", "sc-consensus-epochs", "sc-consensus-grandpa", + "sc-consensus-grandpa-rpc", "sc-consensus-slots", "sc-executor", "sc-keystore", @@ -9814,6 +10409,7 @@ dependencies = [ "sc-network-sync", "sc-offchain", "sc-rpc", + "sc-rpc-api", "sc-service", "sc-service-test", "sc-sync-state-rpc", @@ -9826,6 +10422,7 @@ dependencies = [ "soketto", "sp-api", "sp-authority-discovery", + "sp-block-builder", "sp-blockchain", "sp-consensus", "sp-consensus-babe", @@ -9844,6 +10441,7 @@ dependencies = [ "staging-node-inspect", "substrate-build-script-utils", "substrate-frame-cli", + "substrate-frame-rpc-system", "substrate-rpc-client", "tempfile", "tokio", @@ -9887,6 +10485,11 @@ dependencies = [ name = "phala-node-runtime" version = "2.0.0" dependencies = [ + "evm", + "fp-account", + "fp-evm", + "fp-rpc", + "fp-self-contained", "frame-benchmarking", "frame-election-provider-support", "frame-executive", @@ -9904,15 +10507,23 @@ dependencies = [ "pallet-babe", "pallet-bags-list", "pallet-balances", + "pallet-base-fee", "pallet-bounties", "pallet-child-bounties", "pallet-collective", "pallet-democracy", "pallet-election-provider-multi-phase", "pallet-elections-phragmen", + "pallet-ethereum", + "pallet-evm", + "pallet-evm-precompile-dispatch", + "pallet-evm-precompile-modexp", + "pallet-evm-precompile-sha3fips", + "pallet-evm-precompile-simple", "pallet-evm_account_mapping", "pallet-fast-unstake", "pallet-grandpa", + "pallet-hotfix-sufficients", "pallet-identity", "pallet-im-online", "pallet-indices", @@ -10278,7 +10889,7 @@ dependencies = [ "phf_shared 0.11.2", "proc-macro2", "quote", - "syn 2.0.43", + "syn 2.0.47", ] [[package]] @@ -10317,7 +10928,7 @@ checksum = "ec2e072ecce94ec471b13398d5402c188e76ac03cf74dd1a975161b23a3f6d9c" dependencies = [ "proc-macro2", "quote", - "syn 2.0.43", + "syn 2.0.47", ] [[package]] @@ -10416,7 +11027,7 @@ dependencies = [ "proc-macro2", "quote", "rustfmt-snippet 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", - "syn 2.0.43", + "syn 2.0.47", "unzip3", ] @@ -10757,7 +11368,7 @@ checksum = "a5aab5be6e4732b473071984b3164dbbfb7a3674d30ea5ff44410b6bcd960c3c" dependencies = [ "difflib", "float-cmp", - "itertools", + "itertools 0.10.3", "normalize-line-endings", "predicates-core", "regex", @@ -10771,7 +11382,7 @@ checksum = "09963355b9f467184c04017ced4a2ba2d75cbcb4e7462690d388233253d4b1a9" dependencies = [ "anstyle", "difflib", - "itertools", + "itertools 0.10.3", "predicates-core", ] @@ -10815,12 +11426,12 @@ dependencies = [ [[package]] name = "prettyplease" -version = "0.2.9" +version = "0.2.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9825a04601d60621feed79c4e6b56d65db77cdca55cef43b46b0de1096d1c282" +checksum = "a41cf62165e97c7f814d2221421dbb9afcbcdb0a88068e5ea206e19951c2cbb5" dependencies = [ "proc-macro2", - "syn 2.0.43", + "syn 2.0.47", ] [[package]] @@ -10895,14 +11506,14 @@ checksum = "834da187cfe638ae8abb0203f0b33e5ccdb02a28e7199f2f47b3e2754f50edca" dependencies = [ "proc-macro2", "quote", - "syn 2.0.43", + "syn 2.0.47", ] [[package]] name = "proc-macro2" -version = "1.0.69" +version = "1.0.75" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "134c189feb4956b20f6f547d2cf727d4c0fe06722b20a0eec87ed445a97f92da" +checksum = "907a61bd0f64c2f29cd1cf1dc34d05176426a3f504a78010f08416ddb7b13708" dependencies = [ "unicode-ident", ] @@ -10928,7 +11539,7 @@ checksum = "606c4ba35817e2922a308af55ad51bab3645b59eae5c570d4a6cf07e36bd493b" dependencies = [ "proc-macro2", "quote", - "syn 2.0.43", + "syn 2.0.47", "version_check", "yansi 0.5.1", ] @@ -11022,7 +11633,7 @@ checksum = "62941722fb675d463659e49c4f3fe1fe792ff24fe5bbaa9c08cd3b98a1c354f5" dependencies = [ "bytes", "heck 0.3.3", - "itertools", + "itertools 0.10.3", "lazy_static", "log", "multimap", @@ -11042,7 +11653,7 @@ checksum = "2c828f93f5ca4826f97fedcbd3f9a536c16b12cff3dbbb4a007f932bbad95b12" dependencies = [ "bytes", "heck 0.4.1", - "itertools", + "itertools 0.10.3", "lazy_static", "log", "multimap", @@ -11063,7 +11674,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f9cc1a3263e07e0bf68e96268f37665207b49560d98739662cdfaae215c720fe" dependencies = [ "anyhow", - "itertools", + "itertools 0.10.3", "proc-macro2", "quote", "syn 1.0.109", @@ -11076,7 +11687,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4ea9b0f8cbe5e15a8a042d030bd96668db28ecb567ec37d691971ff5731d2b1b" dependencies = [ "anyhow", - "itertools", + "itertools 0.10.3", "proc-macro2", "quote", "syn 1.0.109", @@ -11119,7 +11730,7 @@ version = "0.1.0" dependencies = [ "either", "heck 0.4.1", - "itertools", + "itertools 0.10.3", "log", "multimap", "proc-macro2", @@ -11257,9 +11868,9 @@ dependencies = [ [[package]] name = "quote" -version = "1.0.33" +version = "1.0.35" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5267fca4496028628a95160fc423a33e8b2e6af8a5302579e322e4b520293cae" +checksum = "291ec9ab5efd934aaf503a6466c5d5251535d108ee747472c3977cc5acc868ef" dependencies = [ "proc-macro2", ] @@ -11639,7 +12250,7 @@ dependencies = [ "serde_cbor", "serde_json", "sp-runtime", - "sqlx", + "sqlx 0.5.13", "tokio", ] @@ -11658,7 +12269,7 @@ dependencies = [ "http", "http-body", "hyper", - "hyper-rustls 0.24.1", + "hyper-rustls", "hyper-tls", "ipnet", "js-sys", @@ -11934,7 +12545,7 @@ dependencies = [ "proc-macro2", "quote", "rocket_http", - "syn 2.0.43", + "syn 2.0.47", "unicode-xid", "version_check", ] @@ -12413,7 +13024,7 @@ dependencies = [ "proc-macro-crate 2.0.1", "proc-macro2", "quote", - "syn 2.0.43", + "syn 2.0.47", ] [[package]] @@ -12427,7 +13038,7 @@ dependencies = [ "clap 4.4.12", "fdlimit", "futures", - "itertools", + "itertools 0.10.3", "libp2p-identity", "log", "names", @@ -12535,6 +13146,35 @@ dependencies = [ "thiserror", ] +[[package]] +name = "sc-consensus-aura" +version = "0.10.0-dev" +source = "git+https://github.com/paritytech/polkadot-sdk.git?branch=release-polkadot-v1.5.0#789ffb66dcfcf3b54a1e6786e928ac91c4fdb465" +dependencies = [ + "async-trait", + "futures", + "log", + "parity-scale-codec", + "sc-block-builder", + "sc-client-api", + "sc-consensus", + "sc-consensus-slots", + "sc-telemetry", + "sp-api", + "sp-application-crypto", + "sp-block-builder", + "sp-blockchain", + "sp-consensus", + "sp-consensus-aura", + "sp-consensus-slots", + "sp-core", + "sp-inherents", + "sp-keystore", + "sp-runtime", + "substrate-prometheus-endpoint", + "thiserror", +] + [[package]] name = "sc-consensus-babe" version = "0.10.0-dev" @@ -12988,7 +13628,7 @@ dependencies = [ "futures", "futures-timer", "hyper", - "hyper-rustls 0.24.1", + "hyper-rustls", "libp2p", "log", "num_cpus", @@ -13323,7 +13963,7 @@ dependencies = [ "proc-macro-crate 2.0.1", "proc-macro2", "quote", - "syn 2.0.43", + "syn 2.0.47", ] [[package]] @@ -13797,9 +14437,9 @@ checksum = "cd0b0ec5f1c1ca621c432a25813d8d60c88abe6d3e08a3eb9cf37d97a0fe3d73" [[package]] name = "serde" -version = "1.0.193" +version = "1.0.194" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "25dd9975e68d0cb5aa1120c288333fc98731bd1dd12f561e468ea4728c042b89" +checksum = "0b114498256798c94a0689e1a15fec6005dee8ac1f41de56404b67afc2a4b773" dependencies = [ "serde_derive", ] @@ -13827,13 +14467,13 @@ dependencies = [ [[package]] name = "serde_derive" -version = "1.0.193" +version = "1.0.194" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "43576ca501357b9b071ac53cdc7da8ef0cbd9493d8df094cd821777ea6e894d3" +checksum = "a3385e45322e8f9931410f01b3031ec534c3947d0e94c18049af4d9f9907d4e0" dependencies = [ "proc-macro2", "quote", - "syn 2.0.43", + "syn 2.0.47", ] [[package]] @@ -14334,7 +14974,7 @@ version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9c792fe9fae2a2f716846f214ca10d5a1e21133e0bf36cef34bcc4a852467b21" dependencies = [ - "itertools", + "itertools 0.10.3", "lalrpop", "lalrpop-util", "phf 0.11.2", @@ -14374,7 +15014,7 @@ dependencies = [ "proc-macro-crate 2.0.1", "proc-macro2", "quote", - "syn 2.0.43", + "syn 2.0.47", ] [[package]] @@ -14563,7 +15203,7 @@ dependencies = [ "hash-db", "hash256-std-hasher", "impl-serde", - "itertools", + "itertools 0.10.3", "libsecp256k1", "log", "merlin 2.0.1", @@ -14611,7 +15251,7 @@ source = "git+https://github.com/paritytech/polkadot-sdk.git?branch=release-polk dependencies = [ "quote", "sp-core-hashing", - "syn 2.0.43", + "syn 2.0.47", ] [[package]] @@ -14651,7 +15291,7 @@ source = "git+https://github.com/paritytech/polkadot-sdk.git?branch=release-polk dependencies = [ "proc-macro2", "quote", - "syn 2.0.43", + "syn 2.0.47", ] [[package]] @@ -14661,7 +15301,7 @@ source = "git+https://github.com/paritytech/polkadot-sdk#cad947951d9e4b2b4b9308d dependencies = [ "proc-macro2", "quote", - "syn 2.0.43", + "syn 2.0.47", ] [[package]] @@ -14904,7 +15544,7 @@ dependencies = [ "proc-macro-crate 2.0.1", "proc-macro2", "quote", - "syn 2.0.43", + "syn 2.0.47", ] [[package]] @@ -14917,7 +15557,7 @@ dependencies = [ "proc-macro-crate 2.0.1", "proc-macro2", "quote", - "syn 2.0.43", + "syn 2.0.47", ] [[package]] @@ -15141,7 +15781,7 @@ dependencies = [ "parity-scale-codec", "proc-macro2", "quote", - "syn 2.0.43", + "syn 2.0.47", ] [[package]] @@ -15196,6 +15836,9 @@ name = "spin" version = "0.9.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c530c2b0d0bf8b69304b39fe2001993e267461948b890cd037d8ad4293fa1a0d" +dependencies = [ + "lock_api", +] [[package]] name = "spinners" @@ -15234,7 +15877,18 @@ version = "0.1.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b4b7922be017ee70900be125523f38bdd644f4f06a1b16e8fa5a8ee8c34bffd4" dependencies = [ - "itertools", + "itertools 0.10.3", + "nom", + "unicode_categories", +] + +[[package]] +name = "sqlformat" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ce81b7bd7c4493975347ef60d8c7e8b742d4694f4c49f93e0a12ea263938176c" +dependencies = [ + "itertools 0.12.0", "nom", "unicode_categories", ] @@ -15245,8 +15899,19 @@ version = "0.5.13" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "551873805652ba0d912fec5bbb0f8b4cdd96baf8e2ebf5970e5671092966019b" dependencies = [ - "sqlx-core", - "sqlx-macros", + "sqlx-core 0.5.13", + "sqlx-macros 0.5.13", +] + +[[package]] +name = "sqlx" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e58421b6bc416714d5115a2ca953718f6c621a51b68e4f4922aea5a4391a721" +dependencies = [ + "sqlx-core 0.7.1", + "sqlx-macros 0.7.1", + "sqlx-sqlite", ] [[package]] @@ -15256,7 +15921,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e48c61941ccf5ddcada342cd59e3e5173b007c509e1e8e990dafc830294d9dc5" dependencies = [ "ahash 0.7.6", - "atoi", + "atoi 0.4.0", "base64 0.13.0", "bitflags 1.3.2", "byteorder", @@ -15269,7 +15934,7 @@ dependencies = [ "event-listener", "futures-channel", "futures-core", - "futures-intrusive", + "futures-intrusive 0.4.0", "futures-util", "hashlink 0.7.0", "hex", @@ -15293,7 +15958,7 @@ dependencies = [ "sha-1 0.10.0", "sha2 0.10.7", "smallvec", - "sqlformat", + "sqlformat 0.1.8", "sqlx-rt", "stringprep", "thiserror", @@ -15304,6 +15969,46 @@ dependencies = [ "whoami", ] +[[package]] +name = "sqlx-core" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dd4cef4251aabbae751a3710927945901ee1d97ee96d757f6880ebb9a79bfd53" +dependencies = [ + "ahash 0.8.3", + "atoi 2.0.0", + "byteorder", + "bytes", + "crc 3.0.0", + "crossbeam-queue", + "dotenvy", + "either", + "event-listener", + "futures-channel", + "futures-core", + "futures-intrusive 0.5.0", + "futures-io", + "futures-util", + "hashlink 0.8.4", + "hex", + "indexmap 2.0.0", + "log", + "memchr", + "native-tls", + "once_cell", + "paste", + "percent-encoding", + "serde", + "sha2 0.10.7", + "smallvec", + "sqlformat 0.2.3", + "thiserror", + "tokio", + "tokio-stream", + "tracing", + "url", +] + [[package]] name = "sqlx-macros" version = "0.5.13" @@ -15317,12 +16022,49 @@ dependencies = [ "proc-macro2", "quote", "sha2 0.10.7", - "sqlx-core", + "sqlx-core 0.5.13", "sqlx-rt", "syn 1.0.109", "url", ] +[[package]] +name = "sqlx-macros" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "208e3165167afd7f3881b16c1ef3f2af69fa75980897aac8874a0696516d12c2" +dependencies = [ + "proc-macro2", + "quote", + "sqlx-core 0.7.1", + "sqlx-macros-core", + "syn 1.0.109", +] + +[[package]] +name = "sqlx-macros-core" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a4a8336d278c62231d87f24e8a7a74898156e34c1c18942857be2acb29c7dfc" +dependencies = [ + "dotenvy", + "either", + "heck 0.4.1", + "hex", + "once_cell", + "proc-macro2", + "quote", + "serde", + "serde_json", + "sha2 0.10.7", + "sqlx-core 0.7.1", + "sqlx-sqlite", + "syn 1.0.109", + "tempfile", + "tokio", + "url", +] + [[package]] name = "sqlx-rt" version = "0.5.13" @@ -15334,6 +16076,28 @@ dependencies = [ "tokio-rustls 0.22.0", ] +[[package]] +name = "sqlx-sqlite" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "be4c21bf34c7cae5b283efb3ac1bcc7670df7561124dc2f8bdc0b59be40f79a2" +dependencies = [ + "atoi 2.0.0", + "flume", + "futures-channel", + "futures-core", + "futures-executor", + "futures-intrusive 0.5.0", + "futures-util", + "libsqlite3-sys", + "log", + "percent-encoding", + "serde", + "sqlx-core 0.7.1", + "tracing", + "url", +] + [[package]] name = "ss58-registry" version = "1.35.0" @@ -15626,7 +16390,7 @@ dependencies = [ "proc-macro2", "quote", "rustversion", - "syn 2.0.43", + "syn 2.0.47", ] [[package]] @@ -15892,7 +16656,7 @@ dependencies = [ "quote", "scale-info", "subxt-metadata", - "syn 2.0.43", + "syn 2.0.47", "thiserror", "tokio", ] @@ -15904,7 +16668,7 @@ dependencies = [ "darling 0.20.1", "proc-macro-error", "subxt-codegen", - "syn 2.0.43", + "syn 2.0.47", ] [[package]] @@ -15951,9 +16715,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.43" +version = "2.0.47" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ee659fb5f3d355364e1f3e5bc10fb82068efbf824a1e9d1c9504244a6469ad53" +checksum = "1726efe18f42ae774cc644f330953a5e7b3c3003d3edcecf18850fe9d4dd9afb" dependencies = [ "proc-macro2", "quote", @@ -15986,7 +16750,7 @@ checksum = "285ba80e733fac80aa4270fbcdf83772a79b80aa35c97075320abfee4a915b06" dependencies = [ "proc-macro2", "quote", - "syn 2.0.43", + "syn 2.0.47", "unicode-xid", ] @@ -16173,7 +16937,7 @@ checksum = "268026685b2be38d7103e9e507c938a1fcb3d7e6eb15e87870b617bf37b6d581" dependencies = [ "proc-macro2", "quote", - "syn 2.0.43", + "syn 2.0.47", ] [[package]] @@ -16328,7 +17092,7 @@ checksum = "5b8a1e28f2deaa14e508979454cb3a223b10b938b45af148bc0986de36f1923b" dependencies = [ "proc-macro2", "quote", - "syn 2.0.43", + "syn 2.0.47", ] [[package]] @@ -16587,7 +17351,7 @@ checksum = "5f4f31f56159e98206da9efd823404b79b6ef3143b4a7ab76e67b1751b25a4ab" dependencies = [ "proc-macro2", "quote", - "syn 2.0.43", + "syn 2.0.47", ] [[package]] @@ -17400,7 +18164,7 @@ dependencies = [ "once_cell", "proc-macro2", "quote", - "syn 2.0.43", + "syn 2.0.47", "wasm-bindgen-shared", ] @@ -17457,7 +18221,7 @@ checksum = "54681b18a46765f095758388f2d0cf16eb8d4169b639ab575a8f5693af210c7b" dependencies = [ "proc-macro2", "quote", - "syn 2.0.43", + "syn 2.0.47", "wasm-bindgen-backend", "wasm-bindgen-shared", ] @@ -17629,7 +18393,7 @@ dependencies = [ "byteorder", "cc", "inkwell", - "itertools", + "itertools 0.10.3", "lazy_static", "libc", "object 0.28.4", @@ -18784,7 +19548,7 @@ dependencies = [ "Inflector", "proc-macro2", "quote", - "syn 2.0.43", + "syn 2.0.47", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index a7dc115de9..e0a482f6f7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -97,6 +97,41 @@ members = [ "scripts/debug-cli" ] +[workspace.dependencies] +# Frontier Client +fc-api = { git = "https://github.com/kvinwang/frontier", branch = "polkadot-v1.5.0" } +fc-cli = { git = "https://github.com/kvinwang/frontier", branch = "polkadot-v1.5.0", default-features = false } +fc-consensus = { git = "https://github.com/kvinwang/frontier", branch = "polkadot-v1.5.0" } +fc-db = { git = "https://github.com/kvinwang/frontier", branch = "polkadot-v1.5.0", default-features = false } +fc-mapping-sync = { git = "https://github.com/kvinwang/frontier", branch = "polkadot-v1.5.0", default-features = false } +fc-rpc = { git = "https://github.com/kvinwang/frontier", branch = "polkadot-v1.5.0", default-features = false } +fc-rpc-core = { git = "https://github.com/kvinwang/frontier", branch = "polkadot-v1.5.0" } +fc-storage = { git = "https://github.com/kvinwang/frontier", branch = "polkadot-v1.5.0" } +# Frontier Primitive +fp-account = { git = "https://github.com/kvinwang/frontier", branch = "polkadot-v1.5.0", default-features = false } +fp-consensus = { git = "https://github.com/kvinwang/frontier", branch = "polkadot-v1.5.0", default-features = false } +fp-dynamic-fee = { git = "https://github.com/kvinwang/frontier", branch = "polkadot-v1.5.0", default-features = false } +fp-ethereum = { git = "https://github.com/kvinwang/frontier", branch = "polkadot-v1.5.0", default-features = false } +fp-evm = { git = "https://github.com/kvinwang/frontier", branch = "polkadot-v1.5.0", default-features = false } +fp-rpc = { git = "https://github.com/kvinwang/frontier", branch = "polkadot-v1.5.0", default-features = false } +fp-self-contained = { git = "https://github.com/kvinwang/frontier", branch = "polkadot-v1.5.0", default-features = false } +fp-storage = { git = "https://github.com/kvinwang/frontier", branch = "polkadot-v1.5.0", default-features = false } +# Frontier FRAME +pallet-base-fee = { git = "https://github.com/kvinwang/frontier", branch = "polkadot-v1.5.0", default-features = false } +pallet-dynamic-fee = { git = "https://github.com/kvinwang/frontier", branch = "polkadot-v1.5.0", default-features = false } +pallet-ethereum = { git = "https://github.com/kvinwang/frontier", branch = "polkadot-v1.5.0", default-features = false } +pallet-evm = { git = "https://github.com/kvinwang/frontier", branch = "polkadot-v1.5.0", default-features = false } +pallet-evm-precompile-modexp = { git = "https://github.com/kvinwang/frontier", branch = "polkadot-v1.5.0", default-features = false } +pallet-evm-precompile-sha3fips = { git = "https://github.com/kvinwang/frontier", branch = "polkadot-v1.5.0", default-features = false } +pallet-evm-precompile-simple = { git = "https://github.com/kvinwang/frontier", branch = "polkadot-v1.5.0", default-features = false } +pallet-evm-precompile-dispatch = { git = "https://github.com/kvinwang/frontier", branch = "polkadot-v1.5.0", default-features = false } +pallet-evm-test-vector-support = { git = "https://github.com/kvinwang/frontier", branch = "polkadot-v1.5.0" } +pallet-hotfix-sufficients = { git = "https://github.com/kvinwang/frontier", branch = "polkadot-v1.5.0", default-features = false } +# Frontier Template +frontier-template-runtime = { git = "https://github.com/kvinwang/frontier", branch = "polkadot-v1.5.0", default-features = false } +# Frontier Utility +precompile-utils = { git = "https://github.com/kvinwang/frontier", branch = "polkadot-v1.5.0", default-features = false } + [patch.crates-io] # TODO.kevin: Move back to crates.io once it released 1.0 derive_more = { version = "0.99.17", git = "https://github.com/JelteF/derive_more" } diff --git a/crates/phala-node-rpc-ext/src/lib.rs b/crates/phala-node-rpc-ext/src/lib.rs index cae838224b..1a81bd7bd8 100644 --- a/crates/phala-node-rpc-ext/src/lib.rs +++ b/crates/phala-node-rpc-ext/src/lib.rs @@ -69,7 +69,7 @@ struct NodeRpcExt { } impl NodeRpcExt { - fn new(client: Arc, backend: Arc, _is_archive_mode: bool, pool: Arc

) -> Self { + fn new(client: Arc, backend: Arc, pool: Arc

) -> Self { Self { client, backend, @@ -89,8 +89,7 @@ where + BlockBackend + HeaderMetadata + ProvideRuntimeApi, - Client::Api: - sp_api::Metadata + ApiExt, + Client::Api: sp_api::Metadata + ApiExt, Client::Api: MqApi, Block: BlockT + 'static, <::Header as Header>::Number: Into, @@ -143,7 +142,6 @@ pub fn extend_rpc( io: &mut RpcModule<()>, client: Arc, backend: Arc, - is_archive_mode: bool, pool: Arc

, ) where BE: Backend + 'static, @@ -154,12 +152,11 @@ pub fn extend_rpc( + ProvideRuntimeApi + 'static, Block: BlockT + 'static, - Client::Api: - sp_api::Metadata + ApiExt, + Client::Api: sp_api::Metadata + ApiExt, Client::Api: MqApi, <::Header as Header>::Number: Into, P: TransactionPool + 'static, { - io.merge(NodeRpcExt::new(client, backend, is_archive_mode, pool).into_rpc()) + io.merge(NodeRpcExt::new(client, backend, pool).into_rpc()) .expect("Initialize Phala node RPC ext failed."); } diff --git a/scripts/debug-cli/src/main.rs b/scripts/debug-cli/src/main.rs index cc9196f08a..e3670487c8 100644 --- a/scripts/debug-cli/src/main.rs +++ b/scripts/debug-cli/src/main.rs @@ -10,7 +10,7 @@ use std::fmt::Debug; // use phala_types; #[derive(Debug, Parser)] -#[clap(name = "Phala Debug Utility CLI")] +#[command(name = "Phala Debug Utility CLI")] enum Cli { DecodeWorkerRegistrationInfo { #[arg(short)] diff --git a/standalone/headers-cache/src/main.rs b/standalone/headers-cache/src/main.rs index 313f0ced6e..ee6ebe4c40 100644 --- a/standalone/headers-cache/src/main.rs +++ b/standalone/headers-cache/src/main.rs @@ -15,7 +15,7 @@ mod web_api; type BlockNumber = u32; #[derive(Parser)] -#[clap(about = "Cache server for relaychain headers", version, author)] +#[command(about = "Cache server for relaychain headers", version, author)] pub struct AppArgs { #[command(subcommand)] action: Action, @@ -123,33 +123,32 @@ struct Serve { #[arg(long, default_value = "cache.db")] db: String, /// If set, it will sync headers from the given mirror cache - #[clap(long)] + #[arg(long)] mirror: Option, /// The genesis block bo be synced - #[clap(long, default_value_t = 8325311)] + #[arg(long, default_value_t = 8325311)] genesis_block: BlockNumber, /// Auto grab new headers from the node - #[clap(long)] + #[arg(long)] #[arg(visible_alias = "grab")] grab_headers: bool, /// Auto grab new parachain headers from the node - #[clap(long)] + #[arg(long)] grab_para_headers: bool, /// Auto grab new storage changes from the node - #[clap(long)] + #[arg(long)] grab_storage_changes: bool, /// Batch size for grabing storage changes - #[clap(long)] - #[clap(default_value_t = 1)] + #[arg(long, default_value_t = 1)] grab_storage_changes_batch: BlockNumber, /// The relaychain RPC endpoint - #[clap(long, default_value = "ws://localhost:9945")] + #[arg(long, default_value = "ws://localhost:9945")] node_uri: String, /// The parachain RPC endpoint - #[clap(long, default_value = "ws://localhost:9944")] + #[arg(long, default_value = "ws://localhost:9944")] para_node_uri: String, /// Interval that start a batch of grab - #[clap(long, default_value_t = 30)] + #[arg(long, default_value_t = 30)] interval: u64, /// Prefered minimum number of blocks between justification #[arg(long, default_value_t = 1000)] @@ -158,13 +157,13 @@ struct Serve { #[arg(long)] token: Option, /// The max batch size to check headers - #[clap(long, default_value_t = 100000)] + #[arg(long, default_value_t = 100000)] check_batch: BlockNumber, /// Don't check state root for each storage changes - #[clap(long)] + #[arg(long)] no_state_root: bool, /// Skip blocks with empty state root while checking storage changes - #[clap(long)] + #[arg(long)] allow_empty_state_root: bool, } diff --git a/standalone/justification-validate/src/main.rs b/standalone/justification-validate/src/main.rs index 8cef6528b2..b9cc626c4a 100644 --- a/standalone/justification-validate/src/main.rs +++ b/standalone/justification-validate/src/main.rs @@ -4,7 +4,7 @@ mod feed_pruntime; mod validator; #[derive(Parser)] -#[clap(about = "Validate justifications", version, author)] +#[command(about = "Validate justifications", version, author)] pub struct Args { /// The genesis.bin grabbed with headers-cache. #[arg(long)] diff --git a/standalone/node/Cargo.toml b/standalone/node/Cargo.toml index 9c96e9411e..b7455b022e 100644 --- a/standalone/node/Cargo.toml +++ b/standalone/node/Cargo.toml @@ -30,7 +30,7 @@ path = "bin/main.rs" required-features = ["cli"] [lib] -crate-type = ["cdylib", "rlib"] +# crate-type = ["cdylib", "rlib"] [dependencies] phala-node-rpc-ext = { path = "../../crates/phala-node-rpc-ext" } @@ -60,6 +60,8 @@ sp-keystore = { git = "https://github.com/paritytech/polkadot-sdk.git", branch = sp-consensus = { git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.5.0" } sp-transaction-storage-proof = { git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.5.0" } sp-io = { git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.5.0" } +sp-blockchain = { git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.5.0" } +sp-block-builder = { git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.5.0" } # client dependencies sc-client-api = { git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.5.0" } @@ -72,7 +74,7 @@ sc-network = { git = "https://github.com/paritytech/polkadot-sdk.git", branch = sc-network-sync = { git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.5.0" } sc-consensus-slots = { git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.5.0" } sc-consensus-babe = { git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.5.0" } -grandpa = { git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.5.0", package = "sc-consensus-grandpa" } +sc-consensus-grandpa = { git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.5.0" } sc-rpc = { git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.5.0" } sc-basic-authorship = { git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.5.0" } sc-service = { git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.5.0" } @@ -82,6 +84,14 @@ sc-authority-discovery = { git = "https://github.com/paritytech/polkadot-sdk.git sc-sync-state-rpc = { git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.5.0" } sc-sysinfo = { git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.5.0" } +# RPC +pallet-transaction-payment-rpc = { git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.5.0" } +sc-consensus-babe-rpc = { git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.5.0" } +sc-consensus-grandpa-rpc = { git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.5.0" } +sc-rpc-api = { git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.5.0" } +substrate-frame-rpc-system = { git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.5.0" } + + # frame dependencies frame-benchmarking = { git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.5.0" } frame-system = { git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.5.0" } @@ -91,7 +101,6 @@ pallet-transaction-payment = { git = "https://github.com/paritytech/polkadot-sdk # node-specific dependencies node-runtime = { path = "../runtime", package = "phala-node-runtime" } -node-rpc = { path = "../rpc" } node-primitives = { git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.5.0" } node-executor = { path = "../executor" } @@ -101,6 +110,20 @@ frame-benchmarking-cli = { git = "https://github.com/paritytech/polkadot-sdk.git node-inspect = { git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.5.0", package = "staging-node-inspect", optional = true } try-runtime-cli = { git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.5.0", optional = true } +# Frontier +fc-api = { workspace = true } +fc-consensus = { workspace = true } +fc-db = { workspace = true } +fc-mapping-sync = { workspace = true, features = ["sql"] } +fc-rpc = { workspace = true } +fc-rpc-core = { workspace = true } +fc-storage = { workspace = true } +fp-account = { workspace = true } +fp-dynamic-fee = { workspace = true, features = ["default"] } +fp-evm = { workspace = true, features = ["default"] } +fp-rpc = { workspace = true, features = ["default"] } +fc-cli = { workspace = true, features = ["default"] } + [dev-dependencies] sc-keystore = { git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.5.0" } sc-client-db = { git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.5.0" } diff --git a/standalone/node/build.rs b/standalone/node/build.rs index 636d0f9d0d..e3bfe3116b 100644 --- a/standalone/node/build.rs +++ b/standalone/node/build.rs @@ -1,66 +1,7 @@ -// This file is part of Substrate. - -// Copyright (C) 2017-2022 Parity Technologies (UK) Ltd. -// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0 - -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with this program. If not, see . +use substrate_build_script_utils::{generate_cargo_keys, rerun_if_git_head_changed}; fn main() { - #[cfg(feature = "cli")] - cli::main(); -} - -#[cfg(feature = "cli")] -mod cli { - include!("src/cli.rs"); - - use clap::{CommandFactory, ValueEnum}; - use clap_complete::{generate_to, Shell}; - use std::{env, fs, path::Path}; - use substrate_build_script_utils::{generate_cargo_keys, rerun_if_git_head_changed}; - - pub fn main() { - build_shell_completion(); - generate_cargo_keys(); - - rerun_if_git_head_changed(); - } - - /// Build shell completion scripts for all known shells - fn build_shell_completion() { - for shell in Shell::value_variants() { - build_completion(shell); - } - } - - /// Build the shell auto-completion for a given Shell - fn build_completion(shell: &Shell) { - let outdir = match env::var_os("OUT_DIR") { - None => return, - Some(dir) => dir, - }; - let path = Path::new(&outdir) - .parent() - .unwrap() - .parent() - .unwrap() - .parent() - .unwrap() - .join("completion-scripts"); - - fs::create_dir(&path).ok(); + generate_cargo_keys(); - let _ = generate_to(*shell, &mut Cli::command(), "phala-node", &path); - } + rerun_if_git_head_changed(); } diff --git a/standalone/node/src/chain_spec.rs b/standalone/node/src/chain_spec.rs index 88a5d6878a..00ef836a80 100644 --- a/standalone/node/src/chain_spec.rs +++ b/standalone/node/src/chain_spec.rs @@ -23,10 +23,10 @@ use hex_literal::hex; use node_runtime::constants::{currency::*, time::*}; use node_runtime::Block; use node_runtime::{ - wasm_binary_unwrap, AssetsConfig, BabeConfig, BalancesConfig, - CouncilConfig, DemocracyConfig, ElectionsConfig, ImOnlineConfig, IndicesConfig, - NominationPoolsConfig, PhalaRegistryConfig, SessionConfig, SessionKeys, SocietyConfig, - StakerStatus, StakingConfig, SudoConfig, SystemConfig, TechnicalCommitteeConfig, + wasm_binary_unwrap, AssetsConfig, BabeConfig, BalancesConfig, BaseFeeConfig, CouncilConfig, + DemocracyConfig, ElectionsConfig, ImOnlineConfig, IndicesConfig, NominationPoolsConfig, + PhalaRegistryConfig, SessionConfig, SessionKeys, SocietyConfig, StakerStatus, StakingConfig, + SudoConfig, SystemConfig, TechnicalCommitteeConfig, }; use pallet_im_online::sr25519::AuthorityId as ImOnlineId; use sc_chain_spec::{ChainSpecExtension, Properties}; @@ -36,6 +36,7 @@ use serde::{Deserialize, Serialize}; use sp_authority_discovery::AuthorityId as AuthorityDiscoveryId; use sp_consensus_babe::AuthorityId as BabeId; use sp_core::{crypto::UncheckedInto, sr25519, Pair, Public}; +use sp_runtime::Permill; use sp_runtime::{ traits::{IdentifyAccount, Verify}, Perbill, @@ -165,6 +166,13 @@ fn development_config_genesis() -> RuntimeGenesisConfig { /// Development config (single validator Alice) pub fn development_config() -> ChainSpec { + let properties = { + let mut p = Properties::new(); + p.insert("tokenSymbol".into(), "PHA".into()); + p.insert("tokenDecimals".into(), 12u32.into()); + p.insert("ss58Format".into(), 30u32.into()); + p + }; ChainSpec::from_genesis( "Phala Development", "phala_dev", @@ -177,14 +185,21 @@ pub fn development_config() -> ChainSpec { None, None, None, - None, + Some(properties), Default::default(), - wasm_binary_unwrap() + wasm_binary_unwrap(), ) } /// Development config (single validator Alice, custom block duration) pub fn development_config_custom_block_duration(bd: u64) -> ChainSpec { + let properties = { + let mut p = Properties::new(); + p.insert("tokenSymbol".into(), "PHA".into()); + p.insert("tokenDecimals".into(), 12u32.into()); + p.insert("ss58Format".into(), 30u32.into()); + p + }; ChainSpec::from_genesis( "Phala Development", "phala_dev", @@ -197,9 +212,9 @@ pub fn development_config_custom_block_duration(bd: u64) -> ChainSpec { None, None, None, - None, + Some(properties), Default::default(), - wasm_binary_unwrap() + wasm_binary_unwrap(), ) } @@ -227,7 +242,7 @@ pub fn local_config() -> ChainSpec { None, Some(properties), Default::default(), - wasm_binary_unwrap() + wasm_binary_unwrap(), ) } @@ -275,7 +290,7 @@ pub fn testnet_local_config() -> ChainSpec { None, Some(properties), Default::default(), - wasm_binary_unwrap() + wasm_binary_unwrap(), ) } @@ -429,7 +444,7 @@ pub fn testnet_genesis( }, }; - RuntimeGenesisConfig { + RuntimeGenesisConfig { system: SystemConfig { ..Default::default() }, @@ -496,7 +511,7 @@ pub fn testnet_genesis( authority_discovery: Default::default(), grandpa: Default::default(), treasury: Default::default(), - society: SocietyConfig { pot: 0 }, + society: SocietyConfig { pot: 0 }, vesting: Default::default(), phala_registry, phala_computation: Default::default(), @@ -507,6 +522,9 @@ pub fn testnet_genesis( min_join_bond: DOLLARS, ..Default::default() }, + base_fee: BaseFeeConfig::new(100_000_000_000_u64.into(), Permill::zero()), + ethereum: Default::default(), + evm: Default::default(), } } @@ -542,7 +560,7 @@ pub(crate) mod tests { None, None, Default::default(), - wasm_binary_unwrap() + wasm_binary_unwrap(), ) } @@ -562,7 +580,7 @@ pub(crate) mod tests { None, None, Default::default(), - wasm_binary_unwrap() + wasm_binary_unwrap(), ) } @@ -579,7 +597,7 @@ pub(crate) mod tests { sync, transaction_pool, .. - } = new_full_base(config, false, |_, _| (), None)?; + } = new_full_base(config, Default::default(), false, None)?; Ok(sc_service_test::TestNetComponents::new( task_manager, client, diff --git a/standalone/node/src/cli.rs b/standalone/node/src/cli.rs index 73024aa178..5965a77986 100644 --- a/standalone/node/src/cli.rs +++ b/standalone/node/src/cli.rs @@ -16,6 +16,8 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . +use crate::eth::EthConfiguration; + /// An overarching CLI command definition. #[derive(Debug, clap::Parser)] pub struct Cli { @@ -44,6 +46,10 @@ pub struct Cli { /// Custom gossip duration in milliseconds. #[arg(long)] pub gossip_duration_millisecs: Option, + + /// Ethereum RPC configuration. + #[command(flatten)] + pub eth: EthConfiguration, } /// Possible subcommands of the main binary. @@ -51,7 +57,7 @@ pub struct Cli { #[derive(Debug, clap::Subcommand)] pub enum Subcommand { /// The custom inspect subcommmand for decoding blocks and extrinsics. - #[clap( + #[command( name = "inspect", about = "Decode given block or extrinsic using current native runtime." )] @@ -98,4 +104,6 @@ pub enum Subcommand { /// Db meta columns information. ChainInfo(sc_cli::ChainInfoCmd), + /// Frontier database subcommands. + FrontierDb(::fc_cli::FrontierDbCmd), } diff --git a/standalone/node/src/command.rs b/standalone/node/src/command.rs index bf1d2f84b3..5eda2828a7 100644 --- a/standalone/node/src/command.rs +++ b/standalone/node/src/command.rs @@ -19,13 +19,12 @@ use super::benchmarking::{inherent_benchmark_data, RemarkBuilder, TransferKeepAliveBuilder}; use crate::{ chain_spec, service, - service::{new_partial, FullClient}, + service::{ChainOpsComponents, FullClient}, Cli, Subcommand, }; use frame_benchmarking_cli::*; use node_runtime::{Block, ExistentialDeposit, RuntimeApi}; use sc_cli::SubstrateCli; -use sc_service::PartialComponents; use sp_keyring::Sr25519Keyring; use std::sync::Arc; @@ -96,9 +95,11 @@ pub fn run() -> sc_cli::Result<()> { runner.run_node_until_exit(|config| async move { service::new_full( config, + &cli.eth, cli.no_hardware_benchmarks, cli.gossip_duration_millisecs, ) + .await .map_err(sc_cli::Error::Service) }) } @@ -110,7 +111,7 @@ pub fn run() -> sc_cli::Result<()> { Some(Subcommand::Benchmark(cmd)) => { let runner = cli.create_runner(cmd)?; - runner.sync_run(|config| { + runner.sync_run(|mut config| { // This switch needs to be in the client, since the client decides // which sub-commands it wants to support. match cmd { @@ -127,7 +128,7 @@ pub fn run() -> sc_cli::Result<()> { } BenchmarkCmd::Block(cmd) => { // ensure that we keep the task manager alive - let partial = new_partial(&config)?; + let partial = service::new_chain_ops(&mut config, &cli.eth)?; cmd.run(partial.client) } #[cfg(not(feature = "runtime-benchmarks"))] @@ -138,7 +139,7 @@ pub fn run() -> sc_cli::Result<()> { #[cfg(feature = "runtime-benchmarks")] BenchmarkCmd::Storage(cmd) => { // ensure that we keep the task manager alive - let partial = new_partial(&config)?; + let partial = service::new_chain_ops(&mut config, &cli.eth)?; let db = partial.backend.expose_db(); let storage = partial.backend.expose_storage(); @@ -146,7 +147,7 @@ pub fn run() -> sc_cli::Result<()> { } BenchmarkCmd::Overhead(cmd) => { // ensure that we keep the task manager alive - let partial = new_partial(&config)?; + let partial = service::new_chain_ops(&mut config, &cli.eth)?; let ext_builder = RemarkBuilder::new(partial.client.clone()); cmd.run( @@ -159,7 +160,7 @@ pub fn run() -> sc_cli::Result<()> { } BenchmarkCmd::Extrinsic(cmd) => { // ensure that we keep the task manager alive - let partial = service::new_partial(&config)?; + let partial = service::new_chain_ops(&mut config, &cli.eth)?; // Register the *Remark* and *TKA* builders. let ext_factory = ExtrinsicFactory(vec![ Box::new(RemarkBuilder::new(partial.client.clone())), @@ -193,47 +194,47 @@ pub fn run() -> sc_cli::Result<()> { } Some(Subcommand::CheckBlock(cmd)) => { let runner = cli.create_runner(cmd)?; - runner.async_run(|config| { - let PartialComponents { + runner.async_run(|mut config| { + let ChainOpsComponents { client, task_manager, import_queue, .. - } = new_partial(&config)?; + } = service::new_chain_ops(&mut config, &cli.eth)?; Ok((cmd.run(client, import_queue), task_manager)) }) } Some(Subcommand::ExportBlocks(cmd)) => { let runner = cli.create_runner(cmd)?; - runner.async_run(|config| { - let PartialComponents { + runner.async_run(|mut config| { + let ChainOpsComponents { client, task_manager, .. - } = new_partial(&config)?; + } = service::new_chain_ops(&mut config, &cli.eth)?; Ok((cmd.run(client, config.database), task_manager)) }) } Some(Subcommand::ExportState(cmd)) => { let runner = cli.create_runner(cmd)?; - runner.async_run(|config| { - let PartialComponents { + runner.async_run(|mut config| { + let ChainOpsComponents { client, task_manager, .. - } = new_partial(&config)?; + } = service::new_chain_ops(&mut config, &cli.eth)?; Ok((cmd.run(client, config.chain_spec), task_manager)) }) } Some(Subcommand::ImportBlocks(cmd)) => { let runner = cli.create_runner(cmd)?; - runner.async_run(|config| { - let PartialComponents { + runner.async_run(|mut config| { + let ChainOpsComponents { client, task_manager, import_queue, .. - } = new_partial(&config)?; + } = service::new_chain_ops(&mut config, &cli.eth)?; Ok((cmd.run(client, import_queue), task_manager)) }) } @@ -243,16 +244,16 @@ pub fn run() -> sc_cli::Result<()> { } Some(Subcommand::Revert(cmd)) => { let runner = cli.create_runner(cmd)?; - runner.async_run(|config| { - let PartialComponents { + runner.async_run(|mut config| { + let ChainOpsComponents { client, task_manager, backend, .. - } = new_partial(&config)?; + } = service::new_chain_ops(&mut config, &cli.eth)?; let aux_revert = Box::new(|client: Arc, backend, blocks| { sc_consensus_babe::revert(client.clone(), backend, blocks)?; - grandpa::revert(client, blocks)?; + sc_consensus_grandpa::revert(client, blocks)?; Ok(()) }); Ok((cmd.run(client, backend, Some(aux_revert)), task_manager)) @@ -262,5 +263,20 @@ pub fn run() -> sc_cli::Result<()> { let runner = cli.create_runner(cmd)?; runner.sync_run(|config| cmd.run::(&config)) } + Some(Subcommand::FrontierDb(cmd)) => { + let runner = cli.create_runner(cmd)?; + runner.sync_run(|mut config| { + let ChainOpsComponents { + client, + frontier_backend, + .. + } = service::new_chain_ops(&mut config, &cli.eth)?; + let frontier_backend = match frontier_backend { + fc_db::Backend::KeyValue(kv) => std::sync::Arc::new(kv), + _ => panic!("Only fc_db::Backend::KeyValue supported"), + }; + cmd.run(client, frontier_backend) + }) + } } } diff --git a/standalone/node/src/eth.rs b/standalone/node/src/eth.rs new file mode 100644 index 0000000000..1aea2e9fe6 --- /dev/null +++ b/standalone/node/src/eth.rs @@ -0,0 +1,204 @@ +use std::{ + collections::BTreeMap, + path::PathBuf, + sync::{Arc, Mutex}, + time::Duration, +}; + +use futures::{future, prelude::*}; +// Substrate +use sc_client_api::BlockchainEvents; +use sc_network_sync::SyncingService; +use sc_service::{error::Error as ServiceError, Configuration, TaskManager}; +// Frontier +use fc_rpc::{EthTask, OverrideHandle}; +pub use fc_rpc_core::types::{FeeHistoryCache, FeeHistoryCacheLimit, FilterPool}; +// Local +use node_primitives::Block; + +use crate::service::{FullBackend, FullClient}; + +/// Frontier DB backend type. +pub type FrontierBackend = fc_db::Backend; + +pub fn db_config_dir(config: &Configuration) -> PathBuf { + config.base_path.config_dir(config.chain_spec.id()) +} + +/// Avalailable frontier backend types. +#[derive(Debug, Copy, Clone, Default, clap::ValueEnum)] +pub enum BackendType { + /// Either RocksDb or ParityDb as per inherited from the global backend settings. + #[default] + KeyValue, + /// Sql database with custom log indexing. + Sql, +} + +/// The ethereum-compatibility configuration used to run a node. +#[derive(Clone, Debug, clap::Parser)] +pub struct EthConfiguration { + /// Maximum number of logs in a query. + #[arg(long, default_value = "10000")] + pub max_past_logs: u32, + + /// Maximum fee history cache size. + #[arg(long, default_value = "2048")] + pub fee_history_limit: u64, + + #[arg(long)] + pub enable_dev_signer: bool, + + /// The dynamic-fee pallet target gas price set by block author + #[arg(long, default_value = "1")] + pub target_gas_price: u64, + + /// Maximum allowed gas limit will be `block.gas_limit * execute_gas_limit_multiplier` + /// when using eth_call/eth_estimateGas. + #[arg(long, default_value = "10")] + pub execute_gas_limit_multiplier: u64, + + /// Size in bytes of the LRU cache for block data. + #[arg(long, default_value = "50")] + pub eth_log_block_cache: usize, + + /// Size in bytes of the LRU cache for transactions statuses data. + #[arg(long, default_value = "50")] + pub eth_statuses_cache: usize, + + /// Sets the frontier backend type (KeyValue or Sql) + #[arg(long, value_enum, ignore_case = true, default_value_t = BackendType::default())] + pub frontier_backend_type: BackendType, + + // Sets the SQL backend's pool size. + #[arg(long, default_value = "100")] + pub frontier_sql_backend_pool_size: u32, + + /// Sets the SQL backend's query timeout in number of VM ops. + #[arg(long, default_value = "10000000")] + pub frontier_sql_backend_num_ops_timeout: u32, + + /// Sets the SQL backend's auxiliary thread limit. + #[arg(long, default_value = "4")] + pub frontier_sql_backend_thread_count: u32, + + /// Sets the SQL backend's query timeout in number of VM ops. + /// Default value is 200MB. + #[arg(long, default_value = "209715200")] + pub frontier_sql_backend_cache_size: u64, +} + +pub struct FrontierPartialComponents { + pub filter_pool: Option, + pub fee_history_cache: FeeHistoryCache, + pub fee_history_cache_limit: FeeHistoryCacheLimit, +} + +pub fn new_frontier_partial( + config: &EthConfiguration, +) -> Result { + Ok(FrontierPartialComponents { + filter_pool: Some(Arc::new(Mutex::new(BTreeMap::new()))), + fee_history_cache: Arc::new(Mutex::new(BTreeMap::new())), + fee_history_cache_limit: config.fee_history_limit, + }) +} + +/// A set of APIs that ethereum-compatible runtimes must implement. +pub trait EthCompatRuntimeApiCollection: + sp_api::ApiExt + + fp_rpc::ConvertTransactionRuntimeApi + + fp_rpc::EthereumRuntimeRPCApi +{ +} + +impl EthCompatRuntimeApiCollection for Api where + Api: sp_api::ApiExt + + fp_rpc::ConvertTransactionRuntimeApi + + fp_rpc::EthereumRuntimeRPCApi +{ +} + +#[allow(clippy::too_many_arguments)] +pub async fn spawn_frontier_tasks( + task_manager: &TaskManager, + client: Arc, + backend: Arc, + frontier_backend: FrontierBackend, + filter_pool: Option, + overrides: Arc>, + fee_history_cache: FeeHistoryCache, + fee_history_cache_limit: FeeHistoryCacheLimit, + sync: Arc>, + pubsub_notification_sinks: Arc< + fc_mapping_sync::EthereumBlockNotificationSinks< + fc_mapping_sync::EthereumBlockNotification, + >, + >, +) { + // Spawn main mapping sync worker background task. + match frontier_backend { + fc_db::Backend::KeyValue(b) => { + task_manager.spawn_essential_handle().spawn( + "frontier-mapping-sync-worker", + Some("frontier"), + fc_mapping_sync::kv::MappingSyncWorker::new( + client.import_notification_stream(), + Duration::new(6, 0), + client.clone(), + backend, + overrides.clone(), + Arc::new(b), + 3, + 0, + fc_mapping_sync::SyncStrategy::Normal, + sync, + pubsub_notification_sinks, + ) + .for_each(|()| future::ready(())), + ); + } + fc_db::Backend::Sql(b) => { + task_manager.spawn_essential_handle().spawn_blocking( + "frontier-mapping-sync-worker", + Some("frontier"), + fc_mapping_sync::sql::SyncWorker::run( + client.clone(), + backend, + Arc::new(b), + client.import_notification_stream(), + fc_mapping_sync::sql::SyncWorkerConfig { + read_notification_timeout: Duration::from_secs(10), + check_indexed_blocks_interval: Duration::from_secs(60), + }, + fc_mapping_sync::SyncStrategy::Parachain, + sync, + pubsub_notification_sinks, + ), + ); + } + } + + // Spawn Frontier EthFilterApi maintenance task. + if let Some(filter_pool) = filter_pool { + // Each filter is allowed to stay in the pool for 100 blocks. + const FILTER_RETAIN_THRESHOLD: u64 = 100; + task_manager.spawn_essential_handle().spawn( + "frontier-filter-pool", + Some("frontier"), + EthTask::filter_pool_task(client.clone(), filter_pool, FILTER_RETAIN_THRESHOLD), + ); + } + + // Spawn Frontier FeeHistory cache maintenance task. + task_manager.spawn_essential_handle().spawn( + "frontier-fee-history", + Some("frontier"), + EthTask::fee_history_task( + client, + overrides, + fee_history_cache, + fee_history_cache_limit, + ), + ); +} diff --git a/standalone/node/src/lib.rs b/standalone/node/src/lib.rs index a4b04c3916..16cdc60d17 100644 --- a/standalone/node/src/lib.rs +++ b/standalone/node/src/lib.rs @@ -38,8 +38,10 @@ mod benchmarking; mod cli; #[cfg(feature = "cli")] mod command; - +#[cfg(feature = "cli")] +mod eth; #[cfg(feature = "cli")] pub use cli::*; #[cfg(feature = "cli")] pub use command::*; +mod rpc; diff --git a/standalone/node/src/rpc.rs b/standalone/node/src/rpc.rs new file mode 100644 index 0000000000..a6e5ee6f84 --- /dev/null +++ b/standalone/node/src/rpc.rs @@ -0,0 +1,165 @@ +// This file is part of Substrate. + +// Copyright (C) 2019-2022 Parity Technologies (UK) Ltd. +// SPDX-License-Identifier: Apache-2.0 + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +//! A collection of node-specific RPC methods. +//! +//! Since `substrate` core functionality makes no assumptions +//! about the modules used inside the runtime, so do +//! RPC methods defined in `sc-rpc` crate. +//! It means that `client/rpc` can't have any methods that +//! need some strong assumptions about the particular runtime. +//! +//! The RPCs available in this crate however can make some assumptions +//! about how the runtime is constructed and what FRAME pallets +//! are part of it. Therefore all node-runtime-specific RPCs can +//! be placed here or imported from corresponding FRAME RPC definitions. + +use std::sync::Arc; + +use jsonrpsee::RpcModule; +use node_primitives::{AccountId, Balance, Block, Nonce}; +use sc_client_api::AuxStore; +use sc_consensus_babe::BabeWorkerHandle; +use sc_consensus_babe_rpc::{Babe, BabeApiServer}; +use sc_rpc::SubscriptionTaskExecutor; +pub use sc_rpc_api::DenyUnsafe; +use sc_transaction_pool::ChainApi; +use sc_transaction_pool_api::TransactionPool; +use sp_api::{CallApiAt, ProvideRuntimeApi}; +use sp_block_builder::BlockBuilder; +use sp_blockchain::{Error as BlockChainError, HeaderBackend, HeaderMetadata}; +use sp_consensus::SelectChain; +use sp_consensus_babe::BabeApi; +use sp_inherents::CreateInherentDataProviders; +use sp_keystore::KeystorePtr; +use sp_runtime::traits::Block as BlockT; + +pub mod eth; + +/// Extra dependencies for BABE. +pub struct BabeDeps { + /// A handle to the BABE worker for issuing requests. + pub babe_worker_handle: BabeWorkerHandle, + /// The keystore that manages the keys of the node. + pub keystore: KeystorePtr, +} + +/// Full client dependencies. +pub struct FullDeps, CT, CIDP> { + /// The client instance to use. + pub client: Arc, + /// Transaction pool instance. + pub pool: Arc

, + /// The SelectChain Strategy + pub select_chain: SC, + /// Whether to deny unsafe calls + pub deny_unsafe: DenyUnsafe, + /// BABE specific dependencies. + pub babe: BabeDeps, + /// The backend used by the node. + pub backend: Arc, + /// Ethereum-compatibility specific dependencies. + pub eth: eth::EthDeps, +} + +/// Instantiate all Full RPC extensions. +pub fn create_full( + deps: FullDeps, + subscription_task_executor: SubscriptionTaskExecutor, + pubsub_notification_sinks: Arc< + fc_mapping_sync::EthereumBlockNotificationSinks< + fc_mapping_sync::EthereumBlockNotification, + >, + >, +) -> Result, Box> +where + C: ProvideRuntimeApi + + CallApiAt + + sc_client_api::BlockchainEvents + + sc_client_api::BlockBackend + + sc_client_api::UsageProvider + + sc_client_api::StorageProvider + + HeaderBackend + + AuxStore + + HeaderMetadata + + Sync + + Send + + 'static, + C::Api: substrate_frame_rpc_system::AccountNonceApi, + C::Api: pallet_transaction_payment_rpc::TransactionPaymentRuntimeApi, + C::Api: BabeApi, + C::Api: BlockBuilder, + C::Api: fp_rpc::EthereumRuntimeRPCApi, + C::Api: fp_rpc::ConvertTransactionRuntimeApi, + P: TransactionPool + 'static, + SC: SelectChain + 'static, + B: sc_client_api::Backend + Send + Sync + 'static, + B::State: sc_client_api::backend::StateBackend>, + A: ChainApi + 'static, + CIDP: CreateInherentDataProviders + Send + 'static, + CT: fp_rpc::ConvertTransaction<::Extrinsic> + Send + Sync + 'static, +{ + use pallet_transaction_payment_rpc::{TransactionPayment, TransactionPaymentApiServer}; + use substrate_frame_rpc_system::{System, SystemApiServer}; + + let mut io = RpcModule::new(()); + let FullDeps { + client, + pool, + deny_unsafe, + babe, + eth, + select_chain, + .. + } = deps; + let BabeDeps { + keystore, + babe_worker_handle, + } = babe; + + io.merge(System::new(client.clone(), pool.clone(), deny_unsafe).into_rpc())?; + io.merge(TransactionPayment::new(client.clone()).into_rpc())?; + io.merge( + Babe::new( + client.clone(), + babe_worker_handle.clone(), + keystore, + select_chain, + deny_unsafe, + ) + .into_rpc(), + )?; + let io = eth::create_eth::<_, _, _, _, _, _, _, DefaultEthConfig>( + io, + eth, + subscription_task_executor, + pubsub_notification_sinks, + )?; + Ok(io) +} + +pub struct DefaultEthConfig(std::marker::PhantomData<(C, BE)>); + +impl fc_rpc::EthConfig for DefaultEthConfig +where + C: sc_client_api::StorageProvider + Sync + Send + 'static, + BE: sc_client_api::Backend + 'static, +{ + type EstimateGasAdapter = (); + type RuntimeStorageOverride = + fc_rpc::frontier_backend_client::SystemAccountId20StorageOverride; +} diff --git a/standalone/node/src/rpc/eth.rs b/standalone/node/src/rpc/eth.rs new file mode 100644 index 0000000000..9712917d24 --- /dev/null +++ b/standalone/node/src/rpc/eth.rs @@ -0,0 +1,195 @@ +use std::{collections::BTreeMap, sync::Arc}; + +use jsonrpsee::RpcModule; +// Substrate +use sc_client_api::{ + backend::{Backend, StorageProvider}, + client::BlockchainEvents, + AuxStore, UsageProvider, +}; +use sc_network::NetworkService; +use sc_network_sync::SyncingService; +use sc_rpc::SubscriptionTaskExecutor; +use sc_transaction_pool::{ChainApi, Pool}; +use sc_transaction_pool_api::TransactionPool; +use sp_api::{CallApiAt, ProvideRuntimeApi}; +use sp_block_builder::BlockBuilder as BlockBuilderApi; +use sp_blockchain::{Error as BlockChainError, HeaderBackend, HeaderMetadata}; +use sp_consensus_babe::BabeApi; +use sp_core::H256; +use sp_inherents::CreateInherentDataProviders; +use sp_runtime::traits::Block as BlockT; +// Frontier +pub use fc_rpc::{EthBlockDataCacheTask, EthConfig, OverrideHandle, StorageOverride}; +pub use fc_rpc_core::types::{FeeHistoryCache, FeeHistoryCacheLimit, FilterPool}; +pub use fc_storage::overrides_handle; +use fp_rpc::{ConvertTransaction, ConvertTransactionRuntimeApi, EthereumRuntimeRPCApi}; + +/// Extra dependencies for Ethereum compatibility. +pub struct EthDeps { + /// The client instance to use. + pub client: Arc, + /// Transaction pool instance. + pub pool: Arc

, + /// Graph pool instance. + pub graph: Arc>, + /// Ethereum transaction converter. + pub converter: Option, + /// The Node authority flag + pub is_authority: bool, + /// Whether to enable dev signer + pub enable_dev_signer: bool, + /// Network service + pub network: Arc>, + /// Chain syncing service + pub sync: Arc>, + /// Frontier Backend. + pub frontier_backend: Arc>, + /// Ethereum data access overrides. + pub overrides: Arc>, + /// Cache for Ethereum block data. + pub block_data_cache: Arc>, + /// EthFilterApi pool. + pub filter_pool: Option, + /// Maximum number of logs in a query. + pub max_past_logs: u32, + /// Fee history cache. + pub fee_history_cache: FeeHistoryCache, + /// Maximum fee history cache size. + pub fee_history_cache_limit: FeeHistoryCacheLimit, + /// Maximum allowed gas limit will be ` block.gas_limit * execute_gas_limit_multiplier` when + /// using eth_call/eth_estimateGas. + pub execute_gas_limit_multiplier: u64, + /// Mandated parent hashes for a given block hash. + pub forced_parent_hashes: Option>, + /// Something that can create the inherent data providers for pending state + pub pending_create_inherent_data_providers: CIDP, +} + +/// Instantiate Ethereum-compatible RPC extensions. +pub fn create_eth( + mut io: RpcModule<()>, + deps: EthDeps, + subscription_task_executor: SubscriptionTaskExecutor, + pubsub_notification_sinks: Arc< + fc_mapping_sync::EthereumBlockNotificationSinks< + fc_mapping_sync::EthereumBlockNotification, + >, + >, +) -> Result, Box> +where + B: BlockT, + C: CallApiAt + ProvideRuntimeApi, + C::Api: BlockBuilderApi + + ConvertTransactionRuntimeApi + + EthereumRuntimeRPCApi + + BabeApi, + C: HeaderBackend + HeaderMetadata, + C: BlockchainEvents + AuxStore + UsageProvider + StorageProvider + 'static, + BE: Backend + 'static, + P: TransactionPool + 'static, + A: ChainApi + 'static, + CT: ConvertTransaction<::Extrinsic> + Send + Sync + 'static, + CIDP: CreateInherentDataProviders + Send + 'static, + EC: EthConfig, +{ + use fc_rpc::{ + Eth, EthApiServer, EthDevSigner, EthFilter, EthFilterApiServer, EthPubSub, + EthPubSubApiServer, EthSigner, Net, NetApiServer, Web3, Web3ApiServer, + }; + #[cfg(feature = "txpool")] + use fc_rpc::{TxPool, TxPoolApiServer}; + + let EthDeps { + client, + pool, + graph, + converter, + is_authority, + enable_dev_signer, + network, + sync, + frontier_backend, + overrides, + block_data_cache, + filter_pool, + max_past_logs, + fee_history_cache, + fee_history_cache_limit, + execute_gas_limit_multiplier, + forced_parent_hashes, + pending_create_inherent_data_providers, + } = deps; + + let mut signers = Vec::new(); + if enable_dev_signer { + signers.push(Box::new(EthDevSigner::new()) as Box); + } + + io.merge( + Eth::::new( + client.clone(), + pool.clone(), + graph.clone(), + converter, + sync.clone(), + signers, + overrides.clone(), + frontier_backend.clone(), + is_authority, + block_data_cache.clone(), + fee_history_cache, + fee_history_cache_limit, + execute_gas_limit_multiplier, + forced_parent_hashes, + pending_create_inherent_data_providers, + None, + ) + .replace_config::() + .into_rpc(), + )?; + + if let Some(filter_pool) = filter_pool { + io.merge( + EthFilter::new( + client.clone(), + frontier_backend, + graph.clone(), + filter_pool, + 500_usize, // max stored filters + max_past_logs, + block_data_cache, + ) + .into_rpc(), + )?; + } + + io.merge( + EthPubSub::new( + pool, + client.clone(), + sync, + subscription_task_executor, + overrides, + pubsub_notification_sinks, + ) + .into_rpc(), + )?; + + io.merge( + Net::new( + client.clone(), + network, + // Whether to format the `peer_count` response as Hex (default) or not. + true, + ) + .into_rpc(), + )?; + + io.merge(Web3::new(client.clone()).into_rpc())?; + + #[cfg(feature = "txpool")] + io.merge(TxPool::new(client, graph).into_rpc())?; + + Ok(io) +} diff --git a/standalone/node/src/service.rs b/standalone/node/src/service.rs index ac20ce3ce0..722d324272 100644 --- a/standalone/node/src/service.rs +++ b/standalone/node/src/service.rs @@ -26,24 +26,25 @@ use futures::prelude::*; use node_primitives::Block; use node_runtime::RuntimeApi; use sc_client_api::{Backend, BlockBackend}; -use sc_consensus_babe::{self, SlotProportion}; +use sc_consensus::BasicQueue; +use sc_consensus_babe::{self, BabeLink, BabeWorkerHandle, SlotProportion}; +use sc_consensus_grandpa as grandpa; use sc_network::{event::Event, NetworkEventStream, NetworkService}; use sc_network_sync::{warp::WarpSyncParams, SyncingService}; -use sc_service::{ - config::Configuration, error::Error as ServiceError, PruningMode, RpcHandlers, TaskManager, -}; -use sc_telemetry::{Telemetry, TelemetryWorker}; +use sc_service::{config::Configuration, error::Error as ServiceError, RpcHandlers, TaskManager}; +use sc_telemetry::{Telemetry, TelemetryHandle, TelemetryWorker}; use sc_transaction_pool_api::OffchainTransactionPoolFactory; use sp_api::ProvideRuntimeApi; -use sp_core::crypto::Pair; +use sp_core::{crypto::Pair, U256}; use sp_runtime::{generic, traits::Block as BlockT, SaturatedConversion}; use std::sync::Arc; +use crate::eth::{self, spawn_frontier_tasks, EthConfiguration, FrontierBackend}; +use crate::rpc; + /// Host functions required for kitchensink runtime and Substrate node. #[cfg(not(feature = "runtime-benchmarks"))] -pub type HostFunctions = ( - sp_io::SubstrateHostFunctions, -); +pub type HostFunctions = (sp_io::SubstrateHostFunctions,); /// Host functions required for kitchensink runtime and Substrate node. #[cfg(feature = "runtime-benchmarks")] @@ -58,10 +59,13 @@ pub type RuntimeExecutor = sc_executor::WasmExecutor; /// The full client type definition. pub type FullClient = sc_service::TFullClient; -type FullBackend = sc_service::TFullBackend; +pub type FullBackend = sc_service::TFullBackend; type FullSelectChain = sc_consensus::LongestChain; -type FullGrandpaBlockImport = - grandpa::GrandpaBlockImport; + +type BasicImportQueue = sc_consensus::DefaultImportQueue; +type GrandpaBlockImport = + grandpa::GrandpaBlockImport; +type BoxBlockImport = sc_consensus::BoxBlockImport; /// The minimum period of blocks on which justifications will be /// imported and generated. @@ -148,10 +152,23 @@ pub fn create_extrinsic( ) } +struct OtherComponents { + block_import: BoxBlockImport, + babe_link: sc_consensus_babe::BabeLink, + babe_worker_handle: BabeWorkerHandle, + grandpa_link: grandpa::LinkHalf, + voter_state: grandpa::SharedVoterState, + telemetry: Option, + frontier_backend: FrontierBackend, + overrides: Arc>, +} + /// Creates a new partial node. #[allow(clippy::type_complexity, clippy::redundant_clone)] -pub fn new_partial( +fn new_partial( config: &Configuration, + eth_config: &EthConfiguration, + build_import_queue: BIQ, ) -> Result< sc_service::PartialComponents< FullClient, @@ -159,22 +176,30 @@ pub fn new_partial( FullSelectChain, sc_consensus::DefaultImportQueue, sc_transaction_pool::FullPool, + OtherComponents, + >, + ServiceError, +> +where + BIQ: FnOnce( + Arc, + Arc, + &Configuration, + &EthConfiguration, + &TaskManager, + Option, + GrandpaBlockImport, + OffchainTransactionPoolFactory, + ) -> Result< ( - impl Fn( - node_rpc::DenyUnsafe, - sc_rpc::SubscriptionTaskExecutor, - ) -> Result, sc_service::Error>, - ( - sc_consensus_babe::BabeBlockImport, - grandpa::LinkHalf, - sc_consensus_babe::BabeLink, - ), - grandpa::SharedVoterState, - Option, + BasicImportQueue, + BabeWorkerHandle, + BoxBlockImport, + BabeLink, ), + ServiceError, >, - ServiceError, -> { +{ let telemetry = config .telemetry_endpoints .clone() @@ -220,101 +245,57 @@ pub fn new_partial( select_chain.clone(), telemetry.as_ref().map(|x| x.handle()), )?; - let justification_import = grandpa_block_import.clone(); - - let (block_import, babe_link) = sc_consensus_babe::block_import( - sc_consensus_babe::configuration(&*client)?, - grandpa_block_import, - client.clone(), - )?; - - let slot_duration = babe_link.config().slot_duration(); - let (import_queue, babe_worker_handle) = - sc_consensus_babe::import_queue(sc_consensus_babe::ImportQueueParams { - link: babe_link.clone(), - block_import: block_import.clone(), - justification_import: Some(Box::new(justification_import)), - client: client.clone(), - select_chain: select_chain.clone(), - create_inherent_data_providers: move |_, ()| async move { - let timestamp = sp_timestamp::InherentDataProvider::from_system_time(); - - let slot = - sp_consensus_babe::inherents::InherentDataProvider::from_timestamp_and_slot_duration( - *timestamp, - slot_duration, - ); - - Ok((slot, timestamp)) - }, - spawner: &task_manager.spawn_essential_handle(), - registry: config.prometheus_registry(), - telemetry: telemetry.as_ref().map(|x| x.handle()), - offchain_tx_pool_factory: OffchainTransactionPoolFactory::new(transaction_pool.clone()), - })?; - - let import_setup = (block_import, grandpa_link, babe_link); - - let (rpc_extensions_builder, rpc_setup) = { - let (_, grandpa_link, _) = &import_setup; - - let justification_stream = grandpa_link.justification_stream(); - let shared_authority_set = grandpa_link.shared_authority_set().clone(); - let shared_voter_state = grandpa::SharedVoterState::empty(); + let (voter_state, import_queue, block_import, babe_link, babe_worker_handle) = { + let shared_voter_state = sc_consensus_grandpa::SharedVoterState::empty(); let shared_voter_state2 = shared_voter_state.clone(); - let finality_proof_provider = grandpa::FinalityProofProvider::new_for_service( - backend.clone(), - Some(shared_authority_set.clone()), - ); - let client = client.clone(); - let pool = transaction_pool.clone(); - let select_chain = select_chain.clone(); - let keystore = keystore_container.keystore(); - let chain_spec = config.chain_spec.cloned_box(); - - let rpc_backend = backend.clone(); - let is_archive_mode = match &config.state_pruning { - Some(m) => match m { - PruningMode::Constrained(_) => false, - PruningMode::ArchiveAll | PruningMode::ArchiveCanonical => true, - }, - None => true, - }; - let rpc_extensions_builder = move |deny_unsafe, subscription_executor| { - let deps = node_rpc::FullDeps { - client: client.clone(), - pool: pool.clone(), - select_chain: select_chain.clone(), - chain_spec: chain_spec.cloned_box(), - deny_unsafe, - babe: node_rpc::BabeDeps { - keystore: keystore.clone(), - babe_worker_handle: babe_worker_handle.clone(), - }, - grandpa: node_rpc::GrandpaDeps { - shared_voter_state: shared_voter_state.clone(), - shared_authority_set: shared_authority_set.clone(), - justification_stream: justification_stream.clone(), - subscription_executor, - finality_provider: finality_proof_provider.clone(), - }, - backend: rpc_backend.clone(), - }; - - let mut io = node_rpc::create_full(deps)?; - phala_node_rpc_ext::extend_rpc( - &mut io, - client.clone(), - rpc_backend.clone(), - is_archive_mode, - pool.clone(), - ); - Ok(io) - }; - - (rpc_extensions_builder, shared_voter_state2) + let (import_queue, babe_worker_handle, block_import, babe_link) = build_import_queue( + client.clone(), + backend.clone(), + config, + eth_config, + &task_manager, + telemetry.as_ref().map(|x| x.handle()), + grandpa_block_import, + OffchainTransactionPoolFactory::new(transaction_pool.clone()), + )?; + ( + shared_voter_state2, + import_queue, + block_import, + babe_link, + babe_worker_handle, + ) + }; + let overrides = fc_storage::overrides_handle(client.clone()); + let frontier_backend = match eth_config.frontier_backend_type { + eth::BackendType::KeyValue => FrontierBackend::KeyValue(fc_db::kv::Backend::open( + Arc::clone(&client), + &config.database, + ð::db_config_dir(config), + )?), + eth::BackendType::Sql => { + let db_path = eth::db_config_dir(config).join("sql"); + std::fs::create_dir_all(&db_path).expect("failed creating sql db directory"); + let backend = futures::executor::block_on(fc_db::sql::Backend::new( + fc_db::sql::BackendConfig::Sqlite(fc_db::sql::SqliteBackendConfig { + path: std::path::Path::new("sqlite:///") + .join(db_path) + .join("frontier.db3") + .to_str() + .unwrap(), + create_if_missing: true, + thread_count: eth_config.frontier_sql_backend_thread_count, + cache_size: eth_config.frontier_sql_backend_cache_size, + }), + eth_config.frontier_sql_backend_pool_size, + std::num::NonZeroU32::new(eth_config.frontier_sql_backend_num_ops_timeout), + overrides.clone(), + )) + .unwrap_or_else(|err| panic!("failed creating sql backend: {:?}", err)); + FrontierBackend::Sql(backend) + } }; Ok(sc_service::PartialComponents { @@ -325,7 +306,16 @@ pub fn new_partial( select_chain, import_queue, transaction_pool, - other: (rpc_extensions_builder, import_setup, rpc_setup, telemetry), + other: OtherComponents { + block_import, + babe_link, + babe_worker_handle, + grandpa_link, + voter_state, + telemetry, + frontier_backend, + overrides, + }, }) } @@ -346,13 +336,10 @@ pub struct NewFullBase { } /// Creates a full service from the configuration. -pub fn new_full_base( +pub async fn new_full_base( config: Configuration, + eth_config: &EthConfiguration, disable_hardware_benchmarks: bool, - with_startup_data: impl FnOnce( - &sc_consensus_babe::BabeBlockImport, - &sc_consensus_babe::BabeLink, - ), gossip_duration_millis: Option, ) -> Result { let hwbench = if !disable_hardware_benchmarks { @@ -364,6 +351,15 @@ pub fn new_full_base( None }; + // Sinks for pubsub notifications. + // Everytime a new subscription is created, a new mpsc channel is added to the sink pool. + // The MappingSyncWorker sends through the channel on block import and the subscription emits a notification to the subscriber on receiving a message through this channel. + // This way we avoid race conditions when using native substrate block import notification stream. + let pubsub_notification_sinks: fc_mapping_sync::EthereumBlockNotificationSinks< + fc_mapping_sync::EthereumBlockNotification, + > = Default::default(); + let pubsub_notification_sinks = Arc::new(pubsub_notification_sinks); + let sc_service::PartialComponents { client, backend, @@ -372,10 +368,25 @@ pub fn new_full_base( keystore_container, select_chain, transaction_pool, - other: (rpc_builder, import_setup, rpc_setup, mut telemetry), - } = new_partial(&config)?; + other, + } = new_partial(&config, eth_config, build_babe_grandpa_import_queue)?; + let OtherComponents { + block_import, + babe_link, + babe_worker_handle, + grandpa_link, + voter_state: shared_voter_state, + mut telemetry, + frontier_backend, + overrides, + .. + } = other; + let eth::FrontierPartialComponents { + filter_pool, + fee_history_cache, + fee_history_cache_limit, + } = eth::new_frontier_partial(eth_config)?; - let shared_voter_state = rpc_setup; let auth_disc_publish_non_global_ips = config.network.allow_non_globals_in_dht; let mut net_config = sc_network::config::FullNetworkConfiguration::new(&config.network); let grandpa_protocol_name = grandpa::protocol_standard_name( @@ -392,7 +403,7 @@ pub fn new_full_base( let warp_sync = Arc::new(grandpa::warp_proof::NetworkProvider::new( backend.clone(), - import_setup.1.shared_authority_set().clone(), + grandpa_link.shared_authority_set().clone(), Vec::default(), )); @@ -418,6 +429,97 @@ pub fn new_full_base( let prometheus_registry = config.prometheus_registry().cloned(); let enable_offchain_worker = config.offchain_worker.enabled; + let rpc_builder = { + let client = client.clone(); + let pool = transaction_pool.clone(); + let network = network.clone(); + let sync_service = sync_service.clone(); + let keystore = keystore_container.keystore(); + + let is_authority = role.is_authority(); + let enable_dev_signer = eth_config.enable_dev_signer; + let max_past_logs = eth_config.max_past_logs; + let execute_gas_limit_multiplier = eth_config.execute_gas_limit_multiplier; + let filter_pool = filter_pool.clone(); + let frontier_backend = frontier_backend.clone(); + let pubsub_notification_sinks = pubsub_notification_sinks.clone(); + let overrides = overrides.clone(); + let fee_history_cache = fee_history_cache.clone(); + let block_data_cache = Arc::new(fc_rpc::EthBlockDataCacheTask::new( + task_manager.spawn_handle(), + overrides.clone(), + eth_config.eth_log_block_cache, + eth_config.eth_statuses_cache, + prometheus_registry.clone(), + )); + + let slot_duration = babe_link.config().slot_duration(); + let target_gas_price = eth_config.target_gas_price; + let pending_create_inherent_data_providers = move |_, ()| async move { + let current = sp_timestamp::InherentDataProvider::from_system_time(); + let next_slot = current.timestamp().as_millis() + slot_duration.as_millis(); + let timestamp = sp_timestamp::InherentDataProvider::new(next_slot.into()); + let slot = sp_consensus_babe::inherents::InherentDataProvider::from_timestamp_and_slot_duration( + *timestamp, + slot_duration, + ); + let dynamic_fee = fp_dynamic_fee::InherentDataProvider(U256::from(target_gas_price)); + Ok((slot, timestamp, dynamic_fee)) + }; + + let rpc_backend = backend.clone(); + let rpc_select_chain = select_chain.clone(); + Box::new(move |deny_unsafe, subscription_task_executor| { + let eth_deps = crate::rpc::eth::EthDeps { + client: client.clone(), + pool: pool.clone(), + graph: pool.pool().clone(), + converter: Some(node_runtime::TransactionConverter), + is_authority, + enable_dev_signer, + network: network.clone(), + sync: sync_service.clone(), + frontier_backend: match frontier_backend.clone() { + fc_db::Backend::KeyValue(b) => Arc::new(b), + fc_db::Backend::Sql(b) => Arc::new(b), + }, + overrides: overrides.clone(), + block_data_cache: block_data_cache.clone(), + filter_pool: filter_pool.clone(), + max_past_logs, + fee_history_cache: fee_history_cache.clone(), + fee_history_cache_limit, + execute_gas_limit_multiplier, + forced_parent_hashes: None, + pending_create_inherent_data_providers, + }; + let deps = rpc::FullDeps { + client: client.clone(), + pool: pool.clone(), + select_chain: rpc_select_chain.clone(), + deny_unsafe, + babe: rpc::BabeDeps { + keystore: keystore.clone(), + babe_worker_handle: babe_worker_handle.clone(), + }, + backend: rpc_backend.clone(), + eth: eth_deps, + }; + let mut io = crate::rpc::create_full( + deps, + subscription_task_executor, + pubsub_notification_sinks.clone(), + )?; + phala_node_rpc_ext::extend_rpc( + &mut io, + client.clone(), + rpc_backend.clone(), + pool.clone(), + ); + Ok(io) + }) + }; + let rpc_handlers = sc_service::spawn_tasks(sc_service::SpawnTasksParams { config, backend: backend.clone(), @@ -446,10 +548,6 @@ pub fn new_full_base( } } - let (block_import, grandpa_link, babe_link) = import_setup; - - (with_startup_data)(&block_import, &babe_link); - if let sc_service::config::Role::Authority { .. } = &role { let proposer = sc_basic_authorship::ProposerFactory::new( task_manager.spawn_handle(), @@ -505,6 +603,20 @@ pub fn new_full_base( ); } + spawn_frontier_tasks( + &task_manager, + client.clone(), + backend.clone(), + frontier_backend, + filter_pool, + overrides, + fee_history_cache, + fee_history_cache_limit, + sync_service.clone(), + pubsub_notification_sinks, + ) + .await; + // Spawn authority discovery module. if role.is_authority() { let authority_discovery_role = @@ -601,12 +713,10 @@ pub fn new_full_base( network_provider: network.clone(), is_validator: role.is_authority(), enable_http_requests: true, - custom_extensions: move |_| { - vec![] - }, + custom_extensions: move |_| vec![], }) - .run(client.clone(), task_manager.spawn_handle()) - .boxed(), + .run(client.clone(), task_manager.spawn_handle()) + .boxed(), ); } @@ -622,302 +732,116 @@ pub fn new_full_base( } /// Builds a new service for a full client. -pub fn new_full( +pub async fn new_full( config: Configuration, + eth_config: &EthConfiguration, disable_hardware_benchmarks: bool, gossip_duration_millis: Option, ) -> Result { new_full_base( config, + eth_config, disable_hardware_benchmarks, - |_, _| (), gossip_duration_millis, ) + .await .map(|NewFullBase { task_manager, .. }| task_manager) } -#[cfg(test)] -mod tests { - use crate::service::{new_full_base, NewFullBase}; - use codec::Encode; - use node_primitives::{Block, DigestItem, Signature}; - use node_runtime::{ - constants::{currency::CENTS, time::SLOT_DURATION}, - Address, BalancesCall, RuntimeCall, UncheckedExtrinsic, - }; - use sc_client_api::BlockBackend; - use sc_consensus::{BlockImport, BlockImportParams, ForkChoiceStrategy}; - use sc_consensus_babe::{BabeIntermediate, CompatibleDigestItem, INTERMEDIATE_KEY}; - use sc_consensus_epochs::descendent_query; - use sc_keystore::LocalKeystore; - use sc_service_test::TestNetNode; - use sc_transaction_pool_api::{ChainEvent, MaintainedTransactionPool}; - use sp_consensus::{BlockOrigin, Environment, Proposer}; - use sp_core::crypto::Pair; - use sp_inherents::InherentDataProvider; - use sp_keyring::AccountKeyring; - use sp_keystore::KeystorePtr; - use sp_runtime::{ - generic::{Digest, Era, SignedPayload}, - key_types::BABE, - traits::{Block as BlockT, Header as HeaderT, IdentifyAccount, Verify}, - RuntimeAppPublic, +/// Build the import queue for the runtime (babe + grandpa). +#[allow(clippy::too_many_arguments)] +pub fn build_babe_grandpa_import_queue( + client: Arc, + backend: Arc, + config: &Configuration, + eth_config: &EthConfiguration, + task_manager: &TaskManager, + telemetry: Option, + grandpa_block_import: GrandpaBlockImport, + offchain_tx_pool_factory: OffchainTransactionPoolFactory, +) -> Result< + ( + BasicImportQueue, + BabeWorkerHandle, + BoxBlockImport, + BabeLink, + ), + ServiceError, +> { + let (babe_block_import, babe_link) = sc_consensus_babe::block_import( + sc_consensus_babe::configuration(&*client)?, + grandpa_block_import.clone(), + client.clone(), + )?; + // The original implemenation is: + // let frontier_block_import = FrontierBlockImport::new(babe_block_import.clone(), client.clone()); + // However, because our runtime didn't contains frontier stuff at the beginning, FrontierBlockImport would reject + // the early blocks until the runtime upgrade to support frontier. So, we use only babe_block_import here to make + // it compatible with the old blocks. + let frontier_block_import = babe_block_import.clone(); + let slot_duration = babe_link.config().slot_duration(); + let target_gas_price = eth_config.target_gas_price; + let create_inherent_data_providers = move |_, ()| async move { + let timestamp = sp_timestamp::InherentDataProvider::from_system_time(); + let slot = + sp_consensus_babe::inherents::InherentDataProvider::from_timestamp_and_slot_duration( + *timestamp, + slot_duration, + ); + let dynamic_fee = fp_dynamic_fee::InherentDataProvider(U256::from(target_gas_price)); + Ok((slot, timestamp, dynamic_fee)) }; - use sp_timestamp; - use std::sync::Arc; - - type AccountPublic = ::Signer; - - #[test] - // It is "ignored", but the node-cli ignored tests are running on the CI. - // This can be run locally with `cargo test --release -p node-cli test_sync -- --ignored`. - #[ignore] - fn test_sync() { - sp_tracing::try_init_simple(); - - let keystore_path = tempfile::tempdir().expect("Creates keystore path"); - let keystore: KeystorePtr = LocalKeystore::open(keystore_path.path(), None) - .expect("Creates keystore") - .into(); - let alice: sp_consensus_babe::AuthorityId = keystore - .sr25519_generate_new(BABE, Some("//Alice")) - .expect("Creates authority pair") - .into(); - - let chain_spec = crate::chain_spec::tests::integration_test_config_with_single_authority(); - - // For the block factory - let mut slot = 1u64; - - // For the extrinsics factory - let bob = Arc::new(AccountKeyring::Bob.pair()); - let charlie = Arc::new(AccountKeyring::Charlie.pair()); - let mut index = 0; - - sc_service_test::sync( - chain_spec, - |config| { - let mut setup_handles = None; - let NewFullBase { - task_manager, - client, - network, - sync, - transaction_pool, - .. - } = new_full_base( - config, - false, - |block_import: &sc_consensus_babe::BabeBlockImport, - babe_link: &sc_consensus_babe::BabeLink| { - setup_handles = Some((block_import.clone(), babe_link.clone())); - }, - None, - )?; - - let node = sc_service_test::TestNetComponents::new( - task_manager, - client, - network, - sync, - transaction_pool, - ); - Ok((node, setup_handles.unwrap())) - }, - |service, &mut (ref mut block_import, ref babe_link)| { - let parent_hash = service.client().chain_info().best_hash; - let parent_header = service.client().header(parent_hash).unwrap().unwrap(); - let parent_number = *parent_header.number(); - - futures::executor::block_on(service.transaction_pool().maintain( - ChainEvent::NewBestBlock { - hash: parent_header.hash(), - tree_route: None, - }, - )); - - let mut proposer_factory = sc_basic_authorship::ProposerFactory::new( - service.spawn_handle(), - service.client(), - service.transaction_pool(), - None, - None, - ); - - let mut digest = Digest::default(); - - // even though there's only one authority some slots might be empty, - // so we must keep trying the next slots until we can claim one. - let (babe_pre_digest, epoch_descriptor) = loop { - let epoch_descriptor = babe_link - .epoch_changes() - .shared_data() - .epoch_descriptor_for_child_of( - descendent_query(&*service.client()), - &parent_hash, - parent_number, - slot.into(), - ) - .unwrap() - .unwrap(); - - let epoch = babe_link - .epoch_changes() - .shared_data() - .epoch_data(&epoch_descriptor, |slot| { - sc_consensus_babe::Epoch::genesis(babe_link.config(), slot) - }) - .unwrap(); - - if let Some(babe_pre_digest) = - sc_consensus_babe::authorship::claim_slot(slot.into(), &epoch, &keystore) - .map(|(digest, _)| digest) - { - break (babe_pre_digest, epoch_descriptor); - } - slot += 1; - }; - - let inherent_data = futures::executor::block_on( - ( - sp_timestamp::InherentDataProvider::new( - std::time::Duration::from_millis(SLOT_DURATION * slot).into(), - ), - sp_consensus_babe::inherents::InherentDataProvider::new(slot.into()), - ) - .create_inherent_data(), - ) - .expect("Creates inherent data"); - - digest.push(::babe_pre_digest( - babe_pre_digest, - )); - - let new_block = futures::executor::block_on(async move { - let proposer = proposer_factory.init(&parent_header).await; - proposer - .unwrap() - .propose( - inherent_data, - digest, - std::time::Duration::from_secs(1), - None, - ) - .await - }) - .expect("Error making test block") - .block; - - let (new_header, new_body) = new_block.deconstruct(); - let pre_hash = new_header.hash(); - // sign the pre-sealed hash of the block and then - // add it to a digest item. - let to_sign = pre_hash.encode(); - let signature = keystore - .sr25519_sign(sp_consensus_babe::AuthorityId::ID, alice.as_ref(), &to_sign) - .unwrap() - .unwrap(); - let item = ::babe_seal(signature.into()); - slot += 1; - - let mut params = BlockImportParams::new(BlockOrigin::File, new_header); - params.post_digests.push(item); - params.body = Some(new_body); - params.insert_intermediate( - INTERMEDIATE_KEY, - BabeIntermediate:: { epoch_descriptor }, - ); - params.fork_choice = Some(ForkChoiceStrategy::LongestChain); - - futures::executor::block_on(block_import.import_block(params)) - .expect("error importing test block"); - }, - |service, _| { - let amount = 5 * CENTS; - let to: Address = AccountPublic::from(bob.public()).into_account().into(); - let from: Address = AccountPublic::from(charlie.public()).into_account().into(); - let genesis_hash = service.client().block_hash(0).unwrap().unwrap(); - let best_hash = service.client().chain_info().best_hash; - let (spec_version, transaction_version) = { - let version = service.client().runtime_version_at(best_hash).unwrap(); - (version.spec_version, version.transaction_version) - }; - let signer = charlie.clone(); - - let function = RuntimeCall::Balances(BalancesCall::transfer_allow_death { - dest: to, - value: amount, - }); + let select_chain = sc_consensus::LongestChain::new(backend.clone()); + let (import_queue, babe_worker_handle) = + sc_consensus_babe::import_queue(sc_consensus_babe::ImportQueueParams { + block_import: frontier_block_import.clone(), + justification_import: Some(Box::new(grandpa_block_import)), + client, + create_inherent_data_providers, + spawner: &task_manager.spawn_essential_handle(), + registry: config.prometheus_registry(), + telemetry, + link: babe_link.clone(), + select_chain, + offchain_tx_pool_factory, + }) + .map_err::(Into::into)?; - let check_non_zero_sender = frame_system::CheckNonZeroSender::new(); - let check_spec_version = frame_system::CheckSpecVersion::new(); - let check_tx_version = frame_system::CheckTxVersion::new(); - let check_genesis = frame_system::CheckGenesis::new(); - let check_era = frame_system::CheckEra::from(Era::Immortal); - let check_nonce = frame_system::CheckNonce::from(index); - let check_weight = frame_system::CheckWeight::new(); - let check_mq_sequence = phala_pallets::mq::CheckMqSequence::new(); - let payment = pallet_transaction_payment::ChargeTransactionPayment::from(0); - let extra = ( - check_non_zero_sender, - check_spec_version, - check_tx_version, - check_genesis, - check_era, - check_nonce, - check_weight, - check_mq_sequence, - payment, - ); - let raw_payload = SignedPayload::from_raw( - function, - extra, - ( - (), - spec_version, - transaction_version, - genesis_hash, - genesis_hash, - (), - (), - (), - (), - ), - ); - let signature = raw_payload.using_encoded(|payload| signer.sign(payload)); - let (function, extra, _) = raw_payload.deconstruct(); - index += 1; - UncheckedExtrinsic::new_signed(function, from, signature.into(), extra).into() - }, - ); - } + Ok(( + import_queue, + babe_worker_handle, + Box::new(frontier_block_import), + babe_link, + )) +} - #[test] - #[ignore] - fn test_consensus() { - sp_tracing::try_init_simple(); - - sc_service_test::consensus( - crate::chain_spec::tests::integration_test_config_with_two_authorities(), - |config| { - let NewFullBase { - task_manager, - client, - network, - sync, - transaction_pool, - .. - } = new_full_base(config, false, |_, _| (), None)?; - Ok(sc_service_test::TestNetComponents::new( - task_manager, - client, - network, - sync, - transaction_pool, - )) - }, - vec!["//Alice".into(), "//Bob".into()], - ) - } +pub struct ChainOpsComponents { + pub client: Arc, + pub backend: Arc, + pub import_queue: BasicQueue, + pub task_manager: TaskManager, + pub frontier_backend: FrontierBackend, +} + +pub fn new_chain_ops( + config: &mut Configuration, + eth_config: &EthConfiguration, +) -> Result { + config.keystore = sc_service::config::KeystoreConfig::InMemory; + let sc_service::PartialComponents { + client, + backend, + import_queue, + task_manager, + other, + .. + } = new_partial(config, eth_config, build_babe_grandpa_import_queue)?; + Ok(ChainOpsComponents { + client, + backend, + import_queue, + task_manager, + frontier_backend: other.frontier_backend, + }) } diff --git a/standalone/phat-poller/src/args.rs b/standalone/phat-poller/src/args.rs index 2671f48716..4df8c9d3c0 100644 --- a/standalone/phat-poller/src/args.rs +++ b/standalone/phat-poller/src/args.rs @@ -4,9 +4,9 @@ use sp_core::{crypto::SecretStringError, Pair, H256}; use std::time::Duration; #[derive(Parser)] -#[clap(about = "Cache server for relaychain headers", version, author)] +#[command(about = "Cache server for relaychain headers", version, author)] pub struct AppArgs { - #[clap(subcommand)] + #[command(subcommand)] pub action: Action, } diff --git a/standalone/pherry/src/lib.rs b/standalone/pherry/src/lib.rs index b2d6e26907..8b050a2024 100644 --- a/standalone/pherry/src/lib.rs +++ b/standalone/pherry/src/lib.rs @@ -55,7 +55,7 @@ use phala_types::{AttestationProvider, AttestationReport, Collateral}; pub use phaxt::connect as subxt_connect; #[derive(Parser, Debug)] -#[clap( +#[command( about = "Sync messages between pruntime and the blockchain.", version, author diff --git a/standalone/pruntime/Cargo.lock b/standalone/pruntime/Cargo.lock index 197f56985c..17e69cdfad 100644 --- a/standalone/pruntime/Cargo.lock +++ b/standalone/pruntime/Cargo.lock @@ -585,7 +585,7 @@ checksum = "7b2d0f03b3640e3a630367e40c468cb7f309529c708ed1d88597047b0e7c6ef7" dependencies = [ "proc-macro2", "quote", - "syn 2.0.43", + "syn 2.0.48", ] [[package]] @@ -1156,7 +1156,7 @@ dependencies = [ "heck 0.4.1", "proc-macro2", "quote", - "syn 2.0.43", + "syn 2.0.48", ] [[package]] @@ -1638,7 +1638,7 @@ checksum = "83fdaf97f4804dcebfa5862639bc9ce4121e82140bec2a987ac5140294865b5b" dependencies = [ "proc-macro2", "quote", - "syn 2.0.43", + "syn 2.0.48", ] [[package]] @@ -1758,7 +1758,7 @@ checksum = "5fe87ce4529967e0ba1dcf8450bab64d97dfd5010a6256187ffe2e43e6f0e049" dependencies = [ "proc-macro2", "quote", - "syn 2.0.43", + "syn 2.0.48", ] [[package]] @@ -1832,7 +1832,7 @@ dependencies = [ "proc-macro2", "proc-macro2-diagnostics 0.10.0", "quote", - "syn 2.0.43", + "syn 2.0.48", ] [[package]] @@ -1935,7 +1935,7 @@ dependencies = [ "proc-macro2", "quote", "regex", - "syn 2.0.43", + "syn 2.0.48", "termcolor", "toml 0.8.2", "walkdir", @@ -2126,7 +2126,7 @@ dependencies = [ "heck 0.4.1", "proc-macro2", "quote", - "syn 2.0.43", + "syn 2.0.48", ] [[package]] @@ -2166,7 +2166,7 @@ checksum = "5e9a1f9f7d83e59740248a6e14ecf93929ade55027844dfcea78beafccc15745" dependencies = [ "proc-macro2", "quote", - "syn 2.0.43", + "syn 2.0.48", ] [[package]] @@ -2301,6 +2301,24 @@ dependencies = [ "tiny-keccak", ] +[[package]] +name = "ethereum" +version = "0.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2e04d24d20b8ff2235cffbf242d5092de3aa45f77c5270ddbfadd2778ca13fea" +dependencies = [ + "bytes", + "ethereum-types", + "hash-db", + "hash256-std-hasher", + "parity-scale-codec", + "rlp", + "scale-info", + "serde", + "sha3", + "trie-root", +] + [[package]] name = "ethereum-types" version = "0.14.1" @@ -2384,7 +2402,7 @@ dependencies = [ "reqwest", "serde", "serde_json", - "syn 2.0.43", + "syn 2.0.48", "toml 0.7.6", "walkdir", ] @@ -2402,7 +2420,7 @@ dependencies = [ "proc-macro2", "quote", "serde_json", - "syn 2.0.43", + "syn 2.0.48", ] [[package]] @@ -2428,7 +2446,7 @@ dependencies = [ "serde", "serde_json", "strum 0.25.0", - "syn 2.0.43", + "syn 2.0.48", "tempfile", "thiserror", "tiny-keccak", @@ -2563,6 +2581,64 @@ dependencies = [ "yansi 0.5.1", ] +[[package]] +name = "evm" +version = "0.41.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "767f43e9630cc36cf8ff2777cbb0121b055f0d1fd6eaaa13b46a1808f0d0e7e9" +dependencies = [ + "auto_impl", + "environmental", + "ethereum", + "evm-core", + "evm-gasometer", + "evm-runtime", + "log", + "parity-scale-codec", + "primitive-types", + "rlp", + "scale-info", + "serde", + "sha3", +] + +[[package]] +name = "evm-core" +version = "0.41.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d1da6cedc5cedb4208e59467106db0d1f50db01b920920589f8e672c02fdc04f" +dependencies = [ + "parity-scale-codec", + "primitive-types", + "scale-info", + "serde", +] + +[[package]] +name = "evm-gasometer" +version = "0.41.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1dc0eb591abc5cd7b05bef6a036c2bb6c66ab6c5e0c5ce94bfe377ab670b1fd7" +dependencies = [ + "environmental", + "evm-core", + "evm-runtime", + "primitive-types", +] + +[[package]] +name = "evm-runtime" +version = "0.41.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "84bbe09b64ae13a29514048c1bb6fda6374ac0b4f6a1f15a443348ab88ef42cd" +dependencies = [ + "auto_impl", + "environmental", + "evm-core", + "primitive-types", + "sha3", +] + [[package]] name = "expander" version = "2.0.0" @@ -2573,7 +2649,7 @@ dependencies = [ "fs-err", "proc-macro2", "quote", - "syn 2.0.43", + "syn 2.0.48", ] [[package]] @@ -2773,6 +2849,104 @@ dependencies = [ "percent-encoding", ] +[[package]] +name = "fp-account" +version = "1.0.0-dev" +source = "git+https://github.com/kvinwang/frontier?branch=polkadot-v1.5.0#67990f8e62b7cc969ca62ec38318ab8a59da6142" +dependencies = [ + "hex", + "impl-serde", + "libsecp256k1", + "log", + "parity-scale-codec", + "scale-info", + "serde", + "sp-core", + "sp-io", + "sp-runtime", + "sp-runtime-interface 17.0.0 (git+https://github.com/paritytech/polkadot-sdk.git?branch=release-polkadot-v1.5.0)", + "sp-std 8.0.0 (git+https://github.com/paritytech/polkadot-sdk.git?branch=release-polkadot-v1.5.0)", +] + +[[package]] +name = "fp-consensus" +version = "2.0.0-dev" +source = "git+https://github.com/kvinwang/frontier?branch=polkadot-v1.5.0#67990f8e62b7cc969ca62ec38318ab8a59da6142" +dependencies = [ + "ethereum", + "parity-scale-codec", + "sp-core", + "sp-runtime", + "sp-std 8.0.0 (git+https://github.com/paritytech/polkadot-sdk.git?branch=release-polkadot-v1.5.0)", +] + +[[package]] +name = "fp-ethereum" +version = "1.0.0-dev" +source = "git+https://github.com/kvinwang/frontier?branch=polkadot-v1.5.0#67990f8e62b7cc969ca62ec38318ab8a59da6142" +dependencies = [ + "ethereum", + "ethereum-types", + "fp-evm", + "frame-support", + "parity-scale-codec", + "sp-std 8.0.0 (git+https://github.com/paritytech/polkadot-sdk.git?branch=release-polkadot-v1.5.0)", +] + +[[package]] +name = "fp-evm" +version = "3.0.0-dev" +source = "git+https://github.com/kvinwang/frontier?branch=polkadot-v1.5.0#67990f8e62b7cc969ca62ec38318ab8a59da6142" +dependencies = [ + "evm", + "frame-support", + "num_enum 0.7.1", + "parity-scale-codec", + "scale-info", + "serde", + "sp-core", + "sp-runtime", + "sp-std 8.0.0 (git+https://github.com/paritytech/polkadot-sdk.git?branch=release-polkadot-v1.5.0)", +] + +[[package]] +name = "fp-rpc" +version = "3.0.0-dev" +source = "git+https://github.com/kvinwang/frontier?branch=polkadot-v1.5.0#67990f8e62b7cc969ca62ec38318ab8a59da6142" +dependencies = [ + "ethereum", + "ethereum-types", + "fp-evm", + "parity-scale-codec", + "scale-info", + "sp-api", + "sp-core", + "sp-runtime", + "sp-state-machine", + "sp-std 8.0.0 (git+https://github.com/paritytech/polkadot-sdk.git?branch=release-polkadot-v1.5.0)", +] + +[[package]] +name = "fp-self-contained" +version = "1.0.0-dev" +source = "git+https://github.com/kvinwang/frontier?branch=polkadot-v1.5.0#67990f8e62b7cc969ca62ec38318ab8a59da6142" +dependencies = [ + "frame-support", + "parity-scale-codec", + "scale-info", + "serde", + "sp-runtime", +] + +[[package]] +name = "fp-storage" +version = "2.0.0" +source = "git+https://github.com/kvinwang/frontier?branch=polkadot-v1.5.0#67990f8e62b7cc969ca62ec38318ab8a59da6142" +dependencies = [ + "parity-scale-codec", + "serde", +] + [[package]] name = "frame-benchmarking" version = "4.0.0-dev" @@ -2806,7 +2980,7 @@ dependencies = [ "proc-macro-crate 2.0.1", "proc-macro2", "quote", - "syn 2.0.43", + "syn 2.0.48", ] [[package]] @@ -2913,7 +3087,7 @@ dependencies = [ "proc-macro2", "quote", "sp-core-hashing", - "syn 2.0.43", + "syn 2.0.48", ] [[package]] @@ -2925,7 +3099,7 @@ dependencies = [ "proc-macro-crate 2.0.1", "proc-macro2", "quote", - "syn 2.0.43", + "syn 2.0.48", ] [[package]] @@ -2935,7 +3109,7 @@ source = "git+https://github.com/paritytech/polkadot-sdk.git?branch=release-polk dependencies = [ "proc-macro2", "quote", - "syn 2.0.43", + "syn 2.0.48", ] [[package]] @@ -3089,7 +3263,7 @@ checksum = "89ca545a94061b6365f2c7355b4b32bd20df3ff95f02da9329b34ccc3bd6ee72" dependencies = [ "proc-macro2", "quote", - "syn 2.0.43", + "syn 2.0.48", ] [[package]] @@ -3763,7 +3937,7 @@ dependencies = [ "quote", "serde", "serde_json", - "syn 2.0.43", + "syn 2.0.48", ] [[package]] @@ -3820,7 +3994,7 @@ dependencies = [ "itertools", "proc-macro2", "quote", - "syn 2.0.43", + "syn 2.0.48", ] [[package]] @@ -3835,7 +4009,7 @@ dependencies = [ "parity-scale-codec", "proc-macro2", "quote", - "syn 2.0.43", + "syn 2.0.48", "synstructure", ] @@ -4266,7 +4440,7 @@ dependencies = [ "macro_magic_core", "macro_magic_macros", "quote", - "syn 2.0.43", + "syn 2.0.48", ] [[package]] @@ -4280,7 +4454,7 @@ dependencies = [ "macro_magic_core_macros", "proc-macro2", "quote", - "syn 2.0.43", + "syn 2.0.48", ] [[package]] @@ -4291,7 +4465,7 @@ checksum = "9ea73aa640dc01d62a590d48c0c3521ed739d53b27f919b25c3551e233481654" dependencies = [ "proc-macro2", "quote", - "syn 2.0.43", + "syn 2.0.48", ] [[package]] @@ -4302,7 +4476,7 @@ checksum = "ef9d79ae96aaba821963320eb2b6e34d17df1e5a83d8a1985c29cc5be59577b3" dependencies = [ "macro_magic_core", "quote", - "syn 2.0.43", + "syn 2.0.48", ] [[package]] @@ -4556,6 +4730,20 @@ dependencies = [ "minimal-lexical", ] +[[package]] +name = "num" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "43db66d1170d347f9a065114077f7dccb00c1b9478c89384490a3425279a4606" +dependencies = [ + "num-bigint", + "num-complex", + "num-integer", + "num-iter", + "num-rational", + "num-traits", +] + [[package]] name = "num-bigint" version = "0.4.3" @@ -4596,6 +4784,17 @@ dependencies = [ "num-traits", ] +[[package]] +name = "num-iter" +version = "0.1.43" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7d03e6c028c5dc5cac6e2dec0efda81fc887605bb3d884578bb6d6bf7514e252" +dependencies = [ + "autocfg", + "num-integer", + "num-traits", +] + [[package]] name = "num-rational" version = "0.4.1" @@ -4603,6 +4802,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0638a1c9d0a3c0914158145bc76cff373a75a627e6ecbfb71cbe6f453a5a19b0" dependencies = [ "autocfg", + "num-bigint", "num-integer", "num-traits", ] @@ -4644,6 +4844,15 @@ dependencies = [ "num_enum_derive 0.6.1", ] +[[package]] +name = "num_enum" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "683751d591e6d81200c39fb0d1032608b77724f34114db54f571ff1317b337c0" +dependencies = [ + "num_enum_derive 0.7.1", +] + [[package]] name = "num_enum_derive" version = "0.5.7" @@ -4665,7 +4874,19 @@ dependencies = [ "proc-macro-crate 1.2.1", "proc-macro2", "quote", - "syn 2.0.43", + "syn 2.0.48", +] + +[[package]] +name = "num_enum_derive" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c11e44798ad209ccdd91fc192f0526a369a01234f7373e1b141c96d7cee4f0e" +dependencies = [ + "proc-macro-crate 2.0.1", + "proc-macro2", + "quote", + "syn 2.0.48", ] [[package]] @@ -4849,6 +5070,20 @@ dependencies = [ "sp-std 8.0.0 (git+https://github.com/paritytech/polkadot-sdk.git?branch=release-polkadot-v1.5.0)", ] +[[package]] +name = "pallet-base-fee" +version = "1.0.0" +source = "git+https://github.com/kvinwang/frontier?branch=polkadot-v1.5.0#67990f8e62b7cc969ca62ec38318ab8a59da6142" +dependencies = [ + "fp-evm", + "frame-support", + "frame-system", + "parity-scale-codec", + "scale-info", + "sp-core", + "sp-runtime", +] + [[package]] name = "pallet-bounties" version = "4.0.0-dev" @@ -4941,7 +5176,7 @@ source = "git+https://github.com/paritytech/polkadot-sdk.git?branch=release-polk dependencies = [ "proc-macro2", "quote", - "syn 2.0.43", + "syn 2.0.48", ] [[package]] @@ -5029,6 +5264,95 @@ dependencies = [ "sp-std 8.0.0 (git+https://github.com/paritytech/polkadot-sdk.git?branch=release-polkadot-v1.5.0)", ] +[[package]] +name = "pallet-ethereum" +version = "4.0.0-dev" +source = "git+https://github.com/kvinwang/frontier?branch=polkadot-v1.5.0#67990f8e62b7cc969ca62ec38318ab8a59da6142" +dependencies = [ + "ethereum", + "ethereum-types", + "evm", + "fp-consensus", + "fp-ethereum", + "fp-evm", + "fp-rpc", + "fp-storage", + "frame-support", + "frame-system", + "pallet-evm", + "parity-scale-codec", + "scale-info", + "sp-io", + "sp-runtime", + "sp-std 8.0.0 (git+https://github.com/paritytech/polkadot-sdk.git?branch=release-polkadot-v1.5.0)", +] + +[[package]] +name = "pallet-evm" +version = "6.0.0-dev" +source = "git+https://github.com/kvinwang/frontier?branch=polkadot-v1.5.0#67990f8e62b7cc969ca62ec38318ab8a59da6142" +dependencies = [ + "environmental", + "evm", + "fp-account", + "fp-evm", + "frame-benchmarking", + "frame-support", + "frame-system", + "hash-db", + "hex", + "hex-literal", + "impl-trait-for-tuples", + "log", + "parity-scale-codec", + "rlp", + "scale-info", + "sp-core", + "sp-io", + "sp-runtime", + "sp-std 8.0.0 (git+https://github.com/paritytech/polkadot-sdk.git?branch=release-polkadot-v1.5.0)", +] + +[[package]] +name = "pallet-evm-precompile-dispatch" +version = "2.0.0-dev" +source = "git+https://github.com/kvinwang/frontier?branch=polkadot-v1.5.0#67990f8e62b7cc969ca62ec38318ab8a59da6142" +dependencies = [ + "fp-evm", + "frame-support", + "pallet-evm", + "parity-scale-codec", + "sp-runtime", +] + +[[package]] +name = "pallet-evm-precompile-modexp" +version = "2.0.0-dev" +source = "git+https://github.com/kvinwang/frontier?branch=polkadot-v1.5.0#67990f8e62b7cc969ca62ec38318ab8a59da6142" +dependencies = [ + "fp-evm", + "num", +] + +[[package]] +name = "pallet-evm-precompile-sha3fips" +version = "2.0.0-dev" +source = "git+https://github.com/kvinwang/frontier?branch=polkadot-v1.5.0#67990f8e62b7cc969ca62ec38318ab8a59da6142" +dependencies = [ + "fp-evm", + "tiny-keccak", +] + +[[package]] +name = "pallet-evm-precompile-simple" +version = "2.0.0-dev" +source = "git+https://github.com/kvinwang/frontier?branch=polkadot-v1.5.0#67990f8e62b7cc969ca62ec38318ab8a59da6142" +dependencies = [ + "fp-evm", + "ripemd", + "sp-io", +] + [[package]] name = "pallet-evm_account_mapping" version = "0.0.1" @@ -5090,6 +5414,22 @@ dependencies = [ "sp-std 8.0.0 (git+https://github.com/paritytech/polkadot-sdk.git?branch=release-polkadot-v1.5.0)", ] +[[package]] +name = "pallet-hotfix-sufficients" +version = "1.0.0" +source = "git+https://github.com/kvinwang/frontier?branch=polkadot-v1.5.0#67990f8e62b7cc969ca62ec38318ab8a59da6142" +dependencies = [ + "frame-benchmarking", + "frame-support", + "frame-system", + "pallet-evm", + "parity-scale-codec", + "scale-info", + "sp-core", + "sp-runtime", + "sp-std 8.0.0 (git+https://github.com/paritytech/polkadot-sdk.git?branch=release-polkadot-v1.5.0)", +] + [[package]] name = "pallet-identity" version = "4.0.0-dev" @@ -5473,7 +5813,7 @@ dependencies = [ "proc-macro-crate 2.0.1", "proc-macro2", "quote", - "syn 2.0.43", + "syn 2.0.48", ] [[package]] @@ -5996,6 +6336,10 @@ dependencies = [ name = "phala-node-runtime" version = "2.0.0" dependencies = [ + "fp-account", + "fp-evm", + "fp-rpc", + "fp-self-contained", "frame-benchmarking", "frame-election-provider-support", "frame-executive", @@ -6013,15 +6357,23 @@ dependencies = [ "pallet-babe", "pallet-bags-list", "pallet-balances", + "pallet-base-fee", "pallet-bounties", "pallet-child-bounties", "pallet-collective", "pallet-democracy", "pallet-election-provider-multi-phase", "pallet-elections-phragmen", + "pallet-ethereum", + "pallet-evm", + "pallet-evm-precompile-dispatch", + "pallet-evm-precompile-modexp", + "pallet-evm-precompile-sha3fips", + "pallet-evm-precompile-simple", "pallet-evm_account_mapping", "pallet-fast-unstake", "pallet-grandpa", + "pallet-hotfix-sufficients", "pallet-identity", "pallet-im-online", "pallet-indices", @@ -6306,7 +6658,7 @@ checksum = "39407670928234ebc5e6e580247dd567ad73a3578460c5990f9503df207e8f07" dependencies = [ "proc-macro2", "quote", - "syn 2.0.43", + "syn 2.0.48", ] [[package]] @@ -6392,7 +6744,7 @@ dependencies = [ "proc-macro-crate 1.2.1", "proc-macro2", "quote", - "syn 2.0.43", + "syn 2.0.48", "unzip3", ] @@ -6538,7 +6890,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9825a04601d60621feed79c4e6b56d65db77cdca55cef43b46b0de1096d1c282" dependencies = [ "proc-macro2", - "syn 2.0.43", + "syn 2.0.48", ] [[package]] @@ -6614,14 +6966,14 @@ checksum = "834da187cfe638ae8abb0203f0b33e5ccdb02a28e7199f2f47b3e2754f50edca" dependencies = [ "proc-macro2", "quote", - "syn 2.0.43", + "syn 2.0.48", ] [[package]] name = "proc-macro2" -version = "1.0.69" +version = "1.0.75" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "134c189feb4956b20f6f547d2cf727d4c0fe06722b20a0eec87ed445a97f92da" +checksum = "907a61bd0f64c2f29cd1cf1dc34d05176426a3f504a78010f08416ddb7b13708" dependencies = [ "unicode-ident", ] @@ -6647,7 +6999,7 @@ checksum = "606c4ba35817e2922a308af55ad51bab3645b59eae5c570d4a6cf07e36bd493b" dependencies = [ "proc-macro2", "quote", - "syn 2.0.43", + "syn 2.0.48", "version_check", "yansi 0.5.1", ] @@ -6898,9 +7250,9 @@ checksum = "a1d01941d82fa2ab50be1e79e6714289dd7cde78eba4c074bc5a4374f650dfe0" [[package]] name = "quote" -version = "1.0.33" +version = "1.0.35" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5267fca4496028628a95160fc423a33e8b2e6af8a5302579e322e4b520293cae" +checksum = "291ec9ab5efd934aaf503a6466c5d5251535d108ee747472c3977cc5acc868ef" dependencies = [ "proc-macro2", ] @@ -7449,7 +7801,7 @@ dependencies = [ "proc-macro2", "quote", "rocket_http", - "syn 2.0.43", + "syn 2.0.48", "unicode-xid", "version_check", ] @@ -7932,9 +8284,9 @@ checksum = "cd0b0ec5f1c1ca621c432a25813d8d60c88abe6d3e08a3eb9cf37d97a0fe3d73" [[package]] name = "serde" -version = "1.0.193" +version = "1.0.194" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "25dd9975e68d0cb5aa1120c288333fc98731bd1dd12f561e468ea4728c042b89" +checksum = "0b114498256798c94a0689e1a15fec6005dee8ac1f41de56404b67afc2a4b773" dependencies = [ "serde_derive", ] @@ -7962,13 +8314,13 @@ dependencies = [ [[package]] name = "serde_derive" -version = "1.0.193" +version = "1.0.194" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "43576ca501357b9b071ac53cdc7da8ef0cbd9493d8df094cd821777ea6e894d3" +checksum = "a3385e45322e8f9931410f01b3031ec534c3947d0e94c18049af4d9f9907d4e0" dependencies = [ "proc-macro2", "quote", - "syn 2.0.43", + "syn 2.0.48", ] [[package]] @@ -8352,7 +8704,7 @@ dependencies = [ "proc-macro-crate 2.0.1", "proc-macro2", "quote", - "syn 2.0.43", + "syn 2.0.48", ] [[package]] @@ -8539,13 +8891,13 @@ source = "git+https://github.com/paritytech/polkadot-sdk.git?branch=release-polk dependencies = [ "quote", "sp-core-hashing", - "syn 2.0.43", + "syn 2.0.48", ] [[package]] name = "sp-crypto-ec-utils" version = "0.4.1" -source = "git+https://github.com/paritytech/polkadot-sdk#b4c816665bd094b6ad703f1d11291c49bf66408f" +source = "git+https://github.com/paritytech/polkadot-sdk#19de1c96607f80ea1f55584c42e7050df08cb3e2" dependencies = [ "ark-bls12-377", "ark-bls12-377-ext", @@ -8570,17 +8922,17 @@ source = "git+https://github.com/paritytech/polkadot-sdk.git?branch=release-polk dependencies = [ "proc-macro2", "quote", - "syn 2.0.43", + "syn 2.0.48", ] [[package]] name = "sp-debug-derive" version = "8.0.0" -source = "git+https://github.com/paritytech/polkadot-sdk#b4c816665bd094b6ad703f1d11291c49bf66408f" +source = "git+https://github.com/paritytech/polkadot-sdk#19de1c96607f80ea1f55584c42e7050df08cb3e2" dependencies = [ "proc-macro2", "quote", - "syn 2.0.43", + "syn 2.0.48", ] [[package]] @@ -8597,7 +8949,7 @@ dependencies = [ [[package]] name = "sp-externalities" version = "0.19.0" -source = "git+https://github.com/paritytech/polkadot-sdk#b4c816665bd094b6ad703f1d11291c49bf66408f" +source = "git+https://github.com/paritytech/polkadot-sdk#19de1c96607f80ea1f55584c42e7050df08cb3e2" dependencies = [ "environmental", "parity-scale-codec", @@ -8767,7 +9119,7 @@ dependencies = [ [[package]] name = "sp-runtime-interface" version = "17.0.0" -source = "git+https://github.com/paritytech/polkadot-sdk#b4c816665bd094b6ad703f1d11291c49bf66408f" +source = "git+https://github.com/paritytech/polkadot-sdk#19de1c96607f80ea1f55584c42e7050df08cb3e2" dependencies = [ "bytes", "impl-trait-for-tuples", @@ -8792,20 +9144,20 @@ dependencies = [ "proc-macro-crate 2.0.1", "proc-macro2", "quote", - "syn 2.0.43", + "syn 2.0.48", ] [[package]] name = "sp-runtime-interface-proc-macro" version = "11.0.0" -source = "git+https://github.com/paritytech/polkadot-sdk#b4c816665bd094b6ad703f1d11291c49bf66408f" +source = "git+https://github.com/paritytech/polkadot-sdk#19de1c96607f80ea1f55584c42e7050df08cb3e2" dependencies = [ "Inflector", "expander", "proc-macro-crate 2.0.1", "proc-macro2", "quote", - "syn 2.0.43", + "syn 2.0.48", ] [[package]] @@ -8866,7 +9218,7 @@ source = "git+https://github.com/paritytech/polkadot-sdk.git?branch=release-polk [[package]] name = "sp-std" version = "8.0.0" -source = "git+https://github.com/paritytech/polkadot-sdk#b4c816665bd094b6ad703f1d11291c49bf66408f" +source = "git+https://github.com/paritytech/polkadot-sdk#19de1c96607f80ea1f55584c42e7050df08cb3e2" [[package]] name = "sp-storage" @@ -8884,7 +9236,7 @@ dependencies = [ [[package]] name = "sp-storage" version = "13.0.0" -source = "git+https://github.com/paritytech/polkadot-sdk#b4c816665bd094b6ad703f1d11291c49bf66408f" +source = "git+https://github.com/paritytech/polkadot-sdk#19de1c96607f80ea1f55584c42e7050df08cb3e2" dependencies = [ "impl-serde", "parity-scale-codec", @@ -8922,7 +9274,7 @@ dependencies = [ [[package]] name = "sp-tracing" version = "10.0.0" -source = "git+https://github.com/paritytech/polkadot-sdk#b4c816665bd094b6ad703f1d11291c49bf66408f" +source = "git+https://github.com/paritytech/polkadot-sdk#19de1c96607f80ea1f55584c42e7050df08cb3e2" dependencies = [ "parity-scale-codec", "sp-std 8.0.0 (git+https://github.com/paritytech/polkadot-sdk)", @@ -8990,7 +9342,7 @@ dependencies = [ "parity-scale-codec", "proc-macro2", "quote", - "syn 2.0.43", + "syn 2.0.48", ] [[package]] @@ -9009,7 +9361,7 @@ dependencies = [ [[package]] name = "sp-wasm-interface" version = "14.0.0" -source = "git+https://github.com/paritytech/polkadot-sdk#b4c816665bd094b6ad703f1d11291c49bf66408f" +source = "git+https://github.com/paritytech/polkadot-sdk#19de1c96607f80ea1f55584c42e7050df08cb3e2" dependencies = [ "anyhow", "impl-trait-for-tuples", @@ -9279,7 +9631,7 @@ dependencies = [ "proc-macro2", "quote", "rustversion", - "syn 2.0.43", + "syn 2.0.48", ] [[package]] @@ -9334,9 +9686,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.43" +version = "2.0.48" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ee659fb5f3d355364e1f3e5bc10fb82068efbf824a1e9d1c9504244a6469ad53" +checksum = "0f3531638e407dfc0814761abb7c00a5b54992b849452a0646b7f65c9f770f3f" dependencies = [ "proc-macro2", "quote", @@ -9351,7 +9703,7 @@ checksum = "285ba80e733fac80aa4270fbcdf83772a79b80aa35c97075320abfee4a915b06" dependencies = [ "proc-macro2", "quote", - "syn 2.0.43", + "syn 2.0.48", "unicode-xid", ] @@ -9506,7 +9858,7 @@ checksum = "266b2e40bc00e5a6c09c3584011e08b06f123c00362c92b975ba9843aaaa14b8" dependencies = [ "proc-macro2", "quote", - "syn 2.0.43", + "syn 2.0.48", ] [[package]] @@ -9635,7 +9987,7 @@ checksum = "630bdcf245f78637c13ec01ffae6187cca34625e8c63150d424b59e55af2675e" dependencies = [ "proc-macro2", "quote", - "syn 2.0.43", + "syn 2.0.48", ] [[package]] @@ -9805,7 +10157,7 @@ checksum = "5f4f31f56159e98206da9efd823404b79b6ef3143b4a7ab76e67b1751b25a4ab" dependencies = [ "proc-macro2", "quote", - "syn 2.0.43", + "syn 2.0.48", ] [[package]] @@ -10011,7 +10363,7 @@ checksum = "97fee6b57c6a41524a810daee9286c02d7752c4253064d0b05472833a438f675" dependencies = [ "cfg-if", "digest 0.10.7", - "rand 0.8.5", + "rand 0.4.6", "static_assertions", ] @@ -10406,7 +10758,7 @@ dependencies = [ "once_cell", "proc-macro2", "quote", - "syn 2.0.43", + "syn 2.0.48", "wasm-bindgen-shared", ] @@ -10463,7 +10815,7 @@ checksum = "54681b18a46765f095758388f2d0cf16eb8d4169b639ab575a8f5693af210c7b" dependencies = [ "proc-macro2", "quote", - "syn 2.0.43", + "syn 2.0.48", "wasm-bindgen-backend", "wasm-bindgen-shared", ] @@ -11335,7 +11687,7 @@ dependencies = [ "Inflector", "proc-macro2", "quote", - "syn 2.0.43", + "syn 2.0.48", ] [[package]] @@ -11376,7 +11728,7 @@ checksum = "ce36e65b0d2999d2aafac989fb249189a141aee1f53c612c1f37d72631959f69" dependencies = [ "proc-macro2", "quote", - "syn 2.0.43", + "syn 2.0.48", ] [[package]] diff --git a/standalone/replay/src/main.rs b/standalone/replay/src/main.rs index b357117b6f..5693a616e9 100644 --- a/standalone/replay/src/main.rs +++ b/standalone/replay/src/main.rs @@ -4,7 +4,7 @@ mod replay_gk; use clap::Parser; #[derive(Parser, Debug)] -#[clap(about = "The Phala TEE worker app.", version, author)] +#[command(about = "The Phala TEE worker app.", version, author)] pub struct Args { #[arg( default_value = "ws://localhost:9944", diff --git a/standalone/runtime/Cargo.toml b/standalone/runtime/Cargo.toml index e5bc1d2c9e..59e99a8e54 100644 --- a/standalone/runtime/Cargo.toml +++ b/standalone/runtime/Cargo.toml @@ -28,6 +28,7 @@ scale-info = { version = "2.10.0", default-features = false, features = ["derive static_assertions = "1.1.0" hex-literal = "0.4.1" log = { version = "0.4.14", default-features = false } +evm = { version = "0.41.1", default-features = false } phala-types = { path = "../../crates/phala-types", default-features = false } # primitives @@ -112,6 +113,21 @@ rmrk-traits = { git = "https://github.com/Phala-Network/rmrk-substrate", branch pallet-evm_account_mapping = { git = "https://github.com/Phala-Network/substrate-evm_account_mapping", branch = "release-polkadot-v1.5.0", default-features = false } +# Frontier +fp-account = { workspace = true, features = ["serde"] } +fp-evm = { workspace = true, features = ["serde"] } +fp-rpc = { workspace = true } +fp-self-contained = { workspace = true, features = ["serde"] } +# Frontier FRAME +pallet-base-fee = { workspace = true } +pallet-ethereum = { workspace = true } +pallet-evm = { workspace = true } +pallet-evm-precompile-modexp = { workspace = true } +pallet-evm-precompile-sha3fips = { workspace = true } +pallet-evm-precompile-simple = { workspace = true } +pallet-evm-precompile-dispatch = { workspace = true } +pallet-hotfix-sufficients = { workspace = true } + [build-dependencies] substrate-wasm-builder = { git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.5.0", optional = true } @@ -195,6 +211,20 @@ std = [ "pallet-rmrk-core/std", "rmrk-traits/std", "phat-offchain-rollup/std", + # Frontier + "fp-account/std", + "fp-evm/std", + "fp-rpc/std", + "fp-self-contained/std", + # Frontier FRAME + "pallet-base-fee/std", + "pallet-ethereum/std", + "pallet-evm/std", + "pallet-evm-precompile-modexp/std", + "pallet-evm-precompile-sha3fips/std", + "pallet-evm-precompile-simple/std", + "pallet-evm-precompile-dispatch/std", + "pallet-hotfix-sufficients/std", ] runtime-benchmarks = [ "frame-benchmarking/runtime-benchmarks", diff --git a/standalone/runtime/src/evm_support/currency.rs b/standalone/runtime/src/evm_support/currency.rs new file mode 100644 index 0000000000..79271b6175 --- /dev/null +++ b/standalone/runtime/src/evm_support/currency.rs @@ -0,0 +1,273 @@ +use crate::{Authorship, Balances, Runtime, Treasury}; +use frame_support::traits::{fungible::Inspect, Currency, Imbalance, OnUnbalanced}; +use node_primitives::{AccountId, Balance}; +use pallet_balances::{NegativeImbalance, PositiveImbalance}; +use pallet_evm::{EVMCurrencyAdapter, OnChargeEVMTransaction}; + +pub struct EvmCurrency; + +trait BalanceExt { + fn into_eth(self) -> Self; + fn into_sub(self) -> Self; +} + +impl BalanceExt for Balance { + fn into_eth(self) -> Self { + // The wallet UI shows balances in ETH convention, so we need to convert the balances + // 1 ETH = 1_000_000_000_000_000_000 wei + // 1 PHA = 1_000_000_000_000 balances + self.checked_mul(1_000_000).expect("overflowed") + } + + fn into_sub(self) -> Self { + self / 1_000_000 + } +} + +impl BalanceExt for PositiveImbalance { + fn into_eth(self) -> Self { + Self::new(self.peek().into_eth()) + } + + fn into_sub(self) -> Self { + Self::new(self.peek().into_sub()) + } +} + +impl BalanceExt for NegativeImbalance { + fn into_eth(self) -> Self { + Self::new(self.peek().into_eth()) + } + + fn into_sub(self) -> Self { + Self::new(self.peek().into_sub()) + } +} + +pub struct EvmDealWithFees; +impl OnUnbalanced> for EvmDealWithFees { + fn on_nonzero_unbalanced(fee: NegativeImbalance) { + // tip is already transfered to the author in pallet evm + Treasury::on_unbalanced(fee.into_sub()) + } +} + +impl OnChargeEVMTransaction for EvmDealWithFees { + type LiquidityInfo = Option>; + + fn withdraw_fee( + who: &sp_core::H160, + fee: sp_core::U256, + ) -> Result> { + as OnChargeEVMTransaction>::withdraw_fee( + who, fee, + ) + } + + fn correct_and_deposit_fee( + who: &sp_core::H160, + corrected_fee: sp_core::U256, + base_fee: sp_core::U256, + already_withdrawn: Self::LiquidityInfo, + ) -> Self::LiquidityInfo { + as OnChargeEVMTransaction>::correct_and_deposit_fee( + who, + corrected_fee, + base_fee, + already_withdrawn, + ) + } + + fn pay_priority_fee(tip: Self::LiquidityInfo) { + if let Some(tip) = tip { + match Authorship::author() { + Some(author) => { + let _ = EvmCurrency::deposit_creating(&author, tip.peek()); + } + None => Self::on_unbalanced(tip), + } + } + } +} + +impl Currency for EvmCurrency { + type Balance = Balance; + + type PositiveImbalance = PositiveImbalance; + + type NegativeImbalance = NegativeImbalance; + + fn total_balance(who: &AccountId) -> Self::Balance { + >::total_balance(who).into_eth() + } + + fn can_slash(who: &AccountId, value: Self::Balance) -> bool { + >::can_slash(who, value.into_sub()) + } + + fn total_issuance() -> Self::Balance { + >::total_issuance().into_eth() + } + + fn minimum_balance() -> Self::Balance { + >::minimum_balance().into_eth() + } + + fn burn(_amount: Self::Balance) -> Self::PositiveImbalance { + unimplemented!() + } + + fn issue(_amount: Self::Balance) -> Self::NegativeImbalance { + unimplemented!() + } + + fn free_balance(who: &AccountId) -> Self::Balance { + >::free_balance(who).into_eth() + } + + fn ensure_can_withdraw( + who: &AccountId, + amount: Self::Balance, + reasons: frame_support::traits::WithdrawReasons, + new_balance: Self::Balance, + ) -> frame_support::pallet_prelude::DispatchResult { + >::ensure_can_withdraw( + who, + amount.into_sub(), + reasons, + new_balance.into_sub(), + ) + } + + fn transfer( + source: &AccountId, + dest: &AccountId, + value: Self::Balance, + existence_requirement: frame_support::traits::ExistenceRequirement, + ) -> frame_support::pallet_prelude::DispatchResult { + >::transfer( + source, + dest, + value.into_sub(), + existence_requirement, + ) + } + + fn slash(who: &AccountId, value: Self::Balance) -> (Self::NegativeImbalance, Self::Balance) { + let (imbalance, remaining) = + >::slash(who, value.into_sub()); + (imbalance.into_eth(), remaining.into_eth()) + } + + fn deposit_into_existing( + who: &AccountId, + value: Self::Balance, + ) -> Result { + >::deposit_into_existing(who, value.into_sub()) + .map(|im| im.into_eth()) + } + + fn deposit_creating(who: &AccountId, value: Self::Balance) -> Self::PositiveImbalance { + >::deposit_creating(who, value.into_sub()).into_eth() + } + + fn withdraw( + who: &AccountId, + value: Self::Balance, + reasons: frame_support::traits::WithdrawReasons, + liveness: frame_support::traits::ExistenceRequirement, + ) -> Result { + >::withdraw(who, value.into_sub(), reasons, liveness) + .map(|im| im.into_eth()) + } + + fn make_free_balance_be( + _who: &AccountId, + _balance: Self::Balance, + ) -> frame_support::traits::SignedImbalance { + unimplemented!() + } + + fn active_issuance() -> Self::Balance { + >::active_issuance().into_eth() + } + + fn deactivate(amount: Self::Balance) { + >::deactivate(amount.into_sub()) + } + + fn reactivate(amount: Self::Balance) { + >::reactivate(amount.into_sub()) + } + + fn pair(_amount: Self::Balance) -> (Self::PositiveImbalance, Self::NegativeImbalance) { + unimplemented!() + } + + fn resolve_into_existing( + _who: &AccountId, + _value: Self::NegativeImbalance, + ) -> Result<(), Self::NegativeImbalance> { + unimplemented!() + } + + fn resolve_creating(_who: &AccountId, _value: Self::NegativeImbalance) { + unimplemented!() + } + + fn settle( + _who: &AccountId, + _value: Self::PositiveImbalance, + _reasons: frame_support::traits::WithdrawReasons, + _liveness: frame_support::traits::ExistenceRequirement, + ) -> Result<(), Self::PositiveImbalance> { + unimplemented!() + } +} + +impl Inspect for EvmCurrency { + type Balance = Balance; + + fn total_issuance() -> Self::Balance { + >::total_issuance().into_eth() + } + + fn minimum_balance() -> Self::Balance { + >::minimum_balance().into_eth() + } + + fn total_balance(who: &AccountId) -> Self::Balance { + >::total_balance(who).into_eth() + } + + fn balance(who: &AccountId) -> Self::Balance { + >::balance(who).into_eth() + } + + fn reducible_balance( + who: &AccountId, + preservation: frame_support::traits::tokens::Preservation, + force: frame_support::traits::tokens::Fortitude, + ) -> Self::Balance { + >::reducible_balance(who, preservation, force).into_eth() + } + + fn can_deposit( + who: &AccountId, + amount: Self::Balance, + provenance: frame_support::traits::tokens::Provenance, + ) -> frame_support::traits::tokens::DepositConsequence { + >::can_deposit(who, amount.into_sub(), provenance) + } + + fn can_withdraw( + who: &AccountId, + amount: Self::Balance, + ) -> frame_support::traits::tokens::WithdrawConsequence { + >::can_withdraw(who, amount.into_sub()) + } + + fn active_issuance() -> Self::Balance { + >::active_issuance().into_eth() + } +} diff --git a/standalone/runtime/src/evm_support/mod.rs b/standalone/runtime/src/evm_support/mod.rs new file mode 100644 index 0000000000..f8dcc38a28 --- /dev/null +++ b/standalone/runtime/src/evm_support/mod.rs @@ -0,0 +1,7 @@ +pub use currency::{EvmCurrency, EvmDealWithFees}; +pub use precompiles::FrontierPrecompiles; +pub use runner::NoCreateRunner; + +mod currency; +mod precompiles; +mod runner; diff --git a/standalone/runtime/src/evm_support/precompiles.rs b/standalone/runtime/src/evm_support/precompiles.rs new file mode 100644 index 0000000000..7893300288 --- /dev/null +++ b/standalone/runtime/src/evm_support/precompiles.rs @@ -0,0 +1,195 @@ +use frame_support::dispatch::{GetDispatchInfo, PostDispatchInfo}; +use pallet_evm::{ + IsPrecompileResult, Precompile, PrecompileHandle, PrecompileResult, PrecompileSet, +}; +use sp_core::H160; +use sp_runtime::traits::Dispatchable; +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(PhantomData) + } +} + +impl FrontierPrecompiles +where + R: pallet_evm::Config, +{ + pub fn used_addresses() -> [H160; 8] { + [ + hash(1), + hash(2), + hash(3), + hash(4), + hash(5), + hash(1024), + hash(1025), + hash(2048), + ] + } +} +impl PrecompileSet for FrontierPrecompiles +where + R: pallet_evm::Config, + R::RuntimeCall: Dispatchable + GetDispatchInfo, + ::RuntimeOrigin: From>, +{ + fn execute(&self, handle: &mut impl PrecompileHandle) -> Option { + match handle.code_address() { + // Ethereum precompiles : + a if a == hash(1) => Some(ECRecover::execute(handle)), + a if a == hash(2) => Some(Sha256::execute(handle)), + a if a == hash(3) => Some(Ripemd160::execute(handle)), + a if a == hash(4) => Some(Identity::execute(handle)), + a if a == hash(5) => Some(Modexp::execute(handle)), + // Non-Frontier specific nor Ethereum precompiles : + a if a == hash(1024) => Some(Sha3FIPS256::execute(handle)), + a if a == hash(1025) => Some(ECRecoverPublicKey::execute(handle)), + a if a == hash(2048) => Some(substrate_call::Dispatch::::execute(handle)), + _ => None, + } + } + + fn is_precompile(&self, address: H160, _gas: u64) -> IsPrecompileResult { + IsPrecompileResult::Answer { + is_precompile: Self::used_addresses().contains(&address), + extra_cost: 0, + } + } +} + +fn hash(a: u64) -> H160 { + H160::from_low_u64_be(a) +} + +mod substrate_call { + use alloc::format; + use core::marker::PhantomData; + + use codec::{Decode, DecodeLimit}; + // Substrate + use frame_support::{ + dispatch::{DispatchClass, GetDispatchInfo, Pays, PostDispatchInfo}, + traits::{ConstU32, Get}, + }; + use sp_runtime::traits::Dispatchable; + // Frontier + use fp_evm::{ + ExitError, ExitSucceed, Precompile, PrecompileFailure, PrecompileHandle, PrecompileOutput, + PrecompileResult, + }; + use pallet_evm::{AddressMapping, GasWeightMapping}; + + // `DecodeLimit` specifies the max depth a call can use when decoding, as unbounded depth + // can be used to overflow the stack. + // Default value is 8, which is the same as in XCM call decoding. + pub struct Dispatch> { + _marker: PhantomData<(T, DispatchValidator, DecodeLimit)>, + } + + impl Precompile for Dispatch + where + T: pallet_evm::Config, + T::RuntimeCall: Dispatchable + GetDispatchInfo + Decode, + ::RuntimeOrigin: From>, + DispatchValidator: DispatchValidateT, + DecodeLimit: Get, + { + fn execute(handle: &mut impl PrecompileHandle) -> PrecompileResult { + let input = handle.input(); + let target_gas = handle.gas_limit(); + let context = handle.context(); + + let call = T::RuntimeCall::decode_with_depth_limit(DecodeLimit::get(), &mut &*input) + .map_err(|_| PrecompileFailure::Error { + exit_status: ExitError::Other("decode failed".into()), + })?; + let info = call.get_dispatch_info(); + + if let Some(gas) = target_gas { + let valid_weight = T::GasWeightMapping::weight_to_gas(info.weight) <= gas; + if !valid_weight { + return Err(PrecompileFailure::Error { + exit_status: ExitError::OutOfGas, + }); + } + } + + let origin = T::AddressMapping::into_account_id(context.caller); + + if let Some(err) = DispatchValidator::validate_before_dispatch(&origin, &call) { + return Err(err); + } + + handle.record_external_cost( + Some(info.weight.ref_time()), + Some(info.weight.proof_size()), + None, + )?; + match call.dispatch(Some(origin).into()) { + Ok(post_info) => { + if post_info.pays_fee(&info) == Pays::Yes { + let actual_weight = post_info.actual_weight.unwrap_or(info.weight); + let cost = T::GasWeightMapping::weight_to_gas(actual_weight); + handle.refund_external_cost( + Some( + info.weight + .ref_time() + .saturating_sub(actual_weight.ref_time()), + ), + Some( + info.weight + .proof_size() + .saturating_sub(actual_weight.proof_size()), + ), + ); + handle.record_cost(cost)?; + } + + Ok(PrecompileOutput { + exit_status: ExitSucceed::Stopped, + output: Default::default(), + }) + } + Err(e) => Err(PrecompileFailure::Error { + exit_status: ExitError::Other( + format!("dispatch execution failed: {}", <&'static str>::from(e)).into(), + ), + }), + } + } + } + + /// Dispatch validation trait. + pub trait DispatchValidateT { + fn validate_before_dispatch( + origin: &AccountId, + call: &RuntimeCall, + ) -> Option; + } + + /// The default implementation of `DispatchValidateT`. + impl DispatchValidateT for () + where + RuntimeCall: GetDispatchInfo, + { + fn validate_before_dispatch( + _origin: &AccountId, + call: &RuntimeCall, + ) -> Option { + let info = call.get_dispatch_info(); + if !(info.pays_fee == Pays::Yes && info.class == DispatchClass::Normal) { + return Some(PrecompileFailure::Error { + exit_status: ExitError::Other("invalid call".into()), + }); + } + None + } + } +} diff --git a/standalone/runtime/src/evm_support/runner.rs b/standalone/runtime/src/evm_support/runner.rs new file mode 100644 index 0000000000..7bcb1a774d --- /dev/null +++ b/standalone/runtime/src/evm_support/runner.rs @@ -0,0 +1,123 @@ +use pallet_evm::{ + runner::stack::Runner as EvmRunner, BalanceOf, Config as EvmConfig, Error as EvmError, +}; +use sp_core::{H160, U256}; +use alloc::vec::Vec; + +pub struct NoCreateRunner(core::marker::PhantomData); + +impl pallet_evm::Runner for NoCreateRunner +where + BalanceOf: TryFrom + Into, +{ + type Error = EvmError; + + fn validate( + source: H160, + target: Option, + input: Vec, + value: U256, + gas_limit: u64, + max_fee_per_gas: Option, + max_priority_fee_per_gas: Option, + nonce: Option, + access_list: Vec<(H160, Vec)>, + is_transactional: bool, + weight_limit: Option, + proof_size_base_cost: Option, + evm_config: &evm::Config, + ) -> Result<(), pallet_evm::RunnerError> { + EvmRunner::::validate( + source, + target, + input, + value, + gas_limit, + max_fee_per_gas, + max_priority_fee_per_gas, + nonce, + access_list, + is_transactional, + weight_limit, + proof_size_base_cost, + evm_config, + ) + } + + fn call( + source: H160, + target: H160, + input: Vec, + value: U256, + gas_limit: u64, + max_fee_per_gas: Option, + max_priority_fee_per_gas: Option, + nonce: Option, + access_list: Vec<(H160, Vec)>, + is_transactional: bool, + validate: bool, + weight_limit: Option, + proof_size_base_cost: Option, + config: &evm::Config, + ) -> Result> { + EvmRunner::::call( + source, + target, + input, + value, + gas_limit, + max_fee_per_gas, + max_priority_fee_per_gas, + nonce, + access_list, + is_transactional, + validate, + weight_limit, + proof_size_base_cost, + config, + ) + } + + fn create( + _source: H160, + _init: Vec, + _value: U256, + _gas_limit: u64, + _max_fee_per_gas: Option, + _max_priority_fee_per_gas: Option, + _nonce: Option, + _access_list: Vec<(H160, Vec)>, + _is_transactional: bool, + _validate: bool, + _weight_limit: Option, + _proof_size_base_cost: Option, + _config: &evm::Config, + ) -> Result> { + Err(pallet_evm::RunnerError { + error: EvmError::Undefined, + weight: Default::default(), + }) + } + + fn create2( + _source: H160, + _init: Vec, + _salt: sp_core::H256, + _value: U256, + _gas_limit: u64, + _max_fee_per_gas: Option, + _max_priority_fee_per_gas: Option, + _nonce: Option, + _access_list: Vec<(H160, Vec)>, + _is_transactional: bool, + _validate: bool, + _weight_limit: Option, + _proof_size_base_cost: Option, + _config: &evm::Config, + ) -> Result> { + Err(pallet_evm::RunnerError { + error: EvmError::Undefined, + weight: Default::default(), + }) + } +} diff --git a/standalone/runtime/src/lib.rs b/standalone/runtime/src/lib.rs index 1c2d161675..e51166bc09 100644 --- a/standalone/runtime/src/lib.rs +++ b/standalone/runtime/src/lib.rs @@ -23,6 +23,9 @@ #![recursion_limit = "1024"] #![allow(clippy::identity_op)] +#[macro_use] +extern crate alloc; + mod msg_routing; use codec::{Decode, Encode, MaxEncodedLen}; @@ -39,8 +42,8 @@ use frame_support::{ fungible::HoldConsideration, tokens::{PayFromAccount, UnityAssetBalanceConversion}, AsEnsureOriginWithArg, ConstU128, ConstU32, Currency, EitherOfDiverse, EqualPrivilegeOnly, - Everything, Imbalance, InstanceFilter, KeyOwnerProofSystem, LockIdentifier, OnUnbalanced, - SortedMembers, WithdrawReasons, LinearStoragePrice, + Everything, FindAuthor, Imbalance, InstanceFilter, KeyOwnerProofSystem, LinearStoragePrice, + LockIdentifier, OnFinalize, OnUnbalanced, SortedMembers, WithdrawReasons, }, weights::{ constants::{ @@ -48,7 +51,7 @@ use frame_support::{ }, IdentityFee, Weight, }, - PalletId, + ConsensusEngineId, PalletId, }; use frame_system::{ limits::{BlockLength, BlockWeights}, @@ -65,17 +68,20 @@ use pallet_transaction_payment::{FeeDetails, RuntimeDispatchInfo}; use sp_api::impl_runtime_apis; use sp_authority_discovery::AuthorityId as AuthorityDiscoveryId; use sp_consensus_grandpa::AuthorityId as GrandpaId; -use sp_core::{crypto::KeyTypeId, OpaqueMetadata}; +use sp_core::{crypto::KeyTypeId, OpaqueMetadata, H160, H256, U256}; use sp_inherents::{CheckInherentsResult, InherentData}; use sp_runtime::{ create_runtime_str, curve::PiecewiseLinear, generic, impl_opaque_keys, traits::{ - self, BlakeTwo256, Block as BlockT, Bounded, ConvertInto, NumberFor, OpaqueKeys, - SaturatedConversion, StaticLookup, TrailingZeroInput, + self, BlakeTwo256, Block as BlockT, Bounded, ConvertInto, DispatchInfoOf, Dispatchable, + NumberFor, OpaqueKeys, PostDispatchInfoOf, SaturatedConversion, StaticLookup, + TrailingZeroInput, UniqueSaturatedInto, + }, + transaction_validity::{ + TransactionPriority, TransactionSource, TransactionValidity, TransactionValidityError, }, - transaction_validity::{TransactionPriority, TransactionSource, TransactionValidity}, AccountId32, ApplyExtrinsicResult, FixedPointNumber, FixedU128, Perbill, Percent, Permill, Perquintill, RuntimeDebug, }; @@ -107,7 +113,6 @@ use sp_runtime::generic::Era; /// Generated voter bag information. mod voter_bags; - pub use phala_pallets::{ pallet_base_pool, pallet_computation, pallet_mq, pallet_phat, pallet_phat_tokenomic, pallet_registry, pallet_stake_pool, pallet_stake_pool_v2, pallet_vault, @@ -115,6 +120,18 @@ pub use phala_pallets::{ }; use phat_offchain_rollup::{anchor as pallet_anchor, oracle as pallet_oracle}; +// Frontier +use fp_evm::weight_per_gas; +use fp_rpc::TransactionStatus; +use pallet_ethereum::{ + Call::transact, PostLogContent, Transaction as EthereumTransaction, TransactionAction, + TransactionData, +}; +use pallet_evm::{Account as EVMAccount, FeeCalculator, Runner}; + +use evm_support::{EvmCurrency, EvmDealWithFees, FrontierPrecompiles, NoCreateRunner}; +mod evm_support; + // Make the WASM binary available. #[cfg(all(feature = "std", feature = "include-wasm"))] include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs")); @@ -122,7 +139,7 @@ include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs")); /// Max size for serialized extrinsic params for this testing runtime. /// This is a quite arbitrary but empirically battle tested value. #[cfg(test)] -pub const CALL_PARAMS_MAX_SIZE: usize = 300; +pub const CALL_PARAMS_MAX_SIZE: usize = 512; /// Wasm binary unwrapped. If built with `SKIP_WASM_BUILD`, the function panics. #[cfg(all(feature = "std", feature = "include-wasm"))] @@ -144,7 +161,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion { // and set impl_version to 0. If only runtime // implementation changes and behavior does not, then leave spec_version as // is and increment impl_version. - spec_version: 101, + spec_version: 102, impl_version: 0, apis: RUNTIME_API_VERSIONS, transaction_version: 1, @@ -194,6 +211,7 @@ const NORMAL_DISPATCH_RATIO: Perbill = Perbill::from_percent(75); /// We allow for 2 seconds of compute with a 6 second average block time, with maximum proof size. const MAXIMUM_BLOCK_WEIGHT: Weight = Weight::from_parts(WEIGHT_REF_TIME_PER_SECOND.saturating_mul(2), u64::MAX); +pub const WEIGHT_MILLISECS_PER_BLOCK: u64 = 2000; parameter_types! { pub const BlockHashCount: BlockNumber = 2400; @@ -337,8 +355,9 @@ impl InstanceFilter for ProxyType { | RuntimeCall::Elections(..) | RuntimeCall::Treasury(..) ), - ProxyType::Staking => - matches!(c, RuntimeCall::Staking(..) | RuntimeCall::FastUnstake(..)), + ProxyType::Staking => { + matches!(c, RuntimeCall::Staking(..) | RuntimeCall::FastUnstake(..)) + } ProxyType::StakePoolManager => matches!( c, RuntimeCall::Utility { .. } @@ -450,7 +469,7 @@ impl pallet_babe::Config for Runtime { type KeyOwnerProof = >::Proof; type EquivocationReportSystem = - pallet_babe::EquivocationReportSystem; + pallet_babe::EquivocationReportSystem; } parameter_types! { @@ -713,13 +732,16 @@ impl Get> for OffchainRandomBalancing { max => { let seed = sp_io::offchain::random_seed(); let random = ::decode(&mut TrailingZeroInput::new(&seed)) - .expect("input is padded with zeroes; qed") % - max.saturating_add(1); + .expect("input is padded with zeroes; qed") + % max.saturating_add(1); random as usize - }, + } }; - let config = BalancingConfig { iterations, tolerance: 0 }; + let config = BalancingConfig { + iterations, + tolerance: 0, + }; Some(config) } } @@ -1212,7 +1234,7 @@ impl pallet_grandpa::Config for Runtime { type MaxSetIdSessionEntries = MaxSetIdSessionEntries; type KeyOwnerProof = >::Proof; type EquivocationReportSystem = - pallet_grandpa::EquivocationReportSystem; + pallet_grandpa::EquivocationReportSystem; } parameter_types! { @@ -1280,7 +1302,7 @@ impl pallet_society::Config for Runtime { type ClaimPeriod = ClaimPeriod; type MaxLockDuration = MaxLockDuration; type FounderSetOrigin = - pallet_collective::EnsureProportionMoreThan; + pallet_collective::EnsureProportionMoreThan; type ChallengePeriod = ChallengePeriod; type MaxPayouts = MaxPayouts; type MaxBids = MaxBids; @@ -1573,6 +1595,136 @@ impl pallet_evm_account_mapping::Config for Runtime { type WeightInfo = pallet_evm_account_mapping::weights::SubstrateWeight; } +pub struct FindAuthorTruncated; +impl FindAuthor for FindAuthorTruncated { + fn find_author<'a, I>(_digests: I) -> Option + where + I: 'a + IntoIterator, + { + let author = Authorship::author()?; + let raw_auth_id: &[u8] = author.as_ref(); + Some(H160::from_slice(&raw_auth_id[..20])) + } +} + +const BLOCK_GAS_LIMIT: u64 = 75_000_000; +const MAX_POV_SIZE: u64 = 5 * 1024 * 1024; + +parameter_types! { + pub BlockGasLimit: U256 = U256::from(BLOCK_GAS_LIMIT); + pub const GasLimitPovSizeRatio: u64 = BLOCK_GAS_LIMIT.saturating_div(MAX_POV_SIZE); + pub PrecompilesValue: FrontierPrecompiles = Default::default(); + pub WeightPerGas: Weight = Weight::from_parts(weight_per_gas(BLOCK_GAS_LIMIT, NORMAL_DISPATCH_RATIO, WEIGHT_MILLISECS_PER_BLOCK), 0); + pub SuicideQuickClearLimit: u32 = 0; +} + +pub struct EnsureOrigin; +impl pallet_evm::EnsureAddressOrigin for EnsureOrigin { + type Success = AccountId; + fn try_address_origin( + address: &H160, + origin: RuntimeOrigin, + ) -> Result { + use pallet_ethereum::RawOrigin::EthereumTransaction; + let OriginCaller::Ethereum(EthereumTransaction(inner_origin)) = origin.caller else { + return Err(origin); + }; + if address != &inner_origin { + return Err(origin); + } + Ok(PostfixAddressMapping::map(inner_origin)) + } +} + +pub struct PostfixAddressMapping; +impl PostfixAddressMapping { + fn map(address: H160) -> AccountId { + let mut account_id = [0u8; 32]; + account_id[..20].copy_from_slice(&address[..]); + account_id[20..].copy_from_slice(b"@evm_address"); + account_id.into() + } +} + +impl pallet_evm::AddressMapping for PostfixAddressMapping { + fn into_account_id(address: H160) -> AccountId { + Self::map(address) + } +} + +parameter_types! { + pub const EVMChainId: u64 = 12035; +} + +impl pallet_evm::Config for Runtime { + type FeeCalculator = BaseFee; + type GasWeightMapping = pallet_evm::FixedGasWeightMapping; + type WeightPerGas = WeightPerGas; + type BlockHashMapping = pallet_ethereum::EthereumBlockHashMapping; + type CallOrigin = EnsureOrigin; + type WithdrawOrigin = EnsureOrigin; + type AddressMapping = PostfixAddressMapping; + type Currency = EvmCurrency; + type RuntimeEvent = RuntimeEvent; + type PrecompilesType = FrontierPrecompiles; + type PrecompilesValue = PrecompilesValue; + type ChainId = EVMChainId; + type BlockGasLimit = BlockGasLimit; + type Runner = NoCreateRunner; + type OnChargeTransaction = EvmDealWithFees; + type OnCreate = (); + type FindAuthor = FindAuthorTruncated; + type GasLimitPovSizeRatio = GasLimitPovSizeRatio; + type SuicideQuickClearLimit = SuicideQuickClearLimit; + type Timestamp = Timestamp; + type WeightInfo = pallet_evm::weights::SubstrateWeight; +} + +parameter_types! { + pub const PostBlockAndTxnHashes: PostLogContent = PostLogContent::BlockAndTxnHashes; +} + +impl pallet_ethereum::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type StateRoot = pallet_ethereum::IntermediateStateRoot; + type PostLogContent = PostBlockAndTxnHashes; + type ExtraDataLength = ConstU32<30>; +} + +parameter_types! { + pub BoundDivision: U256 = U256::from(1024); +} + +parameter_types! { + pub DefaultBaseFeePerGas: U256 = 100_000_000_000_u64.into(); + pub DefaultElasticity: Permill = Permill::zero(); +} + +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 RuntimeEvent = RuntimeEvent; + type Threshold = BaseFeeThreshold; + type DefaultBaseFeePerGas = DefaultBaseFeePerGas; + type DefaultElasticity = DefaultElasticity; +} + +impl pallet_hotfix_sufficients::Config for Runtime { + type AddressMapping = PostfixAddressMapping; + type WeightInfo = pallet_hotfix_sufficients::weights::SubstrateWeight; +} + construct_runtime!( pub struct Runtime { Assets: pallet_assets, @@ -1640,6 +1792,12 @@ construct_runtime!( RmrkCore: pallet_rmrk_core::{Pallet, Call, Event}, EvmAccountMapping: pallet_evm_account_mapping, + + // Frontier + Ethereum: pallet_ethereum, + EVM: pallet_evm, + BaseFee: pallet_base_fee, + HotfixSufficients: pallet_hotfix_sufficients, } ); @@ -1669,13 +1827,8 @@ pub type SignedExtra = ( pallet_mq::CheckMqSequence, pallet_transaction_payment::ChargeTransactionPayment, ); -/// Unchecked extrinsic type as expected by this runtime. -pub type UncheckedExtrinsic = - generic::UncheckedExtrinsic; /// The payload being signed in transactions. pub type SignedPayload = generic::SignedPayload; -/// Extrinsic type that has already been checked. -pub type CheckedExtrinsic = generic::CheckedExtrinsic; /// Executive: handles dispatch to the various modules. pub type Executive = frame_executive::Executive< Runtime, @@ -1686,6 +1839,96 @@ pub type Executive = frame_executive::Executive< Migrations, >; +#[derive(Clone)] +pub struct TransactionConverter; + +impl fp_rpc::ConvertTransaction for TransactionConverter { + fn convert_transaction(&self, transaction: pallet_ethereum::Transaction) -> UncheckedExtrinsic { + UncheckedExtrinsic::new_unsigned( + pallet_ethereum::Call::::transact { transaction }.into(), + ) + } +} + +impl fp_rpc::ConvertTransaction for TransactionConverter { + fn convert_transaction( + &self, + transaction: pallet_ethereum::Transaction, + ) -> sp_runtime::OpaqueExtrinsic { + let extrinsic = UncheckedExtrinsic::new_unsigned( + pallet_ethereum::Call::::transact { transaction }.into(), + ); + let encoded = extrinsic.encode(); + sp_runtime::OpaqueExtrinsic::decode(&mut &encoded[..]) + .expect("Encoded extrinsic is always valid") + } +} + +/// Unchecked extrinsic type as expected by this runtime. +pub type UncheckedExtrinsic = + fp_self_contained::UncheckedExtrinsic; +/// Extrinsic type that has already been checked. +pub type CheckedExtrinsic = + fp_self_contained::CheckedExtrinsic; + +impl fp_self_contained::SelfContainedCall for RuntimeCall { + type SignedInfo = H160; + + fn is_self_contained(&self) -> bool { + match self { + RuntimeCall::Ethereum(call) => call.is_self_contained(), + _ => false, + } + } + + fn check_self_contained(&self) -> Option> { + match self { + RuntimeCall::Ethereum(call) => call.check_self_contained(), + _ => None, + } + } + + fn validate_self_contained( + &self, + info: &Self::SignedInfo, + dispatch_info: &DispatchInfoOf, + len: usize, + ) -> Option { + match self { + RuntimeCall::Ethereum(call) => call.validate_self_contained(info, dispatch_info, len), + _ => None, + } + } + + fn pre_dispatch_self_contained( + &self, + info: &Self::SignedInfo, + dispatch_info: &DispatchInfoOf, + len: usize, + ) -> Option> { + match self { + RuntimeCall::Ethereum(call) => { + call.pre_dispatch_self_contained(info, dispatch_info, len) + } + _ => None, + } + } + + fn apply_self_contained( + self, + info: Self::SignedInfo, + ) -> Option>> { + match self { + call @ RuntimeCall::Ethereum(pallet_ethereum::Call::transact { .. }) => { + Some(call.dispatch(RuntimeOrigin::from( + pallet_ethereum::RawOrigin::EthereumTransaction(info), + ))) + } + _ => None, + } + } +} + // All migrations executed on runtime upgrade as a nested tuple of types implementing // `OnRuntimeUpgrade`. type Migrations = (); @@ -1948,6 +2191,201 @@ impl_runtime_apis! { Executive::try_execute_block(block, state_root_check, signature_check, select).unwrap() } } + + impl fp_rpc::EthereumRuntimeRPCApi for Runtime { + fn chain_id() -> u64 { + ::ChainId::get() + } + + fn account_basic(address: H160) -> EVMAccount { + let (account, _) = pallet_evm::Pallet::::account_basic(&address); + account + } + + fn gas_price() -> U256 { + let (gas_price, _) = ::FeeCalculator::min_gas_price(); + gas_price + } + + fn account_code_at(address: H160) -> Vec { + pallet_evm::AccountCodes::::get(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); + pallet_evm::AccountStorages::::get(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; + Some(config) + } else { + None + }; + + let gas_limit = gas_limit.min(u64::MAX.into()); + let transaction_data = TransactionData::new( + TransactionAction::Call(to), + data.clone(), + nonce.unwrap_or_default(), + gas_limit, + None, + max_fee_per_gas, + max_priority_fee_per_gas, + value, + Some(::ChainId::get()), + access_list.clone().unwrap_or_default(), + ); + let (weight_limit, proof_size_base_cost) = pallet_ethereum::Pallet::::transaction_weight(&transaction_data); + + ::Runner::call( + from, + to, + data, + value, + gas_limit.unique_saturated_into(), + max_fee_per_gas, + max_priority_fee_per_gas, + nonce, + access_list.unwrap_or_default(), + false, + true, + weight_limit, + proof_size_base_cost, + config.as_ref().unwrap_or(::config()), + ).map_err(|err| err.error.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; + Some(config) + } else { + None + }; + + let transaction_data = TransactionData::new( + TransactionAction::Create, + data.clone(), + nonce.unwrap_or_default(), + gas_limit, + None, + max_fee_per_gas, + max_priority_fee_per_gas, + value, + Some(::ChainId::get()), + access_list.clone().unwrap_or_default(), + ); + let (weight_limit, proof_size_base_cost) = pallet_ethereum::Pallet::::transaction_weight(&transaction_data); + + ::Runner::create( + from, + data, + value, + gas_limit.unique_saturated_into(), + max_fee_per_gas, + max_priority_fee_per_gas, + nonce, + access_list.unwrap_or_default(), + false, + true, + weight_limit, + proof_size_base_cost, + config.as_ref().unwrap_or(::config()), + ).map_err(|err| err.error.into()) + } + + fn current_transaction_statuses() -> Option> { + pallet_ethereum::CurrentTransactionStatuses::::get() + } + + fn current_block() -> Option { + pallet_ethereum::CurrentBlock::::get() + } + + fn current_receipts() -> Option> { + pallet_ethereum::CurrentReceipts::::get() + } + + fn current_all() -> ( + Option, + Option>, + Option> + ) { + ( + pallet_ethereum::CurrentBlock::::get(), + pallet_ethereum::CurrentReceipts::::get(), + pallet_ethereum::CurrentTransactionStatuses::::get() + ) + } + + fn extrinsic_filter( + xts: Vec<::Extrinsic>, + ) -> Vec { + xts.into_iter().filter_map(|xt| match xt.0.function { + RuntimeCall::Ethereum(transact { transaction }) => Some(transaction), + _ => None + }).collect::>() + } + + fn elasticity() -> Option { + Some(pallet_base_fee::Elasticity::::get()) + } + + fn gas_limit_multiplier_support() {} + + fn pending_block( + xts: Vec<::Extrinsic>, + ) -> (Option, Option>) { + for ext in xts.into_iter() { + let _ = Executive::apply_extrinsic(ext); + } + + Ethereum::on_finalize(System::block_number() + 1); + + ( + pallet_ethereum::CurrentBlock::::get(), + pallet_ethereum::CurrentTransactionStatuses::::get() + ) + } + } + + impl fp_rpc::ConvertTransactionRuntimeApi for Runtime { + fn convert_transaction(transaction: EthereumTransaction) -> ::Extrinsic { + UncheckedExtrinsic::new_unsigned( + pallet_ethereum::Call::::transact { transaction }.into(), + ) + } + } } #[cfg(test)] diff --git a/standalone/sfq-test/src/main.rs b/standalone/sfq-test/src/main.rs index c5d38e617b..889db2dbbd 100644 --- a/standalone/sfq-test/src/main.rs +++ b/standalone/sfq-test/src/main.rs @@ -9,7 +9,7 @@ use rocket::response::status::Custom; use rocket::{get, launch, routes, State}; #[derive(Parser, Debug)] -#[clap(about = "SFQ test server", version, author)] +#[command(about = "SFQ test server", version, author)] pub struct Args { #[arg(short, long, default_value = "32")] backlog: usize,