Skip to content
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

Prod bootstrap #170

Draft
wants to merge 16 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .darglint
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[darglint]
# Disable darglint checks for private functions.
ignore_regex=^_(.*)
ignore=DAR402
ignore=DAR402,DAR101
3 changes: 2 additions & 1 deletion .flake8
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ docstring-convention=google
# D212 and D213 are mutually exclusive, so we're only allowing D213.
# D205 and D415 don't like multi-line summary statements, which is annoying.
# E203 and W503 don't interact well with black
ignore = D205,D212,D415,E203,W503
# D417 asks for params in the docstring - it's not necessary because of Click
ignore = D205,D212,D415,E203,W503,D417

# This is the line length that black uses
# https://black.readthedocs.io/en/stable/the_black_code_style.html#line-length
Expand Down
2 changes: 2 additions & 0 deletions xbridge_cli/server/config/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
generate_bootstrap,
generate_witness_config,
)
from xbridge_cli.server.config.prod import create_prod_server_configs


@click.group(name="create-config")
Expand All @@ -18,5 +19,6 @@ def create_server_configs() -> None:
create_server_configs.add_command(generate_all_configs, name="all")
create_server_configs.add_command(generate_bootstrap, name="bootstrap")
create_server_configs.add_command(generate_witness_config, name="witness")
create_server_configs.add_command(create_prod_server_configs, name="prod")

