Skip to content

Commit 56daaf3

Browse files
committed
update
1 parent f5682d3 commit 56daaf3

File tree

7 files changed

+156
-13
lines changed

7 files changed

+156
-13
lines changed

container-manager/src/gen/gen_other.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,18 @@ function genXdposKeys() {
2424
short: address.replace(/^0x/i, ""),
2525
};
2626
}
27-
27+
keys["Owner"] = {
28+
PrivateKey: config.keys.grandmaster_pk,
29+
"0x": config.keys.grandmaster_addr,
30+
short: config.keys.grandmaster_addr.replace(/^0x/i, ""),
31+
};
32+
if (Object.keys(keys).length !== config.num_subnet + 1) {
33+
// sanity check
34+
console.log("bad case, key length not equal number of subnets");
35+
console.log(Object.keys(keys).length, config.num_subnet + 1);
36+
console.log(keys);
37+
process.exit();
38+
}
2839
return keys;
2940
}
3041

container-manager/src/gen/gen_xdpos.js

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
const crypto = require("crypto");
22
const fs = require("fs");
3+
const net = require("net");
34
const ethers = require("ethers");
45
const yaml = require("js-yaml");
56
const { exit } = require("process");
@@ -167,6 +168,46 @@ function copyScripts(output_dir) {
167168
}
168169

