internal

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Sep 24, 2018 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultBestContentIndexN = 5
	// parameters of earlier and more you donate, higher reputation you got.
	// unit: coin
	KeyPriceC = 1000 // C = 0.01 lino, C must be larger than 2.
	// The K parameter is set to be always 1, where it means
	// K = 0.00001 lino. The reason is that making K = 1 can optimize the computation a lot.
	// we can still change the key distribution rate by changing C.
	RoundDuration        = 25                                   // how many hours does game last.
	SampleWindowSize     = 10                                   // how many rounds is used to sample out user's customer score.
	DecayFactor          = 100 - (100 / (3 * SampleWindowSize)) // reduce to ~97% at most each time.
	MaxNumKeysEachTime   = 10000000000
	OneLinoCoin          = 100000
	InitialCustomerScore = OneLinoCoin // initial and minimum score is 1 lino.
)

This package does not support parameter hot change by now.

Variables

View Source
var BigIntZero bigInt = big.NewInt(0)
View Source
var (
	KeySeparator = []byte("/")
)

Functions

This section is empty.

Types

type Dp

type Dp = bigInt // donation power

type Pid

type Pid = string

type PostDpPair

type PostDpPair struct {
	Pid   Pid
	SumDp Dp
}

used in topN.

type Rep

type Rep = bigInt

type Reputation

type Reputation interface {
	DonateAt(u Uid, p Pid, s Stake) Dp
	ReportAt(u Uid, p Pid) Rep
	// user's freescore += @p r, NOTE: unit is COIN.
	IncFreeScore(u Uid, r Rep)
	Update(t Time) // called every endblocker.
	// current reputation of the user.
	GetReputation(u Uid) Rep
	GetSumRep(p Pid) Rep
	GetCurrentRound() (RoundId, Time) // current round and its start time.
}

func NewReputation

func NewReputation(s ReputationStore) Reputation

type ReputationImpl

type ReputationImpl struct {
	// contains filtered or unexported fields
}

func (ReputationImpl) DonateAt

func (rep ReputationImpl) DonateAt(u Uid, p Pid, s Stake) Dp

currently all donations count, though we said that only the first 40 donation counts in the spec.

func (ReputationImpl) GetCurrentRound

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

func (ReputationImpl) GetReputation

func (rep ReputationImpl) GetReputation(u Uid) Rep

func (ReputationImpl) GetSettledCustomerScore

func (rep ReputationImpl) GetSettledCustomerScore(u Uid) Rep

func (ReputationImpl) GetSumRep

func (rep ReputationImpl) GetSumRep(p Pid) Rep

func (ReputationImpl) IncFreeScore

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

func (ReputationImpl) ReportAt

func (rep ReputationImpl) ReportAt(u Uid, p Pid) Rep

similar to incPostSumRep, delta is included as well.

func (ReputationImpl) Update

func (rep ReputationImpl) Update(t Time)

type ReputationStore

type ReputationStore interface {
	// Note that, this value may not be the exact customer score of the user
	// due to there might be unsettled keys remaining.
	// Also, because that user can get free reputation when they lockdown coins, this value
	// is solely the user's customer score.
	GetCustomerScore(u Uid) Rep
	SetCustomerScore(u Uid, r Rep)

	// user get free score by coin lockdown.
	GetFreeScore(u Uid) Rep
	SetFreeScore(u Uid, r Rep)

	// till which round has user settled, i.e. his customer score is accurate, initialized as 0.
	GetUserLastSettled(u Uid) RoundId
	SetUserLastSettled(u Uid, r RoundId)

	// The last round that user has any donation.
	// contract is that since any donation will force user to settle any previous customer score,
	// so if there would be any unsettled customer score, when lastDonationRound > LastSettled,
	// they are all in the lastDonationRound.
	GetUserLastDonationRound(u Uid) RoundId
	SetUserLastDonationRound(u Uid, r RoundId)

	// total reputation of a post which is the sum of
	// donors' reputation subtracted by reporters' reputation.
	GetSumRep(p Pid) Rep
	SetSumRep(p Pid, rep Rep)

	// @returns: how much @p u has donated to @p p.
	GetUserDonatedOn(u Uid, p Pid) Dp
	SetUserDonatedOn(u Uid, p Pid, dp Dp)

	// if has not donated before, return 0, otherwise reputation at that time.
	GetUserLastDonation(u Uid, p Pid) Rep
	SetUserLastDonation(u Uid, p Pid, rep Rep)

	// if has not reported before, return 0, otherwise reputation at that time.
	GetUserLastReport(u Uid, p Pid) Rep
	SetUserLastReport(u Uid, p Pid, rep Rep)

	// the final result of round, should be set right after round ends.
	GetRoundResult(r RoundId) []Pid
	SetRoundResult(r RoundId, rst []Pid)

	// sum of donation power of all donations happened during the round.
	GetRoundSumDp(r RoundId) Dp
	SetRoundSumDp(r RoundId, dp Dp)

	// top n posts. Ordering is maintained by this store, update upon SetSumDp is called.
	// NOTE: not the final result.
	GetRoundTopNPosts(r RoundId) []PostDpPair

	GetRoundStartAt(round RoundId) Time

	/// -----------  In this round  -------------
	// TODO(yumin): store them together to avoid second read?
	// RoundId is the current round, starts from 1.
	GetCurrentRound() RoundId
	// write (RoundId + 1, t) into db and update current round
	StartNewRound(t Time)

	// total donation power received of a @p post.
	GetRoundPostSumDp(r RoundId, p Pid) Dp
	// update TopN
	SetRoundPostSumDp(r RoundId, p Pid, dp Dp)

	// total stake received of a @p post.
	GetRoundPostSumStake(r RoundId, p Pid) Stake
	SetRoundPostSumStake(r RoundId, p Pid, s Stake)

	// @returns: how many keys has been sold for @p
	GetRoundNumKeysSold(r RoundId, p Pid) bigInt
	SetRoundNumKeysSold(r RoundId, p Pid, numKeys bigInt)

	// @returns: how many keys this user has on this post. return nil if have zero.
	GetRoundNumKeysHas(r RoundId, u Uid, p Pid) bigInt
	SetRoundNumKeysHas(r RoundId, u Uid, p Pid, numKeys bigInt)
}

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. This store needs to be merkelized to support fast rollback.

func NewReputationStore

func NewReputationStore(s Store, n int) ReputationStore

func NewReputationStoreDefaultN

func NewReputationStoreDefaultN(s Store) ReputationStore

type RoundId

type RoundId = int64

type Stake

type Stake = bigInt

type Store

type Store interface {
	Set(key []byte, val []byte)
	Get(key []byte) []byte
}

type Time

type Time = int64

type Uid

type Uid = string

Jump to

Keyboard shortcuts

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