diff --git a/CHANGELOG.md b/CHANGELOG.md index dc7bc5750..f966aa509 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -26,6 +26,7 @@ At the moment this project **does not** adhere to `dev` instead of `local`. - A user now needs to add a program config, which gets packaged with their program pointer to create program info. This changes both register and change_program_info (previously change_program_pointer). As well set_program now also takes program_type_definition. ([#593](https://github.com/entropyxyz/entropy-core/pull/593)) - Changed program_type_definition to configuration_interface. ([#597](https://github.com/entropyxyz/entropy-core/pull/597)) +- Changed program_modification_account in programs_info of programs pallet to deployer. ([#604](https://github.com/entropyxyz/entropy-core/pull/604)) ### Added - Test CLI which calls the same code as in integration tests ([#417](https://github.com/entropyxyz/entropy-core/pull/417)) @@ -50,6 +51,7 @@ At the moment this project **does not** adhere to - Additive aux data ([#577](https://github.com/entropyxyz/entropy-core/pull/577)) - Refactor Rust-based chain specs ([#592](https://github.com/entropyxyz/entropy-core/pull/592)) - Fix test CLI for additive program pointers and update / refactor tests ([#591](https://github.com/entropyxyz/entropy-core/pull/591)) +- Change `program_modification_account` to `program_deploy_key` ([#604](https://github.com/entropyxyz/entropy-core/pull/604)) ### Fixed - Fix inconsistency between interactive and file based passwords ([#589](https://github.com/entropyxyz/entropy-core/pull/589)) diff --git a/crates/test-cli/src/main.rs b/crates/test-cli/src/main.rs index 3a7d2f00c..ab9caee86 100644 --- a/crates/test-cli/src/main.rs +++ b/crates/test-cli/src/main.rs @@ -368,7 +368,7 @@ async fn run_command() -> anyhow::Result { println!( "{} {} {:>11} {:>14} {}", hash, - program_info.program_modification_account, + program_info.deployer, program_info.ref_counter, program_info.bytecode.len(), !program_info.configuration_interface.is_empty(), diff --git a/crates/testing-utils/src/test_client/mod.rs b/crates/testing-utils/src/test_client/mod.rs index 9eb2ea54c..1ac677e03 100644 --- a/crates/testing-utils/src/test_client/mod.rs +++ b/crates/testing-utils/src/test_client/mod.rs @@ -248,22 +248,21 @@ pub async fn sign( skip_all, fields( signature_request_account, - program_modification_account = ?program_modification_keypair.public(), + deployer = ?deployerpair.public(), ) )] pub async fn store_program( api: &OnlineClient, - program_modification_keypair: &sr25519::Pair, + deployerpair: &sr25519::Pair, program: Vec, configuration_interface: Vec, ) -> anyhow::Result<::Hash> { let update_program_tx = entropy::tx().programs().set_program(program, configuration_interface); - let program_modification_account = - PairSigner::::new(program_modification_keypair.clone()); + let deployer = PairSigner::::new(deployerpair.clone()); let in_block = api .tx() - .sign_and_submit_then_watch_default(&update_program_tx, &program_modification_account) + .sign_and_submit_then_watch_default(&update_program_tx, &deployer) .await? .wait_for_in_block() .await? @@ -279,7 +278,7 @@ pub async fn update_programs( entropy_api: &OnlineClient, rpc: &LegacyRpcMethods, signature_request_account: &sr25519::Pair, - pointer_modification_account: &sr25519::Pair, + deployer: &sr25519::Pair, program_instance: BoundedVec, ) -> anyhow::Result<()> { let block_hash = @@ -289,14 +288,13 @@ pub async fn update_programs( .relayer() .change_program_instance(signature_request_account.public().into(), program_instance); - let account_id32: AccountId32 = pointer_modification_account.public().into(); + let account_id32: AccountId32 = deployer.public().into(); let account_id: ::AccountId = account_id32.into(); let nonce_call = entropy::apis().account_nonce_api().account_nonce(account_id.clone()); let nonce = entropy_api.runtime_api().at(block_hash).call(nonce_call).await?; - let pointer_modification_account = - PairSigner::::new(pointer_modification_account.clone()); + let deployer = PairSigner::::new(deployer.clone()); let partial_tx = entropy_api.tx().create_partial_signed_with_nonce( &update_pointer_tx, @@ -304,7 +302,7 @@ pub async fn update_programs( Default::default(), )?; let signer_payload = partial_tx.signer_payload(); - let signature = pointer_modification_account.sign(&signer_payload); + let signature = deployer.sign(&signer_payload); let tx = partial_tx.sign_with_address_and_signature(&account_id.into(), &signature); @@ -357,7 +355,7 @@ pub async fn put_register_request_on_chain( api: &OnlineClient, rpc: &LegacyRpcMethods, signature_request_keypair: sr25519::Pair, - program_modification_account: SubxtAccountId32, + deployer: SubxtAccountId32, key_visibility: KeyVisibility, program_instance: BoundedVec, ) -> anyhow::Result<()> { @@ -367,11 +365,8 @@ pub async fn put_register_request_on_chain( let signature_request_pair_signer = PairSigner::::new(signature_request_keypair); - let registering_tx = entropy::tx().relayer().register( - program_modification_account, - Static(key_visibility), - program_instance, - ); + let registering_tx = + entropy::tx().relayer().register(deployer, Static(key_visibility), program_instance); let block_hash = rpc.chain_get_block_hash(None).await?.ok_or_else(|| anyhow!("Error getting block hash"))?; diff --git a/crates/threshold-signature-server/entropy_metadata.scale b/crates/threshold-signature-server/entropy_metadata.scale index 74bae0350..002e2b79f 100644 Binary files a/crates/threshold-signature-server/entropy_metadata.scale and b/crates/threshold-signature-server/entropy_metadata.scale differ diff --git a/crates/threshold-signature-server/src/helpers/tests.rs b/crates/threshold-signature-server/src/helpers/tests.rs index 9e219f2d2..9e06218f2 100644 --- a/crates/threshold-signature-server/src/helpers/tests.rs +++ b/crates/threshold-signature-server/src/helpers/tests.rs @@ -184,16 +184,15 @@ pub async fn spawn_testing_validators( pub async fn remove_program( entropy_api: &OnlineClient, rpc: &LegacyRpcMethods, - program_modification_account: &sr25519::Pair, + deployer: &sr25519::Pair, program_hash: ::Hash, ) { // update/set their programs let remove_program_tx = entropy::tx().programs().remove_program(program_hash); - let account_id32: AccountId32 = program_modification_account.public().into(); + let account_id32: AccountId32 = deployer.public().into(); let account_id: ::AccountId = account_id32.into(); - let program_modification_account = - PairSigner::::new(program_modification_account.clone()); + let deployer = PairSigner::::new(deployer.clone()); let block_hash = rpc.chain_get_block_hash(None).await.unwrap().unwrap(); let nonce_call = entropy::apis().account_nonce_api().account_nonce(account_id.clone()); @@ -203,7 +202,7 @@ pub async fn remove_program( .create_partial_signed_with_nonce(&remove_program_tx, nonce.into(), Default::default()) .unwrap(); let signer_payload = partial_tx.signer_payload(); - let signature = program_modification_account.sign(&signer_payload); + let signature = deployer.sign(&signer_payload); let tx = partial_tx.sign_with_address_and_signature(&account_id.into(), &signature); tx.submit_and_watch() diff --git a/pallets/programs/src/benchmarking.rs b/pallets/programs/src/benchmarking.rs index fe34213dd..89bee7e99 100644 --- a/pallets/programs/src/benchmarking.rs +++ b/pallets/programs/src/benchmarking.rs @@ -48,17 +48,17 @@ benchmarks! { hash_input.extend(&configuration_interface); let program_hash = T::Hashing::hash(&hash_input); - let program_modification_account: T::AccountId = whitelisted_caller(); + let deployer: T::AccountId = whitelisted_caller(); let sig_req_account: T::AccountId = whitelisted_caller(); let value = CurrencyOf::::minimum_balance().saturating_mul(1_000_000_000u32.into()); - let _ = CurrencyOf::::make_free_balance_be(&program_modification_account, value); + let _ = CurrencyOf::::make_free_balance_be(&deployer, value); - }: _(RawOrigin::Signed(program_modification_account.clone()), program.clone(), configuration_interface.clone()) + }: _(RawOrigin::Signed(deployer.clone()), program.clone(), configuration_interface.clone()) verify { assert_last_event::( Event::::ProgramCreated { - program_modification_account, + deployer, program_hash, configuration_interface }.into() @@ -76,23 +76,23 @@ benchmarks! { let program_hash = T::Hashing::hash(&hash_input); let random_program = vec![11]; let random_hash = T::Hashing::hash(&random_program); - let program_modification_account: T::AccountId = whitelisted_caller(); + let deployer: T::AccountId = whitelisted_caller(); let value = CurrencyOf::::minimum_balance().saturating_mul(1_000_000_000u32.into()); - let _ = CurrencyOf::::make_free_balance_be(&program_modification_account, value); - >::insert(program_hash.clone(), ProgramInfo {bytecode: program, configuration_interface, program_modification_account: program_modification_account.clone(), ref_counter: 0u128}); + let _ = CurrencyOf::::make_free_balance_be(&deployer, value); + >::insert(program_hash.clone(), ProgramInfo {bytecode: program, configuration_interface, deployer: deployer.clone(), ref_counter: 0u128}); let mut program_hashes = vec![random_hash.clone(); p as usize]; // remove one to make room for the targetted removal program hash program_hashes.pop(); program_hashes.push(program_hash); let bounded_program_hashes: BoundedVec = BoundedVec::try_from(program_hashes).unwrap(); - >::insert(program_modification_account.clone(), bounded_program_hashes); - }: _(RawOrigin::Signed(program_modification_account.clone()), program_hash.clone()) + >::insert(deployer.clone(), bounded_program_hashes); + }: _(RawOrigin::Signed(deployer.clone()), program_hash.clone()) verify { assert_last_event::( Event::::ProgramRemoved { - program_modification_account, + deployer, old_program_hash: program_hash }.into() ); diff --git a/pallets/programs/src/lib.rs b/pallets/programs/src/lib.rs index 1b869e308..4ff648dae 100644 --- a/pallets/programs/src/lib.rs +++ b/pallets/programs/src/lib.rs @@ -17,8 +17,7 @@ //! //! ## Overview //! -//! This pallet stores the WebAssembly (Wasm) program bytecode on-chain and allows users to change -//! it as required. +//! This pallet stores the WebAssembly (Wasm) program bytecode on-chain at the hash of the program code and interface //! //! A program is a piece of logic which is run by the network when a signing operation is requested. //! The succesful execution of a program indicates to validators on the network that they should @@ -32,8 +31,8 @@ //! //! #### Public //! -//! `update_program` - Allows a program-modification account to change the program associated with -//! a particular signature-request account. +//! `set_program` - Allows a deployer account to create a program. +//! `remove_program` - Allows a deployer to remove a program if not in use. #![cfg_attr(not(feature = "std"), no_std)] pub use pallet::*; @@ -90,20 +89,21 @@ pub mod pallet { #[pallet::without_storage_info] pub struct Pallet(_); - /// Information on the program, the bytecode and the account allowed to modify it + /// Information on the program #[derive(Clone, Encode, Decode, Eq, PartialEq, RuntimeDebug, TypeInfo)] pub struct ProgramInfo { /// The bytecode of the program. pub bytecode: Vec, /// The type definition of the program pub configuration_interface: Vec, - /// Owners of the program - pub program_modification_account: AccountId, + /// Deployer of the program + pub deployer: AccountId, /// Accounts that use this program pub ref_counter: u128, } - /// Stores the program bytecode for a given signature-request account. + /// Stores the program info for a given program hash. + /// A program hash is a combination of the bytecode and configuration_interface #[pallet::storage] #[pallet::getter(fn programs)] pub type Programs = @@ -125,8 +125,8 @@ pub mod pallet { pub enum Event { /// The bytecode of a program was created. ProgramCreated { - /// The program modification account which updated the program. - program_modification_account: T::AccountId, + /// The deployer account which created the program. + deployer: T::AccountId, /// The new program hash. program_hash: T::Hash, @@ -136,8 +136,8 @@ pub mod pallet { }, /// The bytecode of a program was removed. ProgramRemoved { - /// The program modification account which removed the program. - program_modification_account: T::AccountId, + /// The depoyer account which removed the program. + deployer: T::AccountId, /// The hash of the removed program. old_program_hash: T::Hash, @@ -162,9 +162,9 @@ pub mod pallet { #[pallet::call] impl Pallet { - /// Sets the program and uses hash as key. + /// Sets the program and uses hash of program and configuration_interface as key. /// - /// Note that the caller becomes the program-modification account. + /// Note that the caller becomes the deployer account. #[pallet::call_index(0)] #[pallet::weight({::WeightInfo::set_program()})] pub fn set_program( @@ -172,7 +172,7 @@ pub mod pallet { new_program: Vec, configuration_interface: Vec, ) -> DispatchResult { - let program_modification_account = ensure_signed(origin)?; + let deployer = ensure_signed(origin)?; let mut hash_input = vec![]; hash_input.extend(&new_program); hash_input.extend(&configuration_interface); @@ -184,19 +184,19 @@ pub mod pallet { ); ensure!(!Programs::::contains_key(program_hash), Error::::ProgramAlreadySet); - Self::reserve_program_deposit(&program_modification_account, new_program_length)?; + Self::reserve_program_deposit(&deployer, new_program_length)?; Programs::::insert( program_hash, &ProgramInfo { bytecode: new_program.clone(), configuration_interface: configuration_interface.clone(), - program_modification_account: program_modification_account.clone(), + deployer: deployer.clone(), ref_counter: 0u128, }, ); OwnedPrograms::::try_mutate( - &program_modification_account, + &deployer, |owned_programs| -> Result<(), DispatchError> { owned_programs .try_push(program_hash) @@ -205,7 +205,7 @@ pub mod pallet { }, )?; Self::deposit_event(Event::ProgramCreated { - program_modification_account, + deployer, program_hash, configuration_interface, }); @@ -214,28 +214,25 @@ pub mod pallet { /// Removes a program at a specific hash /// - /// Caller must be the program modification account for said program. + /// Caller must be the deployer account for said program. #[pallet::call_index(1)] #[pallet::weight({::WeightInfo::remove_program( ::MaxOwnedPrograms::get())})] pub fn remove_program( origin: OriginFor, program_hash: T::Hash, ) -> DispatchResultWithPostInfo { - let program_modification_account = ensure_signed(origin)?; + let deployer = ensure_signed(origin)?; let old_program_info = Self::programs(program_hash).ok_or(Error::::NoProgramDefined)?; - ensure!( - old_program_info.program_modification_account == program_modification_account, - Error::::NotAuthorized - ); + ensure!(old_program_info.deployer == deployer, Error::::NotAuthorized); ensure!(old_program_info.ref_counter == 0, Error::::ProgramInUse); Self::unreserve_program_deposit( - &old_program_info.program_modification_account, + &old_program_info.deployer, old_program_info.bytecode.len() + old_program_info.configuration_interface.len(), ); let mut owned_programs_length = 0; OwnedPrograms::::try_mutate( - &program_modification_account, + &deployer, |owned_programs| -> Result<(), DispatchError> { owned_programs_length = owned_programs.len(); let pos = owned_programs @@ -247,10 +244,7 @@ pub mod pallet { }, )?; Programs::::remove(program_hash); - Self::deposit_event(Event::ProgramRemoved { - program_modification_account, - old_program_hash: program_hash, - }); + Self::deposit_event(Event::ProgramRemoved { deployer, old_program_hash: program_hash }); Ok(Some(::WeightInfo::remove_program(owned_programs_length as u32)).into()) } } diff --git a/pallets/programs/src/tests.rs b/pallets/programs/src/tests.rs index f85c7d1d4..1bd959a54 100644 --- a/pallets/programs/src/tests.rs +++ b/pallets/programs/src/tests.rs @@ -54,7 +54,7 @@ fn set_program() { let program_result = ProgramInfo { bytecode: program.clone(), configuration_interface: configuration_interface.clone(), - program_modification_account: PROGRAM_MODIFICATION_ACCOUNT, + deployer: PROGRAM_MODIFICATION_ACCOUNT, ref_counter: 0u128, }; assert_eq!( @@ -139,7 +139,7 @@ fn remove_program() { "Program bytecode gets set" ); assert_eq!( - ProgramsPallet::programs(program_hash).unwrap().program_modification_account, + ProgramsPallet::programs(program_hash).unwrap().deployer, PROGRAM_MODIFICATION_ACCOUNT, "Program modification account gets set" ); @@ -178,7 +178,7 @@ fn remove_program_fails_ref_count() { ProgramInfo { bytecode: program, configuration_interface, - program_modification_account: PROGRAM_MODIFICATION_ACCOUNT, + deployer: PROGRAM_MODIFICATION_ACCOUNT, ref_counter: 1u128, }, ); diff --git a/pallets/propagation/src/tests.rs b/pallets/propagation/src/tests.rs index 50b115a78..27dc03781 100644 --- a/pallets/propagation/src/tests.rs +++ b/pallets/propagation/src/tests.rs @@ -82,7 +82,7 @@ fn knows_how_to_mock_several_http_calls() { ProgramInfo { bytecode: vec![], configuration_interface: vec![], - program_modification_account: 1, + deployer: 1, ref_counter: 0, }, ); diff --git a/pallets/relayer/src/benchmarking.rs b/pallets/relayer/src/benchmarking.rs index 409bf4bb1..bdbb9c8b1 100644 --- a/pallets/relayer/src/benchmarking.rs +++ b/pallets/relayer/src/benchmarking.rs @@ -81,7 +81,7 @@ benchmarks! { .unwrap(); let program_modification_account: T::AccountId = whitelisted_caller(); - Programs::::insert(program_hash, ProgramInfo {bytecode: program, configuration_interface, program_modification_account: program_modification_account.clone(), ref_counter: 0}); + Programs::::insert(program_hash, ProgramInfo {bytecode: program, configuration_interface, deployer: program_modification_account.clone(), ref_counter: 0}); let sig_req_account: T::AccountId = whitelisted_caller(); let balance = ::Currency::minimum_balance() * 100u32.into(); let _ = ::Currency::make_free_balance_be(&sig_req_account, balance); @@ -101,7 +101,7 @@ benchmarks! { program_pointer: program_hash, program_config: vec![], }]).unwrap(); - Programs::::insert(program_hash, ProgramInfo {bytecode: program, configuration_interface, program_modification_account: program_modification_account.clone(), ref_counter: 1}); + Programs::::insert(program_hash, ProgramInfo {bytecode: program, configuration_interface, deployer: program_modification_account.clone(), ref_counter: 1}); let sig_req_account: T::AccountId = whitelisted_caller(); let balance = ::Currency::minimum_balance() * 100u32.into(); let _ = ::Currency::make_free_balance_be(&sig_req_account, balance); @@ -138,8 +138,8 @@ benchmarks! { }; n as usize]) .unwrap(); let sig_req_account: T::AccountId = whitelisted_caller(); - Programs::::insert(program_hash, ProgramInfo {bytecode: program, configuration_interface: configuration_interface.clone(), program_modification_account: program_modification_account.clone(), ref_counter: 0}); - Programs::::insert(new_program_hash, ProgramInfo {bytecode: new_program, configuration_interface, program_modification_account: program_modification_account.clone(), ref_counter: o as u128}); + Programs::::insert(program_hash, ProgramInfo {bytecode: program, configuration_interface: configuration_interface.clone(), deployer: program_modification_account.clone(), ref_counter: 0}); + Programs::::insert(new_program_hash, ProgramInfo {bytecode: new_program, configuration_interface, deployer: program_modification_account.clone(), ref_counter: o as u128}); let balance = ::Currency::minimum_balance() * 100u32.into(); let _ = ::Currency::make_free_balance_be(&sig_req_account, balance); >::insert( diff --git a/pallets/relayer/src/tests.rs b/pallets/relayer/src/tests.rs index 573782e88..6e9906d2a 100644 --- a/pallets/relayer/src/tests.rs +++ b/pallets/relayer/src/tests.rs @@ -83,7 +83,7 @@ fn it_registers_a_user() { ProgramInfo { bytecode: empty_program.clone(), configuration_interface: empty_program.clone(), - program_modification_account: 1, + deployer: 1, ref_counter: 0, }, ); @@ -131,7 +131,7 @@ fn it_confirms_registers_a_user() { ProgramInfo { bytecode: empty_program.clone(), configuration_interface: empty_program.clone(), - program_modification_account: 1, + deployer: 1, ref_counter: 0, }, ); @@ -220,7 +220,7 @@ fn it_changes_a_program_pointer() { ProgramInfo { bytecode: empty_program.clone(), configuration_interface: empty_program.clone(), - program_modification_account: 1, + deployer: 1, ref_counter: 1, }, ); @@ -238,7 +238,7 @@ fn it_changes_a_program_pointer() { ProgramInfo { bytecode: new_program, configuration_interface: empty_program.clone(), - program_modification_account: 1, + deployer: 1, ref_counter: 1, }, ); @@ -317,7 +317,7 @@ fn it_fails_on_non_matching_verifying_keys() { ProgramInfo { bytecode: empty_program.clone(), configuration_interface: empty_program.clone(), - program_modification_account: 1, + deployer: 1, ref_counter: 0, }, ); @@ -370,7 +370,7 @@ fn it_doesnt_allow_double_registering() { ProgramInfo { bytecode: empty_program.clone(), configuration_interface: empty_program.clone(), - program_modification_account: 1, + deployer: 1, ref_counter: 0, }, ); @@ -450,7 +450,7 @@ fn it_tests_prune_registration() { ProgramInfo { bytecode: inital_program.clone(), configuration_interface: inital_program.clone(), - program_modification_account: 1, + deployer: 1, ref_counter: 1, }, ); @@ -494,7 +494,7 @@ fn it_provides_free_txs_confirm_done() { ProgramInfo { bytecode: empty_program.clone(), configuration_interface: empty_program.clone(), - program_modification_account: 1, + deployer: 1, ref_counter: 0, }, ); @@ -573,7 +573,7 @@ fn it_provides_free_txs_confirm_done_fails_3() { ProgramInfo { bytecode: empty_program.clone(), configuration_interface: empty_program.clone(), - program_modification_account: 1, + deployer: 1, ref_counter: 0, }, ); @@ -622,7 +622,7 @@ fn it_provides_free_txs_confirm_done_fails_4() { ProgramInfo { bytecode: empty_program.clone(), configuration_interface: empty_program.clone(), - program_modification_account: 1, + deployer: 1, ref_counter: 0, }, ); @@ -664,7 +664,7 @@ fn it_provides_free_txs_confirm_done_fails_5() { ProgramInfo { bytecode: empty_program.clone(), configuration_interface: empty_program.clone(), - program_modification_account: 1, + deployer: 1, ref_counter: 0, }, );