iotex-election: github.com/iotexproject/iotex-election/committee Index | Files

package committee

import "github.com/iotexproject/iotex-election/committee"

Index

Package Files

bucketarchive.go committee.go deltarecordtableoperator.go heightmanager.go nativestakingcommittee.go pollarchive.go recordtableoperator.go timetableoperator.go

Constants

const BucketRecordQuery = "SELECT id, start_time, duration, amount, decay, voter, candidate FROM %s WHERE id IN (%s)"

BucketRecordQuery is query to return buckets by ids

const EthHardForkHeight = 8581700

EthHardForkHeight stands for the height of ethereum hard fork

const InsertBucketsQueryMySQL = "INSERT IGNORE INTO %s (hash, start_time, duration, amount, decay, voter, candidate) VALUES (?, ?, ?, ?, ?, ?, ?)"

InsertBucketsQueryMySQL is query to insert buckets in MYSQL driver

const InsertBucketsQuerySQLITE = "INSERT OR IGNORE INTO %s (hash, start_time, duration, amount, decay, voter, candidate) VALUES (?, ?, ?, ?, ?, ?, ?)"

InsertBucketsQuerySQLITE is query to insert buckets in SQLITE driver

const InsertRegistrationQueryMySQL = "INSERT IGNORE INTO %s (hash, name, address, operator_address, reward_address, self_staking_weight) VALUES (?, ?, ?, ?, ?, ?)"

InsertRegistrationQueryMySQL is query to insert registrations in MySQL driver

const InsertRegistrationQuerySQLITE = "" /* 129 byte string literal not displayed */

InsertRegistrationQuerySQLITE is query to insert registrations in SQLITE driver

const RegistrationQuery = "SELECT id, name, address, operator_address, reward_address, self_staking_weight FROM %s WHERE id IN (%s)"

RegistrationQuery is query to get registrations by ids

func InsertBuckets Uses

func InsertBuckets(tableName string, driverName DRIVERTYPE, records interface{}, tx *sql.Tx) (frequencies map[hash.Hash256]int, err error)

InsertBuckets inserts bucket records into table by tx

func InsertDeltaBuckets Uses

func InsertDeltaBuckets(tableName string, driverName DRIVERTYPE, records interface{}, tx *sql.Tx) (
    frequencies map[hash.Hash256]int,
    indexes map[int64]hash.Hash256,
    err error,
)

InsertDeltaBuckets inserts bucket records into table by tx

func InsertRegistrations Uses

func InsertRegistrations(tableName string, driverName DRIVERTYPE, records interface{}, tx *sql.Tx) (frequencies map[hash.Hash256]int, err error)

InsertRegistrations inserts registration records into table by tx

func QueryBuckets Uses

func QueryBuckets(tableName string, frequencies map[int64]int, sdb *sql.DB, tx *sql.Tx) (interface{}, error)

QueryBuckets returns buckets by ids

func QueryRegistrations Uses

func QueryRegistrations(tableName string, frequencies map[int64]int, sdb *sql.DB, tx *sql.Tx) (interface{}, error)

QueryRegistrations get all registrations by ids

type BucketArchive Uses

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

func NewBucketArchive Uses

func NewBucketArchive(dbPath string, numOfRetries uint8, startHeight uint64, interval uint64) (*BucketArchive, error)

NewBucketArchive creates a new archive of bucket

func (*BucketArchive) Buckets Uses

func (arch *BucketArchive) Buckets(height uint64) ([]*types.Bucket, error)

func (*BucketArchive) MintTime Uses

func (arch *BucketArchive) MintTime(height uint64) (time.Time, error)

func (*BucketArchive) PutDelta Uses

func (arch *BucketArchive) PutDelta(height uint64, ts time.Time, updatedBuckets []*pyggBucket) (err error)

func (*BucketArchive) Start Uses

func (arch *BucketArchive) Start(ctx context.Context) (err error)

func (*BucketArchive) Stop Uses

func (arch *BucketArchive) Stop(_ context.Context) (err error)

func (*BucketArchive) TipHeight Uses

func (arch *BucketArchive) TipHeight() (uint64, error)

type CalcGravityChainHeight Uses

type CalcGravityChainHeight func(uint64) (uint64, error)

CalcGravityChainHeight calculates the corresponding gravity chain height for an epoch

type Committee Uses

