calculator

package
v1.4.1 Latest Latest
Warning

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

Go to latest
Published: Mar 21, 2024 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const InitBlockHeight = -1

Variables

This section is empty.

Functions

func New

func New(database db.Database, back *icstage.Snapshot, reward *icreward.Snapshot, logger log.Logger) *calculator

func NewIISS3Reward

func NewIISS3Reward(ctx Context) (*iiss3Reward, error)

func NewIISS4Reward

func NewIISS4Reward(c Context) (*iiss4Reward, error)

Types

type Context

type Context interface {
	Back() *icstage.Snapshot
	Base() *icreward.Snapshot
	Temp() *icreward.State
	Stats() *Stats
	Logger() log.Logger
	UpdateIScore(addr module.Address, reward *big.Int, t RewardType) error
}

type PRep

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

func NewPRep

func NewPRep(owner module.Address, status icmodule.EnableStatus, delegated, bonded *big.Int,
	commissionRate icmodule.Rate, pubkey bool) *PRep

func (*PRep) AccumulatedPower

func (p *PRep) AccumulatedPower() *big.Int

func (*PRep) AccumulatedVoted

func (p *PRep) AccumulatedVoted() *big.Int

func (*PRep) ApplyVote

func (p *PRep) ApplyVote(vType VoteType, amount *big.Int, period int, bondRequirement icmodule.Rate)

ApplyVote applies vote value to PRep. Updates bonded, delegated, power, accumulatedBonded, accumulatedVoted and accumulatedPower

func (*PRep) Bigger

func (p *PRep) Bigger(p1 *PRep) bool

func (*PRep) CalculateReward

func (p *PRep) CalculateReward(totalPRepReward, totalAccumulatedPower, minBond, minWage *big.Int)

func (*PRep) Clone

func (p *PRep) Clone() *PRep

func (*PRep) Equal

func (p *PRep) Equal(p1 *PRep) bool

func (*PRep) Format

func (p *PRep) Format(f fmt.State, c rune)

func (*PRep) GetReward

func (p *PRep) GetReward() *big.Int

func (*PRep) GetVotedValue

func (p *PRep) GetVotedValue() *big.Int

func (*PRep) InitAccumulated

func (p *PRep) InitAccumulated(termPeriod int64)

func (*PRep) IsElectable

func (p *PRep) IsElectable() bool

func (*PRep) IsRewardable

func (p *PRep) IsRewardable(electedPRepCount int) bool

func (*PRep) Owner

func (p *PRep) Owner() module.Address

func (*PRep) SetRank

func (p *PRep) SetRank(rank int)

func (*PRep) SetStatus

func (p *PRep) SetStatus(status icmodule.EnableStatus)

func (*PRep) Status

func (p *PRep) Status() icmodule.EnableStatus

func (*PRep) ToVoted

func (p *PRep) ToVoted() *icreward.Voted

func (*PRep) UpdatePower

func (p *PRep) UpdatePower(bondRequirement icmodule.Rate) *big.Int

func (*PRep) VoterReward

func (p *PRep) VoterReward() *big.Int

type PRepInfo

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

PRepInfo stores information for PRep reward calculation.

func NewPRepInfo

func NewPRepInfo(bondRequirement icmodule.Rate, electedPRepCount, offsetLimit int, logger log.Logger) *PRepInfo

func (*PRepInfo) Add

func (p *PRepInfo) Add(target module.Address, status icmodule.EnableStatus, delegated, bonded *big.Int,
	commissionRate icmodule.Rate, pubkey bool) *PRep

func (*PRepInfo) ApplyVote

func (p *PRepInfo) ApplyVote(vType VoteType, votes icstage.VoteList, offset int)

func (*PRepInfo) CalculateReward

func (p *PRepInfo) CalculateReward(totalReward, totalMinWage, minBond *big.Int) error

CalculateReward calculates commission, wage and voter reward of the PRep.

func (*PRepInfo) ElectedPRepCount

func (p *PRepInfo) ElectedPRepCount() int

func (*PRepInfo) GetPRep

func (p *PRepInfo) GetPRep(key string) *PRep

func (*PRepInfo) GetTermPeriod

func (p *PRepInfo) GetTermPeriod() int64

