Skip to content

Commit

Permalink
feat: create one deal per peer with cuCountPerWorker number of comput…
Browse files Browse the repository at this point in the history
…e units (#1031)
  • Loading branch information
shamsartem authored Sep 13, 2024
1 parent 2a96f20 commit cb2c1aa
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 33 deletions.
4 changes: 2 additions & 2 deletions cli/docs/commands/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -826,8 +826,8 @@ FLAGS
--release
--no-build Don't build the project before running the command
--no-input Don't interactively ask for any input from the user
--peer-ids=<value> Comma separated list of peer ids to deploy to. Creates one deal per
each free CU of the peer. Skips off-chain matching
--peer-ids=<value> Comma separated list of peer ids to deploy to. Creates 1 worker for
each peer with 'cuCountPerWorker' number of compute units
--priv-key=<private-key> !WARNING! for debug purposes only. Passing private keys through flags
is unsecure. On local env
0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80 is
Expand Down
48 changes: 20 additions & 28 deletions cli/src/lib/deal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ export async function dealCreate({
return dealId;
}

export async function createAndMatchDealsWithAllCUsOfPeerIds({
export async function createAndMatchDealsForPeerIds({
peerIdsFromFlags,
...dealCreateArgs
}: Parameters<typeof dealCreate>[0] & { peerIdsFromFlags: string }) {
Expand Down Expand Up @@ -205,37 +205,29 @@ export async function createAndMatchDealsWithAllCUsOfPeerIds({
}),
);

for (const { computeUnits, offerId, peerId } of offersWithCUs) {
for (const unitId of computeUnits) {
const dealAddress = await dealCreate({
...dealCreateArgs,
maxWorkersPerProvider: 1,
targetWorkers: 1,
minWorkers: 1,
});
for (const { offerId, computeUnits, peerId } of offersWithCUs) {
const CUs = computeUnits.slice(0, dealCreateArgs.cuCountPerWorker);

try {
const matchDealTxReceipt = await sign({
title: `Match deal ${dealAddress} with CU ${unitId} from offer ${offerId}`,
method: market.matchDeal,
args: [dealAddress, [offerId], [[[unitId]]]],
});
if (CUs.length < dealCreateArgs.cuCountPerWorker) {
commandObj.warn(
`cuCountPerWorker for this deployment is ${color.yellow(dealCreateArgs.cuCountPerWorker)} but there are only ${color.yellow(CUs.length)} compute units without deals available for the peer ${color.yellow(peerId)}. Aborting deal creation for this peer`,
);

const pats = getEventValues({
contract: market,
txReceipt: matchDealTxReceipt,
eventName: "ComputeUnitsMatched",
value: "unitId",
});
continue;
}

dbg(`got pats: ${stringifyUnknown(pats)}`);
try {
const dealAddress = await dealCreate(dealCreateArgs);

commandObj.logToStderr(
`CU ${color.yellow(unitId)} of peer ${peerId} joined the deal ${dealAddress}`,
);
} catch (e) {
commandObj.warn(stringifyUnknown(e));
}
await sign({
title: `Match deal ${dealAddress} with compute units:\n\n${CUs.join("\n")}\n\nfrom offer ${offerId}`,
method: market.matchDeal,
args: [dealAddress, [offerId], [[CUs]]],
});
} catch (e) {
commandObj.error(
`Couldn't create or match deal for peer ${color.yellow(peerId)}: ${stringifyUnknown(e)}`,
);
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions cli/src/lib/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ import {
} from "./const.js";
import { dbg } from "./dbg.js";
import { dealCreate, dealUpdate, match } from "./deal.js";
import { createAndMatchDealsWithAllCUsOfPeerIds } from "./deal.js";
import { createAndMatchDealsForPeerIds } from "./deal.js";
import { getReadonlyDealClient } from "./dealClient.js";
import { numToStr } from "./helpers/typesafeStringify.js";
import { stringifyUnknown } from "./helpers/utils.js";
Expand All @@ -74,7 +74,7 @@ export const DEPLOY_FLAGS = {
}),
"peer-ids": Flags.string({
description:
"Comma separated list of peer ids to deploy to. Creates one deal per each free CU of the peer. Skips off-chain matching",
"Comma separated list of peer ids to deploy to. Creates 1 worker for each peer with 'cuCountPerWorker' number of compute units",
}),
};

Expand Down Expand Up @@ -288,7 +288,7 @@ export async function deployImpl(this: Deploy, cl: typeof Deploy) {
if (dealState === "notMatched" || dealState === "notEnoughWorkers") {
try {
if (flags["peer-ids"] !== undefined) {
await createAndMatchDealsWithAllCUsOfPeerIds({
await createAndMatchDealsForPeerIds({
...dealCreateArgs,
peerIdsFromFlags: flags["peer-ids"],
});
Expand Down

0 comments on commit cb2c1aa

Please sign in to comment.