From e777a0ee854ad012ee0b8855c5371aaf5bcaa072 Mon Sep 17 00:00:00 2001 From: Ladd Hoffman Date: Sun, 8 Jan 2023 20:28:54 -0600 Subject: [PATCH] Fixup, distribute rewards to voters --- forum-network/src/classes/forum.js | 4 +--- forum-network/src/classes/validation-pool.js | 13 +++++++++---- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/forum-network/src/classes/forum.js b/forum-network/src/classes/forum.js index 9b14e3d..dedaded 100644 --- a/forum-network/src/classes/forum.js +++ b/forum-network/src/classes/forum.js @@ -84,8 +84,6 @@ export class Forum extends Actor { const post = this.getPost(postId); post.setStatus('Validated'); const rewards = await this.propagateValue(pool, post, initialValue); - const totalRewards = Array.from(rewards.values()).reduce((total, value) => total += value, 0); - console.log('total awards from forum:', totalRewards); // Apply computed rewards for (const [id, value] of rewards) { bench.reputations.addTokens(id, value); @@ -114,7 +112,7 @@ export class Forum extends Actor { await this.setPostValue(post, post.value + adjustedIncrement); // Award reputation to post author - console.log('reward for post author', post.authorPublicKey, adjustedIncrement); + console.log(`reward for post author ${post.authorPublicKey}`, adjustedIncrement); addReward(post.authorPublicKey, adjustedIncrement); // Recursively distribute reputation to citations, according to weights diff --git a/forum-network/src/classes/validation-pool.js b/forum-network/src/classes/validation-pool.js index ecbed93..ff13f39 100644 --- a/forum-network/src/classes/validation-pool.js +++ b/forum-network/src/classes/validation-pool.js @@ -230,14 +230,19 @@ export class ValidationPool extends Actor { const { reputationPublicKey } = this.voters.get(signingPublicKey); const reward = (tokensForWinners * stake) / getTotalStaked(votePasses); rewards.set(reputationPublicKey, reward); - console.log(`reward for winning voter ${reputationPublicKey}:`, reward); } - const awardsFromVoting = Array.from(rewards.values()).reduce((total, value) => total += value, 0); - console.log('total awards from voting:', awardsFromVoting); + const authorReputationPublicKey = this.voters.get(this.authorSigningPublicKey).reputationPublicKey; + // Distribute awards to voters other than the author + for (const [id, value] of rewards) { + if (id !== authorReputationPublicKey) { + this.bench.reputations.addTokens(id, value); + console.log(`reward for winning voter ${id}:`, value); + } + } if (votePasses) { - const authorReputationPublicKey = this.voters.get(this.authorSigningPublicKey).reputationPublicKey; + // Distribute awards to author via the forum const tokensForAuthor = this.tokensMinted * params.stakeForAuthor + rewards.get(authorReputationPublicKey); if (votePasses && !!this.forum) {