From ab63ad1868d726807f438bc5ab174948f3b5a3ba Mon Sep 17 00:00:00 2001 From: Ladd Hoffman Date: Mon, 30 Jan 2023 20:30:05 -0600 Subject: [PATCH] Cleanup related to forum network test Also misc minor stub additions --- forum-network/notes/classes.md | 43 ++++++++++++ forum-network/src/classes/block-consensus.js | 3 + forum-network/src/classes/expert.js | 2 +- forum-network/src/classes/forum-node.js | 14 ++-- forum-network/src/classes/forum-view.js | 63 ------------------ forum-network/src/classes/forum.js | 4 +- forum-network/src/classes/storage.js | 0 .../src/tests/forum-network.test.html | 66 +------------------ forum-network/src/tests/reputation.test.html | 6 +- .../src/tests/scripts/forum-network.test.js | 59 +++++++++++++++++ 10 files changed, 119 insertions(+), 141 deletions(-) create mode 100644 forum-network/notes/classes.md create mode 100644 forum-network/src/classes/block-consensus.js create mode 100644 forum-network/src/classes/storage.js create mode 100644 forum-network/src/tests/scripts/forum-network.test.js diff --git a/forum-network/notes/classes.md b/forum-network/notes/classes.md new file mode 100644 index 0000000..36cb19d --- /dev/null +++ b/forum-network/notes/classes.md @@ -0,0 +1,43 @@ +# Primary + +## Forum + +## ValidationPool + +## ReputationToken + +## WDAG + +# Secondary + +## Availability + +## Business + +## ERC721 + +## Expert + +## Bench + +# Tertiary + +## Actor + +## Action + +## Scene + +# To Explore + +## Exchange + +## Storage + +## Network + +## Wallet + +## Agent/UI + +## BlockConsensus diff --git a/forum-network/src/classes/block-consensus.js b/forum-network/src/classes/block-consensus.js new file mode 100644 index 0000000..966f4a9 --- /dev/null +++ b/forum-network/src/classes/block-consensus.js @@ -0,0 +1,3 @@ +export class BlockConsensus { + +} diff --git a/forum-network/src/classes/expert.js b/forum-network/src/classes/expert.js index 10781a1..a30f692 100644 --- a/forum-network/src/classes/expert.js +++ b/forum-network/src/classes/expert.js @@ -31,7 +31,7 @@ export class Expert extends ReputationHolder { // TODO: Include fee const postMessage = new PostMessage({ post, stake }); await postMessage.sign(this.reputationKey); - await this.actions.submitPostViaNetwork.log(this, forumNode, null, { id: post.id }); + await this.actions.submitPostViaNetwork.log(this, forumNode); // For now, directly call forumNode.receiveMessage(); await forumNode.receiveMessage(JSON.stringify(postMessage.toJSON())); } diff --git a/forum-network/src/classes/forum-node.js b/forum-network/src/classes/forum-node.js index bfca521..67008d3 100644 --- a/forum-network/src/classes/forum-node.js +++ b/forum-network/src/classes/forum-node.js @@ -34,7 +34,8 @@ export class ForumNode extends Actor { .filter((forumNode) => forumNode.keyPair.publicKey !== this.keyPair.publicKey); for (const forumNode of otherForumNodes) { // For now just call receiveMessage on the target node - await this.actions.peerMessage.log(this, forumNode, null, message.content); + // await this.actions.peerMessage.log(this, forumNode, null, message.content); + await this.actions.peerMessage.log(this, forumNode); await forumNode.receiveMessage(JSON.stringify(message.toJSON())); } } @@ -61,14 +62,13 @@ export class ForumNode extends Actor { try { await Message.verify(messageJson); } catch (e) { - await this.actions.processMessage.log(this, this, 'invalid signature', messageJson, '-x'); + await this.actions.processMessage.log(this, this, 'invalid signature', null, '-x'); console.log(`${this.name}: received message with invalid signature`); return; } const { publicKey } = messageJson; const message = messageFromJSON(messageJson); - console.log(`${this.name}: processMessage`, message); if (message instanceof PostMessage) { await this.processPostMessage(publicKey, message.content); @@ -77,18 +77,16 @@ export class ForumNode extends Actor { } else { // Unknown message type // Penalize sender for wasting our time - console.log(`${this.name}: penalizing sender for unknown message type ${message.type}`); - this.forumView.incrementReputation(message.publicKey, -1); } } // Process an incoming post, received by whatever means - async processPost(authorId, post, stake) { + async processPost(authorId, post) { if (!post.id) { post.id = CryptoUtil.randomUUID(); } - await this.actions.storePost.log(this, this, null, { authorId, post, stake }); - this.forumView.addPost(authorId, post.id, post, stake); + await this.actions.storePost.log(this, this); + // this.forumView.addPost(authorId, post.id, post, stake); } // Process a post we received in a message diff --git a/forum-network/src/classes/forum-view.js b/forum-network/src/classes/forum-view.js index 3c67def..709e944 100644 --- a/forum-network/src/classes/forum-view.js +++ b/forum-network/src/classes/forum-view.js @@ -51,12 +51,10 @@ export class ForumView { const { citations = [], content } = postContent; const author = this.getOrInitializeAuthor(authorId); const postVertex = new PostVertex(postId, author, stake, content, citations); - console.log('addPost', { id: postId, postContent }); this.posts.addVertex(postId, postVertex); for (const { postId: citedPostId, weight } of citations) { this.posts.addEdge('citation', postId, citedPostId, weight); } - this.applyNonbindingReputationEffects(postVertex); } getPost(postId) { @@ -66,65 +64,4 @@ export class ForumView { getPosts() { return this.posts.getVertices(); } - - // We'll start with naieve implementations of the computations we need. - - // We want to derive a value -- maybe call it a reputation score -- for each post. - // This value is a recursive sum of contributions from citations. - - // There should be a diminishment of effect upon each recursion, - // perhaps following a geometric progression. - - // Each post gets some initial score due to the reputation that the author stakes. - - // Citations are weighted, and can be positive or negative. - - // So each post has a reputation score. Each author also has a reputation score. - // The value of the author's reputation score could be a factor in the magnitude of the effects of their citations. - // Post_rep = (Author_rep * stake); - // - - // Options: - // - update a state model incrementally with each action in the history (/unfolding present) of the forum, - // in order to arrive at the current view. - - // When an author stakes reputation on a post, if it's a non-binding stake, then it merely expresses opinion. - // If it's a binding stake, then they may lose the staked reputation as a result of other posts - // staking reputation against theirs. - - citationFraction = 0.3; - - applyNonbindingReputationEffects(newPost) { - this.distributeNonbindingReputation(newPost, newPost, newPost.stake); - } - - distributeNonbindingReputation(newPost, post, amount, depth = 0) { - console.log('distributeNonbindingReputation', { post, amount, depth }); - // Some of the incoming reputation goes to this post - post.reputation += amount * (1 - this.citationFraction); - this.setReputation(post.id, post.reputation); - // Some of the incoming reputation gets distributed among cited posts - const distributeAmongCitations = amount * this.citationFraction; - - // citation weights can be interpreted as a ratio, or we can somehow constrain the input - // to add up to some specified total. - // It's easy enough to let them be on any arbitrary scale and just compute the ratios here. - const totalWeight = post.citations - ?.map(({ weight }) => weight) - .reduce((acc, cur) => (acc += cur), 0); - - post.citations?.forEach((citation) => { - const citedPost = this.getPost(citation.postId); - if (!citedPost) { - // TODO: Here is where we may want to engage our peer protocol to query for possible missing records - throw new Error(`Post ${post.postId} cites unknown post ${citation.postId}`); - } - this.distributeNonbindingReputation( - newPost, - citedPost, - (citation.weight / totalWeight) * distributeAmongCitations, - depth + 1, - ); - }); - } } diff --git a/forum-network/src/classes/forum.js b/forum-network/src/classes/forum.js index c2081b4..d1b1dbf 100644 --- a/forum-network/src/classes/forum.js +++ b/forum-network/src/classes/forum.js @@ -34,8 +34,8 @@ class Post extends Actor { throw new Error('Post donation total exceeds revaluation limit ' + `(${donationTotal} > ${params.revaluationLimit})`); } - if (this.citations.some(({ weight }) => Math.abs(weight) > 1)) { - throw new Error('Each citation weight must be in the range [-1, 1]'); + if (this.citations.some(({ weight }) => Math.abs(weight) > params.revaluationLimit)) { + throw new Error(`Each citation magnitude must not exceed revaluation limit ${params.revaluationLimit}`); } } diff --git a/forum-network/src/classes/storage.js b/forum-network/src/classes/storage.js new file mode 100644 index 0000000..e69de29 diff --git a/forum-network/src/tests/forum-network.test.html b/forum-network/src/tests/forum-network.test.html index 307aead..f2a994b 100644 --- a/forum-network/src/tests/forum-network.test.html +++ b/forum-network/src/tests/forum-network.test.html @@ -4,68 +4,6 @@ -
+
- + diff --git a/forum-network/src/tests/reputation.test.html b/forum-network/src/tests/reputation.test.html index e55d4d3..fb87fdf 100644 --- a/forum-network/src/tests/reputation.test.html +++ b/forum-network/src/tests/reputation.test.html @@ -4,7 +4,7 @@ -
+