Documentation ¶
Index ¶
- Constants
- func InsertBuckets(tableName string, driverName DRIVERTYPE, records interface{}, tx *sql.Tx) (frequencies map[hash.Hash256]int, err error)
- func InsertRegistrations(tableName string, driverName DRIVERTYPE, records interface{}, tx *sql.Tx) (frequencies map[hash.Hash256]int, err error)
- func QueryBuckets(tableName string, frequencies map[int64]int, sdb *sql.DB, tx *sql.Tx) (interface{}, error)
- func QueryRegistrations(tableName string, frequencies map[int64]int, sdb *sql.DB, tx *sql.Tx) (interface{}, error)
- type CalcGravityChainHeight
- type Committee
- type Config
- type DRIVERTYPE
- type InsertRecordsFunc
- type Operator
- func NewBucketTableOperator(tableName string, driverName DRIVERTYPE) (Operator, error)
- func NewRecordTableOperator(tableName string, driverName DRIVERTYPE, insertRecordsFunc InsertRecordsFunc, ...) (Operator, error)
- func NewRegistrationTableOperator(tableName string, driverName DRIVERTYPE) (Operator, error)
- type PollArchive
- type QueryRecordsFunc
- type Record
- type STATUS
- type TimeTableOperator
- func (operator *TimeTableOperator) CreateTables(tx *sql.Tx) (err error)
- func (operator *TimeTableOperator) Get(height uint64, sdb *sql.DB, tx *sql.Tx) (interface{}, error)
- func (operator *TimeTableOperator) HeightBefore(ts time.Time, sdb *sql.DB, tx *sql.Tx) (height uint64, err error)
- func (operator *TimeTableOperator) Put(height uint64, value interface{}, tx *sql.Tx) error
- func (operator *TimeTableOperator) TipHeight(sdb *sql.DB, tx *sql.Tx) (uint64, error)
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 InsertBucketsQuery = "INSERT OR IGNORE INTO %s (hash, start_time, duration, amount, decay, voter, candidate) VALUES (?, ?, ?, ?, ?, ?, ?)"
InsertBucketsQuery is query to insert buckets
const InsertBucketsQueryMySql = "INSERT IGNORE INTO %s (hash, start_time, duration, amount, decay, voter, candidate) VALUES (?, ?, ?, ?, ?, ?, ?)"
const InsertRegistrationQuery = "" /* 127-byte string literal not displayed */
InsertRegistrationQuery is query to insert registrations
const InsertRegistrationQueryMySql = "INSERT IGNORE INTO %s (hash, name, address, operator_address, reward_address, self_staking_weight) VALUES (?, ?, ?, ?, ?, ?)"
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
Variables ¶
This section is empty.
Functions ¶
func InsertBuckets ¶ added in v0.2.3
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 InsertRegistrations ¶ added in v0.2.3
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
Types ¶
type CalcGravityChainHeight ¶ added in v0.1.5
CalcGravityChainHeight calculates the corresponding gravity chain height for an epoch
type Committee ¶
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 ¶
func NewCommittee(archive PollArchive, cfg Config) (Committee, error)
NewCommittee creates a committee
type Config ¶
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 ¶ added in v0.2.6
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 InsertRecordsFunc ¶ added in v0.2.3
InsertRecordsFunc defines an api to insert records
type Operator ¶ added in v0.2.3
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 }
Operator defines an interface of operations on some tables in SQL DB
func NewBucketTableOperator ¶ added in v0.2.3
func NewBucketTableOperator(tableName string, driverName DRIVERTYPE) (Operator, error)
NewBucketTableOperator creates an operator for bucket table
func NewRecordTableOperator ¶ added in v0.2.3
func NewRecordTableOperator( tableName string, driverName DRIVERTYPE, insertRecordsFunc InsertRecordsFunc, queryRecordsFunc QueryRecordsFunc, recordTableCreation string, ) (Operator, error)
NewRecordTableOperator creates a new arch of poll
func NewRegistrationTableOperator ¶ added in v0.2.3
func NewRegistrationTableOperator(tableName string, driverName DRIVERTYPE) (Operator, error)
NewRegistrationTableOperator create an operator for registration table
type PollArchive ¶ added in v0.2.3
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 ¶ added in v0.2.1
func NewArchive(dbPath string, numOfRetries uint8, startHeight uint64, interval uint64) (PollArchive, error)
NewArchive creates a new archive of poll
type QueryRecordsFunc ¶ added in v0.2.3
QueryRecordsFunc defines an api to query records
type TimeTableOperator ¶ added in v0.2.3
type TimeTableOperator struct {
// contains filtered or unexported fields
}
TimeTableOperator defines an operator on timetable
func NewTimeTableOperator ¶ added in v0.2.3
func NewTimeTableOperator(tableName string, driverName DRIVERTYPE) *TimeTableOperator
NewTimeTableOperator returns an operator to time table
func (*TimeTableOperator) CreateTables ¶ added in v0.2.3
func (operator *TimeTableOperator) CreateTables(tx *sql.Tx) (err error)
CreateTables prepares the tables for the operator
func (*TimeTableOperator) HeightBefore ¶ added in v0.2.3
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