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(network): add API endpoints for deployment #860

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

jzsfkzm
Copy link
Contributor

@jzsfkzm jzsfkzm commented Feb 18, 2025

refs #767

@jzsfkzm jzsfkzm requested a review from a team as a code owner February 18, 2025 17:37
@jzsfkzm jzsfkzm force-pushed the feature/api-deployments branch from 0d05b6a to ace39ce Compare February 18, 2025 18:00
@jzsfkzm jzsfkzm force-pushed the feature/api-deployments branch from ace39ce to 399d40f Compare February 18, 2025 19:05
@codecov-commenter
Copy link

Codecov Report

Attention: Patch coverage is 72.11538% with 29 lines in your changes missing coverage. Please review.

Project coverage is 54.70%. Comparing base (f1a0c32) to head (399d40f).

Files with missing lines Patch % Lines
...message-transmitter/message-transmitter.service.ts 40.00% 15 Missing ⚠️
...ployment/services/deployment/deployment.service.ts 65.51% 10 Missing ⚠️
...nt/controllers/deployment/deployment.controller.ts 90.47% 2 Missing ⚠️
...eployment/routes/deployments/deployments.router.ts 94.11% 1 Missing ⚠️
.../api/src/user/repositories/user/user.repository.ts 0.00% 1 Missing ⚠️

❌ Your patch status has failed because the patch coverage (72.11%) is below the target coverage (80.00%). You can increase the patch coverage or adjust the target coverage.

Additional details and impacted files
@@             Coverage Diff             @@
##             main     #860       +/-   ##
===========================================
+ Coverage   11.33%   54.70%   +43.37%     
===========================================
  Files         439      218      -221     
  Lines       11594     4994     -6600     
  Branches     2451      718     -1733     
===========================================
+ Hits         1314     2732     +1418     
+ Misses      10104     2251     -7853     
+ Partials      176       11      -165     
Flag Coverage Δ
api 54.70% <72.11%> (?)
deploy-web ?
provider-proxy ?

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Comment on lines +73 to +76
deposit: {
denom: "uakt",
amount: "500000"
},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will be the USDC ibc denom for managed wallets, you can use it from here

Also, the amount should be "5000000", but to test and use sandbox uakt it's probably to have parametrized.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

})
};

return await this.messageTransmitterService.signAndBroadcast(account.address, client, [message]);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We already have a sign and broadcast transaction that handles wallet for the master wallet. The gpu bot wallet mnemonic is used to another purpose.

expect(response.status).toBe(400);
});

xit("creates a deployment", async () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

xit?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was pretty unsure about that part of the code, how it should work and what should it actually do. Can we chat about it @ygrishajev?

) { }

public async findByOwnerAndDseq(owner: string, dseq: string): Promise<SingleDeploymentResponse['data']> {
const response = await axios.get<RestAkasheploymentInfoResponse>(`${apiNodeUrl}/akash/deployment/${betaTypeVersion}/deployments/info`, {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will be the perfect candidates for @stalniy's new chain-sdk implemention. Technically we already have an endpoint implemented for this one, but not refactored in the new services architecture. We should abstract those http calls in the http package.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That function is returning a somewhat different type than the one described for this endpoint, escrow_account for example is missing, or I'd rather say balance is the only thing picked from escrow_account. I'm all for using the same interface where it is possible, so happy to use that function, but should we right away?


const getRoute = createRoute({
method: "get",
path: "/v1/deployments/{dseq}",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dseq is not a unique identifier for a deployment. userId + dseq or address/owner + dseq is. In our case user seems to be more appropriate. So the interface should prob be something like:

Suggested change
path: "/v1/deployments/{dseq}",
path: "/v1/deployments/${userId}/{dseq}",

It's not perfect so it's totally open to discussion, however user should be taken into account

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about if it had the same interface as GET /v1/bids, with ?dseq&userId, userId being optional as it can be derived from auth, but also can be forced when you're an admin?
Maybe it should be GET /v1/x/{dseq}?userId now that I think about it. What do you think?

import { StaleManagedDeploymentsCleanerService } from "@src/deployment/services/stale-managed-deployments-cleaner/stale-managed-deployments-cleaner.service";
import { TopUpManagedDeploymentsService } from "@src/deployment/services/top-up-managed-deployments/top-up-managed-deployments.service";
import { TopUpDeploymentsOptions } from "@src/deployment/types/deployments-refiller";
import { CleanUpStaleDeploymentsParams } from "@src/deployment/types/state-deployments";

@singleton()
export class TopUpDeploymentsController {
export class DeploymentController {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

non-blocking: why do you think we should merge these? Why not having 2 specific controllers?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seemed logical to me as both do something with deployments, but I was unsure too, we can keep those separated, so separating.

@@ -19,4 +28,33 @@ export class TopUpDeploymentsController {
async cleanUpStaleDeployment(options: CleanUpStaleDeploymentsParams) {
await this.staleDeploymentsCleanerService.cleanup(options);
}

@Protected([{ action: "create", subject: "DeploymentSetting" }])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

blocking: this doesn't seem right. Why is it DeploymentSetting?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What would be the proper permission here, sign::UserWallet?

});

if ('code' in response.data) {
return {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do we need to resolve with this response? I assume code may be different? controller should throw appropriate http error. E.g. if deployment not found I assume this return value should be undefined and controller should throw 404. If it's smth else it should be 500 perhaps.

try {
sdl = SDL.fromString(input.sdl, 'beta3');
} catch (_error) {
assert(false, 400, "Invalid SDL");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should the error be checked? I mean we should ensure this is a validation issue and not some code bug in which case it should be 500.

});

const message = {
typeUrl: `/akash.deployment.v1beta3.MsgCreateDeployment`,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants