From f24d347956a7ecdd0e9a4fc2bd0863b379859234 Mon Sep 17 00:00:00 2001 From: Irman Nur Muhammad Alamsyah Date: Thu, 11 Nov 2021 08:58:01 +0800 Subject: [PATCH] fix: era reward --- Cargo.lock | 62 +++---- node/src/chain_spec.rs | 122 ++++++++----- node/src/service.rs | 339 +------------------------------------ pallets/rewards/Cargo.toml | 4 + 4 files changed, 113 insertions(+), 414 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index c4a9a749..cd0ac20d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1889,9 +1889,9 @@ dependencies = [ [[package]] name = "frame-metadata" -version = "14.0.0" +version = "14.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "96616f82e069102b95a72c87de4c84d2f87ef7f0f20630e78ce3824436483110" +checksum = "37ed5e5c346de62ca5c184b4325a6600d1eaca210666e4606fe4e449574978d0" dependencies = [ "cfg-if 1.0.0", "parity-scale-codec", @@ -2616,9 +2616,9 @@ dependencies = [ [[package]] name = "if-addrs" -version = "0.6.6" +version = "0.6.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c9a83ec4af652890ac713ffd8dc859e650420a5ef47f7b9be29b6664ab50fbc8" +checksum = "2273e421f7c4f0fc99e1934fe4776f59d8df2972f4199d703fc0da9f2a9f73de" dependencies = [ "if-addrs-sys", "libc", @@ -3014,9 +3014,9 @@ checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55" [[package]] name = "libc" -version = "0.2.106" +version = "0.2.107" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a60553f9a9e039a333b4e9b20573b9e9b9c0bb3a11e201ccc48ef4283456d673" +checksum = "fbe5e23404da5b4f555ef85ebed98fb4083e55a00c317800bc2a50ede9f3d219" [[package]] name = "libloading" @@ -3112,7 +3112,7 @@ dependencies = [ "sha2 0.9.8", "smallvec", "thiserror", - "unsigned-varint 0.7.0", + "unsigned-varint 0.7.1", "void", "zeroize", ] @@ -3182,7 +3182,7 @@ dependencies = [ "regex", "sha2 0.9.8", "smallvec", - "unsigned-varint 0.7.0", + "unsigned-varint 0.7.1", "wasm-timer", ] @@ -3223,7 +3223,7 @@ dependencies = [ "sha2 0.9.8", "smallvec", "uint", - "unsigned-varint 0.7.0", + "unsigned-varint 0.7.1", "void", "wasm-timer", ] @@ -3264,7 +3264,7 @@ dependencies = [ "parking_lot", "rand 0.7.3", "smallvec", - "unsigned-varint 0.7.0", + "unsigned-varint 0.7.1", ] [[package]] @@ -3317,7 +3317,7 @@ dependencies = [ "log", "prost", "prost-build", - "unsigned-varint 0.7.0", + "unsigned-varint 0.7.1", "void", ] @@ -3353,7 +3353,7 @@ dependencies = [ "prost-build", "rand 0.7.3", "smallvec", - "unsigned-varint 0.7.0", + "unsigned-varint 0.7.1", "void", "wasm-timer", ] @@ -3374,7 +3374,7 @@ dependencies = [ "minicbor", "rand 0.7.3", "smallvec", - "unsigned-varint 0.7.0", + "unsigned-varint 0.7.1", "wasm-timer", ] @@ -3909,7 +3909,7 @@ dependencies = [ "percent-encoding 2.1.0", "serde", "static_assertions", - "unsigned-varint 0.7.0", + "unsigned-varint 0.7.1", "url 2.2.2", ] @@ -3951,7 +3951,7 @@ dependencies = [ "generic-array 0.14.4", "multihash-derive", "sha2 0.9.8", - "unsigned-varint 0.7.0", + "unsigned-varint 0.7.1", ] [[package]] @@ -3985,7 +3985,7 @@ dependencies = [ "log", "pin-project 1.0.8", "smallvec", - "unsigned-varint 0.7.0", + "unsigned-varint 0.7.1", ] [[package]] @@ -4672,9 +4672,9 @@ dependencies = [ [[package]] name = "parity-db" -version = "0.3.3" +version = "0.3.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e7ccc4a8687027deb53d45c5434a1f1b330c9d1069a59cfe80a62aa9a1da25ae" +checksum = "7cb5195cb862b13055cf7f7a76c55073dc73885c2a61511e322b8c1666be7332" dependencies = [ "blake2-rfc", "crc32fast", @@ -4828,9 +4828,9 @@ dependencies = [ [[package]] name = "paste" -version = "1.0.5" +version = "1.0.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "acbf547ad0c65e31259204bd90935776d1c693cec2f4ff7abb7a1bbbd40dfe58" +checksum = "0744126afe1a6dd7f394cb50a716dbe086cb06e255e53d8d0185d82828358fb5" [[package]] name = "pbkdf2" @@ -5491,6 +5491,8 @@ dependencies = [ "frame-benchmarking", "frame-support", "frame-system", + "hex-literal", + "pallet-balances", "parity-scale-codec", "scale-info", "serde", @@ -6721,9 +6723,9 @@ dependencies = [ [[package]] name = "serde_json" -version = "1.0.68" +version = "1.0.69" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0f690853975602e1bfe1ccbf50504d67174e3bcf340f23b5ea9992e0587a52d8" +checksum = "e466864e431129c7e0d3476b92f20458e5879919a0596c6472738d9fa2d342f8" dependencies = [ "itoa", "ryu", @@ -7608,9 +7610,9 @@ checksum = "6e63cff320ae2c57904679ba7cb63280a3dc4613885beafb148ee7bf9aa9042d" [[package]] name = "ss58-registry" -version = "1.2.0" +version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bb102b328df61c67f8ccf8471b29c31c7d6da646a867aff95fe8bff386fe7c4d" +checksum = "b9ac591d51e303f0a50ac4bc70d7d2a6cc125859951677ed08133c7bdf839d42" dependencies = [ "Inflector", "proc-macro2", @@ -8354,9 +8356,9 @@ dependencies = [ [[package]] name = "unsigned-varint" -version = "0.7.0" +version = "0.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5f8d425fafb8cd76bc3f22aace4af471d3156301d7508f2107e98fbeae10bc7f" +checksum = "d86a8dc7f45e4c1b0d30e43038c38f274e77af056aa5f74b93c2cf9eb3c1c836" dependencies = [ "asynchronous-codec 0.6.0", "bytes 1.1.0", @@ -8912,18 +8914,18 @@ dependencies = [ [[package]] name = "zeroize" -version = "1.4.2" +version = "1.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bf68b08513768deaa790264a7fac27a58cbf2705cfcdc9448362229217d7e970" +checksum = "d68d9dcec5f9b43a30d38c49f91dfedfaac384cb8f085faca366c26207dd1619" dependencies = [ "zeroize_derive", ] [[package]] name = "zeroize_derive" -version = "1.2.0" +version = "1.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bdff2024a851a322b08f179173ae2ba620445aef1e838f0c196820eade4ae0c7" +checksum = "65f1a51723ec88c66d5d1fe80c841f17f63587d6691901d66be9bec6c3b51f73" dependencies = [ "proc-macro2", "quote", diff --git a/node/src/chain_spec.rs b/node/src/chain_spec.rs index 120fc5b9..741ef79c 100644 --- a/node/src/chain_spec.rs +++ b/node/src/chain_spec.rs @@ -1,11 +1,11 @@ +use beefy_primitives::crypto::AuthorityId as BeefyId; use debio_runtime::{ - currency::UNITS as DBIO, opaque::Block, opaque::SessionKeys, AccountId, Balance, Signature, - WASM_BINARY, BABE_GENESIS_EPOCH_CONFIG, - GenesisConfig, BabeConfig, BalancesConfig, - OctopusAppchainConfig, OctopusLposConfig, SessionConfig, SudoConfig, SystemConfig, - OrdersConfig, RewardsConfig, LabsConfig, ServiceRequestConfig, + currency::UNITS as DBIO, + opaque::{Block, SessionKeys}, + AccountId, BabeConfig, Balance, BalancesConfig, GenesisConfig, LabsConfig, + OctopusAppchainConfig, OctopusLposConfig, OrdersConfig, RewardsConfig, ServiceRequestConfig, + SessionConfig, Signature, SudoConfig, SystemConfig, BABE_GENESIS_EPOCH_CONFIG, WASM_BINARY, }; -use beefy_primitives::crypto::AuthorityId as BeefyId; use pallet_im_online::sr25519::AuthorityId as ImOnlineId; use pallet_octopus_appchain::AuthorityId as OctopusId; use sc_chain_spec::ChainSpecExtension; @@ -220,33 +220,45 @@ pub fn staging_testnet_config() -> Result { vec![ ( // 5DWyDncRWXBuQHwJkwndcxD8EpiNjC5aUpkvQvH5pKWW31kS - hex!["4044558c867f510c90406c029d4132552cff769af982df767536607126f20b3e"].into(), + hex!["4044558c867f510c90406c029d4132552cff769af982df767536607126f20b3e"] + .into(), // 5DWyDncRWXBuQHwJkwndcxD8EpiNjC5aUpkvQvH5pKWW31kS - hex!["4044558c867f510c90406c029d4132552cff769af982df767536607126f20b3e"].unchecked_into(), + hex!["4044558c867f510c90406c029d4132552cff769af982df767536607126f20b3e"] + .unchecked_into(), // 5F3w32CUTSdx6tVtKqtmX5ySxv2EWtf5ALozHXdm1sRmDRyn - hex!["841dd15656fe6f518d7f834be42c8ebac03856b973fe0cfe884d3bf63f54044e"].unchecked_into(), + hex!["841dd15656fe6f518d7f834be42c8ebac03856b973fe0cfe884d3bf63f54044e"] + .unchecked_into(), // 5DWyDncRWXBuQHwJkwndcxD8EpiNjC5aUpkvQvH5pKWW31kS - hex!["4044558c867f510c90406c029d4132552cff769af982df767536607126f20b3e"].unchecked_into(), + hex!["4044558c867f510c90406c029d4132552cff769af982df767536607126f20b3e"] + .unchecked_into(), // KWE8SLkhBFQDYC6mp9BXGFvtHHoXWgVspsnrHhXXwGxdd52J1 - hex!["03ef93c4f8f2b34f0945ac57f666555f9a6a211cbb7f21118dfc8049100347162d"].unchecked_into(), + hex!["03ef93c4f8f2b34f0945ac57f666555f9a6a211cbb7f21118dfc8049100347162d"] + .unchecked_into(), // 5DWyDncRWXBuQHwJkwndcxD8EpiNjC5aUpkvQvH5pKWW31kS - hex!["4044558c867f510c90406c029d4132552cff769af982df767536607126f20b3e"].unchecked_into(), + hex!["4044558c867f510c90406c029d4132552cff769af982df767536607126f20b3e"] + .unchecked_into(), // Stash amount 100 * DBIO, ), ( // 5CaJm3bpWi3ieWYHcbz4xd7MrF8Njma4p7tGTBwemRbYnknT - hex!["16939c61baa637549e3a90277790655b5c5ce0e60ea9688559f9da587b2cb419"].into(), + hex!["16939c61baa637549e3a90277790655b5c5ce0e60ea9688559f9da587b2cb419"] + .into(), // 5CaJm3bpWi3ieWYHcbz4xd7MrF8Njma4p7tGTBwemRbYnknT - hex!["16939c61baa637549e3a90277790655b5c5ce0e60ea9688559f9da587b2cb419"].unchecked_into(), + hex!["16939c61baa637549e3a90277790655b5c5ce0e60ea9688559f9da587b2cb419"] + .unchecked_into(), // 5Ca1whan2BfjBU4JYkcK2HwkkJxcgUvgkXHd1q3sn1kMM2iX - hex!["165b008e2e3181f869893b237406e847daa043d90bf80e62bb8a8442281afac0"].unchecked_into(), + hex!["165b008e2e3181f869893b237406e847daa043d90bf80e62bb8a8442281afac0"] + .unchecked_into(), // 5CaJm3bpWi3ieWYHcbz4xd7MrF8Njma4p7tGTBwemRbYnknT - hex!["16939c61baa637549e3a90277790655b5c5ce0e60ea9688559f9da587b2cb419"].unchecked_into(), + hex!["16939c61baa637549e3a90277790655b5c5ce0e60ea9688559f9da587b2cb419"] + .unchecked_into(), // KW6TMKohWcZBna5xBkcthEuGX1p5R7gn6z8eqCMBDjEWBLUbA - hex!["029c1ead8e295430573bb984b8b38c9479b7a9a236725d7c2090182fd38bf4d9b5"].unchecked_into(), + hex!["029c1ead8e295430573bb984b8b38c9479b7a9a236725d7c2090182fd38bf4d9b5"] + .unchecked_into(), // 5CaJm3bpWi3ieWYHcbz4xd7MrF8Njma4p7tGTBwemRbYnknT - hex!["16939c61baa637549e3a90277790655b5c5ce0e60ea9688559f9da587b2cb419"].unchecked_into(), + hex!["16939c61baa637549e3a90277790655b5c5ce0e60ea9688559f9da587b2cb419"] + .unchecked_into(), // Stash amount 100 * DBIO, ), @@ -256,21 +268,24 @@ pub fn staging_testnet_config() -> Result { ( // Sudo account // 5CB5udaxY6zFqApVHWPQTGTW5FszotkXKAUD48fvi5Y7FSR2 - hex!["04ddb3f730857ed801327da2242dff4d4d85e25b33c43db6f328d55904247f40"].into(), + hex!["04ddb3f730857ed801327da2242dff4d4d85e25b33c43db6f328d55904247f40"] + .into(), // Balance amount 12_498_000 * DBIO, ), ( // Valiadator 1 account // 5DWyDncRWXBuQHwJkwndcxD8EpiNjC5aUpkvQvH5pKWW31kS - hex!["4044558c867f510c90406c029d4132552cff769af982df767536607126f20b3e"].into(), + hex!["4044558c867f510c90406c029d4132552cff769af982df767536607126f20b3e"] + .into(), // Balance amount 1_000 * DBIO, ), ( // Valiadator 2 account // 5CaJm3bpWi3ieWYHcbz4xd7MrF8Njma4p7tGTBwemRbYnknT - hex!["16939c61baa637549e3a90277790655b5c5ce0e60ea9688559f9da587b2cb419"].into(), + hex!["16939c61baa637549e3a90277790655b5c5ce0e60ea9688559f9da587b2cb419"] + .into(), // Balance amount 1_000 * DBIO, ), @@ -325,33 +340,45 @@ pub fn development_testnet_config() -> Result { vec![ ( // 5FNUtTJn1hhx1JEBrtWz9yaGx7M19hGhWZonxaJFHFu6SQ6C - hex!["92437599810542e6c9e435290225920cb7b8174a949ed8f67b3413c6435ad76c"].into(), + hex!["92437599810542e6c9e435290225920cb7b8174a949ed8f67b3413c6435ad76c"] + .into(), // 5FNUtTJn1hhx1JEBrtWz9yaGx7M19hGhWZonxaJFHFu6SQ6C - hex!["92437599810542e6c9e435290225920cb7b8174a949ed8f67b3413c6435ad76c"].unchecked_into(), + hex!["92437599810542e6c9e435290225920cb7b8174a949ed8f67b3413c6435ad76c"] + .unchecked_into(), // 5DZQ8hkpX2STvCDKxnisDS4M3wKr8T4irH7Kb6pi1opYWicR - hex!["421eaffb5d5601b080f546fa8be621d26085a2743b4d935d2b8dd83c2cecaa39"].unchecked_into(), + hex!["421eaffb5d5601b080f546fa8be621d26085a2743b4d935d2b8dd83c2cecaa39"] + .unchecked_into(), // 5FNUtTJn1hhx1JEBrtWz9yaGx7M19hGhWZonxaJFHFu6SQ6C - hex!["92437599810542e6c9e435290225920cb7b8174a949ed8f67b3413c6435ad76c"].unchecked_into(), + hex!["92437599810542e6c9e435290225920cb7b8174a949ed8f67b3413c6435ad76c"] + .unchecked_into(), // KW39i1yj3MYMcCaF5QZUbk8FBPbEzbrn1E6A3Xdmw4beErUGT - hex!["0209f537ca85f50055cf9553d72c8a594516a915b6c040109ed5450da0185c3ff1"].unchecked_into(), + hex!["0209f537ca85f50055cf9553d72c8a594516a915b6c040109ed5450da0185c3ff1"] + .unchecked_into(), // 5FNUtTJn1hhx1JEBrtWz9yaGx7M19hGhWZonxaJFHFu6SQ6C - hex!["92437599810542e6c9e435290225920cb7b8174a949ed8f67b3413c6435ad76c"].unchecked_into(), + hex!["92437599810542e6c9e435290225920cb7b8174a949ed8f67b3413c6435ad76c"] + .unchecked_into(), // Stash amount 100 * DBIO, ), ( // 5DF6RP41YxxgE8yemXAH47aJo9313TG7pVvx1utM4a9WnKk5 - hex!["3428a50b8746e28304b67a2a8dfd5fc40c0ee17c28ce129c5db1ac42c4e9905a"].into(), + hex!["3428a50b8746e28304b67a2a8dfd5fc40c0ee17c28ce129c5db1ac42c4e9905a"] + .into(), // 5DF6RP41YxxgE8yemXAH47aJo9313TG7pVvx1utM4a9WnKk5 - hex!["3428a50b8746e28304b67a2a8dfd5fc40c0ee17c28ce129c5db1ac42c4e9905a"].unchecked_into(), + hex!["3428a50b8746e28304b67a2a8dfd5fc40c0ee17c28ce129c5db1ac42c4e9905a"] + .unchecked_into(), // 5CetaryC3UwJEwSJvo8GzLVM4kxejioSfjmoZyAX4TKPSNuq - hex!["1a1274a58903a684d89cd926735137961a795d798b250926f7c8867b487549d8"].unchecked_into(), + hex!["1a1274a58903a684d89cd926735137961a795d798b250926f7c8867b487549d8"] + .unchecked_into(), // 5DF6RP41YxxgE8yemXAH47aJo9313TG7pVvx1utM4a9WnKk5 - hex!["3428a50b8746e28304b67a2a8dfd5fc40c0ee17c28ce129c5db1ac42c4e9905a"].unchecked_into(), + hex!["3428a50b8746e28304b67a2a8dfd5fc40c0ee17c28ce129c5db1ac42c4e9905a"] + .unchecked_into(), // KW2ywDzHXAmvvcCZu14szXHdsXka9Xuez4Q1RPuXMkw2VTZYk - hex!["020281390b3b2a5f25dcda82477a2da7a00a2570724b24d60e82446a63f81db4c7"].unchecked_into(), + hex!["020281390b3b2a5f25dcda82477a2da7a00a2570724b24d60e82446a63f81db4c7"] + .unchecked_into(), // 5DF6RP41YxxgE8yemXAH47aJo9313TG7pVvx1utM4a9WnKk5 - hex!["3428a50b8746e28304b67a2a8dfd5fc40c0ee17c28ce129c5db1ac42c4e9905a"].unchecked_into(), + hex!["3428a50b8746e28304b67a2a8dfd5fc40c0ee17c28ce129c5db1ac42c4e9905a"] + .unchecked_into(), // Stash amount 100 * DBIO, ), @@ -361,21 +388,24 @@ pub fn development_testnet_config() -> Result { ( // Sudo account // 5G3nLeySH5sFzD9WPKt2kB3KNVnazsZykaFfotouvjf1RZWY - hex!["b03cc727c3c98eab988e5acfa815f6e6ed1939060471adaa78d2e39bbb1fc50b"].into(), + hex!["b03cc727c3c98eab988e5acfa815f6e6ed1939060471adaa78d2e39bbb1fc50b"] + .into(), // Balance amount 12_498_000 * DBIO, ), ( // Valiadator 1 account // 5FNUtTJn1hhx1JEBrtWz9yaGx7M19hGhWZonxaJFHFu6SQ6C - hex!["92437599810542e6c9e435290225920cb7b8174a949ed8f67b3413c6435ad76c"].into(), + hex!["92437599810542e6c9e435290225920cb7b8174a949ed8f67b3413c6435ad76c"] + .into(), // Balance amount 1_000 * DBIO, ), ( // Valiadator 2 account // 5DF6RP41YxxgE8yemXAH47aJo9313TG7pVvx1utM4a9WnKk5 - hex!["3428a50b8746e28304b67a2a8dfd5fc40c0ee17c28ce129c5db1ac42c4e9905a"].into(), + hex!["3428a50b8746e28304b67a2a8dfd5fc40c0ee17c28ce129c5db1ac42c4e9905a"] + .into(), // Balance amount 1_000 * DBIO, ), @@ -502,15 +532,13 @@ pub fn development_config() -> Result { authority_keys_from_seed("Alice", 100 * DBIO), ], // Pre-funded accounts - vec![ - ( - // Sudo account and API admin account - // 5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY - get_account_id_from_seed::("Alice"), - // Balance amount - 12_500_000 * DBIO, - ), - ], + vec![( + // Sudo account and API admin account + // 5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY + get_account_id_from_seed::("Alice"), + // Balance amount + 12_500_000 * DBIO, + )], // Appchain config appchain_config( // Appchain Relay Contract @@ -600,8 +628,8 @@ fn genesis( }, octopus_lpos: OctopusLposConfig { era_payout: appchain_config.3, ..Default::default() }, orders: OrdersConfig { escrow_key: api_admin_key.clone() }, - rewards: RewardsConfig { rewarder_key: api_admin_key.clone() }, - labs: LabsConfig { lab_verifier_key: api_admin_key.clone() }, + rewards: RewardsConfig { rewarder_key: api_admin_key.clone() }, + labs: LabsConfig { lab_verifier_key: api_admin_key.clone() }, service_request: ServiceRequestConfig { admin_key: api_admin_key.clone() }, } } diff --git a/node/src/service.rs b/node/src/service.rs index 9aabe1af..fe7318d4 100644 --- a/node/src/service.rs +++ b/node/src/service.rs @@ -67,77 +67,8 @@ type LightClient = /// The transaction pool type defintion. pub type TransactionPool = sc_transaction_pool::FullPool; -/// Fetch the nonce of the given `account` from the chain state. -/// -/// Note: Should only be used for tests. -pub fn fetch_nonce(client: &FullClient, account: sp_core::sr25519::Pair) -> u32 { - let best_hash = client.chain_info().best_hash; - client - .runtime_api() - .account_nonce(&generic::BlockId::Hash(best_hash), account.public().into()) - .expect("Fetching account nonce works; qed") -} - -/// Create a transaction using the given `call`. -/// -/// The transaction will be signed by `sender`. If `nonce` is `None` it will be fetched from the -/// state of the best block. -/// -/// Note: Should only be used for tests. -pub fn create_extrinsic( - client: &FullClient, - sender: sp_core::sr25519::Pair, - function: impl Into, - nonce: Option, -) -> debio_runtime::UncheckedExtrinsic { - let function = function.into(); - let genesis_hash = client.block_hash(0).ok().flatten().expect("Genesis block exists; qed"); - let best_hash = client.chain_info().best_hash; - let best_block = client.chain_info().best_number; - let nonce = nonce.unwrap_or_else(|| fetch_nonce(client, sender.clone())); - - let period = debio_runtime::BlockHashCount::get() - .checked_next_power_of_two() - .map(|c| c / 2) - .unwrap_or(2) as u64; - let tip = 0; - let extra: debio_runtime::SignedExtra = ( - frame_system::CheckSpecVersion::::new(), - frame_system::CheckTxVersion::::new(), - frame_system::CheckGenesis::::new(), - frame_system::CheckEra::::from(generic::Era::mortal( - period, - best_block.saturated_into(), - )), - frame_system::CheckNonce::::from(nonce), - frame_system::CheckWeight::::new(), - pallet_transaction_payment::ChargeTransactionPayment::::from(tip), - ); - - let raw_payload = debio_runtime::SignedPayload::from_raw( - function.clone(), - extra.clone(), - ( - debio_runtime::VERSION.spec_version, - debio_runtime::VERSION.transaction_version, - genesis_hash, - best_hash, - (), - (), - (), - ), - ); - let signature = raw_payload.using_encoded(|e| sender.sign(e)); - - debio_runtime::UncheckedExtrinsic::new_signed( - function.clone(), - sp_runtime::AccountId32::from(sender.public()).into(), - debio_runtime::Signature::Sr25519(signature.clone()), - extra.clone(), - ) -} - /// Creates a new partial node. +#[allow(clippy::type_complexity)] pub fn new_partial( config: &Configuration, ) -> Result< @@ -529,6 +460,7 @@ pub fn new_full(config: Configuration) -> Result { } /// Creates a light service from the configuration. +#[allow(clippy::type_complexity)] pub fn new_light_base( mut config: Configuration, ) -> Result< @@ -704,270 +636,3 @@ pub fn new_light_base( pub fn new_light(config: Configuration) -> Result { new_light_base(config).map(|(task_manager, _, _, _, _)| task_manager) } - -#[cfg(test)] -mod tests { - use crate::service::{new_full_base, new_light_base, NewFullBase}; - use codec::Encode; - use node_primitives::{Block, DigestItem, Signature}; - use debio_runtime::{ - constants::{currency::CENTS, time::SLOT_DURATION}, - Address, BalancesCall, Call, 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 as CryptoPair, Public, H256}; - use sp_inherents::InherentDataProvider; - use sp_keyring::AccountKeyring; - use sp_keystore::{SyncCryptoStore, SyncCryptoStorePtr}; - use sp_runtime::{ - generic::{BlockId, Digest, Era, SignedPayload}, - key_types::BABE, - traits::{Block as BlockT, Header as HeaderT, IdentifyAccount, Verify}, - RuntimeAppPublic, - }; - use sp_timestamp; - use std::{borrow::Cow, convert::TryInto, 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: SyncCryptoStorePtr = - Arc::new(LocalKeystore::open(keystore_path.path(), None).expect("Creates keystore")); - let alice: sp_consensus_babe::AuthorityId = - SyncCryptoStore::sr25519_generate_new(&*keystore, 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, transaction_pool, .. } = - new_full_base( - config, - |block_import: &sc_consensus_babe::BabeBlockImport, - babe_link: &sc_consensus_babe::BabeLink| { - setup_handles = Some((block_import.clone(), babe_link.clone())); - }, - )?; - - let node = sc_service_test::TestNetComponents::new( - task_manager, - client, - network, - transaction_pool, - ); - Ok((node, setup_handles.unwrap())) - }, - |config| { - let (keep_alive, _, client, network, transaction_pool) = new_light_base(config)?; - Ok(sc_service_test::TestNetComponents::new( - keep_alive, - client, - network, - transaction_pool, - )) - }, - |service, &mut (ref mut block_import, ref babe_link)| { - let parent_id = BlockId::number(service.client().chain_info().best_number); - let parent_header = service.client().header(&parent_id).unwrap().unwrap(); - let parent_hash = parent_header.hash(); - 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 = ( - 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 = SyncCryptoStore::sign_with( - &*keystore, - sp_consensus_babe::AuthorityId::ID, - &alice.to_public_crypto_pair(), - &to_sign, - ) - .unwrap() - .unwrap() - .try_into() - .unwrap(); - let item = ::babe_seal(signature); - slot += 1; - - let mut params = BlockImportParams::new(BlockOrigin::File, new_header); - params.post_digests.push(item); - params.body = Some(new_body); - params.intermediates.insert( - Cow::from(INTERMEDIATE_KEY), - Box::new(BabeIntermediate:: { epoch_descriptor }) as Box<_>, - ); - params.fork_choice = Some(ForkChoiceStrategy::LongestChain); - - futures::executor::block_on(block_import.import_block(params, Default::default())) - .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_block_id = BlockId::number(service.client().chain_info().best_number); - let (spec_version, transaction_version) = { - let version = service.client().runtime_version_at(&best_block_id).unwrap(); - (version.spec_version, version.transaction_version) - }; - let signer = charlie.clone(); - - let function = - Call::Balances(BalancesCall::transfer { dest: to.into(), value: amount }); - - 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 payment = pallet_transaction_payment::ChargeTransactionPayment::from(0); - let extra = ( - check_spec_version, - check_tx_version, - check_genesis, - check_era, - check_nonce, - check_weight, - 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.into(), signature.into(), extra) - .into() - }, - ); - } - - #[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, transaction_pool, .. } = - new_full_base(config, |_, _| ())?; - Ok(sc_service_test::TestNetComponents::new( - task_manager, - client, - network, - transaction_pool, - )) - }, - |config| { - let (keep_alive, _, client, network, transaction_pool) = new_light_base(config)?; - Ok(sc_service_test::TestNetComponents::new( - keep_alive, - client, - network, - transaction_pool, - )) - }, - vec!["//Alice".into(), "//Bob".into()], - ) - } -} diff --git a/pallets/rewards/Cargo.toml b/pallets/rewards/Cargo.toml index 650c5944..017cdabb 100644 --- a/pallets/rewards/Cargo.toml +++ b/pallets/rewards/Cargo.toml @@ -28,9 +28,13 @@ frame-benchmarking = { git = 'https://github.com/paritytech/substrate.git', bran [dev-dependencies] serde = { default-features = false, version = "1.0.119" } +hex-literal = '0.3.3' + sp-core = { git = 'https://github.com/paritytech/substrate.git', branch = 'polkadot-v0.9.12', default-features = false } sp-runtime = { git = 'https://github.com/paritytech/substrate.git', branch = 'polkadot-v0.9.12', default-features = false } +pallet-balances = { git = 'https://github.com/paritytech/substrate.git', branch = 'polkadot-v0.9.12', default-features = false } + [features] default = ['std']