From 516763e07c590f0926d12ea94153fe134d696548 Mon Sep 17 00:00:00 2001 From: Nina Breznik Date: Fri, 16 Feb 2024 01:51:08 +0000 Subject: [PATCH] update retry_amendment --- demo/scenarios/2.js | 22 +++++++------- demo/scenarios/3.js | 22 +++++++------- .../datdot-node-javascript-internal/chain.js | 30 ++++++++++++++----- src/roles/attester.js | 6 ++-- 4 files changed, 49 insertions(+), 31 deletions(-) diff --git a/demo/scenarios/2.js b/demo/scenarios/2.js index 6d679010..72207435 100644 --- a/demo/scenarios/2.js +++ b/demo/scenarios/2.js @@ -7,15 +7,15 @@ module.exports = [ { "name": "nina", "behavior": ["register_chain_account", "offer_service"] }, { "name": "alex", "behavior": ["register_chain_account", "offer_service"] }, { "name": "ana", "behavior": ["register_chain_account", "offer_service"] }, - // { "name": "miguel", "behavior": ["register_chain_account", "offer_service"] }, - // { "name": "andre", "behavior": ["register_chain_account", "offer_service"] }, - // { "name": "hans", "behavior": ["register_chain_account", "offer_service"] }, - // { "name": "mike", "behavior": ["register_chain_account", "offer_service"] }, - // { "name": "luis", "behavior": ["register_chain_account", "offer_service"] }, - // { "name": "isabel", "behavior": ["register_chain_account", "offer_service"] }, - // { "name": "olga", "behavior": ["register_chain_account", "offer_service"] }, - // { "name": "jota", "behavior": ["register_chain_account", "offer_service"] }, - // { "name": "serena", "behavior": ["register_chain_account", "offer_service"] }, - // { "name": "gus", "behavior": ["register_chain_account", "offer_service"] }, - // { "name": "martin", "behavior": ["register_chain_account", "offer_service"] }, + { "name": "miguel", "behavior": ["register_chain_account", "offer_service"] }, + { "name": "andre", "behavior": ["register_chain_account", "offer_service"] }, + { "name": "hans", "behavior": ["register_chain_account", "offer_service"] }, + { "name": "mike", "behavior": ["register_chain_account", "offer_service"] }, + { "name": "luis", "behavior": ["register_chain_account", "offer_service"] }, + { "name": "isabel", "behavior": ["register_chain_account", "offer_service"] }, + { "name": "olga", "behavior": ["register_chain_account", "offer_service"] }, + { "name": "jota", "behavior": ["register_chain_account", "offer_service"] }, + { "name": "serena", "behavior": ["register_chain_account", "offer_service"] }, + { "name": "gus", "behavior": ["register_chain_account", "offer_service"] }, + { "name": "martin", "behavior": ["register_chain_account", "offer_service"] }, ] diff --git a/demo/scenarios/3.js b/demo/scenarios/3.js index bdd5525c..4df40743 100644 --- a/demo/scenarios/3.js +++ b/demo/scenarios/3.js @@ -10,15 +10,15 @@ module.exports = [ { "name": "iztok", "behavior": ["register_chain_account", "offer_service"] }, { "name": "rok", "behavior": ["register_chain_account", "offer_service"] }, { "name": "katja", "behavior": ["register_chain_account", "offer_service"] }, - { "name": "blaz", "behavior": ["register_chain_account", "offer_service"] }, - { "name": "lovro", "behavior": ["register_chain_account", "offer_service"] }, - { "name": "mateja", "behavior": ["register_chain_account", "offer_service"] }, - { "name": "ivanka", "behavior": ["register_chain_account", "offer_service"] }, - { "name": "slavko", "behavior": ["register_chain_account", "offer_service"] }, - { "name": "vinko", "behavior": ["register_chain_account", "offer_service"] }, - { "name": "vesna", "behavior": ["register_chain_account", "offer_service"] }, - { "name": "nada", "behavior": ["register_chain_account", "offer_service"] }, - { "name": "cveta", "behavior": ["register_chain_account", "offer_service"] }, - { "name": "matic", "behavior": ["register_chain_account", "offer_service"] }, - { "name": "nejc", "behavior": ["register_chain_account", "offer_service"] }, + // { "name": "blaz", "behavior": ["register_chain_account", "offer_service"] }, + // { "name": "lovro", "behavior": ["register_chain_account", "offer_service"] }, + // { "name": "mateja", "behavior": ["register_chain_account", "offer_service"] }, + // { "name": "ivanka", "behavior": ["register_chain_account", "offer_service"] }, + // { "name": "slavko", "behavior": ["register_chain_account", "offer_service"] }, + // { "name": "vinko", "behavior": ["register_chain_account", "offer_service"] }, + // { "name": "vesna", "behavior": ["register_chain_account", "offer_service"] }, + // { "name": "nada", "behavior": ["register_chain_account", "offer_service"] }, + // { "name": "cveta", "behavior": ["register_chain_account", "offer_service"] }, + // { "name": "matic", "behavior": ["register_chain_account", "offer_service"] }, + // { "name": "nejc", "behavior": ["register_chain_account", "offer_service"] }, ] diff --git a/src/node_modules/datdot-node-javascript-internal/chain.js b/src/node_modules/datdot-node-javascript-internal/chain.js index 242d470c..a458eedf 100755 --- a/src/node_modules/datdot-node-javascript-internal/chain.js +++ b/src/node_modules/datdot-node-javascript-internal/chain.js @@ -966,13 +966,22 @@ function getProviders (plan, reuse, task_id, log) { // TODO: backtracking!! try all the options before returning no providers available const attesters = attesterAmount >= 1 ? select({ idleProviders: DB.status.idleAttesters, role: 'attester', amount: attesterAmount, avoid, plan, log }) : [] - if (!attesters.length === attesterAmount) return log({ type: 'chain', data: [`missing attesters`] }) + if (!attesters.length === attesterAmount) { + log({ type: 'chain', data: { text:`error: missing attesters`} }) + return + } const encoders = encoderAmount >= 1 ? select({ idleProviders: DB.status.idleEncoders, role: 'encoder', amount: encoderAmount, avoid, plan, log }) : [] - if (!encoders.length === encoderAmount) return log({ type: 'chain', data: [`missing encoders`] }) + if (!encoders.length === encoderAmount) { + log({ type: 'chain', data: { text:`error: missing encoders`} }) + return + } const hosters = hosterAmount >= 1 ? select({ idleProviders: DB.status.idleHosters, role: 'hoster', amount: hosterAmount, avoid, plan, log }) : [] - if (!hosters.length === hosterAmount) return log({ type: 'chain', data: [`missing hosters`] }) + if (!hosters.length === hosterAmount) { + log({ type: 'chain', data: { text:`error: missing hosters`} }) + return + } return { attesters: [...attesters, ...reused_attesters], @@ -1555,23 +1564,30 @@ async function _retry_amendment ({ failed, amendmentID, log }) { const amendment = getAmendmentByID(amendmentID) const reuse = Object.assign({}, amendment.providers) const { providers: { hosters, attesters, encoders }, contract: contractID } = amendment + const contract = getContractByID(contractID) + // check if previous + const prev_amendment_id = contract.amendments[contract.amendments.length-2] + const prev_amendment = getAmendmentByID(prev_amendment_id) log({ type: 'chain', data: { text: 'Retrying amendment', failed, attesters, encoders, hosters, amendmentID } }) for (var i = 0, len = failed.length; i < len; i++) { const id = failed[i] const user = getUserByID(id) log({ type: 'chain', data: { text: 'Failed user', failed, user, amendmentID } }) - if (attesters.includes(id)) { + // did user fail in this amendment OR was the previous also fail and this user was one of the participants + // it is possible that attester keeps te connection although that peer might have disconnected in between + // and that is the reason the amendment failed again + if (attesters.includes(id) || (prev_amendment?.status === 'fail' && prev_amendment?.providers.attesters.includes(id))) { reuse.attesters = [] _pause({ args: { status: 'fail', log }, user }) unbook_and_rate({ id, role: 'attester', task, type: 'hostingSetup', status: 'fail', log }) } - else if (hosters.includes(id)) { + else if (hosters.includes(id) || prev_amendment?.status === 'fail' && prev_amendment?.providers.hosters.includes(id)) { reuse.hosters.splice(hosters.indexOf(id), 1) _pause({ args: { status: 'fail', log }, user }) unbook_and_rate({ id, role: 'hoster', task, type: 'hostingSetup', status: 'fail', log }) } - else if (encoders.includes(id)) { + else if (encoders.includes(id) || (prev_amendment?.status === 'fail' && prev_amendment?.providers.encoders.includes(id))) { reuse.encoders.splice(encoders.indexOf(id), 1) _pause({ args: { status: 'fail', log }, user }) unbook_and_rate({ id, role: 'encoder', task, type: 'hostingSetup', status: 'fail', log }) @@ -1582,7 +1598,7 @@ async function _retry_amendment ({ failed, amendmentID, log }) { // make new amendment const type = 'retry_hostingSetup' const newID = await init_amendment({ contractID, providers: reuse, type, log }) - log({ type: 'chain', data: { text: 'Retry amendment', providers: reuse, newID } }) + log({ type: 'chain', data: { text: 'Retry amendment', reuse, newID } }) DB.queues.tasks.push({ fnName: type, id: newID }) // TODO: sort tasks based on priority (RATIO!) next_task(log) } diff --git a/src/roles/attester.js b/src/roles/attester.js index b68e4ff8..65063556 100755 --- a/src/roles/attester.js +++ b/src/roles/attester.js @@ -130,6 +130,8 @@ async function handle_hostingSetup (args) { for (const key of peers) { if (!conn[key]) failedKeys.push(key.toString('hex')) } + // we connected to all but it still timed out + if (!failedKeys.length) failedKeys.push(...hosterstringkeys, ...encoderstringkeys) const report = { id: amendmentID, failed: failedKeys, sigs } const nonce = await account.getNonce() await chainAPI.amendmentReport({ report, signer, nonce }) @@ -575,7 +577,7 @@ async function performanceChallenge_handler (args) { const { feedkey, contracts: contractIDs } = feedObj const topic = datdot_crypto.get_discoverykey(feedkey) log({ type: 'challenge', data: { text: 'Performance challenge for feed', feedObj } }) - const { hosterkeys, chunks } = await get_challenge_data({ chainAPI, selectedHosters, contractIDs, log }) + const { hosterkeys, hosterIDs, chunks } = await get_challenge_data({ chainAPI, selectedHosters, contractIDs, log }) var conns = {} var attesting = [] @@ -588,7 +590,7 @@ async function performanceChallenge_handler (args) { } for (var i = 0; i < hosterkeys.length; i++) { - const hoster_id = selectedHosters[i] + const hoster_id = hosterIDs[i] const hosterkey = hosterkeys[i] const tid = setTimeout(() => {