type Committee interface {
    // Start starts the committee service
    Start(context.Context) error
    // Stop stops the committee service
    Stop(context.Context) error
    // ResultByHeight returns the result on a specific ethereum height
    ResultByHeight(uint64) (*types.ElectionResult, error)
    //RawDataByHeight returns the bucket list and registration list and mintTime
    RawDataByHeight(uint64) ([]*types.Bucket, []*types.Registration, time.Time, error)
    // HeightByTime returns the nearest result before time
    HeightByTime(time.Time) (uint64, error)
    // LatestHeight returns the height with latest result
    LatestHeight() uint64
    // Status returns the committee status
    Status() STATUS
    // PutNativePollByEpoch puts one native poll record on IoTeX chain
    PutNativePollByEpoch(uint64, time.Time, []*types.Bucket) error
    // NativeBucketsByEpoch returns a list of Bucket of a given epoch number
    NativeBucketsByEpoch(uint64) ([]*types.Bucket, error)
}

Committee defines an interface of an election committee It could be considered as a light state db of gravity chain, that

func NewCommittee Uses

func NewCommittee(archive PollArchive, cfg Config) (Committee, error)

NewCommittee creates a committee

type Config Uses

type Config struct {
    NumOfRetries               uint8    `yaml:"numOfRetries"`
    GravityChainAPIs           []string `yaml:"gravityChainAPIs"`
    GravityChainHeightInterval uint64   `yaml:"gravityChainHeightInterval"`
    GravityChainStartHeight    uint64   `yaml:"gravityChainStartHeight"`
    RegisterContractAddress    string   `yaml:"registerContractAddress"`
    StakingContractAddress     string   `yaml:"stakingContractAddress"`
    PaginationSize             uint8    `yaml:"paginationSize"`
    VoteThreshold              string   `yaml:"voteThreshold"`
    ScoreThreshold             string   `yaml:"scoreThreshold"`
    SelfStakingThreshold       string   `yaml:"selfStakingThreshold"`
    CacheSize                  uint32   `yaml:"cacheSize"`
    NumOfFetchInParallel       uint8    `yaml:"numOfFetchInParallel"`
    SkipManifiedCandidate      bool     `yaml:"skipManifiedCandidate"`
    GravityChainBatchSize      uint64   `yaml:"gravityChainBatchSize"`
}

Config defines the config of the committee

type DRIVERTYPE Uses

type DRIVERTYPE uint8

DRIVERTYPE represents the type of sql driver

const (
    //SQLITE stands for a Sqlite driver
    SQLITE DRIVERTYPE = iota
    //MYSQL stands for a mysql driver
    MYSQL
)

type InsertDeltaRecordsFunc Uses

type InsertDeltaRecordsFunc func(string, DRIVERTYPE, interface{}, *sql.Tx) (
    map[hash.Hash256]int,
    map[int64]hash.Hash256,
    error,
)

InsertDeltaRecordsFunc defines an api to insert records

type InsertRecordsFunc Uses

type InsertRecordsFunc func(string, DRIVERTYPE, interface{}, *sql.Tx) (map[hash.Hash256]int, error)

InsertRecordsFunc defines an api to insert records

type NativeCommittee Uses

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

func NewNativeStakingCommittee Uses

func NewNativeStakingCommittee(
    archive *BucketArchive,
    cfg NativeCommitteeConfig,
) (*NativeCommittee, error)

func (*NativeCommittee) DataByHeight Uses

func (nc *NativeCommittee) DataByHeight(height uint64) (time.Time, []*types.Bucket, error)

func (*NativeCommittee) Start Uses

func (nc *NativeCommittee) Start(ctx context.Context) error

func (*NativeCommittee) Status Uses

func (nc *NativeCommittee) Status() STATUS

func (*NativeCommittee) Stop Uses

func (nc *NativeCommittee) Stop(ctx context.Context) error

func (*NativeCommittee) TipHeight Uses

func (nc *NativeCommittee) TipHeight() uint64

type NativeCommitteeConfig Uses

type NativeCommitteeConfig struct {
    StakingContractAddress string `yaml:"stakingContractAddress"`
    IoTeXAPI               string `yaml:"iotexAPI"`
    StartHeight            uint64 `yaml:"startHeight"`
    Interval               uint64 `yaml:"interval"`
}

type Operator Uses

type Operator interface {
    // CreateTables prepares the tables for the operator
    CreateTables(*sql.Tx) error
    // Get returns the value by height
    Get(uint64, *sql.DB, *sql.Tx) (interface{}, error)
    // Put writes value for height
    Put(uint64, interface{}, *sql.Tx) error
    // TipHeight returns the tip height
    TipHeight(*sql.DB, *sql.Tx) (uint64, error)
}

Operator defines an interface of operations on some tables in SQL DB

func NewBucketTableOperator Uses

