From 8fcb6afdc3210a63080c35f4c8caa5d9539551f4 Mon Sep 17 00:00:00 2001 From: bry Date: Tue, 4 Feb 2025 13:03:58 -0600 Subject: [PATCH] Remove temp endpoint --- .../src/backfill-mobile-deployment-infos.ts | 277 ------------------ .../src/idl/helium_entity_manager.json | 52 +--- .../src/instructions/mod.rs | 2 - .../instructions/temp_backfill_mobile_info.rs | 44 --- programs/helium-entity-manager/src/lib.rs | 7 - 5 files changed, 1 insertion(+), 381 deletions(-) delete mode 100644 packages/helium-admin-cli/src/backfill-mobile-deployment-infos.ts delete mode 100644 programs/helium-entity-manager/src/instructions/temp_backfill_mobile_info.rs diff --git a/packages/helium-admin-cli/src/backfill-mobile-deployment-infos.ts b/packages/helium-admin-cli/src/backfill-mobile-deployment-infos.ts deleted file mode 100644 index e4e922564..000000000 --- a/packages/helium-admin-cli/src/backfill-mobile-deployment-infos.ts +++ /dev/null @@ -1,277 +0,0 @@ -import * as anchor from "@coral-xyz/anchor"; -import { - MobileDeploymentInfoV0, - init as initHEM, - mobileInfoKey, - rewardableEntityConfigKey, -} from "@helium/helium-entity-manager-sdk"; -import { subDaoKey } from "@helium/helium-sub-daos-sdk"; -import { HeliumEntityManager } from "@helium/idls/lib/types/helium_entity_manager"; -import { - MOBILE_MINT, - batchInstructionsToTxsWithPriorityFee, - batchParallelInstructionsWithPriorityFee, - bulkSendTransactions, - chunks, - truthy, -} from "@helium/spl-utils"; -import deepEqual from "fast-deep-equal"; -import { latLngToCell } from "h3-js"; -import os from "os"; -import { Client } from "pg"; -import yargs from "yargs/yargs"; -import { loadKeypair } from "./utils"; - -type WifiInfoRow = { - hs_pubkey: string; - antenna: number; - elevation: number; - azimuth: number; - mechanical_down_tilt: number; - electrical_down_tilt: number; - lat: string; - lng: string; -}; - -type WifiInfo = { - hs_pubkey: string; - location?: anchor.BN; - deploymentInfo: { - antenna: number; - elevation: number; - azimuth: number; - mechanicalDownTilt: number; - electricalDownTilt: number; - }; -}; - -type MobileHotspotInfo = - anchor.IdlAccounts["mobileHotspotInfoV0"]; - -const hasDeploymentInfo = (wi: WifiInfo) => { - return !!( - wi.deploymentInfo.antenna || - wi.deploymentInfo.elevation || - wi.deploymentInfo.azimuth || - wi.deploymentInfo.mechanicalDownTilt || - wi.deploymentInfo.electricalDownTilt - ); -}; - -export const getH3Location = (lat: number, lng: number) => { - try { - const h3Index = latLngToCell(lat, lng, 12); - return new anchor.BN(h3Index, 16); - } catch (e) { - return undefined; - } -}; - -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", - }, - pgUser: { - default: "postgres", - }, - pgPassword: { - type: "string", - }, - pgDatabase: { - type: "string", - }, - pgHost: { - default: "localhost", - }, - pgPort: { - default: "5432", - }, - commit: { - type: "boolean", - default: false, - }, - }); - - const argv = await yarg.argv; - const commit = argv.commit; - 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 conn = provider.connection; - const wallet = new anchor.Wallet(loadKeypair(argv.wallet)); - const hem = await initHEM(provider); - const isRds = argv.pgHost.includes("rds.amazon.com"); - const client = new Client({ - user: argv.pgUser, - password: argv.pgPassword, - host: argv.pgHost, - database: argv.pgDatabase, - port: Number(argv.pgPort), - ssl: argv.noSsl - ? { - rejectUnauthorized: false, - } - : false, - }); - - await client.connect(); - const [subDao] = subDaoKey(MOBILE_MINT); - const [rewardableEntityconfig] = rewardableEntityConfigKey(subDao, "MOBILE"); - const wifiInfos = ( - await client.query(` - SELECT c.hs_pubkey, - c.antenna, - c.height AS elevation, - c.azimuth AS azimuth, - c.mt AS mechanical_down_tilt, - c.et AS electrical_down_tilt - FROM radios AS r - JOIN calculations c ON r.last_success_calculation = c.id - WHERE r.is_active IS TRUE - AND radio_type = 'Wifi'; - `) - ).rows.map( - (wifiInfo: WifiInfoRow): WifiInfo => ({ - ...wifiInfo, - location: getH3Location(Number(wifiInfo.lat), Number(wifiInfo.lng)), - deploymentInfo: { - antenna: Number(wifiInfo.antenna), - elevation: Number(wifiInfo.elevation), - azimuth: Number(wifiInfo.azimuth), - mechanicalDownTilt: Number(wifiInfo.mechanical_down_tilt), - electricalDownTilt: Number(wifiInfo.electrical_down_tilt), - }, - }) - ); - - const mobileInfos = wifiInfos.map( - (wifiInfo) => mobileInfoKey(rewardableEntityconfig, wifiInfo.hs_pubkey)[0] - ); - - const accountInfosWithPk = ( - await Promise.all( - chunks(mobileInfos, 100).map((chunk) => - conn.getMultipleAccountsInfo(chunk) - ) - ) - ) - .flat() - .map((accountInfo, idx) => ({ - pubkey: mobileInfos[idx], - wifiInfo: wifiInfos[idx], - ...accountInfo, - })); - - const ixs = ( - await Promise.all( - accountInfosWithPk.map(async (acc) => { - if (acc.data) { - let correction: { - location?: anchor.BN; - deploymentInfo?: MobileDeploymentInfoV0; - } = {}; - - const decodedAcc: MobileHotspotInfo = hem.coder.accounts.decode( - "MobileHotspotInfoV0", - acc.data as Buffer - ); - - const deploymentInfoMissing = - !decodedAcc.deploymentInfo && hasDeploymentInfo(acc.wifiInfo); - - const correctedDeploymentInfo = { - antenna: - acc.wifiInfo.deploymentInfo.antenna || - decodedAcc.deploymentInfo?.wifiInfoV0?.antenna || - 0, - elevation: - decodedAcc.deploymentInfo?.wifiInfoV0?.elevation || - // floored since stored on chain as i32 representation in whole meters - Math.floor(acc.wifiInfo.deploymentInfo.elevation) || - 0, - azimuth: - decodedAcc.deploymentInfo?.wifiInfoV0?.azimuth || - acc.wifiInfo.deploymentInfo.azimuth || - 0, - mechanicalDownTilt: - decodedAcc.deploymentInfo?.wifiInfoV0?.mechanicalDownTilt || - acc.wifiInfo.deploymentInfo.mechanicalDownTilt || - 0, - electricalDownTilt: - decodedAcc.deploymentInfo?.wifiInfoV0?.electricalDownTilt || - acc.wifiInfo.deploymentInfo.electricalDownTilt || - 0, - }; - - const deploymentInfoChanged = !deepEqual( - decodedAcc.deploymentInfo?.wifiInfoV0, - correctedDeploymentInfo - ); - - const locationMissing = !decodedAcc.location && acc.wifiInfo.location; - - if (deploymentInfoMissing || deploymentInfoChanged) { - correction = { - ...correction, - deploymentInfo: { - wifiInfoV0: correctedDeploymentInfo, - }, - }; - } - - if (locationMissing) { - correction = { - ...correction, - location: acc.wifiInfo.location, - }; - } - - if (Object.keys(correction).length > 0) { - return await hem.methods - .tempBackfillMobileInfo({ - location: correction.location || null, - deploymentInfo: correction.deploymentInfo || null, - }) - .accounts({ - payer: wallet.publicKey, - mobileInfo: acc.pubkey, - }) - .instruction(); - } - } - }) - ) - ).filter(truthy); - - console.log(`Total corrections needed: ${ixs.length}`); - if (commit) { - try { - const transactions = await batchInstructionsToTxsWithPriorityFee( - provider, - ixs, - { useFirstEstimateForAll: true } - ); - - await bulkSendTransactions( - provider, - transactions, - console.log, - 10, - [], - 100 - ); - } catch (e) { - console.error("Failed to process mobile deployment info updates:", e); - process.exit(1); - } - } -} diff --git a/packages/spl-utils/src/idl/helium_entity_manager.json b/packages/spl-utils/src/idl/helium_entity_manager.json index 2acfafbcf..cce82be83 100644 --- a/packages/spl-utils/src/idl/helium_entity_manager.json +++ b/packages/spl-utils/src/idl/helium_entity_manager.json @@ -1,5 +1,5 @@ { - "version": "0.2.11", + "version": "0.2.12", "name": "helium_entity_manager", "instructions": [ { @@ -3302,34 +3302,6 @@ } } ] - }, - { - "name": "tempBackfillMobileInfo", - "accounts": [ - { - "name": "payer", - "isMut": true, - "isSigner": true - }, - { - "name": "mobileInfo", - "isMut": true, - "isSigner": false - }, - { - "name": "systemProgram", - "isMut": false, - "isSigner": false - } - ], - "args": [ - { - "name": "args", - "type": { - "defined": "TempBackfillMobileInfoArgs" - } - } - ] } ], "accounts": [ @@ -4047,28 +4019,6 @@ ] } }, - { - "name": "TempBackfillMobileInfoArgs", - "type": { - "kind": "struct", - "fields": [ - { - "name": "location", - "type": { - "option": "u64" - } - }, - { - "name": "deploymentInfo", - "type": { - "option": { - "defined": "MobileDeploymentInfoV0" - } - } - } - ] - } - }, { "name": "MetadataArgs", "type": { diff --git a/programs/helium-entity-manager/src/instructions/mod.rs b/programs/helium-entity-manager/src/instructions/mod.rs index 7ddb28fa4..417285d6f 100644 --- a/programs/helium-entity-manager/src/instructions/mod.rs +++ b/programs/helium-entity-manager/src/instructions/mod.rs @@ -16,7 +16,6 @@ pub mod revoke_maker_v0; pub mod revoke_program_v0; pub mod set_entity_active_v0; pub mod set_maker_tree_v0; -pub mod temp_backfill_mobile_info; pub mod temp_pay_mobile_onboarding_fee_v0; pub mod temp_standardize_entity; pub mod update_data_only_tree_v0; @@ -44,7 +43,6 @@ pub use revoke_maker_v0::*; pub use revoke_program_v0::*; pub use set_entity_active_v0::*; pub use set_maker_tree_v0::*; -pub use temp_backfill_mobile_info::*; pub use temp_pay_mobile_onboarding_fee_v0::*; pub use temp_standardize_entity::*; pub use update_data_only_tree_v0::*; diff --git a/programs/helium-entity-manager/src/instructions/temp_backfill_mobile_info.rs b/programs/helium-entity-manager/src/instructions/temp_backfill_mobile_info.rs deleted file mode 100644 index bdd32bf1c..000000000 --- a/programs/helium-entity-manager/src/instructions/temp_backfill_mobile_info.rs +++ /dev/null @@ -1,44 +0,0 @@ -use crate::state::*; -use anchor_lang::prelude::*; -use shared_utils::*; -use std::str::FromStr; - -#[derive(AnchorSerialize, AnchorDeserialize, Clone, Default)] -pub struct TempBackfillMobileInfoArgs { - pub location: Option, - pub deployment_info: Option, -} - -#[derive(Accounts)] -#[instruction(args: TempBackfillMobileInfoArgs)] -pub struct TempBackfillMobileInfo<'info> { - #[account( - mut, - address = Pubkey::from_str("hprdnjkbziK8NqhThmAn5Gu4XqrBbctX8du4PfJdgvW").unwrap() - )] - pub payer: Signer<'info>, - #[account(mut)] - pub mobile_info: Box>, - pub system_program: Program<'info, System>, -} - -pub fn handler<'info>( - ctx: Context<'_, '_, '_, 'info, TempBackfillMobileInfo<'info>>, - args: TempBackfillMobileInfoArgs, -) -> Result<()> { - if let Some(new_location) = args.location { - ctx.accounts.mobile_info.location = Some(new_location); - } - - if let Some(deployment_info) = args.deployment_info { - ctx.accounts.mobile_info.deployment_info = Some(deployment_info); - } - - resize_to_fit( - &ctx.accounts.payer, - &ctx.accounts.system_program.to_account_info(), - &ctx.accounts.mobile_info, - )?; - - Ok(()) -} diff --git a/programs/helium-entity-manager/src/lib.rs b/programs/helium-entity-manager/src/lib.rs index 386f10447..34e7c5ac9 100644 --- a/programs/helium-entity-manager/src/lib.rs +++ b/programs/helium-entity-manager/src/lib.rs @@ -187,11 +187,4 @@ pub mod helium_entity_manager { ) -> Result<()> { onboard_data_only_mobile_hotspot_v0::handler(ctx, args) } - - pub fn temp_backfill_mobile_info<'info>( - ctx: Context<'_, '_, '_, 'info, TempBackfillMobileInfo<'info>>, - args: TempBackfillMobileInfoArgs, - ) -> Result<()> { - temp_backfill_mobile_info::handler(ctx, args) - } }