fix: truncate pow compute time before submitting

This commit is contained in:
Aravinth Manivannan 2023-07-02 20:00:25 +05:30
parent 3e5936cb83
commit 1b05cdc391
No known key found for this signature in database
GPG key ID: AD9F0F08E855ED88
3 changed files with 2 additions and 9 deletions

View file

@ -55,7 +55,7 @@ export const solveCaptchaRunner = async (e: Event): Promise<void> => {
worker.onmessage = async (event: MessageEvent) => {
const resp: ServiceWorkerWork = event.data;
console.log(
`Proof generated. Difficuly: ${config.difficulty_factor} Duration: ${resp.duration}`
`Proof generated. Difficuly: ${config.difficulty_factor} Duration: ${resp.work.time}`
);
const proof: Work = {
@ -63,7 +63,7 @@ export const solveCaptchaRunner = async (e: Event): Promise<void> => {
string: config.string,
nonce: resp.work.nonce,
result: resp.work.result,
time: resp.work.time,
time: Math.trunc(resp.work.time),
worker_type: resp.work.worker_type,
};

View file

@ -19,15 +19,9 @@ onmessage = async (e) => {
console.debug("message received at worker");
const config: PoWConfig = e.data;
const t0 = performance.now();
const work = await prove(config);
const t1 = performance.now();
const duration = t1 - t0;
const res: ServiceWorkerWork = {
work,
duration,
};
postMessage(res);

View file

@ -32,7 +32,6 @@ export type WasmWork = {
export type ServiceWorkerWork = {
work: SubmitWork;
duration: number;
};
export type PoWConfig = {