Skip to content

Commit c05a799

Browse files
authored
fix: yaml-diff-patch usage, support latest contracts, other improvements (#1100)
* fix: yaml-diff-patch usage, use dynamic imports for yaml libs * use cloneDeep to fix yamlDiffPatch problems * move migration confirmation to where it belongs * add CP only after approve and print about it, fix resource details, fix bytes per core to be in GiB instead of GB * fix CPU replace * fix * fix removing and adding compute peers * use latest snapshots
1 parent 0dd4c03 commit c05a799

File tree

15 files changed

+409
-325
lines changed

15 files changed

+409
-325
lines changed

packages/cli/package/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
"whatwg-url": "^14.0.0"
5757
},
5858
"dependencies": {
59-
"@fluencelabs/deal-ts-clients": "0.23.2-feat-marketplace-v2-resources-a3ae33d-7546-1.0",
59+
"@fluencelabs/deal-ts-clients": "0.23.2-feat-marketplace-v2-resources-d1eaf27-7661-1.0",
6060
"@kubernetes/client-node": "github:fluencelabs/kubernetes-client-javascript#e72ee00a52fec4eb4a8327632895d888ee504f4d",
6161
"@libp2p/crypto": "4.0.1",
6262
"@libp2p/peer-id-factory": "4.0.5",

packages/cli/package/src/commands/provider/cc-info.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ export default class CCInfo extends BaseCommand<typeof CCInfo> {
4747
return CCs;
4848
}),
4949
)
50-
: stringifyDetailedCommitmentsInfo(ccInfo),
50+
: await stringifyDetailedCommitmentsInfo(ccInfo),
5151
);
5252
}
5353
}

packages/cli/package/src/commands/provider/info.ts

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

18-
import { yamlDiffPatch } from "yaml-diff-patch";
19-
2018
import { BaseCommand } from "../../baseCommand.js";
2119
import { jsonStringify } from "../../common.js";
2220
import { getProviderInfo } from "../../lib/chain/providerInfo.js";
@@ -68,7 +66,8 @@ export default class Info extends BaseCommand<typeof Info> {
6866
return;
6967
}
7068

71-
commandObj.log(yamlDiffPatch("", {}, infoToPrint));
69+
const { stringify } = await import("yaml");
70+
commandObj.log(stringify(infoToPrint));
7271
}
7372
}
7473

packages/cli/package/src/lib/ajvInstance.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,15 @@ export async function validationErrorToString(errors: AjvErrors) {
4646
return "";
4747
}
4848

49-
const { yamlDiffPatch } = await import("yaml-diff-patch");
49+
const { stringify } = await import("yaml");
5050

