repv2

package
v0.6.11 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 3, 2020 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// Inherited from testnet, the unit of 1 reputation is one coin
	// of testnet, which is 10^(-5) * 0.012 USD.
	// Caller need to convert the amount of donation to the number of test coins.
	DefaultRoundDurationSeconds = 25 * 3600 // how many seconds does a round last, default: 25 hours
	DefaultSampleWindowSize     = 10        // how many rounds are used to sample out user's customer score.
	DefaultDecayFactor          = 10        // reputation decay factor %.

	// Initial and minimum score is 10^(-5), one coin.
	DefaultInitialReputation = 1
)

Variables

View Source
var (
	KeySeparator = byte('/')
)

Functions

func IntGTE

func IntGTE(a, b Int) bool

func IntGreater

func IntGreater(a, b Int) bool

func IntLess

func IntLess(a, b Int) bool

func PrefixEndBytes

func PrefixEndBytes(prefix []byte) []byte

PrefixEndBytes returns the []byte that would end a range query for all []byte with a certain prefix Deals with last byte of prefix being FF without overflowing

Types

type Donation

type Donation struct {
	Pid    Pid      `json:"p"`
	Amount LinoCoin `json:"a"`
	Impact IF       `json:"i"`
}

merged donation, used in userUnsettled.

type IF

type IF = bigInt // Impact factor

type Int

type Int struct {
	*big.Int
}

func IntAdd

func IntAdd(a, b Int) Int

func IntDiv

func IntDiv(a, b Int) Int

func IntDivFrac

func IntDivFrac(v Int, num, denom int64) Int

return v / (num / denom)

func IntEMA

func IntEMA(prev, new Int, windowSize int64) Int

return the exponential moving average of @p prev on having a new sample @p new with sample size of @p windowSize.

func IntMax

func IntMax(a, b Int) Int

a bunch of helper functions that takes two bitInt and returns a newly allocated bigInt.

func IntMin

func IntMin(a, b Int) Int

func IntMul

func IntMul(a, b Int) Int

func IntMulFrac

func IntMulFrac(v Int, num, denom int64) Int

return v * (num / denom)

func IntSub

func IntSub(a, b Int) Int

func NewInt

func NewInt(v int64) Int

func NewIntFromBig

func NewIntFromBig(v *big.Int) Int

func (Int) Add

func (i Int) Add(b Int)

func (Int) Clone

func (i Int) Clone() Int

func (Int) Cmp

func (i Int) Cmp(b Int) int

func (Int) Div

func (i Int) Div(b Int)

func (Int) MarshalAmino

func (i Int) MarshalAmino() (string, error)

MarshalAmino defines custom encoding scheme

func (Int) MarshalJSON

func (i Int) MarshalJSON() ([]byte, error)

MarshalJSON defines custom encoding scheme

func (Int) Mul

func (i Int) Mul(b Int)

func (Int) Sub

func (i Int) Sub(b Int)

func (*Int) UnmarshalAmino

func (i *Int) UnmarshalAmino(text string) error

UnmarshalAmino defines custom decoding scheme

func (*Int) UnmarshalJSON

func (i *Int) UnmarshalJSON(bz []byte) error

UnmarshalJSON defines custom decoding scheme

type LinoCoin

type LinoCoin = bigInt

type Pid

type Pid string

type PostIFPair

type PostIFPair struct {
	Pid   Pid `json:"p"`
	SumIF IF  `json:"s_if"`
}

used in topN.

type Rep

type Rep = bigInt

type Reputation

type Reputation interface {
	// Donate to post @p p wit @p s coins.
	// Note that if migrate is required, it must be done before donate.
	DonateAt(u Uid, p Pid, s LinoCoin) IF

	// user's freescore += @p r, NOTE: unit is COIN.
	IncFreeScore(u Uid, r Rep)

	// needs to be called every endblocker.
	Update(t Time)

	// current reputation of the user.
	GetReputation(u Uid) Rep

	// Round 0 is an invalidated round
	// Round 1 is a short round that will last for only one block, because round-1's
	// start time is set to 0.
	GetCurrentRound() (RoundId, Time) // current round and its start time.

	// ExportImporter
	ExportToFile(file string) error
	ImportFromFile(file string) error
}

func NewReputation

func NewReputation(s ReputationStore, bestN int, userMaxN int, roundDurationSeconds, sampleWindowSize, decayFactor int64) Reputation

