Skip to content

Commit d94d9c3

Browse files
authored
feat: Upload IDL by default with option to skip (#3863)
* feat: Upload IDL by default with option to skip * fix: cargo clippy * chore: Update CHANGELOG.md * fix: prevent IDL upload attempt with non-existent file * refactor: rename skip_idl to no_idl * chore: Fix CHANGELOG.md
1 parent eed2937 commit d94d9c3

File tree

3 files changed

+33
-12
lines changed

3 files changed

+33
-12
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ The minor version will be incremented upon a breaking change and the patch versi
1515
- lang: Add `#[error]` attribute to `declare_program!` ([#3757](https://github.com/coral-xyz/anchor/pull/3757)).
1616
- lang: Replace `solana-program` crate with smaller crates ([#3819](https://github.com/solana-foundation/anchor/pull/3819)).
1717
- cli: Replace `anchor verify` to use `solana-verify` under the hood, adding automatic installation via AVM, local path support, and future-proof argument passing ([#3768](https://github.com/solana-foundation/anchor/pull/3768)).
18+
- cli: Make `anchor deploy` to upload the IDL to the cluster by default unless `--no-idl` is passed ([#3863](https://github.com/solana-foundation/anchor/pull/3863)).
1819

1920
### Fixes
2021

cli/src/config.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::{get_keypair, is_hidden, keys_sync};
1+
use crate::{get_keypair, is_hidden, keys_sync, DEFAULT_RPC_PORT};
22
use anchor_client::Cluster;
33
use anchor_lang_idl::types::Idl;
44
use anyhow::{anyhow, Context, Error, Result};
@@ -1107,9 +1107,7 @@ impl From<_Validator> for Validator {
11071107
.ledger
11081108
.unwrap_or_else(|| get_default_ledger_path().display().to_string()),
11091109
limit_ledger_size: _validator.limit_ledger_size,
1110-
rpc_port: _validator
1111-
.rpc_port
1112-
.unwrap_or(solana_sdk::rpc_port::DEFAULT_RPC_PORT),
1110+
rpc_port: _validator.rpc_port.unwrap_or(DEFAULT_RPC_PORT),
11131111
slots_per_epoch: _validator.slots_per_epoch,
11141112
ticks_per_slot: _validator.ticks_per_slot,
11151113
warp_slot: _validator.warp_slot,

cli/src/lib.rs

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ use crate::config::{
55
};
66
use anchor_client::Cluster;
77
use anchor_lang::idl::{IdlAccount, IdlInstruction, ERASED_AUTHORITY};
8+
use anchor_lang::prelude::UpgradeableLoaderState;
9+
use anchor_lang::solana_program::bpf_loader_upgradeable;
810
use anchor_lang::{AccountDeserialize, AnchorDeserialize, AnchorSerialize, Discriminator};
911
use anchor_lang_idl::convert::convert_idl;
1012
use anchor_lang_idl::types::{Idl, IdlArrayLen, IdlDefinedFields, IdlType, IdlTypeDefTy};
@@ -21,7 +23,6 @@ use rust_template::{ProgramTemplate, TestTemplate};
2123
use semver::{Version, VersionReq};
2224
use serde_json::{json, Map, Value as JsonValue};
2325
use solana_client::rpc_client::RpcClient;
24-
use solana_sdk::bpf_loader_upgradeable::{self, UpgradeableLoaderState};
2526
use solana_sdk::commitment_config::CommitmentConfig;
2627
use solana_sdk::compute_budget::ComputeBudgetInstruction;
2728
use solana_sdk::instruction::{AccountMeta, Instruction};
@@ -49,6 +50,9 @@ pub mod rust_template;
4950
pub const VERSION: &str = env!("CARGO_PKG_VERSION");
5051
pub const DOCKER_BUILDER_VERSION: &str = VERSION;
5152

53+
/// Default RPC port
54+
pub const DEFAULT_RPC_PORT: u16 = 8899;
55+
5256
#[derive(Debug, Parser)]
5357
#[clap(version = VERSION)]
5458
pub struct Opts {
@@ -239,6 +243,9 @@ pub enum Command {
239243
/// If true, deploy from path target/verifiable
240244
#[clap(short, long)]
241245
verifiable: bool,
246+
/// Don't upload IDL during deployment (IDL is uploaded by default)
247+
#[clap(long)]
248+
no_idl: bool,
242249
/// Arguments to pass to the underlying `solana program deploy` command.
243250
#[clap(required = false, last = true)]
244251
solana_args: Vec<String>,
@@ -791,12 +798,14 @@ fn process_command(opts: Opts) -> Result<()> {
791798
program_name,
792799
program_keypair,
793800
verifiable,
801+
no_idl,
794802
solana_args,
795803
} => deploy(
796804
&opts.cfg_override,
797805
program_name,
798806
program_keypair,
799807
verifiable,
808+
no_idl,
800809
solana_args,
801810
),
802811
Command::Expand {
@@ -2953,7 +2962,7 @@ fn test(
29532962
// In either case, skip the deploy if the user specifies.
29542963
let is_localnet = cfg.provider.cluster == Cluster::Localnet;
29552964
if (!is_localnet || skip_local_validator) && !skip_deploy {
2956-
deploy(cfg_override, None, None, false, vec![])?;
2965+
deploy(cfg_override, None, None, false, true, vec![])?;
29572966
}
29582967
let mut is_first_suite = true;
29592968
if let Some(test_script) = cfg.scripts.get_mut("test") {
@@ -3370,7 +3379,7 @@ fn start_test_validator(
33703379
.test_validator
33713380
.as_ref()
33723381
.and_then(|test| test.validator.as_ref().map(|v| v.rpc_port))
3373-
.unwrap_or(solana_sdk::rpc_port::DEFAULT_RPC_PORT);
3382+
.unwrap_or(DEFAULT_RPC_PORT);
33743383
if !portpicker::is_free(rpc_port) {
33753384
return Err(anyhow!(
33763385
"Your configured rpc port: {rpc_port} is already in use"
@@ -3520,6 +3529,7 @@ fn deploy(
35203529
program_name: Option<String>,
35213530
program_keypair: Option<String>,
35223531
verifiable: bool,
3532+
no_idl: bool,
35233533
solana_args: Vec<String>,
35243534
) -> Result<()> {
35253535
// Execute the code within the workspace
@@ -3572,16 +3582,28 @@ fn deploy(
35723582
std::process::exit(exit.status.code().unwrap_or(1));
35733583
}
35743584

3585+
// Get the IDL filepath
3586+
let idl_filepath = Path::new("target")
3587+
.join("idl")
3588+
.join(&program.lib_name)
3589+
.with_extension("json");
3590+
35753591
if let Some(idl) = program.idl.as_mut() {
35763592
// Add program address to the IDL.
35773593
idl.address = program_id.to_string();
35783594

35793595
// Persist it.
3580-
let idl_out = Path::new("target")
3581-
.join("idl")
3582-
.join(&idl.metadata.name)
3583-
.with_extension("json");
3584-
write_idl(idl, OutFile::File(idl_out))?;
3596+
write_idl(idl, OutFile::File(idl_filepath.clone()))?;
3597+
3598+
// Upload the IDL to the cluster by default (unless no_idl is set)
3599+
if !no_idl {
3600+
idl_init(
3601+
cfg_override,
3602+
program_id,
3603+
idl_filepath.display().to_string(),
3604+
None,
3605+
)?;
3606+
}
35853607
}
35863608
}
35873609

0 commit comments

Comments
 (0)