Skip to content

Commit

Permalink
Merge pull request #79 from EpicsDAO/ledger
Browse files Browse the repository at this point in the history
add LEDGER_PATH in solv.config.json
  • Loading branch information
POPPIN-FUMI authored Feb 22, 2024
2 parents ce0b0d9 + ce54a8f commit 0bc5d92
Show file tree
Hide file tree
Showing 10 changed files with 56 additions and 16 deletions.
22 changes: 22 additions & 0 deletions .changeset/neat-melons-marry.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
---
'@epics-dao/solv': patch
---

## added LEDGER_PATH in solv.config.json

Update solv version

```bash
pnpm add -g @epics-dao/solv
```

To set custom ledger path, add LEDGER_PATH in solv.config.json

```~/solv.config.json
{
"LEDGER_PATH": "path/to/ledger",
..
}
```

Default ledger path is `/mnt/ledger`
4 changes: 2 additions & 2 deletions packages/solv/src/cli/get/monitorSolana.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { startupScriptPaths } from '@/config/config'
import { readOrCreateDefaultConfig } from '@/lib/readOrCreateDefaultConfig'
import { spawnSync } from 'child_process'

export const monitorSolana = () => {
const { ledger } = startupScriptPaths()
const ledger = readOrCreateDefaultConfig().config.LEDGER_PATH
const cmd = `solana-validator --ledger ${ledger} monitor`
spawnSync(cmd, { shell: true, stdio: 'inherit' })
}
12 changes: 7 additions & 5 deletions packages/solv/src/cli/restart/createSnapshot.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import { MT_PATHS } from '@/config/config'
import { ConfigParams } from '@/lib/readOrCreateDefaultConfig'
import { spawnSync } from 'child_process'

export const createSnapshot = () => {
export const createSnapshot = (solvConfig: ConfigParams) => {
try {
const cmd = `solana-ledger-tool -l ${MT_PATHS.LEDGER} \
--snapshot-archive-path ${MT_PATHS.LEDGER} \
--incremental-snapshot-archive-path ${MT_PATHS.LEDGER} \
create-snapshot 254108256 ${MT_PATHS.LEDGER} \
const ledgerPath = solvConfig.config.LEDGER_PATH
const cmd = `solana-ledger-tool -l ${ledgerPath} \
--snapshot-archive-path ${ledgerPath} \
--incremental-snapshot-archive-path ${ledgerPath} \
create-snapshot 254108256 ${ledgerPath} \
--hard-fork 254108256 \
--deactivate-feature-gate EJJewYSddEEtSZHiqugnvhQHiWyZKjkFDQASd7oKSagn`
spawnSync(cmd, { shell: true, stdio: 'inherit' })
Expand Down
2 changes: 1 addition & 1 deletion packages/solv/src/cli/restart/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export const restartCommand = (solvConfig: ConfigParams) => {
if (!answer.confirm) {
return
}
createSnapshot()
createSnapshot(solvConfig)
if (options.snapshot) {
restartFetch(solvConfig)
} else {
Expand Down
4 changes: 3 additions & 1 deletion packages/solv/src/config/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,15 @@ export type CONFIG_TYPE = {
IS_CLIENT: boolean
VALIDATOR_IPS: string[]
MAINNET_TYPE: MAINNET_TYPES
LEDGER_PATH: string
}

export type PartialConfigType = Partial<CONFIG_TYPE>

export const CONFIG: CONFIG_TYPE = {
LANG: LANGS.EN,
USERNAME: 'solv',
SOLANA_VERSION: '1.18.1',
SOLANA_VERSION: '1.18.2',
TESTNET_SOLANA_VERSION: '1.18.2',
MAINNET_SOLANA_VERSION: '1.17.22',
NODE_VERSION: '20.10.0',
Expand All @@ -63,6 +64,7 @@ export const CONFIG: CONFIG_TYPE = {
IS_CLIENT: false,
VALIDATOR_IPS: [],
MAINNET_TYPE: MAINNET_TYPES.SOLANA_CLIENT,
LEDGER_PATH: '/mnt/ledger',
}

export const HOME_PATHS = {
Expand Down
10 changes: 9 additions & 1 deletion packages/solv/src/lib/readOrCreateDefaultConfig.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { CONFIG, CONFIG_TYPE, FILES } from '@/config/config'
import { CONFIG, CONFIG_TYPE, FILES, MT_PATHS } from '@/config/config'
import { LocaleParams } from '@/locales/localeParams'
import readLocale from '@/locales/readLocale'
import { existsSync, readFileSync, writeFileSync } from 'fs'
import os from 'os'
import { updateSolvConfig } from './updateSolvConfig'

export type ConfigParams = {
config: CONFIG_TYPE
Expand All @@ -25,5 +26,12 @@ export const readOrCreateDefaultConfig = () => {
config = CONFIG
}
const locale = readLocale(config.LANG)
if (!config.LEDGER_PATH) {
config.LEDGER_PATH = MT_PATHS.LEDGER
console.log(
'Default LEDGER_PATH is set to ~/solv.config.json\nPlease change it if necessary.',
)
updateSolvConfig({ LEDGER_PATH: MT_PATHS.LEDGER })
}
return { config, locale } as ConfigParams
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { startupScriptPaths } from '@/config/config'
import { readOrCreateDefaultConfig } from '@/lib/readOrCreateDefaultConfig'

export const startJitoValidatorScript = (
commissionBps = 1000,
Expand All @@ -7,8 +8,8 @@ export const startJitoValidatorScript = (
shredReceiverAddr: string,
) => {
const isTest = false
const { identity, voteAccount, log, accounts, ledger } =
startupScriptPaths(isTest)
const ledger = readOrCreateDefaultConfig().config.LEDGER_PATH
const { identity, voteAccount, log, accounts } = startupScriptPaths(isTest)
const script = `#!/bin/bash
exec solana-validator \\
--identity ${identity} \\
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { startupScriptPaths } from '@/config/config'
import { readOrCreateDefaultConfig } from '@/lib/readOrCreateDefaultConfig'

export const startMainnetValidatorScript = () => {
const isTest = false
const { identity, voteAccount, log, accounts, ledger } =
startupScriptPaths(isTest)
const ledger = readOrCreateDefaultConfig().config.LEDGER_PATH
const { identity, voteAccount, log, accounts } = startupScriptPaths(isTest)
const script = `#!/bin/bash
exec solana-validator \\
--identity ${identity} \\
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { startupScriptPaths } from '@/config/config'
import { readOrCreateDefaultConfig } from '@/lib/readOrCreateDefaultConfig'

export const startRPCNodeScript = () => {
const isTest = false
const { identity, log, accounts, ledger } = startupScriptPaths(isTest)
const ledger = readOrCreateDefaultConfig().config.LEDGER_PATH
const { identity, log, accounts } = startupScriptPaths(isTest)
const script = `#!/bin/bash
exec solana-validator \\
--identity ${identity} \\
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { startupScriptPaths } from '@/config/config'
import { readOrCreateDefaultConfig } from '@/lib/readOrCreateDefaultConfig'

export const startTestnetValidatorScript = () => {
const { identity, voteAccount, log, accounts, ledger } = startupScriptPaths()
const ledger = readOrCreateDefaultConfig().config.LEDGER_PATH
const { identity, voteAccount, log, accounts } = startupScriptPaths()
const script = `#!/bin/bash
exec solana-validator \\
--identity ${identity} \\
Expand Down

0 comments on commit 0bc5d92

Please sign in to comment.