Skip to content

Commit

Permalink
add getSolanaCLI for agave/solana CLI
Browse files Browse the repository at this point in the history
  • Loading branch information
POPPIN-FUMI committed Nov 5, 2024
1 parent e419d60 commit 1e3e3f0
Show file tree
Hide file tree
Showing 14 changed files with 56 additions and 195 deletions.
15 changes: 8 additions & 7 deletions packages/solv/src/cli/get/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,12 @@ import { AGAVE_VALIDATOR, SOLANA_VALIDATOR } from '@/config/constants'
import chalk from 'chalk'
import { DefaultConfigType } from '@/config/types'
import { Network, NodeType } from '@/config/enums'
import { VERSION_MAINNET, VERSION_SOLANA_RPC, VERSION_TESTNET } from '@/config/versionConfig'
import {
VERSION_MAINNET,
VERSION_SOLANA_RPC,
VERSION_TESTNET,
} from '@/config/versionConfig'
import getSolanaCLI from '@/config/getSolanaCLI'

export const getCommands = (config: DefaultConfigType) => {
const isTest = config.NETWORK === Network.TESTNET
Expand Down Expand Up @@ -64,11 +69,7 @@ export const getCommands = (config: DefaultConfigType) => {
'Snapshot Path',
'/mnt/ledger/snapshot',
)
.option(
'-v, --version <version>',
'Specific Version Node',
version,
)
.option('-v, --version <version>', 'Specific Version Node', version)
.description(`Download the latest snapshot`)
.action(
(options: {
Expand All @@ -89,7 +90,7 @@ export const getCommands = (config: DefaultConfigType) => {
.command('contact')
.description('Show Validator Contact Information')
.action(() => {
const solanaValidatorClient = isTest ? AGAVE_VALIDATOR : SOLANA_VALIDATOR
const solanaValidatorClient = getSolanaCLI()
const cmd = `${solanaValidatorClient} --ledger /mnt/ledger/ contact-info`
spawnSync(cmd, { shell: true, stdio: 'inherit' })
})
Expand Down
15 changes: 3 additions & 12 deletions packages/solv/src/cli/get/monitorSolana.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,10 @@
import {
AGAVE_VALIDATOR,
LEDGER_PATH,
SOLANA_VALIDATOR,
} from '@/config/constants'
import { Network, NodeType } from '@/config/enums'
import { LEDGER_PATH } from '@/config/constants'
import getSolanaCLI from '@/config/getSolanaCLI'
import { DefaultConfigType } from '@/config/types'
import { spawnSync } from 'node:child_process'

export const monitorSolana = (config: DefaultConfigType) => {
const isTestnet = config.NETWORK === Network.TESTNET
const isRPC = config.NODE_TYPE === NodeType.RPC
let solanaValidatorClient = isTestnet ? AGAVE_VALIDATOR : SOLANA_VALIDATOR
if (isRPC) {
solanaValidatorClient = AGAVE_VALIDATOR
}
const solanaValidatorClient = getSolanaCLI()
const cmd = `${solanaValidatorClient} --ledger ${LEDGER_PATH} monitor`
spawnSync(cmd, { shell: true, stdio: 'inherit' })
}
3 changes: 2 additions & 1 deletion packages/solv/src/cli/relayer/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import chalk from 'chalk'
import { LEDGER_PATH } from '@/config/constants'
import { spawnSync } from 'child_process'
import { relayerEnable } from './relayerEnable'
import getSolanaCLI from '@/config/getSolanaCLI'

export const relayerCommands = () => {
const relayer = program
Expand Down Expand Up @@ -66,7 +67,7 @@ export const relayerCommands = () => {
console.log(chalk.red('Please provide a URL'))
return
}
const cmd = `solana-validator --ledger ${LEDGER_PATH} set-relayer-config --relayer-url ${options.url}`
const cmd = `${getSolanaCLI()} --ledger ${LEDGER_PATH} set-relayer-config --relayer-url ${options.url}`
console.log(chalk.white('Setting Relayer URL ...'))
spawnSync(cmd, { shell: true, stdio: 'inherit' })
console.log(chalk.green('🟢 Relayer URL Set'))
Expand Down
15 changes: 3 additions & 12 deletions packages/solv/src/cli/restart/index.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,12 @@
import { program } from '@/index'
import { spawnSync } from 'node:child_process'
import chalk from 'chalk'
import {
AGAVE_VALIDATOR,
LEDGER_PATH,
SOLANA_VALIDATOR,
} from '@/config/constants'
import { LEDGER_PATH } from '@/config/constants'
import { DefaultConfigType } from '@/config/types'
import { Network, NodeType } from '@/config/enums'
import getSolanaCLI from '@/config/getSolanaCLI'

export const restartCommand = (config: DefaultConfigType) => {
const isTestnet = config.NETWORK === Network.TESTNET
const isRPC = config.NODE_TYPE === NodeType.RPC
let solanaValidatorClient = isTestnet ? AGAVE_VALIDATOR : SOLANA_VALIDATOR
if (isRPC) {
solanaValidatorClient = AGAVE_VALIDATOR
}
let solanaValidatorClient = getSolanaCLI()
program
.command('restart')
.description('Restart Solana Validator')
Expand Down
26 changes: 0 additions & 26 deletions packages/solv/src/cli/setup/genStartupValidatorScript.ts

This file was deleted.

8 changes: 2 additions & 6 deletions packages/solv/src/cli/switch/changeIdentityIncoming.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import {
AGAVE_VALIDATOR,
IDENTITY_KEY,
IDENTITY_KEY_PATH,
LEDGER_PATH,
MAINNET_VALIDATOR_KEY_PATH,
SOLANA_VALIDATOR,
SOLV_HOME,
TESTNET_VALIDATOR_KEY_PATH,
UNSTAKED_KEY,
Expand All @@ -16,6 +14,7 @@ import checkValidatorKey from './checkValidatorKey'
import { updateDefaultConfig } from '@/config/updateDefaultConfig'
import { DefaultConfigType } from '@/config/types'
import { Network, NodeType } from '@/config/enums'
import getSolanaCLI from '@/config/getSolanaCLI'

const unstakedKeyPath = join(SOLV_HOME, UNSTAKED_KEY)
const identityKeyPath = join(SOLV_HOME, IDENTITY_KEY)
Expand All @@ -33,10 +32,7 @@ export const changeIdentityIncoming = async (
if (isRPC) {
validatorKeyPath = TESTNET_VALIDATOR_KEY_PATH
}
let solanaClient = isTestnet ? AGAVE_VALIDATOR : SOLANA_VALIDATOR
if (isRPC) {
solanaClient = AGAVE_VALIDATOR
}
const solanaClient = getSolanaCLI()

const isKeyOkay = checkValidatorKey(validatorKeyPath, ip)
if (!isKeyOkay) {
Expand Down
8 changes: 2 additions & 6 deletions packages/solv/src/cli/switch/changeIdentityOutgoing.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import {
AGAVE_VALIDATOR,
IDENTITY_KEY,
IDENTITY_KEY_PATH,
LEDGER_PATH,
MAINNET_VALIDATOR_KEY_PATH,
SOLANA_VALIDATOR,
SOLV_HOME,
TESTNET_VALIDATOR_KEY_PATH,
UNSTAKED_KEY,
Expand All @@ -16,6 +14,7 @@ import checkValidatorKey from './checkValidatorKey'
import { updateDefaultConfig } from '@/config/updateDefaultConfig'
import { DefaultConfigType } from '@/config/types'
import { Network, NodeType } from '@/config/enums'
import getSolanaCLI from '@/config/getSolanaCLI'

const unstakedKeyPath = join(SOLV_HOME, UNSTAKED_KEY)
const identityKeyPath = join(SOLV_HOME, IDENTITY_KEY)
Expand All @@ -34,10 +33,7 @@ export const changeIdentityOutgoing = async (
if (isRPC) {
validatorKeyPath = TESTNET_VALIDATOR_KEY_PATH
}
let solanaClient = isTestnet ? AGAVE_VALIDATOR : SOLANA_VALIDATOR
if (isRPC) {
solanaClient = AGAVE_VALIDATOR
}
let solanaClient = getSolanaCLI()

const isKeyOkay = checkValidatorKey(validatorKeyPath, ip)
if (!isKeyOkay) {
Expand Down
21 changes: 5 additions & 16 deletions packages/solv/src/cli/update/update.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,11 @@
import {
AGAVE_VALIDATOR,
LEDGER_PATH,
SOLANA_VALIDATOR,
} from '@/config/constants'
import { AGAVE_VALIDATOR, LEDGER_PATH } from '@/config/constants'
import { spawnSync } from 'child_process'
import installAgave from '../install/installAgave'
import readConfig from '@/config/readConfig'
import { Network, NodeType } from '@/config/enums'
import getSolanaCLI from '@/config/getSolanaCLI'

export const updateVersion = async (version: string) => {
const config = await readConfig()
const isTestnet = config.NETWORK === Network.TESTNET
const isRPC = config.NODE_TYPE === NodeType.RPC
if (isTestnet || isRPC) {
const solanaCLI = getSolanaCLI()
if (solanaCLI === AGAVE_VALIDATOR) {
installAgave(version)
return
}
Expand All @@ -26,11 +19,7 @@ export const monitorUpdate = async (
maxDelinquentStake: number,
noMonitor = false,
) => {
const config = await readConfig()
const isTestnet = config.NETWORK === Network.TESTNET
const isRPC = config.NODE_TYPE === NodeType.RPC
let solanaValidatorClient =
isRPC || isTestnet ? AGAVE_VALIDATOR : SOLANA_VALIDATOR
const solanaValidatorClient = getSolanaCLI()
let cmd = `${solanaValidatorClient} --ledger ${LEDGER_PATH} exit --max-delinquent-stake ${maxDelinquentStake} --monitor`
if (noMonitor) {
cmd = `${solanaValidatorClient} --ledger ${LEDGER_PATH} exit --max-delinquent-stake ${maxDelinquentStake}`
Expand Down
24 changes: 24 additions & 0 deletions packages/solv/src/config/getSolanaCLI.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import getSolanaVersion from '@/cli/epochTimer/getSolanaVersion'

const SOLANA_CLI = 'solana-validator'
const AGAVE_CLI = 'agave-validator'

export type SolanaCLI = typeof SOLANA_CLI | typeof AGAVE_CLI

const getSolanaCLI = (): SolanaCLI => {
try {
const solanaVersion = getSolanaVersion()
console.log(solanaVersion)
// convert solanaVersion to number. e.g. 1.2.0 to 120
const hasVersion20 = solanaVersion.includes('2.0')
if (hasVersion20) {
return AGAVE_CLI
}
return SOLANA_CLI
} catch (error) {
console.error(error)
return SOLANA_CLI
}
}

export default getSolanaCLI
6 changes: 3 additions & 3 deletions packages/solv/src/config/versionConfig.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
export const VERSION_TESTNET = '2.0.14'
export const VERSION_MAINNET = '1.18.25'
export const VERSION_MAINNET = '2.0.14'
export const VERSION_JITO_TESTNET = '2.0.14'
export const VERSION_JITO_MAINNET = '1.18.26'
export const VERSION_JITO_MAINNET = '2.0.14'
export const VERSION_JITO_RPC = '2.0.14'
export const VERSION_SOLANA_RPC = '1.18.26'
export const VERSION_SOLANA_RPC = '2.0.14'
export const DELINQUENT_STAKE_TESTNET = 10
export const DELINQUENT_STAKE_MAINNET = 5
export const COMMISSION = 5
Expand Down
51 changes: 0 additions & 51 deletions packages/solv/src/lib/migrate/migrateSetup.ts

This file was deleted.

52 changes: 0 additions & 52 deletions packages/solv/src/template/getStartupScript.ts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@ export const startJitoValidatorScript = (
relayerUrl: string,
blockEngineUrl: string,
shredReceiverAddr: string,
solanaCLI = 'agave-validator',
) => {
const script = `#!/bin/bash
exec solana-validator \\
exec ${solanaCLI} \\
--identity ${IDENTITY_KEY_PATH} \\
--vote-account ${MAINNET_VALIDATOR_VOTE_KEY_PATH} \\
--authorized-voter ${MAINNET_VALIDATOR_KEY_PATH} \\
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import {
MAINNET_VALIDATOR_VOTE_KEY_PATH,
} from '@/config/constants'

export const startMainnetValidatorScript = () => {
export const startMainnetValidatorScript = (solanaCLI = 'agave-validator') => {
const script = `#!/bin/bash
exec solana-validator \\
exec ${solanaCLI} \\
--identity ${IDENTITY_KEY_PATH} \\
--vote-account ${MAINNET_VALIDATOR_VOTE_KEY_PATH} \\
--authorized-voter ${MAINNET_VALIDATOR_KEY_PATH} \\
Expand Down

0 comments on commit 1e3e3f0

Please sign in to comment.