Skip to content

Commit

Permalink
update - cli
Browse files Browse the repository at this point in the history
  • Loading branch information
POPPIN-FUMI committed Jan 16, 2025
1 parent 1b63c54 commit 3a3d031
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 37 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ example shows how to set an existing identity key.
.
.
✔︎ Success
✔ Inventory updated to ~/.slv/inventory.yml
✔ Inventory updated to ~/.slv/inventory.testnet.validators.yml
✔ Successfully created solv user on x.x.x.x
```

Expand Down
19 changes: 15 additions & 4 deletions cli/lib/encryptPassword.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,21 @@
import { exec } from '@elsoul/child-process'
import { colors } from '@cliffy/colors'

const encryptPassword = async (password: string): Promise<string> => {
const process = await exec(
`openssl passwd -6 ${password}`,
)
return process.message
try {
const process = await exec(
`openssl passwd -6 ${password}`,
)
return process.message
} catch (_error) {
const errorMessage =
`⚠️ Please install openssl (MacOS: brew install openssl)
brew install openssl
brew --prefix openssl
echo 'export PATH="{openssl path}"' >> ~/.zshrc`
console.error(colors.yellow(errorMessage))
return ''
}
}

export { encryptPassword }
22 changes: 16 additions & 6 deletions cli/lib/getIPByIdentityKey.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,38 @@
import type { InventoryType } from '@cmn/types/config.ts'
import { genOrReadInventory } from '/lib/genOrReadInventory.ts'
import { colors } from '@cliffy/colors'

/// Inventory Data
// testnet_validators:
// hosts:
// 1.1.1.1:
// EjDwu2Czy8eWEYRuNwtjniYks47Du3KNJ6JY9rs3aFSV:
// ansible_host: 1.1.1.1
// identity_account: EjDwu2Czy8eWEYRuNwtjniYks47Du3KNJ6JY9rs3aFSV
// name: EjDwu2Czy8eWEYRuNwtjniYks47Du3KNJ6JY9rs3aFSV
// ansible_user: solv
// ....

const getIPByIdentityKey = async (
identityAccount: string,
limit = 'testnet_validators',
inventoryType: InventoryType,
) => {
try {
const inventory = await genOrReadInventory()
if (!inventory[limit].hosts) {
const inventory = await genOrReadInventory(inventoryType)
if (!inventory[inventoryType].hosts) {
console.log(colors.white('⚠️ No inventory found'))
throw new Error('❌ No inventory found')
}
const ip = Object.keys(inventory[limit].hosts).find(
(key) => inventory[limit].hosts[key].identity_account === identityAccount,
const ip = Object.keys(inventory[inventoryType].hosts).find(
(key) => {
inventory[inventoryType].hosts[key].identity_account === identityAccount
? inventory[inventoryType].hosts[key].ansible_host
: null
},
)
if (!ip) {
console.log(colors.yellow('❌ No IP found'))
throw new Error('❌ No IP found')
}
console.log(colors.white(`✔ Matched IP: ${ip}`))
return ip
} catch (error) {
Expand Down
47 changes: 22 additions & 25 deletions cli/src/validator/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import { listValidators } from '/src/validator/listValidators.ts'
import { getIPByIdentityKey } from '/lib/getIPByIdentityKey.ts'
import { getTemplatePath } from '/lib/getTemplatePath.ts'
import { runAnsilbe } from '/lib/runAnsible.ts'
import type { InventoryType, NetworkType } from '@cmn/types/config.ts'
import { genOrReadInventory } from '/lib/genOrReadInventory.ts'

export const validatorCmd = new Command()
.description('Manage Solana Validator Nodes')
Expand Down Expand Up @@ -50,8 +52,8 @@ validatorCmd.command('list')
default: 'testnet',
})
.action(async (options) => {
// const network = options.network
await listValidators()
const network = options.network as NetworkType
await listValidators(network)
})

validatorCmd.command('set:identity')
Expand All @@ -66,16 +68,14 @@ validatorCmd.command('set:identity')
console.log(colors.yellow('⚠️ Public Key is required'))
return
}
const ip = await getIPByIdentityKey(options.pubkey)
if (!ip) {
console.log(colors.yellow('⚠️ IP not found'))
return
}
console.log(`Setting Validator Identity with IP: ${ip}`)
const inventoryType: InventoryType = options.network === 'mainnet'
? 'mainnet_validators'
: 'testnet_validators'

const templateRoot = getTemplatePath()
const playbook =
`${templateRoot}/ansible/testnet-validator/change_identity_and_restart.yml`
const result = await runAnsilbe(playbook, ip)
const result = await runAnsilbe(playbook, inventoryType, options.pubkey)
if (result) {
console.log(colors.white('✅ Successfully Set Validator Identity'))
return
Expand All @@ -95,16 +95,14 @@ validatorCmd.command('set:unstaked')
console.log(colors.yellow('⚠️ Public Key is required'))
return
}
const ip = await getIPByIdentityKey(options.pubkey)
if (!ip) {
console.log(colors.yellow('⚠️ IP not found'))
return
}
console.log(`Setting Validator Identity with IP: ${ip}`)

const inventoryType: InventoryType = options.network === 'mainnet'
? 'mainnet_validators'
: 'testnet_validators'
const templateRoot = getTemplatePath()
const playbook =
`${templateRoot}/ansible/testnet-validator/set_unstaked_key.yml`
const result = await runAnsilbe(playbook, ip)
const result = await runAnsilbe(playbook, inventoryType, options.pubkey)
if (result) {
console.log(colors.white('✅ Successfully Set Unstaked Identity'))
return
Expand All @@ -127,18 +125,17 @@ validatorCmd.command('restart')
console.log(colors.yellow('⚠️ Public Key is required'))
return
}
const ip = await getIPByIdentityKey(options.pubkey)
if (!ip) {
console.log(colors.yellow('⚠️ IP not found'))
return
}
console.log(`Setting Validator Identity with IP: ${ip}`)
const inventoryType: InventoryType = options.network === 'mainnet'
? 'mainnet_validators'
: 'testnet_validators'
const templateRoot = getTemplatePath()
const inventory = await genOrReadInventory(inventoryType)
const validator = inventory[inventoryType].hosts[options.pubkey]
const playbook = options.rm
? `${templateRoot}/ansible/testnet-validator/restart_firedancer_with_rm_ledger.yml`
: `${templateRoot}/ansible/testnet-validator/restart_firedancer.yml`
? `${templateRoot}/ansible/testnet-validator/restart_${validator.validator_type}_with_rm_ledger.yml`
: `${templateRoot}/ansible/testnet-validator/restart_${validator.validator_type}.yml`

const result = await runAnsilbe(playbook, ip)
const result = await runAnsilbe(playbook, inventoryType, options.pubkey)
if (result) {
console.log(colors.white('✅ Successfully Restarted Validator'))
return
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
- name: Execute tasks as solv user
- name: Stop Agave, Rm ledger, DL snapshot, and run Agave
hosts: all
become: yes
tasks:
Expand Down

0 comments on commit 3a3d031

Please sign in to comment.