Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename ProgramInfo.config_interface to interface_description #631

Merged
merged 9 commits into from
Feb 26, 2024
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ At the moment this project **does not** adhere to
`StakingExtensionConfig::proactive_refresh_validators` field used by the chain spec is now
`StakingExtensionConfigproactive_refresh_data` and takes a tuple of `Vec`. Both should be empty at
genesis for production.
- In [#631](https://github.com/entropyxyz/entropy-core/pull/631), the `config_interface` field of `ProgramInfo` was renamed to `interface_description` to be more semantically accurate. This field will now be used to describe program interfaces, including the auxilary and configuration interfaces of the program.

### Added
- Add ValidatorSubgroupRotated event ([#618](https://github.com/entropyxyz/entropy-core/pull/618))
Expand Down
24 changes: 12 additions & 12 deletions crates/test-cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ enum CliCommand {
/// a '.json' extension, it will be read and used as the configuration for that program.
///
/// If the path to a wasm file is given, and there is a file with the same name with a
/// '.config-interface' extension, it will be stored as that program's configuration
/// '.interface-description' extension, it will be stored as that program's configuration
/// interface. If no such file exists, it is assumed the program has no configuration
/// interface.
programs: Vec<String>,
Expand Down Expand Up @@ -129,7 +129,7 @@ enum CliCommand {
/// a '.json' extension, it will be read and used as the configuration for that program.
///
/// If the path to a wasm file is given, and there is a file with the same name with a
/// '.config-interface' extension, it will be stored as that program's configuration
/// '.interface-description' extension, it will be stored as that program's configuration
/// interface. If no such file exists, it is assumed the program has no configuration
/// interface.
programs: Vec<String>,
Expand Down Expand Up @@ -391,7 +391,7 @@ async fn run_command() -> anyhow::Result<String> {
program_info.deployer,
program_info.ref_counter,
program_info.bytecode.len(),
!program_info.configuration_interface.is_empty(),
!program_info.interface_description.is_empty(),
);
}
}
Expand Down Expand Up @@ -485,11 +485,11 @@ impl Program {
) -> anyhow::Result<Self> {
let program_bytecode = fs::read(&filename)?;

// If there is a file with the same name with the '.config-interface' extension, read it
let configuration_interface = {
let mut configuration_interface_file = PathBuf::from(&filename);
configuration_interface_file.set_extension("config-interface");
fs::read(&configuration_interface_file).unwrap_or_default()
// If there is a file with the same name with the '.interface-description' extension, read it
let interface_description = {
let mut interface_description_file = PathBuf::from(&filename);
interface_description_file.set_extension("interface-description");
fs::read(&interface_description_file).unwrap_or_default()
};

// If there is a file with the same name with the '.json' extension, read it
Expand All @@ -500,12 +500,12 @@ impl Program {
};

ensure!(
(configuration_interface.is_empty() && configuration.is_empty())
|| (!configuration_interface.is_empty() && !configuration.is_empty()),
"If giving a configuration interface you must also give a configuration"
(interface_description.is_empty() && configuration.is_empty())
|| (!interface_description.is_empty() && !configuration.is_empty()),
"If giving an interface description you must also give a configuration"
);

match store_program(api, rpc, keypair, program_bytecode.clone(), configuration_interface)
match store_program(api, rpc, keypair, program_bytecode.clone(), interface_description)
.await
{
Ok(hash) => Ok(Self::new(hash, configuration)),
Expand Down
Binary file modified crates/threshold-signature-server/entropy_metadata.scale
Binary file not shown.
14 changes: 7 additions & 7 deletions pallets/programs/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ benchmarks! {

set_program {
let program = vec![10];
let configuration_interface = vec![11];
let interface_description = vec![11];
let mut hash_input: Vec<u8> = vec![];
hash_input.extend(&program);
hash_input.extend(&configuration_interface);
hash_input.extend(&interface_description);

let program_hash = T::Hashing::hash(&hash_input);
let deployer: T::AccountId = whitelisted_caller();
Expand All @@ -54,24 +54,24 @@ benchmarks! {
let value = CurrencyOf::<T>::minimum_balance().saturating_mul(1_000_000_000u32.into());
let _ = CurrencyOf::<T>::make_free_balance_be(&deployer, value);

}: _(RawOrigin::Signed(deployer.clone()), program.clone(), configuration_interface.clone())
}: _(RawOrigin::Signed(deployer.clone()), program.clone(), interface_description.clone())
verify {
assert_last_event::<T>(
Event::<T>::ProgramCreated {
deployer,
program_hash,
configuration_interface
interface_description
}.into()
);
}

remove_program {
let p in 0..T::MaxOwnedPrograms::get();
let program = vec![10];
let configuration_interface = vec![11];
let interface_description = vec![11];
let mut hash_input: Vec<u8> = vec![];
hash_input.extend(&program);
hash_input.extend(&configuration_interface);
hash_input.extend(&interface_description);

let program_hash = T::Hashing::hash(&hash_input);
let random_program = vec![11];
Expand All @@ -80,7 +80,7 @@ benchmarks! {

let value = CurrencyOf::<T>::minimum_balance().saturating_mul(1_000_000_000u32.into());
let _ = CurrencyOf::<T>::make_free_balance_be(&deployer, value);
<Programs<T>>::insert(program_hash.clone(), ProgramInfo {bytecode: program, configuration_interface, deployer: deployer.clone(), ref_counter: 0u128});
<Programs<T>>::insert(program_hash.clone(), ProgramInfo {bytecode: program, interface_description, 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();
Expand Down
22 changes: 11 additions & 11 deletions pallets/programs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,16 +94,16 @@ pub mod pallet {
pub struct ProgramInfo<AccountId> {
/// The bytecode of the program.
pub bytecode: Vec<u8>,
/// The type definition of the program
pub configuration_interface: Vec<u8>,
/// An interface description for the program (config, auxilary data, etc)
pub interface_description: Vec<u8>,
/// Deployer of the program
pub deployer: AccountId,
/// Accounts that use this program
pub ref_counter: u128,
}

/// Stores the program info for a given program hash.
/// A program hash is a combination of the bytecode and configuration_interface
/// A program hash is a combination of the bytecode and interface_description
#[pallet::storage]
#[pallet::getter(fn programs)]
pub type Programs<T: Config> =
Expand Down Expand Up @@ -132,7 +132,7 @@ pub mod pallet {
program_hash: T::Hash,

/// The new program type definition
configuration_interface: Vec<u8>,
interface_description: Vec<u8>,
},
/// The bytecode of a program was removed.
ProgramRemoved {
Expand Down Expand Up @@ -162,22 +162,22 @@ pub mod pallet {

#[pallet::call]
impl<T: Config> Pallet<T> {
/// Sets the program and uses hash of program and configuration_interface as key.
/// Sets the program and uses hash of program and interface_description as key.
///
/// Note that the caller becomes the deployer account.
#[pallet::call_index(0)]
#[pallet::weight({<T as Config>::WeightInfo::set_program()})]
pub fn set_program(
origin: OriginFor<T>,
new_program: Vec<u8>,
configuration_interface: Vec<u8>,
interface_description: Vec<u8>,
) -> DispatchResult {
let deployer = ensure_signed(origin)?;
let mut hash_input = vec![];
hash_input.extend(&new_program);
hash_input.extend(&configuration_interface);
hash_input.extend(&interface_description);
let program_hash = T::Hashing::hash(&hash_input);
let new_program_length = new_program.len() + configuration_interface.len();
let new_program_length = new_program.len() + interface_description.len();
ensure!(
new_program_length as u32 <= T::MaxBytecodeLength::get(),
Error::<T>::ProgramLengthExceeded
Expand All @@ -190,7 +190,7 @@ pub mod pallet {
program_hash,
&ProgramInfo {
bytecode: new_program.clone(),
configuration_interface: configuration_interface.clone(),
interface_description: interface_description.clone(),
deployer: deployer.clone(),
ref_counter: 0u128,
},
Expand All @@ -207,7 +207,7 @@ pub mod pallet {
Self::deposit_event(Event::ProgramCreated {
deployer,
program_hash,
configuration_interface,
interface_description,
});
Ok(())
}
Expand All @@ -228,7 +228,7 @@ pub mod pallet {
ensure!(old_program_info.ref_counter == 0, Error::<T>::ProgramInUse);
Self::unreserve_program_deposit(
&old_program_info.deployer,
old_program_info.bytecode.len() + old_program_info.configuration_interface.len(),
old_program_info.bytecode.len() + old_program_info.interface_description.len(),
);
let mut owned_programs_length = 0;
OwnedPrograms::<T>::try_mutate(
Expand Down
26 changes: 13 additions & 13 deletions pallets/programs/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,19 @@ fn set_program() {
new_test_ext().execute_with(|| {
let program = vec![10u8, 11u8];
let program_2 = vec![12u8, 13u8];
let configuration_interface = vec![14u8];
let interface_description = vec![14u8];
let too_long = vec![1u8, 2u8, 3u8, 4u8, 5u8];
let mut hash_input: Vec<u8> = vec![];
hash_input.extend(&program);
hash_input.extend(&configuration_interface);
hash_input.extend(&interface_description);

let program_hash = <Test as frame_system::Config>::Hashing::hash(&hash_input);
// can't pay deposit
assert_noop!(
ProgramsPallet::set_program(
RuntimeOrigin::signed(PROGRAM_MODIFICATION_ACCOUNT),
program.clone(),
configuration_interface.clone()
interface_description.clone()
),
BalancesError::<Test>::InsufficientBalance
);
Expand All @@ -49,11 +49,11 @@ fn set_program() {
assert_ok!(ProgramsPallet::set_program(
RuntimeOrigin::signed(PROGRAM_MODIFICATION_ACCOUNT),
program.clone(),
configuration_interface.clone()
interface_description.clone()
));
let program_result = ProgramInfo {
bytecode: program.clone(),
configuration_interface: configuration_interface.clone(),
interface_description: interface_description.clone(),
deployer: PROGRAM_MODIFICATION_ACCOUNT,
ref_counter: 0u128,
};
Expand All @@ -75,7 +75,7 @@ fn set_program() {
ProgramsPallet::set_program(
RuntimeOrigin::signed(PROGRAM_MODIFICATION_ACCOUNT),
program.clone(),
configuration_interface.clone()
interface_description.clone()
),
Error::<Test>::ProgramAlreadySet
);
Expand All @@ -85,7 +85,7 @@ fn set_program() {
ProgramsPallet::set_program(
RuntimeOrigin::signed(PROGRAM_MODIFICATION_ACCOUNT),
program_2.clone(),
configuration_interface.clone()
interface_description.clone()
),
Error::<Test>::TooManyProgramsOwned
);
Expand All @@ -94,7 +94,7 @@ fn set_program() {
ProgramsPallet::set_program(
RuntimeOrigin::signed(PROGRAM_MODIFICATION_ACCOUNT),
too_long,
configuration_interface
interface_description
),
Error::<Test>::ProgramLengthExceeded
);
Expand All @@ -105,10 +105,10 @@ fn set_program() {
fn remove_program() {
new_test_ext().execute_with(|| {
let program = vec![10u8, 11u8];
let configuration_interface = vec![14u8];
let interface_description = vec![14u8];
let mut hash_input: Vec<u8> = vec![];
hash_input.extend(&program);
hash_input.extend(&configuration_interface);
hash_input.extend(&interface_description);
let program_hash = <Test as frame_system::Config>::Hashing::hash(&hash_input);

// no program
Expand All @@ -125,7 +125,7 @@ fn remove_program() {
assert_ok!(ProgramsPallet::set_program(
RuntimeOrigin::signed(PROGRAM_MODIFICATION_ACCOUNT),
program.clone(),
configuration_interface.clone()
interface_description.clone()
));
assert_eq!(
ProgramsPallet::owned_programs(PROGRAM_MODIFICATION_ACCOUNT),
Expand Down Expand Up @@ -171,13 +171,13 @@ fn remove_program_fails_ref_count() {
new_test_ext().execute_with(|| {
let program = vec![10u8, 11u8];
let program_hash = <Test as frame_system::Config>::Hashing::hash(&program);
let configuration_interface = vec![14u8];
let interface_description = vec![14u8];

Programs::<Test>::insert(
program_hash,
ProgramInfo {
bytecode: program,
configuration_interface,
interface_description,
deployer: PROGRAM_MODIFICATION_ACCOUNT,
ref_counter: 1u128,
},
Expand Down
2 changes: 1 addition & 1 deletion pallets/propagation/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ fn knows_how_to_mock_several_http_calls() {
<Test as frame_system::Config>::Hash::default(),
ProgramInfo {
bytecode: vec![],
configuration_interface: vec![],
interface_description: vec![],
deployer: 1,
ref_counter: 0,
},
Expand Down
20 changes: 10 additions & 10 deletions pallets/relayer/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ benchmarks! {
register {
let p in 1 .. T::MaxProgramHashes::get();
let program = vec![0u8];
let configuration_interface = vec![1u8];
let interface_description = vec![1u8];
let program_hash = T::Hashing::hash(&program);
let programs_info = BoundedVec::try_from(vec![ProgramInstance {
program_pointer: program_hash,
Expand All @@ -81,7 +81,7 @@ benchmarks! {
.unwrap();

let program_modification_account: T::AccountId = whitelisted_caller();
Programs::<T>::insert(program_hash, ProgramInfo {bytecode: program, configuration_interface, deployer: program_modification_account.clone(), ref_counter: 0});
Programs::<T>::insert(program_hash, ProgramInfo {bytecode: program, interface_description, deployer: program_modification_account.clone(), ref_counter: 0});
let sig_req_account: T::AccountId = whitelisted_caller();
let balance = <T as pallet_staking_extension::Config>::Currency::minimum_balance() * 100u32.into();
let _ = <T as pallet_staking_extension::Config>::Currency::make_free_balance_be(&sig_req_account, balance);
Expand All @@ -95,13 +95,13 @@ benchmarks! {
let p in 1 .. T::MaxProgramHashes::get();
let program_modification_account: T::AccountId = whitelisted_caller();
let program = vec![0u8];
let configuration_interface = vec![1u8];
let interface_description = vec![1u8];
let program_hash = T::Hashing::hash(&program);
let programs_info = BoundedVec::try_from(vec![ProgramInstance {
program_pointer: program_hash,
program_config: vec![],
}]).unwrap();
Programs::<T>::insert(program_hash, ProgramInfo {bytecode: program, configuration_interface, deployer: program_modification_account.clone(), ref_counter: 1});
Programs::<T>::insert(program_hash, ProgramInfo {bytecode: program, interface_description, deployer: program_modification_account.clone(), ref_counter: 1});
let sig_req_account: T::AccountId = whitelisted_caller();
let balance = <T as pallet_staking_extension::Config>::Currency::minimum_balance() * 100u32.into();
let _ = <T as pallet_staking_extension::Config>::Currency::make_free_balance_be(&sig_req_account, balance);
Expand All @@ -123,7 +123,7 @@ benchmarks! {

let program_modification_account: T::AccountId = whitelisted_caller();
let program = vec![0u8];
let configuration_interface = vec![1u8];
let interface_description = vec![1u8];
let program_hash = T::Hashing::hash(&program);
let programs_info = BoundedVec::try_from(vec![ProgramInstance {
program_pointer: program_hash,
Expand All @@ -138,8 +138,8 @@ benchmarks! {
}; n as usize])
.unwrap();
let sig_req_account: T::AccountId = whitelisted_caller();
Programs::<T>::insert(program_hash, ProgramInfo {bytecode: program, configuration_interface: configuration_interface.clone(), deployer: program_modification_account.clone(), ref_counter: 0});
Programs::<T>::insert(new_program_hash, ProgramInfo {bytecode: new_program, configuration_interface, deployer: program_modification_account.clone(), ref_counter: o as u128});
Programs::<T>::insert(program_hash, ProgramInfo {bytecode: program, interface_description: interface_description.clone(), deployer: program_modification_account.clone(), ref_counter: 0});
Programs::<T>::insert(new_program_hash, ProgramInfo {bytecode: new_program, interface_description, deployer: program_modification_account.clone(), ref_counter: o as u128});
let balance = <T as pallet_staking_extension::Config>::Currency::minimum_balance() * 100u32.into();
let _ = <T as pallet_staking_extension::Config>::Currency::make_free_balance_be(&sig_req_account, balance);
<Registered<T>>::insert(
Expand All @@ -159,7 +159,7 @@ benchmarks! {
confirm_register_registering {
let c in 0 .. SIG_PARTIES as u32;
let program = vec![0u8];
let configuration_interface = vec![1u8];
let interface_description = vec![1u8];

let program_hash = T::Hashing::hash(&program);
let programs_info = BoundedVec::try_from(vec![ProgramInstance {
Expand Down Expand Up @@ -193,7 +193,7 @@ benchmarks! {
confirm_register_failed_registering {
let c in 0 .. SIG_PARTIES as u32;
let program = vec![0u8];
let configuration_interface = vec![1u8];
let interface_description = vec![1u8];

let program_hash = T::Hashing::hash(&program);
let programs_info = BoundedVec::try_from(vec![ProgramInstance {
Expand Down Expand Up @@ -230,7 +230,7 @@ benchmarks! {
confirm_register_registered {
let c in 0 .. SIG_PARTIES as u32;
let program = vec![0u8];
let configuration_interface = vec![1u8];
let interface_description = vec![1u8];
let program_hash = T::Hashing::hash(&program);
let programs_info = BoundedVec::try_from(vec![ProgramInstance {
program_pointer: program_hash,
Expand Down
Loading