Skip to content

Commit e90c087

Browse files
shamsartemfolex
andauthored
feat!: group cc infos by status, store offer id right after it's created [JS-814, JS-815] (#1059)
* feat: group cc infos by status, store offer id right after it's created, decrease deciderPeriodSec to 15 on local network [JS-814, JS-815, JS-816] * chore(ci,tests): print load average * set workerPeriodSec * fix * Apply automatic changes * fix(ci): run uptime always * remove additional noxes * fix * fix * Apply automatic changes * fix * run provider tests first * fix * fix * improve * restore deciderPeriodSec * improve * fix * fix --------- Co-authored-by: folex <[email protected]> Co-authored-by: shamsartem <[email protected]>
1 parent 76b3020 commit e90c087

File tree

12 files changed

+270
-181
lines changed

12 files changed

+270
-181
lines changed

.github/workflows/tests.yml

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,10 @@ jobs:
280280
run: yarn local-up
281281
working-directory: cli
282282

283+
- name: Run provider tests
284+
run: yarn vitest-provider
285+
working-directory: cli
286+
283287
- name: Run deal deploy tests
284288
run: yarn vitest-deal-deploy
285289
working-directory: cli
@@ -296,9 +300,9 @@ jobs:
296300
run: yarn vitest-js-to-aqua
297301
working-directory: cli
298302

299-
- name: Run provider tests
300-
run: yarn vitest-provider
301-
working-directory: cli
303+
- name: Show Runner Load Average
304+
run: uptime
305+
if: always()
302306

303307
- name: Dump container logs
304308
if: always()

