From de5e98fa74175ebbf2ed2daa3e621da407454d1d Mon Sep 17 00:00:00 2001 From: Sanka Darshana Date: Thu, 17 Aug 2023 23:21:29 +0530 Subject: [PATCH] wasm bug fixing --- lib/blockchain.ts | 28 +++++++++++++++++----------- package-lock.json | 4 ++-- package.json | 2 +- 3 files changed, 20 insertions(+), 14 deletions(-) diff --git a/lib/blockchain.ts b/lib/blockchain.ts index 1bf904e..d1732f6 100644 --- a/lib/blockchain.ts +++ b/lib/blockchain.ts @@ -42,13 +42,13 @@ export default class Blockchain extends WasmWrapper { let callbackIndices = this.callbackIndices.get(block_hash); let confirmations = this.confirmations.get(block_hash) || BigInt(-1); console.log( - `running callbacks for ${block_hash}. callbacks : ${callbacks?.length} confirmations : ${confirmations}` + `running callbacks for ${block_hash}. callbacks : ${callbacks?.length} indexes : ${callbackIndices?.length} confirmations : ${confirmations} from_blocks_back : ${from_blocks_back}` ); if (Number(confirmations) && callbacks && callbackIndices) { for (let i = Number(confirmations) + 1; i < from_blocks_back; i++) { for (let j = 0; j < callbacks.length; j++) { try { - if (callbacks[j] && callbackIndices[j]) { + if (callbacks[j] !== undefined && callbackIndices[j] !== undefined) { await callbacks[j](block, block.transactions[callbackIndices[j]], i); } else { console.log( @@ -105,17 +105,17 @@ export default class Blockchain extends WasmWrapper { block_id_to_run_callbacks_from = block_id_to_run_callbacks_from + BigInt(1); } - //console.log("block_id_to_run_callbacks_from = " + block_id_to_run_callbacks_from); - //console.log( - // "block_id_in_which_to_delete_callbacks = " + block_id_in_which_to_delete_callbacks - // ); - + console.log("block_id_to_run_callbacks_from = " + block_id_to_run_callbacks_from); + console.log( + "block_id_in_which_to_delete_callbacks = " + block_id_in_which_to_delete_callbacks + ); + console.log("block.id = " + block.id); if (block_id_to_run_callbacks_from > BigInt(0)) { - for (let i = block_id_to_run_callbacks_from; i <= block.id; i++) { + for (let i = block_id_to_run_callbacks_from; i <= block.id; i += BigInt(1)) { + // for (let i = block_id_to_run_callbacks_from; Number(i) <= Number(block.id); i++) { let confirmation_count = block.id - BigInt(i) + BigInt(1); let run_callbacks = true; - - // if bid is less than our last-bid but it is still + // if bid is less than our last-bid, but it is still // the biggest BID we have, then we should avoid // running callbacks as we will have already run // them. We check TS as sanity check as well. @@ -127,6 +127,7 @@ export default class Blockchain extends WasmWrapper { } } + console.log(`i = ${i} confirmations = ${confirmation_count}`); if (run_callbacks) { let callback_block_hash = await this.instance.get_longest_chain_hash_at(i); if (callback_block_hash !== "" && callback_block_hash !== DefaultEmptyBlockHash) { @@ -143,7 +144,11 @@ export default class Blockchain extends WasmWrapper { let callback_block_hash = await this.instance.get_longest_chain_hash_at( block_id_in_which_to_delete_callbacks + BigInt(1) // because block ring starts from 1 ); - console.log(`deleting callbacks for : ${callback_block_hash}`); + console.log( + `deleting callbacks for ${ + block_id_in_which_to_delete_callbacks + BigInt(1) + }: ${callback_block_hash}` + ); this.callbacks.delete(callback_block_hash); this.callbackIndices.delete(callback_block_hash); // this.confirmations.delete(callback_block_hash); @@ -162,6 +167,7 @@ export default class Blockchain extends WasmWrapper { ); } } catch (error) { + console.error("failed running callbacks"); console.error(error); } } diff --git a/package-lock.json b/package-lock.json index 778ba9c..ae2d585 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "saito-js", - "version": "0.0.46", + "version": "0.0.47", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "saito-js", - "version": "0.0.46", + "version": "0.0.47", "license": "ISC", "dependencies": { "base-58": "^0.0.1", diff --git a/package.json b/package.json index c1c842a..fbd2da4 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "saito-js", - "version": "0.0.46", + "version": "0.0.47", "description": "js wrappings around saito-core using wasm", "scripts": { "test": "env TS_NODE_PROJECT=\"tsconfig.testing.json\" mocha --require ts-node/register 'tests/**/*.ts'",