🌳
pt0/deployF/ethF/doSyncGethF.mts
1import * as _ from 'lodash-es'
4import { jwtPath } from './jwtPathF.mts'
13const builtinTestnets = ['sepolia', 'holesky']
15const gethDeploymentTmpl = ({name, ethNetwork, nodePort, image, networkConfig, configHash, syncMode}: {
16 name: string, ethNetwork: string, nodePort: number, image: string,
17 networkConfig: {bootnodes: string[], genesisJson?: string} | null, configHash: string | undefined, syncMode: string | undefined,
18}) => {
19 const jwtSecretName = ethNetwork + '-jwt'
20 const isCustomNetwork = !!networkConfig
21 const isBuiltinTestnet = builtinTestnets.includes(ethNetwork)
23 if (!isCustomNetwork && !isBuiltinTestnet) throwIf(() => ethNetwork != 'mainnet')
25 const baseCmd = [
26 'geth', '--datadir', '/geth-pv', '--cache', '4096',
27 '--authrpc.jwtsecret', jwtPath,
28 '--authrpc.addr=0.0.0.0',
29 '--authrpc.port=8551',
30 '--authrpc.vhosts=*',
31 '--http',
32 '--http.api=eth,net,engine,admin,web3,txpool',
33 '--http.addr', '0.0.0.0',
34 '--http.vhosts', '*',
35 '--http.corsdomain', '*',
36 `--port=${nodePort}`,
37 ]
39 let command
40 if (isCustomNetwork) {
41 command = [
42 ...baseCmd,
43 '--override.genesis=/config/genesis.json',
44 `--bootnodes=${networkConfig.bootnodes.join(',')}`,
45 '--syncmode=full',
46 ]
47 } else if (isBuiltinTestnet) {
48 command = [...baseCmd, `--${ethNetwork}`, `--syncmode=${syncMode || 'snap'}`]
49 } else {
50 command = baseCmd
51 }
53 let volumeMounts = [
54 {mountPath: '/geth-pv', name},
55 {mountPath: jwtPath, name: jwtSecretName, subPath: jwtSecretName},
56 ]
57 const volumes: Record<string, unknown>[] = [
58 {name, persistentVolumeClaim: {claimName: name}},
59 {name: jwtSecretName, secret: {secretName: jwtSecretName}},
60 ]
62 if (isCustomNetwork) {
63 const genesisConfigMapName = `${name}-genesis`
64 volumeMounts.push({mountPath: '/config', name: 'genesis-config'})
65 volumes.push({name: 'genesis-config', configMap: {name: genesisConfigMapName}})
66 }
68 const annotations = configHash ? {configHash} : undefined
70 return {
71 apiVersion: 'apps/v1',
72 kind: 'Deployment',
73 metadata: {name},
74 spec: {
75 selector: {matchLabels: {name}},
76 replicas: 1,
77 strategy: {type: 'Recreate'},
78 template: {
79 metadata: {labels: {name, [deployLabel]: name}, annotations},
80 spec: {
81 containers: [{
82 name: 'geth', image, command,
83 volumeMounts,
84 livenessProbe: {
85 httpGet: {path: '/', port: 8545, httpHeaders: [{name: 'Content-Type', value: 'application/json'}]},
86 initialDelaySeconds: 30,
87 periodSeconds: 8
88 }
89 }],
90 volumes
91 }
92 }
93 }
94 }
97export const doSyncGeth = async ({sizeGb, nodePort, ethNetwork, image, networkConfig, syncMode}: {
98 sizeGb: number, nodePort: number, ethNetwork: string, image: string,
99 networkConfig: {bootnodes: string[], genesisJson?: string} | null, syncMode?: string,
100}) => {
101 const {cluster_name} = getKlusterCtx()
102 const action = getAction()
103 const name = `geth-${ethNetwork}`
105 let configHash, genesisConfigMap
106 if (networkConfig?.genesisJson) {
107 const genesisConfigMapName = `${name}-genesis`
108 const result = configMapWithHash({name: genesisConfigMapName, data: {'genesis.json': networkConfig.genesisJson}, mountPath: '/config'})
109 configHash = result.configHash
110 genesisConfigMap = result.configMap
111 }
113 let resources = [
114 gethDeploymentTmpl({name, ethNetwork, nodePort, image, networkConfig, configHash, syncMode}),
115 kubeSvcTmpl({name, portNos: [8545, 8551]}),
116 dualNodePortTmpl({name, selfName: name + '-p2p', nodePort}),
117 ...await genericPvcTmplA({action, name, sizeGb}),
118 ]
120 if (genesisConfigMap) resources.push(genesisConfigMap)
122 await resourcesAction({resources, action, cluster_name})