committee

package
v0.3.6 Latest Latest
Warning

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

Go to latest
Published: Sep 7, 2023 License: GPL-3.0 Imports: 36 Imported by: 15

Documentation

Index

Constants

View Source
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

View Source
const EthHardForkHeight = 8581700

EthHardForkHeight stands for the height of ethereum hard fork

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

InsertBucketsQueryMySQL is query to insert buckets in MYSQL driver

View Source
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

View Source
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

View Source
const InsertRegistrationQuerySQLITE = "" /* 127-byte string literal not displayed */

InsertRegistrationQuerySQLITE is query to insert registrations in SQLITE driver

View Source
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 InsertDeltaBuckets added in v0.2.14

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 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

func QueryBuckets added in v0.2.3

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

QueryBuckets returns buckets by ids

func QueryRegistrations added in v0.2.3

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

QueryRegistrations get all registrations by ids

Types

type BucketArchive added in v0.2.14

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

func NewBucketArchive added in v0.2.14

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

NewBucketArchive creates a new archive of bucket

func (*BucketArchive) Buckets added in v0.2.14

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

func (*BucketArchive) MintTime added in v0.2.14

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

func (*BucketArchive) PutDelta added in v0.2.14

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

func (*BucketArchive) Start added in v0.2.14

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

func (*BucketArchive) Stop added in v0.2.14

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

func (*BucketArchive) TipHeight added in v0.2.14

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

type CalcGravityChainHeight added in v0.1.5

type CalcGravityChainHeight func(uint64) (uint64, error)

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"`
	GravityChainCeilingHeight  uint64   `yaml:"gravityChainCeilingHeight"`
	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 InsertDeltaRecordsFunc added in v0.2.14

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 added in v0.2.3

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

InsertRecordsFunc defines an api to insert records

type NativeCommittee added in v0.2.14

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

func NewNativeStakingCommittee added in v0.2.14

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

func (*NativeCommittee) DataByHeight added in v0.2.14

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

func (*NativeCommittee) Start added in v0.2.14

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

func (*NativeCommittee) Status added in v0.2.14

func (nc *NativeCommittee) Status() STATUS

func (*NativeCommittee) Stop added in v0.2.14

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

func (*NativeCommittee) TipHeight added in v0.2.14

func (nc *NativeCommittee) TipHeight() uint64

type NativeCommitteeConfig added in v0.2.14

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

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
	// 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 added in v0.2.3

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

NewBucketTableOperator creates an operator for bucket table

func NewDeltaBucketTableOperator added in v0.2.14

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

NewDeltaBucketTableOperator creates an operator for bucket table

func NewDeltaRecordTableOperator added in v0.2.14

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

NewDeltaRecordTableOperator creates a record table storing delta

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

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

QueryRecordsFunc defines an api to query records

type Record added in v0.2.3

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

Record defines a record

type STATUS added in v0.1.4

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 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) Get added in v0.2.3

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

Get returns the value by height

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

func (*TimeTableOperator) Put added in v0.2.3

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

Put writes value for height

func (*TimeTableOperator) TipHeight added in v0.2.3

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

TipHeight returns the tip height in the time table

Jump to

Keyboard shortcuts

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