Skip to content

Commit

Permalink
Update programs to accespt multiple oracle data
Browse files Browse the repository at this point in the history
  • Loading branch information
JesseAbram committed Nov 6, 2024
1 parent 2acaeff commit 0f94fe1
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 23 deletions.
6 changes: 2 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file modified crates/client/entropy_metadata.scale
Binary file not shown.
2 changes: 1 addition & 1 deletion crates/threshold-signature-server/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ entropy-client={ version="0.3.0-rc.1", path="../client", default-features=false,
] }

# Programs
entropy-programs-runtime="0.10.0"
entropy-programs-runtime={ git="https://github.com/entropyxyz/programs.git", branch="Allow-multiple-oracle-inputs" }

# Logging
tracing ="0.1.37"
Expand Down
17 changes: 11 additions & 6 deletions crates/threshold-signature-server/src/helpers/substrate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,17 @@ pub async fn get_program(
pub async fn get_oracle_data(
api: &OnlineClient<EntropyConfig>,
rpc: &LegacyRpcMethods<EntropyConfig>,
program_oracle_data: Vec<u8>,
) -> Result<Vec<u8>, UserErr> {
let oracle_data_call = entropy::storage().oracle().oracle_data(BoundedVec(program_oracle_data));
let oracle_info =
query_chain(api, rpc, oracle_data_call, None).await?.unwrap_or(BoundedVec(vec![]));
Ok(oracle_info.0)
program_oracle_datas: Vec<Vec<u8>>,
) -> Result<Vec<Vec<u8>>, UserErr> {
let mut oracle_infos = vec![];
for program_oracle_data in program_oracle_datas {
let oracle_data_call =
entropy::storage().oracle().oracle_data(BoundedVec(program_oracle_data));
let oracle_info =
query_chain(api, rpc, oracle_data_call, None).await?.unwrap_or(BoundedVec(vec![]));
oracle_infos.push(oracle_info.0);
}
Ok(oracle_infos)
}

/// Takes Stash keys and returns validator info from chain
Expand Down
2 changes: 1 addition & 1 deletion crates/threshold-signature-server/src/user/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -689,7 +689,7 @@ pub async fn pre_sign_checks(

for (i, program_data) in user_details.programs_data.0.iter().enumerate() {
let program_info = get_program(api, rpc, &program_data.program_pointer).await?;
let oracle_data = get_oracle_data(api, rpc, program_info.oracle_data_pointer).await?;
let oracle_data = get_oracle_data(api, rpc, program_info.oracle_data_pointers).await?;
let auxilary_data = auxilary_data_vec[i].as_ref().map(hex::decode).transpose()?;
let signature_request = SignatureRequest { message: message.clone(), auxilary_data };
runtime.evaluate(
Expand Down
25 changes: 14 additions & 11 deletions pallets/programs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ pub mod pallet {
configuration_schema: program_info.2.clone(),
auxiliary_data_schema: program_info.3.clone(),
deployer: program_info.4.clone(),
oracle_data_pointer: vec![],
oracle_data_pointers: vec![],
ref_counter: program_info.5,
version_number: 0,
},
Expand Down Expand Up @@ -138,8 +138,8 @@ pub mod pallet {
/// [JSON Schema](https://json-schema.org/) in order to simplify the life of off-chain
/// actors.
pub auxiliary_data_schema: Vec<u8>,
/// The location of the oracle data needed for this program
pub oracle_data_pointer: Vec<u8>,
/// The locations of the oracle data needed for this program
pub oracle_data_pointers: Vec<Vec<u8>>,
/// Deployer of the program
pub deployer: AccountId,
/// Accounts that use this program
Expand Down Expand Up @@ -184,8 +184,8 @@ pub mod pallet {
/// The new program auxiliary data schema.
auxiliary_data_schema: Vec<u8>,

/// The oracle data location needed for the program
oracle_data_pointer: Vec<u8>,
/// The oracle data locations needed for the program
oracle_data_pointers: Vec<Vec<u8>>,

/// The version number of runtime for which the program was written
version_number: u8,
Expand Down Expand Up @@ -230,24 +230,26 @@ pub mod pallet {
new_program: Vec<u8>,
configuration_schema: Vec<u8>,
auxiliary_data_schema: Vec<u8>,
oracle_data_pointer: Vec<u8>,
oracle_data_pointers: Vec<Vec<u8>>,
version_number: u8,
) -> DispatchResult {
let deployer = ensure_signed(origin)?;
let mut hash_input = vec![];
hash_input.extend(&new_program);
hash_input.extend(&configuration_schema);
hash_input.extend(&auxiliary_data_schema);
hash_input.extend(&oracle_data_pointer);
// TODO: fix
// hash_input.extend(&oracle_data_pointers);
hash_input.extend(&vec![version_number]);
let program_hash = T::Hashing::hash(&hash_input);
// TODO: handle length check here better
let new_program_length = new_program
.len()
.checked_add(configuration_schema.len())
.ok_or(Error::<T>::ArithmeticError)?
.checked_add(auxiliary_data_schema.len())
.ok_or(Error::<T>::ArithmeticError)?
.checked_add(oracle_data_pointer.len())
.checked_add(oracle_data_pointers.len())
.ok_or(Error::<T>::ArithmeticError)?;
ensure!(
new_program_length as u32 <= T::MaxBytecodeLength::get(),
Expand All @@ -263,7 +265,7 @@ pub mod pallet {
bytecode: new_program.clone(),
configuration_schema: configuration_schema.clone(),
auxiliary_data_schema: auxiliary_data_schema.clone(),
oracle_data_pointer: oracle_data_pointer.clone(),
oracle_data_pointers: oracle_data_pointers.clone(),
deployer: deployer.clone(),
ref_counter: 0u128,
version_number,
Expand All @@ -283,7 +285,7 @@ pub mod pallet {
program_hash,
configuration_schema,
auxiliary_data_schema,
oracle_data_pointer,
oracle_data_pointers,
version_number,
});
Ok(())
Expand All @@ -303,12 +305,13 @@ pub mod pallet {
Self::programs(program_hash).ok_or(Error::<T>::NoProgramDefined)?;
ensure!(old_program_info.deployer == deployer, Error::<T>::NotAuthorized);
ensure!(old_program_info.ref_counter == 0, Error::<T>::ProgramInUse);
// TODO: handle length check here better
Self::unreserve_program_deposit(
&old_program_info.deployer,
old_program_info.bytecode.len()
+ old_program_info.configuration_schema.len()
+ old_program_info.auxiliary_data_schema.len()
+ old_program_info.oracle_data_pointer.len(),
+ old_program_info.oracle_data_pointers.len(),
);
let mut owned_programs_length = 0;
OwnedPrograms::<T>::try_mutate(
Expand Down

0 comments on commit 0f94fe1

Please sign in to comment.