Skip to content
This repository has been archived by the owner on May 16, 2024. It is now read-only.

Commit

Permalink
feat: configuring DDC with setup script [wip]
Browse files Browse the repository at this point in the history
  • Loading branch information
yahortsaryk committed Sep 11, 2023
1 parent 224684b commit 7065feb
Show file tree
Hide file tree
Showing 2 changed files with 114 additions and 102 deletions.
135 changes: 69 additions & 66 deletions scripts/ddc-setup/ddcBucketSetup.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,20 @@ const {
CERE,
MGAS,
ddcBucket,
randomAccount,
deploymentRegistry,
config
} = require("../sdk/src");
const ddcConfig = require('./ddcConfig.js');
const ddcConfig = require('./ddcConfigNew.js');
const log = console.log;

const DDC_BUCKET_CONTRACT_NAME = config.DDC_BUCKET_CONTRACT_NAME;
const ENV = process.env.ENV;
const ddcEnvConfig = ddcConfig[ENV];
const SUPERADMIN_MNEMONIC = process.env.SUPERADMIN;
const DDC_CONTRACT_ADDRESS = process.env.DDC_CONTRACT;


const ddcEnvConfig = ddcConfig[ENV];
if (!ddcEnvConfig) {
console.error("Please provide ENV as one of ", Object.keys(ddcConfig));
process.exit(-1);
console.error("Please provide ENV as one of ", Object.keys(ddcConfig));
process.exit(-1);
}
console.log(ddcEnvConfig);

Expand All @@ -31,41 +29,42 @@ if (!SUPERADMIN_MNEMONIC) {
process.exit(-1);
}

deploymentRegistry.initContract(
DDC_BUCKET_CONTRACT_NAME,
ENV,
ddcEnvConfig.contract_address
);
if (!DDC_CONTRACT_ADDRESS) {
console.error("Please provide DDC_CONTRACT address");
process.exit(-1);
}

deploymentRegistry.initContract(config.DDC_BUCKET_CONTRACT_NAME, ENV, DDC_CONTRACT_ADDRESS);

