From 437db89f02d0213342aa694fed2b8dcd2d0b7275 Mon Sep 17 00:00:00 2001 From: mich-master Date: Thu, 14 Jul 2022 15:08:26 +0300 Subject: [PATCH] #52 Implement create-start-evm Subcommand --- governance-lib/src/proposal.rs | 38 +++++++-------- launch-script/src/main.rs | 12 ++++- .../src/proposals/create_treasury_pool.rs | 48 ------------------- .../src/proposals/create_upgrade_evm.rs | 46 +++++++----------- launch-script/src/proposals/mod.rs | 3 +- run-tests.sh | 26 +++++----- testing.cfg | 2 +- 7 files changed, 62 insertions(+), 113 deletions(-) diff --git a/governance-lib/src/proposal.rs b/governance-lib/src/proposal.rs index ac3e53f..a7bfb07 100644 --- a/governance-lib/src/proposal.rs +++ b/governance-lib/src/proposal.rs @@ -31,8 +31,6 @@ use { std::fmt, }; -pub const COMPUTE_BUDGET_UNITS: u32 = 1_200_000; - #[derive(Debug)] pub struct Proposal<'a> { pub governance: &'a Governance<'a>, @@ -157,14 +155,14 @@ impl<'a> Proposal<'a> { ) } - pub fn execute_transactions(&self, option_index: u8) -> ClientResult> { + pub fn execute_transactions(&self, option_index: u8, compute_budget_opt: Option) -> ClientResult> { let mut signatures = vec!(); let mut index = 0; while let Some(proposal_transaction) = self.get_proposal_transaction_data(option_index, index)? { if proposal_transaction.execution_status == TransactionExecutionStatus::None { //println!("Execute proposal transaction: {} {} =====================", option_index, index); - signatures.push(self._execute_transaction(&proposal_transaction)?); + signatures.push(self._execute_transaction(&proposal_transaction,compute_budget_opt)?); } index += 1; } @@ -176,7 +174,7 @@ impl<'a> Proposal<'a> { // self._execute_transaction(&proposal_transaction) // } - fn _execute_transaction(&self, proposal_transaction: &ProposalTransactionV2) -> ClientResult { + fn _execute_transaction(&self, proposal_transaction: &ProposalTransactionV2, compute_budget_opt: Option) -> ClientResult { //println!("Proposal transaction: {:?}", proposal_transaction); let mut accounts = vec!(); for instruction in &proposal_transaction.instructions { @@ -193,21 +191,23 @@ impl<'a> Proposal<'a> { //println!("Proposal: {}", self.proposal_address); //println!("Execute transaction with accounts {:?}", accounts); - self.governance.realm.client.send_and_confirm_transaction_with_payer_only( - &[ - ComputeBudgetInstruction::set_compute_unit_limit(COMPUTE_BUDGET_UNITS), - execute_transaction( - &self.governance.realm.program_id, - &self.governance.governance_address, - &self.proposal_address, - &self.get_proposal_transaction_address( - proposal_transaction.option_index, - proposal_transaction.transaction_index), - &self.governance.governance_address, // Dummy account to call execute_transaction (bug in instruction.rs implementation) - &accounts, - ), - ] + let mut instructions: Vec = Vec::new(); + if let Some(compute_budget) = compute_budget_opt { + instructions.push(ComputeBudgetInstruction::set_compute_unit_limit(compute_budget)); + }; + instructions.push( + execute_transaction( + &self.governance.realm.program_id, + &self.governance.governance_address, + &self.proposal_address, + &self.get_proposal_transaction_address( + proposal_transaction.option_index, + proposal_transaction.transaction_index), + &self.governance.governance_address, // Dummy account to call execute_transaction (bug in instruction.rs implementation) + &accounts, ) + ); + self.governance.realm.client.send_and_confirm_transaction_with_payer_only(&instructions) } pub fn finalize_vote(&self, proposal_owner_record: &Pubkey) -> ClientResult { diff --git a/launch-script/src/main.rs b/launch-script/src/main.rs index b17bbbc..afbc2fa 100644 --- a/launch-script/src/main.rs +++ b/launch-script/src/main.rs @@ -323,6 +323,13 @@ fn main() { ) .subcommand(SubCommand::with_name("execute") .about("Execute proposal (after approve)") + .arg( + Arg::with_name("compute-units") + .long("compute-units") + .takes_value(true) + .value_name("COMPUTE_UNITS") + .help("Compute Budget Units") + ) ) ).get_matches(); @@ -463,7 +470,10 @@ fn main() { finalize_vote_proposal(&wallet, &client, &proposal, verbose).unwrap() } "execute" => { - execute_proposal(&wallet, &client, &proposal, verbose).unwrap() + let compute_budget_opt: Option = cmd_matches + .value_of("compute-units") + .and_then(|v| v.parse::().ok() ); + execute_proposal(&wallet, &client, &proposal, compute_budget_opt, verbose).unwrap() } _ => unreachable!(), } diff --git a/launch-script/src/proposals/create_treasury_pool.rs b/launch-script/src/proposals/create_treasury_pool.rs index a0ee1c5..0234c1c 100644 --- a/launch-script/src/proposals/create_treasury_pool.rs +++ b/launch-script/src/proposals/create_treasury_pool.rs @@ -2,10 +2,6 @@ // Create collateral pool accounts // ========================================================================= -// use solana_sdk::{ -// signer::keypair::Keypair, -// system_instruction::create_account, -// }; use crate::prelude::*; const TREASURY_POOL_ACCOUNT_COUNT: u32 = 10; @@ -26,7 +22,6 @@ pub fn create_collateral_pool_accounts(wallet: &Wallet, client: &Client, transac println!("Maintenance DAO Address: {:?}", maintenance_governance_pubkey); println!("Maintenance Record Address: {:?}", maintenance_record_pubkey); - // println!("Proposal Governance Address: {:?}", transaction_inserter.proposal.governance.governance_address); let minimum_balance_for_rent_exemption = cfg.client.get_minimum_balance_for_rent_exemption(0).unwrap(); @@ -37,38 +32,6 @@ pub fn create_collateral_pool_accounts(wallet: &Wallet, client: &Client, transac verbose: transaction_inserter.verbose, }; - // let internal_payer: Keypair = Keypair::new(); - // let internal_payer_pubkey: Pubkey = internal_payer.pubkey(); - // println!("Internal Payer: {:?}", internal_payer_pubkey); - - // // ----------- Check or create internal payer ---------------------- - // executor.check_and_create_object( - // "Proposal Internal Payer", - // client.get_account(&internal_payer_pubkey)?, - // |_| { - // Ok(None) - // }, - // || { - // let lamports: u64 = minimum_balance_for_rent_exemption * (TREASURY_POOL_ACCOUNT_COUNT as u64 + 1); - // let transaction = client.create_transaction( - // &[ - // create_account( - // &client.payer.pubkey(), // from - // &internal_payer_pubkey, // to - // lamports, // lamports - // 0, // space - // &transaction_inserter.proposal.governance.governance_address, // owner - // ), - // ], - // &[ - // &client.payer, - // &internal_payer, - // ] - // )?; - // Ok(Some(transaction)) - // }, - // )?; - for index in 0u32..TREASURY_POOL_ACCOUNT_COUNT { let seed: String = format!("collateral_seed_{}", index.to_string().as_str()); println!("\nCollateral Poool Seed: {}", seed); @@ -104,17 +67,6 @@ pub fn create_collateral_pool_accounts(wallet: &Wallet, client: &Client, transac seed.as_str(), &cfg.wallet.neon_evm_program_id, ).into(), - // system_instruction::create_account_with_seed( - // // &maintenance_governance_pubkey, - // &internal_payer_pubkey, - // &collateral_pool_account, - // &maintenance_governance_pubkey, - // seed.as_str(), - // // 0, - // minimum_balance_for_rent_exemption, - // 0, - // &cfg.wallet.neon_evm_program_id, - // ).into(), ], )?; } diff --git a/launch-script/src/proposals/create_upgrade_evm.rs b/launch-script/src/proposals/create_upgrade_evm.rs index bdf34b3..8c7de54 100644 --- a/launch-script/src/proposals/create_upgrade_evm.rs +++ b/launch-script/src/proposals/create_upgrade_evm.rs @@ -52,20 +52,6 @@ pub fn create_upgrade_evm(wallet: &Wallet, client: &Client, verbose: transaction_inserter.verbose, }; - // executor.check_and_create_object( - // "EVM loader", - // client.get_account(&wallet.neon_evm_program_id)?, - // |evm_loader_account| { - // let (maintenance_record_pubkey,_): (Pubkey,u8) = - // println!("Address: {:?}", get_maintenance_record_address(&wallet.maintenance_program_id, &wallet.neon_evm_program_id)); - // if evm_loader_account.owner != maintenance_record_pubkey { - // return Err( StateError::WrongEvmLoaderAccountOwner(evm_loader_account.owner).into() ); - // } - // Ok(None) - // }, - // || Err( StateError::MissingEvmLoader(wallet.neon_evm_program_id).into() ), - // )?; - let upgrade_authority_opt = client.get_program_upgrade_authority(&wallet.neon_evm_program_id)?; executor.check_and_create_object( &format!("EVM loader upgrade authority: {:?}", upgrade_authority_opt), @@ -86,28 +72,28 @@ pub fn create_upgrade_evm(wallet: &Wallet, client: &Client, let elf = Elf::parse(program_data).expect("Can't parse Elf data"); let elf_params = parse_elf_params(elf, program_data); - println!("elf_params: {:?}", elf_params); - // if elf_params.get("NEON_TOKEN_MINT") - // .and_then(|value| Pubkey::from_str(value.as_str()).ok() ) - // .map(|neon_mint| { - // println!("neon_mint: {:?}", neon_mint); - // neon_mint != wallet.community_pubkey - // }) - // .unwrap_or(true) { - // return Err( StateError::InvalidNeonMint.into() ); - // } + // println!("elf_params: {:?}", elf_params); + if elf_params.get("NEON_TOKEN_MINT") + .and_then(|value| Pubkey::from_str(value.as_str()).ok() ) + .map(|neon_mint| { + println!("neon_mint: {:?}", neon_mint); + neon_mint != wallet.community_pubkey + }) + .unwrap_or(true) { + return Err( StateError::InvalidNeonMint.into() ); + } if elf_params.get("NEON_TOKEN_MINT_DECIMALS") .and_then(|value| value.parse().ok() ) .map(|decimals: u32| decimals != 9 ) .unwrap_or(true) { return Err( StateError::WrongNeonDecimals.into() ); } - // if elf_params.get("NEON_POOL_BASE") - // .and_then(|value| Pubkey::from_str(value.as_str()).ok() ) - // .map(|neon_pool_base| neon_pool_base != wallet.maintenance_program_id ) - // .unwrap_or(true) { - // return Err( StateError::InvalidPoolBase.into() ); - // } + if elf_params.get("NEON_POOL_BASE") + .and_then(|value| Pubkey::from_str(value.as_str()).ok() ) + .map(|neon_pool_base| neon_pool_base != wallet.maintenance_program_id ) + .unwrap_or(true) { + return Err( StateError::InvalidPoolBase.into() ); + } if elf_params.get("NEON_CHAIN_ID") .and_then(|value| value.parse().ok() ) .map(|chain_id: u64| chain_id != cfg.chain_id ) diff --git a/launch-script/src/proposals/mod.rs b/launch-script/src/proposals/mod.rs index db99bad..6c86925 100644 --- a/launch-script/src/proposals/mod.rs +++ b/launch-script/src/proposals/mod.rs @@ -315,9 +315,10 @@ pub fn execute_proposal( _wallet: &Wallet, _client: &Client, proposal: &Proposal, + compute_budget_opt: Option, _verbose: bool, ) -> Result<(), ScriptError> { - let result = proposal.execute_transactions(0)?; + let result = proposal.execute_transactions(0,compute_budget_opt)?; println!("Execute transactions from proposal option 0: {:?}", result); Ok(()) diff --git a/run-tests.sh b/run-tests.sh index 2a5ebe8..b03ede6 100755 --- a/run-tests.sh +++ b/run-tests.sh @@ -30,18 +30,18 @@ launch-script --config testing.cfg --send-trx proposal --governance MSIG_5.$DELE sleep 5 launch-script --config testing.cfg --send-trx proposal --governance MSIG_5.$DELEGATED_BALANCE --proposal LAST execute -# # Stage 1: Preparing Token Genesis Event and switch to vesting-addin -# launch-script --config testing.cfg --send-trx proposal --name 'Token Genesis Event' create-tge -# launch-script --config testing.cfg --send-trx proposal --proposal LAST sign-off -# launch-script --config testing.cfg --send-trx proposal --proposal LAST approve --voters artifacts/voters/ -# sleep 185 -# launch-script --config testing.cfg --send-trx proposal --proposal LAST finalize-vote -# sleep 65 -# launch-script --config testing.cfg --send-trx proposal --proposal LAST execute - -solana program deploy -v --keypair artifacts/payer.keypair --upgrade-authority artifacts/creator.keypair --program-id artifacts/neon-evm.keypair deploy/evm_loader.so - -solana program write-buffer -v --keypair artifacts/payer.keypair --buffer artifacts/buffer.keypair deploy/evm_loader.so +# Stage 1: Preparing Token Genesis Event and switch to vesting-addin +launch-script --config testing.cfg --send-trx proposal --name 'Token Genesis Event' create-tge +launch-script --config testing.cfg --send-trx proposal --proposal LAST sign-off +launch-script --config testing.cfg --send-trx proposal --proposal LAST approve --voters artifacts/voters/ +sleep 185 +launch-script --config testing.cfg --send-trx proposal --proposal LAST finalize-vote +sleep 65 +launch-script --config testing.cfg --send-trx proposal --proposal LAST execute + +solana program deploy -v --keypair artifacts/payer.keypair --upgrade-authority artifacts/creator.keypair --program-id artifacts/neon-evm.keypair deploy/evm_loader-govertest.so + +solana program write-buffer -v --keypair artifacts/payer.keypair --buffer artifacts/buffer.keypair deploy/evm_loader-govertest.so solana program set-buffer-authority -v --buffer-authority artifacts/payer.keypair artifacts/buffer.keypair --new-buffer-authority $MAINTENANCE_RECORD_ADDRESS launch-script --config testing.cfg --send-trx environment evm @@ -52,4 +52,4 @@ launch-script --config testing.cfg --send-trx proposal --governance MAINTENANCE sleep 185 launch-script --config testing.cfg --send-trx proposal --governance MAINTENANCE --proposal LAST finalize-vote sleep 65 -launch-script --config testing.cfg --send-trx proposal --governance MAINTENANCE --proposal LAST execute +launch-script --config testing.cfg --send-trx proposal --governance MAINTENANCE --proposal LAST execute --compute-units 1200000 diff --git a/testing.cfg b/testing.cfg index 1f0f6e5..275e760 100644 --- a/testing.cfg +++ b/testing.cfg @@ -6,7 +6,7 @@ "vesting-addin": "5tgpCGfXYaZhKWJsrNR4zyp4o4n3wSQ81i5MzPqKEeAK", "neon-evm-program": "DCPSnJHB38e7vNK6o3AVLswJGRaP87iiNx2zvvapiKBz", "maintenance-program": "7aPH9mBAvUtJDGV2L1KyvpR5nKF7man5DZzBPaxmisg5", - "executables-paths": ["deploy/evm_loader.so"], + "executables-paths": ["deploy/evm_loader-govertest.so"], "delegates": ["CVAimMqtcmSUCV4RLZSJAreDpEd7JEZmrvCVj85yaRzZ"], "chain-id": 111, "start-time": "2022-06-21T00:00:00",