staking

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jan 14, 2021 License: LGPL-3.0 Imports: 31 Imported by: 0

Documentation

Index

Constants

View Source
const (
	//Module name of the module
	Module = "staking" // 0x000000000000000000000000000000000000000000000000007374616b696e67

	//logs topic name
	LogTopicCreate         = "create"          // 0x0000000000000000000000000000000000000000000000000000637265617465
	LogTopicUpdate         = "update"          // 0x0000000000000000000000000000000000000000000000000000757064617465
	LogTopicDeposit        = "deposit"         // 0x000000000000000000000000000000000000000000000000006465706f736974
	LogTopicDepositFailed  = "deposit_failed"  // 0x0000000000000000000000000000000000006465706f7369745f6661696c6564
	LogTopicWithdraw       = "withdraw"        // 0x0000000000000000000000000000000000000000000000007769746864726177
	LogTopicWithdrawEffect = "withdraw_effect" // 0x000000000000000000000000000000000077697468647261775f656666656374
	// LogTopicWithdrawResult
	// Topics[1] : operator address
	// data:
	// [0,19]   [20,31]
	// receipt  arrivalAmount
	LogTopicWithdrawResult     = "withdraw_result"      // 0x000000000000000000000000000000000077697468647261775f726573756c74
	LogTopicRewards            = "rewards"              // 0x0000000000000000000000000000000000000000000000000072657761726473
	LogTopicSlashing           = "slashing"             // 0x000000000000000000000000000000000000000000000000736c617368696e67
	LogTopicChangeStatus       = "change_status"        // 0x000000000000000000000000000000000000006368616e67655f737461747573
	LogTopicChangeStatusFailed = "change_status_failed" // 0x0000000000000000000000006368616e67655f7374617475735f6661696c6564
	LogTopicSettle             = "settle"               // 0x0000000000000000000000000000000000000000000000000000736574746c65

	// topics of pending delegation transaction,
	// the "data" is a combined data as follow:
	// 		[0,8)							[8,32)
	// take-effects-on-which-block-number	final-delegation-tokens-after-the-transaction-take-effects (ignore it for settle)
	LogTopicDelegationPending = "delegation_op_pending" // 0x000000000000000000000064656c65676174696f6e5f6f705f70656e64696e67

	LogTopicDelegationAddFailed = "delegation_add_failed" // 0x000000000000000000000064656c65676174696f6e5f6164645f6661696c6564
	LogTopicDelegationSubFailed = "delegation_sub_failed" // 0x000000000000000000000064656c65676174696f6e5f7375625f6661696c6564
	LogTopicDelegationSubEffect = "delegation_sub_effect" // 0x000000000000000000000064656c65676174696f6e5f7375625f656666656374

	LogTopicProposerRewards = "proposer_rewards" // 0x0000000000000000000000000000000070726f706f7365725f72657761726473

	//0x00007265636f7665725f66726f6d5f657870697265645f657870656c6c696e67
	LogTopicRecoverFromExpiredExpelling = "recover_from_expired_expelling"
)
View Source
const (
	//EvidenceTypeDoubleSign name of duplicate vote
	EvidenceTypeDoubleSign = "doublesign"
	//EvidenceTypeInactive name of inactive
	EvidenceTypeInactive     = "inactive"
	EvidenceTypeDoubleSignV5 = "doublesignv5"
)
View Source
const (
	VoteNone uint8 = iota
	Propose
	Prevote
	Precommit
	NextIndex
	Certificate
)

ucon vote type

Variables

View Source
var (

	//EventTypeDoubleSign type of slashdata
	EventTypeDoubleSign uint8 = 0x0
	//EventTypeInactive type of slashdata
	EventTypeInactive uint8 = 0x1
)

Functions

func DecodeLogDataFromBytes

func DecodeLogDataFromBytes(data []byte) (topic string, tags []string, payload interface{}, err error)

DecodeLogDataFromBytes .

func EncodeMessage

func EncodeMessage(action ActionType, payload Msg) ([]byte, error)

