Skip to content

Commit

Permalink
chore: streamline dbs deployment (#229)
Browse files Browse the repository at this point in the history
* refactor: databases

* fix: pless zkevm node deployment

* chore: lint

* fix: pless and grafana issues

* ci: list dbs

* fix: enclave name

* chore: rename aggregator syncer db
  • Loading branch information
leovct authored Aug 21, 2024
1 parent 025e1a5 commit 771c9f9
Show file tree
Hide file tree
Showing 7 changed files with 113 additions and 60 deletions.
20 changes: 20 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ jobs:
- name: Inspect enclave
run: kurtosis enclave inspect ${{ env.ENCLAVE_NAME }}

- name: List first CDK L2 chain databases (erigon)
run: |
postgres1_port=$(kurtosis port print ${{ env.ENCLAVE_NAME }} postgres-001 postgres | cut -d':' -f3)
PGPASSWORD=master_password psql --host 127.0.0.1 --port "$postgres1_port" --username master_user --dbname master --list
- name: Attach a second CDK L2 chain (erigon)
run: |
Expand All @@ -43,6 +48,11 @@ jobs:
- name: Inspect enclave
run: kurtosis enclave inspect ${{ env.ENCLAVE_NAME }}

- name: List second CDK L2 chain databases (erigon)
run: |
postgres2_port=$(kurtosis port print ${{ env.ENCLAVE_NAME }} postgres-002 postgres | cut -d':' -f3)
PGPASSWORD=master_password psql --host 127.0.0.1 --port "$postgres2_port" --username master_user --dbname master --list
- name: Update the agglayer config
run: |
Expand Down Expand Up @@ -100,6 +110,11 @@ jobs:
- name: Inspect enclave
run: kurtosis enclave inspect ${{ env.ENCLAVE_NAME }}

- name: List first CDK L2 chain databases (zkevm)
run: |
postgres1_port=$(kurtosis port print ${{ env.ENCLAVE_NAME }} postgres-001 postgres | cut -d':' -f3)
PGPASSWORD=master_password psql --host 127.0.0.1 --port "$postgres1_port" --username master_user --dbname master --list
- name: Attach a second CDK L2 chain (erigon)
run: |
Expand All @@ -108,6 +123,11 @@ jobs:
- name: Inspect enclave
run: kurtosis enclave inspect ${{ env.ENCLAVE_NAME }}

- name: List second CDK L2 chain databases (erigon)
run: |
postgres2_port=$(kurtosis port print ${{ env.ENCLAVE_NAME }} postgres-002 postgres | cut -d':' -f3)
PGPASSWORD=master_password psql --host 127.0.0.1 --port "$postgres2_port" --username master_user --dbname master --list
- name: Update the agglayer config
run: |
Expand Down
4 changes: 3 additions & 1 deletion cdk_bridge_infra.star
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ databases = import_module("./databases.star")

def run(plan, args):
contract_setup_addresses = service_package.get_contract_setup_addresses(plan, args)
db_configs = databases.get_db_configs(args["deployment_suffix"])
db_configs = databases.get_db_configs(
args["deployment_suffix"], args["sequencer_type"]
)

# Create the bridge service config.
bridge_config_artifact = create_bridge_config_artifact(
Expand Down
5 changes: 4 additions & 1 deletion cdk_central_environment.star
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ databases = import_module("./databases.star")


def run(plan, args):
db_configs = databases.get_db_configs(args["deployment_suffix"])
db_configs = databases.get_db_configs(
args["deployment_suffix"], args["sequencer_type"]
)

# Start prover.
prover_config_template = read_file(
src="./templates/trusted-node/prover-config.json"
Expand Down
124 changes: 73 additions & 51 deletions databases.star
Original file line number Diff line number Diff line change
Expand Up @@ -22,71 +22,89 @@ POSTGRES_MASTER_PASSWORD = "master_password"
# This way, users can also leverage our 'reset_postgres.sh' script,
# Which automatically wipes all CDK databases and reapplies proper db permissions
# TO DO: add env var support for credentials
TRUSTED_DATABASES = {
"event_db": {
"name": "event_db",
"user": "event_user",

# Databases that make up the central environment of an L2 chain, including sequencer, aggregator,
# prover, bridge service, and DAC.
CENTRAL_ENV_DBS = {
"aggregator_db": {
"name": "aggregator_db",
"user": "aggregator_user",
"password": "redacted",
"init": read_file(src="./templates/databases/event-db-init.sql"),
},
"pool_db": {
"name": "pool_db",
"user": "pool_user",
"aggregator_syncer_db": {
"name": "aggregator_syncer_db",
"user": "aggregator_syncer_db_user",
"password": "redacted",
},
"pool_manager_db": {
"name": "pool_manager_db",
"user": "pool_manager_user",
"bridge_db": {
"name": "bridge_db",
"user": "bridge_user",
"password": "redacted",
},
"dac_db": {
"name": "dac_db",
"user": "dac_user",
"password": "redacted",
},
}

# The prover database is a component of both central environment and permissionless zkEVM node environment.
# Therefore, it is defined separately.
PROVER_DB = {
"prover_db": {
"name": "prover_db",
"user": "prover_user",
"password": "redacted",
"init": read_file(src="./templates/databases/prover-db-init.sql"),
},
"state_db": {
"name": "state_db",
"user": "state_user",
}
}

# Databases required for a zkevm node to function as either a sequencer or a permissionless node.
ZKEVM_NODE_DBS = {
"event_db": {
"name": "event_db",
"user": "event_user",
"password": "redacted",
"init": read_file(src="./templates/databases/event-db-init.sql"),
},
"aggregator_db": {
"name": "aggregator_db",
"user": "aggregator_user",
"pool_db": {
"name": "pool_db",
"user": "pool_user",
"password": "redacted",
},
"aggregator_syncer_db": {
"name": "syncer_db",
"user": "syncer_user",
"state_db": {
"name": "state_db",
"user": "state_user",
"password": "redacted",
},
}

PERMISSIONLESS_DATABASES = {
"bridge_db": {
"name": "bridge_db",
"user": "bridge_user",
"password": "redacted",
},
"dac_db": {
"name": "dac_db",
"user": "dac_user",
# Databases required for a cdk erigon node to function as either a sequencer or a permissionless node.
CDK_ERIGON_DBS = {
"pool_manager_db": {
"name": "pool_manager_db",
"user": "pool_manager_user",
"password": "redacted",
},
}
}

DATABASES = TRUSTED_DATABASES | PERMISSIONLESS_DATABASES

DATABASES = CENTRAL_ENV_DBS | PROVER_DB | ZKEVM_NODE_DBS | CDK_ERIGON_DBS

def _service_name(suffix):
return POSTGRES_SERVICE_NAME + suffix

def run(plan, suffix, sequencer_type):
db_configs = get_db_configs(suffix, sequencer_type)
create_postgres_service(plan, db_configs, suffix)

def _pless_suffix(suffix):
return "-pless" + suffix

def get_db_configs(suffix, sequencer_type):
dbs = None
if sequencer_type == "erigon":
dbs = CENTRAL_ENV_DBS | PROVER_DB | CDK_ERIGON_DBS
elif sequencer_type == "zkevm":
dbs = CENTRAL_ENV_DBS | PROVER_DB | ZKEVM_NODE_DBS
else:
fail("Unsupported sequencer type: %s" % sequencer_type)

def get_db_configs(suffix):
configs = {
k: v
| {
Expand All @@ -95,12 +113,22 @@ def get_db_configs(suffix):
else _service_name(suffix),
"port": POSTGRES_PORT,
}
for k, v in DATABASES.items()
for k, v in dbs.items()
}
return configs


def get_pless_db_configs(suffix):
def _service_name(suffix):
return POSTGRES_SERVICE_NAME + suffix


def run_pless_zkevm(plan, suffix):
db_configs = get_pless_zkevm_db_configs(suffix)
create_postgres_service(plan, db_configs, _pless_suffix(suffix))


def get_pless_zkevm_db_configs(suffix):
dbs = ZKEVM_NODE_DBS | PROVER_DB
configs = {
k: v
| {
Expand All @@ -109,11 +137,15 @@ def get_pless_db_configs(suffix):
else _service_name(_pless_suffix(suffix)),
"port": POSTGRES_PORT,
}
for k, v in TRUSTED_DATABASES.items()
for k, v in dbs.items()
}
return configs


def _pless_suffix(suffix):
return "-pless" + suffix


def create_postgres_service(plan, db_configs, suffix):
init_script_tpl = read_file(src="./templates/databases/init.sql")
init_script = plan.render_templates(
Expand Down Expand Up @@ -149,13 +181,3 @@ def create_postgres_service(plan, db_configs, suffix):
config=postgres_service_cfg,
description="Starting Postgres Service",
)


def run(plan, suffix):
db_configs = get_db_configs(suffix)
create_postgres_service(plan, db_configs, suffix)


def run_pless(plan, suffix):
db_configs = get_pless_db_configs(suffix)
create_postgres_service(plan, db_configs, _pless_suffix(suffix))
12 changes: 8 additions & 4 deletions main.star
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,16 @@ def run(
else:
plan.print("Skipping the deployment of helper service to retrieve rollup data")

# Deploy zkevm node and cdk peripheral databases.
# Deploy databases.
if deploy_databases:
plan.print("Deploying zkevm node and cdk peripheral databases")
import_module(databases_package).run(plan, suffix=args["deployment_suffix"])
plan.print("Deploying databases")
import_module(databases_package).run(
plan,
suffix=args["deployment_suffix"],
sequencer_type=args["sequencer_type"],
)
else:
plan.print("Skipping the deployment of zkevm node and cdk peripheral databases")
plan.print("Skipping the deployment of databases")

# Get the genesis file.
genesis_artifact = ""
Expand Down
4 changes: 2 additions & 2 deletions src/additional_services/pless_zkevm_node.star
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ databases_package = import_module("../../databases.star")

def run(plan, args, genesis_artifact):
# Start dbs.
databases_package.run_pless(plan, suffix=args["original_suffix"])
db_config = databases_package.get_pless_db_configs(args["original_suffix"])
databases_package.run_pless_zkevm(plan, suffix=args["original_suffix"])
db_config = databases_package.get_pless_zkevm_db_configs(args["original_suffix"])

# Start executor.
executor_config_template = read_file(
Expand Down
4 changes: 3 additions & 1 deletion zkevm_pool_manager.star
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ databases = import_module("./databases.star")


def run_zkevm_pool_manager(plan, args):
db_configs = databases.get_db_configs(args["deployment_suffix"])
db_configs = databases.get_db_configs(
args["deployment_suffix"], args["sequencer_type"]
)

zkevm_pool_manager_config_artifact = create_zkevm_pool_manager_config_artifact(
plan, args, db_configs
Expand Down

0 comments on commit 771c9f9

Please sign in to comment.