-
Notifications
You must be signed in to change notification settings - Fork 2
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
Add a programs version #1045
Add a programs version #1045
Changes from all commits
d369b6e
d2f37d4
7a275fc
b119b5e
19e0cc5
8de1f5f
7b9c281
6e6fa9a
03daff8
9660576
5634f19
3a5490d
1d0a878
1ebcd37
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -76,3 +76,6 @@ pub const SIGNER_THRESHOLD: u8 = 2; | |
|
||
/// For testing to line up chain mock data and reshare_test | ||
pub const TEST_RESHARE_BLOCK_NUMBER: u32 = 5; | ||
|
||
/// Program version number, must be incremented if version number changes | ||
pub const PROGRAM_VERSION_NUMBER: u8 = 0; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We don't yet have a check for this when evaluating the program, but when we do, i think it might make sense for this constant to be exported by The argument not to would be if we need this constant in the program's pallet, so that we can refuse to accept programs with an unsupported version number. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I struggled with this decision a little, I came to this for a few reasons, one was it is a PITA the way we are pulling stuff into the templates to make a change and see it reflected. Also we would also have any changes need to be reflected in core before it is usable, and this keeps our updates for releases to core There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. #1056 opened this |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,6 +30,7 @@ use entropy_client::{ | |
VERIFYING_KEY_LENGTH, | ||
}, | ||
}; | ||
pub use entropy_shared::PROGRAM_VERSION_NUMBER; | ||
HCastano marked this conversation as resolved.
Show resolved
Hide resolved
|
||
use sp_core::{sr25519, Hasher, Pair}; | ||
use sp_runtime::traits::BlakeTwo256; | ||
use std::{fs, path::PathBuf}; | ||
|
@@ -74,6 +75,8 @@ enum CliCommand { | |
/// interface. If no such file exists, it is assumed the program has no configuration | ||
/// interface. | ||
programs: Vec<String>, | ||
/// Option of version numbers to go with the programs, will default to 0 if None | ||
program_version_numbers: Option<Vec<u8>>, | ||
/// A name or mnemonic from which to derive a program modification keypair. | ||
/// This is used to send the register extrinsic so it must be funded | ||
/// If giving a name it must be preceded with "//", eg: "--mnemonic-option //Alice" | ||
|
@@ -109,6 +112,8 @@ enum CliCommand { | |
/// interface. If no such file exists, it is assumed the program has no configuration | ||
/// interface. | ||
programs: Vec<String>, | ||
/// Option of version numbers to go with the programs, will default to 0 if None | ||
program_version_numbers: Option<Vec<u8>>, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm this is not going to be very nice to use, but i can't think of a better suggestion There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ya this took me a bit, was easy until I realized launch a program was possible in all these calls, this was my best solution, we can play with it in the future and change it if it sucks |
||
/// The mnemonic to use for the call | ||
#[arg(short, long)] | ||
mnemonic_option: Option<String>, | ||
|
@@ -121,6 +126,8 @@ enum CliCommand { | |
config_interface_file: Option<PathBuf>, | ||
/// The path to a file containing the program aux interface (defaults to empty) | ||
aux_data_interface_file: Option<PathBuf>, | ||
/// The version number of the program's runtime you compiled with | ||
program_version_number: Option<u8>, | ||
/// The mnemonic to use for the call | ||
#[arg(short, long)] | ||
mnemonic_option: Option<String>, | ||
|
@@ -170,6 +177,7 @@ pub async fn run_command( | |
program_file_option: Option<PathBuf>, | ||
config_interface_file_option: Option<PathBuf>, | ||
aux_data_interface_file_option: Option<PathBuf>, | ||
program_version_number_option: Option<u8>, | ||
) -> anyhow::Result<String> { | ||
let cli = Cli::parse(); | ||
|
||
|
@@ -183,7 +191,7 @@ pub async fn run_command( | |
let rpc = get_rpc(&endpoint_addr).await?; | ||
|
||
match cli.command { | ||
CliCommand::Register { mnemonic_option, programs } => { | ||
CliCommand::Register { mnemonic_option, programs, program_version_numbers } => { | ||
let mnemonic = if let Some(mnemonic_option) = mnemonic_option { | ||
mnemonic_option | ||
} else { | ||
|
@@ -196,9 +204,19 @@ pub async fn run_command( | |
|
||
let mut programs_info = vec![]; | ||
|
||
for program in programs { | ||
for (i, program) in programs.into_iter().enumerate() { | ||
let program_version_number = | ||
program_version_numbers.as_ref().map_or(0u8, |versions| versions[i]); | ||
programs_info.push( | ||
Program::from_hash_or_filename(&api, &rpc, &program_keypair, program).await?.0, | ||
Program::from_hash_or_filename( | ||
&api, | ||
&rpc, | ||
&program_keypair, | ||
program, | ||
program_version_number, | ||
) | ||
.await? | ||
.0, | ||
); | ||
} | ||
|
||
|
@@ -248,6 +266,7 @@ pub async fn run_command( | |
program_file, | ||
config_interface_file, | ||
aux_data_interface_file, | ||
program_version_number, | ||
} => { | ||
let mnemonic = if let Some(mnemonic_option) = mnemonic_option { | ||
mnemonic_option | ||
|
@@ -276,6 +295,11 @@ pub async fn run_command( | |
)?, | ||
}; | ||
|
||
let program_version_number = match program_version_number_option { | ||
Some(program_version_number) => program_version_number, | ||
None => program_version_number.unwrap_or(0u8), | ||
}; | ||
|
||
let hash = store_program( | ||
&api, | ||
&rpc, | ||
|
@@ -284,6 +308,7 @@ pub async fn run_command( | |
config_interface, | ||
aux_data_interface, | ||
vec![], | ||
program_version_number, | ||
) | ||
.await?; | ||
Ok(format!("Program stored {hash}")) | ||
|
@@ -305,7 +330,12 @@ pub async fn run_command( | |
|
||
Ok("Program removed".to_string()) | ||
}, | ||
CliCommand::UpdatePrograms { signature_verifying_key, mnemonic_option, programs } => { | ||
CliCommand::UpdatePrograms { | ||
signature_verifying_key, | ||
mnemonic_option, | ||
programs, | ||
program_version_numbers, | ||
} => { | ||
let mnemonic = if let Some(mnemonic_option) = mnemonic_option { | ||
mnemonic_option | ||
} else { | ||
|
@@ -315,9 +345,20 @@ pub async fn run_command( | |
println!("Program account: {}", program_keypair.public()); | ||
|
||
let mut programs_info = Vec::new(); | ||
for program in programs { | ||
|
||
for (i, program) in programs.into_iter().enumerate() { | ||
let program_version_number = | ||
program_version_numbers.as_ref().map_or(0u8, |versions| versions[i]); | ||
programs_info.push( | ||
Program::from_hash_or_filename(&api, &rpc, &program_keypair, program).await?.0, | ||
Program::from_hash_or_filename( | ||
&api, | ||
&rpc, | ||
&program_keypair, | ||
program, | ||
program_version_number, | ||
) | ||
.await? | ||
.0, | ||
); | ||
} | ||
|
||
|
@@ -459,6 +500,7 @@ impl Program { | |
rpc: &LegacyRpcMethods<EntropyConfig>, | ||
keypair: &sr25519::Pair, | ||
hash_or_filename: String, | ||
program_version_number: u8, | ||
) -> anyhow::Result<Self> { | ||
match hex::decode(hash_or_filename.clone()) { | ||
Ok(hash) => { | ||
|
@@ -474,10 +516,15 @@ impl Program { | |
}; | ||
Ok(Self::new(H256(hash_32), configuration)) | ||
}, | ||
Err(_) => Self::from_file(api, rpc, keypair, hash_or_filename).await, | ||
Err(_) => { | ||
Self::from_file(api, rpc, keypair, hash_or_filename, program_version_number) | ||
.await | ||
}, | ||
} | ||
}, | ||
Err(_) => Self::from_file(api, rpc, keypair, hash_or_filename).await, | ||
Err(_) => { | ||
Self::from_file(api, rpc, keypair, hash_or_filename, program_version_number).await | ||
}, | ||
} | ||
} | ||
|
||
|
@@ -488,6 +535,7 @@ impl Program { | |
rpc: &LegacyRpcMethods<EntropyConfig>, | ||
keypair: &sr25519::Pair, | ||
filename: String, | ||
program_version_number: u8, | ||
) -> anyhow::Result<Self> { | ||
let program_bytecode = fs::read(&filename)?; | ||
|
||
|
@@ -526,6 +574,7 @@ impl Program { | |
config_description, | ||
auxiliary_data_schema, | ||
vec![], | ||
program_version_number, | ||
) | ||
.await | ||
{ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -317,6 +317,7 @@ pub async fn store_program_and_register( | |
vec![], | ||
vec![], | ||
vec![], | ||
0u8, | ||
) | ||
.await | ||
.unwrap(); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -198,6 +198,7 @@ async fn test_reshare() { | |
vec![], | ||
vec![], | ||
vec![], | ||
0u8, | ||
) | ||
.await | ||
.unwrap(); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -64,6 +64,7 @@ async fn integration_test_register_and_sign() { | |
vec![], | ||
vec![], | ||
vec![], | ||
0u8, | ||
) | ||
.await | ||
.unwrap(); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -74,6 +74,7 @@ async fn integration_test_sign_eth_tx() { | |
vec![], | ||
vec![], | ||
vec![], | ||
0u8, | ||
) | ||
.await | ||
.unwrap(); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe time to couple the input data