type ReputationImpl

type ReputationImpl struct {
	BestN                int
	UserMaxN             int
	RoundDurationSeconds int64
	SampleWindowSize     int64
	DecayFactor          int64
	// contains filtered or unexported fields
}

func (ReputationImpl) DonateAt

func (rep ReputationImpl) DonateAt(u Uid, p Pid, amount LinoCoin) IF

Record @p u has donated to @p p with @p amount LinoCoin. Only the first UserMaxN posts will be counted and have impact. The invarience is that user will have only *one* round of donations unsettled, either because that round is current round(not ended yet), or the user has never donated after that round. So when a user donates, we first update user's reputation, then we add this donation to records.

func (ReputationImpl) ExportToFile

func (rep ReputationImpl) ExportToFile(file string) error

ExportToFile - implementing ExporteImporter

func (ReputationImpl) GetCurrentRound

func (rep ReputationImpl) GetCurrentRound() (RoundId, Time)

return the current round id the the start time of the round.

func (ReputationImpl) GetReputation

func (rep ReputationImpl) GetReputation(u Uid) Rep

return the reputation of @p u.

func (ReputationImpl) ImportFromFile

func (rep ReputationImpl) ImportFromFile(file string) error

ImportFromFile - implementing ExporteImporter

func (ReputationImpl) IncFreeScore

func (rep ReputationImpl) IncFreeScore(u Uid, score Rep)

increase @p u user's reputation by @p score. To make added score permanent, add it on consumption, as reputation is only a temporory result, same in reputation migration.

func (ReputationImpl) StartNewRound

func (rep ReputationImpl) StartNewRound(t Time)

write (RoundId + 1, t) into db and update current round

func (ReputationImpl) Update

func (rep ReputationImpl) Update(t Time)

On BlockEnd(@p t), select out the seed set of the current round and start a new round.

type ReputationStore

type ReputationStore interface {
	// Export all state to deterministic bytes
	Export() *UserReputationTable

	// Import state from bytes
	Import(tb *UserReputationTable)

	// Iterator over usernames
	IterateUsers(UserIterator)

	GetUserMeta(u Uid) *userMeta
	SetUserMeta(u Uid, data *userMeta)

	SetRoundMeta(r RoundId, dt *roundMeta)
	GetRoundMeta(r RoundId) *roundMeta

	// total donation power received of a @p post in @p r round.
	GetRoundPostMeta(r RoundId, p Pid) *roundPostMeta
	SetRoundPostMeta(r RoundId, p Pid, dt *roundPostMeta)
	DelRoundPostMeta(r RoundId, p Pid)

	/// -----------  In this round  -------------
	// RoundId is the current round, starts from 1.
	GetCurrentRound() RoundId

	// Global data.
	GetGameMeta() *gameMeta
	SetGameMeta(dt *gameMeta)
}

ReputationStore - store reputation values. a simple wrapper around kv-store. It does not handle any reputation computation logic, except for init value for some field, like customer score. This interface should only be used by the reputation system implementation.

func NewReputationStore

func NewReputationStore(s Store, initRep int64) ReputationStore

type RoundId

type RoundId int64

type Store

type Store interface {
	Set(key []byte, val []byte)
	Get(key []byte) []byte
	Has(key []byte) bool
	Delete(key []byte)
	// Iterator over a domain of keys in ascending order. End is exclusive.
	// Start must be less than end, or the Iterator is invalid.
	// Iterator must be closed by caller.
	// To iterate over entire domain, use store.Iterator(nil, nil)
	// CONTRACT: No writes may happen within a domain while an iterator exists over it.
	Iterator(start, end []byte) db.Iterator
}

Store - store.

type Time

type Time int64

Time in this package is an int64, unix timestamp, in seconds.

type Uid

type Uid string

type UserIterator

type UserIterator = func(user Uid) bool // return true to break.

type UserReputation

type UserReputation struct {
	Username      Uid  `json:"username"`
	CustomerScore Rep  `json:"customer_score"`
	FreeScore     Rep  `json:"free_score"`
	IsMiniDollar  bool `json:"is_mini_dollar,omitempty"`
}

UserReputation - pk: Username

type UserReputationTable

type UserReputationTable struct {
	Reputations []UserReputation `json:"reputations"`
}

UserReputationTable - pk by Username

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL