From d6a76441aee09cd0d74231e84ccd948d9c96e416 Mon Sep 17 00:00:00 2001 From: Ladd Hoffman Date: Thu, 17 Nov 2022 09:07:11 -0600 Subject: [PATCH] Add more details to graph --- forum-network/public/classes/member.js | 4 +-- forum-network/public/classes/params.js | 2 +- .../public/classes/validation-pool.js | 21 ++++++++------ forum-network/public/validation-pool-test.js | 29 +++++++++---------- 4 files changed, 29 insertions(+), 27 deletions(-) diff --git a/forum-network/public/classes/member.js b/forum-network/public/classes/member.js index b657243..eaea89d 100644 --- a/forum-network/public/classes/member.js +++ b/forum-network/public/classes/member.js @@ -37,7 +37,7 @@ export class Member extends Actor { // For now, directly call bench.initiateValidationPool(); const signingKey = await CryptoUtil.generateAsymmetricKey(); const signingPublicKey = await CryptoUtil.exportKey(signingKey.publicKey) - this.actions.initiateValidationPool.log(this, bench); + this.actions.initiateValidationPool.log(this, bench, `(fee: ${options.fee})`); const pool = bench.initiateValidationPool(this.reputationPublicKey, {...options, signingPublicKey}); this.validationPools.set(pool.id, {signingPublicKey}); return pool; @@ -49,7 +49,7 @@ export class Member extends Actor { this.validationPools.set(validationPool.id, {signingPublicKey}); // TODO: encrypt vote // TODO: sign message - this.actions.castVote.log(this, validationPool); + this.actions.castVote.log(this, validationPool, `(${position ? "for" : "against"}, stake: ${stake})`); validationPool.castVote(signingPublicKey, position, stake, lockingTime); } diff --git a/forum-network/public/classes/params.js b/forum-network/public/classes/params.js index 033ed14..d9e1039 100644 --- a/forum-network/public/classes/params.js +++ b/forum-network/public/classes/params.js @@ -3,7 +3,7 @@ const params = { stakeForWin: 0.5, // c2 // stakeForAuthor: 0.5, // c3 - For now we keep the default that stakeForAuthor = stakeForWin winningRatio: 0.5, // c4 - quorum: 0, // c5 + quorum: 0.5, // c5 activeVoterThreshold: null, // c6 voteDuration: { // c7 min: 0, diff --git a/forum-network/public/classes/validation-pool.js b/forum-network/public/classes/validation-pool.js index 616d5ce..33d7ea4 100644 --- a/forum-network/public/classes/validation-pool.js +++ b/forum-network/public/classes/validation-pool.js @@ -20,6 +20,7 @@ export class ValidationPool extends Actor { throw new Error(`Duration must be in the range [${params.voteDuration.min}, ${params.voteDuration.max ?? 'Inf'}]; got ${duration}`); } this.state = ValidationPoolStates.OPEN; + this.setStatus("Open"); this.votes = new Map(); this.voters = new Map(); this.bench = bench; @@ -67,9 +68,17 @@ export class ValidationPool extends Actor { // All voters have revealed their reputation public keys // Now we can evaluate winning conditions this.state = ValidationPoolStates.CLOSED; + this.setStatus("Closed"); const result = this.evaluateWinningConditions(); - this.applyTokenLocking(); - this.distributeTokens(result); + if (result === null) { + this.setStatus("Closed - Quorum not met"); + this.scene.log(`note over ${this.name} : Quorum not met`); + } else { + this.setStatus(`Closed - ${result ? "Won" : "Lost"}`); + this.scene.log(`note over ${this.name} : ${result ? "Win" : "Lose"}`); + this.applyTokenLocking(); + this.distributeTokens(result); + } this.deactivate(); } } @@ -118,13 +127,7 @@ export class ValidationPool extends Actor { const votePasses = upvoteValue >= params.winningRatio * downvoteValue; const quorumMet = upvoteValue + downvoteValue >= params.quorum * activeAvailableReputation; - // TODO: If quorum is not met, what should happen? - if (!quorumMet) { - this.deactivate(); - // console.log("Quorum is not met", {upvoteValue, downvoteValue, activeAvailableReputation}); - throw new Error("Quorum is not met"); - } - return votePasses && quorumMet; + return quorumMet ? votePasses : null; } distributeTokens(result) { diff --git a/forum-network/public/validation-pool-test.js b/forum-network/public/validation-pool-test.js index 898062a..a3b878e 100644 --- a/forum-network/public/validation-pool-test.js +++ b/forum-network/public/validation-pool-test.js @@ -36,21 +36,20 @@ await delay(1000); await delay(1000); } -// // Failure example: second member can not self-approve -// try { -// const pool = member2.initiateValidationPool(bench, {fee: 1, duration: 1000, tokenLossRatio: 1}); -// await member2.castVote(pool, true, 0, 0); -// await member2.revealIdentity(pool); // Quorum not met! -// await updateDisplayValues(); -// await delay(1000); -// } catch(e) { -// if (e.message.match(/Quorum is not met/)) { -// console.log("Caught expected error: Quorum not met") -// } else { -// console.error("Unexpected error") -// throw e; -// } -// } +// Failure example: second member can not self-approve +try { + const pool = await member2.initiateValidationPool(bench, {fee: 1, duration: 1000, tokenLossRatio: 1}); + await member2.revealIdentity(pool); // Quorum not met! + await updateDisplayValues(); + await delay(1000); +} catch(e) { + if (e.message.match(/Quorum is not met/)) { + console.log("Caught expected error: Quorum not met") + } else { + console.error("Unexpected error") + throw e; + } +} // Second member must be approved by first member {