__all__ = ["create_server_configs"]
20 changes: 20 additions & 0 deletions xbridge_cli/server/config/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,13 @@ def _generate_rippled_configs(config_dir: str, docker: bool = False) -> Tuple[in
is_flag=True,
help="Whether the config files are for a docker setup.",
)
@click.option(
"--locking-ip",
"locking_chain_ip",
default="127.0.0.1",
type=str,
help="The IP address of the locking chain node.",
)
@click.option(
"--locking-port",
"locking_chain_port",
Expand All @@ -136,6 +143,13 @@ def _generate_rippled_configs(config_dir: str, docker: bool = False) -> Tuple[in
type=int,
help="The port used by the locking chain.",
)
@click.option(
"--issuing-ip",
"issuing_chain_ip",
default="127.0.0.1",
type=str,
help="The IP address of the issuing chain node.",
)
@click.option(
"--issuing-port",
"issuing_chain_port",
Expand Down Expand Up @@ -227,7 +241,9 @@ def _generate_rippled_configs(config_dir: str, docker: bool = False) -> Tuple[in
def generate_witness_config(
config_dir: str,
name: str,
locking_chain_ip: str,
locking_chain_port: int,
issuing_chain_ip: str,
issuing_chain_port: int,
witness_port: int,
locking_reward_seed: str,
Expand All @@ -249,6 +265,8 @@ def generate_witness_config(
Args:
config_dir: The folder in which to store config files.
name: The name of the witness server.
locking_chain_ip: The IP address of the locking chain node.
issuing_chain_ip: The IP address of the issuing chain node.
locking_chain_port: The port used by the locking chain.
issuing_chain_port: The port used by the issuing chain.
witness_port: The port that will be used by the witness server.
Expand Down Expand Up @@ -293,7 +311,9 @@ def generate_witness_config(
log_file = os.path.join(sub_dir, "witness.log")

template_data = {
"locking_chain_ip": locking_chain_ip,
"locking_chain_port": locking_chain_port,
"issuing_chain_ip": issuing_chain_ip,
"issuing_chain_port": issuing_chain_port,
"witness_port": witness_port,
"db_dir": os.path.join(sub_dir, "db"),
Expand Down
24 changes: 24 additions & 0 deletions xbridge_cli/server/config/prod/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
"""Subcommand for all commands dealing with production server config file generation."""

import click

from xbridge_cli.server.config.prod.bootstrap import (
combine_bootstrap_pieces,
get_bootstrap_piece_from_witness,
)
from xbridge_cli.server.config.prod.witness import generate_prod_witness_config


@click.group(name="prod")
def create_prod_server_configs() -> None:
"""Subcommand for production server config file generation."""
pass


create_prod_server_configs.add_command(generate_prod_witness_config, name="witness")
create_prod_server_configs.add_command(
get_bootstrap_piece_from_witness, name="bootstrap"
)
create_prod_server_configs.add_command(combine_bootstrap_pieces, name="combine")

__all__ = ["create_prod_server_configs"]
157 changes: 157 additions & 0 deletions xbridge_cli/server/config/prod/bootstrap.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
"""Generate files related to a production bootstrap file."""

import json
import os
from sys import platform
from typing import List, Optional

import click
from xrpl import CryptoAlgorithm
from xrpl.wallet import Wallet

from xbridge_cli.server.config.config import _generate_template


@click.command(name="bootstrap")
@click.option(
"-w",
"--witness_file",
required=True,
prompt=True,
type=click.Path(exists=True),
help="The location of the witness config file.",
)
@click.option(
"-o",
"--output_file",
prompt=True,
default="./bootstrap-piece.json",
type=click.Path(),
help=(
"The location of the witness config file. The default is "
"'./bootstrap-piece.json'."
),
)
def get_bootstrap_piece_from_witness(
witness_file: str, output_file: Optional[str] = "./bootstrap-piece.json"
) -> None:
"""
Extract the info needed for the bootstrap file from a witness config file, without
revealing any secret information.
"""
with open(witness_file) as f:
witness_config = json.load(f)

locking_config = witness_config["LockingChain"]
issuing_config = witness_config["IssuingChain"]

locking_reward_account = locking_config["RewardAccount"]
locking_submit_account = locking_config["TxnSubmit"]["SubmittingAccount"]
issuing_reward_account = issuing_config["RewardAccount"]
issuing_submit_account = issuing_config["TxnSubmit"]["SubmittingAccount"]
signing_key_seed = witness_config["SigningKeySeed"]
signing_key_algo = CryptoAlgorithm(witness_config["SigningKeyType"].upper())
signing_key_account = Wallet.from_seed(
signing_key_seed, algorithm=signing_key_algo
).classic_address

template_data = {
"locking_reward_account": locking_reward_account,
"locking_submit_account": locking_submit_account,
"issuing_reward_account": issuing_reward_account,
"issuing_submit_account": issuing_submit_account,
"signing_key_type": signing_key_algo.value,
"signing_key_account": signing_key_account,
}

# add the rippled.cfg file
_generate_template(
"bootstrap-witness.jinja",
template_data,
output_file or os.path.join(os.getcwd(), "bootstrap-witness.json"),
)


@click.command(name="combine")
@click.option(
"-l",
"--locking_seed",
"locking_door_seed",
required=True,
prompt=True,
help="The seed of the locking chain's door account.",
)
@click.option(
"-i",
"--issuing_seed",
"issuing_door_seed",
required=True,
prompt=True,
help="The seed of the issuing chain's door account.",
)
@click.option(
"-b",
"--bootstrap_piece",
"bootstrap_pieces",
required=True,
multiple=True,
type=click.Path(exists=True),
help="One of the bootstrap pieces. Must include all of them here.",
)
def combine_bootstrap_pieces(
locking_door_seed: str,
issuing_door_seed: str,
bootstrap_pieces: List[str],
) -> None:
"""Combine the bootstrap witness files into the bridge bootstrap file."""
locking_reward_accounts = []
locking_submit_accounts = []
issuing_reward_accounts = []
issuing_submit_accounts = []
signing_accounts = []
for bootstrap_piece in bootstrap_pieces:
with open(os.path.abspath(bootstrap_piece)) as f:
bootstrap_config = json.load(f)
locking_reward_accounts.append(
bootstrap_config["LockingChain"]["RewardAccount"]
)
locking_submit_accounts.append(
bootstrap_config["LockingChain"]["SubmitAccount"]
)
issuing_reward_accounts.append(
bootstrap_config["IssuingChain"]["RewardAccount"]
)
issuing_submit_accounts.append(
bootstrap_config["IssuingChain"]["SubmitAccount"]
)
signing_accounts.append(bootstrap_config["SigningKeyAccount"])

locking_door = Wallet.from_seed(locking_door_seed)
issuing_door = Wallet.from_seed(issuing_door_seed)
locking_issue = "XRP"
issuing_issue = "XRP"

template_data = {
"is_linux": platform == "linux" or platform == "linux2",
"locking_node_port": 5005,
"locking_door_account": locking_door.classic_address,
"locking_door_seed": locking_door.seed,
"locking_issue": repr(locking_issue).replace("'", '"'),
"locking_reward_accounts": locking_reward_accounts,
"locking_submit_accounts": locking_submit_accounts,
"issuing_node_port": 5006,
"issuing_door_account": issuing_door.classic_address,
"issuing_door_seed": issuing_door.seed,
"issuing_issue": repr(issuing_issue).replace("'", '"'),
"issuing_reward_accounts": issuing_reward_accounts,
"issuing_submit_accounts": issuing_reward_accounts,
"signing_accounts": signing_accounts,
}
# if verbose:
# click.echo(pformat(template_data))

_generate_template(
"bootstrap.jinja",
template_data,
os.path.join(os.getcwd(), "bridge_bootstrap.json"),
)
Loading
Loading