Skip to content

Commit

Permalink
Add temp endpoint to fix mobile hotspots (#683)
Browse files Browse the repository at this point in the history
  • Loading branch information
ChewingGlass authored Aug 2, 2024
1 parent 66ee560 commit 4db971f
Show file tree
Hide file tree
Showing 7 changed files with 129 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

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

54 changes: 54 additions & 0 deletions packages/helium-admin-cli/src/repair-mobile-hotpots.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import * as anchor from "@coral-xyz/anchor";
import { init as initHem } from "@helium/helium-entity-manager-sdk";
import os from "os";
import yargs from "yargs/yargs";
import fs from "fs";
import { batchInstructionsToTxsWithPriorityFee, sendInstructions } from "@helium/spl-utils";
import { PublicKey, TransactionInstruction } from "@solana/web3.js";

export async function run(args: any = process.argv) {
const yarg = yargs(args).options({
wallet: {
alias: "k",
describe: "Anchor wallet keypair",
default: `${os.homedir()}/.config/solana/id.json`,
},
url: {
alias: "u",
default: "http://127.0.0.1:8899",
describe: "The solana url",
},
badHotspotsFile: {
type: "string",
required: true,
}
});

const argv = await yarg.argv;
process.env.ANCHOR_WALLET = argv.wallet;
process.env.ANCHOR_PROVIDER_URL = argv.url;
anchor.setProvider(anchor.AnchorProvider.local(argv.url));

const provider = anchor.getProvider() as anchor.AnchorProvider;
const hemProgram = await initHem(provider);

const badHotspots = JSON.parse(
fs.readFileSync(argv.badHotspotsFile, "utf-8")
);

let instructions: TransactionInstruction[] = [];
for (const hotspot of badHotspots) {
instructions.push(
await hemProgram.methods
.tempRepairMobileHotspotInfo()
.accounts({
mobileInfo: new PublicKey(hotspot),
})
.instruction()
);
}

await batchInstructionsToTxsWithPriorityFee(provider, instructions, {
useFirstEstimateForAll: true,

Check failure on line 52 in packages/helium-admin-cli/src/repair-mobile-hotpots.ts

View workflow job for this annotation

GitHub Actions / Test Anchor Contracts (tests/circuit-breaker.ts)

Argument of type '{ useFirstEstimateForAll: boolean; }' is not assignable to parameter of type '{ computeUnitLimit?: number | undefined; computeScaleUp?: number | undefined; basePriorityFee?: number | undefined; addressLookupTableAddresses?: PublicKey[] | undefined; extraSigners?: Signer[] | undefined; }'.

Check failure on line 52 in packages/helium-admin-cli/src/repair-mobile-hotpots.ts

View workflow job for this annotation

GitHub Actions / Test Anchor Contracts (tests/circuit-breaker.ts)

Argument of type '{ useFirstEstimateForAll: boolean; }' is not assignable to parameter of type '{ computeUnitLimit?: number | undefined; computeScaleUp?: number | undefined; basePriorityFee?: number | undefined; addressLookupTableAddresses?: PublicKey[] | undefined; extraSigners?: Signer[] | undefined; }'.

Check failure on line 52 in packages/helium-admin-cli/src/repair-mobile-hotpots.ts

View workflow job for this annotation

GitHub Actions / Test Development Workflow

Argument of type '{ useFirstEstimateForAll: boolean; }' is not assignable to parameter of type '{ computeUnitLimit?: number | undefined; computeScaleUp?: number | undefined; basePriorityFee?: number | undefined; addressLookupTableAddresses?: PublicKey[] | undefined; extraSigners?: Signer[] | undefined; }'.

Check failure on line 52 in packages/helium-admin-cli/src/repair-mobile-hotpots.ts

View workflow job for this annotation

GitHub Actions / Test Development Workflow

Argument of type '{ useFirstEstimateForAll: boolean; }' is not assignable to parameter of type '{ computeUnitLimit?: number | undefined; computeScaleUp?: number | undefined; basePriorityFee?: number | undefined; addressLookupTableAddresses?: PublicKey[] | undefined; extraSigners?: Signer[] | undefined; }'.

Check failure on line 52 in packages/helium-admin-cli/src/repair-mobile-hotpots.ts

View workflow job for this annotation

GitHub Actions / Test Anchor Contracts (tests/treasury-management.ts)

Argument of type '{ useFirstEstimateForAll: boolean; }' is not assignable to parameter of type '{ computeUnitLimit?: number | undefined; computeScaleUp?: number | undefined; basePriorityFee?: number | undefined; addressLookupTableAddresses?: PublicKey[] | undefined; extraSigners?: Signer[] | undefined; }'.

Check failure on line 52 in packages/helium-admin-cli/src/repair-mobile-hotpots.ts

View workflow job for this annotation

GitHub Actions / Test Anchor Contracts (tests/treasury-management.ts)

Argument of type '{ useFirstEstimateForAll: boolean; }' is not assignable to parameter of type '{ computeUnitLimit?: number | undefined; computeScaleUp?: number | undefined; basePriorityFee?: number | undefined; addressLookupTableAddresses?: PublicKey[] | undefined; extraSigners?: Signer[] | undefined; }'.

Check failure on line 52 in packages/helium-admin-cli/src/repair-mobile-hotpots.ts

View workflow job for this annotation

GitHub Actions / Test Anchor Contracts (tests/price-oracle.ts)

Argument of type '{ useFirstEstimateForAll: boolean; }' is not assignable to parameter of type '{ computeUnitLimit?: number | undefined; computeScaleUp?: number | undefined; basePriorityFee?: number | undefined; addressLookupTableAddresses?: PublicKey[] | undefined; extraSigners?: Signer[] | undefined; }'.

Check failure on line 52 in packages/helium-admin-cli/src/repair-mobile-hotpots.ts

View workflow job for this annotation

GitHub Actions / Test Anchor Contracts (tests/price-oracle.ts)

Argument of type '{ useFirstEstimateForAll: boolean; }' is not assignable to parameter of type '{ computeUnitLimit?: number | undefined; computeScaleUp?: number | undefined; basePriorityFee?: number | undefined; addressLookupTableAddresses?: PublicKey[] | undefined; extraSigners?: Signer[] | undefined; }'.

Check failure on line 52 in packages/helium-admin-cli/src/repair-mobile-hotpots.ts

View workflow job for this annotation

GitHub Actions / Test Anchor Contracts (tests/mobile-entity-manager.ts)

Argument of type '{ useFirstEstimateForAll: boolean; }' is not assignable to parameter of type '{ computeUnitLimit?: number | undefined; computeScaleUp?: number | undefined; basePriorityFee?: number | undefined; addressLookupTableAddresses?: PublicKey[] | undefined; extraSigners?: Signer[] | undefined; }'.

Check failure on line 52 in packages/helium-admin-cli/src/repair-mobile-hotpots.ts

View workflow job for this annotation

GitHub Actions / Test Anchor Contracts (tests/mobile-entity-manager.ts)

Argument of type '{ useFirstEstimateForAll: boolean; }' is not assignable to parameter of type '{ computeUnitLimit?: number | undefined; computeScaleUp?: number | undefined; basePriorityFee?: number | undefined; addressLookupTableAddresses?: PublicKey[] | undefined; extraSigners?: Signer[] | undefined; }'.

Check failure on line 52 in packages/helium-admin-cli/src/repair-mobile-hotpots.ts

View workflow job for this annotation

GitHub Actions / Test Anchor Contracts (tests/helium-sub-daos.ts)

Argument of type '{ useFirstEstimateForAll: boolean; }' is not assignable to parameter of type '{ computeUnitLimit?: number | undefined; computeScaleUp?: number | undefined; basePriorityFee?: number | undefined; addressLookupTableAddresses?: PublicKey[] | undefined; extraSigners?: Signer[] | undefined; }'.

Check failure on line 52 in packages/helium-admin-cli/src/repair-mobile-hotpots.ts

View workflow job for this annotation

GitHub Actions / Test Anchor Contracts (tests/helium-sub-daos.ts)

Argument of type '{ useFirstEstimateForAll: boolean; }' is not assignable to parameter of type '{ computeUnitLimit?: number | undefined; computeScaleUp?: number | undefined; basePriorityFee?: number | undefined; addressLookupTableAddresses?: PublicKey[] | undefined; extraSigners?: Signer[] | undefined; }'.

Check failure on line 52 in packages/helium-admin-cli/src/repair-mobile-hotpots.ts

View workflow job for this annotation

GitHub Actions / Test Anchor Contracts (tests/lazy-distributor.ts)

Argument of type '{ useFirstEstimateForAll: boolean; }' is not assignable to parameter of type '{ computeUnitLimit?: number | undefined; computeScaleUp?: number | undefined; basePriorityFee?: number | undefined; addressLookupTableAddresses?: PublicKey[] | undefined; extraSigners?: Signer[] | undefined; }'.

Check failure on line 52 in packages/helium-admin-cli/src/repair-mobile-hotpots.ts

View workflow job for this annotation

GitHub Actions / Test Anchor Contracts (tests/lazy-distributor.ts)

Argument of type '{ useFirstEstimateForAll: boolean; }' is not assignable to parameter of type '{ computeUnitLimit?: number | undefined; computeScaleUp?: number | undefined; basePriorityFee?: number | undefined; addressLookupTableAddresses?: PublicKey[] | undefined; extraSigners?: Signer[] | undefined; }'.

Check failure on line 52 in packages/helium-admin-cli/src/repair-mobile-hotpots.ts

View workflow job for this annotation

GitHub Actions / Test Anchor Contracts (tests/data-credits.ts)

Argument of type '{ useFirstEstimateForAll: boolean; }' is not assignable to parameter of type '{ computeUnitLimit?: number | undefined; computeScaleUp?: number | undefined; basePriorityFee?: number | undefined; addressLookupTableAddresses?: PublicKey[] | undefined; extraSigners?: Signer[] | undefined; }'.

Check failure on line 52 in packages/helium-admin-cli/src/repair-mobile-hotpots.ts

View workflow job for this annotation

GitHub Actions / Test Anchor Contracts (tests/data-credits.ts)

Argument of type '{ useFirstEstimateForAll: boolean; }' is not assignable to parameter of type '{ computeUnitLimit?: number | undefined; computeScaleUp?: number | undefined; basePriorityFee?: number | undefined; addressLookupTableAddresses?: PublicKey[] | undefined; extraSigners?: Signer[] | undefined; }'.

Check failure on line 52 in packages/helium-admin-cli/src/repair-mobile-hotpots.ts

View workflow job for this annotation

GitHub Actions / Test Anchor Contracts (tests/lazy-transactions.ts)

Argument of type '{ useFirstEstimateForAll: boolean; }' is not assignable to parameter of type '{ computeUnitLimit?: number | undefined; computeScaleUp?: number | undefined; basePriorityFee?: number | undefined; addressLookupTableAddresses?: PublicKey[] | undefined; extraSigners?: Signer[] | undefined; }'.

Check failure on line 52 in packages/helium-admin-cli/src/repair-mobile-hotpots.ts

View workflow job for this annotation

GitHub Actions / Test Anchor Contracts (tests/lazy-transactions.ts)

Argument of type '{ useFirstEstimateForAll: boolean; }' is not assignable to parameter of type '{ computeUnitLimit?: number | undefined; computeScaleUp?: number | undefined; basePriorityFee?: number | undefined; addressLookupTableAddresses?: PublicKey[] | undefined; extraSigners?: Signer[] | undefined; }'.

Check failure on line 52 in packages/helium-admin-cli/src/repair-mobile-hotpots.ts

View workflow job for this annotation

GitHub Actions / Test Anchor Contracts (tests/voter-stake-registry.ts)

Argument of type '{ useFirstEstimateForAll: boolean; }' is not assignable to parameter of type '{ computeUnitLimit?: number | undefined; computeScaleUp?: number | undefined; basePriorityFee?: number | undefined; addressLookupTableAddresses?: PublicKey[] | undefined; extraSigners?: Signer[] | undefined; }'.

Check failure on line 52 in packages/helium-admin-cli/src/repair-mobile-hotpots.ts

View workflow job for this annotation

GitHub Actions / Test Anchor Contracts (tests/voter-stake-registry.ts)

Argument of type '{ useFirstEstimateForAll: boolean; }' is not assignable to parameter of type '{ computeUnitLimit?: number | undefined; computeScaleUp?: number | undefined; basePriorityFee?: number | undefined; addressLookupTableAddresses?: PublicKey[] | undefined; extraSigners?: Signer[] | undefined; }'.

Check failure on line 52 in packages/helium-admin-cli/src/repair-mobile-hotpots.ts

View workflow job for this annotation

GitHub Actions / Test Anchor Contracts (tests/fanout.ts)

Argument of type '{ useFirstEstimateForAll: boolean; }' is not assignable to parameter of type '{ computeUnitLimit?: number | undefined; computeScaleUp?: number | undefined; basePriorityFee?: number | undefined; addressLookupTableAddresses?: PublicKey[] | undefined; extraSigners?: Signer[] | undefined; }'.

Check failure on line 52 in packages/helium-admin-cli/src/repair-mobile-hotpots.ts

View workflow job for this annotation

GitHub Actions / Test Anchor Contracts (tests/fanout.ts)

Argument of type '{ useFirstEstimateForAll: boolean; }' is not assignable to parameter of type '{ computeUnitLimit?: number | undefined; computeScaleUp?: number | undefined; basePriorityFee?: number | undefined; addressLookupTableAddresses?: PublicKey[] | undefined; extraSigners?: Signer[] | undefined; }'.

Check failure on line 52 in packages/helium-admin-cli/src/repair-mobile-hotpots.ts

View workflow job for this annotation

GitHub Actions / Test Anchor Contracts (tests/helium-entity-manager.ts)

Argument of type '{ useFirstEstimateForAll: boolean; }' is not assignable to parameter of type '{ computeUnitLimit?: number | undefined; computeScaleUp?: number | undefined; basePriorityFee?: number | undefined; addressLookupTableAddresses?: PublicKey[] | undefined; extraSigners?: Signer[] | undefined; }'.

Check failure on line 52 in packages/helium-admin-cli/src/repair-mobile-hotpots.ts

View workflow job for this annotation

GitHub Actions / Test Anchor Contracts (tests/helium-entity-manager.ts)

Argument of type '{ useFirstEstimateForAll: boolean; }' is not assignable to parameter of type '{ computeUnitLimit?: number | undefined; computeScaleUp?: number | undefined; basePriorityFee?: number | undefined; addressLookupTableAddresses?: PublicKey[] | undefined; extraSigners?: Signer[] | undefined; }'.

Check failure on line 52 in packages/helium-admin-cli/src/repair-mobile-hotpots.ts

View workflow job for this annotation

GitHub Actions / Test Anchor Contracts (tests/hexboosting.ts)

Argument of type '{ useFirstEstimateForAll: boolean; }' is not assignable to parameter of type '{ computeUnitLimit?: number | undefined; computeScaleUp?: number | undefined; basePriorityFee?: number | undefined; addressLookupTableAddresses?: PublicKey[] | undefined; extraSigners?: Signer[] | undefined; }'.

Check failure on line 52 in packages/helium-admin-cli/src/repair-mobile-hotpots.ts

View workflow job for this annotation

GitHub Actions / Test Anchor Contracts (tests/hexboosting.ts)

Argument of type '{ useFirstEstimateForAll: boolean; }' is not assignable to parameter of type '{ computeUnitLimit?: number | undefined; computeScaleUp?: number | undefined; basePriorityFee?: number | undefined; addressLookupTableAddresses?: PublicKey[] | undefined; extraSigners?: Signer[] | undefined; }'.

Check failure on line 52 in packages/helium-admin-cli/src/repair-mobile-hotpots.ts

View workflow job for this annotation

GitHub Actions / Test Anchor Contracts (tests/sus.ts)

Argument of type '{ useFirstEstimateForAll: boolean; }' is not assignable to parameter of type '{ computeUnitLimit?: number | undefined; computeScaleUp?: number | undefined; basePriorityFee?: number | undefined; addressLookupTableAddresses?: PublicKey[] | undefined; extraSigners?: Signer[] | undefined; }'.

Check failure on line 52 in packages/helium-admin-cli/src/repair-mobile-hotpots.ts

View workflow job for this annotation

GitHub Actions / Test Anchor Contracts (tests/sus.ts)

Argument of type '{ useFirstEstimateForAll: boolean; }' is not assignable to parameter of type '{ computeUnitLimit?: number | undefined; computeScaleUp?: number | undefined; basePriorityFee?: number | undefined; addressLookupTableAddresses?: PublicKey[] | undefined; extraSigners?: Signer[] | undefined; }'.

Check failure on line 52 in packages/helium-admin-cli/src/repair-mobile-hotpots.ts

View workflow job for this annotation

GitHub Actions / Test Anchor Contracts (tests/distributor-oracle.ts)

Argument of type '{ useFirstEstimateForAll: boolean; }' is not assignable to parameter of type '{ computeUnitLimit?: number | undefined; computeScaleUp?: number | undefined; basePriorityFee?: number | undefined; addressLookupTableAddresses?: PublicKey[] | undefined; extraSigners?: Signer[] | undefined; }'.

Check failure on line 52 in packages/helium-admin-cli/src/repair-mobile-hotpots.ts

View workflow job for this annotation

GitHub Actions / Test Anchor Contracts (tests/distributor-oracle.ts)

Argument of type '{ useFirstEstimateForAll: boolean; }' is not assignable to parameter of type '{ computeUnitLimit?: number | undefined; computeScaleUp?: number | undefined; basePriorityFee?: number | undefined; addressLookupTableAddresses?: PublicKey[] | undefined; extraSigners?: Signer[] | undefined; }'.
});
}
2 changes: 1 addition & 1 deletion programs/helium-entity-manager/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "helium-entity-manager"
version = "0.2.8"
version = "0.2.9"
description = "Created with Anchor"
edition = "2021"

Expand Down
2 changes: 2 additions & 0 deletions programs/helium-entity-manager/src/instructions/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ pub mod revoke_program_v0;
pub mod set_entity_active_v0;
pub mod set_maker_tree_v0;
pub mod temp_pay_mobile_onboarding_fee_v0;
pub mod temp_repair_mobile_hotspot_info;
pub mod temp_standardize_entity;
pub mod update_data_only_tree_v0;
pub mod update_iot_info_v0;
Expand All @@ -42,6 +43,7 @@ pub use revoke_program_v0::*;
pub use set_entity_active_v0::*;
pub use set_maker_tree_v0::*;
pub use temp_pay_mobile_onboarding_fee_v0::*;
pub use temp_repair_mobile_hotspot_info::*;
pub use temp_standardize_entity::*;
pub use update_data_only_tree_v0::*;
pub use update_iot_info_v0::*;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
use crate::error::ErrorCode;
use crate::state::*;
use anchor_lang::prelude::*;
use std::str::FromStr;

use anchor_lang::{AnchorDeserialize, AnchorSerialize};

#[account]
pub struct OldMobileHotspotInfo {
pub asset: Pubkey,
pub bump_seed: u8,

pub location: Option<u64>,
pub is_full_hotspot: bool,
pub num_location_asserts: u16,
pub is_active: bool,
pub dc_onboarding_fee_paid: u64,
pub device_type: MobileDeviceTypeV0,
}

const FIX_DEPLOYER_KEY: &str = "hprdnjkbziK8NqhThmAn5Gu4XqrBbctX8du4PfJdgvW";
#[derive(Accounts)]
pub struct TempRepairMobileHotspotInfo<'info> {
/// CHECK: no
#[account(mut)]
pub mobile_info: UncheckedAccount<'info>,
#[account(
constraint = authority.key() == Pubkey::from_str(FIX_DEPLOYER_KEY).unwrap(),
)]
pub authority: Signer<'info>,
pub system_program: Program<'info, System>,
}

