Skip to content

Commit

Permalink
feat: add admin system (#27)
Browse files Browse the repository at this point in the history
  • Loading branch information
yiweichi authored Sep 18, 2024
1 parent 574c783 commit 0c993a7
Show file tree
Hide file tree
Showing 7 changed files with 107 additions and 2 deletions.
1 change: 1 addition & 0 deletions docker/Dockerfile.gen-configs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ COPY ./docker/templates/coordinator-config.json /contracts/docker/templates/coor
COPY ./docker/templates/genesis.json /contracts/docker/templates/genesis.json
COPY ./docker/templates/rollup-config.json /contracts/docker/templates/rollup-config.json
COPY ./docker/templates/rollup-explorer-backend-config.json /contracts/docker/templates/rollup-explorer-backend-config.json
COPY ./docker/templates/admin-system-backend-config.json /contracts/docker/templates/admin-system-backend-config.json

COPY ./docker/scripts/gen-configs.sh /contracts/docker/scripts/gen-configs.sh

Expand Down
5 changes: 5 additions & 0 deletions docker/config-example.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ L2_GAS_ORACLE_SENDER_ADDR = "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266"

[db]

ADMIN_SYSTEM_BACKEND_DB_CONNECTION_STRING = "postgresql://postgres:qwerty12345@postgresql:5432/scroll_admin_system?sslmode=disable"
BLOCKSCOUT_DB_CONNECTION_STRING = "postgres://postgres:qwerty12345@postgresql:5432/blockscout"
BRIDGE_HISTORY_DB_CONNECTION_STRING = "postgres://postgres:qwerty12345@postgresql:5432/scroll?sslmode=disable"
CHAIN_MONITOR_DB_CONNECTION_STRING = "postgres://postgres:qwerty12345@postgresql:5432/scroll?sslmode=disable"
Expand Down Expand Up @@ -73,6 +74,8 @@ BRIDGE_API_URI = "http://bridge-history-api.scrollsdk/api"
ROLLUPSCAN_API_URI = "http://rollup-explorer-backend.scrollsdk/api"
EXTERNAL_EXPLORER_URI_L1 = "http://l1-explorer.scrollsdk"
EXTERNAL_EXPLORER_URI_L2 = "http://blockscout.scrollsdk"
ADMIN_SYSTEM_DASHBOARD_URI = "http://admin-system-dashboard.scrollsdk"
GRAFANA_URI = "http://grafana.scrollsdk"

[genesis]

Expand Down Expand Up @@ -110,3 +113,5 @@ ROLLUP_EXPLORER_API_HOST = "rollup-explorer-backend.scrollsdk"
COORDINATOR_API_HOST = "coordinator-api.scrollsdk"
RPC_GATEWAY_HOST = "l2-rpc.scrollsdk"
BLOCKSCOUT_HOST = "blockscout.scrollsdk"
ADMIN_SYSTEM_DASHBOARD_HOST= "admin-system-dashboard.scrollsdk"
GRAFANA_HOST = "http://grafana.scrollsdk"
4 changes: 4 additions & 0 deletions docker/scripts/gen-configs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,7 @@ forge script scripts/deterministic/GenerateConfigs.s.sol:GenerateFrontendConfig
echo ""
echo "generating rollup-explorer-backend-config.json"
forge script scripts/deterministic/GenerateConfigs.s.sol:GenerateRollupExplorerBackendConfig || exit 1

echo ""
echo "generating admin-system-backend-config.json"
forge script scripts/deterministic/GenerateConfigs.s.sol:GenerateAdminSystemBackendConfig || exit 1
59 changes: 59 additions & 0 deletions docker/templates/admin-system-backend-config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
{
"db_config": {
"driver_name": "postgres",
"dsn": "",
"max_open_connections": 200,
"max_idel_connections": 20
},
"read_only_db_config": {
"driver_name": "postgres",
"dsn": "",
"max_open_connections": 200,
"max_idel_connections": 20
},
"db_mappings": {
"default": "read_only",
"batch_chunk": "read_only",
"prover_block_list": "read_write"
},
"auth_db_config": {
"driver_name": "postgres",
"dsn": "",
"max_open_connections": 200,
"max_idel_connections": 20
},
"authentication": {
"mode": "skip",
"jwt": {
"secret": "scroll admin system secret key",
"token_expire_seconds": 3600
},
"ldap": {
"endpoint": "ldap://xxx.xxx.com:389",
"bind_dn": "",
"bind_password": "",
"search_base_dn_list": [""],
"search_filter": "(mail=%s)"
},
"otp": {
"issuer": "ScrollAdmin(Dev)",
"enabled": true,
"admin_only": true
}
},
"authorization": {
"casbin": {
"model_path": "conf/model.conf",
"policy_path": "conf/policy.csv"
}
},
"prometheus": {
"endpoint": "https://xxx.xxx.com/prometheus",
"user": "",
"password": ""
},
"admin": {
"prover_becomes_offline_since_last_get_task_seconds": 3600,
"prover_becomes_idle_since_last_task_assigned_seconds": 1800
}
}
4 changes: 4 additions & 0 deletions scripts/deterministic/Configuration.sol
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ abstract contract Configuration is Script {
string internal ROLLUPSCAN_API_URI;
string internal EXTERNAL_EXPLORER_URI_L1;
string internal EXTERNAL_EXPLORER_URI_L2;
string internal ADMIN_SYSTEM_DASHBOARD_URI;
string internal GRAFANA_URI;

/**********************
* Internal interface *
Expand Down Expand Up @@ -153,6 +155,8 @@ abstract contract Configuration is Script {
ROLLUPSCAN_API_URI = cfg.readString(".frontend.ROLLUPSCAN_API_URI");
EXTERNAL_EXPLORER_URI_L1 = cfg.readString(".frontend.EXTERNAL_EXPLORER_URI_L1");
EXTERNAL_EXPLORER_URI_L2 = cfg.readString(".frontend.EXTERNAL_EXPLORER_URI_L2");
ADMIN_SYSTEM_DASHBOARD_URI = cfg.readString(".frontend.ADMIN_SYSTEM_DASHBOARD_URI");
GRAFANA_URI = cfg.readString(".frontend.GRAFANA_URI");

runSanityCheck();
}
Expand Down
4 changes: 3 additions & 1 deletion scripts/deterministic/Constants.sol
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ string constant CHAIN_MONITOR_CONFIG_TEMPLATE_PATH = "./docker/templates/chain-m
string constant BRIDGE_HISTORY_CONFIG_TEMPLATE_PATH = "./docker/templates/bridge-history-config.json";
string constant BALANCE_CHECKER_CONFIG_TEMPLATE_PATH = "./docker/templates/balance-checker-config.json";
string constant ROLLUP_EXPLORER_BACKEND_CONFIG_TEMPLATE_PATH = "./docker/templates/rollup-explorer-backend-config.json";
string constant ADMIN_SYSTEM_BACKEND_CONFIG_TEMPLATE_PATH = "./docker/templates/admin-system-backend-config.json";

// input files
string constant CONFIG_PATH = "./volume/config.toml";
Expand All @@ -35,6 +36,7 @@ string constant BRIDGE_HISTORY_CONFIG_PATH = "./volume/bridge-history-config.jso
string constant BALANCE_CHECKER_CONFIG_PATH = "./volume/balance-checker-config.json";
string constant FRONTEND_ENV_PATH = "./volume/frontend-config";
string constant ROLLUP_EXPLORER_BACKEND_CONFIG_PATH = "./volume/rollup-explorer-backend-config.json";
string constant ADMIN_SYSTEM_BACKEND_CONFIG_PATH = "./volume/admin-system-backend-config.json";

// plonk verifier configs
bytes32 constant V4_VERIFIER_DIGEST = 0x0a1904dbfff4614fb090b4b3864af4874f12680c32f07889e9ede8665097e5ec;
bytes32 constant V4_VERIFIER_DIGEST = 0x0a1904dbfff4614fb090b4b3864af4874f12680c32f07889e9ede8665097e5ec;
32 changes: 31 additions & 1 deletion scripts/deterministic/GenerateConfigs.s.sol
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity =0.8.24;

import {BALANCE_CHECKER_CONFIG_PATH, BALANCE_CHECKER_CONFIG_TEMPLATE_PATH, BRIDGE_HISTORY_CONFIG_PATH, BRIDGE_HISTORY_CONFIG_TEMPLATE_PATH, CHAIN_MONITOR_CONFIG_PATH, CHAIN_MONITOR_CONFIG_TEMPLATE_PATH, COORDINATOR_CONFIG_PATH, COORDINATOR_CONFIG_TEMPLATE_PATH, FRONTEND_ENV_PATH, ROLLUP_CONFIG_PATH, ROLLUP_CONFIG_TEMPLATE_PATH, ROLLUP_EXPLORER_BACKEND_CONFIG_PATH, ROLLUP_EXPLORER_BACKEND_CONFIG_TEMPLATE_PATH} from "./Constants.sol";
import {ADMIN_SYSTEM_BACKEND_CONFIG_PATH, ADMIN_SYSTEM_BACKEND_CONFIG_TEMPLATE_PATH, BALANCE_CHECKER_CONFIG_PATH, BALANCE_CHECKER_CONFIG_TEMPLATE_PATH, BRIDGE_HISTORY_CONFIG_PATH, BRIDGE_HISTORY_CONFIG_TEMPLATE_PATH, CHAIN_MONITOR_CONFIG_PATH, CHAIN_MONITOR_CONFIG_TEMPLATE_PATH, COORDINATOR_CONFIG_PATH, COORDINATOR_CONFIG_TEMPLATE_PATH, FRONTEND_ENV_PATH, ROLLUP_CONFIG_PATH, ROLLUP_CONFIG_TEMPLATE_PATH, ROLLUP_EXPLORER_BACKEND_CONFIG_PATH, ROLLUP_EXPLORER_BACKEND_CONFIG_TEMPLATE_PATH} from "./Constants.sol";
import {DeployScroll} from "./DeployScroll.s.sol";
import {DeterministicDeployment} from "./DeterministicDeployment.sol";

Expand Down Expand Up @@ -278,6 +278,8 @@ contract GenerateFrontendConfig is DeployScroll {
vm.writeLine(FRONTEND_ENV_PATH, string.concat("REACT_APP_ROLLUPSCAN_API_URI = \"", ROLLUPSCAN_API_URI, "\""));
vm.writeLine(FRONTEND_ENV_PATH, string.concat("REACT_APP_EXTERNAL_EXPLORER_URI_L1 = \"", EXTERNAL_EXPLORER_URI_L1, "\""));
vm.writeLine(FRONTEND_ENV_PATH, string.concat("REACT_APP_EXTERNAL_EXPLORER_URI_L2 = \"", EXTERNAL_EXPLORER_URI_L2, "\""));
vm.writeLine(FRONTEND_ENV_PATH, string.concat("ADMIN_SYSTEM_DASHBOARD_URI = \"", ADMIN_SYSTEM_DASHBOARD_URI, "\""));
vm.writeLine(FRONTEND_ENV_PATH, string.concat("GRAFANA_URI = \"", GRAFANA_URI, "\""));

// L1 contracts
vm.writeLine(FRONTEND_ENV_PATH, "");
Expand Down Expand Up @@ -353,3 +355,31 @@ contract GenerateRollupExplorerBackendConfig is DeployScroll {
vm.writeJson(ROLLUP_EXPLORER_BACKEND_DB_CONNECTION_STRING, ROLLUP_EXPLORER_BACKEND_CONFIG_PATH, ".db_url");
}
}

contract GenerateAdminSystemBackendConfig is DeployScroll {
/***************
* Entry point *
***************/

function run() public {
DeterministicDeployment.initialize(ScriptMode.VerifyConfig);
predictAllContracts();

generateAdminSystemBackendConfig();
}

/*********************
* Private functions *
*********************/

// prettier-ignore
function generateAdminSystemBackendConfig() private {
// initialize template file
if (vm.exists(ADMIN_SYSTEM_BACKEND_CONFIG_PATH)) {
vm.removeFile(ADMIN_SYSTEM_BACKEND_CONFIG_PATH);
}

string memory template = vm.readFile(ADMIN_SYSTEM_BACKEND_CONFIG_TEMPLATE_PATH);
vm.writeFile(ADMIN_SYSTEM_BACKEND_CONFIG_PATH, template);
}
}

0 comments on commit 0c993a7

Please sign in to comment.