threefoldtech / tfgrid-sdk-ts

Apache License 2.0
4 stars 8 forks source link

🐞 [Bug]: free_cru not working on mainnet. #3097

Closed Parkers145 closed 4 months ago

Parkers145 commented 4 months ago

Is there an existing issue for this?

which package/s did you face the problem with?

grid_client

What happened?

Im not able to filter for free_cru on main net in the same way i can on dev net

here is an example output on devnet

yarn ts-node --project /scripts/tsconfig-node.json /scripts/deploy.ts deployNetwork myNetwork i
yarn run v1.19.0
$ /threefold_project/tfgrid-sdk-ts/node_modules/.bin/ts-node --project /scripts/tsconfig-node.json /scripts/deploy.ts deployNetwork myNetwork i
Credentials not all found in env variables. Loading all credentials from default config.json...
2024-07-09 03:53:56        API/INIT: RPC methods not decorated: chainHead_unstable_body, chainHead_unstable_call, chainHead_unstable_follow, chainHead_unstable_genesisHash, chainHead_unstable_header, chainHead_unstable_stopBody, chainHead_unstable_stopCall, chainHead_unstable_stopStorage, chainHead_unstable_storage, chainHead_unstable_unfollow, chainHead_unstable_unpin, transaction_unstable_submitAndWatch, transaction_unstable_unwatch
2024-07-09 03:53:56        API/INIT: Not decorating runtime apis without matching versions: TransactionPaymentApi/4 (1 known), Metadata/2 (1 known)
(node:1040) ExperimentalWarning: The Fetch API is an experimental feature. This feature could change at any time
(Use `node --trace-warnings ...` to show where the warning was created)
'Start creating the network deployment with name myNetworki'
Start creating the machine deployment with name myNetworki
Adding node 14 to network myNetworki
Node 14 reserved ports: [11882,6732,24269,5701,29759,9336,3968,7878,2283,7416,20536,29938,3201,9945,19920,7255,24950,2515,24150,9651,443,29827,2593,10749,4188,9944,25707,1720,5209,27512,13748,31870,31962,9943,17124,5321,2043,18658,3445,5868,5671,15614,300,2939,4560,2434,2707,15818,5865,28838,8082,4082,7337,13387,26321,1276,20789,16856,10847,80,8398,15523,3181,30782,15746,10925,16123,2597,4076,19827,7433,5945,24789,7393,7950,5399,24345,22949,4400,10874,25742,6660,22006,2150,6997,8754,11176,9105]
Generating peers for network myNetworki
Adding access to node 14
Generating peers for network myNetworki
Creating a vm on node: 14, network: myNetworki with private ip: 10.238.2.2
Merging workloads
Updating network workload with name: myNetworki
Deploying on node_id: 14
Deploying on node_id: 14
Lock acquired
2024-07-09 03:55:43        API/INIT: Not decorating runtime apis without matching versions: TransactionPaymentApi/4 (1 known), Metadata/2 (1 known)
phase: {"applyExtrinsic":1}, section: balances, method: Withdraw, data: ["5CXvd6VF8aG3yH2MYKTCzA7rv16cm9wn3sVyEF5fjCvf1pWq",10341]
phase: {"applyExtrinsic":1}, section: smartContractModule, method: ContractCreated, data: [{"version":4,"state":{"created":null},"contractId":130317,"twinId":669,"contractType":{"nodeContract":{"nodeId":14,"deploymentHash":"0x6366333066636262383965663962373138323133373135663134323738323232","deploymentData":"0x7b2276657273696f6e223a332c2274797065223a226e6574776f726b222c226e616d65223a226d794e6574776f726b69222c2270726f6a6563744e616d65223a22227d","publicIps":0,"publicIpsList":[]}},"solutionProviderId":null}]
phase: {"applyExtrinsic":1}, section: utility, method: ItemCompleted, data: []
phase: {"applyExtrinsic":1}, section: smartContractModule, method: ContractCreated, data: [{"version":4,"state":{"created":null},"contractId":130318,"twinId":669,"contractType":{"nodeContract":{"nodeId":14,"deploymentHash":"0x3365666539616235336434373530326534633634613630663135306338663232","deploymentData":"0x7b2276657273696f6e223a332c2274797065223a22766d222c226e616d65223a226d794e6574776f726b69222c2270726f6a6563744e616d65223a22766d2f6d794e6574776f726b69227d","publicIps":0,"publicIpsList":[]}},"solutionProviderId":null}]
phase: {"applyExtrinsic":1}, section: utility, method: ItemCompleted, data: []
phase: {"applyExtrinsic":1}, section: utility, method: BatchCompleted, data: []
phase: {"applyExtrinsic":1}, section: balances, method: Deposit, data: ["5FXAK4MktAf5dQZURaC5sdRWZNgJPr8zB6iFr3Cbi1j4Svjv",10341]
phase: {"applyExtrinsic":1}, section: transactionPayment, method: TransactionFeePaid, data: ["5CXvd6VF8aG3yH2MYKTCzA7rv16cm9wn3sVyEF5fjCvf1pWq",10341,0]
phase: {"applyExtrinsic":1}, section: system, method: ExtrinsicSuccess, data: [{"weight":{"refTime":2448602399,"proofSize":8666},"class":"Normal","paysFee":"Yes"}]
Lock released
Sending deployment to node_id: 14
A deployment has been created on node_id: 14 with contract_id: 130317
Sending deployment to node_id: 14
2024-07-09 03:55:55        API/INIT: Not decorating runtime apis without matching versions: TransactionPaymentApi/4 (1 known), Metadata/2 (1 known)
A deployment has been created on node_id: 14 with contract_id: 130318
Waiting for deployment with contract_id: 130317 to be ready
Waiting for deployment with contract_id: 130318 to be ready
{
  contracts: {
    created: [
      {
        version: 4,
        state: { created: null },
        contractId: 130318,
        twinId: 669,
        contractType: {
          nodeContract: {
            nodeId: 14,
            deploymentHash: '3efe9ab53d47502e4c64a60f150c8f22',
            deploymentData: '{"version":3,"type":"vm","name":"myNetworki","projectName":"vm/myNetworki"}',
            publicIps: 0,
            publicIpsList: []
          }
        },
        solutionProviderId: null
      }
    ],
    updated: [],
    deleted: []
  },
  wireguard_config: '[Interface]\n' +
    'Address = 100.64.238.3/32\n' +
    'PrivateKey = VzyrASZ3hvowAVvx1NnliCIocZnPiXHvLcUeRkQbVwo=\n' +
    '\n' +
    '[Peer]\n' +
    'PublicKey = mBwjdMJIa/eEvWJYbMkIXQa0F3l/G5ZG+ZCwAhFzkEU=\n' +
    'AllowedIPs = 10.238.0.0/16, 100.64.238.0/32\n' +
    'PersistentKeepalive = 25\n' +
    'Endpoint = 185.206.122.31:9404'
}

