Skip to content

Commit 07c2cd5

Browse files
authored
feat: support vm effector by default, rename cc-collateral-withdraw to 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]>
1 parent 46af000 commit 07c2cd5

File tree

17 files changed

+296
-91
lines changed

17 files changed

+296
-91
lines changed

cli/docs/commands/README.md

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@
4343
* [`fluence module pack [PATH]`](#fluence-module-pack-path)
4444
* [`fluence module remove [NAME | PATH | URL]`](#fluence-module-remove-name--path--url)
4545
* [`fluence provider cc-activate`](#fluence-provider-cc-activate)
46-
* [`fluence provider cc-collateral-withdraw`](#fluence-provider-cc-collateral-withdraw)
4746
* [`fluence provider cc-create`](#fluence-provider-cc-create)
47+
* [`fluence provider cc-finish`](#fluence-provider-cc-finish)
4848
* [`fluence provider cc-info`](#fluence-provider-cc-info)
4949
* [`fluence provider cc-remove`](#fluence-provider-cc-remove)
5050
* [`fluence provider cc-rewards-withdraw`](#fluence-provider-cc-rewards-withdraw)
@@ -1257,20 +1257,17 @@ ALIASES
12571257

12581258
_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)_
12591259

1260-
## `fluence provider cc-collateral-withdraw`
1260+
## `fluence provider cc-create`
12611261

1262-
Withdraw FLT collateral from capacity commitments
1262+
Create Capacity commitment
12631263

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

1291-
_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)_
1288+
_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)_
12921289

1293-
## `fluence provider cc-create`
1290+
## `fluence provider cc-finish`
12941291

1295-
Create Capacity commitment
1292+
Move resources from deals, withdraw FLT collateral from capacity commitments, remove compute units from capacity commitments and finish capacity commitments
12961293

12971294
```
12981295
USAGE
1299-
$ fluence provider cc-create [--no-input] [--env <testnet | mainnet | stage | local | custom>] [--priv-key
1300-
<private-key>] [--nox-names <nox-1,nox-2>] [--offers <offer-1,offer-2>]
1296+
$ fluence provider cc-finish [--no-input] [--nox-names <nox-1,nox-2> | --cc-ids <value>] [--offers <offer-1,offer-2>]
1297+
[--env <testnet | mainnet | stage | local | custom>] [--priv-key <private-key>] [--max-cus <value>]
13011298
13021299
FLAGS
1300+
--cc-ids=<value> Comma separated capacity commitment IDs
13031301
--env=<testnet | mainnet | stage | local | custom> Fluence Environment to use when running the command
1302+
--max-cus=<value> [default: 32] Maximum number of compute units to put in a batch
1303+
when signing a transaction
13041304
--no-input Don't interactively ask for any input from the user
13051305
--nox-names=<nox-1,nox-2> Comma-separated names of noxes from provider.yaml. To use all of
13061306
your noxes: --nox-names all
@@ -1312,13 +1312,14 @@ FLAGS
13121312
is used by default when CLI is used in non-interactive mode
13131313
13141314
DESCRIPTION
1315-
Create Capacity commitment
1315+
Move resources from deals, withdraw FLT collateral from capacity commitments, remove compute units from capacity
1316+
commitments and finish capacity commitments
13161317
13171318
ALIASES
1318-
$ fluence provider cc
1319+
$ fluence provider ccf
13191320
```
13201321

1321-
_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)_
1322+
_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)_
13221323

13231324
## `fluence provider cc-info`
13241325

@@ -1589,11 +1590,12 @@ Init provider config. Creates a provider.yaml file
15891590
```
15901591
USAGE
15911592
$ fluence provider init [--no-input] [--noxes <value>] [--env <testnet | mainnet | stage | local | custom>]
1592-
[--priv-key <private-key>]
1593+
[--priv-key <private-key>] [--no-vm]
15931594
15941595
FLAGS
15951596
--env=<testnet | mainnet | stage | local | custom> Fluence Environment to use when running the command
15961597
--no-input Don't interactively ask for any input from the user
1598+
--no-vm Generate provider.yaml without vm configuration
15971599
--noxes=<value> Number of Compute Peers to generate when a new provider.yaml is
15981600
created
15991601
--priv-key=<private-key> !WARNING! for debug purposes only. Passing private keys through

cli/docs/configs/fluence.md

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -97,21 +97,21 @@ Deployment config
9797

9898
#### Properties
9999

100-
| Property | Type | Required | Description |
101-
|-------------------------|----------|----------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
102-
| `blacklist` | string[] | No | Blacklist of providers to deploy to. Can't be used together with whitelist |
103-
| `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 |
104-
| `cuCountPerWorker` | integer | No | Number of compute units per worker. Default: 1 |
105-
| `effectors` | string[] | No | Effector CIDs to be used in the deal. Must be a valid CID |
106-
| `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 |
107-
| `maxWorkersPerProvider` | integer | No | Max workers per provider. Matches target workers by default |
108-
| `minWorkers` | integer | No | Required workers to activate the deal. Matches target workers by default |
109-
| `pricePerCuPerEpoch` | string | No | Price per compute unit per epoch in USDC |
110-
| `protocolVersion` | integer | No | Protocol version. Default: 1 |
111-
| `services` | string[] | No | An array of service names to include in this worker. Service names must be listed in fluence.yaml |
112-
| `spells` | string[] | No | An array of spell names to include in this worker. Spell names must be listed in fluence.yaml |
113-
| `targetWorkers` | integer | No | Max workers in the deal |
114-
| `whitelist` | string[] | No | Whitelist of providers to deploy to. Can't be used together with blacklist |
100+
| Property | Type | Required | Description |
101+
|-------------------------|----------|----------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
102+
| `blacklist` | string[] | No | Blacklist of providers to deploy to. Can't be used together with whitelist |
103+
| `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 |
104+
| `cuCountPerWorker` | integer | No | Number of compute units per worker. Default: 1 |
105+
| `effectors` | string[] | No | Effector CIDs to be used in the deal. Must be a valid CID |
106+
| `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 |
107+
| `maxWorkersPerProvider` | integer | No | Max workers per provider. Matches target workers by default |
108+
| `minWorkers` | integer | No | Required workers to activate the deal. Matches target workers by default |
109+
| `pricePerCuPerEpoch` | string | No | Price per compute unit per epoch in USDC |
110+
| `protocolVersion` | integer | No | Protocol version. Default: 1 |
111+
| `services` | string[] | No | An array of service names to include in this worker. Service names must be listed in fluence.yaml |
112+
| `spells` | string[] | No | An array of spell names to include in this worker. Spell names must be listed in fluence.yaml |
113+
| `targetWorkers` | integer | No | Max workers in the deal |
114+
| `whitelist` | string[] | No | Whitelist of providers to deploy to. Can't be used together with blacklist |
115115

116116
## hosts
117117

cli/docs/configs/provider.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -249,8 +249,8 @@ Effector configuration
249249

250250
| Property | Type | Required | Description |
251251
|-------------------|----------------------------|----------|--------------------------|
252-
| `allowedBinaries` | [object](#allowedbinaries) | **Yes** | Allowed binaries |
253252
| `wasmCID` | string | **Yes** | Wasm CID of the effector |
253+
| `allowedBinaries` | [object](#allowedbinaries) | No | Allowed binaries |
254254

255255
**allowedBinaries**
256256

@@ -440,8 +440,8 @@ Effector configuration
440440

441441
| Property | Type | Required | Description |
442442
|-------------------|----------------------------|----------|--------------------------|
443-
| `allowedBinaries` | [object](#allowedbinaries) | **Yes** | Allowed binaries |
444443
| `wasmCID` | string | **Yes** | Wasm CID of the effector |
444+
| `allowedBinaries` | [object](#allowedbinaries) | No | Allowed binaries |
445445

446446
##### allowedBinaries
447447

cli/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@
7474
"@oclif/plugin-update": "4.2.11",
7575
"@total-typescript/ts-reset": "0.5.1",
7676
"ajv": "8.13.0",
77+
"ajv-formats": "^3.0.1",
7778
"chokidar": "3.6.0",
7879
"countly-sdk-nodejs": "22.6.0",
7980
"debug": "4.3.4",

cli/src/commands/provider/cc-collateral-withdraw.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,13 @@ import {
2525
} from "../../lib/const.js";
2626
import { initCli } from "../../lib/lifeCycle.js";
2727

28+
// Deprecated alias for provider cc-finish
2829
export default class CCCollateralWithdraw extends BaseCommand<
2930
typeof CCCollateralWithdraw
3031
> {
32+
static override hidden = true;
3133
static override aliases = ["provider:ccw"];
32-
static override description = `Withdraw ${FLT_SYMBOL} collateral from capacity commitments`;
34+
static override description = `Move resources from deals, withdraw ${FLT_SYMBOL} collateral from capacity commitments, remove compute units from capacity commitments and finish capacity commitments`;
3335
static override flags = {
3436
...baseFlags,
3537
...CC_FLAGS,
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/**
2+
* Fluence CLI
3+
* Copyright (C) 2024 Fluence DAO
4+
*
5+
* This program is free software: you can redistribute it and/or modify
6+
* it under the terms of the GNU Affero General Public License as
7+
* published by the Free Software Foundation, version 3.
8+
*
9+
* This program is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU Affero General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU Affero General Public License
15+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
16+
*/
17+
18+
import { BaseCommand, baseFlags } from "../../baseCommand.js";
19+
import { collateralWithdraw } from "../../lib/chain/commitment.js";
20+
import {
21+
CHAIN_FLAGS,
22+
FLT_SYMBOL,
23+
CC_FLAGS,
24+
MAX_CUS_FLAG,
25+
} from "../../lib/const.js";
26+
import { initCli } from "../../lib/lifeCycle.js";
27+
28+
export default class CCFinish extends BaseCommand<typeof CCFinish> {
29+
static override aliases = ["provider:ccf"];
30+
static override description = `Move resources from deals, withdraw ${FLT_SYMBOL} collateral from capacity commitments, remove compute units from capacity commitments and finish capacity commitments`;
31+
static override flags = {
32+
...baseFlags,
33+
...CC_FLAGS,
34+
...CHAIN_FLAGS,
35+
...MAX_CUS_FLAG,
36+
};
37+
38+
async run(): Promise<void> {
39+
const { flags } = await initCli(this, await this.parse(CCFinish));
40+
await collateralWithdraw(flags);
41+
}
42+
}

cli/src/commands/provider/init.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
*/
1717

1818
import { color } from "@oclif/color";
19+
import { Flags } from "@oclif/core";
1920

2021
import { BaseCommand, baseFlags } from "../../baseCommand.js";
2122
import { commandObj } from "../../lib/commandObj.js";
@@ -36,6 +37,10 @@ export default class Init extends BaseCommand<typeof Init> {
3637
...baseFlags,
3738
...NOXES_FLAG,
3839
...CHAIN_FLAGS,
40+
"no-vm": Flags.boolean({
41+
description: `Generate ${PROVIDER_CONFIG_FULL_FILE_NAME} without vm configuration`,
42+
default: false,
43+
}),
3944
};
4045

4146
async run(): Promise<void> {

cli/src/lib/ajvInstance.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
import { color } from "@oclif/color";
1919
import Ajv from "ajv";
20+
import addFormats from "ajv-formats";
2021

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

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

31+
addFormats.default(ajv);
32+
3033
type AjvErrors =
3134
| Ajv.ErrorObject<string, Record<string, unknown>>[]
3235
| null

cli/src/lib/configs/initConfig.ts

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -306,16 +306,21 @@ export function getReadonlyConfigInitFunction<
306306
let { configPath } = getConfigPathResult;
307307

308308
const Ajv = (await import("ajv")).default;
309+
const addFormats = (await import("ajv-formats")).default.default;
309310

310-
const validateAllConfigVersions = new Ajv.default({
311-
allowUnionTypes: true,
312-
}).compile<Config>({
311+
const validateAllConfigVersions = addFormats(
312+
new Ajv.default({
313+
allowUnionTypes: true,
314+
}),
315+
).compile<Config>({
313316
oneOf: allSchemas,
314317
});
315318

316-
const validateLatestConfig = new Ajv.default({
317-
allowUnionTypes: true,
318-
}).compile<LatestConfig>(latestSchema);
319+
const validateLatestConfig = addFormats(
320+
new Ajv.default({
321+
allowUnionTypes: true,
322+
}),
323+
).compile<LatestConfig>(latestSchema);
319324

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

cli/src/lib/configs/project/fluence.ts

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import CLIPackageJSON from "../../../versions/cli.package.json" assert { type: "
3535
import { versions } from "../../../versions.js";
3636
import { ajv, validationErrorToString } from "../../ajvInstance.js";
3737
import { validateProtocolVersion } from "../../chain/chainValidators.js";
38+
import { commandObj } from "../../commandObj.js";
3839
import {
3940
COMPUTE_UNIT_MEMORY_STR,
4041
MAX_HEAP_SIZE_DESCRIPTION,
@@ -286,7 +287,7 @@ const dealSchemaObj = {
286287
minimum: 1,
287288
maximum: 1,
288289
default: 1,
289-
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`,
290+
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`,
290291
nullable: true,
291292
},
292293
targetWorkers: {
@@ -1733,6 +1734,26 @@ async function validateProtocolVersions(config: LatestConfig) {
17331734
return true;
17341735
}
17351736

1737+
function warnComputeUnitsIsDeprecated(config: LatestConfig): true {
1738+
const deploymentsWithWarning = Object.entries(
1739+
config.deployments ?? {},
1740+
).filter(([, deployment]) => {
1741+
return "computeUnits" in deployment;
1742+
});
1743+
1744+
if (deploymentsWithWarning.length > 0) {
1745+
commandObj.warn(
1746+
`'computeUnits' property is deprecated. Use 'cuCountPerWorker' instead. Deployment(s): ${deploymentsWithWarning
1747+
.map(([deploymentName]) => {
1748+
return deploymentName;
1749+
})
1750+
.join(", ")}`,
1751+
);
1752+
}
1753+
1754+
return true;
1755+
}
1756+
17361757
const validate: ConfigValidateFunction<LatestConfig> = async (config) => {
17371758
return validateBatchAsync(
17381759
validateNotBothBlacklistAndWhitelist(config),
@@ -1754,6 +1775,7 @@ const validate: ConfigValidateFunction<LatestConfig> = async (config) => {
17541775
validateVersionsIsExact("marineVersion", config.marineVersion),
17551776
validateVersionsIsExact("mreplVersion", config.mreplVersion),
17561777
validateProtocolVersions(config),
1778+
warnComputeUnitsIsDeprecated(config),
17571779
);
17581780
};
17591781

0 commit comments

Comments
 (0)