5151
return (
5252
"Errors:\n\n" +
5353
errors
5454
.map(({ instancePath, params, message }, i) => {
55-
const paramsMessage = yamlDiffPatch("", {}, params);
55+
const paramsMessage =
56+
Object.keys(params).length === 0 ? "" : `\n${stringify(params)}`;
57+
5658
const prevError = errors[i - 1];
5759

5860
const isDuplicateError =
@@ -64,7 +66,7 @@ export async function validationErrorToString(errors: AjvErrors) {
6466
return "";
6567
}
6668

67-
return `${instancePath === "" ? "" : `${color.yellow(instancePath)} `}${message ?? ""}${paramsMessage === "" ? "" : `\n${paramsMessage}`}`;
69+
return `${instancePath === "" ? "" : `${color.yellow(instancePath)} `}${message ?? ""}${paramsMessage}`;
6870
})
6971
.filter((s) => {
7072
return s !== "";

packages/cli/package/src/lib/chain/commitment.ts

Lines changed: 57 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import assert from "assert";
2020
import type { Contracts } from "@fluencelabs/deal-ts-clients";
2121
import { color } from "@oclif/color";
2222
import parse from "parse-duration";
23-
import { yamlDiffPatch } from "yaml-diff-patch";
2423

2524
import { commandObj } from "../commandObj.js";
2625
import { initProviderConfig } from "../configs/project/provider/provider.js";
@@ -471,7 +470,7 @@ export async function createCommitments(flags: PeerAndOfferNameFlags) {
471470
);
472471

473472
commandObj.logToStderr(
474-
stringifyDetailedCommitmentsInfo(
473+
await stringifyDetailedCommitmentsInfo(
475474
await getDetailedCommitmentsInfoGroupedByStatus({
476475
[PEER_NAMES_FLAG_NAME]: computePeers
477476
.map(({ name }) => {
@@ -1049,21 +1048,31 @@ export async function getDetailedCommitmentsInfoGroupedByStatus(
10491048
);
10501049
}
10511050

1052-
export function stringifyDetailedCommitmentsInfo(
1051+
export async function stringifyDetailedCommitmentsInfo(
10531052
detailedCommitmentsInfoGroupedByStatus: Awaited<
10541053
ReturnType<typeof getDetailedCommitmentsInfoGroupedByStatus>
10551054
>,
10561055
) {
1057-
return detailedCommitmentsInfoGroupedByStatus
1058-
.map(({ statusInfo, CCs }) => {
1059-
return `${getStatusHeading(statusInfo)}${CCs.map((cc) => {
1060-
const peerNameString =
1061-
"peerName" in cc ? color.yellow(`Peer: ${cc.peerName}\n`) : "";
1062-
1063-
return `${peerNameString}${getDetailedCommitmentInfoString(cc)}`;
1064-
}).join("\n\n")}`;
1065-
})
1066-
.join("\n\n");
1056+
return (
1057+
await Promise.all(
1058+
detailedCommitmentsInfoGroupedByStatus.map(
1059+
async ({ statusInfo, CCs }) => {
1060+
return `${getStatusHeading(statusInfo)}${(
1061+
await Promise.all(
1062+
CCs.map(async (cc) => {
1063+
const peerNameString =
1064+
"peerName" in cc
1065+
? color.yellow(`Peer: ${cc.peerName}\n`)
1066+
: "";
1067+
1068+
return `${peerNameString}${await getDetailedCommitmentInfoString(cc)}`;
1069+
}),
1070+
)
1071+
).join("\n\n")}`;
1072+
},
1073+
),
1074+
)
1075+
).join("\n\n");
10671076
}
10681077

10691078
function getStatusHeading(cc: CommitmentGroupedByStatus[number]) {
@@ -1197,47 +1206,43 @@ async function getDetailedCommitmentInfo({
11971206
} satisfies Record<string, string>;
11981207
}
11991208

1200-
function getDetailedCommitmentInfoString(
1209+
async function getDetailedCommitmentInfoString(
12011210
detailedCommitmentInfo: Awaited<ReturnType<typeof getDetailedCommitmentInfo>>,
12021211
) {
1203-
return yamlDiffPatch(
1204-
"",
1205-
{},
1206-
{
1207-
PeerId: detailedCommitmentInfo.peerId,
1208-
"Capacity commitment ID": detailedCommitmentInfo.commitmentId,
1209-
Status: detailedCommitmentInfo.status,
1210-
Staker: detailedCommitmentInfo.staker,
1211-
"Staker reward": detailedCommitmentInfo.stakerReward,
1212-
"Duration (epochs)": detailedCommitmentInfo.durationEpochs,
1213-
"Start / End / Current epoch": [
1214-
detailedCommitmentInfo.startEpoch,
1215-
detailedCommitmentInfo.endEpoch,
1216-
detailedCommitmentInfo.currentEpoch,
1217-
].join(" / "),
1218-
"Start date": detailedCommitmentInfo.startDate,
1219-
"Expiration date": detailedCommitmentInfo.expirationDate,
1220-
"Total CU": detailedCommitmentInfo.totalCU,
1221-
"Missed proofs / Threshold": [
1222-
detailedCommitmentInfo.missedProofs,
1223-
detailedCommitmentInfo.threshold,
1224-
].join(" / "),
1225-
"Collateral per unit": detailedCommitmentInfo.collateralPerUnit,
1226-
"Exited unit count": detailedCommitmentInfo.exitedUnitCount,
1227-
"Total CC rewards over time":
1228-
detailedCommitmentInfo.totalCCRewardsOverTime,
1229-
"In vesting / Available / Total claimed (Provider)": [
1230-
detailedCommitmentInfo.providerRewardsInVesting,
1231-
detailedCommitmentInfo.providerRewardsAvailable,
1232-
detailedCommitmentInfo.providerRewardsTotalClaimed,
1233-
].join(" / "),
1234-
"In vesting / Available / Total claimed (Staker)": [
1235-
detailedCommitmentInfo.stakerRewardsInVesting,
1236-
detailedCommitmentInfo.stakerRewardsAvailable,
1237-
detailedCommitmentInfo.stakerRewardsTotalClaimed,
1238-
].join(" / "),
1239-
},
1240-
);
1212+
const { stringify } = await import("yaml");
1213+
return stringify({
1214+
PeerId: detailedCommitmentInfo.peerId,
1215+
"Capacity commitment ID": detailedCommitmentInfo.commitmentId,
1216+
Status: detailedCommitmentInfo.status,
1217+
Staker: detailedCommitmentInfo.staker,
1218+
"Staker reward": detailedCommitmentInfo.stakerReward,
1219+
"Duration (epochs)": detailedCommitmentInfo.durationEpochs,
1220+
"Start / End / Current epoch": [
1221+
detailedCommitmentInfo.startEpoch,
1222+
detailedCommitmentInfo.endEpoch,
1223+
detailedCommitmentInfo.currentEpoch,
1224+
].join(" / "),
1225+
"Start date": detailedCommitmentInfo.startDate,
1226+
"Expiration date": detailedCommitmentInfo.expirationDate,
1227+
"Total CU": detailedCommitmentInfo.totalCU,
1228+
"Missed proofs / Threshold": [
1229+
detailedCommitmentInfo.missedProofs,
1230+
detailedCommitmentInfo.threshold,
1231+
].join(" / "),
1232+
"Collateral per unit": detailedCommitmentInfo.collateralPerUnit,
1233+
"Exited unit count": detailedCommitmentInfo.exitedUnitCount,
1234+
"Total CC rewards over time": detailedCommitmentInfo.totalCCRewardsOverTime,
1235+
"In vesting / Available / Total claimed (Provider)": [
1236+
detailedCommitmentInfo.providerRewardsInVesting,
1237+
detailedCommitmentInfo.providerRewardsAvailable,
1238+
detailedCommitmentInfo.providerRewardsTotalClaimed,
1239+
].join(" / "),
1240+
"In vesting / Available / Total claimed (Staker)": [
1241+
detailedCommitmentInfo.stakerRewardsInVesting,
1242+
detailedCommitmentInfo.stakerRewardsAvailable,
1243+
detailedCommitmentInfo.stakerRewardsTotalClaimed,
1244+
].join(" / "),
1245+
});
12411246
}
12421247

12431248
type Rewards = { ccRewards: bigint; dealStakerRewards: bigint };

0 commit comments

Comments
 (0)