func NewBucketTableOperator(tableName string, driverName DRIVERTYPE) (Operator, error)

NewBucketTableOperator creates an operator for bucket table

func NewDeltaBucketTableOperator Uses

func NewDeltaBucketTableOperator(tableName string, driverName DRIVERTYPE) (Operator, error)

NewDeltaBucketTableOperator creates an operator for bucket table

func NewDeltaRecordTableOperator Uses

func NewDeltaRecordTableOperator(
    tableName string,
    driverName DRIVERTYPE,
    insertDeltaRecordsFunc InsertDeltaRecordsFunc,
    queryRecordsFunc QueryRecordsFunc,
    recordTableCreation string,
) (Operator, error)

NewDeltaRecordTableOperator creates a record table storing delta

func NewRecordTableOperator Uses

func NewRecordTableOperator(
    tableName string,
    driverName DRIVERTYPE,
    insertRecordsFunc InsertRecordsFunc,
    queryRecordsFunc QueryRecordsFunc,
    recordTableCreation string,
) (Operator, error)

NewRecordTableOperator creates a new arch of poll

func NewRegistrationTableOperator Uses

func NewRegistrationTableOperator(tableName string, driverName DRIVERTYPE) (Operator, error)

NewRegistrationTableOperator create an operator for registration table

type PollArchive Uses

type PollArchive interface {
    HeightBefore(time.Time) (uint64, error)
    // Buckets returns a list of Bucket of a given height
    Buckets(uint64) ([]*types.Bucket, error)
    // NativeBuckets returns a list of Bucket of a given epoch number
    NativeBuckets(uint64) ([]*types.Bucket, error)
    // Registrations returns a list of Registration of a given height
    Registrations(uint64) ([]*types.Registration, error)
    // MintTime returns the mint time of a given height
    MintTime(uint64) (time.Time, error)
    // NativeMintTime returns the mint time of a given epoch number
    NativeMintTime(uint64) (time.Time, error)
    // PutPoll puts one poll record
    PutPoll(uint64, time.Time, []*types.Registration, []*types.Bucket) error
    // PutNativePoll puts one native poll record on IoTeX chain
    PutNativePoll(uint64, time.Time, []*types.Bucket) error
    // TipHeight returns the tip height stored in archive
    TipHeight() (uint64, error)
    // Start starts the archive
    Start(context.Context) error
    // Stop stops the archive
    Stop(context.Context) error
}

PollArchive stores registrations, buckets, and other data

func NewArchive Uses

func NewArchive(dbPath string, numOfRetries uint8, startHeight uint64, interval uint64) (PollArchive, error)

NewArchive creates a new archive of poll

type QueryRecordsFunc Uses

type QueryRecordsFunc func(string, map[int64]int, *sql.DB, *sql.Tx) (interface{}, error)

QueryRecordsFunc defines an api to query records

type Record Uses

type Record interface {
    Hash() (hash.Hash256, error)
}

Record defines a record

type STATUS Uses

type STATUS uint8

STATUS represents the status of committee

const (
    // STARTING stands for a starting status
    STARTING STATUS = iota
    // ACTIVE stands for an active status
    ACTIVE
    // INACTIVE stands for an inactive status
    INACTIVE
)

type TimeTableOperator Uses

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

TimeTableOperator defines an operator on timetable

func NewTimeTableOperator Uses

func NewTimeTableOperator(tableName string, driverName DRIVERTYPE) *TimeTableOperator

NewTimeTableOperator returns an operator to time table

func (*TimeTableOperator) CreateTables Uses

func (operator *TimeTableOperator) CreateTables(tx *sql.Tx) (err error)

CreateTables prepares the tables for the operator

func (*TimeTableOperator) Get Uses

func (operator *TimeTableOperator) Get(height uint64, sdb *sql.DB, tx *sql.Tx) (interface{}, error)

Get returns the value by height

func (*TimeTableOperator) HeightBefore Uses

func (operator *TimeTableOperator) HeightBefore(ts time.Time, sdb *sql.DB, tx *sql.Tx) (height uint64, err error)

HeightBefore returns the Height before ts in the time table

func (*TimeTableOperator) Put Uses

func (operator *TimeTableOperator) Put(height uint64, value interface{}, tx *sql.Tx) error

Put writes value for height

func (*TimeTableOperator) TipHeight Uses

func (operator *TimeTableOperator) TipHeight(sdb *sql.DB, tx *sql.Tx) (uint64, error)

TipHeight returns the tip height in the time table

Package committee imports 34 packages (graph) and is imported by 6 packages. Updated 2020-02-28. Refresh now. Tools for package owners.