EncodeMessage will do a PreCheck for the detailed-action-message and then pack it up to a staking-common-message using rlp encode.

func EndBlock

func EndBlock(staking *Staking) core.BlockHookFn

EndBlock process slashing and rewarding for block

func MakeSign

func MakeSign(msg Msg, key *ecdsa.PrivateKey) ([]byte, error)

Types

type ActionType

type ActionType uint8

DelegateActionType is the type of delegate action

const (
	ValidatorCreate ActionType = 0x1 + iota
	ValidatorUpdate
	ValidatorDeposit
	ValidatorWithDraw
	ValidatorChangeStatus
	ValidatorSettle
)

split actions to groups

const (
	DelegationAdd    ActionType = 0x10 + iota // add delegation
	DelegationSub                             // subtract delegation
	DelegationSettle                          // settle delegation rewards
)

type Evidence

type Evidence struct {
	Type string `json:"type"`
	Data []byte `json:"data"`
	// contains filtered or unexported fields
}

Evidence the evidence of validator's action

func NewEvidence

func NewEvidence(data interface{}) Evidence

NewEvidence create a new evidence

type EvidenceDoubleSign

type EvidenceDoubleSign struct {
	Round      *big.Int
	RoundIndex uint32
	Signs      map[common.Hash][]byte
}

EvidenceDoubleSign data of dup-vote Deprecated: using EvidenceDoubleSignV5 instead.

func (*EvidenceDoubleSign) DecodeRLP

func (e *EvidenceDoubleSign) DecodeRLP(c *rlp.Stream) error

DecodeRLP .

func (EvidenceDoubleSign) EncodeRLP

func (e EvidenceDoubleSign) EncodeRLP(w io.Writer) error

EncodeRLP implements rlp.Encoder.

type EvidenceDoubleSignV5 added in v1.0.0

type EvidenceDoubleSignV5 struct {
	Round      uint64
	RoundIndex uint32
	SignerIdx  uint32
	VoteType   uint8
	Signs      []*SignInfo
}

EvidenceDoubleSignV5 is the data of dup-vote with bls signature.

type EvidenceInactive

type EvidenceInactive struct {
	Round      uint64
	Validators []common.Address
}

EvidenceInactive data of inactive

type LogData

type LogData struct {
	Topic string   `json:"topic"`
	Tags  []string `json:"tags"`
	Data  []byte   `json:"data"`
}

LogData LogData

func (*LogData) DecodeRLP

func (l *LogData) DecodeRLP(s *rlp.Stream) error

DecodeRLP .

func (LogData) EncodeRLP

func (l LogData) EncodeRLP(w io.Writer) error

EncodeRLP .

func (LogData) EncodeToBytes

func (l LogData) EncodeToBytes() []byte

EncodeToBytes .

func (LogData) MarshalJSON

func (l LogData) MarshalJSON() ([]byte, error)

MarshalJSON .

func (*LogData) UnmarshalJSON

func (l *LogData) UnmarshalJSON(bs []byte) error

UnmarshalJSON .

type Message

type Message struct {
	Action  ActionType
	Payload []byte
}

Message is the base message of a staking transaction

type Msg

type Msg interface {
	PreCheck() error
	Hash() common.Hash
	Verify(nonce uint64, master common.Address) bool
}

Msg is a interface for detailed action message

type PenaltyRecord added in v1.0.0

type PenaltyRecord struct {
	Address common.Address `json:"address"`
	Amount  *big.Int       `json:"amount"`
}

type SignInfo added in v1.0.0

type SignInfo struct {
	Hash common.Hash
	Sign []byte
}

type SlashData

type SlashData struct {
	Type        uint8                  `json:"type"`
	MainAddress common.Address         `json:"mainAddress"`
	Total       *big.Int               `json:"penaltyAmount"` // total
	Records     []*SlashWithdrawRecord `json:"records"`       // from withdraw records
	Evidence    interface{}            `json:"evidence"`      // confirmed evidence
	// contains filtered or unexported fields
}

