diff --git a/faucet-client/src/pow/PoWMiner.ts b/faucet-client/src/pow/PoWMiner.ts index fc6d6300d..c31513be7 100644 --- a/faucet-client/src/pow/PoWMiner.ts +++ b/faucet-client/src/pow/PoWMiner.ts @@ -58,6 +58,12 @@ export interface IPoWMinerVerification { data: string; } +export interface IPoWMinerVerificationResult { + shareId: string; + params: string; + isValid: boolean; +} + interface PoWMinerEvents { 'stats': (stats: IPoWMinerStats) => void; } @@ -480,7 +486,7 @@ export class PoWMiner extends TypedEmitter { }); } - private onWorkerVerifyResult(worker: IPoWMinerWorker, result: any) { + private onWorkerVerifyResult(worker: IPoWMinerWorker, result: IPoWMinerVerificationResult) { this.options.session.submitVerifyResult(result); } diff --git a/faucet-client/src/pow/PoWSession.ts b/faucet-client/src/pow/PoWSession.ts index 3a6407f23..80c7cb81a 100644 --- a/faucet-client/src/pow/PoWSession.ts +++ b/faucet-client/src/pow/PoWSession.ts @@ -1,8 +1,10 @@ import { TypedEmitter } from 'tiny-typed-emitter'; import { PoWClient } from "./PoWClient"; -import { IPoWMinerShare, IPoWMinerVerification, PoWMiner } from "./PoWMiner"; +import { IPoWMinerShare, IPoWMinerVerification, IPoWMinerVerificationResult, PoWMiner } from "./PoWMiner"; import { FaucetTime } from '../common/FaucetTime'; import { FaucetSession } from '../common/FaucetSession'; +import { getPoWParamsStr } from '../utils/PoWParamsHelper'; +import { IFaucetConfig, IPoWModuleConfig } from '../common/FaucetConfig'; export interface IPoWSessionOptions { session: FaucetSession; @@ -32,7 +34,7 @@ export class PoWSession extends TypedEmitter { private balance: bigint; private shareQueue: IPoWMinerShare[]; private shareQueueProcessing: boolean; - private verifyResultQueue: any[]; + private verifyResultQueue: IPoWMinerVerificationResult[]; public constructor(options: IPoWSessionOptions) { super(); @@ -106,6 +108,9 @@ export class PoWSession extends TypedEmitter { private _submitShare(share: IPoWMinerShare) { this.options.client.sendRequest("foundShare", share).catch((err) => { + if(err.code === "INVALID_SHARE" && err.data && err.data.message === "Invalid share params") + return; // Ignore invalid params + this.options.showNotification("error", "Submission error: [" + err.code + "] " + err.message, true, 20 * 1000); }); } @@ -114,7 +119,7 @@ export class PoWSession extends TypedEmitter { this.miner.processVerification(verification); } - public submitVerifyResult(result) { + public submitVerifyResult(result: IPoWMinerVerificationResult) { if(this.options.client.isReady() && this.verifyResultQueue.length === 0) this._submitVerifyResult(result); else @@ -125,8 +130,11 @@ export class PoWSession extends TypedEmitter { this.verifyResultQueue.forEach((result) => this._submitVerifyResult(result)); } - private _submitVerifyResult(result) { + private _submitVerifyResult(result: IPoWMinerVerificationResult) { this.options.client.sendRequest("verifyResult", result).catch((err) => { + if(err.code === "INVALID_VERIFYRESULT" && err.data && err.data.message === "Invalid share params") + return; // Ignore invalid params + this.options.showNotification("error", "Verification error: [" + err.code + "] " + err.message, true, 20 * 1000); }); } diff --git a/faucet-client/src/worker/PoWWorker.ts b/faucet-client/src/worker/PoWWorker.ts index 1acec6ad4..d7b9f666f 100644 --- a/faucet-client/src/worker/PoWWorker.ts +++ b/faucet-client/src/worker/PoWWorker.ts @@ -27,7 +27,6 @@ export class PoWWorker { private options: IPoWWorkerOptions; private workerId: number; private powParams: IPoWWorkerParams; - private powDifficulty: number; private powPreImage: string; private working = false; private workNonce: number; @@ -122,6 +121,7 @@ export class PoWWorker { action: "verifyResult", data: { shareId: share.shareId, + params: this.powParams.pstr, isValid: isValid } }); diff --git a/src/modules/pow/PoWClient.ts b/src/modules/pow/PoWClient.ts index 5f7f30d33..7d0982b6b 100644 --- a/src/modules/pow/PoWClient.ts +++ b/src/modules/pow/PoWClient.ts @@ -222,9 +222,13 @@ export class PoWClient { let verifyRes: { shareId: string; + params?: string; isValid: boolean; } = message.data; + if(verifyRes.params && verifyRes.params !== this.module.getPoWParamsStr()) + return this.sendErrorResponse("INVALID_VERIFYRESULT", "Invalid share params", message); + let verifyValid = PoWShareVerification.processVerificationResult(verifyRes.shareId, this.getFaucetSession().getSessionId(), verifyRes.isValid); let verifyReward = BigInt(this.module.getModuleConfig().powShareReward) * BigInt(this.module.getModuleConfig().verifyMinerRewardPerc * 100) / 10000n; if(verifyValid && verifyReward > 0n) {