Skip to content
Closed
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -528,7 +528,7 @@ DESCRIPTION
EXAMPLES
$ scrollsdk setup configs

$ scrollsdk setup configs --image-tag gen-configs-8ff2948aa2b9cbd24a7644b060097765a6faee10
$ scrollsdk setup configs --image-tag gen-configs-64c65842e35017142b68d878e691dae7e41a7af9

$ scrollsdk setup configs --configs-dir custom-configs
```
Expand Down Expand Up @@ -726,7 +726,7 @@ DESCRIPTION
EXAMPLES
$ scrollsdk setup verify-contracts

$ scrollsdk setup verify-contracts --image-tag verify-8ff2948aa2b9cbd24a7644b060097765a6faee10
$ scrollsdk setup verify-contracts --image-tag verify-64c65842e35017142b68d878e691dae7e41a7af9
```

_See code: [src/commands/setup/verify-contracts.ts](https://github.com/scroll-tech/scroll-sdk-cli/blob/v0.1.2/src/commands/setup/verify-contracts.ts)_
Expand Down
1 change: 1 addition & 0 deletions src/commands/helper/fund-accounts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ export default class HelperFundAccounts extends Command {
}

const l2Addresses: Record<string, string> = {

L2_GAS_ORACLE_SENDER: config.accounts.L2_GAS_ORACLE_SENDER_ADDR,
}

Expand Down
79 changes: 40 additions & 39 deletions src/commands/setup/configs.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import {Command, Flags} from '@oclif/core'
import { Command, Flags } from '@oclif/core'
import Docker from 'dockerode'
import * as fs from 'fs'
import * as path from 'path'
import * as toml from '@iarna/toml'
import chalk from 'chalk'
import {confirm, input, select} from '@inquirer/prompts'
import {ethers} from 'ethers'
import { confirm, input, select } from '@inquirer/prompts'
import { ethers } from 'ethers'
import * as yaml from 'js-yaml'
import * as childProcess from 'child_process'

Expand All @@ -14,7 +14,7 @@ export default class SetupConfigs extends Command {

static override examples = [
'<%= config.bin %> <%= command.id %>',
'<%= config.bin %> <%= command.id %> --image-tag gen-configs-f961bf3e75c7c3fec63250062e751b0aaf47fefd',
'<%= config.bin %> <%= command.id %> --image-tag gen-configs-64c65842e35017142b68d878e691dae7e41a7af9',
'<%= config.bin %> <%= command.id %> --configs-dir custom-configs',
]

Expand Down Expand Up @@ -139,7 +139,7 @@ export default class SetupConfigs extends Command {
}

// TODO: check privatekey secrets once integrated
private generateEnvContent(service: string, config: any): {[key: string]: string} {
private generateEnvContent(service: string, config: any): { [key: string]: string } {
const mapping: Record<string, string[]> = {
'admin-system-backend': [
'ADMIN_SYSTEM_BACKEND_DB_CONNECTION_STRING:SCROLL_ADMIN_AUTH_DB_CONFIG_DSN',
Expand All @@ -165,8 +165,8 @@ export default class SetupConfigs extends Command {
],
'gas-oracle': [
'GAS_ORACLE_DB_CONNECTION_STRING:SCROLL_ROLLUP_DB_CONFIG_DSN',
'L1_GAS_ORACLE_SENDER_PRIVATE_KEY:SCROLL_ROLLUP_L1_CONFIG_RELAYER_CONFIG_GAS_ORACLE_SENDER_SIGNER_CONFIG_PRIVATE_KEY_SIGNER_CONFIG_PRIVATE_KEY',
'L2_GAS_ORACLE_SENDER_PRIVATE_KEY:SCROLL_ROLLUP_L2_CONFIG_RELAYER_CONFIG_GAS_ORACLE_SENDER_SIGNER_CONFIG_PRIVATE_KEY_SIGNER_CONFIG_PRIVATE_KEY',
'L1_GAS_ORACLE_SENDER_PRIVATE_KEY:SCROLL_ROLLUP_L2_CONFIG_RELAYER_CONFIG_GAS_ORACLE_SENDER_SIGNER_CONFIG_PRIVATE_KEY_SIGNER_CONFIG_PRIVATE_KEY',
'L2_GAS_ORACLE_SENDER_PRIVATE_KEY:SCROLL_ROLLUP_L1_CONFIG_RELAYER_CONFIG_GAS_ORACLE_SENDER_SIGNER_CONFIG_PRIVATE_KEY_SIGNER_CONFIG_PRIVATE_KEY',
],
'l1-explorer': ['L1_EXPLORER_DB_CONNECTION_STRING:DATABASE_URL'],
'l2-sequencer': [
Expand All @@ -181,7 +181,7 @@ export default class SetupConfigs extends Command {
],
}

const envFiles: {[key: string]: string} = {}
const envFiles: { [key: string]: string } = {}

if (service === 'l2-sequencer') {
// Handle all sequencers (primary and backups)
Expand Down Expand Up @@ -224,9 +224,9 @@ export default class SetupConfigs extends Command {

private createMigrateDbFiles(config: any): void {
const migrateDbFiles = [
{service: 'bridge-history-fetcher', key: 'BRIDGE_HISTORY_DB_CONNECTION_STRING'},
{service: 'gas-oracle', key: 'GAS_ORACLE_DB_CONNECTION_STRING'},
{service: 'rollup-node', key: 'ROLLUP_NODE_DB_CONNECTION_STRING'},
{ service: 'bridge-history-fetcher', key: 'BRIDGE_HISTORY_DB_CONNECTION_STRING' },
{ service: 'gas-oracle', key: 'GAS_ORACLE_DB_CONNECTION_STRING' },
{ service: 'rollup-node', key: 'ROLLUP_NODE_DB_CONNECTION_STRING' },
]

for (const file of migrateDbFiles) {
Expand Down Expand Up @@ -318,7 +318,7 @@ export default class SetupConfigs extends Command {
if (!config.contracts) {
config.contracts = {}
}
;(config.contracts as any).DEPLOYMENT_SALT = newSalt
; (config.contracts as any).DEPLOYMENT_SALT = newSalt

fs.writeFileSync(configPath, toml.stringify(config as any))
this.log(chalk.green(`Deployment salt updated in config.toml from "${currentSalt}" to "${newSalt}"`))
Expand Down Expand Up @@ -375,7 +375,7 @@ export default class SetupConfigs extends Command {
if (!config.general) {
config.general = {}
}
;(config.general as any).L1_CONTRACT_DEPLOYMENT_BLOCK = newBlock
; (config.general as any).L1_CONTRACT_DEPLOYMENT_BLOCK = newBlock

fs.writeFileSync(configPath, toml.stringify(config as any))
this.log(
Expand Down Expand Up @@ -465,7 +465,7 @@ export default class SetupConfigs extends Command {
}

private async getDockerImageTag(providedTag: string | undefined): Promise<string> {
const defaultTag = 'gen-configs-f961bf3e75c7c3fec63250062e751b0aaf47fefd'
const defaultTag = 'gen-configs-64c65842e35017142b68d878e691dae7e41a7af9'

if (!providedTag) {
return defaultTag
Expand All @@ -483,7 +483,7 @@ export default class SetupConfigs extends Command {

const selectedTag = await select({
message: 'Select a Docker image tag:',
choices: tags.map((tag) => ({name: tag, value: tag})),
choices: tags.map((tag) => ({ name: tag, value: tag })),
})

return selectedTag
Expand All @@ -495,7 +495,7 @@ export default class SetupConfigs extends Command {

// Ensure the target directory exists
if (!fs.existsSync(targetDir)) {
fs.mkdirSync(targetDir, {recursive: true})
fs.mkdirSync(targetDir, { recursive: true })
}

// Check permissions and potentially change ownership before processing
Expand All @@ -509,7 +509,7 @@ export default class SetupConfigs extends Command {
if (changeOwnership) {
try {
const command = `sudo find ${sourceDir} -name "*.yaml" -user root -exec sudo chown -R $USER: {} \\;`
childProcess.execSync(command, {stdio: 'inherit'})
childProcess.execSync(command, { stdio: 'inherit' })
this.log(chalk.green('File ownership changed successfully.'))
} catch (error) {
this.error(`Failed to change file ownership: ${error}`)
Expand All @@ -522,19 +522,19 @@ export default class SetupConfigs extends Command {
}

const fileMappings = [
{source: 'admin-system-backend-config.yaml', target: 'admin-system-backend-config.yaml'},
{source: 'admin-system-backend-config.yaml', target: 'admin-system-cron-config.yaml'},
{source: 'balance-checker-config.yaml', target: 'balance-checker-config.yaml'},
{source: 'bridge-history-config.yaml', target: 'bridge-history-api-config.yaml'},
{source: 'bridge-history-config.yaml', target: 'bridge-history-fetcher-config.yaml'},
{source: 'chain-monitor-config.yaml', target: 'chain-monitor-config.yaml'},
{source: 'coordinator-config.yaml', target: 'coordinator-api-config.yaml'},
{source: 'coordinator-config.yaml', target: 'coordinator-cron-config.yaml'},
{source: 'frontend-config.yaml', target: 'frontends-config.yaml'},
{source: 'genesis.yaml', target: 'genesis.yaml'},
{source: 'rollup-config.yaml', target: 'gas-oracle-config.yaml'},
{source: 'rollup-config.yaml', target: 'rollup-node-config.yaml'},
{source: 'rollup-explorer-backend-config.yaml', target: 'rollup-explorer-backend-config.yaml'},
{ source: 'admin-system-backend-config.yaml', target: 'admin-system-backend-config.yaml' },
{ source: 'admin-system-backend-config.yaml', target: 'admin-system-cron-config.yaml' },
{ source: 'balance-checker-config.yaml', target: 'balance-checker-config.yaml' },
{ source: 'bridge-history-config.yaml', target: 'bridge-history-api-config.yaml' },
{ source: 'bridge-history-config.yaml', target: 'bridge-history-fetcher-config.yaml' },
{ source: 'chain-monitor-config.yaml', target: 'chain-monitor-config.yaml' },
{ source: 'coordinator-config.yaml', target: 'coordinator-api-config.yaml' },
{ source: 'coordinator-config.yaml', target: 'coordinator-cron-config.yaml' },
{ source: 'frontend-config.yaml', target: 'frontends-config.yaml' },
{ source: 'genesis.yaml', target: 'genesis.yaml' },
{ source: 'rollup-config.yaml', target: 'gas-oracle-config.yaml' },
{ source: 'rollup-config.yaml', target: 'rollup-node-config.yaml' },
{ source: 'rollup-explorer-backend-config.yaml', target: 'rollup-explorer-backend-config.yaml' },
]

// Process all mappings
Expand Down Expand Up @@ -566,7 +566,7 @@ export default class SetupConfigs extends Command {
const existingContent = fs.readFileSync(scrollMonitorProductionFilePath, 'utf8')
const existingYaml = yaml.load(existingContent) as any
existingYaml['kube-prometheus-stack'].additionalPrometheusRules = addedAlertRules
fs.writeFileSync(scrollMonitorProductionFilePath, yaml.dump(existingYaml, {indent: 2}))
fs.writeFileSync(scrollMonitorProductionFilePath, yaml.dump(existingYaml, { indent: 2 }))
} catch {
this.error(`generating balance-checker alert rules file failed`)
}
Expand All @@ -590,8 +590,8 @@ export default class SetupConfigs extends Command {

// Process config.toml and config-contracts.toml
const configFiles = [
{source: 'config.toml', target: 'scroll-common-config.yaml', key: 'scrollConfig'},
{source: 'config-contracts.toml', target: 'scroll-common-config-contracts.yaml', key: 'scrollConfigContracts'},
{ source: 'config.toml', target: 'scroll-common-config.yaml', key: 'scrollConfig' },
{ source: 'config-contracts.toml', target: 'scroll-common-config-contracts.yaml', key: 'scrollConfigContracts' },
]

for (const file of configFiles) {
Expand All @@ -603,7 +603,7 @@ export default class SetupConfigs extends Command {
const yamlContent = {
[file.key]: content,
}
const yamlString = yaml.dump(yamlContent, {indent: 2})
const yamlString = yaml.dump(yamlContent, { indent: 2 })
fs.writeFileSync(targetPath, yamlString)
this.log(chalk.green(`Processed file: ${file.target}`))
} else {
Expand Down Expand Up @@ -659,7 +659,7 @@ export default class SetupConfigs extends Command {
if (!config.contracts) {
config.contracts = {}
}
;(config.contracts as any).L1_FEE_VAULT_ADDR = newAddr
; (config.contracts as any).L1_FEE_VAULT_ADDR = newAddr

fs.writeFileSync(configPath, toml.stringify(config as any))
this.log(chalk.green(`L1_FEE_VAULT_ADDR updated in config.toml to "${newAddr}"`))
Expand All @@ -681,6 +681,7 @@ export default class SetupConfigs extends Command {
this.log(chalk.yellow('Note: If you do not set L1_PLONK_VERIFIER_ADDR, one will be automatically deployed.'))

const updatePlonkVerifier = await confirm({
default: false,
message: 'Would you like to set a value for L1_PLONK_VERIFIER_ADDR?',
})

Expand All @@ -707,7 +708,7 @@ export default class SetupConfigs extends Command {
if (!config.contracts) {
config.contracts = {}
}
;(config.contracts as any).L1_PLONK_VERIFIER_ADDR = newAddr
; (config.contracts as any).L1_PLONK_VERIFIER_ADDR = newAddr

fs.writeFileSync(configPath, toml.stringify(config as any))
this.log(chalk.green(`L1_PLONK_VERIFIER_ADDR updated in config.toml to "${newAddr}"`))
Expand All @@ -717,7 +718,7 @@ export default class SetupConfigs extends Command {
}

public async run(): Promise<void> {
const {flags} = await this.parse(SetupConfigs)
const { flags } = await this.parse(SetupConfigs)

const imageTag = await this.getDockerImageTag(flags['image-tag'])
this.log(chalk.blue(`Using Docker image tag: ${imageTag}`))
Expand Down Expand Up @@ -762,15 +763,15 @@ export default class SetupConfigs extends Command {
const yamlContent = fs.readFileSync(sourcePath, 'utf8')
const parsedYaml = yaml.load(yamlContent) as any
const jsonConfig = JSON.parse(parsedYaml.scrollConfig)
const {addresses} = jsonConfig
const { addresses } = jsonConfig

const alertRules = [
{
groups: [
{
name: 'balance-cheker-group',
rules: addresses.map(
(item: {address: string; min_balance_ether: string; name: string; rpc_url: string}) => ({
(item: { address: string; min_balance_ether: string; name: string; rpc_url: string }) => ({
alert: `ether_balance_of_${item.name}`,
annotations: {
description: `Balance of ${item.name} (${item.address}) is less than threshold ${item.min_balance_ether}`,
Expand Down
15 changes: 15 additions & 0 deletions src/commands/setup/domains.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,21 @@ export default class SetupDomains extends Command {
this.logKeyValue(key, value)
}

ingressConfig.RPC_GATEWAY_WS_HOST = "ws."+ ingressConfig.RPC_GATEWAY_HOST
const needRpcGateWay = await confirm({
default: false,
message: `Do you want to use another RPC gateway for websocket host(${ingressConfig.RPC_GATEWAY_WS_HOST})`,
})

if (needRpcGateWay) {
ingressConfig.RPC_GATEWAY_WS_HOST = await input({
message: 'Enter the WebSocket RPC gateway URL (RPC_GATEWAY_WS_HOST) for the SDK backend:',
})
} else {
// Use the same domain as RPC_GATEWAY_HOST

}

const confirmUpdate = await confirm({
message: 'Do you want to update the config.toml file with these new configurations?',
})
Expand Down
62 changes: 54 additions & 8 deletions src/commands/setup/prep-charts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,13 +143,13 @@ export default class SetupPrepCharts extends Command {
// if (value === '' || value === '[""]' || value === '[]' ||
// (Array.isArray(value) && (value.length === 0 || (value.length === 1 && value[0] === ''))) ||
// value === null || value === undefined) {
const configMapping = this.configMapping[key]
if (configMapping) {
const configPathOrResolver = this.configMapping[key]
if (configPathOrResolver) {
let configKey: string
if (typeof configMapping === 'function') {
configKey = configMapping(chartName, productionNumber)
if (typeof configPathOrResolver === 'function') {
configKey = configPathOrResolver(chartName, productionNumber)
} else {
configKey = configMapping
configKey = configPathOrResolver
}
if (chartName === "l1-devnet" && key === "CHAIN_ID") {
configKey = "general.CHAIN_ID_L1";
Expand Down Expand Up @@ -250,6 +250,11 @@ export default class SetupPrepCharts extends Command {
blockscout-stack.frontend.env.NEXT_PUBLIC_API_HOST:blockscout.scrollsdk
blockscout-stack.frontend.ingress.annotations.nginx.ingress.kubernetes.io/cors-allow-origin: "https://blockscout.scrollsdk"
blockscout-stack.frontend.ingress.hostname: "blockscout.scrollsdk"

NEXT_PUBLIC_API_PROTOCOL: https
NEXT_PUBLIC_API_WEBSOCKET_PROTOCOL: wss
NEXT_PUBLIC_API_HOST: "blockscout.scrollsdk"
NEXT_PUBLIC_APP_PROTOCOL: https
*/
if (productionYaml["blockscout-stack"]) {
let ingressUpdated = false;
Expand All @@ -269,11 +274,43 @@ export default class SetupPrepCharts extends Command {
blockscout.ingress.hostname = blockscout_host;
ingressUpdated = true;
}

//only enable tls if use command scrollsdk setup tls
if (blockscout?.ingress?.tls?.enabled) {
if (blockscout.ingress.tls.enabled != "false") {
blockscout.ingress.tls.enabled = false;
changes.push({ key: `ingress.blockscout.tls`, oldValue: blockscout.ingress.tls, newValue: "false" });
ingressUpdated = true;
}
}

if (frontend?.env?.NEXT_PUBLIC_API_HOST) {
changes.push({ key: `frontend.env.NEXT_PUBLIC_API_HOST`, oldValue: frontend.env.NEXT_PUBLIC_API_HOST, newValue: blockscout_host });
frontend.env.NEXT_PUBLIC_API_HOST = blockscout_host;
ingressUpdated = true;
}

if (frontend?.env?.NEXT_PUBLIC_API_PROTOCOL) {
let protocol = blockscout_host.startsWith("https") ? "https" : "http";
changes.push({
key: `frontend.env.NEXT_PUBLIC_API_PROTOCOL`,
oldValue: frontend.env.NEXT_PUBLIC_API_PROTOCOL,
newValue: protocol
});
frontend.env.NEXT_PUBLIC_API_PROTOCOL = protocol;
ingressUpdated = true;
}
if (frontend?.env?.NEXT_PUBLIC_APP_PROTOCOL) {
let protocol = blockscout_host.startsWith("https") ? "https" : "http";
changes.push({
key: `frontend.env.NEXT_PUBLIC_APP_PROTOCOL`,
oldValue: frontend.env.NEXT_PUBLIC_APP_PROTOCOL,
newValue: protocol
});
frontend.env.NEXT_PUBLIC_APP_PROTOCOL = protocol;
ingressUpdated = true;
}

if (frontend?.ingress?.annotations?.["nginx.ingress.kubernetes.io/cors-allow-origin"]) {
changes.push({ key: `frontend.ingress.annotations["nginx.ingress.kubernetes.io/cors-allow-origin"]`, oldValue: frontend.ingress.annotations["nginx.ingress.kubernetes.io/cors-allow-origin"], newValue: blockscout_url });
frontend.ingress.annotations["nginx.ingress.kubernetes.io/cors-allow-origin"] = blockscout_url;
Expand All @@ -284,6 +321,15 @@ export default class SetupPrepCharts extends Command {
frontend.ingress.hostname = blockscout_host;
ingressUpdated = true;
}

//only enable tls if use command scrollsdk setup tls
if(frontend?.ingress?.tls?.enabled) {
if(frontend.ingress.tls.enabled != "false"){
changes.push({ key: `frontend.ingress.tls`, oldValue: frontend.ingress.tls, newValue: "false" });
frontend.ingress.tls.enabled = false;
ingressUpdated = true;
}
}
/*
INDEXER_SCROLL_L1_CHAIN_CONTRACT: ""
INDEXER_SCROLL_L1_BATCH_START_BLOCK: ""
Expand All @@ -292,9 +338,9 @@ export default class SetupPrepCharts extends Command {
INDEXER_SCROLL_L2_MESSENGER_CONTRACT: ""
INDEXER_SCROLL_L2_GAS_ORACLE_CONTRACT: ""
INDEXER_SCROLL_L1_RPC: ""
INDEXER_SCROLL_L2_MESSENGER_START_BLOCK: 0
INDEXER_SCROLL_L1_ETH_GET_LOGS_RANGE_SIZE: 500
INDEXER_SCROLL_L2_ETH_GET_LOGS_RANGE_SIZE: 500
INDEXER_SCROLL_L2_MESSENGER_START_BLOCK: 0
INDEXER_SCROLL_L1_ETH_GET_LOGS_RANGE_SIZE: 500
INDEXER_SCROLL_L2_ETH_GET_LOGS_RANGE_SIZE: 500
*/
interface BlockscoutEnvMapping {
key: string;
Expand Down
Loading
Loading