Skip to content

Commit

Permalink
Merge remote-tracking branch 'up/master' into HEAD
Browse files Browse the repository at this point in the history
  • Loading branch information
mina86 committed Dec 12, 2023
2 parents 54d7794 + 61244a8 commit 84b9d9c
Show file tree
Hide file tree
Showing 81 changed files with 1,897 additions and 781 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,25 @@ The minor version will be incremented upon a breaking change and the patch versi
### Features

- cli: Allow force `init` and `new` ([#2698](https://github.com/coral-xyz/anchor/pull/2698)).
- cli: Add verifiable option when `deploy` ([#2705](https://github.com/coral-xyz/anchor/pull/2705)).
- cli: Add support for passing arguments to the underlying `solana program deploy` command with `anchor deploy` ([#2709](https://github.com/coral-xyz/anchor/pull/2709)).

### Fixes

- syn: Add missing `new_from_array` method to `Hash` ([#2682](https://github.com/coral-xyz/anchor/pull/2682)).
- cli: Switch to Cargo feature resolver(`resolver = "2"`) ([#2676](https://github.com/coral-xyz/anchor/pull/2676)).
- cli: Fix using user specific path for `provider.wallet` in `Anchor.toml` ([#2696](https://github.com/coral-xyz/anchor/pull/2696)).
- syn: Fix IDL constant seeds parsing ([#2699](https://github.com/coral-xyz/anchor/pull/2699)).
- cli: Display errors if toolchain override restoration fails ([#2700](https://github.com/coral-xyz/anchor/pull/2700)).
- cli: Fix commit based `anchor_version` override ([#2704](https://github.com/coral-xyz/anchor/pull/2704)).
- spl: Fix compilation with `shmem` feature enabled ([#2722](https://github.com/coral-xyz/anchor/pull/2722)).
- cli: Localhost default test validator address changes from `localhost` to `127.0.0.1`, NodeJS 17 IP resolution changes for IPv6 ([#2725](https://github.com/coral-xyz/anchor/pull/2725)).

### Breaking

- cli: Make `cargo build-sbf` the default build command ([#2694](https://github.com/coral-xyz/anchor/pull/2694)).
- cli: Require explicit `overflow-checks` flag ([#2716](https://github.com/coral-xyz/anchor/pull/2716)).
- ts: Remove `anchor-deprecated-state` feature ([#2717](https://github.com/coral-xyz/anchor/pull/2717)).

## [0.29.0] - 2023-10-16

Expand Down
12 changes: 6 additions & 6 deletions bench/BINARY_SIZE.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ The programs and their tests are located in [/tests/bench](https://github.com/co

Solana version: 1.17.0

| Program | Binary Size | - |
| ------- | ----------- | --- |
| bench | 735,800 | - |
| Program | Binary Size | - |
| ------- | ----------- | ------------------- |
| bench | 743,208 | 🔴 **+152 (0.02%)** |

### Notable changes

Expand All @@ -30,7 +30,7 @@ Solana version: 1.17.0

| Program | Binary Size | +/- |
| ------- | ----------- | ------------------------ |
| bench | 735,800 | 🟢 **-417,936 (36.22%)** |
| bench | 743,056 | 🟢 **-417,904 (36.00%)** |

### Notable changes

Expand All @@ -46,7 +46,7 @@ Solana version: 1.16.0

| Program | Binary Size | +/- |
| ------- | ----------- | ---------------------- |
| bench | 1,153,736 | 🔴 **+35,000 (3.13%)** |
| bench | 1,160,960 | 🔴 **+23,272 (2.05%)** |

### Notable changes

Expand All @@ -60,6 +60,6 @@ Solana version: 1.14.16

| Program | Binary Size | +/- |
| ------- | ----------- | --- |
| bench | 1,118,736 | N/A |
| bench | 1,137,688 | N/A |

---
696 changes: 348 additions & 348 deletions bench/COMPUTE_UNITS.md

Large diffs are not rendered by default.

22 changes: 22 additions & 0 deletions cli/src/checks.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
use std::path::Path;

use anyhow::{anyhow, Result};

use crate::config::Manifest;

/// Check whether `overflow-checks` codegen option is enabled.
///
/// https://doc.rust-lang.org/rustc/codegen-options/index.html#overflow-checks
pub fn check_overflow(cargo_toml_path: impl AsRef<Path>) -> Result<bool> {
Manifest::from_path(cargo_toml_path)?
.profile
.release
.as_ref()
.and_then(|profile| profile.overflow_checks)
.ok_or(anyhow!(
"`overflow-checks` is not enabled. To enable, add:\n\n\
[profile.release]\n\
overflow-checks = true\n\n\
in workspace root Cargo.toml.",
))
}
19 changes: 12 additions & 7 deletions cli/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,12 +125,11 @@ impl Manifest {
format!("Error reading the directory with path: {}", cwd.display())
})?
.path();
if let Some(filename) = p.file_name() {
if filename.to_str() == Some("Cargo.toml") {
let m = WithPath::new(Manifest::from_path(&p)?, p);
return Ok(Some(m));
if let Some(filename) = p.file_name().and_then(|name| name.to_str()) {
if filename == "Cargo.toml" {
return Ok(Some(WithPath::new(Manifest::from_path(&p)?, p)));
}
if filename.to_str() == Some("Anchor.toml") {
if filename == "Anchor.toml" {
anchor_toml = true;
}
}
Expand Down Expand Up @@ -1257,10 +1256,16 @@ impl Program {
Ok(WithPath::new(file, path))
}

pub fn binary_path(&self) -> PathBuf {
pub fn binary_path(&self, verifiable: bool) -> PathBuf {
let path = if verifiable {
format!("target/verifiable/{}.so", self.lib_name)
} else {
format!("target/deploy/{}.so", self.lib_name)
};

std::env::current_dir()
.expect("Must have current dir")
.join(format!("target/deploy/{}.so", self.lib_name))
.join(path)
}
}

Expand Down
91 changes: 66 additions & 25 deletions cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use anchor_syn::idl::types::{
IdlTypeDefinitionTy,
};
use anyhow::{anyhow, Context, Result};
use checks::check_overflow;
use clap::Parser;
use dirs::home_dir;
use flate2::read::GzDecoder;
Expand Down Expand Up @@ -44,11 +45,12 @@ use std::ffi::OsString;
use std::fs::{self, File};
use std::io::prelude::*;
use std::path::{Path, PathBuf};
use std::process::{Child, ExitStatus, Stdio};
use std::process::{Child, Stdio};
use std::str::FromStr;
use std::string::ToString;
use tar::Archive;

mod checks;
pub mod config;
pub mod rust_template;
pub mod solidity_template;
Expand Down Expand Up @@ -246,6 +248,12 @@ pub enum Command {
/// Keypair of the program (filepath) (requires program-name)
#[clap(long, requires = "program_name")]
program_keypair: Option<String>,
/// If true, deploy from path target/verifiable
#[clap(short, long)]
verifiable: bool,
/// Arguments to pass to the underlying `solana program deploy` command.
#[clap(required = false, last = true)]
solana_args: Vec<String>,
},
/// Runs the deploy migration script.
Migrate,
Expand Down Expand Up @@ -488,7 +496,7 @@ fn override_toolchain(cfg_override: &ConfigOverride) -> Result<RestoreToolchainC
let cfg = Config::discover(cfg_override)?;
if let Some(cfg) = cfg {
fn get_current_version(cmd_name: &str) -> Result<String> {
let output: std::process::Output = std::process::Command::new(cmd_name)
let output = std::process::Command::new(cmd_name)
.arg("--version")
.output()?;
let output_version = std::str::from_utf8(&output.stdout)?;
Expand All @@ -511,24 +519,25 @@ fn override_toolchain(cfg_override: &ConfigOverride) -> Result<RestoreToolchainC
// We are overriding with `solana-install` command instead of using the binaries
// from `~/.local/share/solana/install/releases` because we use multiple Solana
// binaries in various commands.
fn override_solana_version(version: String) -> std::io::Result<ExitStatus> {
fn override_solana_version(version: String) -> std::io::Result<bool> {
std::process::Command::new("solana-install")
.arg("init")
.arg(&version)
.stderr(Stdio::null())
.stdout(Stdio::null())
.spawn()?
.wait()
.map(|status| status.success())
}

match override_solana_version(solana_version.to_owned()) {
Ok(_) => restore_cbs.push(Box::new(|| {
match override_solana_version(current_version)?.success() {
match override_solana_version(solana_version.to_owned())? {
true => restore_cbs.push(Box::new(|| {
match override_solana_version(current_version)? {
true => Ok(()),
false => Err(anyhow!("Failed to restore `solana` version")),
}
})),
Err(_) => {
false => {
eprintln!(
"Failed to override `solana` version to {solana_version}, \
using {current_version} instead"
Expand All @@ -540,16 +549,31 @@ fn override_toolchain(cfg_override: &ConfigOverride) -> Result<RestoreToolchainC

// Anchor version override should be handled last
if let Some(anchor_version) = &cfg.toolchain.anchor_version {
let current_version = VERSION;
if anchor_version != current_version {
// Anchor binary name prefix(applies to binaries that are installed via `avm`)
const ANCHOR_BINARY_PREFIX: &str = "anchor-";

// Get the current version from the executing binary name if possible because commit
// based toolchain overrides do not have version information.
let current_version = std::env::args()
.next()
.expect("First arg should exist")
.parse::<PathBuf>()?
.file_name()
.and_then(|name| name.to_str())
.expect("File name should be valid Unicode")
.split_once(ANCHOR_BINARY_PREFIX)
.map(|(_, version)| version)
.unwrap_or(VERSION)
.to_owned();
if anchor_version != &current_version {
let binary_path = home_dir()
.unwrap()
.join(".avm")
.join("bin")
.join(format!("anchor-{anchor_version}"));
.join(format!("{ANCHOR_BINARY_PREFIX}{anchor_version}"));

if !binary_path.exists() {
println!(
eprintln!(
"`anchor` {anchor_version} is not installed with `avm`. Installing...\n"
);

Expand All @@ -559,7 +583,7 @@ fn override_toolchain(cfg_override: &ConfigOverride) -> Result<RestoreToolchainC
.spawn()?
.wait()?;
if !exit_status.success() {
println!(
eprintln!(
"Failed to install `anchor` {anchor_version}, \
using {current_version} instead"
);
Expand Down Expand Up @@ -676,7 +700,15 @@ fn process_command(opts: Opts) -> Result<()> {
Command::Deploy {
program_name,
program_keypair,
} => deploy(&opts.cfg_override, program_name, program_keypair),
verifiable,
solana_args,
} => deploy(
&opts.cfg_override,
program_name,
program_keypair,
verifiable,
solana_args,
),
Command::Expand {
program_name,
cargo_args,
Expand Down Expand Up @@ -1154,15 +1186,13 @@ pub fn build(
}

let cfg = Config::discover(cfg_override)?.expect("Not in workspace.");
let build_config = BuildConfig {
verifiable,
solana_version: solana_version.or_else(|| cfg.toolchain.solana_version.clone()),
docker_image: docker_image.unwrap_or_else(|| cfg.docker()),
bootstrap,
};
let cfg_parent = cfg.path().parent().expect("Invalid Anchor.toml");

let cargo = Manifest::discover()?;
// Require overflow checks
let workspace_cargo_toml_path = cfg_parent.join("Cargo.toml");
if workspace_cargo_toml_path.exists() {
check_overflow(workspace_cargo_toml_path)?;
}

let idl_out = match idl {
Some(idl) => Some(PathBuf::from(idl)),
Expand All @@ -1176,10 +1206,17 @@ pub fn build(
};
fs::create_dir_all(idl_ts_out.as_ref().unwrap())?;

if !&cfg.workspace.types.is_empty() {
if !cfg.workspace.types.is_empty() {
fs::create_dir_all(cfg_parent.join(&cfg.workspace.types))?;
};

let cargo = Manifest::discover()?;
let build_config = BuildConfig {
verifiable,
solana_version: solana_version.or_else(|| cfg.toolchain.solana_version.clone()),
docker_image: docker_image.unwrap_or_else(|| cfg.docker()),
bootstrap,
};
match cargo {
// No Cargo.toml so build the entire workspace.
None => build_all(
Expand Down Expand Up @@ -3027,7 +3064,7 @@ fn test(
// In either case, skip the deploy if the user specifies.
let is_localnet = cfg.provider.cluster == Cluster::Localnet;
if (!is_localnet || skip_local_validator) && !skip_deploy {
deploy(cfg_override, None, None)?;
deploy(cfg_override, None, None, false, vec![])?;
}
let mut is_first_suite = true;
if cfg.scripts.get("test").is_some() {
Expand Down Expand Up @@ -3189,7 +3226,8 @@ fn validator_flags(

let mut flags = Vec::new();
for mut program in cfg.read_all_programs()? {
let binary_path = program.binary_path().display().to_string();
let verifiable = false;
let binary_path = program.binary_path(verifiable).display().to_string();

// Use the [programs.cluster] override and fallback to the keypair
// files if no override is given.
Expand Down Expand Up @@ -3476,7 +3514,7 @@ fn test_validator_rpc_url(test_validator: &Option<TestValidator>) -> String {
validator: Some(validator),
..
}) => format!("http://{}:{}", validator.bind_address, validator.rpc_port),
_ => "http://localhost:8899".to_string(),
_ => "http://127.0.0.1:8899".to_string(),
}
}

Expand Down Expand Up @@ -3559,6 +3597,8 @@ fn deploy(
cfg_override: &ConfigOverride,
program_name: Option<String>,
program_keypair: Option<String>,
verifiable: bool,
solana_args: Vec<String>,
) -> Result<()> {
// Execute the code within the workspace
with_workspace(cfg_override, |cfg| {
Expand All @@ -3570,7 +3610,7 @@ fn deploy(
println!("Upgrade authority: {}", keypair);

for mut program in cfg.get_programs(program_name)? {
let binary_path = program.binary_path().display().to_string();
let binary_path = program.binary_path(verifiable).display().to_string();

println!("Deploying program {:?}...", program.lib_name);
println!("Program path: {}...", binary_path);
Expand Down Expand Up @@ -3599,6 +3639,7 @@ fn deploy(
.arg("--program-id")
.arg(strip_workspace_prefix(program_keypair_filepath))
.arg(strip_workspace_prefix(binary_path))
.args(&solana_args)
.stdout(Stdio::inherit())
.stderr(Stdio::inherit())
.output()
Expand Down
6 changes: 3 additions & 3 deletions client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ impl<T> Iterator for ProgramAccountsIterator<T> {
}
}

fn handle_program_log<T: anchor_lang::Event + anchor_lang::AnchorDeserialize>(
pub fn handle_program_log<T: anchor_lang::Event + anchor_lang::AnchorDeserialize>(
self_program_str: &str,
l: &str,
) -> Result<(Option<T>, Option<String>, bool), ClientError> {
Expand Down Expand Up @@ -364,7 +364,7 @@ fn handle_program_log<T: anchor_lang::Event + anchor_lang::AnchorDeserialize>(
}
}

fn handle_system_log(this_program_str: &str, log: &str) -> (Option<String>, bool) {
pub fn handle_system_log(this_program_str: &str, log: &str) -> (Option<String>, bool) {
if log.starts_with(&format!("Program {this_program_str} log:")) {
(Some(this_program_str.to_string()), false)
} else if log.contains("invoke") {
Expand All @@ -379,7 +379,7 @@ fn handle_system_log(this_program_str: &str, log: &str) -> (Option<String>, bool
}
}

struct Execution {
pub struct Execution {
stack: Vec<String>,
}

Expand Down
Binary file added docs/public/solpg-anchor.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/public/solpg-build-deploy.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/public/solpg-github.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/public/solpg-import.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/public/solpg-test.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/public/solpg-wallet.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions docs/src/pages/_app.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ const navigation = [
title: 'Getting Started',
links: [
{ title: 'Introduction', href: '/' },
{ title: 'Quickstart', href: '/docs/solana-playground' },
{ title: 'Installation', href: '/docs/installation' },
{ title: 'Hello World', href: '/docs/hello-world' },
{ title: 'Intro to Solana', href: '/docs/intro-to-solana' },
Expand Down Expand Up @@ -67,6 +68,8 @@ const navigation = [
{
title: 'References',
links: [
{ title: 'Account Constraints', href: '/docs/account-constraints' },
{ title: 'Account Types', href: '/docs/account-types' },
{ title: 'Anchor.toml', href: '/docs/manifest' },
{ title: 'CLI', href: '/docs/cli' },
{ title: 'AVM', href: '/docs/avm' },
Expand Down
Loading

0 comments on commit 84b9d9c

Please sign in to comment.