Documentation ¶
Index ¶
- Constants
- Variables
- func OpinionCaller(handler interface{}, params ...interface{})
- func RoundStatsCaller(handler interface{}, params ...interface{})
- type Context
- func (vc *Context) AddOpinion(opn opinion.Opinion)
- func (vc *Context) HadFirstRound() bool
- func (vc *Context) HadFixedRound(coolingOffPeriod, totalRoundsFinalization, totalRoundsFixedThreshold int) bool
- func (vc *Context) IsFinalized(coolingOffPeriod, totalRoundsFinalization int) bool
- func (vc *Context) IsNew() bool
- func (vc *Context) LastOpinion() opinion.Opinion
- type DRNGRoundBasedVoter
- type Events
- type ObjectType
- type OpinionEvent
- type RoundStats
- type Voter
- type VotingWeights
Constants ¶
const ( // ConflictType defines an object type conflict. ConflictType = iota // TimestampType defines an object type timestamp. TimestampType )
Variables ¶
var ErrVotingNotFound = errors.New("no voting found")
ErrVotingNotFound is returned when a voting for a given id wasn't found.
Functions ¶
func OpinionCaller ¶
func OpinionCaller(handler interface{}, params ...interface{})
OpinionCaller calls the given handler with an OpinionEvent (containing its opinions, its associated ID and context).
func RoundStatsCaller ¶
func RoundStatsCaller(handler interface{}, params ...interface{})
RoundStatsCaller calls the given handler with a RoundStats.
Types ¶
type Context ¶
type Context struct { ID string Type ObjectType // The percentage of OpinionGivers who liked this item on the last query. ProportionLiked float64 // The number of voting rounds performed. Rounds int // Append-only list of opinions formed after each round. // the first opinion is the initial opinion when this vote context was created. Opinions []opinion.Opinion // Weights used for voting Weights VotingWeights }
Context is the context of votes from multiple rounds about a given item.
func NewContext ¶
func NewContext(id string, objectType ObjectType, initOpn opinion.Opinion) *Context
NewContext creates a new vote context.
func (*Context) AddOpinion ¶
AddOpinion adds the given opinion to this vote context.
func (*Context) HadFirstRound ¶
HadFirstRound tells whether the vote context just had its first round.
func (*Context) HadFixedRound ¶ added in v0.5.5
func (vc *Context) HadFixedRound(coolingOffPeriod, totalRoundsFinalization, totalRoundsFixedThreshold int) bool
HadFixedRound tells whether the vote context is in the last l2 rounds of fixed threshold
func (*Context) IsFinalized ¶
IsFinalized tells whether this vote context is finalized by checking whether the opinion was held for totalRoundsFinalization number of rounds.
func (*Context) LastOpinion ¶
LastOpinion returns the last formed opinion.
type DRNGRoundBasedVoter ¶
type DRNGRoundBasedVoter interface { Voter // Round starts a new round. Round(rand float64, delayedRoundStart ...time.Duration) error }
DRNGRoundBasedVoter is a Voter which votes in rounds and uses random numbers which were generated in a decentralized fashion.
type Events ¶
type Events struct { // Fired when an Opinion has been finalized. Finalized *events.Event // Fired when an Opinion couldn't be finalized. Failed *events.Event // Fired when a DRNGRoundBasedVoter has executed a round. RoundExecuted *events.Event // Fired when internal errors occur. Error *events.Event }
Events defines events which happen on a Voter.
type ObjectType ¶ added in v0.3.2
type ObjectType uint8
ObjectType is the object type of a voting (e.g., conflict or timestamp)
type OpinionEvent ¶
type OpinionEvent struct { // ID is the of the conflict. ID string // Opinion is an opinion about a conflict. Opinion opinion.Opinion // Ctx contains all relevant infos regarding the conflict. Ctx Context }
OpinionEvent is the struct containing data to be passed around with Finalized and Failed events.
type RoundStats ¶
type RoundStats struct { // The time it took to complete a round. Duration time.Duration `json:"duration"` // The rand number used during the round. RandUsed float64 `json:"rand_used"` // The vote contexts on which opinions were formed and queried. // This list does not include the vote contexts which were finalized/aborted // during the execution of the round. // Create a copy of this map if you need to modify any of its elements. ActiveVoteContexts map[string]*Context `json:"active_vote_contexts"` // The opinions which were queried during the round per opinion giver. QueriedOpinions []opinion.QueriedOpinions `json:"queried_opinions"` }
RoundStats encapsulates data about an executed round.
type Voter ¶
type Voter interface { // Vote submits the given ID for voting with its initial Opinion. Vote(id string, objectType ObjectType, initOpn opinion.Opinion) error // IntermediateOpinion gets intermediate Opinion about the given ID. IntermediateOpinion(id string) (opinion.Opinion, error) // Events returns the Events instance of the given Voter. Events() Events }
Voter votes on hashes.
type VotingWeights ¶ added in v0.5.5
type VotingWeights struct { // Total base mana of opinion givers from the last query TotalWeights float64 // Own mana from the last query OwnWeight float64 }
VotingWeights stores parameters used for weighted voting calculation