replaced chunks with tuples in validator (#30499)
* replaced chunks with tuples in test validator * update Cargo.lock * replaced chunks with tuples in genesis * Update Cargo.lock
This commit is contained in:
parent
7361fe27f9
commit
5631685d30
|
@ -5551,6 +5551,7 @@ dependencies = [
|
||||||
"base64 0.13.0",
|
"base64 0.13.0",
|
||||||
"bincode",
|
"bincode",
|
||||||
"clap 2.33.3",
|
"clap 2.33.3",
|
||||||
|
"itertools",
|
||||||
"serde",
|
"serde",
|
||||||
"serde_json",
|
"serde_json",
|
||||||
"serde_yaml 0.9.13",
|
"serde_yaml 0.9.13",
|
||||||
|
@ -6957,6 +6958,7 @@ dependencies = [
|
||||||
"crossbeam-channel",
|
"crossbeam-channel",
|
||||||
"fd-lock",
|
"fd-lock",
|
||||||
"indicatif",
|
"indicatif",
|
||||||
|
"itertools",
|
||||||
"jsonrpc-core",
|
"jsonrpc-core",
|
||||||
"jsonrpc-core-client",
|
"jsonrpc-core-client",
|
||||||
"jsonrpc-derive",
|
"jsonrpc-derive",
|
||||||
|
|
|
@ -13,6 +13,7 @@ edition = { workspace = true }
|
||||||
base64 = { workspace = true }
|
base64 = { workspace = true }
|
||||||
bincode = { workspace = true }
|
bincode = { workspace = true }
|
||||||
clap = { workspace = true }
|
clap = { workspace = true }
|
||||||
|
itertools = { workspace = true }
|
||||||
serde = { workspace = true }
|
serde = { workspace = true }
|
||||||
serde_json = { workspace = true }
|
serde_json = { workspace = true }
|
||||||
serde_yaml = { workspace = true }
|
serde_yaml = { workspace = true }
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
|
|
||||||
use {
|
use {
|
||||||
clap::{crate_description, crate_name, value_t, value_t_or_exit, App, Arg, ArgMatches},
|
clap::{crate_description, crate_name, value_t, value_t_or_exit, App, Arg, ArgMatches},
|
||||||
|
itertools::Itertools,
|
||||||
solana_clap_utils::{
|
solana_clap_utils::{
|
||||||
input_parsers::{
|
input_parsers::{
|
||||||
cluster_type_of, pubkey_of, pubkeys_of, unix_timestamp_from_rfc3339_datetime,
|
cluster_type_of, pubkey_of, pubkeys_of, unix_timestamp_from_rfc3339_datetime,
|
||||||
|
@ -615,85 +616,76 @@ fn main() -> Result<(), Box<dyn error::Error>> {
|
||||||
};
|
};
|
||||||
|
|
||||||
if let Some(values) = matches.values_of("bpf_program") {
|
if let Some(values) = matches.values_of("bpf_program") {
|
||||||
let values: Vec<&str> = values.collect::<Vec<_>>();
|
for (address, loader, program) in values.tuples() {
|
||||||
for address_loader_program in values.chunks(3) {
|
let address = parse_address(address, "address");
|
||||||
match address_loader_program {
|
let loader = parse_address(loader, "loader");
|
||||||
[address, loader, program] => {
|
let program_data = parse_program_data(program);
|
||||||
let address = parse_address(address, "address");
|
genesis_config.add_account(
|
||||||
let loader = parse_address(loader, "loader");
|
address,
|
||||||
let program_data = parse_program_data(program);
|
AccountSharedData::from(Account {
|
||||||
genesis_config.add_account(
|
lamports: genesis_config.rent.minimum_balance(program_data.len()),
|
||||||
address,
|
data: program_data,
|
||||||
AccountSharedData::from(Account {
|
executable: true,
|
||||||
lamports: genesis_config.rent.minimum_balance(program_data.len()),
|
owner: loader,
|
||||||
data: program_data,
|
rent_epoch: 0,
|
||||||
executable: true,
|
}),
|
||||||
owner: loader,
|
);
|
||||||
rent_epoch: 0,
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
_ => unreachable!(),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(values) = matches.values_of("upgradeable_program") {
|
if let Some(values) = matches.values_of("upgradeable_program") {
|
||||||
let values: Vec<&str> = values.collect::<Vec<_>>();
|
for (address, loader, program, upgrade_authority) in values.tuples() {
|
||||||
for address_loader_program_upgrade_authority in values.chunks(4) {
|
let address = parse_address(address, "address");
|
||||||
match address_loader_program_upgrade_authority {
|
let loader = parse_address(loader, "loader");
|
||||||
[address, loader, program, upgrade_authority] => {
|
let program_data_elf = parse_program_data(program);
|
||||||
let address = parse_address(address, "address");
|
let upgrade_authority_address = if upgrade_authority == "none" {
|
||||||
let loader = parse_address(loader, "loader");
|
Pubkey::default()
|
||||||
let program_data_elf = parse_program_data(program);
|
} else {
|
||||||
let upgrade_authority_address = if *upgrade_authority == "none" {
|
upgrade_authority.parse::<Pubkey>().unwrap_or_else(|_| {
|
||||||
Pubkey::default()
|
read_keypair_file(upgrade_authority)
|
||||||
} else {
|
.map(|keypair| keypair.pubkey())
|
||||||
upgrade_authority.parse::<Pubkey>().unwrap_or_else(|_| {
|
.unwrap_or_else(|err| {
|
||||||
read_keypair_file(upgrade_authority).map(|keypair| keypair.pubkey()).unwrap_or_else(|err| {
|
eprintln!(
|
||||||
eprintln!("Error: invalid upgrade_authority {upgrade_authority}: {err}");
|
"Error: invalid upgrade_authority {upgrade_authority}: {err}"
|
||||||
process::exit(1);
|
);
|
||||||
})
|
process::exit(1);
|
||||||
})
|
|
||||||
};
|
|
||||||
|
|
||||||
let (programdata_address, _) =
|
|
||||||
Pubkey::find_program_address(&[address.as_ref()], &loader);
|
|
||||||
let mut program_data =
|
|
||||||
bincode::serialize(&UpgradeableLoaderState::ProgramData {
|
|
||||||
slot: 0,
|
|
||||||
upgrade_authority_address: Some(upgrade_authority_address),
|
|
||||||
})
|
})
|
||||||
.unwrap();
|
})
|
||||||
program_data.extend_from_slice(&program_data_elf);
|
};
|
||||||
genesis_config.add_account(
|
|
||||||
programdata_address,
|
|
||||||
AccountSharedData::from(Account {
|
|
||||||
lamports: genesis_config.rent.minimum_balance(program_data.len()),
|
|
||||||
data: program_data,
|
|
||||||
owner: loader,
|
|
||||||
executable: false,
|
|
||||||
rent_epoch: 0,
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
|
|
||||||
let program_data = bincode::serialize(&UpgradeableLoaderState::Program {
|
let (programdata_address, _) =
|
||||||
programdata_address,
|
Pubkey::find_program_address(&[address.as_ref()], &loader);
|
||||||
})
|
let mut program_data = bincode::serialize(&UpgradeableLoaderState::ProgramData {
|
||||||
.unwrap();
|
slot: 0,
|
||||||
genesis_config.add_account(
|
upgrade_authority_address: Some(upgrade_authority_address),
|
||||||
address,
|
})
|
||||||
AccountSharedData::from(Account {
|
.unwrap();
|
||||||
lamports: genesis_config.rent.minimum_balance(program_data.len()),
|
program_data.extend_from_slice(&program_data_elf);
|
||||||
data: program_data,
|
genesis_config.add_account(
|
||||||
owner: loader,
|
programdata_address,
|
||||||
executable: true,
|
AccountSharedData::from(Account {
|
||||||
rent_epoch: 0,
|
lamports: genesis_config.rent.minimum_balance(program_data.len()),
|
||||||
}),
|
data: program_data,
|
||||||
);
|
owner: loader,
|
||||||
}
|
executable: false,
|
||||||
_ => unreachable!(),
|
rent_epoch: 0,
|
||||||
}
|
}),
|
||||||
|
);
|
||||||
|
|
||||||
|
let program_data = bincode::serialize(&UpgradeableLoaderState::Program {
|
||||||
|
programdata_address,
|
||||||
|
})
|
||||||
|
.unwrap();
|
||||||
|
genesis_config.add_account(
|
||||||
|
address,
|
||||||
|
AccountSharedData::from(Account {
|
||||||
|
lamports: genesis_config.rent.minimum_balance(program_data.len()),
|
||||||
|
data: program_data,
|
||||||
|
owner: loader,
|
||||||
|
executable: true,
|
||||||
|
rent_epoch: 0,
|
||||||
|
}),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6162,6 +6162,7 @@ dependencies = [
|
||||||
"crossbeam-channel",
|
"crossbeam-channel",
|
||||||
"fd-lock",
|
"fd-lock",
|
||||||
"indicatif",
|
"indicatif",
|
||||||
|
"itertools",
|
||||||
"jsonrpc-core",
|
"jsonrpc-core",
|
||||||
"jsonrpc-core-client",
|
"jsonrpc-core-client",
|
||||||
"jsonrpc-derive",
|
"jsonrpc-derive",
|
||||||
|
|
|
@ -18,6 +18,7 @@ core_affinity = { workspace = true }
|
||||||
crossbeam-channel = { workspace = true }
|
crossbeam-channel = { workspace = true }
|
||||||
fd-lock = { workspace = true }
|
fd-lock = { workspace = true }
|
||||||
indicatif = { workspace = true }
|
indicatif = { workspace = true }
|
||||||
|
itertools = { workspace = true }
|
||||||
jsonrpc-core = { workspace = true }
|
jsonrpc-core = { workspace = true }
|
||||||
jsonrpc-core-client = { workspace = true, features = ["ipc"] }
|
jsonrpc-core-client = { workspace = true, features = ["ipc"] }
|
||||||
jsonrpc-derive = { workspace = true }
|
jsonrpc-derive = { workspace = true }
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
use {
|
use {
|
||||||
clap::{crate_name, value_t, value_t_or_exit, values_t_or_exit},
|
clap::{crate_name, value_t, value_t_or_exit, values_t_or_exit},
|
||||||
crossbeam_channel::unbounded,
|
crossbeam_channel::unbounded,
|
||||||
|
itertools::Itertools,
|
||||||
log::*,
|
log::*,
|
||||||
solana_clap_utils::{
|
solana_clap_utils::{
|
||||||
input_parsers::{pubkey_of, pubkeys_of, value_of},
|
input_parsers::{pubkey_of, pubkeys_of, value_of},
|
||||||
|
@ -203,79 +204,61 @@ fn main() {
|
||||||
|
|
||||||
let mut upgradeable_programs_to_load = vec![];
|
let mut upgradeable_programs_to_load = vec![];
|
||||||
if let Some(values) = matches.values_of("bpf_program") {
|
if let Some(values) = matches.values_of("bpf_program") {
|
||||||
let values: Vec<&str> = values.collect::<Vec<_>>();
|
for (address, program) in values.into_iter().tuples() {
|
||||||
for address_program in values.chunks(2) {
|
let address = parse_address(address, "address");
|
||||||
match address_program {
|
let program_path = parse_program_path(program);
|
||||||
[address, program] => {
|
|
||||||
let address = parse_address(address, "address");
|
|
||||||
let program_path = parse_program_path(program);
|
|
||||||
|
|
||||||
upgradeable_programs_to_load.push(UpgradeableProgramInfo {
|
upgradeable_programs_to_load.push(UpgradeableProgramInfo {
|
||||||
program_id: address,
|
program_id: address,
|
||||||
loader: solana_sdk::bpf_loader_upgradeable::id(),
|
loader: solana_sdk::bpf_loader_upgradeable::id(),
|
||||||
upgrade_authority: Pubkey::default(),
|
upgrade_authority: Pubkey::default(),
|
||||||
program_path,
|
program_path,
|
||||||
});
|
});
|
||||||
}
|
|
||||||
_ => unreachable!(),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(values) = matches.values_of("upgradeable_program") {
|
if let Some(values) = matches.values_of("upgradeable_program") {
|
||||||
let values: Vec<&str> = values.collect::<Vec<_>>();
|
for (address, program, upgrade_authority) in
|
||||||
for address_program_upgrade_authority in values.chunks(3) {
|
values.into_iter().tuples::<(&str, &str, &str)>()
|
||||||
match address_program_upgrade_authority {
|
{
|
||||||
[address, program, upgrade_authority] => {
|
let address = parse_address(address, "address");
|
||||||
let address = parse_address(address, "address");
|
let program_path = parse_program_path(program);
|
||||||
let program_path = parse_program_path(program);
|
let upgrade_authority_address = if upgrade_authority == "none" {
|
||||||
let upgrade_authority_address = if *upgrade_authority == "none" {
|
Pubkey::default()
|
||||||
Pubkey::default()
|
} else {
|
||||||
} else {
|
upgrade_authority
|
||||||
upgrade_authority
|
.parse::<Pubkey>()
|
||||||
.parse::<Pubkey>()
|
.or_else(|_| {
|
||||||
.or_else(|_| {
|
read_keypair_file(upgrade_authority).map(|keypair| keypair.pubkey())
|
||||||
read_keypair_file(upgrade_authority).map(|keypair| keypair.pubkey())
|
})
|
||||||
})
|
.unwrap_or_else(|err| {
|
||||||
.unwrap_or_else(|err| {
|
println!("Error: invalid upgrade_authority {upgrade_authority}: {err}");
|
||||||
println!(
|
exit(1);
|
||||||
"Error: invalid upgrade_authority {upgrade_authority}: {err}"
|
})
|
||||||
);
|
};
|
||||||
exit(1);
|
|
||||||
})
|
|
||||||
};
|
|
||||||
|
|
||||||
upgradeable_programs_to_load.push(UpgradeableProgramInfo {
|
upgradeable_programs_to_load.push(UpgradeableProgramInfo {
|
||||||
program_id: address,
|
program_id: address,
|
||||||
loader: solana_sdk::bpf_loader_upgradeable::id(),
|
loader: solana_sdk::bpf_loader_upgradeable::id(),
|
||||||
upgrade_authority: upgrade_authority_address,
|
upgrade_authority: upgrade_authority_address,
|
||||||
program_path,
|
program_path,
|
||||||
});
|
});
|
||||||
}
|
|
||||||
_ => unreachable!(),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut accounts_to_load = vec![];
|
let mut accounts_to_load = vec![];
|
||||||
if let Some(values) = matches.values_of("account") {
|
if let Some(values) = matches.values_of("account") {
|
||||||
let values: Vec<&str> = values.collect::<Vec<_>>();
|
for (address, filename) in values.into_iter().tuples() {
|
||||||
for address_filename in values.chunks(2) {
|
let address = if address == "-" {
|
||||||
match address_filename {
|
None
|
||||||
[address, filename] => {
|
} else {
|
||||||
let address = if *address == "-" {
|
Some(address.parse::<Pubkey>().unwrap_or_else(|err| {
|
||||||
None
|
println!("Error: invalid address {address}: {err}");
|
||||||
} else {
|
exit(1);
|
||||||
Some(address.parse::<Pubkey>().unwrap_or_else(|err| {
|
}))
|
||||||
println!("Error: invalid address {address}: {err}");
|
};
|
||||||
exit(1);
|
|
||||||
}))
|
|
||||||
};
|
|
||||||
|
|
||||||
accounts_to_load.push(AccountInfo { address, filename });
|
accounts_to_load.push(AccountInfo { address, filename });
|
||||||
}
|
|
||||||
_ => unreachable!(),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue