Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: removeCUFromCC only for units that are not already exited #1056

Merged
merged 2 commits into from
Sep 23, 2024
Merged
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
24 changes: 18 additions & 6 deletions cli/src/lib/chain/commitment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -480,15 +480,23 @@ export async function collateralWithdraw(

for (const commitment of commitments) {
const { commitmentId } = commitment;
const commitmentInfo = await capacity.getCommitment(commitmentId);
const unitIds = await market.getComputeUnitIds(commitmentInfo.peerId);

const [unitIds, isExitedStatuses] =
await capacity.getUnitExitStatuses(commitmentId);

const units = await batchRead(
unitIds.map((unitId) => {
unitIds.map((unitId, i) => {
return async () => {
return {
unitId,
unitInfo: await market.getComputeUnit(unitId),
isExited:
isExitedStatuses[i] ??
(() => {
throw new Error(
`Unreachable. No exit status returned from getUnitExitStatuses for unit ${unitId}`,
);
})(),
};
};
}),
Expand Down Expand Up @@ -564,9 +572,13 @@ export async function collateralWithdraw(
await signBatch(
`Remove compute units from capacity commitments and finish commitment ${commitmentId}`,
[
...unitIds.map((unitId) => {
return populateTx(capacity.removeCUFromCC, commitmentId, [unitId]);
}),
...units
.filter(({ isExited }) => {
return !isExited;
})
.map(({ unitId }) => {
return populateTx(capacity.removeCUFromCC, commitmentId, [unitId]);
}),
populateTx(capacity.finishCommitment, commitmentId),
],
);
Expand Down
Loading