From 0de919cc337d4615f281cd718de734bcf3761039 Mon Sep 17 00:00:00 2001 From: Anmol1696 Date: Fri, 27 Jun 2025 16:44:01 +0530 Subject: [PATCH 1/6] initial refactor for cosmos chains to various componenets --- .../src/builders/chains/cosmos/configmap.ts | 353 +++++ .../src/builders/chains/cosmos/genesis.ts | 481 +++++++ .../src/builders/chains/cosmos/index.ts | 51 + .../src/builders/chains/cosmos/statefulset.ts | 38 + .../src/builders/chains/cosmos/validator.ts | 265 ++++ .../packages/generator/src/builders/cosmos.ts | 1183 ----------------- .../packages/generator/src/builders/index.ts | 2 +- 7 files changed, 1189 insertions(+), 1184 deletions(-) create mode 100644 packages/packages/generator/src/builders/chains/cosmos/index.ts create mode 100644 packages/packages/generator/src/builders/chains/cosmos/statefulset.ts delete mode 100644 packages/packages/generator/src/builders/cosmos.ts diff --git a/packages/packages/generator/src/builders/chains/cosmos/configmap.ts b/packages/packages/generator/src/builders/chains/cosmos/configmap.ts index e69de29bb..83f4cea19 100644 --- a/packages/packages/generator/src/builders/chains/cosmos/configmap.ts +++ b/packages/packages/generator/src/builders/chains/cosmos/configmap.ts @@ -0,0 +1,353 @@ +import { Chain, StarshipConfig } from '@starship-ci/types'; +import * as fs from 'fs'; +import { ConfigMap } from 'kubernetesjs'; +import * as path from 'path'; + +import { DefaultsManager } from '../../../defaults'; +import * as helpers from '../../../helpers'; +import { ScriptManager } from '../../../scripts'; +import { IGenerator, Manifest } from '../../../types'; + +/** + * Keys ConfigMap generator + * Handles the global keys.json configuration + */ +export class KeysConfigMapGenerator implements IGenerator { + private config: StarshipConfig; + private projectRoot: string; + + constructor(config: StarshipConfig, projectRoot: string = process.cwd()) { + this.config = config; + this.projectRoot = projectRoot; + } + + generate(): Manifest[] { + const keysFilePath = path.join(this.projectRoot, 'configs', 'keys.json'); + + if (!fs.existsSync(keysFilePath)) { + console.warn( + `Warning: 'configs/keys.json' not found. Skipping Keys ConfigMap.` + ); + return []; + } + + try { + const keysFileContent = fs.readFileSync(keysFilePath, 'utf-8'); + return [ + { + apiVersion: 'v1', + kind: 'ConfigMap', + metadata: { + name: 'keys', + labels: { + ...helpers.getCommonLabels(this.config), + 'app.kubernetes.io/component': 'configmap', + 'app.kubernetes.io/part-of': 'global' + } + }, + data: { + 'keys.json': keysFileContent + } + } + ]; + } catch (error) { + console.warn( + `Warning: Could not read 'configs/keys.json'. Error: ${(error as Error).message}. Skipping.` + ); + return []; + } + } +} + +/** + * Global Scripts ConfigMap generator + * Handles the shared scripts from scripts/default directory + */ +export class GlobalScriptsConfigMapGenerator implements IGenerator { + private config: StarshipConfig; + private projectRoot: string; + + constructor(config: StarshipConfig, projectRoot: string = process.cwd()) { + this.config = config; + this.projectRoot = projectRoot; + } + + generate(): Manifest[] { + const scriptsDir = path.join(this.projectRoot, 'scripts', 'default'); + if (!fs.existsSync(scriptsDir)) { + return []; + } + + const data: { [key: string]: string } = {}; + try { + const scriptFiles = fs + .readdirSync(scriptsDir) + .filter((file) => file.endsWith('.sh')); + + if (scriptFiles.length === 0) { + return []; + } + + scriptFiles.forEach((fileName) => { + const filePath = path.join(scriptsDir, fileName); + data[fileName] = fs.readFileSync(filePath, 'utf-8'); + }); + } catch (error) { + console.warn( + `Warning: Could not read global scripts directory. Error: ${(error as Error).message}. Skipping.` + ); + return []; + } + + return [ + { + apiVersion: 'v1', + kind: 'ConfigMap', + metadata: { + name: 'setup-scripts', + labels: { + ...helpers.getCommonLabels(this.config), + 'app.kubernetes.io/component': 'configmap', + 'app.kubernetes.io/part-of': 'global' + } + }, + data + } + ]; + } +} + +/** + * Chain-specific setup scripts ConfigMap generator + */ +export class SetupScriptsConfigMapGenerator implements IGenerator { + private config: StarshipConfig; + private chain: Chain; + private scriptManager: ScriptManager; + + constructor(chain: Chain, config: StarshipConfig, scriptManager: ScriptManager) { + this.config = config; + this.chain = chain; + this.scriptManager = scriptManager; + } + + generate(): Manifest[] { + const scripts = this.chain.scripts; + + if (!scripts || Object.keys(scripts).length === 0) { + return []; + } + + const data: { [key: string]: string } = {}; + + Object.entries(scripts).forEach(([key, script]) => { + if (!script) return; + + const scriptName = script.name || `${key}.sh`; + try { + data[scriptName] = this.scriptManager.getScriptContent(script); + } catch (error) { + console.warn( + `Warning: Could not load script ${scriptName}. Error: ${(error as Error).message}. Skipping.` + ); + } + }); + + if (Object.keys(data).length === 0) { + return []; + } + + return [ + { + apiVersion: 'v1', + kind: 'ConfigMap', + metadata: { + name: `setup-scripts-${helpers.getHostname(this.chain)}`, + labels: { + ...helpers.getCommonLabels(this.config), + 'app.kubernetes.io/component': 'chain', + 'app.kubernetes.io/name': this.chain.name, + 'app.kubernetes.io/part-of': helpers.getChainId(this.chain), + 'app.kubernetes.io/role': 'setup-scripts', + 'starship.io/chain-name': this.chain.name, + 'starship.io/chain-id': helpers.getChainId(this.chain) + } + }, + data + } + ]; + } +} + +/** + * Genesis patch ConfigMap generator + */ +export class GenesisPatchConfigMapGenerator implements IGenerator { + private config: StarshipConfig; + private chain: Chain; + + constructor(chain: Chain, config: StarshipConfig) { + this.config = config; + this.chain = chain; + } + + generate(): Manifest[] { + if (!this.chain.genesis) { + return []; + } + + return [ + { + apiVersion: 'v1', + kind: 'ConfigMap', + metadata: { + name: `patch-${helpers.getHostname(this.chain)}`, + labels: { + ...helpers.getCommonLabels(this.config), + 'app.kubernetes.io/component': 'chain', + 'app.kubernetes.io/name': this.chain.name, + 'app.kubernetes.io/part-of': helpers.getChainId(this.chain), + 'app.kubernetes.io/role': 'genesis-patch', + 'starship.io/chain-name': this.chain.name, + 'starship.io/chain-id': helpers.getChainId(this.chain) + } + }, + data: { + 'genesis.json': JSON.stringify(this.chain.genesis, null, 2) + } + } + ]; + } +} + +/** + * ICS Consumer Proposal ConfigMap generator + */ +export class IcsConsumerProposalConfigMapGenerator implements IGenerator { + private config: StarshipConfig; + private chain: Chain; + private defaultsManager: DefaultsManager; + + constructor(chain: Chain, config: StarshipConfig) { + this.config = config; + this.chain = chain; + this.defaultsManager = new DefaultsManager(); + } + + generate(): Manifest[] { + if (!this.chain.ics?.enabled || !this.chain.ics.provider) { + return []; + } + + const providerChain = this.config.chains.find( + (c) => c.id === this.chain.ics.provider + ); + + if (!providerChain) { + console.warn( + `Warning: ICS Provider chain '${this.chain.ics.provider}' not found. Skipping ICS proposal for '${this.chain.id}'.` + ); + return []; + } + + const processedProviderChain = this.defaultsManager.processChain(providerChain); + + const proposal = { + title: `Add ${this.chain.name} consumer chain`, + summary: `Add ${this.chain.name} consumer chain with id ${helpers.getChainId(this.chain)}`, + chain_id: helpers.getChainId(this.chain), + initial_height: { + revision_height: 1, + revision_number: 1 + }, + genesis_hash: + 'd86d756e10118e66e6805e9cc476949da2e750098fcc7634fd0cc77f57a0b2b0', + binary_hash: + '376cdbd3a222a3d5c730c9637454cd4dd925e2f9e2e0d0f3702fc922928583f1', + spawn_time: '2023-02-28T20:40:00.000000Z', + unbonding_period: 294000000000, + ccv_timeout_period: 259920000000, + transfer_timeout_period: 18000000000, + consumer_redistribution_fraction: '0.75', + blocks_per_distribution_transmission: 10, + historical_entries: 100, + distribution_transmission_channel: '', + top_N: 95, + validators_power_cap: 0, + validator_set_cap: 0, + allowlist: [] as string[], + denylist: [] as string[], + deposit: `10000${processedProviderChain.denom}` + }; + + return [ + { + apiVersion: 'v1', + kind: 'ConfigMap', + metadata: { + name: `consumer-proposal-${helpers.getHostname(this.chain)}`, + labels: { + ...helpers.getCommonLabels(this.config), + 'app.kubernetes.io/component': 'chain', + 'app.kubernetes.io/name': this.chain.name, + 'app.kubernetes.io/part-of': helpers.getChainId(this.chain), + 'app.kubernetes.io/role': 'ics-proposal', + 'starship.io/chain-name': this.chain.name, + 'starship.io/chain-id': helpers.getChainId(this.chain) + } + }, + data: { + 'proposal.json': JSON.stringify(proposal, null, 2) + } + } + ]; + } +} + +/** + * Main ConfigMap generator orchestrator for Cosmos chains + */ +export class CosmosConfigMapGenerator implements IGenerator { + private config: StarshipConfig; + private chain: Chain; + private scriptManager: ScriptManager; + private generators: IGenerator[]; + + constructor(chain: Chain, config: StarshipConfig, scriptManager: ScriptManager) { + this.config = config; + this.chain = chain; + this.scriptManager = scriptManager; + + this.generators = [ + new SetupScriptsConfigMapGenerator(this.chain, this.config, this.scriptManager), + new GenesisPatchConfigMapGenerator(this.chain, this.config), + new IcsConsumerProposalConfigMapGenerator(this.chain, this.config) + ]; + } + + generate(): Manifest[] { + return this.generators.flatMap((generator) => generator.generate()); + } +} + +/** + * Global ConfigMap generator orchestrator + * Handles ConfigMaps that are shared across all chains + */ +export class GlobalConfigMapGenerator implements IGenerator { + private config: StarshipConfig; + private generators: IGenerator[]; + + constructor(config: StarshipConfig, projectRoot?: string) { + this.config = config; + + this.generators = [ + new KeysConfigMapGenerator(this.config, projectRoot), + new GlobalScriptsConfigMapGenerator(this.config, projectRoot) + ]; + } + + generate(): Manifest[] { + return this.generators.flatMap((generator) => generator.generate()); + } +} diff --git a/packages/packages/generator/src/builders/chains/cosmos/genesis.ts b/packages/packages/generator/src/builders/chains/cosmos/genesis.ts index e69de29bb..ae291fa07 100644 --- a/packages/packages/generator/src/builders/chains/cosmos/genesis.ts +++ b/packages/packages/generator/src/builders/chains/cosmos/genesis.ts @@ -0,0 +1,481 @@ +import { Chain, StarshipConfig } from '@starship-ci/types'; +import { Container, StatefulSet } from 'kubernetesjs'; + +import { DefaultsManager } from '../../../defaults'; +import * as helpers from '../../../helpers'; +import { ScriptManager } from '../../../scripts'; +import { IGenerator, Manifest } from '../../../types'; +import { getGeneratorVersion } from '../../../version'; + +export class CosmosGenesisStatefulSetGenerator implements IGenerator { + private config: StarshipConfig; + private chain: Chain; + private scriptManager: ScriptManager; + private defaultsManager: DefaultsManager; + + constructor(chain: Chain, config: StarshipConfig, scriptManager: ScriptManager) { + this.config = config; + this.chain = chain; + this.scriptManager = scriptManager; + this.defaultsManager = new DefaultsManager(); + } + + labels(): Record { + const processedChain = this.defaultsManager.processChain(this.chain); + return { + ...helpers.getCommonLabels(this.config), + 'app.kubernetes.io/component': 'chain', + 'app.kubernetes.io/part-of': helpers.getChainId(processedChain), + 'app.kubernetes.io/id': helpers.getChainId(processedChain), + 'app.kubernetes.io/name': `${helpers.getHostname(processedChain)}-genesis`, + 'app.kubernetes.io/type': `${helpers.getChainId(processedChain)}-statefulset`, + 'app.kubernetes.io/role': 'genesis', + 'starship.io/chain-name': processedChain.name + }; + } + + generate(): Array { + const processedChain = this.defaultsManager.processChain(this.chain); + + return [ + { + apiVersion: 'apps/v1', + kind: 'StatefulSet', + metadata: { + name: `${helpers.getHostname(processedChain)}-genesis`, + labels: this.labels() + }, + spec: { + serviceName: `${helpers.getHostname(processedChain)}-genesis`, + replicas: 1, + revisionHistoryLimit: 3, + selector: { + matchLabels: { + 'app.kubernetes.io/instance': this.config.name, + 'app.kubernetes.io/name': `${helpers.getChainId(processedChain)}-genesis` + } + }, + template: { + metadata: { + annotations: { + quality: 'release', + role: 'api-gateway', + sla: 'high', + tier: 'gateway' + }, + labels: { + 'app.kubernetes.io/instance': this.config.name, + 'app.kubernetes.io/type': helpers.getChainId(processedChain), + 'app.kubernetes.io/name': `${helpers.getChainId(processedChain)}-genesis`, + 'app.kubernetes.io/rawname': helpers.getChainId(processedChain), + 'app.kubernetes.io/version': getGeneratorVersion(), + 'app.kubernetes.io/role': 'genesis' + } + }, + spec: { + ...((processedChain as any).imagePullSecrets + ? helpers.generateImagePullSecrets((processedChain as any).imagePullSecrets) + : {}), + initContainers: this.createInitContainers(processedChain), + containers: this.createMainContainers(processedChain), + volumes: helpers.generateChainVolumes(processedChain) + } + } + } + } + ]; + } + + private createInitContainers(chain: Chain): Container[] { + const initContainers: Container[] = []; + const exposerPort = this.config.exposer?.ports?.rest || 8081; + + // Build images init container if needed + if (chain.build?.enabled || chain.upgrade?.enabled) { + initContainers.push(this.createBuildImagesInitContainer(chain)); + } + + // Genesis init container + initContainers.push(this.createGenesisInitContainer(chain)); + + // Config init container + initContainers.push(this.createConfigInitContainer(chain)); + + // Add additional init containers based on chain configuration + if (chain.faucet?.enabled && chain.faucet.type === 'starship') { + initContainers.push(this.createFaucetInitContainer(chain)); + } + + if (chain.ics?.enabled) { + initContainers.push(this.createIcsInitContainer(chain, exposerPort)); + } + + return initContainers; + } + + private createMainContainers(chain: Chain): Container[] { + const containers: Container[] = []; + + // Main validator container + containers.push(this.createValidatorContainer(chain)); + + // Exposer container + containers.push(this.createExposerContainer(chain)); + + // Faucet container if enabled + if (chain.faucet?.enabled) { + containers.push(this.createFaucetContainer(chain)); + } + + return containers; + } + + private createBuildImagesInitContainer(chain: Chain): Container { + const buildCommands = [ + '# Install cosmovisor', + 'go install github.com/cosmos/cosmos-sdk/cosmovisor/cmd/cosmovisor@v1.0.0', + '', + '# Build genesis' + ]; + + if (chain.upgrade?.enabled) { + // Build genesis version + buildCommands.push( + `UPGRADE_NAME=genesis CODE_TAG=${chain.upgrade.genesis} bash -e /scripts/build-chain.sh` + ); + + // Build upgrade versions + if (chain.upgrade.upgrades) { + chain.upgrade.upgrades.forEach((upgrade: any) => { + buildCommands.push( + `UPGRADE_NAME=${upgrade.name} CODE_TAG=${upgrade.version} bash -e /scripts/build-chain.sh` + ); + }); + } + } else if (chain.build?.enabled) { + buildCommands.push( + `UPGRADE_NAME=genesis CODE_TAG=${chain.build.source} bash -e /scripts/build-chain.sh` + ); + } + + return { + name: 'init-build-images', + image: 'ghcr.io/cosmology-tech/starship/builder:latest', + imagePullPolicy: 'IfNotPresent', + command: ['bash', '-c', buildCommands.join('\n')], + env: [ + { name: 'CODE_REF', value: chain.repo }, + { name: 'UPGRADE_DIR', value: `${chain.home}/cosmovisor` }, + { name: 'GOBIN', value: '/go/bin' }, + { name: 'CHAIN_NAME', value: helpers.getChainId(chain) }, + ...helpers.getDefaultEnvVars(chain) + ], + resources: helpers.getNodeResources(chain, this.config), + volumeMounts: helpers.generateChainVolumeMounts(chain) + }; + } + + private createGenesisInitContainer(chain: Chain): Container { + return { + name: 'init-genesis', + image: chain.image, + imagePullPolicy: this.config.images?.imagePullPolicy || 'IfNotPresent', + env: [ + ...helpers.getDefaultEnvVars(chain), + ...helpers.getChainEnvVars(chain), + ...helpers.getTimeoutEnvVars(this.config.timeouts || {}), + { name: 'KEYS_CONFIG', value: '/configs/keys.json' }, + { + name: 'FAUCET_ENABLED', + value: String(chain.faucet?.enabled || false) + }, + { + name: 'NUM_VALIDATORS', + value: String(chain.numValidators || 1) + }, + { + name: 'NUM_RELAYERS', + value: String(this.config.relayers?.length || 0) + } + ], + command: ['bash', '-c', this.getGenesisScript(chain)], + resources: helpers.getNodeResources(chain, this.config), + volumeMounts: helpers.generateChainVolumeMounts(chain) + }; + } + + private createConfigInitContainer(chain: Chain): Container { + return { + name: 'init-config', + image: chain.image, + imagePullPolicy: this.config.images?.imagePullPolicy || 'IfNotPresent', + env: [ + ...helpers.getDefaultEnvVars(chain), + ...helpers.getChainEnvVars(chain), + ...helpers.getTimeoutEnvVars(this.config.timeouts || {}), + { name: 'KEYS_CONFIG', value: '/configs/keys.json' }, + { name: 'METRICS', value: String(chain.metrics || false) } + ], + command: ['bash', '-c', '/scripts/update-config.sh'], + resources: helpers.getNodeResources(chain, this.config), + volumeMounts: [ + ...helpers.generateChainVolumeMounts(chain), + ...(chain.genesis + ? [ + { + mountPath: '/patch', + name: 'patch' + } + ] + : []) + ] + }; + } + + private createFaucetInitContainer(chain: Chain): Container { + return { + name: 'init-faucet', + image: chain.faucet!.image, + imagePullPolicy: 'IfNotPresent', + command: [ + 'bash', + '-c', + 'cp /bin/faucet /faucet/faucet && chmod +x /faucet/faucet' + ], + resources: helpers.getNodeResources(chain, this.config), + volumeMounts: [{ mountPath: '/faucet', name: 'faucet' }] + }; + } + + private createIcsInitContainer(chain: Chain, exposerPort: number): Container { + return { + name: 'init-ics', + image: chain.image, + imagePullPolicy: this.config.images?.imagePullPolicy || 'IfNotPresent', + env: [ + ...helpers.getDefaultEnvVars(chain), + { name: 'EXPOSER_PORT', value: String(exposerPort) } + ], + command: [ + 'bash', + '-c', + `echo "ICS initialization for consumer chain ${helpers.getChainId(chain)}"` + ], + resources: helpers.getNodeResources(chain, this.config), + volumeMounts: helpers.generateChainVolumeMounts(chain) + }; + } + + private createValidatorContainer(chain: Chain): Container { + return { + name: 'validator', + image: chain.image, + imagePullPolicy: this.config.images?.imagePullPolicy || 'IfNotPresent', + env: [ + ...helpers.getDefaultEnvVars(chain), + ...helpers.getChainEnvVars(chain), + { + name: 'FAUCET_ENABLED', + value: String(chain.faucet?.enabled || false) + }, + { name: 'SLOGFILE', value: 'slog.slog' }, + ...(chain.env || []).map((env: any) => ({ + name: env.name, + value: String(env.value) + })) + ], + command: ['bash', '-c', this.getValidatorStartScript(chain)], + resources: helpers.getNodeResources(chain, this.config), + volumeMounts: helpers.generateChainVolumeMounts(chain), + ...(chain.cometmock?.enabled + ? {} + : { + readinessProbe: chain.readinessProbe || { + exec: { + command: [ + 'bash', + '-e', + '/scripts/chain-rpc-ready.sh', + 'http://localhost:26657' + ] + }, + initialDelaySeconds: 10, + periodSeconds: 10, + timeoutSeconds: 15 + } + }) + }; + } + + private createExposerContainer(chain: Chain): Container { + return { + name: 'exposer', + image: + this.config.exposer?.image || + 'ghcr.io/cosmology-tech/starship/exposer:latest', + imagePullPolicy: this.config.images?.imagePullPolicy || 'IfNotPresent', + env: [ + ...helpers.getGenesisEnvVars( + chain, + this.config.exposer?.ports?.rest || 8081 + ), + { name: 'EXPOSER_HTTP_PORT', value: '8081' }, + { name: 'EXPOSER_GRPC_PORT', value: '9099' }, + { + name: 'EXPOSER_GENESIS_FILE', + value: `${chain.home}/config/genesis.json` + }, + { name: 'EXPOSER_MNEMONIC_FILE', value: '/configs/keys.json' }, + { + name: 'EXPOSER_PRIV_VAL_FILE', + value: `${chain.home}/config/priv_validator_key.json` + }, + { + name: 'EXPOSER_NODE_KEY_FILE', + value: `${chain.home}/config/node_key.json` + }, + { + name: 'EXPOSER_NODE_ID_FILE', + value: `${chain.home}/config/node_id.json` + }, + { + name: 'EXPOSER_PRIV_VAL_STATE_FILE', + value: `${chain.home}/data/priv_validator_state.json` + } + ], + command: ['exposer'], + resources: helpers.getResourceObject( + this.config.exposer?.resources || { cpu: '0.1', memory: '128M' } + ), + volumeMounts: [ + { mountPath: chain.home, name: 'node' }, + { mountPath: '/configs', name: 'addresses' } + ] + }; + } + + private createFaucetContainer(chain: Chain): Container { + if (chain.faucet?.type === 'cosmjs') { + return this.createCosmjsFaucetContainer(chain); + } + return this.createStarshipFaucetContainer(chain); + } + + private createCosmjsFaucetContainer(chain: Chain): Container { + const faucet = chain.faucet as any; + return { + name: 'faucet', + image: faucet.image, + imagePullPolicy: this.config.images?.imagePullPolicy || 'IfNotPresent', + env: [ + { + name: 'FAUCET_CONCURRENCY', + value: String(faucet.concurrency || 1) + }, + { + name: 'FAUCET_PORT', + value: String(faucet.ports?.rest || 8000) + }, + { + name: 'FAUCET_GAS_PRICE', + value: faucet.gasPrice || '0.025' + }, + { + name: 'FAUCET_PATH_PATTERN', + value: faucet.pathPattern || '' + }, + { name: 'FAUCET_ADDRESS_PREFIX', value: chain.prefix }, + { + name: 'FAUCET_TOKENS', + value: faucet.tokens?.join(',') || chain.denom + }, + { + name: 'FAUCET_CREDIT_AMOUNT_SEND', + value: String(faucet.creditAmount?.send || 10000000) + }, + { + name: 'FAUCET_CREDIT_AMOUNT_STAKE', + value: String(faucet.creditAmount?.stake || 10000000) + }, + { + name: 'FAUCET_MAX_CREDIT', + value: String(faucet.maxCredit || 99999999) + }, + { name: 'FAUCET_MNEMONIC', value: faucet.mnemonic || '' }, + { name: 'FAUCET_CHAIN_ID', value: helpers.getChainId(chain) }, + { + name: 'FAUCET_RPC_ENDPOINT', + value: `http://localhost:${helpers.getPortMap().rpc}` + } + ], + command: ['yarn', 'start'], + resources: helpers.getResourceObject( + faucet.resources || { cpu: '0.2', memory: '200M' } + ), + volumeMounts: [{ mountPath: '/configs', name: 'addresses' }] + }; + } + + private createStarshipFaucetContainer(chain: Chain): Container { + const faucet = chain.faucet as any; + return { + name: 'faucet', + image: 'busybox:1.34.1', + imagePullPolicy: 'IfNotPresent', + env: [ + { + name: 'FAUCET_CONCURRENCY', + value: String(faucet.concurrency || 1) + }, + { + name: 'FAUCET_PORT', + value: String(faucet.ports?.rest || 8000) + }, + { name: 'FAUCET_CHAIN_ID', value: helpers.getChainId(chain) }, + { name: 'FAUCET_CHAIN_DENOM', value: chain.denom }, + { name: 'FAUCET_CHAIN_PREFIX', value: chain.prefix }, + { + name: 'FAUCET_AMOUNT_SEND', + value: String(faucet.creditAmount?.send || 10000000) + }, + { + name: 'FAUCET_AMOUNT_STAKE', + value: String(faucet.creditAmount?.stake || 10000000) + }, + { + name: 'FAUCET_RPC_ENDPOINT', + value: `http://localhost:${helpers.getPortMap().rpc}` + }, + { + name: 'FAUCET_REST_ENDPOINT', + value: `http://localhost:${helpers.getPortMap().rest}` + } + ], + command: ['sh', '-c', '/faucet/faucet'], + resources: helpers.getResourceObject( + faucet.resources || { cpu: '0.1', memory: '128M' } + ), + volumeMounts: [ + { mountPath: '/configs', name: 'addresses' }, + { mountPath: '/faucet', name: 'faucet' } + ] + }; + } + + private getGenesisScript(chain: Chain): string { + return this.scriptManager.getScriptContent( + chain.scripts?.createGenesis || { + name: 'create-genesis.sh', + data: '/scripts/create-genesis.sh' + } + ); + } + + private getValidatorStartScript(chain: Chain): string { + return `#!/bin/bash +set -euo pipefail + +echo "Starting ${chain.binary} validator..." +exec ${chain.binary} start --home ${chain.home} --log_level info`; + } +} diff --git a/packages/packages/generator/src/builders/chains/cosmos/index.ts b/packages/packages/generator/src/builders/chains/cosmos/index.ts new file mode 100644 index 000000000..0822a49f9 --- /dev/null +++ b/packages/packages/generator/src/builders/chains/cosmos/index.ts @@ -0,0 +1,51 @@ +import { StarshipConfig } from '@starship-ci/types'; + +import { ScriptManager } from '../../../scripts'; +import { IGenerator, Manifest } from '../../../types'; +import { CosmosConfigMapGenerator, GlobalConfigMapGenerator } from './configmap'; +import { CosmosServiceGenerator } from './service'; +import { CosmosStatefulSetGenerator } from './statefulset'; + +/** + * Main Cosmos builder + * Orchestrates ConfigMap, Service, and StatefulSet generation for all Cosmos chains + */ +export class CosmosBuilder implements IGenerator { + private config: StarshipConfig; + private scriptManager: ScriptManager; + private generators: IGenerator[]; + + constructor(config: StarshipConfig) { + this.config = config; + this.scriptManager = new ScriptManager(); + this.generators = []; + + // Filter cosmos chains + const cosmosChains = this.config.chains?.filter( + (chain) => chain.name !== 'ethereum' && typeof chain.id === 'string' + ) || []; + + if (cosmosChains.length === 0) { + return; // No cosmos chains to process + } + + // Global ConfigMaps (keys, global scripts) + this.generators.push(new GlobalConfigMapGenerator(this.config)); + + // Per-chain generators + cosmosChains.forEach((chain) => { + // Services + this.generators.push(new CosmosServiceGenerator(chain, this.config)); + + // StatefulSets + this.generators.push(new CosmosStatefulSetGenerator(chain, this.config, this.scriptManager)); + + // ConfigMaps + this.generators.push(new CosmosConfigMapGenerator(chain, this.config, this.scriptManager)); + }); + } + + generate(): Manifest[] { + return this.generators.flatMap((generator) => generator.generate()); + } +} \ No newline at end of file diff --git a/packages/packages/generator/src/builders/chains/cosmos/statefulset.ts b/packages/packages/generator/src/builders/chains/cosmos/statefulset.ts new file mode 100644 index 000000000..15f12128f --- /dev/null +++ b/packages/packages/generator/src/builders/chains/cosmos/statefulset.ts @@ -0,0 +1,38 @@ +import { Chain, StarshipConfig } from '@starship-ci/types'; + +import { ScriptManager } from '../../../scripts'; +import { IGenerator, Manifest } from '../../../types'; +import { CosmosGenesisStatefulSetGenerator } from './genesis'; +import { CosmosValidatorStatefulSetGenerator } from './validator'; + +/** + * StatefulSet generator for Cosmos chains + * Handles genesis and validator StatefulSets + */ +export class CosmosStatefulSetGenerator implements IGenerator { + private config: StarshipConfig; + private chain: Chain; + private scriptManager: ScriptManager; + private statefulSetGenerators: Array; + + constructor(chain: Chain, config: StarshipConfig, scriptManager: ScriptManager) { + this.config = config; + this.chain = chain; + this.scriptManager = scriptManager; + + this.statefulSetGenerators = [ + new CosmosGenesisStatefulSetGenerator(this.chain, this.config, this.scriptManager) + ]; + + // Add validator StatefulSet if numValidators > 1 + if (this.chain.numValidators && this.chain.numValidators > 1) { + this.statefulSetGenerators.push( + new CosmosValidatorStatefulSetGenerator(this.chain, this.config, this.scriptManager) + ); + } + } + + generate(): Array { + return this.statefulSetGenerators.flatMap((generator) => generator.generate()); + } +} \ No newline at end of file diff --git a/packages/packages/generator/src/builders/chains/cosmos/validator.ts b/packages/packages/generator/src/builders/chains/cosmos/validator.ts index e69de29bb..61d4fa7cb 100644 --- a/packages/packages/generator/src/builders/chains/cosmos/validator.ts +++ b/packages/packages/generator/src/builders/chains/cosmos/validator.ts @@ -0,0 +1,265 @@ +import { Chain, StarshipConfig } from '@starship-ci/types'; +import { Container, StatefulSet } from 'kubernetesjs'; + +import { DefaultsManager } from '../../../defaults'; +import * as helpers from '../../../helpers'; +import { ScriptManager } from '../../../scripts'; +import { IGenerator, Manifest } from '../../../types'; +import { getGeneratorVersion } from '../../../version'; + +export class CosmosValidatorStatefulSetGenerator implements IGenerator { + private config: StarshipConfig; + private chain: Chain; + private scriptManager: ScriptManager; + private defaultsManager: DefaultsManager; + + constructor(chain: Chain, config: StarshipConfig, scriptManager: ScriptManager) { + this.config = config; + this.chain = chain; + this.scriptManager = scriptManager; + this.defaultsManager = new DefaultsManager(); + } + + labels(): Record { + const processedChain = this.defaultsManager.processChain(this.chain); + return { + ...helpers.getCommonLabels(this.config), + 'app.kubernetes.io/component': 'chain', + 'app.kubernetes.io/part-of': helpers.getChainId(processedChain), + 'app.kubernetes.io/id': helpers.getChainId(processedChain), + 'app.kubernetes.io/name': `${helpers.getHostname(processedChain)}-validator`, + 'app.kubernetes.io/type': `${helpers.getChainId(processedChain)}-statefulset`, + 'app.kubernetes.io/role': 'validator', + 'starship.io/chain-name': processedChain.name + }; + } + + generate(): Array { + const processedChain = this.defaultsManager.processChain(this.chain); + + return [ + { + apiVersion: 'apps/v1', + kind: 'StatefulSet', + metadata: { + name: `${helpers.getHostname(processedChain)}-validator`, + labels: this.labels() + }, + spec: { + serviceName: `${helpers.getHostname(processedChain)}-validator`, + podManagementPolicy: 'Parallel', + replicas: (processedChain.numValidators || 1) - 1, + revisionHistoryLimit: 3, + selector: { + matchLabels: { + 'app.kubernetes.io/instance': this.config.name, + 'app.kubernetes.io/name': `${helpers.getChainId(processedChain)}-validator` + } + }, + template: { + metadata: { + annotations: { + quality: 'release', + role: 'api-gateway', + sla: 'high', + tier: 'gateway' + }, + labels: { + 'app.kubernetes.io/instance': this.config.name, + 'app.kubernetes.io/type': helpers.getChainId(processedChain), + 'app.kubernetes.io/name': `${helpers.getChainId(processedChain)}-validator`, + 'app.kubernetes.io/version': getGeneratorVersion(), + 'app.kubernetes.io/role': 'validator' + } + }, + spec: { + ...((processedChain as any).imagePullSecrets + ? helpers.generateImagePullSecrets((processedChain as any).imagePullSecrets) + : {}), + initContainers: this.createInitContainers(processedChain), + containers: this.createMainContainers(processedChain), + volumes: helpers.generateChainVolumes(processedChain) + } + } + } + } + ]; + } + + private createInitContainers(chain: Chain): Container[] { + const initContainers: Container[] = []; + + // Build images init container if needed + if (chain.build?.enabled || chain.upgrade?.enabled) { + initContainers.push(this.createBuildImagesInitContainer(chain)); + } + + // Validator init container + initContainers.push(this.createValidatorInitContainer(chain)); + + // Validator config init container + initContainers.push(this.createValidatorConfigContainer(chain)); + + return initContainers; + } + + private createMainContainers(chain: Chain): Container[] { + return [this.createValidatorContainer(chain)]; + } + + private createBuildImagesInitContainer(chain: Chain): Container { + const buildCommands = [ + '# Install cosmovisor', + 'go install github.com/cosmos/cosmos-sdk/cosmovisor/cmd/cosmovisor@v1.0.0', + '', + '# Build genesis' + ]; + + if (chain.upgrade?.enabled) { + // Build genesis version + buildCommands.push( + `UPGRADE_NAME=genesis CODE_TAG=${chain.upgrade.genesis} bash -e /scripts/build-chain.sh` + ); + + // Build upgrade versions + if (chain.upgrade.upgrades) { + chain.upgrade.upgrades.forEach((upgrade: any) => { + buildCommands.push( + `UPGRADE_NAME=${upgrade.name} CODE_TAG=${upgrade.version} bash -e /scripts/build-chain.sh` + ); + }); + } + } else if (chain.build?.enabled) { + buildCommands.push( + `UPGRADE_NAME=genesis CODE_TAG=${chain.build.source} bash -e /scripts/build-chain.sh` + ); + } + + return { + name: 'init-build-images', + image: 'ghcr.io/cosmology-tech/starship/builder:latest', + imagePullPolicy: 'IfNotPresent', + command: ['bash', '-c', buildCommands.join('\n')], + env: [ + { name: 'CODE_REF', value: chain.repo }, + { name: 'UPGRADE_DIR', value: `${chain.home}/cosmovisor` }, + { name: 'GOBIN', value: '/go/bin' }, + { name: 'CHAIN_NAME', value: helpers.getChainId(chain) }, + ...helpers.getDefaultEnvVars(chain) + ], + resources: helpers.getNodeResources(chain, this.config), + volumeMounts: helpers.generateChainVolumeMounts(chain) + }; + } + + private createValidatorInitContainer(chain: Chain): Container { + return { + name: 'init-validator', + image: chain.image, + imagePullPolicy: this.config.images?.imagePullPolicy || 'IfNotPresent', + env: [ + ...helpers.getDefaultEnvVars(chain), + ...helpers.getChainEnvVars(chain), + ...helpers.getTimeoutEnvVars(this.config.timeouts || {}), + { name: 'KEYS_CONFIG', value: '/configs/keys.json' } + ], + command: ['bash', '-c', this.getValidatorInitScript(chain)], + resources: helpers.getNodeResources(chain, this.config), + volumeMounts: helpers.generateChainVolumeMounts(chain) + }; + } + + private createValidatorConfigContainer(chain: Chain): Container { + return { + name: 'init-validator-config', + image: chain.image, + imagePullPolicy: this.config.images?.imagePullPolicy || 'IfNotPresent', + env: [ + ...helpers.getDefaultEnvVars(chain), + ...helpers.getChainEnvVars(chain), + ...helpers.getTimeoutEnvVars(this.config.timeouts || {}), + { name: 'KEYS_CONFIG', value: '/configs/keys.json' }, + { name: 'METRICS', value: String(chain.metrics || false) } + ], + command: ['bash', '-c', this.getValidatorConfigScript(chain)], + resources: helpers.getNodeResources(chain, this.config), + volumeMounts: helpers.generateChainVolumeMounts(chain) + }; + } + + private createValidatorContainer(chain: Chain): Container { + return { + name: 'validator', + image: chain.image, + imagePullPolicy: this.config.images?.imagePullPolicy || 'IfNotPresent', + env: [ + ...helpers.getDefaultEnvVars(chain), + ...helpers.getChainEnvVars(chain), + { name: 'SLOGFILE', value: 'slog.slog' }, + ...(chain.env || []).map((env: any) => ({ + name: env.name, + value: String(env.value) + })) + ], + command: ['bash', '-c', this.getValidatorStartScript(chain)], + resources: helpers.getNodeResources(chain, this.config), + volumeMounts: helpers.generateChainVolumeMounts(chain), + lifecycle: { + postStart: { + exec: { + command: ['bash', '-c', this.getValidatorPostStartScript(chain)] + } + } + }, + ...(chain.cometmock?.enabled + ? {} + : { + readinessProbe: chain.readinessProbe || { + exec: { + command: [ + 'bash', + '-e', + '/scripts/chain-rpc-ready.sh', + 'http://localhost:26657' + ] + }, + initialDelaySeconds: 10, + periodSeconds: 10, + timeoutSeconds: 15 + } + }) + }; + } + + private getValidatorInitScript(chain: Chain): string { + return `#!/bin/bash +set -euo pipefail + +echo "Initializing validator node for ${helpers.getChainId(chain)}..." +${chain.binary} init validator-\${HOSTNAME##*-} --chain-id ${helpers.getChainId(chain)} --home ${chain.home} +echo "Validator initialization completed"`; + } + + private getValidatorConfigScript(chain: Chain): string { + return this.scriptManager.getScriptContent( + chain.scripts?.updateConfig || { + name: 'update-config.sh', + data: '/scripts/update-config.sh' + } + ); + } + + private getValidatorStartScript(chain: Chain): string { + return `#!/bin/bash +set -euo pipefail + +echo "Starting ${chain.binary} validator..." +exec ${chain.binary} start --home ${chain.home} --log_level info`; + } + + private getValidatorPostStartScript(chain: Chain): string { + return `#!/bin/bash +echo "Validator post-start hook for ${helpers.getChainId(chain)}" +# Add any post-start logic here`; + } +} diff --git a/packages/packages/generator/src/builders/cosmos.ts b/packages/packages/generator/src/builders/cosmos.ts deleted file mode 100644 index a9932488f..000000000 --- a/packages/packages/generator/src/builders/cosmos.ts +++ /dev/null @@ -1,1183 +0,0 @@ -import { Chain, StarshipConfig } from '@starship-ci/types'; -import * as fs from 'fs'; -import { ConfigMap, Container, StatefulSet } from 'kubernetesjs'; -import * as path from 'path'; - -import { DefaultsManager } from '../defaults'; -import * as helpers from '../helpers'; -import { ScriptManager } from '../scripts'; -import { IGenerator, Manifest } from '../types'; -import { getGeneratorVersion } from '../version'; -import { CosmosServiceGenerator } from './chains/cosmos/service'; - -/** - * ConfigMap generator for Cosmos chains - * Handles scripts, genesis patches, and ICS consumer proposals - */ -export class CosmosConfigMapGenerator implements IGenerator { - private scriptManager: ScriptManager; - private defaultsManager: DefaultsManager; - private config: StarshipConfig; - private chain: Chain; - - constructor( - chain: Chain, - config: StarshipConfig, - scriptManager: ScriptManager - ) { - this.scriptManager = scriptManager; - this.defaultsManager = new DefaultsManager(); - this.config = config; - this.chain = this.defaultsManager.processChain(chain); - } - - labels(): Record { - return { - ...helpers.getCommonLabels(this.config), - 'app.kubernetes.io/component': 'chain', - 'app.kubernetes.io/part-of': helpers.getChainId(this.chain), - 'app.kubernetes.io/id': helpers.getChainId(this.chain), - 'app.kubernetes.io/name': this.chain.name, - 'app.kubernetes.io/type': `${helpers.getChainId(this.chain)}-configmap` - }; - } - - /** - * Create scripts ConfigMap - */ - scriptsConfigMap(): ConfigMap { - const scriptsData: Record = {}; - - for (const [key, script] of Object.entries(this.chain.scripts)) { - const scriptName = script.name || `${key}.sh`; - scriptsData[scriptName] = this.scriptManager.getScriptContent(script); - } - - return { - apiVersion: 'v1', - kind: 'ConfigMap', - metadata: { - name: `setup-scripts-${helpers.getHostname(this.chain)}`, - labels: this.labels() - }, - data: scriptsData - }; - } - - /** - * Create genesis patch ConfigMap - */ - genesisPatchConfigMap(): ConfigMap | null { - if (!this.chain.genesis) return null; - - return { - apiVersion: 'v1', - kind: 'ConfigMap', - metadata: { - name: `patch-${helpers.getHostname(this.chain)}`, - labels: this.labels() - }, - data: { - 'genesis.json': JSON.stringify(this.chain.genesis, null, 2) - } - }; - } - - /** - * Create ICS consumer proposal ConfigMap - */ - icsConsumerProposalConfigMap(): ConfigMap | null { - if (!this.chain.ics?.enabled) return null; - - const icsChain = this.defaultsManager.processChain( - this.config.chains.find((c) => c.id === this.chain.ics.provider)! - ); - - return { - apiVersion: 'v1', - kind: 'ConfigMap', - metadata: { - name: `consumer-proposal-${helpers.getHostname(this.chain)}`, - labels: this.labels() - }, - data: { - 'proposal.json': JSON.stringify( - { - title: `Add ${this.chain.name} consumer chain`, - summary: `Add ${this.chain.name} consumer chain with id ${helpers.getChainId(this.chain)}`, - chain_id: helpers.getChainId(this.chain), - initial_height: { - revision_height: 1, - revision_number: 1 - }, - genesis_hash: - 'd86d756e10118e66e6805e9cc476949da2e750098fcc7634fd0cc77f57a0b2b0', - binary_hash: - '376cdbd3a222a3d5c730c9637454cd4dd925e2f9e2e0d0f3702fc922928583f1', - spawn_time: '2023-02-28T20:40:00.000000Z', - unbonding_period: 294000000000, - ccv_timeout_period: 259920000000, - transfer_timeout_period: 18000000000, - consumer_redistribution_fraction: '0.75', - blocks_per_distribution_transmission: 10, - historical_entries: 100, - distribution_transmission_channel: '', - top_N: 95, - validators_power_cap: 0, - validator_set_cap: 0, - allowlist: [] as string[], - denylist: [] as string[], - deposit: `10000${icsChain.denom}` - }, - null, - 2 - ) - } - }; - } - - generate(): Manifest[] { - return [ - this.scriptsConfigMap(), - this.genesisPatchConfigMap(), - this.icsConsumerProposalConfigMap() - ]; - } -} - -/** - * StatefulSet generator for Cosmos chains - * Handles genesis and validator StatefulSets with proper container and init container management - */ -export class CosmosStatefulSetGenerator implements IGenerator { - private scriptManager: ScriptManager; - private defaultsManager: DefaultsManager; - private config: StarshipConfig; - private chain: any; // Chain - - constructor( - chain: Chain, - config: StarshipConfig, - scriptManager: ScriptManager - ) { - this.scriptManager = scriptManager; - this.defaultsManager = new DefaultsManager(); - this.config = config; - this.chain = this.defaultsManager.processChain(chain); - } - - labels(): Record { - return { - ...helpers.getCommonLabels(this.config), - 'app.kubernetes.io/component': 'chain', - 'app.kubernetes.io/part-of': helpers.getChainId(this.chain), - 'app.kubernetes.io/id': helpers.getChainId(this.chain), - 'app.kubernetes.io/name': `${helpers.getHostname(this.chain)}-genesis`, - 'app.kubernetes.io/type': `${helpers.getChainId(this.chain)}-statefulset` - }; - } - - /** - * Create StatefulSet for genesis node - */ - genesisStatefulSet(): StatefulSet { - return { - apiVersion: 'apps/v1', - kind: 'StatefulSet', - metadata: { - name: `${helpers.getHostname(this.chain)}-genesis`, - labels: { - ...this.labels(), - 'app.kubernetes.io/role': 'genesis', - 'starship.io/chain-name': this.chain.name // For directory organization - } - }, - spec: { - serviceName: `${helpers.getHostname(this.chain)}-genesis`, - replicas: 1, - revisionHistoryLimit: 3, - selector: { - matchLabels: { - 'app.kubernetes.io/instance': this.config.name, - 'app.kubernetes.io/name': `${helpers.getChainId(this.chain)}-genesis` - } - }, - template: { - metadata: { - annotations: { - quality: 'release', - role: 'api-gateway', - sla: 'high', - tier: 'gateway' - }, - labels: { - 'app.kubernetes.io/instance': this.config.name, - 'app.kubernetes.io/type': helpers.getChainId(this.chain), - 'app.kubernetes.io/name': `${helpers.getChainId(this.chain)}-genesis`, - 'app.kubernetes.io/rawname': helpers.getChainId(this.chain), - 'app.kubernetes.io/version': getGeneratorVersion(), - 'app.kubernetes.io/role': 'genesis' - } - }, - spec: { - ...(this.chain.imagePullSecrets - ? helpers.generateImagePullSecrets(this.chain.imagePullSecrets) - : {}), - initContainers: this.genesisInitContainers(), - containers: this.genesisContainers(), - volumes: helpers.generateChainVolumes(this.chain) - } - } - } - }; - } - - /** - * Create StatefulSet for validator nodes - */ - validatorStatefulSet(): StatefulSet { - return { - apiVersion: 'apps/v1', - kind: 'StatefulSet', - metadata: { - name: `${helpers.getHostname(this.chain)}-validator`, - labels: { - ...this.labels(), - 'app.kubernetes.io/role': 'validator', - 'starship.io/chain-name': this.chain.name // For directory organization - } - }, - spec: { - serviceName: `${helpers.getHostname(this.chain)}-validator`, - podManagementPolicy: 'Parallel', - replicas: (this.chain.numValidators || 1) - 1, - revisionHistoryLimit: 3, - selector: { - matchLabels: { - 'app.kubernetes.io/instance': this.config.name, - 'app.kubernetes.io/name': `${helpers.getChainId(this.chain)}-validator` - } - }, - template: { - metadata: { - annotations: { - quality: 'release', - role: 'api-gateway', - sla: 'high', - tier: 'gateway' - }, - labels: { - 'app.kubernetes.io/instance': this.config.name, - 'app.kubernetes.io/type': helpers.getChainId(this.chain), - 'app.kubernetes.io/name': `${helpers.getChainId(this.chain)}-validator`, - 'app.kubernetes.io/version': getGeneratorVersion(), - 'app.kubernetes.io/role': 'validator' - } - }, - spec: { - ...(this.chain.imagePullSecrets - ? helpers.generateImagePullSecrets(this.chain.imagePullSecrets) - : {}), - initContainers: this.validatorInitContainers(), - containers: this.validatorContainers(), - volumes: helpers.generateChainVolumes(this.chain) - } - } - } - }; - } - - generate(): Manifest[] { - return [this.genesisStatefulSet(), this.validatorStatefulSet()]; - } - - /** - * Create init containers for genesis node - */ - private genesisInitContainers(): Container[] { - const initContainers: Container[] = []; - const exposerPort = this.config.exposer?.ports?.rest || 8081; - - // Build images init container if needed - if (this.chain.build?.enabled || this.chain.upgrade?.enabled) { - const buildCommands = [ - '# Install cosmovisor', - 'go install github.com/cosmos/cosmos-sdk/cosmovisor/cmd/cosmovisor@v1.0.0', - '', - '# Build genesis' - ]; - - if (this.chain.upgrade?.enabled) { - // Build genesis version - buildCommands.push( - `UPGRADE_NAME=genesis CODE_TAG=${this.chain.upgrade.genesis} bash -e /scripts/build-chain.sh` - ); - - // Build upgrade versions - if (this.chain.upgrade.upgrades) { - this.chain.upgrade.upgrades.forEach((upgrade: any) => { - buildCommands.push( - `UPGRADE_NAME=${upgrade.name} CODE_TAG=${upgrade.version} bash -e /scripts/build-chain.sh` - ); - }); - } - } else if (this.chain.build?.enabled) { - buildCommands.push( - `UPGRADE_NAME=genesis CODE_TAG=${this.chain.build.source} bash -e /scripts/build-chain.sh` - ); - } - - initContainers.push({ - name: 'init-build-images', - image: 'ghcr.io/cosmology-tech/starship/builder:latest', - imagePullPolicy: 'IfNotPresent', - command: ['bash', '-c', buildCommands.join('\n')], - env: [ - { name: 'CODE_REF', value: this.chain.repo }, - { name: 'UPGRADE_DIR', value: `${this.chain.home}/cosmovisor` }, - { name: 'GOBIN', value: '/go/bin' }, - { name: 'CHAIN_NAME', value: helpers.getChainId(this.chain) }, - ...helpers.getDefaultEnvVars(this.chain) - ], - resources: helpers.getNodeResources(this.chain, this.config), - volumeMounts: helpers.generateChainVolumeMounts(this.chain) - }); - } - - // Genesis init container - initContainers.push({ - name: 'init-genesis', - image: this.chain.image, - imagePullPolicy: this.config.images?.imagePullPolicy || 'IfNotPresent', - env: [ - ...helpers.getDefaultEnvVars(this.chain), - ...helpers.getChainEnvVars(this.chain), - ...helpers.getTimeoutEnvVars(this.config.timeouts || {}), - { name: 'KEYS_CONFIG', value: '/configs/keys.json' }, - { - name: 'FAUCET_ENABLED', - value: String(this.chain.faucet?.enabled || false) - }, - { - name: 'NUM_VALIDATORS', - value: String(this.chain.numValidators || 1) - }, - { - name: 'NUM_RELAYERS', - value: String(this.config.relayers?.length || 0) - } - ], - command: ['bash', '-c', this.genesisScript()], - resources: helpers.getNodeResources(this.chain, this.config), - volumeMounts: helpers.generateChainVolumeMounts(this.chain) - }); - - // Config init container - initContainers.push({ - name: 'init-config', - image: this.chain.image, - imagePullPolicy: this.config.images?.imagePullPolicy || 'IfNotPresent', - env: [ - ...helpers.getDefaultEnvVars(this.chain), - ...helpers.getChainEnvVars(this.chain), - ...helpers.getTimeoutEnvVars(this.config.timeouts || {}), - { name: 'KEYS_CONFIG', value: '/configs/keys.json' }, - { name: 'METRICS', value: String(this.chain.metrics || false) } - ], - command: ['bash', '-c', '/scripts/update-config.sh'], - resources: helpers.getNodeResources(this.chain, this.config), - volumeMounts: [ - ...helpers.generateChainVolumeMounts(this.chain), - ...(this.chain.genesis - ? [ - { - mountPath: '/patch', - name: 'patch' - } - ] - : []) - ] - }); - - // Add additional init containers based on chain configuration - if (this.chain.faucet?.enabled && this.chain.faucet.type === 'starship') { - initContainers.push(this.faucetInitContainer()); - } - - if (this.chain.ics?.enabled) { - initContainers.push(this.icsInitContainer(exposerPort)); - } - - return initContainers; - } - - /** - * Create main containers for genesis node - */ - private genesisContainers(): Container[] { - const containers: Container[] = []; - - // Main validator container - containers.push({ - name: 'validator', - image: this.chain.image, - imagePullPolicy: this.config.images?.imagePullPolicy || 'IfNotPresent', - env: [ - ...helpers.getDefaultEnvVars(this.chain), - ...helpers.getChainEnvVars(this.chain), - { - name: 'FAUCET_ENABLED', - value: String(this.chain.faucet?.enabled || false) - }, - { name: 'SLOGFILE', value: 'slog.slog' }, - ...(this.chain.env || []).map((env: any) => ({ - name: env.name, - value: String(env.value) - })) - ], - command: ['bash', '-c', this.validatorStartScript()], - resources: helpers.getNodeResources(this.chain, this.config), - volumeMounts: helpers.generateChainVolumeMounts(this.chain), - ...(this.chain.cometmock?.enabled - ? {} - : { - readinessProbe: this.chain.readinessProbe || { - exec: { - command: [ - 'bash', - '-e', - '/scripts/chain-rpc-ready.sh', - 'http://localhost:26657' - ] - }, - initialDelaySeconds: 10, - periodSeconds: 10, - timeoutSeconds: 15 - } - }) - }); - - // Exposer container - containers.push({ - name: 'exposer', - image: - this.config.exposer?.image || - 'ghcr.io/cosmology-tech/starship/exposer:latest', - imagePullPolicy: this.config.images?.imagePullPolicy || 'IfNotPresent', - env: [ - ...helpers.getGenesisEnvVars( - this.chain, - this.config.exposer?.ports?.rest || 8081 - ), - { name: 'EXPOSER_HTTP_PORT', value: '8081' }, - { name: 'EXPOSER_GRPC_PORT', value: '9099' }, - { - name: 'EXPOSER_GENESIS_FILE', - value: `${this.chain.home}/config/genesis.json` - }, - { name: 'EXPOSER_MNEMONIC_FILE', value: '/configs/keys.json' }, - { - name: 'EXPOSER_PRIV_VAL_FILE', - value: `${this.chain.home}/config/priv_validator_key.json` - }, - { - name: 'EXPOSER_NODE_KEY_FILE', - value: `${this.chain.home}/config/node_key.json` - }, - { - name: 'EXPOSER_NODE_ID_FILE', - value: `${this.chain.home}/config/node_id.json` - }, - { - name: 'EXPOSER_PRIV_VAL_STATE_FILE', - value: `${this.chain.home}/data/priv_validator_state.json` - } - ], - command: ['exposer'], - resources: helpers.getResourceObject( - this.config.exposer?.resources || { cpu: '0.1', memory: '128M' } - ), - volumeMounts: [ - { mountPath: this.chain.home, name: 'node' }, - { mountPath: '/configs', name: 'addresses' } - ] - }); - - // Faucet container if enabled - if (this.chain.faucet?.enabled) { - containers.push(this.faucetContainer()); - } - - return containers; - } - - /** - * Create init containers for validator nodes - */ - private validatorInitContainers(): Container[] { - const initContainers: Container[] = []; - - // Build images init container if needed - if (this.chain.build?.enabled || this.chain.upgrade?.enabled) { - const buildCommands = [ - '# Install cosmovisor', - 'go install github.com/cosmos/cosmos-sdk/cosmovisor/cmd/cosmovisor@v1.0.0', - '', - '# Build genesis' - ]; - - if (this.chain.upgrade?.enabled) { - // Build genesis version - buildCommands.push( - `UPGRADE_NAME=genesis CODE_TAG=${this.chain.upgrade.genesis} bash -e /scripts/build-chain.sh` - ); - - // Build upgrade versions - if (this.chain.upgrade.upgrades) { - this.chain.upgrade.upgrades.forEach((upgrade: any) => { - buildCommands.push( - `UPGRADE_NAME=${upgrade.name} CODE_TAG=${upgrade.version} bash -e /scripts/build-chain.sh` - ); - }); - } - } else if (this.chain.build?.enabled) { - buildCommands.push( - `UPGRADE_NAME=genesis CODE_TAG=${this.chain.build.source} bash -e /scripts/build-chain.sh` - ); - } - - initContainers.push({ - name: 'init-build-images', - image: 'ghcr.io/cosmology-tech/starship/builder:latest', - imagePullPolicy: 'IfNotPresent', - command: ['bash', '-c', buildCommands.join('\n')], - env: [ - { name: 'CODE_REF', value: this.chain.repo }, - { name: 'UPGRADE_DIR', value: `${this.chain.home}/cosmovisor` }, - { name: 'GOBIN', value: '/go/bin' }, - { name: 'CHAIN_NAME', value: helpers.getChainId(this.chain) }, - ...helpers.getDefaultEnvVars(this.chain) - ], - resources: helpers.getNodeResources(this.chain, this.config), - volumeMounts: helpers.generateChainVolumeMounts(this.chain) - }); - } - - // Validator init container - initContainers.push({ - name: 'init-validator', - image: this.chain.image, - imagePullPolicy: this.config.images?.imagePullPolicy || 'IfNotPresent', - env: [ - ...helpers.getDefaultEnvVars(this.chain), - ...helpers.getChainEnvVars(this.chain), - ...helpers.getTimeoutEnvVars(this.config.timeouts || {}), - { name: 'KEYS_CONFIG', value: '/configs/keys.json' } - ], - command: ['bash', '-c', this.validatorInitScript()], - resources: helpers.getNodeResources(this.chain, this.config), - volumeMounts: helpers.generateChainVolumeMounts(this.chain) - }); - - // Validator config init container - initContainers.push({ - name: 'init-validator-config', - image: this.chain.image, - imagePullPolicy: this.config.images?.imagePullPolicy || 'IfNotPresent', - env: [ - ...helpers.getDefaultEnvVars(this.chain), - ...helpers.getChainEnvVars(this.chain), - ...helpers.getTimeoutEnvVars(this.config.timeouts || {}), - { name: 'KEYS_CONFIG', value: '/configs/keys.json' }, - { name: 'METRICS', value: String(this.chain.metrics || false) } - ], - command: ['bash', '-c', this.validatorConfigScript()], - resources: helpers.getNodeResources(this.chain, this.config), - volumeMounts: helpers.generateChainVolumeMounts(this.chain) - }); - - return initContainers; - } - - /** - * Create main containers for validator nodes - */ - private validatorContainers(): Container[] { - const containers: Container[] = []; - - // Main validator container - containers.push({ - name: 'validator', - image: this.chain.image, - imagePullPolicy: this.config.images?.imagePullPolicy || 'IfNotPresent', - env: [ - ...helpers.getDefaultEnvVars(this.chain), - ...helpers.getChainEnvVars(this.chain), - { name: 'SLOGFILE', value: 'slog.slog' }, - ...(this.chain.env || []).map((env: any) => ({ - name: env.name, - value: String(env.value) - })) - ], - command: ['bash', '-c', this.validatorStartScript()], - resources: helpers.getNodeResources(this.chain, this.config), - volumeMounts: helpers.generateChainVolumeMounts(this.chain), - lifecycle: { - postStart: { - exec: { - command: ['bash', '-c', this.validatorPostStartScript()] - } - } - }, - ...(this.chain.cometmock?.enabled - ? {} - : { - readinessProbe: this.chain.readinessProbe || { - exec: { - command: [ - 'bash', - '-e', - '/scripts/chain-rpc-ready.sh', - 'http://localhost:26657' - ] - }, - initialDelaySeconds: 10, - periodSeconds: 10, - timeoutSeconds: 15 - } - }) - }); - - return containers; - } - - private genesisScript(): string { - return this.scriptManager.getScriptContent( - this.chain.scripts['create-genesis'] || { - name: 'create-genesis.sh', - data: '/scripts/create-genesis.sh' - } - ); - } - - private configScript(): string { - return this.scriptManager.getScriptContent( - this.chain.scripts['update-config'] || { - name: 'update-config.sh', - data: '/scripts/update-config.sh' - } - ); - } - - private validatorStartScript(): string { - return `#!/bin/bash -set -euo pipefail - -echo "Starting ${this.chain.binary} validator..." -exec ${this.chain.binary} start --home ${this.chain.home} --log_level info`; - } - - private validatorInitScript(): string { - return `#!/bin/bash -set -euo pipefail - -echo "Initializing validator node for ${helpers.getChainId(this.chain)}..." -${this.chain.binary} init validator-\${HOSTNAME##*-} --chain-id ${helpers.getChainId(this.chain)} --home ${this.chain.home} -echo "Validator initialization completed"`; - } - - private validatorConfigScript(): string { - return this.scriptManager.getScriptContent( - this.chain.scripts['update-config'] || { - name: 'update-config.sh', - data: '/scripts/update-config.sh' - } - ); - } - - private validatorPostStartScript(): string { - return `#!/bin/bash -echo "Validator post-start hook for ${helpers.getChainId(this.chain)}" -# Add any post-start logic here`; - } - - private faucetInitContainer(): Container { - return { - name: 'init-faucet', - image: this.chain.faucet!.image, - imagePullPolicy: 'IfNotPresent', - command: [ - 'bash', - '-c', - 'cp /bin/faucet /faucet/faucet && chmod +x /faucet/faucet' - ], - resources: helpers.getNodeResources(this.chain, this.config), - volumeMounts: [{ mountPath: '/faucet', name: 'faucet' }] - }; - } - - private icsInitContainer(exposerPort: number): Container { - return { - name: 'init-ics', - image: this.chain.image, - imagePullPolicy: this.config.images?.imagePullPolicy || 'IfNotPresent', - env: [ - ...helpers.getDefaultEnvVars(this.chain), - { name: 'EXPOSER_PORT', value: String(exposerPort) } - ], - command: [ - 'bash', - '-c', - `echo "ICS initialization for consumer chain ${helpers.getChainId(this.chain)}"` - ], - resources: helpers.getNodeResources(this.chain, this.config), - volumeMounts: helpers.generateChainVolumeMounts(this.chain) - }; - } - - private faucetContainer(): Container { - if (this.chain.faucet?.type === 'cosmjs') { - return this.cosmjsFaucetContainer(); - } - return this.starshipFaucetContainer(); - } - - private cosmjsFaucetContainer(): Container { - return { - name: 'faucet', - image: this.chain.faucet!.image, - imagePullPolicy: this.config.images?.imagePullPolicy || 'IfNotPresent', - env: [ - { - name: 'FAUCET_CONCURRENCY', - value: String(this.chain.faucet!.concurrency || 1) - }, - { - name: 'FAUCET_PORT', - value: String(this.chain.faucet!.ports?.rest || 8000) - }, - { - name: 'FAUCET_GAS_PRICE', - value: this.chain.faucet!.gasPrice || '0.025' - }, - { - name: 'FAUCET_PATH_PATTERN', - value: this.chain.faucet!.pathPattern || '' - }, - { name: 'FAUCET_ADDRESS_PREFIX', value: this.chain.prefix }, - { - name: 'FAUCET_TOKENS', - value: this.chain.faucet!.tokens?.join(',') || this.chain.denom - }, - { - name: 'FAUCET_CREDIT_AMOUNT_SEND', - value: String(this.chain.faucet!.creditAmount?.send || 10000000) - }, - { - name: 'FAUCET_CREDIT_AMOUNT_STAKE', - value: String(this.chain.faucet!.creditAmount?.stake || 10000000) - }, - { - name: 'FAUCET_MAX_CREDIT', - value: String(this.chain.faucet!.maxCredit || 99999999) - }, - { name: 'FAUCET_MNEMONIC', value: this.chain.faucet!.mnemonic || '' }, - { name: 'FAUCET_CHAIN_ID', value: helpers.getChainId(this.chain) }, - { - name: 'FAUCET_RPC_ENDPOINT', - value: `http://localhost:${helpers.getPortMap().rpc}` - } - ], - command: ['yarn', 'start'], - resources: helpers.getResourceObject( - this.chain.faucet!.resources || { cpu: '0.2', memory: '200M' } - ), - volumeMounts: [{ mountPath: '/configs', name: 'addresses' }] - }; - } - - private starshipFaucetContainer(): Container { - return { - name: 'faucet', - image: 'busybox:1.34.1', - imagePullPolicy: 'IfNotPresent', - env: [ - { - name: 'FAUCET_CONCURRENCY', - value: String(this.chain.faucet!.concurrency || 1) - }, - { - name: 'FAUCET_PORT', - value: String(this.chain.faucet!.ports?.rest || 8000) - }, - { name: 'FAUCET_CHAIN_ID', value: helpers.getChainId(this.chain) }, - { name: 'FAUCET_CHAIN_DENOM', value: this.chain.denom }, - { name: 'FAUCET_CHAIN_PREFIX', value: this.chain.prefix }, - { - name: 'FAUCET_AMOUNT_SEND', - value: String(this.chain.faucet!.creditAmount?.send || 10000000) - }, - { - name: 'FAUCET_AMOUNT_STAKE', - value: String(this.chain.faucet!.creditAmount?.stake || 10000000) - }, - { - name: 'FAUCET_RPC_ENDPOINT', - value: `http://localhost:${helpers.getPortMap().rpc}` - }, - { - name: 'FAUCET_REST_ENDPOINT', - value: `http://localhost:${helpers.getPortMap().rest}` - } - ], - command: ['sh', '-c', '/faucet/faucet'], - resources: helpers.getResourceObject( - this.chain.faucet!.resources || { cpu: '0.1', memory: '128M' } - ), - volumeMounts: [ - { mountPath: '/configs', name: 'addresses' }, - { mountPath: '/faucet', name: 'faucet' } - ] - }; - } -} - -/** - * Main Cosmos builder - * Orchestrates ConfigMap, Service, and StatefulSet generation and file output - */ -export class CosmosBuilder implements IGenerator { - private config: StarshipConfig; - private scriptManager: ScriptManager; - - constructor(config: StarshipConfig) { - this.config = config; - this.scriptManager = new ScriptManager(); - } - - generate(): Manifest[] { - const manifests: Manifest[] = []; - if (!this.config.chains) { - return manifests; - } - - // Filter out non-Cosmos chains (e.g., Ethereum) - const cosmosChains = this.config.chains.filter( - (chain) => chain.name !== 'ethereum' && typeof chain.id === 'string' - ); - - if (cosmosChains.length === 0) { - return manifests; - } - - // Keys ConfigMap - const keysConfigMap = new KeysConfigMap(this.config); - manifests.push(...keysConfigMap.generate()); - - // Global Scripts ConfigMap - const globalScripts = new GlobalScriptsConfigMap(this.config); - manifests.push(...globalScripts.generate()); - - cosmosChains.forEach((chain) => { - // Use sophisticated service generator - const serviceGenerator = new CosmosServiceGenerator(chain, this.config); - - // Genesis Service (always needed) - manifests.push(...serviceGenerator.generate()); - - // Use sophisticated StatefulSet generator - const statefulSetGenerator = new CosmosStatefulSetGenerator( - chain, - this.config, - this.scriptManager - ); - - // Genesis StatefulSet (always needed) - manifests.push(statefulSetGenerator.genesisStatefulSet()); - - // Validator StatefulSet (only if numValidators > 1) - if ((chain.numValidators || 1) > 1) { - manifests.push(statefulSetGenerator.validatorStatefulSet()); - } - - // Setup Scripts ConfigMap - const setupScripts = new SetupScriptsConfigMap(this.config, chain); - manifests.push(...setupScripts.generate()); - - // Genesis Patch ConfigMap (if needed) - if (chain.genesis) { - const patch = new GenesisPatchConfigMap(this.config, chain); - manifests.push(...patch.generate()); - } - - // ICS Consumer Proposal ConfigMap - const icsProposal = new IcsConsumerProposalConfigMap( - this.config, - chain, - cosmosChains - ); - manifests.push(...icsProposal.generate()); - }); - - return manifests; - } -} - -class KeysConfigMap implements IGenerator { - constructor( - private config: StarshipConfig, - private projectRoot: string = process.cwd() - ) {} - - generate(): Manifest[] { - const keysFilePath = path.join(this.projectRoot, 'configs', 'keys.json'); - - if (!fs.existsSync(keysFilePath)) { - console.warn( - `Warning: 'configs/keys.json' not found. Skipping Keys ConfigMap.` - ); - return []; - } - - try { - const keysFileContent = fs.readFileSync(keysFilePath, 'utf-8'); - return [ - { - apiVersion: 'v1', - kind: 'ConfigMap', - metadata: { - name: 'keys', - labels: { - ...helpers.getCommonLabels(this.config), - 'app.kubernetes.io/component': 'configmap', - 'app.kubernetes.io/part-of': 'global' - } - }, - data: { - 'keys.json': keysFileContent - } - } - ]; - } catch (error) { - console.warn( - `Warning: Could not read 'configs/keys.json'. Error: ${(error as Error).message}. Skipping.` - ); - return null; - } - } -} - -class GlobalScriptsConfigMap implements IGenerator { - constructor( - private config: StarshipConfig, - private projectRoot: string = process.cwd() - ) {} - - generate(): Manifest[] { - const scriptsDir = path.join(this.projectRoot, 'scripts', 'default'); - if (!fs.existsSync(scriptsDir)) { - return null; // No global scripts directory found - } - - const data: { [key: string]: string } = {}; - try { - const scriptFiles = fs - .readdirSync(scriptsDir) - .filter((file) => file.endsWith('.sh')); - - if (scriptFiles.length === 0) { - return null; - } - - scriptFiles.forEach((fileName) => { - const filePath = path.join(scriptsDir, fileName); - data[fileName] = fs.readFileSync(filePath, 'utf-8'); - }); - } catch (error) { - console.warn( - `Warning: Could not read global scripts directory. Error: ${(error as Error).message}. Skipping.` - ); - return []; - } - - return [ - { - apiVersion: 'v1', - kind: 'ConfigMap', - metadata: { - name: 'setup-scripts', - labels: { - ...helpers.getCommonLabels(this.config), - 'app.kubernetes.io/component': 'configmap', - 'app.kubernetes.io/part-of': 'global' - } - }, - data - } - ]; - } -} - -class SetupScriptsConfigMap implements IGenerator { - constructor( - private config: StarshipConfig, - private chain: Chain - ) {} - - generate(): Manifest[] { - const scripts = this.chain.scripts; - - if (!scripts || Object.keys(scripts).length === 0) { - return []; - } - - const data: { [key: string]: string } = {}; - - Object.entries(scripts).forEach(([key, script]) => { - if (!script) return; - - const scriptName = script.name || `${key}.sh`; - - if (script.data) { - data[scriptName] = script.data; - } else if (script.file) { - try { - // Assuming file paths are relative to the current working directory - data[scriptName] = fs.readFileSync(script.file, 'utf-8'); - } catch (error) { - console.warn( - `Warning: Could not read script file ${script.file}. Error: ${(error as Error).message}. Skipping.` - ); - } - } - }); - - if (Object.keys(data).length === 0) { - return []; - } - - return [ - { - apiVersion: 'v1', - kind: 'ConfigMap', - metadata: { - name: `setup-scripts-${helpers.getChainName(String(this.chain.id))}`, - labels: { - ...helpers.getCommonLabels(this.config), - 'app.kubernetes.io/component': 'chain', - 'app.kubernetes.io/name': this.chain.name, // Add the missing chain name label - 'app.kubernetes.io/part-of': String(this.chain.id), - 'app.kubernetes.io/role': 'setup-scripts' - } - }, - data - } - ]; - } -} - -class GenesisPatchConfigMap implements IGenerator { - constructor( - private config: StarshipConfig, - private chain: Chain - ) {} - - generate(): Manifest[] { - // ConfigMap definition here... - return [ - { - apiVersion: 'v1', - kind: 'ConfigMap', - metadata: { - name: `patch-${helpers.getChainName(String(this.chain.id))}`, - labels: { - ...helpers.getCommonLabels(this.config), - 'app.kubernetes.io/component': 'chain', - 'app.kubernetes.io/name': this.chain.name, // Add the missing chain name label - 'app.kubernetes.io/part-of': String(this.chain.id), - 'app.kubernetes.io/role': 'genesis-patch' - } - }, - data: { - 'patch.json': JSON.stringify(this.chain.genesis, null, 2) - } - } - ]; - } -} - -class IcsConsumerProposalConfigMap implements IGenerator { - constructor( - private config: StarshipConfig, - private chain: Chain, - private allChains: Chain[] - ) {} - - generate(): Manifest[] { - if ( - !this.chain.ics || - !this.chain.ics.enabled || - !this.chain.ics.provider - ) { - return []; - } - - const providerChain = this.allChains.find( - (c) => c.id === this.chain.ics.provider - ); - if (!providerChain) { - console.warn( - `Warning: ICS Provider chain '${this.chain.ics.provider}' not found. Skipping ICS proposal for '${this.chain.id}'.` - ); - return []; - } - - const proposal = { - title: `Add ${this.chain.name} consumer chain`, - summary: `Add ${this.chain.name} consumer chain with id ${this.chain.id}`, - chain_id: this.chain.id, - initial_height: { - revision_height: 1, - revision_number: 1 - }, - genesis_hash: - 'd86d756e10118e66e6805e9cc476949da2e750098fcc7634fd0cc77f57a0b2b0', // placeholder - binary_hash: - '376cdbd3a222a3d5c730c9637454cd4dd925e2f9e2e0d0f3702fc922928583f1', // placeholder - spawn_time: '2023-02-28T20:40:00.000000Z', // placeholder - unbonding_period: 294000000000, - ccv_timeout_period: 259920000000, - transfer_timeout_period: 18000000000, - consumer_redistribution_fraction: '0.75', - blocks_per_distribution_transmission: 10, - historical_entries: 100, - distribution_transmission_channel: '', - top_N: 95, - validators_power_cap: 0, - validator_set_cap: 0, - allowlist: [] as string[], - denylist: [] as string[], - deposit: `10000${providerChain.denom}` - }; - - return [ - { - apiVersion: 'v1', - kind: 'ConfigMap', - metadata: { - name: `consumer-proposal-${helpers.getChainName(String(this.chain.id))}`, - labels: { - ...helpers.getCommonLabels(this.config), - 'app.kubernetes.io/component': 'chain', - 'app.kubernetes.io/name': this.chain.name, // Add the missing chain name label - 'app.kubernetes.io/part-of': String(this.chain.id), - 'app.kubernetes.io/role': 'ics-proposal' - } - }, - data: { - 'proposal.json': JSON.stringify(proposal, null, 2) - } - } - ]; - } -} diff --git a/packages/packages/generator/src/builders/index.ts b/packages/packages/generator/src/builders/index.ts index 64d63e81a..ddd3c362a 100644 --- a/packages/packages/generator/src/builders/index.ts +++ b/packages/packages/generator/src/builders/index.ts @@ -5,7 +5,7 @@ import * as path from 'path'; import { applyDefaults } from '../defaults'; import { Manifest } from '../types'; -import { CosmosBuilder } from './cosmos'; +import { CosmosBuilder } from './chains/cosmos'; import { ExplorerBuilder } from './explorer'; import { FrontendBuilder } from './frontend'; import { RegistryBuilder } from './registry'; From 47eb8877a219bff74e11f2c1ee8d6ba32dd72276 Mon Sep 17 00:00:00 2001 From: Anmol1696 Date: Mon, 30 Jun 2025 16:11:32 +0530 Subject: [PATCH 2/6] update some basic functions for cosmos --- .../src/builders/chains/cosmos/genesis.ts | 354 ++++++++++++++---- packages/packages/generator/src/helpers.ts | 18 + 2 files changed, 300 insertions(+), 72 deletions(-) diff --git a/packages/packages/generator/src/builders/chains/cosmos/genesis.ts b/packages/packages/generator/src/builders/chains/cosmos/genesis.ts index ae291fa07..665a20d47 100644 --- a/packages/packages/generator/src/builders/chains/cosmos/genesis.ts +++ b/packages/packages/generator/src/builders/chains/cosmos/genesis.ts @@ -1,4 +1,4 @@ -import { Chain, StarshipConfig } from '@starship-ci/types'; +import { Chain, FaucetConfig, StarshipConfig } from '@starship-ci/types'; import { Container, StatefulSet } from 'kubernetesjs'; import { DefaultsManager } from '../../../defaults'; @@ -107,6 +107,9 @@ export class CosmosGenesisStatefulSetGenerator implements IGenerator { } if (chain.ics?.enabled) { + // Add wait container for provider chain + const providerChainId = chain.ics.provider || 'cosmoshub'; + initContainers.push(this.createIcsWaitInitContainer([{ id: providerChainId } as Chain], exposerPort)); initContainers.push(this.createIcsInitContainer(chain, exposerPort)); } @@ -198,7 +201,7 @@ export class CosmosGenesisStatefulSetGenerator implements IGenerator { value: String(this.config.relayers?.length || 0) } ], - command: ['bash', '-c', this.getGenesisScript(chain)], + command: ['bash', '-c', this.getGenesisInitScript(chain)], resources: helpers.getNodeResources(chain, this.config), volumeMounts: helpers.generateChainVolumeMounts(chain) }; @@ -216,7 +219,7 @@ export class CosmosGenesisStatefulSetGenerator implements IGenerator { { name: 'KEYS_CONFIG', value: '/configs/keys.json' }, { name: 'METRICS', value: String(chain.metrics || false) } ], - command: ['bash', '-c', '/scripts/update-config.sh'], + command: ['bash', '-c', this.getConfigInitScript(chain)], resources: helpers.getNodeResources(chain, this.config), volumeMounts: [ ...helpers.generateChainVolumeMounts(chain), @@ -248,25 +251,50 @@ export class CosmosGenesisStatefulSetGenerator implements IGenerator { } private createIcsInitContainer(chain: Chain, exposerPort: number): Container { + // Need to get provider chain info - for now using a placeholder + // In real implementation, this would need access to provider chain config + const providerChainId = chain.ics?.provider || 'cosmoshub'; + const providerHostname = helpers.getChainName(providerChainId); + return { name: 'init-ics', - image: chain.image, + image: chain.image, // Should use provider chain image in real implementation imagePullPolicy: this.config.images?.imagePullPolicy || 'IfNotPresent', env: [ ...helpers.getDefaultEnvVars(chain), - { name: 'EXPOSER_PORT', value: String(exposerPort) } - ], - command: [ - 'bash', - '-c', - `echo "ICS initialization for consumer chain ${helpers.getChainId(chain)}"` + ...helpers.getChainEnvVars(chain), + { + name: 'NAMESPACE', + valueFrom: { + fieldRef: { + fieldPath: 'metadata.namespace' + } + } + }, + { name: 'KEYS_CONFIG', value: '/configs/keys.json' } ], + command: ['bash', '-c', this.getIcsInitScript(chain, providerHostname)], resources: helpers.getNodeResources(chain, this.config), - volumeMounts: helpers.generateChainVolumeMounts(chain) + volumeMounts: [ + { mountPath: '/proposal', name: 'proposal' }, + { mountPath: chain.home, name: 'node' }, + { mountPath: '/configs', name: 'addresses' }, + { mountPath: '/scripts', name: 'scripts' } + ] }; } + private createIcsWaitInitContainer(chains: Chain[], port: number): Container { + return helpers.generateWaitInitContainer( + chains, + port, + this.config.images?.imagePullPolicy || 'IfNotPresent' + ) as Container; + } + private createValidatorContainer(chain: Chain): Container { + const toBuild = chain.build?.enabled || chain.upgrade?.enabled; + return { name: 'validator', image: chain.image, @@ -279,6 +307,10 @@ export class CosmosGenesisStatefulSetGenerator implements IGenerator { value: String(chain.faucet?.enabled || false) }, { name: 'SLOGFILE', value: 'slog.slog' }, + ...(toBuild ? [ + { name: 'DAEMON_NAME', value: chain.binary || helpers.getChainId(chain) }, + { name: 'DAEMON_HOME', value: chain.home || `/home/validator/.${helpers.getChainId(chain)}` } + ] : []), ...(chain.env || []).map((env: any) => ({ name: env.name, value: String(env.value) @@ -362,10 +394,10 @@ export class CosmosGenesisStatefulSetGenerator implements IGenerator { } private createCosmjsFaucetContainer(chain: Chain): Container { - const faucet = chain.faucet as any; + const faucet = chain.faucet as FaucetConfig; return { name: 'faucet', - image: faucet.image, + image: faucet.image || 'ghcr.io/cosmology-tech/starship/faucet:latest', imagePullPolicy: this.config.images?.imagePullPolicy || 'IfNotPresent', env: [ { @@ -376,92 +408,157 @@ export class CosmosGenesisStatefulSetGenerator implements IGenerator { name: 'FAUCET_PORT', value: String(faucet.ports?.rest || 8000) }, - { - name: 'FAUCET_GAS_PRICE', - value: faucet.gasPrice || '0.025' - }, - { - name: 'FAUCET_PATH_PATTERN', - value: faucet.pathPattern || '' - }, + { name: 'FAUCET_MEMO', value: 'faucet txn' }, + { name: 'FAUCET_GAS_PRICE', value: `1.25${chain.denom}` }, + { name: 'FAUCET_GAS_LIMIT', value: '2000000' }, { name: 'FAUCET_ADDRESS_PREFIX', value: chain.prefix }, - { - name: 'FAUCET_TOKENS', - value: faucet.tokens?.join(',') || chain.denom - }, - { - name: 'FAUCET_CREDIT_AMOUNT_SEND', - value: String(faucet.creditAmount?.send || 10000000) - }, - { - name: 'FAUCET_CREDIT_AMOUNT_STAKE', - value: String(faucet.creditAmount?.stake || 10000000) - }, - { - name: 'FAUCET_MAX_CREDIT', - value: String(faucet.maxCredit || 99999999) - }, - { name: 'FAUCET_MNEMONIC', value: faucet.mnemonic || '' }, - { name: 'FAUCET_CHAIN_ID', value: helpers.getChainId(chain) }, - { - name: 'FAUCET_RPC_ENDPOINT', - value: `http://localhost:${helpers.getPortMap().rpc}` - } + { name: 'FAUCET_REFILL_FACTOR', value: '8' }, + { name: 'FAUCET_REFILL_THRESHOLD', value: '20' }, + { name: 'FAUCET_COOLDOWN_TIME', value: '0' }, + { name: 'COINS', value: chain.coins || `1000000000000000000${chain.denom}` }, + { name: 'HD_PATH', value: chain.hdPath || "m/44'/118'/0'/0/0" } ], - command: ['yarn', 'start'], + command: ['bash', '-c', this.getCosmjsFaucetScript()], resources: helpers.getResourceObject( faucet.resources || { cpu: '0.2', memory: '200M' } ), - volumeMounts: [{ mountPath: '/configs', name: 'addresses' }] + volumeMounts: [ + { mountPath: '/configs', name: 'addresses' }, + { mountPath: '/scripts', name: 'scripts' } + ], + readinessProbe: { + httpGet: { + path: '/status', + port: String(faucet.ports?.rest || 8000) + }, + initialDelaySeconds: 30, + periodSeconds: 10 + } }; } private createStarshipFaucetContainer(chain: Chain): Container { - const faucet = chain.faucet as any; + const faucet = chain.faucet as FaucetConfig; return { name: 'faucet', - image: 'busybox:1.34.1', - imagePullPolicy: 'IfNotPresent', + image: chain.image, + imagePullPolicy: this.config.images?.imagePullPolicy || 'IfNotPresent', env: [ { name: 'FAUCET_CONCURRENCY', value: String(faucet.concurrency || 1) }, { - name: 'FAUCET_PORT', + name: 'FAUCET_HTTP_PORT', value: String(faucet.ports?.rest || 8000) }, + { name: 'FAUCET_CHAIN_BINARY', value: chain.binary || helpers.getChainId(chain) }, { name: 'FAUCET_CHAIN_ID', value: helpers.getChainId(chain) }, - { name: 'FAUCET_CHAIN_DENOM', value: chain.denom }, - { name: 'FAUCET_CHAIN_PREFIX', value: chain.prefix }, - { - name: 'FAUCET_AMOUNT_SEND', - value: String(faucet.creditAmount?.send || 10000000) - }, - { - name: 'FAUCET_AMOUNT_STAKE', - value: String(faucet.creditAmount?.stake || 10000000) - }, - { - name: 'FAUCET_RPC_ENDPOINT', - value: `http://localhost:${helpers.getPortMap().rpc}` - }, - { - name: 'FAUCET_REST_ENDPOINT', - value: `http://localhost:${helpers.getPortMap().rest}` - } + { name: 'COINS', value: chain.coins || `1000000000000000000${chain.denom}` } ], - command: ['sh', '-c', '/faucet/faucet'], + command: ['bash', '-c', this.getStarshipFaucetScript()], resources: helpers.getResourceObject( faucet.resources || { cpu: '0.1', memory: '128M' } ), volumeMounts: [ { mountPath: '/configs', name: 'addresses' }, - { mountPath: '/faucet', name: 'faucet' } - ] + { mountPath: '/faucet', name: 'faucet' }, + { mountPath: '/scripts', name: 'scripts' } + ], + readinessProbe: { + httpGet: { + path: '/status', + port: String(faucet.ports?.rest || 8000) + }, + initialDelaySeconds: 30, + periodSeconds: 10 + } }; } + private getGenesisInitScript(chain: Chain): string { + const toBuild = chain.build?.enabled || chain.upgrade?.enabled; + + let script = ` +VAL_INDEX=\${HOSTNAME##*-} +echo "Validator Index: $VAL_INDEX" +`; + + // Add build binary copying logic if needed + if (toBuild) { + script += ` +cp $CHAIN_DIR/cosmovisor/genesis/bin/$CHAIN_BIN /usr/bin +`; + } + + script += ` +if [ -f $CHAIN_DIR/config/genesis.json ]; then + echo "Genesis file exists, exiting init container" + exit 0 +fi + +echo "Running setup genesis script..." +bash -e /scripts/create-genesis.sh +bash -e /scripts/update-genesis.sh + +echo "Create node id json file" +NODE_ID=$($CHAIN_BIN tendermint show-node-id) +echo '{"node_id":"'$NODE_ID'"}' > $CHAIN_DIR/config/node_id.json + +echo "Create consensus key json file" +$CHAIN_BIN tendermint show-validator > $CHAIN_DIR/config/consensus_key.json +cat $CHAIN_DIR/config/consensus_key.json + +echo "Add custom accounts and balances" +CHAIN_GENESIS_CMD=$($CHAIN_BIN 2>&1 | grep -q "genesis-related subcommands" && echo "genesis" || echo "") +`; + + // Add balances if configured + if (chain.balances && chain.balances.length > 0) { + chain.balances.forEach((balance: any) => { + script += ` +echo "Adding balance to ${balance.address}" +$CHAIN_BIN $CHAIN_GENESIS_CMD add-genesis-account ${balance.address} ${balance.amount} --keyring-backend="test" +`; + }); + } + + return script.trim(); + } + + private getConfigInitScript(chain: Chain): string { + const toBuild = chain.build?.enabled || chain.upgrade?.enabled; + + let script = ` +VAL_INDEX=\${HOSTNAME##*-} +echo "Validator Index: $VAL_INDEX" +`; + + // Add build binary copying logic if needed + if (toBuild) { + script += ` +cp $CHAIN_DIR/cosmovisor/genesis/bin/$CHAIN_BIN /usr/bin +`; + } + + script += ` +echo "Running setup config script..." +`; + + // Add genesis patching logic BEFORE config script (order matters!) + if (chain.genesis && Object.keys(chain.genesis).length > 0) { + script += ` +jq -s '.[0] * .[1]' $CHAIN_DIR/config/genesis.json /patch/genesis.json > $CHAIN_DIR/config/genesis.json.tmp && mv $CHAIN_DIR/config/genesis.json.tmp $CHAIN_DIR/config/genesis.json +`; + } + + script += ` +bash -e /scripts/update-config.sh +`; + + return script.trim(); + } + private getGenesisScript(chain: Chain): string { return this.scriptManager.getScriptContent( chain.scripts?.createGenesis || { @@ -472,10 +569,123 @@ export class CosmosGenesisStatefulSetGenerator implements IGenerator { } private getValidatorStartScript(chain: Chain): string { + const toBuild = chain.build?.enabled || chain.upgrade?.enabled; + const chainBin = chain.binary || helpers.getChainId(chain); + const chainHome = chain.home || `/home/validator/.${helpers.getChainId(chain)}`; + return `#!/bin/bash set -euo pipefail -echo "Starting ${chain.binary} validator..." -exec ${chain.binary} start --home ${chain.home} --log_level info`; +START_ARGS="" +${chain.cometmock?.enabled ? `START_ARGS="--grpc-web.enable=false --transport=grpc --with-tendermint=false --address tcp://0.0.0.0:26658"` : ''} + +${toBuild ? `/usr/bin/cosmovisor start $START_ARGS` : `$CHAIN_BIN start $START_ARGS`}`; + } + + private getCosmjsFaucetScript(): string { + return ` +export FAUCET_TOKENS=$(printf '%s\\n' \${COINS//[[:digit:]]/}) +for coin in \${COINS//,/ } +do + var="FAUCET_CREDIT_AMOUNT_$(printf '%s\\n' \${coin//[[:digit:]]/} | tr '[:lower:]' '[:upper:]')" + amt="\${coin//[!0-9]/}" + + if [ \${#amt} -gt 18 ]; then + creditAmt=$(echo $amt | sed -e "s/000000$//") + feesAmt=$(echo $amt | sed -e "s/0000000000000$//") + else + creditAmt=$(echo $amt | sed -e "s/0000$//") + feesAmt=$(echo $amt | sed -e "s/00000000$//") + fi + + export $var="$creditAmt" +done + +export FAUCET_PATH_PATTERN="\${HD_PATH:0:$((\${#HD_PATH}-1))}a" +export FAUCET_MNEMONIC=$(jq -r ".faucet[0].mnemonic" /configs/keys.json) + +echo "FAUCET_MNEMONIC: $FAUCET_MNEMONIC" +echo "FAUCET_PATH_PATTERN: $FAUCET_PATH_PATTERN" + +export | grep "FAUCET" + +until bash -e /scripts/chain-rpc-ready.sh http://localhost:26657; do + sleep 10; +done + +/app/packages/faucet/bin/cosmos-faucet-dist start "http://localhost:26657" +`.trim(); + } + + private getStarshipFaucetScript(): string { + return ` +CREDIT_COINS="" +FEES="" +for coin in \${COINS//,/ } +do + amt="\${coin//[!0-9]/}" + denom="\${coin//[0-9]/}" + + # Calculate the order of magnitude + if [ \${#amt} -gt 18 ]; then + creditAmt=$(echo $amt | sed -e "s/000000$//") + feesAmt=$(echo $amt | sed -e "s/0000000000000$//") + else + creditAmt=$(echo $amt | sed -e "s/0000$//") + feesAmt=$(echo $amt | sed -e "s/00000000$//") + fi + + if [[ $CREDIT_COINS == "" ]] + then + CREDIT_COINS="$creditAmt$denom" + FEES="$feesAmt$denom" + else + CREDIT_COINS="\${CREDIT_COINS},$creditAmt$denom" + fi +done + +export FAUCET_MNEMONIC=$(jq -r ".faucet[0].mnemonic" /configs/keys.json) + +export | grep "FAUCET" + +until bash -e /scripts/chain-rpc-ready.sh http://localhost:26657; do + sleep 10 +done + +/faucet/faucet --credit-coins="$CREDIT_COINS" --chain-fees="$FEES" +`.trim(); + } + + private getIcsInitScript(chain: Chain, providerHostname: string): string { + return ` +export + +echo "Fetching priv keys from provider exposer" +curl -s http://${providerHostname}-genesis.$NAMESPACE.svc.cluster.local:8081/priv_keys | jq > $CHAIN_DIR/config/provider_priv_validator_key.json +cat $CHAIN_DIR/config/provider_priv_validator_key.json + +echo "Replace provider priv validator key with provider keys" +mv $CHAIN_DIR/config/priv_validator_key.json $CHAIN_DIR/config/previous_priv_validator_key.json +mv $CHAIN_DIR/config/provider_priv_validator_key.json $CHAIN_DIR/config/priv_validator_key.json + +echo "Create consumer addition proposal" +DENOM=${chain.ics?.provider ? '$DENOM' : 'uatom'} \\ + CHAIN_ID=${chain.ics?.provider || 'cosmoshub'} \\ + CHAIN_BIN=${chain.binary || '$CHAIN_BIN'} \\ + NODE_URL=http://${providerHostname}-genesis.$NAMESPACE.svc.cluster.local:26657 \\ + PROPOSAL_FILE=/proposal/proposal.json \\ + bash -e /scripts/create-ics.sh + +echo "create ccv state file" +${chain.binary || '$CHAIN_BIN'} query provider consumer-genesis ${helpers.getChainId(chain)} \\ + --node http://${providerHostname}-genesis.$NAMESPACE.svc.cluster.local:26657 \\ + -o json > $CHAIN_DIR/config/ccv-state.json +cat $CHAIN_DIR/config/ccv-state.json | jq + +echo "Update genesis file with ccv state" +jq -s '.[0].app_state.ccvconsumer = .[1] | .[0]' $CHAIN_DIR/config/genesis.json $CHAIN_DIR/config/ccv-state.json > $CHAIN_DIR/config/genesis-ccv.json +mv $CHAIN_DIR/config/genesis.json $CHAIN_DIR/config/genesis-no-ccv.json +mv $CHAIN_DIR/config/genesis-ccv.json $CHAIN_DIR/config/genesis.json +`.trim(); } } diff --git a/packages/packages/generator/src/helpers.ts b/packages/packages/generator/src/helpers.ts index 99acd44ab..c319aa6ea 100644 --- a/packages/packages/generator/src/helpers.ts +++ b/packages/packages/generator/src/helpers.ts @@ -396,6 +396,24 @@ export function generateChainVolumes(chain: Chain): any[] { }); } + // Add faucet volume if starship faucet is enabled + if (chain.faucet?.enabled && chain.faucet.type === 'starship') { + volumes.push({ + name: 'faucet', + emptyDir: {} + }); + } + + // Add proposal volume if ICS is enabled + if (chain.ics?.enabled) { + volumes.push({ + name: 'proposal', + configMap: { + name: `consumer-proposal-${getChainName(String(chain.id))}` + } + }); + } + return volumes; } From 911d7ce8ae6aeb132cae518703107ac311524c24 Mon Sep 17 00:00:00 2001 From: Anmol1696 Date: Mon, 30 Jun 2025 17:29:58 +0530 Subject: [PATCH 3/6] genesis and validator statefulset to be refactored --- .../src/builders/chains/cosmos/genesis.ts | 10 +- .../src/builders/chains/cosmos/validator.ts | 228 +++++++++++++++--- packages/packages/generator/src/helpers.ts | 32 +-- 3 files changed, 220 insertions(+), 50 deletions(-) diff --git a/packages/packages/generator/src/builders/chains/cosmos/genesis.ts b/packages/packages/generator/src/builders/chains/cosmos/genesis.ts index 665a20d47..a5b391609 100644 --- a/packages/packages/generator/src/builders/chains/cosmos/genesis.ts +++ b/packages/packages/generator/src/builders/chains/cosmos/genesis.ts @@ -109,7 +109,7 @@ export class CosmosGenesisStatefulSetGenerator implements IGenerator { if (chain.ics?.enabled) { // Add wait container for provider chain const providerChainId = chain.ics.provider || 'cosmoshub'; - initContainers.push(this.createIcsWaitInitContainer([{ id: providerChainId } as Chain], exposerPort)); + initContainers.push(this.createIcsWaitInitContainer([providerChainId], exposerPort)); initContainers.push(this.createIcsInitContainer(chain, exposerPort)); } @@ -284,12 +284,12 @@ export class CosmosGenesisStatefulSetGenerator implements IGenerator { }; } - private createIcsWaitInitContainer(chains: Chain[], port: number): Container { + private createIcsWaitInitContainer(chainIDs: string[], port: number): Container { return helpers.generateWaitInitContainer( - chains, + chainIDs, port, - this.config.images?.imagePullPolicy || 'IfNotPresent' - ) as Container; + this.config + ); } private createValidatorContainer(chain: Chain): Container { diff --git a/packages/packages/generator/src/builders/chains/cosmos/validator.ts b/packages/packages/generator/src/builders/chains/cosmos/validator.ts index 61d4fa7cb..76fe63c4e 100644 --- a/packages/packages/generator/src/builders/chains/cosmos/validator.ts +++ b/packages/packages/generator/src/builders/chains/cosmos/validator.ts @@ -94,17 +94,70 @@ export class CosmosValidatorStatefulSetGenerator implements IGenerator { initContainers.push(this.createBuildImagesInitContainer(chain)); } + // Wait for genesis node to be ready + initContainers.push(this.createWaitInitContainer(chain)); + // Validator init container initContainers.push(this.createValidatorInitContainer(chain)); - // Validator config init container + // Validator config init container initContainers.push(this.createValidatorConfigContainer(chain)); + // ICS init container if enabled + if (chain.ics?.enabled) { + initContainers.push(this.createIcsInitContainer(chain)); + } + return initContainers; } private createMainContainers(chain: Chain): Container[] { - return [this.createValidatorContainer(chain)]; + const containers: Container[] = []; + + // Main validator container + containers.push(this.createValidatorContainer(chain)); + + // Exposer container + containers.push(this.createExposerContainer(chain)); + + return containers; + } + + private createWaitInitContainer(chain: Chain): Container { + const exposerPort = this.config.exposer?.ports?.rest || 8081; + return helpers.generateWaitInitContainer( + [helpers.getChainId(chain)], + exposerPort, + this.config + ) as Container; + } + + private createIcsInitContainer(chain: Chain): Container { + const providerChainId = chain.ics?.provider; + const providerHostname = helpers.getChainName(providerChainId); + const providerChain = this.config.chains.find((c) => c.id === providerChainId); + + return { + name: 'init-ics', + image: chain.image, // Should use provider chain image in real implementation + imagePullPolicy: this.config.images?.imagePullPolicy || 'IfNotPresent', + env: [ + ...helpers.getDefaultEnvVars(chain), + ...helpers.getChainEnvVars(chain), + { + name: 'NAMESPACE', + valueFrom: { + fieldRef: { + fieldPath: 'metadata.namespace' + } + } + }, + { name: 'KEYS_CONFIG', value: '/configs/keys.json' } + ], + command: ['bash', '-c', this.getIcsInitScript(chain, providerHostname)], + resources: helpers.getNodeResources(chain, this.config), + volumeMounts: helpers.generateChainVolumeMounts(chain) + }; } private createBuildImagesInitContainer(chain: Chain): Container { @@ -161,7 +214,10 @@ export class CosmosValidatorStatefulSetGenerator implements IGenerator { ...helpers.getDefaultEnvVars(chain), ...helpers.getChainEnvVars(chain), ...helpers.getTimeoutEnvVars(this.config.timeouts || {}), - { name: 'KEYS_CONFIG', value: '/configs/keys.json' } + ...helpers.getGenesisEnvVars(chain, this.config.exposer?.ports?.rest || 8081), + { name: 'KEYS_CONFIG', value: '/configs/keys.json' }, + { name: 'FAUCET_ENABLED', value: String(chain.faucet?.enabled || false) }, + { name: 'METRICS', value: String(chain.metrics || false) } ], command: ['bash', '-c', this.getValidatorInitScript(chain)], resources: helpers.getNodeResources(chain, this.config), @@ -171,13 +227,14 @@ export class CosmosValidatorStatefulSetGenerator implements IGenerator { private createValidatorConfigContainer(chain: Chain): Container { return { - name: 'init-validator-config', + name: 'init-config', image: chain.image, imagePullPolicy: this.config.images?.imagePullPolicy || 'IfNotPresent', env: [ ...helpers.getDefaultEnvVars(chain), ...helpers.getChainEnvVars(chain), ...helpers.getTimeoutEnvVars(this.config.timeouts || {}), + ...helpers.getGenesisEnvVars(chain, this.config.exposer?.ports?.rest || 8081), { name: 'KEYS_CONFIG', value: '/configs/keys.json' }, { name: 'METRICS', value: String(chain.metrics || false) } ], @@ -195,6 +252,8 @@ export class CosmosValidatorStatefulSetGenerator implements IGenerator { env: [ ...helpers.getDefaultEnvVars(chain), ...helpers.getChainEnvVars(chain), + ...helpers.getGenesisEnvVars(chain, this.config.exposer?.ports?.rest || 8081), + { name: 'KEYS_CONFIG', value: '/configs/keys.json' }, { name: 'SLOGFILE', value: 'slog.slog' }, ...(chain.env || []).map((env: any) => ({ name: env.name, @@ -204,13 +263,17 @@ export class CosmosValidatorStatefulSetGenerator implements IGenerator { command: ['bash', '-c', this.getValidatorStartScript(chain)], resources: helpers.getNodeResources(chain, this.config), volumeMounts: helpers.generateChainVolumeMounts(chain), - lifecycle: { - postStart: { - exec: { - command: ['bash', '-c', this.getValidatorPostStartScript(chain)] - } - } - }, + ...(chain.cometmock?.enabled || chain.ics?.enabled + ? {} + : { + lifecycle: { + postStart: { + exec: { + command: ['bash', '-c', '-e', this.getValidatorPostStartScript(chain)] + } + } + } + }), ...(chain.cometmock?.enabled ? {} : { @@ -231,35 +294,142 @@ export class CosmosValidatorStatefulSetGenerator implements IGenerator { }; } + private createExposerContainer(chain: Chain): Container { + return { + name: 'exposer', + image: this.config.exposer?.image || 'ghcr.io/cosmology-tech/starship/exposer:latest', + imagePullPolicy: this.config.images?.imagePullPolicy || 'IfNotPresent', + env: [ + ...helpers.getDefaultEnvVars(chain), + ...helpers.getChainEnvVars(chain), + ...helpers.getGenesisEnvVars(chain, this.config.exposer?.ports?.rest || 8081), + { name: 'EXPOSER_HTTP_PORT', value: '8081' }, + { name: 'EXPOSER_GRPC_PORT', value: '9099' }, + { name: 'EXPOSER_GENESIS_FILE', value: `${chain.home}/config/genesis.json` }, + { name: 'EXPOSER_MNEMONIC_FILE', value: '/configs/keys.json' }, + { name: 'EXPOSER_PRIV_VAL_FILE', value: `${chain.home}/config/priv_validator_key.json` }, + { name: 'EXPOSER_NODE_KEY_FILE', value: `${chain.home}/config/node_key.json` }, + { name: 'EXPOSER_PRIV_VAL_STATE_FILE', value: `${chain.home}/data/priv_validator_state.json` } + ], + command: ['exposer'], + resources: helpers.getResourceObject(this.config.exposer?.resources || { cpu: '0.1', memory: '128M' }), + volumeMounts: [ + { mountPath: chain.home, name: 'node' }, + { mountPath: '/configs', name: 'addresses' } + ] + }; + } + + private getIcsInitScript(chain: Chain, providerHostname: string): string { + return ` +VAL_INDEX=\${HOSTNAME##*-} +echo "Validator Index: $VAL_INDEX" + +echo "Fetching priv keys from provider exposer" +curl -s http://${providerHostname}-validator-$VAL_INDEX.${providerHostname}-validator.$NAMESPACE.svc.cluster.local:8081/priv_keys | jq > $CHAIN_DIR/config/provider_priv_validator_key.json +cat $CHAIN_DIR/config/provider_priv_validator_key.json + +echo "Replace provider priv validator key with provider keys" +mv $CHAIN_DIR/config/priv_validator_key.json $CHAIN_DIR/config/previous_priv_validator_key.json +mv $CHAIN_DIR/config/provider_priv_validator_key.json $CHAIN_DIR/config/priv_validator_key.json +`.trim(); + } + private getValidatorInitScript(chain: Chain): string { - return `#!/bin/bash -set -euo pipefail + const toBuild = chain.build?.enabled || chain.upgrade?.enabled; + + return ` +VAL_INDEX=\${HOSTNAME##*-} +echo "Validator Index: $VAL_INDEX" +${toBuild ? 'cp $CHAIN_DIR/cosmovisor/genesis/bin/$CHAIN_BIN /usr/bin' : ''} + +if [ -f $CHAIN_DIR/config/genesis.json ]; then + echo "Genesis file exists, exiting early" + exit 0 +fi + +VAL_NAME=$(jq -r ".validators[0].name" $KEYS_CONFIG)-$VAL_INDEX +echo "Validator Index: $VAL_INDEX, Key name: $VAL_NAME" + +echo "Recover validator $VAL_NAME" +$CHAIN_BIN init $VAL_NAME --chain-id $CHAIN_ID +jq -r ".validators[0].mnemonic" $KEYS_CONFIG | $CHAIN_BIN keys add $VAL_NAME --index $VAL_INDEX --recover --keyring-backend="test" -echo "Initializing validator node for ${helpers.getChainId(chain)}..." -${chain.binary} init validator-\${HOSTNAME##*-} --chain-id ${helpers.getChainId(chain)} --home ${chain.home} -echo "Validator initialization completed"`; +curl http://$GENESIS_HOST.$NAMESPACE.svc.cluster.local:$GENESIS_PORT/genesis -o $CHAIN_DIR/config/genesis.json +echo "Genesis file that we got....." +cat $CHAIN_DIR/config/genesis.json + +echo "Create node id json file" +NODE_ID=$($CHAIN_BIN tendermint show-node-id) +echo '{"node_id":"'$NODE_ID'"}' > $CHAIN_DIR/config/node_id.json +`.trim(); } private getValidatorConfigScript(chain: Chain): string { - return this.scriptManager.getScriptContent( - chain.scripts?.updateConfig || { - name: 'update-config.sh', - data: '/scripts/update-config.sh' - } - ); + const toBuild = chain.build?.enabled || chain.upgrade?.enabled; + + return ` +VAL_INDEX=\${HOSTNAME##*-} +echo "Validator Index: $VAL_INDEX" +${toBuild ? 'cp $CHAIN_DIR/cosmovisor/genesis/bin/$CHAIN_BIN /usr/bin' : ''} + +echo "Running setup config script..." +bash -e /scripts/update-config.sh + +curl -s http://$GENESIS_HOST.$NAMESPACE.svc.cluster.local:$GENESIS_PORT/node_id +NODE_ID=$(curl -s http://$GENESIS_HOST.$NAMESPACE.svc.cluster.local:$GENESIS_PORT/node_id | jq -r ".node_id") +if [[ $NODE_ID == "" ]]; then + echo "Node ID is null, exiting early" + exit 1 +fi + +GENESIS_NODE_P2P=$NODE_ID@$GENESIS_HOST.$NAMESPACE.svc.cluster.local:26656 +echo "Node P2P: $GENESIS_NODE_P2P" +sed -i "s/persistent_peers = \\"\\"/persistent_peers = \\"$GENESIS_NODE_P2P\\"/g" $CHAIN_DIR/config/config.toml + +echo "Printing the whole config.toml file" +cat $CHAIN_DIR/config/config.toml +`.trim(); } private getValidatorStartScript(chain: Chain): string { - return `#!/bin/bash -set -euo pipefail + const toBuild = chain.build?.enabled || chain.upgrade?.enabled; + + return ` +set -eux +START_ARGS="" +${chain.cometmock?.enabled ? 'START_ARGS="--grpc-web.enable=false --transport=grpc --with-tendermint=false --address tcp://0.0.0.0:26658"' : ''} -echo "Starting ${chain.binary} validator..." -exec ${chain.binary} start --home ${chain.home} --log_level info`; +# Starting the chain +${toBuild ? ` +cp $CHAIN_DIR/cosmovisor/genesis/bin/$CHAIN_BIN /usr/bin +/usr/bin/cosmovisor start $START_ARGS` : ` +$CHAIN_BIN start $START_ARGS`} +`.trim(); } private getValidatorPostStartScript(chain: Chain): string { - return `#!/bin/bash -echo "Validator post-start hook for ${helpers.getChainId(chain)}" -# Add any post-start logic here`; + return ` +until bash -e /scripts/chain-rpc-ready.sh http://localhost:26657; do + sleep 10 +done + +set -eux +export +VAL_INDEX=\${HOSTNAME##*-} +VAL_NAME="$(jq -r ".validators[0].name" $KEYS_CONFIG)-$VAL_INDEX" +echo "Validator Index: $VAL_INDEX, Key name: $VAL_NAME. Chain bin $CHAIN_BIN" + +VAL_ADDR=$($CHAIN_BIN keys show $VAL_NAME -a --keyring-backend="test") +echo "Transfer tokens to address $VAL_ADDR before trying to create validator. Best effort" +bash -e /scripts/transfer-tokens.sh \\ + $VAL_ADDR \\ + $DENOM \\ + http://$GENESIS_HOST.$NAMESPACE.svc.cluster.local:8000/credit \\ + "${chain.faucet?.enabled || false}" || true + +$CHAIN_BIN keys list --keyring-backend test | jq +VAL_NAME=$VAL_NAME bash -e /scripts/create-validator.sh +`.trim(); } } diff --git a/packages/packages/generator/src/helpers.ts b/packages/packages/generator/src/helpers.ts index c319aa6ea..4c8ed93d5 100644 --- a/packages/packages/generator/src/helpers.ts +++ b/packages/packages/generator/src/helpers.ts @@ -1,5 +1,5 @@ -import { Chain, StarshipConfig } from '@starship-ci/types'; -import { EnvVar } from 'kubernetesjs'; +import { Chain, StarshipConfig, Resources } from '@starship-ci/types'; +import { EnvVar, Container, ResourceRequirements, Volume } from 'kubernetesjs'; import { getGeneratorVersion } from './version'; @@ -107,7 +107,7 @@ export function getGenesisEnvVars(chain: Chain, port: number): EnvVar[] { * Get resource object based on input * Handles both simple cpu/memory format and full k8s resource format */ -export function getResourceObject(resources: any): any { +export function getResourceObject(resources: Resources): ResourceRequirements { if (!resources) { return {}; } @@ -133,7 +133,7 @@ export function getResourceObject(resources: any): any { /** * Get node resources with chain-specific overrides */ -export function getNodeResources(chain: Chain, context: StarshipConfig): any { +export function getNodeResources(chain: Chain, context: StarshipConfig): ResourceRequirements { if (chain.resources) { return getResourceObject(chain.resources); } @@ -283,16 +283,16 @@ export function getChainExposerAddrs( * Generate init container for waiting on chains to be ready */ export function generateWaitInitContainer( - chains: Chain[], + chainIDs: string[], port: number, - imagePullPolicy: string = 'IfNotPresent' -): any { - const waitScript = chains + config?: StarshipConfig +): Container { + const waitScript = chainIDs .map( - (chain) => ` - while [ $(curl -sw '%{http_code}' http://${getChainName(String(chain.id))}-genesis.$NAMESPACE.svc.cluster.local:$GENESIS_PORT/node_id -o /dev/null) -ne 200 ]; do - echo "Genesis validator does not seem to be ready for: ${chain.id}. Waiting for it to start..." - echo "Checking: http://${getChainName(String(chain.id))}-genesis.$NAMESPACE.svc.cluster.local:$GENESIS_PORT/node_id" + (chainID) => ` + while [ $(curl -sw '%{http_code}' http://${getChainName(String(chainID))}-genesis.$NAMESPACE.svc.cluster.local:$GENESIS_PORT/node_id -o /dev/null) -ne 200 ]; do + echo "Genesis validator does not seem to be ready for: ${chainID}. Waiting for it to start..." + echo "Checking: http://${getChainName(String(chainID))}-genesis.$NAMESPACE.svc.cluster.local:$GENESIS_PORT/node_id" sleep 10; done` ) @@ -300,8 +300,8 @@ export function generateWaitInitContainer( return { name: 'wait-for-chains', - image: 'curlimages/curl', - imagePullPolicy, + image: 'curlimages/curl:latest', + imagePullPolicy: config?.images?.imagePullPolicy || 'IfNotPresent', env: [ { name: 'GENESIS_PORT', value: String(port) }, { @@ -314,7 +314,7 @@ export function generateWaitInitContainer( } ], command: ['/bin/sh', '-c', `${waitScript}\necho "Ready to start"\nexit 0`], - resources: getResourceObject({ cpu: '0.1', memory: '128M' }) + resources: getResourceObject(config?.resources?.wait || { cpu: '0.1', memory: '128M' }) }; } @@ -366,7 +366,7 @@ export function generateChainVolumeMounts(chain: Chain): any[] { /** * Generate standard volumes for chain pods */ -export function generateChainVolumes(chain: Chain): any[] { +export function generateChainVolumes(chain: Chain): Volume[] { const volumes = [ { name: 'node', From 43d5af182c3395493e6995f701923c67b7dc4c81 Mon Sep 17 00:00:00 2001 From: Anmol1696 Date: Mon, 30 Jun 2025 17:57:57 +0530 Subject: [PATCH 4/6] use chain builder as a router for all chains to be supported --- .../generator/src/builders/chains/index.ts | 40 +++++++++++++++++++ .../packages/generator/src/builders/index.ts | 4 +- .../generator/src/builders/relayers/index.ts | 6 +-- 3 files changed, 43 insertions(+), 7 deletions(-) create mode 100644 packages/packages/generator/src/builders/chains/index.ts diff --git a/packages/packages/generator/src/builders/chains/index.ts b/packages/packages/generator/src/builders/chains/index.ts new file mode 100644 index 000000000..c56d77163 --- /dev/null +++ b/packages/packages/generator/src/builders/chains/index.ts @@ -0,0 +1,40 @@ +import { Chain, StarshipConfig } from '@starship-ci/types'; + +import { IGenerator, Manifest } from '../../types'; +import { CosmosBuilder } from './cosmos'; + +// Export all individual builders and components +export * from './cosmos'; + +const chainBuilderRegistry: Record< + string, + new (config: StarshipConfig) => IGenerator +> = { + // ethereum: EthereumBuilder, // Future: when ethereum builder is implemented +}; + +function createBuilder(chainName: string, config: StarshipConfig): IGenerator { + const builder = chainBuilderRegistry[chainName] || CosmosBuilder; // default to cosmos builder if no builder is found + return new builder(config); +} + +/** + * Main ChainBuilder that uses the factory pattern to create appropriate builders + */ +export class ChainBuilder implements IGenerator { + private config: StarshipConfig; + private generators: IGenerator[] = []; + + constructor(config: StarshipConfig) { + this.config = config; + + // Create builders for each chain + this.config.chains?.forEach((chain) => { + this.generators.push(createBuilder(chain.name, this.config)); + }); + } + + generate(): Manifest[] { + return this.generators.flatMap((generator) => generator.generate()); + } +} diff --git a/packages/packages/generator/src/builders/index.ts b/packages/packages/generator/src/builders/index.ts index ddd3c362a..25d4fec4d 100644 --- a/packages/packages/generator/src/builders/index.ts +++ b/packages/packages/generator/src/builders/index.ts @@ -5,7 +5,7 @@ import * as path from 'path'; import { applyDefaults } from '../defaults'; import { Manifest } from '../types'; -import { CosmosBuilder } from './chains/cosmos'; +import { ChainBuilder } from './chains'; import { ExplorerBuilder } from './explorer'; import { FrontendBuilder } from './frontend'; import { RegistryBuilder } from './registry'; @@ -76,7 +76,7 @@ export class BuilderManager { build(outputDir: string): void { const builders = [ - new CosmosBuilder(this.config), + new ChainBuilder(this.config), new RegistryBuilder(this.config), new ExplorerBuilder(this.config), new FrontendBuilder(this.config), diff --git a/packages/packages/generator/src/builders/relayers/index.ts b/packages/packages/generator/src/builders/relayers/index.ts index 2f60bfefa..4750ef343 100644 --- a/packages/packages/generator/src/builders/relayers/index.ts +++ b/packages/packages/generator/src/builders/relayers/index.ts @@ -38,17 +38,13 @@ function createBuilder(relayer: Relayer, config: StarshipConfig): IGenerator { export class RelayerBuilder implements IGenerator { private config: StarshipConfig; private relayers: Relayer[]; - private defaultsManager: DefaultsManager; private generators: IGenerator[] = []; constructor(config: StarshipConfig) { this.config = config; - this.defaultsManager = new DefaultsManager(); // Process relayers with defaults - this.relayers = (config.relayers || []).map((relayer) => - this.defaultsManager.processRelayer(relayer) - ); + this.relayers = config.relayers || [] this.generators = this.relayers.map((relayer) => createBuilder(relayer, this.config) From 1b2bc47ff0bbb7711cd66d14d35a6638273ab97c Mon Sep 17 00:00:00 2001 From: Anmol1696 Date: Mon, 30 Jun 2025 18:37:16 +0530 Subject: [PATCH 5/6] fix tests and snapshots for cosmos builder --- .../persistencecore/genesis-statefulset.yaml | 141 +- .../setup-scripts-configmap.yaml | 2 + .../validator-statefulset.yaml | 253 +- .../cosmoshub/genesis-statefulset.yaml | 60 +- .../cosmoshub/setup-scripts-configmap.yaml | 2 + .../persistencecore/genesis-statefulset.yaml | 141 +- .../setup-scripts-configmap.yaml | 2 + .../validator-statefulset.yaml | 253 +- .../cosmoshub/genesis-statefulset.yaml | 60 +- .../cosmoshub/setup-scripts-configmap.yaml | 2 + .../osmosis/genesis-statefulset.yaml | 140 +- .../osmosis/setup-scripts-configmap.yaml | 2 + .../cosmoshub/genesis-statefulset.yaml | 53 +- .../cosmoshub/setup-scripts-configmap.yaml | 2 + .../cosmoshub/validator-statefulset.yaml | 246 +- .../osmosis/genesis-statefulset.yaml | 130 +- .../osmosis/setup-scripts-configmap.yaml | 2 + .../osmosis/validator-statefulset.yaml | 248 +- .../osmosis/genesis-patch-configmap.yaml | 4 +- .../osmosis/genesis-statefulset.yaml | 146 +- .../osmosis/setup-scripts-configmap.yaml | 2 + .../osmosis/genesis-patch-configmap.yaml | 4 +- .../osmosis/genesis-statefulset.yaml | 146 +- .../osmosis/setup-scripts-configmap.yaml | 2 + .../osmosis/genesis-statefulset.yaml | 140 +- .../osmosis/setup-scripts-configmap.yaml | 2 + .../osmosis/genesis-patch-configmap.yaml | 4 +- .../osmosis/genesis-statefulset.yaml | 146 +- .../osmosis/setup-scripts-configmap.yaml | 2 + .../cosmoshub/genesis-statefulset.yaml | 53 +- .../cosmoshub/setup-scripts-configmap.yaml | 2 + .../cosmoshub/validator-statefulset.yaml | 246 +- .../osmosis/genesis-statefulset.yaml | 130 +- .../osmosis/setup-scripts-configmap.yaml | 2 + .../osmosis/validator-statefulset.yaml | 248 +- .../cosmoshub/genesis-statefulset.yaml | 53 +- .../cosmoshub/setup-scripts-configmap.yaml | 2 + .../cosmoshub/validator-statefulset.yaml | 246 +- .../osmosis/genesis-statefulset.yaml | 130 +- .../osmosis/setup-scripts-configmap.yaml | 2 + .../osmosis/validator-statefulset.yaml | 248 +- .../cosmoshub/genesis-statefulset.yaml | 53 +- .../cosmoshub/setup-scripts-configmap.yaml | 2 + .../cosmoshub/validator-statefulset.yaml | 246 +- .../relayers/osmosis/genesis-statefulset.yaml | 130 +- .../osmosis/setup-scripts-configmap.yaml | 2 + .../osmosis/validator-statefulset.yaml | 248 +- .../osmosis/genesis-patch-configmap.yaml | 4 +- .../osmosis/genesis-statefulset.yaml | 146 +- .../osmosis/setup-scripts-configmap.yaml | 2 + .../test-chain/genesis-patch-configmap.yaml | 4 +- .../test-chain/genesis-statefulset.yaml | 143 +- .../test-chain/setup-scripts-configmap.yaml | 2 + .../__snapshots__/builder.test.ts.snap | 2796 ++++++++++++++--- .../__snapshots__/cosmos.test.ts.snap | 850 ++++- .../__tests__/cosmos.integration.test.ts | 2 +- .../generator/__tests__/cosmos.test.ts | 4 +- .../src/builders/chains/cosmos/genesis.ts | 2 +- 58 files changed, 7266 insertions(+), 1069 deletions(-) diff --git a/packages/packages/generator/__tests__/__output__/builder-tests/build-chain/persistencecore/genesis-statefulset.yaml b/packages/packages/generator/__tests__/__output__/builder-tests/build-chain/persistencecore/genesis-statefulset.yaml index 4c40b763e..a7025d296 100644 --- a/packages/packages/generator/__tests__/__output__/builder-tests/build-chain/persistencecore/genesis-statefulset.yaml +++ b/packages/packages/generator/__tests__/__output__/builder-tests/build-chain/persistencecore/genesis-statefulset.yaml @@ -122,7 +122,47 @@ spec: command: - bash - '-c' - - /scripts/create-genesis.sh + - >- + VAL_INDEX=${HOSTNAME##*-} + + echo "Validator Index: $VAL_INDEX" + + + cp $CHAIN_DIR/cosmovisor/genesis/bin/$CHAIN_BIN /usr/bin + + + if [ -f $CHAIN_DIR/config/genesis.json ]; then + echo "Genesis file exists, exiting init container" + exit 0 + fi + + + echo "Running setup genesis script..." + + bash -e /scripts/create-genesis.sh + + bash -e /scripts/update-genesis.sh + + + echo "Create node id json file" + + NODE_ID=$($CHAIN_BIN tendermint show-node-id) + + echo '{"node_id":"'$NODE_ID'"}' > $CHAIN_DIR/config/node_id.json + + + echo "Create consensus key json file" + + $CHAIN_BIN tendermint show-validator > + $CHAIN_DIR/config/consensus_key.json + + cat $CHAIN_DIR/config/consensus_key.json + + + echo "Add custom accounts and balances" + + CHAIN_GENESIS_CMD=$($CHAIN_BIN 2>&1 | grep -q "genesis-related + subcommands" && echo "genesis" || echo "") resources: limits: cpu: '2' @@ -164,7 +204,15 @@ spec: command: - bash - '-c' - - /scripts/update-config.sh + - |- + VAL_INDEX=${HOSTNAME##*-} + echo "Validator Index: $VAL_INDEX" + + cp $CHAIN_DIR/cosmovisor/genesis/bin/$CHAIN_BIN /usr/bin + + echo "Running setup config script..." + + bash -e /scripts/update-config.sh resources: limits: cpu: '2' @@ -221,19 +269,21 @@ spec: value: 'true' - name: SLOGFILE value: slog.slog + - name: DAEMON_NAME + value: persistenceCore + - name: DAEMON_HOME + value: /root/.persistenceCore command: - bash - '-c' - - >- + - |- #!/bin/bash - set -euo pipefail + START_ARGS="" - echo "Starting persistenceCore validator..." - exec persistenceCore start --home /root/.persistenceCore - --log_level info + /usr/bin/cosmovisor start $START_ARGS resources: limits: cpu: '2' @@ -301,31 +351,66 @@ spec: - mountPath: /configs name: addresses - name: faucet - image: busybox:1.34.1 + image: ghcr.io/cosmology-tech/starship/runner:latest imagePullPolicy: IfNotPresent env: - name: FAUCET_CONCURRENCY value: '5' - - name: FAUCET_PORT + - name: FAUCET_HTTP_PORT value: '8000' + - name: FAUCET_CHAIN_BINARY + value: persistenceCore - name: FAUCET_CHAIN_ID value: core-1 - - name: FAUCET_CHAIN_DENOM - value: uxprt - - name: FAUCET_CHAIN_PREFIX - value: persistence - - name: FAUCET_AMOUNT_SEND - value: '10000000' - - name: FAUCET_AMOUNT_STAKE - value: '10000000' - - name: FAUCET_RPC_ENDPOINT - value: http://localhost:26657 - - name: FAUCET_REST_ENDPOINT - value: http://localhost:1317 + - name: COINS + value: 100000000000000uxprt command: - - sh + - bash - '-c' - - /faucet/faucet + - >- + CREDIT_COINS="" + + FEES="" + + for coin in ${COINS//,/ } + + do + amt="${coin//[!0-9]/}" + denom="${coin//[0-9]/}" + + # Calculate the order of magnitude + if [ ${#amt} -gt 18 ]; then + creditAmt=$(echo $amt | sed -e "s/000000$//") + feesAmt=$(echo $amt | sed -e "s/0000000000000$//") + else + creditAmt=$(echo $amt | sed -e "s/0000$//") + feesAmt=$(echo $amt | sed -e "s/00000000$//") + fi + + if [[ $CREDIT_COINS == "" ]] + then + CREDIT_COINS="$creditAmt$denom" + FEES="$feesAmt$denom" + else + CREDIT_COINS="${CREDIT_COINS},$creditAmt$denom" + fi + done + + + export FAUCET_MNEMONIC=$(jq -r ".faucet[0].mnemonic" + /configs/keys.json) + + + export | grep "FAUCET" + + + until bash -e /scripts/chain-rpc-ready.sh http://localhost:26657; + do + sleep 10 + done + + + /faucet/faucet --credit-coins="$CREDIT_COINS" --chain-fees="$FEES" resources: limits: cpu: '0.1' @@ -338,6 +423,14 @@ spec: name: addresses - mountPath: /faucet name: faucet + - mountPath: /scripts + name: scripts + readinessProbe: + httpGet: + path: /status + port: '8000' + initialDelaySeconds: 30 + periodSeconds: 10 volumes: - name: node emptyDir: {} @@ -347,3 +440,5 @@ spec: - name: scripts configMap: name: setup-scripts-core-1 + - name: faucet + emptyDir: {} diff --git a/packages/packages/generator/__tests__/__output__/builder-tests/build-chain/persistencecore/setup-scripts-configmap.yaml b/packages/packages/generator/__tests__/__output__/builder-tests/build-chain/persistencecore/setup-scripts-configmap.yaml index c6d4653b8..7b9ad4d80 100644 --- a/packages/packages/generator/__tests__/__output__/builder-tests/build-chain/persistencecore/setup-scripts-configmap.yaml +++ b/packages/packages/generator/__tests__/__output__/builder-tests/build-chain/persistencecore/setup-scripts-configmap.yaml @@ -10,6 +10,8 @@ metadata: app.kubernetes.io/name: persistencecore app.kubernetes.io/part-of: core-1 app.kubernetes.io/role: setup-scripts + starship.io/chain-name: persistencecore + starship.io/chain-id: core-1 data: create-genesis.sh: > #!/bin/bash diff --git a/packages/packages/generator/__tests__/__output__/builder-tests/build-chain/persistencecore/validator-statefulset.yaml b/packages/packages/generator/__tests__/__output__/builder-tests/build-chain/persistencecore/validator-statefulset.yaml index d855efb7d..9bae55f93 100644 --- a/packages/packages/generator/__tests__/__output__/builder-tests/build-chain/persistencecore/validator-statefulset.yaml +++ b/packages/packages/generator/__tests__/__output__/builder-tests/build-chain/persistencecore/validator-statefulset.yaml @@ -9,7 +9,7 @@ metadata: app.kubernetes.io/component: chain app.kubernetes.io/part-of: core-1 app.kubernetes.io/id: core-1 - app.kubernetes.io/name: core-1-genesis + app.kubernetes.io/name: core-1-validator app.kubernetes.io/type: core-1-statefulset app.kubernetes.io/role: validator starship.io/chain-name: persistencecore @@ -91,6 +91,35 @@ spec: name: addresses - mountPath: /scripts name: scripts + - name: wait-for-chains + image: curlimages/curl:latest + imagePullPolicy: IfNotPresent + env: + - name: GENESIS_PORT + value: '8081' + - name: NAMESPACE + valueFrom: + fieldRef: + fieldPath: metadata.namespace + command: + - /bin/sh + - '-c' + - |2- + + while [ $(curl -sw '%{http_code}' http://core-1-genesis.$NAMESPACE.svc.cluster.local:$GENESIS_PORT/node_id -o /dev/null) -ne 200 ]; do + echo "Genesis validator does not seem to be ready for: core-1. Waiting for it to start..." + echo "Checking: http://core-1-genesis.$NAMESPACE.svc.cluster.local:$GENESIS_PORT/node_id" + sleep 10; + done + echo "Ready to start" + exit 0 + resources: + limits: + cpu: '0.1' + memory: 128M + requests: + cpu: '0.1' + memory: 128M - name: init-validator image: ghcr.io/cosmology-tech/starship/runner:latest imagePullPolicy: IfNotPresent @@ -111,23 +140,64 @@ spec: value: persistenceCore - name: CHAIN_ID value: core-1 + - name: GENESIS_HOST + value: core-1-genesis + - name: GENESIS_PORT + value: '8081' + - name: NAMESPACE + valueFrom: + fieldRef: + fieldPath: metadata.namespace - name: KEYS_CONFIG value: /configs/keys.json + - name: FAUCET_ENABLED + value: 'true' + - name: METRICS + value: 'false' command: - bash - '-c' - >- - #!/bin/bash + VAL_INDEX=${HOSTNAME##*-} + + echo "Validator Index: $VAL_INDEX" + + cp $CHAIN_DIR/cosmovisor/genesis/bin/$CHAIN_BIN /usr/bin + + + if [ -f $CHAIN_DIR/config/genesis.json ]; then + echo "Genesis file exists, exiting early" + exit 0 + fi + + + VAL_NAME=$(jq -r ".validators[0].name" $KEYS_CONFIG)-$VAL_INDEX + + echo "Validator Index: $VAL_INDEX, Key name: $VAL_NAME" + + + echo "Recover validator $VAL_NAME" + + $CHAIN_BIN init $VAL_NAME --chain-id $CHAIN_ID + + jq -r ".validators[0].mnemonic" $KEYS_CONFIG | $CHAIN_BIN keys add + $VAL_NAME --index $VAL_INDEX --recover --keyring-backend="test" + - set -euo pipefail + curl + http://$GENESIS_HOST.$NAMESPACE.svc.cluster.local:$GENESIS_PORT/genesis + -o $CHAIN_DIR/config/genesis.json + echo "Genesis file that we got....." - echo "Initializing validator node for core-1..." + cat $CHAIN_DIR/config/genesis.json - persistenceCore init validator-${HOSTNAME##*-} --chain-id core-1 - --home /root/.persistenceCore - echo "Validator initialization completed" + echo "Create node id json file" + + NODE_ID=$($CHAIN_BIN tendermint show-node-id) + + echo '{"node_id":"'$NODE_ID'"}' > $CHAIN_DIR/config/node_id.json resources: limits: cpu: '2' @@ -142,7 +212,7 @@ spec: name: addresses - mountPath: /scripts name: scripts - - name: init-validator-config + - name: init-config image: ghcr.io/cosmology-tech/starship/runner:latest imagePullPolicy: IfNotPresent env: @@ -162,6 +232,14 @@ spec: value: persistenceCore - name: CHAIN_ID value: core-1 + - name: GENESIS_HOST + value: core-1-genesis + - name: GENESIS_PORT + value: '8081' + - name: NAMESPACE + valueFrom: + fieldRef: + fieldPath: metadata.namespace - name: KEYS_CONFIG value: /configs/keys.json - name: METRICS @@ -169,7 +247,43 @@ spec: command: - bash - '-c' - - /scripts/update-config.sh + - >- + VAL_INDEX=${HOSTNAME##*-} + + echo "Validator Index: $VAL_INDEX" + + cp $CHAIN_DIR/cosmovisor/genesis/bin/$CHAIN_BIN /usr/bin + + + echo "Running setup config script..." + + bash -e /scripts/update-config.sh + + + curl -s + http://$GENESIS_HOST.$NAMESPACE.svc.cluster.local:$GENESIS_PORT/node_id + + NODE_ID=$(curl -s + http://$GENESIS_HOST.$NAMESPACE.svc.cluster.local:$GENESIS_PORT/node_id + | jq -r ".node_id") + + if [[ $NODE_ID == "" ]]; then + echo "Node ID is null, exiting early" + exit 1 + fi + + + GENESIS_NODE_P2P=$NODE_ID@$GENESIS_HOST.$NAMESPACE.svc.cluster.local:26656 + + echo "Node P2P: $GENESIS_NODE_P2P" + + sed -i "s/persistent_peers = \"\"/persistent_peers = + \"$GENESIS_NODE_P2P\"/g" $CHAIN_DIR/config/config.toml + + + echo "Printing the whole config.toml file" + + cat $CHAIN_DIR/config/config.toml resources: limits: cpu: '2' @@ -205,21 +319,30 @@ spec: value: persistenceCore - name: CHAIN_ID value: core-1 + - name: GENESIS_HOST + value: core-1-genesis + - name: GENESIS_PORT + value: '8081' + - name: NAMESPACE + valueFrom: + fieldRef: + fieldPath: metadata.namespace + - name: KEYS_CONFIG + value: /configs/keys.json - name: SLOGFILE value: slog.slog command: - bash - '-c' - - >- - #!/bin/bash - - set -euo pipefail + - |- + set -eux + START_ARGS="" - echo "Starting persistenceCore validator..." + # Starting the chain - exec persistenceCore start --home /root/.persistenceCore - --log_level info + cp $CHAIN_DIR/cosmovisor/genesis/bin/$CHAIN_BIN /usr/bin + /usr/bin/cosmovisor start $START_ARGS resources: limits: cpu: '2' @@ -240,10 +363,42 @@ spec: command: - bash - '-c' - - |- - #!/bin/bash - echo "Validator post-start hook for core-1" - # Add any post-start logic here + - '-e' + - >- + until bash -e /scripts/chain-rpc-ready.sh + http://localhost:26657; do + sleep 10 + done + + + set -eux + + export + + VAL_INDEX=${HOSTNAME##*-} + + VAL_NAME="$(jq -r ".validators[0].name" + $KEYS_CONFIG)-$VAL_INDEX" + + echo "Validator Index: $VAL_INDEX, Key name: $VAL_NAME. + Chain bin $CHAIN_BIN" + + + VAL_ADDR=$($CHAIN_BIN keys show $VAL_NAME -a + --keyring-backend="test") + + echo "Transfer tokens to address $VAL_ADDR before trying to + create validator. Best effort" + + bash -e /scripts/transfer-tokens.sh \ + $VAL_ADDR \ + $DENOM \ + http://$GENESIS_HOST.$NAMESPACE.svc.cluster.local:8000/credit \ + "true" || true + + $CHAIN_BIN keys list --keyring-backend test | jq + + VAL_NAME=$VAL_NAME bash -e /scripts/create-validator.sh readinessProbe: exec: command: @@ -254,6 +409,62 @@ spec: initialDelaySeconds: 10 periodSeconds: 10 timeoutSeconds: 15 + - name: exposer + image: ghcr.io/cosmology-tech/starship/exposer:latest + imagePullPolicy: IfNotPresent + env: + - name: DENOM + value: uxprt + - name: COINS + value: 100000000000000uxprt + - name: CHAIN_BIN + value: persistenceCore + - name: CHAIN_DIR + value: /root/.persistenceCore + - name: CODE_REPO + value: https://github.com/persistenceOne/persistenceCore + - name: DAEMON_HOME + value: /root/.persistenceCore + - name: DAEMON_NAME + value: persistenceCore + - name: CHAIN_ID + value: core-1 + - name: GENESIS_HOST + value: core-1-genesis + - name: GENESIS_PORT + value: '8081' + - name: NAMESPACE + valueFrom: + fieldRef: + fieldPath: metadata.namespace + - name: EXPOSER_HTTP_PORT + value: '8081' + - name: EXPOSER_GRPC_PORT + value: '9099' + - name: EXPOSER_GENESIS_FILE + value: /root/.persistenceCore/config/genesis.json + - name: EXPOSER_MNEMONIC_FILE + value: /configs/keys.json + - name: EXPOSER_PRIV_VAL_FILE + value: /root/.persistenceCore/config/priv_validator_key.json + - name: EXPOSER_NODE_KEY_FILE + value: /root/.persistenceCore/config/node_key.json + - name: EXPOSER_PRIV_VAL_STATE_FILE + value: /root/.persistenceCore/data/priv_validator_state.json + command: + - exposer + resources: + limits: + cpu: '0.1' + memory: 128M + requests: + cpu: '0.1' + memory: 128M + volumeMounts: + - mountPath: /root/.persistenceCore + name: node + - mountPath: /configs + name: addresses volumes: - name: node emptyDir: {} @@ -263,3 +474,5 @@ spec: - name: scripts configMap: name: setup-scripts-core-1 + - name: faucet + emptyDir: {} diff --git a/packages/packages/generator/__tests__/__output__/builder-tests/cometmock/cosmoshub/genesis-statefulset.yaml b/packages/packages/generator/__tests__/__output__/builder-tests/cometmock/cosmoshub/genesis-statefulset.yaml index f12fcef3e..bfa208188 100644 --- a/packages/packages/generator/__tests__/__output__/builder-tests/cometmock/cosmoshub/genesis-statefulset.yaml +++ b/packages/packages/generator/__tests__/__output__/builder-tests/cometmock/cosmoshub/genesis-statefulset.yaml @@ -68,7 +68,44 @@ spec: command: - bash - '-c' - - /scripts/create-genesis.sh + - >- + VAL_INDEX=${HOSTNAME##*-} + + echo "Validator Index: $VAL_INDEX" + + + if [ -f $CHAIN_DIR/config/genesis.json ]; then + echo "Genesis file exists, exiting init container" + exit 0 + fi + + + echo "Running setup genesis script..." + + bash -e /scripts/create-genesis.sh + + bash -e /scripts/update-genesis.sh + + + echo "Create node id json file" + + NODE_ID=$($CHAIN_BIN tendermint show-node-id) + + echo '{"node_id":"'$NODE_ID'"}' > $CHAIN_DIR/config/node_id.json + + + echo "Create consensus key json file" + + $CHAIN_BIN tendermint show-validator > + $CHAIN_DIR/config/consensus_key.json + + cat $CHAIN_DIR/config/consensus_key.json + + + echo "Add custom accounts and balances" + + CHAIN_GENESIS_CMD=$($CHAIN_BIN 2>&1 | grep -q "genesis-related + subcommands" && echo "genesis" || echo "") resources: limits: cpu: '0.3' @@ -110,7 +147,13 @@ spec: command: - bash - '-c' - - /scripts/update-config.sh + - |- + VAL_INDEX=${HOSTNAME##*-} + echo "Validator Index: $VAL_INDEX" + + echo "Running setup config script..." + + bash -e /scripts/update-config.sh resources: limits: cpu: '0.3' @@ -153,12 +196,19 @@ spec: command: - bash - '-c' - - |- + - >- #!/bin/bash + set -euo pipefail - echo "Starting gaiad validator..." - exec gaiad start --home /root/.gaia --log_level info + + START_ARGS="" + + START_ARGS="--grpc-web.enable=false --transport=grpc + --with-tendermint=false --address tcp://0.0.0.0:26658" + + + $CHAIN_BIN start $START_ARGS resources: limits: cpu: '0.3' diff --git a/packages/packages/generator/__tests__/__output__/builder-tests/cometmock/cosmoshub/setup-scripts-configmap.yaml b/packages/packages/generator/__tests__/__output__/builder-tests/cometmock/cosmoshub/setup-scripts-configmap.yaml index 4ea5e61f9..0fa5e316a 100644 --- a/packages/packages/generator/__tests__/__output__/builder-tests/cometmock/cosmoshub/setup-scripts-configmap.yaml +++ b/packages/packages/generator/__tests__/__output__/builder-tests/cometmock/cosmoshub/setup-scripts-configmap.yaml @@ -10,6 +10,8 @@ metadata: app.kubernetes.io/name: cosmoshub app.kubernetes.io/part-of: cosmoshub-4 app.kubernetes.io/role: setup-scripts + starship.io/chain-name: cosmoshub + starship.io/chain-id: cosmoshub-4 data: create-genesis.sh: > #!/bin/bash diff --git a/packages/packages/generator/__tests__/__output__/builder-tests/consistency-build/persistencecore/genesis-statefulset.yaml b/packages/packages/generator/__tests__/__output__/builder-tests/consistency-build/persistencecore/genesis-statefulset.yaml index 4c40b763e..a7025d296 100644 --- a/packages/packages/generator/__tests__/__output__/builder-tests/consistency-build/persistencecore/genesis-statefulset.yaml +++ b/packages/packages/generator/__tests__/__output__/builder-tests/consistency-build/persistencecore/genesis-statefulset.yaml @@ -122,7 +122,47 @@ spec: command: - bash - '-c' - - /scripts/create-genesis.sh + - >- + VAL_INDEX=${HOSTNAME##*-} + + echo "Validator Index: $VAL_INDEX" + + + cp $CHAIN_DIR/cosmovisor/genesis/bin/$CHAIN_BIN /usr/bin + + + if [ -f $CHAIN_DIR/config/genesis.json ]; then + echo "Genesis file exists, exiting init container" + exit 0 + fi + + + echo "Running setup genesis script..." + + bash -e /scripts/create-genesis.sh + + bash -e /scripts/update-genesis.sh + + + echo "Create node id json file" + + NODE_ID=$($CHAIN_BIN tendermint show-node-id) + + echo '{"node_id":"'$NODE_ID'"}' > $CHAIN_DIR/config/node_id.json + + + echo "Create consensus key json file" + + $CHAIN_BIN tendermint show-validator > + $CHAIN_DIR/config/consensus_key.json + + cat $CHAIN_DIR/config/consensus_key.json + + + echo "Add custom accounts and balances" + + CHAIN_GENESIS_CMD=$($CHAIN_BIN 2>&1 | grep -q "genesis-related + subcommands" && echo "genesis" || echo "") resources: limits: cpu: '2' @@ -164,7 +204,15 @@ spec: command: - bash - '-c' - - /scripts/update-config.sh + - |- + VAL_INDEX=${HOSTNAME##*-} + echo "Validator Index: $VAL_INDEX" + + cp $CHAIN_DIR/cosmovisor/genesis/bin/$CHAIN_BIN /usr/bin + + echo "Running setup config script..." + + bash -e /scripts/update-config.sh resources: limits: cpu: '2' @@ -221,19 +269,21 @@ spec: value: 'true' - name: SLOGFILE value: slog.slog + - name: DAEMON_NAME + value: persistenceCore + - name: DAEMON_HOME + value: /root/.persistenceCore command: - bash - '-c' - - >- + - |- #!/bin/bash - set -euo pipefail + START_ARGS="" - echo "Starting persistenceCore validator..." - exec persistenceCore start --home /root/.persistenceCore - --log_level info + /usr/bin/cosmovisor start $START_ARGS resources: limits: cpu: '2' @@ -301,31 +351,66 @@ spec: - mountPath: /configs name: addresses - name: faucet - image: busybox:1.34.1 + image: ghcr.io/cosmology-tech/starship/runner:latest imagePullPolicy: IfNotPresent env: - name: FAUCET_CONCURRENCY value: '5' - - name: FAUCET_PORT + - name: FAUCET_HTTP_PORT value: '8000' + - name: FAUCET_CHAIN_BINARY + value: persistenceCore - name: FAUCET_CHAIN_ID value: core-1 - - name: FAUCET_CHAIN_DENOM - value: uxprt - - name: FAUCET_CHAIN_PREFIX - value: persistence - - name: FAUCET_AMOUNT_SEND - value: '10000000' - - name: FAUCET_AMOUNT_STAKE - value: '10000000' - - name: FAUCET_RPC_ENDPOINT - value: http://localhost:26657 - - name: FAUCET_REST_ENDPOINT - value: http://localhost:1317 + - name: COINS + value: 100000000000000uxprt command: - - sh + - bash - '-c' - - /faucet/faucet + - >- + CREDIT_COINS="" + + FEES="" + + for coin in ${COINS//,/ } + + do + amt="${coin//[!0-9]/}" + denom="${coin//[0-9]/}" + + # Calculate the order of magnitude + if [ ${#amt} -gt 18 ]; then + creditAmt=$(echo $amt | sed -e "s/000000$//") + feesAmt=$(echo $amt | sed -e "s/0000000000000$//") + else + creditAmt=$(echo $amt | sed -e "s/0000$//") + feesAmt=$(echo $amt | sed -e "s/00000000$//") + fi + + if [[ $CREDIT_COINS == "" ]] + then + CREDIT_COINS="$creditAmt$denom" + FEES="$feesAmt$denom" + else + CREDIT_COINS="${CREDIT_COINS},$creditAmt$denom" + fi + done + + + export FAUCET_MNEMONIC=$(jq -r ".faucet[0].mnemonic" + /configs/keys.json) + + + export | grep "FAUCET" + + + until bash -e /scripts/chain-rpc-ready.sh http://localhost:26657; + do + sleep 10 + done + + + /faucet/faucet --credit-coins="$CREDIT_COINS" --chain-fees="$FEES" resources: limits: cpu: '0.1' @@ -338,6 +423,14 @@ spec: name: addresses - mountPath: /faucet name: faucet + - mountPath: /scripts + name: scripts + readinessProbe: + httpGet: + path: /status + port: '8000' + initialDelaySeconds: 30 + periodSeconds: 10 volumes: - name: node emptyDir: {} @@ -347,3 +440,5 @@ spec: - name: scripts configMap: name: setup-scripts-core-1 + - name: faucet + emptyDir: {} diff --git a/packages/packages/generator/__tests__/__output__/builder-tests/consistency-build/persistencecore/setup-scripts-configmap.yaml b/packages/packages/generator/__tests__/__output__/builder-tests/consistency-build/persistencecore/setup-scripts-configmap.yaml index c6d4653b8..7b9ad4d80 100644 --- a/packages/packages/generator/__tests__/__output__/builder-tests/consistency-build/persistencecore/setup-scripts-configmap.yaml +++ b/packages/packages/generator/__tests__/__output__/builder-tests/consistency-build/persistencecore/setup-scripts-configmap.yaml @@ -10,6 +10,8 @@ metadata: app.kubernetes.io/name: persistencecore app.kubernetes.io/part-of: core-1 app.kubernetes.io/role: setup-scripts + starship.io/chain-name: persistencecore + starship.io/chain-id: core-1 data: create-genesis.sh: > #!/bin/bash diff --git a/packages/packages/generator/__tests__/__output__/builder-tests/consistency-build/persistencecore/validator-statefulset.yaml b/packages/packages/generator/__tests__/__output__/builder-tests/consistency-build/persistencecore/validator-statefulset.yaml index d855efb7d..9bae55f93 100644 --- a/packages/packages/generator/__tests__/__output__/builder-tests/consistency-build/persistencecore/validator-statefulset.yaml +++ b/packages/packages/generator/__tests__/__output__/builder-tests/consistency-build/persistencecore/validator-statefulset.yaml @@ -9,7 +9,7 @@ metadata: app.kubernetes.io/component: chain app.kubernetes.io/part-of: core-1 app.kubernetes.io/id: core-1 - app.kubernetes.io/name: core-1-genesis + app.kubernetes.io/name: core-1-validator app.kubernetes.io/type: core-1-statefulset app.kubernetes.io/role: validator starship.io/chain-name: persistencecore @@ -91,6 +91,35 @@ spec: name: addresses - mountPath: /scripts name: scripts + - name: wait-for-chains + image: curlimages/curl:latest + imagePullPolicy: IfNotPresent + env: + - name: GENESIS_PORT + value: '8081' + - name: NAMESPACE + valueFrom: + fieldRef: + fieldPath: metadata.namespace + command: + - /bin/sh + - '-c' + - |2- + + while [ $(curl -sw '%{http_code}' http://core-1-genesis.$NAMESPACE.svc.cluster.local:$GENESIS_PORT/node_id -o /dev/null) -ne 200 ]; do + echo "Genesis validator does not seem to be ready for: core-1. Waiting for it to start..." + echo "Checking: http://core-1-genesis.$NAMESPACE.svc.cluster.local:$GENESIS_PORT/node_id" + sleep 10; + done + echo "Ready to start" + exit 0 + resources: + limits: + cpu: '0.1' + memory: 128M + requests: + cpu: '0.1' + memory: 128M - name: init-validator image: ghcr.io/cosmology-tech/starship/runner:latest imagePullPolicy: IfNotPresent @@ -111,23 +140,64 @@ spec: value: persistenceCore - name: CHAIN_ID value: core-1 + - name: GENESIS_HOST + value: core-1-genesis + - name: GENESIS_PORT + value: '8081' + - name: NAMESPACE + valueFrom: + fieldRef: + fieldPath: metadata.namespace - name: KEYS_CONFIG value: /configs/keys.json + - name: FAUCET_ENABLED + value: 'true' + - name: METRICS + value: 'false' command: - bash - '-c' - >- - #!/bin/bash + VAL_INDEX=${HOSTNAME##*-} + + echo "Validator Index: $VAL_INDEX" + + cp $CHAIN_DIR/cosmovisor/genesis/bin/$CHAIN_BIN /usr/bin + + + if [ -f $CHAIN_DIR/config/genesis.json ]; then + echo "Genesis file exists, exiting early" + exit 0 + fi + + + VAL_NAME=$(jq -r ".validators[0].name" $KEYS_CONFIG)-$VAL_INDEX + + echo "Validator Index: $VAL_INDEX, Key name: $VAL_NAME" + + + echo "Recover validator $VAL_NAME" + + $CHAIN_BIN init $VAL_NAME --chain-id $CHAIN_ID + + jq -r ".validators[0].mnemonic" $KEYS_CONFIG | $CHAIN_BIN keys add + $VAL_NAME --index $VAL_INDEX --recover --keyring-backend="test" + - set -euo pipefail + curl + http://$GENESIS_HOST.$NAMESPACE.svc.cluster.local:$GENESIS_PORT/genesis + -o $CHAIN_DIR/config/genesis.json + echo "Genesis file that we got....." - echo "Initializing validator node for core-1..." + cat $CHAIN_DIR/config/genesis.json - persistenceCore init validator-${HOSTNAME##*-} --chain-id core-1 - --home /root/.persistenceCore - echo "Validator initialization completed" + echo "Create node id json file" + + NODE_ID=$($CHAIN_BIN tendermint show-node-id) + + echo '{"node_id":"'$NODE_ID'"}' > $CHAIN_DIR/config/node_id.json resources: limits: cpu: '2' @@ -142,7 +212,7 @@ spec: name: addresses - mountPath: /scripts name: scripts - - name: init-validator-config + - name: init-config image: ghcr.io/cosmology-tech/starship/runner:latest imagePullPolicy: IfNotPresent env: @@ -162,6 +232,14 @@ spec: value: persistenceCore - name: CHAIN_ID value: core-1 + - name: GENESIS_HOST + value: core-1-genesis + - name: GENESIS_PORT + value: '8081' + - name: NAMESPACE + valueFrom: + fieldRef: + fieldPath: metadata.namespace - name: KEYS_CONFIG value: /configs/keys.json - name: METRICS @@ -169,7 +247,43 @@ spec: command: - bash - '-c' - - /scripts/update-config.sh + - >- + VAL_INDEX=${HOSTNAME##*-} + + echo "Validator Index: $VAL_INDEX" + + cp $CHAIN_DIR/cosmovisor/genesis/bin/$CHAIN_BIN /usr/bin + + + echo "Running setup config script..." + + bash -e /scripts/update-config.sh + + + curl -s + http://$GENESIS_HOST.$NAMESPACE.svc.cluster.local:$GENESIS_PORT/node_id + + NODE_ID=$(curl -s + http://$GENESIS_HOST.$NAMESPACE.svc.cluster.local:$GENESIS_PORT/node_id + | jq -r ".node_id") + + if [[ $NODE_ID == "" ]]; then + echo "Node ID is null, exiting early" + exit 1 + fi + + + GENESIS_NODE_P2P=$NODE_ID@$GENESIS_HOST.$NAMESPACE.svc.cluster.local:26656 + + echo "Node P2P: $GENESIS_NODE_P2P" + + sed -i "s/persistent_peers = \"\"/persistent_peers = + \"$GENESIS_NODE_P2P\"/g" $CHAIN_DIR/config/config.toml + + + echo "Printing the whole config.toml file" + + cat $CHAIN_DIR/config/config.toml resources: limits: cpu: '2' @@ -205,21 +319,30 @@ spec: value: persistenceCore - name: CHAIN_ID value: core-1 + - name: GENESIS_HOST + value: core-1-genesis + - name: GENESIS_PORT + value: '8081' + - name: NAMESPACE + valueFrom: + fieldRef: + fieldPath: metadata.namespace + - name: KEYS_CONFIG + value: /configs/keys.json - name: SLOGFILE value: slog.slog command: - bash - '-c' - - >- - #!/bin/bash - - set -euo pipefail + - |- + set -eux + START_ARGS="" - echo "Starting persistenceCore validator..." + # Starting the chain - exec persistenceCore start --home /root/.persistenceCore - --log_level info + cp $CHAIN_DIR/cosmovisor/genesis/bin/$CHAIN_BIN /usr/bin + /usr/bin/cosmovisor start $START_ARGS resources: limits: cpu: '2' @@ -240,10 +363,42 @@ spec: command: - bash - '-c' - - |- - #!/bin/bash - echo "Validator post-start hook for core-1" - # Add any post-start logic here + - '-e' + - >- + until bash -e /scripts/chain-rpc-ready.sh + http://localhost:26657; do + sleep 10 + done + + + set -eux + + export + + VAL_INDEX=${HOSTNAME##*-} + + VAL_NAME="$(jq -r ".validators[0].name" + $KEYS_CONFIG)-$VAL_INDEX" + + echo "Validator Index: $VAL_INDEX, Key name: $VAL_NAME. + Chain bin $CHAIN_BIN" + + + VAL_ADDR=$($CHAIN_BIN keys show $VAL_NAME -a + --keyring-backend="test") + + echo "Transfer tokens to address $VAL_ADDR before trying to + create validator. Best effort" + + bash -e /scripts/transfer-tokens.sh \ + $VAL_ADDR \ + $DENOM \ + http://$GENESIS_HOST.$NAMESPACE.svc.cluster.local:8000/credit \ + "true" || true + + $CHAIN_BIN keys list --keyring-backend test | jq + + VAL_NAME=$VAL_NAME bash -e /scripts/create-validator.sh readinessProbe: exec: command: @@ -254,6 +409,62 @@ spec: initialDelaySeconds: 10 periodSeconds: 10 timeoutSeconds: 15 + - name: exposer + image: ghcr.io/cosmology-tech/starship/exposer:latest + imagePullPolicy: IfNotPresent + env: + - name: DENOM + value: uxprt + - name: COINS + value: 100000000000000uxprt + - name: CHAIN_BIN + value: persistenceCore + - name: CHAIN_DIR + value: /root/.persistenceCore + - name: CODE_REPO + value: https://github.com/persistenceOne/persistenceCore + - name: DAEMON_HOME + value: /root/.persistenceCore + - name: DAEMON_NAME + value: persistenceCore + - name: CHAIN_ID + value: core-1 + - name: GENESIS_HOST + value: core-1-genesis + - name: GENESIS_PORT + value: '8081' + - name: NAMESPACE + valueFrom: + fieldRef: + fieldPath: metadata.namespace + - name: EXPOSER_HTTP_PORT + value: '8081' + - name: EXPOSER_GRPC_PORT + value: '9099' + - name: EXPOSER_GENESIS_FILE + value: /root/.persistenceCore/config/genesis.json + - name: EXPOSER_MNEMONIC_FILE + value: /configs/keys.json + - name: EXPOSER_PRIV_VAL_FILE + value: /root/.persistenceCore/config/priv_validator_key.json + - name: EXPOSER_NODE_KEY_FILE + value: /root/.persistenceCore/config/node_key.json + - name: EXPOSER_PRIV_VAL_STATE_FILE + value: /root/.persistenceCore/data/priv_validator_state.json + command: + - exposer + resources: + limits: + cpu: '0.1' + memory: 128M + requests: + cpu: '0.1' + memory: 128M + volumeMounts: + - mountPath: /root/.persistenceCore + name: node + - mountPath: /configs + name: addresses volumes: - name: node emptyDir: {} @@ -263,3 +474,5 @@ spec: - name: scripts configMap: name: setup-scripts-core-1 + - name: faucet + emptyDir: {} diff --git a/packages/packages/generator/__tests__/__output__/builder-tests/consistency-cometmock/cosmoshub/genesis-statefulset.yaml b/packages/packages/generator/__tests__/__output__/builder-tests/consistency-cometmock/cosmoshub/genesis-statefulset.yaml index f12fcef3e..bfa208188 100644 --- a/packages/packages/generator/__tests__/__output__/builder-tests/consistency-cometmock/cosmoshub/genesis-statefulset.yaml +++ b/packages/packages/generator/__tests__/__output__/builder-tests/consistency-cometmock/cosmoshub/genesis-statefulset.yaml @@ -68,7 +68,44 @@ spec: command: - bash - '-c' - - /scripts/create-genesis.sh + - >- + VAL_INDEX=${HOSTNAME##*-} + + echo "Validator Index: $VAL_INDEX" + + + if [ -f $CHAIN_DIR/config/genesis.json ]; then + echo "Genesis file exists, exiting init container" + exit 0 + fi + + + echo "Running setup genesis script..." + + bash -e /scripts/create-genesis.sh + + bash -e /scripts/update-genesis.sh + + + echo "Create node id json file" + + NODE_ID=$($CHAIN_BIN tendermint show-node-id) + + echo '{"node_id":"'$NODE_ID'"}' > $CHAIN_DIR/config/node_id.json + + + echo "Create consensus key json file" + + $CHAIN_BIN tendermint show-validator > + $CHAIN_DIR/config/consensus_key.json + + cat $CHAIN_DIR/config/consensus_key.json + + + echo "Add custom accounts and balances" + + CHAIN_GENESIS_CMD=$($CHAIN_BIN 2>&1 | grep -q "genesis-related + subcommands" && echo "genesis" || echo "") resources: limits: cpu: '0.3' @@ -110,7 +147,13 @@ spec: command: - bash - '-c' - - /scripts/update-config.sh + - |- + VAL_INDEX=${HOSTNAME##*-} + echo "Validator Index: $VAL_INDEX" + + echo "Running setup config script..." + + bash -e /scripts/update-config.sh resources: limits: cpu: '0.3' @@ -153,12 +196,19 @@ spec: command: - bash - '-c' - - |- + - >- #!/bin/bash + set -euo pipefail - echo "Starting gaiad validator..." - exec gaiad start --home /root/.gaia --log_level info + + START_ARGS="" + + START_ARGS="--grpc-web.enable=false --transport=grpc + --with-tendermint=false --address tcp://0.0.0.0:26658" + + + $CHAIN_BIN start $START_ARGS resources: limits: cpu: '0.3' diff --git a/packages/packages/generator/__tests__/__output__/builder-tests/consistency-cometmock/cosmoshub/setup-scripts-configmap.yaml b/packages/packages/generator/__tests__/__output__/builder-tests/consistency-cometmock/cosmoshub/setup-scripts-configmap.yaml index 4ea5e61f9..0fa5e316a 100644 --- a/packages/packages/generator/__tests__/__output__/builder-tests/consistency-cometmock/cosmoshub/setup-scripts-configmap.yaml +++ b/packages/packages/generator/__tests__/__output__/builder-tests/consistency-cometmock/cosmoshub/setup-scripts-configmap.yaml @@ -10,6 +10,8 @@ metadata: app.kubernetes.io/name: cosmoshub app.kubernetes.io/part-of: cosmoshub-4 app.kubernetes.io/role: setup-scripts + starship.io/chain-name: cosmoshub + starship.io/chain-id: cosmoshub-4 data: create-genesis.sh: > #!/bin/bash diff --git a/packages/packages/generator/__tests__/__output__/builder-tests/consistency-cosmjs/osmosis/genesis-statefulset.yaml b/packages/packages/generator/__tests__/__output__/builder-tests/consistency-cosmjs/osmosis/genesis-statefulset.yaml index f7e6e0be0..0849609af 100644 --- a/packages/packages/generator/__tests__/__output__/builder-tests/consistency-cosmjs/osmosis/genesis-statefulset.yaml +++ b/packages/packages/generator/__tests__/__output__/builder-tests/consistency-cosmjs/osmosis/genesis-statefulset.yaml @@ -68,7 +68,44 @@ spec: command: - bash - '-c' - - /scripts/create-genesis.sh + - >- + VAL_INDEX=${HOSTNAME##*-} + + echo "Validator Index: $VAL_INDEX" + + + if [ -f $CHAIN_DIR/config/genesis.json ]; then + echo "Genesis file exists, exiting init container" + exit 0 + fi + + + echo "Running setup genesis script..." + + bash -e /scripts/create-genesis.sh + + bash -e /scripts/update-genesis.sh + + + echo "Create node id json file" + + NODE_ID=$($CHAIN_BIN tendermint show-node-id) + + echo '{"node_id":"'$NODE_ID'"}' > $CHAIN_DIR/config/node_id.json + + + echo "Create consensus key json file" + + $CHAIN_BIN tendermint show-validator > + $CHAIN_DIR/config/consensus_key.json + + cat $CHAIN_DIR/config/consensus_key.json + + + echo "Add custom accounts and balances" + + CHAIN_GENESIS_CMD=$($CHAIN_BIN 2>&1 | grep -q "genesis-related + subcommands" && echo "genesis" || echo "") resources: limits: cpu: '0.5' @@ -110,7 +147,13 @@ spec: command: - bash - '-c' - - /scripts/update-config.sh + - |- + VAL_INDEX=${HOSTNAME##*-} + echo "Validator Index: $VAL_INDEX" + + echo "Running setup config script..." + + bash -e /scripts/update-config.sh resources: limits: cpu: '0.5' @@ -157,8 +200,10 @@ spec: #!/bin/bash set -euo pipefail - echo "Starting osmosisd validator..." - exec osmosisd start --home /root/.osmosisd --log_level info + START_ARGS="" + + + $CHAIN_BIN start $START_ARGS resources: limits: cpu: '0.5' @@ -233,29 +278,70 @@ spec: value: '2' - name: FAUCET_PORT value: '8000' + - name: FAUCET_MEMO + value: faucet txn - name: FAUCET_GAS_PRICE - value: '0.025' - - name: FAUCET_PATH_PATTERN - value: '' + value: 1.25uosmo + - name: FAUCET_GAS_LIMIT + value: '2000000' - name: FAUCET_ADDRESS_PREFIX value: osmo - - name: FAUCET_TOKENS - value: uosmo - - name: FAUCET_CREDIT_AMOUNT_SEND - value: '10000000' - - name: FAUCET_CREDIT_AMOUNT_STAKE - value: '10000000' - - name: FAUCET_MAX_CREDIT - value: '99999999' - - name: FAUCET_MNEMONIC - value: '' - - name: FAUCET_CHAIN_ID - value: osmosis-1 - - name: FAUCET_RPC_ENDPOINT - value: http://localhost:26657 + - name: FAUCET_REFILL_FACTOR + value: '8' + - name: FAUCET_REFILL_THRESHOLD + value: '20' + - name: FAUCET_COOLDOWN_TIME + value: '0' + - name: COINS + value: 100000000000000uosmo,100000000000000uion + - name: HD_PATH + value: m/44'/118'/0'/0/0 command: - - yarn - - start + - bash + - '-c' + - >- + export FAUCET_TOKENS=$(printf '%s\n' ${COINS//[[:digit:]]/}) + + for coin in ${COINS//,/ } + + do + var="FAUCET_CREDIT_AMOUNT_$(printf '%s\n' ${coin//[[:digit:]]/} | tr '[:lower:]' '[:upper:]')" + amt="${coin//[!0-9]/}" + + if [ ${#amt} -gt 18 ]; then + creditAmt=$(echo $amt | sed -e "s/000000$//") + feesAmt=$(echo $amt | sed -e "s/0000000000000$//") + else + creditAmt=$(echo $amt | sed -e "s/0000$//") + feesAmt=$(echo $amt | sed -e "s/00000000$//") + fi + + export $var="$creditAmt" + done + + + export FAUCET_PATH_PATTERN="${HD_PATH:0:$((${#HD_PATH}-1))}a" + + export FAUCET_MNEMONIC=$(jq -r ".faucet[0].mnemonic" + /configs/keys.json) + + + echo "FAUCET_MNEMONIC: $FAUCET_MNEMONIC" + + echo "FAUCET_PATH_PATTERN: $FAUCET_PATH_PATTERN" + + + export | grep "FAUCET" + + + until bash -e /scripts/chain-rpc-ready.sh http://localhost:26657; + do + sleep 10; + done + + + /app/packages/faucet/bin/cosmos-faucet-dist start + "http://localhost:26657" resources: limits: cpu: '0.2' @@ -266,6 +352,14 @@ spec: volumeMounts: - mountPath: /configs name: addresses + - mountPath: /scripts + name: scripts + readinessProbe: + httpGet: + path: /status + port: '8000' + initialDelaySeconds: 30 + periodSeconds: 10 volumes: - name: node emptyDir: {} diff --git a/packages/packages/generator/__tests__/__output__/builder-tests/consistency-cosmjs/osmosis/setup-scripts-configmap.yaml b/packages/packages/generator/__tests__/__output__/builder-tests/consistency-cosmjs/osmosis/setup-scripts-configmap.yaml index 770edb52d..0f3d10fee 100644 --- a/packages/packages/generator/__tests__/__output__/builder-tests/consistency-cosmjs/osmosis/setup-scripts-configmap.yaml +++ b/packages/packages/generator/__tests__/__output__/builder-tests/consistency-cosmjs/osmosis/setup-scripts-configmap.yaml @@ -10,6 +10,8 @@ metadata: app.kubernetes.io/name: osmosis app.kubernetes.io/part-of: osmosis-1 app.kubernetes.io/role: setup-scripts + starship.io/chain-name: osmosis + starship.io/chain-id: osmosis-1 data: create-genesis.sh: > #!/bin/bash diff --git a/packages/packages/generator/__tests__/__output__/builder-tests/consistency-multi/cosmoshub/genesis-statefulset.yaml b/packages/packages/generator/__tests__/__output__/builder-tests/consistency-multi/cosmoshub/genesis-statefulset.yaml index 9faa6ae15..46d80e179 100644 --- a/packages/packages/generator/__tests__/__output__/builder-tests/consistency-multi/cosmoshub/genesis-statefulset.yaml +++ b/packages/packages/generator/__tests__/__output__/builder-tests/consistency-multi/cosmoshub/genesis-statefulset.yaml @@ -68,7 +68,44 @@ spec: command: - bash - '-c' - - /scripts/create-genesis.sh + - >- + VAL_INDEX=${HOSTNAME##*-} + + echo "Validator Index: $VAL_INDEX" + + + if [ -f $CHAIN_DIR/config/genesis.json ]; then + echo "Genesis file exists, exiting init container" + exit 0 + fi + + + echo "Running setup genesis script..." + + bash -e /scripts/create-genesis.sh + + bash -e /scripts/update-genesis.sh + + + echo "Create node id json file" + + NODE_ID=$($CHAIN_BIN tendermint show-node-id) + + echo '{"node_id":"'$NODE_ID'"}' > $CHAIN_DIR/config/node_id.json + + + echo "Create consensus key json file" + + $CHAIN_BIN tendermint show-validator > + $CHAIN_DIR/config/consensus_key.json + + cat $CHAIN_DIR/config/consensus_key.json + + + echo "Add custom accounts and balances" + + CHAIN_GENESIS_CMD=$($CHAIN_BIN 2>&1 | grep -q "genesis-related + subcommands" && echo "genesis" || echo "") resources: limits: cpu: '0.5' @@ -110,7 +147,13 @@ spec: command: - bash - '-c' - - /scripts/update-config.sh + - |- + VAL_INDEX=${HOSTNAME##*-} + echo "Validator Index: $VAL_INDEX" + + echo "Running setup config script..." + + bash -e /scripts/update-config.sh resources: limits: cpu: '0.5' @@ -157,8 +200,10 @@ spec: #!/bin/bash set -euo pipefail - echo "Starting gaiad validator..." - exec gaiad start --home /root/.gaia --log_level info + START_ARGS="" + + + $CHAIN_BIN start $START_ARGS resources: limits: cpu: '0.5' diff --git a/packages/packages/generator/__tests__/__output__/builder-tests/consistency-multi/cosmoshub/setup-scripts-configmap.yaml b/packages/packages/generator/__tests__/__output__/builder-tests/consistency-multi/cosmoshub/setup-scripts-configmap.yaml index 4ea5e61f9..0fa5e316a 100644 --- a/packages/packages/generator/__tests__/__output__/builder-tests/consistency-multi/cosmoshub/setup-scripts-configmap.yaml +++ b/packages/packages/generator/__tests__/__output__/builder-tests/consistency-multi/cosmoshub/setup-scripts-configmap.yaml @@ -10,6 +10,8 @@ metadata: app.kubernetes.io/name: cosmoshub app.kubernetes.io/part-of: cosmoshub-4 app.kubernetes.io/role: setup-scripts + starship.io/chain-name: cosmoshub + starship.io/chain-id: cosmoshub-4 data: create-genesis.sh: > #!/bin/bash diff --git a/packages/packages/generator/__tests__/__output__/builder-tests/consistency-multi/cosmoshub/validator-statefulset.yaml b/packages/packages/generator/__tests__/__output__/builder-tests/consistency-multi/cosmoshub/validator-statefulset.yaml index eba7a5c53..426a6f37b 100644 --- a/packages/packages/generator/__tests__/__output__/builder-tests/consistency-multi/cosmoshub/validator-statefulset.yaml +++ b/packages/packages/generator/__tests__/__output__/builder-tests/consistency-multi/cosmoshub/validator-statefulset.yaml @@ -9,7 +9,7 @@ metadata: app.kubernetes.io/component: chain app.kubernetes.io/part-of: cosmoshub-4 app.kubernetes.io/id: cosmoshub-4 - app.kubernetes.io/name: cosmoshub-4-genesis + app.kubernetes.io/name: cosmoshub-4-validator app.kubernetes.io/type: cosmoshub-4-statefulset app.kubernetes.io/role: validator starship.io/chain-name: cosmoshub @@ -37,6 +37,35 @@ spec: app.kubernetes.io/role: validator spec: initContainers: + - name: wait-for-chains + image: curlimages/curl:latest + imagePullPolicy: IfNotPresent + env: + - name: GENESIS_PORT + value: '8081' + - name: NAMESPACE + valueFrom: + fieldRef: + fieldPath: metadata.namespace + command: + - /bin/sh + - '-c' + - |2- + + while [ $(curl -sw '%{http_code}' http://cosmoshub-4-genesis.$NAMESPACE.svc.cluster.local:$GENESIS_PORT/node_id -o /dev/null) -ne 200 ]; do + echo "Genesis validator does not seem to be ready for: cosmoshub-4. Waiting for it to start..." + echo "Checking: http://cosmoshub-4-genesis.$NAMESPACE.svc.cluster.local:$GENESIS_PORT/node_id" + sleep 10; + done + echo "Ready to start" + exit 0 + resources: + limits: + cpu: '0.1' + memory: 128M + requests: + cpu: '0.1' + memory: 128M - name: init-validator image: ghcr.io/cosmology-tech/starship/gaia:v18.0.0 imagePullPolicy: IfNotPresent @@ -57,23 +86,63 @@ spec: value: gaiad - name: CHAIN_ID value: cosmoshub-4 + - name: GENESIS_HOST + value: cosmoshub-4-genesis + - name: GENESIS_PORT + value: '8081' + - name: NAMESPACE + valueFrom: + fieldRef: + fieldPath: metadata.namespace - name: KEYS_CONFIG value: /configs/keys.json + - name: FAUCET_ENABLED + value: 'false' + - name: METRICS + value: 'false' command: - bash - '-c' - >- - #!/bin/bash + VAL_INDEX=${HOSTNAME##*-} + + echo "Validator Index: $VAL_INDEX" + + + + if [ -f $CHAIN_DIR/config/genesis.json ]; then + echo "Genesis file exists, exiting early" + exit 0 + fi + + + VAL_NAME=$(jq -r ".validators[0].name" $KEYS_CONFIG)-$VAL_INDEX + + echo "Validator Index: $VAL_INDEX, Key name: $VAL_NAME" + + + echo "Recover validator $VAL_NAME" + + $CHAIN_BIN init $VAL_NAME --chain-id $CHAIN_ID + + jq -r ".validators[0].mnemonic" $KEYS_CONFIG | $CHAIN_BIN keys add + $VAL_NAME --index $VAL_INDEX --recover --keyring-backend="test" - set -euo pipefail + curl + http://$GENESIS_HOST.$NAMESPACE.svc.cluster.local:$GENESIS_PORT/genesis + -o $CHAIN_DIR/config/genesis.json - echo "Initializing validator node for cosmoshub-4..." + echo "Genesis file that we got....." - gaiad init validator-${HOSTNAME##*-} --chain-id cosmoshub-4 --home - /root/.gaia + cat $CHAIN_DIR/config/genesis.json - echo "Validator initialization completed" + + echo "Create node id json file" + + NODE_ID=$($CHAIN_BIN tendermint show-node-id) + + echo '{"node_id":"'$NODE_ID'"}' > $CHAIN_DIR/config/node_id.json resources: limits: cpu: '0.5' @@ -88,7 +157,7 @@ spec: name: addresses - mountPath: /scripts name: scripts - - name: init-validator-config + - name: init-config image: ghcr.io/cosmology-tech/starship/gaia:v18.0.0 imagePullPolicy: IfNotPresent env: @@ -108,6 +177,14 @@ spec: value: gaiad - name: CHAIN_ID value: cosmoshub-4 + - name: GENESIS_HOST + value: cosmoshub-4-genesis + - name: GENESIS_PORT + value: '8081' + - name: NAMESPACE + valueFrom: + fieldRef: + fieldPath: metadata.namespace - name: KEYS_CONFIG value: /configs/keys.json - name: METRICS @@ -115,7 +192,42 @@ spec: command: - bash - '-c' - - /scripts/update-config.sh + - >- + VAL_INDEX=${HOSTNAME##*-} + + echo "Validator Index: $VAL_INDEX" + + + + echo "Running setup config script..." + + bash -e /scripts/update-config.sh + + + curl -s + http://$GENESIS_HOST.$NAMESPACE.svc.cluster.local:$GENESIS_PORT/node_id + + NODE_ID=$(curl -s + http://$GENESIS_HOST.$NAMESPACE.svc.cluster.local:$GENESIS_PORT/node_id + | jq -r ".node_id") + + if [[ $NODE_ID == "" ]]; then + echo "Node ID is null, exiting early" + exit 1 + fi + + + GENESIS_NODE_P2P=$NODE_ID@$GENESIS_HOST.$NAMESPACE.svc.cluster.local:26656 + + echo "Node P2P: $GENESIS_NODE_P2P" + + sed -i "s/persistent_peers = \"\"/persistent_peers = + \"$GENESIS_NODE_P2P\"/g" $CHAIN_DIR/config/config.toml + + + echo "Printing the whole config.toml file" + + cat $CHAIN_DIR/config/config.toml resources: limits: cpu: '0.5' @@ -151,17 +263,29 @@ spec: value: gaiad - name: CHAIN_ID value: cosmoshub-4 + - name: GENESIS_HOST + value: cosmoshub-4-genesis + - name: GENESIS_PORT + value: '8081' + - name: NAMESPACE + valueFrom: + fieldRef: + fieldPath: metadata.namespace + - name: KEYS_CONFIG + value: /configs/keys.json - name: SLOGFILE value: slog.slog command: - bash - '-c' - |- - #!/bin/bash - set -euo pipefail + set -eux + START_ARGS="" + + + # Starting the chain - echo "Starting gaiad validator..." - exec gaiad start --home /root/.gaia --log_level info + $CHAIN_BIN start $START_ARGS resources: limits: cpu: '0.5' @@ -182,10 +306,42 @@ spec: command: - bash - '-c' - - |- - #!/bin/bash - echo "Validator post-start hook for cosmoshub-4" - # Add any post-start logic here + - '-e' + - >- + until bash -e /scripts/chain-rpc-ready.sh + http://localhost:26657; do + sleep 10 + done + + + set -eux + + export + + VAL_INDEX=${HOSTNAME##*-} + + VAL_NAME="$(jq -r ".validators[0].name" + $KEYS_CONFIG)-$VAL_INDEX" + + echo "Validator Index: $VAL_INDEX, Key name: $VAL_NAME. + Chain bin $CHAIN_BIN" + + + VAL_ADDR=$($CHAIN_BIN keys show $VAL_NAME -a + --keyring-backend="test") + + echo "Transfer tokens to address $VAL_ADDR before trying to + create validator. Best effort" + + bash -e /scripts/transfer-tokens.sh \ + $VAL_ADDR \ + $DENOM \ + http://$GENESIS_HOST.$NAMESPACE.svc.cluster.local:8000/credit \ + "false" || true + + $CHAIN_BIN keys list --keyring-backend test | jq + + VAL_NAME=$VAL_NAME bash -e /scripts/create-validator.sh readinessProbe: exec: command: @@ -196,6 +352,62 @@ spec: initialDelaySeconds: 10 periodSeconds: 10 timeoutSeconds: 15 + - name: exposer + image: ghcr.io/cosmology-tech/starship/exposer:latest + imagePullPolicy: IfNotPresent + env: + - name: DENOM + value: uatom + - name: COINS + value: 100000000000000uatom + - name: CHAIN_BIN + value: gaiad + - name: CHAIN_DIR + value: /root/.gaia + - name: CODE_REPO + value: https://github.com/cosmos/gaia + - name: DAEMON_HOME + value: /root/.gaia + - name: DAEMON_NAME + value: gaiad + - name: CHAIN_ID + value: cosmoshub-4 + - name: GENESIS_HOST + value: cosmoshub-4-genesis + - name: GENESIS_PORT + value: '8081' + - name: NAMESPACE + valueFrom: + fieldRef: + fieldPath: metadata.namespace + - name: EXPOSER_HTTP_PORT + value: '8081' + - name: EXPOSER_GRPC_PORT + value: '9099' + - name: EXPOSER_GENESIS_FILE + value: /root/.gaia/config/genesis.json + - name: EXPOSER_MNEMONIC_FILE + value: /configs/keys.json + - name: EXPOSER_PRIV_VAL_FILE + value: /root/.gaia/config/priv_validator_key.json + - name: EXPOSER_NODE_KEY_FILE + value: /root/.gaia/config/node_key.json + - name: EXPOSER_PRIV_VAL_STATE_FILE + value: /root/.gaia/data/priv_validator_state.json + command: + - exposer + resources: + limits: + cpu: '0.1' + memory: 128M + requests: + cpu: '0.1' + memory: 128M + volumeMounts: + - mountPath: /root/.gaia + name: node + - mountPath: /configs + name: addresses volumes: - name: node emptyDir: {} diff --git a/packages/packages/generator/__tests__/__output__/builder-tests/consistency-multi/osmosis/genesis-statefulset.yaml b/packages/packages/generator/__tests__/__output__/builder-tests/consistency-multi/osmosis/genesis-statefulset.yaml index 377f0bfc8..cad6c40d0 100644 --- a/packages/packages/generator/__tests__/__output__/builder-tests/consistency-multi/osmosis/genesis-statefulset.yaml +++ b/packages/packages/generator/__tests__/__output__/builder-tests/consistency-multi/osmosis/genesis-statefulset.yaml @@ -68,7 +68,44 @@ spec: command: - bash - '-c' - - /scripts/create-genesis.sh + - >- + VAL_INDEX=${HOSTNAME##*-} + + echo "Validator Index: $VAL_INDEX" + + + if [ -f $CHAIN_DIR/config/genesis.json ]; then + echo "Genesis file exists, exiting init container" + exit 0 + fi + + + echo "Running setup genesis script..." + + bash -e /scripts/create-genesis.sh + + bash -e /scripts/update-genesis.sh + + + echo "Create node id json file" + + NODE_ID=$($CHAIN_BIN tendermint show-node-id) + + echo '{"node_id":"'$NODE_ID'"}' > $CHAIN_DIR/config/node_id.json + + + echo "Create consensus key json file" + + $CHAIN_BIN tendermint show-validator > + $CHAIN_DIR/config/consensus_key.json + + cat $CHAIN_DIR/config/consensus_key.json + + + echo "Add custom accounts and balances" + + CHAIN_GENESIS_CMD=$($CHAIN_BIN 2>&1 | grep -q "genesis-related + subcommands" && echo "genesis" || echo "") resources: limits: cpu: '0.5' @@ -110,7 +147,13 @@ spec: command: - bash - '-c' - - /scripts/update-config.sh + - |- + VAL_INDEX=${HOSTNAME##*-} + echo "Validator Index: $VAL_INDEX" + + echo "Running setup config script..." + + bash -e /scripts/update-config.sh resources: limits: cpu: '0.5' @@ -174,8 +217,10 @@ spec: #!/bin/bash set -euo pipefail - echo "Starting osmosisd validator..." - exec osmosisd start --home /root/.osmosisd --log_level info + START_ARGS="" + + + $CHAIN_BIN start $START_ARGS resources: limits: cpu: '0.5' @@ -243,31 +288,66 @@ spec: - mountPath: /configs name: addresses - name: faucet - image: busybox:1.34.1 + image: ghcr.io/cosmology-tech/starship/osmosis:v25.0.0 imagePullPolicy: IfNotPresent env: - name: FAUCET_CONCURRENCY value: '5' - - name: FAUCET_PORT + - name: FAUCET_HTTP_PORT value: '8000' + - name: FAUCET_CHAIN_BINARY + value: osmosisd - name: FAUCET_CHAIN_ID value: osmosis-1 - - name: FAUCET_CHAIN_DENOM - value: uosmo - - name: FAUCET_CHAIN_PREFIX - value: osmo - - name: FAUCET_AMOUNT_SEND - value: '10000000' - - name: FAUCET_AMOUNT_STAKE - value: '10000000' - - name: FAUCET_RPC_ENDPOINT - value: http://localhost:26657 - - name: FAUCET_REST_ENDPOINT - value: http://localhost:1317 + - name: COINS + value: 100000000000000uosmo,100000000000000uion command: - - sh + - bash - '-c' - - /faucet/faucet + - >- + CREDIT_COINS="" + + FEES="" + + for coin in ${COINS//,/ } + + do + amt="${coin//[!0-9]/}" + denom="${coin//[0-9]/}" + + # Calculate the order of magnitude + if [ ${#amt} -gt 18 ]; then + creditAmt=$(echo $amt | sed -e "s/000000$//") + feesAmt=$(echo $amt | sed -e "s/0000000000000$//") + else + creditAmt=$(echo $amt | sed -e "s/0000$//") + feesAmt=$(echo $amt | sed -e "s/00000000$//") + fi + + if [[ $CREDIT_COINS == "" ]] + then + CREDIT_COINS="$creditAmt$denom" + FEES="$feesAmt$denom" + else + CREDIT_COINS="${CREDIT_COINS},$creditAmt$denom" + fi + done + + + export FAUCET_MNEMONIC=$(jq -r ".faucet[0].mnemonic" + /configs/keys.json) + + + export | grep "FAUCET" + + + until bash -e /scripts/chain-rpc-ready.sh http://localhost:26657; + do + sleep 10 + done + + + /faucet/faucet --credit-coins="$CREDIT_COINS" --chain-fees="$FEES" resources: limits: cpu: '0.1' @@ -280,6 +360,14 @@ spec: name: addresses - mountPath: /faucet name: faucet + - mountPath: /scripts + name: scripts + readinessProbe: + httpGet: + path: /status + port: '8000' + initialDelaySeconds: 30 + periodSeconds: 10 volumes: - name: node emptyDir: {} @@ -289,3 +377,5 @@ spec: - name: scripts configMap: name: setup-scripts-osmosis-1 + - name: faucet + emptyDir: {} diff --git a/packages/packages/generator/__tests__/__output__/builder-tests/consistency-multi/osmosis/setup-scripts-configmap.yaml b/packages/packages/generator/__tests__/__output__/builder-tests/consistency-multi/osmosis/setup-scripts-configmap.yaml index 770edb52d..0f3d10fee 100644 --- a/packages/packages/generator/__tests__/__output__/builder-tests/consistency-multi/osmosis/setup-scripts-configmap.yaml +++ b/packages/packages/generator/__tests__/__output__/builder-tests/consistency-multi/osmosis/setup-scripts-configmap.yaml @@ -10,6 +10,8 @@ metadata: app.kubernetes.io/name: osmosis app.kubernetes.io/part-of: osmosis-1 app.kubernetes.io/role: setup-scripts + starship.io/chain-name: osmosis + starship.io/chain-id: osmosis-1 data: create-genesis.sh: > #!/bin/bash diff --git a/packages/packages/generator/__tests__/__output__/builder-tests/consistency-multi/osmosis/validator-statefulset.yaml b/packages/packages/generator/__tests__/__output__/builder-tests/consistency-multi/osmosis/validator-statefulset.yaml index 623026aa6..8f58c8f76 100644 --- a/packages/packages/generator/__tests__/__output__/builder-tests/consistency-multi/osmosis/validator-statefulset.yaml +++ b/packages/packages/generator/__tests__/__output__/builder-tests/consistency-multi/osmosis/validator-statefulset.yaml @@ -9,7 +9,7 @@ metadata: app.kubernetes.io/component: chain app.kubernetes.io/part-of: osmosis-1 app.kubernetes.io/id: osmosis-1 - app.kubernetes.io/name: osmosis-1-genesis + app.kubernetes.io/name: osmosis-1-validator app.kubernetes.io/type: osmosis-1-statefulset app.kubernetes.io/role: validator starship.io/chain-name: osmosis @@ -37,6 +37,35 @@ spec: app.kubernetes.io/role: validator spec: initContainers: + - name: wait-for-chains + image: curlimages/curl:latest + imagePullPolicy: IfNotPresent + env: + - name: GENESIS_PORT + value: '8081' + - name: NAMESPACE + valueFrom: + fieldRef: + fieldPath: metadata.namespace + command: + - /bin/sh + - '-c' + - |2- + + while [ $(curl -sw '%{http_code}' http://osmosis-1-genesis.$NAMESPACE.svc.cluster.local:$GENESIS_PORT/node_id -o /dev/null) -ne 200 ]; do + echo "Genesis validator does not seem to be ready for: osmosis-1. Waiting for it to start..." + echo "Checking: http://osmosis-1-genesis.$NAMESPACE.svc.cluster.local:$GENESIS_PORT/node_id" + sleep 10; + done + echo "Ready to start" + exit 0 + resources: + limits: + cpu: '0.1' + memory: 128M + requests: + cpu: '0.1' + memory: 128M - name: init-validator image: ghcr.io/cosmology-tech/starship/osmosis:v25.0.0 imagePullPolicy: IfNotPresent @@ -57,23 +86,63 @@ spec: value: osmosisd - name: CHAIN_ID value: osmosis-1 + - name: GENESIS_HOST + value: osmosis-1-genesis + - name: GENESIS_PORT + value: '8081' + - name: NAMESPACE + valueFrom: + fieldRef: + fieldPath: metadata.namespace - name: KEYS_CONFIG value: /configs/keys.json + - name: FAUCET_ENABLED + value: 'true' + - name: METRICS + value: 'false' command: - bash - '-c' - >- - #!/bin/bash + VAL_INDEX=${HOSTNAME##*-} + + echo "Validator Index: $VAL_INDEX" + + + + if [ -f $CHAIN_DIR/config/genesis.json ]; then + echo "Genesis file exists, exiting early" + exit 0 + fi + + + VAL_NAME=$(jq -r ".validators[0].name" $KEYS_CONFIG)-$VAL_INDEX + + echo "Validator Index: $VAL_INDEX, Key name: $VAL_NAME" + + + echo "Recover validator $VAL_NAME" + + $CHAIN_BIN init $VAL_NAME --chain-id $CHAIN_ID + + jq -r ".validators[0].mnemonic" $KEYS_CONFIG | $CHAIN_BIN keys add + $VAL_NAME --index $VAL_INDEX --recover --keyring-backend="test" + - set -euo pipefail + curl + http://$GENESIS_HOST.$NAMESPACE.svc.cluster.local:$GENESIS_PORT/genesis + -o $CHAIN_DIR/config/genesis.json + echo "Genesis file that we got....." - echo "Initializing validator node for osmosis-1..." + cat $CHAIN_DIR/config/genesis.json - osmosisd init validator-${HOSTNAME##*-} --chain-id osmosis-1 - --home /root/.osmosisd - echo "Validator initialization completed" + echo "Create node id json file" + + NODE_ID=$($CHAIN_BIN tendermint show-node-id) + + echo '{"node_id":"'$NODE_ID'"}' > $CHAIN_DIR/config/node_id.json resources: limits: cpu: '0.5' @@ -88,7 +157,7 @@ spec: name: addresses - mountPath: /scripts name: scripts - - name: init-validator-config + - name: init-config image: ghcr.io/cosmology-tech/starship/osmosis:v25.0.0 imagePullPolicy: IfNotPresent env: @@ -108,6 +177,14 @@ spec: value: osmosisd - name: CHAIN_ID value: osmosis-1 + - name: GENESIS_HOST + value: osmosis-1-genesis + - name: GENESIS_PORT + value: '8081' + - name: NAMESPACE + valueFrom: + fieldRef: + fieldPath: metadata.namespace - name: KEYS_CONFIG value: /configs/keys.json - name: METRICS @@ -115,7 +192,42 @@ spec: command: - bash - '-c' - - /scripts/update-config.sh + - >- + VAL_INDEX=${HOSTNAME##*-} + + echo "Validator Index: $VAL_INDEX" + + + + echo "Running setup config script..." + + bash -e /scripts/update-config.sh + + + curl -s + http://$GENESIS_HOST.$NAMESPACE.svc.cluster.local:$GENESIS_PORT/node_id + + NODE_ID=$(curl -s + http://$GENESIS_HOST.$NAMESPACE.svc.cluster.local:$GENESIS_PORT/node_id + | jq -r ".node_id") + + if [[ $NODE_ID == "" ]]; then + echo "Node ID is null, exiting early" + exit 1 + fi + + + GENESIS_NODE_P2P=$NODE_ID@$GENESIS_HOST.$NAMESPACE.svc.cluster.local:26656 + + echo "Node P2P: $GENESIS_NODE_P2P" + + sed -i "s/persistent_peers = \"\"/persistent_peers = + \"$GENESIS_NODE_P2P\"/g" $CHAIN_DIR/config/config.toml + + + echo "Printing the whole config.toml file" + + cat $CHAIN_DIR/config/config.toml resources: limits: cpu: '0.5' @@ -151,17 +263,29 @@ spec: value: osmosisd - name: CHAIN_ID value: osmosis-1 + - name: GENESIS_HOST + value: osmosis-1-genesis + - name: GENESIS_PORT + value: '8081' + - name: NAMESPACE + valueFrom: + fieldRef: + fieldPath: metadata.namespace + - name: KEYS_CONFIG + value: /configs/keys.json - name: SLOGFILE value: slog.slog command: - bash - '-c' - |- - #!/bin/bash - set -euo pipefail + set -eux + START_ARGS="" - echo "Starting osmosisd validator..." - exec osmosisd start --home /root/.osmosisd --log_level info + + # Starting the chain + + $CHAIN_BIN start $START_ARGS resources: limits: cpu: '0.5' @@ -182,10 +306,42 @@ spec: command: - bash - '-c' - - |- - #!/bin/bash - echo "Validator post-start hook for osmosis-1" - # Add any post-start logic here + - '-e' + - >- + until bash -e /scripts/chain-rpc-ready.sh + http://localhost:26657; do + sleep 10 + done + + + set -eux + + export + + VAL_INDEX=${HOSTNAME##*-} + + VAL_NAME="$(jq -r ".validators[0].name" + $KEYS_CONFIG)-$VAL_INDEX" + + echo "Validator Index: $VAL_INDEX, Key name: $VAL_NAME. + Chain bin $CHAIN_BIN" + + + VAL_ADDR=$($CHAIN_BIN keys show $VAL_NAME -a + --keyring-backend="test") + + echo "Transfer tokens to address $VAL_ADDR before trying to + create validator. Best effort" + + bash -e /scripts/transfer-tokens.sh \ + $VAL_ADDR \ + $DENOM \ + http://$GENESIS_HOST.$NAMESPACE.svc.cluster.local:8000/credit \ + "true" || true + + $CHAIN_BIN keys list --keyring-backend test | jq + + VAL_NAME=$VAL_NAME bash -e /scripts/create-validator.sh readinessProbe: exec: command: @@ -196,6 +352,62 @@ spec: initialDelaySeconds: 10 periodSeconds: 10 timeoutSeconds: 15 + - name: exposer + image: ghcr.io/cosmology-tech/starship/exposer:latest + imagePullPolicy: IfNotPresent + env: + - name: DENOM + value: uosmo + - name: COINS + value: 100000000000000uosmo,100000000000000uion + - name: CHAIN_BIN + value: osmosisd + - name: CHAIN_DIR + value: /root/.osmosisd + - name: CODE_REPO + value: https://github.com/osmosis-labs/osmosis + - name: DAEMON_HOME + value: /root/.osmosisd + - name: DAEMON_NAME + value: osmosisd + - name: CHAIN_ID + value: osmosis-1 + - name: GENESIS_HOST + value: osmosis-1-genesis + - name: GENESIS_PORT + value: '8081' + - name: NAMESPACE + valueFrom: + fieldRef: + fieldPath: metadata.namespace + - name: EXPOSER_HTTP_PORT + value: '8081' + - name: EXPOSER_GRPC_PORT + value: '9099' + - name: EXPOSER_GENESIS_FILE + value: /root/.osmosisd/config/genesis.json + - name: EXPOSER_MNEMONIC_FILE + value: /configs/keys.json + - name: EXPOSER_PRIV_VAL_FILE + value: /root/.osmosisd/config/priv_validator_key.json + - name: EXPOSER_NODE_KEY_FILE + value: /root/.osmosisd/config/node_key.json + - name: EXPOSER_PRIV_VAL_STATE_FILE + value: /root/.osmosisd/data/priv_validator_state.json + command: + - exposer + resources: + limits: + cpu: '0.1' + memory: 128M + requests: + cpu: '0.1' + memory: 128M + volumeMounts: + - mountPath: /root/.osmosisd + name: node + - mountPath: /configs + name: addresses volumes: - name: node emptyDir: {} @@ -205,3 +417,5 @@ spec: - name: scripts configMap: name: setup-scripts-osmosis-1 + - name: faucet + emptyDir: {} diff --git a/packages/packages/generator/__tests__/__output__/builder-tests/consistency-single/osmosis/genesis-patch-configmap.yaml b/packages/packages/generator/__tests__/__output__/builder-tests/consistency-single/osmosis/genesis-patch-configmap.yaml index 9d9f28269..9f6eabb71 100644 --- a/packages/packages/generator/__tests__/__output__/builder-tests/consistency-single/osmosis/genesis-patch-configmap.yaml +++ b/packages/packages/generator/__tests__/__output__/builder-tests/consistency-single/osmosis/genesis-patch-configmap.yaml @@ -10,8 +10,10 @@ metadata: app.kubernetes.io/name: osmosis app.kubernetes.io/part-of: osmosis-1 app.kubernetes.io/role: genesis-patch + starship.io/chain-name: osmosis + starship.io/chain-id: osmosis-1 data: - patch.json: |- + genesis.json: |- { "app_state": { "staking": { diff --git a/packages/packages/generator/__tests__/__output__/builder-tests/consistency-single/osmosis/genesis-statefulset.yaml b/packages/packages/generator/__tests__/__output__/builder-tests/consistency-single/osmosis/genesis-statefulset.yaml index b681e88a9..9f4102b5b 100644 --- a/packages/packages/generator/__tests__/__output__/builder-tests/consistency-single/osmosis/genesis-statefulset.yaml +++ b/packages/packages/generator/__tests__/__output__/builder-tests/consistency-single/osmosis/genesis-statefulset.yaml @@ -68,7 +68,52 @@ spec: command: - bash - '-c' - - /scripts/create-genesis.sh + - >- + VAL_INDEX=${HOSTNAME##*-} + + echo "Validator Index: $VAL_INDEX" + + + if [ -f $CHAIN_DIR/config/genesis.json ]; then + echo "Genesis file exists, exiting init container" + exit 0 + fi + + + echo "Running setup genesis script..." + + bash -e /scripts/create-genesis.sh + + bash -e /scripts/update-genesis.sh + + + echo "Create node id json file" + + NODE_ID=$($CHAIN_BIN tendermint show-node-id) + + echo '{"node_id":"'$NODE_ID'"}' > $CHAIN_DIR/config/node_id.json + + + echo "Create consensus key json file" + + $CHAIN_BIN tendermint show-validator > + $CHAIN_DIR/config/consensus_key.json + + cat $CHAIN_DIR/config/consensus_key.json + + + echo "Add custom accounts and balances" + + CHAIN_GENESIS_CMD=$($CHAIN_BIN 2>&1 | grep -q "genesis-related + subcommands" && echo "genesis" || echo "") + + + echo "Adding balance to + osmo1e9ucjn5fjmetky5wezzcsccp7hqcwzrrhthpf5" + + $CHAIN_BIN $CHAIN_GENESIS_CMD add-genesis-account + osmo1e9ucjn5fjmetky5wezzcsccp7hqcwzrrhthpf5 2000000000000uosmo + --keyring-backend="test" resources: limits: cpu: '0.5' @@ -110,7 +155,21 @@ spec: command: - bash - '-c' - - /scripts/update-config.sh + - >- + VAL_INDEX=${HOSTNAME##*-} + + echo "Validator Index: $VAL_INDEX" + + + echo "Running setup config script..." + + + jq -s '.[0] * .[1]' $CHAIN_DIR/config/genesis.json + /patch/genesis.json > $CHAIN_DIR/config/genesis.json.tmp && mv + $CHAIN_DIR/config/genesis.json.tmp $CHAIN_DIR/config/genesis.json + + + bash -e /scripts/update-config.sh resources: limits: cpu: '0.5' @@ -176,8 +235,10 @@ spec: #!/bin/bash set -euo pipefail - echo "Starting osmosisd validator..." - exec osmosisd start --home /root/.osmosisd --log_level info + START_ARGS="" + + + $CHAIN_BIN start $START_ARGS resources: limits: cpu: '0.5' @@ -245,31 +306,66 @@ spec: - mountPath: /configs name: addresses - name: faucet - image: busybox:1.34.1 + image: ghcr.io/cosmology-tech/starship/osmosis:v25.0.0 imagePullPolicy: IfNotPresent env: - name: FAUCET_CONCURRENCY value: '2' - - name: FAUCET_PORT + - name: FAUCET_HTTP_PORT value: '8000' + - name: FAUCET_CHAIN_BINARY + value: osmosisd - name: FAUCET_CHAIN_ID value: osmosis-1 - - name: FAUCET_CHAIN_DENOM - value: uosmo - - name: FAUCET_CHAIN_PREFIX - value: osmo - - name: FAUCET_AMOUNT_SEND - value: '10000000' - - name: FAUCET_AMOUNT_STAKE - value: '10000000' - - name: FAUCET_RPC_ENDPOINT - value: http://localhost:26657 - - name: FAUCET_REST_ENDPOINT - value: http://localhost:1317 + - name: COINS + value: 100000000000000uosmo,100000000000000uion command: - - sh + - bash - '-c' - - /faucet/faucet + - >- + CREDIT_COINS="" + + FEES="" + + for coin in ${COINS//,/ } + + do + amt="${coin//[!0-9]/}" + denom="${coin//[0-9]/}" + + # Calculate the order of magnitude + if [ ${#amt} -gt 18 ]; then + creditAmt=$(echo $amt | sed -e "s/000000$//") + feesAmt=$(echo $amt | sed -e "s/0000000000000$//") + else + creditAmt=$(echo $amt | sed -e "s/0000$//") + feesAmt=$(echo $amt | sed -e "s/00000000$//") + fi + + if [[ $CREDIT_COINS == "" ]] + then + CREDIT_COINS="$creditAmt$denom" + FEES="$feesAmt$denom" + else + CREDIT_COINS="${CREDIT_COINS},$creditAmt$denom" + fi + done + + + export FAUCET_MNEMONIC=$(jq -r ".faucet[0].mnemonic" + /configs/keys.json) + + + export | grep "FAUCET" + + + until bash -e /scripts/chain-rpc-ready.sh http://localhost:26657; + do + sleep 10 + done + + + /faucet/faucet --credit-coins="$CREDIT_COINS" --chain-fees="$FEES" resources: limits: cpu: '0.1' @@ -282,6 +378,14 @@ spec: name: addresses - mountPath: /faucet name: faucet + - mountPath: /scripts + name: scripts + readinessProbe: + httpGet: + path: /status + port: '8000' + initialDelaySeconds: 30 + periodSeconds: 10 volumes: - name: node emptyDir: {} @@ -294,3 +398,5 @@ spec: - name: patch configMap: name: patch-osmosis-1 + - name: faucet + emptyDir: {} diff --git a/packages/packages/generator/__tests__/__output__/builder-tests/consistency-single/osmosis/setup-scripts-configmap.yaml b/packages/packages/generator/__tests__/__output__/builder-tests/consistency-single/osmosis/setup-scripts-configmap.yaml index 770edb52d..0f3d10fee 100644 --- a/packages/packages/generator/__tests__/__output__/builder-tests/consistency-single/osmosis/setup-scripts-configmap.yaml +++ b/packages/packages/generator/__tests__/__output__/builder-tests/consistency-single/osmosis/setup-scripts-configmap.yaml @@ -10,6 +10,8 @@ metadata: app.kubernetes.io/name: osmosis app.kubernetes.io/part-of: osmosis-1 app.kubernetes.io/role: setup-scripts + starship.io/chain-name: osmosis + starship.io/chain-id: osmosis-1 data: create-genesis.sh: > #!/bin/bash diff --git a/packages/packages/generator/__tests__/__output__/builder-tests/content-validation/osmosis/genesis-patch-configmap.yaml b/packages/packages/generator/__tests__/__output__/builder-tests/content-validation/osmosis/genesis-patch-configmap.yaml index 9d9f28269..9f6eabb71 100644 --- a/packages/packages/generator/__tests__/__output__/builder-tests/content-validation/osmosis/genesis-patch-configmap.yaml +++ b/packages/packages/generator/__tests__/__output__/builder-tests/content-validation/osmosis/genesis-patch-configmap.yaml @@ -10,8 +10,10 @@ metadata: app.kubernetes.io/name: osmosis app.kubernetes.io/part-of: osmosis-1 app.kubernetes.io/role: genesis-patch + starship.io/chain-name: osmosis + starship.io/chain-id: osmosis-1 data: - patch.json: |- + genesis.json: |- { "app_state": { "staking": { diff --git a/packages/packages/generator/__tests__/__output__/builder-tests/content-validation/osmosis/genesis-statefulset.yaml b/packages/packages/generator/__tests__/__output__/builder-tests/content-validation/osmosis/genesis-statefulset.yaml index b681e88a9..9f4102b5b 100644 --- a/packages/packages/generator/__tests__/__output__/builder-tests/content-validation/osmosis/genesis-statefulset.yaml +++ b/packages/packages/generator/__tests__/__output__/builder-tests/content-validation/osmosis/genesis-statefulset.yaml @@ -68,7 +68,52 @@ spec: command: - bash - '-c' - - /scripts/create-genesis.sh + - >- + VAL_INDEX=${HOSTNAME##*-} + + echo "Validator Index: $VAL_INDEX" + + + if [ -f $CHAIN_DIR/config/genesis.json ]; then + echo "Genesis file exists, exiting init container" + exit 0 + fi + + + echo "Running setup genesis script..." + + bash -e /scripts/create-genesis.sh + + bash -e /scripts/update-genesis.sh + + + echo "Create node id json file" + + NODE_ID=$($CHAIN_BIN tendermint show-node-id) + + echo '{"node_id":"'$NODE_ID'"}' > $CHAIN_DIR/config/node_id.json + + + echo "Create consensus key json file" + + $CHAIN_BIN tendermint show-validator > + $CHAIN_DIR/config/consensus_key.json + + cat $CHAIN_DIR/config/consensus_key.json + + + echo "Add custom accounts and balances" + + CHAIN_GENESIS_CMD=$($CHAIN_BIN 2>&1 | grep -q "genesis-related + subcommands" && echo "genesis" || echo "") + + + echo "Adding balance to + osmo1e9ucjn5fjmetky5wezzcsccp7hqcwzrrhthpf5" + + $CHAIN_BIN $CHAIN_GENESIS_CMD add-genesis-account + osmo1e9ucjn5fjmetky5wezzcsccp7hqcwzrrhthpf5 2000000000000uosmo + --keyring-backend="test" resources: limits: cpu: '0.5' @@ -110,7 +155,21 @@ spec: command: - bash - '-c' - - /scripts/update-config.sh + - >- + VAL_INDEX=${HOSTNAME##*-} + + echo "Validator Index: $VAL_INDEX" + + + echo "Running setup config script..." + + + jq -s '.[0] * .[1]' $CHAIN_DIR/config/genesis.json + /patch/genesis.json > $CHAIN_DIR/config/genesis.json.tmp && mv + $CHAIN_DIR/config/genesis.json.tmp $CHAIN_DIR/config/genesis.json + + + bash -e /scripts/update-config.sh resources: limits: cpu: '0.5' @@ -176,8 +235,10 @@ spec: #!/bin/bash set -euo pipefail - echo "Starting osmosisd validator..." - exec osmosisd start --home /root/.osmosisd --log_level info + START_ARGS="" + + + $CHAIN_BIN start $START_ARGS resources: limits: cpu: '0.5' @@ -245,31 +306,66 @@ spec: - mountPath: /configs name: addresses - name: faucet - image: busybox:1.34.1 + image: ghcr.io/cosmology-tech/starship/osmosis:v25.0.0 imagePullPolicy: IfNotPresent env: - name: FAUCET_CONCURRENCY value: '2' - - name: FAUCET_PORT + - name: FAUCET_HTTP_PORT value: '8000' + - name: FAUCET_CHAIN_BINARY + value: osmosisd - name: FAUCET_CHAIN_ID value: osmosis-1 - - name: FAUCET_CHAIN_DENOM - value: uosmo - - name: FAUCET_CHAIN_PREFIX - value: osmo - - name: FAUCET_AMOUNT_SEND - value: '10000000' - - name: FAUCET_AMOUNT_STAKE - value: '10000000' - - name: FAUCET_RPC_ENDPOINT - value: http://localhost:26657 - - name: FAUCET_REST_ENDPOINT - value: http://localhost:1317 + - name: COINS + value: 100000000000000uosmo,100000000000000uion command: - - sh + - bash - '-c' - - /faucet/faucet + - >- + CREDIT_COINS="" + + FEES="" + + for coin in ${COINS//,/ } + + do + amt="${coin//[!0-9]/}" + denom="${coin//[0-9]/}" + + # Calculate the order of magnitude + if [ ${#amt} -gt 18 ]; then + creditAmt=$(echo $amt | sed -e "s/000000$//") + feesAmt=$(echo $amt | sed -e "s/0000000000000$//") + else + creditAmt=$(echo $amt | sed -e "s/0000$//") + feesAmt=$(echo $amt | sed -e "s/00000000$//") + fi + + if [[ $CREDIT_COINS == "" ]] + then + CREDIT_COINS="$creditAmt$denom" + FEES="$feesAmt$denom" + else + CREDIT_COINS="${CREDIT_COINS},$creditAmt$denom" + fi + done + + + export FAUCET_MNEMONIC=$(jq -r ".faucet[0].mnemonic" + /configs/keys.json) + + + export | grep "FAUCET" + + + until bash -e /scripts/chain-rpc-ready.sh http://localhost:26657; + do + sleep 10 + done + + + /faucet/faucet --credit-coins="$CREDIT_COINS" --chain-fees="$FEES" resources: limits: cpu: '0.1' @@ -282,6 +378,14 @@ spec: name: addresses - mountPath: /faucet name: faucet + - mountPath: /scripts + name: scripts + readinessProbe: + httpGet: + path: /status + port: '8000' + initialDelaySeconds: 30 + periodSeconds: 10 volumes: - name: node emptyDir: {} @@ -294,3 +398,5 @@ spec: - name: patch configMap: name: patch-osmosis-1 + - name: faucet + emptyDir: {} diff --git a/packages/packages/generator/__tests__/__output__/builder-tests/content-validation/osmosis/setup-scripts-configmap.yaml b/packages/packages/generator/__tests__/__output__/builder-tests/content-validation/osmosis/setup-scripts-configmap.yaml index 770edb52d..0f3d10fee 100644 --- a/packages/packages/generator/__tests__/__output__/builder-tests/content-validation/osmosis/setup-scripts-configmap.yaml +++ b/packages/packages/generator/__tests__/__output__/builder-tests/content-validation/osmosis/setup-scripts-configmap.yaml @@ -10,6 +10,8 @@ metadata: app.kubernetes.io/name: osmosis app.kubernetes.io/part-of: osmosis-1 app.kubernetes.io/role: setup-scripts + starship.io/chain-name: osmosis + starship.io/chain-id: osmosis-1 data: create-genesis.sh: > #!/bin/bash diff --git a/packages/packages/generator/__tests__/__output__/builder-tests/cosmjs-faucet/osmosis/genesis-statefulset.yaml b/packages/packages/generator/__tests__/__output__/builder-tests/cosmjs-faucet/osmosis/genesis-statefulset.yaml index f7e6e0be0..0849609af 100644 --- a/packages/packages/generator/__tests__/__output__/builder-tests/cosmjs-faucet/osmosis/genesis-statefulset.yaml +++ b/packages/packages/generator/__tests__/__output__/builder-tests/cosmjs-faucet/osmosis/genesis-statefulset.yaml @@ -68,7 +68,44 @@ spec: command: - bash - '-c' - - /scripts/create-genesis.sh + - >- + VAL_INDEX=${HOSTNAME##*-} + + echo "Validator Index: $VAL_INDEX" + + + if [ -f $CHAIN_DIR/config/genesis.json ]; then + echo "Genesis file exists, exiting init container" + exit 0 + fi + + + echo "Running setup genesis script..." + + bash -e /scripts/create-genesis.sh + + bash -e /scripts/update-genesis.sh + + + echo "Create node id json file" + + NODE_ID=$($CHAIN_BIN tendermint show-node-id) + + echo '{"node_id":"'$NODE_ID'"}' > $CHAIN_DIR/config/node_id.json + + + echo "Create consensus key json file" + + $CHAIN_BIN tendermint show-validator > + $CHAIN_DIR/config/consensus_key.json + + cat $CHAIN_DIR/config/consensus_key.json + + + echo "Add custom accounts and balances" + + CHAIN_GENESIS_CMD=$($CHAIN_BIN 2>&1 | grep -q "genesis-related + subcommands" && echo "genesis" || echo "") resources: limits: cpu: '0.5' @@ -110,7 +147,13 @@ spec: command: - bash - '-c' - - /scripts/update-config.sh + - |- + VAL_INDEX=${HOSTNAME##*-} + echo "Validator Index: $VAL_INDEX" + + echo "Running setup config script..." + + bash -e /scripts/update-config.sh resources: limits: cpu: '0.5' @@ -157,8 +200,10 @@ spec: #!/bin/bash set -euo pipefail - echo "Starting osmosisd validator..." - exec osmosisd start --home /root/.osmosisd --log_level info + START_ARGS="" + + + $CHAIN_BIN start $START_ARGS resources: limits: cpu: '0.5' @@ -233,29 +278,70 @@ spec: value: '2' - name: FAUCET_PORT value: '8000' + - name: FAUCET_MEMO + value: faucet txn - name: FAUCET_GAS_PRICE - value: '0.025' - - name: FAUCET_PATH_PATTERN - value: '' + value: 1.25uosmo + - name: FAUCET_GAS_LIMIT + value: '2000000' - name: FAUCET_ADDRESS_PREFIX value: osmo - - name: FAUCET_TOKENS - value: uosmo - - name: FAUCET_CREDIT_AMOUNT_SEND - value: '10000000' - - name: FAUCET_CREDIT_AMOUNT_STAKE - value: '10000000' - - name: FAUCET_MAX_CREDIT - value: '99999999' - - name: FAUCET_MNEMONIC - value: '' - - name: FAUCET_CHAIN_ID - value: osmosis-1 - - name: FAUCET_RPC_ENDPOINT - value: http://localhost:26657 + - name: FAUCET_REFILL_FACTOR + value: '8' + - name: FAUCET_REFILL_THRESHOLD + value: '20' + - name: FAUCET_COOLDOWN_TIME + value: '0' + - name: COINS + value: 100000000000000uosmo,100000000000000uion + - name: HD_PATH + value: m/44'/118'/0'/0/0 command: - - yarn - - start + - bash + - '-c' + - >- + export FAUCET_TOKENS=$(printf '%s\n' ${COINS//[[:digit:]]/}) + + for coin in ${COINS//,/ } + + do + var="FAUCET_CREDIT_AMOUNT_$(printf '%s\n' ${coin//[[:digit:]]/} | tr '[:lower:]' '[:upper:]')" + amt="${coin//[!0-9]/}" + + if [ ${#amt} -gt 18 ]; then + creditAmt=$(echo $amt | sed -e "s/000000$//") + feesAmt=$(echo $amt | sed -e "s/0000000000000$//") + else + creditAmt=$(echo $amt | sed -e "s/0000$//") + feesAmt=$(echo $amt | sed -e "s/00000000$//") + fi + + export $var="$creditAmt" + done + + + export FAUCET_PATH_PATTERN="${HD_PATH:0:$((${#HD_PATH}-1))}a" + + export FAUCET_MNEMONIC=$(jq -r ".faucet[0].mnemonic" + /configs/keys.json) + + + echo "FAUCET_MNEMONIC: $FAUCET_MNEMONIC" + + echo "FAUCET_PATH_PATTERN: $FAUCET_PATH_PATTERN" + + + export | grep "FAUCET" + + + until bash -e /scripts/chain-rpc-ready.sh http://localhost:26657; + do + sleep 10; + done + + + /app/packages/faucet/bin/cosmos-faucet-dist start + "http://localhost:26657" resources: limits: cpu: '0.2' @@ -266,6 +352,14 @@ spec: volumeMounts: - mountPath: /configs name: addresses + - mountPath: /scripts + name: scripts + readinessProbe: + httpGet: + path: /status + port: '8000' + initialDelaySeconds: 30 + periodSeconds: 10 volumes: - name: node emptyDir: {} diff --git a/packages/packages/generator/__tests__/__output__/builder-tests/cosmjs-faucet/osmosis/setup-scripts-configmap.yaml b/packages/packages/generator/__tests__/__output__/builder-tests/cosmjs-faucet/osmosis/setup-scripts-configmap.yaml index 770edb52d..0f3d10fee 100644 --- a/packages/packages/generator/__tests__/__output__/builder-tests/cosmjs-faucet/osmosis/setup-scripts-configmap.yaml +++ b/packages/packages/generator/__tests__/__output__/builder-tests/cosmjs-faucet/osmosis/setup-scripts-configmap.yaml @@ -10,6 +10,8 @@ metadata: app.kubernetes.io/name: osmosis app.kubernetes.io/part-of: osmosis-1 app.kubernetes.io/role: setup-scripts + starship.io/chain-name: osmosis + starship.io/chain-id: osmosis-1 data: create-genesis.sh: > #!/bin/bash diff --git a/packages/packages/generator/__tests__/__output__/builder-tests/full-builders/osmosis/genesis-patch-configmap.yaml b/packages/packages/generator/__tests__/__output__/builder-tests/full-builders/osmosis/genesis-patch-configmap.yaml index bde8606b4..6d7735eb4 100644 --- a/packages/packages/generator/__tests__/__output__/builder-tests/full-builders/osmosis/genesis-patch-configmap.yaml +++ b/packages/packages/generator/__tests__/__output__/builder-tests/full-builders/osmosis/genesis-patch-configmap.yaml @@ -10,8 +10,10 @@ metadata: app.kubernetes.io/name: osmosis app.kubernetes.io/part-of: osmosis-1 app.kubernetes.io/role: genesis-patch + starship.io/chain-name: osmosis + starship.io/chain-id: osmosis-1 data: - patch.json: |- + genesis.json: |- { "app_state": { "staking": { diff --git a/packages/packages/generator/__tests__/__output__/builder-tests/full-builders/osmosis/genesis-statefulset.yaml b/packages/packages/generator/__tests__/__output__/builder-tests/full-builders/osmosis/genesis-statefulset.yaml index 482fc8d2b..05362d6d9 100644 --- a/packages/packages/generator/__tests__/__output__/builder-tests/full-builders/osmosis/genesis-statefulset.yaml +++ b/packages/packages/generator/__tests__/__output__/builder-tests/full-builders/osmosis/genesis-statefulset.yaml @@ -68,7 +68,52 @@ spec: command: - bash - '-c' - - /scripts/create-genesis.sh + - >- + VAL_INDEX=${HOSTNAME##*-} + + echo "Validator Index: $VAL_INDEX" + + + if [ -f $CHAIN_DIR/config/genesis.json ]; then + echo "Genesis file exists, exiting init container" + exit 0 + fi + + + echo "Running setup genesis script..." + + bash -e /scripts/create-genesis.sh + + bash -e /scripts/update-genesis.sh + + + echo "Create node id json file" + + NODE_ID=$($CHAIN_BIN tendermint show-node-id) + + echo '{"node_id":"'$NODE_ID'"}' > $CHAIN_DIR/config/node_id.json + + + echo "Create consensus key json file" + + $CHAIN_BIN tendermint show-validator > + $CHAIN_DIR/config/consensus_key.json + + cat $CHAIN_DIR/config/consensus_key.json + + + echo "Add custom accounts and balances" + + CHAIN_GENESIS_CMD=$($CHAIN_BIN 2>&1 | grep -q "genesis-related + subcommands" && echo "genesis" || echo "") + + + echo "Adding balance to + osmo1e9ucjn5fjmetky5wezzcsccp7hqcwzrrhthpf5" + + $CHAIN_BIN $CHAIN_GENESIS_CMD add-genesis-account + osmo1e9ucjn5fjmetky5wezzcsccp7hqcwzrrhthpf5 2000000000000uosmo + --keyring-backend="test" resources: limits: cpu: '0.5' @@ -110,7 +155,21 @@ spec: command: - bash - '-c' - - /scripts/update-config.sh + - >- + VAL_INDEX=${HOSTNAME##*-} + + echo "Validator Index: $VAL_INDEX" + + + echo "Running setup config script..." + + + jq -s '.[0] * .[1]' $CHAIN_DIR/config/genesis.json + /patch/genesis.json > $CHAIN_DIR/config/genesis.json.tmp && mv + $CHAIN_DIR/config/genesis.json.tmp $CHAIN_DIR/config/genesis.json + + + bash -e /scripts/update-config.sh resources: limits: cpu: '0.5' @@ -176,8 +235,10 @@ spec: #!/bin/bash set -euo pipefail - echo "Starting osmosisd validator..." - exec osmosisd start --home /root/.osmosisd --log_level info + START_ARGS="" + + + $CHAIN_BIN start $START_ARGS resources: limits: cpu: '0.5' @@ -245,31 +306,66 @@ spec: - mountPath: /configs name: addresses - name: faucet - image: busybox:1.34.1 + image: ghcr.io/cosmology-tech/starship/osmosis:v25.0.0 imagePullPolicy: IfNotPresent env: - name: FAUCET_CONCURRENCY value: '2' - - name: FAUCET_PORT + - name: FAUCET_HTTP_PORT value: '8000' + - name: FAUCET_CHAIN_BINARY + value: osmosisd - name: FAUCET_CHAIN_ID value: osmosis-1 - - name: FAUCET_CHAIN_DENOM - value: uosmo - - name: FAUCET_CHAIN_PREFIX - value: osmo - - name: FAUCET_AMOUNT_SEND - value: '10000000' - - name: FAUCET_AMOUNT_STAKE - value: '10000000' - - name: FAUCET_RPC_ENDPOINT - value: http://localhost:26657 - - name: FAUCET_REST_ENDPOINT - value: http://localhost:1317 + - name: COINS + value: 100000000000000uosmo,100000000000000uion command: - - sh + - bash - '-c' - - /faucet/faucet + - >- + CREDIT_COINS="" + + FEES="" + + for coin in ${COINS//,/ } + + do + amt="${coin//[!0-9]/}" + denom="${coin//[0-9]/}" + + # Calculate the order of magnitude + if [ ${#amt} -gt 18 ]; then + creditAmt=$(echo $amt | sed -e "s/000000$//") + feesAmt=$(echo $amt | sed -e "s/0000000000000$//") + else + creditAmt=$(echo $amt | sed -e "s/0000$//") + feesAmt=$(echo $amt | sed -e "s/00000000$//") + fi + + if [[ $CREDIT_COINS == "" ]] + then + CREDIT_COINS="$creditAmt$denom" + FEES="$feesAmt$denom" + else + CREDIT_COINS="${CREDIT_COINS},$creditAmt$denom" + fi + done + + + export FAUCET_MNEMONIC=$(jq -r ".faucet[0].mnemonic" + /configs/keys.json) + + + export | grep "FAUCET" + + + until bash -e /scripts/chain-rpc-ready.sh http://localhost:26657; + do + sleep 10 + done + + + /faucet/faucet --credit-coins="$CREDIT_COINS" --chain-fees="$FEES" resources: limits: cpu: '0.1' @@ -282,6 +378,14 @@ spec: name: addresses - mountPath: /faucet name: faucet + - mountPath: /scripts + name: scripts + readinessProbe: + httpGet: + path: /status + port: '8000' + initialDelaySeconds: 30 + periodSeconds: 10 volumes: - name: node emptyDir: {} @@ -294,3 +398,5 @@ spec: - name: patch configMap: name: patch-osmosis-1 + - name: faucet + emptyDir: {} diff --git a/packages/packages/generator/__tests__/__output__/builder-tests/full-builders/osmosis/setup-scripts-configmap.yaml b/packages/packages/generator/__tests__/__output__/builder-tests/full-builders/osmosis/setup-scripts-configmap.yaml index 9dc9b50f6..fabc88531 100644 --- a/packages/packages/generator/__tests__/__output__/builder-tests/full-builders/osmosis/setup-scripts-configmap.yaml +++ b/packages/packages/generator/__tests__/__output__/builder-tests/full-builders/osmosis/setup-scripts-configmap.yaml @@ -10,6 +10,8 @@ metadata: app.kubernetes.io/name: osmosis app.kubernetes.io/part-of: osmosis-1 app.kubernetes.io/role: setup-scripts + starship.io/chain-name: osmosis + starship.io/chain-id: osmosis-1 data: create-genesis.sh: > #!/bin/bash diff --git a/packages/packages/generator/__tests__/__output__/builder-tests/multi-chain/cosmoshub/genesis-statefulset.yaml b/packages/packages/generator/__tests__/__output__/builder-tests/multi-chain/cosmoshub/genesis-statefulset.yaml index 9faa6ae15..46d80e179 100644 --- a/packages/packages/generator/__tests__/__output__/builder-tests/multi-chain/cosmoshub/genesis-statefulset.yaml +++ b/packages/packages/generator/__tests__/__output__/builder-tests/multi-chain/cosmoshub/genesis-statefulset.yaml @@ -68,7 +68,44 @@ spec: command: - bash - '-c' - - /scripts/create-genesis.sh + - >- + VAL_INDEX=${HOSTNAME##*-} + + echo "Validator Index: $VAL_INDEX" + + + if [ -f $CHAIN_DIR/config/genesis.json ]; then + echo "Genesis file exists, exiting init container" + exit 0 + fi + + + echo "Running setup genesis script..." + + bash -e /scripts/create-genesis.sh + + bash -e /scripts/update-genesis.sh + + + echo "Create node id json file" + + NODE_ID=$($CHAIN_BIN tendermint show-node-id) + + echo '{"node_id":"'$NODE_ID'"}' > $CHAIN_DIR/config/node_id.json + + + echo "Create consensus key json file" + + $CHAIN_BIN tendermint show-validator > + $CHAIN_DIR/config/consensus_key.json + + cat $CHAIN_DIR/config/consensus_key.json + + + echo "Add custom accounts and balances" + + CHAIN_GENESIS_CMD=$($CHAIN_BIN 2>&1 | grep -q "genesis-related + subcommands" && echo "genesis" || echo "") resources: limits: cpu: '0.5' @@ -110,7 +147,13 @@ spec: command: - bash - '-c' - - /scripts/update-config.sh + - |- + VAL_INDEX=${HOSTNAME##*-} + echo "Validator Index: $VAL_INDEX" + + echo "Running setup config script..." + + bash -e /scripts/update-config.sh resources: limits: cpu: '0.5' @@ -157,8 +200,10 @@ spec: #!/bin/bash set -euo pipefail - echo "Starting gaiad validator..." - exec gaiad start --home /root/.gaia --log_level info + START_ARGS="" + + + $CHAIN_BIN start $START_ARGS resources: limits: cpu: '0.5' diff --git a/packages/packages/generator/__tests__/__output__/builder-tests/multi-chain/cosmoshub/setup-scripts-configmap.yaml b/packages/packages/generator/__tests__/__output__/builder-tests/multi-chain/cosmoshub/setup-scripts-configmap.yaml index 4ea5e61f9..0fa5e316a 100644 --- a/packages/packages/generator/__tests__/__output__/builder-tests/multi-chain/cosmoshub/setup-scripts-configmap.yaml +++ b/packages/packages/generator/__tests__/__output__/builder-tests/multi-chain/cosmoshub/setup-scripts-configmap.yaml @@ -10,6 +10,8 @@ metadata: app.kubernetes.io/name: cosmoshub app.kubernetes.io/part-of: cosmoshub-4 app.kubernetes.io/role: setup-scripts + starship.io/chain-name: cosmoshub + starship.io/chain-id: cosmoshub-4 data: create-genesis.sh: > #!/bin/bash diff --git a/packages/packages/generator/__tests__/__output__/builder-tests/multi-chain/cosmoshub/validator-statefulset.yaml b/packages/packages/generator/__tests__/__output__/builder-tests/multi-chain/cosmoshub/validator-statefulset.yaml index eba7a5c53..426a6f37b 100644 --- a/packages/packages/generator/__tests__/__output__/builder-tests/multi-chain/cosmoshub/validator-statefulset.yaml +++ b/packages/packages/generator/__tests__/__output__/builder-tests/multi-chain/cosmoshub/validator-statefulset.yaml @@ -9,7 +9,7 @@ metadata: app.kubernetes.io/component: chain app.kubernetes.io/part-of: cosmoshub-4 app.kubernetes.io/id: cosmoshub-4 - app.kubernetes.io/name: cosmoshub-4-genesis + app.kubernetes.io/name: cosmoshub-4-validator app.kubernetes.io/type: cosmoshub-4-statefulset app.kubernetes.io/role: validator starship.io/chain-name: cosmoshub @@ -37,6 +37,35 @@ spec: app.kubernetes.io/role: validator spec: initContainers: + - name: wait-for-chains + image: curlimages/curl:latest + imagePullPolicy: IfNotPresent + env: + - name: GENESIS_PORT + value: '8081' + - name: NAMESPACE + valueFrom: + fieldRef: + fieldPath: metadata.namespace + command: + - /bin/sh + - '-c' + - |2- + + while [ $(curl -sw '%{http_code}' http://cosmoshub-4-genesis.$NAMESPACE.svc.cluster.local:$GENESIS_PORT/node_id -o /dev/null) -ne 200 ]; do + echo "Genesis validator does not seem to be ready for: cosmoshub-4. Waiting for it to start..." + echo "Checking: http://cosmoshub-4-genesis.$NAMESPACE.svc.cluster.local:$GENESIS_PORT/node_id" + sleep 10; + done + echo "Ready to start" + exit 0 + resources: + limits: + cpu: '0.1' + memory: 128M + requests: + cpu: '0.1' + memory: 128M - name: init-validator image: ghcr.io/cosmology-tech/starship/gaia:v18.0.0 imagePullPolicy: IfNotPresent @@ -57,23 +86,63 @@ spec: value: gaiad - name: CHAIN_ID value: cosmoshub-4 + - name: GENESIS_HOST + value: cosmoshub-4-genesis + - name: GENESIS_PORT + value: '8081' + - name: NAMESPACE + valueFrom: + fieldRef: + fieldPath: metadata.namespace - name: KEYS_CONFIG value: /configs/keys.json + - name: FAUCET_ENABLED + value: 'false' + - name: METRICS + value: 'false' command: - bash - '-c' - >- - #!/bin/bash + VAL_INDEX=${HOSTNAME##*-} + + echo "Validator Index: $VAL_INDEX" + + + + if [ -f $CHAIN_DIR/config/genesis.json ]; then + echo "Genesis file exists, exiting early" + exit 0 + fi + + + VAL_NAME=$(jq -r ".validators[0].name" $KEYS_CONFIG)-$VAL_INDEX + + echo "Validator Index: $VAL_INDEX, Key name: $VAL_NAME" + + + echo "Recover validator $VAL_NAME" + + $CHAIN_BIN init $VAL_NAME --chain-id $CHAIN_ID + + jq -r ".validators[0].mnemonic" $KEYS_CONFIG | $CHAIN_BIN keys add + $VAL_NAME --index $VAL_INDEX --recover --keyring-backend="test" - set -euo pipefail + curl + http://$GENESIS_HOST.$NAMESPACE.svc.cluster.local:$GENESIS_PORT/genesis + -o $CHAIN_DIR/config/genesis.json - echo "Initializing validator node for cosmoshub-4..." + echo "Genesis file that we got....." - gaiad init validator-${HOSTNAME##*-} --chain-id cosmoshub-4 --home - /root/.gaia + cat $CHAIN_DIR/config/genesis.json - echo "Validator initialization completed" + + echo "Create node id json file" + + NODE_ID=$($CHAIN_BIN tendermint show-node-id) + + echo '{"node_id":"'$NODE_ID'"}' > $CHAIN_DIR/config/node_id.json resources: limits: cpu: '0.5' @@ -88,7 +157,7 @@ spec: name: addresses - mountPath: /scripts name: scripts - - name: init-validator-config + - name: init-config image: ghcr.io/cosmology-tech/starship/gaia:v18.0.0 imagePullPolicy: IfNotPresent env: @@ -108,6 +177,14 @@ spec: value: gaiad - name: CHAIN_ID value: cosmoshub-4 + - name: GENESIS_HOST + value: cosmoshub-4-genesis + - name: GENESIS_PORT + value: '8081' + - name: NAMESPACE + valueFrom: + fieldRef: + fieldPath: metadata.namespace - name: KEYS_CONFIG value: /configs/keys.json - name: METRICS @@ -115,7 +192,42 @@ spec: command: - bash - '-c' - - /scripts/update-config.sh + - >- + VAL_INDEX=${HOSTNAME##*-} + + echo "Validator Index: $VAL_INDEX" + + + + echo "Running setup config script..." + + bash -e /scripts/update-config.sh + + + curl -s + http://$GENESIS_HOST.$NAMESPACE.svc.cluster.local:$GENESIS_PORT/node_id + + NODE_ID=$(curl -s + http://$GENESIS_HOST.$NAMESPACE.svc.cluster.local:$GENESIS_PORT/node_id + | jq -r ".node_id") + + if [[ $NODE_ID == "" ]]; then + echo "Node ID is null, exiting early" + exit 1 + fi + + + GENESIS_NODE_P2P=$NODE_ID@$GENESIS_HOST.$NAMESPACE.svc.cluster.local:26656 + + echo "Node P2P: $GENESIS_NODE_P2P" + + sed -i "s/persistent_peers = \"\"/persistent_peers = + \"$GENESIS_NODE_P2P\"/g" $CHAIN_DIR/config/config.toml + + + echo "Printing the whole config.toml file" + + cat $CHAIN_DIR/config/config.toml resources: limits: cpu: '0.5' @@ -151,17 +263,29 @@ spec: value: gaiad - name: CHAIN_ID value: cosmoshub-4 + - name: GENESIS_HOST + value: cosmoshub-4-genesis + - name: GENESIS_PORT + value: '8081' + - name: NAMESPACE + valueFrom: + fieldRef: + fieldPath: metadata.namespace + - name: KEYS_CONFIG + value: /configs/keys.json - name: SLOGFILE value: slog.slog command: - bash - '-c' - |- - #!/bin/bash - set -euo pipefail + set -eux + START_ARGS="" + + + # Starting the chain - echo "Starting gaiad validator..." - exec gaiad start --home /root/.gaia --log_level info + $CHAIN_BIN start $START_ARGS resources: limits: cpu: '0.5' @@ -182,10 +306,42 @@ spec: command: - bash - '-c' - - |- - #!/bin/bash - echo "Validator post-start hook for cosmoshub-4" - # Add any post-start logic here + - '-e' + - >- + until bash -e /scripts/chain-rpc-ready.sh + http://localhost:26657; do + sleep 10 + done + + + set -eux + + export + + VAL_INDEX=${HOSTNAME##*-} + + VAL_NAME="$(jq -r ".validators[0].name" + $KEYS_CONFIG)-$VAL_INDEX" + + echo "Validator Index: $VAL_INDEX, Key name: $VAL_NAME. + Chain bin $CHAIN_BIN" + + + VAL_ADDR=$($CHAIN_BIN keys show $VAL_NAME -a + --keyring-backend="test") + + echo "Transfer tokens to address $VAL_ADDR before trying to + create validator. Best effort" + + bash -e /scripts/transfer-tokens.sh \ + $VAL_ADDR \ + $DENOM \ + http://$GENESIS_HOST.$NAMESPACE.svc.cluster.local:8000/credit \ + "false" || true + + $CHAIN_BIN keys list --keyring-backend test | jq + + VAL_NAME=$VAL_NAME bash -e /scripts/create-validator.sh readinessProbe: exec: command: @@ -196,6 +352,62 @@ spec: initialDelaySeconds: 10 periodSeconds: 10 timeoutSeconds: 15 + - name: exposer + image: ghcr.io/cosmology-tech/starship/exposer:latest + imagePullPolicy: IfNotPresent + env: + - name: DENOM + value: uatom + - name: COINS + value: 100000000000000uatom + - name: CHAIN_BIN + value: gaiad + - name: CHAIN_DIR + value: /root/.gaia + - name: CODE_REPO + value: https://github.com/cosmos/gaia + - name: DAEMON_HOME + value: /root/.gaia + - name: DAEMON_NAME + value: gaiad + - name: CHAIN_ID + value: cosmoshub-4 + - name: GENESIS_HOST + value: cosmoshub-4-genesis + - name: GENESIS_PORT + value: '8081' + - name: NAMESPACE + valueFrom: + fieldRef: + fieldPath: metadata.namespace + - name: EXPOSER_HTTP_PORT + value: '8081' + - name: EXPOSER_GRPC_PORT + value: '9099' + - name: EXPOSER_GENESIS_FILE + value: /root/.gaia/config/genesis.json + - name: EXPOSER_MNEMONIC_FILE + value: /configs/keys.json + - name: EXPOSER_PRIV_VAL_FILE + value: /root/.gaia/config/priv_validator_key.json + - name: EXPOSER_NODE_KEY_FILE + value: /root/.gaia/config/node_key.json + - name: EXPOSER_PRIV_VAL_STATE_FILE + value: /root/.gaia/data/priv_validator_state.json + command: + - exposer + resources: + limits: + cpu: '0.1' + memory: 128M + requests: + cpu: '0.1' + memory: 128M + volumeMounts: + - mountPath: /root/.gaia + name: node + - mountPath: /configs + name: addresses volumes: - name: node emptyDir: {} diff --git a/packages/packages/generator/__tests__/__output__/builder-tests/multi-chain/osmosis/genesis-statefulset.yaml b/packages/packages/generator/__tests__/__output__/builder-tests/multi-chain/osmosis/genesis-statefulset.yaml index 377f0bfc8..cad6c40d0 100644 --- a/packages/packages/generator/__tests__/__output__/builder-tests/multi-chain/osmosis/genesis-statefulset.yaml +++ b/packages/packages/generator/__tests__/__output__/builder-tests/multi-chain/osmosis/genesis-statefulset.yaml @@ -68,7 +68,44 @@ spec: command: - bash - '-c' - - /scripts/create-genesis.sh + - >- + VAL_INDEX=${HOSTNAME##*-} + + echo "Validator Index: $VAL_INDEX" + + + if [ -f $CHAIN_DIR/config/genesis.json ]; then + echo "Genesis file exists, exiting init container" + exit 0 + fi + + + echo "Running setup genesis script..." + + bash -e /scripts/create-genesis.sh + + bash -e /scripts/update-genesis.sh + + + echo "Create node id json file" + + NODE_ID=$($CHAIN_BIN tendermint show-node-id) + + echo '{"node_id":"'$NODE_ID'"}' > $CHAIN_DIR/config/node_id.json + + + echo "Create consensus key json file" + + $CHAIN_BIN tendermint show-validator > + $CHAIN_DIR/config/consensus_key.json + + cat $CHAIN_DIR/config/consensus_key.json + + + echo "Add custom accounts and balances" + + CHAIN_GENESIS_CMD=$($CHAIN_BIN 2>&1 | grep -q "genesis-related + subcommands" && echo "genesis" || echo "") resources: limits: cpu: '0.5' @@ -110,7 +147,13 @@ spec: command: - bash - '-c' - - /scripts/update-config.sh + - |- + VAL_INDEX=${HOSTNAME##*-} + echo "Validator Index: $VAL_INDEX" + + echo "Running setup config script..." + + bash -e /scripts/update-config.sh resources: limits: cpu: '0.5' @@ -174,8 +217,10 @@ spec: #!/bin/bash set -euo pipefail - echo "Starting osmosisd validator..." - exec osmosisd start --home /root/.osmosisd --log_level info + START_ARGS="" + + + $CHAIN_BIN start $START_ARGS resources: limits: cpu: '0.5' @@ -243,31 +288,66 @@ spec: - mountPath: /configs name: addresses - name: faucet - image: busybox:1.34.1 + image: ghcr.io/cosmology-tech/starship/osmosis:v25.0.0 imagePullPolicy: IfNotPresent env: - name: FAUCET_CONCURRENCY value: '5' - - name: FAUCET_PORT + - name: FAUCET_HTTP_PORT value: '8000' + - name: FAUCET_CHAIN_BINARY + value: osmosisd - name: FAUCET_CHAIN_ID value: osmosis-1 - - name: FAUCET_CHAIN_DENOM - value: uosmo - - name: FAUCET_CHAIN_PREFIX - value: osmo - - name: FAUCET_AMOUNT_SEND - value: '10000000' - - name: FAUCET_AMOUNT_STAKE - value: '10000000' - - name: FAUCET_RPC_ENDPOINT - value: http://localhost:26657 - - name: FAUCET_REST_ENDPOINT - value: http://localhost:1317 + - name: COINS + value: 100000000000000uosmo,100000000000000uion command: - - sh + - bash - '-c' - - /faucet/faucet + - >- + CREDIT_COINS="" + + FEES="" + + for coin in ${COINS//,/ } + + do + amt="${coin//[!0-9]/}" + denom="${coin//[0-9]/}" + + # Calculate the order of magnitude + if [ ${#amt} -gt 18 ]; then + creditAmt=$(echo $amt | sed -e "s/000000$//") + feesAmt=$(echo $amt | sed -e "s/0000000000000$//") + else + creditAmt=$(echo $amt | sed -e "s/0000$//") + feesAmt=$(echo $amt | sed -e "s/00000000$//") + fi + + if [[ $CREDIT_COINS == "" ]] + then + CREDIT_COINS="$creditAmt$denom" + FEES="$feesAmt$denom" + else + CREDIT_COINS="${CREDIT_COINS},$creditAmt$denom" + fi + done + + + export FAUCET_MNEMONIC=$(jq -r ".faucet[0].mnemonic" + /configs/keys.json) + + + export | grep "FAUCET" + + + until bash -e /scripts/chain-rpc-ready.sh http://localhost:26657; + do + sleep 10 + done + + + /faucet/faucet --credit-coins="$CREDIT_COINS" --chain-fees="$FEES" resources: limits: cpu: '0.1' @@ -280,6 +360,14 @@ spec: name: addresses - mountPath: /faucet name: faucet + - mountPath: /scripts + name: scripts + readinessProbe: + httpGet: + path: /status + port: '8000' + initialDelaySeconds: 30 + periodSeconds: 10 volumes: - name: node emptyDir: {} @@ -289,3 +377,5 @@ spec: - name: scripts configMap: name: setup-scripts-osmosis-1 + - name: faucet + emptyDir: {} diff --git a/packages/packages/generator/__tests__/__output__/builder-tests/multi-chain/osmosis/setup-scripts-configmap.yaml b/packages/packages/generator/__tests__/__output__/builder-tests/multi-chain/osmosis/setup-scripts-configmap.yaml index 770edb52d..0f3d10fee 100644 --- a/packages/packages/generator/__tests__/__output__/builder-tests/multi-chain/osmosis/setup-scripts-configmap.yaml +++ b/packages/packages/generator/__tests__/__output__/builder-tests/multi-chain/osmosis/setup-scripts-configmap.yaml @@ -10,6 +10,8 @@ metadata: app.kubernetes.io/name: osmosis app.kubernetes.io/part-of: osmosis-1 app.kubernetes.io/role: setup-scripts + starship.io/chain-name: osmosis + starship.io/chain-id: osmosis-1 data: create-genesis.sh: > #!/bin/bash diff --git a/packages/packages/generator/__tests__/__output__/builder-tests/multi-chain/osmosis/validator-statefulset.yaml b/packages/packages/generator/__tests__/__output__/builder-tests/multi-chain/osmosis/validator-statefulset.yaml index 623026aa6..8f58c8f76 100644 --- a/packages/packages/generator/__tests__/__output__/builder-tests/multi-chain/osmosis/validator-statefulset.yaml +++ b/packages/packages/generator/__tests__/__output__/builder-tests/multi-chain/osmosis/validator-statefulset.yaml @@ -9,7 +9,7 @@ metadata: app.kubernetes.io/component: chain app.kubernetes.io/part-of: osmosis-1 app.kubernetes.io/id: osmosis-1 - app.kubernetes.io/name: osmosis-1-genesis + app.kubernetes.io/name: osmosis-1-validator app.kubernetes.io/type: osmosis-1-statefulset app.kubernetes.io/role: validator starship.io/chain-name: osmosis @@ -37,6 +37,35 @@ spec: app.kubernetes.io/role: validator spec: initContainers: + - name: wait-for-chains + image: curlimages/curl:latest + imagePullPolicy: IfNotPresent + env: + - name: GENESIS_PORT + value: '8081' + - name: NAMESPACE + valueFrom: + fieldRef: + fieldPath: metadata.namespace + command: + - /bin/sh + - '-c' + - |2- + + while [ $(curl -sw '%{http_code}' http://osmosis-1-genesis.$NAMESPACE.svc.cluster.local:$GENESIS_PORT/node_id -o /dev/null) -ne 200 ]; do + echo "Genesis validator does not seem to be ready for: osmosis-1. Waiting for it to start..." + echo "Checking: http://osmosis-1-genesis.$NAMESPACE.svc.cluster.local:$GENESIS_PORT/node_id" + sleep 10; + done + echo "Ready to start" + exit 0 + resources: + limits: + cpu: '0.1' + memory: 128M + requests: + cpu: '0.1' + memory: 128M - name: init-validator image: ghcr.io/cosmology-tech/starship/osmosis:v25.0.0 imagePullPolicy: IfNotPresent @@ -57,23 +86,63 @@ spec: value: osmosisd - name: CHAIN_ID value: osmosis-1 + - name: GENESIS_HOST + value: osmosis-1-genesis + - name: GENESIS_PORT + value: '8081' + - name: NAMESPACE + valueFrom: + fieldRef: + fieldPath: metadata.namespace - name: KEYS_CONFIG value: /configs/keys.json + - name: FAUCET_ENABLED + value: 'true' + - name: METRICS + value: 'false' command: - bash - '-c' - >- - #!/bin/bash + VAL_INDEX=${HOSTNAME##*-} + + echo "Validator Index: $VAL_INDEX" + + + + if [ -f $CHAIN_DIR/config/genesis.json ]; then + echo "Genesis file exists, exiting early" + exit 0 + fi + + + VAL_NAME=$(jq -r ".validators[0].name" $KEYS_CONFIG)-$VAL_INDEX + + echo "Validator Index: $VAL_INDEX, Key name: $VAL_NAME" + + + echo "Recover validator $VAL_NAME" + + $CHAIN_BIN init $VAL_NAME --chain-id $CHAIN_ID + + jq -r ".validators[0].mnemonic" $KEYS_CONFIG | $CHAIN_BIN keys add + $VAL_NAME --index $VAL_INDEX --recover --keyring-backend="test" + - set -euo pipefail + curl + http://$GENESIS_HOST.$NAMESPACE.svc.cluster.local:$GENESIS_PORT/genesis + -o $CHAIN_DIR/config/genesis.json + echo "Genesis file that we got....." - echo "Initializing validator node for osmosis-1..." + cat $CHAIN_DIR/config/genesis.json - osmosisd init validator-${HOSTNAME##*-} --chain-id osmosis-1 - --home /root/.osmosisd - echo "Validator initialization completed" + echo "Create node id json file" + + NODE_ID=$($CHAIN_BIN tendermint show-node-id) + + echo '{"node_id":"'$NODE_ID'"}' > $CHAIN_DIR/config/node_id.json resources: limits: cpu: '0.5' @@ -88,7 +157,7 @@ spec: name: addresses - mountPath: /scripts name: scripts - - name: init-validator-config + - name: init-config image: ghcr.io/cosmology-tech/starship/osmosis:v25.0.0 imagePullPolicy: IfNotPresent env: @@ -108,6 +177,14 @@ spec: value: osmosisd - name: CHAIN_ID value: osmosis-1 + - name: GENESIS_HOST + value: osmosis-1-genesis + - name: GENESIS_PORT + value: '8081' + - name: NAMESPACE + valueFrom: + fieldRef: + fieldPath: metadata.namespace - name: KEYS_CONFIG value: /configs/keys.json - name: METRICS @@ -115,7 +192,42 @@ spec: command: - bash - '-c' - - /scripts/update-config.sh + - >- + VAL_INDEX=${HOSTNAME##*-} + + echo "Validator Index: $VAL_INDEX" + + + + echo "Running setup config script..." + + bash -e /scripts/update-config.sh + + + curl -s + http://$GENESIS_HOST.$NAMESPACE.svc.cluster.local:$GENESIS_PORT/node_id + + NODE_ID=$(curl -s + http://$GENESIS_HOST.$NAMESPACE.svc.cluster.local:$GENESIS_PORT/node_id + | jq -r ".node_id") + + if [[ $NODE_ID == "" ]]; then + echo "Node ID is null, exiting early" + exit 1 + fi + + + GENESIS_NODE_P2P=$NODE_ID@$GENESIS_HOST.$NAMESPACE.svc.cluster.local:26656 + + echo "Node P2P: $GENESIS_NODE_P2P" + + sed -i "s/persistent_peers = \"\"/persistent_peers = + \"$GENESIS_NODE_P2P\"/g" $CHAIN_DIR/config/config.toml + + + echo "Printing the whole config.toml file" + + cat $CHAIN_DIR/config/config.toml resources: limits: cpu: '0.5' @@ -151,17 +263,29 @@ spec: value: osmosisd - name: CHAIN_ID value: osmosis-1 + - name: GENESIS_HOST + value: osmosis-1-genesis + - name: GENESIS_PORT + value: '8081' + - name: NAMESPACE + valueFrom: + fieldRef: + fieldPath: metadata.namespace + - name: KEYS_CONFIG + value: /configs/keys.json - name: SLOGFILE value: slog.slog command: - bash - '-c' - |- - #!/bin/bash - set -euo pipefail + set -eux + START_ARGS="" - echo "Starting osmosisd validator..." - exec osmosisd start --home /root/.osmosisd --log_level info + + # Starting the chain + + $CHAIN_BIN start $START_ARGS resources: limits: cpu: '0.5' @@ -182,10 +306,42 @@ spec: command: - bash - '-c' - - |- - #!/bin/bash - echo "Validator post-start hook for osmosis-1" - # Add any post-start logic here + - '-e' + - >- + until bash -e /scripts/chain-rpc-ready.sh + http://localhost:26657; do + sleep 10 + done + + + set -eux + + export + + VAL_INDEX=${HOSTNAME##*-} + + VAL_NAME="$(jq -r ".validators[0].name" + $KEYS_CONFIG)-$VAL_INDEX" + + echo "Validator Index: $VAL_INDEX, Key name: $VAL_NAME. + Chain bin $CHAIN_BIN" + + + VAL_ADDR=$($CHAIN_BIN keys show $VAL_NAME -a + --keyring-backend="test") + + echo "Transfer tokens to address $VAL_ADDR before trying to + create validator. Best effort" + + bash -e /scripts/transfer-tokens.sh \ + $VAL_ADDR \ + $DENOM \ + http://$GENESIS_HOST.$NAMESPACE.svc.cluster.local:8000/credit \ + "true" || true + + $CHAIN_BIN keys list --keyring-backend test | jq + + VAL_NAME=$VAL_NAME bash -e /scripts/create-validator.sh readinessProbe: exec: command: @@ -196,6 +352,62 @@ spec: initialDelaySeconds: 10 periodSeconds: 10 timeoutSeconds: 15 + - name: exposer + image: ghcr.io/cosmology-tech/starship/exposer:latest + imagePullPolicy: IfNotPresent + env: + - name: DENOM + value: uosmo + - name: COINS + value: 100000000000000uosmo,100000000000000uion + - name: CHAIN_BIN + value: osmosisd + - name: CHAIN_DIR + value: /root/.osmosisd + - name: CODE_REPO + value: https://github.com/osmosis-labs/osmosis + - name: DAEMON_HOME + value: /root/.osmosisd + - name: DAEMON_NAME + value: osmosisd + - name: CHAIN_ID + value: osmosis-1 + - name: GENESIS_HOST + value: osmosis-1-genesis + - name: GENESIS_PORT + value: '8081' + - name: NAMESPACE + valueFrom: + fieldRef: + fieldPath: metadata.namespace + - name: EXPOSER_HTTP_PORT + value: '8081' + - name: EXPOSER_GRPC_PORT + value: '9099' + - name: EXPOSER_GENESIS_FILE + value: /root/.osmosisd/config/genesis.json + - name: EXPOSER_MNEMONIC_FILE + value: /configs/keys.json + - name: EXPOSER_PRIV_VAL_FILE + value: /root/.osmosisd/config/priv_validator_key.json + - name: EXPOSER_NODE_KEY_FILE + value: /root/.osmosisd/config/node_key.json + - name: EXPOSER_PRIV_VAL_STATE_FILE + value: /root/.osmosisd/data/priv_validator_state.json + command: + - exposer + resources: + limits: + cpu: '0.1' + memory: 128M + requests: + cpu: '0.1' + memory: 128M + volumeMounts: + - mountPath: /root/.osmosisd + name: node + - mountPath: /configs + name: addresses volumes: - name: node emptyDir: {} @@ -205,3 +417,5 @@ spec: - name: scripts configMap: name: setup-scripts-osmosis-1 + - name: faucet + emptyDir: {} diff --git a/packages/packages/generator/__tests__/__output__/builder-tests/organization-validation/cosmoshub/genesis-statefulset.yaml b/packages/packages/generator/__tests__/__output__/builder-tests/organization-validation/cosmoshub/genesis-statefulset.yaml index 9faa6ae15..46d80e179 100644 --- a/packages/packages/generator/__tests__/__output__/builder-tests/organization-validation/cosmoshub/genesis-statefulset.yaml +++ b/packages/packages/generator/__tests__/__output__/builder-tests/organization-validation/cosmoshub/genesis-statefulset.yaml @@ -68,7 +68,44 @@ spec: command: - bash - '-c' - - /scripts/create-genesis.sh + - >- + VAL_INDEX=${HOSTNAME##*-} + + echo "Validator Index: $VAL_INDEX" + + + if [ -f $CHAIN_DIR/config/genesis.json ]; then + echo "Genesis file exists, exiting init container" + exit 0 + fi + + + echo "Running setup genesis script..." + + bash -e /scripts/create-genesis.sh + + bash -e /scripts/update-genesis.sh + + + echo "Create node id json file" + + NODE_ID=$($CHAIN_BIN tendermint show-node-id) + + echo '{"node_id":"'$NODE_ID'"}' > $CHAIN_DIR/config/node_id.json + + + echo "Create consensus key json file" + + $CHAIN_BIN tendermint show-validator > + $CHAIN_DIR/config/consensus_key.json + + cat $CHAIN_DIR/config/consensus_key.json + + + echo "Add custom accounts and balances" + + CHAIN_GENESIS_CMD=$($CHAIN_BIN 2>&1 | grep -q "genesis-related + subcommands" && echo "genesis" || echo "") resources: limits: cpu: '0.5' @@ -110,7 +147,13 @@ spec: command: - bash - '-c' - - /scripts/update-config.sh + - |- + VAL_INDEX=${HOSTNAME##*-} + echo "Validator Index: $VAL_INDEX" + + echo "Running setup config script..." + + bash -e /scripts/update-config.sh resources: limits: cpu: '0.5' @@ -157,8 +200,10 @@ spec: #!/bin/bash set -euo pipefail - echo "Starting gaiad validator..." - exec gaiad start --home /root/.gaia --log_level info + START_ARGS="" + + + $CHAIN_BIN start $START_ARGS resources: limits: cpu: '0.5' diff --git a/packages/packages/generator/__tests__/__output__/builder-tests/organization-validation/cosmoshub/setup-scripts-configmap.yaml b/packages/packages/generator/__tests__/__output__/builder-tests/organization-validation/cosmoshub/setup-scripts-configmap.yaml index 4ea5e61f9..0fa5e316a 100644 --- a/packages/packages/generator/__tests__/__output__/builder-tests/organization-validation/cosmoshub/setup-scripts-configmap.yaml +++ b/packages/packages/generator/__tests__/__output__/builder-tests/organization-validation/cosmoshub/setup-scripts-configmap.yaml @@ -10,6 +10,8 @@ metadata: app.kubernetes.io/name: cosmoshub app.kubernetes.io/part-of: cosmoshub-4 app.kubernetes.io/role: setup-scripts + starship.io/chain-name: cosmoshub + starship.io/chain-id: cosmoshub-4 data: create-genesis.sh: > #!/bin/bash diff --git a/packages/packages/generator/__tests__/__output__/builder-tests/organization-validation/cosmoshub/validator-statefulset.yaml b/packages/packages/generator/__tests__/__output__/builder-tests/organization-validation/cosmoshub/validator-statefulset.yaml index eba7a5c53..426a6f37b 100644 --- a/packages/packages/generator/__tests__/__output__/builder-tests/organization-validation/cosmoshub/validator-statefulset.yaml +++ b/packages/packages/generator/__tests__/__output__/builder-tests/organization-validation/cosmoshub/validator-statefulset.yaml @@ -9,7 +9,7 @@ metadata: app.kubernetes.io/component: chain app.kubernetes.io/part-of: cosmoshub-4 app.kubernetes.io/id: cosmoshub-4 - app.kubernetes.io/name: cosmoshub-4-genesis + app.kubernetes.io/name: cosmoshub-4-validator app.kubernetes.io/type: cosmoshub-4-statefulset app.kubernetes.io/role: validator starship.io/chain-name: cosmoshub @@ -37,6 +37,35 @@ spec: app.kubernetes.io/role: validator spec: initContainers: + - name: wait-for-chains + image: curlimages/curl:latest + imagePullPolicy: IfNotPresent + env: + - name: GENESIS_PORT + value: '8081' + - name: NAMESPACE + valueFrom: + fieldRef: + fieldPath: metadata.namespace + command: + - /bin/sh + - '-c' + - |2- + + while [ $(curl -sw '%{http_code}' http://cosmoshub-4-genesis.$NAMESPACE.svc.cluster.local:$GENESIS_PORT/node_id -o /dev/null) -ne 200 ]; do + echo "Genesis validator does not seem to be ready for: cosmoshub-4. Waiting for it to start..." + echo "Checking: http://cosmoshub-4-genesis.$NAMESPACE.svc.cluster.local:$GENESIS_PORT/node_id" + sleep 10; + done + echo "Ready to start" + exit 0 + resources: + limits: + cpu: '0.1' + memory: 128M + requests: + cpu: '0.1' + memory: 128M - name: init-validator image: ghcr.io/cosmology-tech/starship/gaia:v18.0.0 imagePullPolicy: IfNotPresent @@ -57,23 +86,63 @@ spec: value: gaiad - name: CHAIN_ID value: cosmoshub-4 + - name: GENESIS_HOST + value: cosmoshub-4-genesis + - name: GENESIS_PORT + value: '8081' + - name: NAMESPACE + valueFrom: + fieldRef: + fieldPath: metadata.namespace - name: KEYS_CONFIG value: /configs/keys.json + - name: FAUCET_ENABLED + value: 'false' + - name: METRICS + value: 'false' command: - bash - '-c' - >- - #!/bin/bash + VAL_INDEX=${HOSTNAME##*-} + + echo "Validator Index: $VAL_INDEX" + + + + if [ -f $CHAIN_DIR/config/genesis.json ]; then + echo "Genesis file exists, exiting early" + exit 0 + fi + + + VAL_NAME=$(jq -r ".validators[0].name" $KEYS_CONFIG)-$VAL_INDEX + + echo "Validator Index: $VAL_INDEX, Key name: $VAL_NAME" + + + echo "Recover validator $VAL_NAME" + + $CHAIN_BIN init $VAL_NAME --chain-id $CHAIN_ID + + jq -r ".validators[0].mnemonic" $KEYS_CONFIG | $CHAIN_BIN keys add + $VAL_NAME --index $VAL_INDEX --recover --keyring-backend="test" - set -euo pipefail + curl + http://$GENESIS_HOST.$NAMESPACE.svc.cluster.local:$GENESIS_PORT/genesis + -o $CHAIN_DIR/config/genesis.json - echo "Initializing validator node for cosmoshub-4..." + echo "Genesis file that we got....." - gaiad init validator-${HOSTNAME##*-} --chain-id cosmoshub-4 --home - /root/.gaia + cat $CHAIN_DIR/config/genesis.json - echo "Validator initialization completed" + + echo "Create node id json file" + + NODE_ID=$($CHAIN_BIN tendermint show-node-id) + + echo '{"node_id":"'$NODE_ID'"}' > $CHAIN_DIR/config/node_id.json resources: limits: cpu: '0.5' @@ -88,7 +157,7 @@ spec: name: addresses - mountPath: /scripts name: scripts - - name: init-validator-config + - name: init-config image: ghcr.io/cosmology-tech/starship/gaia:v18.0.0 imagePullPolicy: IfNotPresent env: @@ -108,6 +177,14 @@ spec: value: gaiad - name: CHAIN_ID value: cosmoshub-4 + - name: GENESIS_HOST + value: cosmoshub-4-genesis + - name: GENESIS_PORT + value: '8081' + - name: NAMESPACE + valueFrom: + fieldRef: + fieldPath: metadata.namespace - name: KEYS_CONFIG value: /configs/keys.json - name: METRICS @@ -115,7 +192,42 @@ spec: command: - bash - '-c' - - /scripts/update-config.sh + - >- + VAL_INDEX=${HOSTNAME##*-} + + echo "Validator Index: $VAL_INDEX" + + + + echo "Running setup config script..." + + bash -e /scripts/update-config.sh + + + curl -s + http://$GENESIS_HOST.$NAMESPACE.svc.cluster.local:$GENESIS_PORT/node_id + + NODE_ID=$(curl -s + http://$GENESIS_HOST.$NAMESPACE.svc.cluster.local:$GENESIS_PORT/node_id + | jq -r ".node_id") + + if [[ $NODE_ID == "" ]]; then + echo "Node ID is null, exiting early" + exit 1 + fi + + + GENESIS_NODE_P2P=$NODE_ID@$GENESIS_HOST.$NAMESPACE.svc.cluster.local:26656 + + echo "Node P2P: $GENESIS_NODE_P2P" + + sed -i "s/persistent_peers = \"\"/persistent_peers = + \"$GENESIS_NODE_P2P\"/g" $CHAIN_DIR/config/config.toml + + + echo "Printing the whole config.toml file" + + cat $CHAIN_DIR/config/config.toml resources: limits: cpu: '0.5' @@ -151,17 +263,29 @@ spec: value: gaiad - name: CHAIN_ID value: cosmoshub-4 + - name: GENESIS_HOST + value: cosmoshub-4-genesis + - name: GENESIS_PORT + value: '8081' + - name: NAMESPACE + valueFrom: + fieldRef: + fieldPath: metadata.namespace + - name: KEYS_CONFIG + value: /configs/keys.json - name: SLOGFILE value: slog.slog command: - bash - '-c' - |- - #!/bin/bash - set -euo pipefail + set -eux + START_ARGS="" + + + # Starting the chain - echo "Starting gaiad validator..." - exec gaiad start --home /root/.gaia --log_level info + $CHAIN_BIN start $START_ARGS resources: limits: cpu: '0.5' @@ -182,10 +306,42 @@ spec: command: - bash - '-c' - - |- - #!/bin/bash - echo "Validator post-start hook for cosmoshub-4" - # Add any post-start logic here + - '-e' + - >- + until bash -e /scripts/chain-rpc-ready.sh + http://localhost:26657; do + sleep 10 + done + + + set -eux + + export + + VAL_INDEX=${HOSTNAME##*-} + + VAL_NAME="$(jq -r ".validators[0].name" + $KEYS_CONFIG)-$VAL_INDEX" + + echo "Validator Index: $VAL_INDEX, Key name: $VAL_NAME. + Chain bin $CHAIN_BIN" + + + VAL_ADDR=$($CHAIN_BIN keys show $VAL_NAME -a + --keyring-backend="test") + + echo "Transfer tokens to address $VAL_ADDR before trying to + create validator. Best effort" + + bash -e /scripts/transfer-tokens.sh \ + $VAL_ADDR \ + $DENOM \ + http://$GENESIS_HOST.$NAMESPACE.svc.cluster.local:8000/credit \ + "false" || true + + $CHAIN_BIN keys list --keyring-backend test | jq + + VAL_NAME=$VAL_NAME bash -e /scripts/create-validator.sh readinessProbe: exec: command: @@ -196,6 +352,62 @@ spec: initialDelaySeconds: 10 periodSeconds: 10 timeoutSeconds: 15 + - name: exposer + image: ghcr.io/cosmology-tech/starship/exposer:latest + imagePullPolicy: IfNotPresent + env: + - name: DENOM + value: uatom + - name: COINS + value: 100000000000000uatom + - name: CHAIN_BIN + value: gaiad + - name: CHAIN_DIR + value: /root/.gaia + - name: CODE_REPO + value: https://github.com/cosmos/gaia + - name: DAEMON_HOME + value: /root/.gaia + - name: DAEMON_NAME + value: gaiad + - name: CHAIN_ID + value: cosmoshub-4 + - name: GENESIS_HOST + value: cosmoshub-4-genesis + - name: GENESIS_PORT + value: '8081' + - name: NAMESPACE + valueFrom: + fieldRef: + fieldPath: metadata.namespace + - name: EXPOSER_HTTP_PORT + value: '8081' + - name: EXPOSER_GRPC_PORT + value: '9099' + - name: EXPOSER_GENESIS_FILE + value: /root/.gaia/config/genesis.json + - name: EXPOSER_MNEMONIC_FILE + value: /configs/keys.json + - name: EXPOSER_PRIV_VAL_FILE + value: /root/.gaia/config/priv_validator_key.json + - name: EXPOSER_NODE_KEY_FILE + value: /root/.gaia/config/node_key.json + - name: EXPOSER_PRIV_VAL_STATE_FILE + value: /root/.gaia/data/priv_validator_state.json + command: + - exposer + resources: + limits: + cpu: '0.1' + memory: 128M + requests: + cpu: '0.1' + memory: 128M + volumeMounts: + - mountPath: /root/.gaia + name: node + - mountPath: /configs + name: addresses volumes: - name: node emptyDir: {} diff --git a/packages/packages/generator/__tests__/__output__/builder-tests/organization-validation/osmosis/genesis-statefulset.yaml b/packages/packages/generator/__tests__/__output__/builder-tests/organization-validation/osmosis/genesis-statefulset.yaml index 377f0bfc8..cad6c40d0 100644 --- a/packages/packages/generator/__tests__/__output__/builder-tests/organization-validation/osmosis/genesis-statefulset.yaml +++ b/packages/packages/generator/__tests__/__output__/builder-tests/organization-validation/osmosis/genesis-statefulset.yaml @@ -68,7 +68,44 @@ spec: command: - bash - '-c' - - /scripts/create-genesis.sh + - >- + VAL_INDEX=${HOSTNAME##*-} + + echo "Validator Index: $VAL_INDEX" + + + if [ -f $CHAIN_DIR/config/genesis.json ]; then + echo "Genesis file exists, exiting init container" + exit 0 + fi + + + echo "Running setup genesis script..." + + bash -e /scripts/create-genesis.sh + + bash -e /scripts/update-genesis.sh + + + echo "Create node id json file" + + NODE_ID=$($CHAIN_BIN tendermint show-node-id) + + echo '{"node_id":"'$NODE_ID'"}' > $CHAIN_DIR/config/node_id.json + + + echo "Create consensus key json file" + + $CHAIN_BIN tendermint show-validator > + $CHAIN_DIR/config/consensus_key.json + + cat $CHAIN_DIR/config/consensus_key.json + + + echo "Add custom accounts and balances" + + CHAIN_GENESIS_CMD=$($CHAIN_BIN 2>&1 | grep -q "genesis-related + subcommands" && echo "genesis" || echo "") resources: limits: cpu: '0.5' @@ -110,7 +147,13 @@ spec: command: - bash - '-c' - - /scripts/update-config.sh + - |- + VAL_INDEX=${HOSTNAME##*-} + echo "Validator Index: $VAL_INDEX" + + echo "Running setup config script..." + + bash -e /scripts/update-config.sh resources: limits: cpu: '0.5' @@ -174,8 +217,10 @@ spec: #!/bin/bash set -euo pipefail - echo "Starting osmosisd validator..." - exec osmosisd start --home /root/.osmosisd --log_level info + START_ARGS="" + + + $CHAIN_BIN start $START_ARGS resources: limits: cpu: '0.5' @@ -243,31 +288,66 @@ spec: - mountPath: /configs name: addresses - name: faucet - image: busybox:1.34.1 + image: ghcr.io/cosmology-tech/starship/osmosis:v25.0.0 imagePullPolicy: IfNotPresent env: - name: FAUCET_CONCURRENCY value: '5' - - name: FAUCET_PORT + - name: FAUCET_HTTP_PORT value: '8000' + - name: FAUCET_CHAIN_BINARY + value: osmosisd - name: FAUCET_CHAIN_ID value: osmosis-1 - - name: FAUCET_CHAIN_DENOM - value: uosmo - - name: FAUCET_CHAIN_PREFIX - value: osmo - - name: FAUCET_AMOUNT_SEND - value: '10000000' - - name: FAUCET_AMOUNT_STAKE - value: '10000000' - - name: FAUCET_RPC_ENDPOINT - value: http://localhost:26657 - - name: FAUCET_REST_ENDPOINT - value: http://localhost:1317 + - name: COINS + value: 100000000000000uosmo,100000000000000uion command: - - sh + - bash - '-c' - - /faucet/faucet + - >- + CREDIT_COINS="" + + FEES="" + + for coin in ${COINS//,/ } + + do + amt="${coin//[!0-9]/}" + denom="${coin//[0-9]/}" + + # Calculate the order of magnitude + if [ ${#amt} -gt 18 ]; then + creditAmt=$(echo $amt | sed -e "s/000000$//") + feesAmt=$(echo $amt | sed -e "s/0000000000000$//") + else + creditAmt=$(echo $amt | sed -e "s/0000$//") + feesAmt=$(echo $amt | sed -e "s/00000000$//") + fi + + if [[ $CREDIT_COINS == "" ]] + then + CREDIT_COINS="$creditAmt$denom" + FEES="$feesAmt$denom" + else + CREDIT_COINS="${CREDIT_COINS},$creditAmt$denom" + fi + done + + + export FAUCET_MNEMONIC=$(jq -r ".faucet[0].mnemonic" + /configs/keys.json) + + + export | grep "FAUCET" + + + until bash -e /scripts/chain-rpc-ready.sh http://localhost:26657; + do + sleep 10 + done + + + /faucet/faucet --credit-coins="$CREDIT_COINS" --chain-fees="$FEES" resources: limits: cpu: '0.1' @@ -280,6 +360,14 @@ spec: name: addresses - mountPath: /faucet name: faucet + - mountPath: /scripts + name: scripts + readinessProbe: + httpGet: + path: /status + port: '8000' + initialDelaySeconds: 30 + periodSeconds: 10 volumes: - name: node emptyDir: {} @@ -289,3 +377,5 @@ spec: - name: scripts configMap: name: setup-scripts-osmosis-1 + - name: faucet + emptyDir: {} diff --git a/packages/packages/generator/__tests__/__output__/builder-tests/organization-validation/osmosis/setup-scripts-configmap.yaml b/packages/packages/generator/__tests__/__output__/builder-tests/organization-validation/osmosis/setup-scripts-configmap.yaml index 770edb52d..0f3d10fee 100644 --- a/packages/packages/generator/__tests__/__output__/builder-tests/organization-validation/osmosis/setup-scripts-configmap.yaml +++ b/packages/packages/generator/__tests__/__output__/builder-tests/organization-validation/osmosis/setup-scripts-configmap.yaml @@ -10,6 +10,8 @@ metadata: app.kubernetes.io/name: osmosis app.kubernetes.io/part-of: osmosis-1 app.kubernetes.io/role: setup-scripts + starship.io/chain-name: osmosis + starship.io/chain-id: osmosis-1 data: create-genesis.sh: > #!/bin/bash diff --git a/packages/packages/generator/__tests__/__output__/builder-tests/organization-validation/osmosis/validator-statefulset.yaml b/packages/packages/generator/__tests__/__output__/builder-tests/organization-validation/osmosis/validator-statefulset.yaml index 623026aa6..8f58c8f76 100644 --- a/packages/packages/generator/__tests__/__output__/builder-tests/organization-validation/osmosis/validator-statefulset.yaml +++ b/packages/packages/generator/__tests__/__output__/builder-tests/organization-validation/osmosis/validator-statefulset.yaml @@ -9,7 +9,7 @@ metadata: app.kubernetes.io/component: chain app.kubernetes.io/part-of: osmosis-1 app.kubernetes.io/id: osmosis-1 - app.kubernetes.io/name: osmosis-1-genesis + app.kubernetes.io/name: osmosis-1-validator app.kubernetes.io/type: osmosis-1-statefulset app.kubernetes.io/role: validator starship.io/chain-name: osmosis @@ -37,6 +37,35 @@ spec: app.kubernetes.io/role: validator spec: initContainers: + - name: wait-for-chains + image: curlimages/curl:latest + imagePullPolicy: IfNotPresent + env: + - name: GENESIS_PORT + value: '8081' + - name: NAMESPACE + valueFrom: + fieldRef: + fieldPath: metadata.namespace + command: + - /bin/sh + - '-c' + - |2- + + while [ $(curl -sw '%{http_code}' http://osmosis-1-genesis.$NAMESPACE.svc.cluster.local:$GENESIS_PORT/node_id -o /dev/null) -ne 200 ]; do + echo "Genesis validator does not seem to be ready for: osmosis-1. Waiting for it to start..." + echo "Checking: http://osmosis-1-genesis.$NAMESPACE.svc.cluster.local:$GENESIS_PORT/node_id" + sleep 10; + done + echo "Ready to start" + exit 0 + resources: + limits: + cpu: '0.1' + memory: 128M + requests: + cpu: '0.1' + memory: 128M - name: init-validator image: ghcr.io/cosmology-tech/starship/osmosis:v25.0.0 imagePullPolicy: IfNotPresent @@ -57,23 +86,63 @@ spec: value: osmosisd - name: CHAIN_ID value: osmosis-1 + - name: GENESIS_HOST + value: osmosis-1-genesis + - name: GENESIS_PORT + value: '8081' + - name: NAMESPACE + valueFrom: + fieldRef: + fieldPath: metadata.namespace - name: KEYS_CONFIG value: /configs/keys.json + - name: FAUCET_ENABLED + value: 'true' + - name: METRICS + value: 'false' command: - bash - '-c' - >- - #!/bin/bash + VAL_INDEX=${HOSTNAME##*-} + + echo "Validator Index: $VAL_INDEX" + + + + if [ -f $CHAIN_DIR/config/genesis.json ]; then + echo "Genesis file exists, exiting early" + exit 0 + fi + + + VAL_NAME=$(jq -r ".validators[0].name" $KEYS_CONFIG)-$VAL_INDEX + + echo "Validator Index: $VAL_INDEX, Key name: $VAL_NAME" + + + echo "Recover validator $VAL_NAME" + + $CHAIN_BIN init $VAL_NAME --chain-id $CHAIN_ID + + jq -r ".validators[0].mnemonic" $KEYS_CONFIG | $CHAIN_BIN keys add + $VAL_NAME --index $VAL_INDEX --recover --keyring-backend="test" + - set -euo pipefail + curl + http://$GENESIS_HOST.$NAMESPACE.svc.cluster.local:$GENESIS_PORT/genesis + -o $CHAIN_DIR/config/genesis.json + echo "Genesis file that we got....." - echo "Initializing validator node for osmosis-1..." + cat $CHAIN_DIR/config/genesis.json - osmosisd init validator-${HOSTNAME##*-} --chain-id osmosis-1 - --home /root/.osmosisd - echo "Validator initialization completed" + echo "Create node id json file" + + NODE_ID=$($CHAIN_BIN tendermint show-node-id) + + echo '{"node_id":"'$NODE_ID'"}' > $CHAIN_DIR/config/node_id.json resources: limits: cpu: '0.5' @@ -88,7 +157,7 @@ spec: name: addresses - mountPath: /scripts name: scripts - - name: init-validator-config + - name: init-config image: ghcr.io/cosmology-tech/starship/osmosis:v25.0.0 imagePullPolicy: IfNotPresent env: @@ -108,6 +177,14 @@ spec: value: osmosisd - name: CHAIN_ID value: osmosis-1 + - name: GENESIS_HOST + value: osmosis-1-genesis + - name: GENESIS_PORT + value: '8081' + - name: NAMESPACE + valueFrom: + fieldRef: + fieldPath: metadata.namespace - name: KEYS_CONFIG value: /configs/keys.json - name: METRICS @@ -115,7 +192,42 @@ spec: command: - bash - '-c' - - /scripts/update-config.sh + - >- + VAL_INDEX=${HOSTNAME##*-} + + echo "Validator Index: $VAL_INDEX" + + + + echo "Running setup config script..." + + bash -e /scripts/update-config.sh + + + curl -s + http://$GENESIS_HOST.$NAMESPACE.svc.cluster.local:$GENESIS_PORT/node_id + + NODE_ID=$(curl -s + http://$GENESIS_HOST.$NAMESPACE.svc.cluster.local:$GENESIS_PORT/node_id + | jq -r ".node_id") + + if [[ $NODE_ID == "" ]]; then + echo "Node ID is null, exiting early" + exit 1 + fi + + + GENESIS_NODE_P2P=$NODE_ID@$GENESIS_HOST.$NAMESPACE.svc.cluster.local:26656 + + echo "Node P2P: $GENESIS_NODE_P2P" + + sed -i "s/persistent_peers = \"\"/persistent_peers = + \"$GENESIS_NODE_P2P\"/g" $CHAIN_DIR/config/config.toml + + + echo "Printing the whole config.toml file" + + cat $CHAIN_DIR/config/config.toml resources: limits: cpu: '0.5' @@ -151,17 +263,29 @@ spec: value: osmosisd - name: CHAIN_ID value: osmosis-1 + - name: GENESIS_HOST + value: osmosis-1-genesis + - name: GENESIS_PORT + value: '8081' + - name: NAMESPACE + valueFrom: + fieldRef: + fieldPath: metadata.namespace + - name: KEYS_CONFIG + value: /configs/keys.json - name: SLOGFILE value: slog.slog command: - bash - '-c' - |- - #!/bin/bash - set -euo pipefail + set -eux + START_ARGS="" - echo "Starting osmosisd validator..." - exec osmosisd start --home /root/.osmosisd --log_level info + + # Starting the chain + + $CHAIN_BIN start $START_ARGS resources: limits: cpu: '0.5' @@ -182,10 +306,42 @@ spec: command: - bash - '-c' - - |- - #!/bin/bash - echo "Validator post-start hook for osmosis-1" - # Add any post-start logic here + - '-e' + - >- + until bash -e /scripts/chain-rpc-ready.sh + http://localhost:26657; do + sleep 10 + done + + + set -eux + + export + + VAL_INDEX=${HOSTNAME##*-} + + VAL_NAME="$(jq -r ".validators[0].name" + $KEYS_CONFIG)-$VAL_INDEX" + + echo "Validator Index: $VAL_INDEX, Key name: $VAL_NAME. + Chain bin $CHAIN_BIN" + + + VAL_ADDR=$($CHAIN_BIN keys show $VAL_NAME -a + --keyring-backend="test") + + echo "Transfer tokens to address $VAL_ADDR before trying to + create validator. Best effort" + + bash -e /scripts/transfer-tokens.sh \ + $VAL_ADDR \ + $DENOM \ + http://$GENESIS_HOST.$NAMESPACE.svc.cluster.local:8000/credit \ + "true" || true + + $CHAIN_BIN keys list --keyring-backend test | jq + + VAL_NAME=$VAL_NAME bash -e /scripts/create-validator.sh readinessProbe: exec: command: @@ -196,6 +352,62 @@ spec: initialDelaySeconds: 10 periodSeconds: 10 timeoutSeconds: 15 + - name: exposer + image: ghcr.io/cosmology-tech/starship/exposer:latest + imagePullPolicy: IfNotPresent + env: + - name: DENOM + value: uosmo + - name: COINS + value: 100000000000000uosmo,100000000000000uion + - name: CHAIN_BIN + value: osmosisd + - name: CHAIN_DIR + value: /root/.osmosisd + - name: CODE_REPO + value: https://github.com/osmosis-labs/osmosis + - name: DAEMON_HOME + value: /root/.osmosisd + - name: DAEMON_NAME + value: osmosisd + - name: CHAIN_ID + value: osmosis-1 + - name: GENESIS_HOST + value: osmosis-1-genesis + - name: GENESIS_PORT + value: '8081' + - name: NAMESPACE + valueFrom: + fieldRef: + fieldPath: metadata.namespace + - name: EXPOSER_HTTP_PORT + value: '8081' + - name: EXPOSER_GRPC_PORT + value: '9099' + - name: EXPOSER_GENESIS_FILE + value: /root/.osmosisd/config/genesis.json + - name: EXPOSER_MNEMONIC_FILE + value: /configs/keys.json + - name: EXPOSER_PRIV_VAL_FILE + value: /root/.osmosisd/config/priv_validator_key.json + - name: EXPOSER_NODE_KEY_FILE + value: /root/.osmosisd/config/node_key.json + - name: EXPOSER_PRIV_VAL_STATE_FILE + value: /root/.osmosisd/data/priv_validator_state.json + command: + - exposer + resources: + limits: + cpu: '0.1' + memory: 128M + requests: + cpu: '0.1' + memory: 128M + volumeMounts: + - mountPath: /root/.osmosisd + name: node + - mountPath: /configs + name: addresses volumes: - name: node emptyDir: {} @@ -205,3 +417,5 @@ spec: - name: scripts configMap: name: setup-scripts-osmosis-1 + - name: faucet + emptyDir: {} diff --git a/packages/packages/generator/__tests__/__output__/builder-tests/relayers/cosmoshub/genesis-statefulset.yaml b/packages/packages/generator/__tests__/__output__/builder-tests/relayers/cosmoshub/genesis-statefulset.yaml index 400c56b61..9ba11eacc 100644 --- a/packages/packages/generator/__tests__/__output__/builder-tests/relayers/cosmoshub/genesis-statefulset.yaml +++ b/packages/packages/generator/__tests__/__output__/builder-tests/relayers/cosmoshub/genesis-statefulset.yaml @@ -68,7 +68,44 @@ spec: command: - bash - '-c' - - /scripts/create-genesis.sh + - >- + VAL_INDEX=${HOSTNAME##*-} + + echo "Validator Index: $VAL_INDEX" + + + if [ -f $CHAIN_DIR/config/genesis.json ]; then + echo "Genesis file exists, exiting init container" + exit 0 + fi + + + echo "Running setup genesis script..." + + bash -e /scripts/create-genesis.sh + + bash -e /scripts/update-genesis.sh + + + echo "Create node id json file" + + NODE_ID=$($CHAIN_BIN tendermint show-node-id) + + echo '{"node_id":"'$NODE_ID'"}' > $CHAIN_DIR/config/node_id.json + + + echo "Create consensus key json file" + + $CHAIN_BIN tendermint show-validator > + $CHAIN_DIR/config/consensus_key.json + + cat $CHAIN_DIR/config/consensus_key.json + + + echo "Add custom accounts and balances" + + CHAIN_GENESIS_CMD=$($CHAIN_BIN 2>&1 | grep -q "genesis-related + subcommands" && echo "genesis" || echo "") resources: limits: cpu: '0.5' @@ -110,7 +147,13 @@ spec: command: - bash - '-c' - - /scripts/update-config.sh + - |- + VAL_INDEX=${HOSTNAME##*-} + echo "Validator Index: $VAL_INDEX" + + echo "Running setup config script..." + + bash -e /scripts/update-config.sh resources: limits: cpu: '0.5' @@ -157,8 +200,10 @@ spec: #!/bin/bash set -euo pipefail - echo "Starting gaiad validator..." - exec gaiad start --home /root/.gaia --log_level info + START_ARGS="" + + + $CHAIN_BIN start $START_ARGS resources: limits: cpu: '0.5' diff --git a/packages/packages/generator/__tests__/__output__/builder-tests/relayers/cosmoshub/setup-scripts-configmap.yaml b/packages/packages/generator/__tests__/__output__/builder-tests/relayers/cosmoshub/setup-scripts-configmap.yaml index 4ea5e61f9..0fa5e316a 100644 --- a/packages/packages/generator/__tests__/__output__/builder-tests/relayers/cosmoshub/setup-scripts-configmap.yaml +++ b/packages/packages/generator/__tests__/__output__/builder-tests/relayers/cosmoshub/setup-scripts-configmap.yaml @@ -10,6 +10,8 @@ metadata: app.kubernetes.io/name: cosmoshub app.kubernetes.io/part-of: cosmoshub-4 app.kubernetes.io/role: setup-scripts + starship.io/chain-name: cosmoshub + starship.io/chain-id: cosmoshub-4 data: create-genesis.sh: > #!/bin/bash diff --git a/packages/packages/generator/__tests__/__output__/builder-tests/relayers/cosmoshub/validator-statefulset.yaml b/packages/packages/generator/__tests__/__output__/builder-tests/relayers/cosmoshub/validator-statefulset.yaml index eba7a5c53..426a6f37b 100644 --- a/packages/packages/generator/__tests__/__output__/builder-tests/relayers/cosmoshub/validator-statefulset.yaml +++ b/packages/packages/generator/__tests__/__output__/builder-tests/relayers/cosmoshub/validator-statefulset.yaml @@ -9,7 +9,7 @@ metadata: app.kubernetes.io/component: chain app.kubernetes.io/part-of: cosmoshub-4 app.kubernetes.io/id: cosmoshub-4 - app.kubernetes.io/name: cosmoshub-4-genesis + app.kubernetes.io/name: cosmoshub-4-validator app.kubernetes.io/type: cosmoshub-4-statefulset app.kubernetes.io/role: validator starship.io/chain-name: cosmoshub @@ -37,6 +37,35 @@ spec: app.kubernetes.io/role: validator spec: initContainers: + - name: wait-for-chains + image: curlimages/curl:latest + imagePullPolicy: IfNotPresent + env: + - name: GENESIS_PORT + value: '8081' + - name: NAMESPACE + valueFrom: + fieldRef: + fieldPath: metadata.namespace + command: + - /bin/sh + - '-c' + - |2- + + while [ $(curl -sw '%{http_code}' http://cosmoshub-4-genesis.$NAMESPACE.svc.cluster.local:$GENESIS_PORT/node_id -o /dev/null) -ne 200 ]; do + echo "Genesis validator does not seem to be ready for: cosmoshub-4. Waiting for it to start..." + echo "Checking: http://cosmoshub-4-genesis.$NAMESPACE.svc.cluster.local:$GENESIS_PORT/node_id" + sleep 10; + done + echo "Ready to start" + exit 0 + resources: + limits: + cpu: '0.1' + memory: 128M + requests: + cpu: '0.1' + memory: 128M - name: init-validator image: ghcr.io/cosmology-tech/starship/gaia:v18.0.0 imagePullPolicy: IfNotPresent @@ -57,23 +86,63 @@ spec: value: gaiad - name: CHAIN_ID value: cosmoshub-4 + - name: GENESIS_HOST + value: cosmoshub-4-genesis + - name: GENESIS_PORT + value: '8081' + - name: NAMESPACE + valueFrom: + fieldRef: + fieldPath: metadata.namespace - name: KEYS_CONFIG value: /configs/keys.json + - name: FAUCET_ENABLED + value: 'false' + - name: METRICS + value: 'false' command: - bash - '-c' - >- - #!/bin/bash + VAL_INDEX=${HOSTNAME##*-} + + echo "Validator Index: $VAL_INDEX" + + + + if [ -f $CHAIN_DIR/config/genesis.json ]; then + echo "Genesis file exists, exiting early" + exit 0 + fi + + + VAL_NAME=$(jq -r ".validators[0].name" $KEYS_CONFIG)-$VAL_INDEX + + echo "Validator Index: $VAL_INDEX, Key name: $VAL_NAME" + + + echo "Recover validator $VAL_NAME" + + $CHAIN_BIN init $VAL_NAME --chain-id $CHAIN_ID + + jq -r ".validators[0].mnemonic" $KEYS_CONFIG | $CHAIN_BIN keys add + $VAL_NAME --index $VAL_INDEX --recover --keyring-backend="test" - set -euo pipefail + curl + http://$GENESIS_HOST.$NAMESPACE.svc.cluster.local:$GENESIS_PORT/genesis + -o $CHAIN_DIR/config/genesis.json - echo "Initializing validator node for cosmoshub-4..." + echo "Genesis file that we got....." - gaiad init validator-${HOSTNAME##*-} --chain-id cosmoshub-4 --home - /root/.gaia + cat $CHAIN_DIR/config/genesis.json - echo "Validator initialization completed" + + echo "Create node id json file" + + NODE_ID=$($CHAIN_BIN tendermint show-node-id) + + echo '{"node_id":"'$NODE_ID'"}' > $CHAIN_DIR/config/node_id.json resources: limits: cpu: '0.5' @@ -88,7 +157,7 @@ spec: name: addresses - mountPath: /scripts name: scripts - - name: init-validator-config + - name: init-config image: ghcr.io/cosmology-tech/starship/gaia:v18.0.0 imagePullPolicy: IfNotPresent env: @@ -108,6 +177,14 @@ spec: value: gaiad - name: CHAIN_ID value: cosmoshub-4 + - name: GENESIS_HOST + value: cosmoshub-4-genesis + - name: GENESIS_PORT + value: '8081' + - name: NAMESPACE + valueFrom: + fieldRef: + fieldPath: metadata.namespace - name: KEYS_CONFIG value: /configs/keys.json - name: METRICS @@ -115,7 +192,42 @@ spec: command: - bash - '-c' - - /scripts/update-config.sh + - >- + VAL_INDEX=${HOSTNAME##*-} + + echo "Validator Index: $VAL_INDEX" + + + + echo "Running setup config script..." + + bash -e /scripts/update-config.sh + + + curl -s + http://$GENESIS_HOST.$NAMESPACE.svc.cluster.local:$GENESIS_PORT/node_id + + NODE_ID=$(curl -s + http://$GENESIS_HOST.$NAMESPACE.svc.cluster.local:$GENESIS_PORT/node_id + | jq -r ".node_id") + + if [[ $NODE_ID == "" ]]; then + echo "Node ID is null, exiting early" + exit 1 + fi + + + GENESIS_NODE_P2P=$NODE_ID@$GENESIS_HOST.$NAMESPACE.svc.cluster.local:26656 + + echo "Node P2P: $GENESIS_NODE_P2P" + + sed -i "s/persistent_peers = \"\"/persistent_peers = + \"$GENESIS_NODE_P2P\"/g" $CHAIN_DIR/config/config.toml + + + echo "Printing the whole config.toml file" + + cat $CHAIN_DIR/config/config.toml resources: limits: cpu: '0.5' @@ -151,17 +263,29 @@ spec: value: gaiad - name: CHAIN_ID value: cosmoshub-4 + - name: GENESIS_HOST + value: cosmoshub-4-genesis + - name: GENESIS_PORT + value: '8081' + - name: NAMESPACE + valueFrom: + fieldRef: + fieldPath: metadata.namespace + - name: KEYS_CONFIG + value: /configs/keys.json - name: SLOGFILE value: slog.slog command: - bash - '-c' - |- - #!/bin/bash - set -euo pipefail + set -eux + START_ARGS="" + + + # Starting the chain - echo "Starting gaiad validator..." - exec gaiad start --home /root/.gaia --log_level info + $CHAIN_BIN start $START_ARGS resources: limits: cpu: '0.5' @@ -182,10 +306,42 @@ spec: command: - bash - '-c' - - |- - #!/bin/bash - echo "Validator post-start hook for cosmoshub-4" - # Add any post-start logic here + - '-e' + - >- + until bash -e /scripts/chain-rpc-ready.sh + http://localhost:26657; do + sleep 10 + done + + + set -eux + + export + + VAL_INDEX=${HOSTNAME##*-} + + VAL_NAME="$(jq -r ".validators[0].name" + $KEYS_CONFIG)-$VAL_INDEX" + + echo "Validator Index: $VAL_INDEX, Key name: $VAL_NAME. + Chain bin $CHAIN_BIN" + + + VAL_ADDR=$($CHAIN_BIN keys show $VAL_NAME -a + --keyring-backend="test") + + echo "Transfer tokens to address $VAL_ADDR before trying to + create validator. Best effort" + + bash -e /scripts/transfer-tokens.sh \ + $VAL_ADDR \ + $DENOM \ + http://$GENESIS_HOST.$NAMESPACE.svc.cluster.local:8000/credit \ + "false" || true + + $CHAIN_BIN keys list --keyring-backend test | jq + + VAL_NAME=$VAL_NAME bash -e /scripts/create-validator.sh readinessProbe: exec: command: @@ -196,6 +352,62 @@ spec: initialDelaySeconds: 10 periodSeconds: 10 timeoutSeconds: 15 + - name: exposer + image: ghcr.io/cosmology-tech/starship/exposer:latest + imagePullPolicy: IfNotPresent + env: + - name: DENOM + value: uatom + - name: COINS + value: 100000000000000uatom + - name: CHAIN_BIN + value: gaiad + - name: CHAIN_DIR + value: /root/.gaia + - name: CODE_REPO + value: https://github.com/cosmos/gaia + - name: DAEMON_HOME + value: /root/.gaia + - name: DAEMON_NAME + value: gaiad + - name: CHAIN_ID + value: cosmoshub-4 + - name: GENESIS_HOST + value: cosmoshub-4-genesis + - name: GENESIS_PORT + value: '8081' + - name: NAMESPACE + valueFrom: + fieldRef: + fieldPath: metadata.namespace + - name: EXPOSER_HTTP_PORT + value: '8081' + - name: EXPOSER_GRPC_PORT + value: '9099' + - name: EXPOSER_GENESIS_FILE + value: /root/.gaia/config/genesis.json + - name: EXPOSER_MNEMONIC_FILE + value: /configs/keys.json + - name: EXPOSER_PRIV_VAL_FILE + value: /root/.gaia/config/priv_validator_key.json + - name: EXPOSER_NODE_KEY_FILE + value: /root/.gaia/config/node_key.json + - name: EXPOSER_PRIV_VAL_STATE_FILE + value: /root/.gaia/data/priv_validator_state.json + command: + - exposer + resources: + limits: + cpu: '0.1' + memory: 128M + requests: + cpu: '0.1' + memory: 128M + volumeMounts: + - mountPath: /root/.gaia + name: node + - mountPath: /configs + name: addresses volumes: - name: node emptyDir: {} diff --git a/packages/packages/generator/__tests__/__output__/builder-tests/relayers/osmosis/genesis-statefulset.yaml b/packages/packages/generator/__tests__/__output__/builder-tests/relayers/osmosis/genesis-statefulset.yaml index 70cd2ace7..7c235ffd0 100644 --- a/packages/packages/generator/__tests__/__output__/builder-tests/relayers/osmosis/genesis-statefulset.yaml +++ b/packages/packages/generator/__tests__/__output__/builder-tests/relayers/osmosis/genesis-statefulset.yaml @@ -68,7 +68,44 @@ spec: command: - bash - '-c' - - /scripts/create-genesis.sh + - >- + VAL_INDEX=${HOSTNAME##*-} + + echo "Validator Index: $VAL_INDEX" + + + if [ -f $CHAIN_DIR/config/genesis.json ]; then + echo "Genesis file exists, exiting init container" + exit 0 + fi + + + echo "Running setup genesis script..." + + bash -e /scripts/create-genesis.sh + + bash -e /scripts/update-genesis.sh + + + echo "Create node id json file" + + NODE_ID=$($CHAIN_BIN tendermint show-node-id) + + echo '{"node_id":"'$NODE_ID'"}' > $CHAIN_DIR/config/node_id.json + + + echo "Create consensus key json file" + + $CHAIN_BIN tendermint show-validator > + $CHAIN_DIR/config/consensus_key.json + + cat $CHAIN_DIR/config/consensus_key.json + + + echo "Add custom accounts and balances" + + CHAIN_GENESIS_CMD=$($CHAIN_BIN 2>&1 | grep -q "genesis-related + subcommands" && echo "genesis" || echo "") resources: limits: cpu: '0.5' @@ -110,7 +147,13 @@ spec: command: - bash - '-c' - - /scripts/update-config.sh + - |- + VAL_INDEX=${HOSTNAME##*-} + echo "Validator Index: $VAL_INDEX" + + echo "Running setup config script..." + + bash -e /scripts/update-config.sh resources: limits: cpu: '0.5' @@ -174,8 +217,10 @@ spec: #!/bin/bash set -euo pipefail - echo "Starting osmosisd validator..." - exec osmosisd start --home /root/.osmosisd --log_level info + START_ARGS="" + + + $CHAIN_BIN start $START_ARGS resources: limits: cpu: '0.5' @@ -243,31 +288,66 @@ spec: - mountPath: /configs name: addresses - name: faucet - image: busybox:1.34.1 + image: ghcr.io/cosmology-tech/starship/osmosis:v25.0.0 imagePullPolicy: IfNotPresent env: - name: FAUCET_CONCURRENCY value: '5' - - name: FAUCET_PORT + - name: FAUCET_HTTP_PORT value: '8000' + - name: FAUCET_CHAIN_BINARY + value: osmosisd - name: FAUCET_CHAIN_ID value: osmosis-1 - - name: FAUCET_CHAIN_DENOM - value: uosmo - - name: FAUCET_CHAIN_PREFIX - value: osmo - - name: FAUCET_AMOUNT_SEND - value: '10000000' - - name: FAUCET_AMOUNT_STAKE - value: '10000000' - - name: FAUCET_RPC_ENDPOINT - value: http://localhost:26657 - - name: FAUCET_REST_ENDPOINT - value: http://localhost:1317 + - name: COINS + value: 100000000000000uosmo,100000000000000uion command: - - sh + - bash - '-c' - - /faucet/faucet + - >- + CREDIT_COINS="" + + FEES="" + + for coin in ${COINS//,/ } + + do + amt="${coin//[!0-9]/}" + denom="${coin//[0-9]/}" + + # Calculate the order of magnitude + if [ ${#amt} -gt 18 ]; then + creditAmt=$(echo $amt | sed -e "s/000000$//") + feesAmt=$(echo $amt | sed -e "s/0000000000000$//") + else + creditAmt=$(echo $amt | sed -e "s/0000$//") + feesAmt=$(echo $amt | sed -e "s/00000000$//") + fi + + if [[ $CREDIT_COINS == "" ]] + then + CREDIT_COINS="$creditAmt$denom" + FEES="$feesAmt$denom" + else + CREDIT_COINS="${CREDIT_COINS},$creditAmt$denom" + fi + done + + + export FAUCET_MNEMONIC=$(jq -r ".faucet[0].mnemonic" + /configs/keys.json) + + + export | grep "FAUCET" + + + until bash -e /scripts/chain-rpc-ready.sh http://localhost:26657; + do + sleep 10 + done + + + /faucet/faucet --credit-coins="$CREDIT_COINS" --chain-fees="$FEES" resources: limits: cpu: '0.1' @@ -280,6 +360,14 @@ spec: name: addresses - mountPath: /faucet name: faucet + - mountPath: /scripts + name: scripts + readinessProbe: + httpGet: + path: /status + port: '8000' + initialDelaySeconds: 30 + periodSeconds: 10 volumes: - name: node emptyDir: {} @@ -289,3 +377,5 @@ spec: - name: scripts configMap: name: setup-scripts-osmosis-1 + - name: faucet + emptyDir: {} diff --git a/packages/packages/generator/__tests__/__output__/builder-tests/relayers/osmosis/setup-scripts-configmap.yaml b/packages/packages/generator/__tests__/__output__/builder-tests/relayers/osmosis/setup-scripts-configmap.yaml index 770edb52d..0f3d10fee 100644 --- a/packages/packages/generator/__tests__/__output__/builder-tests/relayers/osmosis/setup-scripts-configmap.yaml +++ b/packages/packages/generator/__tests__/__output__/builder-tests/relayers/osmosis/setup-scripts-configmap.yaml @@ -10,6 +10,8 @@ metadata: app.kubernetes.io/name: osmosis app.kubernetes.io/part-of: osmosis-1 app.kubernetes.io/role: setup-scripts + starship.io/chain-name: osmosis + starship.io/chain-id: osmosis-1 data: create-genesis.sh: > #!/bin/bash diff --git a/packages/packages/generator/__tests__/__output__/builder-tests/relayers/osmosis/validator-statefulset.yaml b/packages/packages/generator/__tests__/__output__/builder-tests/relayers/osmosis/validator-statefulset.yaml index 623026aa6..8f58c8f76 100644 --- a/packages/packages/generator/__tests__/__output__/builder-tests/relayers/osmosis/validator-statefulset.yaml +++ b/packages/packages/generator/__tests__/__output__/builder-tests/relayers/osmosis/validator-statefulset.yaml @@ -9,7 +9,7 @@ metadata: app.kubernetes.io/component: chain app.kubernetes.io/part-of: osmosis-1 app.kubernetes.io/id: osmosis-1 - app.kubernetes.io/name: osmosis-1-genesis + app.kubernetes.io/name: osmosis-1-validator app.kubernetes.io/type: osmosis-1-statefulset app.kubernetes.io/role: validator starship.io/chain-name: osmosis @@ -37,6 +37,35 @@ spec: app.kubernetes.io/role: validator spec: initContainers: + - name: wait-for-chains + image: curlimages/curl:latest + imagePullPolicy: IfNotPresent + env: + - name: GENESIS_PORT + value: '8081' + - name: NAMESPACE + valueFrom: + fieldRef: + fieldPath: metadata.namespace + command: + - /bin/sh + - '-c' + - |2- + + while [ $(curl -sw '%{http_code}' http://osmosis-1-genesis.$NAMESPACE.svc.cluster.local:$GENESIS_PORT/node_id -o /dev/null) -ne 200 ]; do + echo "Genesis validator does not seem to be ready for: osmosis-1. Waiting for it to start..." + echo "Checking: http://osmosis-1-genesis.$NAMESPACE.svc.cluster.local:$GENESIS_PORT/node_id" + sleep 10; + done + echo "Ready to start" + exit 0 + resources: + limits: + cpu: '0.1' + memory: 128M + requests: + cpu: '0.1' + memory: 128M - name: init-validator image: ghcr.io/cosmology-tech/starship/osmosis:v25.0.0 imagePullPolicy: IfNotPresent @@ -57,23 +86,63 @@ spec: value: osmosisd - name: CHAIN_ID value: osmosis-1 + - name: GENESIS_HOST + value: osmosis-1-genesis + - name: GENESIS_PORT + value: '8081' + - name: NAMESPACE + valueFrom: + fieldRef: + fieldPath: metadata.namespace - name: KEYS_CONFIG value: /configs/keys.json + - name: FAUCET_ENABLED + value: 'true' + - name: METRICS + value: 'false' command: - bash - '-c' - >- - #!/bin/bash + VAL_INDEX=${HOSTNAME##*-} + + echo "Validator Index: $VAL_INDEX" + + + + if [ -f $CHAIN_DIR/config/genesis.json ]; then + echo "Genesis file exists, exiting early" + exit 0 + fi + + + VAL_NAME=$(jq -r ".validators[0].name" $KEYS_CONFIG)-$VAL_INDEX + + echo "Validator Index: $VAL_INDEX, Key name: $VAL_NAME" + + + echo "Recover validator $VAL_NAME" + + $CHAIN_BIN init $VAL_NAME --chain-id $CHAIN_ID + + jq -r ".validators[0].mnemonic" $KEYS_CONFIG | $CHAIN_BIN keys add + $VAL_NAME --index $VAL_INDEX --recover --keyring-backend="test" + - set -euo pipefail + curl + http://$GENESIS_HOST.$NAMESPACE.svc.cluster.local:$GENESIS_PORT/genesis + -o $CHAIN_DIR/config/genesis.json + echo "Genesis file that we got....." - echo "Initializing validator node for osmosis-1..." + cat $CHAIN_DIR/config/genesis.json - osmosisd init validator-${HOSTNAME##*-} --chain-id osmosis-1 - --home /root/.osmosisd - echo "Validator initialization completed" + echo "Create node id json file" + + NODE_ID=$($CHAIN_BIN tendermint show-node-id) + + echo '{"node_id":"'$NODE_ID'"}' > $CHAIN_DIR/config/node_id.json resources: limits: cpu: '0.5' @@ -88,7 +157,7 @@ spec: name: addresses - mountPath: /scripts name: scripts - - name: init-validator-config + - name: init-config image: ghcr.io/cosmology-tech/starship/osmosis:v25.0.0 imagePullPolicy: IfNotPresent env: @@ -108,6 +177,14 @@ spec: value: osmosisd - name: CHAIN_ID value: osmosis-1 + - name: GENESIS_HOST + value: osmosis-1-genesis + - name: GENESIS_PORT + value: '8081' + - name: NAMESPACE + valueFrom: + fieldRef: + fieldPath: metadata.namespace - name: KEYS_CONFIG value: /configs/keys.json - name: METRICS @@ -115,7 +192,42 @@ spec: command: - bash - '-c' - - /scripts/update-config.sh + - >- + VAL_INDEX=${HOSTNAME##*-} + + echo "Validator Index: $VAL_INDEX" + + + + echo "Running setup config script..." + + bash -e /scripts/update-config.sh + + + curl -s + http://$GENESIS_HOST.$NAMESPACE.svc.cluster.local:$GENESIS_PORT/node_id + + NODE_ID=$(curl -s + http://$GENESIS_HOST.$NAMESPACE.svc.cluster.local:$GENESIS_PORT/node_id + | jq -r ".node_id") + + if [[ $NODE_ID == "" ]]; then + echo "Node ID is null, exiting early" + exit 1 + fi + + + GENESIS_NODE_P2P=$NODE_ID@$GENESIS_HOST.$NAMESPACE.svc.cluster.local:26656 + + echo "Node P2P: $GENESIS_NODE_P2P" + + sed -i "s/persistent_peers = \"\"/persistent_peers = + \"$GENESIS_NODE_P2P\"/g" $CHAIN_DIR/config/config.toml + + + echo "Printing the whole config.toml file" + + cat $CHAIN_DIR/config/config.toml resources: limits: cpu: '0.5' @@ -151,17 +263,29 @@ spec: value: osmosisd - name: CHAIN_ID value: osmosis-1 + - name: GENESIS_HOST + value: osmosis-1-genesis + - name: GENESIS_PORT + value: '8081' + - name: NAMESPACE + valueFrom: + fieldRef: + fieldPath: metadata.namespace + - name: KEYS_CONFIG + value: /configs/keys.json - name: SLOGFILE value: slog.slog command: - bash - '-c' - |- - #!/bin/bash - set -euo pipefail + set -eux + START_ARGS="" - echo "Starting osmosisd validator..." - exec osmosisd start --home /root/.osmosisd --log_level info + + # Starting the chain + + $CHAIN_BIN start $START_ARGS resources: limits: cpu: '0.5' @@ -182,10 +306,42 @@ spec: command: - bash - '-c' - - |- - #!/bin/bash - echo "Validator post-start hook for osmosis-1" - # Add any post-start logic here + - '-e' + - >- + until bash -e /scripts/chain-rpc-ready.sh + http://localhost:26657; do + sleep 10 + done + + + set -eux + + export + + VAL_INDEX=${HOSTNAME##*-} + + VAL_NAME="$(jq -r ".validators[0].name" + $KEYS_CONFIG)-$VAL_INDEX" + + echo "Validator Index: $VAL_INDEX, Key name: $VAL_NAME. + Chain bin $CHAIN_BIN" + + + VAL_ADDR=$($CHAIN_BIN keys show $VAL_NAME -a + --keyring-backend="test") + + echo "Transfer tokens to address $VAL_ADDR before trying to + create validator. Best effort" + + bash -e /scripts/transfer-tokens.sh \ + $VAL_ADDR \ + $DENOM \ + http://$GENESIS_HOST.$NAMESPACE.svc.cluster.local:8000/credit \ + "true" || true + + $CHAIN_BIN keys list --keyring-backend test | jq + + VAL_NAME=$VAL_NAME bash -e /scripts/create-validator.sh readinessProbe: exec: command: @@ -196,6 +352,62 @@ spec: initialDelaySeconds: 10 periodSeconds: 10 timeoutSeconds: 15 + - name: exposer + image: ghcr.io/cosmology-tech/starship/exposer:latest + imagePullPolicy: IfNotPresent + env: + - name: DENOM + value: uosmo + - name: COINS + value: 100000000000000uosmo,100000000000000uion + - name: CHAIN_BIN + value: osmosisd + - name: CHAIN_DIR + value: /root/.osmosisd + - name: CODE_REPO + value: https://github.com/osmosis-labs/osmosis + - name: DAEMON_HOME + value: /root/.osmosisd + - name: DAEMON_NAME + value: osmosisd + - name: CHAIN_ID + value: osmosis-1 + - name: GENESIS_HOST + value: osmosis-1-genesis + - name: GENESIS_PORT + value: '8081' + - name: NAMESPACE + valueFrom: + fieldRef: + fieldPath: metadata.namespace + - name: EXPOSER_HTTP_PORT + value: '8081' + - name: EXPOSER_GRPC_PORT + value: '9099' + - name: EXPOSER_GENESIS_FILE + value: /root/.osmosisd/config/genesis.json + - name: EXPOSER_MNEMONIC_FILE + value: /configs/keys.json + - name: EXPOSER_PRIV_VAL_FILE + value: /root/.osmosisd/config/priv_validator_key.json + - name: EXPOSER_NODE_KEY_FILE + value: /root/.osmosisd/config/node_key.json + - name: EXPOSER_PRIV_VAL_STATE_FILE + value: /root/.osmosisd/data/priv_validator_state.json + command: + - exposer + resources: + limits: + cpu: '0.1' + memory: 128M + requests: + cpu: '0.1' + memory: 128M + volumeMounts: + - mountPath: /root/.osmosisd + name: node + - mountPath: /configs + name: addresses volumes: - name: node emptyDir: {} @@ -205,3 +417,5 @@ spec: - name: scripts configMap: name: setup-scripts-osmosis-1 + - name: faucet + emptyDir: {} diff --git a/packages/packages/generator/__tests__/__output__/builder-tests/single-chain/osmosis/genesis-patch-configmap.yaml b/packages/packages/generator/__tests__/__output__/builder-tests/single-chain/osmosis/genesis-patch-configmap.yaml index 9d9f28269..9f6eabb71 100644 --- a/packages/packages/generator/__tests__/__output__/builder-tests/single-chain/osmosis/genesis-patch-configmap.yaml +++ b/packages/packages/generator/__tests__/__output__/builder-tests/single-chain/osmosis/genesis-patch-configmap.yaml @@ -10,8 +10,10 @@ metadata: app.kubernetes.io/name: osmosis app.kubernetes.io/part-of: osmosis-1 app.kubernetes.io/role: genesis-patch + starship.io/chain-name: osmosis + starship.io/chain-id: osmosis-1 data: - patch.json: |- + genesis.json: |- { "app_state": { "staking": { diff --git a/packages/packages/generator/__tests__/__output__/builder-tests/single-chain/osmosis/genesis-statefulset.yaml b/packages/packages/generator/__tests__/__output__/builder-tests/single-chain/osmosis/genesis-statefulset.yaml index b681e88a9..9f4102b5b 100644 --- a/packages/packages/generator/__tests__/__output__/builder-tests/single-chain/osmosis/genesis-statefulset.yaml +++ b/packages/packages/generator/__tests__/__output__/builder-tests/single-chain/osmosis/genesis-statefulset.yaml @@ -68,7 +68,52 @@ spec: command: - bash - '-c' - - /scripts/create-genesis.sh + - >- + VAL_INDEX=${HOSTNAME##*-} + + echo "Validator Index: $VAL_INDEX" + + + if [ -f $CHAIN_DIR/config/genesis.json ]; then + echo "Genesis file exists, exiting init container" + exit 0 + fi + + + echo "Running setup genesis script..." + + bash -e /scripts/create-genesis.sh + + bash -e /scripts/update-genesis.sh + + + echo "Create node id json file" + + NODE_ID=$($CHAIN_BIN tendermint show-node-id) + + echo '{"node_id":"'$NODE_ID'"}' > $CHAIN_DIR/config/node_id.json + + + echo "Create consensus key json file" + + $CHAIN_BIN tendermint show-validator > + $CHAIN_DIR/config/consensus_key.json + + cat $CHAIN_DIR/config/consensus_key.json + + + echo "Add custom accounts and balances" + + CHAIN_GENESIS_CMD=$($CHAIN_BIN 2>&1 | grep -q "genesis-related + subcommands" && echo "genesis" || echo "") + + + echo "Adding balance to + osmo1e9ucjn5fjmetky5wezzcsccp7hqcwzrrhthpf5" + + $CHAIN_BIN $CHAIN_GENESIS_CMD add-genesis-account + osmo1e9ucjn5fjmetky5wezzcsccp7hqcwzrrhthpf5 2000000000000uosmo + --keyring-backend="test" resources: limits: cpu: '0.5' @@ -110,7 +155,21 @@ spec: command: - bash - '-c' - - /scripts/update-config.sh + - >- + VAL_INDEX=${HOSTNAME##*-} + + echo "Validator Index: $VAL_INDEX" + + + echo "Running setup config script..." + + + jq -s '.[0] * .[1]' $CHAIN_DIR/config/genesis.json + /patch/genesis.json > $CHAIN_DIR/config/genesis.json.tmp && mv + $CHAIN_DIR/config/genesis.json.tmp $CHAIN_DIR/config/genesis.json + + + bash -e /scripts/update-config.sh resources: limits: cpu: '0.5' @@ -176,8 +235,10 @@ spec: #!/bin/bash set -euo pipefail - echo "Starting osmosisd validator..." - exec osmosisd start --home /root/.osmosisd --log_level info + START_ARGS="" + + + $CHAIN_BIN start $START_ARGS resources: limits: cpu: '0.5' @@ -245,31 +306,66 @@ spec: - mountPath: /configs name: addresses - name: faucet - image: busybox:1.34.1 + image: ghcr.io/cosmology-tech/starship/osmosis:v25.0.0 imagePullPolicy: IfNotPresent env: - name: FAUCET_CONCURRENCY value: '2' - - name: FAUCET_PORT + - name: FAUCET_HTTP_PORT value: '8000' + - name: FAUCET_CHAIN_BINARY + value: osmosisd - name: FAUCET_CHAIN_ID value: osmosis-1 - - name: FAUCET_CHAIN_DENOM - value: uosmo - - name: FAUCET_CHAIN_PREFIX - value: osmo - - name: FAUCET_AMOUNT_SEND - value: '10000000' - - name: FAUCET_AMOUNT_STAKE - value: '10000000' - - name: FAUCET_RPC_ENDPOINT - value: http://localhost:26657 - - name: FAUCET_REST_ENDPOINT - value: http://localhost:1317 + - name: COINS + value: 100000000000000uosmo,100000000000000uion command: - - sh + - bash - '-c' - - /faucet/faucet + - >- + CREDIT_COINS="" + + FEES="" + + for coin in ${COINS//,/ } + + do + amt="${coin//[!0-9]/}" + denom="${coin//[0-9]/}" + + # Calculate the order of magnitude + if [ ${#amt} -gt 18 ]; then + creditAmt=$(echo $amt | sed -e "s/000000$//") + feesAmt=$(echo $amt | sed -e "s/0000000000000$//") + else + creditAmt=$(echo $amt | sed -e "s/0000$//") + feesAmt=$(echo $amt | sed -e "s/00000000$//") + fi + + if [[ $CREDIT_COINS == "" ]] + then + CREDIT_COINS="$creditAmt$denom" + FEES="$feesAmt$denom" + else + CREDIT_COINS="${CREDIT_COINS},$creditAmt$denom" + fi + done + + + export FAUCET_MNEMONIC=$(jq -r ".faucet[0].mnemonic" + /configs/keys.json) + + + export | grep "FAUCET" + + + until bash -e /scripts/chain-rpc-ready.sh http://localhost:26657; + do + sleep 10 + done + + + /faucet/faucet --credit-coins="$CREDIT_COINS" --chain-fees="$FEES" resources: limits: cpu: '0.1' @@ -282,6 +378,14 @@ spec: name: addresses - mountPath: /faucet name: faucet + - mountPath: /scripts + name: scripts + readinessProbe: + httpGet: + path: /status + port: '8000' + initialDelaySeconds: 30 + periodSeconds: 10 volumes: - name: node emptyDir: {} @@ -294,3 +398,5 @@ spec: - name: patch configMap: name: patch-osmosis-1 + - name: faucet + emptyDir: {} diff --git a/packages/packages/generator/__tests__/__output__/builder-tests/single-chain/osmosis/setup-scripts-configmap.yaml b/packages/packages/generator/__tests__/__output__/builder-tests/single-chain/osmosis/setup-scripts-configmap.yaml index 770edb52d..0f3d10fee 100644 --- a/packages/packages/generator/__tests__/__output__/builder-tests/single-chain/osmosis/setup-scripts-configmap.yaml +++ b/packages/packages/generator/__tests__/__output__/builder-tests/single-chain/osmosis/setup-scripts-configmap.yaml @@ -10,6 +10,8 @@ metadata: app.kubernetes.io/name: osmosis app.kubernetes.io/part-of: osmosis-1 app.kubernetes.io/role: setup-scripts + starship.io/chain-name: osmosis + starship.io/chain-id: osmosis-1 data: create-genesis.sh: > #!/bin/bash diff --git a/packages/packages/generator/__tests__/__output__/builder-tests/special-chars/test-chain/genesis-patch-configmap.yaml b/packages/packages/generator/__tests__/__output__/builder-tests/special-chars/test-chain/genesis-patch-configmap.yaml index 56af3647d..918ba47ee 100644 --- a/packages/packages/generator/__tests__/__output__/builder-tests/special-chars/test-chain/genesis-patch-configmap.yaml +++ b/packages/packages/generator/__tests__/__output__/builder-tests/special-chars/test-chain/genesis-patch-configmap.yaml @@ -10,8 +10,10 @@ metadata: app.kubernetes.io/name: test-chain app.kubernetes.io/part-of: test-chain-1 app.kubernetes.io/role: genesis-patch + starship.io/chain-name: test-chain + starship.io/chain-id: test-chain-1 data: - patch.json: |- + genesis.json: |- { "app_state": { "staking": { diff --git a/packages/packages/generator/__tests__/__output__/builder-tests/special-chars/test-chain/genesis-statefulset.yaml b/packages/packages/generator/__tests__/__output__/builder-tests/special-chars/test-chain/genesis-statefulset.yaml index 86c41ceab..5d69b96ae 100644 --- a/packages/packages/generator/__tests__/__output__/builder-tests/special-chars/test-chain/genesis-statefulset.yaml +++ b/packages/packages/generator/__tests__/__output__/builder-tests/special-chars/test-chain/genesis-statefulset.yaml @@ -67,7 +67,52 @@ spec: command: - bash - '-c' - - /scripts/create-genesis.sh + - >- + VAL_INDEX=${HOSTNAME##*-} + + echo "Validator Index: $VAL_INDEX" + + + if [ -f $CHAIN_DIR/config/genesis.json ]; then + echo "Genesis file exists, exiting init container" + exit 0 + fi + + + echo "Running setup genesis script..." + + bash -e /scripts/create-genesis.sh + + bash -e /scripts/update-genesis.sh + + + echo "Create node id json file" + + NODE_ID=$($CHAIN_BIN tendermint show-node-id) + + echo '{"node_id":"'$NODE_ID'"}' > $CHAIN_DIR/config/node_id.json + + + echo "Create consensus key json file" + + $CHAIN_BIN tendermint show-validator > + $CHAIN_DIR/config/consensus_key.json + + cat $CHAIN_DIR/config/consensus_key.json + + + echo "Add custom accounts and balances" + + CHAIN_GENESIS_CMD=$($CHAIN_BIN 2>&1 | grep -q "genesis-related + subcommands" && echo "genesis" || echo "") + + + echo "Adding balance to + osmo1e9ucjn5fjmetky5wezzcsccp7hqcwzrrhthpf5" + + $CHAIN_BIN $CHAIN_GENESIS_CMD add-genesis-account + osmo1e9ucjn5fjmetky5wezzcsccp7hqcwzrrhthpf5 2000000000000uosmo + --keyring-backend="test" resources: limits: cpu: '0.5' @@ -107,7 +152,21 @@ spec: command: - bash - '-c' - - /scripts/update-config.sh + - >- + VAL_INDEX=${HOSTNAME##*-} + + echo "Validator Index: $VAL_INDEX" + + + echo "Running setup config script..." + + + jq -s '.[0] * .[1]' $CHAIN_DIR/config/genesis.json + /patch/genesis.json > $CHAIN_DIR/config/genesis.json.tmp && mv + $CHAIN_DIR/config/genesis.json.tmp $CHAIN_DIR/config/genesis.json + + + bash -e /scripts/update-config.sh resources: limits: cpu: '0.5' @@ -171,8 +230,10 @@ spec: #!/bin/bash set -euo pipefail - echo "Starting undefined validator..." - exec undefined start --home undefined --log_level info + START_ARGS="" + + + $CHAIN_BIN start $START_ARGS resources: limits: cpu: '0.5' @@ -238,29 +299,65 @@ spec: - mountPath: /configs name: addresses - name: faucet - image: busybox:1.34.1 imagePullPolicy: IfNotPresent env: - name: FAUCET_CONCURRENCY value: '2' - - name: FAUCET_PORT + - name: FAUCET_HTTP_PORT value: '8000' + - name: FAUCET_CHAIN_BINARY + value: test-chain-1 - name: FAUCET_CHAIN_ID value: test-chain-1 - - name: FAUCET_CHAIN_DENOM - - name: FAUCET_CHAIN_PREFIX - - name: FAUCET_AMOUNT_SEND - value: '10000000' - - name: FAUCET_AMOUNT_STAKE - value: '10000000' - - name: FAUCET_RPC_ENDPOINT - value: http://localhost:26657 - - name: FAUCET_REST_ENDPOINT - value: http://localhost:1317 + - name: COINS + value: 1000000000000000000undefined command: - - sh + - bash - '-c' - - /faucet/faucet + - >- + CREDIT_COINS="" + + FEES="" + + for coin in ${COINS//,/ } + + do + amt="${coin//[!0-9]/}" + denom="${coin//[0-9]/}" + + # Calculate the order of magnitude + if [ ${#amt} -gt 18 ]; then + creditAmt=$(echo $amt | sed -e "s/000000$//") + feesAmt=$(echo $amt | sed -e "s/0000000000000$//") + else + creditAmt=$(echo $amt | sed -e "s/0000$//") + feesAmt=$(echo $amt | sed -e "s/00000000$//") + fi + + if [[ $CREDIT_COINS == "" ]] + then + CREDIT_COINS="$creditAmt$denom" + FEES="$feesAmt$denom" + else + CREDIT_COINS="${CREDIT_COINS},$creditAmt$denom" + fi + done + + + export FAUCET_MNEMONIC=$(jq -r ".faucet[0].mnemonic" + /configs/keys.json) + + + export | grep "FAUCET" + + + until bash -e /scripts/chain-rpc-ready.sh http://localhost:26657; + do + sleep 10 + done + + + /faucet/faucet --credit-coins="$CREDIT_COINS" --chain-fees="$FEES" resources: limits: cpu: '0.1' @@ -273,6 +370,14 @@ spec: name: addresses - mountPath: /faucet name: faucet + - mountPath: /scripts + name: scripts + readinessProbe: + httpGet: + path: /status + port: '8000' + initialDelaySeconds: 30 + periodSeconds: 10 volumes: - name: node emptyDir: {} @@ -285,3 +390,5 @@ spec: - name: patch configMap: name: patch-test-chain-1 + - name: faucet + emptyDir: {} diff --git a/packages/packages/generator/__tests__/__output__/builder-tests/special-chars/test-chain/setup-scripts-configmap.yaml b/packages/packages/generator/__tests__/__output__/builder-tests/special-chars/test-chain/setup-scripts-configmap.yaml index d5dbb1b49..1f0b73aa2 100644 --- a/packages/packages/generator/__tests__/__output__/builder-tests/special-chars/test-chain/setup-scripts-configmap.yaml +++ b/packages/packages/generator/__tests__/__output__/builder-tests/special-chars/test-chain/setup-scripts-configmap.yaml @@ -10,6 +10,8 @@ metadata: app.kubernetes.io/name: test-chain app.kubernetes.io/part-of: test-chain-1 app.kubernetes.io/role: setup-scripts + starship.io/chain-name: test-chain + starship.io/chain-id: test-chain-1 data: create-genesis.sh: > #!/bin/bash diff --git a/packages/packages/generator/__tests__/__snapshots__/builder.test.ts.snap b/packages/packages/generator/__tests__/__snapshots__/builder.test.ts.snap index 72f6dbe82..4e1a7687a 100644 --- a/packages/packages/generator/__tests__/__snapshots__/builder.test.ts.snap +++ b/packages/packages/generator/__tests__/__snapshots__/builder.test.ts.snap @@ -876,8 +876,10 @@ $CHAIN_BIN tendermint show-node-id "#!/bin/bash set -euo pipefail -echo "Starting gaiad validator..." -exec gaiad start --home /root/.gaia --log_level info", +START_ARGS="" +START_ARGS="--grpc-web.enable=false --transport=grpc --with-tendermint=false --address tcp://0.0.0.0:26658" + +$CHAIN_BIN start $START_ARGS", ], "env": [ { @@ -1033,7 +1035,28 @@ exec gaiad start --home /root/.gaia --log_level info", "command": [ "bash", "-c", - "/scripts/create-genesis.sh", + "VAL_INDEX=\${HOSTNAME##*-} +echo "Validator Index: $VAL_INDEX" + +if [ -f $CHAIN_DIR/config/genesis.json ]; then + echo "Genesis file exists, exiting init container" + exit 0 +fi + +echo "Running setup genesis script..." +bash -e /scripts/create-genesis.sh +bash -e /scripts/update-genesis.sh + +echo "Create node id json file" +NODE_ID=$($CHAIN_BIN tendermint show-node-id) +echo '{"node_id":"'$NODE_ID'"}' > $CHAIN_DIR/config/node_id.json + +echo "Create consensus key json file" +$CHAIN_BIN tendermint show-validator > $CHAIN_DIR/config/consensus_key.json +cat $CHAIN_DIR/config/consensus_key.json + +echo "Add custom accounts and balances" +CHAIN_GENESIS_CMD=$($CHAIN_BIN 2>&1 | grep -q "genesis-related subcommands" && echo "genesis" || echo "")", ], "env": [ { @@ -1117,7 +1140,12 @@ exec gaiad start --home /root/.gaia --log_level info", "command": [ "bash", "-c", - "/scripts/update-config.sh", + "VAL_INDEX=\${HOSTNAME##*-} +echo "Validator Index: $VAL_INDEX" + +echo "Running setup config script..." + +bash -e /scripts/update-config.sh", ], "env": [ { @@ -1838,6 +1866,8 @@ $CHAIN_BIN tendermint show-node-id "app.kubernetes.io/part-of": "cosmoshub-4", "app.kubernetes.io/role": "setup-scripts", "app.kubernetes.io/version": "4.0.0-alpha.0", + "starship.io/chain-id": "cosmoshub-4", + "starship.io/chain-name": "cosmoshub", "starship.io/name": "starship-generator-test", }, "name": "setup-scripts-cosmoshub-4", @@ -2722,8 +2752,10 @@ $CHAIN_BIN tendermint show-node-id "#!/bin/bash set -euo pipefail -echo "Starting osmosisd validator..." -exec osmosisd start --home /root/.osmosisd --log_level info", +START_ARGS="" + + +$CHAIN_BIN start $START_ARGS", ], "env": [ { @@ -2888,8 +2920,38 @@ exec osmosisd start --home /root/.osmosisd --log_level info", }, { "command": [ - "yarn", - "start", + "bash", + "-c", + "export FAUCET_TOKENS=$(printf '%s\\n' \${COINS//[[:digit:]]/}) +for coin in \${COINS//,/ } +do + var="FAUCET_CREDIT_AMOUNT_$(printf '%s\\n' \${coin//[[:digit:]]/} | tr '[:lower:]' '[:upper:]')" + amt="\${coin//[!0-9]/}" + + if [ \${#amt} -gt 18 ]; then + creditAmt=$(echo $amt | sed -e "s/000000$//") + feesAmt=$(echo $amt | sed -e "s/0000000000000$//") + else + creditAmt=$(echo $amt | sed -e "s/0000$//") + feesAmt=$(echo $amt | sed -e "s/00000000$//") + fi + + export $var="$creditAmt" +done + +export FAUCET_PATH_PATTERN="\${HD_PATH:0:$((\${#HD_PATH}-1))}a" +export FAUCET_MNEMONIC=$(jq -r ".faucet[0].mnemonic" /configs/keys.json) + +echo "FAUCET_MNEMONIC: $FAUCET_MNEMONIC" +echo "FAUCET_PATH_PATTERN: $FAUCET_PATH_PATTERN" + +export | grep "FAUCET" + +until bash -e /scripts/chain-rpc-ready.sh http://localhost:26657; do + sleep 10; +done + +/app/packages/faucet/bin/cosmos-faucet-dist start "http://localhost:26657"", ], "env": [ { @@ -2900,50 +2962,54 @@ exec osmosisd start --home /root/.osmosisd --log_level info", "name": "FAUCET_PORT", "value": "8000", }, + { + "name": "FAUCET_MEMO", + "value": "faucet txn", + }, { "name": "FAUCET_GAS_PRICE", - "value": "0.025", + "value": "1.25uosmo", }, { - "name": "FAUCET_PATH_PATTERN", - "value": "", + "name": "FAUCET_GAS_LIMIT", + "value": "2000000", }, { "name": "FAUCET_ADDRESS_PREFIX", "value": "osmo", }, { - "name": "FAUCET_TOKENS", - "value": "uosmo", - }, - { - "name": "FAUCET_CREDIT_AMOUNT_SEND", - "value": "10000000", - }, - { - "name": "FAUCET_CREDIT_AMOUNT_STAKE", - "value": "10000000", + "name": "FAUCET_REFILL_FACTOR", + "value": "8", }, { - "name": "FAUCET_MAX_CREDIT", - "value": "99999999", + "name": "FAUCET_REFILL_THRESHOLD", + "value": "20", }, { - "name": "FAUCET_MNEMONIC", - "value": "", + "name": "FAUCET_COOLDOWN_TIME", + "value": "0", }, { - "name": "FAUCET_CHAIN_ID", - "value": "osmosis-1", + "name": "COINS", + "value": "100000000000000uosmo,100000000000000uion", }, { - "name": "FAUCET_RPC_ENDPOINT", - "value": "http://localhost:26657", + "name": "HD_PATH", + "value": "m/44'/118'/0'/0/0", }, ], "image": "ghcr.io/hyperweb-io/starship/faucet:20250325-2207109", "imagePullPolicy": "IfNotPresent", "name": "faucet", + "readinessProbe": { + "httpGet": { + "path": "/status", + "port": "8000", + }, + "initialDelaySeconds": 30, + "periodSeconds": 10, + }, "resources": { "limits": { "cpu": "0.2", @@ -2959,6 +3025,10 @@ exec osmosisd start --home /root/.osmosisd --log_level info", "mountPath": "/configs", "name": "addresses", }, + { + "mountPath": "/scripts", + "name": "scripts", + }, ], }, ], @@ -2967,7 +3037,28 @@ exec osmosisd start --home /root/.osmosisd --log_level info", "command": [ "bash", "-c", - "/scripts/create-genesis.sh", + "VAL_INDEX=\${HOSTNAME##*-} +echo "Validator Index: $VAL_INDEX" + +if [ -f $CHAIN_DIR/config/genesis.json ]; then + echo "Genesis file exists, exiting init container" + exit 0 +fi + +echo "Running setup genesis script..." +bash -e /scripts/create-genesis.sh +bash -e /scripts/update-genesis.sh + +echo "Create node id json file" +NODE_ID=$($CHAIN_BIN tendermint show-node-id) +echo '{"node_id":"'$NODE_ID'"}' > $CHAIN_DIR/config/node_id.json + +echo "Create consensus key json file" +$CHAIN_BIN tendermint show-validator > $CHAIN_DIR/config/consensus_key.json +cat $CHAIN_DIR/config/consensus_key.json + +echo "Add custom accounts and balances" +CHAIN_GENESIS_CMD=$($CHAIN_BIN 2>&1 | grep -q "genesis-related subcommands" && echo "genesis" || echo "")", ], "env": [ { @@ -3051,7 +3142,12 @@ exec osmosisd start --home /root/.osmosisd --log_level info", "command": [ "bash", "-c", - "/scripts/update-config.sh", + "VAL_INDEX=\${HOSTNAME##*-} +echo "Validator Index: $VAL_INDEX" + +echo "Running setup config script..." + +bash -e /scripts/update-config.sh", ], "env": [ { @@ -3772,6 +3868,8 @@ $CHAIN_BIN tendermint show-node-id "app.kubernetes.io/part-of": "osmosis-1", "app.kubernetes.io/role": "setup-scripts", "app.kubernetes.io/version": "4.0.0-alpha.0", + "starship.io/chain-id": "osmosis-1", + "starship.io/chain-name": "osmosis", "starship.io/name": "starship-generator-test", }, "name": "setup-scripts-osmosis-1", @@ -4656,8 +4754,10 @@ $CHAIN_BIN tendermint show-node-id "#!/bin/bash set -euo pipefail -echo "Starting persistenceCore validator..." -exec persistenceCore start --home /root/.persistenceCore --log_level info", +START_ARGS="" + + +/usr/bin/cosmovisor start $START_ARGS", ], "env": [ { @@ -4700,6 +4800,14 @@ exec persistenceCore start --home /root/.persistenceCore --log_level info", "name": "SLOGFILE", "value": "slog.slog", }, + { + "name": "DAEMON_NAME", + "value": "persistenceCore", + }, + { + "name": "DAEMON_HOME", + "value": "/root/.persistenceCore", + }, ], "image": "ghcr.io/cosmology-tech/starship/runner:latest", "imagePullPolicy": "IfNotPresent", @@ -4822,9 +4930,42 @@ exec persistenceCore start --home /root/.persistenceCore --log_level info", }, { "command": [ - "sh", + "bash", "-c", - "/faucet/faucet", + "CREDIT_COINS="" +FEES="" +for coin in \${COINS//,/ } +do + amt="\${coin//[!0-9]/}" + denom="\${coin//[0-9]/}" + + # Calculate the order of magnitude + if [ \${#amt} -gt 18 ]; then + creditAmt=$(echo $amt | sed -e "s/000000$//") + feesAmt=$(echo $amt | sed -e "s/0000000000000$//") + else + creditAmt=$(echo $amt | sed -e "s/0000$//") + feesAmt=$(echo $amt | sed -e "s/00000000$//") + fi + + if [[ $CREDIT_COINS == "" ]] + then + CREDIT_COINS="$creditAmt$denom" + FEES="$feesAmt$denom" + else + CREDIT_COINS="\${CREDIT_COINS},$creditAmt$denom" + fi +done + +export FAUCET_MNEMONIC=$(jq -r ".faucet[0].mnemonic" /configs/keys.json) + +export | grep "FAUCET" + +until bash -e /scripts/chain-rpc-ready.sh http://localhost:26657; do + sleep 10 +done + +/faucet/faucet --credit-coins="$CREDIT_COINS" --chain-fees="$FEES"", ], "env": [ { @@ -4832,41 +4973,33 @@ exec persistenceCore start --home /root/.persistenceCore --log_level info", "value": "5", }, { - "name": "FAUCET_PORT", + "name": "FAUCET_HTTP_PORT", "value": "8000", }, { - "name": "FAUCET_CHAIN_ID", - "value": "core-1", - }, - { - "name": "FAUCET_CHAIN_DENOM", - "value": "uxprt", - }, - { - "name": "FAUCET_CHAIN_PREFIX", - "value": "persistence", - }, - { - "name": "FAUCET_AMOUNT_SEND", - "value": "10000000", - }, - { - "name": "FAUCET_AMOUNT_STAKE", - "value": "10000000", + "name": "FAUCET_CHAIN_BINARY", + "value": "persistenceCore", }, { - "name": "FAUCET_RPC_ENDPOINT", - "value": "http://localhost:26657", + "name": "FAUCET_CHAIN_ID", + "value": "core-1", }, { - "name": "FAUCET_REST_ENDPOINT", - "value": "http://localhost:1317", + "name": "COINS", + "value": "100000000000000uxprt", }, ], - "image": "busybox:1.34.1", + "image": "ghcr.io/cosmology-tech/starship/runner:latest", "imagePullPolicy": "IfNotPresent", "name": "faucet", + "readinessProbe": { + "httpGet": { + "path": "/status", + "port": "8000", + }, + "initialDelaySeconds": 30, + "periodSeconds": 10, + }, "resources": { "limits": { "cpu": "0.1", @@ -4886,6 +5019,10 @@ exec persistenceCore start --home /root/.persistenceCore --log_level info", "mountPath": "/faucet", "name": "faucet", }, + { + "mountPath": "/scripts", + "name": "scripts", + }, ], }, ], @@ -4978,7 +5115,30 @@ UPGRADE_NAME=genesis CODE_TAG=v7.0.0 bash -e /scripts/build-chain.sh", "command": [ "bash", "-c", - "/scripts/create-genesis.sh", + "VAL_INDEX=\${HOSTNAME##*-} +echo "Validator Index: $VAL_INDEX" + +cp $CHAIN_DIR/cosmovisor/genesis/bin/$CHAIN_BIN /usr/bin + +if [ -f $CHAIN_DIR/config/genesis.json ]; then + echo "Genesis file exists, exiting init container" + exit 0 +fi + +echo "Running setup genesis script..." +bash -e /scripts/create-genesis.sh +bash -e /scripts/update-genesis.sh + +echo "Create node id json file" +NODE_ID=$($CHAIN_BIN tendermint show-node-id) +echo '{"node_id":"'$NODE_ID'"}' > $CHAIN_DIR/config/node_id.json + +echo "Create consensus key json file" +$CHAIN_BIN tendermint show-validator > $CHAIN_DIR/config/consensus_key.json +cat $CHAIN_DIR/config/consensus_key.json + +echo "Add custom accounts and balances" +CHAIN_GENESIS_CMD=$($CHAIN_BIN 2>&1 | grep -q "genesis-related subcommands" && echo "genesis" || echo "")", ], "env": [ { @@ -5062,7 +5222,14 @@ UPGRADE_NAME=genesis CODE_TAG=v7.0.0 bash -e /scripts/build-chain.sh", "command": [ "bash", "-c", - "/scripts/update-config.sh", + "VAL_INDEX=\${HOSTNAME##*-} +echo "Validator Index: $VAL_INDEX" + +cp $CHAIN_DIR/cosmovisor/genesis/bin/$CHAIN_BIN /usr/bin + +echo "Running setup config script..." + +bash -e /scripts/update-config.sh", ], "env": [ { @@ -5178,6 +5345,10 @@ UPGRADE_NAME=genesis CODE_TAG=v7.0.0 bash -e /scripts/build-chain.sh", }, "name": "scripts", }, + { + "emptyDir": {}, + "name": "faucet", + }, ], }, }, @@ -5809,6 +5980,8 @@ $CHAIN_BIN tendermint show-node-id "app.kubernetes.io/part-of": "core-1", "app.kubernetes.io/role": "setup-scripts", "app.kubernetes.io/version": "4.0.0-alpha.0", + "starship.io/chain-id": "core-1", + "starship.io/chain-name": "persistencecore", "starship.io/name": "starship-generator-test", }, "name": "setup-scripts-core-1", @@ -5902,7 +6075,7 @@ $CHAIN_BIN tendermint show-node-id "app.kubernetes.io/component": "chain", "app.kubernetes.io/id": "core-1", "app.kubernetes.io/managed-by": "starship", - "app.kubernetes.io/name": "core-1-genesis", + "app.kubernetes.io/name": "core-1-validator", "app.kubernetes.io/part-of": "core-1", "app.kubernetes.io/role": "validator", "app.kubernetes.io/type": "core-1-statefulset", @@ -5945,11 +6118,14 @@ $CHAIN_BIN tendermint show-node-id "command": [ "bash", "-c", - "#!/bin/bash -set -euo pipefail + "set -eux +START_ARGS="" + -echo "Starting persistenceCore validator..." -exec persistenceCore start --home /root/.persistenceCore --log_level info", +# Starting the chain + +cp $CHAIN_DIR/cosmovisor/genesis/bin/$CHAIN_BIN /usr/bin +/usr/bin/cosmovisor start $START_ARGS", ], "env": [ { @@ -5984,6 +6160,26 @@ exec persistenceCore start --home /root/.persistenceCore --log_level info", "name": "CHAIN_ID", "value": "core-1", }, + { + "name": "GENESIS_HOST", + "value": "core-1-genesis", + }, + { + "name": "GENESIS_PORT", + "value": "8081", + }, + { + "name": "NAMESPACE", + "valueFrom": { + "fieldRef": { + "fieldPath": "metadata.namespace", + }, + }, + }, + { + "name": "KEYS_CONFIG", + "value": "/configs/keys.json", + }, { "name": "SLOGFILE", "value": "slog.slog", @@ -5997,9 +6193,27 @@ exec persistenceCore start --home /root/.persistenceCore --log_level info", "command": [ "bash", "-c", - "#!/bin/bash -echo "Validator post-start hook for core-1" -# Add any post-start logic here", + "-e", + "until bash -e /scripts/chain-rpc-ready.sh http://localhost:26657; do + sleep 10 +done + +set -eux +export +VAL_INDEX=\${HOSTNAME##*-} +VAL_NAME="$(jq -r ".validators[0].name" $KEYS_CONFIG)-$VAL_INDEX" +echo "Validator Index: $VAL_INDEX, Key name: $VAL_NAME. Chain bin $CHAIN_BIN" + +VAL_ADDR=$($CHAIN_BIN keys show $VAL_NAME -a --keyring-backend="test") +echo "Transfer tokens to address $VAL_ADDR before trying to create validator. Best effort" +bash -e /scripts/transfer-tokens.sh \\ + $VAL_ADDR \\ + $DENOM \\ + http://$GENESIS_HOST.$NAMESPACE.svc.cluster.local:8000/credit \\ + "true" || true + +$CHAIN_BIN keys list --keyring-backend test | jq +VAL_NAME=$VAL_NAME bash -e /scripts/create-validator.sh", ], }, }, @@ -6043,35 +6257,11 @@ echo "Validator post-start hook for core-1" }, ], }, - ], - "initContainers": [ { "command": [ - "bash", - "-c", - "# Install cosmovisor -go install github.com/cosmos/cosmos-sdk/cosmovisor/cmd/cosmovisor@v1.0.0 - -# Build genesis -UPGRADE_NAME=genesis CODE_TAG=v7.0.0 bash -e /scripts/build-chain.sh", + "exposer", ], "env": [ - { - "name": "CODE_REF", - "value": "https://github.com/persistenceOne/persistenceCore", - }, - { - "name": "UPGRADE_DIR", - "value": "/root/.persistenceCore/cosmovisor", - }, - { - "name": "GOBIN", - "value": "/go/bin", - }, - { - "name": "CHAIN_NAME", - "value": "core-1", - }, { "name": "DENOM", "value": "uxprt", @@ -6100,18 +6290,66 @@ UPGRADE_NAME=genesis CODE_TAG=v7.0.0 bash -e /scripts/build-chain.sh", "name": "DAEMON_NAME", "value": "persistenceCore", }, + { + "name": "CHAIN_ID", + "value": "core-1", + }, + { + "name": "GENESIS_HOST", + "value": "core-1-genesis", + }, + { + "name": "GENESIS_PORT", + "value": "8081", + }, + { + "name": "NAMESPACE", + "valueFrom": { + "fieldRef": { + "fieldPath": "metadata.namespace", + }, + }, + }, + { + "name": "EXPOSER_HTTP_PORT", + "value": "8081", + }, + { + "name": "EXPOSER_GRPC_PORT", + "value": "9099", + }, + { + "name": "EXPOSER_GENESIS_FILE", + "value": "/root/.persistenceCore/config/genesis.json", + }, + { + "name": "EXPOSER_MNEMONIC_FILE", + "value": "/configs/keys.json", + }, + { + "name": "EXPOSER_PRIV_VAL_FILE", + "value": "/root/.persistenceCore/config/priv_validator_key.json", + }, + { + "name": "EXPOSER_NODE_KEY_FILE", + "value": "/root/.persistenceCore/config/node_key.json", + }, + { + "name": "EXPOSER_PRIV_VAL_STATE_FILE", + "value": "/root/.persistenceCore/data/priv_validator_state.json", + }, ], - "image": "ghcr.io/cosmology-tech/starship/builder:latest", + "image": "ghcr.io/cosmology-tech/starship/exposer:latest", "imagePullPolicy": "IfNotPresent", - "name": "init-build-images", + "name": "exposer", "resources": { "limits": { - "cpu": "2", - "memory": "2Gi", + "cpu": "0.1", + "memory": "128M", }, "requests": { - "cpu": "2", - "memory": "2Gi", + "cpu": "0.1", + "memory": "128M", }, }, "volumeMounts": [ @@ -6123,22 +6361,162 @@ UPGRADE_NAME=genesis CODE_TAG=v7.0.0 bash -e /scripts/build-chain.sh", "mountPath": "/configs", "name": "addresses", }, - { - "mountPath": "/scripts", - "name": "scripts", - }, ], }, + ], + "initContainers": [ { "command": [ "bash", "-c", - "#!/bin/bash -set -euo pipefail + "# Install cosmovisor +go install github.com/cosmos/cosmos-sdk/cosmovisor/cmd/cosmovisor@v1.0.0 + +# Build genesis +UPGRADE_NAME=genesis CODE_TAG=v7.0.0 bash -e /scripts/build-chain.sh", + ], + "env": [ + { + "name": "CODE_REF", + "value": "https://github.com/persistenceOne/persistenceCore", + }, + { + "name": "UPGRADE_DIR", + "value": "/root/.persistenceCore/cosmovisor", + }, + { + "name": "GOBIN", + "value": "/go/bin", + }, + { + "name": "CHAIN_NAME", + "value": "core-1", + }, + { + "name": "DENOM", + "value": "uxprt", + }, + { + "name": "COINS", + "value": "100000000000000uxprt", + }, + { + "name": "CHAIN_BIN", + "value": "persistenceCore", + }, + { + "name": "CHAIN_DIR", + "value": "/root/.persistenceCore", + }, + { + "name": "CODE_REPO", + "value": "https://github.com/persistenceOne/persistenceCore", + }, + { + "name": "DAEMON_HOME", + "value": "/root/.persistenceCore", + }, + { + "name": "DAEMON_NAME", + "value": "persistenceCore", + }, + ], + "image": "ghcr.io/cosmology-tech/starship/builder:latest", + "imagePullPolicy": "IfNotPresent", + "name": "init-build-images", + "resources": { + "limits": { + "cpu": "2", + "memory": "2Gi", + }, + "requests": { + "cpu": "2", + "memory": "2Gi", + }, + }, + "volumeMounts": [ + { + "mountPath": "/root/.persistenceCore", + "name": "node", + }, + { + "mountPath": "/configs", + "name": "addresses", + }, + { + "mountPath": "/scripts", + "name": "scripts", + }, + ], + }, + { + "command": [ + "/bin/sh", + "-c", + " + while [ $(curl -sw '%{http_code}' http://core-1-genesis.$NAMESPACE.svc.cluster.local:$GENESIS_PORT/node_id -o /dev/null) -ne 200 ]; do + echo "Genesis validator does not seem to be ready for: core-1. Waiting for it to start..." + echo "Checking: http://core-1-genesis.$NAMESPACE.svc.cluster.local:$GENESIS_PORT/node_id" + sleep 10; + done +echo "Ready to start" +exit 0", + ], + "env": [ + { + "name": "GENESIS_PORT", + "value": "8081", + }, + { + "name": "NAMESPACE", + "valueFrom": { + "fieldRef": { + "fieldPath": "metadata.namespace", + }, + }, + }, + ], + "image": "curlimages/curl:latest", + "imagePullPolicy": "IfNotPresent", + "name": "wait-for-chains", + "resources": { + "limits": { + "cpu": "0.1", + "memory": "128M", + }, + "requests": { + "cpu": "0.1", + "memory": "128M", + }, + }, + }, + { + "command": [ + "bash", + "-c", + "VAL_INDEX=\${HOSTNAME##*-} +echo "Validator Index: $VAL_INDEX" +cp $CHAIN_DIR/cosmovisor/genesis/bin/$CHAIN_BIN /usr/bin + +if [ -f $CHAIN_DIR/config/genesis.json ]; then + echo "Genesis file exists, exiting early" + exit 0 +fi + +VAL_NAME=$(jq -r ".validators[0].name" $KEYS_CONFIG)-$VAL_INDEX +echo "Validator Index: $VAL_INDEX, Key name: $VAL_NAME" + +echo "Recover validator $VAL_NAME" +$CHAIN_BIN init $VAL_NAME --chain-id $CHAIN_ID +jq -r ".validators[0].mnemonic" $KEYS_CONFIG | $CHAIN_BIN keys add $VAL_NAME --index $VAL_INDEX --recover --keyring-backend="test" + +curl http://$GENESIS_HOST.$NAMESPACE.svc.cluster.local:$GENESIS_PORT/genesis -o $CHAIN_DIR/config/genesis.json +echo "Genesis file that we got....." +cat $CHAIN_DIR/config/genesis.json -echo "Initializing validator node for core-1..." -persistenceCore init validator-\${HOSTNAME##*-} --chain-id core-1 --home /root/.persistenceCore -echo "Validator initialization completed"", +echo "Create node id json file" +NODE_ID=$($CHAIN_BIN tendermint show-node-id) +echo '{"node_id":"'$NODE_ID'"}' > $CHAIN_DIR/config/node_id.json", ], "env": [ { @@ -6173,10 +6551,34 @@ echo "Validator initialization completed"", "name": "CHAIN_ID", "value": "core-1", }, + { + "name": "GENESIS_HOST", + "value": "core-1-genesis", + }, + { + "name": "GENESIS_PORT", + "value": "8081", + }, + { + "name": "NAMESPACE", + "valueFrom": { + "fieldRef": { + "fieldPath": "metadata.namespace", + }, + }, + }, { "name": "KEYS_CONFIG", "value": "/configs/keys.json", }, + { + "name": "FAUCET_ENABLED", + "value": "true", + }, + { + "name": "METRICS", + "value": "false", + }, ], "image": "ghcr.io/cosmology-tech/starship/runner:latest", "imagePullPolicy": "IfNotPresent", @@ -6210,7 +6612,26 @@ echo "Validator initialization completed"", "command": [ "bash", "-c", - "/scripts/update-config.sh", + "VAL_INDEX=\${HOSTNAME##*-} +echo "Validator Index: $VAL_INDEX" +cp $CHAIN_DIR/cosmovisor/genesis/bin/$CHAIN_BIN /usr/bin + +echo "Running setup config script..." +bash -e /scripts/update-config.sh + +curl -s http://$GENESIS_HOST.$NAMESPACE.svc.cluster.local:$GENESIS_PORT/node_id +NODE_ID=$(curl -s http://$GENESIS_HOST.$NAMESPACE.svc.cluster.local:$GENESIS_PORT/node_id | jq -r ".node_id") +if [[ $NODE_ID == "" ]]; then + echo "Node ID is null, exiting early" + exit 1 +fi + +GENESIS_NODE_P2P=$NODE_ID@$GENESIS_HOST.$NAMESPACE.svc.cluster.local:26656 +echo "Node P2P: $GENESIS_NODE_P2P" +sed -i "s/persistent_peers = \\"\\"/persistent_peers = \\"$GENESIS_NODE_P2P\\"/g" $CHAIN_DIR/config/config.toml + +echo "Printing the whole config.toml file" +cat $CHAIN_DIR/config/config.toml", ], "env": [ { @@ -6245,6 +6666,22 @@ echo "Validator initialization completed"", "name": "CHAIN_ID", "value": "core-1", }, + { + "name": "GENESIS_HOST", + "value": "core-1-genesis", + }, + { + "name": "GENESIS_PORT", + "value": "8081", + }, + { + "name": "NAMESPACE", + "valueFrom": { + "fieldRef": { + "fieldPath": "metadata.namespace", + }, + }, + }, { "name": "KEYS_CONFIG", "value": "/configs/keys.json", @@ -6256,7 +6693,7 @@ echo "Validator initialization completed"", ], "image": "ghcr.io/cosmology-tech/starship/runner:latest", "imagePullPolicy": "IfNotPresent", - "name": "init-validator-config", + "name": "init-config", "resources": { "limits": { "cpu": "2", @@ -6300,6 +6737,10 @@ echo "Validator initialization completed"", }, "name": "scripts", }, + { + "emptyDir": {}, + "name": "faucet", + }, ], }, }, @@ -7184,8 +7625,10 @@ $CHAIN_BIN tendermint show-node-id "#!/bin/bash set -euo pipefail -echo "Starting gaiad validator..." -exec gaiad start --home /root/.gaia --log_level info", +START_ARGS="" + + +$CHAIN_BIN start $START_ARGS", ], "env": [ { @@ -7354,7 +7797,28 @@ exec gaiad start --home /root/.gaia --log_level info", "command": [ "bash", "-c", - "/scripts/create-genesis.sh", + "VAL_INDEX=\${HOSTNAME##*-} +echo "Validator Index: $VAL_INDEX" + +if [ -f $CHAIN_DIR/config/genesis.json ]; then + echo "Genesis file exists, exiting init container" + exit 0 +fi + +echo "Running setup genesis script..." +bash -e /scripts/create-genesis.sh +bash -e /scripts/update-genesis.sh + +echo "Create node id json file" +NODE_ID=$($CHAIN_BIN tendermint show-node-id) +echo '{"node_id":"'$NODE_ID'"}' > $CHAIN_DIR/config/node_id.json + +echo "Create consensus key json file" +$CHAIN_BIN tendermint show-validator > $CHAIN_DIR/config/consensus_key.json +cat $CHAIN_DIR/config/consensus_key.json + +echo "Add custom accounts and balances" +CHAIN_GENESIS_CMD=$($CHAIN_BIN 2>&1 | grep -q "genesis-related subcommands" && echo "genesis" || echo "")", ], "env": [ { @@ -7438,7 +7902,12 @@ exec gaiad start --home /root/.gaia --log_level info", "command": [ "bash", "-c", - "/scripts/update-config.sh", + "VAL_INDEX=\${HOSTNAME##*-} +echo "Validator Index: $VAL_INDEX" + +echo "Running setup config script..." + +bash -e /scripts/update-config.sh", ], "env": [ { @@ -8159,6 +8628,8 @@ $CHAIN_BIN tendermint show-node-id "app.kubernetes.io/part-of": "cosmoshub-4", "app.kubernetes.io/role": "setup-scripts", "app.kubernetes.io/version": "4.0.0-alpha.0", + "starship.io/chain-id": "cosmoshub-4", + "starship.io/chain-name": "cosmoshub", "starship.io/name": "starship-generator-test", }, "name": "setup-scripts-cosmoshub-4", @@ -8252,7 +8723,7 @@ $CHAIN_BIN tendermint show-node-id "app.kubernetes.io/component": "chain", "app.kubernetes.io/id": "cosmoshub-4", "app.kubernetes.io/managed-by": "starship", - "app.kubernetes.io/name": "cosmoshub-4-genesis", + "app.kubernetes.io/name": "cosmoshub-4-validator", "app.kubernetes.io/part-of": "cosmoshub-4", "app.kubernetes.io/role": "validator", "app.kubernetes.io/type": "cosmoshub-4-statefulset", @@ -8295,11 +8766,13 @@ $CHAIN_BIN tendermint show-node-id "command": [ "bash", "-c", - "#!/bin/bash -set -euo pipefail + "set -eux +START_ARGS="" -echo "Starting gaiad validator..." -exec gaiad start --home /root/.gaia --log_level info", + +# Starting the chain + +$CHAIN_BIN start $START_ARGS", ], "env": [ { @@ -8334,6 +8807,26 @@ exec gaiad start --home /root/.gaia --log_level info", "name": "CHAIN_ID", "value": "cosmoshub-4", }, + { + "name": "GENESIS_HOST", + "value": "cosmoshub-4-genesis", + }, + { + "name": "GENESIS_PORT", + "value": "8081", + }, + { + "name": "NAMESPACE", + "valueFrom": { + "fieldRef": { + "fieldPath": "metadata.namespace", + }, + }, + }, + { + "name": "KEYS_CONFIG", + "value": "/configs/keys.json", + }, { "name": "SLOGFILE", "value": "slog.slog", @@ -8347,9 +8840,27 @@ exec gaiad start --home /root/.gaia --log_level info", "command": [ "bash", "-c", - "#!/bin/bash -echo "Validator post-start hook for cosmoshub-4" -# Add any post-start logic here", + "-e", + "until bash -e /scripts/chain-rpc-ready.sh http://localhost:26657; do + sleep 10 +done + +set -eux +export +VAL_INDEX=\${HOSTNAME##*-} +VAL_NAME="$(jq -r ".validators[0].name" $KEYS_CONFIG)-$VAL_INDEX" +echo "Validator Index: $VAL_INDEX, Key name: $VAL_NAME. Chain bin $CHAIN_BIN" + +VAL_ADDR=$($CHAIN_BIN keys show $VAL_NAME -a --keyring-backend="test") +echo "Transfer tokens to address $VAL_ADDR before trying to create validator. Best effort" +bash -e /scripts/transfer-tokens.sh \\ + $VAL_ADDR \\ + $DENOM \\ + http://$GENESIS_HOST.$NAMESPACE.svc.cluster.local:8000/credit \\ + "false" || true + +$CHAIN_BIN keys list --keyring-backend test | jq +VAL_NAME=$VAL_NAME bash -e /scripts/create-validator.sh", ], }, }, @@ -8393,18 +8904,9 @@ echo "Validator post-start hook for cosmoshub-4" }, ], }, - ], - "initContainers": [ { "command": [ - "bash", - "-c", - "#!/bin/bash -set -euo pipefail - -echo "Initializing validator node for cosmoshub-4..." -gaiad init validator-\${HOSTNAME##*-} --chain-id cosmoshub-4 --home /root/.gaia -echo "Validator initialization completed"", + "exposer", ], "env": [ { @@ -8440,31 +8942,228 @@ echo "Validator initialization completed"", "value": "cosmoshub-4", }, { - "name": "KEYS_CONFIG", - "value": "/configs/keys.json", - }, - ], - "image": "ghcr.io/cosmology-tech/starship/gaia:v18.0.0", - "imagePullPolicy": "IfNotPresent", - "name": "init-validator", - "resources": { - "limits": { - "cpu": "0.5", - "memory": "500M", - }, - "requests": { - "cpu": "0.5", - "memory": "500M", + "name": "GENESIS_HOST", + "value": "cosmoshub-4-genesis", }, - }, - "volumeMounts": [ { - "mountPath": "/root/.gaia", - "name": "node", + "name": "GENESIS_PORT", + "value": "8081", }, { - "mountPath": "/configs", - "name": "addresses", + "name": "NAMESPACE", + "valueFrom": { + "fieldRef": { + "fieldPath": "metadata.namespace", + }, + }, + }, + { + "name": "EXPOSER_HTTP_PORT", + "value": "8081", + }, + { + "name": "EXPOSER_GRPC_PORT", + "value": "9099", + }, + { + "name": "EXPOSER_GENESIS_FILE", + "value": "/root/.gaia/config/genesis.json", + }, + { + "name": "EXPOSER_MNEMONIC_FILE", + "value": "/configs/keys.json", + }, + { + "name": "EXPOSER_PRIV_VAL_FILE", + "value": "/root/.gaia/config/priv_validator_key.json", + }, + { + "name": "EXPOSER_NODE_KEY_FILE", + "value": "/root/.gaia/config/node_key.json", + }, + { + "name": "EXPOSER_PRIV_VAL_STATE_FILE", + "value": "/root/.gaia/data/priv_validator_state.json", + }, + ], + "image": "ghcr.io/cosmology-tech/starship/exposer:latest", + "imagePullPolicy": "IfNotPresent", + "name": "exposer", + "resources": { + "limits": { + "cpu": "0.1", + "memory": "128M", + }, + "requests": { + "cpu": "0.1", + "memory": "128M", + }, + }, + "volumeMounts": [ + { + "mountPath": "/root/.gaia", + "name": "node", + }, + { + "mountPath": "/configs", + "name": "addresses", + }, + ], + }, + ], + "initContainers": [ + { + "command": [ + "/bin/sh", + "-c", + " + while [ $(curl -sw '%{http_code}' http://cosmoshub-4-genesis.$NAMESPACE.svc.cluster.local:$GENESIS_PORT/node_id -o /dev/null) -ne 200 ]; do + echo "Genesis validator does not seem to be ready for: cosmoshub-4. Waiting for it to start..." + echo "Checking: http://cosmoshub-4-genesis.$NAMESPACE.svc.cluster.local:$GENESIS_PORT/node_id" + sleep 10; + done +echo "Ready to start" +exit 0", + ], + "env": [ + { + "name": "GENESIS_PORT", + "value": "8081", + }, + { + "name": "NAMESPACE", + "valueFrom": { + "fieldRef": { + "fieldPath": "metadata.namespace", + }, + }, + }, + ], + "image": "curlimages/curl:latest", + "imagePullPolicy": "IfNotPresent", + "name": "wait-for-chains", + "resources": { + "limits": { + "cpu": "0.1", + "memory": "128M", + }, + "requests": { + "cpu": "0.1", + "memory": "128M", + }, + }, + }, + { + "command": [ + "bash", + "-c", + "VAL_INDEX=\${HOSTNAME##*-} +echo "Validator Index: $VAL_INDEX" + + +if [ -f $CHAIN_DIR/config/genesis.json ]; then + echo "Genesis file exists, exiting early" + exit 0 +fi + +VAL_NAME=$(jq -r ".validators[0].name" $KEYS_CONFIG)-$VAL_INDEX +echo "Validator Index: $VAL_INDEX, Key name: $VAL_NAME" + +echo "Recover validator $VAL_NAME" +$CHAIN_BIN init $VAL_NAME --chain-id $CHAIN_ID +jq -r ".validators[0].mnemonic" $KEYS_CONFIG | $CHAIN_BIN keys add $VAL_NAME --index $VAL_INDEX --recover --keyring-backend="test" + +curl http://$GENESIS_HOST.$NAMESPACE.svc.cluster.local:$GENESIS_PORT/genesis -o $CHAIN_DIR/config/genesis.json +echo "Genesis file that we got....." +cat $CHAIN_DIR/config/genesis.json + +echo "Create node id json file" +NODE_ID=$($CHAIN_BIN tendermint show-node-id) +echo '{"node_id":"'$NODE_ID'"}' > $CHAIN_DIR/config/node_id.json", + ], + "env": [ + { + "name": "DENOM", + "value": "uatom", + }, + { + "name": "COINS", + "value": "100000000000000uatom", + }, + { + "name": "CHAIN_BIN", + "value": "gaiad", + }, + { + "name": "CHAIN_DIR", + "value": "/root/.gaia", + }, + { + "name": "CODE_REPO", + "value": "https://github.com/cosmos/gaia", + }, + { + "name": "DAEMON_HOME", + "value": "/root/.gaia", + }, + { + "name": "DAEMON_NAME", + "value": "gaiad", + }, + { + "name": "CHAIN_ID", + "value": "cosmoshub-4", + }, + { + "name": "GENESIS_HOST", + "value": "cosmoshub-4-genesis", + }, + { + "name": "GENESIS_PORT", + "value": "8081", + }, + { + "name": "NAMESPACE", + "valueFrom": { + "fieldRef": { + "fieldPath": "metadata.namespace", + }, + }, + }, + { + "name": "KEYS_CONFIG", + "value": "/configs/keys.json", + }, + { + "name": "FAUCET_ENABLED", + "value": "false", + }, + { + "name": "METRICS", + "value": "false", + }, + ], + "image": "ghcr.io/cosmology-tech/starship/gaia:v18.0.0", + "imagePullPolicy": "IfNotPresent", + "name": "init-validator", + "resources": { + "limits": { + "cpu": "0.5", + "memory": "500M", + }, + "requests": { + "cpu": "0.5", + "memory": "500M", + }, + }, + "volumeMounts": [ + { + "mountPath": "/root/.gaia", + "name": "node", + }, + { + "mountPath": "/configs", + "name": "addresses", }, { "mountPath": "/scripts", @@ -8476,7 +9175,26 @@ echo "Validator initialization completed"", "command": [ "bash", "-c", - "/scripts/update-config.sh", + "VAL_INDEX=\${HOSTNAME##*-} +echo "Validator Index: $VAL_INDEX" + + +echo "Running setup config script..." +bash -e /scripts/update-config.sh + +curl -s http://$GENESIS_HOST.$NAMESPACE.svc.cluster.local:$GENESIS_PORT/node_id +NODE_ID=$(curl -s http://$GENESIS_HOST.$NAMESPACE.svc.cluster.local:$GENESIS_PORT/node_id | jq -r ".node_id") +if [[ $NODE_ID == "" ]]; then + echo "Node ID is null, exiting early" + exit 1 +fi + +GENESIS_NODE_P2P=$NODE_ID@$GENESIS_HOST.$NAMESPACE.svc.cluster.local:26656 +echo "Node P2P: $GENESIS_NODE_P2P" +sed -i "s/persistent_peers = \\"\\"/persistent_peers = \\"$GENESIS_NODE_P2P\\"/g" $CHAIN_DIR/config/config.toml + +echo "Printing the whole config.toml file" +cat $CHAIN_DIR/config/config.toml", ], "env": [ { @@ -8511,6 +9229,22 @@ echo "Validator initialization completed"", "name": "CHAIN_ID", "value": "cosmoshub-4", }, + { + "name": "GENESIS_HOST", + "value": "cosmoshub-4-genesis", + }, + { + "name": "GENESIS_PORT", + "value": "8081", + }, + { + "name": "NAMESPACE", + "valueFrom": { + "fieldRef": { + "fieldPath": "metadata.namespace", + }, + }, + }, { "name": "KEYS_CONFIG", "value": "/configs/keys.json", @@ -8522,7 +9256,7 @@ echo "Validator initialization completed"", ], "image": "ghcr.io/cosmology-tech/starship/gaia:v18.0.0", "imagePullPolicy": "IfNotPresent", - "name": "init-validator-config", + "name": "init-config", "resources": { "limits": { "cpu": "0.5", @@ -8838,8 +9572,10 @@ echo "Validator initialization completed"", "#!/bin/bash set -euo pipefail -echo "Starting osmosisd validator..." -exec osmosisd start --home /root/.osmosisd --log_level info", +START_ARGS="" + + +$CHAIN_BIN start $START_ARGS", ], "env": [ { @@ -9004,9 +9740,42 @@ exec osmosisd start --home /root/.osmosisd --log_level info", }, { "command": [ - "sh", + "bash", "-c", - "/faucet/faucet", + "CREDIT_COINS="" +FEES="" +for coin in \${COINS//,/ } +do + amt="\${coin//[!0-9]/}" + denom="\${coin//[0-9]/}" + + # Calculate the order of magnitude + if [ \${#amt} -gt 18 ]; then + creditAmt=$(echo $amt | sed -e "s/000000$//") + feesAmt=$(echo $amt | sed -e "s/0000000000000$//") + else + creditAmt=$(echo $amt | sed -e "s/0000$//") + feesAmt=$(echo $amt | sed -e "s/00000000$//") + fi + + if [[ $CREDIT_COINS == "" ]] + then + CREDIT_COINS="$creditAmt$denom" + FEES="$feesAmt$denom" + else + CREDIT_COINS="\${CREDIT_COINS},$creditAmt$denom" + fi +done + +export FAUCET_MNEMONIC=$(jq -r ".faucet[0].mnemonic" /configs/keys.json) + +export | grep "FAUCET" + +until bash -e /scripts/chain-rpc-ready.sh http://localhost:26657; do + sleep 10 +done + +/faucet/faucet --credit-coins="$CREDIT_COINS" --chain-fees="$FEES"", ], "env": [ { @@ -9014,41 +9783,33 @@ exec osmosisd start --home /root/.osmosisd --log_level info", "value": "5", }, { - "name": "FAUCET_PORT", + "name": "FAUCET_HTTP_PORT", "value": "8000", }, { - "name": "FAUCET_CHAIN_ID", - "value": "osmosis-1", - }, - { - "name": "FAUCET_CHAIN_DENOM", - "value": "uosmo", - }, - { - "name": "FAUCET_CHAIN_PREFIX", - "value": "osmo", - }, - { - "name": "FAUCET_AMOUNT_SEND", - "value": "10000000", - }, - { - "name": "FAUCET_AMOUNT_STAKE", - "value": "10000000", + "name": "FAUCET_CHAIN_BINARY", + "value": "osmosisd", }, { - "name": "FAUCET_RPC_ENDPOINT", - "value": "http://localhost:26657", + "name": "FAUCET_CHAIN_ID", + "value": "osmosis-1", }, { - "name": "FAUCET_REST_ENDPOINT", - "value": "http://localhost:1317", + "name": "COINS", + "value": "100000000000000uosmo,100000000000000uion", }, ], - "image": "busybox:1.34.1", + "image": "ghcr.io/cosmology-tech/starship/osmosis:v25.0.0", "imagePullPolicy": "IfNotPresent", "name": "faucet", + "readinessProbe": { + "httpGet": { + "path": "/status", + "port": "8000", + }, + "initialDelaySeconds": 30, + "periodSeconds": 10, + }, "resources": { "limits": { "cpu": "0.1", @@ -9068,6 +9829,10 @@ exec osmosisd start --home /root/.osmosisd --log_level info", "mountPath": "/faucet", "name": "faucet", }, + { + "mountPath": "/scripts", + "name": "scripts", + }, ], }, ], @@ -9076,7 +9841,28 @@ exec osmosisd start --home /root/.osmosisd --log_level info", "command": [ "bash", "-c", - "/scripts/create-genesis.sh", + "VAL_INDEX=\${HOSTNAME##*-} +echo "Validator Index: $VAL_INDEX" + +if [ -f $CHAIN_DIR/config/genesis.json ]; then + echo "Genesis file exists, exiting init container" + exit 0 +fi + +echo "Running setup genesis script..." +bash -e /scripts/create-genesis.sh +bash -e /scripts/update-genesis.sh + +echo "Create node id json file" +NODE_ID=$($CHAIN_BIN tendermint show-node-id) +echo '{"node_id":"'$NODE_ID'"}' > $CHAIN_DIR/config/node_id.json + +echo "Create consensus key json file" +$CHAIN_BIN tendermint show-validator > $CHAIN_DIR/config/consensus_key.json +cat $CHAIN_DIR/config/consensus_key.json + +echo "Add custom accounts and balances" +CHAIN_GENESIS_CMD=$($CHAIN_BIN 2>&1 | grep -q "genesis-related subcommands" && echo "genesis" || echo "")", ], "env": [ { @@ -9160,7 +9946,12 @@ exec osmosisd start --home /root/.osmosisd --log_level info", "command": [ "bash", "-c", - "/scripts/update-config.sh", + "VAL_INDEX=\${HOSTNAME##*-} +echo "Validator Index: $VAL_INDEX" + +echo "Running setup config script..." + +bash -e /scripts/update-config.sh", ], "env": [ { @@ -9276,6 +10067,10 @@ exec osmosisd start --home /root/.osmosisd --log_level info", }, "name": "scripts", }, + { + "emptyDir": {}, + "name": "faucet", + }, ], }, }, @@ -9907,6 +10702,8 @@ $CHAIN_BIN tendermint show-node-id "app.kubernetes.io/part-of": "osmosis-1", "app.kubernetes.io/role": "setup-scripts", "app.kubernetes.io/version": "4.0.0-alpha.0", + "starship.io/chain-id": "osmosis-1", + "starship.io/chain-name": "osmosis", "starship.io/name": "starship-generator-test", }, "name": "setup-scripts-osmosis-1", @@ -10000,7 +10797,7 @@ $CHAIN_BIN tendermint show-node-id "app.kubernetes.io/component": "chain", "app.kubernetes.io/id": "osmosis-1", "app.kubernetes.io/managed-by": "starship", - "app.kubernetes.io/name": "osmosis-1-genesis", + "app.kubernetes.io/name": "osmosis-1-validator", "app.kubernetes.io/part-of": "osmosis-1", "app.kubernetes.io/role": "validator", "app.kubernetes.io/type": "osmosis-1-statefulset", @@ -10041,13 +10838,149 @@ $CHAIN_BIN tendermint show-node-id "containers": [ { "command": [ - "bash", - "-c", - "#!/bin/bash -set -euo pipefail - -echo "Starting osmosisd validator..." -exec osmosisd start --home /root/.osmosisd --log_level info", + "bash", + "-c", + "set -eux +START_ARGS="" + + +# Starting the chain + +$CHAIN_BIN start $START_ARGS", + ], + "env": [ + { + "name": "DENOM", + "value": "uosmo", + }, + { + "name": "COINS", + "value": "100000000000000uosmo,100000000000000uion", + }, + { + "name": "CHAIN_BIN", + "value": "osmosisd", + }, + { + "name": "CHAIN_DIR", + "value": "/root/.osmosisd", + }, + { + "name": "CODE_REPO", + "value": "https://github.com/osmosis-labs/osmosis", + }, + { + "name": "DAEMON_HOME", + "value": "/root/.osmosisd", + }, + { + "name": "DAEMON_NAME", + "value": "osmosisd", + }, + { + "name": "CHAIN_ID", + "value": "osmosis-1", + }, + { + "name": "GENESIS_HOST", + "value": "osmosis-1-genesis", + }, + { + "name": "GENESIS_PORT", + "value": "8081", + }, + { + "name": "NAMESPACE", + "valueFrom": { + "fieldRef": { + "fieldPath": "metadata.namespace", + }, + }, + }, + { + "name": "KEYS_CONFIG", + "value": "/configs/keys.json", + }, + { + "name": "SLOGFILE", + "value": "slog.slog", + }, + ], + "image": "ghcr.io/cosmology-tech/starship/osmosis:v25.0.0", + "imagePullPolicy": "IfNotPresent", + "lifecycle": { + "postStart": { + "exec": { + "command": [ + "bash", + "-c", + "-e", + "until bash -e /scripts/chain-rpc-ready.sh http://localhost:26657; do + sleep 10 +done + +set -eux +export +VAL_INDEX=\${HOSTNAME##*-} +VAL_NAME="$(jq -r ".validators[0].name" $KEYS_CONFIG)-$VAL_INDEX" +echo "Validator Index: $VAL_INDEX, Key name: $VAL_NAME. Chain bin $CHAIN_BIN" + +VAL_ADDR=$($CHAIN_BIN keys show $VAL_NAME -a --keyring-backend="test") +echo "Transfer tokens to address $VAL_ADDR before trying to create validator. Best effort" +bash -e /scripts/transfer-tokens.sh \\ + $VAL_ADDR \\ + $DENOM \\ + http://$GENESIS_HOST.$NAMESPACE.svc.cluster.local:8000/credit \\ + "true" || true + +$CHAIN_BIN keys list --keyring-backend test | jq +VAL_NAME=$VAL_NAME bash -e /scripts/create-validator.sh", + ], + }, + }, + }, + "name": "validator", + "readinessProbe": { + "exec": { + "command": [ + "bash", + "-e", + "/scripts/chain-rpc-ready.sh", + "http://localhost:26657", + ], + }, + "initialDelaySeconds": 10, + "periodSeconds": 10, + "timeoutSeconds": 15, + }, + "resources": { + "limits": { + "cpu": "0.5", + "memory": "500M", + }, + "requests": { + "cpu": "0.5", + "memory": "500M", + }, + }, + "volumeMounts": [ + { + "mountPath": "/root/.osmosisd", + "name": "node", + }, + { + "mountPath": "/configs", + "name": "addresses", + }, + { + "mountPath": "/scripts", + "name": "scripts", + }, + ], + }, + { + "command": [ + "exposer", ], "env": [ { @@ -10083,47 +11016,61 @@ exec osmosisd start --home /root/.osmosisd --log_level info", "value": "osmosis-1", }, { - "name": "SLOGFILE", - "value": "slog.slog", + "name": "GENESIS_HOST", + "value": "osmosis-1-genesis", }, - ], - "image": "ghcr.io/cosmology-tech/starship/osmosis:v25.0.0", - "imagePullPolicy": "IfNotPresent", - "lifecycle": { - "postStart": { - "exec": { - "command": [ - "bash", - "-c", - "#!/bin/bash -echo "Validator post-start hook for osmosis-1" -# Add any post-start logic here", - ], + { + "name": "GENESIS_PORT", + "value": "8081", + }, + { + "name": "NAMESPACE", + "valueFrom": { + "fieldRef": { + "fieldPath": "metadata.namespace", + }, }, }, - }, - "name": "validator", - "readinessProbe": { - "exec": { - "command": [ - "bash", - "-e", - "/scripts/chain-rpc-ready.sh", - "http://localhost:26657", - ], + { + "name": "EXPOSER_HTTP_PORT", + "value": "8081", }, - "initialDelaySeconds": 10, - "periodSeconds": 10, - "timeoutSeconds": 15, - }, + { + "name": "EXPOSER_GRPC_PORT", + "value": "9099", + }, + { + "name": "EXPOSER_GENESIS_FILE", + "value": "/root/.osmosisd/config/genesis.json", + }, + { + "name": "EXPOSER_MNEMONIC_FILE", + "value": "/configs/keys.json", + }, + { + "name": "EXPOSER_PRIV_VAL_FILE", + "value": "/root/.osmosisd/config/priv_validator_key.json", + }, + { + "name": "EXPOSER_NODE_KEY_FILE", + "value": "/root/.osmosisd/config/node_key.json", + }, + { + "name": "EXPOSER_PRIV_VAL_STATE_FILE", + "value": "/root/.osmosisd/data/priv_validator_state.json", + }, + ], + "image": "ghcr.io/cosmology-tech/starship/exposer:latest", + "imagePullPolicy": "IfNotPresent", + "name": "exposer", "resources": { "limits": { - "cpu": "0.5", - "memory": "500M", + "cpu": "0.1", + "memory": "128M", }, "requests": { - "cpu": "0.5", - "memory": "500M", + "cpu": "0.1", + "memory": "128M", }, }, "volumeMounts": [ @@ -10135,24 +11082,78 @@ echo "Validator post-start hook for osmosis-1" "mountPath": "/configs", "name": "addresses", }, - { - "mountPath": "/scripts", - "name": "scripts", - }, ], }, ], "initContainers": [ + { + "command": [ + "/bin/sh", + "-c", + " + while [ $(curl -sw '%{http_code}' http://osmosis-1-genesis.$NAMESPACE.svc.cluster.local:$GENESIS_PORT/node_id -o /dev/null) -ne 200 ]; do + echo "Genesis validator does not seem to be ready for: osmosis-1. Waiting for it to start..." + echo "Checking: http://osmosis-1-genesis.$NAMESPACE.svc.cluster.local:$GENESIS_PORT/node_id" + sleep 10; + done +echo "Ready to start" +exit 0", + ], + "env": [ + { + "name": "GENESIS_PORT", + "value": "8081", + }, + { + "name": "NAMESPACE", + "valueFrom": { + "fieldRef": { + "fieldPath": "metadata.namespace", + }, + }, + }, + ], + "image": "curlimages/curl:latest", + "imagePullPolicy": "IfNotPresent", + "name": "wait-for-chains", + "resources": { + "limits": { + "cpu": "0.1", + "memory": "128M", + }, + "requests": { + "cpu": "0.1", + "memory": "128M", + }, + }, + }, { "command": [ "bash", "-c", - "#!/bin/bash -set -euo pipefail + "VAL_INDEX=\${HOSTNAME##*-} +echo "Validator Index: $VAL_INDEX" + + +if [ -f $CHAIN_DIR/config/genesis.json ]; then + echo "Genesis file exists, exiting early" + exit 0 +fi + +VAL_NAME=$(jq -r ".validators[0].name" $KEYS_CONFIG)-$VAL_INDEX +echo "Validator Index: $VAL_INDEX, Key name: $VAL_NAME" + +echo "Recover validator $VAL_NAME" +$CHAIN_BIN init $VAL_NAME --chain-id $CHAIN_ID +jq -r ".validators[0].mnemonic" $KEYS_CONFIG | $CHAIN_BIN keys add $VAL_NAME --index $VAL_INDEX --recover --keyring-backend="test" + +curl http://$GENESIS_HOST.$NAMESPACE.svc.cluster.local:$GENESIS_PORT/genesis -o $CHAIN_DIR/config/genesis.json +echo "Genesis file that we got....." +cat $CHAIN_DIR/config/genesis.json -echo "Initializing validator node for osmosis-1..." -osmosisd init validator-\${HOSTNAME##*-} --chain-id osmosis-1 --home /root/.osmosisd -echo "Validator initialization completed"", +echo "Create node id json file" +NODE_ID=$($CHAIN_BIN tendermint show-node-id) +echo '{"node_id":"'$NODE_ID'"}' > $CHAIN_DIR/config/node_id.json", ], "env": [ { @@ -10187,10 +11188,34 @@ echo "Validator initialization completed"", "name": "CHAIN_ID", "value": "osmosis-1", }, + { + "name": "GENESIS_HOST", + "value": "osmosis-1-genesis", + }, + { + "name": "GENESIS_PORT", + "value": "8081", + }, + { + "name": "NAMESPACE", + "valueFrom": { + "fieldRef": { + "fieldPath": "metadata.namespace", + }, + }, + }, { "name": "KEYS_CONFIG", "value": "/configs/keys.json", }, + { + "name": "FAUCET_ENABLED", + "value": "true", + }, + { + "name": "METRICS", + "value": "false", + }, ], "image": "ghcr.io/cosmology-tech/starship/osmosis:v25.0.0", "imagePullPolicy": "IfNotPresent", @@ -10224,7 +11249,26 @@ echo "Validator initialization completed"", "command": [ "bash", "-c", - "/scripts/update-config.sh", + "VAL_INDEX=\${HOSTNAME##*-} +echo "Validator Index: $VAL_INDEX" + + +echo "Running setup config script..." +bash -e /scripts/update-config.sh + +curl -s http://$GENESIS_HOST.$NAMESPACE.svc.cluster.local:$GENESIS_PORT/node_id +NODE_ID=$(curl -s http://$GENESIS_HOST.$NAMESPACE.svc.cluster.local:$GENESIS_PORT/node_id | jq -r ".node_id") +if [[ $NODE_ID == "" ]]; then + echo "Node ID is null, exiting early" + exit 1 +fi + +GENESIS_NODE_P2P=$NODE_ID@$GENESIS_HOST.$NAMESPACE.svc.cluster.local:26656 +echo "Node P2P: $GENESIS_NODE_P2P" +sed -i "s/persistent_peers = \\"\\"/persistent_peers = \\"$GENESIS_NODE_P2P\\"/g" $CHAIN_DIR/config/config.toml + +echo "Printing the whole config.toml file" +cat $CHAIN_DIR/config/config.toml", ], "env": [ { @@ -10259,6 +11303,22 @@ echo "Validator initialization completed"", "name": "CHAIN_ID", "value": "osmosis-1", }, + { + "name": "GENESIS_HOST", + "value": "osmosis-1-genesis", + }, + { + "name": "GENESIS_PORT", + "value": "8081", + }, + { + "name": "NAMESPACE", + "valueFrom": { + "fieldRef": { + "fieldPath": "metadata.namespace", + }, + }, + }, { "name": "KEYS_CONFIG", "value": "/configs/keys.json", @@ -10270,7 +11330,7 @@ echo "Validator initialization completed"", ], "image": "ghcr.io/cosmology-tech/starship/osmosis:v25.0.0", "imagePullPolicy": "IfNotPresent", - "name": "init-validator-config", + "name": "init-config", "resources": { "limits": { "cpu": "0.5", @@ -10314,6 +11374,10 @@ echo "Validator initialization completed"", }, "name": "scripts", }, + { + "emptyDir": {}, + "name": "faucet", + }, ], }, }, @@ -11948,7 +13012,7 @@ $CHAIN_BIN tendermint show-node-id "osmosis/genesis-patch-configmap.yaml": { "apiVersion": "v1", "data": { - "patch.json": "{ + "genesis.json": "{ "app_state": { "staking": { "params": { @@ -11977,6 +13041,8 @@ $CHAIN_BIN tendermint show-node-id "app.kubernetes.io/part-of": "osmosis-1", "app.kubernetes.io/role": "genesis-patch", "app.kubernetes.io/version": "4.0.0-alpha.0", + "starship.io/chain-id": "osmosis-1", + "starship.io/chain-name": "osmosis", "starship.io/name": "full-testnet", }, "name": "patch-osmosis-1", @@ -12122,8 +13188,10 @@ $CHAIN_BIN tendermint show-node-id "#!/bin/bash set -euo pipefail -echo "Starting osmosisd validator..." -exec osmosisd start --home /root/.osmosisd --log_level info", +START_ARGS="" + + +$CHAIN_BIN start $START_ARGS", ], "env": [ { @@ -12288,9 +13356,42 @@ exec osmosisd start --home /root/.osmosisd --log_level info", }, { "command": [ - "sh", + "bash", "-c", - "/faucet/faucet", + "CREDIT_COINS="" +FEES="" +for coin in \${COINS//,/ } +do + amt="\${coin//[!0-9]/}" + denom="\${coin//[0-9]/}" + + # Calculate the order of magnitude + if [ \${#amt} -gt 18 ]; then + creditAmt=$(echo $amt | sed -e "s/000000$//") + feesAmt=$(echo $amt | sed -e "s/0000000000000$//") + else + creditAmt=$(echo $amt | sed -e "s/0000$//") + feesAmt=$(echo $amt | sed -e "s/00000000$//") + fi + + if [[ $CREDIT_COINS == "" ]] + then + CREDIT_COINS="$creditAmt$denom" + FEES="$feesAmt$denom" + else + CREDIT_COINS="\${CREDIT_COINS},$creditAmt$denom" + fi +done + +export FAUCET_MNEMONIC=$(jq -r ".faucet[0].mnemonic" /configs/keys.json) + +export | grep "FAUCET" + +until bash -e /scripts/chain-rpc-ready.sh http://localhost:26657; do + sleep 10 +done + +/faucet/faucet --credit-coins="$CREDIT_COINS" --chain-fees="$FEES"", ], "env": [ { @@ -12298,41 +13399,33 @@ exec osmosisd start --home /root/.osmosisd --log_level info", "value": "2", }, { - "name": "FAUCET_PORT", + "name": "FAUCET_HTTP_PORT", "value": "8000", }, { - "name": "FAUCET_CHAIN_ID", - "value": "osmosis-1", - }, - { - "name": "FAUCET_CHAIN_DENOM", - "value": "uosmo", - }, - { - "name": "FAUCET_CHAIN_PREFIX", - "value": "osmo", - }, - { - "name": "FAUCET_AMOUNT_SEND", - "value": "10000000", - }, - { - "name": "FAUCET_AMOUNT_STAKE", - "value": "10000000", + "name": "FAUCET_CHAIN_BINARY", + "value": "osmosisd", }, { - "name": "FAUCET_RPC_ENDPOINT", - "value": "http://localhost:26657", + "name": "FAUCET_CHAIN_ID", + "value": "osmosis-1", }, { - "name": "FAUCET_REST_ENDPOINT", - "value": "http://localhost:1317", + "name": "COINS", + "value": "100000000000000uosmo,100000000000000uion", }, ], - "image": "busybox:1.34.1", + "image": "ghcr.io/cosmology-tech/starship/osmosis:v25.0.0", "imagePullPolicy": "IfNotPresent", "name": "faucet", + "readinessProbe": { + "httpGet": { + "path": "/status", + "port": "8000", + }, + "initialDelaySeconds": 30, + "periodSeconds": 10, + }, "resources": { "limits": { "cpu": "0.1", @@ -12352,6 +13445,10 @@ exec osmosisd start --home /root/.osmosisd --log_level info", "mountPath": "/faucet", "name": "faucet", }, + { + "mountPath": "/scripts", + "name": "scripts", + }, ], }, ], @@ -12360,7 +13457,31 @@ exec osmosisd start --home /root/.osmosisd --log_level info", "command": [ "bash", "-c", - "/scripts/create-genesis.sh", + "VAL_INDEX=\${HOSTNAME##*-} +echo "Validator Index: $VAL_INDEX" + +if [ -f $CHAIN_DIR/config/genesis.json ]; then + echo "Genesis file exists, exiting init container" + exit 0 +fi + +echo "Running setup genesis script..." +bash -e /scripts/create-genesis.sh +bash -e /scripts/update-genesis.sh + +echo "Create node id json file" +NODE_ID=$($CHAIN_BIN tendermint show-node-id) +echo '{"node_id":"'$NODE_ID'"}' > $CHAIN_DIR/config/node_id.json + +echo "Create consensus key json file" +$CHAIN_BIN tendermint show-validator > $CHAIN_DIR/config/consensus_key.json +cat $CHAIN_DIR/config/consensus_key.json + +echo "Add custom accounts and balances" +CHAIN_GENESIS_CMD=$($CHAIN_BIN 2>&1 | grep -q "genesis-related subcommands" && echo "genesis" || echo "") + +echo "Adding balance to osmo1e9ucjn5fjmetky5wezzcsccp7hqcwzrrhthpf5" +$CHAIN_BIN $CHAIN_GENESIS_CMD add-genesis-account osmo1e9ucjn5fjmetky5wezzcsccp7hqcwzrrhthpf5 2000000000000uosmo --keyring-backend="test"", ], "env": [ { @@ -12444,7 +13565,14 @@ exec osmosisd start --home /root/.osmosisd --log_level info", "command": [ "bash", "-c", - "/scripts/update-config.sh", + "VAL_INDEX=\${HOSTNAME##*-} +echo "Validator Index: $VAL_INDEX" + +echo "Running setup config script..." + +jq -s '.[0] * .[1]' $CHAIN_DIR/config/genesis.json /patch/genesis.json > $CHAIN_DIR/config/genesis.json.tmp && mv $CHAIN_DIR/config/genesis.json.tmp $CHAIN_DIR/config/genesis.json + +bash -e /scripts/update-config.sh", ], "env": [ { @@ -12570,6 +13698,10 @@ exec osmosisd start --home /root/.osmosisd --log_level info", }, "name": "patch", }, + { + "emptyDir": {}, + "name": "faucet", + }, ], }, }, @@ -13201,6 +14333,8 @@ $CHAIN_BIN tendermint show-node-id "app.kubernetes.io/part-of": "osmosis-1", "app.kubernetes.io/role": "setup-scripts", "app.kubernetes.io/version": "4.0.0-alpha.0", + "starship.io/chain-id": "osmosis-1", + "starship.io/chain-name": "osmosis", "starship.io/name": "full-testnet", }, "name": "setup-scripts-osmosis-1", @@ -14145,7 +15279,7 @@ $CHAIN_BIN tendermint show-node-id "test-chain/genesis-patch-configmap.yaml": { "apiVersion": "v1", "data": { - "patch.json": "{ + "genesis.json": "{ "app_state": { "staking": { "params": { @@ -14174,6 +15308,8 @@ $CHAIN_BIN tendermint show-node-id "app.kubernetes.io/part-of": "test-chain-1", "app.kubernetes.io/role": "genesis-patch", "app.kubernetes.io/version": "4.0.0-alpha.0", + "starship.io/chain-id": "test-chain-1", + "starship.io/chain-name": "test-chain", "starship.io/name": "special-testnet", }, "name": "patch-test-chain-1", @@ -14319,8 +15455,10 @@ $CHAIN_BIN tendermint show-node-id "#!/bin/bash set -euo pipefail -echo "Starting undefined validator..." -exec undefined start --home undefined --log_level info", +START_ARGS="" + + +$CHAIN_BIN start $START_ARGS", ], "env": [ { @@ -14482,9 +15620,42 @@ exec undefined start --home undefined --log_level info", }, { "command": [ - "sh", + "bash", "-c", - "/faucet/faucet", + "CREDIT_COINS="" +FEES="" +for coin in \${COINS//,/ } +do + amt="\${coin//[!0-9]/}" + denom="\${coin//[0-9]/}" + + # Calculate the order of magnitude + if [ \${#amt} -gt 18 ]; then + creditAmt=$(echo $amt | sed -e "s/000000$//") + feesAmt=$(echo $amt | sed -e "s/0000000000000$//") + else + creditAmt=$(echo $amt | sed -e "s/0000$//") + feesAmt=$(echo $amt | sed -e "s/00000000$//") + fi + + if [[ $CREDIT_COINS == "" ]] + then + CREDIT_COINS="$creditAmt$denom" + FEES="$feesAmt$denom" + else + CREDIT_COINS="\${CREDIT_COINS},$creditAmt$denom" + fi +done + +export FAUCET_MNEMONIC=$(jq -r ".faucet[0].mnemonic" /configs/keys.json) + +export | grep "FAUCET" + +until bash -e /scripts/chain-rpc-ready.sh http://localhost:26657; do + sleep 10 +done + +/faucet/faucet --credit-coins="$CREDIT_COINS" --chain-fees="$FEES"", ], "env": [ { @@ -14492,39 +15663,32 @@ exec undefined start --home undefined --log_level info", "value": "2", }, { - "name": "FAUCET_PORT", + "name": "FAUCET_HTTP_PORT", "value": "8000", }, { - "name": "FAUCET_CHAIN_ID", + "name": "FAUCET_CHAIN_BINARY", "value": "test-chain-1", }, { - "name": "FAUCET_CHAIN_DENOM", - }, - { - "name": "FAUCET_CHAIN_PREFIX", - }, - { - "name": "FAUCET_AMOUNT_SEND", - "value": "10000000", - }, - { - "name": "FAUCET_AMOUNT_STAKE", - "value": "10000000", - }, - { - "name": "FAUCET_RPC_ENDPOINT", - "value": "http://localhost:26657", + "name": "FAUCET_CHAIN_ID", + "value": "test-chain-1", }, { - "name": "FAUCET_REST_ENDPOINT", - "value": "http://localhost:1317", + "name": "COINS", + "value": "1000000000000000000undefined", }, ], - "image": "busybox:1.34.1", "imagePullPolicy": "IfNotPresent", "name": "faucet", + "readinessProbe": { + "httpGet": { + "path": "/status", + "port": "8000", + }, + "initialDelaySeconds": 30, + "periodSeconds": 10, + }, "resources": { "limits": { "cpu": "0.1", @@ -14544,6 +15708,10 @@ exec undefined start --home undefined --log_level info", "mountPath": "/faucet", "name": "faucet", }, + { + "mountPath": "/scripts", + "name": "scripts", + }, ], }, ], @@ -14552,7 +15720,31 @@ exec undefined start --home undefined --log_level info", "command": [ "bash", "-c", - "/scripts/create-genesis.sh", + "VAL_INDEX=\${HOSTNAME##*-} +echo "Validator Index: $VAL_INDEX" + +if [ -f $CHAIN_DIR/config/genesis.json ]; then + echo "Genesis file exists, exiting init container" + exit 0 +fi + +echo "Running setup genesis script..." +bash -e /scripts/create-genesis.sh +bash -e /scripts/update-genesis.sh + +echo "Create node id json file" +NODE_ID=$($CHAIN_BIN tendermint show-node-id) +echo '{"node_id":"'$NODE_ID'"}' > $CHAIN_DIR/config/node_id.json + +echo "Create consensus key json file" +$CHAIN_BIN tendermint show-validator > $CHAIN_DIR/config/consensus_key.json +cat $CHAIN_DIR/config/consensus_key.json + +echo "Add custom accounts and balances" +CHAIN_GENESIS_CMD=$($CHAIN_BIN 2>&1 | grep -q "genesis-related subcommands" && echo "genesis" || echo "") + +echo "Adding balance to osmo1e9ucjn5fjmetky5wezzcsccp7hqcwzrrhthpf5" +$CHAIN_BIN $CHAIN_GENESIS_CMD add-genesis-account osmo1e9ucjn5fjmetky5wezzcsccp7hqcwzrrhthpf5 2000000000000uosmo --keyring-backend="test"", ], "env": [ { @@ -14634,7 +15826,14 @@ exec undefined start --home undefined --log_level info", "command": [ "bash", "-c", - "/scripts/update-config.sh", + "VAL_INDEX=\${HOSTNAME##*-} +echo "Validator Index: $VAL_INDEX" + +echo "Running setup config script..." + +jq -s '.[0] * .[1]' $CHAIN_DIR/config/genesis.json /patch/genesis.json > $CHAIN_DIR/config/genesis.json.tmp && mv $CHAIN_DIR/config/genesis.json.tmp $CHAIN_DIR/config/genesis.json + +bash -e /scripts/update-config.sh", ], "env": [ { @@ -14758,6 +15957,10 @@ exec undefined start --home undefined --log_level info", }, "name": "patch", }, + { + "emptyDir": {}, + "name": "faucet", + }, ], }, }, @@ -15389,6 +16592,8 @@ $CHAIN_BIN tendermint show-node-id "app.kubernetes.io/part-of": "test-chain-1", "app.kubernetes.io/role": "setup-scripts", "app.kubernetes.io/version": "4.0.0-alpha.0", + "starship.io/chain-id": "test-chain-1", + "starship.io/chain-name": "test-chain", "starship.io/name": "special-testnet", }, "name": "setup-scripts-test-chain-1", @@ -16372,8 +17577,10 @@ $CHAIN_BIN tendermint show-node-id "#!/bin/bash set -euo pipefail -echo "Starting gaiad validator..." -exec gaiad start --home /root/.gaia --log_level info", +START_ARGS="" + + +$CHAIN_BIN start $START_ARGS", ], "env": [ { @@ -16542,7 +17749,28 @@ exec gaiad start --home /root/.gaia --log_level info", "command": [ "bash", "-c", - "/scripts/create-genesis.sh", + "VAL_INDEX=\${HOSTNAME##*-} +echo "Validator Index: $VAL_INDEX" + +if [ -f $CHAIN_DIR/config/genesis.json ]; then + echo "Genesis file exists, exiting init container" + exit 0 +fi + +echo "Running setup genesis script..." +bash -e /scripts/create-genesis.sh +bash -e /scripts/update-genesis.sh + +echo "Create node id json file" +NODE_ID=$($CHAIN_BIN tendermint show-node-id) +echo '{"node_id":"'$NODE_ID'"}' > $CHAIN_DIR/config/node_id.json + +echo "Create consensus key json file" +$CHAIN_BIN tendermint show-validator > $CHAIN_DIR/config/consensus_key.json +cat $CHAIN_DIR/config/consensus_key.json + +echo "Add custom accounts and balances" +CHAIN_GENESIS_CMD=$($CHAIN_BIN 2>&1 | grep -q "genesis-related subcommands" && echo "genesis" || echo "")", ], "env": [ { @@ -16626,7 +17854,12 @@ exec gaiad start --home /root/.gaia --log_level info", "command": [ "bash", "-c", - "/scripts/update-config.sh", + "VAL_INDEX=\${HOSTNAME##*-} +echo "Validator Index: $VAL_INDEX" + +echo "Running setup config script..." + +bash -e /scripts/update-config.sh", ], "env": [ { @@ -17347,6 +18580,8 @@ $CHAIN_BIN tendermint show-node-id "app.kubernetes.io/part-of": "cosmoshub-4", "app.kubernetes.io/role": "setup-scripts", "app.kubernetes.io/version": "4.0.0-alpha.0", + "starship.io/chain-id": "cosmoshub-4", + "starship.io/chain-name": "cosmoshub", "starship.io/name": "starship-generator-test", }, "name": "setup-scripts-cosmoshub-4", @@ -17440,7 +18675,7 @@ $CHAIN_BIN tendermint show-node-id "app.kubernetes.io/component": "chain", "app.kubernetes.io/id": "cosmoshub-4", "app.kubernetes.io/managed-by": "starship", - "app.kubernetes.io/name": "cosmoshub-4-genesis", + "app.kubernetes.io/name": "cosmoshub-4-validator", "app.kubernetes.io/part-of": "cosmoshub-4", "app.kubernetes.io/role": "validator", "app.kubernetes.io/type": "cosmoshub-4-statefulset", @@ -17483,11 +18718,13 @@ $CHAIN_BIN tendermint show-node-id "command": [ "bash", "-c", - "#!/bin/bash -set -euo pipefail + "set -eux +START_ARGS="" + -echo "Starting gaiad validator..." -exec gaiad start --home /root/.gaia --log_level info", +# Starting the chain + +$CHAIN_BIN start $START_ARGS", ], "env": [ { @@ -17522,6 +18759,26 @@ exec gaiad start --home /root/.gaia --log_level info", "name": "CHAIN_ID", "value": "cosmoshub-4", }, + { + "name": "GENESIS_HOST", + "value": "cosmoshub-4-genesis", + }, + { + "name": "GENESIS_PORT", + "value": "8081", + }, + { + "name": "NAMESPACE", + "valueFrom": { + "fieldRef": { + "fieldPath": "metadata.namespace", + }, + }, + }, + { + "name": "KEYS_CONFIG", + "value": "/configs/keys.json", + }, { "name": "SLOGFILE", "value": "slog.slog", @@ -17535,9 +18792,27 @@ exec gaiad start --home /root/.gaia --log_level info", "command": [ "bash", "-c", - "#!/bin/bash -echo "Validator post-start hook for cosmoshub-4" -# Add any post-start logic here", + "-e", + "until bash -e /scripts/chain-rpc-ready.sh http://localhost:26657; do + sleep 10 +done + +set -eux +export +VAL_INDEX=\${HOSTNAME##*-} +VAL_NAME="$(jq -r ".validators[0].name" $KEYS_CONFIG)-$VAL_INDEX" +echo "Validator Index: $VAL_INDEX, Key name: $VAL_NAME. Chain bin $CHAIN_BIN" + +VAL_ADDR=$($CHAIN_BIN keys show $VAL_NAME -a --keyring-backend="test") +echo "Transfer tokens to address $VAL_ADDR before trying to create validator. Best effort" +bash -e /scripts/transfer-tokens.sh \\ + $VAL_ADDR \\ + $DENOM \\ + http://$GENESIS_HOST.$NAMESPACE.svc.cluster.local:8000/credit \\ + "false" || true + +$CHAIN_BIN keys list --keyring-backend test | jq +VAL_NAME=$VAL_NAME bash -e /scripts/create-validator.sh", ], }, }, @@ -17558,41 +18833,205 @@ echo "Validator post-start hook for cosmoshub-4" }, "resources": { "limits": { - "cpu": "0.5", - "memory": "500M", + "cpu": "0.5", + "memory": "500M", + }, + "requests": { + "cpu": "0.5", + "memory": "500M", + }, + }, + "volumeMounts": [ + { + "mountPath": "/root/.gaia", + "name": "node", + }, + { + "mountPath": "/configs", + "name": "addresses", + }, + { + "mountPath": "/scripts", + "name": "scripts", + }, + ], + }, + { + "command": [ + "exposer", + ], + "env": [ + { + "name": "DENOM", + "value": "uatom", + }, + { + "name": "COINS", + "value": "100000000000000uatom", + }, + { + "name": "CHAIN_BIN", + "value": "gaiad", + }, + { + "name": "CHAIN_DIR", + "value": "/root/.gaia", + }, + { + "name": "CODE_REPO", + "value": "https://github.com/cosmos/gaia", + }, + { + "name": "DAEMON_HOME", + "value": "/root/.gaia", + }, + { + "name": "DAEMON_NAME", + "value": "gaiad", + }, + { + "name": "CHAIN_ID", + "value": "cosmoshub-4", + }, + { + "name": "GENESIS_HOST", + "value": "cosmoshub-4-genesis", + }, + { + "name": "GENESIS_PORT", + "value": "8081", + }, + { + "name": "NAMESPACE", + "valueFrom": { + "fieldRef": { + "fieldPath": "metadata.namespace", + }, + }, + }, + { + "name": "EXPOSER_HTTP_PORT", + "value": "8081", + }, + { + "name": "EXPOSER_GRPC_PORT", + "value": "9099", + }, + { + "name": "EXPOSER_GENESIS_FILE", + "value": "/root/.gaia/config/genesis.json", + }, + { + "name": "EXPOSER_MNEMONIC_FILE", + "value": "/configs/keys.json", + }, + { + "name": "EXPOSER_PRIV_VAL_FILE", + "value": "/root/.gaia/config/priv_validator_key.json", + }, + { + "name": "EXPOSER_NODE_KEY_FILE", + "value": "/root/.gaia/config/node_key.json", + }, + { + "name": "EXPOSER_PRIV_VAL_STATE_FILE", + "value": "/root/.gaia/data/priv_validator_state.json", + }, + ], + "image": "ghcr.io/cosmology-tech/starship/exposer:latest", + "imagePullPolicy": "IfNotPresent", + "name": "exposer", + "resources": { + "limits": { + "cpu": "0.1", + "memory": "128M", + }, + "requests": { + "cpu": "0.1", + "memory": "128M", + }, + }, + "volumeMounts": [ + { + "mountPath": "/root/.gaia", + "name": "node", + }, + { + "mountPath": "/configs", + "name": "addresses", + }, + ], + }, + ], + "initContainers": [ + { + "command": [ + "/bin/sh", + "-c", + " + while [ $(curl -sw '%{http_code}' http://cosmoshub-4-genesis.$NAMESPACE.svc.cluster.local:$GENESIS_PORT/node_id -o /dev/null) -ne 200 ]; do + echo "Genesis validator does not seem to be ready for: cosmoshub-4. Waiting for it to start..." + echo "Checking: http://cosmoshub-4-genesis.$NAMESPACE.svc.cluster.local:$GENESIS_PORT/node_id" + sleep 10; + done +echo "Ready to start" +exit 0", + ], + "env": [ + { + "name": "GENESIS_PORT", + "value": "8081", + }, + { + "name": "NAMESPACE", + "valueFrom": { + "fieldRef": { + "fieldPath": "metadata.namespace", + }, + }, + }, + ], + "image": "curlimages/curl:latest", + "imagePullPolicy": "IfNotPresent", + "name": "wait-for-chains", + "resources": { + "limits": { + "cpu": "0.1", + "memory": "128M", }, "requests": { - "cpu": "0.5", - "memory": "500M", + "cpu": "0.1", + "memory": "128M", }, }, - "volumeMounts": [ - { - "mountPath": "/root/.gaia", - "name": "node", - }, - { - "mountPath": "/configs", - "name": "addresses", - }, - { - "mountPath": "/scripts", - "name": "scripts", - }, - ], }, - ], - "initContainers": [ { "command": [ "bash", "-c", - "#!/bin/bash -set -euo pipefail + "VAL_INDEX=\${HOSTNAME##*-} +echo "Validator Index: $VAL_INDEX" + + +if [ -f $CHAIN_DIR/config/genesis.json ]; then + echo "Genesis file exists, exiting early" + exit 0 +fi + +VAL_NAME=$(jq -r ".validators[0].name" $KEYS_CONFIG)-$VAL_INDEX +echo "Validator Index: $VAL_INDEX, Key name: $VAL_NAME" + +echo "Recover validator $VAL_NAME" +$CHAIN_BIN init $VAL_NAME --chain-id $CHAIN_ID +jq -r ".validators[0].mnemonic" $KEYS_CONFIG | $CHAIN_BIN keys add $VAL_NAME --index $VAL_INDEX --recover --keyring-backend="test" -echo "Initializing validator node for cosmoshub-4..." -gaiad init validator-\${HOSTNAME##*-} --chain-id cosmoshub-4 --home /root/.gaia -echo "Validator initialization completed"", +curl http://$GENESIS_HOST.$NAMESPACE.svc.cluster.local:$GENESIS_PORT/genesis -o $CHAIN_DIR/config/genesis.json +echo "Genesis file that we got....." +cat $CHAIN_DIR/config/genesis.json + +echo "Create node id json file" +NODE_ID=$($CHAIN_BIN tendermint show-node-id) +echo '{"node_id":"'$NODE_ID'"}' > $CHAIN_DIR/config/node_id.json", ], "env": [ { @@ -17627,10 +19066,34 @@ echo "Validator initialization completed"", "name": "CHAIN_ID", "value": "cosmoshub-4", }, + { + "name": "GENESIS_HOST", + "value": "cosmoshub-4-genesis", + }, + { + "name": "GENESIS_PORT", + "value": "8081", + }, + { + "name": "NAMESPACE", + "valueFrom": { + "fieldRef": { + "fieldPath": "metadata.namespace", + }, + }, + }, { "name": "KEYS_CONFIG", "value": "/configs/keys.json", }, + { + "name": "FAUCET_ENABLED", + "value": "false", + }, + { + "name": "METRICS", + "value": "false", + }, ], "image": "ghcr.io/cosmology-tech/starship/gaia:v18.0.0", "imagePullPolicy": "IfNotPresent", @@ -17664,7 +19127,26 @@ echo "Validator initialization completed"", "command": [ "bash", "-c", - "/scripts/update-config.sh", + "VAL_INDEX=\${HOSTNAME##*-} +echo "Validator Index: $VAL_INDEX" + + +echo "Running setup config script..." +bash -e /scripts/update-config.sh + +curl -s http://$GENESIS_HOST.$NAMESPACE.svc.cluster.local:$GENESIS_PORT/node_id +NODE_ID=$(curl -s http://$GENESIS_HOST.$NAMESPACE.svc.cluster.local:$GENESIS_PORT/node_id | jq -r ".node_id") +if [[ $NODE_ID == "" ]]; then + echo "Node ID is null, exiting early" + exit 1 +fi + +GENESIS_NODE_P2P=$NODE_ID@$GENESIS_HOST.$NAMESPACE.svc.cluster.local:26656 +echo "Node P2P: $GENESIS_NODE_P2P" +sed -i "s/persistent_peers = \\"\\"/persistent_peers = \\"$GENESIS_NODE_P2P\\"/g" $CHAIN_DIR/config/config.toml + +echo "Printing the whole config.toml file" +cat $CHAIN_DIR/config/config.toml", ], "env": [ { @@ -17699,6 +19181,22 @@ echo "Validator initialization completed"", "name": "CHAIN_ID", "value": "cosmoshub-4", }, + { + "name": "GENESIS_HOST", + "value": "cosmoshub-4-genesis", + }, + { + "name": "GENESIS_PORT", + "value": "8081", + }, + { + "name": "NAMESPACE", + "valueFrom": { + "fieldRef": { + "fieldPath": "metadata.namespace", + }, + }, + }, { "name": "KEYS_CONFIG", "value": "/configs/keys.json", @@ -17710,7 +19208,7 @@ echo "Validator initialization completed"", ], "image": "ghcr.io/cosmology-tech/starship/gaia:v18.0.0", "imagePullPolicy": "IfNotPresent", - "name": "init-validator-config", + "name": "init-config", "resources": { "limits": { "cpu": "0.5", @@ -17893,8 +19391,10 @@ echo "Validator initialization completed"", "#!/bin/bash set -euo pipefail -echo "Starting osmosisd validator..." -exec osmosisd start --home /root/.osmosisd --log_level info", +START_ARGS="" + + +$CHAIN_BIN start $START_ARGS", ], "env": [ { @@ -18059,9 +19559,42 @@ exec osmosisd start --home /root/.osmosisd --log_level info", }, { "command": [ - "sh", + "bash", "-c", - "/faucet/faucet", + "CREDIT_COINS="" +FEES="" +for coin in \${COINS//,/ } +do + amt="\${coin//[!0-9]/}" + denom="\${coin//[0-9]/}" + + # Calculate the order of magnitude + if [ \${#amt} -gt 18 ]; then + creditAmt=$(echo $amt | sed -e "s/000000$//") + feesAmt=$(echo $amt | sed -e "s/0000000000000$//") + else + creditAmt=$(echo $amt | sed -e "s/0000$//") + feesAmt=$(echo $amt | sed -e "s/00000000$//") + fi + + if [[ $CREDIT_COINS == "" ]] + then + CREDIT_COINS="$creditAmt$denom" + FEES="$feesAmt$denom" + else + CREDIT_COINS="\${CREDIT_COINS},$creditAmt$denom" + fi +done + +export FAUCET_MNEMONIC=$(jq -r ".faucet[0].mnemonic" /configs/keys.json) + +export | grep "FAUCET" + +until bash -e /scripts/chain-rpc-ready.sh http://localhost:26657; do + sleep 10 +done + +/faucet/faucet --credit-coins="$CREDIT_COINS" --chain-fees="$FEES"", ], "env": [ { @@ -18069,41 +19602,33 @@ exec osmosisd start --home /root/.osmosisd --log_level info", "value": "5", }, { - "name": "FAUCET_PORT", + "name": "FAUCET_HTTP_PORT", "value": "8000", }, { - "name": "FAUCET_CHAIN_ID", - "value": "osmosis-1", - }, - { - "name": "FAUCET_CHAIN_DENOM", - "value": "uosmo", - }, - { - "name": "FAUCET_CHAIN_PREFIX", - "value": "osmo", - }, - { - "name": "FAUCET_AMOUNT_SEND", - "value": "10000000", - }, - { - "name": "FAUCET_AMOUNT_STAKE", - "value": "10000000", + "name": "FAUCET_CHAIN_BINARY", + "value": "osmosisd", }, { - "name": "FAUCET_RPC_ENDPOINT", - "value": "http://localhost:26657", + "name": "FAUCET_CHAIN_ID", + "value": "osmosis-1", }, { - "name": "FAUCET_REST_ENDPOINT", - "value": "http://localhost:1317", + "name": "COINS", + "value": "100000000000000uosmo,100000000000000uion", }, ], - "image": "busybox:1.34.1", + "image": "ghcr.io/cosmology-tech/starship/osmosis:v25.0.0", "imagePullPolicy": "IfNotPresent", "name": "faucet", + "readinessProbe": { + "httpGet": { + "path": "/status", + "port": "8000", + }, + "initialDelaySeconds": 30, + "periodSeconds": 10, + }, "resources": { "limits": { "cpu": "0.1", @@ -18123,6 +19648,10 @@ exec osmosisd start --home /root/.osmosisd --log_level info", "mountPath": "/faucet", "name": "faucet", }, + { + "mountPath": "/scripts", + "name": "scripts", + }, ], }, ], @@ -18131,7 +19660,28 @@ exec osmosisd start --home /root/.osmosisd --log_level info", "command": [ "bash", "-c", - "/scripts/create-genesis.sh", + "VAL_INDEX=\${HOSTNAME##*-} +echo "Validator Index: $VAL_INDEX" + +if [ -f $CHAIN_DIR/config/genesis.json ]; then + echo "Genesis file exists, exiting init container" + exit 0 +fi + +echo "Running setup genesis script..." +bash -e /scripts/create-genesis.sh +bash -e /scripts/update-genesis.sh + +echo "Create node id json file" +NODE_ID=$($CHAIN_BIN tendermint show-node-id) +echo '{"node_id":"'$NODE_ID'"}' > $CHAIN_DIR/config/node_id.json + +echo "Create consensus key json file" +$CHAIN_BIN tendermint show-validator > $CHAIN_DIR/config/consensus_key.json +cat $CHAIN_DIR/config/consensus_key.json + +echo "Add custom accounts and balances" +CHAIN_GENESIS_CMD=$($CHAIN_BIN 2>&1 | grep -q "genesis-related subcommands" && echo "genesis" || echo "")", ], "env": [ { @@ -18215,7 +19765,12 @@ exec osmosisd start --home /root/.osmosisd --log_level info", "command": [ "bash", "-c", - "/scripts/update-config.sh", + "VAL_INDEX=\${HOSTNAME##*-} +echo "Validator Index: $VAL_INDEX" + +echo "Running setup config script..." + +bash -e /scripts/update-config.sh", ], "env": [ { @@ -18331,6 +19886,10 @@ exec osmosisd start --home /root/.osmosisd --log_level info", }, "name": "scripts", }, + { + "emptyDir": {}, + "name": "faucet", + }, ], }, }, @@ -18962,6 +20521,8 @@ $CHAIN_BIN tendermint show-node-id "app.kubernetes.io/part-of": "osmosis-1", "app.kubernetes.io/role": "setup-scripts", "app.kubernetes.io/version": "4.0.0-alpha.0", + "starship.io/chain-id": "osmosis-1", + "starship.io/chain-name": "osmosis", "starship.io/name": "starship-generator-test", }, "name": "setup-scripts-osmosis-1", @@ -19055,7 +20616,7 @@ $CHAIN_BIN tendermint show-node-id "app.kubernetes.io/component": "chain", "app.kubernetes.io/id": "osmosis-1", "app.kubernetes.io/managed-by": "starship", - "app.kubernetes.io/name": "osmosis-1-genesis", + "app.kubernetes.io/name": "osmosis-1-validator", "app.kubernetes.io/part-of": "osmosis-1", "app.kubernetes.io/role": "validator", "app.kubernetes.io/type": "osmosis-1-statefulset", @@ -19096,13 +20657,149 @@ $CHAIN_BIN tendermint show-node-id "containers": [ { "command": [ - "bash", - "-c", - "#!/bin/bash -set -euo pipefail - -echo "Starting osmosisd validator..." -exec osmosisd start --home /root/.osmosisd --log_level info", + "bash", + "-c", + "set -eux +START_ARGS="" + + +# Starting the chain + +$CHAIN_BIN start $START_ARGS", + ], + "env": [ + { + "name": "DENOM", + "value": "uosmo", + }, + { + "name": "COINS", + "value": "100000000000000uosmo,100000000000000uion", + }, + { + "name": "CHAIN_BIN", + "value": "osmosisd", + }, + { + "name": "CHAIN_DIR", + "value": "/root/.osmosisd", + }, + { + "name": "CODE_REPO", + "value": "https://github.com/osmosis-labs/osmosis", + }, + { + "name": "DAEMON_HOME", + "value": "/root/.osmosisd", + }, + { + "name": "DAEMON_NAME", + "value": "osmosisd", + }, + { + "name": "CHAIN_ID", + "value": "osmosis-1", + }, + { + "name": "GENESIS_HOST", + "value": "osmosis-1-genesis", + }, + { + "name": "GENESIS_PORT", + "value": "8081", + }, + { + "name": "NAMESPACE", + "valueFrom": { + "fieldRef": { + "fieldPath": "metadata.namespace", + }, + }, + }, + { + "name": "KEYS_CONFIG", + "value": "/configs/keys.json", + }, + { + "name": "SLOGFILE", + "value": "slog.slog", + }, + ], + "image": "ghcr.io/cosmology-tech/starship/osmosis:v25.0.0", + "imagePullPolicy": "IfNotPresent", + "lifecycle": { + "postStart": { + "exec": { + "command": [ + "bash", + "-c", + "-e", + "until bash -e /scripts/chain-rpc-ready.sh http://localhost:26657; do + sleep 10 +done + +set -eux +export +VAL_INDEX=\${HOSTNAME##*-} +VAL_NAME="$(jq -r ".validators[0].name" $KEYS_CONFIG)-$VAL_INDEX" +echo "Validator Index: $VAL_INDEX, Key name: $VAL_NAME. Chain bin $CHAIN_BIN" + +VAL_ADDR=$($CHAIN_BIN keys show $VAL_NAME -a --keyring-backend="test") +echo "Transfer tokens to address $VAL_ADDR before trying to create validator. Best effort" +bash -e /scripts/transfer-tokens.sh \\ + $VAL_ADDR \\ + $DENOM \\ + http://$GENESIS_HOST.$NAMESPACE.svc.cluster.local:8000/credit \\ + "true" || true + +$CHAIN_BIN keys list --keyring-backend test | jq +VAL_NAME=$VAL_NAME bash -e /scripts/create-validator.sh", + ], + }, + }, + }, + "name": "validator", + "readinessProbe": { + "exec": { + "command": [ + "bash", + "-e", + "/scripts/chain-rpc-ready.sh", + "http://localhost:26657", + ], + }, + "initialDelaySeconds": 10, + "periodSeconds": 10, + "timeoutSeconds": 15, + }, + "resources": { + "limits": { + "cpu": "0.5", + "memory": "500M", + }, + "requests": { + "cpu": "0.5", + "memory": "500M", + }, + }, + "volumeMounts": [ + { + "mountPath": "/root/.osmosisd", + "name": "node", + }, + { + "mountPath": "/configs", + "name": "addresses", + }, + { + "mountPath": "/scripts", + "name": "scripts", + }, + ], + }, + { + "command": [ + "exposer", ], "env": [ { @@ -19138,47 +20835,61 @@ exec osmosisd start --home /root/.osmosisd --log_level info", "value": "osmosis-1", }, { - "name": "SLOGFILE", - "value": "slog.slog", + "name": "GENESIS_HOST", + "value": "osmosis-1-genesis", }, - ], - "image": "ghcr.io/cosmology-tech/starship/osmosis:v25.0.0", - "imagePullPolicy": "IfNotPresent", - "lifecycle": { - "postStart": { - "exec": { - "command": [ - "bash", - "-c", - "#!/bin/bash -echo "Validator post-start hook for osmosis-1" -# Add any post-start logic here", - ], + { + "name": "GENESIS_PORT", + "value": "8081", + }, + { + "name": "NAMESPACE", + "valueFrom": { + "fieldRef": { + "fieldPath": "metadata.namespace", + }, }, }, - }, - "name": "validator", - "readinessProbe": { - "exec": { - "command": [ - "bash", - "-e", - "/scripts/chain-rpc-ready.sh", - "http://localhost:26657", - ], + { + "name": "EXPOSER_HTTP_PORT", + "value": "8081", }, - "initialDelaySeconds": 10, - "periodSeconds": 10, - "timeoutSeconds": 15, - }, + { + "name": "EXPOSER_GRPC_PORT", + "value": "9099", + }, + { + "name": "EXPOSER_GENESIS_FILE", + "value": "/root/.osmosisd/config/genesis.json", + }, + { + "name": "EXPOSER_MNEMONIC_FILE", + "value": "/configs/keys.json", + }, + { + "name": "EXPOSER_PRIV_VAL_FILE", + "value": "/root/.osmosisd/config/priv_validator_key.json", + }, + { + "name": "EXPOSER_NODE_KEY_FILE", + "value": "/root/.osmosisd/config/node_key.json", + }, + { + "name": "EXPOSER_PRIV_VAL_STATE_FILE", + "value": "/root/.osmosisd/data/priv_validator_state.json", + }, + ], + "image": "ghcr.io/cosmology-tech/starship/exposer:latest", + "imagePullPolicy": "IfNotPresent", + "name": "exposer", "resources": { "limits": { - "cpu": "0.5", - "memory": "500M", + "cpu": "0.1", + "memory": "128M", }, "requests": { - "cpu": "0.5", - "memory": "500M", + "cpu": "0.1", + "memory": "128M", }, }, "volumeMounts": [ @@ -19190,24 +20901,78 @@ echo "Validator post-start hook for osmosis-1" "mountPath": "/configs", "name": "addresses", }, - { - "mountPath": "/scripts", - "name": "scripts", - }, ], }, ], "initContainers": [ + { + "command": [ + "/bin/sh", + "-c", + " + while [ $(curl -sw '%{http_code}' http://osmosis-1-genesis.$NAMESPACE.svc.cluster.local:$GENESIS_PORT/node_id -o /dev/null) -ne 200 ]; do + echo "Genesis validator does not seem to be ready for: osmosis-1. Waiting for it to start..." + echo "Checking: http://osmosis-1-genesis.$NAMESPACE.svc.cluster.local:$GENESIS_PORT/node_id" + sleep 10; + done +echo "Ready to start" +exit 0", + ], + "env": [ + { + "name": "GENESIS_PORT", + "value": "8081", + }, + { + "name": "NAMESPACE", + "valueFrom": { + "fieldRef": { + "fieldPath": "metadata.namespace", + }, + }, + }, + ], + "image": "curlimages/curl:latest", + "imagePullPolicy": "IfNotPresent", + "name": "wait-for-chains", + "resources": { + "limits": { + "cpu": "0.1", + "memory": "128M", + }, + "requests": { + "cpu": "0.1", + "memory": "128M", + }, + }, + }, { "command": [ "bash", "-c", - "#!/bin/bash -set -euo pipefail + "VAL_INDEX=\${HOSTNAME##*-} +echo "Validator Index: $VAL_INDEX" + + +if [ -f $CHAIN_DIR/config/genesis.json ]; then + echo "Genesis file exists, exiting early" + exit 0 +fi -echo "Initializing validator node for osmosis-1..." -osmosisd init validator-\${HOSTNAME##*-} --chain-id osmosis-1 --home /root/.osmosisd -echo "Validator initialization completed"", +VAL_NAME=$(jq -r ".validators[0].name" $KEYS_CONFIG)-$VAL_INDEX +echo "Validator Index: $VAL_INDEX, Key name: $VAL_NAME" + +echo "Recover validator $VAL_NAME" +$CHAIN_BIN init $VAL_NAME --chain-id $CHAIN_ID +jq -r ".validators[0].mnemonic" $KEYS_CONFIG | $CHAIN_BIN keys add $VAL_NAME --index $VAL_INDEX --recover --keyring-backend="test" + +curl http://$GENESIS_HOST.$NAMESPACE.svc.cluster.local:$GENESIS_PORT/genesis -o $CHAIN_DIR/config/genesis.json +echo "Genesis file that we got....." +cat $CHAIN_DIR/config/genesis.json + +echo "Create node id json file" +NODE_ID=$($CHAIN_BIN tendermint show-node-id) +echo '{"node_id":"'$NODE_ID'"}' > $CHAIN_DIR/config/node_id.json", ], "env": [ { @@ -19242,10 +21007,34 @@ echo "Validator initialization completed"", "name": "CHAIN_ID", "value": "osmosis-1", }, + { + "name": "GENESIS_HOST", + "value": "osmosis-1-genesis", + }, + { + "name": "GENESIS_PORT", + "value": "8081", + }, + { + "name": "NAMESPACE", + "valueFrom": { + "fieldRef": { + "fieldPath": "metadata.namespace", + }, + }, + }, { "name": "KEYS_CONFIG", "value": "/configs/keys.json", }, + { + "name": "FAUCET_ENABLED", + "value": "true", + }, + { + "name": "METRICS", + "value": "false", + }, ], "image": "ghcr.io/cosmology-tech/starship/osmosis:v25.0.0", "imagePullPolicy": "IfNotPresent", @@ -19279,7 +21068,26 @@ echo "Validator initialization completed"", "command": [ "bash", "-c", - "/scripts/update-config.sh", + "VAL_INDEX=\${HOSTNAME##*-} +echo "Validator Index: $VAL_INDEX" + + +echo "Running setup config script..." +bash -e /scripts/update-config.sh + +curl -s http://$GENESIS_HOST.$NAMESPACE.svc.cluster.local:$GENESIS_PORT/node_id +NODE_ID=$(curl -s http://$GENESIS_HOST.$NAMESPACE.svc.cluster.local:$GENESIS_PORT/node_id | jq -r ".node_id") +if [[ $NODE_ID == "" ]]; then + echo "Node ID is null, exiting early" + exit 1 +fi + +GENESIS_NODE_P2P=$NODE_ID@$GENESIS_HOST.$NAMESPACE.svc.cluster.local:26656 +echo "Node P2P: $GENESIS_NODE_P2P" +sed -i "s/persistent_peers = \\"\\"/persistent_peers = \\"$GENESIS_NODE_P2P\\"/g" $CHAIN_DIR/config/config.toml + +echo "Printing the whole config.toml file" +cat $CHAIN_DIR/config/config.toml", ], "env": [ { @@ -19314,6 +21122,22 @@ echo "Validator initialization completed"", "name": "CHAIN_ID", "value": "osmosis-1", }, + { + "name": "GENESIS_HOST", + "value": "osmosis-1-genesis", + }, + { + "name": "GENESIS_PORT", + "value": "8081", + }, + { + "name": "NAMESPACE", + "valueFrom": { + "fieldRef": { + "fieldPath": "metadata.namespace", + }, + }, + }, { "name": "KEYS_CONFIG", "value": "/configs/keys.json", @@ -19325,7 +21149,7 @@ echo "Validator initialization completed"", ], "image": "ghcr.io/cosmology-tech/starship/osmosis:v25.0.0", "imagePullPolicy": "IfNotPresent", - "name": "init-validator-config", + "name": "init-config", "resources": { "limits": { "cpu": "0.5", @@ -19369,6 +21193,10 @@ echo "Validator initialization completed"", }, "name": "scripts", }, + { + "emptyDir": {}, + "name": "faucet", + }, ], }, }, @@ -20129,7 +21957,7 @@ $CHAIN_BIN tendermint show-node-id "osmosis/genesis-patch-configmap.yaml": { "apiVersion": "v1", "data": { - "patch.json": "{ + "genesis.json": "{ "app_state": { "staking": { "params": { @@ -20158,6 +21986,8 @@ $CHAIN_BIN tendermint show-node-id "app.kubernetes.io/part-of": "osmosis-1", "app.kubernetes.io/role": "genesis-patch", "app.kubernetes.io/version": "4.0.0-alpha.0", + "starship.io/chain-id": "osmosis-1", + "starship.io/chain-name": "osmosis", "starship.io/name": "starship-generator-test", }, "name": "patch-osmosis-1", @@ -20303,8 +22133,10 @@ $CHAIN_BIN tendermint show-node-id "#!/bin/bash set -euo pipefail -echo "Starting osmosisd validator..." -exec osmosisd start --home /root/.osmosisd --log_level info", +START_ARGS="" + + +$CHAIN_BIN start $START_ARGS", ], "env": [ { @@ -20469,9 +22301,42 @@ exec osmosisd start --home /root/.osmosisd --log_level info", }, { "command": [ - "sh", + "bash", "-c", - "/faucet/faucet", + "CREDIT_COINS="" +FEES="" +for coin in \${COINS//,/ } +do + amt="\${coin//[!0-9]/}" + denom="\${coin//[0-9]/}" + + # Calculate the order of magnitude + if [ \${#amt} -gt 18 ]; then + creditAmt=$(echo $amt | sed -e "s/000000$//") + feesAmt=$(echo $amt | sed -e "s/0000000000000$//") + else + creditAmt=$(echo $amt | sed -e "s/0000$//") + feesAmt=$(echo $amt | sed -e "s/00000000$//") + fi + + if [[ $CREDIT_COINS == "" ]] + then + CREDIT_COINS="$creditAmt$denom" + FEES="$feesAmt$denom" + else + CREDIT_COINS="\${CREDIT_COINS},$creditAmt$denom" + fi +done + +export FAUCET_MNEMONIC=$(jq -r ".faucet[0].mnemonic" /configs/keys.json) + +export | grep "FAUCET" + +until bash -e /scripts/chain-rpc-ready.sh http://localhost:26657; do + sleep 10 +done + +/faucet/faucet --credit-coins="$CREDIT_COINS" --chain-fees="$FEES"", ], "env": [ { @@ -20479,41 +22344,33 @@ exec osmosisd start --home /root/.osmosisd --log_level info", "value": "2", }, { - "name": "FAUCET_PORT", + "name": "FAUCET_HTTP_PORT", "value": "8000", }, { - "name": "FAUCET_CHAIN_ID", - "value": "osmosis-1", - }, - { - "name": "FAUCET_CHAIN_DENOM", - "value": "uosmo", - }, - { - "name": "FAUCET_CHAIN_PREFIX", - "value": "osmo", - }, - { - "name": "FAUCET_AMOUNT_SEND", - "value": "10000000", - }, - { - "name": "FAUCET_AMOUNT_STAKE", - "value": "10000000", + "name": "FAUCET_CHAIN_BINARY", + "value": "osmosisd", }, { - "name": "FAUCET_RPC_ENDPOINT", - "value": "http://localhost:26657", + "name": "FAUCET_CHAIN_ID", + "value": "osmosis-1", }, { - "name": "FAUCET_REST_ENDPOINT", - "value": "http://localhost:1317", + "name": "COINS", + "value": "100000000000000uosmo,100000000000000uion", }, ], - "image": "busybox:1.34.1", + "image": "ghcr.io/cosmology-tech/starship/osmosis:v25.0.0", "imagePullPolicy": "IfNotPresent", "name": "faucet", + "readinessProbe": { + "httpGet": { + "path": "/status", + "port": "8000", + }, + "initialDelaySeconds": 30, + "periodSeconds": 10, + }, "resources": { "limits": { "cpu": "0.1", @@ -20533,6 +22390,10 @@ exec osmosisd start --home /root/.osmosisd --log_level info", "mountPath": "/faucet", "name": "faucet", }, + { + "mountPath": "/scripts", + "name": "scripts", + }, ], }, ], @@ -20541,7 +22402,31 @@ exec osmosisd start --home /root/.osmosisd --log_level info", "command": [ "bash", "-c", - "/scripts/create-genesis.sh", + "VAL_INDEX=\${HOSTNAME##*-} +echo "Validator Index: $VAL_INDEX" + +if [ -f $CHAIN_DIR/config/genesis.json ]; then + echo "Genesis file exists, exiting init container" + exit 0 +fi + +echo "Running setup genesis script..." +bash -e /scripts/create-genesis.sh +bash -e /scripts/update-genesis.sh + +echo "Create node id json file" +NODE_ID=$($CHAIN_BIN tendermint show-node-id) +echo '{"node_id":"'$NODE_ID'"}' > $CHAIN_DIR/config/node_id.json + +echo "Create consensus key json file" +$CHAIN_BIN tendermint show-validator > $CHAIN_DIR/config/consensus_key.json +cat $CHAIN_DIR/config/consensus_key.json + +echo "Add custom accounts and balances" +CHAIN_GENESIS_CMD=$($CHAIN_BIN 2>&1 | grep -q "genesis-related subcommands" && echo "genesis" || echo "") + +echo "Adding balance to osmo1e9ucjn5fjmetky5wezzcsccp7hqcwzrrhthpf5" +$CHAIN_BIN $CHAIN_GENESIS_CMD add-genesis-account osmo1e9ucjn5fjmetky5wezzcsccp7hqcwzrrhthpf5 2000000000000uosmo --keyring-backend="test"", ], "env": [ { @@ -20625,7 +22510,14 @@ exec osmosisd start --home /root/.osmosisd --log_level info", "command": [ "bash", "-c", - "/scripts/update-config.sh", + "VAL_INDEX=\${HOSTNAME##*-} +echo "Validator Index: $VAL_INDEX" + +echo "Running setup config script..." + +jq -s '.[0] * .[1]' $CHAIN_DIR/config/genesis.json /patch/genesis.json > $CHAIN_DIR/config/genesis.json.tmp && mv $CHAIN_DIR/config/genesis.json.tmp $CHAIN_DIR/config/genesis.json + +bash -e /scripts/update-config.sh", ], "env": [ { @@ -20751,6 +22643,10 @@ exec osmosisd start --home /root/.osmosisd --log_level info", }, "name": "patch", }, + { + "emptyDir": {}, + "name": "faucet", + }, ], }, }, @@ -21382,6 +23278,8 @@ $CHAIN_BIN tendermint show-node-id "app.kubernetes.io/part-of": "osmosis-1", "app.kubernetes.io/role": "setup-scripts", "app.kubernetes.io/version": "4.0.0-alpha.0", + "starship.io/chain-id": "osmosis-1", + "starship.io/chain-name": "osmosis", "starship.io/name": "starship-generator-test", }, "name": "setup-scripts-osmosis-1", diff --git a/packages/packages/generator/__tests__/__snapshots__/cosmos.test.ts.snap b/packages/packages/generator/__tests__/__snapshots__/cosmos.test.ts.snap index 5242f056b..975ee8041 100644 --- a/packages/packages/generator/__tests__/__snapshots__/cosmos.test.ts.snap +++ b/packages/packages/generator/__tests__/__snapshots__/cosmos.test.ts.snap @@ -55,6 +55,8 @@ exports[`Cosmos Generator Tests Manifest Generation should generate ICS consumer "app.kubernetes.io/part-of": "osmosis-1", "app.kubernetes.io/role": "ics-proposal", "app.kubernetes.io/version": "4.0.0-alpha.0", + "starship.io/chain-id": "osmosis-1", + "starship.io/chain-name": "osmosis", "starship.io/name": "starship-generator-test", }, "name": "consumer-proposal-osmosis-1", @@ -1018,8 +1020,10 @@ $CHAIN_BIN tendermint show-node-id "#!/bin/bash set -euo pipefail -echo "Starting osmosisd validator..." -exec osmosisd start --home /root/.osmosisd --log_level info", +START_ARGS="" + + +$CHAIN_BIN start $START_ARGS", ], "env": [ { @@ -1184,9 +1188,42 @@ exec osmosisd start --home /root/.osmosisd --log_level info", }, { "command": [ - "sh", + "bash", "-c", - "/faucet/faucet", + "CREDIT_COINS="" +FEES="" +for coin in \${COINS//,/ } +do + amt="\${coin//[!0-9]/}" + denom="\${coin//[0-9]/}" + + # Calculate the order of magnitude + if [ \${#amt} -gt 18 ]; then + creditAmt=$(echo $amt | sed -e "s/000000$//") + feesAmt=$(echo $amt | sed -e "s/0000000000000$//") + else + creditAmt=$(echo $amt | sed -e "s/0000$//") + feesAmt=$(echo $amt | sed -e "s/00000000$//") + fi + + if [[ $CREDIT_COINS == "" ]] + then + CREDIT_COINS="$creditAmt$denom" + FEES="$feesAmt$denom" + else + CREDIT_COINS="\${CREDIT_COINS},$creditAmt$denom" + fi +done + +export FAUCET_MNEMONIC=$(jq -r ".faucet[0].mnemonic" /configs/keys.json) + +export | grep "FAUCET" + +until bash -e /scripts/chain-rpc-ready.sh http://localhost:26657; do + sleep 10 +done + +/faucet/faucet --credit-coins="$CREDIT_COINS" --chain-fees="$FEES"", ], "env": [ { @@ -1194,41 +1231,33 @@ exec osmosisd start --home /root/.osmosisd --log_level info", "value": "2", }, { - "name": "FAUCET_PORT", + "name": "FAUCET_HTTP_PORT", "value": "8000", }, { - "name": "FAUCET_CHAIN_ID", - "value": "osmosis-1", - }, - { - "name": "FAUCET_CHAIN_DENOM", - "value": "uosmo", - }, - { - "name": "FAUCET_CHAIN_PREFIX", - "value": "osmo", - }, - { - "name": "FAUCET_AMOUNT_SEND", - "value": "10000000", - }, - { - "name": "FAUCET_AMOUNT_STAKE", - "value": "10000000", + "name": "FAUCET_CHAIN_BINARY", + "value": "osmosisd", }, { - "name": "FAUCET_RPC_ENDPOINT", - "value": "http://localhost:26657", + "name": "FAUCET_CHAIN_ID", + "value": "osmosis-1", }, { - "name": "FAUCET_REST_ENDPOINT", - "value": "http://localhost:1317", + "name": "COINS", + "value": "100000000000000uosmo,100000000000000uion", }, ], - "image": "busybox:1.34.1", + "image": "ghcr.io/cosmology-tech/starship/osmosis:v25.0.0", "imagePullPolicy": "IfNotPresent", "name": "faucet", + "readinessProbe": { + "httpGet": { + "path": "/status", + "port": "8000", + }, + "initialDelaySeconds": 30, + "periodSeconds": 10, + }, "resources": { "limits": { "cpu": "0.1", @@ -1248,6 +1277,10 @@ exec osmosisd start --home /root/.osmosisd --log_level info", "mountPath": "/faucet", "name": "faucet", }, + { + "mountPath": "/scripts", + "name": "scripts", + }, ], }, ], @@ -1256,7 +1289,28 @@ exec osmosisd start --home /root/.osmosisd --log_level info", "command": [ "bash", "-c", - "/scripts/create-genesis.sh", + "VAL_INDEX=\${HOSTNAME##*-} +echo "Validator Index: $VAL_INDEX" + +if [ -f $CHAIN_DIR/config/genesis.json ]; then + echo "Genesis file exists, exiting init container" + exit 0 +fi + +echo "Running setup genesis script..." +bash -e /scripts/create-genesis.sh +bash -e /scripts/update-genesis.sh + +echo "Create node id json file" +NODE_ID=$($CHAIN_BIN tendermint show-node-id) +echo '{"node_id":"'$NODE_ID'"}' > $CHAIN_DIR/config/node_id.json + +echo "Create consensus key json file" +$CHAIN_BIN tendermint show-validator > $CHAIN_DIR/config/consensus_key.json +cat $CHAIN_DIR/config/consensus_key.json + +echo "Add custom accounts and balances" +CHAIN_GENESIS_CMD=$($CHAIN_BIN 2>&1 | grep -q "genesis-related subcommands" && echo "genesis" || echo "")", ], "env": [ { @@ -1340,7 +1394,12 @@ exec osmosisd start --home /root/.osmosisd --log_level info", "command": [ "bash", "-c", - "/scripts/update-config.sh", + "VAL_INDEX=\${HOSTNAME##*-} +echo "Validator Index: $VAL_INDEX" + +echo "Running setup config script..." + +bash -e /scripts/update-config.sh", ], "env": [ { @@ -1456,6 +1515,10 @@ exec osmosisd start --home /root/.osmosisd --log_level info", }, "name": "scripts", }, + { + "emptyDir": {}, + "name": "faucet", + }, ], }, }, @@ -1469,7 +1532,7 @@ exec osmosisd start --home /root/.osmosisd --log_level info", "app.kubernetes.io/component": "chain", "app.kubernetes.io/id": "osmosis-1", "app.kubernetes.io/managed-by": "starship", - "app.kubernetes.io/name": "osmosis-1-genesis", + "app.kubernetes.io/name": "osmosis-1-validator", "app.kubernetes.io/part-of": "osmosis-1", "app.kubernetes.io/role": "validator", "app.kubernetes.io/type": "osmosis-1-statefulset", @@ -1512,11 +1575,13 @@ exec osmosisd start --home /root/.osmosisd --log_level info", "command": [ "bash", "-c", - "#!/bin/bash -set -euo pipefail + "set -eux +START_ARGS="" + -echo "Starting osmosisd validator..." -exec osmosisd start --home /root/.osmosisd --log_level info", +# Starting the chain + +$CHAIN_BIN start $START_ARGS", ], "env": [ { @@ -1551,6 +1616,26 @@ exec osmosisd start --home /root/.osmosisd --log_level info", "name": "CHAIN_ID", "value": "osmosis-1", }, + { + "name": "GENESIS_HOST", + "value": "osmosis-1-genesis", + }, + { + "name": "GENESIS_PORT", + "value": "8081", + }, + { + "name": "NAMESPACE", + "valueFrom": { + "fieldRef": { + "fieldPath": "metadata.namespace", + }, + }, + }, + { + "name": "KEYS_CONFIG", + "value": "/configs/keys.json", + }, { "name": "SLOGFILE", "value": "slog.slog", @@ -1564,9 +1649,27 @@ exec osmosisd start --home /root/.osmosisd --log_level info", "command": [ "bash", "-c", - "#!/bin/bash -echo "Validator post-start hook for osmosis-1" -# Add any post-start logic here", + "-e", + "until bash -e /scripts/chain-rpc-ready.sh http://localhost:26657; do + sleep 10 +done + +set -eux +export +VAL_INDEX=\${HOSTNAME##*-} +VAL_NAME="$(jq -r ".validators[0].name" $KEYS_CONFIG)-$VAL_INDEX" +echo "Validator Index: $VAL_INDEX, Key name: $VAL_NAME. Chain bin $CHAIN_BIN" + +VAL_ADDR=$($CHAIN_BIN keys show $VAL_NAME -a --keyring-backend="test") +echo "Transfer tokens to address $VAL_ADDR before trying to create validator. Best effort" +bash -e /scripts/transfer-tokens.sh \\ + $VAL_ADDR \\ + $DENOM \\ + http://$GENESIS_HOST.$NAMESPACE.svc.cluster.local:8000/credit \\ + "true" || true + +$CHAIN_BIN keys list --keyring-backend test | jq +VAL_NAME=$VAL_NAME bash -e /scripts/create-validator.sh", ], }, }, @@ -1610,18 +1713,182 @@ echo "Validator post-start hook for osmosis-1" }, ], }, + { + "command": [ + "exposer", + ], + "env": [ + { + "name": "DENOM", + "value": "uosmo", + }, + { + "name": "COINS", + "value": "100000000000000uosmo,100000000000000uion", + }, + { + "name": "CHAIN_BIN", + "value": "osmosisd", + }, + { + "name": "CHAIN_DIR", + "value": "/root/.osmosisd", + }, + { + "name": "CODE_REPO", + "value": "https://github.com/osmosis-labs/osmosis", + }, + { + "name": "DAEMON_HOME", + "value": "/root/.osmosisd", + }, + { + "name": "DAEMON_NAME", + "value": "osmosisd", + }, + { + "name": "CHAIN_ID", + "value": "osmosis-1", + }, + { + "name": "GENESIS_HOST", + "value": "osmosis-1-genesis", + }, + { + "name": "GENESIS_PORT", + "value": "8081", + }, + { + "name": "NAMESPACE", + "valueFrom": { + "fieldRef": { + "fieldPath": "metadata.namespace", + }, + }, + }, + { + "name": "EXPOSER_HTTP_PORT", + "value": "8081", + }, + { + "name": "EXPOSER_GRPC_PORT", + "value": "9099", + }, + { + "name": "EXPOSER_GENESIS_FILE", + "value": "/root/.osmosisd/config/genesis.json", + }, + { + "name": "EXPOSER_MNEMONIC_FILE", + "value": "/configs/keys.json", + }, + { + "name": "EXPOSER_PRIV_VAL_FILE", + "value": "/root/.osmosisd/config/priv_validator_key.json", + }, + { + "name": "EXPOSER_NODE_KEY_FILE", + "value": "/root/.osmosisd/config/node_key.json", + }, + { + "name": "EXPOSER_PRIV_VAL_STATE_FILE", + "value": "/root/.osmosisd/data/priv_validator_state.json", + }, + ], + "image": "ghcr.io/cosmology-tech/starship/exposer:latest", + "imagePullPolicy": "IfNotPresent", + "name": "exposer", + "resources": { + "limits": { + "cpu": "0.1", + "memory": "128M", + }, + "requests": { + "cpu": "0.1", + "memory": "128M", + }, + }, + "volumeMounts": [ + { + "mountPath": "/root/.osmosisd", + "name": "node", + }, + { + "mountPath": "/configs", + "name": "addresses", + }, + ], + }, ], "initContainers": [ + { + "command": [ + "/bin/sh", + "-c", + " + while [ $(curl -sw '%{http_code}' http://osmosis-1-genesis.$NAMESPACE.svc.cluster.local:$GENESIS_PORT/node_id -o /dev/null) -ne 200 ]; do + echo "Genesis validator does not seem to be ready for: osmosis-1. Waiting for it to start..." + echo "Checking: http://osmosis-1-genesis.$NAMESPACE.svc.cluster.local:$GENESIS_PORT/node_id" + sleep 10; + done +echo "Ready to start" +exit 0", + ], + "env": [ + { + "name": "GENESIS_PORT", + "value": "8081", + }, + { + "name": "NAMESPACE", + "valueFrom": { + "fieldRef": { + "fieldPath": "metadata.namespace", + }, + }, + }, + ], + "image": "curlimages/curl:latest", + "imagePullPolicy": "IfNotPresent", + "name": "wait-for-chains", + "resources": { + "limits": { + "cpu": "0.1", + "memory": "128M", + }, + "requests": { + "cpu": "0.1", + "memory": "128M", + }, + }, + }, { "command": [ "bash", "-c", - "#!/bin/bash -set -euo pipefail + "VAL_INDEX=\${HOSTNAME##*-} +echo "Validator Index: $VAL_INDEX" + + +if [ -f $CHAIN_DIR/config/genesis.json ]; then + echo "Genesis file exists, exiting early" + exit 0 +fi + +VAL_NAME=$(jq -r ".validators[0].name" $KEYS_CONFIG)-$VAL_INDEX +echo "Validator Index: $VAL_INDEX, Key name: $VAL_NAME" -echo "Initializing validator node for osmosis-1..." -osmosisd init validator-\${HOSTNAME##*-} --chain-id osmosis-1 --home /root/.osmosisd -echo "Validator initialization completed"", +echo "Recover validator $VAL_NAME" +$CHAIN_BIN init $VAL_NAME --chain-id $CHAIN_ID +jq -r ".validators[0].mnemonic" $KEYS_CONFIG | $CHAIN_BIN keys add $VAL_NAME --index $VAL_INDEX --recover --keyring-backend="test" + +curl http://$GENESIS_HOST.$NAMESPACE.svc.cluster.local:$GENESIS_PORT/genesis -o $CHAIN_DIR/config/genesis.json +echo "Genesis file that we got....." +cat $CHAIN_DIR/config/genesis.json + +echo "Create node id json file" +NODE_ID=$($CHAIN_BIN tendermint show-node-id) +echo '{"node_id":"'$NODE_ID'"}' > $CHAIN_DIR/config/node_id.json", ], "env": [ { @@ -1656,10 +1923,34 @@ echo "Validator initialization completed"", "name": "CHAIN_ID", "value": "osmosis-1", }, + { + "name": "GENESIS_HOST", + "value": "osmosis-1-genesis", + }, + { + "name": "GENESIS_PORT", + "value": "8081", + }, + { + "name": "NAMESPACE", + "valueFrom": { + "fieldRef": { + "fieldPath": "metadata.namespace", + }, + }, + }, { "name": "KEYS_CONFIG", "value": "/configs/keys.json", }, + { + "name": "FAUCET_ENABLED", + "value": "true", + }, + { + "name": "METRICS", + "value": "false", + }, ], "image": "ghcr.io/cosmology-tech/starship/osmosis:v25.0.0", "imagePullPolicy": "IfNotPresent", @@ -1693,7 +1984,26 @@ echo "Validator initialization completed"", "command": [ "bash", "-c", - "/scripts/update-config.sh", + "VAL_INDEX=\${HOSTNAME##*-} +echo "Validator Index: $VAL_INDEX" + + +echo "Running setup config script..." +bash -e /scripts/update-config.sh + +curl -s http://$GENESIS_HOST.$NAMESPACE.svc.cluster.local:$GENESIS_PORT/node_id +NODE_ID=$(curl -s http://$GENESIS_HOST.$NAMESPACE.svc.cluster.local:$GENESIS_PORT/node_id | jq -r ".node_id") +if [[ $NODE_ID == "" ]]; then + echo "Node ID is null, exiting early" + exit 1 +fi + +GENESIS_NODE_P2P=$NODE_ID@$GENESIS_HOST.$NAMESPACE.svc.cluster.local:26656 +echo "Node P2P: $GENESIS_NODE_P2P" +sed -i "s/persistent_peers = \\"\\"/persistent_peers = \\"$GENESIS_NODE_P2P\\"/g" $CHAIN_DIR/config/config.toml + +echo "Printing the whole config.toml file" +cat $CHAIN_DIR/config/config.toml", ], "env": [ { @@ -1728,6 +2038,22 @@ echo "Validator initialization completed"", "name": "CHAIN_ID", "value": "osmosis-1", }, + { + "name": "GENESIS_HOST", + "value": "osmosis-1-genesis", + }, + { + "name": "GENESIS_PORT", + "value": "8081", + }, + { + "name": "NAMESPACE", + "valueFrom": { + "fieldRef": { + "fieldPath": "metadata.namespace", + }, + }, + }, { "name": "KEYS_CONFIG", "value": "/configs/keys.json", @@ -1739,7 +2065,7 @@ echo "Validator initialization completed"", ], "image": "ghcr.io/cosmology-tech/starship/osmosis:v25.0.0", "imagePullPolicy": "IfNotPresent", - "name": "init-validator-config", + "name": "init-config", "resources": { "limits": { "cpu": "0.3", @@ -1783,6 +2109,10 @@ echo "Validator initialization completed"", }, "name": "scripts", }, + { + "emptyDir": {}, + "name": "faucet", + }, ], }, }, @@ -2414,6 +2744,8 @@ $CHAIN_BIN tendermint show-node-id "app.kubernetes.io/part-of": "osmosis-1", "app.kubernetes.io/role": "setup-scripts", "app.kubernetes.io/version": "4.0.0-alpha.0", + "starship.io/chain-id": "osmosis-1", + "starship.io/chain-name": "osmosis", "starship.io/name": "starship-generator-test", }, "name": "setup-scripts-osmosis-1", @@ -3304,8 +3636,10 @@ $CHAIN_BIN tendermint show-node-id "#!/bin/bash set -euo pipefail -echo "Starting osmosisd validator..." -exec osmosisd start --home /root/.osmosisd --log_level info", +START_ARGS="" + + +$CHAIN_BIN start $START_ARGS", ], "env": [ { @@ -3470,9 +3804,42 @@ exec osmosisd start --home /root/.osmosisd --log_level info", }, { "command": [ - "sh", + "bash", "-c", - "/faucet/faucet", + "CREDIT_COINS="" +FEES="" +for coin in \${COINS//,/ } +do + amt="\${coin//[!0-9]/}" + denom="\${coin//[0-9]/}" + + # Calculate the order of magnitude + if [ \${#amt} -gt 18 ]; then + creditAmt=$(echo $amt | sed -e "s/000000$//") + feesAmt=$(echo $amt | sed -e "s/0000000000000$//") + else + creditAmt=$(echo $amt | sed -e "s/0000$//") + feesAmt=$(echo $amt | sed -e "s/00000000$//") + fi + + if [[ $CREDIT_COINS == "" ]] + then + CREDIT_COINS="$creditAmt$denom" + FEES="$feesAmt$denom" + else + CREDIT_COINS="\${CREDIT_COINS},$creditAmt$denom" + fi +done + +export FAUCET_MNEMONIC=$(jq -r ".faucet[0].mnemonic" /configs/keys.json) + +export | grep "FAUCET" + +until bash -e /scripts/chain-rpc-ready.sh http://localhost:26657; do + sleep 10 +done + +/faucet/faucet --credit-coins="$CREDIT_COINS" --chain-fees="$FEES"", ], "env": [ { @@ -3480,41 +3847,33 @@ exec osmosisd start --home /root/.osmosisd --log_level info", "value": "2", }, { - "name": "FAUCET_PORT", + "name": "FAUCET_HTTP_PORT", "value": "8000", }, { - "name": "FAUCET_CHAIN_ID", - "value": "osmosis-1", - }, - { - "name": "FAUCET_CHAIN_DENOM", - "value": "uosmo", - }, - { - "name": "FAUCET_CHAIN_PREFIX", - "value": "osmo", - }, - { - "name": "FAUCET_AMOUNT_SEND", - "value": "10000000", - }, - { - "name": "FAUCET_AMOUNT_STAKE", - "value": "10000000", + "name": "FAUCET_CHAIN_BINARY", + "value": "osmosisd", }, { - "name": "FAUCET_RPC_ENDPOINT", - "value": "http://localhost:26657", + "name": "FAUCET_CHAIN_ID", + "value": "osmosis-1", }, { - "name": "FAUCET_REST_ENDPOINT", - "value": "http://localhost:1317", + "name": "COINS", + "value": "100000000000000uosmo,100000000000000uion", }, ], - "image": "busybox:1.34.1", + "image": "ghcr.io/cosmology-tech/starship/osmosis:v25.0.0", "imagePullPolicy": "IfNotPresent", "name": "faucet", + "readinessProbe": { + "httpGet": { + "path": "/status", + "port": "8000", + }, + "initialDelaySeconds": 30, + "periodSeconds": 10, + }, "resources": { "limits": { "cpu": "0.1", @@ -3534,6 +3893,10 @@ exec osmosisd start --home /root/.osmosisd --log_level info", "mountPath": "/faucet", "name": "faucet", }, + { + "mountPath": "/scripts", + "name": "scripts", + }, ], }, ], @@ -3542,7 +3905,31 @@ exec osmosisd start --home /root/.osmosisd --log_level info", "command": [ "bash", "-c", - "/scripts/create-genesis.sh", + "VAL_INDEX=\${HOSTNAME##*-} +echo "Validator Index: $VAL_INDEX" + +if [ -f $CHAIN_DIR/config/genesis.json ]; then + echo "Genesis file exists, exiting init container" + exit 0 +fi + +echo "Running setup genesis script..." +bash -e /scripts/create-genesis.sh +bash -e /scripts/update-genesis.sh + +echo "Create node id json file" +NODE_ID=$($CHAIN_BIN tendermint show-node-id) +echo '{"node_id":"'$NODE_ID'"}' > $CHAIN_DIR/config/node_id.json + +echo "Create consensus key json file" +$CHAIN_BIN tendermint show-validator > $CHAIN_DIR/config/consensus_key.json +cat $CHAIN_DIR/config/consensus_key.json + +echo "Add custom accounts and balances" +CHAIN_GENESIS_CMD=$($CHAIN_BIN 2>&1 | grep -q "genesis-related subcommands" && echo "genesis" || echo "") + +echo "Adding balance to osmo1e9ucjn5fjmetky5wezzcsccp7hqcwzrrhthpf5" +$CHAIN_BIN $CHAIN_GENESIS_CMD add-genesis-account osmo1e9ucjn5fjmetky5wezzcsccp7hqcwzrrhthpf5 2000000000000uosmo --keyring-backend="test"", ], "env": [ { @@ -3626,7 +4013,14 @@ exec osmosisd start --home /root/.osmosisd --log_level info", "command": [ "bash", "-c", - "/scripts/update-config.sh", + "VAL_INDEX=\${HOSTNAME##*-} +echo "Validator Index: $VAL_INDEX" + +echo "Running setup config script..." + +jq -s '.[0] * .[1]' $CHAIN_DIR/config/genesis.json /patch/genesis.json > $CHAIN_DIR/config/genesis.json.tmp && mv $CHAIN_DIR/config/genesis.json.tmp $CHAIN_DIR/config/genesis.json + +bash -e /scripts/update-config.sh", ], "env": [ { @@ -3752,6 +4146,10 @@ exec osmosisd start --home /root/.osmosisd --log_level info", }, "name": "patch", }, + { + "emptyDir": {}, + "name": "faucet", + }, ], }, }, @@ -4383,6 +4781,8 @@ $CHAIN_BIN tendermint show-node-id "app.kubernetes.io/part-of": "osmosis-1", "app.kubernetes.io/role": "setup-scripts", "app.kubernetes.io/version": "4.0.0-alpha.0", + "starship.io/chain-id": "osmosis-1", + "starship.io/chain-name": "osmosis", "starship.io/name": "starship-generator-test", }, "name": "setup-scripts-osmosis-1", @@ -4391,7 +4791,7 @@ $CHAIN_BIN tendermint show-node-id { "apiVersion": "v1", "data": { - "patch.json": "{ + "genesis.json": "{ "app_state": { "staking": { "params": { @@ -4420,6 +4820,8 @@ $CHAIN_BIN tendermint show-node-id "app.kubernetes.io/part-of": "osmosis-1", "app.kubernetes.io/role": "genesis-patch", "app.kubernetes.io/version": "4.0.0-alpha.0", + "starship.io/chain-id": "osmosis-1", + "starship.io/chain-name": "osmosis", "starship.io/name": "starship-generator-test", }, "name": "patch-osmosis-1", @@ -4432,7 +4834,7 @@ exports[`Cosmos Generator Tests Manifest Generation should generate genesis patc { "apiVersion": "v1", "data": { - "patch.json": "{ + "genesis.json": "{ "app_state": { "staking": { "params": { @@ -4461,6 +4863,8 @@ exports[`Cosmos Generator Tests Manifest Generation should generate genesis patc "app.kubernetes.io/part-of": "osmosis-1", "app.kubernetes.io/role": "genesis-patch", "app.kubernetes.io/version": "4.0.0-alpha.0", + "starship.io/chain-id": "osmosis-1", + "starship.io/chain-name": "osmosis", "starship.io/name": "starship-generator-test", }, "name": "patch-osmosis-1", @@ -5344,8 +5748,10 @@ $CHAIN_BIN tendermint show-node-id "#!/bin/bash set -euo pipefail -echo "Starting gaiad validator..." -exec gaiad start --home /root/.gaia --log_level info", +START_ARGS="" +START_ARGS="--grpc-web.enable=false --transport=grpc --with-tendermint=false --address tcp://0.0.0.0:26658" + +$CHAIN_BIN start $START_ARGS", ], "env": [ { @@ -5501,7 +5907,28 @@ exec gaiad start --home /root/.gaia --log_level info", "command": [ "bash", "-c", - "/scripts/create-genesis.sh", + "VAL_INDEX=\${HOSTNAME##*-} +echo "Validator Index: $VAL_INDEX" + +if [ -f $CHAIN_DIR/config/genesis.json ]; then + echo "Genesis file exists, exiting init container" + exit 0 +fi + +echo "Running setup genesis script..." +bash -e /scripts/create-genesis.sh +bash -e /scripts/update-genesis.sh + +echo "Create node id json file" +NODE_ID=$($CHAIN_BIN tendermint show-node-id) +echo '{"node_id":"'$NODE_ID'"}' > $CHAIN_DIR/config/node_id.json + +echo "Create consensus key json file" +$CHAIN_BIN tendermint show-validator > $CHAIN_DIR/config/consensus_key.json +cat $CHAIN_DIR/config/consensus_key.json + +echo "Add custom accounts and balances" +CHAIN_GENESIS_CMD=$($CHAIN_BIN 2>&1 | grep -q "genesis-related subcommands" && echo "genesis" || echo "")", ], "env": [ { @@ -5585,7 +6012,12 @@ exec gaiad start --home /root/.gaia --log_level info", "command": [ "bash", "-c", - "/scripts/update-config.sh", + "VAL_INDEX=\${HOSTNAME##*-} +echo "Validator Index: $VAL_INDEX" + +echo "Running setup config script..." + +bash -e /scripts/update-config.sh", ], "env": [ { @@ -6306,6 +6738,8 @@ $CHAIN_BIN tendermint show-node-id "app.kubernetes.io/part-of": "cosmoshub-4", "app.kubernetes.io/role": "setup-scripts", "app.kubernetes.io/version": "4.0.0-alpha.0", + "starship.io/chain-id": "cosmoshub-4", + "starship.io/chain-name": "cosmoshub", "starship.io/name": "starship-generator-test", }, "name": "setup-scripts-cosmoshub-4", @@ -7199,8 +7633,10 @@ $CHAIN_BIN tendermint show-node-id "#!/bin/bash set -euo pipefail -echo "Starting osmosisd validator..." -exec osmosisd start --home /root/.osmosisd --log_level info", +START_ARGS="" + + +$CHAIN_BIN start $START_ARGS", ], "env": [ { @@ -7365,8 +7801,38 @@ exec osmosisd start --home /root/.osmosisd --log_level info", }, { "command": [ - "yarn", - "start", + "bash", + "-c", + "export FAUCET_TOKENS=$(printf '%s\\n' \${COINS//[[:digit:]]/}) +for coin in \${COINS//,/ } +do + var="FAUCET_CREDIT_AMOUNT_$(printf '%s\\n' \${coin//[[:digit:]]/} | tr '[:lower:]' '[:upper:]')" + amt="\${coin//[!0-9]/}" + + if [ \${#amt} -gt 18 ]; then + creditAmt=$(echo $amt | sed -e "s/000000$//") + feesAmt=$(echo $amt | sed -e "s/0000000000000$//") + else + creditAmt=$(echo $amt | sed -e "s/0000$//") + feesAmt=$(echo $amt | sed -e "s/00000000$//") + fi + + export $var="$creditAmt" +done + +export FAUCET_PATH_PATTERN="\${HD_PATH:0:$((\${#HD_PATH}-1))}a" +export FAUCET_MNEMONIC=$(jq -r ".faucet[0].mnemonic" /configs/keys.json) + +echo "FAUCET_MNEMONIC: $FAUCET_MNEMONIC" +echo "FAUCET_PATH_PATTERN: $FAUCET_PATH_PATTERN" + +export | grep "FAUCET" + +until bash -e /scripts/chain-rpc-ready.sh http://localhost:26657; do + sleep 10; +done + +/app/packages/faucet/bin/cosmos-faucet-dist start "http://localhost:26657"", ], "env": [ { @@ -7377,50 +7843,54 @@ exec osmosisd start --home /root/.osmosisd --log_level info", "name": "FAUCET_PORT", "value": "8000", }, + { + "name": "FAUCET_MEMO", + "value": "faucet txn", + }, { "name": "FAUCET_GAS_PRICE", - "value": "0.025", + "value": "1.25uosmo", }, { - "name": "FAUCET_PATH_PATTERN", - "value": "", + "name": "FAUCET_GAS_LIMIT", + "value": "2000000", }, { "name": "FAUCET_ADDRESS_PREFIX", "value": "osmo", }, { - "name": "FAUCET_TOKENS", - "value": "uosmo", - }, - { - "name": "FAUCET_CREDIT_AMOUNT_SEND", - "value": "10000000", - }, - { - "name": "FAUCET_CREDIT_AMOUNT_STAKE", - "value": "10000000", + "name": "FAUCET_REFILL_FACTOR", + "value": "8", }, { - "name": "FAUCET_MAX_CREDIT", - "value": "99999999", + "name": "FAUCET_REFILL_THRESHOLD", + "value": "20", }, { - "name": "FAUCET_MNEMONIC", - "value": "", + "name": "FAUCET_COOLDOWN_TIME", + "value": "0", }, { - "name": "FAUCET_CHAIN_ID", - "value": "osmosis-1", + "name": "COINS", + "value": "100000000000000uosmo,100000000000000uion", }, { - "name": "FAUCET_RPC_ENDPOINT", - "value": "http://localhost:26657", + "name": "HD_PATH", + "value": "m/44'/118'/0'/0/0", }, ], "image": "ghcr.io/hyperweb-io/starship/faucet:20250325-2207109", "imagePullPolicy": "IfNotPresent", "name": "faucet", + "readinessProbe": { + "httpGet": { + "path": "/status", + "port": "8000", + }, + "initialDelaySeconds": 30, + "periodSeconds": 10, + }, "resources": { "limits": { "cpu": "0.2", @@ -7436,6 +7906,10 @@ exec osmosisd start --home /root/.osmosisd --log_level info", "mountPath": "/configs", "name": "addresses", }, + { + "mountPath": "/scripts", + "name": "scripts", + }, ], }, ], @@ -7444,7 +7918,28 @@ exec osmosisd start --home /root/.osmosisd --log_level info", "command": [ "bash", "-c", - "/scripts/create-genesis.sh", + "VAL_INDEX=\${HOSTNAME##*-} +echo "Validator Index: $VAL_INDEX" + +if [ -f $CHAIN_DIR/config/genesis.json ]; then + echo "Genesis file exists, exiting init container" + exit 0 +fi + +echo "Running setup genesis script..." +bash -e /scripts/create-genesis.sh +bash -e /scripts/update-genesis.sh + +echo "Create node id json file" +NODE_ID=$($CHAIN_BIN tendermint show-node-id) +echo '{"node_id":"'$NODE_ID'"}' > $CHAIN_DIR/config/node_id.json + +echo "Create consensus key json file" +$CHAIN_BIN tendermint show-validator > $CHAIN_DIR/config/consensus_key.json +cat $CHAIN_DIR/config/consensus_key.json + +echo "Add custom accounts and balances" +CHAIN_GENESIS_CMD=$($CHAIN_BIN 2>&1 | grep -q "genesis-related subcommands" && echo "genesis" || echo "")", ], "env": [ { @@ -7528,7 +8023,12 @@ exec osmosisd start --home /root/.osmosisd --log_level info", "command": [ "bash", "-c", - "/scripts/update-config.sh", + "VAL_INDEX=\${HOSTNAME##*-} +echo "Validator Index: $VAL_INDEX" + +echo "Running setup config script..." + +bash -e /scripts/update-config.sh", ], "env": [ { @@ -8249,6 +8749,8 @@ $CHAIN_BIN tendermint show-node-id "app.kubernetes.io/part-of": "osmosis-1", "app.kubernetes.io/role": "setup-scripts", "app.kubernetes.io/version": "4.0.0-alpha.0", + "starship.io/chain-id": "osmosis-1", + "starship.io/chain-name": "osmosis", "starship.io/name": "starship-generator-test", }, "name": "setup-scripts-osmosis-1", @@ -9139,8 +9641,10 @@ $CHAIN_BIN tendermint show-node-id "#!/bin/bash set -euo pipefail -echo "Starting osmosisd validator..." -exec osmosisd start --home /root/.osmosisd --log_level info", +START_ARGS="" + + +$CHAIN_BIN start $START_ARGS", ], "env": [ { @@ -9305,9 +9809,42 @@ exec osmosisd start --home /root/.osmosisd --log_level info", }, { "command": [ - "sh", + "bash", "-c", - "/faucet/faucet", + "CREDIT_COINS="" +FEES="" +for coin in \${COINS//,/ } +do + amt="\${coin//[!0-9]/}" + denom="\${coin//[0-9]/}" + + # Calculate the order of magnitude + if [ \${#amt} -gt 18 ]; then + creditAmt=$(echo $amt | sed -e "s/000000$//") + feesAmt=$(echo $amt | sed -e "s/0000000000000$//") + else + creditAmt=$(echo $amt | sed -e "s/0000$//") + feesAmt=$(echo $amt | sed -e "s/00000000$//") + fi + + if [[ $CREDIT_COINS == "" ]] + then + CREDIT_COINS="$creditAmt$denom" + FEES="$feesAmt$denom" + else + CREDIT_COINS="\${CREDIT_COINS},$creditAmt$denom" + fi +done + +export FAUCET_MNEMONIC=$(jq -r ".faucet[0].mnemonic" /configs/keys.json) + +export | grep "FAUCET" + +until bash -e /scripts/chain-rpc-ready.sh http://localhost:26657; do + sleep 10 +done + +/faucet/faucet --credit-coins="$CREDIT_COINS" --chain-fees="$FEES"", ], "env": [ { @@ -9315,41 +9852,33 @@ exec osmosisd start --home /root/.osmosisd --log_level info", "value": "2", }, { - "name": "FAUCET_PORT", + "name": "FAUCET_HTTP_PORT", "value": "8000", }, { - "name": "FAUCET_CHAIN_ID", - "value": "osmosis-1", - }, - { - "name": "FAUCET_CHAIN_DENOM", - "value": "uosmo", - }, - { - "name": "FAUCET_CHAIN_PREFIX", - "value": "osmo", - }, - { - "name": "FAUCET_AMOUNT_SEND", - "value": "10000000", - }, - { - "name": "FAUCET_AMOUNT_STAKE", - "value": "10000000", + "name": "FAUCET_CHAIN_BINARY", + "value": "osmosisd", }, { - "name": "FAUCET_RPC_ENDPOINT", - "value": "http://localhost:26657", + "name": "FAUCET_CHAIN_ID", + "value": "osmosis-1", }, { - "name": "FAUCET_REST_ENDPOINT", - "value": "http://localhost:1317", + "name": "COINS", + "value": "100000000000000uosmo,100000000000000uion", }, ], - "image": "busybox:1.34.1", + "image": "ghcr.io/cosmology-tech/starship/osmosis:v25.0.0", "imagePullPolicy": "IfNotPresent", "name": "faucet", + "readinessProbe": { + "httpGet": { + "path": "/status", + "port": "8000", + }, + "initialDelaySeconds": 30, + "periodSeconds": 10, + }, "resources": { "limits": { "cpu": "0.1", @@ -9369,6 +9898,10 @@ exec osmosisd start --home /root/.osmosisd --log_level info", "mountPath": "/faucet", "name": "faucet", }, + { + "mountPath": "/scripts", + "name": "scripts", + }, ], }, ], @@ -9377,7 +9910,31 @@ exec osmosisd start --home /root/.osmosisd --log_level info", "command": [ "bash", "-c", - "/scripts/create-genesis.sh", + "VAL_INDEX=\${HOSTNAME##*-} +echo "Validator Index: $VAL_INDEX" + +if [ -f $CHAIN_DIR/config/genesis.json ]; then + echo "Genesis file exists, exiting init container" + exit 0 +fi + +echo "Running setup genesis script..." +bash -e /scripts/create-genesis.sh +bash -e /scripts/update-genesis.sh + +echo "Create node id json file" +NODE_ID=$($CHAIN_BIN tendermint show-node-id) +echo '{"node_id":"'$NODE_ID'"}' > $CHAIN_DIR/config/node_id.json + +echo "Create consensus key json file" +$CHAIN_BIN tendermint show-validator > $CHAIN_DIR/config/consensus_key.json +cat $CHAIN_DIR/config/consensus_key.json + +echo "Add custom accounts and balances" +CHAIN_GENESIS_CMD=$($CHAIN_BIN 2>&1 | grep -q "genesis-related subcommands" && echo "genesis" || echo "") + +echo "Adding balance to osmo1e9ucjn5fjmetky5wezzcsccp7hqcwzrrhthpf5" +$CHAIN_BIN $CHAIN_GENESIS_CMD add-genesis-account osmo1e9ucjn5fjmetky5wezzcsccp7hqcwzrrhthpf5 2000000000000uosmo --keyring-backend="test"", ], "env": [ { @@ -9461,7 +10018,14 @@ exec osmosisd start --home /root/.osmosisd --log_level info", "command": [ "bash", "-c", - "/scripts/update-config.sh", + "VAL_INDEX=\${HOSTNAME##*-} +echo "Validator Index: $VAL_INDEX" + +echo "Running setup config script..." + +jq -s '.[0] * .[1]' $CHAIN_DIR/config/genesis.json /patch/genesis.json > $CHAIN_DIR/config/genesis.json.tmp && mv $CHAIN_DIR/config/genesis.json.tmp $CHAIN_DIR/config/genesis.json + +bash -e /scripts/update-config.sh", ], "env": [ { @@ -9587,6 +10151,10 @@ exec osmosisd start --home /root/.osmosisd --log_level info", }, "name": "patch", }, + { + "emptyDir": {}, + "name": "faucet", + }, ], }, }, @@ -10218,6 +10786,8 @@ $CHAIN_BIN tendermint show-node-id "app.kubernetes.io/part-of": "osmosis-1", "app.kubernetes.io/role": "setup-scripts", "app.kubernetes.io/version": "4.0.0-alpha.0", + "starship.io/chain-id": "osmosis-1", + "starship.io/chain-name": "osmosis", "starship.io/name": "starship-generator-test", }, "name": "setup-scripts-osmosis-1", @@ -10226,7 +10796,7 @@ $CHAIN_BIN tendermint show-node-id { "apiVersion": "v1", "data": { - "patch.json": "{ + "genesis.json": "{ "app_state": { "staking": { "params": { @@ -10255,6 +10825,8 @@ $CHAIN_BIN tendermint show-node-id "app.kubernetes.io/part-of": "osmosis-1", "app.kubernetes.io/role": "genesis-patch", "app.kubernetes.io/version": "4.0.0-alpha.0", + "starship.io/chain-id": "osmosis-1", + "starship.io/chain-name": "osmosis", "starship.io/name": "starship-generator-test", }, "name": "patch-osmosis-1", diff --git a/packages/packages/generator/__tests__/cosmos.integration.test.ts b/packages/packages/generator/__tests__/cosmos.integration.test.ts index 7440267ad..4f8fb3102 100644 --- a/packages/packages/generator/__tests__/cosmos.integration.test.ts +++ b/packages/packages/generator/__tests__/cosmos.integration.test.ts @@ -1,7 +1,7 @@ import { existsSync, mkdirSync } from 'fs'; import { join } from 'path'; -import { CosmosBuilder } from '../src/builders/cosmos'; +import { CosmosBuilder } from '../src/builders/chains/cosmos'; import { applyDefaults } from '../src/defaults'; import { buildChainConfig, diff --git a/packages/packages/generator/__tests__/cosmos.test.ts b/packages/packages/generator/__tests__/cosmos.test.ts index a27982de6..f8dc7eda7 100644 --- a/packages/packages/generator/__tests__/cosmos.test.ts +++ b/packages/packages/generator/__tests__/cosmos.test.ts @@ -1,7 +1,7 @@ import { mkdirSync } from 'fs'; import { join } from 'path'; -import { CosmosBuilder } from '../src/builders/cosmos'; +import { CosmosBuilder } from '../src/builders/chains/cosmos'; import { applyDefaults } from '../src/defaults'; import { buildChainConfig, @@ -118,7 +118,7 @@ describe('Cosmos Generator Tests', () => { expect(patchConfigMap).toBeDefined(); expect(patchConfigMap?.kind).toBe('ConfigMap'); - const genesisJsonString = patchConfigMap?.data?.['patch.json'] as string; + const genesisJsonString = patchConfigMap?.data?.['genesis.json'] as string; const genesisData = JSON.parse(genesisJsonString || '{}'); expect(genesisData.app_state.staking.params.unbonding_time).toBe('5s'); diff --git a/packages/packages/generator/src/builders/chains/cosmos/genesis.ts b/packages/packages/generator/src/builders/chains/cosmos/genesis.ts index a5b391609..8b4117874 100644 --- a/packages/packages/generator/src/builders/chains/cosmos/genesis.ts +++ b/packages/packages/generator/src/builders/chains/cosmos/genesis.ts @@ -397,7 +397,7 @@ export class CosmosGenesisStatefulSetGenerator implements IGenerator { const faucet = chain.faucet as FaucetConfig; return { name: 'faucet', - image: faucet.image || 'ghcr.io/cosmology-tech/starship/faucet:latest', + image: faucet.image || this.config.faucet?.image || 'ghcr.io/cosmology-tech/starship/faucet:latest', imagePullPolicy: this.config.images?.imagePullPolicy || 'IfNotPresent', env: [ { From d9978139702ce02661fbc8064ba83864e078620e Mon Sep 17 00:00:00 2001 From: Anmol1696 Date: Mon, 30 Jun 2025 22:47:48 +0530 Subject: [PATCH 6/6] update cosmos based chain and genesis file to match helm --- .../generator/__tests__/cosmos.test.ts | 4 +- .../src/builders/chains/cosmos/configmap.ts | 28 +++-- .../src/builders/chains/cosmos/genesis.ts | 107 ++++++++++++------ .../src/builders/chains/cosmos/index.ts | 24 ++-- .../src/builders/chains/cosmos/statefulset.ts | 28 +++-- .../src/builders/chains/cosmos/validator.ts | 100 +++++++++++----- .../generator/src/builders/chains/index.ts | 6 +- .../generator/src/builders/relayers/index.ts | 3 +- packages/packages/generator/src/helpers.ts | 17 ++- 9 files changed, 221 insertions(+), 96 deletions(-) diff --git a/packages/packages/generator/__tests__/cosmos.test.ts b/packages/packages/generator/__tests__/cosmos.test.ts index f8dc7eda7..077a42410 100644 --- a/packages/packages/generator/__tests__/cosmos.test.ts +++ b/packages/packages/generator/__tests__/cosmos.test.ts @@ -118,7 +118,9 @@ describe('Cosmos Generator Tests', () => { expect(patchConfigMap).toBeDefined(); expect(patchConfigMap?.kind).toBe('ConfigMap'); - const genesisJsonString = patchConfigMap?.data?.['genesis.json'] as string; + const genesisJsonString = patchConfigMap?.data?.[ + 'genesis.json' + ] as string; const genesisData = JSON.parse(genesisJsonString || '{}'); expect(genesisData.app_state.staking.params.unbonding_time).toBe('5s'); diff --git a/packages/packages/generator/src/builders/chains/cosmos/configmap.ts b/packages/packages/generator/src/builders/chains/cosmos/configmap.ts index 83f4cea19..d827814e5 100644 --- a/packages/packages/generator/src/builders/chains/cosmos/configmap.ts +++ b/packages/packages/generator/src/builders/chains/cosmos/configmap.ts @@ -1,6 +1,5 @@ import { Chain, StarshipConfig } from '@starship-ci/types'; import * as fs from 'fs'; -import { ConfigMap } from 'kubernetesjs'; import * as path from 'path'; import { DefaultsManager } from '../../../defaults'; @@ -125,7 +124,11 @@ export class SetupScriptsConfigMapGenerator implements IGenerator { private chain: Chain; private scriptManager: ScriptManager; - constructor(chain: Chain, config: StarshipConfig, scriptManager: ScriptManager) { + constructor( + chain: Chain, + config: StarshipConfig, + scriptManager: ScriptManager + ) { this.config = config; this.chain = chain; this.scriptManager = scriptManager; @@ -242,7 +245,7 @@ export class IcsConsumerProposalConfigMapGenerator implements IGenerator { const providerChain = this.config.chains.find( (c) => c.id === this.chain.ics.provider ); - + if (!providerChain) { console.warn( `Warning: ICS Provider chain '${this.chain.ics.provider}' not found. Skipping ICS proposal for '${this.chain.id}'.` @@ -250,7 +253,8 @@ export class IcsConsumerProposalConfigMapGenerator implements IGenerator { return []; } - const processedProviderChain = this.defaultsManager.processChain(providerChain); + const processedProviderChain = + this.defaultsManager.processChain(providerChain); const proposal = { title: `Add ${this.chain.name} consumer chain`, @@ -313,13 +317,21 @@ export class CosmosConfigMapGenerator implements IGenerator { private scriptManager: ScriptManager; private generators: IGenerator[]; - constructor(chain: Chain, config: StarshipConfig, scriptManager: ScriptManager) { + constructor( + chain: Chain, + config: StarshipConfig, + scriptManager: ScriptManager + ) { this.config = config; this.chain = chain; this.scriptManager = scriptManager; - + this.generators = [ - new SetupScriptsConfigMapGenerator(this.chain, this.config, this.scriptManager), + new SetupScriptsConfigMapGenerator( + this.chain, + this.config, + this.scriptManager + ), new GenesisPatchConfigMapGenerator(this.chain, this.config), new IcsConsumerProposalConfigMapGenerator(this.chain, this.config) ]; @@ -340,7 +352,7 @@ export class GlobalConfigMapGenerator implements IGenerator { constructor(config: StarshipConfig, projectRoot?: string) { this.config = config; - + this.generators = [ new KeysConfigMapGenerator(this.config, projectRoot), new GlobalScriptsConfigMapGenerator(this.config, projectRoot) diff --git a/packages/packages/generator/src/builders/chains/cosmos/genesis.ts b/packages/packages/generator/src/builders/chains/cosmos/genesis.ts index 8b4117874..17e0627c2 100644 --- a/packages/packages/generator/src/builders/chains/cosmos/genesis.ts +++ b/packages/packages/generator/src/builders/chains/cosmos/genesis.ts @@ -4,7 +4,7 @@ import { Container, StatefulSet } from 'kubernetesjs'; import { DefaultsManager } from '../../../defaults'; import * as helpers from '../../../helpers'; import { ScriptManager } from '../../../scripts'; -import { IGenerator, Manifest } from '../../../types'; +import { IGenerator } from '../../../types'; import { getGeneratorVersion } from '../../../version'; export class CosmosGenesisStatefulSetGenerator implements IGenerator { @@ -13,7 +13,11 @@ export class CosmosGenesisStatefulSetGenerator implements IGenerator { private scriptManager: ScriptManager; private defaultsManager: DefaultsManager; - constructor(chain: Chain, config: StarshipConfig, scriptManager: ScriptManager) { + constructor( + chain: Chain, + config: StarshipConfig, + scriptManager: ScriptManager + ) { this.config = config; this.chain = chain; this.scriptManager = scriptManager; @@ -36,7 +40,7 @@ export class CosmosGenesisStatefulSetGenerator implements IGenerator { generate(): Array { const processedChain = this.defaultsManager.processChain(this.chain); - + return [ { apiVersion: 'apps/v1', @@ -74,7 +78,9 @@ export class CosmosGenesisStatefulSetGenerator implements IGenerator { }, spec: { ...((processedChain as any).imagePullSecrets - ? helpers.generateImagePullSecrets((processedChain as any).imagePullSecrets) + ? helpers.generateImagePullSecrets( + (processedChain as any).imagePullSecrets + ) : {}), initContainers: this.createInitContainers(processedChain), containers: this.createMainContainers(processedChain), @@ -109,7 +115,9 @@ export class CosmosGenesisStatefulSetGenerator implements IGenerator { if (chain.ics?.enabled) { // Add wait container for provider chain const providerChainId = chain.ics.provider || 'cosmoshub'; - initContainers.push(this.createIcsWaitInitContainer([providerChainId], exposerPort)); + initContainers.push( + this.createIcsWaitInitContainer([providerChainId], exposerPort) + ); initContainers.push(this.createIcsInitContainer(chain, exposerPort)); } @@ -254,11 +262,13 @@ export class CosmosGenesisStatefulSetGenerator implements IGenerator { // Need to get provider chain info - for now using a placeholder // In real implementation, this would need access to provider chain config const providerChainId = chain.ics?.provider || 'cosmoshub'; - const providerHostname = helpers.getChainName(providerChainId); - + const providerChain = this.config.chains.find( + (c) => c.id === providerChainId + ); + return { name: 'init-ics', - image: chain.image, // Should use provider chain image in real implementation + image: providerChain?.image, imagePullPolicy: this.config.images?.imagePullPolicy || 'IfNotPresent', env: [ ...helpers.getDefaultEnvVars(chain), @@ -273,7 +283,11 @@ export class CosmosGenesisStatefulSetGenerator implements IGenerator { }, { name: 'KEYS_CONFIG', value: '/configs/keys.json' } ], - command: ['bash', '-c', this.getIcsInitScript(chain, providerHostname)], + command: [ + 'bash', + '-c', + this.getIcsInitScript(chain, providerChain, exposerPort) + ], resources: helpers.getNodeResources(chain, this.config), volumeMounts: [ { mountPath: '/proposal', name: 'proposal' }, @@ -284,17 +298,16 @@ export class CosmosGenesisStatefulSetGenerator implements IGenerator { }; } - private createIcsWaitInitContainer(chainIDs: string[], port: number): Container { - return helpers.generateWaitInitContainer( - chainIDs, - port, - this.config - ); + private createIcsWaitInitContainer( + chainIDs: string[], + port: number + ): Container { + return helpers.generateWaitInitContainer(chainIDs, port, this.config); } private createValidatorContainer(chain: Chain): Container { const toBuild = chain.build?.enabled || chain.upgrade?.enabled; - + return { name: 'validator', image: chain.image, @@ -307,10 +320,19 @@ export class CosmosGenesisStatefulSetGenerator implements IGenerator { value: String(chain.faucet?.enabled || false) }, { name: 'SLOGFILE', value: 'slog.slog' }, - ...(toBuild ? [ - { name: 'DAEMON_NAME', value: chain.binary || helpers.getChainId(chain) }, - { name: 'DAEMON_HOME', value: chain.home || `/home/validator/.${helpers.getChainId(chain)}` } - ] : []), + ...(toBuild + ? [ + { + name: 'DAEMON_NAME', + value: chain.binary || helpers.getChainId(chain) + }, + { + name: 'DAEMON_HOME', + value: + chain.home || `/home/validator/.${helpers.getChainId(chain)}` + } + ] + : []), ...(chain.env || []).map((env: any) => ({ name: env.name, value: String(env.value) @@ -397,7 +419,10 @@ export class CosmosGenesisStatefulSetGenerator implements IGenerator { const faucet = chain.faucet as FaucetConfig; return { name: 'faucet', - image: faucet.image || this.config.faucet?.image || 'ghcr.io/cosmology-tech/starship/faucet:latest', + image: + faucet.image || + this.config.faucet?.image || + 'ghcr.io/cosmology-tech/starship/faucet:latest', imagePullPolicy: this.config.images?.imagePullPolicy || 'IfNotPresent', env: [ { @@ -415,7 +440,10 @@ export class CosmosGenesisStatefulSetGenerator implements IGenerator { { name: 'FAUCET_REFILL_FACTOR', value: '8' }, { name: 'FAUCET_REFILL_THRESHOLD', value: '20' }, { name: 'FAUCET_COOLDOWN_TIME', value: '0' }, - { name: 'COINS', value: chain.coins || `1000000000000000000${chain.denom}` }, + { + name: 'COINS', + value: chain.coins || `1000000000000000000${chain.denom}` + }, { name: 'HD_PATH', value: chain.hdPath || "m/44'/118'/0'/0/0" } ], command: ['bash', '-c', this.getCosmjsFaucetScript()], @@ -452,9 +480,15 @@ export class CosmosGenesisStatefulSetGenerator implements IGenerator { name: 'FAUCET_HTTP_PORT', value: String(faucet.ports?.rest || 8000) }, - { name: 'FAUCET_CHAIN_BINARY', value: chain.binary || helpers.getChainId(chain) }, + { + name: 'FAUCET_CHAIN_BINARY', + value: chain.binary || helpers.getChainId(chain) + }, { name: 'FAUCET_CHAIN_ID', value: helpers.getChainId(chain) }, - { name: 'COINS', value: chain.coins || `1000000000000000000${chain.denom}` } + { + name: 'COINS', + value: chain.coins || `1000000000000000000${chain.denom}` + } ], command: ['bash', '-c', this.getStarshipFaucetScript()], resources: helpers.getResourceObject( @@ -478,7 +512,7 @@ export class CosmosGenesisStatefulSetGenerator implements IGenerator { private getGenesisInitScript(chain: Chain): string { const toBuild = chain.build?.enabled || chain.upgrade?.enabled; - + let script = ` VAL_INDEX=\${HOSTNAME##*-} echo "Validator Index: $VAL_INDEX" @@ -528,7 +562,7 @@ $CHAIN_BIN $CHAIN_GENESIS_CMD add-genesis-account ${balance.address} ${balance.a private getConfigInitScript(chain: Chain): string { const toBuild = chain.build?.enabled || chain.upgrade?.enabled; - + let script = ` VAL_INDEX=\${HOSTNAME##*-} echo "Validator Index: $VAL_INDEX" @@ -570,9 +604,7 @@ bash -e /scripts/update-config.sh private getValidatorStartScript(chain: Chain): string { const toBuild = chain.build?.enabled || chain.upgrade?.enabled; - const chainBin = chain.binary || helpers.getChainId(chain); - const chainHome = chain.home || `/home/validator/.${helpers.getChainId(chain)}`; - + return `#!/bin/bash set -euo pipefail @@ -656,12 +688,17 @@ done `.trim(); } - private getIcsInitScript(chain: Chain, providerHostname: string): string { + private getIcsInitScript( + chain: Chain, + providerChain: Chain, + exposerPort: number + ): string { + const providerHostname = helpers.getChainName(providerChain.id); return ` export echo "Fetching priv keys from provider exposer" -curl -s http://${providerHostname}-genesis.$NAMESPACE.svc.cluster.local:8081/priv_keys | jq > $CHAIN_DIR/config/provider_priv_validator_key.json +curl -s http://${providerHostname}-genesis.$NAMESPACE.svc.cluster.local:${exposerPort}/priv_keys | jq > $CHAIN_DIR/config/provider_priv_validator_key.json cat $CHAIN_DIR/config/provider_priv_validator_key.json echo "Replace provider priv validator key with provider keys" @@ -669,15 +706,15 @@ mv $CHAIN_DIR/config/priv_validator_key.json $CHAIN_DIR/config/previous_priv_val mv $CHAIN_DIR/config/provider_priv_validator_key.json $CHAIN_DIR/config/priv_validator_key.json echo "Create consumer addition proposal" -DENOM=${chain.ics?.provider ? '$DENOM' : 'uatom'} \\ - CHAIN_ID=${chain.ics?.provider || 'cosmoshub'} \\ - CHAIN_BIN=${chain.binary || '$CHAIN_BIN'} \\ +DENOM=${providerChain?.denom} \\ + CHAIN_ID=${providerChain?.id} \\ + CHAIN_BIN=${providerChain?.binary || '$CHAIN_BIN'} \\ NODE_URL=http://${providerHostname}-genesis.$NAMESPACE.svc.cluster.local:26657 \\ PROPOSAL_FILE=/proposal/proposal.json \\ bash -e /scripts/create-ics.sh echo "create ccv state file" -${chain.binary || '$CHAIN_BIN'} query provider consumer-genesis ${helpers.getChainId(chain)} \\ +${providerChain?.binary || '$CHAIN_BIN'} query provider consumer-genesis ${chain.id} \\ --node http://${providerHostname}-genesis.$NAMESPACE.svc.cluster.local:26657 \\ -o json > $CHAIN_DIR/config/ccv-state.json cat $CHAIN_DIR/config/ccv-state.json | jq diff --git a/packages/packages/generator/src/builders/chains/cosmos/index.ts b/packages/packages/generator/src/builders/chains/cosmos/index.ts index 0822a49f9..22c6e0f6e 100644 --- a/packages/packages/generator/src/builders/chains/cosmos/index.ts +++ b/packages/packages/generator/src/builders/chains/cosmos/index.ts @@ -2,7 +2,10 @@ import { StarshipConfig } from '@starship-ci/types'; import { ScriptManager } from '../../../scripts'; import { IGenerator, Manifest } from '../../../types'; -import { CosmosConfigMapGenerator, GlobalConfigMapGenerator } from './configmap'; +import { + CosmosConfigMapGenerator, + GlobalConfigMapGenerator +} from './configmap'; import { CosmosServiceGenerator } from './service'; import { CosmosStatefulSetGenerator } from './statefulset'; @@ -21,9 +24,10 @@ export class CosmosBuilder implements IGenerator { this.generators = []; // Filter cosmos chains - const cosmosChains = this.config.chains?.filter( - (chain) => chain.name !== 'ethereum' && typeof chain.id === 'string' - ) || []; + const cosmosChains = + this.config.chains?.filter( + (chain) => chain.name !== 'ethereum' && typeof chain.id === 'string' + ) || []; if (cosmosChains.length === 0) { return; // No cosmos chains to process @@ -37,15 +41,19 @@ export class CosmosBuilder implements IGenerator { // Services this.generators.push(new CosmosServiceGenerator(chain, this.config)); - // StatefulSets - this.generators.push(new CosmosStatefulSetGenerator(chain, this.config, this.scriptManager)); + // StatefulSets + this.generators.push( + new CosmosStatefulSetGenerator(chain, this.config, this.scriptManager) + ); // ConfigMaps - this.generators.push(new CosmosConfigMapGenerator(chain, this.config, this.scriptManager)); + this.generators.push( + new CosmosConfigMapGenerator(chain, this.config, this.scriptManager) + ); }); } generate(): Manifest[] { return this.generators.flatMap((generator) => generator.generate()); } -} \ No newline at end of file +} diff --git a/packages/packages/generator/src/builders/chains/cosmos/statefulset.ts b/packages/packages/generator/src/builders/chains/cosmos/statefulset.ts index 15f12128f..283f6976d 100644 --- a/packages/packages/generator/src/builders/chains/cosmos/statefulset.ts +++ b/packages/packages/generator/src/builders/chains/cosmos/statefulset.ts @@ -15,24 +15,38 @@ export class CosmosStatefulSetGenerator implements IGenerator { private scriptManager: ScriptManager; private statefulSetGenerators: Array; - constructor(chain: Chain, config: StarshipConfig, scriptManager: ScriptManager) { + constructor( + chain: Chain, + config: StarshipConfig, + scriptManager: ScriptManager + ) { this.config = config; this.chain = chain; this.scriptManager = scriptManager; - + this.statefulSetGenerators = [ - new CosmosGenesisStatefulSetGenerator(this.chain, this.config, this.scriptManager) + new CosmosGenesisStatefulSetGenerator( + this.chain, + this.config, + this.scriptManager + ) ]; - + // Add validator StatefulSet if numValidators > 1 if (this.chain.numValidators && this.chain.numValidators > 1) { this.statefulSetGenerators.push( - new CosmosValidatorStatefulSetGenerator(this.chain, this.config, this.scriptManager) + new CosmosValidatorStatefulSetGenerator( + this.chain, + this.config, + this.scriptManager + ) ); } } generate(): Array { - return this.statefulSetGenerators.flatMap((generator) => generator.generate()); + return this.statefulSetGenerators.flatMap((generator) => + generator.generate() + ); } -} \ No newline at end of file +} diff --git a/packages/packages/generator/src/builders/chains/cosmos/validator.ts b/packages/packages/generator/src/builders/chains/cosmos/validator.ts index 76fe63c4e..d915ceb30 100644 --- a/packages/packages/generator/src/builders/chains/cosmos/validator.ts +++ b/packages/packages/generator/src/builders/chains/cosmos/validator.ts @@ -4,7 +4,7 @@ import { Container, StatefulSet } from 'kubernetesjs'; import { DefaultsManager } from '../../../defaults'; import * as helpers from '../../../helpers'; import { ScriptManager } from '../../../scripts'; -import { IGenerator, Manifest } from '../../../types'; +import { IGenerator } from '../../../types'; import { getGeneratorVersion } from '../../../version'; export class CosmosValidatorStatefulSetGenerator implements IGenerator { @@ -13,7 +13,11 @@ export class CosmosValidatorStatefulSetGenerator implements IGenerator { private scriptManager: ScriptManager; private defaultsManager: DefaultsManager; - constructor(chain: Chain, config: StarshipConfig, scriptManager: ScriptManager) { + constructor( + chain: Chain, + config: StarshipConfig, + scriptManager: ScriptManager + ) { this.config = config; this.chain = chain; this.scriptManager = scriptManager; @@ -36,7 +40,7 @@ export class CosmosValidatorStatefulSetGenerator implements IGenerator { generate(): Array { const processedChain = this.defaultsManager.processChain(this.chain); - + return [ { apiVersion: 'apps/v1', @@ -74,7 +78,9 @@ export class CosmosValidatorStatefulSetGenerator implements IGenerator { }, spec: { ...((processedChain as any).imagePullSecrets - ? helpers.generateImagePullSecrets((processedChain as any).imagePullSecrets) + ? helpers.generateImagePullSecrets( + (processedChain as any).imagePullSecrets + ) : {}), initContainers: this.createInitContainers(processedChain), containers: this.createMainContainers(processedChain), @@ -100,7 +106,7 @@ export class CosmosValidatorStatefulSetGenerator implements IGenerator { // Validator init container initContainers.push(this.createValidatorInitContainer(chain)); - // Validator config init container + // Validator config init container initContainers.push(this.createValidatorConfigContainer(chain)); // ICS init container if enabled @@ -135,11 +141,13 @@ export class CosmosValidatorStatefulSetGenerator implements IGenerator { private createIcsInitContainer(chain: Chain): Container { const providerChainId = chain.ics?.provider; const providerHostname = helpers.getChainName(providerChainId); - const providerChain = this.config.chains.find((c) => c.id === providerChainId); - + const providerChain = this.config.chains.find( + (c) => c.id === providerChainId + ); + return { name: 'init-ics', - image: chain.image, // Should use provider chain image in real implementation + image: providerChain?.image, // Should use provider chain image in real implementation imagePullPolicy: this.config.images?.imagePullPolicy || 'IfNotPresent', env: [ ...helpers.getDefaultEnvVars(chain), @@ -214,9 +222,15 @@ export class CosmosValidatorStatefulSetGenerator implements IGenerator { ...helpers.getDefaultEnvVars(chain), ...helpers.getChainEnvVars(chain), ...helpers.getTimeoutEnvVars(this.config.timeouts || {}), - ...helpers.getGenesisEnvVars(chain, this.config.exposer?.ports?.rest || 8081), + ...helpers.getGenesisEnvVars( + chain, + this.config.exposer?.ports?.rest || 8081 + ), { name: 'KEYS_CONFIG', value: '/configs/keys.json' }, - { name: 'FAUCET_ENABLED', value: String(chain.faucet?.enabled || false) }, + { + name: 'FAUCET_ENABLED', + value: String(chain.faucet?.enabled || false) + }, { name: 'METRICS', value: String(chain.metrics || false) } ], command: ['bash', '-c', this.getValidatorInitScript(chain)], @@ -234,7 +248,10 @@ export class CosmosValidatorStatefulSetGenerator implements IGenerator { ...helpers.getDefaultEnvVars(chain), ...helpers.getChainEnvVars(chain), ...helpers.getTimeoutEnvVars(this.config.timeouts || {}), - ...helpers.getGenesisEnvVars(chain, this.config.exposer?.ports?.rest || 8081), + ...helpers.getGenesisEnvVars( + chain, + this.config.exposer?.ports?.rest || 8081 + ), { name: 'KEYS_CONFIG', value: '/configs/keys.json' }, { name: 'METRICS', value: String(chain.metrics || false) } ], @@ -252,7 +269,10 @@ export class CosmosValidatorStatefulSetGenerator implements IGenerator { env: [ ...helpers.getDefaultEnvVars(chain), ...helpers.getChainEnvVars(chain), - ...helpers.getGenesisEnvVars(chain, this.config.exposer?.ports?.rest || 8081), + ...helpers.getGenesisEnvVars( + chain, + this.config.exposer?.ports?.rest || 8081 + ), { name: 'KEYS_CONFIG', value: '/configs/keys.json' }, { name: 'SLOGFILE', value: 'slog.slog' }, ...(chain.env || []).map((env: any) => ({ @@ -269,7 +289,12 @@ export class CosmosValidatorStatefulSetGenerator implements IGenerator { lifecycle: { postStart: { exec: { - command: ['bash', '-c', '-e', this.getValidatorPostStartScript(chain)] + command: [ + 'bash', + '-c', + '-e', + this.getValidatorPostStartScript(chain) + ] } } } @@ -297,22 +322,41 @@ export class CosmosValidatorStatefulSetGenerator implements IGenerator { private createExposerContainer(chain: Chain): Container { return { name: 'exposer', - image: this.config.exposer?.image || 'ghcr.io/cosmology-tech/starship/exposer:latest', + image: + this.config.exposer?.image || + 'ghcr.io/cosmology-tech/starship/exposer:latest', imagePullPolicy: this.config.images?.imagePullPolicy || 'IfNotPresent', env: [ ...helpers.getDefaultEnvVars(chain), ...helpers.getChainEnvVars(chain), - ...helpers.getGenesisEnvVars(chain, this.config.exposer?.ports?.rest || 8081), + ...helpers.getGenesisEnvVars( + chain, + this.config.exposer?.ports?.rest || 8081 + ), { name: 'EXPOSER_HTTP_PORT', value: '8081' }, { name: 'EXPOSER_GRPC_PORT', value: '9099' }, - { name: 'EXPOSER_GENESIS_FILE', value: `${chain.home}/config/genesis.json` }, + { + name: 'EXPOSER_GENESIS_FILE', + value: `${chain.home}/config/genesis.json` + }, { name: 'EXPOSER_MNEMONIC_FILE', value: '/configs/keys.json' }, - { name: 'EXPOSER_PRIV_VAL_FILE', value: `${chain.home}/config/priv_validator_key.json` }, - { name: 'EXPOSER_NODE_KEY_FILE', value: `${chain.home}/config/node_key.json` }, - { name: 'EXPOSER_PRIV_VAL_STATE_FILE', value: `${chain.home}/data/priv_validator_state.json` } + { + name: 'EXPOSER_PRIV_VAL_FILE', + value: `${chain.home}/config/priv_validator_key.json` + }, + { + name: 'EXPOSER_NODE_KEY_FILE', + value: `${chain.home}/config/node_key.json` + }, + { + name: 'EXPOSER_PRIV_VAL_STATE_FILE', + value: `${chain.home}/data/priv_validator_state.json` + } ], command: ['exposer'], - resources: helpers.getResourceObject(this.config.exposer?.resources || { cpu: '0.1', memory: '128M' }), + resources: helpers.getResourceObject( + this.config.exposer?.resources || { cpu: '0.1', memory: '128M' } + ), volumeMounts: [ { mountPath: chain.home, name: 'node' }, { mountPath: '/configs', name: 'addresses' } @@ -337,7 +381,7 @@ mv $CHAIN_DIR/config/provider_priv_validator_key.json $CHAIN_DIR/config/priv_val private getValidatorInitScript(chain: Chain): string { const toBuild = chain.build?.enabled || chain.upgrade?.enabled; - + return ` VAL_INDEX=\${HOSTNAME##*-} echo "Validator Index: $VAL_INDEX" @@ -367,7 +411,7 @@ echo '{"node_id":"'$NODE_ID'"}' > $CHAIN_DIR/config/node_id.json private getValidatorConfigScript(chain: Chain): string { const toBuild = chain.build?.enabled || chain.upgrade?.enabled; - + return ` VAL_INDEX=\${HOSTNAME##*-} echo "Validator Index: $VAL_INDEX" @@ -394,17 +438,21 @@ cat $CHAIN_DIR/config/config.toml private getValidatorStartScript(chain: Chain): string { const toBuild = chain.build?.enabled || chain.upgrade?.enabled; - + return ` set -eux START_ARGS="" ${chain.cometmock?.enabled ? 'START_ARGS="--grpc-web.enable=false --transport=grpc --with-tendermint=false --address tcp://0.0.0.0:26658"' : ''} # Starting the chain -${toBuild ? ` +${ + toBuild + ? ` cp $CHAIN_DIR/cosmovisor/genesis/bin/$CHAIN_BIN /usr/bin -/usr/bin/cosmovisor start $START_ARGS` : ` -$CHAIN_BIN start $START_ARGS`} +/usr/bin/cosmovisor start $START_ARGS` + : ` +$CHAIN_BIN start $START_ARGS` +} `.trim(); } diff --git a/packages/packages/generator/src/builders/chains/index.ts b/packages/packages/generator/src/builders/chains/index.ts index c56d77163..01e9ecf6a 100644 --- a/packages/packages/generator/src/builders/chains/index.ts +++ b/packages/packages/generator/src/builders/chains/index.ts @@ -1,4 +1,4 @@ -import { Chain, StarshipConfig } from '@starship-ci/types'; +import { StarshipConfig } from '@starship-ci/types'; import { IGenerator, Manifest } from '../../types'; import { CosmosBuilder } from './cosmos'; @@ -14,7 +14,7 @@ const chainBuilderRegistry: Record< }; function createBuilder(chainName: string, config: StarshipConfig): IGenerator { - const builder = chainBuilderRegistry[chainName] || CosmosBuilder; // default to cosmos builder if no builder is found + const builder = chainBuilderRegistry[chainName] || CosmosBuilder; // default to cosmos builder if no builder is found return new builder(config); } @@ -27,7 +27,7 @@ export class ChainBuilder implements IGenerator { constructor(config: StarshipConfig) { this.config = config; - + // Create builders for each chain this.config.chains?.forEach((chain) => { this.generators.push(createBuilder(chain.name, this.config)); diff --git a/packages/packages/generator/src/builders/relayers/index.ts b/packages/packages/generator/src/builders/relayers/index.ts index 4750ef343..4cdf5e27e 100644 --- a/packages/packages/generator/src/builders/relayers/index.ts +++ b/packages/packages/generator/src/builders/relayers/index.ts @@ -1,6 +1,5 @@ import { Relayer, StarshipConfig } from '@starship-ci/types'; -import { DefaultsManager } from '../../defaults'; import { IGenerator, Manifest } from '../../types'; import { GoRelayerBuilder } from './go-relayer'; import { HermesRelayerBuilder } from './hermes'; @@ -44,7 +43,7 @@ export class RelayerBuilder implements IGenerator { this.config = config; // Process relayers with defaults - this.relayers = config.relayers || [] + this.relayers = config.relayers || []; this.generators = this.relayers.map((relayer) => createBuilder(relayer, this.config) diff --git a/packages/packages/generator/src/helpers.ts b/packages/packages/generator/src/helpers.ts index 4c8ed93d5..6adf26767 100644 --- a/packages/packages/generator/src/helpers.ts +++ b/packages/packages/generator/src/helpers.ts @@ -1,5 +1,5 @@ -import { Chain, StarshipConfig, Resources } from '@starship-ci/types'; -import { EnvVar, Container, ResourceRequirements, Volume } from 'kubernetesjs'; +import { Chain, Resources, StarshipConfig } from '@starship-ci/types'; +import { Container, EnvVar, ResourceRequirements, Volume } from 'kubernetesjs'; import { getGeneratorVersion } from './version'; @@ -7,8 +7,8 @@ import { getGeneratorVersion } from './version'; * Convert chain.id to name usable by templates * Replaces underscores with hyphens and truncates to 63 chars */ -export function getChainName(chainId: string): string { - return chainId.replace(/_/g, '-').substring(0, 63); +export function getChainName(chainId: string | number): string { + return String(chainId).replace(/_/g, '-').substring(0, 63); } /** @@ -133,7 +133,10 @@ export function getResourceObject(resources: Resources): ResourceRequirements { /** * Get node resources with chain-specific overrides */ -export function getNodeResources(chain: Chain, context: StarshipConfig): ResourceRequirements { +export function getNodeResources( + chain: Chain, + context: StarshipConfig +): ResourceRequirements { if (chain.resources) { return getResourceObject(chain.resources); } @@ -314,7 +317,9 @@ export function generateWaitInitContainer( } ], command: ['/bin/sh', '-c', `${waitScript}\necho "Ready to start"\nexit 0`], - resources: getResourceObject(config?.resources?.wait || { cpu: '0.1', memory: '128M' }) + resources: getResourceObject( + config?.resources?.wait || { cpu: '0.1', memory: '128M' } + ) }; }