Skip to content

feat: add admin system #27

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Sep 18, 2024
1 change: 1 addition & 0 deletions docker/Dockerfile.gen-configs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,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
1 change: 1 addition & 0 deletions docker/config-example.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ SCROLL_DB_CONNECTION_STRING = "postgres://postgres:scroll2022@db:5432/scroll?ssl
CHAIN_MONITOR_DB_CONNECTION_STRING = "postgres://postgres:scroll2022@db:5432/chain_monitor?sslmode=disable"
BRIDGE_HISTORY_DB_CONNECTION_STRING = "postgres://postgres:scroll2022@db:5432/bridge_history?sslmode=disable"
ROLLUP_EXPLORER_DB_CONNECTION_STRING = "postgres://postgres:scroll2022@db:5432/rollup_explorer?sslmode=disable"
ADMIN_SYSTEM_BACKEND_DB_CONNECTION_STRING = "postgresql://postgres:qwerty12345@postgresql:5432/scroll_admin_system?sslmode=disable"


[genesis]
Expand Down
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
57 changes: 57 additions & 0 deletions docker/templates/admin-system-backend-config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
{
"db_config": {
"driver_name": "postgres",
"dsn": null,
"max_open_connections": 200,
"max_idel_connections": 20
},
"read_only_db_config": {
"driver_name": "postgres",
"dsn": null,
"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": null,
"max_open_connections": 200,
"max_idel_connections": 20
},
"authentication": {
"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": false
}
},
"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
}
}
2 changes: 2 additions & 0 deletions scripts/deterministic/Configuration.sol
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ abstract contract Configuration is Script {
string internal CHAIN_MONITOR_DB_CONNECTION_STRING;
string internal BRIDGE_HISTORY_DB_CONNECTION_STRING;
string internal ROLLUP_EXPLORER_BACKEND_DB_CONNECTION_STRING;
string internal ADMIN_SYSTEM_BACKEND_DB_CONNECTION_STRING;

// genesis
uint256 internal L2_MAX_ETH_SUPPLY;
Expand Down Expand Up @@ -137,6 +138,7 @@ abstract contract Configuration is Script {
CHAIN_MONITOR_DB_CONNECTION_STRING = cfg.readString(".db.CHAIN_MONITOR_DB_CONNECTION_STRING");
BRIDGE_HISTORY_DB_CONNECTION_STRING = cfg.readString(".db.BRIDGE_HISTORY_DB_CONNECTION_STRING");
ROLLUP_EXPLORER_BACKEND_DB_CONNECTION_STRING = cfg.readString(".db.ROLLUP_EXPLORER_DB_CONNECTION_STRING");
ADMIN_SYSTEM_BACKEND_DB_CONNECTION_STRING = cfg.readString(".db.ADMIN_SYSTEM_BACKEND_DB_CONNECTION_STRING");

L2_MAX_ETH_SUPPLY = cfg.readUint(".genesis.L2_MAX_ETH_SUPPLY");
L2_DEPLOYER_INITIAL_BALANCE = cfg.readUint(".genesis.L2_DEPLOYER_INITIAL_BALANCE");
Expand Down
2 changes: 2 additions & 0 deletions 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,3 +36,4 @@ 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/.env.frontend";
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";
34 changes: 33 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 {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, ADMIN_SYSTEM_BACKEND_CONFIG_PATH, ADMIN_SYSTEM_BACKEND_CONFIG_TEMPLATE_PATH} from "./Constants.sol";
import {DeployScroll} from "./DeployScroll.s.sol";

contract GenerateRollupConfig is DeployScroll {
Expand Down Expand Up @@ -366,3 +366,35 @@ 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 {
setScriptMode(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);

vm.writeJson(SCROLL_DB_CONNECTION_STRING, ADMIN_SYSTEM_BACKEND_CONFIG_PATH, ".db_config.dsn");
vm.writeJson(SCROLL_DB_CONNECTION_STRING, ADMIN_SYSTEM_BACKEND_CONFIG_PATH, ".read_only_db_config.dsn");
vm.writeJson(ADMIN_SYSTEM_BACKEND_DB_CONNECTION_STRING, ADMIN_SYSTEM_BACKEND_CONFIG_PATH, ".auth_db_config.dsn");
}
}
Loading