async function main() {
const {api, chainName, getExplorerUrl} = await connect(ddcEnvConfig.ws_provider);
const {api, chainName, getExplorerUrl} = await connect(ddcEnvConfig.blockchainUrl);
log("Connected to blockchain:", chainName);

const sadmin = accountFromUri(SUPERADMIN_MNEMONIC);
console.log(`Superadmin: ${sadmin.address}`);

const bucketContract = getContract(DDC_BUCKET_CONTRACT_NAME, ENV, api);
log("Using bucket contract", DDC_BUCKET_CONTRACT_NAME, "at", bucketContract.address.toString());
const bucketContract = getContract(config.DDC_BUCKET_CONTRACT_NAME, ENV, api);
log("Using bucket contract", config.DDC_BUCKET_CONTRACT_NAME, "at", bucketContract.address.toString());

const txOptions = {
storageDepositLimit: null,
gasLimit: 100_000_000_000n,
};

console.log(`Setup Started`);

{
log("1. accountSetUsdPerCere");
log(`Setting USD per CERE rate ...`);
const tx = bucketContract.tx.accountSetUsdPerCere(
txOptions,
1000n * CERE
);

const result = await sendTx(sadmin, tx);
log(getExplorerUrl(result), "\n");
}

{
log("2. grantTrustedManagerPermission");
log(`Granting trusted managers permissions ...`);
const tx = bucketContract.tx.grantTrustedManagerPermission(
txOptions,
sadmin.address
Expand All @@ -74,70 +73,74 @@ async function main() {
log(getExplorerUrl(result), "\n");
}

const cdnNodesKeys = []
{
console.log("3. cdnNodeCreate");
for (let i = 0; i < ddcEnvConfig.cdn_node_params.length; i++) {
const cdnNodeKey = ddcEnvConfig.cdn_node_params[i].publicKey;
cdnNodesKeys.push(cdnNodeKey);

const tx = bucketContract.tx.cdnNodeCreate(
txOptions,
cdnNodeKey,
JSON.stringify(ddcEnvConfig.cdn_node_params[i])
);

const result = await sendTx(sadmin, tx);
log(getExplorerUrl(result), "\n");
}
}

const storageNodesKeys = []
{
console.log("4. nodeCreate");
for (let i = 0; i < ddcEnvConfig.storage_node_params.length; i++) {
const param = JSON.stringify(ddcEnvConfig.storage_node_params[i]);
const user = randomAccount();
for (let i = 0; i < ddcEnvConfig.clusters.length; i++) {
const cluster = ddcEnvConfig.clusters[i];

fs.appendFileSync('secrets.txt', `${user.address}: ${user.mnemonic} -- ${ENV} storage ${i}\n`);
console.log(` node ${i}: address ${user.address}, param ${param}`);
console.log(`Creating Cluster ${i} ...`);
const clusterCreateTx = bucketContract.tx.clusterCreate(
txOptions,
JSON.stringify(cluster.params),
100000n
);
const result = await sendTx(sadmin, clusterCreateTx);
log(getExplorerUrl(result), "\n");
let { clusterId } = ddcBucket.findClusterCreatedEvent(result.contractEvents || []);
console.log(`Cluster ${clusterId} created`);

const storageNodeKey = user.address;
storageNodesKeys.push(storageNodeKey);
for (let j = 0; j < cluster.storageNodes.length; j++) {
const storageNode = cluster.storageNodes[j];
const storageNodeKey = storageNode.pubKey;
const vNodes = storageNode.vNodes;
const params = JSON.stringify(storageNode.params);

const tx = bucketContract.tx.nodeCreate(
console.log(`Creating Storage node ${storageNodeKey} ...`);
const nodeCreateTx = bucketContract.tx.nodeCreate(
txOptions,
storageNodeKey,
param,
params,
100000n,
1n * CERE
);
const result1 = await sendTx(sadmin, nodeCreateTx);
log(getExplorerUrl(result1), "\n");

const result = await sendTx(sadmin, tx);
log(getExplorerUrl(result), "\n");
console.log(`Adding Storage node ${storageNodeKey} to Cluster ${clusterId} ...`);
const clusterAddNodeTx = bucketContract.tx.clusterAddNode(
txOptions,
clusterId,
storageNodeKey,
vNodes
)
const result2 = await sendTx(sadmin, clusterAddNodeTx);
log(getExplorerUrl(result2), "\n");
}
}

const clustersIds = [];
{
for (let key in ddcEnvConfig.cluster) {
console.log("5. clusterCreate ");

const tx1 = bucketContract.tx.clusterCreate(
txOptions,
JSON.stringify(ddcEnvConfig.cluster[key].param),
100000n
);
for (let j = 0; j < cluster.cdnNodes.length; j++) {
const cdnNode = cluster.cdnNodes[j];
const cdnNodeKey = cdnNode.pubKey;
const params = JSON.stringify(cdnNode.params);

const result1 = await sendTx(sadmin, tx1);
console.log(`Creating CDN node ${cdnNodeKey} ...`);
const cdnNodeCreateTx = bucketContract.tx.cdnNodeCreate(
txOptions,
cdnNodeKey,
params
);
const result1 = await sendTx(sadmin, cdnNodeCreateTx);
log(getExplorerUrl(result1), "\n");
let { clusterId } = ddcBucket.findClusterCreatedEvent(result1.contractEvents || []);
clustersIds.push(clusterId);

console.log(`Adding CDN node ${cdnNodeKey} to Cluster ${clusterId} ...`);
const clusterAddCdnNodeTx = bucketContract.tx.clusterAddCdnNode(
txOptions,
clusterId,
cdnNodeKey,
)
const result2 = await sendTx(sadmin, clusterAddCdnNodeTx);
log(getExplorerUrl(result2), "\n");
}
}

// TODO: Add Storage nodes and CDN nodes to clusters

console.log(`Setup Finished`);
process.exit(0);
}

Expand Down
81 changes: 45 additions & 36 deletions scripts/ddc-setup/ddcConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,46 +2,55 @@ const GEN = 0x10000000000000000n; // UINT64_MAX

module.exports = {
devnet: {
ws_provider: "wss://archive.devnet.cere.network/ws",
contract_address: "6SfBsKbfPUTN35GCcqAHSMY4MemedK2A73VeJ34Z2FV6PB4r",
cluster: {
1n: {
param: { replicationFactor: 3 },
vnodes: [ [0n], [GEN / 4n], [GEN * 2n / 4n], [GEN * 3n / 4n] ],
storage_nodes: [1n, 2n, 3n, 4n],
},
},
storage_node_params: [
{ url: `https://node-0.v2.storage.devnet.cere.network` },
{ url: `https://node-1.v2.storage.devnet.cere.network` },
{ url: `https://node-2.v2.storage.devnet.cere.network` },
{ url: `https://node-3.v2.storage.devnet.cere.network` },
],
cdn_cluster: {
0n: {
cdn_nodes: [1n, 2n, 3n, 4n],
},
},
cdn_node_params: [
{
url: `https://node-0.v2.cdn.devnet.cere.network`,
publicKey: "0x1c4a1b081af8dd09096ebb6e7ad61dd549ac2931cdb2b1216589094ad71ca90b",
},
// blockchainUrl: "wss://archive.devnet.cere.network/ws",
blockchainUrl: "ws://127.0.0.1:9944",
ddcContractAddress: "6TYVo3hhwUqmB32Q2bSUp94KC6JnVkXCrJuYRqmY8qdF2XYC",
clusters: [
{
url: `https://node-1.v2.cdn.devnet.cere.network`,
publicKey: "0x3ec2ec407053acdfe8137d7105e90294f2e0e5f5fe5420fd3172142671dbc25f",
params: { replicationFactor: 3 },
storageNodes: [
{
pubKey: "0xd43593c715fdd31c61141abd04a99fd6822c8558854ccde39a5684e7a56da27d",
vNodes: [0n],
params: { url: `https://node-0.v2.storage.devnet.cere.network` },
},
{
pubKey: "0x8eaf04151687736326c9fea17e25fc5287613693c912909cb226aa4794f26a48",
vNodes: [GEN / 4n],
params: { url: `https://node-1.v2.storage.devnet.cere.network` },
},
{
pubKey: "0x90b5ab205c6974c9ea841be688864633dc9ca8a357843eeacf2314649965fe22",
vNodes: [GEN * 2n / 4n],
params: { url: `https://node-2.v2.storage.devnet.cere.network` },
},
{
pubKey: "0x306721211d5404bd9da88e0204360a1a9ab8b87c66c1bc2fcdd37f3c2222cc20",
vNodes: [GEN * 3n / 4n],
params: { url: `https://node-3.v2.storage.devnet.cere.network` },
}
],
cdnNodes: [
{
pubKey: "0xfe65717dad0447d715f660a0a58411de509b42e6efb8375f562f58a554d5860e",
params: { url: `https://node-0.v2.cdn.devnet.cere.network` },
},
{
pubKey: "0x1e07379407fecc4b89eb7dbd287c2c781cfb1907a96947a3eb18e4f8e7198625",
params: { url: `https://node-1.v2.cdn.devnet.cere.network` },
},
{
pubKey: "0xe860f1b1c7227f7c22602f53f15af80747814dffd839719731ee3bba6edc126c",
params: { url: `https://node-2.v2.cdn.devnet.cere.network` },
},
{
pubKey: "0x8ac59e11963af19174d0b94d5d78041c233f55d2e19324665bafdfb62925af2d",
params: { url: `https://node-3.v2.cdn.devnet.cere.network` },
}
]
},
{
url: `https://node-2.v2.cdn.devnet.cere.network`,
publicKey: "0x20e448c403d3f009ec309394d3aab828c3dbf0d2cc8047f01dded984ec992b41",
},
{
url: `https://node-3.v2.cdn.devnet.cere.network`,
publicKey: "0xd2f93cea79e37cfc9e5f78cd3e51b989afb1e257adcbbae00b8cd081539e9f13",
}
],
},

testnet: {
ws_provider: "wss://archive.devnet.cere.network/ws",
// contract_address: "6R2PF5gzKYbNkNLymTr8YNeQgWqNkE6azspwaMLZF2UHc1sg",
Expand Down

0 comments on commit 7065feb

Please sign in to comment.