Skip to content

Commit

Permalink
feat: support vm effector by default, rename cc-collateral-withdraw t…
Browse files Browse the repository at this point in the history
…o cc-finish (#1042)

* feat: support vm effector buy default, rename cc-collateral-withdraw to cc-finish

* Apply automatic changes

* set allowed binaries to an empty object if it's missing

* print deal id

* fix

* Apply automatic changes

---------

Co-authored-by: shamsartem <[email protected]>
  • Loading branch information
shamsartem and shamsartem authored Sep 17, 2024
1 parent 46af000 commit 07c2cd5
Show file tree
Hide file tree
Showing 17 changed files with 296 additions and 91 deletions.
40 changes: 21 additions & 19 deletions cli/docs/commands/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@
* [`fluence module pack [PATH]`](#fluence-module-pack-path)
* [`fluence module remove [NAME | PATH | URL]`](#fluence-module-remove-name--path--url)
* [`fluence provider cc-activate`](#fluence-provider-cc-activate)
* [`fluence provider cc-collateral-withdraw`](#fluence-provider-cc-collateral-withdraw)
* [`fluence provider cc-create`](#fluence-provider-cc-create)
* [`fluence provider cc-finish`](#fluence-provider-cc-finish)
* [`fluence provider cc-info`](#fluence-provider-cc-info)
* [`fluence provider cc-remove`](#fluence-provider-cc-remove)
* [`fluence provider cc-rewards-withdraw`](#fluence-provider-cc-rewards-withdraw)
Expand Down Expand Up @@ -1257,20 +1257,17 @@ ALIASES

_See code: [src/commands/provider/cc-activate.ts](https://github.com/fluencelabs/cli/blob/fluence-cli-v0.20.2/src/commands/provider/cc-activate.ts)_

## `fluence provider cc-collateral-withdraw`
## `fluence provider cc-create`

Withdraw FLT collateral from capacity commitments
Create Capacity commitment

```
USAGE
$ fluence provider cc-collateral-withdraw [--no-input] [--nox-names <nox-1,nox-2> | --cc-ids <value>] [--offers <offer-1,offer-2>]
[--env <testnet | mainnet | stage | local | custom>] [--priv-key <private-key>] [--max-cus <value>]
$ fluence provider cc-create [--no-input] [--env <testnet | mainnet | stage | local | custom>] [--priv-key
<private-key>] [--nox-names <nox-1,nox-2>] [--offers <offer-1,offer-2>]
FLAGS
--cc-ids=<value> Comma separated capacity commitment IDs
--env=<testnet | mainnet | stage | local | custom> Fluence Environment to use when running the command
--max-cus=<value> [default: 32] Maximum number of compute units to put in a batch
when signing a transaction
--no-input Don't interactively ask for any input from the user
--nox-names=<nox-1,nox-2> Comma-separated names of noxes from provider.yaml. To use all of
your noxes: --nox-names all
Expand All @@ -1282,25 +1279,28 @@ FLAGS
is used by default when CLI is used in non-interactive mode
DESCRIPTION
Withdraw FLT collateral from capacity commitments
Create Capacity commitment
ALIASES
$ fluence provider ccw
$ fluence provider cc
```

_See code: [src/commands/provider/cc-collateral-withdraw.ts](https://github.com/fluencelabs/cli/blob/fluence-cli-v0.20.2/src/commands/provider/cc-collateral-withdraw.ts)_
_See code: [src/commands/provider/cc-create.ts](https://github.com/fluencelabs/cli/blob/fluence-cli-v0.20.2/src/commands/provider/cc-create.ts)_

## `fluence provider cc-create`
## `fluence provider cc-finish`

Create Capacity commitment
Move resources from deals, withdraw FLT collateral from capacity commitments, remove compute units from capacity commitments and finish capacity commitments

```
USAGE
$ fluence provider cc-create [--no-input] [--env <testnet | mainnet | stage | local | custom>] [--priv-key
<private-key>] [--nox-names <nox-1,nox-2>] [--offers <offer-1,offer-2>]
$ fluence provider cc-finish [--no-input] [--nox-names <nox-1,nox-2> | --cc-ids <value>] [--offers <offer-1,offer-2>]
[--env <testnet | mainnet | stage | local | custom>] [--priv-key <private-key>] [--max-cus <value>]
FLAGS
--cc-ids=<value> Comma separated capacity commitment IDs
--env=<testnet | mainnet | stage | local | custom> Fluence Environment to use when running the command
--max-cus=<value> [default: 32] Maximum number of compute units to put in a batch
when signing a transaction
--no-input Don't interactively ask for any input from the user
--nox-names=<nox-1,nox-2> Comma-separated names of noxes from provider.yaml. To use all of
your noxes: --nox-names all
Expand All @@ -1312,13 +1312,14 @@ FLAGS
is used by default when CLI is used in non-interactive mode
DESCRIPTION
Create Capacity commitment
Move resources from deals, withdraw FLT collateral from capacity commitments, remove compute units from capacity
commitments and finish capacity commitments
ALIASES
$ fluence provider cc
$ fluence provider ccf
```

_See code: [src/commands/provider/cc-create.ts](https://github.com/fluencelabs/cli/blob/fluence-cli-v0.20.2/src/commands/provider/cc-create.ts)_
_See code: [src/commands/provider/cc-finish.ts](https://github.com/fluencelabs/cli/blob/fluence-cli-v0.20.2/src/commands/provider/cc-finish.ts)_

## `fluence provider cc-info`

Expand Down Expand Up @@ -1589,11 +1590,12 @@ Init provider config. Creates a provider.yaml file
```
USAGE
$ fluence provider init [--no-input] [--noxes <value>] [--env <testnet | mainnet | stage | local | custom>]
[--priv-key <private-key>]
[--priv-key <private-key>] [--no-vm]
FLAGS
--env=<testnet | mainnet | stage | local | custom> Fluence Environment to use when running the command
--no-input Don't interactively ask for any input from the user
--no-vm Generate provider.yaml without vm configuration
--noxes=<value> Number of Compute Peers to generate when a new provider.yaml is
created
--priv-key=<private-key> !WARNING! for debug purposes only. Passing private keys through
Expand Down
30 changes: 15 additions & 15 deletions cli/docs/configs/fluence.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,21 +97,21 @@ Deployment config

#### Properties

| Property | Type | Required | Description |
|-------------------------|----------|----------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `blacklist` | string[] | No | Blacklist of providers to deploy to. Can't be used together with whitelist |
| `computeUnits` | integer | No | Number of compute units you require. 1 compute unit = 2GB. Currently the only allowed value is 1. This will change in the future. Default: 1 |
| `cuCountPerWorker` | integer | No | Number of compute units per worker. Default: 1 |
| `effectors` | string[] | No | Effector CIDs to be used in the deal. Must be a valid CID |
| `initialBalance` | string | No | Initial balance after deploy in USDC. Default: targetWorkers * pricePerCuPerEpoch * minDealDepositedEpochs. For local environment: enough for deal to be active for 1 day |
| `maxWorkersPerProvider` | integer | No | Max workers per provider. Matches target workers by default |
| `minWorkers` | integer | No | Required workers to activate the deal. Matches target workers by default |
| `pricePerCuPerEpoch` | string | No | Price per compute unit per epoch in USDC |
| `protocolVersion` | integer | No | Protocol version. Default: 1 |
| `services` | string[] | No | An array of service names to include in this worker. Service names must be listed in fluence.yaml |
| `spells` | string[] | No | An array of spell names to include in this worker. Spell names must be listed in fluence.yaml |
| `targetWorkers` | integer | No | Max workers in the deal |
| `whitelist` | string[] | No | Whitelist of providers to deploy to. Can't be used together with blacklist |
| Property | Type | Required | Description |
|-------------------------|----------|----------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `blacklist` | string[] | No | Blacklist of providers to deploy to. Can't be used together with whitelist |
| `computeUnits` | integer | No | DEPRECATED. USE cuCountPerWorker INSTEAD. Number of compute units you require. 1 compute unit = 2GB. Currently the only allowed value is 1. This will change in the future. Default: 1 |
| `cuCountPerWorker` | integer | No | Number of compute units per worker. Default: 1 |
| `effectors` | string[] | No | Effector CIDs to be used in the deal. Must be a valid CID |
| `initialBalance` | string | No | Initial balance after deploy in USDC. Default: targetWorkers * pricePerCuPerEpoch * minDealDepositedEpochs. For local environment: enough for deal to be active for 1 day |
| `maxWorkersPerProvider` | integer | No | Max workers per provider. Matches target workers by default |
| `minWorkers` | integer | No | Required workers to activate the deal. Matches target workers by default |
| `pricePerCuPerEpoch` | string | No | Price per compute unit per epoch in USDC |
| `protocolVersion` | integer | No | Protocol version. Default: 1 |
| `services` | string[] | No | An array of service names to include in this worker. Service names must be listed in fluence.yaml |
| `spells` | string[] | No | An array of spell names to include in this worker. Spell names must be listed in fluence.yaml |
| `targetWorkers` | integer | No | Max workers in the deal |
| `whitelist` | string[] | No | Whitelist of providers to deploy to. Can't be used together with blacklist |

## hosts

Expand Down
4 changes: 2 additions & 2 deletions cli/docs/configs/provider.md
Original file line number Diff line number Diff line change
Expand Up @@ -249,8 +249,8 @@ Effector configuration

| Property | Type | Required | Description |
|-------------------|----------------------------|----------|--------------------------|
| `allowedBinaries` | [object](#allowedbinaries) | **Yes** | Allowed binaries |
| `wasmCID` | string | **Yes** | Wasm CID of the effector |
| `allowedBinaries` | [object](#allowedbinaries) | No | Allowed binaries |

**allowedBinaries**

Expand Down Expand Up @@ -440,8 +440,8 @@ Effector configuration

| Property | Type | Required | Description |
|-------------------|----------------------------|----------|--------------------------|
| `allowedBinaries` | [object](#allowedbinaries) | **Yes** | Allowed binaries |
| `wasmCID` | string | **Yes** | Wasm CID of the effector |
| `allowedBinaries` | [object](#allowedbinaries) | No | Allowed binaries |

##### allowedBinaries

Expand Down
1 change: 1 addition & 0 deletions cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@
"@oclif/plugin-update": "4.2.11",
"@total-typescript/ts-reset": "0.5.1",
"ajv": "8.13.0",
"ajv-formats": "^3.0.1",
"chokidar": "3.6.0",
"countly-sdk-nodejs": "22.6.0",
"debug": "4.3.4",
Expand Down
4 changes: 3 additions & 1 deletion cli/src/commands/provider/cc-collateral-withdraw.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,13 @@ import {
} from "../../lib/const.js";
import { initCli } from "../../lib/lifeCycle.js";

// Deprecated alias for provider cc-finish
export default class CCCollateralWithdraw extends BaseCommand<
typeof CCCollateralWithdraw
> {
static override hidden = true;
static override aliases = ["provider:ccw"];
static override description = `Withdraw ${FLT_SYMBOL} collateral from capacity commitments`;
static override description = `Move resources from deals, withdraw ${FLT_SYMBOL} collateral from capacity commitments, remove compute units from capacity commitments and finish capacity commitments`;
static override flags = {
...baseFlags,
...CC_FLAGS,
Expand Down
42 changes: 42 additions & 0 deletions cli/src/commands/provider/cc-finish.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/**
* Fluence CLI
* Copyright (C) 2024 Fluence DAO
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

import { BaseCommand, baseFlags } from "../../baseCommand.js";
import { collateralWithdraw } from "../../lib/chain/commitment.js";
import {
CHAIN_FLAGS,
FLT_SYMBOL,
CC_FLAGS,
MAX_CUS_FLAG,
} from "../../lib/const.js";
import { initCli } from "../../lib/lifeCycle.js";

export default class CCFinish extends BaseCommand<typeof CCFinish> {
static override aliases = ["provider:ccf"];
static override description = `Move resources from deals, withdraw ${FLT_SYMBOL} collateral from capacity commitments, remove compute units from capacity commitments and finish capacity commitments`;
static override flags = {
...baseFlags,
...CC_FLAGS,
...CHAIN_FLAGS,
...MAX_CUS_FLAG,
};

async run(): Promise<void> {
const { flags } = await initCli(this, await this.parse(CCFinish));
await collateralWithdraw(flags);
}
}
5 changes: 5 additions & 0 deletions cli/src/commands/provider/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
*/

import { color } from "@oclif/color";
import { Flags } from "@oclif/core";

import { BaseCommand, baseFlags } from "../../baseCommand.js";
import { commandObj } from "../../lib/commandObj.js";
Expand All @@ -36,6 +37,10 @@ export default class Init extends BaseCommand<typeof Init> {
...baseFlags,
...NOXES_FLAG,
...CHAIN_FLAGS,
"no-vm": Flags.boolean({
description: `Generate ${PROVIDER_CONFIG_FULL_FILE_NAME} without vm configuration`,
default: false,
}),
};

async run(): Promise<void> {
Expand Down
3 changes: 3 additions & 0 deletions cli/src/lib/ajvInstance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import { color } from "@oclif/color";
import Ajv from "ajv";
import addFormats from "ajv-formats";

import { jsonStringify } from "../common.js";

Expand All @@ -27,6 +28,8 @@ export const ajv = new Ajv.default({
code: { esm: true },
});

addFormats.default(ajv);

type AjvErrors =
| Ajv.ErrorObject<string, Record<string, unknown>>[]
| null
Expand Down
17 changes: 11 additions & 6 deletions cli/src/lib/configs/initConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -306,16 +306,21 @@ export function getReadonlyConfigInitFunction<
let { configPath } = getConfigPathResult;

const Ajv = (await import("ajv")).default;
const addFormats = (await import("ajv-formats")).default.default;

const validateAllConfigVersions = new Ajv.default({
allowUnionTypes: true,
}).compile<Config>({
const validateAllConfigVersions = addFormats(
new Ajv.default({
allowUnionTypes: true,
}),
).compile<Config>({
oneOf: allSchemas,
});

const validateLatestConfig = new Ajv.default({
allowUnionTypes: true,
}).compile<LatestConfig>(latestSchema);
const validateLatestConfig = addFormats(
new Ajv.default({
allowUnionTypes: true,
}),
).compile<LatestConfig>(latestSchema);

const schemaPathCommentStart = "# yaml-language-server: $schema=";

Expand Down
24 changes: 23 additions & 1 deletion cli/src/lib/configs/project/fluence.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import CLIPackageJSON from "../../../versions/cli.package.json" assert { type: "
import { versions } from "../../../versions.js";
import { ajv, validationErrorToString } from "../../ajvInstance.js";
import { validateProtocolVersion } from "../../chain/chainValidators.js";
import { commandObj } from "../../commandObj.js";
import {
COMPUTE_UNIT_MEMORY_STR,
MAX_HEAP_SIZE_DESCRIPTION,
Expand Down Expand Up @@ -286,7 +287,7 @@ const dealSchemaObj = {
minimum: 1,
maximum: 1,
default: 1,
description: `Number of compute units you require. 1 compute unit = ${COMPUTE_UNIT_MEMORY_STR}. Currently the only allowed value is 1. This will change in the future. Default: 1`,
description: `DEPRECATED. USE cuCountPerWorker INSTEAD. Number of compute units you require. 1 compute unit = ${COMPUTE_UNIT_MEMORY_STR}. Currently the only allowed value is 1. This will change in the future. Default: 1`,
nullable: true,
},
targetWorkers: {
Expand Down Expand Up @@ -1733,6 +1734,26 @@ async function validateProtocolVersions(config: LatestConfig) {
return true;
}

function warnComputeUnitsIsDeprecated(config: LatestConfig): true {
const deploymentsWithWarning = Object.entries(
config.deployments ?? {},
).filter(([, deployment]) => {
return "computeUnits" in deployment;
});

if (deploymentsWithWarning.length > 0) {
commandObj.warn(
`'computeUnits' property is deprecated. Use 'cuCountPerWorker' instead. Deployment(s): ${deploymentsWithWarning
.map(([deploymentName]) => {
return deploymentName;
})
.join(", ")}`,
);
}

return true;
}

const validate: ConfigValidateFunction<LatestConfig> = async (config) => {
return validateBatchAsync(
validateNotBothBlacklistAndWhitelist(config),
Expand All @@ -1754,6 +1775,7 @@ const validate: ConfigValidateFunction<LatestConfig> = async (config) => {
validateVersionsIsExact("marineVersion", config.marineVersion),
validateVersionsIsExact("mreplVersion", config.mreplVersion),
validateProtocolVersions(config),
warnComputeUnitsIsDeprecated(config),
);
};

Expand Down
Loading

0 comments on commit 07c2cd5

Please sign in to comment.