Skip to content

Commit

Permalink
reformat
Browse files Browse the repository at this point in the history
  • Loading branch information
wanwiset25 committed Aug 12, 2024
1 parent 644545e commit a8fbcef
Show file tree
Hide file tree
Showing 5 changed files with 139 additions and 97 deletions.
14 changes: 10 additions & 4 deletions subnet/deployment-generator/src/config_gen.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@ const config = {
process.env.IMAGE_NAME || "xinfinorg/subnet-generator:latest",
operating_system: process.env.OS || "linux",
version: {
subnet: (process.env.VERSION_SUBNET || 'feature-v1-release'),
bootnode: (process.env.VERSION_BOOTNODE || 'feature-v1-release'),
subnet: process.env.VERSION_SUBNET || "feature-v1-release",
bootnode: process.env.VERSION_BOOTNODE || "feature-v1-release",
// observer: (process.env.VERSION_OBSERVER || 'latest'),
relayer: process.env.VERSION_RELAYER || "feature-v1-release",
stats: process.env.VERSION_STATS || "feature-v1-release",
frontend: process.env.VERSION_FRONTEND || "feature-v1-release",
// csc: process.env.VERSION_CSC || "v0.2.0",
csc: process.env.VERSION_CSC || "feature-v0.2.1",
zero: (process.env.VERSION_ZERO || 'v0.1.0')
zero: process.env.VERSION_ZERO || "v0.1.0",
},
parentnet: {
network: process.env.PARENTNET || "testnet",
Expand Down Expand Up @@ -97,7 +97,13 @@ function configSanityCheck(config) {
process.exit(1);
}

if (!(config.relayer_mode === "full" || config.relayer_mode === "lite" || config.relayer_mode === "temp" )) {
if (
!(
config.relayer_mode === "full" ||
config.relayer_mode === "lite" ||
config.relayer_mode === "temp"
)
) {
console.log("RELAYER_MODE only accepts 'full' or 'lite' (default full)");
process.exit(1);
}
Expand Down
29 changes: 22 additions & 7 deletions subnet/deployment-generator/src/gen.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,14 @@ if (config.operating_system === "mac") {
for (let i = 1; i <= config.num_subnet; i++) {
subnetconf.push(gen_env.genSubnetConfigMac(i, keys, ip_record));
}
deployconf = gen_env.genContractDeployEnvMac()
deployconf = gen_env.genContractDeployEnvMac();
} else if (config.operating_system === "linux") {
commonconf = gen_env.genServicesConfig();
subnetconf = [];
for (let i = 1; i <= config.num_subnet; i++) {
subnetconf.push(gen_env.genSubnetConfig(i, keys));
}
deployconf = gen_env.genContractDeployEnv()
deployconf = gen_env.genContractDeployEnv();
} else {
console.log(`ERROR: unknown OS ${config.operating_system} not supported`);
process.exit(1);
Expand Down Expand Up @@ -199,9 +199,24 @@ function copyScripts(output_dir) {
exit();
}
});
fs.copyFileSync(`${__dirname}/../scripts/check-mining.sh`, `${output_dir}/scripts/check-mining.sh`);
fs.copyFileSync(`${__dirname}/../scripts/check-peer.sh`, `${output_dir}/scripts/check-peer.sh`);
fs.copyFileSync(`${__dirname}/../scripts/docker-up.sh`, `${output_dir}/scripts/docker-up.sh`);
fs.copyFileSync(`${__dirname}/../scripts/docker-down.sh`, `${output_dir}/scripts/docker-down.sh`);
fs.copyFileSync(`${__dirname}/../scripts/csc.sh`, `${output_dir}/scripts/csc.sh`);
fs.copyFileSync(
`${__dirname}/../scripts/check-mining.sh`,
`${output_dir}/scripts/check-mining.sh`
);
fs.copyFileSync(
`${__dirname}/../scripts/check-peer.sh`,
`${output_dir}/scripts/check-peer.sh`
);
fs.copyFileSync(
`${__dirname}/../scripts/docker-up.sh`,
`${output_dir}/scripts/docker-up.sh`
);
fs.copyFileSync(
`${__dirname}/../scripts/docker-down.sh`,
`${output_dir}/scripts/docker-down.sh`
);
fs.copyFileSync(
`${__dirname}/../scripts/csc.sh`,
`${output_dir}/scripts/csc.sh`
);
}
6 changes: 3 additions & 3 deletions subnet/deployment-generator/src/gen_compose.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,9 @@ function genServices(machine_id) {
restart: "always",
env_file: config_path, // not used directly (injected via volume) but required to trigger restart if common.env changes
volumes: [`${config_path}:/app/.env.local`],
ports: ['6000:6000'],
profiles: [machine]
}
ports: ["6000:6000"],
profiles: [machine],
};
const relayer = {
image: `xinfinorg/xdc-relayer:${config.version.relayer}`,
restart: "always",
Expand Down
15 changes: 7 additions & 8 deletions subnet/deployment-generator/src/gen_env.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ module.exports = {
genServicesConfigMac,
genContractDeployEnv,
genContractDeployEnvMac,

};

function genSubnetConfig(subnet_id, key) {
Expand Down Expand Up @@ -148,7 +147,7 @@ PARENTNET_WALLET_PK=${config.parentnet.privatekey}
return config_env;
}

function genContractDeployEnvMac(){
function genContractDeployEnvMac() {
const config_deploy = `
PARENTNET_URL=${config.parentnet.url}
SUBNET_URL=http://${ip_record["subnet1"]}:8545
Expand All @@ -164,11 +163,11 @@ REVERSE_CSC=0x0000000000000000000000000000000000000000
# PARENTNET_ZERO_CONTRACT=0x0000000000000000000000000000000000000000
# SUBNET_APP=0x0000000000000000000000000000000000000000
# PARENTNET_APP=0x0000000000000000000000000000000000000000
`
return config_deploy
`;
return config_deploy;
}

function genContractDeployEnv(){
function genContractDeployEnv() {
const config_deploy = `
PARENTNET_URL=${config.parentnet.url}
SUBNET_URL=http://${config.ip_1}:8545
Expand All @@ -185,6 +184,6 @@ REVERSE_CSC=0x0000000000000000000000000000000000000000
# PARENTNET_ZERO_CONTRACT=0x0000000000000000000000000000000000000000
# SUBNET_APP=0x0000000000000000000000000000000000000000
# PARENTNET_APP=0x0000000000000000000000000000000000000000
`
return config_deploy
}
`;
return config_deploy;
}
172 changes: 97 additions & 75 deletions subnet/deployment-generator/src/gen_other.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,101 +72,123 @@ function genDeploymentJson(keys) {
function genCommands() {
const conf_path = __dirname + "/config/";
const set_env = "SUBNET_CONFIG_PATH=" + conf_path;
let csc_mode = "full"
if (config.relayer_mode == "lite"){
csc_mode = "lite"
let csc_mode = "full";
if (config.relayer_mode == "lite") {
csc_mode = "lite";
}
let commands = "";
commands += "Start under generated/ directory\n"
commands += "Start under generated/ directory\n";
commands += "\n1. Deploy Subnet nodes\n";
for (let i = 1; i <= config.num_machines; i++) {
const machine_name = "machine" + i.toString();
if (config.num_machines > 1){
commands +=
machine_name + `: deploy subnet on machine${i}\n`;
if (config.num_machines > 1) {
commands +=
machine_name + `: deploy subnet on machine${i}\n`;
}
if (i !== 1) {
commands += ` Prerequisite: copy docker-compose.yml,docker-compose.env,config/subnetX.env to ${machine_name}. Make sure docker-compose.env points to subnetX.env directory.\n`;
}
commands += ` docker compose --env-file docker-compose.env --profile ${machine_name} pull\n`;
commands += ` docker compose --env-file docker-compose.env --profile ${machine_name} up -d\n\n`;
}
commands += "\n2. After 60 seconds, confirm the Subnet is running correctly\n";
commands += " ./scripts/check-mining.sh\n"
commands += "\n3. Deploy Checkpoint Smart Contract (CSC)\n"
commands += ` docker pull xinfinorg/csc:${config.version.csc}\n`
if (config.operating_system == 'mac'){
commands += ` docker run --env-file contract_deploy.env --network generated_docker_net xinfinorg/csc:${config.version.csc} ${csc_mode}\n`
commands +=
"\n2. After 60 seconds, confirm the Subnet is running correctly\n";
commands += " ./scripts/check-mining.sh\n";
commands += "\n3. Deploy Checkpoint Smart Contract (CSC)\n";
commands += ` docker pull xinfinorg/csc:${config.version.csc}\n`;
if (config.operating_system == "mac") {
commands += ` docker run --env-file contract_deploy.env --network generated_docker_net xinfinorg/csc:${config.version.csc} ${csc_mode}\n`;
} else {
commands += ` docker run --env-file contract_deploy.env xinfinorg/csc:${config.version.csc} ${csc_mode}\n`
commands += ` docker run --env-file contract_deploy.env xinfinorg/csc:${config.version.csc} ${csc_mode}\n`;
}
commands += "\n4. Add CSC configuration to common.env\n"
commands += " - copy step 3. output CHECKPOINT_CONTRACT to common.env\n"
commands += "\n5. Start services (relayer, backend, frontend)\n"
commands += "\n4. Add CSC configuration to common.env\n";
commands += " - copy step 3. output CHECKPOINT_CONTRACT to common.env\n";
commands += "\n5. Start services (relayer, backend, frontend)\n";
commands += ` docker compose --env-file docker-compose.env --profile services pull\n`;
commands += ` docker compose --env-file docker-compose.env --profile services up -d\n`;
commands += "\n6. Confirm Subnet services through browser UI\n"
commands += ` Frontend: http://${config.public_ip}:6000\n`
commands += ` Relayer: http://${config.public_ip}:4000\n`

if (config.relayer_mode == 'lite'){
commands += "\n6. Confirm Subnet services through browser UI\n";
commands += ` Frontend: http://${config.public_ip}:6000\n`;
commands += ` Relayer: http://${config.public_ip}:4000\n`;

} else if (config.relayer_mode == 'full'){
commands += "\n\nOPTIONAL: Deploy XDC-Zero crosschain framework (one-directional)\n"
commands += "\n1. Add CSC configuration to contract_deploy.env\n"
commands += " - copy CHECKPOINT_CONTRACT from common.env to and rename it to CSC in contract_deploy.env\n"
commands += " - copy CHECKPOINT_CONTRACT from common.env to and rename it to REVERSE_CSC in contract_deploy.env\n"
commands += "\n2. Deploy XDC-Zero\n"
commands += ` docker pull xinfinorg/xdc-zero:${config.version.zero}\n`
commands += ` docker run --env-file contract_deploy.env --network generated_docker_net xinfinorg/xdc-zero:${config.version.zero} endpointandregisterchain\n`
commands += " \n (Optional) Deploy Subswap and Register Application to XDC-Zero\n"
commands += " - copy SUBNET_ZERO_CONTRACT and PARENTNET_ZERO_CONTRACT to contract_deploy.env\n"
commands += " docker run --env-file contract_deploy.env --network generated_docker_net xinfinorg/xdc-zero:v0.1.0 subswap\n"
commands += " - copy SUBNET_APP and PARENTNET_APP to contract_deploy.env\n"
commands += " docker run --env-file contract_deploy.env --network generated_docker_net xinfinorg/xdc-zero:v0.1.0 applicationregister\n"
commands += "\n3. Add XDC-Zero Configuration to common.env\n"
commands += " - copy step 2. output SUBNET_ZERO_CONTRACT and PARENTNET_ZERO_CONTRACT to common.env\n"
commands += " - Add PARENTNET_ZERO_WALLET_PK to common.env, this should be different from PARENTNET_WALLET_PK\n"
commands += "\n4. Restart Relayer\n"
commands += ` docker compose --env-file docker-compose.env --profile services down\n`;
commands += ` docker compose --env-file docker-compose.env --profile services up -d\n`;
commands += "\n5. Confirm Relayer is running \n"
commands += ` Relayer: http://${config.public_ip}:4000\n`
commands += ` Frontend: http://${config.public_ip}:6000\n`
} else if (config.relayer_mode == 'temp'){
commands += "\n\nOPTIONAL: Deploy XDC-Zero crosschain framework (bi-directional)\n"
commands += "\n1. Deploy Reverse Checkpoint Smart Contract (Reverse CSC)"
commands += ` docker pull xinfinorg/csc:${config.version.csc}\n`
if (config.operating_system == 'mac'){
commands += ` docker run --env-file contract_deploy.env --network generated_docker_net xinfinorg/csc:${config.version.csc} reverse\n`
if (config.relayer_mode == "lite") {
} else if (config.relayer_mode == "full") {
commands +=
"\n\nOPTIONAL: Deploy XDC-Zero crosschain framework (one-directional)\n";
commands += "\n1. Add CSC configuration to contract_deploy.env\n";
commands +=
" - copy CHECKPOINT_CONTRACT from common.env to and rename it to CSC in contract_deploy.env\n";
commands +=
" - copy CHECKPOINT_CONTRACT from common.env to and rename it to REVERSE_CSC in contract_deploy.env\n";
commands += "\n2. Deploy XDC-Zero\n";
commands += ` docker pull xinfinorg/xdc-zero:${config.version.zero}\n`;
commands += ` docker run --env-file contract_deploy.env --network generated_docker_net xinfinorg/xdc-zero:${config.version.zero} endpointandregisterchain\n`;
commands +=
" \n (Optional) Deploy Subswap and Register Application to XDC-Zero\n";
commands +=
" - copy SUBNET_ZERO_CONTRACT and PARENTNET_ZERO_CONTRACT to contract_deploy.env\n";
commands +=
" docker run --env-file contract_deploy.env --network generated_docker_net xinfinorg/xdc-zero:v0.1.0 subswap\n";
commands +=
" - copy SUBNET_APP and PARENTNET_APP to contract_deploy.env\n";
commands +=
" docker run --env-file contract_deploy.env --network generated_docker_net xinfinorg/xdc-zero:v0.1.0 applicationregister\n";
commands += "\n3. Add XDC-Zero Configuration to common.env\n";
commands +=
" - copy step 2. output SUBNET_ZERO_CONTRACT and PARENTNET_ZERO_CONTRACT to common.env\n";
commands +=
" - Add PARENTNET_ZERO_WALLET_PK to common.env, this should be different from PARENTNET_WALLET_PK\n";
commands += "\n4. Restart Relayer\n";
commands += ` docker compose --env-file docker-compose.env --profile services down\n`;
commands += ` docker compose --env-file docker-compose.env --profile services up -d\n`;
commands += "\n5. Confirm Relayer is running \n";
commands += ` Relayer: http://${config.public_ip}:4000\n`;
commands += ` Frontend: http://${config.public_ip}:6000\n`;
} else if (config.relayer_mode == "temp") {
commands +=
"\n\nOPTIONAL: Deploy XDC-Zero crosschain framework (bi-directional)\n";
commands += "\n1. Deploy Reverse Checkpoint Smart Contract (Reverse CSC)";
commands += ` docker pull xinfinorg/csc:${config.version.csc}\n`;
if (config.operating_system == "mac") {
commands += ` docker run --env-file contract_deploy.env --network generated_docker_net xinfinorg/csc:${config.version.csc} reverse\n`;
} else {
commands += ` docker run --env-file contract_deploy.env xinfinorg/csc:${config.version.csc} reversefull\n`
commands += ` docker run --env-file contract_deploy.env xinfinorg/csc:${config.version.csc} reversefull\n`;
}
commands += "\n2. Add CSC and Reverse CSC configuration"
commands += " - copy previous step output REVERSE_CHECKPOINT_CONTRACT to common.env\n"
commands += " - copy REVERSE_CHECKPOINT_CONTRACT from common.env and rename it to REVERSE_CSC in contract_deploy.env\n"
commands += " - copy CHECKPOINT_CONTRACT from common.env and rename it to CSC in contract_deploy.env\n"
commands += "\n3. Deploy XDC-Zero\n"
commands += ` docker pull xinfinorg/xdc-zero:${config.version.zero}\n`
commands += ` docker run --env-file contract_deploy.env xinfinorg/xdc-zero:${config.version.zero} endpointandregisterchain\n`
commands += " \n (Optional) Deploy Subswap and Register Application to XDC-Zero\n"
commands += " - copy SUBNET_ZERO_CONTRACT and PARENTNET_ZERO_CONTRACT to contract_deploy.env\n"
commands += " docker run --env-file contract_deploy.env xinfinorg/xdc-zero:v0.1.0 subswap\n"
commands += " - copy SUBNET_APP and PARENTNET_APP to contract_deploy.env\n"
commands += " docker run --env-file contract_deploy.env xinfinorg/xdc-zero:v0.1.0 applicationregister\n"
commands += "\n4. Add XDC-Zero Configuration to common.env\n"
commands += " - copy step 3. output SUBNET_ZERO_CONTRACT and PARENTNET_ZERO_CONTRACT to common.env\n"
commands += " - Add SUBNET_WALLET_PK and SUBNET_ZERO_WALLET_PK to common.env, they should be different from each other\n"
commands += " - Add PARENTNET_ZERO_WALLET_PK to common.env, this should be different from PARENTNET_WALLET_PK\n"
commands += "\n5. Restart Relayer\n"
commands += ` docker compose --env-file docker-compose.env --profile services down\n`;
commands += ` docker compose --env-file docker-compose.env --profile services up -d\n`;
commands += "\n6. Confirm Relayer is running \n"
commands += ` Relayer: http://${config.public_ip}:4000\n`
commands += ` Frontend: http://${config.public_ip}:6000\n`
commands += "\n2. Add CSC and Reverse CSC configuration";
commands +=
" - copy previous step output REVERSE_CHECKPOINT_CONTRACT to common.env\n";
commands +=
" - copy REVERSE_CHECKPOINT_CONTRACT from common.env and rename it to REVERSE_CSC in contract_deploy.env\n";
commands +=
" - copy CHECKPOINT_CONTRACT from common.env and rename it to CSC in contract_deploy.env\n";
commands += "\n3. Deploy XDC-Zero\n";
commands += ` docker pull xinfinorg/xdc-zero:${config.version.zero}\n`;
commands += ` docker run --env-file contract_deploy.env xinfinorg/xdc-zero:${config.version.zero} endpointandregisterchain\n`;
commands +=
" \n (Optional) Deploy Subswap and Register Application to XDC-Zero\n";
commands +=
" - copy SUBNET_ZERO_CONTRACT and PARENTNET_ZERO_CONTRACT to contract_deploy.env\n";
commands +=
" docker run --env-file contract_deploy.env xinfinorg/xdc-zero:v0.1.0 subswap\n";
commands +=
" - copy SUBNET_APP and PARENTNET_APP to contract_deploy.env\n";
commands +=
" docker run --env-file contract_deploy.env xinfinorg/xdc-zero:v0.1.0 applicationregister\n";
commands += "\n4. Add XDC-Zero Configuration to common.env\n";
commands +=
" - copy step 3. output SUBNET_ZERO_CONTRACT and PARENTNET_ZERO_CONTRACT to common.env\n";
commands +=
" - Add SUBNET_WALLET_PK and SUBNET_ZERO_WALLET_PK to common.env, they should be different from each other\n";
commands +=
" - Add PARENTNET_ZERO_WALLET_PK to common.env, this should be different from PARENTNET_WALLET_PK\n";
commands += "\n5. Restart Relayer\n";
commands += ` docker compose --env-file docker-compose.env --profile services down\n`;
commands += ` docker compose --env-file docker-compose.env --profile services up -d\n`;
commands += "\n6. Confirm Relayer is running \n";
commands += ` Relayer: http://${config.public_ip}:4000\n`;
commands += ` Frontend: http://${config.public_ip}:6000\n`;
} else {
console.log("Error: Invalid Relayer Mode")
exit()
console.log("Error: Invalid Relayer Mode");
exit();
}

return commands;
Expand Down

0 comments on commit a8fbcef

Please sign in to comment.