SlashData .

func NewSlashData

func NewSlashData(typ uint8, mainAddress common.Address, penaltyAmount *big.Int, records []*SlashWithdrawRecord, evidence *Evidence) (*SlashData, error)

NewSlashData create a slashData

func (*SlashData) DecodeRLP

func (l *SlashData) DecodeRLP(s *rlp.Stream) error

DecodeRLP .

func (SlashData) EncodeRLP

func (l SlashData) EncodeRLP(w io.Writer) error

EncodeRLP .

func (*SlashData) Hash

func (l *SlashData) Hash() (h common.Hash)

Hash .

type SlashDataV5 added in v1.0.0

type SlashDataV5 struct {
	Type         uint8                  `json:"type"`
	MainAddress  common.Address         `json:"mainAddress"`
	Total        *big.Int               `json:"penaltyAmount"` // total
	FromWithdraw []*SlashWithdrawRecord `json:"fromWithdraw"`  // from withdraw records
	FromDeposit  []*PenaltyRecord       `json:"fromDeposit"`
}

type SlashWithdrawRecord

type SlashWithdrawRecord struct {
	Token  *big.Int              `json:"token"`
	Record *state.WithdrawRecord `json:"record"`
}

SlashWithdrawRecord save modified withdraw record

type Staking

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

Staking staking container

func NewStaking

func NewStaking(mux *event.TypeMux) *Staking

NewStaking create a staking obj

func (*Staking) Register

func (s *Staking) Register(router core.IRouter)

Register reg module to router

func (*Staking) Start

func (s *Staking) Start(blockChain *core.BlockChain, eng interface{}) error

Start start staking module, blockchain and cons-engine are required

func (*Staking) Stop

func (s *Staking) Stop()

Stop stop staking module

type TxConverter

type TxConverter struct {
}

func (*TxConverter) ApplyMessage

func (t *TxConverter) ApplyMessage(msgCtx *core.MessageContext) ([]byte, uint64, bool, error)

func (*TxConverter) IntrinsicGas

func (t *TxConverter) IntrinsicGas(data []byte, to *common.Address) (uint64, error)

type TxCreateValidator

type TxCreateValidator struct {
	Name             string               `json:"name"`            // alias name for validator
	OperatorAddress  common.Address       `json:"operatorAddress"` // operator is the address who can manage the validator
	Coinbase         common.Address       `json:"coinbase"`        // coinbase is the address that mining rewards will be send to
	MainPubKey       hexutil.Bytes        `json:"mainPubKey"`
	BlsPubKey        hexutil.Bytes        `json:"blsPubKey"`
	Value            *big.Int             `json:"value"`
	Nonce            uint64               `json:"nonce"`
	CommissionRate   uint16               `json:"commissionRate"` // number over ten-thousandth
	RiskObligation   uint16               `json:"riskObligation"`
	AcceptDelegation uint16               `json:"acceptDelegation"`
	Role             params.ValidatorRole `json:"role"`
	Sign             hexutil.Bytes        `json:"sign"` //hash(m.Hash().Bytes())
}

TxCreateValidator create a new validator

func (*TxCreateValidator) Hash

func (m *TxCreateValidator) Hash() common.Hash

func (*TxCreateValidator) PreCheck

func (m *TxCreateValidator) PreCheck() error

func (*TxCreateValidator) Verify

func (m *TxCreateValidator) Verify(nonce uint64, master common.Address) bool

type TxDelegation

type TxDelegation struct {
	Validator common.Address //validator main address
	Value     *big.Int       // the value to add or subtract
}

TxDelegation contains module specific detail data for a delegation transaction

func (*TxDelegation) Hash

func (t *TxDelegation) Hash() common.Hash

func (*TxDelegation) PreCheck

func (t *TxDelegation) PreCheck() error

func (*TxDelegation) Verify

func (t *TxDelegation) Verify(uint64, common.Address) bool

type TxDelegationSettle

type TxDelegationSettle struct {
	Validator common.Address //validator main address
}