func (*PRepInfo) InitAccumulated

func (p *PRepInfo) InitAccumulated()

InitAccumulated update accumulated values of elected PReps

func (*PRepInfo) OffsetLimit

func (p *PRepInfo) OffsetLimit() int

func (*PRepInfo) PReps

func (p *PRepInfo) PReps() map[string]*PRep

func (*PRepInfo) SetStatus

func (p *PRepInfo) SetStatus(target module.Address, status icmodule.EnableStatus)

func (*PRepInfo) Sort

func (p *PRepInfo) Sort()

func (*PRepInfo) UpdateTotalAccumulatedPower

func (p *PRepInfo) UpdateTotalAccumulatedPower()

UpdateTotalAccumulatedPower updates totalAccumulatedPower of PRepInfo with accumulatedPower of elected preps

func (*PRepInfo) UpdateVoted

func (p *PRepInfo) UpdateVoted(writer RewardWriter) error

UpdateVoted writes updated Voted to database

type RewardCalculator

type RewardCalculator interface {
	Calculate() error
}

type RewardReader

type RewardReader interface {
	GetDelegating(addr module.Address) (*icreward.Delegating, error)
	GetBonding(addr module.Address) (*icreward.Bonding, error)
}

RewardReader reads from icreward.Snapshot

type RewardType

type RewardType int
const (
	RTBlockProduce RewardType = iota
	RTPRep
	RTVoter
)

func (RewardType) String

func (r RewardType) String() string

type RewardWriter

type RewardWriter interface {
	SetVoted(addr module.Address, voted *icreward.Voted) error
	SetDelegating(addr module.Address, delegating *icreward.Delegating) error
	SetBonding(addr module.Address, bonding *icreward.Bonding) error
}

RewardWriter writes to icreward.State

type Stats

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

func NewStats

func NewStats() *Stats

func (*Stats) GetCount added in v1.4.1

func (s *Stats) GetCount(t RewardType) int64

func (*Stats) GetValue

func (s *Stats) GetValue(t RewardType) *big.Int

func (*Stats) IncreaseReward

func (s *Stats) IncreaseReward(t RewardType, amount *big.Int)

func (*Stats) String

func (s *Stats) String() string

func (*Stats) Total

func (s *Stats) Total() *big.Int

type VoteEvent

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

func NewVoteEvent

func NewVoteEvent(vType VoteType, votes icstage.VoteList, offset int) *VoteEvent

func (*VoteEvent) Equal

func (v *VoteEvent) Equal(v1 *VoteEvent) bool

func (*VoteEvent) Offset

func (v *VoteEvent) Offset() int

func (*VoteEvent) Type

func (v *VoteEvent) Type() VoteType

func (*VoteEvent) Votes

func (v *VoteEvent) Votes() icstage.VoteList

type VoteEvents

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

func NewVoteEvents

func NewVoteEvents() *VoteEvents

func (*VoteEvents) AddEvent

func (v *VoteEvents) AddEvent(vType VoteType, from module.Address, votes icstage.VoteList, offset int)

func (*VoteEvents) Events

func (v *VoteEvents) Events() map[string][]*VoteEvent

func (*VoteEvents) Get

func (v *VoteEvents) Get(from module.Address) []*VoteEvent

func (*VoteEvents) IsCalculated

func (v *VoteEvents) IsCalculated(key string) bool

func (*VoteEvents) SetCalculated

func (v *VoteEvents) SetCalculated(from module.Address)

func (*VoteEvents) UpdateVoting

func (v *VoteEvents) UpdateVoting(reader RewardReader, writer RewardWriter) error

UpdateVoting writes updated Bonding and Delegating to database

type VoteType

type VoteType int

type Voter

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

func NewVoter

func NewVoter(owner module.Address, logger log.Logger) *Voter

func (*Voter) ApplyEvent

func (v *Voter) ApplyEvent(event *VoteEvent, period int)

func (*Voter) ApplyVoting

func (v *Voter) ApplyVoting(voting icreward.Voting, period int64)

func (*Voter) CalculateReward

func (v *Voter) CalculateReward(pInfo *PRepInfo) *big.Int

func (*Voter) Owner

func (v *Voter) Owner() module.Address

Jump to

Keyboard shortcuts

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