committee

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2020 License: GPL-3.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// example:
	// key: hash("/v1/29d3fbe3e7983a41d0e6d984c480ceedb3c251fd/from")
	StakingInList = "/v1/staking/%v/inlist"

	// the 1st block expected to participant in validator and proposer
	StakingKeyFrom = "/v1/staking/%v/from"

	// the last block to participant in validator and proposer, the tokens will be refunded
	// to participants' addresses after this block has mined
	StakingKeyTo = "/v1/staking/%v/to"

	// StakingHash is the last hash in hashchain,  random nubmers(R) in futureBlock
	// will be hashed for (futureBlock - stakingFrom) times to match with StakingHash.
	StakingKeyHash = "/v1/staking/%v/hash"

	// records the number of tokens staked
	StakingKeyValue = "/v1/staking/%v/value"

	// record the total number of staked users
	StakingUsersCount = "/v1/staking/count"

	// staking users index , index -> address
	StakingUserIndex = "/v1/staking/address/%v"
)
View Source
const (
	Staking = StakingOp(0x00)
	Redeem  = StakingOp(0xFF)
)

Staking Operations

Variables

View Source
var (
	CommonCoin = []byte("Sperax")
	// block 0 common random number
	W0 = crypto.Keccak256Hash(hexutil.MustDecode("0x03243F6A8885A308D313198A2E037073"))
	// potential propser expectation
	E1 = big.NewInt(5)
	// BFT committee expectationA
	E2 = big.NewInt(50)
	// unit of staking SPA
	StakingUnit = new(big.Int).Mul(big.NewInt(1000), big.NewInt(params.Ether))
	// transfering tokens to this address will be specially treated
	StakingAddress = common.HexToAddress("0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee")

	// max unsigned 256-bit integer
	MaxUint256 = big.NewInt(0).SetBytes(common.FromHex("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"))
)
View Source
var (
	ErrStakingRequest        = errors.New("STAKING: already staked")
	ErrStakingMinimumTokens  = errors.New("STAKING: less than minimum values")
	ErrStakingZeroValue      = errors.New("STAKING: cannot stake 0 value")
	ErrStakingInvalidPeriod  = errors.New("STAKING: invalid staking period, make sure from < to")
	ErrStakingAlreadyExpired = errors.New("STAKING: staking period already expired")
	ErrRedeemRequest         = errors.New("REDEEM: not staked")
	ErrRedeemValidNonZero    = errors.New("REDEEM: the redeem transaction has none 0 value")
)
View Source
var (
	// Base Quorum is the quorum to make sure blockchain can generate new blocks
	// while no other validators are running.
	BaseQuorum = []common.Address{
		common.HexToAddress("f2580391fe8a83366ed550de4e45af1714d74b8d"),
		common.HexToAddress("066aaff9e575302365b7862dcebd4a5a65f75f5f"),
		common.HexToAddress("3f80e8718d8e17a1768b467f193a6fbeaa6236e3"),
		common.HexToAddress("29d3fbe3e7983a41d0e6d984c480ceedb3c251fd"),
	}
)

Functions

func AddStakerToList

func AddStakerToList(addr common.Address, state vm.StateDB)

AddStakerToList adds a new staker's address to the staker's list in account storage trie

func CreateValidators

func CreateValidators(header *types.Header, state vm.StateDB) []bdls.Identity

CreateValidators creates an ordered list for all qualified validators with weights

func DeriveStakingSeed

func DeriveStakingSeed(priv *ecdsa.PrivateKey, stakingFrom uint64) []byte

DeriveStakingSeed deterministically derives the pseudo-random number with height and private key seed := H(H(privatekey,stakingFrom) *G)

func DeriveW

func DeriveW(header *types.Header) common.Hash

GetW calculates random number W based on block information W0 = H(U0) Wj = H(Pj-1,Wj-1) for 0<j<=r,

func GetAllStakers

func GetAllStakers(state vm.StateDB) []common.Address

GetAllStakers retrieve all staker's addresses from account storage trie

func HasStaked

func HasStaked(addr common.Address, state vm.StateDB) bool

HasStaked is a O(1) way to test whether an account has staked

func HashChain

func HashChain(hash []byte, from, to uint64) []byte

compute hash recursively for to - from times

func IsBaseQuorum

func IsBaseQuorum(address common.Address) bool

IsBaseQuorum check whether a address is from base quorum

func IsProposer

func IsProposer(header *types.Header, parentState vm.StateDB) bool

H(r;0;Ri,r,0;Wr) > max{0;1 i-aip}

func ProposerHash

func ProposerHash(header *types.Header) common.Hash

ProposerHash computes a hash for proposer's random number

func RemoveStakerFromList

func RemoveStakerFromList(addr common.Address, state vm.StateDB)

RemoveStakerFromList remove a staker's address from staker's list account storage trie

func SetStakerData

func SetStakerData(staker *Staker, state vm.StateDB)

SetStakerData sets staking information to storage account trie

func TotalStaked

func TotalStaked(state vm.StateDB) *big.Int

TotalStaked retrieves value staked in staking account

Types

type Staker

type Staker struct {
	// the Staker's address
	Address common.Address
	// the 1st block expected to participant in validator and proposer
	StakingFrom uint64
	// the last block to participant in validator and proposer, the tokens will be refunded
	// to participants' addresses after this block has mined
	StakingTo uint64
	// StakingHash is the last hash in hashchain,  random nubmers(R) in futureBlock
	// will be hashed for (futureBlock - stakingFrom) times to match with StakingHash.
	StakingHash common.Hash
	// records the number of tokens staked
	StakedValue *big.Int
}

Staker represents a staker's information retrieved from account storage trie

func GetStakerData

func GetStakerData(addr common.Address, state vm.StateDB) *Staker

GetStakerData retrieves staking information from storage account trie

type StakingOp

type StakingOp byte

types of staking related operation

type StakingRequest

type StakingRequest struct {
	// Staking or Redeem operation
	StakingOp StakingOp

	// The begining height to participate in consensus
	StakingFrom uint64

	// The ending  height to participate in consensus
	StakingTo uint64

	// The staker's hash at the height - StakingFrom
	StakingHash common.Hash
}

StakingRequest will be sent along in transaction.payload

Jump to

Keyboard shortcuts

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