Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
3 changes: 2 additions & 1 deletion packages/cli/package/docs/commands/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -319,11 +319,12 @@ Move resources from deals, withdraw FLT collateral from capacity commitments, re
```
USAGE
$ fluence provider cc-finish [--no-input] [--peer-names <peer-1,peer-2> | --cc-ids <value>] [--offers
<offer-1,offer-2>] [--env <testnet | mainnet | stage | local>] [--priv-key <private-key>]
<offer-1,offer-2>] [--env <testnet | mainnet | stage | local>] [--priv-key <private-key>] [--force]

FLAGS
--cc-ids=<value> Comma separated capacity commitment IDs
--env=<testnet | mainnet | stage | local> Fluence Environment to use when running the command
--force Allow finish Active CC
--no-input Don't interactively ask for any input from the user
--offers=<offer-1,offer-2> Comma-separated list of offer names. To use all of your offers: --offers
all
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/package/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
"whatwg-url": "^14.0.0"
},
"dependencies": {
"@fluencelabs/deal-ts-clients": "0.24.3-feat-beam-support-f0edb5b-8391-1.0",
"@fluencelabs/deal-ts-clients": "0.27.2-release-candidate-v0-27-2-7faf671-9169-1.0",
"@kubernetes/client-node": "github:fluencelabs/kubernetes-client-javascript#e72ee00a52fec4eb4a8327632895d888ee504f4d",
"@libp2p/crypto": "4.0.1",
"@libp2p/peer-id-factory": "4.0.5",
Expand Down
8 changes: 7 additions & 1 deletion packages/cli/package/src/commands/provider/cc-finish.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,12 @@

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

Expand All @@ -30,6 +35,7 @@ export default class CCFinish extends BaseCommand<typeof CCFinish> {
static override flags = {
...CC_FLAGS,
...CHAIN_FLAGS,
...CC_FINISH_FORCE_FLAG,
};

async run(): Promise<void> {
Expand Down
85 changes: 15 additions & 70 deletions packages/cli/package/src/lib/chain/commitment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -538,14 +538,24 @@ export async function removeCommitments(flags: CCFlags) {
export async function collateralWithdraw(
flags: CCFlags & {
[FINISH_COMMITMENT_FLAG_NAME]?: boolean;
force?: boolean;
},
) {
const isStatusAllowed: (status: CapacityCommitmentStatusString) => boolean =
flags.force === true
? (status) => {
return (
status === "Completed" || status === "Failed" || status === "Active"
);
}
: (status) => {
return status === "Completed" || status === "Failed";
};

const [invalidCommitments, commitments] = splitErrorsAndResults(
await getCommitmentsGroupedByStatus(flags),
(c) => {
return c.status === "Completed" || c.status === "Failed"
? { result: c }
: { error: c };
return isStatusAllowed(c.status) ? { result: c } : { error: c };
},
);

Expand All @@ -570,52 +580,6 @@ export async function collateralWithdraw(
})) {
const { ccId, name: peerName } = commitment;

// TODO: improve how we get this info
const [unitIds, isExitedStatuses] =
await contracts.diamond.getUnitExitStatuses(ccId);

// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
const computeUnitInfos = (await multicallRead(
unitIds.map((unitId): MulticallReadItem => {
return {
target: contracts.deployment.diamond,
callData: contracts.diamond.interface.encodeFunctionData(
"getComputeUnit",
[unitId],
),
decode(returnData) {
return contracts.diamond.interface.decodeFunctionResult(
"getComputeUnit",
returnData,
);
},
};
}),
)) as (
| Awaited<ReturnType<typeof contracts.diamond.getComputeUnit>>
| undefined
)[];

const units = unitIds.map((unitId, i) => {
return {
unitId,
unitInfo:
computeUnitInfos[i] ??
(() => {
throw new Error(
`Unreachable. Unit ${unitId} not found after running getComputeUnit`,
);
})(),
isExited:
isExitedStatuses[i] ??
(() => {
throw new Error(
`Unreachable. No exit status returned from getUnitExitStatuses for unit ${unitId}`,
);
})(),
};
});

await sign({
title: `withdraw collateral from: ${ccId}`,
method: contracts.diamond.withdrawCollateral,
Expand All @@ -632,28 +596,9 @@ export async function collateralWithdraw(
continue;
}

const [firstNotExitedUnit, ...restNotExitedUnits] = units.filter(
({ isExited }) => {
return !isExited;
},
);

await signBatch({
title: `${firstNotExitedUnit === undefined ? "Finish" : "Remove compute units from capacity commitments and finish"} commitment ${peerName === undefined ? ccId : `for ${peerName} (${ccId})`} ${ccId}`,
populatedTxs:
firstNotExitedUnit === undefined
? [populateTx(contracts.diamond.finishCommitment, ccId)]
: [
populateTx(contracts.diamond.removeCUFromCC, ccId, [
firstNotExitedUnit.unitId,
]),
...restNotExitedUnits.map(({ unitId }) => {
return populateTx(contracts.diamond.removeCUFromCC, ccId, [
unitId,
]);
}),
populateTx(contracts.diamond.finishCommitment, ccId),
],
title: `Finish commitment ${peerName === undefined ? ccId : `for ${peerName} (${ccId})`} ${ccId}`,
populatedTxs: [populateTx(contracts.diamond.finishCommitment, ccId)],
});
}
}
Expand Down
6 changes: 6 additions & 0 deletions packages/cli/package/src/lib/const.ts
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,12 @@ export const CC_FLAGS = {
...OFFER_FLAG,
};

export const CC_FINISH_FORCE_FLAG = {
force: Flags.boolean({
description: "Allow finish Active CC",
}),
};

export const FINISH_COMMITMENT_FLAG_NAME = "finish";

export const JSON_FLAG = {
Expand Down
6 changes: 3 additions & 3 deletions packages/cli/package/src/versions.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"protocolVersion": 2,
"chain-rpc": "docker.fluence.dev/chain-rpc:feat-beam-support-f0edb5b-8391-1",
"chain-deploy-script": "docker.fluence.dev/chain-deploy-script:feat-beam-support-f0edb5b-8391-1",
"subgraph-deploy-script": "docker.fluence.dev/subgraph-deploy-script:feat-beam-support-f0edb5b-8391-1"
"chain-rpc": "docker.fluence.dev/chain-rpc:release-candidate-v0-27-2-1d44fe4-9165-1",
"chain-deploy-script": "docker.fluence.dev/chain-deploy-script:release-candidate-v0-27-2-1d44fe4-9165-1",
"subgraph-deploy-script": "docker.fluence.dev/subgraph-deploy-script:release-candidate-v0-27-2-1d44fe4-9165-1"
}
10 changes: 5 additions & 5 deletions packages/cli/package/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1964,7 +1964,7 @@ __metadata:
dependencies:
"@actions/core": "npm:1.11.1"
"@aws-sdk/lib-storage": "npm:^3.501.0"
"@fluencelabs/deal-ts-clients": "npm:0.24.3-feat-beam-support-f0edb5b-8391-1.0"
"@fluencelabs/deal-ts-clients": "npm:0.27.2-release-candidate-v0-27-2-7faf671-9169-1.0"
"@graphql-codegen/cli": "npm:^5.0.3"
"@graphql-codegen/typescript": "npm:^4.1.1"
"@graphql-codegen/typescript-graphql-request": "npm:^6.2.0"
Expand Down Expand Up @@ -2038,9 +2038,9 @@ __metadata:
languageName: unknown
linkType: soft

"@fluencelabs/deal-ts-clients@npm:0.24.3-feat-beam-support-f0edb5b-8391-1.0":
version: 0.24.3-feat-beam-support-f0edb5b-8391-1.0
resolution: "@fluencelabs/deal-ts-clients@npm:0.24.3-feat-beam-support-f0edb5b-8391-1.0"
"@fluencelabs/deal-ts-clients@npm:0.27.2-release-candidate-v0-27-2-7faf671-9169-1.0":
version: 0.27.2-release-candidate-v0-27-2-7faf671-9169-1.0
resolution: "@fluencelabs/deal-ts-clients@npm:0.27.2-release-candidate-v0-27-2-7faf671-9169-1.0"
dependencies:
"@graphql-typed-document-node/core": "npm:^3.2.0"
debug: "npm:^4.3.4"
Expand All @@ -2052,7 +2052,7 @@ __metadata:
graphql-tag: "npm:^2.12.6"
ipfs-http-client: "npm:^60.0.1"
multiformats: "npm:^13.0.1"
checksum: 10c0/2478de8b0eeb12a98f3206dbf2af4501f59da55d413b261dbd84303054ad1053c7f602ce786e4fafb4ce322318605e897d48182759c5875c46685877f5356d58
checksum: 10c0/21a9db2c8f3651a7fd0e89d53aed6fe69755577c3c379317406fd9542006e7cb2f273e4f2786135bf1fbdaba8f8f2370d03cececb0afe95cad2929d6713f1835
languageName: node
linkType: hard

Expand Down
Loading