diff --git a/src/components/c2d/compute_engine_base.ts b/src/components/c2d/compute_engine_base.ts index b6cb3e1e5..119c5848c 100644 --- a/src/components/c2d/compute_engine_base.ts +++ b/src/components/c2d/compute_engine_base.ts @@ -529,13 +529,23 @@ export abstract class C2DEngine { token: string, maxJobDuration: number ): number | null { + CORE_LOGGER.logMessage(`minJobDuration ${env?.minJobDuration}`) + if (maxJobDuration < env.minJobDuration) maxJobDuration = env.minJobDuration + CORE_LOGGER.logMessage(`Env maxJobDuration ${maxJobDuration}`) + const prices = this.getEnvPricesForToken(env, chainId, token) if (!prices) return null let cost: number = 0 for (const request of resourcesRequest) { + CORE_LOGGER.logMessage(`Resource ${request.id} with amount ${request.amount}`) + const resourcePrice = this.getResourcePrice(prices, request.id) - cost += resourcePrice * request.amount * Math.ceil(maxJobDuration / 60) + CORE_LOGGER.logMessage(`Resource price ${resourcePrice}`) + const resourceCost = resourcePrice * request.amount * Math.ceil(maxJobDuration / 60) + CORE_LOGGER.logMessage(`Resource cost ${resourceCost}`) + + cost += resourceCost } return cost } diff --git a/src/components/core/compute/startCompute.ts b/src/components/core/compute/startCompute.ts index 48aa56f49..13a5bf3fc 100644 --- a/src/components/core/compute/startCompute.ts +++ b/src/components/core/compute/startCompute.ts @@ -68,6 +68,7 @@ export class PaidComputeStartHandler extends CommandHandler { if (!task.queueMaxWaitTime) { task.queueMaxWaitTime = 0 } + const authValidationResponse = await this.validateTokenOrSignature( task.authorization, task.consumerAddress, @@ -522,6 +523,7 @@ export class PaidComputeStartHandler extends CommandHandler { // job ID unicity const jobId = generateUniqueID(s) // let's calculate payment needed based on resources request and maxJobDuration + CORE_LOGGER.logMessage(`MaxJobDuration received ${task.maxJobDuration}`) const cost = engine.calculateResourcesCost( task.resources, env, diff --git a/src/components/core/utils/escrow.ts b/src/components/core/utils/escrow.ts index e336f63e1..88b5764bc 100644 --- a/src/components/core/utils/escrow.ts +++ b/src/components/core/utils/escrow.ts @@ -38,6 +38,9 @@ export class Escrow { } getMinLockTime(maxJobDuration: number) { + console.log( + `maxJobDuration ${maxJobDuration} and claimDurationTimeout ${this.claimDurationTimeout}` + ) return maxJobDuration + this.claimDurationTimeout } @@ -150,6 +153,7 @@ export class Escrow { amount: number, expiry: BigNumberish ): Promise { + console.log(`--> createLock expiry ${expiry}`) const jobId = create256Hash(job) const blockchain = this.getBlockchain(chain) const signer = await blockchain.getSigner() @@ -157,6 +161,13 @@ export class Escrow { if (!contract) throw new Error(`Failed to initialize escrow contract`) const wei = await this.getPaymentAmountInWei(amount, chain, token) const userBalance = await this.getUserAvailableFunds(chain, payer, token) + console.log(`--> createLock userBalance ${userBalance}`) + console.log(`--> createLock userBalance ${BigInt(userBalance.toString())}`) + CORE_LOGGER.logMessage( + `User balance ${BigInt(userBalance.toString())} and payment amount in wei ${BigInt(wei)}` + ) + console.log(`--> createLock wei ${wei}`) + console.log(`--> createLock wei ${BigInt(wei)}`) if (BigInt(userBalance.toString()) < BigInt(wei)) { // not enough funds throw new Error(`User ${payer} does not have enough funds`) @@ -189,15 +200,26 @@ export class Escrow { } authorizations.` ) } + console.log( + `--> createLock auths[0].currentLockedAmount ${auths[0].currentLockedAmount}` + ) + console.log(`--> createLock auths[0].maxLockedAmount ${auths[0].maxLockedAmount}`) + + console.log( + `--> createLock BigInt(auths[0].currentLockedAmount.toString()) + BigInt(wei) ${BigInt(auths[0].currentLockedAmount.toString()) + BigInt(wei)}` + ) if ( BigInt(auths[0].currentLockedAmount.toString()) + BigInt(wei) > BigInt(auths[0].maxLockedAmount.toString()) ) { throw new Error(`No valid escrow auths found(will go over limit)`) } + console.log('--> Before maxLockSeconds check') + if (BigInt(auths[0].maxLockSeconds.toString()) < BigInt(expiry)) { throw new Error(`No valid escrow auths found(maxLockSeconds too low)`) } + console.log('--> After maxLockSeconds check') if ( BigInt(auths[0].currentLocks.toString()) + BigInt(1) > BigInt(auths[0].maxLockCounts.toString()) diff --git a/src/components/core/utils/nonceHandler.ts b/src/components/core/utils/nonceHandler.ts index 9fdd86a98..19016f98a 100644 --- a/src/components/core/utils/nonceHandler.ts +++ b/src/components/core/utils/nonceHandler.ts @@ -205,15 +205,19 @@ async function validateNonceAndSignature( try { const addressFromHashSignature = ethers.verifyMessage(consumerMessage, signature) const addressFromBytesSignature = ethers.verifyMessage(messageHashBytes, signature) + if ( ethers.getAddress(addressFromHashSignature)?.toLowerCase() === ethers.getAddress(consumer)?.toLowerCase() || ethers.getAddress(addressFromBytesSignature)?.toLowerCase() === ethers.getAddress(consumer)?.toLowerCase() ) { + CORE_LOGGER.logMessage('[DEBUG] ✅ EOA signature validation PASSED', true) return { valid: true } } + CORE_LOGGER.logMessage('[DEBUG] ❌ EOA signature validation FAILED', true) } catch (error) { + CORE_LOGGER.logMessage(`[DEBUG] EOA validation exception: ${error.message}`, true) // Continue to smart account check }