Browse Source

cli: Verify for write buffers

armaniferrante 4 years ago
parent
commit
060313725e
1 changed files with 24 additions and 18 deletions
  1. 24 18
      cli/src/main.rs

+ 24 - 18
cli/src/main.rs

@@ -457,31 +457,34 @@ fn verify(program_id: Pubkey) -> Result<()> {
     build(None, true)?;
     build(None, true)?;
     std::env::set_current_dir(&cur_dir)?;
     std::env::set_current_dir(&cur_dir)?;
 
 
-    // Verify IDL.
-    std::env::set_current_dir(program_dir)?;
     let local_idl = extract_idl("src/lib.rs")?;
     let local_idl = extract_idl("src/lib.rs")?;
-    let deployed_idl = fetch_idl(program_id)?;
-    if local_idl != deployed_idl {
-        println!("Error: IDLs don't match");
-        std::process::exit(1);
-    }
 
 
     // Verify binary.
     // Verify binary.
     let bin_path = program_dir
     let bin_path = program_dir
         .join("../../target/deploy/")
         .join("../../target/deploy/")
         .join(format!("{}.so", local_idl.name));
         .join(format!("{}.so", local_idl.name));
-    verify_bin(program_id, &bin_path, cfg.cluster.url())?;
+    let is_buffer = verify_bin(program_id, &bin_path, cfg.cluster.url())?;
+
+    // Verify IDL (only if it's not a buffer account).
+    if !is_buffer {
+        std::env::set_current_dir(program_dir)?;
+        let deployed_idl = fetch_idl(program_id)?;
+        if local_idl != deployed_idl {
+            println!("Error: IDLs don't match");
+            std::process::exit(1);
+        }
+    }
 
 
     println!("{} is verified.", program_id);
     println!("{} is verified.", program_id);
 
 
     Ok(())
     Ok(())
 }
 }
 
 
-fn verify_bin(program_id: Pubkey, bin_path: &Path, cluster: &str) -> Result<()> {
+fn verify_bin(program_id: Pubkey, bin_path: &Path, cluster: &str) -> Result<bool> {
     let client = RpcClient::new(cluster.to_string());
     let client = RpcClient::new(cluster.to_string());
 
 
     // Get the deployed build artifacts.
     // Get the deployed build artifacts.
-    let deployed_bin = {
+    let (deployed_bin, is_buffer) = {
         let account = client
         let account = client
             .get_account_with_commitment(&program_id, CommitmentConfig::default())?
             .get_account_with_commitment(&program_id, CommitmentConfig::default())?
             .value
             .value
@@ -489,15 +492,18 @@ fn verify_bin(program_id: Pubkey, bin_path: &Path, cluster: &str) -> Result<()>
         match account.state()? {
         match account.state()? {
             UpgradeableLoaderState::Program {
             UpgradeableLoaderState::Program {
                 programdata_address,
                 programdata_address,
-            } => client
-                .get_account_with_commitment(&programdata_address, CommitmentConfig::default())?
-                .value
-                .map_or(Err(anyhow!("Account not found")), Ok)?
-                .data[UpgradeableLoaderState::programdata_data_offset().unwrap_or(0)..]
-                .to_vec(),
+            } => (
+                client
+                    .get_account_with_commitment(&programdata_address, CommitmentConfig::default())?
+                    .value
+                    .map_or(Err(anyhow!("Account not found")), Ok)?
+                    .data[UpgradeableLoaderState::programdata_data_offset().unwrap_or(0)..]
+                    .to_vec(),
+                false,
+            ),
             UpgradeableLoaderState::Buffer { .. } => {
             UpgradeableLoaderState::Buffer { .. } => {
                 let offset = UpgradeableLoaderState::buffer_data_offset().unwrap_or(0);
                 let offset = UpgradeableLoaderState::buffer_data_offset().unwrap_or(0);
-                account.data[offset..].to_vec()
+                (account.data[offset..].to_vec(), true)
             }
             }
             _ => return Err(anyhow!("Invalid program id")),
             _ => return Err(anyhow!("Invalid program id")),
         }
         }
@@ -521,7 +527,7 @@ fn verify_bin(program_id: Pubkey, bin_path: &Path, cluster: &str) -> Result<()>
         std::process::exit(1);
         std::process::exit(1);
     }
     }
 
 
-    Ok(())
+    Ok(is_buffer)
 }
 }
 
 
 // Fetches an IDL for the given program_id.
 // Fetches an IDL for the given program_id.