Backup module: bug fixes
- Fixed: keys.addShare unhandled on reject - Fixed: sinks in Cooldown period not added in sink_chest (for market to verify tx that already occurred) on master process start. - Fixed: sink list from slaves not handled properly for reconstruct (if needed) - Fixed: minor syntax bugs
This commit is contained in:
parent
e4603078d2
commit
70c943c997
@ -55,7 +55,8 @@ function sendSharesToNodes(sinkID, group, shares) {
|
|||||||
let ref = Date.now();
|
let ref = Date.now();
|
||||||
shares_pending[sinkID] = { shares, group, ref };
|
shares_pending[sinkID] = { shares, group, ref };
|
||||||
if (keys.node_id in shares) {
|
if (keys.node_id in shares) {
|
||||||
shares.forEach(s => keys.addShare(group, sinkID, ref, s))
|
shares_pending[sinkID].shares[keys.node_id].forEach(s =>
|
||||||
|
keys.addShare(group, sinkID, ref, s).then(_ => null).catch(error => console.error(error)));
|
||||||
delete shares_pending[sinkID].shares[keys.node_id];
|
delete shares_pending[sinkID].shares[keys.node_id];
|
||||||
}
|
}
|
||||||
for (let node in shares)
|
for (let node in shares)
|
||||||
@ -134,7 +135,7 @@ function collectShares(sinkID, ref, share) {
|
|||||||
if (_mode !== MASTER_MODE)
|
if (_mode !== MASTER_MODE)
|
||||||
return console.warn("Not serving as master");
|
return console.warn("Not serving as master");
|
||||||
if (!(sinkID in shares_collected))
|
if (!(sinkID in shares_collected))
|
||||||
return console.error("Something is wrong! Slaves are sending sinkID thats not been collected");
|
return console.debug("Received shares for sink thats not been collected right now");
|
||||||
if (shares_collected[sinkID].ref > ref)
|
if (shares_collected[sinkID].ref > ref)
|
||||||
return console.debug("Received expired share");
|
return console.debug("Received expired share");
|
||||||
else if (shares_collected[sinkID].ref < ref) {
|
else if (shares_collected[sinkID].ref < ref) {
|
||||||
@ -206,16 +207,19 @@ function informLiveNodes(init) {
|
|||||||
console.warn(`Node(${nodes[i]}) is offline`);
|
console.warn(`Node(${nodes[i]}) is offline`);
|
||||||
if (init && flag)
|
if (init && flag)
|
||||||
syncRequest();
|
syncRequest();
|
||||||
keys.getStoredList().then(result => {
|
keys.getStoredList().then(stored_list => {
|
||||||
if (Object.keys(result).length) {
|
if (Object.keys(stored_list).length) {
|
||||||
keys.getDiscardedList().then(discarded_list => {
|
keys.getDiscardedList().then(discarded_list => {
|
||||||
for (let group in result)
|
let cur_time = Date.now();
|
||||||
result.group.forEach(id => {
|
for (let group in stored_list)
|
||||||
|
stored_list[group].forEach(id => {
|
||||||
if (!(id in discarded_list))
|
if (!(id in discarded_list))
|
||||||
reconstructShares(group, id);
|
reconstructShares(group, id)
|
||||||
|
else if (cur_time - discarded_list[id] < DISCARD_COOLDOWN) //sinkID still in cooldown period
|
||||||
|
keys.sink_chest.set_id(group, id, null);
|
||||||
});
|
});
|
||||||
}).catch(error => console.error(error))
|
}).catch(error => console.error(error))
|
||||||
} else if (!flag) {
|
} else if (init && !flag) {
|
||||||
console.log("Starting the exchange...");
|
console.log("Starting the exchange...");
|
||||||
//generate a sinkID for each group in starting list
|
//generate a sinkID for each group in starting list
|
||||||
keys.sink_groups.initial_list.forEach(group =>
|
keys.sink_groups.initial_list.forEach(group =>
|
||||||
@ -248,7 +252,7 @@ function reconstructShares(group, sinkID) {
|
|||||||
collectAndCall(group, sinkID, sinkKey => sendSharesToNodes(sinkID, group, generateShares(sinkKey)));
|
collectAndCall(group, sinkID, sinkKey => sendSharesToNodes(sinkID, group, generateShares(sinkKey)));
|
||||||
}
|
}
|
||||||
|
|
||||||
function slaveConnect(floID, pubKey, ws, sinks) {
|
function slaveConnect(floID, pubKey, ws, slave_sinks) {
|
||||||
if (_mode !== MASTER_MODE)
|
if (_mode !== MASTER_MODE)
|
||||||
return console.warn("Not serving as master");
|
return console.warn("Not serving as master");
|
||||||
ws.floID = floID;
|
ws.floID = floID;
|
||||||
@ -263,17 +267,18 @@ function slaveConnect(floID, pubKey, ws, sinks) {
|
|||||||
for (let sinkID in shares_collected)
|
for (let sinkID in shares_collected)
|
||||||
requestShare(ws, shares_collected[sinkID].group, sinkID);
|
requestShare(ws, shares_collected[sinkID].group, sinkID);
|
||||||
//check if sinks in slaves are present
|
//check if sinks in slaves are present
|
||||||
if (Array.isArray(sinks)) {
|
if (slave_sinks instanceof Object) {
|
||||||
for (let sinkID of sinks) {
|
for (let group in slave_sinks)
|
||||||
if (!keys.sink_chest.includes(shares_collected[sinkID].group, sinkID))
|
for (let sinkID of slave_sinks[group]) {
|
||||||
|
if (!keys.sink_chest.includes(group, sinkID))
|
||||||
keys.checkIfDiscarded(sinkID)
|
keys.checkIfDiscarded(sinkID)
|
||||||
.then(result => result === false ? reconstructShares(shares_collected[sinkID].group, sinkID) : null)
|
.then(result => result === false ? reconstructShares(group, sinkID) : null)
|
||||||
.catch(error => console.error(error))
|
.catch(error => console.error(error))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const eCode = require('../docs/scripts/floExchangeAPI').errorCode;
|
const eCode = require('../../docs/scripts/floExchangeAPI').errorCode;
|
||||||
|
|
||||||
function generateSink(group) {
|
function generateSink(group) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
@ -292,7 +297,7 @@ function generateSink(group) {
|
|||||||
|
|
||||||
function reshareSink(id) {
|
function reshareSink(id) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
if (!floCrypto.validateAddr(data.id))
|
if (!floCrypto.validateAddr(id))
|
||||||
return reject(INVALID(eCode.INVALID_VALUE, `Invalid ID ${id}`));
|
return reject(INVALID(eCode.INVALID_VALUE, `Invalid ID ${id}`));
|
||||||
else {
|
else {
|
||||||
let group = keys.sink_chest.find_group(id);
|
let group = keys.sink_chest.find_group(id);
|
||||||
@ -315,7 +320,7 @@ function reshareSink(id) {
|
|||||||
|
|
||||||
function discardSink(id) {
|
function discardSink(id) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
if (!floCrypto.validateAddr(data.id))
|
if (!floCrypto.validateAddr(id))
|
||||||
return reject(INVALID(eCode.INVALID_VALUE, `Invalid ID ${id}`));
|
return reject(INVALID(eCode.INVALID_VALUE, `Invalid ID ${id}`));
|
||||||
else if (!keys.sink_chest.find_group(id))
|
else if (!keys.sink_chest.find_group(id))
|
||||||
return reject(INVALID(eCode.NOT_FOUND, `ID ${id} not found`));
|
return reject(INVALID(eCode.NOT_FOUND, `ID ${id} not found`));
|
||||||
@ -341,8 +346,8 @@ function checkForDiscardedSinks() {
|
|||||||
keys.sink_chest.rm_id(group, id);
|
keys.sink_chest.rm_id(group, id);
|
||||||
else
|
else
|
||||||
keys.sink_chest.set_id(group, id, null);
|
keys.sink_chest.set_id(group, id, null);
|
||||||
if (sinkID in shares_collected && !discarded_sinks.includes(sinkID))
|
if (id in shares_collected && !discarded_sinks.includes(id))
|
||||||
discarded_sinks.push(sinkID);
|
discarded_sinks.push(id);
|
||||||
}
|
}
|
||||||
}).catch(error => console.debug(error)))
|
}).catch(error => console.debug(error)))
|
||||||
}
|
}
|
||||||
|
|||||||
@ -21,14 +21,16 @@ function startSlaveProcess(ws, init) {
|
|||||||
//set masterWS
|
//set masterWS
|
||||||
ws.on('message', processDataFromMaster);
|
ws.on('message', processDataFromMaster);
|
||||||
masterWS = ws;
|
masterWS = ws;
|
||||||
let sinks_stored = [];
|
let sinks_stored = {};
|
||||||
Promise.all([keys.getStoredList(), keys.getDiscardedList()]).then(result => {
|
Promise.all([keys.getStoredList(), keys.getDiscardedList()]).then(result => {
|
||||||
let stored_list = result[0],
|
let stored_list = result[0],
|
||||||
discarded_list = result[1];
|
discarded_list = result[1];
|
||||||
for (let g in stored_list)
|
for (let group in stored_list) {
|
||||||
for (let id in stored_list[g])
|
sinks_stored[group] = [];
|
||||||
if (!(stored_list[g][id] in discarded_list))
|
for (let id of stored_list[group])
|
||||||
sinks_stored.push(id);
|
if (!(id in discarded_list))
|
||||||
|
sinks_stored[group].push(id);
|
||||||
|
}
|
||||||
}).catch(error => console.error(error)).finally(_ => {
|
}).catch(error => console.error(error)).finally(_ => {
|
||||||
//inform master
|
//inform master
|
||||||
let message = {
|
let message = {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user