From 28db256e2571de8b53ed308e7a92762367a67ad3 Mon Sep 17 00:00:00 2001 From: Xavier Lau Date: Mon, 21 Nov 2022 13:42:23 +0800 Subject: [PATCH] Process system and balances state (#39) * Process state part.1 * More detail * Take storages * Take KV * Merge balances * Extract balance lock * Format * Flatten account * Preprocess storage key * Fix properties * Add shell config * Modularize processor * Calculate total issuance * Recover nonce --- .gitignore | 2 +- Cargo.lock | 198 ++++--- node/src/chain_spec.rs | 70 ++- node/src/command.rs | 1 + tool/state-processor/Cargo.lock | 628 ++++++++++++++++++++++ tool/state-processor/Cargo.toml | 24 + tool/state-processor/src/balances/mod.rs | 37 ++ tool/state-processor/src/main.rs | 192 +++++++ tool/state-processor/src/system/mod.rs | 200 +++++++ tool/state-processor/src/type_registry.rs | 34 ++ 10 files changed, 1304 insertions(+), 82 deletions(-) create mode 100644 tool/state-processor/Cargo.lock create mode 100644 tool/state-processor/Cargo.toml create mode 100644 tool/state-processor/src/balances/mod.rs create mode 100644 tool/state-processor/src/main.rs create mode 100644 tool/state-processor/src/system/mod.rs create mode 100644 tool/state-processor/src/type_registry.rs diff --git a/.gitignore b/.gitignore index fa143606b..a9a20e83c 100644 --- a/.gitignore +++ b/.gitignore @@ -7,7 +7,7 @@ # Package Manager ## cargo -/target +target ## npm node_modules diff --git a/Cargo.lock b/Cargo.lock index 0b887893c..de80273b5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -123,9 +123,9 @@ dependencies = [ [[package]] name = "array-bytes" -version = "4.1.0" +version = "4.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6a913633b0c922e6b745072795f50d90ebea78ba31a57e2ac8c2fc7b50950949" +checksum = "f52f63c5c1316a16a4b35eaac8b76a98248961a533f061684cb2a7cb0eafb6c6" [[package]] name = "arrayref" @@ -182,22 +182,22 @@ version = "1.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e14485364214912d3b19cc3435dde4df66065127f05fa0d75c712f36f12c2f28" dependencies = [ - "concurrent-queue", + "concurrent-queue 1.2.4", "event-listener", "futures-core", ] [[package]] name = "async-executor" -version = "1.4.1" +version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "871f9bb5e0a22eeb7e8cf16641feb87c9dc67032ccf8ff49e772eb9941d3a965" +checksum = "17adb73da160dfb475c183343c8cccd80721ea5a605d3eb57125f0a7b7a92d0b" dependencies = [ + "async-lock", "async-task", - "concurrent-queue", + "concurrent-queue 2.0.0", "fastrand", "futures-lite", - "once_cell", "slab", ] @@ -224,7 +224,7 @@ checksum = "e8121296a9f05be7f34aa4196b1747243b3b62e048bb7906f644f3fbfc490cf7" dependencies = [ "async-lock", "autocfg", - "concurrent-queue", + "concurrent-queue 1.2.4", "futures-lite", "libc", "log", @@ -574,9 +574,9 @@ dependencies = [ [[package]] name = "blake2" -version = "0.10.4" +version = "0.10.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b9cf849ee05b2ee5fba5e36f97ff8ec2533916700fc0758d40d92136a42f3388" +checksum = "b12e5fd123190ce1c2e559308a94c9bacad77907d4c6005d9e58fe1a0689e55e" dependencies = [ "digest 0.10.5", ] @@ -942,9 +942,9 @@ dependencies = [ [[package]] name = "cc" -version = "1.0.75" +version = "1.0.76" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "41ca34107f97baef6cfb231b32f36115781856b8f8208e8c580e0bcaea374842" +checksum = "76a284da2e6fe2092f2353e51713435363112dfd60030e22add80be333fb928f" dependencies = [ "jobserver", ] @@ -1012,9 +1012,9 @@ dependencies = [ [[package]] name = "chrono" -version = "0.4.22" +version = "0.4.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bfd4d1b31faaa3a89d7934dbded3111da0d2ef28e3ebccdb4f0179f5929d1ef1" +checksum = "16b0a3d9ed01224b22057780a37bb8c5dbfe1be8ba48678e7bf57ec4b385411f" dependencies = [ "iana-time-zone", "js-sys", @@ -1167,6 +1167,15 @@ dependencies = [ "cache-padded", ] +[[package]] +name = "concurrent-queue" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bd7bef69dc86e3c610e4e7aed41035e2a7ed12e72dd7530f61327a6579a4390b" +dependencies = [ + "crossbeam-utils", +] + [[package]] name = "const-oid" version = "0.7.1" @@ -1230,18 +1239,18 @@ dependencies = [ [[package]] name = "cranelift-bforest" -version = "0.88.1" +version = "0.88.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "44409ccf2d0f663920cab563d2b79fcd6b2e9a2bcc6e929fef76c8f82ad6c17a" +checksum = "52056f6d0584484b57fa6c1a65c1fcb15f3780d8b6a758426d9e3084169b2ddd" dependencies = [ "cranelift-entity", ] [[package]] name = "cranelift-codegen" -version = "0.88.1" +version = "0.88.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "98de2018ad96eb97f621f7d6b900a0cc661aec8d02ea4a50e56ecb48e5a2fcaf" +checksum = "18fed94c8770dc25d01154c3ffa64ed0b3ba9d583736f305fed7beebe5d9cf74" dependencies = [ "arrayvec 0.7.2", "bumpalo", @@ -1259,33 +1268,33 @@ dependencies = [ [[package]] name = "cranelift-codegen-meta" -version = "0.88.1" +version = "0.88.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5287ce36e6c4758fbaf298bd1a8697ad97a4f2375a3d1b61142ea538db4877e5" +checksum = "1c451b81faf237d11c7e4f3165eeb6bac61112762c5cfe7b4c0fb7241474358f" dependencies = [ "cranelift-codegen-shared", ] [[package]] name = "cranelift-codegen-shared" -version = "0.88.1" +version = "0.88.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2855c24219e2f08827f3f4ffb2da92e134ae8d8ecc185b11ec8f9878cf5f588e" +checksum = "e7c940133198426d26128f08be2b40b0bd117b84771fd36798969c4d712d81fc" [[package]] name = "cranelift-entity" -version = "0.88.1" +version = "0.88.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b65673279d75d34bf11af9660ae2dbd1c22e6d28f163f5c72f4e1dc56d56103" +checksum = "87a0f1b2fdc18776956370cf8d9b009ded3f855350c480c1c52142510961f352" dependencies = [ "serde", ] [[package]] name = "cranelift-frontend" -version = "0.88.1" +version = "0.88.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3ed2b3d7a4751163f6c4a349205ab1b7d9c00eecf19dcea48592ef1f7688eefc" +checksum = "34897538b36b216cc8dd324e73263596d51b8cf610da6498322838b2546baf8a" dependencies = [ "cranelift-codegen", "log", @@ -1295,15 +1304,15 @@ dependencies = [ [[package]] name = "cranelift-isle" -version = "0.88.1" +version = "0.88.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3be64cecea9d90105fc6a2ba2d003e98c867c1d6c4c86cc878f97ad9fb916293" +checksum = "1b2629a569fae540f16a76b70afcc87ad7decb38dc28fa6c648ac73b51e78470" [[package]] name = "cranelift-native" -version = "0.88.1" +version = "0.88.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c4a03a6ac1b063e416ca4b93f6247978c991475e8271465340caa6f92f3c16a4" +checksum = "20937dab4e14d3e225c5adfc9c7106bafd4ac669bdb43027b911ff794c6fb318" dependencies = [ "cranelift-codegen", "libc", @@ -1312,9 +1321,9 @@ dependencies = [ [[package]] name = "cranelift-wasm" -version = "0.88.1" +version = "0.88.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c699873f7b30bc5f20dd03a796b4183e073a46616c91704792ec35e45d13f913" +checksum = "80fc2288957a94fd342a015811479de1837850924166d1f1856d8406e6f3609b" dependencies = [ "cranelift-codegen", "cranelift-entity", @@ -3760,9 +3769,9 @@ dependencies = [ [[package]] name = "hyper-rustls" -version = "0.23.0" +version = "0.23.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d87c48c02e0dc5e3b849a2041db3029fd066650f8f717c07bf8ed78ccb895cac" +checksum = "59df7c4e19c950e6e0e868dcc0a300b09a9b88e9ec55bd879ca819087a77355d" dependencies = [ "http", "hyper", @@ -3934,6 +3943,16 @@ version = "0.7.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "59ce5ef949d49ee85593fc4d3f3f95ad61657076395cbbce23e2121fc5542074" +[[package]] +name = "io-lifetimes" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a7d367024b3f3414d8e01f437f704f41a9f64ab36f9067fa73e526ad4c763c87" +dependencies = [ + "libc", + "windows-sys 0.42.0", +] + [[package]] name = "ip_network" version = "0.4.1" @@ -3942,9 +3961,9 @@ checksum = "aa2f047c0a98b2f299aa5d6d7088443570faae494e9ae1305e48be000c9e0eb1" [[package]] name = "ipconfig" -version = "0.3.0" +version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "723519edce41262b05d4143ceb95050e4c614f483e78e9fd9e39a8275a84ad98" +checksum = "bd302af1b90f2463a98fa5ad469fc212c8e3175a41c3068601bfa2727591c5be" dependencies = [ "socket2", "widestring", @@ -4149,9 +4168,12 @@ dependencies = [ [[package]] name = "keccak" -version = "0.1.2" +version = "0.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f9b7d56ba4a8344d6be9729995e6b06f928af29998cdf79fe390cbf6b1fee838" +checksum = "3afef3b6eff9ce9d8ff9b3601125eec7f0c8cbac7abd14f355d053fa56c98768" +dependencies = [ + "cpufeatures", +] [[package]] name = "kusama-runtime" @@ -4350,9 +4372,9 @@ dependencies = [ [[package]] name = "libm" -version = "0.2.5" +version = "0.2.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "292a948cd991e376cf75541fe5b97a1081d713c618b4f1b9500f8844e49eb565" +checksum = "348108ab3fba42ec82ff6e9564fc4ca0247bdccdc68dd8af9764bbc79c3c8ffb" [[package]] name = "libp2p" @@ -4983,6 +5005,12 @@ version = "0.0.46" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d4d2456c373231a208ad294c33dc5bff30051eafd954cd4caae83a712b12854d" +[[package]] +name = "linux-raw-sys" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bb68f22743a3fb35785f1e7f844ca5a3de2dde5bd0c0ef5b372065814699b121" + [[package]] name = "lock_api" version = "0.4.9" @@ -5097,18 +5125,18 @@ checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d" [[package]] name = "memfd" -version = "0.6.1" +version = "0.6.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "480b5a5de855d11ff13195950bdc8b98b5e942ef47afc447f6615cdcc4e15d80" +checksum = "b20a59d985586e4a5aef64564ac77299f8586d8be6cf9106a5a40207e8908efb" dependencies = [ - "rustix", + "rustix 0.36.1", ] [[package]] name = "memmap2" -version = "0.5.7" +version = "0.5.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "95af15f345b17af2efc8ead6080fb8bc376f8cec1b35277b935637595fe77498" +checksum = "4b182332558b18d807c4ce1ca8ca983b34c3ee32765e47b3f0f69b90355cc1dc" dependencies = [ "libc", ] @@ -5639,9 +5667,9 @@ dependencies = [ [[package]] name = "os_str_bytes" -version = "6.3.1" +version = "6.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3baf96e39c5359d2eb0dd6ccb42c62b91d9678aa68160d261b9e0ccbf9e9dea9" +checksum = "7b5bf27447411e9ee3ff51186bf7a08e16c341efdde93f4d823e8844429bed7e" [[package]] name = "owning_ref" @@ -8990,9 +9018,23 @@ checksum = "727a1a6d65f786ec22df8a81ca3121107f235970dc1705ed681d3e6e8b9cd5f9" dependencies = [ "bitflags", "errno", - "io-lifetimes", + "io-lifetimes 0.7.5", + "libc", + "linux-raw-sys 0.0.46", + "windows-sys 0.42.0", +] + +[[package]] +name = "rustix" +version = "0.36.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "812a2ec2043c4d6bc6482f5be2ab8244613cac2493d128d36c0759e52a626ab3" +dependencies = [ + "bitflags", + "errno", + "io-lifetimes 1.0.1", "libc", - "linux-raw-sys", + "linux-raw-sys 0.1.2", "windows-sys 0.42.0", ] @@ -9491,7 +9533,7 @@ dependencies = [ "once_cell", "parity-scale-codec", "parity-wasm 0.45.0", - "rustix", + "rustix 0.35.13", "sc-allocator", "sc-executor-common", "sp-runtime-interface", @@ -11296,9 +11338,9 @@ dependencies = [ [[package]] name = "ss58-registry" -version = "1.33.0" +version = "1.34.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3ab7554f8a8b6f8d71cd5a8e6536ef116e2ce0504cf97ebf16311d58065dc8a6" +checksum = "37a9821878e1f13aba383aa40a86fb1b33c7265774ec91e32563cb1dd1577496" dependencies = [ "Inflector", "num-format", @@ -12381,9 +12423,9 @@ dependencies = [ [[package]] name = "wasmtime" -version = "1.0.1" +version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f1f511c4917c83d04da68333921107db75747c4e11a2f654a8e909cc5e0520dc" +checksum = "4ad5af6ba38311282f2a21670d96e78266e8c8e2f38cbcd52c254df6ccbc7731" dependencies = [ "anyhow", "bincode", @@ -12409,18 +12451,18 @@ dependencies = [ [[package]] name = "wasmtime-asm-macros" -version = "1.0.1" +version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "39bf3debfe744bf19dd3732990ce6f8c0ced7439e2370ba4e1d8f5a3660a3178" +checksum = "45de63ddfc8b9223d1adc8f7b2ee5f35d1f6d112833934ad7ea66e4f4339e597" dependencies = [ "cfg-if 1.0.0", ] [[package]] name = "wasmtime-cache" -version = "1.0.1" +version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ece42fa4676a263f7558cdaaf5a71c2592bebcbac22a0580e33cf3406c103da2" +checksum = "bcd849399d17d2270141cfe47fa0d91ee52d5f8ea9b98cf7ddde0d53e5f79882" dependencies = [ "anyhow", "base64", @@ -12428,7 +12470,7 @@ dependencies = [ "directories-next", "file-per-thread-logger", "log", - "rustix", + "rustix 0.35.13", "serde", "sha2 0.9.9", "toml", @@ -12438,9 +12480,9 @@ dependencies = [ [[package]] name = "wasmtime-cranelift" -version = "1.0.1" +version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "058217e28644b012bdcdf0e445f58d496d78c2e0b6a6dd93558e701591dad705" +checksum = "4bd91339b742ff20bfed4532a27b73c86b5bcbfedd6bea2dcdf2d64471e1b5c6" dependencies = [ "anyhow", "cranelift-codegen", @@ -12459,9 +12501,9 @@ dependencies = [ [[package]] name = "wasmtime-environ" -version = "1.0.1" +version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c7af06848df28b7661471d9a80d30a973e0f401f2e3ed5396ad7e225ed217047" +checksum = "ebb881c61f4f627b5d45c54e629724974f8a8890d455bcbe634330cc27309644" dependencies = [ "anyhow", "cranelift-entity", @@ -12478,9 +12520,9 @@ dependencies = [ [[package]] name = "wasmtime-jit" -version = "1.0.1" +version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9028fb63a54185b3c192b7500ef8039c7bb8d7f62bfc9e7c258483a33a3d13bb" +checksum = "1985c628011fe26adf5e23a5301bdc79b245e0e338f14bb58b39e4e25e4d8681" dependencies = [ "addr2line", "anyhow", @@ -12491,7 +12533,7 @@ dependencies = [ "log", "object", "rustc-demangle", - "rustix", + "rustix 0.35.13", "serde", "target-lexicon", "thiserror", @@ -12503,20 +12545,20 @@ dependencies = [ [[package]] name = "wasmtime-jit-debug" -version = "1.0.1" +version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "25e82d4ef93296785de7efca92f7679dc67fe68a13b625a5ecc8d7503b377a37" +checksum = "f671b588486f5ccec8c5a3dba6b4c07eac2e66ab8c60e6f4e53717c77f709731" dependencies = [ "object", "once_cell", - "rustix", + "rustix 0.35.13", ] [[package]] name = "wasmtime-runtime" -version = "1.0.1" +version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9f0e9bea7d517d114fe66b930b2124ee086516ee93eeebfd97f75f366c5b0553" +checksum = "ee8f92ad4b61736339c29361da85769ebc200f184361959d1792832e592a1afd" dependencies = [ "anyhow", "cc", @@ -12529,7 +12571,7 @@ dependencies = [ "memoffset", "paste", "rand 0.8.5", - "rustix", + "rustix 0.35.13", "thiserror", "wasmtime-asm-macros", "wasmtime-environ", @@ -12539,9 +12581,9 @@ dependencies = [ [[package]] name = "wasmtime-types" -version = "1.0.1" +version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "69b83e93ed41b8fdc936244cfd5e455480cf1eca1fd60c78a0040038b4ce5075" +checksum = "d23d61cb4c46e837b431196dd06abb11731541021916d03476a178b54dc07aeb" dependencies = [ "cranelift-entity", "serde", @@ -12882,18 +12924,18 @@ checksum = "f40009d85759725a34da6d89a94e63d7bdc50a862acf0dbc7c8e488f1edcb6f5" [[package]] name = "winreg" -version = "0.7.0" +version = "0.10.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0120db82e8a1e0b9fb3345a539c478767c0048d842860994d96113d5b667bd69" +checksum = "80d0f4e272c85def139476380b12f9ac60926689dd2e01d4923222f40580869d" dependencies = [ "winapi", ] [[package]] name = "wyz" -version = "0.5.0" +version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "30b31594f29d27036c383b53b59ed3476874d518f0efb151b27a4c275141390e" +checksum = "05f360fc0b24296329c78fda852a1e9ae82de9cf7b27dae4b7f62f118f77b9ed" dependencies = [ "tap", ] diff --git a/node/src/chain_spec.rs b/node/src/chain_spec.rs index f18ffff66..c4195e3ad 100644 --- a/node/src/chain_spec.rs +++ b/node/src/chain_spec.rs @@ -96,7 +96,7 @@ pub fn session_keys(keys: AuraId) -> darwinia_runtime::SessionKeys { pub fn development_config() -> ChainSpec { // Give your base currency a unit name and decimal places let mut properties = sc_chain_spec::Properties::new(); - properties.insert("tokenSymbol".into(), "UNIT".into()); + properties.insert("tokenSymbol".into(), "RING".into()); properties.insert("tokenDecimals".into(), 18.into()); properties.insert("ss58Format".into(), 18.into()); @@ -140,7 +140,7 @@ pub fn development_config() -> ChainSpec { None, None, None, - None, + Some(properties), Extensions { relay_chain: "rococo-local".into(), // You MUST set this to the correct network! para_id: 1000, @@ -151,7 +151,7 @@ pub fn development_config() -> ChainSpec { pub fn local_testnet_config() -> ChainSpec { // Give your base currency a unit name and decimal places let mut properties = sc_chain_spec::Properties::new(); - properties.insert("tokenSymbol".into(), "UNIT".into()); + properties.insert("tokenSymbol".into(), "RING".into()); properties.insert("tokenDecimals".into(), 18.into()); properties.insert("ss58Format".into(), 18.into()); @@ -209,6 +209,70 @@ pub fn local_testnet_config() -> ChainSpec { ) } +pub fn shell_config() -> ChainSpec { + // Give your base currency a unit name and decimal places + let mut properties = sc_chain_spec::Properties::new(); + properties.insert("tokenSymbol".into(), "RING".into()); + properties.insert("tokenDecimals".into(), 18.into()); + properties.insert("ss58Format".into(), 18.into()); + + ChainSpec::from_genesis( + // Name + "Darwinia", + // ID + "darwinia", + ChainType::Live, + move || { + darwinia_runtime::GenesisConfig { + system: darwinia_runtime::SystemConfig { + code: darwinia_runtime::WASM_BINARY + .expect("WASM binary was not build, please build it!") + .to_vec(), + }, + balances: Default::default(), + parachain_info: darwinia_runtime::ParachainInfoConfig { parachain_id: 2046.into() }, + collator_selection: darwinia_runtime::CollatorSelectionConfig { + invulnerables: vec![get_account_id_from_seed::("Alice")], + ..Default::default() + }, + session: darwinia_runtime::SessionConfig { + keys: vec![( + get_account_id_from_seed::("Alice"), + get_account_id_from_seed::("Alice"), + session_keys(get_collator_keys_from_seed("Alice")), + )], + }, + // no need to pass anything to aura, in fact it will panic if we do. Session will + // take care of this. + aura: Default::default(), + aura_ext: Default::default(), + parachain_system: Default::default(), + polkadot_xcm: darwinia_runtime::PolkadotXcmConfig { + safe_xcm_version: Some(SAFE_XCM_VERSION), + }, + ethereum: Default::default(), + evm: Default::default(), + base_fee: Default::default(), + } + }, + // Bootnodes + Vec::new(), + // Telemetry + None, + // Protocol ID + Some("darwinia"), + // Fork ID + None, + // Properties + Some(properties), + // Extensions + Extensions { + relay_chain: "polkadot".into(), // You MUST set this to the correct network! + para_id: 2046, + }, + ) +} + fn testnet_genesis( invulnerables: Vec<(AccountId, AuraId)>, endowed_accounts: Vec, diff --git a/node/src/command.rs b/node/src/command.rs index 21f65d236..eb3a59152 100644 --- a/node/src/command.rs +++ b/node/src/command.rs @@ -495,6 +495,7 @@ fn load_spec(id: &str) -> std::result::Result, String> { Ok(match id { "dev" => Box::new(chain_spec::development_config()), "" | "local" => Box::new(chain_spec::local_testnet_config()), + "shell" => Box::new(chain_spec::shell_config()), path => Box::new(chain_spec::ChainSpec::from_json_file(std::path::PathBuf::from(path))?), }) } diff --git a/tool/state-processor/Cargo.lock b/tool/state-processor/Cargo.lock new file mode 100644 index 000000000..ba158446d --- /dev/null +++ b/tool/state-processor/Cargo.lock @@ -0,0 +1,628 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "aho-corasick" +version = "0.7.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b4f55bd91a0978cbfd91c457a164bab8b4001c833b7f323132c0a4e1922dd44e" +dependencies = [ + "memchr", +] + +[[package]] +name = "anyhow" +version = "1.0.66" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "216261ddc8289130e551ddcd5ce8a064710c0d064a4d2895c67151c92b5443f6" + +[[package]] +name = "array-bytes" +version = "4.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6a913633b0c922e6b745072795f50d90ebea78ba31a57e2ac8c2fc7b50950949" + +[[package]] +name = "arrayvec" +version = "0.4.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cd9fd44efafa8690358b7408d253adf110036b88f55672a933f01d616ad9b1b9" +dependencies = [ + "nodrop", +] + +[[package]] +name = "arrayvec" +version = "0.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8da52d66c7071e2e3fa2a1e5c6d088fec47b593032b254f5e980de8ea54454d6" + +[[package]] +name = "atty" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8" +dependencies = [ + "hermit-abi", + "libc", + "winapi", +] + +[[package]] +name = "bitvec" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1bc2832c24239b0141d5674bb9174f9d68a8b5b3f2753311927c172ca46f7e9c" +dependencies = [ + "funty", + "radium", + "tap", + "wyz", +] + +[[package]] +name = "blake2-rfc" +version = "0.2.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5d6d530bdd2d52966a6d03b7a964add7ae1a288d25214066fd4b600f0f796400" +dependencies = [ + "arrayvec 0.4.12", + "constant_time_eq", +] + +[[package]] +name = "block-buffer" +version = "0.10.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "69cce20737498f97b993470a6e536b8523f0af7892a4f928cceb1ac5e52ebe7e" +dependencies = [ + "generic-array", +] + +[[package]] +name = "byte-slice-cast" +version = "1.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c3ac9f8b63eca6fd385229b3675f6cc0dc5c8a5c8a54a59d4f52ffd670d87b0c" + +[[package]] +name = "byteorder" +version = "1.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610" + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "constant_time_eq" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "245097e9a4535ee1e3e3931fcfcd55a796a44c643e8596ff6566d68f09b87bbc" + +[[package]] +name = "cpufeatures" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "28d997bd5e24a5928dd43e46dc529867e207907fe0b239c3477d924f7f2ca320" +dependencies = [ + "libc", +] + +[[package]] +name = "crunchy" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a81dae078cea95a014a339291cec439d2f232ebe854a9d672b796c6afafa9b7" + +[[package]] +name = "crypto-common" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1bfb12502f3fc46cca1bb51ac28df9d618d813cdc3d2f25b9fe775a34af26bb3" +dependencies = [ + "generic-array", + "typenum", +] + +[[package]] +name = "digest" +version = "0.10.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "adfbc57365a37acbd2ebf2b64d7e69bb766e2fea813521ed536f5d0520dcf86c" +dependencies = [ + "block-buffer", + "crypto-common", +] + +[[package]] +name = "env_logger" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "44533bbbb3bb3c1fa17d9f2e4e38bbbaf8396ba82193c4cb1b6445d711445d36" +dependencies = [ + "atty", + "humantime", + "log", + "regex", + "termcolor", +] + +[[package]] +name = "funty" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6d5a32815ae3f33302d95fdcb2ce17862f8c65363dcfd29360480ba1001fc9c" + +[[package]] +name = "fxhash" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c31b6d751ae2c7f11320402d34e41349dd1016f8d5d45e48c4312bc8625af50c" +dependencies = [ + "byteorder", +] + +[[package]] +name = "generic-array" +version = "0.14.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bff49e947297f3312447abdca79f45f4738097cc82b06e72054d2223f601f1b9" +dependencies = [ + "typenum", + "version_check", +] + +[[package]] +name = "getrandom" +version = "0.2.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c05aeb6a22b8f62540c194aac980f2115af067bfe15a0734d7277a768d396b31" +dependencies = [ + "cfg-if", + "libc", + "wasi", +] + +[[package]] +name = "hermit-abi" +version = "0.1.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "62b467343b94ba476dcb2500d242dadbb39557df889310ac77c5d99100aaac33" +dependencies = [ + "libc", +] + +[[package]] +name = "humantime" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "df004cfca50ef23c36850aaaa59ad52cc70d0e90243c3c7737a4dd32dc7a3c4f" +dependencies = [ + "quick-error", +] + +[[package]] +name = "impl-trait-for-tuples" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "11d7a9f6330b71fea57921c9b61c47ee6e84f72d394754eff6163ae67e7395eb" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "itoa" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4217ad341ebadf8d8e724e264f13e593e0648f5b3e94b3896a5df283be015ecc" + +[[package]] +name = "libc" +version = "0.2.137" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fc7fcc620a3bff7cdd7a365be3376c97191aeaccc2a603e600951e452615bf89" + +[[package]] +name = "log" +version = "0.4.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "abb12e687cfb44aa40f41fc3978ef76448f9b6038cad6aef4259d3c095a2382e" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "memchr" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d" + +[[package]] +name = "nodrop" +version = "0.1.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72ef4a56884ca558e5ddb05a1d1e7e1bfd9a68d9ed024c21704cc98872dae1bb" + +[[package]] +name = "once_cell" +version = "1.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "86f0b0d4bf799edbc74508c1e8bf170ff5f41238e5f8225603ca7caaae2b7860" + +[[package]] +name = "parity-scale-codec" +version = "3.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "366e44391a8af4cfd6002ef6ba072bae071a96aafca98d7d448a34c5dca38b6a" +dependencies = [ + "arrayvec 0.7.2", + "bitvec", + "byte-slice-cast", + "impl-trait-for-tuples", + "parity-scale-codec-derive", + "serde", +] + +[[package]] +name = "parity-scale-codec-derive" +version = "3.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9299338969a3d2f491d65f140b00ddec470858402f888af98e8642fb5e8965cd" +dependencies = [ + "proc-macro-crate", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "ppv-lite86" +version = "0.2.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de" + +[[package]] +name = "pretty_env_logger" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "926d36b9553851b8b0005f1275891b392ee4d2d833852c417ed025477350fb9d" +dependencies = [ + "env_logger", + "log", +] + +[[package]] +name = "proc-macro-crate" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eda0fc3b0fb7c975631757e14d9049da17374063edb6ebbcbc54d880d4fe94e9" +dependencies = [ + "once_cell", + "thiserror", + "toml", +] + +[[package]] +name = "proc-macro2" +version = "1.0.47" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5ea3d908b0e36316caf9e9e2c4625cdde190a7e6f440d794667ed17a1855e725" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quick-error" +version = "1.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a1d01941d82fa2ab50be1e79e6714289dd7cde78eba4c074bc5a4374f650dfe0" + +[[package]] +name = "quote" +version = "1.0.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbe448f377a7d6961e30f5955f9b8d106c3f5e449d493ee1b125c1d43c2b5179" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "radium" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc33ff2d4973d518d823d61aa239014831e521c75da58e3df4840d3f47749d09" + +[[package]] +name = "rand" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" +dependencies = [ + "libc", + "rand_chacha", + "rand_core", +] + +[[package]] +name = "rand_chacha" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" +dependencies = [ + "ppv-lite86", + "rand_core", +] + +[[package]] +name = "rand_core" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" +dependencies = [ + "getrandom", +] + +[[package]] +name = "regex" +version = "1.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e076559ef8e241f2ae3479e36f97bd5741c0330689e217ad51ce2c76808b868a" +dependencies = [ + "aho-corasick", + "memchr", + "regex-syntax", +] + +[[package]] +name = "regex-syntax" +version = "0.6.28" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "456c603be3e8d448b072f410900c09faf164fbce2d480456f50eea6e25f9c848" + +[[package]] +name = "ryu" +version = "1.0.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4501abdff3ae82a1c1b477a17252eb69cee9e66eb915c1abaa4f44d873df9f09" + +[[package]] +name = "serde" +version = "1.0.147" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d193d69bae983fc11a79df82342761dfbf28a99fc8d203dca4c3c1b590948965" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.147" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4f1d362ca8fc9c3e3a7484440752472d68a6caa98f1ab81d99b5dfe517cec852" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "serde_json" +version = "1.0.87" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6ce777b7b150d76b9cf60d28b55f5847135a003f7d7350c6be7a773508ce7d45" +dependencies = [ + "itoa", + "ryu", + "serde", +] + +[[package]] +name = "sha2" +version = "0.10.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "82e6b795fe2e3b1e845bafcb27aa35405c4d47cdfc92af5fc8d3002f76cebdc0" +dependencies = [ + "cfg-if", + "cpufeatures", + "digest", +] + +[[package]] +name = "state-processor" +version = "0.0.0" +dependencies = [ + "anyhow", + "array-bytes", + "fxhash", + "log", + "parity-scale-codec", + "pretty_env_logger", + "serde", + "serde_json", + "subhasher", + "subspector", + "substorager", +] + +[[package]] +name = "static_assertions" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" + +[[package]] +name = "subhasher" +version = "0.9.0-rc16" +source = "git+https://github.com/hack-ink/subalfred#de1ed2b16b0b2c3ceeb61b1f9168401bc0ace51d" +dependencies = [ + "blake2-rfc", + "byteorder", + "sha2", + "tiny-keccak", + "twox-hash", +] + +[[package]] +name = "subspector" +version = "0.9.0-rc16" +source = "git+https://github.com/hack-ink/subalfred#de1ed2b16b0b2c3ceeb61b1f9168401bc0ace51d" +dependencies = [ + "fxhash", + "serde", + "serde_json", +] + +[[package]] +name = "substorager" +version = "0.9.0-rc16" +source = "git+https://github.com/hack-ink/subalfred#de1ed2b16b0b2c3ceeb61b1f9168401bc0ace51d" +dependencies = [ + "array-bytes", + "subhasher", +] + +[[package]] +name = "syn" +version = "1.0.103" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a864042229133ada95abf3b54fdc62ef5ccabe9515b64717bcb9a1919e59445d" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "tap" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "55937e1799185b12863d447f42597ed69d9928686b8d88a1df17376a097d8369" + +[[package]] +name = "termcolor" +version = "1.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bab24d30b911b2376f3a13cc2cd443142f0c81dda04c118693e35b3835757755" +dependencies = [ + "winapi-util", +] + +[[package]] +name = "thiserror" +version = "1.0.37" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "10deb33631e3c9018b9baf9dcbbc4f737320d2b576bac10f6aefa048fa407e3e" +dependencies = [ + "thiserror-impl", +] + +[[package]] +name = "thiserror-impl" +version = "1.0.37" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "982d17546b47146b28f7c22e3d08465f6b8903d0ea13c1660d9d84a6e7adcdbb" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "tiny-keccak" +version = "2.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2c9d3793400a45f954c52e73d068316d76b6f4e36977e3fcebb13a2721e80237" +dependencies = [ + "crunchy", +] + +[[package]] +name = "toml" +version = "0.5.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8d82e1a7758622a465f8cee077614c73484dac5b836c02ff6a40d5d1010324d7" +dependencies = [ + "serde", +] + +[[package]] +name = "twox-hash" +version = "1.6.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "97fee6b57c6a41524a810daee9286c02d7752c4253064d0b05472833a438f675" +dependencies = [ + "cfg-if", + "rand", + "static_assertions", +] + +[[package]] +name = "typenum" +version = "1.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dcf81ac59edc17cc8697ff311e8f5ef2d99fcbd9817b34cec66f90b6c3dfd987" + +[[package]] +name = "unicode-ident" +version = "1.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6ceab39d59e4c9499d4e5a8ee0e2735b891bb7308ac83dfb4e80cad195c9f6f3" + +[[package]] +name = "version_check" +version = "0.9.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" + +[[package]] +name = "wasi" +version = "0.11.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" + +[[package]] +name = "winapi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" +dependencies = [ + "winapi-i686-pc-windows-gnu", + "winapi-x86_64-pc-windows-gnu", +] + +[[package]] +name = "winapi-i686-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" + +[[package]] +name = "winapi-util" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178" +dependencies = [ + "winapi", +] + +[[package]] +name = "winapi-x86_64-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" + +[[package]] +name = "wyz" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "30b31594f29d27036c383b53b59ed3476874d518f0efb151b27a4c275141390e" +dependencies = [ + "tap", +] diff --git a/tool/state-processor/Cargo.toml b/tool/state-processor/Cargo.toml new file mode 100644 index 000000000..829a5f9e8 --- /dev/null +++ b/tool/state-processor/Cargo.toml @@ -0,0 +1,24 @@ +[package] +authors = ["Xavier Lau "] +edition = "2021" +license = "GPL-3.0" +name = "state-processor" +version = "0.0.0" + +[dependencies] +# crates.io +anyhow = { version = "1.0" } +array-bytes = { version = "4.1" } +fxhash = { version = "0.2" } +log = { version = "0.4" } +parity-scale-codec = { version = "3.2", features = ["derive"] } +pretty_env_logger = { version = "0.4" } +serde = { version = "1.0" } +serde_json = { version = "1.0" } +# hack-ink +subhasher = { git = "https://github.com/hack-ink/subalfred" } +subspector = { git = "https://github.com/hack-ink/subalfred" } +substorager = { git = "https://github.com/hack-ink/subalfred" } + +[workspace] +exclude = [] diff --git a/tool/state-processor/src/balances/mod.rs b/tool/state-processor/src/balances/mod.rs new file mode 100644 index 000000000..ec9d4dbc5 --- /dev/null +++ b/tool/state-processor/src/balances/mod.rs @@ -0,0 +1,37 @@ +// darwinia +use crate::*; + +impl Processor { + pub fn process_balances( + &mut self, + ring_locks: &mut Map>, + kton_locks: &mut Map>, + ) -> &mut Self { + log::info!("take solo balance locks"); + self.solo_state + .take::, _>( + b"Balances", + b"Locks", + ring_locks, + get_blake2_128_concat_suffix, + ) + .take::, _>( + b"Kton", + b"Locks", + kton_locks, + get_blake2_128_concat_suffix, + ); + + // --- + // Currently, there are only fee-market locks. + // I suggest shutting down the fee-market before merging. + // So, we could ignore the para balance locks migration. + // --- + + log::info!("adjust solo balance lock decimals"); + ring_locks.iter_mut().for_each(|(_, v)| v.iter_mut().for_each(|l| l.amount *= GWEI)); + kton_locks.iter_mut().for_each(|(_, v)| v.iter_mut().for_each(|l| l.amount *= GWEI)); + + self + } +} diff --git a/tool/state-processor/src/main.rs b/tool/state-processor/src/main.rs new file mode 100644 index 000000000..2268700de --- /dev/null +++ b/tool/state-processor/src/main.rs @@ -0,0 +1,192 @@ +mod balances; +mod system; + +mod type_registry; +use type_registry::*; + +// std +use std::{ + env, + fs::File, + io::{Read, Write}, +}; +// crates.io +use anyhow::Result; +use fxhash::FxHashMap; +use parity_scale_codec::{Decode, Encode}; +use serde::de::DeserializeOwned; +// hack-ink +use subspector::ChainSpec; + +type Map = FxHashMap; + +fn main() -> Result<()> { + env::set_var("RUST_LOG", "state_processor"); + pretty_env_logger::init(); + + Processor::new()?.process()?; + + Ok(()) +} + +struct Processor { + solo_state: State, + para_state: State, + shell_chain_spec: ChainSpec, +} +impl Processor { + fn new() -> Result { + Ok(Self { + solo_state: State::from_file("test-data/solo.json")?, + para_state: State::from_file("test-data/para.json")?, + shell_chain_spec: from_file("test-data/shell.json")?, + }) + } + + fn process(mut self) -> Result<()> { + self.process_system(); + + self.save() + } + + fn save(self) -> Result<()> { + log::info!("save processed chain spec"); + + let mut f = File::create("test-data/processed.json")?; + let v = serde_json::to_vec(&self.shell_chain_spec)?; + + f.write_all(&v)?; + + Ok(()) + } +} + +struct State(Map); +impl State { + fn from_file(path: &str) -> Result { + Ok(Self(from_file::(path)?.genesis.raw.top)) + } + + #[allow(unused)] + fn prune(&mut self, pallet: &[u8], items: Option<&[&[u8]]>) -> &mut Self { + // Prune specific storages. + if let Some(items) = items { + for item in items { + let k = item_key(pallet, item); + + self.0.remove(&k).or_else(|| { + log::warn!( + "`{}::{}: {k}` not found", + String::from_utf8_lossy(pallet), + String::from_utf8_lossy(item) + ); + + None + }); + } + } + // Prune entire pallet. + else { + let prefix = pallet_key(pallet); + let mut pruned = false; + + self.0.retain(|full_key, _| { + if full_key.starts_with(&prefix) { + pruned = true; + + false + } else { + true + } + }); + + if !pruned { + log::warn!("`{}: {prefix}` not found", String::from_utf8_lossy(pallet)); + } + } + + self + } + + fn take( + &mut self, + pallet: &[u8], + item: &[u8], + buffer: &mut Map, + preprocess_key: F, + ) -> &mut Self + where + D: Decode, + F: Fn(&str, &str) -> String, + { + let item_key = item_key(pallet, item); + + self.0.retain(|full_key, v| { + if full_key.starts_with(&item_key) { + match decode(v) { + Ok(v) => { + buffer.insert(preprocess_key(full_key, &item_key), v); + }, + Err(e) => log::warn!("failed to decode `{full_key}:{v}`, due to `{e}`"), + } + + false + } else { + true + } + }); + + self + } +} + +fn from_file(path: &str) -> Result +where + D: DeserializeOwned, +{ + log::info!("load data from {path:?}"); + + let mut f = File::open(path)?; + let mut v = Vec::new(); + + f.read_to_end(&mut v)?; + + Ok(serde_json::from_slice(&v)?) +} + +fn pallet_key(pallet: &[u8]) -> String { + let prefix = subhasher::twox128(pallet); + + array_bytes::bytes2hex("0x", &prefix) +} + +fn item_key(pallet: &[u8], item: &[u8]) -> String { + let k = substorager::storage_key(pallet, item); + + array_bytes::bytes2hex("0x", &k.0) +} + +fn encode_value(v: V) -> String +where + V: Encode, +{ + array_bytes::bytes2hex("0x", &v.encode()) +} + +fn decode(hex: &str) -> Result +where + D: Decode, +{ + let v = array_bytes::hex2bytes(hex).map_err(|e| anyhow::anyhow!("{e:?}"))?; + + Ok(D::decode(&mut &*v)?) +} + +fn get_blake2_128_concat_suffix(full_key: &str, item_key: &str) -> String { + full_key.trim_start_matches(item_key).into() +} + +#[allow(unused)] +fn get_concat_suffix(full_key: &str, _: &str) -> String { + format!("0x{}", &full_key[full_key.len() - 64..]) +} diff --git a/tool/state-processor/src/system/mod.rs b/tool/state-processor/src/system/mod.rs new file mode 100644 index 000000000..66977d038 --- /dev/null +++ b/tool/state-processor/src/system/mod.rs @@ -0,0 +1,200 @@ +// darwinia +use crate::*; + +#[derive(Debug)] +pub struct AccountAll { + pub key: String, + pub nonce: u32, + pub consumers: u32, + pub providers: u32, + pub sufficients: u32, + pub ring: u128, + pub ring_reserved: u128, + pub ring_locks: Vec, + pub kton: u128, + pub kton_reserved: u128, + pub kton_locks: Vec, +} + +impl Processor { + // System storage items. + // https://github.com/paritytech/substrate/blob/polkadot-v0.9.16/frame/system/src/lib.rs#L545-L639 + // Balances storage items. + // https://github.com/paritytech/substrate/blob/polkadot-v0.9.16/frame/balances/src/lib.rs#L486-L535 + pub fn process_system(&mut self) -> &mut Self { + let mut accounts = Map::default(); + let mut solo_account_infos = Map::default(); + let mut solo_ring_locks = Map::default(); + let mut solo_kton_locks = Map::default(); + let mut para_account_infos = Map::default(); + let mut remaining_ring = Map::default(); + let mut remaining_kton = Map::default(); + let mut ring_total_issuance = 0; + + log::info!("take solo and remaining balances"); + self.solo_state + .take::( + b"System", + b"Account", + &mut solo_account_infos, + get_blake2_128_concat_suffix, + ) + .take::( + b"Ethereum", + b"RemainingRingBalance", + &mut remaining_ring, + get_blake2_128_concat_suffix, + ) + .take::( + b"Ethereum", + b"RemainingKtonBalance", + &mut remaining_kton, + get_blake2_128_concat_suffix, + ); + + log::info!("take solo and para balance locks"); + self.process_balances(&mut solo_ring_locks, &mut solo_kton_locks); + + log::info!("take para balances"); + self.para_state.take::( + b"System", + b"Account", + &mut para_account_infos, + get_blake2_128_concat_suffix, + ); + + log::info!("adjust solo balance decimals"); + solo_account_infos.iter_mut().for_each(|(_, v)| { + v.data.free *= GWEI; + v.data.reserved *= GWEI; + v.data.free_kton_or_misc_frozen *= GWEI; + v.data.reserved_kton_or_fee_frozen *= GWEI; + }); + + log::info!("merge solo and remaining balances"); + remaining_ring.into_iter().for_each(|(k, v)| { + if let Some(a) = solo_account_infos.get_mut(&k) { + a.data.free += v; + } else { + log::warn!("`RemainingRingBalance({k})` not found"); + } + }); + remaining_kton.into_iter().for_each(|(k, v)| { + if let Some(a) = solo_account_infos.get_mut(&k) { + a.data.free_kton_or_misc_frozen += v; + } else { + log::warn!("`RemainingKtonBalance({k})` not found"); + } + }); + + log::info!("build accounts"); + log::info!("calculate ring total issuance"); + solo_account_infos.into_iter().for_each(|(k, v)| { + let ring_locks = solo_ring_locks.remove(&k).unwrap_or_default(); + let kton_locks = solo_kton_locks.remove(&k).unwrap_or_default(); + + ring_total_issuance += v.data.free; + ring_total_issuance += v.data.reserved; + + accounts.insert( + k.clone(), + AccountAll { + key: k, + nonce: v.nonce, + // --- + // TODO: check if we could ignore para's. + consumers: v.consumers, + providers: v.providers, + sufficients: v.sufficients, + // --- + ring: v.data.free, + ring_reserved: v.data.reserved, + ring_locks, + kton: v.data.free_kton_or_misc_frozen, + kton_reserved: v.data.reserved_kton_or_fee_frozen, + kton_locks, + }, + ); + }); + para_account_infos.into_iter().for_each(|(k, v)| { + ring_total_issuance += v.data.free; + ring_total_issuance += v.data.reserved; + + accounts + .entry(k.clone()) + .and_modify(|a| { + a.nonce = v.nonce.max(a.nonce); + a.ring += v.data.free; + a.ring_reserved += v.data.reserved; + }) + .or_insert(AccountAll { + key: k, + nonce: v.nonce, + consumers: v.consumers, + providers: v.providers, + sufficients: v.sufficients, + ring: v.data.free, + ring_reserved: v.data.reserved, + ring_locks: Vec::new(), + kton: 0, + kton_reserved: 0, + kton_locks: Vec::new(), + }); + }); + + log::info!("check solo remaining locks"); + solo_ring_locks.into_iter().for_each(|(k, _)| log::warn!("ring_locks' owner({k}) dropped")); + solo_kton_locks.into_iter().for_each(|(k, _)| log::warn!("kton_locks' owner({k}) dropped")); + + let state = &mut self.shell_chain_spec.genesis.raw.top; + + log::info!("set `Balances::TotalIssuance`"); + state.insert(item_key(b"Balances", b"TotalIssuance"), encode_value(ring_total_issuance)); + + log::info!("update ring misc frozen and fee frozen"); + log::info!("set `System::Account`"); + log::info!("set `Balances::Locks`"); + accounts.into_iter().for_each(|(k, v)| { + let mut a = AccountInfo { + nonce: v.nonce, + consumers: v.consumers, + providers: v.providers, + sufficients: v.sufficients, + data: AccountData { + free: v.ring, + reserved: v.ring_reserved, + free_kton_or_misc_frozen: 0, + reserved_kton_or_fee_frozen: 0, + }, + }; + + // https://github.com/paritytech/substrate/blob/polkadot-v0.9.16/frame/balances/src/lib.rs#L945-L952 + // Update ring misc frozen and fee frozen. + for l in v.ring_locks.iter() { + if l.reasons == Reasons::All || l.reasons == Reasons::Misc { + a.data.free_kton_or_misc_frozen = a.data.free_kton_or_misc_frozen.max(l.amount); + } + if l.reasons == Reasons::All || l.reasons == Reasons::Fee { + a.data.reserved_kton_or_fee_frozen = + a.data.reserved_kton_or_fee_frozen.max(l.amount); + } + } + // --- + // TODO: migrate kton locks. + // --- + + // Set `System::Account`. + state.insert(format!("{}{k}", item_key(b"System", b"Account")), encode_value(a)); + // Set `Balances::Locks`. + // Skip empty locks. + if !v.ring_locks.is_empty() { + state.insert( + format!("{}{k}", item_key(b"Balances", b"Locks")), + encode_value(v.ring_locks), + ); + } + }); + + self + } +} diff --git a/tool/state-processor/src/type_registry.rs b/tool/state-processor/src/type_registry.rs new file mode 100644 index 000000000..4379e9d5d --- /dev/null +++ b/tool/state-processor/src/type_registry.rs @@ -0,0 +1,34 @@ +// crates.io +use parity_scale_codec::{Decode, Encode}; + +pub const GWEI: u128 = 1_000_000_000; + +#[derive(Debug, Encode, Decode)] +pub struct AccountInfo { + pub nonce: u32, + pub consumers: u32, + pub providers: u32, + pub sufficients: u32, + pub data: AccountData, +} +#[derive(Debug, Encode, Decode)] +pub struct AccountData { + pub free: u128, + pub reserved: u128, + pub free_kton_or_misc_frozen: u128, + pub reserved_kton_or_fee_frozen: u128, +} + +#[derive(Debug, Encode, Decode)] +pub struct BalanceLock { + pub id: [u8; 8], + pub amount: u128, + pub reasons: Reasons, +} +#[allow(clippy::unnecessary_cast)] +#[derive(Debug, PartialEq, Eq, Encode, Decode)] +pub enum Reasons { + Fee = 0, + Misc = 1, + All = 2, +}