Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a script that allows people to query when the next adjustment interval will be #196

Closed
Jackalgirl opened this issue Apr 12, 2024 · 1 comment
Assignees

Comments

@Jackalgirl
Copy link
Contributor

Jackalgirl commented Apr 12, 2024

By: @rajkaramchedu and @Jackalgirl

Purpose: instructions to download and create a script that allows users to query a subnet and discover the future next adjustment interval block will be (and provide an approximate time to adjustment), using a terminal window.

Instructions:

  1. On a macOS or Linux terminal, install "node" if you don't have it (see https://nodejs.org/en/download for help)
  2. If you have not installed yarn yet, run npm install --global yarn (if you are not root, you may need sudo npm install --global yarn)
  3. Run yarn add @polkadot/api
  4. Run yarn add prompt-sync
  5. Save the following into a file (for example: "bittensor_check-interval.js")
const { ApiPromise, WsProvider } = require("@polkadot/api");
const prompt = require("prompt-sync")();

// If you do not want to be prompted for network when running the script,
// change this variable to "finney" to default to the finney endpoint,
//  or "local" if you want to default to your own subtensor endpoint.

let network = "";

// If you have your own local subtensor and want to use its entry point, specify
// your entrypoint's wss address here (e.g., "wss://127.0.0.1:443")

let localNetworkEntryPoint = "";

if (network === "") {
  network = prompt("Enter network (finney, subvortex, local): ");
}

if ((network === "local" || network === "l") && localNetworkEntryPoint != "") {
  networkEntryPoint = localNetworkEntryPoint;
} else {
  networkEntryPoint = "wss://entrypoint-finney.opentensor.ai:443";
}

let subnet = prompt("Enter subnet netuid to query:");

if (!(Number.isInteger(subnet)) || subnet < 1 || subnet > 32) {
  subnet == 1;
} else {
  subnet == subnet;
}

async function queryBittensorData() {
  const wsProvider = new WsProvider(
    networkEntryPoint  );
  const api = await ApiPromise.create({ provider: wsProvider });

  const [
    lastAdjustmentBlock,
    adjustmentInterval,
    currentBlock,
  ] = await Promise.all([
    api.query.subtensorModule.lastAdjustmentBlock(subnet),
    api.query.subtensorModule.adjustmentInterval(subnet),
    api.query.system.number(),
  ]);

  let nextAdjustmentBlock = lastAdjustmentBlock.toNumber() + adjustmentInterval.toNumber();
  let currentBlockNumber = currentBlock.toNumber();
  let blocksToGo = nextAdjustmentBlock - currentBlockNumber;

  console.log(`Information for subnet`,subnet);
  console.log(`-=-=-=-=-=-=-=-=-=-=-=-=-=-`);
  console.log(`Last Adjustment Block: ${lastAdjustmentBlock.toNumber()}`);
  console.log(`Adjustment Interval: ${adjustmentInterval.toNumber()}`);
  console.log(`Next Adjustment Block: `, nextAdjustmentBlock);
  console.log(`Current Block: `, currentBlockNumber);
  console.log(`Blocks to go:`,blocksToGo,`in approximately`,blocksToGo*12,`seconds (`,blocksToGo*12/60,`minutes).`);
}

queryBittensorData()
  .catch(console.error)
  .finally(() => process.exit());

console.warn = () => {};
  1. You can run this file via node <filename> (for example: node bittensor_check-interval.js)
@Jackalgirl
Copy link
Contributor Author

Jackalgirl commented Apr 12, 2024

I'm still tinkering. Will update the above in a minute (maybe). : )

Done! For now. : )

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants