Add more details to graph

This commit is contained in:
Ladd Hoffman 2022-11-17 09:07:11 -06:00
parent 64a2feeaa8
commit d6a76441ae
4 changed files with 29 additions and 27 deletions

View File

@ -37,7 +37,7 @@ export class Member extends Actor {
// For now, directly call bench.initiateValidationPool(); // For now, directly call bench.initiateValidationPool();
const signingKey = await CryptoUtil.generateAsymmetricKey(); const signingKey = await CryptoUtil.generateAsymmetricKey();
const signingPublicKey = await CryptoUtil.exportKey(signingKey.publicKey) 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}); const pool = bench.initiateValidationPool(this.reputationPublicKey, {...options, signingPublicKey});
this.validationPools.set(pool.id, {signingPublicKey}); this.validationPools.set(pool.id, {signingPublicKey});
return pool; return pool;
@ -49,7 +49,7 @@ export class Member extends Actor {
this.validationPools.set(validationPool.id, {signingPublicKey}); this.validationPools.set(validationPool.id, {signingPublicKey});
// TODO: encrypt vote // TODO: encrypt vote
// TODO: sign message // 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); validationPool.castVote(signingPublicKey, position, stake, lockingTime);
} }

View File

@ -3,7 +3,7 @@ const params = {
stakeForWin: 0.5, // c2 stakeForWin: 0.5, // c2
// stakeForAuthor: 0.5, // c3 - For now we keep the default that stakeForAuthor = stakeForWin // stakeForAuthor: 0.5, // c3 - For now we keep the default that stakeForAuthor = stakeForWin
winningRatio: 0.5, // c4 winningRatio: 0.5, // c4
quorum: 0, // c5 quorum: 0.5, // c5
activeVoterThreshold: null, // c6 activeVoterThreshold: null, // c6
voteDuration: { // c7 voteDuration: { // c7
min: 0, min: 0,

View File

@ -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}`); throw new Error(`Duration must be in the range [${params.voteDuration.min}, ${params.voteDuration.max ?? 'Inf'}]; got ${duration}`);
} }
this.state = ValidationPoolStates.OPEN; this.state = ValidationPoolStates.OPEN;
this.setStatus("Open");
this.votes = new Map(); this.votes = new Map();
this.voters = new Map(); this.voters = new Map();
this.bench = bench; this.bench = bench;
@ -67,9 +68,17 @@ export class ValidationPool extends Actor {
// All voters have revealed their reputation public keys // All voters have revealed their reputation public keys
// Now we can evaluate winning conditions // Now we can evaluate winning conditions
this.state = ValidationPoolStates.CLOSED; this.state = ValidationPoolStates.CLOSED;
this.setStatus("Closed");
const result = this.evaluateWinningConditions(); const result = this.evaluateWinningConditions();
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.applyTokenLocking();
this.distributeTokens(result); this.distributeTokens(result);
}
this.deactivate(); this.deactivate();
} }
} }
@ -118,13 +127,7 @@ export class ValidationPool extends Actor {
const votePasses = upvoteValue >= params.winningRatio * downvoteValue; const votePasses = upvoteValue >= params.winningRatio * downvoteValue;
const quorumMet = upvoteValue + downvoteValue >= params.quorum * activeAvailableReputation; const quorumMet = upvoteValue + downvoteValue >= params.quorum * activeAvailableReputation;
// TODO: If quorum is not met, what should happen? return quorumMet ? votePasses : null;
if (!quorumMet) {
this.deactivate();
// console.log("Quorum is not met", {upvoteValue, downvoteValue, activeAvailableReputation});
throw new Error("Quorum is not met");
}
return votePasses && quorumMet;
} }
distributeTokens(result) { distributeTokens(result) {

View File

@ -36,21 +36,20 @@ await delay(1000);
await delay(1000); await delay(1000);
} }
// // Failure example: second member can not self-approve // Failure example: second member can not self-approve
// try { try {
// const pool = member2.initiateValidationPool(bench, {fee: 1, duration: 1000, tokenLossRatio: 1}); const pool = await member2.initiateValidationPool(bench, {fee: 1, duration: 1000, tokenLossRatio: 1});
// await member2.castVote(pool, true, 0, 0); await member2.revealIdentity(pool); // Quorum not met!
// await member2.revealIdentity(pool); // Quorum not met! await updateDisplayValues();
// await updateDisplayValues(); await delay(1000);
// await delay(1000); } catch(e) {
// } catch(e) { if (e.message.match(/Quorum is not met/)) {
// if (e.message.match(/Quorum is not met/)) { console.log("Caught expected error: Quorum not met")
// console.log("Caught expected error: Quorum not met") } else {
// } else { console.error("Unexpected error")
// console.error("Unexpected error") throw e;
// throw e; }
// } }
// }
// Second member must be approved by first member // Second member must be approved by first member
{ {