and the same script running on main net

yarn ts-node --project /scripts/tsconfig-node.json /scripts/deploy.ts deployNetwork myNetwork i
yarn run v1.19.0
$ /threefold_project/tfgrid-sdk-ts/node_modules/.bin/ts-node --project /scripts/tsconfig-node.json /scripts/deploy.ts deployNetwork myNetwork i
Credentials not all found in env variables. Loading all credentials from default config.json...
2024-07-09 04:01:18        API/INIT: RPC methods not decorated: transaction_unstable_submitAndWatch, transaction_unstable_unwatch
2024-07-09 04:01:18        API/INIT: Not decorating runtime apis without matching versions: TransactionPaymentApi/4 (1 known), Metadata/2 (1 known)
(node:1157) ExperimentalWarning: The Fetch API is an experimental feature. This feature could change at any time
(Use `node --trace-warnings ...` to show where the warning was created)
/threefold_project/tfgrid-sdk-ts/packages/grid_client/src/helpers/requests.ts:19
    throw new RequestError(`HTTP request failed ${errorMessage ? "due to " + errorMessage : ""}.`, response?.status);
          ^
RequestError: RequestError: HTTP request failed due to "free_cru" is not a sort filed for Node type.
    at sendWithFullResponse (/threefold_project/tfgrid-sdk-ts/packages/grid_client/src/helpers/requests.ts:19:11)
    at processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async send (/threefold_project/tfgrid-sdk-ts/packages/grid_client/src/helpers/requests.ts:24:20)
    at async Nodes.filterNodes (/threefold_project/tfgrid-sdk-ts/packages/grid_client/src/primitives/nodes.ts:344:13)
    at async Capacity.filterNodes (/threefold_project/tfgrid-sdk-ts/packages/grid_client/src/modules/capacity.ts:87:36)
    at async deployNetwork (/threefold_project/tfgrid-sdk-ts/packages/grid_client/scripts/deploy.ts:605:21) {
  code: 7,
  module: 'Generic',
  statusCode: 400
}
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

