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

feat: implement validators commands #162

Open
wants to merge 14 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ VALIDATORS_CONFIG_JSON=''


VSCODEDEBUG="false"
LOCALNETVERSION="latest"
LOCALNETVERSION=""

FRONTEND_BUILD_TARGET = 'final' # change to 'dev' to run in dev mode

Expand Down
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@


## 0.10.0-beta.0 (2024-12-13)


### Features

* new global var to deal with compatible version ([33a4c02](https://github.com/yeagerai/genlayer-cli/commit/33a4c02f091e87faf1b884177ee854fe1b66f52b))

## 0.9.1 (2024-12-13)


Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "genlayer",
"version": "0.9.1",
"version": "0.10.0-beta.0",
"description": "GenLayer Command Line Tool",
"main": "src/index.ts",
"bin": {
Expand Down
4 changes: 3 additions & 1 deletion src/commands/general/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { Command } from "commander";

import simulatorService from "../../lib/services/simulator";
import { initAction, InitActionOptions } from "./init";
import { startAction, StartActionOptions } from "./start";
import {localnetCompatibleVersion} from "../../lib/config/simulator";

export function initializeGeneralCommands(program: Command) {
program
Expand All @@ -10,7 +12,7 @@ export function initializeGeneralCommands(program: Command) {
.option("--numValidators <numValidators>", "Number of validators", "5")
.option("--headless", "Headless mode", false)
.option("--reset-db", "Reset Database", false)
.option("--localnet-version <localnetVersion>", "Select a specific localnet version", "latest")
.option("--localnet-version <localnetVersion>", "Select a specific localnet version", localnetCompatibleVersion)
.action((options: InitActionOptions) => initAction(options, simulatorService));

program
Expand Down
1 change: 0 additions & 1 deletion src/commands/general/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,6 @@ export async function initAction(options: InitActionOptions, simulatorService: I
simulatorService.addConfigToEnvFile(aiProvidersEnvVars);
simulatorService.addConfigToEnvFile({LOCALNETVERSION: localnetVersion});


// Run the GenLayer Simulator
console.log("Running the GenLayer Simulator...");
try {
Expand Down
84 changes: 84 additions & 0 deletions src/commands/validators/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
import { Command } from "commander";
import { ValidatorsAction } from "./validators";

export function initializeValidatorCommands(program: Command) {
const validatorsAction = new ValidatorsAction();

const validatorsCommand = program
.command("validators")
.description("Manage validator operations");

validatorsCommand
.command("get")

.description("Retrieve details of a specific validator or all validators")
.option("--address <validatorAddress>", "The address of the validator to retrieve (omit to retrieve all validators)")
.action(async (options) => {
await validatorsAction.getValidator({ address: options.address });
});

validatorsCommand
.command("delete")
.description("Delete a specific validator or all validators")
.option("--address <validatorAddress>", "The address of the validator to delete (omit to delete all validators)")
.action(async (options) => {
await validatorsAction.deleteValidator({ address: options.address });
});

validatorsCommand
.command("count")
.description("Count all validators")
.action(async () => {
await validatorsAction.countValidators();
});

validatorsCommand
.command("update <validatorAddress>")
.description("Update a validator's details")
.option("--stake <stake>", "New stake for the validator")
.option("--provider <provider>", "New provider for the validator")
.option("--model <model>", "New model for the validator")
.option("--config <config>", "New JSON config for the validator")
.action(async (validatorAddress, options) => {
await validatorsAction.updateValidator({
address: validatorAddress,
stake: options.stake,
provider: options.provider,
model: options.model,
config: options.config,
});
});

validatorsCommand
.command("create-random")
.description("Create random validators")
.option("--count <count>", "Number of validators to create", "1") // Default to "1"
.option(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@epsjunior we are also missing the --models option to match the endpoint full parameters: https://github.com/yeagerai/genlayer-studio/blob/main/backend/protocol_rpc/endpoints.py#L190

"--providers <providers...>",
"Space-separated list of provider names (e.g., openai ollama)",
[]
)
.action(async (options) => {
await validatorsAction.createRandomValidators({
count: options.count,
providers: options.providers,
});
});

validatorsCommand
.command("create")
.description("Create a new validator")
.option("--stake <stake>", "Stake amount for the validator (default: 1)", "1")
.option(
"--config <config>",
'Optional JSON configuration for the validator (e.g., \'{"max_tokens": 500, "temperature": 0.75}\')'
)
.action(async (options) => {
await validatorsAction.createValidator({
stake: options.stake,
config: options.config,
});
});

return program;
}
Loading