Merge branch 'dev' into 'main'

Add special case: Incineration

See merge request dao-governance-framework/science-publishing-dao!4
This commit is contained in:
Ladd Hoffman 2023-03-15 02:19:44 +00:00
commit 5ca884686b
15 changed files with 289 additions and 30 deletions

View File

@ -10,3 +10,11 @@ Effective power can be considered as a flow rate of posts; (value per post) / (d
Internal energy is similar to Forum total value / DAO total reputation
Total available reputation is similar to thermodynamic free energy
---
Examples to add:
- Incinerator
- Negatively cite a zero-value post -- intent is to show how governance might cite a post as a counter-example

View File

@ -0,0 +1,9 @@
Matrix is a communications network.
It has a client-server, server-server decentralized architecture.
Rooms are synced (eventually consistent) among all servers with clients participating in the room.
Matrix supports "Application Services", which are limited to funcion in a passive mode, meaning they only piggyback on top of the existing protocols.
Synapse, a Matrix server implementation, supports "Modules"
The Matrix devs recognize the need for a robust reputation system and are in pursuit of funding and development for that purpose.

View File

@ -3,7 +3,7 @@ import { Action } from '../display/action.js';
import { Actor } from '../display/actor.js';
import params from '../../params.js';
import { ReputationHolder } from '../reputation/reputation-holder.js';
import { displayNumber, EPSILON } from '../../util.js';
import { displayNumber, EPSILON, INCINERATOR_ADDRESS } from '../../util.js';
const CITATION = 'citation';
const BALANCE = 'balance';
@ -70,9 +70,14 @@ export class Forum extends ReputationHolder {
}
async addPost(authorId, postContent) {
console.log('addPost', { authorId, postContent });
const post = new Post(this, authorId, postContent);
this.posts.addVertex(post.id, post, post.getLabel());
for (const { postId: citedPostId, weight } of post.citations) {
// Special case: Incinerator
if (citedPostId === INCINERATOR_ADDRESS && !this.posts.getVertex(INCINERATOR_ADDRESS)) {
this.posts.addVertex(INCINERATOR_ADDRESS, { name: 'Incinerator' }, 'Incinerator');
}
this.posts.addEdge(CITATION, post.id, citedPostId, weight);
}
return post;
@ -171,22 +176,44 @@ export class Forum extends ReputationHolder {
for (const citationEdge of citationEdges) {
const { weight } = citationEdge;
let outboundAmount = weight * increment;
if (Math.abs(outboundAmount) > EPSILON) {
const balanceToOutbound = this.posts.getEdgeWeight(BALANCE, citationEdge.from, citationEdge.to) ?? 0;
let refundFromOutbound = 0;
// Special case: Incineration.
if (citationEdge.to.id === INCINERATOR_ADDRESS) {
// Only a positive amount may be incinerated! Otherwise the sink could be used as a source.
if (outboundAmount < 0) {
this.scene?.flowchart?.log(`style ${citationEdge.from.id} fill:#620000`);
throw new Error('Incinerator can only receive positive citations!');
}
// Reputation sent to the incinerator is burned! This means it is deducted from the sender,
// without increasing the value of any other token.
this.actions.propagate.log(citationEdge.from.data, { name: 'Incinerator' }, `(${increment})`);
} else {
// We need to ensure that we at most undo the prior effects of this post
if (initialNegative) {
outboundAmount = outboundAmount < 0
? Math.max(outboundAmount, -balanceToOutbound)
: Math.min(outboundAmount, -balanceToOutbound);
}
if (Math.abs(outboundAmount) > EPSILON) {
const refundFromOutbound = await this.propagateValue(citationEdge, {
// Recursively propagate reputation effects
refundFromOutbound = await this.propagateValue(citationEdge, {
rewardsAccumulator,
increment: outboundAmount,
depth: depth + 1,
initialNegative: initialNegative || (depth === 0 && outboundAmount < 0),
});
// Any excess (negative) amount that could not be propagated,
// i.e. because a cited post has been reduced to zero value,
// is retained by the citing post.
outboundAmount -= refundFromOutbound;
}
// Keep a record of the effect of the reputation transferred along this edge in the graph,
// so that later, negative citations can be constrained to at most undo these effects.
this.posts.setEdgeWeight(BALANCE, citationEdge.from, citationEdge.to, balanceToOutbound + outboundAmount);
totalOutboundAmount += outboundAmount;

View File

@ -54,8 +54,7 @@ export class ValidationPool extends ReputationHolder {
|| [null, undefined].includes(duration)
) {
throw new Error(
`Duration must be in the range [${params.voteDuration.min}, ${
params.voteDuration.max ?? 'Inf'
`Duration must be in the range [${params.voteDuration.min}, ${params.voteDuration.max ?? 'Inf'
}]; got ${duration}`,
);
}

View File

@ -21,6 +21,9 @@
<li><a href="./tests/forum4.test.html">Redistribute power through subsequent support</a></li>
<li><a href="./tests/forum5.test.html">Destroy a post after it has received positive citations</a></li>
<li><a href="./tests/forum6.test.html">Initially zero-valued posts later receive citations</a></li>
<li><a href="./tests/forum7.test.html">Negatively cite a zero-valued post</a></li>
<li><a href="./tests/forum8.test.html">Incinerate reputation</a></li>
<li><a href="./tests/forum9.test.html">Use incineration to achieve more balanced reweighting</a></li>
</ol>
</ul>
<ul>

View File

@ -33,6 +33,9 @@
<script type="module" src="./scripts/forum/forum4.test.js"></script>
<script type="module" src="./scripts/forum/forum5.test.js"></script>
<script type="module" src="./scripts/forum/forum6.test.js"></script>
<script type="module" src="./scripts/forum/forum7.test.js"></script>
<script type="module" src="./scripts/forum/forum8.test.js"></script>
<script type="module" src="./scripts/forum/forum9.test.js"></script>
<script defer class="mocha-init">
mocha.setup({
ui: 'bdd',

View File

@ -0,0 +1,26 @@
<!DOCTYPE html>
<head>
<title>Forum test 7</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="stylesheet" href="https://unpkg.com/mocha/mocha.css" />
<link type="text/css" rel="stylesheet" href="../index.css" />
</head>
<body>
<h2><a href="../">DGF Tests</a></h2>
<div id="mocha"></div>
<div id="scene"></div>
</body>
<script src="https://cdnjs.cloudflare.com/ajax/libs/radash/10.7.0/radash.js"
integrity="sha512-S207zKWG3iqXqe6msO7/Mr8X3DzzF4u8meFlokHjGtBPTGUhgzVo0lpcqEy0GoiMUdcoct+H+SqzoLsxXbynzg=="
crossorigin="anonymous" referrerpolicy="no-referrer"></script>
<script src="https://unpkg.com/mocha/mocha.js"></script>
<script src="https://unpkg.com/chai/chai.js"></script>
<script type="module" src="./scripts/forum/forum7.test.js"></script>
<script defer class="mocha-init">
mocha.setup({
ui: 'bdd',
});
chai.should();
</script>

View File

@ -0,0 +1,26 @@
<!DOCTYPE html>
<head>
<title>Forum test 8</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="stylesheet" href="https://unpkg.com/mocha/mocha.css" />
<link type="text/css" rel="stylesheet" href="../index.css" />
</head>
<body>
<h2><a href="../">DGF Tests</a></h2>
<div id="mocha"></div>
<div id="scene"></div>
</body>
<script src="https://cdnjs.cloudflare.com/ajax/libs/radash/10.7.0/radash.js"
integrity="sha512-S207zKWG3iqXqe6msO7/Mr8X3DzzF4u8meFlokHjGtBPTGUhgzVo0lpcqEy0GoiMUdcoct+H+SqzoLsxXbynzg=="
crossorigin="anonymous" referrerpolicy="no-referrer"></script>
<script src="https://unpkg.com/mocha/mocha.js"></script>
<script src="https://unpkg.com/chai/chai.js"></script>
<script type="module" src="./scripts/forum/forum8.test.js"></script>
<script defer class="mocha-init">
mocha.setup({
ui: 'bdd',
});
chai.should();
</script>

View File

@ -0,0 +1,26 @@
<!DOCTYPE html>
<head>
<title>Forum test 9</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="stylesheet" href="https://unpkg.com/mocha/mocha.css" />
<link type="text/css" rel="stylesheet" href="../index.css" />
</head>
<body>
<h2><a href="../">DGF Tests</a></h2>
<div id="mocha"></div>
<div id="scene"></div>
</body>
<script src="https://cdnjs.cloudflare.com/ajax/libs/radash/10.7.0/radash.js"
integrity="sha512-S207zKWG3iqXqe6msO7/Mr8X3DzzF4u8meFlokHjGtBPTGUhgzVo0lpcqEy0GoiMUdcoct+H+SqzoLsxXbynzg=="
crossorigin="anonymous" referrerpolicy="no-referrer"></script>
<script src="https://unpkg.com/mocha/mocha.js"></script>
<script src="https://unpkg.com/chai/chai.js"></script>
<script type="module" src="./scripts/forum/forum9.test.js"></script>
<script defer class="mocha-init">
mocha.setup({
ui: 'bdd',
});
chai.should();
</script>

View File

@ -19,9 +19,9 @@ describe('Forum', function tests() {
it('Post2', async () => {
const { forum, experts, posts } = forumTest;
await forumTest.addPost(experts[0], 10);
await forumTest.addPost(experts[0], 0);
forum.getPost(posts[0]).value.should.equal(10);
forum.getPost(posts[1]).value.should.equal(10);
forum.getPost(posts[1]).value.should.equal(0);
});
it('Post3 cites Post2 and negatively cites Post1', async () => {
@ -31,7 +31,7 @@ describe('Forum', function tests() {
{ postId: posts[1], weight: 1 },
]);
forum.getPost(posts[0]).value.should.equal(0);
forum.getPost(posts[1]).value.should.equal(30);
forum.getPost(posts[1]).value.should.equal(20);
forum.getPost(posts[2]).value.should.equal(0);
});
});

View File

@ -10,7 +10,7 @@ describe('Forum', function tests() {
await forumTest.setup();
});
context('Initially zero-valued post later receives citations', async () => {
context('Negatively citing a zero-valued post', async () => {
let forum;
let experts;
let posts;
@ -66,11 +66,4 @@ describe('Forum', function tests() {
});
});
// await addPost(experts[0], 10);
// await addPost(experts[0], 10, [{ postId: posts[3], weight: -1 }]);
// await addPost(experts[0], 10, [{ postId: posts[4], weight: -1 }]);
// await addPost(expert3, 'Post 4', 100, [{ postId: postId2, weight: -1 }]);
// await addPost(expert1, 'Post 5', 100, [{ postId: postId3, weight: -1 }]);
mochaRun();

View File

@ -0,0 +1,39 @@
import { mochaRun } from '../../../util.js';
import { ForumTest } from './forum.test-util.js';
describe('Forum', function tests() {
this.timeout(0);
const forumTest = new ForumTest();
before(async () => {
await forumTest.setup();
});
context('Initially zero-valued post later receives citations', async () => {
let forum;
let experts;
let posts;
before(() => {
forum = forumTest.forum;
experts = forumTest.experts;
posts = forumTest.posts;
});
it('Post1 has zero value', async () => {
await forumTest.addPost(experts[0], 0);
forum.getPost(posts[0]).value.should.equal(0);
});
it('Post2 negatively cites Post1', async () => {
await forumTest.addPost(experts[0], 10, [
{ postId: posts[0], weight: -1 },
]);
forum.getPost(posts[0]).value.should.equal(0);
forum.getPost(posts[1]).value.should.equal(10);
});
});
});
mochaRun();

View File

@ -0,0 +1,50 @@
import { INCINERATOR_ADDRESS, mochaRun } from '../../../util.js';
import { ForumTest } from './forum.test-util.js';
describe('Forum', function tests() {
this.timeout(0);
const forumTest = new ForumTest();
before(async () => {
await forumTest.setup();
});
context('Incinerate reputation', async () => {
let forum;
let experts;
let posts;
before(() => {
forum = forumTest.forum;
experts = forumTest.experts;
posts = forumTest.posts;
});
it('Post1', async () => {
await forumTest.addPost(experts[0], 10);
forum.getPost(posts[0]).value.should.equal(10);
});
it('Post2 burns reputation from Post1', async () => {
await forumTest.addPost(experts[0], 10, [
{ postId: posts[0], weight: -1 },
{ postId: INCINERATOR_ADDRESS, weight: 1 },
]);
forum.getPost(posts[0]).value.should.equal(0);
forum.getPost(posts[1]).value.should.equal(0);
});
it('Reputation can not be sourced from the incinerator', async () => {
try {
await forumTest.addPost(experts[0], 10, [
{ postId: INCINERATOR_ADDRESS, weight: -1 },
]);
} catch (e) {
e.message.should.match(/Incinerator can only receive positive citations/);
}
});
});
});
mochaRun();

View File

@ -0,0 +1,48 @@
import { INCINERATOR_ADDRESS, mochaRun } from '../../../util.js';
import { ForumTest } from './forum.test-util.js';
describe('Forum', function tests() {
this.timeout(0);
const forumTest = new ForumTest();
before(async () => {
await forumTest.setup();
});
context('Use incineration to achieve more balanced reweighting', async () => {
let forum;
let experts;
let posts;
before(() => {
forum = forumTest.forum;
experts = forumTest.experts;
posts = forumTest.posts;
});
it('Post1', async () => {
await forumTest.addPost(experts[0], 10);
forum.getPost(posts[0]).value.should.equal(10);
});
it('Post2', async () => {
await forumTest.addPost(experts[0], 0);
forum.getPost(posts[0]).value.should.equal(10);
forum.getPost(posts[1]).value.should.equal(0);
});
it('Post3 transfers reputation from Post1 to Post2', async () => {
await forumTest.addPost(experts[0], 10, [
{ postId: posts[0], weight: -1 },
{ postId: posts[1], weight: 0.5 },
{ postId: INCINERATOR_ADDRESS, weight: 0.5 },
]);
forum.getPost(posts[0]).value.should.equal(0);
forum.getPost(posts[1]).value.should.equal(10);
forum.getPost(posts[2]).value.should.equal(0);
});
});
});
mochaRun();

View File

@ -4,6 +4,8 @@ const timers = new Map();
export const EPSILON = 2.23e-16;
export const INCINERATOR_ADDRESS = 0;
export const debounce = async (fn, delayMs) => {
const timer = timers.get(fn);
if (timer) {