func (*TxDelegationSettle) Hash

func (t *TxDelegationSettle) Hash() common.Hash

func (*TxDelegationSettle) PreCheck

func (t *TxDelegationSettle) PreCheck() error

func (*TxDelegationSettle) Verify

type TxUpdateValidator

type TxUpdateValidator struct {
	Nonce            uint64         `json:"nonce"`
	Name             string         `json:"name"`
	MainAddress      common.Address `json:"mainAddress"`
	OperatorAddress  common.Address `json:"operatorAddress"`
	Coinbase         common.Address `json:"coinbase"`
	CommissionRate   uint16         `json:"commissionRate"` // number over ten-thousandth
	RiskObligation   uint16         `json:"riskObligation"`
	AcceptDelegation uint16         `json:"acceptDelegation"`
	Sign             hexutil.Bytes  `json:"sign"` //  hash(m.Hash().Bytes())
}

TxUpdateValidator 修改validator的信息

func (*TxUpdateValidator) Hash

func (m *TxUpdateValidator) Hash() common.Hash

func (*TxUpdateValidator) PreCheck

func (m *TxUpdateValidator) PreCheck() error

func (*TxUpdateValidator) Verify

func (m *TxUpdateValidator) Verify(nonce uint64, master common.Address) bool

type TxValidatorChangeStatus

type TxValidatorChangeStatus struct {
	MainAddress common.Address `json:"mainAddress"`
	Status      uint8          `json:"status"`
	Nonce       uint64         `json:"nonce"`
	Sign        hexutil.Bytes  `json:"sign"`
}

TxValidatorChangeStatus .

func (*TxValidatorChangeStatus) Hash

func (*TxValidatorChangeStatus) PreCheck

func (m *TxValidatorChangeStatus) PreCheck() error

func (*TxValidatorChangeStatus) Verify

func (m *TxValidatorChangeStatus) Verify(nonce uint64, master common.Address) bool

type TxValidatorDeposit

type TxValidatorDeposit struct {
	MainAddress common.Address `json:"mainAddress"`
	Value       *big.Int       `json:"value"`
	Nonce       uint64         `json:"nonce"`
	Sign        hexutil.Bytes  `json:"sign"` //  hash(m.Hash().Bytes())
}

TxValidatorDeposit more deposit for validator

func (*TxValidatorDeposit) Hash

func (m *TxValidatorDeposit) Hash() common.Hash

func (*TxValidatorDeposit) PreCheck

func (m *TxValidatorDeposit) PreCheck() error

func (*TxValidatorDeposit) Verify

func (m *TxValidatorDeposit) Verify(nonce uint64, master common.Address) bool

type TxValidatorSettle

type TxValidatorSettle struct {
	MainAddress common.Address `json:"mainAddress"`
}

func (*TxValidatorSettle) Hash

func (m *TxValidatorSettle) Hash() common.Hash

func (*TxValidatorSettle) PreCheck

func (m *TxValidatorSettle) PreCheck() error

func (*TxValidatorSettle) Verify

func (m *TxValidatorSettle) Verify(nonce uint64, master common.Address) bool

type TxValidatorWithdraw

type TxValidatorWithdraw struct {
	MainAddress common.Address `json:"mainAddress"`
	Recipient   common.Address `json:"recipient"` // tokens will be refunded to this account
	Value       *big.Int       `json:"value"`     // tokens that the validator wants to withdraw
	Nonce       uint64         `json:"nonce"`
	Sign        hexutil.Bytes  `json:"sign"` // hash(m.Hash().Bytes())
}

TxValidatorWithdraw .

func (*TxValidatorWithdraw) Hash

func (m *TxValidatorWithdraw) Hash() common.Hash

func (*TxValidatorWithdraw) PreCheck

func (m *TxValidatorWithdraw) PreCheck() error

func (*TxValidatorWithdraw) Verify

func (m *TxValidatorWithdraw) Verify(nonce uint64, master common.Address) bool

Jump to

Keyboard shortcuts

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