Steps To Reproduce

The function being used

async function deployNetwork(networkNameOrPath: string, instanceId: string) {
  const grid3 = await getClient();
  let networkConfig: any;

  if (fs.existsSync(networkNameOrPath)) {
    networkConfig = JSON.parse(fs.readFileSync(networkNameOrPath, "utf-8"));
  } else {
    networkConfig = networkConfigurations[networkNameOrPath];
  }

  if (!networkConfig) {
    console.error(`Network configuration not found for ${networkNameOrPath}`);
    await grid3.disconnect();
    return;
  }

  const uniqueNetworkName = `${networkConfig.name}${instanceId}`;

  const network = new NetworkModel();
  network.name = uniqueNetworkName;
  network.ip_range = networkConfig.ip_range || "10.238.0.0/16";
  network.addAccess = networkConfig.addAccess !== undefined ? networkConfig.addAccess : true;

  if (network.addAccess) {
    const gwQueryOptions: FilterOptions = {
      gateway: true,
      country: networkConfig.gatewayCountry
    };
    const gwNodes = await grid3.capacity.filterNodes(gwQueryOptions);
    if (gwNodes.length === 0) {
      throw new Error(`No gateway nodes available in the specified country: ${networkConfig.gatewayCountry}`);
    }
    network.accessNodeId = gwNodes[0].nodeId;
  }

  // Create VM for WireGuard router
  const vmQueryOptions: FilterOptions = {
    cru: 1,
    mru: 2, // GB
    sru: 5, // GB
    availableFor: grid3.twinId,
    country: networkConfig.gatewayCountry,
  };

  const vmNodes = await grid3.capacity.filterNodes(vmQueryOptions);
  if (vmNodes.length === 0) {
    throw new Error("No nodes available for the WireGuard router VM");
  }
  const vmNode = vmNodes[0].nodeId;

  const vmConfig = networkConfig.wireGuardVM;

  const vm = new MachineModel();
  vm.name = `${vmConfig.name}${instanceId}`;
  vm.node_id = vmNode;
  vm.disks = [];
  vm.public_ip = vmConfig.public_ip;
  vm.public_ip6 = vmConfig.public_ip6;
  vm.planetary = vmConfig.planetary;
  vm.cpu = vmConfig.cpu;
  vm.memory = vmConfig.memory;
  vm.rootfs_size = vmConfig.rootfs_size;
  vm.flist = vmConfig.flist;
  vm.entrypoint = vmConfig.entrypoint;
  vm.env = { SSH_KEY: config.ssh_key, ...vmConfig.env };
  vm.mycelium = vmConfig.mycelium;

  // Create VMs object with the network and the WireGuard VM
  const vms = new MachinesModel();
  vms.name = uniqueNetworkName;
  vms.network = network;
  vms.machines = [vm];
  vms.metadata = "{'networkOnly': true}";
  vms.description = `Deploying network with WireGuard router via ts grid3 client for ${uniqueNetworkName}`;

  try {
    // Deploy network with WireGuard VM
    log(`Start creating the network deployment with name ${vms.name}`);
    await deployVMS(grid3, vms);

    // Get WireGuard configuration
    const wireGuardConfig = await getWireGuardConfig(grid3, uniqueNetworkName, network.ip_range);

    const aggregatedInfo = {
      type: 'deployNetwork',
      data: {
        network: network,
        wireGuardConfig: wireGuardConfig
      },
      error: null as string | null
    };

    process.stdout.write(JSON.stringify(aggregatedInfo, null, 2));

  } catch (error) {
    log(`Error during network deployment: ${error.message}`);
  } finally {
    await grid3.disconnect();
  }
}

which network/s did you face the problem on?

Main

version

current

Twin ID/s

No response

Node ID/s

No response

Farm ID/s

No response

Contract ID/s

No response

Relevant screenshots/screen records

none

Relevant log output

see above
Parkers145 commented 4 months ago

Answered in grid tester chat by Ahmed thabet this just hasn't made main net yet.