pub fn handler(ctx: Context<TempRepairMobileHotspotInfo>) -> Result<()> {
let mut data = ctx.accounts.mobile_info.try_borrow_mut_data()?;
let old_info: OldMobileHotspotInfo =
OldMobileHotspotInfo::try_deserialize_unchecked(&mut &data[..])?;
let old_info_bytes = old_info.try_to_vec()?;
for byte in &mut data[(8 + old_info_bytes.len())..] {
*byte = 0;
}

msg!("Repaired, checking...");
let new_info: MobileHotspotInfoV0 = MobileHotspotInfoV0::try_deserialize(&mut &data[..])?;

require_eq!(new_info.asset, old_info.asset);
require_eq!(new_info.bump_seed, old_info.bump_seed);
require_eq!(new_info.location.is_some(), old_info.location.is_some());
if new_info.location.is_some() {
require_eq!(new_info.location.unwrap(), old_info.location.unwrap());
}
require_eq!(new_info.is_full_hotspot, old_info.is_full_hotspot);
require_eq!(new_info.num_location_asserts, old_info.num_location_asserts);
require_eq!(new_info.is_active, old_info.is_active);
require_eq!(
new_info.dc_onboarding_fee_paid,
old_info.dc_onboarding_fee_paid
);
if new_info.device_type != old_info.device_type {
return Err(ErrorCode::InvalidDeviceType.into());
}

Ok(())
}
6 changes: 6 additions & 0 deletions programs/helium-entity-manager/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,4 +180,10 @@ pub mod helium_entity_manager {
) -> Result<()> {
temp_standardize_entity::handler(ctx, args)
}

pub fn temp_repair_mobile_hotspot_info<'info>(
ctx: Context<'_, '_, '_, 'info, TempRepairMobileHotspotInfo<'info>>,
) -> Result<()> {
temp_repair_mobile_hotspot_info::handler(ctx)
}
}
2 changes: 1 addition & 1 deletion programs/helium-entity-manager/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ pub struct RewardableEntityConfigV0 {
pub staking_requirement: u64,
}

#[derive(AnchorSerialize, AnchorDeserialize, Clone, Copy, Default, PartialEq)]
#[derive(AnchorSerialize, AnchorDeserialize, Clone, Copy, Default, PartialEq, Debug)]
pub enum MobileDeviceTypeV0 {
#[default]
Cbrs,
Expand Down

0 comments on commit 4db971f

Please sign in to comment.