-
Notifications
You must be signed in to change notification settings - Fork 212
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: publish vote results from the voteCounter #6204
Changes from 2 commits
67a1340
ef87a2f
e93c279
e67ab9b
f14f06d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ | |
import { Far } from '@endo/marshal'; | ||
import { makePromiseKit } from '@endo/promise-kit'; | ||
import { makeHeapFarInstance, keyEQ, makeStore } from '@agoric/store'; | ||
import { E } from '@endo/eventual-send'; | ||
|
||
import { | ||
buildUnrankedQuestion, | ||
|
@@ -53,7 +54,12 @@ const validateBinaryQuestionSpec = questionSpec => { | |
// independently. The standard Zoe start function is at the bottom of this file. | ||
|
||
/** @type {BuildVoteCounter} */ | ||
const makeBinaryVoteCounter = (questionSpec, threshold, instance) => { | ||
const makeBinaryVoteCounter = ( | ||
questionSpec, | ||
threshold, | ||
instance, | ||
publisher, | ||
) => { | ||
validateBinaryQuestionSpec(questionSpec); | ||
|
||
const question = buildUnrankedQuestion(questionSpec, instance); | ||
|
@@ -113,6 +119,12 @@ const makeBinaryVoteCounter = (questionSpec, threshold, instance) => { | |
|
||
if (!makeQuorumCounter(threshold).check(stats)) { | ||
outcomePromise.reject('No quorum'); | ||
const voteOutcome = { | ||
question: details.questionHandle, | ||
outcome: 'No quorum', | ||
}; | ||
// @ts-expect-error Expand type to allow non-position? | ||
E(publisher).publish(voteOutcome); | ||
return; | ||
} | ||
|
||
|
@@ -123,6 +135,12 @@ const makeBinaryVoteCounter = (questionSpec, threshold, instance) => { | |
} else { | ||
outcomePromise.resolve(questionSpec.tieOutcome); | ||
} | ||
|
||
// XXX if we should distinguish ties, publish should be called in if above | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This would be good too but I don't object to leaving this tech debt for later. If you want to do it now, e93c279 shows how. |
||
E.when(outcomePromise.promise, outcome => { | ||
const voteOutcome = { question: details.questionHandle, outcome }; | ||
return E(publisher).publish(voteOutcome); | ||
}); | ||
}; | ||
|
||
const closeFacet = makeHeapFarInstance( | ||
|
@@ -198,7 +216,7 @@ const makeBinaryVoteCounter = (questionSpec, threshold, instance) => { | |
/** | ||
* @type {ContractStartFn<VoteCounterPublicFacet, VoteCounterCreatorFacet, {questionSpec: QuestionSpec, quorumThreshold: bigint}>} | ||
*/ | ||
const start = zcf => { | ||
const start = (zcf, { outcomesPublisher }) => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Practically every publisher publishes more than once so the "s" plurality for that isn't informative. What is informative is what each thing they publish is. (That helps to distinguish from when each publication is not unary.) In this case, |
||
// There are a variety of ways of counting quorums. The parameters must be | ||
// visible in the terms. We're doing a simple threshold here. If we wanted to | ||
// discount abstentions, we could refactor to provide the quorumCounter as a | ||
|
@@ -210,6 +228,7 @@ const start = zcf => { | |
questionSpec, | ||
quorumThreshold, | ||
zcf.getInstance(), | ||
outcomesPublisher, | ||
); | ||
|
||
scheduleClose(questionSpec.closingRule, () => closeFacet.closeVoting()); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -43,12 +43,12 @@ const start = (zcf, privateArgs) => { | |
const allQuestions = makeStore('Question'); | ||
assert(privateArgs?.storageNode, 'Missing storageNode'); | ||
assert(privateArgs?.marshaller, 'Missing marshaller'); | ||
const questionNode = E(privateArgs.storageNode).makeChildNode( | ||
'latestQuestion', | ||
); | ||
/** @type {StoredPublishKit<QuestionDetails>} */ | ||
const { subscriber: questionsSubscriber, publisher: questionsPublisher } = | ||
makeStoredPublishKit( | ||
E(privateArgs.storageNode).makeChildNode('latestQuestion'), | ||
privateArgs.marshaller, | ||
); | ||
makeStoredPublishKit(questionNode, privateArgs.marshaller); | ||
|
||
const makeCommitteeVoterInvitation = index => { | ||
/** @type {OfferHandler} */ | ||
|
@@ -158,13 +158,24 @@ const start = (zcf, privateArgs) => { | |
} | ||
}; | ||
|
||
const outcomeNode = E(privateArgs.storageNode).makeChildNode( | ||
'latestOutcome', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. a little hesitant to have a node for each of these but feels right to error on the side of more nodes so we don't create backwards compatibility problems for any nodes with broader responsibilities. |
||
); | ||
|
||
/** @type {StoredPublishKit<{question: Handle<'Question'>,outcome: Position}>} */ | ||
const { publisher: outcomesPublisher } = makeStoredPublishKit( | ||
outcomeNode, | ||
privateArgs.marshaller, | ||
); | ||
|
||
return startCounter( | ||
zcf, | ||
questionSpec, | ||
quorumThreshold(questionSpec.quorumRule), | ||
voteCounter, | ||
allQuestions, | ||
questionsPublisher, | ||
outcomesPublisher, | ||
); | ||
}, | ||
getVoterInvitations() { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, we should. I pushed e93c279