Documentation ¶
Index ¶
- Constants
- Variables
- func AddStakerToList(addr common.Address, state vm.StateDB)
- func CreateValidators(header *types.Header, state vm.StateDB) []bdls.Identity
- func DeriveStakingSeed(priv *ecdsa.PrivateKey, stakingFrom uint64) []byte
- func DeriveW(header *types.Header) common.Hash
- func GetAllStakers(state vm.StateDB) []common.Address
- func HasStaked(addr common.Address, state vm.StateDB) bool
- func HashChain(hash []byte, from, to uint64) []byte
- func IsBaseQuorum(address common.Address) bool
- func IsProposer(header *types.Header, parentState vm.StateDB) bool
- func ProposerHash(header *types.Header) common.Hash
- func RemoveStakerFromList(addr common.Address, state vm.StateDB)
- func SetStakerData(staker *Staker, state vm.StateDB)
- func TotalStaked(state vm.StateDB) *big.Int
- type Staker
- type StakingOp
- type StakingRequest
Constants ¶
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" )
const ( Staking = StakingOp(0x00) Redeem = StakingOp(0xFF) )
Staking Operations
Variables ¶
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")) )
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") )
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 ¶
AddStakerToList adds a new staker's address to the staker's list in account storage trie
func CreateValidators ¶
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 ¶
GetW calculates random number W based on block information W0 = H(U0) Wj = H(Pj-1,Wj-1) for 0<j<=r,
func GetAllStakers ¶
GetAllStakers retrieve all staker's addresses from account storage trie
func IsBaseQuorum ¶
IsBaseQuorum check whether a address is from base quorum
func IsProposer ¶
H(r;0;Ri,r,0;Wr) > max{0;1 i-aip}
func ProposerHash ¶
ProposerHash computes a hash for proposer's random number
func RemoveStakerFromList ¶
RemoveStakerFromList remove a staker's address from staker's list account storage trie
func SetStakerData ¶
SetStakerData sets staking information to storage account trie
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
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