fixed backup sync issue

This commit is contained in:
Abhishek Sinha 2019-10-16 17:09:08 +05:30
parent c961821a04
commit ea1c155681

View File

@ -12270,9 +12270,11 @@
localbitcoinplusplus.newBackupDatabase.db[backup_db]; localbitcoinplusplus.newBackupDatabase.db[backup_db];
_readAllDB = foreign_db.backup_readAllDB.bind(foreign_db); _readAllDB = foreign_db.backup_readAllDB.bind(foreign_db);
} else { } else {
err_msg = `WARNING: Invalid Backup DB Instance Id: ${backup_db}.`; if(backup_db!==localbitcoinplusplus.wallets.my_local_flo_address) {
showMessage(err_msg); err_msg = `WARNING: Invalid Backup DB Instance Id: ${backup_db}.`;
throw new Error(err_msg); showMessage(err_msg);
throw new Error(err_msg);
}
} }
} }
for (const elem of dbTableNamesArray) { for (const elem of dbTableNamesArray) {
@ -13748,21 +13750,24 @@
m => localbitcoinplusplus.backupWS[m].ws_connection.readyState < 2 m => localbitcoinplusplus.backupWS[m].ws_connection.readyState < 2
); );
const reqFloIdIndex = Object.keys(localbitcoinplusplus.myClosestSupernodes).indexOf(getFLOId); if(currenctBackupWsList.length) {
const reqFloIdIndex = Object.keys(localbitcoinplusplus.myClosestSupernodes).indexOf(getFLOId);
// Get the highest index of connected supernodes
let highestIndexOfConnectedSupernode = -1;
for(let i=0; i<=currenctBackupWsList.length; i++) { // Get the highest index of connected supernodes
if(localbitcoinplusplus.myClosestSupernodes.indexOf(currenctBackupWsList[i]) let highestIndexOfConnectedSupernode = -1;
>highestIndexOfConnectedSupernode) {
highestIndexOfConnectedSupernode for(let i=0; i<=currenctBackupWsList.length; i++) {
= localbitcoinplusplus.myClosestSupernodes.indexOf(currenctBackupWsList[i]); if(Object.keys(localbitcoinplusplus.myClosestSupernodes).indexOf(currenctBackupWsList[i])
>highestIndexOfConnectedSupernode) {
highestIndexOfConnectedSupernode
= Object.keys(localbitcoinplusplus.myClosestSupernodes).indexOf(currenctBackupWsList[i]);
}
} }
// Only if a nearer Supernode than any connected Supernode can pass through
if(reqFloIdIndex>=highestIndexOfConnectedSupernode) return;
} }
// Only if a nearer Supernode than any connected Supernode can pass through
if(reqFloIdIndex>=highestIndexOfConnectedSupernode) return;
if ( if (
typeof localbitcoinplusplus.backupWS[getFLOId] === "object" && typeof localbitcoinplusplus.backupWS[getFLOId] === "object" &&
@ -26479,32 +26484,41 @@
console.log(mismatched_fields); console.log(mismatched_fields);
let latest_data = {}; let latest_data = {};
let old_data = {};
for (var i = 0; i < mismatched_fields.length; i++) { for (var i = 0; i < mismatched_fields.length; i++) {
const mf = mismatched_fields[i]; const mf = mismatched_fields[i];
latest_data[mf] = [];
old_data[mf] = [];
const res_data_obj = await _readAllDB(mf, false); const res_data_obj = await _readAllDB(mf, false);
let filtered_data = res_data_obj.filter(odho => { if(res_data_obj.length===0) {
old_data[mf].push(res_data_obj);
continue;
}
for (let j = 0; j < res_data_obj.length; j++) {
const odho = res_data_obj[j];
if ( if (
typeof odho.timestamp == "number" && typeof odho.timestamp == "number" &&
typeof response_object.higestTimestampList[ typeof response_object
`${mf}_TIME` .higestTimestampList[`${mf}_TIME`] !== "undefined"
] !== "undefined"
) { ) {
return ( if(odho.timestamp >=
odho.timestamp >= Number(
Number( response_object.higestTimestampList[
response_object.higestTimestampList[ `${mf}_TIME`
`${mf}_TIME` ] - 3600000
] - 3600000 )) {
) latest_data[mf].push(odho);
); } else {
} if(typeof odho.is_deletable ==="boolean") continue;
}); old_data[mf].push(odho);
}
latest_data[mf] = filtered_data; }
}
} }
console.log(latest_data); console.log(latest_data);
console.log(old_data);
// Send the data back to sender // Send the data back to sender
if ( if (
@ -26537,6 +26551,15 @@
doSend(server_sync_response) doSend(server_sync_response)
); );
} }
let old_data_with_values = Object.values(old_data).filter(f=>f.length>0);
if(Object.values(old_data_with_values).length) {
localbitcoinplusplus.actions.sync_backup_supernode_from_backup_supernode(
localbitcoinplusplus.wallets.my_local_flo_address,
res_obj.globalParams.senderFloId,
primarySupernodeOfThisUser
);
}
}); });
} }