Skip to content

Commit

Permalink
pull current validators (#45)
Browse files Browse the repository at this point in the history
pull current validators
  • Loading branch information
GalaxySciTech authored Jun 7, 2024
1 parent 2601094 commit c7ee8e8
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 22 deletions.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ We recommend setting up the contract in a Python virtual environment since it ut
Complete the fields in `deployment.config.json`:

- `subnet`: subnet deploy config :
- `validators`: List of initial validator addresses
- `gap`: GAP block number on the public chain
- `epoch`: Blocks per epoch on the public chain
- `gsbn`: gap start block number, gap block required
Expand Down
8 changes: 1 addition & 7 deletions deployment.config.json.example
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
{
"subnet": {
"validators": [
"0x57fA1EB91134F4440782C08b0AAE2A13410A5F40",
"0x45a4c6B05484C5284dD84eCeFF909f48D43D361d",
"0x11DACEFFA12E31F8014589dA4F6452C7a61F453d",
"0x15fdac2F7fb67F306FC3264a84881Afb5844EdF9",
"0xc07e9FBeB9695c89748594AB0e410ba11f75DE11"
],

"gap": 450,
"epoch": 900,
"gsbn": 451
Expand Down
7 changes: 6 additions & 1 deletion scripts/FullCheckpointDeploy.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ async function main() {
subnetDeploy.gsbn
);

const validators = await subnet.validators(
network.xdcsubnet,
subnetDeploy.gsbn
);

// We get the contract to deploy
const checkpointFactory = await hre.ethers.getContractFactory(
"FullCheckpoint"
Expand All @@ -29,7 +34,7 @@ async function main() {
await full.deployed();

const tx = await full.init(
subnetDeploy["validators"],
validators,
data0Encoded,
subnetDeploy["gap"],
subnetDeploy["epoch"],
Expand Down
3 changes: 2 additions & 1 deletion scripts/LiteCheckpointDeploy.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const network = require("../network.config.json");

async function main() {
const { data0Encoded } = await subnet.data(network.xdcsubnet, 1);
const validators = await subnet.validators(network.xdcsubnet, 1);
const subnetDeploy = deploy["subnet"];
// We get the contract to deploy
const checkpointFactory = await hre.ethers.getContractFactory(
Expand All @@ -23,7 +24,7 @@ async function main() {

await lite.deployed();
const tx = await lite.init(
subnetDeploy["validators"],
validators,
data0Encoded,
subnetDeploy["gap"],
subnetDeploy["epoch"]
Expand Down
47 changes: 35 additions & 12 deletions scripts/utils/xdcnet.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,24 @@ function base64ToHex(base64String) {
return hexString;
}

async function validators(url, number) {
const block0 = {
jsonrpc: "2.0",
method: "XDPoS_getMasternodesByNumber",
params: ["0x" + Number(number).toString(16)],
id: 1,
};

const data0 = await send(url, block0);

if (!data0["result"]["Masternodes"]) {
console.error("remote node block " + number + " no validators");
return;
}

return data0["result"]["Masternodes"];
}

async function data(url, number) {
const block0 = {
jsonrpc: "2.0",
Expand All @@ -22,28 +40,33 @@ async function data(url, number) {
id: 1,
};

let data0;
const data0 = await send(url, block0);

if (!data0["result"]["Committed"]) {
console.error("remote node block " + number + " is not committed");
return;
}
const data0Encoded = "0x" + base64ToHex(data0["result"]["EncodedRLP"]);

return { data0Encoded };
}

async function send(url, body) {
let data;
try {
console.error("connecting to network at url:", url);
const block0res = await fetch(url, {
method: "POST",
body: JSON.stringify(block0),
body: JSON.stringify(body),
headers: { "Content-Type": "application/json" },
});

data0 = await block0res.json();
data = await block0res.json();
} catch (e) {
console.error(e, "\n");
throw Error("Fetch remote node data error , pls check the node status");
}

if (!data0["result"]["Committed"]) {
console.error("remote node block " + number + " is not committed");
return;
}
const data0Encoded = "0x" + base64ToHex(data0["result"]["EncodedRLP"]);

return { data0Encoded };
return data;
}

module.exports = { data };
module.exports = { data, validators };

0 comments on commit c7ee8e8

Please sign in to comment.