Browse Source

Remove RuntimeUpgradeHash proposal details

- remove the optimization for the runtime upgrade proposal
Shamil Gadelshin 4 years ago
parent
commit
2562fbe147

+ 6 - 6
runtime-modules/proposals/codex/Cargo.toml

@@ -91,12 +91,6 @@ git = 'https://github.com/paritytech/substrate.git'
 package = 'srml-staking'
 rev = 'c37bb08535c49a12320af7facfd555ce05cce2e8'
 
-[dependencies.runtime-io]
-default_features = false
-git = 'https://github.com/paritytech/substrate.git'
-package = 'sr-io'
-rev = 'c37bb08535c49a12320af7facfd555ce05cce2e8'
-
 [dependencies.stake]
 default_features = false
 package = 'substrate-stake-module'
@@ -173,6 +167,12 @@ git = 'https://github.com/paritytech/substrate.git'
 package = 'sr-staking-primitives'
 rev = 'c37bb08535c49a12320af7facfd555ce05cce2e8'
 
+[dev-dependencies.runtime-io]
+default_features = false
+git = 'https://github.com/paritytech/substrate.git'
+package = 'sr-io'
+rev = 'c37bb08535c49a12320af7facfd555ce05cce2e8'
+
 # don't rename the dependency it is causing some strange compiler error:
 # https://github.com/rust-lang/rust/issues/64450
 [dev-dependencies.srml-staking-reward-curve]

+ 1 - 8
runtime-modules/proposals/codex/src/lib.rs

@@ -55,7 +55,6 @@ use rstd::convert::TryInto;
 use rstd::prelude::*;
 use rstd::str::from_utf8;
 use rstd::vec::Vec;
-use runtime_io::blake2_256;
 use sr_primitives::traits::SaturatedConversion;
 use sr_primitives::traits::{One, Zero};
 use sr_primitives::Perbill;
@@ -372,16 +371,10 @@ decl_module! {
             ensure!(wasm.len() as u32 <= T::RuntimeUpgradeWasmProposalMaxLength::get(),
                 Error::RuntimeProposalSizeExceeded);
 
-            let wasm_hash = blake2_256(&wasm);
-
-            // The runtime upgrade proposal has two proposal details: wasm and wasm hash.
-            // This is an exception for the optimization.
-
             let proposal_parameters = proposal_types::parameters::runtime_upgrade_proposal::<T>();
             let proposal_details = ProposalDetails::RuntimeUpgrade(wasm);
             let proposal_code = T::ProposalEncoder::encode_proposal(proposal_details.clone());
 
-            let proposal_details_for_hash = ProposalDetails::RuntimeUpgradeHash(wasm_hash.to_vec());
             Self::create_proposal(
                 origin,
                 member_id,
@@ -390,7 +383,7 @@ decl_module! {
                 stake_balance,
                 proposal_code,
                 proposal_parameters,
-                proposal_details_for_hash,
+                proposal_details,
             )?;
         }
 

+ 1 - 6
runtime-modules/proposals/codex/src/proposal_types/mod.rs

@@ -30,12 +30,7 @@ pub enum ProposalDetails<MintedBalance, CurrencyBalance, BlockNumber, AccountId,
     /// The text of the `text` proposal
     Text(Vec<u8>),
 
-    /// The hash of wasm code for the `runtime upgrade` proposal. The runtime upgrade proposal has
-    /// two proposal details: wasm and wasm hash. This is an exception for the optimization.
-    RuntimeUpgradeHash(Vec<u8>),
-
-    /// The wasm code for the `runtime upgrade` proposal. The runtime upgrade proposal has
-    /// two proposal details: wasm and wasm hash. This is an exception for the optimization.
+    /// The wasm code for the `runtime upgrade` proposal
     RuntimeUpgrade(Vec<u8>),
 
     /// Election parameters for the `set election parameters` proposal

+ 1 - 2
runtime-modules/proposals/codex/src/tests/mod.rs

@@ -8,7 +8,6 @@ use system::RawOrigin;
 use crate::{BalanceOf, Error, ProposalDetails};
 use proposal_engine::ProposalParameters;
 use roles::actors::RoleParameters;
-use runtime_io::blake2_256;
 use srml_support::dispatch::DispatchResult;
 
 pub use mock::*;
@@ -223,7 +222,7 @@ fn create_runtime_upgrade_common_checks_succeed() {
                 )
             },
             proposal_parameters: crate::proposal_types::parameters::runtime_upgrade_proposal::<Test>(),
-            proposal_details: ProposalDetails::RuntimeUpgradeHash(blake2_256(b"wasm").to_vec()),
+            proposal_details: ProposalDetails::RuntimeUpgrade(b"wasm".to_vec()),
         };
         proposal_fixture.check_all();
     });

+ 4 - 20
runtime/src/integration/proposals/proposal_encoder.rs

@@ -4,7 +4,6 @@ use roles::actors::Role;
 
 use codec::Encode;
 use rstd::vec::Vec;
-use srml_support::print;
 
 /// _ProposalEncoder_ implementation. It encodes extrinsics with proposal details parameters
 /// using Runtime Call and parity codec.
@@ -43,25 +42,10 @@ impl ProposalEncoder<Runtime> for ExtrinsicProposalEncoder {
                 roles::actors::Call::set_role_parameters(Role::StorageProvider, role_parameters),
             )
             .encode(),
-            ProposalDetails::RuntimeUpgrade(wasm_code) => {
-                // The runtime upgrade proposal has two proposal details: wasm and wasm hash.
-                // This is an exception for the optimization.
-
-                // This is a real extrinsic call.
-                Call::ProposalsCodex(proposals_codex::Call::execute_runtime_upgrade_proposal(
-                    wasm_code,
-                ))
-                .encode()
-            }
-            ProposalDetails::RuntimeUpgradeHash(_) => {
-                // The runtime upgrade proposal has two proposal details: wasm and wasm hash.
-                // This is an exception for the optimization.
-
-                // Cannot be here. This is a bug.
-                print("Invalid proposal: cannot encode ProposalDetails::RuntimeUpgradeHash");
-
-                Vec::new()
-            }
+            ProposalDetails::RuntimeUpgrade(wasm_code) => Call::ProposalsCodex(
+                proposals_codex::Call::execute_runtime_upgrade_proposal(wasm_code),
+            )
+            .encode(),
         }
     }
 }