Skip to content

Commit

Permalink
Merge pull request #740 from helium/bugfix/relinquish-no-position
Browse files Browse the repository at this point in the history
Bugfix relinquishing votes with expired positions, bump cargo for verify
  • Loading branch information
ChewingGlass authored Nov 20, 2024
2 parents 22a2d00 + e1fa3d9 commit b6a60f8
Show file tree
Hide file tree
Showing 9 changed files with 102 additions and 20 deletions.
12 changes: 6 additions & 6 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion programs/circuit-breaker/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "circuit-breaker"
version = "0.1.0"
version = "0.1.1"
description = "Created with Anchor"
edition = "2021"

Expand Down
2 changes: 1 addition & 1 deletion programs/fanout/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "fanout"
version = "0.1.0"
version = "0.1.1"
description = "Created with Anchor"
edition = "2021"

Expand Down
2 changes: 1 addition & 1 deletion programs/lazy-distributor/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "lazy-distributor"
version = "0.2.0"
version = "0.2.1"
description = "Created with Anchor"
edition = "2021"

Expand Down
2 changes: 1 addition & 1 deletion programs/rewards-oracle/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "rewards-oracle"
version = "0.2.1"
version = "0.2.2"
description = "Created with Anchor"
edition = "2021"

Expand Down
2 changes: 1 addition & 1 deletion programs/treasury-management/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "treasury-management"
version = "0.2.0"
version = "0.2.1"
description = "Created with Anchor"
edition = "2021"

Expand Down
2 changes: 1 addition & 1 deletion programs/voter-stake-registry/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "voter-stake-registry"
version = "0.3.3"
version = "0.3.4"
description = "Heliums voter weight plugin for spl-governance"
license = "GPL-3.0-or-later"
homepage = "https://github.com/helium/helium-program-library"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,9 @@ pub struct RelinquishExpiredVoteV0<'info> {
close = rent_refund
)]
pub marker: Box<Account<'info, VoteMarkerV0>>,
#[account(
mut,
constraint = position.mint == marker.mint
)]
pub position: Box<Account<'info, PositionV0>>,
#[account(mut)]
/// CHECK: Deserialized later
pub position: AccountInfo<'info>,
#[account(
constraint = !matches!(proposal.state, ProposalState::Voting { .. })
)]
Expand All @@ -31,9 +29,12 @@ pub struct RelinquishExpiredVoteV0<'info> {
}

pub fn handler(ctx: Context<RelinquishExpiredVoteV0>) -> Result<()> {
// Allow closing old markers that just had the relinquished boolean.
if !ctx.accounts.marker._deprecated_relinquished {
ctx.accounts.position.num_active_votes -= ctx.accounts.marker.choices.len() as u16;
let mut data = ctx.accounts.position.try_borrow_mut_data()?;
if !data.is_empty() && !ctx.accounts.marker._deprecated_relinquished {
let mut position = PositionV0::try_deserialize(&mut data.as_ref())?;
require_eq!(position.mint, ctx.accounts.marker.mint);
position.num_active_votes -= ctx.accounts.marker.choices.len() as u16;
position.try_serialize(&mut *data)?;
}

Ok(())
Expand Down
81 changes: 81 additions & 0 deletions scripts/verify.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
#!/bin/bash

# Function to get the latest semver tag for a program
get_latest_tag() {
local program_name=$1
git tag -l "program-$program_name-*" | sort -t. -k1,1n -k2,2n -k3,3n | tail -n 1
}

# Function to get commit hash from a tag
get_commit_hash() {
local tag=$1
git rev-list -n 1 "$tag"
}

# Function to verify a single program
verify_program() {
local program_dir=$1
local max_attempts=5
local attempt=1

# Get the base name and convert hyphens to underscores
library_name=$(basename "$program_dir" | tr '-' '_')

# Get the program ID from Anchor.toml
program_id=$(toml get Anchor.toml programs.localnet.$library_name | tr -d '"')

# Skip if program ID is empty
[ -z "$program_id" ] && return

# Get the program name (for tag matching)
program_name=$(basename "$program_dir")

# Get the latest tag and its commit hash
latest_tag=$(get_latest_tag "$program_name")

# Check if tag exists
if [ -z "$latest_tag" ]; then
echo "Error: No tags found for $program_name"
return 1
fi

commit_hash=$(get_commit_hash "$latest_tag")

echo "Verifying $library_name with program ID $program_id"
echo "Using tag $latest_tag (commit: $commit_hash)"

while [ $attempt -le $max_attempts ]; do
if solana-verify verify-from-repo \
https://github.com/helium/helium-program-library \
--program-id "$program_id" \
--remote \
--commit-hash "$commit_hash" \
--library-name "$library_name" \
-b solanafoundation/solana-verifiable-build:1.16.13; then
return 0
fi

echo "Attempt $attempt failed. Retrying in 10 seconds..."
sleep 10
attempt=$((attempt + 1))
done

echo "Error: Verification failed after $max_attempts attempts"
return 1
}

# Check if a specific program was provided
if [ $# -eq 1 ]; then
program_dir="programs/$1"
if [ -d "$program_dir" ]; then
verify_program "$program_dir"
else
echo "Error: Program directory '$program_dir' not found"
exit 1
fi
else
# Iterate through each directory in programs/
for program_dir in programs/*/; do
verify_program "$program_dir"
done
fi

0 comments on commit b6a60f8

Please sign in to comment.