fixed issues during sync of crypto shares to backups
This commit is contained in:
parent
21710857ca
commit
fb491449c1
349
index.html
349
index.html
@ -13600,168 +13600,6 @@
|
|||||||
reactor.registerEvent("enquire_crypto_shares_availability_to_backups");
|
reactor.registerEvent("enquire_crypto_shares_availability_to_backups");
|
||||||
reactor.registerEvent("send_crypto_shares_to_backups");
|
reactor.registerEvent("send_crypto_shares_to_backups");
|
||||||
|
|
||||||
reactor.addEventListener('send_crypto_shares_to_backups', async function(req_params={}) {
|
|
||||||
try {
|
|
||||||
const promise_list = [];
|
|
||||||
|
|
||||||
for (const share_id of req_params.data) {
|
|
||||||
const all_chunks = readDB('supernode_private_key_chunks', share_id);
|
|
||||||
promise_list.push(all_chunks);
|
|
||||||
|
|
||||||
for (let backup_db in localbitcoinplusplus.myClosestSupernodes) {
|
|
||||||
if (
|
|
||||||
typeof localbitcoinplusplus.newBackupDatabase.db[backup_db] ==
|
|
||||||
"object" && backup_db !== localbitcoinplusplus.wallets.my_local_flo_address
|
|
||||||
) {
|
|
||||||
promise_list.push(localbitcoinplusplus.newBackupDatabase.db[backup_db]
|
|
||||||
.backup_readDB('supernode_private_key_chunks', share_id));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
const resolved_list = await Promise.all(promise_list);
|
|
||||||
const all_shares = resolved_list.filter(f=>![null, undefined].includes(f))
|
|
||||||
.reduce((acc, cv)=>acc.concat(cv), []);
|
|
||||||
const shares_object_list = [...new Set(all_shares)];
|
|
||||||
console.log(shares_object_list);
|
|
||||||
|
|
||||||
const msg_obj = {};
|
|
||||||
msg_obj.protocol = '__ALL_SUPERNODES_MSG__';
|
|
||||||
msg_obj.event = 'sync_these_crypto_shares';
|
|
||||||
msg_obj.data = shares_object_list;
|
|
||||||
msg_obj.initialSender = localbitcoinplusplus.wallets.my_local_flo_address;
|
|
||||||
msg_obj.su_pubKey = localbitcoinplusplus.wallets.my_local_flo_public_key;
|
|
||||||
msg_obj.db_name = req_params.db_name;
|
|
||||||
msg_obj.trader_flo_address = req_params.db_name;
|
|
||||||
msg_obj.receiverFloAddress = req_params.initialSender;
|
|
||||||
msg_obj.receivers_list = [req_params.initialSender];
|
|
||||||
msg_obj.hash = Crypto.SHA256(msg_obj);
|
|
||||||
msg_obj.sign = RM_WALLET.sign(
|
|
||||||
msg_obj.hash,
|
|
||||||
localbitcoinplusplus.wallets.MY_SUPERNODE_PRIVATE_KEY
|
|
||||||
);
|
|
||||||
|
|
||||||
const finalMessage = JSON.stringify(msg_obj);
|
|
||||||
console.log(finalMessage);
|
|
||||||
|
|
||||||
reactor.dispatchEvent("informAllSuperNode", msg_obj);
|
|
||||||
showMessage("Sent Crypto shares to "+req_params.initialSender);
|
|
||||||
return console.info("Sent Crypto shares to "+req_params.initialSender);
|
|
||||||
|
|
||||||
} catch(e) {
|
|
||||||
console.error(e);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
reactor.addEventListener('enquire_crypto_shares_availability_to_backups', async function() {
|
|
||||||
try {
|
|
||||||
const RM_WALLET = new localbitcoinplusplus.wallets;
|
|
||||||
const promise_list = [];
|
|
||||||
const all_chunks = readAllDB('supernode_private_key_chunks');
|
|
||||||
promise_list.push(all_chunks);
|
|
||||||
for (let backup_db in localbitcoinplusplus.myClosestSupernodes) {
|
|
||||||
if (
|
|
||||||
typeof localbitcoinplusplus.newBackupDatabase.db[backup_db] ==
|
|
||||||
"object" && backup_db !== localbitcoinplusplus.wallets.my_local_flo_address
|
|
||||||
) {
|
|
||||||
promise_list.push(localbitcoinplusplus.newBackupDatabase.db[backup_db]
|
|
||||||
.backup_readAllDB('supernode_private_key_chunks'));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
const resolved_list = await Promise.all(promise_list);
|
|
||||||
const all_shares = resolved_list.reduce((acc, cv)=>acc.concat(cv), []);
|
|
||||||
const unique_set = [...new Set(all_shares)];
|
|
||||||
|
|
||||||
const sorted_list = {};
|
|
||||||
|
|
||||||
for (const chunk of unique_set) {
|
|
||||||
const primarySuObj = await localbitcoinplusplus.kademlia
|
|
||||||
.determineClosestSupernode(chunk.trader_flo_address);
|
|
||||||
const primarySu = primarySuObj[0].data.id;
|
|
||||||
if(typeof sorted_list[primarySu] !=="object") sorted_list[primarySu] = [];
|
|
||||||
sorted_list[primarySu].push(chunk.id);
|
|
||||||
}
|
|
||||||
|
|
||||||
const extra_backup_ws = {};
|
|
||||||
|
|
||||||
for (const primarySu in sorted_list) {
|
|
||||||
const closestNodesToPrimary = await localbitcoinplusplus.kademlia.determineClosestSupernode(
|
|
||||||
"",
|
|
||||||
"",
|
|
||||||
"",
|
|
||||||
primarySu
|
|
||||||
);
|
|
||||||
const primarySuBackups = closestNodesToPrimary.map(m=>m.data.id)
|
|
||||||
.splice(1, localbitcoinplusplus.master_configurations.MaxBackups);
|
|
||||||
|
|
||||||
console.log(primarySuBackups)
|
|
||||||
for (const closestBackup of primarySuBackups) {
|
|
||||||
// If you yourself are the backup save the data in owner's primarySu
|
|
||||||
if(closestBackup===localbitcoinplusplus.wallets.my_local_flo_address) {
|
|
||||||
localbitcoinplusplus.newBackupDatabase.db[primarySu]
|
|
||||||
.backup_updateinDB('supernode_private_key_chunks', chunk);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
const msg_obj = {};
|
|
||||||
msg_obj.protocol = '__ALL_SUPERNODES_MSG__';
|
|
||||||
msg_obj.event = 'do_you_have_these_crypto_shares';
|
|
||||||
msg_obj.data = sorted_list[primarySu];
|
|
||||||
msg_obj.initialSender = localbitcoinplusplus.wallets.my_local_flo_address;
|
|
||||||
msg_obj.su_pubKey = localbitcoinplusplus.wallets.my_local_flo_public_key;
|
|
||||||
msg_obj.db_name = primarySu;
|
|
||||||
msg_obj.trader_flo_address = primarySu;
|
|
||||||
msg_obj.receiverFloAddress = closestBackup;
|
|
||||||
msg_obj.hash = Crypto.SHA256(msg_obj);
|
|
||||||
msg_obj.sign = RM_WALLET.sign(
|
|
||||||
msg_obj.hash,
|
|
||||||
localbitcoinplusplus.wallets.MY_SUPERNODE_PRIVATE_KEY
|
|
||||||
);
|
|
||||||
|
|
||||||
const finalMessage = JSON.stringify(msg_obj);
|
|
||||||
console.log(finalMessage);
|
|
||||||
|
|
||||||
if (typeof localbitcoinplusplus.backupWS[closestBackup] == "object"
|
|
||||||
&& localbitcoinplusplus.backupWS[closestBackup].ws_connection.readyState == WebSocket.OPEN) {
|
|
||||||
|
|
||||||
localbitcoinplusplus.backupWS[closestBackup].ws_connection.send(finalMessage);
|
|
||||||
|
|
||||||
} else if (typeof extra_backup_ws[closestBackup] == "object") {
|
|
||||||
|
|
||||||
extra_backup_ws[closestBackup].send(finalMessage);
|
|
||||||
|
|
||||||
} else {
|
|
||||||
const url = `${WS}://${localbitcoinplusplus.myClosestSupernodes[closestBackup].ip}`;
|
|
||||||
|
|
||||||
if (closestBackup == localbitcoinplusplus.wallets.my_local_flo_address) return;
|
|
||||||
|
|
||||||
extra_backup_ws[closestBackup] = new WebSocket(url);
|
|
||||||
extra_backup_ws[closestBackup].onopen = function (evt) {
|
|
||||||
//if (extra_backup_ws[closestBackup].bufferedAmount == 0) {
|
|
||||||
extra_backup_ws[closestBackup].send(finalMessage);
|
|
||||||
//}
|
|
||||||
};
|
|
||||||
extra_backup_ws[closestBackup].onclose = function (evt) {
|
|
||||||
console.info(`Closed extra conn ${evt.srcElement.url}`);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
await localbitcoinplusplus.actions.delay(60000);
|
|
||||||
|
|
||||||
for (const wskey in extra_backup_ws) {
|
|
||||||
if (extra_backup_ws.hasOwnProperty(wskey)) {
|
|
||||||
const conn = extra_backup_ws[wskey];
|
|
||||||
conn.close();
|
|
||||||
delete extra_backup_ws[wskey];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
} catch(e) {
|
|
||||||
console.warn(e);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
reactor.addEventListener("new_supernode_connected", async function (evt) {
|
reactor.addEventListener("new_supernode_connected", async function (evt) {
|
||||||
const switchMyWS = new backupSupernodesWebSocketObject();
|
const switchMyWS = new backupSupernodesWebSocketObject();
|
||||||
const connected_su_flo_id = await switchMyWS.getFloIdFromWSUrl(evt.srcElement.url);
|
const connected_su_flo_id = await switchMyWS.getFloIdFromWSUrl(evt.srcElement.url);
|
||||||
@ -15085,6 +14923,170 @@
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
reactor.addEventListener('send_crypto_shares_to_backups', async function(req_params={}) {
|
||||||
|
try {
|
||||||
|
const RM_WALLET = new localbitcoinplusplus.wallets;
|
||||||
|
const promise_list = [];
|
||||||
|
|
||||||
|
for (const share_id of req_params.data) {
|
||||||
|
const all_chunks = readDB('supernode_private_key_chunks', share_id);
|
||||||
|
promise_list.push(all_chunks);
|
||||||
|
|
||||||
|
for (let backup_db in localbitcoinplusplus.myClosestSupernodes) {
|
||||||
|
if (
|
||||||
|
typeof localbitcoinplusplus.newBackupDatabase.db[backup_db] ==
|
||||||
|
"object" && backup_db !== localbitcoinplusplus.wallets.my_local_flo_address
|
||||||
|
) {
|
||||||
|
promise_list.push(localbitcoinplusplus.newBackupDatabase.db[backup_db]
|
||||||
|
.backup_readDB('supernode_private_key_chunks', share_id));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
const resolved_list = await Promise.all(promise_list);
|
||||||
|
const all_shares = resolved_list.filter(f=>![null, undefined].includes(f))
|
||||||
|
.reduce((acc, cv)=>acc.concat(cv), []);
|
||||||
|
const shares_object_list = [...new Set(all_shares)];
|
||||||
|
console.log(shares_object_list);
|
||||||
|
|
||||||
|
const msg_obj = {};
|
||||||
|
msg_obj.protocol = '__ALL_SUPERNODES_MSG__';
|
||||||
|
msg_obj.event = 'sync_these_crypto_shares';
|
||||||
|
msg_obj.data = shares_object_list;
|
||||||
|
msg_obj.initialSender = localbitcoinplusplus.wallets.my_local_flo_address;
|
||||||
|
msg_obj.su_pubKey = localbitcoinplusplus.wallets.my_local_flo_public_key;
|
||||||
|
msg_obj.db_name = req_params.db_name;
|
||||||
|
msg_obj.trader_flo_address = req_params.db_name;
|
||||||
|
msg_obj.receiverFloAddress = req_params.initialSender;
|
||||||
|
msg_obj.receivers_list = [req_params.initialSender];
|
||||||
|
msg_obj.hash = Crypto.SHA256(msg_obj);
|
||||||
|
msg_obj.sign = RM_WALLET.sign(
|
||||||
|
msg_obj.hash,
|
||||||
|
localbitcoinplusplus.wallets.MY_SUPERNODE_PRIVATE_KEY
|
||||||
|
);
|
||||||
|
|
||||||
|
const finalMessage = JSON.stringify(msg_obj);
|
||||||
|
console.log(finalMessage);
|
||||||
|
|
||||||
|
reactor.dispatchEvent("informAllSuperNode", msg_obj);
|
||||||
|
showMessage("Sent Crypto shares to "+req_params.initialSender);
|
||||||
|
return console.info("Sent Crypto shares to "+req_params.initialSender);
|
||||||
|
|
||||||
|
} catch(e) {
|
||||||
|
console.error(e);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
reactor.addEventListener('enquire_crypto_shares_availability_to_backups', async function() {
|
||||||
|
try {
|
||||||
|
const RM_WALLET = new localbitcoinplusplus.wallets;
|
||||||
|
const promise_list = [];
|
||||||
|
const all_chunks = readAllDB('supernode_private_key_chunks');
|
||||||
|
promise_list.push(all_chunks);
|
||||||
|
for (let backup_db in localbitcoinplusplus.myClosestSupernodes) {
|
||||||
|
if (
|
||||||
|
typeof localbitcoinplusplus.newBackupDatabase.db[backup_db] ==
|
||||||
|
"object" && backup_db !== localbitcoinplusplus.wallets.my_local_flo_address
|
||||||
|
) {
|
||||||
|
promise_list.push(localbitcoinplusplus.newBackupDatabase.db[backup_db]
|
||||||
|
.backup_readAllDB('supernode_private_key_chunks'));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
const resolved_list = await Promise.all(promise_list);
|
||||||
|
const all_shares = resolved_list.reduce((acc, cv)=>acc.concat(cv), []);
|
||||||
|
const unique_set = [...new Set(all_shares)];
|
||||||
|
|
||||||
|
const sorted_list = {};
|
||||||
|
|
||||||
|
for (const chunk of unique_set) {
|
||||||
|
const primarySuObj = await localbitcoinplusplus.kademlia
|
||||||
|
.determineClosestSupernode(chunk.trader_flo_address);
|
||||||
|
const primarySu = primarySuObj[0].data.id;
|
||||||
|
if(typeof sorted_list[primarySu] !=="object") sorted_list[primarySu] = [];
|
||||||
|
sorted_list[primarySu].push(chunk.id);
|
||||||
|
}
|
||||||
|
|
||||||
|
const extra_backup_ws = {};
|
||||||
|
|
||||||
|
for (const primarySu in sorted_list) {
|
||||||
|
const closestNodesToPrimary = await localbitcoinplusplus.kademlia.determineClosestSupernode(
|
||||||
|
"",
|
||||||
|
"",
|
||||||
|
"",
|
||||||
|
primarySu
|
||||||
|
);
|
||||||
|
const primarySuBackups = closestNodesToPrimary.map(m=>m.data.id)
|
||||||
|
.splice(1, localbitcoinplusplus.master_configurations.MaxBackups);
|
||||||
|
|
||||||
|
console.log(primarySuBackups)
|
||||||
|
for (const closestBackup of primarySuBackups) {
|
||||||
|
// If you yourself are the backup save the data in owner's primarySu
|
||||||
|
if(closestBackup===localbitcoinplusplus.wallets.my_local_flo_address) {
|
||||||
|
localbitcoinplusplus.newBackupDatabase.db[primarySu]
|
||||||
|
.backup_updateinDB('supernode_private_key_chunks', chunk);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
const msg_obj = {};
|
||||||
|
msg_obj.protocol = '__ALL_SUPERNODES_MSG__';
|
||||||
|
msg_obj.event = 'do_you_have_these_crypto_shares';
|
||||||
|
msg_obj.data = sorted_list[primarySu];
|
||||||
|
msg_obj.initialSender = localbitcoinplusplus.wallets.my_local_flo_address;
|
||||||
|
msg_obj.su_pubKey = localbitcoinplusplus.wallets.my_local_flo_public_key;
|
||||||
|
msg_obj.db_name = primarySu;
|
||||||
|
msg_obj.trader_flo_address = primarySu;
|
||||||
|
msg_obj.receiverFloAddress = closestBackup;
|
||||||
|
msg_obj.hash = Crypto.SHA256(msg_obj);
|
||||||
|
msg_obj.sign = RM_WALLET.sign(
|
||||||
|
msg_obj.hash,
|
||||||
|
localbitcoinplusplus.wallets.MY_SUPERNODE_PRIVATE_KEY
|
||||||
|
);
|
||||||
|
|
||||||
|
const finalMessage = JSON.stringify(msg_obj);
|
||||||
|
console.log(finalMessage);
|
||||||
|
|
||||||
|
if (typeof localbitcoinplusplus.backupWS[closestBackup] == "object"
|
||||||
|
&& localbitcoinplusplus.backupWS[closestBackup].ws_connection.readyState == WebSocket.OPEN) {
|
||||||
|
|
||||||
|
localbitcoinplusplus.backupWS[closestBackup].ws_connection.send(finalMessage);
|
||||||
|
|
||||||
|
} else if (typeof extra_backup_ws[closestBackup] == "object") {
|
||||||
|
|
||||||
|
extra_backup_ws[closestBackup].send(finalMessage);
|
||||||
|
|
||||||
|
} else {
|
||||||
|
const url = `${WS}://${localbitcoinplusplus.myClosestSupernodes[closestBackup].ip}`;
|
||||||
|
|
||||||
|
if (closestBackup == localbitcoinplusplus.wallets.my_local_flo_address) return;
|
||||||
|
|
||||||
|
extra_backup_ws[closestBackup] = new WebSocket(url);
|
||||||
|
extra_backup_ws[closestBackup].onopen = function (evt) {
|
||||||
|
//if (extra_backup_ws[closestBackup].bufferedAmount == 0) {
|
||||||
|
extra_backup_ws[closestBackup].send(finalMessage);
|
||||||
|
//}
|
||||||
|
};
|
||||||
|
extra_backup_ws[closestBackup].onclose = function (evt) {
|
||||||
|
console.info(`Closed extra conn ${evt.srcElement.url}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
await localbitcoinplusplus.actions.delay(60000);
|
||||||
|
|
||||||
|
for (const wskey in extra_backup_ws) {
|
||||||
|
if (extra_backup_ws.hasOwnProperty(wskey)) {
|
||||||
|
const conn = extra_backup_ws[wskey];
|
||||||
|
conn.close();
|
||||||
|
delete extra_backup_ws[wskey];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch(e) {
|
||||||
|
console.warn(e);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
// SECTION: Misc functions
|
// SECTION: Misc functions
|
||||||
function removeWhiteSpaces(text = '') {
|
function removeWhiteSpaces(text = '') {
|
||||||
return text.replace(/\s/g, '');
|
return text.replace(/\s/g, '');
|
||||||
@ -15617,15 +15619,12 @@
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Promise.all(deposit_promises).then(res => {
|
const deposit_promises_res = await Promise.all(deposit_promises);
|
||||||
console.log(res);
|
let timenow = + new Date();
|
||||||
let timenow = + new Date();
|
localStorage.setItem(`refresh_reserved_cryptos_prices_time_${getSupernodeAddr}`, timenow);
|
||||||
localStorage.setItem(`refresh_reserved_cryptos_prices_time_${getSupernodeAddr}`, timenow);
|
console.info('Updated deposited crypto prices.');
|
||||||
console.info('Updated deposited crypto prices.');
|
return deposit_promises_res;
|
||||||
return res;
|
|
||||||
})
|
|
||||||
.catch(e => console.warn("Failed to update deposited crypto balances"));
|
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
throw new Error(error)
|
throw new Error(error)
|
||||||
}
|
}
|
||||||
@ -22671,6 +22670,11 @@
|
|||||||
if(old_idx<0) throw new Error('Negative index in Supernode Kbucket array.');
|
if(old_idx<0) throw new Error('Negative index in Supernode Kbucket array.');
|
||||||
|
|
||||||
limit_function_calls(async function () {
|
limit_function_calls(async function () {
|
||||||
|
// Close all databases first
|
||||||
|
db.close();
|
||||||
|
for (su in localbitcoinplusplus.newBackupDatabase.db) {
|
||||||
|
localbitcoinplusplus.newBackupDatabase.db[su].db.close();
|
||||||
|
}
|
||||||
BitBang.call(localbitcoinplusplus);
|
BitBang.call(localbitcoinplusplus);
|
||||||
console.log("REALLOCATTION_OF_USER_DATA");
|
console.log("REALLOCATTION_OF_USER_DATA");
|
||||||
showMessage('User data re-allocation to start in 3 mins.');
|
showMessage('User data re-allocation to start in 3 mins.');
|
||||||
@ -22824,7 +22828,8 @@
|
|||||||
localbitcoinplusplus.newBackupDatabase.db[backup_db]
|
localbitcoinplusplus.newBackupDatabase.db[backup_db]
|
||||||
.backup_readDB('supernode_private_key_chunks', share_id)
|
.backup_readDB('supernode_private_key_chunks', share_id)
|
||||||
.then(async sharesObj=>{
|
.then(async sharesObj=>{
|
||||||
if(typeof sharesObj.trader_flo_address=="string") {
|
if(typeof sharesObj=="object"
|
||||||
|
&& typeof sharesObj.trader_flo_address=="string") {
|
||||||
const getSupernode = await localbitcoinplusplus.kademlia.determineClosestSupernode(sharesObj.trader_flo_address);
|
const getSupernode = await localbitcoinplusplus.kademlia.determineClosestSupernode(sharesObj.trader_flo_address);
|
||||||
const getSupernodeAddr = getSupernode[0].data.id;
|
const getSupernodeAddr = getSupernode[0].data.id;
|
||||||
const getSupernodeNeighbors = await localbitcoinplusplus.kademlia.determineClosestSupernode(
|
const getSupernodeNeighbors = await localbitcoinplusplus.kademlia.determineClosestSupernode(
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user