remove wasm processes cache

This commit is contained in:
Sosthene 2025-08-12 12:52:14 +02:00
parent eda7102ded
commit 8e9d7f0c76

View File

@ -541,10 +541,40 @@ export default class Services {
// await this.saveCipherTxToDb(parsedTx)
}
async parseNewTx(tx: string) {
async parseNewTx(newTxMsg: string) {
const parsedMsg: NewTxMessage = JSON.parse(newTxMsg);
if (parsedMsg.error !== null) {
console.error('Received error in new tx message:', parsedMsg.error);
return;
}
const membersList = this.getAllMembers();
try {
const parsedTx = this.sdkClient.parse_new_tx(tx, 0, membersList);
// Does the transaction spend the tip of a process?
const prevouts = this.sdkClient.get_prevouts(parsedMsg.transaction);
console.log('prevouts:', prevouts);
for (const process of Object.values(this.processesCache)) {
const tip = process.states[process.states.length - 1].commited_in;
if (prevouts.includes(tip)) {
const processId = process.states[0].commited_in;
const newTip = this.sdkClient.get_txid(parsedMsg.transaction);
console.log('Transaction', newTip, 'spends the tip of process', processId);
// We take the data out of the output
const newStateId = this.sdkClient.get_new_state_id(parsedMsg.transaction);
console.log('newStateId:', newStateId);
// We update the relevant process
const updatedProcess = this.sdkClient.process_commit_new_state(process, newStateId, newTip);
this.processesCache[processId] = updatedProcess;
console.log('updatedProcess:', updatedProcess);
break;
}
}
} catch (e) {
console.error('Failed to parse new tx for commitments:', e);
}
try {
const parsedTx = this.sdkClient.parse_new_tx(parsedMsg.transaction, 0, membersList);
if (parsedTx) {
try {
await this.handleApiReturn(parsedTx);
@ -555,7 +585,7 @@ export default class Services {
}
}
} catch (e) {
console.trace(e);
console.debug(e);
}
}
@ -1060,7 +1090,7 @@ export default class Services {
await this.restoreProcessesFromDB();
}
// Restore process in wasm with persistent storage
// Restore processes cache from persistent storage
public async restoreProcessesFromDB() {
const db = await Database.getInstance();
try {
@ -1068,7 +1098,6 @@ export default class Services {
if (processes && Object.keys(processes).length != 0) {
console.log(`Restoring ${Object.keys(processes).length} processes`);
this.processesCache = processes;
this.sdkClient.set_process_cache(processes);
} else {
console.log('No processes to restore!');
}