cli/docs/commands/README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
* [`fluence provider cc-rewards-withdraw`](#fluence-provider-cc-rewards-withdraw)
5151
* [`fluence provider deal-exit`](#fluence-provider-deal-exit)
5252
* [`fluence provider deal-list`](#fluence-provider-deal-list)
53-
* [`fluence provider deal-rewards-info [DEAL-ADDRESS] [UNIT-ID]`](#fluence-provider-deal-rewards-info-deal-address-unit-id)
53+
* [`fluence provider deal-rewards-info [DEAL-ADDRESS] [ON-CHAIN-WORKER-ID]`](#fluence-provider-deal-rewards-info-deal-address-on-chain-worker-id)
5454
* [`fluence provider deal-rewards-withdraw`](#fluence-provider-deal-rewards-withdraw)
5555
* [`fluence provider gen`](#fluence-provider-gen)
5656
* [`fluence provider info`](#fluence-provider-info)
@@ -1466,18 +1466,18 @@ ALIASES
14661466

14671467
_See code: [src/commands/provider/deal-list.ts](https://github.com/fluencelabs/cli/blob/fluence-cli-v0.21.0/src/commands/provider/deal-list.ts)_
14681468

1469-
## `fluence provider deal-rewards-info [DEAL-ADDRESS] [UNIT-ID]`
1469+
## `fluence provider deal-rewards-info [DEAL-ADDRESS] [ON-CHAIN-WORKER-ID]`
14701470

14711471
Deal rewards info
14721472

14731473
```
14741474
USAGE
1475-
$ fluence provider deal-rewards-info [DEAL-ADDRESS] [UNIT-ID] [--no-input] [--env <testnet | mainnet | stage | local |
1476-
custom>] [--priv-key <private-key>]
1475+
$ fluence provider deal-rewards-info [DEAL-ADDRESS] [ON-CHAIN-WORKER-ID] [--no-input] [--env <testnet | mainnet | stage |
1476+
local | custom>] [--priv-key <private-key>]
14771477
14781478
ARGUMENTS
1479-
DEAL-ADDRESS Deal address
1480-
UNIT-ID Compute unit ID
1479+
DEAL-ADDRESS Deal address
1480+
ON-CHAIN-WORKER-ID On-chain worker id
14811481
14821482
FLAGS
14831483
--env=<testnet | mainnet | stage | local | custom> Fluence Environment to use when running the command

cli/docs/configs/provider.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,7 @@ Decider service configuration
326326
| `startBlock` | string | No | Start block (deprecated) |
327327
| `walletKey` | string | No | Wallet key (deprecated) |
328328
| `workerIpfsMultiaddr` | string | No | Multiaddress of worker IPFS node |
329+
| `workerPeriodSec` | integer | No | Worker period in seconds |
329330

330331
##### vm
331332

@@ -517,6 +518,7 @@ Decider service configuration
517518
| `startBlock` | string | No | Start block (deprecated) |
518519
| `walletKey` | string | No | Wallet key (deprecated) |
519520
| `workerIpfsMultiaddr` | string | No | Multiaddress of worker IPFS node |
521+
| `workerPeriodSec` | integer | No | Worker period in seconds |
520522

521523
### vm
522524

cli/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
"vitest-deal-update": "vitest run dealUpdate.test.ts",
3636
"vitest-smoke": "vitest run smoke.test.ts",
3737
"vitest-js-to-aqua": "vitest run jsToAqua.test.ts",
38-
"vitest": "yarn vitest-deal-deploy && yarn vitest-deal-update && yarn vitest-smoke && yarn vitest-js-to-aqua && yarn vitest-provider",
38+
"vitest": "yarn vitest-provider && yarn vitest-deal-deploy && yarn vitest-deal-update && yarn vitest-smoke && yarn vitest-js-to-aqua",
3939
"pack-linux-x64": "oclif pack tarballs -t \"linux-x64\" --no-xz",
4040
"pack-darwin-x64": "oclif pack tarballs -t \"darwin-x64\" --no-xz",
4141
"pack-darwin-arm64": "oclif pack tarballs -t \"darwin-arm64\" --no-xz",

cli/src/commands/provider/deal-rewards-info.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ export default class DealRewardsInfo extends BaseCommand<
4040
"DEAL-ADDRESS": Args.string({
4141
description: "Deal address",
4242
}),
43-
"UNIT-ID": Args.string({
44-
description: "Compute unit ID",
43+
"ON-CHAIN-WORKER-ID": Args.string({
44+
description: "On-chain worker id",
4545
}),
4646
};
4747

@@ -51,12 +51,13 @@ export default class DealRewardsInfo extends BaseCommand<
5151
const dealAddress =
5252
args["DEAL-ADDRESS"] ?? (await input({ message: "Enter deal address" }));
5353

54-
const unitId =
55-
args["UNIT-ID"] ?? (await input({ message: "Enter unit id" }));
54+
const onChainWorkerId =
55+
args["ON-CHAIN-WORKER-ID"] ??
56+
(await input({ message: "Enter on-chain worker id" }));
5657

5758
const { readonlyDealClient } = await getReadonlyDealClient();
5859
const deal = readonlyDealClient.getDeal(dealAddress);
59-
const rewardAmount = await deal.getRewardAmount(unitId);
60+
const rewardAmount = await deal.getRewardAmount(onChainWorkerId);
6061

6162
commandObj.log(
6263
`Provider reward: ${color.yellow(

cli/src/commands/provider/deal-rewards-withdraw.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
*/
1717

1818
import { BaseCommand, baseFlags } from "../../baseCommand.js";
19+
import { peerIdHexStringToBase58String } from "../../lib/chain/conversions.js";
1920
import { ptFormatWithSymbol } from "../../lib/chain/currencies.js";
2021
import { commandObj } from "../../lib/commandObj.js";
2122
import {
@@ -66,7 +67,20 @@ export default class DealRewardsWithdraw extends BaseCommand<
6667
let providerRewards = 0n;
6768
let stakerRewards = 0n;
6869

69-
for (const { onchainId } of workers) {
70+
for (const { onchainId, peerId } of workers) {
71+
const rewardAmount = await deal.getRewardAmount(onchainId);
72+
73+
if (
74+
rewardAmount.providerReward === 0n &&
75+
rewardAmount.stakerReward === 0n
76+
) {
77+
commandObj.logToStderr(
78+
`No rewards to withdraw for worker ${onchainId} (${await peerIdHexStringToBase58String(peerId)})`,
79+
);
80+
81+
continue;
82+
}
83+
7084
const txReceipt = await sign({
7185
title: `Withdraw rewards for worker ${onchainId}`,
7286
method: deal.withdrawRewards,

cli/src/lib/chain/commitment.ts

Lines changed: 72 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
* along with this program. If not, see <http://www.gnu.org/licenses/>.
1616
*/
1717

18-
import { type ICapacity } from "@fluencelabs/deal-ts-clients";
18+
import { CommitmentStatus, type ICapacity } from "@fluencelabs/deal-ts-clients";
1919
import { color } from "@oclif/color";
2020
import isUndefined from "lodash-es/isUndefined.js";
2121
import omitBy from "lodash-es/omitBy.js";
@@ -478,8 +478,10 @@ export async function collateralWithdraw(
478478
const capacity = dealClient.getCapacity();
479479
const market = dealClient.getMarket();
480480

481-
for (const commitment of commitments) {
482-
const { commitmentId } = commitment;
481+
for (const commitment of commitments.flatMap(({ ccInfos }) => {
482+
return ccInfos;
483+
})) {
484+
const { commitmentId, noxName } = commitment;
483485

484486
const [unitIds, isExitedStatuses] =
485487
await capacity.getUnitExitStatuses(commitmentId);
@@ -570,7 +572,7 @@ export async function collateralWithdraw(
570572
}
571573

572574
await signBatch(
573-
`Remove compute units from capacity commitments and finish commitment ${commitmentId}`,
575+
`Remove compute units from capacity commitments and finish commitment ${noxName === undefined ? commitmentId : `for ${noxName} (${commitmentId})`} ${commitmentId}`,
574576
[
575577
...units
576578
.filter(({ isExited }) => {
@@ -606,7 +608,7 @@ export async function collateralRewardWithdraw(flags: CCFlags) {
606608
export function stringifyBasicCommitmentInfo(
607609
commitment:
608610
| Awaited<ReturnType<typeof getCommitments>>[number]
609-
| Awaited<ReturnType<typeof getCommitmentsInfo>>[number],
611+
| Awaited<ReturnType<typeof getCommitmentsInfo>>[number]["ccInfos"][number],
610612
) {
611613
if ("providerConfigComputePeer" in commitment) {
612614
return `${color.yellow(
@@ -637,6 +639,7 @@ export function stringifyBasicCommitmentInfo(
637639

638640
export async function getCommitmentsInfo(flags: CCFlags) {
639641
const { readonlyDealClient } = await getReadonlyDealClient();
642+
const { CommitmentStatus } = await import("@fluencelabs/deal-ts-clients");
640643
const capacity = readonlyDealClient.getCapacity();
641644
const core = readonlyDealClient.getCore();
642645

@@ -656,7 +659,7 @@ export async function getCommitmentsInfo(flags: CCFlags) {
656659

657660
const dealExplorerClient = await getDealExplorerClient();
658661

659-
return Promise.all(
662+
const commitmentsInfo = await Promise.all(
660663
commitments.map(async (c) => {
661664
let commitment: Partial<ICapacity.CommitmentViewStructOutput> =
662665
"commitmentCreatedEvent" in c
@@ -713,6 +716,8 @@ export async function getCommitmentsInfo(flags: CCFlags) {
713716
initTimestamp + commitment.endEpoch * epochDuration,
714717
);
715718

719+
const status = Number(commitment.status);
720+
716721
return {
717722
...("providerConfigComputePeer" in c
718723
? {
@@ -722,10 +727,7 @@ export async function getCommitmentsInfo(flags: CCFlags) {
722727
: {}),
723728
ccFromExplorer,
724729
commitmentId: c.commitmentId,
725-
status:
726-
commitment.status === undefined
727-
? undefined
728-
: Number(commitment.status),
730+
status: status in CommitmentStatus ? status : undefined,
729731
currentEpoch: bigintToStr(currentEpoch),
730732
startEpoch: optBigIntToStr(commitment.startEpoch),
731733
startDate: ccStartDate,
@@ -744,6 +746,29 @@ export async function getCommitmentsInfo(flags: CCFlags) {
744746
};
745747
}),
746748
);
749+
750+
// group commitments by status
751+
return Array.from(
752+
commitmentsInfo
753+
.reduce<
754+
Map<CommitmentStatus | undefined, (typeof commitmentsInfo)[number][]>
755+
>((acc, v) => {
756+
const infos = acc.get(v.status) ?? [];
757+
infos.push(v);
758+
759+
acc.set(
760+
v.status !== undefined && v.status in CommitmentStatus
761+
? v.status
762+
: undefined,
763+
infos,
764+
);
765+
766+
return acc;
767+
}, new Map())
768+
.entries(),
769+
).map(([status, ccInfos]) => {
770+
return { status, ccInfos };
771+
});
747772
}
748773

749774
function optBigIntToStr(value: bigint | undefined) {
@@ -769,25 +794,46 @@ export async function printCommitmentsInfo(flags: CCFlags) {
769794
commandObj.logToStderr(
770795
(
771796
await Promise.all(
772-
ccInfos.map(async (ccInfo) => {
773-
const noxName =
774-
ccInfo.noxName === undefined
775-
? ""
776-
: color.yellow(`Nox: ${ccInfo.noxName}\n`);
777-
778-
return `${noxName}${await getCommitmentInfoString(ccInfo)}`;
797+
ccInfos.map(async ({ status, ccInfos }) => {
798+
return `${await getStatusHeading(status, ccInfos)}${(
799+
await Promise.all(
800+
ccInfos.map(async (ccInfo) => {
801+
const noxName =
802+
ccInfo.noxName === undefined
803+
? ""
804+
: color.yellow(`Nox: ${ccInfo.noxName}\n`);
805+
806+
return `${noxName}${await getCommitmentInfoString(ccInfo)}`;
807+
}),
808+
)
809+
).join("\n\n")}`;
779810
}),
780811
)
781812
).join("\n\n"),
782813
);
783814
}
784815

816+
async function getStatusHeading(
817+
status: CommitmentStatus | undefined,
818+
ccInfos: { noxName?: undefined | string; commitmentId: string }[],
819+
) {
820+
return color.yellow(
821+
`Status: ${await ccStatusToString(status)} (${ccInfos
822+
.map(({ commitmentId, noxName }) => {
823+
return noxName ?? commitmentId;
824+
})
825+
.join(",")})\n\n`,
826+
);
827+
}
828+
785829
export async function printCommitmentsInfoJSON(flags: CCFlags) {
786830
commandObj.log(jsonStringify(await getCommitmentsInfo(flags)));
787831
}
788832

789-
export async function getCommitmentInfoString(
790-
ccInfo: Awaited<ReturnType<typeof getCommitmentsInfo>>[number],
833+
async function getCommitmentInfoString(
834+
ccInfo: Awaited<
835+
ReturnType<typeof getCommitmentsInfo>
836+
>[number]["ccInfos"][number],
791837
) {
792838
const { ethers } = await import("ethers");
793839

@@ -877,18 +923,20 @@ async function ccStatusToString(status: number | undefined) {
877923
return `Unknown (${numToStr(status)})`;
878924
}
879925

880-
return statusStr;
926+
return statusStr === "Inactive" ? "Completed" : statusStr;
881927
}
882928

883929
export async function basicCCInfoAndStatusToString(
884930
ccInfos: Awaited<ReturnType<typeof getCommitmentsInfo>>,
885931
) {
886932
return (
887933
await Promise.all(
888-
ccInfos.map(async (ccInfo) => {
889-
return `${stringifyBasicCommitmentInfo(
890-
ccInfo,
891-
)} Status: ${await ccStatusToString(ccInfo.status)}`;
934+
ccInfos.map(async ({ status, ccInfos }) => {
935+
return `${await getStatusHeading(status, ccInfos)}${ccInfos
936+
.map((ccInfo) => {
937+
return stringifyBasicCommitmentInfo(ccInfo);
938+
})
939+
.join("\n\n")} `;
892940
}),
893941
)
894942
).join("\n\n");

cli/src/lib/chain/depositCollateral.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,16 +32,14 @@ import { fltFormatWithSymbol } from "./currencies.js";
3232
export async function depositCollateral(flags: CCFlags) {
3333
const { CommitmentStatus } = await import("@fluencelabs/deal-ts-clients");
3434

35-
const [commitmentsWithInvalidStatus, commitments] = splitErrorsAndResults(
36-
await getCommitmentsInfo(flags),
37-
(c) => {
35+
const [commitmentsWithInvalidStatus, commitmentsWithWaitDelegation] =
36+
splitErrorsAndResults(await getCommitmentsInfo(flags), (c) => {
3837
if (c.status === CommitmentStatus.WaitDelegation) {
3938
return { result: c };
4039
}
4140

4241
return { error: c };
43-
},
44-
);
42+
});
4543

4644
if (commitmentsWithInvalidStatus.length > 0) {
4745
commandObj.warn(
@@ -51,6 +49,10 @@ export async function depositCollateral(flags: CCFlags) {
5149
);
5250
}
5351

52+
const commitments = commitmentsWithWaitDelegation.flatMap(({ ccInfos }) => {
53+
return ccInfos;
54+
});
55+
5456
if (commitments.length === 0) {
5557
return commandObj.error(
5658
"No capacity commitments in the 'WaitDelegation' status found",

0 commit comments

Comments
 (0)