169170
function initConfig(config) {
171+
if (!config.num_machines || !config.num_subnet || !config.network_name) {
172+
console.log("NUM_MACHINE and NUM_SUBNET and NETWORK_NAME must be set");
173+
process.exit(1);
174+
}
175+
176+
if (config.num_machines < 1 || config.num_subnet < 1) {
177+
console.log("NUM_MACHINE and NUM_SUBNET must be 1 or more");
178+
process.exit(1);
179+
}
180+
181+
if (net.isIP(config.main_ip) != 0) {
182+
console.log("MAIN_IP Invalid IP address");
183+
process.exit(1);
184+
}
185+
186+
if (!config.network_name || config.network_name === "") {
187+
console.log("NETWORK_NAME cannot be empty");
188+
process.exit(1);
189+
}
190+
191+
if (config.network_id < 1 || config.network_id >= 65536) {
192+
console.log("NETWORK_ID should be in range of 1 to 65536");
193+
process.exit(1);
194+
}
195+
196+
if (config.keys.grandmaster_pk !== "") {
197+
try {
198+
[config.keys.grandmaster_addr, config.keys.grandmaster_pk] = validatePK(
199+
config.keys.grandmaster_pk
200+
);
201+
} catch {
202+
console.log("Invalid GRANDMASTER_PK");
203+
process.exit(1);
204+
}
205+
} else {
206+
const privatekey = crypto.randomBytes(32).toString("hex");
207+
[config.keys.grandmaster_addr, config.keys.grandmaster_pk] =
208+
validatePK(privatekey);
209+
}
210+
170211
if (config.keys.subnets_pk !== "") {
171212
try {
172213
let output_pk = [];

container-manager/src/libs/exec.js

Lines changed: 61 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ async function execute(command, outputHandler, doneHandler) {
148148
}
149149

150150
function generateXdpos(params) {
151-
genEnv = genGenEnv(params);
151+
genEnv = genGenXdposEnv(params);
152152
fs.writeFileSync(path.join(mountPath, "gen.env"), genEnv, (err) => {
153153
//write to mount
154154
if (err) {
@@ -167,7 +167,12 @@ function generateXdpos(params) {
167167
console.log("gen success");
168168

169169
//step 2: generate genesis.json
170-
// command = `cd ${mountPath}; docker run -v ${config.hostPath}:/app/generated/ --entrypoint 'bash' xinfinorg/xdcsubnets:${config.version.genesis} /work/puppeth.sh`;
170+
171+
let genesisVersion = "latest";
172+
if ("customversion-subnet" in params && params["customversion-subnet"] != "") {
173+
genesisVersion = `${params["customversion-subnet"]}`;
174+
}
175+
// command = `cd ${mountPath}; docker run -v ${config.hostPath}:/app/generated/ --entrypoint 'bash' xinfinorg/xdposchain:${genesisVersion} /work/puppeth.sh`;
171176
command = `cd ${mountPath}; docker run -v ${config.hostPath}:/app/generated/ --entrypoint 'bash' test-privnet:latest /work/puppeth.sh`;
172177
console.log(command);
173178
const [result2, out2] = callExec(command);
@@ -327,6 +332,60 @@ RELAYER_MODE=${relayer_mode}
327332
return content;
328333
}
329334

335+
function genGenXdposEnv(input){
336+
console.log(input);
337+
let content_machine = "";
338+
if (input["text-num-machine"] > 1) {
339+
content_machine += `\nMAIN_IP=${input["text-private-ip"]}`;
340+
if (input["text-public-ip"] != "") {
341+
content_machine += `\nPUBLIC_IP=${input["text-public-ip"]}`;
342+
}
343+
if (input["text-num-machine"] != "") {
344+
content_machine += `\nNUM_MACHINE=${input["text-num-machine"]}`;
345+
}
346+
} else {
347+
content_machine += `\nMAIN_IP=127.0.0.1`;
348+
content_machine += `\nNUM_MACHINE=1`;
349+
}
350+
351+
let content_custom_key = "";
352+
if ("customowner-checkbox" in input && input["customowner-checkbox"] != "") {
353+
content_custom_key += `\nGRANDMASTER_PK=${input["customowner-subnet"]}`;
354+
}
355+
if ("customkeys-checkbox" in input && input["customkeys-checkbox"] != "") {
356+
let subnet_keys = [];
357+
let idx = 1;
358+
while ("subnet-key" + idx.toString() in input) {
359+
key = "subnet-key" + idx.toString();
360+
subnet_keys.push(input[key]);
361+
idx++;
362+
}
363+
if (subnet_keys.length > 0) {
364+
key_string = subnet_keys.join(",");
365+
content_custom_key += `\nSUBNETS_PK=${key_string}`;
366+
}
367+
}
368+
369+
let content_version = "";
370+
if ("customversion-subnet" in input && input["customversion-subnet"] != "") {
371+
content_version += `\nVERSION_NODE=${input["customversion-subnet"]}`;
372+
}
373+
374+
content = `
375+
NETWORK_NAME=${input["text-subnet-name"]}
376+
NUM_SUBNET=${input["text-num-subnet"]}
377+
`;
378+
content += content_machine;
379+
content += "\n";
380+
content += content_custom_key;
381+
content += "\n";
382+
content += content_version;
383+
384+
console.log(content);
385+
386+
return content;
387+
}
388+
330389
async function processTransfer(provider, fromWallet, toAddress, amount) {
331390
// fromPK = inputs[2];
332391
// toAddress = inputs[3];

container-manager/src/views/generator/index.pug

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ body
8080
.info-icon(tabindex="0" role="button" aria-label="more info") ?
8181
.tooltip Default is random
8282
label.pure-checkbox(for='customkeys-checkbox') Custom Subnet Keys
83-
input#customkeys-checkbox.checkbox-indent(type='checkbox' name="customkeys-cheeckbox")
83+
input#customkeys-checkbox.checkbox-indent(type='checkbox' name="customkeys-checkbox")
8484
#customkeys.content
8585
.pure-control-group
8686
label() Grandmaster PK

container-manager/src/views/xdpos_generator/custom.css

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,13 @@
130130
display: block;
131131
}
132132

133+
#customowner {
134+
display: none;
135+
}
136+
#customowner-checkbox:checked + #customowner {
137+
display: block;
138+
}
139+
133140
#xdczero {
134141
display: none;
135142
}

container-manager/src/views/xdpos_generator/index.pug

Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,23 +20,23 @@ body
2020
.info-icon(tabindex="0" role="button" aria-label="more info") ?
2121
.tooltip This cannot be changed later.
2222
label() Network Name
23-
input#text-subnet-name(type='text' placeholder='privatechain' name="text-subnet-name")
23+
input#text-subnet-name(type='text' placeholder='privatechain' value='privatechain' name="text-subnet-name")
2424
span.pure-form-message-inline Required
2525

2626
.pure-control-group
2727
.info-container
2828
.info-icon(tabindex="0" role="button" aria-label="more info") ?
2929
.tooltip At least 2/3 of nodes must be online to have consensus and make the blockchain run.
3030
label() Number of Masternodes
31-
input#text-num-subnet(type='number' placeholder='3' name="text-num-subnet")
31+
input#text-num-subnet(type='number' placeholder='3' value='3' name="text-num-subnet")
3232
span.pure-form-message-inline Required
3333

3434
.pure-control-group
3535
.info-container
3636
.info-icon(tabindex="0" role="button" aria-label="more info") ?
3737
.tooltip The generated configs will evenly spread the nodes across the machines.
3838
label() Number of Machines
39-
input#text-num-machine(type='number' placeholder='1' name="text-num-machine" oninput="numMachineMoreThanOne()")
39+
input#text-num-machine(type='number' placeholder='1' value='1' name="text-num-machine" oninput="numMachineMoreThanOne()")
4040

4141
input#checkbox-num-machine(type='checkbox' name='checkbox-num-machine')
4242

@@ -49,13 +49,24 @@ body
4949
input#text-private-ip(type='text' placeholder='192.168.1.1' name="text-private-ip")
5050
span.pure-form-message-inline Required
5151

52+
.pure-control-group
53+
.info-container
54+
.info-icon(tabindex="0" role="button" aria-label="more info") ?
55+
.tooltip Owner delegates stake to Masternode Addresses
56+
label.pure-checkbox(for='customowner-checkbox') Custom Masternodes Owner PK
57+
input#customowner-checkbox.checkbox-indent(type='checkbox' name="customowner-checkbox")
58+
#customowner.content
59+
center
60+
.pure-control-group
61+
label() Masternodes Owner
62+
input#customowner-subnet.pure-input-2-3(type='text' placeholder='0x1111111111111111111111111111111111111111111111111111111111111111' name="customowner-subnet")
5263

5364
.pure-control-group
5465
.info-container
5566
.info-icon(tabindex="0" role="button" aria-label="more info") ?
5667
.tooltip Default is random
5768
label.pure-checkbox(for='customkeys-checkbox') Custom Masternode Keys
58-
input#customkeys-checkbox.checkbox-indent(type='checkbox' name="customkeys-cheeckbox" onchange="customSubnetKeyJs()")
69+
input#customkeys-checkbox.checkbox-indent(type='checkbox' name="customkeys-checkbox" onchange="customSubnetKeyJs()")
5970
#customkeys.content
6071
center
6172
//- button.pure-button.pure-button-primary#button-custom-subnet-key(type="button" onclick="customSubnetKeyJs()") Custom Subnet Node Keys
@@ -65,14 +76,30 @@ body
6576
.info-container
6677
.info-icon(tabindex="0" role="button" aria-label="more info") ?
6778
.tooltip Default to stable
68-
label.pure-checkbox(for='customversion-checkbox') Custom Version
79+
label.pure-checkbox(for='customversion-checkbox') Custom Node Version
6980
input#customversion-checkbox.checkbox-indent(type='checkbox' name="customversion-checkbox")
7081
#customversion.content
7182
center
7283
.pure-control-group
7384
label() Node Version (Docker Image Tag)
7485
input#customversion-subnet.pure-input(type='text' placeholder='latest' name="customversion-subnet")
7586

87+
.pure-control-group
88+
.info-container
89+
.info-icon(tabindex="0" role="button" aria-label="more info") ?
90+
.tooltip 000000000
91+
label() Minimum Stake to Become Masternode
92+
input#text-num-subnet(type='number' placeholder='10000000' value='10000000' name="text-minimum-stake")
93+
span.pure-form-message-inline Required
94+
95+
.pure-control-group
96+
.info-container
97+
.info-icon(tabindex="0" role="button" aria-label="more info") ?
98+
.tooltip Value must be between 0 and 100
99+
label() Masternode Rewards APY
100+
input#text-num-subnet(type='number' placeholder='10' value='10' name="text-reward-apy")
101+
span.pure-form-message-inline Required
102+
76103

77104
center
78105
#incomplete-required-warning
@@ -152,9 +179,7 @@ script.
152179
console.log('validateForm called')
153180
const form = document.forms["myForm"]
154181

155-
const name = form["text-subnet-name"].value;
156-
const num_subnet = form["text-num-subnet"].value;
157-
if (name == "" || num_subnet == ""){
182+
if (form["text-subnet-name"] == "" || form["text-num-subnet"] == "" || form["text-minimum-stake"] == "" || form ["text-reward-apy"] == ""){
158183
document.getElementById("incomplete-required-warning").innerHTML="Please fill in all required fields"
159184
return false
160185
}

deployment-generator/src/views/index.pug

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ body
8080
.info-icon(tabindex="0" role="button" aria-label="more info") ?
8181
.tooltip Default is random
8282
label.pure-checkbox(for='customkeys-checkbox') Custom Subnet Keys
83-
input#customkeys-checkbox.checkbox-indent(type='checkbox' name="customkeys-cheeckbox")
83+
input#customkeys-checkbox.checkbox-indent(type='checkbox' name="customkeys-checkbox")
8484
#customkeys.content
8585
.pure-control-group
8686
label() Grandmaster PK

0 commit comments

Comments
 (0)