Skip to content

Commit

Permalink
make retry_hostingAmendment without reuse + fix some bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
ninabreznik committed Feb 23, 2024
1 parent 62de935 commit 36e6048
Show file tree
Hide file tree
Showing 8 changed files with 116 additions and 119 deletions.
26 changes: 13 additions & 13 deletions demo/scenarios/3.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,22 @@
// author has no additional actions

module.exports = [
// { "name": "grega", "behavior": ["register_chain_account", "sponsor_plan", "offer_service"] },
// { "name": "marko", "behavior": ["register_chain_account", "author_hypercore"] },
{ "name": "grega", "behavior": ["register_chain_account", "sponsor_plan", "offer_service"] },
{ "name": "marko", "behavior": ["register_chain_account", "author_hypercore"] },
{ "name": "andreja", "behavior": ["register_chain_account", "offer_service"] },
{ "name": "bojan", "behavior": ["register_chain_account", "offer_service"] },
{ "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"] },
]
2 changes: 1 addition & 1 deletion demo/simsim.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ async function run (params) {

console.log('3. ===== stop `two` =====')
// console.log('4. ===== just end everything =====')
const delay3 = 12000
const delay3 = 10000
// setTimeout(() => all_processes[pos2].kill('SIGINT'), delay3)
}
/**********************************************************
Expand Down
10 changes: 6 additions & 4 deletions src/node_modules/_datdot-service-helpers/hyper.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

58 changes: 31 additions & 27 deletions src/node_modules/datdot-node-javascript-internal/chain.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 16 additions & 16 deletions src/node_modules/datdot-simulate-user/behavior/sponsor-plan.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

64 changes: 22 additions & 42 deletions src/roles/attester.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,54 +48,34 @@ module.exports = APIS => {

async function handle_hostingSetup_failed (args) {
const { event, chainAPI, account, signer, attesterkey, myAddress, hyper, log } = args
const [amendmentID, failedIDs] = event.data
const [amendmentID] = event.data
const amendment = await chainAPI.getAmendmentByID(amendmentID)
const [attesterID] = amendment.providers.attesters
const attesterAddress = await chainAPI.getUserAddress(attesterID)
if (attesterAddress !== myAddress) return
const { providers: { hosters, encoders, attesters } } = amendment
const [attesterID] = attesters
const address = await chainAPI.getUserAddress(attesterID)
if (address !== myAddress) return

const { hosters, encoders, attesters } = amendment.providers
const contract = await chainAPI.getContractByID(amendment.contract)
const { feed: feedID } = contract
const { feedkey } = await chainAPI.getFeedByID(feedID)
const myID = await chainAPI.getUserIDByNoiseKey(attesterkey)
const { tasks } = account.state

log({ type: 'encoder', data: [`Event received: ${event.method} ${event.data.toString()}`] })
log({ type: 'attester', data: [`Event received: ${event.method} ${event.data.toString()}`] })

if (failedIDs.includes(myID)) { // disconnect from all
for (const id of hosters) {
const hosterkey = await chainAPI.getHosterKey(id)
const topic = derive_topic({ senderKey: attesterkey, feedkey, receiverKey: hosterkey, id: amendmentID, log })
const stringtopic = topic.toString('hex')
if (!tasks[stringtopic]) continue
await done_task_cleanup({ role: 'attester2hoster', topic, remotestringkey: hosterkey.toString('hex'), state: account.state, log })
}
for (const id of encoders) {
const encoderkey = await chainAPI.getEncoderKey(id)
const topic = derive_topic({ senderKey: encoderkey, feedkey, receiverKey: attesterkey, id: amendmentID, log })
const stringtopic = topic.toString('hex')
if (!tasks[stringtopic]) continue
await done_task_cleanup({ role: 'attester2encoder', topic, remotestringkey: encoderkey.toString('hex'), state: account.state, log })
}
}
else { // disconnect from failed
for (const id of failedIDs) {
if (hosters.includes(id)) {
const hosterkey = await chainAPI.getHosterKey(id)
const topic = derive_topic({ senderKey: attesterkey, feedkey, receiverKey: hosterkey, id: amendmentID, log })
const stringtopic = topic.toString('hex')
if (!tasks[stringtopic]) continue
await done_task_cleanup({ role: 'attester2hoster', topic, remotestringkey: hosterkey.toString('hex'), state: account.state, log })
}
else if (encoders.includes(id)) {
const encoderkey = await chainAPI.getEncoderKey(id)
const topic = derive_topic({ senderKey: encoderkey, feedkey, receiverKey: attesterkey, id: amendmentID, log })
const stringtopic = topic.toString('hex')
if (!tasks[stringtopic]) continue
await done_task_cleanup({ role: 'attester2encoder', topic, remotestringkey: encoderkey.toString('hex'), state: account.state, log })
}
}
for (const id of hosters) {
const hosterkey = await chainAPI.getHosterKey(id)
const topic = derive_topic({ senderKey: attesterkey, feedkey, receiverKey: hosterkey, id: amendmentID, log })
const stringtopic = topic.toString('hex')
if (!tasks[stringtopic]) continue
await done_task_cleanup({ role: 'attester2hoster', topic, remotestringkey: hosterkey.toString('hex'), state: account.state, log })
}
for (const id of encoders) {
const encoderkey = await chainAPI.getEncoderKey(id)
const topic = derive_topic({ senderKey: encoderkey, feedkey, receiverKey: attesterkey, id: amendmentID, log })
const stringtopic = topic.toString('hex')
if (!tasks[stringtopic]) continue
await done_task_cleanup({ role: 'attester2encoder', topic, remotestringkey: encoderkey.toString('hex'), state: account.state, log })
}

}
Expand Down Expand Up @@ -125,12 +105,12 @@ async function handle_hostingSetup (args) {
const hosterstringkeys = hosterkeys.map(key => key.toString('hex'))
const encoderstringkeys = encoderkeys.map(key => key.toString('hex'))
const peers = [...hosterstringkeys, ...encoderstringkeys]
log({ type: 'attester', data: { texts: 'error: hosting setup - timeout', amendmentID, failedKeys, conn, hosterkeys, encoderkeys, peers } })
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)
// we connected to all but it still timed out
if (!failedKeys.length) failedKeys.push(...hosterstringkeys, ...encoderstringkeys)
log({ type: 'attester', data: { texts: 'error: hosting setup - timeout', amendmentID, failedKeys, conn, hosterkeys, encoderkeys, peers } })
const report = { id: amendmentID, failed: failedKeys, sigs }
const nonce = await account.getNonce()
await chainAPI.amendmentReport({ report, signer, nonce })
Expand Down
Loading

0 comments on commit 36e6048

Please sign in to comment.