Skip to content

Commit

Permalink
Merge pull request #1039 from golemfactory/feature/golem-stats-improv…
Browse files Browse the repository at this point in the history
…ements

Feature/golem stats improvements
  • Loading branch information
grisha87 authored Aug 1, 2024
2 parents 5adb483 + 4c3a61c commit 1fd6d6e
Show file tree
Hide file tree
Showing 4 changed files with 121 additions and 5 deletions.
27 changes: 23 additions & 4 deletions src/market/proposal/proposal-properties.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,28 @@ export type GenericGolemProtocolPropertyType = Record<string, string | number |
*
* @link https://github.com/golemfactory/golem-architecture/blob/master/gaps/gap-3_mid_agreement_payments/gap-3_mid_agreement_payments.md
*/
export type Gap3MidAgreementPaymentProps = {
"golem.com.scheme.payu.debit-note.interval-sec?"?: number;
"golem.com.scheme.payu.payment-timeout-sec?"?: number;
};
export type Gap3MidAgreementPaymentProps = Partial<{
"golem.com.scheme.payu.debit-note.interval-sec?": number;
"golem.com.scheme.payu.payment-timeout-sec?": number;
}>;

/**
* Properties defined by GAP-35
*
* @link https://github.com/golemfactory/golem-architecture/blob/master/gaps/gap-35_gpu_pci_capability/gap-35_gpu_pci_capability.md
*/
export type Gap35GpuSupportProps = Partial<{
"golem.!exp.gap-35.v1.inf.gpu.model": string;
"golem.!exp.gap-35.v1.inf.gpu.clocks.graphics.mhz": number;
"golem.!exp.gap-35.v1.inf.gpu.clocks.memory.mhz": number;
"golem.!exp.gap-35.v1.inf.gpu.clocks.sm.mhz": number;
"golem.!exp.gap-35.v1.inf.gpu.clocks.video.mhz": number;
"golem.!exp.gap-35.v1.inf.gpu.cuda.cores": number;
"golem.!exp.gap-35.v1.inf.gpu.cuda.enabled": boolean;
"golem.!exp.gap-35.v1.inf.gpu.cuda.version": string;
"golem.!exp.gap-35.v1.inf.gpu.memory.bandwidth.gib": number;
"golem.!exp.gap-35.v1.inf.gpu.memory.total.gib": number;
}>;
/**
* @link https://github.com/golemfactory/golem-architecture/tree/master/standards/0-commons
*/
Expand Down Expand Up @@ -98,6 +116,7 @@ export type ProposalProperties =
StandardComputationPlatformProps &
// Attach GAP specific property sets
Gap3MidAgreementPaymentProps &
Gap35GpuSupportProps &
/**
* These are around byt not really specified in any standard
* FIXME #yagna - Standardize?
Expand Down
2 changes: 1 addition & 1 deletion src/market/scan/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export * from "./types";
export * from "./scan-director";
export * from "./scanned-proposal";
export * from "./scanned-offer";
22 changes: 22 additions & 0 deletions src/market/scan/scanned-offer.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { ScannedOffer } from "./scanned-offer";

describe("Scanned Offer", () => {
test("Returns payment platform address information", async () => {
const offer = new ScannedOffer({
offerId: "example-id",
properties: {
"golem.com.payment.platform.erc20-polygon-glm.address": "0xPolygonAddress",
"golem.com.payment.platform.erc20-holesky-tglm.address": "0xHoleskyAddress",
"golem.com.payment.platform.nonsense": "0xNonsense",
"some.other.prop": "with-a-value",
},
timestamp: new Date().toISOString(),
providerId: "provider-id",
constraints: "",
});

expect(offer.paymentPlatformAddresses["erc20-polygon-glm"]).toEqual("0xPolygonAddress");
expect(offer.paymentPlatformAddresses["erc20-holesky-tglm"]).toEqual("0xHoleskyAddress");
expect(Object.entries(offer.paymentPlatformAddresses).length).toEqual(2);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ import type { MarketApi } from "ya-ts-client";

type ScannedOfferDTO = MarketApi.OfferDTO;

type PaymentPlatformAddressSet = {
/** The payment platform and address map */
[paymentPlatform: string]: string | undefined;
};

export class ScannedOffer {
constructor(private readonly model: ScannedOfferDTO) {}

Expand Down Expand Up @@ -51,34 +56,104 @@ export class ScannedOffer {
name: this.properties["golem.node.id.name"] || "<unknown>",
};
}

get transferProtocol() {
return this.properties["golem.activity.caps.transfer.protocol"];
}

get cpuBrand() {
return this.properties["golem.inf.cpu.brand"];
}

get cpuVendor() {
return this.properties["golem.inf.cpu.vendor"];
}

get cpuCapabilities() {
return this.properties["golem.inf.cpu.capabilities"];
}

get cpuCores() {
return this.properties["golem.inf.cpu.cores"];
}

get cpuThreads() {
return this.properties["golem.inf.cpu.threads"];
}

get gpuBrand() {
return this.properties["golem.!exp.gap-35.v1.inf.gpu.model"];
}

/** @deprecated Use {@link memoryGib} instead */
get memory() {
return this.memoryGib;
}

get memoryGib() {
return this.properties["golem.inf.mem.gib"];
}

/** @deprecated Use {@link storageGib} instead */
get storage() {
return this.storageGib;
}

get storageGib() {
return this.properties["golem.inf.storage.gib"];
}

get publicNet() {
return this.properties["golem.node.net.is-public"];
}

get runtimeCapabilities() {
return this.properties["golem.runtime.capabilities"];
}

get runtimeName() {
return this.properties["golem.runtime.name"];
}

/**
* Get the ID of the offer published by the Provider
*
* Note:
* - this ID will change after the provider refreshes the offer (usually after 1h)
* - this ID will remain unchanged for the same published offer between different scans
*/
get offerId() {
return this.model.offerId;
}

/**
* The timestamp at which the offer was generated by the Provider
*/
get offerCreateAt() {
return this.model.timestamp;
}

/**
* Lists down payment addresses on different payment platforms
*
* @example Example return value
* ```json
* {
* "erc20-polygon-glm": "0x8737beea5668595fda9d50e85cae9cad10b4c980",
* "erc20-holesky-tglm:" "0x8737beea5668595fda9d50e85cae9cad10b4c980",
* }
* ```
*/
get paymentPlatformAddresses(): PaymentPlatformAddressSet {
const propRegex = /golem\.com\.payment\.platform\.([a-z0-9-]+)\.address/;

const platformAddress = Object.entries(this.model.properties)
.map<[string, string]>(([key, address]) => {
const match = key.match(propRegex);
return [match ? match[1] : "", address];
})
.filter(([key]) => !!key);

return Object.fromEntries(platformAddress);
}
}

0 comments on commit 1fd6d6e

Please sign in to comment.